Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions magma-gestion-impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@
<artifactId>boot-properties-logger-starter</artifactId>
<version>1.5.0</version>
</dependency>
<dependency>
<groupId>fr.insee.rmes</groupId>
<artifactId>magma-gestion-interface</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,15 @@ public DataSetModelSwagger(Id id, List<LangContent> title, Uri uri, Modified mod
this.validationState = validationState;
this.themeModelSwaggerS = themeModelSwaggerS;
}

public DataSetModelSwagger(Id id, List<LangContent> title, Uri uri, String validationState, CatalogRecordCreated catalogRecordCreated, CatalogRecordModified catalogRecordModified, CatalogRecordCreator catalogRecordCreator, CatalogRecordContributor catalogRecordContributor) {
this.id = id.toString();
this.title = title;
this.uri = uri.toString();
this.validationState = validationState;
this.catalogRecordContributor = catalogRecordContributor;
this.catalogRecordCreator = catalogRecordCreator;
this.catalogRecordCreated = catalogRecordCreated;
this.catalogRecordModified = catalogRecordModified;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,22 @@ protected DataSetModelSwagger findDataSetModelSwagger(String id) throws RmesExce
List<LangContent> title = constructLangContent(catalogue_result.getString("titleLg1"), catalogue_result.getString("titleLg2"));
Id id1=new Id(catalogue_result.getString("id"));
Uri uri = new Uri(catalogue_result.getString("uri"));
DisseminationStatus disseminationStatus = new DisseminationStatus(ontologies_result.getString("labeldisseminationStatusLg1"));

CatalogRecordCreated catalogRecordCreated = new CatalogRecordCreated(catalogue_result.getString("catalogRecordCreated"));
CatalogRecordModified catalogRecordModified = new CatalogRecordModified(catalogue_result.getString("catalogRecordModified"));
CatalogRecordCreator catalogRecordCreator = new CatalogRecordCreator(catalogue_result.getString("catalogRecordCreator"));
CatalogRecordContributor catalogRecordContributor = new CatalogRecordContributor(catalogue_result.getString("catalogRecordContributor"));
String validationState = catalogue_result.getString("statutValidation");
DataSetModelSwagger response = new DataSetModelSwagger(id1, title, uri, validationState, disseminationStatus, catalogRecordCreated,catalogRecordModified,catalogRecordCreator,catalogRecordContributor);

DisseminationStatus disseminationStatus = null;
DataSetModelSwagger response = null;
if (ontologies_result.has("labeldisseminationStatusLg1")){
disseminationStatus = new DisseminationStatus(ontologies_result.getString("labeldisseminationStatusLg1"));
response = new DataSetModelSwagger(id1, title, uri, validationState, disseminationStatus, catalogRecordCreated, catalogRecordModified, catalogRecordCreator, catalogRecordContributor);
} else {
response = new DataSetModelSwagger(id1, title, uri, validationState, catalogRecordCreated, catalogRecordModified, catalogRecordCreator, catalogRecordContributor);
}

testPresenceVariablePuisAjout(response,catalogue_result,adms_result,codes_result,organisations_result,structures_result);
return response;
} else {
Expand Down Expand Up @@ -524,10 +533,14 @@ private List<IdLabel> getWasGeneratedBy(List<String> operationStat) throws RmesE
params.put("URI", s.replace(" ", ""));

JSONObject wasGeneratedByQuery = repoGestion.getResponseAsObject(buildRequest(Constants.DATASETS_QUERIES_PATH+DATASET_BY_ID_PATH, "getDataSetByIdWasGeneratedBy.ftlh", params));
List<LangContent> wasGeneratedByTitles = constructLangContent(wasGeneratedByQuery.getString("labelwasGeneratedByLg1"),wasGeneratedByQuery.getString("labelwasGeneratedByLg2"));
IdLabel wasGeneratedByIdLabel = new IdLabel(wasGeneratedByQuery.getString("wasGeneratedById"),wasGeneratedByTitles);
wasGeneratedByIdLabel.setType(wasGeneratedByQuery.getString("typeWasGeneratedBy"));
wasGeneratedBy.add(wasGeneratedByIdLabel);
List<LangContent> wasGeneratedByTitles = null;
IdLabel wasGeneratedByIdLabel = null;
if (wasGeneratedByQuery.has("wasGeneratedById")) {
wasGeneratedByTitles = constructLangContent(wasGeneratedByQuery.getString("labelwasGeneratedByLg1"), wasGeneratedByQuery.getString("labelwasGeneratedByLg2"));
wasGeneratedByIdLabel = new IdLabel(wasGeneratedByQuery.getString("wasGeneratedById"), wasGeneratedByTitles);
wasGeneratedByIdLabel.setType(wasGeneratedByQuery.getString("typeWasGeneratedBy"));
wasGeneratedBy.add(wasGeneratedByIdLabel);
}
}
return wasGeneratedBy;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ select distinct ?id ?dateModification
FROM <http://rdf.insee.fr/graphes/catalogue>

where {
?uri a dcat:Dataset ;
dcterms:identifier "${ID}" ;
dcterms:identifier ?id ;
OPTIONAL {?uri dcterms:modified ?dateModification . }
?uri a dcat:Dataset ;
dcterms:identifier "${ID}" ;
dcterms:identifier ?id ;
OPTIONAL {
?record a dcat:CatalogRecord ;
foaf:primaryTopic ?uri ;
dcterms:modified ?dateModification .
}

} group by ?id ?dateModification
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package fr.insee.rmes.magma.gestion.old.modelSwagger.datasets;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.json.JsonMapper;
import fr.insee.rmes.magma.gestion.old.model.datasets.*;
import fr.insee.rmes.magma.gestion.old.modelSwagger.dataset.DataSetModelSwagger;
import fr.insee.rmes.magma.gestion.old.modelSwagger.dataset.LangContent;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.jupiter.api.Test;

import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;

class DataSetModelSwaggerTest {


@Test
void verify_jacksonAnnotation_test() throws JsonProcessingException, JSONException {
var dataSetModelSwagger=new DataSetModelSwagger();
dataSetModelSwagger.setCatalogRecordContributor(new CatalogRecordContributor("test_contributor"));
dataSetModelSwagger.setCatalogRecordCreated(new CatalogRecordCreated("recordCreated"));
dataSetModelSwagger.setCatalogRecordCreator(new CatalogRecordCreator("creator"));
dataSetModelSwagger.setCatalogRecordModified(new CatalogRecordModified("modified"));
ObjectMapper mapper=new JsonMapper();
var result=mapper.writeValueAsString(dataSetModelSwagger);
var json=new JSONObject(result);

assertThat(json.keySet()).contains("catalogRecordContributor", "catalogRecordCreated", "catalogRecordCreator", "catalogRecordModified");
assertThat(result).contains("\"catalogRecordContributor\":\"test_contributor\"",
"\"catalogRecordCreated\":\"recordCreated\"",
"\"catalogRecordCreator\":\"creator\"",
"\"catalogRecordModified\":\"modified\"");
}

@Test
void constructor_withIdTitleUriValidationStateAndCatalogFields_shouldSetAllFields() {
Id id = new Id("jd1000");
Uri uri = new Uri("http://bauhaus/catalogues/jeuDeDonnees/jd1000");
List<LangContent> title = List.of(new LangContent("fr", "Titre FR"), new LangContent("en", "Title EN"));
String validationState = "Published";
CatalogRecordCreated created = new CatalogRecordCreated("2024-01-01T00:00:00");
CatalogRecordModified modified = new CatalogRecordModified("2024-06-15T10:00:00");
CatalogRecordCreator creator = new CatalogRecordCreator("creator1");
CatalogRecordContributor contributor = new CatalogRecordContributor("contributor1");

DataSetModelSwagger result = new DataSetModelSwagger(id, title, uri, validationState, created, modified, creator, contributor);

assertThat(result.getId()).isEqualTo("jd1000");
assertThat(result.getUri()).isEqualTo("http://bauhaus/catalogues/jeuDeDonnees/jd1000");
assertThat(result.getTitle()).isEqualTo(title);
assertThat(result.getValidationState()).isEqualTo("Published");
assertThat(result.getCatalogRecordCreated()).isEqualTo(created);
assertThat(result.getCatalogRecordModified()).isEqualTo(modified);
assertThat(result.getCatalogRecordCreator()).isEqualTo(creator);
assertThat(result.getCatalogRecordContributor()).isEqualTo(contributor);
}

@Test
void constructor_withIdTitleUriValidationStateAndCatalogFields_shouldSerializeToJson() throws JsonProcessingException, JSONException {
Id id = new Id("jd1000");
Uri uri = new Uri("http://bauhaus/catalogues/jeuDeDonnees/jd1000");
List<LangContent> title = List.of(new LangContent("fr", "Titre FR"), new LangContent("en", "Title EN"));
CatalogRecordCreated created = new CatalogRecordCreated("2024-01-01T00:00:00");
CatalogRecordModified modified = new CatalogRecordModified("2024-06-15T10:00:00");
CatalogRecordCreator creator = new CatalogRecordCreator("creator1");
CatalogRecordContributor contributor = new CatalogRecordContributor("contributor1");

DataSetModelSwagger result = new DataSetModelSwagger(id, title, uri, "Published", created, modified, creator, contributor);

ObjectMapper mapper = new JsonMapper();
String json = mapper.writeValueAsString(result);
JSONObject jsonObject = new JSONObject(json);

assertThat(jsonObject.getString("id")).isEqualTo("jd1000");
assertThat(jsonObject.getString("uri")).isEqualTo("http://bauhaus/catalogues/jeuDeDonnees/jd1000");
assertThat(jsonObject.getString("validationState")).isEqualTo("Published");
assertThat(jsonObject.getString("catalogRecordCreated")).isEqualTo("2024-01-01T00:00:00");
assertThat(jsonObject.getString("catalogRecordModified")).isEqualTo("2024-06-15T10:00:00");
assertThat(jsonObject.getString("catalogRecordCreator")).isEqualTo("creator1");
assertThat(jsonObject.getString("catalogRecordContributor")).isEqualTo("contributor1");
assertThat(jsonObject.getJSONArray("title")).hasSize(2);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package fr.insee.rmes.magma.gestion.old.persistence;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.skyscreamer.jsonassert.JSONAssert;

import static org.junit.jupiter.api.Assertions.*;

class RdfServiceTest {

private RdfService rdfService;

@BeforeEach
void init(){
rdfService=new RdfService() {};
}

@Test
@DisplayName("Test de formatLabel, cas nominal")
void formatLabelTest_nominal() throws JSONException{
JSONObject jsonObject=new JSONObject();
jsonObject.put("prefLabelLg1", "description en français");
jsonObject.put("prefLabelLg2", "english description");
JSONArray expected=new JSONArray("[{\"contenu\":\"description en français\"},{\"contenu\":\"english description\"}]");
JSONAssert.assertEquals(expected, rdfService.formatLabel(jsonObject), false);
}

@Test
void formatLabelTest_empty() {
JSONObject jsonObject=new JSONObject();
assertThrows(JSONException.class, ()->rdfService.formatLabel(jsonObject));
}

@Test
@DisplayName("Test de formatNom, cas nominal")
void formatNomTest_nominal() throws JSONException{
JSONObject jsonObject=new JSONObject();
jsonObject.put("altLabelLg1", "description en français");
jsonObject.put("altLabelLg2", "english description");
JSONArray expected=new JSONArray("[{\"contenu\":\"description en français\"},{\"contenu\":\"english description\"}]");
System.out.println(rdfService.formatNom(jsonObject));
JSONAssert.assertEquals(expected, rdfService.formatNom(jsonObject), false);
}

@Test
@DisplayName("Test de getValidationState")
void getValidationStateTest() {
//GIVEN
String str = "Validated";
String str2 = "UnPubLIShed";
String str3 = "Modified";
//WHEN
String result = rdfService.getValidationState(str);
String result2 = rdfService.getValidationState(str2);
String result3 = rdfService.getValidationState(str3);
//THEN
assertEquals("Publiée", result);
assertEquals("Provisoire, jamais publiée", result2);
assertEquals("Provisoire, déjà publiée", result3);
}



}
Loading