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

787 publication des triplets uriserie dcthaspart urioperation #797

Merged
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
6 changes: 4 additions & 2 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ services:
build: .
ports:
- "8080:8080"
environment:
- fr.insee.rmes.bauhaus.sesame.gestion.sesameServer=http://graphdb:7200
links:
- graphdb:localhost
- graphdb
graphdb:
image: ontotext/graphdb:latest
image: ontotext/graphdb:10.6.4
FBibonne marked this conversation as resolved.
Show resolved Hide resolved
restart: always
ports:
- "7200:7200"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package fr.insee.rmes.bauhaus_services;

import fr.insee.rmes.exceptions.RmesException;

import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.nio.file.Path;

public interface FilesOperations {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
import fr.insee.rmes.model.operations.Indicator;
import fr.insee.rmes.model.operations.Operation;
import fr.insee.rmes.model.operations.Series;
import org.springframework.core.io.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;

public interface OperationsService {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import fr.insee.rmes.bauhaus_services.rdf_utils.RdfUtils;
import fr.insee.rmes.exceptions.ErrorCodes;
import fr.insee.rmes.exceptions.RmesException;
import fr.insee.rmes.exceptions.RmesFileException;
import fr.insee.rmes.exceptions.RmesNotFoundException;
import org.apache.http.HttpStatus;
import org.eclipse.rdf4j.model.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,110 +5,139 @@
import fr.insee.rmes.bauhaus_services.rdf_utils.PublicationUtils;
import fr.insee.rmes.bauhaus_services.rdf_utils.RdfService;
import fr.insee.rmes.bauhaus_services.rdf_utils.RdfUtils;
import fr.insee.rmes.exceptions.*;
import org.apache.http.HttpStatus;
import fr.insee.rmes.exceptions.ErrorCodes;
import fr.insee.rmes.exceptions.RmesBadRequestException;
import fr.insee.rmes.exceptions.RmesException;
import fr.insee.rmes.exceptions.RmesNotFoundException;
import fr.insee.rmes.persistance.ontologies.DCTERMS;
import fr.insee.rmes.persistance.sparql_queries.operations.series.OpSeriesQueries;
import fr.insee.rmes.utils.JSONUtils;
import org.eclipse.rdf4j.model.Model;
import org.eclipse.rdf4j.model.Resource;
import org.eclipse.rdf4j.model.Statement;
import org.eclipse.rdf4j.model.impl.LinkedHashModel;
import org.eclipse.rdf4j.repository.RepositoryConnection;
import org.eclipse.rdf4j.repository.RepositoryException;
import org.eclipse.rdf4j.repository.RepositoryResult;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class SeriesPublication extends RdfService {

@Autowired
ParentUtils ownersUtils;

public void publishSeries(String seriesId, JSONObject serieJson) throws RmesException {
Model model = new LinkedHashModel();
Resource series = RdfUtils.seriesIRI(seriesId);
String familyId = serieJson.getJSONObject(Constants.FAMILY).getString(Constants.ID);
String status= ownersUtils.getValidationStatus(familyId);

if(PublicationUtils.isPublished(status)) {
throw new RmesBadRequestException(
ErrorCodes.SERIES_VALIDATION_UNPUBLISHED_FAMILY,
"This Series cannot be published before its family is published",
"Series: "+seriesId+" ; Family: "+familyId);
}

RepositoryConnection con = repoGestion.getConnection();
RepositoryResult<Statement> statements = repoGestion.getStatements(con, series);

RepositoryResult<Statement> hasPartStatements = repoGestion.getHasPartStatements(con, series);
RepositoryResult<Statement> replacesStatements = repoGestion.getReplacesStatements(con, series);
RepositoryResult<Statement> isReplacedByStatements = repoGestion.getIsReplacedByStatements(con, series);

try {
try {
if (!statements.hasNext()) {
throw new RmesNotFoundException(ErrorCodes.SERIES_UNKNOWN_ID,"Series not found", seriesId);
}
while (statements.hasNext()) {
Statement st = statements.next();
String pred = RdfUtils.toString(st.getPredicate());

// Other URI to transform
if (pred.endsWith("isPartOf") ||
pred.endsWith(Constants.SEEALSO) ||
pred.endsWith(Constants.REPLACES) ||
pred.endsWith(Constants.ISREPLACEDBY)||
pred.endsWith(Constants.DATA_COLLECTOR) ||
pred.endsWith(Constants.CONTRIBUTOR) ||
pred.endsWith(Constants.PUBLISHER) ||
pred.endsWith("accrualPeriodicity")||
pred.endsWith("type") ) {
transformSubjectAndObject(model, st);
} else if (pred.endsWith("isValidated")
|| pred.endsWith("validationState")
|| pred.endsWith("hasPart")) {
// nothing, wouldn't copy this attr
}
// Literals
else {
model.add(publicationUtils.tranformBaseURIToPublish(st.getSubject()),
st.getPredicate(),
st.getObject(),
st.getContext()
);
}
addStatementsToModel(model, hasPartStatements);
addStatementsToModel(model, replacesStatements);
addStatementsToModel(model, isReplacedByStatements);

}
} catch (RepositoryException e) {
throw new RmesException(HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage(), Constants.REPOSITORY_EXCEPTION);
}

} finally {
repoGestion.closeStatements(statements);
repoGestion.closeStatements(hasPartStatements);
con.close();
}
Resource seriesToPublishRessource = publicationUtils.tranformBaseURIToPublish(series);
repositoryPublication.publishResource(seriesToPublishRessource, model, "serie");

}

public void addStatementsToModel(Model model, RepositoryResult<Statement> statements) {
while (statements.hasNext()) {
Statement statement = statements.next();
transformSubjectAndObject(model, statement);
}
}

public void transformSubjectAndObject(Model model, Statement statement) {
model.add(publicationUtils.tranformBaseURIToPublish(statement.getSubject()),
statement.getPredicate(),
publicationUtils.tranformBaseURIToPublish((Resource) statement.getObject()),
statement.getContext());
}

final
ParentUtils ownersUtils;

public SeriesPublication(ParentUtils ownersUtils) {
this.ownersUtils = ownersUtils;
}

private static void checkIfSeriesExist(String id, RepositoryResult<Statement> statements) throws RmesNotFoundException {
if (!statements.hasNext()) {
throw new RmesNotFoundException(ErrorCodes.SERIES_UNKNOWN_ID, "Series not found", id);
}
}
public void publishSeries(String id, JSONObject series) throws RmesException {
String familyId = series.getJSONObject(Constants.FAMILY).getString(Constants.ID);
String status = ownersUtils.getValidationStatus(familyId);

if (PublicationUtils.isPublished(status)) {
throw new RmesBadRequestException(
ErrorCodes.SERIES_VALIDATION_UNPUBLISHED_FAMILY,
"This Series cannot be published before its family is published",
"Series: " + id + " ; Family: " + familyId);
}

Model model = new LinkedHashModel();
Resource resource = RdfUtils.seriesIRI(id);

RepositoryConnection con = repoGestion.getConnection();
RepositoryResult<Statement> statements = repoGestion.getStatements(con, resource);

checkIfSeriesExist(id, statements);

RepositoryResult<Statement> hasPartStatements = repoGestion.getHasPartStatements(con, resource);
RepositoryResult<Statement> replacesStatements = repoGestion.getReplacesStatements(con, resource);
RepositoryResult<Statement> isReplacedByStatements = repoGestion.getIsReplacedByStatements(con, resource);

try {
while (statements.hasNext()) {
Statement st = statements.next();
String pred = RdfUtils.toString(st.getPredicate());

// Other URI to transform
if (pred.endsWith("isPartOf") ||
pred.endsWith(Constants.SEEALSO) ||
pred.endsWith(Constants.REPLACES) ||
pred.endsWith(Constants.ISREPLACEDBY) ||
pred.endsWith(Constants.DATA_COLLECTOR) ||
pred.endsWith(Constants.CONTRIBUTOR) ||
pred.endsWith(Constants.PUBLISHER) ||
pred.endsWith("accrualPeriodicity") ||
pred.endsWith("type")) {
transformSubjectAndObject(model, st);
} else if (pred.endsWith("isValidated")
|| pred.endsWith("validationState")
|| pred.endsWith("hasPart")) {
// nothing, wouldn't copy this attr
}
// Literals
else {
model.add(publicationUtils.tranformBaseURIToPublish(st.getSubject()),
st.getPredicate(),
st.getObject(),
st.getContext()
);
}
addStatementsToModel(model, hasPartStatements);
addStatementsToModel(model, replacesStatements);
addStatementsToModel(model, isReplacedByStatements);
}

/**
* We have to query all published operations linked to this series and publish all of them
*/
addOperationsWhoHavePartWithToModel(resource, model);


} finally {
repoGestion.closeStatements(statements);
repoGestion.closeStatements(hasPartStatements);
con.close();
}
Resource seriesToPublishRessource = publicationUtils.tranformBaseURIToPublish(resource);
repositoryPublication.publishResource(seriesToPublishRessource, model, "serie");

}


private void addOperationsWhoHavePartWithToModel(Resource resource, Model model) throws RmesException {
JSONArray operations = repoGestion.getResponseAsArray(OpSeriesQueries.getPublishedOperationsForSeries(resource.toString()));
JSONUtils.stream(operations)
.map(operation -> operation.getString("operation"))
.forEach(iri -> {
model.add(
publicationUtils.tranformBaseURIToPublish(resource),
DCTERMS.HAS_PART,
publicationUtils.tranformBaseURIToPublish(RdfUtils.createIRI(iri)),
RdfUtils.operationsGraph()
);
});
}

public void addStatementsToModel(Model model, RepositoryResult<Statement> statements) {
while (statements.hasNext()) {
Statement statement = statements.next();
transformSubjectAndObject(model, statement);
}
}

public void transformSubjectAndObject(Model model, Statement statement) {
model.add(publicationUtils.tranformBaseURIToPublish(statement.getSubject()),
statement.getPredicate(),
publicationUtils.tranformBaseURIToPublish((Resource) statement.getObject()),
statement.getContext());
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,10 @@ public static String checkIfSeriesExists(List<String> iris) throws RmesException
params.put(URI_SERIES, iris);
return buildSeriesRequest("checkIfSeriesExists.ftlh", params);
}

public static String getPublishedOperationsForSeries(String iri) throws RmesException {
Map<String, Object> params = initParams();
params.put("SERIES_IRI", iri);
return buildSeriesRequest("getPublishedOperationsForSeries.ftlh", params);
}
}
1 change: 0 additions & 1 deletion src/main/java/fr/insee/rmes/utils/StringUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,4 @@ public static String convertHtmlStringToRaw(String html) {
}
return raw;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,6 @@
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
* WebService class for resources of Classifications
*
*
* @author N. Laval
*
*/

@RestController
@RequestMapping("/classifications")
@Tag(name ="Classifications",description = "Classification API")
Expand Down
8 changes: 0 additions & 8 deletions src/main/java/fr/insee/rmes/webservice/ConceptsResources.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,13 @@
import jakarta.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
* WebService class for resources of Concepts
*
*
* @author N. Laval
*
*/
@RestController
@RequestMapping("/concepts")
@SecurityRequirement(name = "bearerAuth")
Expand Down
11 changes: 1 addition & 10 deletions src/main/java/fr/insee/rmes/webservice/LoaderResources.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,7 @@
import java.io.IOException;
import java.io.InputStream;

/**
* WebService class to download/upload resources in databases
*
* schemes: - http
*
* consumes: - application/json
*
* produces: - application/json
*
*/

@RestController
@RequestMapping("/loader")
@SecurityRequirement(name = "bearerAuth")
Expand Down
8 changes: 0 additions & 8 deletions src/main/java/fr/insee/rmes/webservice/PublicResources.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@
import java.util.List;
import java.util.TreeSet;

/**
* WebService class for resources
* schemes: - http
* <p>
* consumes: - application/json
* <p>
* produces: - application/json
*/
@RestController
@RequestMapping("/")
@Tag(name = "Application", description = "Application API")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import fr.insee.rmes.config.swagger.model.IdLabelAltLabel;
import fr.insee.rmes.exceptions.RmesException;
import fr.insee.rmes.model.operations.Operation;
import fr.insee.rmes.utils.XMLUtils;
import fr.insee.rmes.webservice.OperationsCommonResources;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public ResponseEntity<Object> createSeries(
consumes = MediaType.APPLICATION_JSON_VALUE)
@io.swagger.v3.oas.annotations.Operation(operationId = "setSeriesValidation", summary = "Series validation")
public ResponseEntity<Object> setSeriesValidation(
@PathVariable(Constants.ID) String id) throws RmesException {
@PathVariable(Constants.ID) String id) {
try {
operationsService.setSeriesValidation(id);
} catch (RmesException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SELECT ?operation
FROM <${OPERATIONS_GRAPH}>
WHERE {
<${SERIES_IRI}> dcterms:hasPart ?operation .
?operation insee:validationState ?value
FILTER(?value != 'Unpublished') .
}
Loading