use of mom.trd.opentheso.bdd.helper.nodes.concept.NodeConceptTree in project opentheso by miledrousset.
the class ConceptHelper method getListConcepts.
/**
* Cette fonction permet de récupérer la liste des concepts suivant l'id du
* Concept-Père et le thésaurus sous forme de classe NodeConceptTree (sans
* les relations)
*
* @param ds
* @param idConcept
* @param idThesaurus
* @param idLang
* @return Objet class NodeConceptTree
*/
/*public ArrayList<NodeConceptTree> getListConcepts(HikariDataSource ds,
String idConcept, String idThesaurus, String idLang) {
Connection conn;
Statement stmt;
ResultSet resultSet;
ArrayList<NodeConceptTree> nodeConceptTree = null;
try {
// Get connection from pool
conn = ds.getConnection();
try {
stmt = conn.createStatement();
try {
String query = "SELECT DISTINCT term.lexical_value, term.lang,"
+ " term.id_thesaurus, preferred_term.id_concept, concept.status"
+ " FROM term,preferred_term,concept,hierarchical_relationship"
+ " WHERE preferred_term.id_term = term.id_term AND"
+ " preferred_term.id_thesaurus = term.id_thesaurus AND"
+ " concept.id_concept = preferred_term.id_concept AND"
+ " concept.id_thesaurus = preferred_term.id_thesaurus AND"
+ " hierarchical_relationship.id_concept2 = concept.id_concept"
+ " and concept.id_thesaurus = '" + idThesaurus + "'"
+ " and hierarchical_relationship.role = 'NT'"
+ " and hierarchical_relationship.id_concept1 = '" + idConcept + "'"
+ " and term.lang = '" + idLang + "'";
//" ORDER BY unaccent_string(term.lexical_value) ASC;";
stmt.executeQuery(query);
resultSet = stmt.getResultSet();
if (resultSet != null) {
nodeConceptTree = new ArrayList<>();
while (resultSet.next()) {
NodeConceptTree nodeConceptTree1 = new NodeConceptTree();
nodeConceptTree1.setIdConcept(resultSet.getString("id_concept"));
nodeConceptTree1.setStatusConcept(resultSet.getString("status"));
nodeConceptTree1.setIdThesaurus(idThesaurus);
nodeConceptTree1.setIdLang(idLang);
if (resultSet.getString("lexical_value").trim().equals("")) {
nodeConceptTree1.setTitle("");
} else {
nodeConceptTree1.setTitle(resultSet.getString("lexical_value").trim());
}
nodeConceptTree1.setHaveChildren(
haveChildren(ds, idThesaurus, nodeConceptTree1.getIdConcept()));
nodeConceptTree.add(nodeConceptTree1);
}
}
} finally {
stmt.close();
}
} finally {
conn.close();
}
} catch (SQLException sqle) {
// Log exception
log.error("Error while getting ListConcept of Concept : " + idConcept, sqle);
}
Collections.sort(nodeConceptTree);
return nodeConceptTree;
}*/
public ArrayList<NodeConceptTree> getListConcepts(HikariDataSource ds, String idConcept, String idThesaurus, String idLang) {
Connection conn;
Statement stmt;
ResultSet resultSet;
ArrayList<NodeConceptTree> nodeConceptTree = null;
try {
// Get connection from pool
conn = ds.getConnection();
try {
stmt = conn.createStatement();
try {
String query = "select id_concept2 from hierarchical_relationship" + " where id_thesaurus = '" + idThesaurus + "'" + " and id_concept1 = '" + idConcept + "'" + " and role LIKE 'NT%'";
stmt.executeQuery(query);
resultSet = stmt.getResultSet();
if (resultSet != null) {
nodeConceptTree = new ArrayList<>();
while (resultSet.next()) {
NodeConceptTree nodeConceptTree1 = new NodeConceptTree();
nodeConceptTree1.setIdConcept(resultSet.getString("id_concept2"));
nodeConceptTree1.setIdThesaurus(idThesaurus);
nodeConceptTree1.setIdLang(idLang);
nodeConceptTree1.setIsTerm(true);
nodeConceptTree.add(nodeConceptTree1);
}
}
for (NodeConceptTree nodeConceptTree1 : nodeConceptTree) {
/* désactivé, ne marche pas pour les termes dépréciés
query = "SELECT term.lexical_value, term.status FROM term, preferred_term"
+ " WHERE preferred_term.id_term = term.id_term"
+ " and preferred_term.id_concept ='"
+ nodeConceptTree1.getIdConcept() + "'"
+ " and term.lang = '" + idLang + "'"
+ " and term.id_thesaurus = '" + idThesaurus + "'";
*/
query = "SELECT term.lexical_value, concept.status" + " FROM concept, preferred_term, term" + " WHERE concept.id_concept = preferred_term.id_concept AND" + " concept.id_thesaurus = preferred_term.id_thesaurus AND" + " preferred_term.id_term = term.id_term AND" + " preferred_term.id_thesaurus = term.id_thesaurus AND" + " concept.id_concept = '" + nodeConceptTree1.getIdConcept() + "' AND" + " term.lang = '" + idLang + "' AND" + " term.id_thesaurus = '" + idThesaurus + "';";
stmt.executeQuery(query);
resultSet = stmt.getResultSet();
if (resultSet != null) {
resultSet.next();
if (resultSet.getRow() == 0) {
nodeConceptTree1.setTitle("");
nodeConceptTree1.setStatusConcept("");
} else {
nodeConceptTree1.setTitle(resultSet.getString("lexical_value"));
if (resultSet.getString("status") == null) {
nodeConceptTree1.setStatusConcept("");
} else {
nodeConceptTree1.setStatusConcept(resultSet.getString("status"));
}
}
nodeConceptTree1.setHaveChildren(haveChildren(ds, idThesaurus, nodeConceptTree1.getIdConcept()));
}
}
} finally {
stmt.close();
}
} finally {
conn.close();
}
} catch (SQLException sqle) {
// Log exception
log.error("Error while getting ListConcept of Concept : " + idConcept, sqle);
}
Collections.sort(nodeConceptTree);
return nodeConceptTree;
}
use of mom.trd.opentheso.bdd.helper.nodes.concept.NodeConceptTree in project opentheso by miledrousset.
the class SelectedTerme method creerTermeSpe.
/**
* *************************************** CREATION
* ****************************************
*/
/**
* Crée un nouveau terme spécifique au terme sélectionné
*
* @param selecedTerm
* @return true or false
*/
public boolean creerTermeSpe(MyTreeNode selecedTerm) {
ConceptHelper instance = new ConceptHelper();
if (user.nodePreference == null)
return false;
instance.setNodePreference(user.getNodePreference());
// 1 = domaine/Group, 2 = TT (top Term), 3 = Concept/term
if (selecedTerm.isIsSubGroup() || selecedTerm.isIsGroup()) {
// ici c'est le cas d'un Group ou Sous Group, on crée un TT Top Terme
Concept concept = new Concept();
concept.setIdGroup(selecedTerm.getIdConcept());
concept.setIdThesaurus(idTheso);
concept.setStatus("D");
concept.setNotation("");
Term terme = new Term();
terme.setId_thesaurus(idTheso);
terme.setLang(idlangue);
terme.setLexical_value(valueEdit);
terme.setSource("");
terme.setStatus("");
if (instance.addTopConcept(connect.getPoolConnexion(), idTheso, concept, terme, user.getUser().getId()) == null) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", instance.getMessage()));
return false;
}
// instance.insertID_grouptoPermuted(connect.getPoolConnexion(), concept.getIdThesaurus(), concept.getIdConcept());
ConceptHelper ch = new ConceptHelper();
ArrayList<NodeConceptTree> tempNT = ch.getListTopConcepts(connect.getPoolConnexion(), idC, idTheso, idlangue);
termesSpecifique = new ArrayList<>();
HashMap<String, String> tempMap = new HashMap<>();
for (NodeConceptTree nct : tempNT) {
tempMap.put(nct.getIdConcept(), nct.getTitle());
}
termesSpecifique.addAll(tempMap.entrySet());
} else {
Concept concept = new Concept();
concept.setIdGroup(selecedTerm.getIdCurrentGroup());
concept.setIdThesaurus(idTheso);
concept.setStatus("D");
concept.setNotation("");
Term terme = new Term();
terme.setId_thesaurus(idTheso);
terme.setLang(idlangue);
terme.setLexical_value(valueEdit);
terme.setSource("");
terme.setStatus("");
// String idTC = idTopConcept;
String idP = idC;
if (instance.addConcept(connect.getPoolConnexion(), idP, concept, terme, user.getUser().getId()) == null) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", instance.getMessage()));
return false;
}
// instance.insertID_grouptoPermuted(connect.getPoolConnexion(), concept.getIdThesaurus(), concept.getIdConcept());
concept.getUserName();
ArrayList<NodeNT> tempNT = new RelationsHelper().getListNT(connect.getPoolConnexion(), idC, idTheso, idlangue);
termesSpecifique = new ArrayList<>();
HashMap<String, String> tempMap = new HashMap<>();
for (NodeNT nnt : tempNT) {
tempMap.put(nnt.getIdConcept(), nnt.getTitle() + " (" + nnt.getRole() + ")");
}
termesSpecifique.addAll(tempMap.entrySet());
}
vue.setAddTSpe(false);
valueEdit = "";
return true;
}
use of mom.trd.opentheso.bdd.helper.nodes.concept.NodeConceptTree in project opentheso by miledrousset.
the class SelectedTerme method initTree.
/**
* Récupère les concept pour remplir la racine de l'arbre des facette
*/
public void initTree() {
List<Integer> idFacettes = new FacetHelper().getIdFacetOfConcept(connect.getPoolConnexion(), idC, idTheso);
ArrayList<NodeConceptTree> racineNode = new ArrayList<>();
for (Integer i : idFacettes) {
racineNode.add(new FacetHelper().getConceptOnFacet(connect.getPoolConnexion(), i, idTheso, idlangue));
}
for (NodeConceptTree n : racineNode) {
TreeNode dynamicTreeNode;
if (n.getTitle().trim().isEmpty()) {
dynamicTreeNode = (TreeNode) new MyTreeNode(1, n.getIdConcept(), idTheso, idlangue, "", "", "", "dossier", n.getIdConcept(), root);
} else {
dynamicTreeNode = (TreeNode) new MyTreeNode(1, n.getIdConcept(), idTheso, idlangue, "", "", "", "dossier", n.getTitle(), root);
}
DefaultTreeNode defaultTreeNode = new DefaultTreeNode("fake", dynamicTreeNode);
defaultTreeNode.setExpanded(true);
}
}
use of mom.trd.opentheso.bdd.helper.nodes.concept.NodeConceptTree in project opentheso by miledrousset.
the class NewTreeBean method reExpandChild.
private void reExpandChild(ArrayList<String> listeId, TreeNode node, int cpt) {
if (!node.isExpanded()) {
ArrayList<NodeConceptTree> listeConcept;
ArrayList<NodeConceptTree> listeSubGroup = new ArrayList<>();
ArrayList<String> idGroupList;
ConceptHelper conceptHelper = new ConceptHelper();
GroupHelper groupHelper = new GroupHelper();
int type = 3;
if (node.getChildCount() == 1) {
node.getChildren().remove(0);
}
MyTreeNode myTreeNode = (MyTreeNode) node;
String idConcept = myTreeNode.getIdConcept();
if (groupHelper.isIdOfGroup(connect.getPoolConnexion(), idConcept, myTreeNode.getIdTheso())) {
// pour group ?
myTreeNode.setTypeConcept(1);
myTreeNode.setIsGroup(true);
listeSubGroup = groupHelper.getRelationGroupOf(connect.getPoolConnexion(), idConcept, myTreeNode.getIdTheso(), myTreeNode.getLangue());
if (listeSubGroup == null) {
listeSubGroup = new ArrayList<>();
}
// pour récupérer les concepts mélangés avec les Sous_Groupes
listeConcept = conceptHelper.getListTopConcepts(connect.getPoolConnexion(), idConcept, myTreeNode.getIdTheso(), myTreeNode.getLangue(), isSortByNotation);
} else {
listeConcept = conceptHelper.getListConcepts(connect.getPoolConnexion(), idConcept, myTreeNode.getIdTheso(), myTreeNode.getLangue(), isSortByNotation);
// myTreeNode.setIsTopConcept(true);
}
TreeNode treeNode = null;
String value = "";
String idTC = "";
String icon;
boolean isTopTerm;
/**
* Ajout des Groupes (MT, C, G, T ..)
*/
for (NodeConceptTree nodeConceptTreeGroup : listeSubGroup) {
value = nodeConceptTreeGroup.getTitle();
if (groupHelper.isHaveSubGroup(connect.getPoolConnexion(), nodeConceptTreeGroup.getIdThesaurus(), nodeConceptTreeGroup.getIdConcept()) || nodeConceptTreeGroup.isHaveChildren()) {
icon = getTypeOfSubGroup(myTreeNode.getTypeDomaine());
treeNode = new MyTreeNode(1, nodeConceptTreeGroup.getIdConcept(), myTreeNode.getIdTheso(), myTreeNode.getLangue(), myTreeNode.getIdCurrentGroup(), myTreeNode.getTypeDomaine(), idTC, icon, value, myTreeNode);
((MyTreeNode) treeNode).setIsSubGroup(true);
((MyTreeNode) treeNode).setIdCurrentGroup(nodeConceptTreeGroup.getIdConcept());
new DefaultTreeNode("fake", treeNode);
if (listeId.contains(((MyTreeNode) treeNode).getIdConcept())) {
((MyTreeNode) treeNode).setExpanded(true);
}
if (listeId.get(cpt).equals(((MyTreeNode) treeNode).getIdConcept())) {
if (cpt + 1 < listeId.size()) {
treeNode.setSelected(false);
reExpandChild(listeId, treeNode, cpt + 1);
} else {
treeNode.setSelected(true);
selectedNode = treeNode;
selectedNodes.add(treeNode);
}
}
}
}
// Ajout dans l'arbre
for (NodeConceptTree nodeConceptTree : listeConcept) {
isTopTerm = false;
if (conceptHelper.haveChildren(connect.getPoolConnexion(), nodeConceptTree.getIdThesaurus(), nodeConceptTree.getIdConcept()) || nodeConceptTree.isHaveChildren()) {
icon = "dossier";
if (nodeConceptTree.isIsGroup()) {
icon = "domaine";
// String type = getTypeOfGroup(typeCode);
} else if (nodeConceptTree.isIsSubGroup()) {
icon = getTypeOfSubGroup(myTreeNode.getTypeDomaine());
}
if (nodeConceptTree.isIsTopTerm()) {
// Création de topConcepts
if (nodeConceptTree.getTitle().trim().isEmpty()) {
value = nodeConceptTree.getIdConcept();
} else {
value = nodeConceptTree.getTitle();
}
idTC = value;
isTopTerm = true;
} else {
// Création de concepts
idTC = ((MyTreeNode) node).getIdTopConcept();
if (nodeConceptTree.getTitle().trim().isEmpty()) {
value = nodeConceptTree.getIdConcept();
} else {
value = nodeConceptTree.getTitle();
}
}
if (nodeConceptTree.getStatusConcept() != null) {
if (nodeConceptTree.getStatusConcept().equals("hidden")) {
icon = "hidden";
}
}
treeNode = new MyTreeNode(type, nodeConceptTree.getIdConcept(), ((MyTreeNode) node).getIdTheso(), ((MyTreeNode) node).getLangue(), ((MyTreeNode) node).getIdCurrentGroup(), ((MyTreeNode) node).getTypeDomaine(), idTC, icon, value, node);
if (isTopTerm) {
((MyTreeNode) treeNode).setIsTopConcept(true);
}
idGroupList = groupHelper.getListIdGroupOfConcept(connect.getPoolConnexion(), nodeConceptTree.getIdThesaurus(), nodeConceptTree.getIdConcept());
((MyTreeNode) treeNode).setOtherGroup(idGroupList);
new DefaultTreeNode("fake", treeNode);
if (listeId.get(cpt).equals(((MyTreeNode) treeNode).getIdConcept())) {
if (cpt + 1 < listeId.size()) {
treeNode.setSelected(false);
reExpandChild(listeId, treeNode, cpt + 1);
} else {
treeNode.setSelected(true);
selectedNode = treeNode;
selectedNodes.add(treeNode);
}
}
} else {
icon = "fichier";
if (nodeConceptTree.isIsTopTerm()) {
// Création de topConcepts
idTC = nodeConceptTree.getIdConcept();
if (nodeConceptTree.getTitle().trim().isEmpty()) {
value = nodeConceptTree.getIdConcept();
} else {
value = nodeConceptTree.getTitle();
}
isTopTerm = true;
} else {
// Création de concepts
idTC = ((MyTreeNode) node).getIdTopConcept();
if (nodeConceptTree.getTitle().trim().isEmpty()) {
value = nodeConceptTree.getIdConcept();
} else {
value = nodeConceptTree.getTitle();
}
}
if (nodeConceptTree.getStatusConcept().equals("hidden")) {
icon = "hidden";
}
treeNode = new MyTreeNode(type, nodeConceptTree.getIdConcept(), ((MyTreeNode) node).getIdTheso(), ((MyTreeNode) node).getLangue(), ((MyTreeNode) node).getIdCurrentGroup(), ((MyTreeNode) node).getTypeDomaine(), idTC, icon, value, node);
if (isTopTerm) {
((MyTreeNode) treeNode).setIsTopConcept(true);
}
idGroupList = groupHelper.getListIdGroupOfConcept(connect.getPoolConnexion(), nodeConceptTree.getIdThesaurus(), nodeConceptTree.getIdConcept());
((MyTreeNode) treeNode).setOtherGroup(idGroupList);
if (listeId.get(cpt).equals(((MyTreeNode) treeNode).getIdConcept())) {
treeNode.setSelected(true);
selectedNode = treeNode;
selectedNodes.add(treeNode);
} else {
treeNode.setSelected(false);
}
}
}
node.setExpanded(true);
} else {
List<TreeNode> children = node.getChildren();
for (TreeNode mtn : children) {
if (listeId.get(cpt).equals(((MyTreeNode) mtn).getIdConcept())) {
if (cpt + 1 < listeId.size()) {
mtn.setSelected(false);
reExpandChild(listeId, mtn, cpt + 1);
} else {
mtn.setSelected(true);
selectedNode = mtn;
selectedNodes.add(mtn);
}
}
}
}
}
use of mom.trd.opentheso.bdd.helper.nodes.concept.NodeConceptTree in project opentheso by miledrousset.
the class SelectedTerme method onNodeExpand.
/**
* Expension de l'abre sur un seul noeud (ouvert manuellement)
*
* @param event Le noeud ouvert
*/
public void onNodeExpand(NodeExpandEvent event) {
String theso = ((MyTreeNode) event.getTreeNode()).getIdTheso();
String lang = ((MyTreeNode) event.getTreeNode()).getLangue();
// Récupération des facettes
ArrayList<Integer> listIdFacet = new FacetHelper().getIdFacetUnderConcept(connect.getPoolConnexion(), ((MyTreeNode) event.getTreeNode()).getIdConcept(), theso);
ArrayList<NodeFacet> listFacet = new ArrayList<>();
for (Integer id : listIdFacet) {
NodeFacet nf = new FacetHelper().getThisFacet(connect.getPoolConnexion(), id, theso, lang);
listFacet.add(nf);
}
// <Retirer noeuds fictifs>
if (event.getTreeNode().getChildCount() == 1) {
event.getTreeNode().getChildren().remove(0);
}
// Récupération et insertion des facettes avec leurs concepts
for (NodeFacet nf : listFacet) {
String valeur = nf.getLexicalValue() + "(" + String.valueOf(nf.getIdFacet()) + ")";
new MyTreeNode(1, String.valueOf(nf.getIdFacet()), theso, lang, "", "", "", "facette", valeur, event.getTreeNode());
ArrayList<String> listIdC = new FacetHelper().getIdConceptsOfFacet(connect.getPoolConnexion(), nf.getIdFacet(), theso);
ArrayList<NodeConceptTree> liste = new ArrayList<>();
for (String id : listIdC) {
String value = new TermHelper().getThisTerm(connect.getPoolConnexion(), id, theso, lang).getLexical_value();
NodeConceptTree nct = new NodeConceptTree();
nct.setHaveChildren(false);
nct.setIdConcept(id);
nct.setIdLang(lang);
nct.setIdThesaurus(theso);
nct.setTitle(value);
liste.add(nct);
}
// Ajout dans l'arbre
for (NodeConceptTree nct : liste) {
new MyTreeNode(3, nct.getIdConcept(), theso, lang, "", "", "", "fichier", nct.getTitle() + "(" + nct.getIdConcept() + ")", event.getTreeNode());
}
}
}
Aggregations