Skip to content

Commit

Permalink
Merge pull request #127 from EmmanuelDemey/acceptance
Browse files Browse the repository at this point in the history
fix: delete component specification when publishing
  • Loading branch information
alicela authored May 10, 2021
2 parents 6488ec9 + 321665d commit b4d57ff
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package fr.insee.rmes.bauhaus_services.rdf_utils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.Response.Status.Family;

import fr.insee.rmes.persistance.ontologies.QB;
import org.apache.http.HttpStatus;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -20,6 +22,7 @@
import org.eclipse.rdf4j.repository.RepositoryConnection;
import org.eclipse.rdf4j.repository.RepositoryException;
import org.eclipse.rdf4j.repository.RepositoryResult;
import org.eclipse.rdf4j.repository.util.Repositories;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
Expand Down Expand Up @@ -193,8 +196,42 @@ private static void publishContext(Resource context, Model model, String type, R
throw new RmesException(HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage(), CONNECTION_TO + repo + FAILED);
}
}



public static void clearStructureAndComponentForAllRepositories(Resource structure) {
clearStructureAndComponents(structure, REPOSITORY_PUBLICATION);
clearStructureAndComponents(structure, REPOSITORY_PUBLICATION_INTERNE);
}

public static void clearStructureAndComponents(Resource structure, Repository repository) {
List<Resource> toRemove = new ArrayList<>();
try {
RepositoryConnection conn = repository.getConnection();
RepositoryResult<Statement> nodes = null;
RepositoryResult<Statement> specifications = null;
nodes = conn.getStatements(structure, QB.COMPONENT, null, false);
while (nodes.hasNext()) {
Resource node = (Resource) nodes.next().getObject();
toRemove.add(node);
specifications = conn.getStatements(node, QB.COMPONENT, null, false);
while (specifications.hasNext()) {
toRemove.add((Resource) specifications.next().getObject());
}
specifications.close();

}
nodes.close();
toRemove.forEach(res -> {
try {
RepositoryResult<Statement> statements = conn.getStatements(res, null, null, false);
conn.remove(statements);
} catch (RepositoryException e) {
logger.error("RepositoryGestion Error {}", e.getMessage());
}
});
} catch (RepositoryException e) {
new RmesException(HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage(), "Failure deletion : " + structure);
}
}
private static void clearConceptLinks(Resource concept, RepositoryConnection conn) throws RmesException {
List<IRI> typeOfLink = Arrays.asList(SKOS.BROADER, SKOS.NARROWER, SKOS.MEMBER, DCTERMS.REFERENCES,
DCTERMS.REPLACES, SKOS.RELATED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@ public void publish(Resource structure) throws RmesException {
RepositoryConnection con = repoGestion.getConnection();

this.copyTriplet(structure, model, con, new String[]{"validationState", Constants.CREATOR, Constants.CONTRIBUTOR});
Resource componentToPublishRessource = PublicationUtils.tranformBaseURIToPublish(structure);
RepositoryPublication.publishResource(componentToPublishRessource, model, "Structure");

Resource structureToPublish = PublicationUtils.tranformBaseURIToPublish(structure);

RepositoryPublication.clearStructureAndComponentForAllRepositories(structureToPublish);
RepositoryPublication.publishResource(structureToPublish, model, "Structure");

}

}
Expand Down

0 comments on commit b4d57ff

Please sign in to comment.