use of mom.trd.opentheso.bdd.datas.HierarchicalRelationship in project opentheso by miledrousset.
the class ImportTabuleIntoBDD method writeRelationsList.
private boolean writeRelationsList(HikariDataSource ds, TabulateDocument tabulateDocument, String idThesaurus, int idUser) {
ConceptHelper conceptHelper = new ConceptHelper();
HierarchicalRelationship hierarchicalRelationship = new HierarchicalRelationship();
for (String broader : tabulateDocument.getBroader()) {
hierarchicalRelationship.setIdConcept1(tabulateDocument.getId());
hierarchicalRelationship.setIdConcept2(broader);
hierarchicalRelationship.setIdThesaurus(idThesaurus);
hierarchicalRelationship.setRole("BT");
try {
Connection conn = ds.getConnection();
conn.setAutoCommit(false);
if (!conceptHelper.addLinkHierarchicalRelation(conn, hierarchicalRelationship, idUser)) {
conn.rollback();
conn.close();
return false;
}
conn.commit();
conn.close();
} catch (SQLException ex) {
Logger.getLogger(ImportTabuleIntoBDD.class.getName()).log(Level.SEVERE, null, ex);
}
}
for (String narrower : tabulateDocument.getNarrower()) {
hierarchicalRelationship.setIdConcept1(tabulateDocument.getId());
hierarchicalRelationship.setIdConcept2(narrower);
hierarchicalRelationship.setIdThesaurus(idThesaurus);
hierarchicalRelationship.setRole("NT");
try {
Connection conn = ds.getConnection();
conn.setAutoCommit(false);
if (!conceptHelper.addLinkHierarchicalRelation(conn, hierarchicalRelationship, idUser)) {
conn.rollback();
conn.close();
return false;
}
conn.commit();
conn.close();
} catch (SQLException ex) {
Logger.getLogger(ImportTabuleIntoBDD.class.getName()).log(Level.SEVERE, null, ex);
}
}
for (String related : tabulateDocument.getRelated()) {
hierarchicalRelationship.setIdConcept1(tabulateDocument.getId());
hierarchicalRelationship.setIdConcept2(related);
hierarchicalRelationship.setIdThesaurus(idThesaurus);
hierarchicalRelationship.setRole("RT");
try {
Connection conn = ds.getConnection();
conn.setAutoCommit(false);
if (conceptHelper.addLinkHierarchicalRelation(conn, hierarchicalRelationship, idUser)) {
conn.rollback();
conn.close();
return false;
}
conn.commit();
conn.close();
} catch (SQLException ex) {
Logger.getLogger(ImportTabuleIntoBDD.class.getName()).log(Level.SEVERE, null, ex);
}
}
return true;
}
use of mom.trd.opentheso.bdd.datas.HierarchicalRelationship in project opentheso by miledrousset.
the class ConceptHelper method addConcept.
/**
* Cette fonction permet d'ajouter un Concept complet à la base avec le
* libellé et les relations Si l'opération échoue, elle envoi un NULL et ne
* modifie pas la base de données
*
* @param ds
* @param idParent
* @param concept
* @param term
* @param idUser
* @return null si le term existe ou si erreur, sinon le numero de Concept
*/
public String addConcept(HikariDataSource ds, String idParent, Concept concept, Term term, int idUser) {
Connection conn = null;
try {
conn = ds.getConnection();
conn.setAutoCommit(false);
TermHelper termHelper = new TermHelper();
// controle si le term existe avant de rajouter un concept
/*if (termHelper.isTermExist(ds, term.getLexical_value(),
term.getId_thesaurus(), term.getLang())) {
conn.close();
return null;
}*/
concept.setTopConcept(false);
String idConcept = addConceptInTable(conn, concept, idUser);
new GroupHelper().addConceptGroupConcept(ds, concept.getIdGroup(), concept.getIdConcept(), concept.getIdThesaurus());
if (idConcept == null) {
conn.rollback();
conn.close();
return null;
}
String idTerm = termHelper.addTerm(conn, term, idConcept, idUser);
if (idTerm == null) {
conn.rollback();
conn.close();
return null;
}
term.setId_term(idTerm);
/**
* ajouter le lien hiérarchique
*/
HierarchicalRelationship hierarchicalRelationship = new HierarchicalRelationship();
hierarchicalRelationship.setIdConcept1(idParent);
hierarchicalRelationship.setIdConcept2(idConcept);
hierarchicalRelationship.setIdThesaurus(concept.getIdThesaurus());
hierarchicalRelationship.setRole("NT");
if (!addLinkHierarchicalRelation(conn, hierarchicalRelationship, idUser)) {
conn.rollback();
conn.close();
return null;
}
hierarchicalRelationship.setIdConcept1(idConcept);
hierarchicalRelationship.setIdConcept2(idParent);
hierarchicalRelationship.setIdThesaurus(concept.getIdThesaurus());
hierarchicalRelationship.setRole("BT");
if (!addLinkHierarchicalRelation(conn, hierarchicalRelationship, idUser)) {
conn.rollback();
conn.close();
return null;
}
/* termHelper.splitConceptForPermute(ds, idConcept,
getGroupIdOfConcept(ds, idConcept, term.getId_thesaurus()),
term.getId_thesaurus(),
term.getLang(),
term.getLexical_value());*/
if (nodePreference != null) {
// alors c'est le moment de récupérer le code ARK
if (nodePreference.isUseArk()) {
NodeMetaData nodeMetaData = new NodeMetaData();
nodeMetaData.setCreator(term.getSource());
nodeMetaData.setTitle(term.getLexical_value());
nodeMetaData.setDcElementsList(new ArrayList<>());
if (!addIdArk(conn, idConcept, concept.getIdThesaurus(), nodeMetaData)) {
conn.rollback();
conn.close();
Logger.getLogger(ConceptHelper.class.getName()).log(Level.SEVERE, null, "La création Ark a échouée");
return null;
}
}
// création de l'identifiant Handle
if (nodePreference.isUseHandle()) {
if (!addIdHandle(conn, idConcept, concept.getIdThesaurus())) {
conn.rollback();
conn.close();
Logger.getLogger(ConceptHelper.class.getName()).log(Level.SEVERE, null, "La création Handle a échouée");
return null;
}
}
}
conn.commit();
conn.close();
return idConcept;
} catch (SQLException ex) {
try {
Logger.getLogger(ConceptHelper.class.getName()).log(Level.SEVERE, null, ex);
if (conn != null) {
conn.close();
}
} catch (SQLException ex1) {
}
}
return null;
}
use of mom.trd.opentheso.bdd.datas.HierarchicalRelationship in project opentheso by miledrousset.
the class SelectedTerme method creerTermeAsso.
/**
* Ajoute une relation terme associé au concept courant
*
* @param idC2 le concept associé
*/
public void creerTermeAsso(String idC2) {
HierarchicalRelationship hr = new HierarchicalRelationship();
hr.setIdConcept1(idC);
hr.setIdConcept2(idC2);
hr.setIdThesaurus(idTheso);
hr.setRole("RT");
new ConceptHelper().addAssociativeRelation(connect.getPoolConnexion(), hr, user.getUser().getId());
ArrayList<NodeRT> tempRT = new RelationsHelper().getListRT(connect.getPoolConnexion(), idC, idTheso, idlangue);
termesAssocies = new ArrayList<>();
HashMap<String, String> tempMap = new HashMap<>();
for (NodeRT nrt : tempRT) {
tempMap.put(nrt.getIdConcept(), nrt.getTitle() + " (" + nrt.getRole() + ")");
}
termesAssocies.addAll(tempMap.entrySet());
vue.setAddTAsso(0);
}
use of mom.trd.opentheso.bdd.datas.HierarchicalRelationship in project opentheso by miledrousset.
the class ConceptHelper method addConceptSpecial.
/**
* Cette fonction permet d'ajouter un Concept et de choisir le type de
* relation complet à la base avec le libellé et les relations Si
* l'opération échoue, elle envoi un NULL et ne modifie pas la base de
* données
*
* @param ds
* @param idParent
* @param concept
* @param term
* @param BTname
* @param NTname
* @param idUser
* @return null si le term existe ou si erreur, sinon le numero de Concept
*/
public String addConceptSpecial(HikariDataSource ds, String idParent, Concept concept, Term term, String BTname, String NTname, int idUser) {
Connection conn = null;
try {
conn = ds.getConnection();
conn.setAutoCommit(false);
TermHelper termHelper = new TermHelper();
// controle si le term existe avant de rajouter un concept
/*if (termHelper.isTermExist(ds, term.getLexical_value(),
term.getId_thesaurus(), term.getLang())) {
conn.close();
return null;
}*/
concept.setTopConcept(false);
String idConcept = addConceptInTable(conn, concept, idUser);
new GroupHelper().addConceptGroupConcept(ds, concept.getIdGroup(), concept.getIdConcept(), concept.getIdThesaurus());
if (idConcept == null) {
conn.rollback();
conn.close();
return null;
}
String idTerm = termHelper.addTerm(conn, term, idConcept, idUser);
if (idTerm == null) {
conn.rollback();
conn.close();
return null;
}
term.setId_term(idTerm);
/**
* ajouter le lien hiérarchique
*/
HierarchicalRelationship hierarchicalRelationship = new HierarchicalRelationship();
hierarchicalRelationship.setIdConcept1(idParent);
hierarchicalRelationship.setIdConcept2(idConcept);
hierarchicalRelationship.setIdThesaurus(concept.getIdThesaurus());
hierarchicalRelationship.setRole(NTname);
if (!addLinkHierarchicalRelation(conn, hierarchicalRelationship, idUser)) {
conn.rollback();
conn.close();
return null;
}
hierarchicalRelationship.setIdConcept1(idConcept);
hierarchicalRelationship.setIdConcept2(idParent);
hierarchicalRelationship.setIdThesaurus(concept.getIdThesaurus());
hierarchicalRelationship.setRole(BTname);
if (!addLinkHierarchicalRelation(conn, hierarchicalRelationship, idUser)) {
conn.rollback();
conn.close();
return null;
}
// alors c'est le moment de récupérer le code ARK
if (nodePreference != null) {
// alors c'est le moment de récupérer le code ARK
if (nodePreference.isUseArk()) {
NodeMetaData nodeMetaData = new NodeMetaData();
nodeMetaData.setCreator(term.getSource());
nodeMetaData.setTitle(term.getLexical_value());
nodeMetaData.setDcElementsList(new ArrayList<>());
if (!addIdArk(conn, idConcept, concept.getIdThesaurus(), nodeMetaData)) {
conn.rollback();
conn.close();
Logger.getLogger(ConceptHelper.class.getName()).log(Level.SEVERE, null, "La création Ark a échouée");
return null;
}
}
// création de l'identifiant Handle
if (nodePreference.isUseHandle()) {
if (!addIdHandle(conn, idConcept, concept.getIdThesaurus())) {
conn.rollback();
conn.close();
Logger.getLogger(ConceptHelper.class.getName()).log(Level.SEVERE, null, "La création Handle a échouée");
return null;
}
}
}
conn.commit();
conn.close();
return idConcept;
} catch (SQLException ex) {
try {
Logger.getLogger(ConceptHelper.class.getName()).log(Level.SEVERE, null, ex);
if (conn != null) {
conn.close();
}
} catch (SQLException ex1) {
}
}
return null;
}
use of mom.trd.opentheso.bdd.datas.HierarchicalRelationship in project opentheso by miledrousset.
the class RelationsHelper method getListLoopRelations.
/**
* Cette fonction permet de récupérer la liste des relations qui sont en boucle
* pour une relation donnée (NT, BT, RT)
*
* @param ds
* @param role
* @param idThesaurus
* @return
* #MR
*/
public ArrayList<HierarchicalRelationship> getListLoopRelations(HikariDataSource ds, String role, String idThesaurus) {
Connection conn;
Statement stmt;
ResultSet resultSet;
ArrayList<HierarchicalRelationship> listRelations = new ArrayList<>();
try {
// Get connection from pool
conn = ds.getConnection();
try {
stmt = conn.createStatement();
try {
String query = "select * from hierarchical_relationship" + " where id_concept1 = id_concept2" + " and id_thesaurus = '" + idThesaurus + "'" + " and role = '" + role + "'";
stmt.executeQuery(query);
resultSet = stmt.getResultSet();
while (resultSet.next()) {
HierarchicalRelationship hierarchicalRelationship = new HierarchicalRelationship();
hierarchicalRelationship.setIdConcept1(resultSet.getString("id_concept1"));
hierarchicalRelationship.setIdConcept2(resultSet.getString("id_concept2"));
hierarchicalRelationship.setIdThesaurus(idThesaurus);
hierarchicalRelationship.setRole(role);
listRelations.add(hierarchicalRelationship);
}
} finally {
stmt.close();
}
} finally {
conn.close();
}
} catch (SQLException sqle) {
// Log exception
log.error("Error while getting List of Loop relations of thesaurus : " + idThesaurus, sqle);
}
return listRelations;
}
Aggregations