-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat : add controls for URL format and URN format. #865
base: main
Are you sure you want to change the base?
The head ref may contain hidden characters: "858-pouvoir-saisir-des-urn-et-des-url-dans-le-champ-structure-des-jeux-de-donn\u00E9es-new"
feat : add controls for URL format and URN format. #865
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Il ne faut pas rejeter un dataStructure à null car l'attribut n'est pas toujours renseigné
- La validation d'URI (et a fortiori des URL), c'est compliqué (cf. cas supplméntaires sur les tests) : on peut faciliter le travail en passant le type de
Dataset.dataStructure
à URI - quelques remarques sur la syntaxe également
@@ -538,10 +538,34 @@ private String persist(Dataset dataset) throws RmesException { | |||
return dataset.getId(); | |||
} | |||
|
|||
boolean URNValidator(String URN) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deux remarques sur le nommage :
- par convention le nom d'une méthode commence par une minuscule (par exemple
isValiURN
) - les noms de paramètres commencent par une minuscule également (
urn
)
La méthode est une méthode utilitaire relative aux URI donc on pourrait la placer dans fr.insee.rmes.utils.UriUtils
return (conforme); | ||
} | ||
|
||
boolean URLValidator(String URL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deux remarques sur le nommage :
- par convention le nom d'une méthode commence par une minuscule (par exemple
isValiURL
) - les noms de paramètres commencent par une minuscule également (
url
)
La méthode est une méthode utilitaire relative aux URI donc on pourrait la placer dans fr.insee.rmes.utils.UriUtils
boolean URNValidator(String URN) { | ||
|
||
boolean conforme = false; | ||
List<String> detailsURN = Arrays.asList(URN.split(":")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on ne vérifie pas si le paramètre avec lequel on appelle la méthode URNValidator est null ou pas avant l'appel donc il faut gérer le cas null dans la méthode
boolean conforme = false; | ||
List<String> detailsURN = Arrays.asList(URN.split(":")); | ||
if ((detailsURN.size()>=3 && ("urn").equals(detailsURN.getFirst()))) conforme = true; | ||
return (conforme); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
même test en plus concis :
return URN != null && URN.startWith("urn:") && StringUtils.countOccurrencesOf(URN, ":") > 2;
boolean URLValidator(String URL) { | ||
|
||
boolean conforme = false; | ||
List<String> detailsURL = Arrays.asList(URL.split("//")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on ne vérifie pas si le paramètre avec lequel on appelle la méthode URNValidator est null ou pas avant l'appel donc il faut gérer le cas null dans la méthode
|
||
@Test | ||
void shouldnotValidateURN(){ | ||
List<String> URN = Arrays.asList("test:test:test","urn:test","urn:test:","urn : : ","urn::"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
List.of
List<Boolean> URNTypeActual = new ArrayList<>(); | ||
URN.forEach(element -> URNTypeActual.add(new DatasetServiceImpl().URNValidator(element))); | ||
List<Boolean> URNTypeExpected = Arrays.asList(false,false,false,false,false); | ||
assertEquals(URNTypeExpected,URNTypeActual); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
En deux lignes :
var datasetServiceImpl=new DatasetServiceImpl();
URN.forEach(urn->assertFalse(datasetServiceImpl.URLValidator(urn)));
@@ -704,4 +702,38 @@ void shouldDeleteDataSet() throws RmesException { | |||
} | |||
} | |||
|
|||
@Test | |||
void shouldValidateURL(){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ajouter les cas suivants au test : ils doivent être valides également : "http://http://","http://[::FFFF:129.144.52.38]:80/index.html"
} | ||
|
||
@Test | ||
void shouldnotValidateURL(){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ajouter les cas suivants au test : ils doivent être également invalides : "http://\\","http://]","http://|", "http://[", "http:// 1", "http://test:-2/index.html"
} | ||
|
||
@Test | ||
void shouldnotValidateURN(){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ajouter le cas suivant "urn: 1:2"
: il doit être invalide
J'ai modifié le code pour tenir compte des modifications proposées
|
#858