use of mom.trd.opentheso.bdd.datas.HierarchicalRelationship in project opentheso by miledrousset.
the class WriteSkosBDD method writeRelationsList.
public void writeRelationsList(ArrayList<SKOSRelation> relationsList, String idConcept, String idThesaurus, int idUser) {
ConceptHelper conceptHelper = new ConceptHelper();
HierarchicalRelationship hierarchicalRelationship = new HierarchicalRelationship();
for (SKOSRelation relation : relationsList) {
switch(relation.getProperty()) {
case SKOSProperty.related:
hierarchicalRelationship.setIdConcept1(idConcept);
hierarchicalRelationship.setIdConcept2(getId(relation.getTargetUri()));
hierarchicalRelationship.setIdThesaurus(idThesaurus);
hierarchicalRelationship.setRole("RT");
try {
try (Connection conn = ds.getConnection()) {
conn.setAutoCommit(false);
if (!conceptHelper.addLinkHierarchicalRelation(conn, hierarchicalRelationship, idUser)) {
conn.rollback();
conn.close();
}
conn.commit();
conn.close();
}
} catch (SQLException ex) {
Logger.getLogger(WriteSkosBDD.class.getName()).log(Level.SEVERE, null, ex);
}
// query.addRelation(id_terme, "RT", getId(relation.getTargetUri()), id_thesaurus);
break;
case SKOSProperty.narrower:
hierarchicalRelationship.setIdConcept1(idConcept);
hierarchicalRelationship.setIdConcept2(getId(relation.getTargetUri()));
hierarchicalRelationship.setIdThesaurus(idThesaurus);
hierarchicalRelationship.setRole("NT");
try {
try (Connection conn = ds.getConnection()) {
conn.setAutoCommit(false);
if (!conceptHelper.addLinkHierarchicalRelation(conn, hierarchicalRelationship, idUser)) {
conn.rollback();
conn.close();
}
conn.commit();
conn.close();
}
} catch (SQLException ex) {
Logger.getLogger(WriteSkosBDD.class.getName()).log(Level.SEVERE, null, ex);
}
// query.addRelation(id_terme, "NT", getId(relation.getTargetUri()), id_thesaurus);
break;
case SKOSProperty.broader:
hierarchicalRelationship.setIdConcept1(idConcept);
hierarchicalRelationship.setIdConcept2(getId(relation.getTargetUri()));
hierarchicalRelationship.setIdThesaurus(idThesaurus);
hierarchicalRelationship.setRole("BT");
try {
try (Connection conn = ds.getConnection()) {
conn.setAutoCommit(false);
if (!conceptHelper.addLinkHierarchicalRelation(conn, hierarchicalRelationship, idUser)) {
conn.rollback();
conn.close();
}
conn.commit();
conn.close();
}
} catch (SQLException ex) {
Logger.getLogger(WriteSkosBDD.class.getName()).log(Level.SEVERE, null, ex);
}
// query.addRelation(id_terme, "BT", getId(relation.getTargetUri()), id_thesaurus);
break;
default:
break;
}
}
}
use of mom.trd.opentheso.bdd.datas.HierarchicalRelationship in project opentheso by miledrousset.
the class ImportRdf4jHelper method addRelationNoBTHiera.
private void addRelationNoBTHiera(AddConceptsStruct acs) {
HierarchicalRelationship hierarchicalRelationship;
int prop;
String idConcept2;
for (SKOSRelation relation : acs.conceptResource.getRelationsList()) {
prop = relation.getProperty();
hierarchicalRelationship = new HierarchicalRelationship();
String role;
switch(prop) {
case SKOSProperty.narrower:
role = "NT";
break;
case SKOSProperty.narrowerGeneric:
role = "NTG";
break;
case SKOSProperty.narrowerPartitive:
role = "NTP";
break;
case SKOSProperty.narrowerInstantive:
role = "NTI";
break;
case SKOSProperty.related:
role = "RT";
break;
case SKOSProperty.relatedHasPart:
role = "RHP";
break;
case SKOSProperty.relatedPartOf:
role = "RPO";
break;
default:
role = "";
}
if (!role.equals("")) {
hierarchicalRelationship.setIdConcept1(acs.concept.getIdConcept());
// option cochée
// if(identifierType.equalsIgnoreCase("sans")){
// idConcept2 = getIdFromUri(relation.getTargetUri());
// } else {
// Récupération des Id Ark ou Handle
idConcept2 = getOriginalId(relation.getTargetUri());
// }
hierarchicalRelationship.setIdConcept2(idConcept2);
hierarchicalRelationship.setIdThesaurus(idTheso);
hierarchicalRelationship.setRole(role);
acs.hierarchicalRelationships.add(hierarchicalRelationship);
} else if (prop == SKOSProperty.inScheme) {
// ?
/*} else if (prop == SKOSProperty.memberOf) {
acs.idGrps.add(getIdFromUri(relation.getTargetUri()));
//addIdGroupToVector(uri); ????
*/
} else if (prop == SKOSProperty.topConceptOf) {
acs.isTopConcept = true;
}
if (hasTopConcceptList.contains(acs.conceptResource.getUri())) {
acs.isTopConcept = true;
}
String idConcept = acs.conceptResource.getUri();
String idPere = memberHashMap.get(idConcept);
if (idPere != null) {
acs.idGrps.add(idPere);
memberHashMap.remove(idConcept);
}
}
}
use of mom.trd.opentheso.bdd.datas.HierarchicalRelationship in project opentheso by miledrousset.
the class ImportRdf4jHelper method addBranch.
/**
* ajoute une brache en choisissant un concept père
*
* @param selectedTerme
* @throws java.text.ParseException
* @throws java.sql.SQLException
*/
public void addBranch(SelectedTerme selectedTerme) throws ParseException, SQLException {
String idGroup = selectedTerme.getIdDomaine();
String idConceptPere = selectedTerme.getIdC();
idTheso = selectedTerme.getIdTheso();
SKOSResource root = detectRootOfBranch();
// on ajoute la racine de la branche
AddConceptsStruct acs;
acs = new AddConceptsStruct();
acs.conceptHelper = new ConceptHelper();
initAddConceptsStruct(acs, root);
addRelationNoBTHiera(acs);
acs.concept.setTopConcept(false);
acs.concept.setIdGroup(idGroup);
acs.conceptHelper.insertConceptInTable(ds, acs.concept, idUser);
// on lie le nouveau concept au concept père
HierarchicalRelationship hierarchicalRelationship1 = new HierarchicalRelationship(acs.concept.getIdConcept(), idConceptPere, idTheso, "BT");
HierarchicalRelationship hierarchicalRelationship2 = new HierarchicalRelationship(idConceptPere, acs.concept.getIdConcept(), idTheso, "NT");
acs.hierarchicalRelationships.add(hierarchicalRelationship1);
acs.hierarchicalRelationships.add(hierarchicalRelationship2);
new GroupHelper().addConceptGroupConcept(ds, idGroup, acs.concept.getIdConcept(), acs.concept.getIdThesaurus());
finalizeAddConceptStruct(acs);
// on ajoute le reste
skosXmlDocument.getConceptList().remove(root);
for (SKOSResource resource : skosXmlDocument.getConceptList()) {
acs = new AddConceptsStruct();
acs.conceptHelper = new ConceptHelper();
initAddConceptsStruct(acs, resource);
addRelation(acs);
acs.concept.setTopConcept(false);
acs.concept.setIdGroup(idGroup);
acs.conceptHelper.insertConceptInTable(ds, acs.concept, idUser);
new GroupHelper().addConceptGroupConcept(ds, idGroup, acs.concept.getIdConcept(), acs.concept.getIdThesaurus());
finalizeAddConceptStruct(acs);
}
}
use of mom.trd.opentheso.bdd.datas.HierarchicalRelationship in project opentheso by miledrousset.
the class ImportRdf4jHelper method addSingleConcept.
/**
* ajoute un seul concept en choisissant un concept père
*
* @param selectedTerme
* @throws java.sql.SQLException
* @throws java.text.ParseException
*/
public void addSingleConcept(SelectedTerme selectedTerme) throws SQLException, ParseException {
String idGroup = selectedTerme.getIdDomaine();
String idConceptPere = selectedTerme.getIdC();
idTheso = selectedTerme.getIdTheso();
AddConceptsStruct acs = new AddConceptsStruct();
acs.conceptHelper = new ConceptHelper();
// addConcepts
if (skosXmlDocument.getConceptList().size() == 1) {
initAddConceptsStruct(acs, skosXmlDocument.getConceptList().get(0));
addRelationNoBTHiera(acs);
acs.concept.setTopConcept(false);
acs.concept.setIdGroup(idGroup);
acs.conceptHelper.insertConceptInTable(ds, acs.concept, idUser);
// on lie le nouveau concept au concept père
HierarchicalRelationship hierarchicalRelationship1 = new HierarchicalRelationship(acs.concept.getIdConcept(), idConceptPere, idTheso, "BT");
HierarchicalRelationship hierarchicalRelationship2 = new HierarchicalRelationship(idConceptPere, acs.concept.getIdConcept(), idTheso, "NT");
acs.hierarchicalRelationships.add(hierarchicalRelationship1);
acs.hierarchicalRelationships.add(hierarchicalRelationship2);
new GroupHelper().addConceptGroupConcept(ds, idGroup, acs.concept.getIdConcept(), acs.concept.getIdThesaurus());
finalizeAddConceptStruct(acs);
} else {
// erreur il y a plus d'un concept
}
}
use of mom.trd.opentheso.bdd.datas.HierarchicalRelationship in project opentheso by miledrousset.
the class ToolsHelper method removeLoopRelations.
/**
* Permet de supprimer les relations en boucle qui sont interdites
* (100 -> BT -> 100) ou (100 -> NT -> 100)ou (100 -> RT -> 100)
* c'est incohérent et ca provoque une boucle à l'infini
* @param ds
* @param role
* @param idThesaurus
* @return
*/
public boolean removeLoopRelations(HikariDataSource ds, String role, String idThesaurus) {
RelationsHelper relationsHelper = new RelationsHelper();
// récupération des relations en Loop
ArrayList<HierarchicalRelationship> tabRelations = relationsHelper.getListLoopRelations(ds, role, idThesaurus);
if (!tabRelations.isEmpty()) {
for (HierarchicalRelationship relation : tabRelations) {
relationsHelper.deleteThisRelation(ds, relation.getIdConcept1(), idThesaurus, role, relation.getIdConcept2());
}
}
return true;
}
Aggregations