Skip to content
This repository has been archived by the owner on Jul 31, 2024. It is now read-only.

Commit

Permalink
ajout des commandes au webservices :
Browse files Browse the repository at this point in the history
	- récupération de tous les thésaurus
	- récupération de toutes les langues d'un thésaurus
  • Loading branch information
miledrousset committed Apr 10, 2020
1 parent 926b7bc commit b2a2f06
Show file tree
Hide file tree
Showing 11 changed files with 377 additions and 25 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<!-- ici c'est pour la version du WAR, pour la version d'Opentheso, il faut modifier le fichier web.xml-->
<groupId>trd</groupId>
<artifactId>opentheso</artifactId>
<version>4.5.8</version>
<version>4.5.9</version>
<packaging>war</packaging>

<name>opentheso</name>
Expand Down
119 changes: 115 additions & 4 deletions src/main/java/mom/trd/opentheso/SelectedBeans/SelectedTerme.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,24 @@
import com.k_int.IR.Searchable;
import com.k_int.IR.TimeoutExceededException;
import com.k_int.hss.HeterogeneousSetOfSearchable;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import mom.trd.opentheso.bdd.tools.AsciiUtils;
import java.io.Serializable;
import java.io.StringReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.X509Certificate;
import java.sql.Connection;
import java.sql.SQLException;
import java.text.DateFormat;
Expand All @@ -41,8 +49,16 @@
import javax.json.Json;
import javax.json.JsonArray;
import javax.json.JsonException;
import javax.json.JsonNumber;
import javax.json.JsonObject;
import javax.json.JsonReader;
import javax.json.JsonString;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

import mom.trd.opentheso.core.alignment.AlignmentQuery;
import mom.trd.opentheso.bdd.datas.Concept;
Expand Down Expand Up @@ -82,6 +98,7 @@
import mom.trd.opentheso.bdd.tools.StringPlus;
import mom.trd.opentheso.beans.vuegroups.TreeNodeData;
import mom.trd.opentheso.core.alignment.AlignementSource;
import mom.trd.opentheso.ws.handle.HandleClient;
import org.primefaces.PrimeFaces;
import org.primefaces.event.NodeExpandEvent;
import org.primefaces.event.NodeSelectEvent;
Expand Down Expand Up @@ -511,16 +528,24 @@ private void majNoticeBdd() {
} else {
urlNotice = urlNotice.replace("##value##", nom);
}

// récupération du total des notices
String urlCounterBdd = roleOnTheso.getNodePreference().getUrlCounterBdd();
urlCounterBdd = urlCounterBdd.replace("##conceptId##", idC);
// String urlCounterBdd = roleOnTheso.getNodePreference().getUrlCounterBdd();
// urlCounterBdd = urlCounterBdd.replace("##conceptId##", idC);

nbNotices = getCountOfResources();
if(nbNotices < 0)
nbNotices = 0;


///// à revoir par #MR


//urlCounterBdd = "http://healthandco.test.o2sources.com/concept/40/total";
// exemple des données récupérées
// "{\"content\":[{\"nb_notices\":\"s7\"}],\"debug\":\"\",\"error\":0}\" ";
//{"content":[{"nb_notices":"7"}],"debug":"","error":0}

/*
URL url;
try {
url = new URL(urlCounterBdd);
Expand Down Expand Up @@ -554,13 +579,99 @@ private void majNoticeBdd() {
} catch (IOException ex) {
Logger.getLogger(SelectedTerme.class.getName()).log(Level.SEVERE, null, ex);
}
*/


// try {
// urlNotice = URLEncoder.encode(urlNotice);
// } catch (UnsupportedEncodingException ex) {
// Logger.getLogger(SelectedTerme.class.getName()).log(Level.SEVERE, null, ex);
// }
}

private int getCountOfResources() {

String output;
String json = "";

TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}

public void checkClientTrusted(X509Certificate[] certs, String authType) {
}

public void checkServerTrusted(X509Certificate[] certs, String authType) {
}
}
};

// Install the all-trusting trust manager
SSLContext sc;
try {
sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
} catch (NoSuchAlgorithmException ex) {
Logger.getLogger(SelectedTerme.class.getName()).log(Level.SEVERE, null, ex);
} catch (KeyManagementException ex) {
Logger.getLogger(SelectedTerme.class.getName()).log(Level.SEVERE, null, ex);
}
// Create all-trusting host name verifier
HostnameVerifier allHostsValid = new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;
}
};
// Install the all-trusting host verifier
HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);


// récupération du total des notices
String urlCounterBdd = roleOnTheso.getNodePreference().getUrlCounterBdd();
urlCounterBdd = urlCounterBdd.replace("##conceptId##", idC);

try {
urlCounterBdd = urlCounterBdd.replace("http://", "https://");
URL url = new URL(urlCounterBdd);

HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Content-Type", "application/json");
conn.setUseCaches(false);
conn.setDoInput(true);
conn.setDoOutput(true);
int status = conn.getResponseCode();
InputStream in = status >= 400 ? conn.getErrorStream() : conn.getInputStream();

BufferedReader br = new BufferedReader(new InputStreamReader(in));
while ((output = br.readLine()) != null) {
json += output;
}
return getCountFromJson(json);

} catch (UnsupportedEncodingException ex) {
Logger.getLogger(HandleClient.class.getName()).log(Level.SEVERE, null, ex);
} catch (MalformedURLException ex) {
Logger.getLogger(HandleClient.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(HandleClient.class.getName()).log(Level.SEVERE, null, ex);
} catch (Exception ex) {
Logger.getLogger(HandleClient.class.getName()).log(Level.SEVERE, null, ex);
}
return 0;
}
private int getCountFromJson(String jsonText) {
if(jsonText == null) return 0;
JsonObject jsonObject;
try ( //{"responseCode":1,"handle":"20.500.11942/opentheso443"}
JsonReader reader = Json.createReader(new StringReader(jsonText))) {
jsonObject = reader.readObject();
return jsonObject.getInt("count");
}
}


private void majTAsso() {
termesAssocies = new ArrayList<>();
Expand Down
22 changes: 13 additions & 9 deletions src/main/java/mom/trd/opentheso/bdd/helper/ConceptHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -3930,19 +3930,23 @@ public ArrayList<NodeConceptExport> exportAllConcepts(HikariDataSource ds,
if (nodeConcept == null || nodeConcept.getConcept() == null) {
System.err.println("Attention Null proche de = : " + idConcept);
return null;
}

nodeConceptExports.add(nodeConcept);
} else
nodeConceptExports.add(nodeConcept);

for (String listIdsOfConceptChildren1 : listIdsOfConceptChildren) {
nodeConcept = conceptHelper.getConceptForExport(ds, listIdsOfConceptChildren1, idThesaurus, false);
nodeConceptExports.add(nodeConcept);
if (!nodeConcept.getNodeListOfNT().isEmpty()) {
for (int j = 0; j < nodeConcept.getNodeListOfNT().size(); j++) {
if (nodeConcept == null || nodeConcept.getConcept() == null) {
System.err.println("Attention Null proche de = : " + idConcept);
return null;
} else {
nodeConceptExports.add(nodeConcept);
if (!nodeConcept.getNodeListOfNT().isEmpty()) {
for (int j = 0; j < nodeConcept.getNodeListOfNT().size(); j++) {

exportAllConcepts(ds,
nodeConcept.getNodeListOfNT().get(j).getUri().getIdConcept(),
idThesaurus, nodeConceptExports);
exportAllConcepts(ds,
nodeConcept.getNodeListOfNT().get(j).getUri().getIdConcept(),
idThesaurus, nodeConceptExports);
}
}
}
}
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/mom/trd/opentheso/core/alignment/GpsQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,11 @@
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import static javax.management.Query.lt;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import mom.trd.opentheso.bdd.helper.nodes.NodeAlignment;
import mom.trd.opentheso.bdd.helper.nodes.NodeLang;
import mom.trd.opentheso.core.exports.privatesdatas.importxml.importxml;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.JDOMException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ public void addJsonData(String uri, String value) {

}


public void addJsonObject(
String id, String value){
JsonObjectBuilder builder = Json.createObjectBuilder();
builder.add(id, value);
jab.add(builder);
}

public JsonArray getBuilder() {
if(jab != null)
return jab.build();
Expand Down
Loading

0 comments on commit b2a2f06

Please sign in to comment.