Skip to content
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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

SMaSndil
Copy link

@SMaSndil SMaSndil commented Feb 6, 2025

Copy link
Member

@FBibonne FBibonne left a 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) {
Copy link
Member

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) {
Copy link
Member

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(":"));
Copy link
Member

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);
Copy link
Member

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("//"));
Copy link
Member

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::");
Copy link
Member

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);
Copy link
Member

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(){
Copy link
Member

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(){
Copy link
Member

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(){
Copy link
Member

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

@SMaSndil
Copy link
Author

J'ai modifié le code pour tenir compte des modifications proposées

  • classes modifiées : UriUtils et DatasetServiceImpl
  • classe pour les tests ajoutée : UriUtilsTest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pouvoir saisir des URN et des URL dans le champ structure des jeux de données
2 participants