use of mom.trd.opentheso.core.imports.old.ReadFileSKOS in project opentheso by miledrousset.
the class AlignmentQuery method queryOpentheso.
/**
* Cette fonction permet de récupérer les alignements présents sur Opentheso
* pour un concept passé en paramètre et un thésaurus donné
*
* @param idC
* @param idTheso
* @param lexicalValue
* @param lang
* @param requete
* @param source
* @return
*/
public ArrayList<NodeAlignment> queryOpentheso(String idC, String idTheso, String lexicalValue, String lang, String requete, String source) {
if (requete.trim().equals("")) {
return null;
}
if (lexicalValue.trim().equals("")) {
return null;
}
listeAlign = new ArrayList<>();
// construction de la requête de type (webservices Opentheso)
lexicalValue = lexicalValue.replaceAll(" ", "%20");
requete = requete.replace("##lang##", lang);
requete = requete.replace("##value##", lexicalValue);
try {
URL url = new URL(requete);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", "application/xml");
if (conn.getResponseCode() != 200) {
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));
String output;
String xmlRecord = "";
while ((output = br.readLine()) != null) {
xmlRecord += output;
}
byte[] bytes = xmlRecord.getBytes();
xmlRecord = new String(bytes, Charset.forName("UTF-8"));
conn.disconnect();
StringBuffer sb = new StringBuffer(xmlRecord);
try {
SKOSXmlDocument sxd = new ReadFileSKOS().readStringBuffer(sb);
for (SKOSResource resource : sxd.getResourcesList()) {
NodeAlignment na = new NodeAlignment();
na.setInternal_id_concept(idC);
na.setInternal_id_thesaurus(idTheso);
// "Pactols");
na.setThesaurus_target(source);
na.setUri_target(resource.getUri());
for (SKOSLabel label : resource.getLabelsList()) {
switch(label.getProperty()) {
case SKOSProperty.prefLabel:
if (label.getLanguage().equals(lang)) {
na.setConcept_target(label.getLabel());
}
break;
case SKOSProperty.altLabel:
if (label.getLanguage().equals(lang)) {
if (na.getConcept_target_alt().isEmpty()) {
na.setConcept_target_alt(label.getLabel());
} else {
na.setConcept_target_alt(na.getConcept_target_alt() + ";" + label.getLabel());
}
}
break;
default:
break;
}
}
for (SKOSDocumentation sd : resource.getDocumentationsList()) {
if (sd.getProperty() == SKOSProperty.definition && sd.getLanguage().equals(lang)) {
na.setDef_target(sd.getText());
}
}
listeAlign.add(na);
}
} catch (Exception ex) {
Logger.getLogger(AlignmentQuery.class.getName()).log(Level.SEVERE, null, ex);
}
} catch (MalformedURLException e) {
} catch (IOException e) {
}
return listeAlign;
}
use of mom.trd.opentheso.core.imports.old.ReadFileSKOS in project opentheso by miledrousset.
the class TestImportBranch method readSkosFile.
private SKOSXmlDocument readSkosFile(HikariDataSource conn, FileInputStream file, String dateFromat, boolean useArk, String adresseSite) {
try {
ReadFileSKOS readFileSKOS = new ReadFileSKOS();
readFileSKOS.readBranchFile(conn, file, dateFromat, useArk, adresseSite);
SKOSXmlDocument sKOSXmlDocument = readFileSKOS.getThesaurus();
return sKOSXmlDocument;
} catch (Exception ex) {
Logger.getLogger(TestImportBranch.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
use of mom.trd.opentheso.core.imports.old.ReadFileSKOS in project opentheso by miledrousset.
the class JsonHelper method readSkosDocument.
public SKOSXmlDocument readSkosDocument(StringBuffer skosStringBuffer) {
SKOSXmlDocument sKOSXmlDocument;
try {
ReadFileSKOS readFileSKOS = new ReadFileSKOS();
sKOSXmlDocument = readFileSKOS.readStringBuffer(skosStringBuffer);
return sKOSXmlDocument;
} catch (Exception ex) {
Logger.getLogger(JsonHelper.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
use of mom.trd.opentheso.core.imports.old.ReadFileSKOS in project opentheso by miledrousset.
the class FileBean method chargeSkos.
/**
* Cette fonction permet d'insérer un thésaurus en base de données à partir
* d'un fichier Skos
*
* @param event
*/
public void chargeSkos(FileUploadEvent event) {
if (!PhaseId.INVOKE_APPLICATION.equals(event.getPhaseId())) {
event.setPhaseId(PhaseId.INVOKE_APPLICATION);
event.queue();
} else {
UploadedFile file = event.getFile();
if (formatDate == null || formatDate.equals("") || user == null || user.getNodePreference() == null) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("file.error2")));
} else {
try {
boolean useArk = false;
useArk = user.getNodePreference().isUseArk();
// bundlePref.getString("cheminSite");
String adressSite = user.getNodePreference().getCheminSite();
int idUser = selectedTerme.getUser().getUser().getId();
new ReadFileSKOS().readFile(connect.getPoolConnexion(), file.getInputstream(), formatDate, useArk, adressSite, idUser, langueSource);
} catch (IOException ex) {
Logger.getLogger(FileBean.class.getName()).log(Level.SEVERE, null, ex);
} catch (Exception ex) {
Logger.getLogger(FileBean.class.getName()).log(Level.SEVERE, null, ex);
}
vue.setAddSkos(false);
}
}
}
use of mom.trd.opentheso.core.imports.old.ReadFileSKOS in project opentheso by miledrousset.
the class FileBean_progress method chargeSkos.
/**
* Cette fonction permet d'insérer un thésaurus en base de données à partir
* d'un fichier Skos
*
* @param event
*/
public void chargeSkos(FileUploadEvent event) {
if (!PhaseId.INVOKE_APPLICATION.equals(event.getPhaseId())) {
event.setPhaseId(PhaseId.INVOKE_APPLICATION);
event.queue();
} else {
UploadedFile file = event.getFile();
if (formatDate == null || formatDate.equals("")) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("file.error2")));
} else {
try {
boolean useArk = false;
ResourceBundle bundlePref = getBundlePref();
if (bundlePref.getString("useArk").equalsIgnoreCase("true")) {
useArk = true;
}
String adressSite = bundlePref.getString("cheminSite");
int idUser = selectedTerme.getUser().getUser().getId();
new ReadFileSKOS().readFile(connect.getPoolConnexion(), file.getInputstream(), formatDate, useArk, adressSite, idUser, "");
} catch (IOException ex) {
Logger.getLogger(FileBean.class.getName()).log(Level.SEVERE, null, ex);
} catch (Exception ex) {
Logger.getLogger(FileBean.class.getName()).log(Level.SEVERE, null, ex);
}
vue.setAddSkos(false);
}
}
}
Aggregations