Skip to content
Permalink
Browse files

Ajout de concetps :

	- possibilité d'ajouter une relation de type NT ppour un concept (sans avoir à utiliser le BT)
  • Loading branch information...
miledrousset committed Feb 14, 2018
1 parent ee968b2 commit 2732afc49f92e1ae55561c64803dfc43a6d0a500
@@ -1,32 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-shared-configuration>
<?xml version="1.0" encoding="UTF-8"?>
<project-shared-configuration>
<!--
This file contains additional configuration written by modules in the NetBeans IDE.
The configuration is intended to be shared among all the users of project and
therefore it is assumed to be part of version control checkout.
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
-->
<libraries xmlns="http://www.netbeans.org/ns/cdnjs-libraries/1"/>
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
-->
<libraries xmlns="http://www.netbeans.org/ns/cdnjs-libraries/1"/>
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
<!--
Properties that influence various parts of the IDE, especially code formatting and the like.
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
That way multiple projects can share the same settings (useful for formatting rules for example).
Any value defined here will override the pom.xml file value but is only applicable to the current project.
-->
<org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_j2eeVersion>1.7-web</org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_j2eeVersion>
<org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server>Tomcat</org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server>
<org-netbeans-modules-maven-jaxws.rest_2e_config_2e_type>ide</org-netbeans-modules-maven-jaxws.rest_2e_config_2e_type>
<org-netbeans-modules-projectapi.jsf_2e_language>Facelets</org-netbeans-modules-projectapi.jsf_2e_language>
<org-netbeans-modules-maven-jaxws.generate_5f_nonjsr109>false</org-netbeans-modules-maven-jaxws.generate_5f_nonjsr109>
<org-netbeans-modules-css-prep.less_2e_mappings>/less:/css</org-netbeans-modules-css-prep.less_2e_mappings>
<org-netbeans-modules-css-prep.less_2e_enabled>false</org-netbeans-modules-css-prep.less_2e_enabled>
<org-netbeans-modules-css-prep.sass_2e_enabled>false</org-netbeans-modules-css-prep.sass_2e_enabled>
<org-netbeans-modules-css-prep.sass_2e_compiler_2e_options/>
<org-netbeans-modules-css-prep.less_2e_compiler_2e_options/>
<org-netbeans-modules-css-prep.sass_2e_mappings>/scss:/css</org-netbeans-modules-css-prep.sass_2e_mappings>
<org-netbeans-modules-web-clientproject-api.js_2e_libs_2e_folder>javascript</org-netbeans-modules-web-clientproject-api.js_2e_libs_2e_folder>
<org-netbeans-modules-javascript2-requirejs.enabled>true</org-netbeans-modules-javascript2-requirejs.enabled>
<netbeans.compile.on.save>none</netbeans.compile.on.save>
</properties>
</project-shared-configuration>
-->
<org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_j2eeVersion>1.7-web</org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_j2eeVersion>
<org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server>Tomcat</org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server>
<org-netbeans-modules-maven-jaxws.rest_2e_config_2e_type>ide</org-netbeans-modules-maven-jaxws.rest_2e_config_2e_type>
<org-netbeans-modules-projectapi.jsf_2e_language>JSP</org-netbeans-modules-projectapi.jsf_2e_language>
<org-netbeans-modules-maven-jaxws.generate_5f_nonjsr109>false</org-netbeans-modules-maven-jaxws.generate_5f_nonjsr109>
<org-netbeans-modules-css-prep.less_2e_mappings>/less:/css</org-netbeans-modules-css-prep.less_2e_mappings>
<org-netbeans-modules-css-prep.less_2e_enabled>false</org-netbeans-modules-css-prep.less_2e_enabled>
<org-netbeans-modules-css-prep.sass_2e_enabled>false</org-netbeans-modules-css-prep.sass_2e_enabled>
<org-netbeans-modules-css-prep.sass_2e_compiler_2e_options/>
<org-netbeans-modules-css-prep.less_2e_compiler_2e_options/>
<org-netbeans-modules-css-prep.sass_2e_mappings>/scss:/css</org-netbeans-modules-css-prep.sass_2e_mappings>
<org-netbeans-modules-web-clientproject-api.js_2e_libs_2e_folder>javascript</org-netbeans-modules-web-clientproject-api.js_2e_libs_2e_folder>
<org-netbeans-modules-javascript2-requirejs.enabled>true</org-netbeans-modules-javascript2-requirejs.enabled>
<netbeans.compile.on.save>none</netbeans.compile.on.save>
</properties>
</project-shared-configuration>
@@ -12,7 +12,10 @@
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.event.AjaxBehaviorEvent;
import javax.swing.event.ChangeEvent;
import mom.trd.opentheso.bdd.helper.Connexion;
import mom.trd.opentheso.bdd.datas.Term;
import mom.trd.opentheso.bdd.helper.ConceptHelper;
@@ -53,12 +56,33 @@
@ManagedProperty(value = "#{langueBean}")
private LanguageBean langueBean;

public List<NodeAutoCompletion> completTerm(String query) {

/**
* permet de retourner la liste des concepts possibles
* pour ajouter une relation NT
* (en ignorant les relations interdites)
* on ignore les concepts de type TT
* on ignore les concepts de type RT
* @param value
* @return
*/
public List<NodeAutoCompletion> getAutoCompletForRelationNT(String value) {
selectedAtt = new NodeAutoCompletion();
List<NodeAutoCompletion> liste = new ArrayList<>();
if (theso.getThesaurus().getId_thesaurus() != null && theso.getThesaurus().getLanguage() != null) {
liste = new TermHelper().getAutoCompletForRelationNT(connect.getPoolConnexion(), theso.getThesaurus().getId_thesaurus(),
theso.getThesaurus().getLanguage(), value);
}
return liste;
}


public List<NodeAutoCompletion> completTerm(String value) {
selectedAtt = new NodeAutoCompletion();
List<NodeAutoCompletion> liste = new ArrayList<>();
if (theso.getThesaurus().getId_thesaurus() != null && theso.getThesaurus().getLanguage() != null) {
liste = new TermHelper().getAutoCompletionTerm(connect.getPoolConnexion(), theso.getThesaurus().getId_thesaurus(),
theso.getThesaurus().getLanguage(), query);
theso.getThesaurus().getLanguage(), value);
}
return liste;
}
@@ -124,6 +148,7 @@ public void onItemSelect(SelectEvent event) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Item Selected", event.getObject().toString()));
}


public List<NodeAutoCompletion> completSearchTerm(String query) {
selectedAtt = new NodeAutoCompletion();
List<NodeAutoCompletion> liste = new ArrayList<>();
@@ -492,11 +492,12 @@ public void changeTerme(String id, int type) {
}

String idTC;
if (type == 2) { //On vient d'un domaine
if (((MyTreeNode)selectedNode).isIsGroup() || ((MyTreeNode)selectedNode).isIsSubGroup()) {//type == 2) { //On vient d'un domaine
idTC = id;
} else {
idTC = selectedTerme.getIdTopConcept();
}
/// ????? à comprendre pourquoi ?????
if (type == 0) {
boolean temp = new ConceptHelper().getThisConcept(connect.getPoolConnexion(), id, selectedTerme.getIdTheso()).isTopConcept();
if (temp) {
@@ -880,6 +881,53 @@ public void newTSpe() {
selectedTerme.setSelectedTermComp(new NodeAutoCompletion());
createValid = true;
}

/**
* Permet d'ajouter une relation terme spécifique NT pour un concept
* #MR
*/
public void newRelationNT() {
createValid = false;
if ((selectedTerme.getSelectedTermComp() == null ) ||
(selectedTerme.getSelectedTermComp().getIdConcept() == null) ||
(selectedTerme.getSelectedTermComp().getIdConcept().isEmpty())) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("tree.error1")));
return;
}

// vérification si la relation est cohérente (NT et RT à la fois ?)
if(!isAddRelationNTValid(selectedTerme.getIdC(), selectedTerme.getSelectedTermComp().getIdConcept())){
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("relation.errorNTRT")));
return;
}

RelationsHelper relationsHelper = new RelationsHelper();
if (!relationsHelper.addRelationNT(connect.getPoolConnexion(),
selectedTerme.getIdC(),
idThesoSelected,
selectedTerme.getSelectedTermComp().getIdConcept(),
selectedTerme.getUser().getUser().getId())) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("error")));
return;
}

reInit();
reExpand();
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(langueBean.getMsg("info") + " :",
selectedTerme.getSelectedTermComp().getIdConcept() + " " + langueBean.getMsg("tree.info1")));
selectedTerme.setSelectedTermComp(new NodeAutoCompletion());
createValid = true;
}

private boolean isAddRelationNTValid(String idConcept1, String idConcept2) {
RelationsHelper relationsHelper = new RelationsHelper();
if(relationsHelper.isConceptHaveRelationRT(connect.getPoolConnexion(),
idConcept1, idConcept2, idThesoSelected) == true)
return false;
else
return true;
}


public void newSpecialTSpe() {
createValid = false;
@@ -8,6 +8,7 @@

@FacesConverter("termConverterLexical")
public class TermeConverterLexical implements Converter{

@Override
public Object getAsObject(FacesContext fc, UIComponent uic, String value) {
if(value != null && value.trim().length() > 0) {
@@ -25,7 +26,8 @@ public String getAsString(FacesContext fc, UIComponent uic, Object o) {
if(o == null) {
return null;
} else {
return ((NodeAutoCompletion)o).getTermLexicalValue();
return ((NodeAutoCompletion)o).getTermLexicalValue();
}
}

}
@@ -521,6 +521,72 @@ public boolean addRelationBT(Connection conn,
}
return status;
}

/**
* Cette fonction permet de rajouter une relation terme spécifique à un
* concept
*
* @param ds
* @param idConcept
* @param idConceptNT
* @param idThesaurus
* @param idUser
* @return boolean
*/
public boolean addRelationNT(HikariDataSource ds,
String idConcept, String idThesaurus,
String idConceptNT, int idUser) {

Statement stmt;
boolean status = false;
Connection conn;
try {
conn = ds.getConnection();
try {
conn.setAutoCommit(false);
stmt = conn.createStatement();
try {
if (!new RelationsHelper().addRelationHistorique(conn, idConcept, idThesaurus, idConceptNT, "NT", idUser, "ADD")) {
conn.rollback();
conn.close();
return false;
}

String query = "Insert into hierarchical_relationship"
+ "(id_concept1, id_thesaurus, role, id_concept2)"
+ " values ("
+ "'" + idConcept + "'"
+ ",'" + idThesaurus + "'"
+ ",'NT'"
+ ",'" + idConceptNT + "')";

stmt.executeUpdate(query);
query = "Insert into hierarchical_relationship"
+ "(id_concept1, id_thesaurus, role, id_concept2)"
+ " values ("
+ "'" + idConceptNT + "'"
+ ",'" + idThesaurus + "'"
+ ",'BT'"
+ ",'" + idConcept + "')";
stmt.executeUpdate(query);
status = true;
conn.commit();
} finally {
stmt.close();
}
} finally {
conn.close();
}
} catch (SQLException sqle) {
// Log exception
// if (sqle.getMessage().contains("duplicate key value violates unique constraint")) {

if (!sqle.getSQLState().equalsIgnoreCase("23505")) {
log.error("Error while adding relation NT : " + idConcept + "-> " + idConceptNT, sqle);
}
}
return status;
}

/**
* Cette fonction permet de rajouter une relation dans l'historique
@@ -1836,6 +1902,51 @@ public boolean isRelationNTExist(HikariDataSource ds,
}
return existe;
}

/**
* Cette fonction permet de savoir si le Concept1 a une relation RT avec le concept2
* permet d'éviter l'ajout des relations NT et RT en même temps (c'est interdit par la norme)
*
* @param ds
* @param idConcept1
* @param idConcept2
* @param idThesaurus
* @return Objet class Concept
*/
public boolean isConceptHaveRelationRT(HikariDataSource ds,
String idConcept1, String idConcept2, String idThesaurus) {

Connection conn;
Statement stmt;
ResultSet resultSet;
boolean existe = false;

try {
// Get connection from pool
conn = ds.getConnection();
try {
stmt = conn.createStatement();
try {
String query = "select id_concept1 from hierarchical_relationship"
+ " where id_thesaurus = '" + idThesaurus + "'"
+ " and id_concept1 = '" + idConcept1 + "'"
+ " and id_concept2 = '" + idConcept2 + "'"
+ " and role LIKE 'RT%'";
stmt.executeQuery(query);
resultSet = stmt.getResultSet();
existe = resultSet.next();
} finally {
stmt.close();
}
} finally {
conn.close();
}
} catch (SQLException sqle) {
// Log exception
log.error("Error while asking if relation RT exist of Concept1 : " + idConcept1 + " for concept2 : " + idConcept2, sqle);
}
return existe;
}

/**
* Cette fonction permet de récupérer les termes associés d'un concept

0 comments on commit 2732afc

Please sign in to comment.
You can’t perform that action at this time.