Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,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;
}
}
25 changes: 19 additions & 6 deletions src/main/java/fr/insee/rmes/services/datasets/DataSetsImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,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 @@ -522,10 +531,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
Expand Up @@ -3,14 +3,13 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.json.JsonMapper;
import fr.insee.rmes.model.datasets.CatalogRecordContributor;
import fr.insee.rmes.model.datasets.CatalogRecordCreated;
import fr.insee.rmes.model.datasets.CatalogRecordCreator;
import fr.insee.rmes.model.datasets.CatalogRecordModified;
import fr.insee.rmes.model.datasets.*;
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 {
Expand All @@ -34,4 +33,53 @@ void verify_jacksonAnnotation_test() throws JsonProcessingException, JSONExcepti
"\"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);
}

}
Loading