Skip to content

Commit

Permalink
Merge pull request #43 from InseeFr/acceptance
Browse files Browse the repository at this point in the history
2.1.0
  • Loading branch information
alicela authored Aug 11, 2020
2 parents 07732f6 + 31832bd commit 3ff7fa2
Show file tree
Hide file tree
Showing 26 changed files with 112 additions and 109 deletions.
1 change: 1 addition & 0 deletions bauhaus-back-changeLog.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.1.0 : Ajout de la publication vers l'interne et changement d'ergonomie de l'application
20 changes: 1 addition & 19 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>fr.insee.rmes</groupId>
<artifactId>Bauhaus-BO</artifactId>
<packaging>war</packaging>
<version>2.0.0</version>
<version>2.1.0</version>
<name>Bauhaus-Back-Office</name>
<description>Back-office services for Bauhaus</description>
<url>https://github.com/InseeFr/Bauhaus-Back-Office</url>
Expand Down Expand Up @@ -441,24 +441,6 @@
</configuration>
</plugin>

<!-- Plugin lancement des tests -->
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<includes>
<include>**/*Test.java</include>
</includes>
</configuration>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.3.2</version>
</dependency>
</dependencies>
</plugin>

<!-- Plugin pour prise en compte des tests sur SonarQube plate-forme innovation -->
<plugin>
<groupId>org.jacoco</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,18 @@
import fr.insee.rmes.utils.JSONUtils;

@Component
public class ConceptsUtils extends RdfService {
public class ConceptsUtils extends RdfService {

static final Logger logger = LogManager.getLogger(ConceptsUtils.class);
private static final Logger logger = LogManager.getLogger(ConceptsUtils.class);

@Autowired
ConceptsPublication conceptsPublication;
private ConceptsPublication conceptsPublication;

@Autowired
private NoteManager noteManager;

/**
* Concepts
*/

public String createID() throws RmesException{
public String createID() throws RmesException {
JSONObject json = repoGestion.getResponseAsObject(ConceptsQueries.lastConceptID());
String notation = json.getString("notation");
int id = Integer.parseInt(notation.substring(1))+1;
Expand All @@ -78,39 +78,47 @@ public JSONObject getConceptById(String id) throws RmesException{
return concept;
}

/**
* CREATION
* @param body
* @return
* @throws RmesException
*/
public String setConcept(String body) throws RmesException {
if(!stampsRestrictionsService.canCreateConcept()) {
throw new RmesUnauthorizedException(ErrorCodes.CONCEPT_CREATION_RIGHTS_DENIED, "Only an admin or concepts manager can create a new concept.");
}
ObjectMapper mapper = new ObjectMapper();
mapper.configure(
DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
Concept concept = null;
try {
concept = mapper.readValue(body, Concept.class);
} catch (IOException e) {
throw new RmesException(HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage(), "IOException");
}
createRdfConcept(concept);
Concept concept = setConcept(createID(), true, body);
logger.info("Create concept : {} - {}", concept.getId() , concept.getPrefLabelLg1());
return concept.getId();
}

/**
* UPDATE
* @param id
* @param body
* @throws RmesException
*/
public void setConcept(String id, String body) throws RmesException {
if(!stampsRestrictionsService.canModifyConcept(RdfUtils.conceptIRI(id))) {
throw new RmesUnauthorizedException(ErrorCodes.CONCEPT_MODIFICATION_RIGHTS_DENIED, "");
}
Concept concept = setConcept(id, false, body);
logger.info("Update concept : {} - {}" , concept.getId() , concept.getPrefLabelLg1());
}

private Concept setConcept(String id, boolean isNewConcept, String body) throws RmesException {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(
DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
Concept concept = new Concept(id);
Concept concept = new Concept(id, isNewConcept);
try {
concept = mapper.readerForUpdating(concept).readValue(body);
concept = mapper.readerForUpdating(concept).readValue(body);
} catch (IOException e) {
throw new RmesException(HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage(), "IOException");
}
createRdfConcept(concept);
logger.info("Update concept : {} - {}" , concept.getId() , concept.getPrefLabelLg1());
return concept;
}

public void conceptsValidation(String body) throws RmesException {
Expand Down Expand Up @@ -156,7 +164,7 @@ public void createRdfConcept(Concept concept) throws RmesException {
RdfUtils.addTripleDateTime(conceptURI, DCTERMS.MODIFIED, concept.getModified(), model, RdfUtils.conceptGraph());

// Add notes to model, delete some notes and updates some other notes
List<List<IRI>> notesToDeleteAndUpdate = new NoteManager().setNotes(concept, model);
List<List<IRI>> notesToDeleteAndUpdate = noteManager.setNotes(concept, model);

// Add links to model and save member links
new LinksUtils().createRdfLinks(conceptURI, concept.getLinks(), model);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.eclipse.rdf4j.repository.RepositoryResult;
import org.json.JSONArray;
import org.jsoup.Jsoup;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Component;

import fr.insee.rmes.bauhaus_services.Constants;
import fr.insee.rmes.bauhaus_services.rdf_utils.PublicationUtils;
Expand All @@ -28,7 +28,7 @@
import fr.insee.rmes.persistance.ontologies.XKOS;
import fr.insee.rmes.persistance.sparql_queries.concepts.ConceptsQueries;

@Repository
@Component
public class ConceptsPublication extends RdfService{


Expand All @@ -45,7 +45,7 @@ public void publishConcepts(JSONArray conceptsToPublish) throws RmesException {
checkTopConceptOf(conceptId, model);
Resource concept = RdfUtils.conceptIRI(conceptId);

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

String[] notes = {"scopeNote","definition","editorialNote"} ;
Expand Down Expand Up @@ -195,7 +195,7 @@ public void publishCollection(JSONArray collectionsToValidate) throws RmesExcept
Resource collection = RdfUtils.collectionIRI(collectionId);
//TODO uncomment when we can notify...
//Boolean creation = !RepositoryPublication.getResponseAsBoolean(CollectionsQueries.isCollectionExist(collectionId));
RepositoryConnection con = PublicationUtils.getRepositoryConnectionGestion();
RepositoryConnection con = repoGestion.getConnection();
RepositoryResult<Statement> statements = repoGestion.getStatements(con, collection);

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ public void createRdfLinks(IRI conceptURI, List<Link> links, Model model) {
if (link.getTypeOfLink().equals("narrower")) {
addTripleNarrower(conceptURI, link.getIds(), model);
}
if (link.getTypeOfLink().equals("broader")) {
else if (link.getTypeOfLink().equals("broader")) {
addTripleBroader(conceptURI, link.getIds(), model);
}
if (link.getTypeOfLink().equals("references")) {
else if (link.getTypeOfLink().equals("references")) {
addTripleReferences(conceptURI, link.getIds(), model);
}
if (link.getTypeOfLink().equals("succeed")) {
else if (link.getTypeOfLink().equals("succeed")) {
addTripleSucceed(conceptURI, link.getIds(), model);
}
if (link.getTypeOfLink().equals("related")) {
else if (link.getTypeOfLink().equals("related")) {
addTripleRelated(conceptURI, link.getIds(), model);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.Model;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import fr.insee.rmes.bauhaus_services.rdf_utils.RdfUtils;
import fr.insee.rmes.exceptions.RmesException;
Expand All @@ -16,11 +18,13 @@
import fr.insee.rmes.model.notes.concepts.ConceptsDatedNoteTypes;
import fr.insee.rmes.model.notes.concepts.ConceptsVersionnedNoteTypes;

@Component
public class NoteManager {

@Autowired
NotesUtils noteUtils;

public List<List<IRI>> setNotes(Concept concept, Model model) throws RmesException {

NotesUtils noteUtils = new NotesUtils();
// TODO : see extreme cases to close notes

List<VersionableNote> versionableNotes = concept.getVersionableNotes();
Expand All @@ -34,17 +38,17 @@ public List<List<IRI>> setNotes(Concept concept, Model model) throws RmesExcepti

Set<String> versionableNoteTypesInConcept = new HashSet<>();

setVersionableNotes(concept, model, noteUtils, versionableNotes, conceptId, conceptVersion, notesToDelete,
setVersionableNotes(concept, model, versionableNotes, conceptId, conceptVersion, notesToDelete,
versionableNoteTypesInConcept);

Set<String> versionableNoteTypes = new HashSet<>();
for (ConceptsVersionnedNoteTypes c : ConceptsVersionnedNoteTypes.values()) {
versionableNoteTypes.add(c.toString());
}
versionableNoteTypes.removeAll(versionableNoteTypesInConcept);
setVersionableNoteTypes(concept, model, noteUtils, conceptId, conceptVersion, versionableNoteTypes);
setVersionableNoteTypes(concept, model, conceptId, conceptVersion, versionableNoteTypes);

setDatableNotes(concept, model, noteUtils, datableNotes, conceptId, notesToDelete);
setDatableNotes(concept, model, datableNotes, conceptId, notesToDelete);

// Keep historical notes
noteUtils.keepHistoricalNotes(conceptId, conceptVersion, model);
Expand All @@ -57,8 +61,7 @@ public List<List<IRI>> setNotes(Concept concept, Model model) throws RmesExcepti

}

private void setVersionableNotes(Concept concept, Model model, NotesUtils noteUtils,
List<VersionableNote> versionableNotes, String conceptId, String conceptVersion, List<IRI> notesToDelete,
private void setVersionableNotes(Concept concept, Model model, List<VersionableNote> versionableNotes, String conceptId, String conceptVersion, List<IRI> notesToDelete,
Set<String> versionableNoteTypesInConcept) throws RmesException {
for (VersionableNote versionableNote : versionableNotes) {
versionableNoteTypesInConcept.add(versionableNote.getNoteType());
Expand All @@ -85,7 +88,7 @@ private void setVersionableNotes(Concept concept, Model model, NotesUtils noteUt
}
}

private void setDatableNotes(Concept concept, Model model, NotesUtils noteUtils, List<DatableNote> datableNotes,
private void setDatableNotes(Concept concept, Model model, List<DatableNote> datableNotes,
String conceptId, List<IRI> notesToDelete) throws RmesException {
for (DatableNote datableNote : datableNotes) {
for (ConceptsDatedNoteTypes c : ConceptsDatedNoteTypes.values()) {
Expand All @@ -101,7 +104,7 @@ private void setDatableNotes(Concept concept, Model model, NotesUtils noteUtils,
}
}

private void setVersionableNoteTypes(Concept concept, Model model, NotesUtils noteUtils, String conceptId,
private void setVersionableNoteTypes(Concept concept, Model model, String conceptId,
String conceptVersion, Set<String> versionableNoteTypes) throws RmesException {
for (String noteType : versionableNoteTypes) {
ConceptsVersionnedNoteTypes versionnedNoteType = ConceptsVersionnedNoteTypes.getByName(noteType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.eclipse.rdf4j.model.vocabulary.RDF;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.stereotype.Component;

import fr.insee.rmes.bauhaus_services.rdf_utils.RdfService;
import fr.insee.rmes.bauhaus_services.rdf_utils.RdfUtils;
Expand All @@ -22,6 +23,7 @@
import fr.insee.rmes.persistance.ontologies.XKOS;
import fr.insee.rmes.persistance.sparql_queries.notes.NotesQueries;

@Component
public class NotesUtils extends RdfService {

private static final String ONE = "1";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void publishFamily(String familyId) throws RmesException {
Model model = new LinkedHashModel();
Resource family = RdfUtils.familyIRI(familyId);
//TODO notify...
RepositoryConnection con = PublicationUtils.getRepositoryConnectionGestion();
RepositoryConnection con = repoGestion.getConnection();
RepositoryResult<Statement> statements = repoGestion.getStatements(con, family);

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void publishIndicator(String indicatorId) throws RmesException {
Resource indicator= RdfUtils.objectIRI(ObjectType.INDICATOR,indicatorId);

//TODO notify...
RepositoryConnection con = PublicationUtils.getRepositoryConnectionGestion();
RepositoryConnection con = repoGestion.getConnection();
RepositoryResult<Statement> statements = repoGestion.getStatements(con, indicator);

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void publishOperation(String operationId) throws RmesException {

checkSeriesIsPublished(operationId, operationJson);

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

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void publishSeries(String seriesId) throws RmesException {
"Series: "+seriesId+" ; Family: "+familyId);
}

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

RepositoryResult<Statement> hasPartStatements = repoGestion.getHasPartStatements(con, series);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,12 @@
import java.util.Arrays;

import org.eclipse.rdf4j.model.Resource;
import org.eclipse.rdf4j.repository.RepositoryConnection;
import org.springframework.beans.factory.annotation.Autowired;

import fr.insee.rmes.bauhaus_services.Constants;
import fr.insee.rmes.config.Config;
import fr.insee.rmes.exceptions.RmesException;
import fr.insee.rmes.model.ValidationStatus;

public abstract class PublicationUtils {

@Autowired
static RepositoryUtils repoUtils;

@Autowired
protected static RepositoryGestion repoGestion;

private PublicationUtils() {
throw new IllegalStateException("Utility class");
Expand All @@ -36,7 +27,4 @@ public static boolean isPublished(String status) {
return status.equals(ValidationStatus.UNPUBLISHED.getValue()) || status.equals(Constants.UNDEFINED);
}

public static RepositoryConnection getRepositoryConnectionGestion() throws RmesException {
return repoUtils.getConnection(RepositoryGestion.REPOSITORY_GESTION);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ public void objectsValidation(List<IRI> collectionsToValidateList, Model model)
RepositoryConnection conn = RepositoryGestion.REPOSITORY_GESTION.getConnection();
for (IRI item : collectionsToValidateList) {
conn.remove(item, INSEE.VALIDATION_STATE, null);
conn.remove(item, INSEE.IS_VALIDATED, null);
}
conn.add(model);
conn.close();
Expand All @@ -249,6 +250,7 @@ public void objectValidation(IRI ressourceURI, Model model) throws RmesException
try {
RepositoryConnection conn = RepositoryGestion.REPOSITORY_GESTION.getConnection();
conn.remove(ressourceURI, INSEE.VALIDATION_STATE, null);
conn.remove(ressourceURI, INSEE.IS_VALIDATED, null);
conn.add(model);
conn.close();
} catch (RepositoryException e) {
Expand Down Expand Up @@ -365,4 +367,8 @@ public void loadSimpleObject(IRI geoIRI, Model model) throws RmesException {
loadSimpleObject(geoIRI, model, null);
}

public RepositoryConnection getConnection() throws RmesException {
return getConnection(RepositoryGestion.REPOSITORY_GESTION);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public abstract class RepositoryUtils {
private static final String BINDINGS = "bindings";
private static final String RESULTS = "results";
private static final String EXECUTE_QUERY_FAILED = "Execute query failed : ";

static final Logger logger = LogManager.getLogger(RepositoryUtils.class);


Expand Down
2 changes: 1 addition & 1 deletion src/main/java/fr/insee/rmes/config/ApplicationContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

@Configuration("AppContext")
@PropertySource(value = { "classpath:bauhaus-core.properties", "classpath:bauhaus-dev.properties",
"file:${catalina.base}/webapps/bauhaus-dev.properties", "file:${catalina.base}/webapps/bauhaus-qf.properties",
"file:${catalina.base}/webapps/bauhaus-dev.properties", "file:${catalina.base}/webapps/bauhaus-qf.properties","file:${catalina.base}/webapps/bauhaus-production.properties",
"file:${catalina.base}/webapps/production.properties", }, ignoreResourceNotFound = true)
public class ApplicationContext {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ private Properties getProperties() throws IOException {
props.load(getClass().getClassLoader().getResourceAsStream("bauhaus-dev.properties"));
loadPropertiesIfExist(props, "bauhaus-dev.properties");
loadPropertiesIfExist(props, "bauhaus-qf.properties");
loadPropertiesIfExist(props, "bauhaus-production.properties");
loadPropertiesIfExist(props, "production.properties");
return props;
}
Expand Down
Loading

0 comments on commit 3ff7fa2

Please sign in to comment.