Search in sources :

Example 6 with ArkClient

use of mom.trd.opentheso.ws.ark.ArkClient in project opentheso by miledrousset.

the class ConceptHelper method regenerateArkId.

/**
 * permet de vérifier si l'id ark existe; si oui, on ne fait rien, s'il
 * n'existe pas, on l'ajoute.
 *
 * @param ds
 * @param url
 * @param idConcept
 * @param idLang
 * @param idTheso
 * @return #MR
 */
public boolean regenerateArkId(HikariDataSource ds, String idConcept, String idLang, String idTheso) {
    String idArk;
    ArkClient ark_Client = new ArkClient();
    Concept concept = getThisConcept(ds, idConcept, idTheso);
    if (concept.getIdArk() == null) {
        // création d'un identifiant Ark
        return prepareToAddArkId(ds, idConcept, idLang, idTheso);
    }
    if (concept.getIdArk().isEmpty()) {
        // création d'un identifiant Ark
        return prepareToAddArkId(ds, idConcept, idLang, idTheso);
    }
    // ici, nous avons un  IdArk, on vérifie s'il est encore valide ?
    idArk = ark_Client.getInfosArkId(concept.getIdArk());
    // exp :  idArk = ark_Client.getInfosArkId("66666/pcrtgG3244vfqgI8");
    if (idArk == null) {
        // l'idArk n'est plus valide, il faut le créer
        return prepareToAddArkId(ds, idConcept, idLang, idTheso);
    }
    // ici l'idArk est valide, on ne fait rien.
    return true;
}
Also used : NodeConcept(mom.trd.opentheso.bdd.helper.nodes.concept.NodeConcept) Concept(mom.trd.opentheso.bdd.datas.Concept) ArkClient(mom.trd.opentheso.ws.ark.ArkClient)

Example 7 with ArkClient

use of mom.trd.opentheso.ws.ark.ArkClient in project opentheso by miledrousset.

the class VerifyArkIdTest method addIdArk.

/**
 * @param conn
 * @param idConcept
 * @param idThesaurus
 * @param urlSite
 * @param nodeMetaData
 * @return
 */
private boolean addIdArk(Connection conn, String idConcept, String idThesaurus, String urlSite, NodeMetaData nodeMetaData, int idUser) {
    /**
     * récupération du code Ark via WebServices
     */
    ArkClient ark_Client = new ArkClient();
    String idArk = ark_Client.getArkId(new FileUtilities().getDate(), urlSite + "?idc=" + idConcept + "&idt=" + idThesaurus, // title
    nodeMetaData.getTitle(), // creator
    nodeMetaData.getCreator(), nodeMetaData.getDcElementsList(), // pcrt : p= pactols, crt=code DCMI pour collection
    "pcrt");
    // description
    if (idArk == null) {
        return false;
    }
    return updateArkIdOfConcept(conn, idConcept, idThesaurus, idArk);
}
Also used : FileUtilities(mom.trd.opentheso.bdd.tools.FileUtilities) ArkClient(mom.trd.opentheso.ws.ark.ArkClient)

Example 8 with ArkClient

use of mom.trd.opentheso.ws.ark.ArkClient in project opentheso by miledrousset.

the class ThesaurusHelper method addThesaurus.

/**
 * Permet de créer un nouveau Thésaurus. Retourne l'identifiant du thésaurus
 * ou null
 *
 * @param ds le pool de connexion
 * @param thesaurus
 * @param urlSite
 * @param isArkActive
 * @return String Id du thésaurus rajouté
 */
public String addThesaurus(HikariDataSource ds, Thesaurus thesaurus, String urlSite, boolean isArkActive) {
    // "TH";//"ark:/66666/srvq9a5Ll41sk";
    String idThesaurus = null;
    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "select max(id) from thesaurus";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                resultSet.next();
                int idNumeriqueThesaurus = resultSet.getInt(1);
                idThesaurus = "" + ++idNumeriqueThesaurus;
                /**
                 * récupération du code Ark via WebServices
                 */
                String idArk = "";
                if (isArkActive) {
                    ArrayList<DcElement> dcElementsList = new ArrayList<>();
                    ArkClient ark_Client = new ArkClient();
                    idArk = ark_Client.getArkId(new FileUtilities().getDate(), urlSite + "?idt=" + idThesaurus, "", "", dcElementsList, // pcrt : p= pactols, crt=code DCMI pour collection
                    "pcrt");
                }
                query = "Insert into thesaurus (id_thesaurus," + " id_ark, created, modified)" + " values (" + "'" + idThesaurus + "'" + ",'" + idArk + "'" + "," + "current_date," + "current_date)";
                stmt.executeUpdate(query);
                thesaurus.setId_thesaurus(idThesaurus);
            /*   if(thesaurus.getTitle().isEmpty()){
                        thesaurus.setTitle("Theso_" + idThesaurus);
                    }
                    addThesaurusTraduction(ds, thesaurus);*/
            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error while adding Thesaurus : " + idThesaurus, sqle);
        idThesaurus = null;
    }
    return idThesaurus;
}
Also used : DcElement(fr.mom.arkeo.soap.DcElement) FileUtilities(mom.trd.opentheso.bdd.tools.FileUtilities) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) ArkClient(mom.trd.opentheso.ws.ark.ArkClient)

Example 9 with ArkClient

use of mom.trd.opentheso.ws.ark.ArkClient in project opentheso by miledrousset.

the class ToolsHelper method GenerateArkIds.

/**
 * Cette fonction permet de regénerer ou générer tous les identifiants Ark
 * du thésaurus
 *
 * @param ds
 * @param idThesaurus
 * @return ArrayList de NodePermute
 */
public boolean GenerateArkIds(HikariDataSource ds, String idThesaurus) {
    ConceptHelper conceptHelper = new ConceptHelper();
    TermHelper termHelper = new TermHelper();
    ArrayList<NodeTermTraduction> nodeTermTraductionList;
    // Génération des Id Ark pour les concepts
    ArrayList<String> tabIdConcept = conceptHelper.getAllIdConceptOfThesaurus(ds, idThesaurus);
    String idArk;
    ArkClient ark_Client = new ArkClient();
    ArrayList<DcElement> dcElementsList = new ArrayList<>();
    for (String idConcept : tabIdConcept) {
        dcElementsList.clear();
        nodeTermTraductionList = termHelper.getAllTraductionsOfConcept(ds, idConcept, idThesaurus);
        for (NodeTermTraduction nodeTermTraduction : nodeTermTraductionList) {
            DcElement dcElement = new DcElement();
            // cette fonction permet de remplir la table Permutée
            dcElement.setName("description");
            dcElement.setValue(nodeTermTraduction.getLexicalValue());
            dcElement.setLanguage(nodeTermTraduction.getLang());
            dcElementsList.add(dcElement);
        }
        // String date, String url, String title, String creator, String description, String type
        idArk = ark_Client.getArkId(new FileUtilities().getDate(), "http://pactols.frantiq.fr/" + "?idc=" + idConcept + "&idt=" + idThesaurus, idConcept, "Frantiq", dcElementsList, // pcrt : p= pactols, crt=code DCMI pour collection
        "pcrt");
        conceptHelper.updateArkIdOfConcept(ds, idConcept, idThesaurus, idArk);
    }
    return true;
}
Also used : DcElement(fr.mom.arkeo.soap.DcElement) FileUtilities(mom.trd.opentheso.bdd.tools.FileUtilities) ArrayList(java.util.ArrayList) NodeTermTraduction(mom.trd.opentheso.bdd.helper.nodes.term.NodeTermTraduction) ArkClient(mom.trd.opentheso.ws.ark.ArkClient)

Aggregations

ArkClient (mom.trd.opentheso.ws.ark.ArkClient)9 FileUtilities (mom.trd.opentheso.bdd.tools.FileUtilities)8 DcElement (fr.mom.arkeo.soap.DcElement)6 ArrayList (java.util.ArrayList)6 PreparedStatement (java.sql.PreparedStatement)4 SQLException (java.sql.SQLException)4 Statement (java.sql.Statement)4 Connection (java.sql.Connection)3 ResultSet (java.sql.ResultSet)3 Properties (java.util.Properties)1 Concept (mom.trd.opentheso.bdd.datas.Concept)1 ConceptGroupLabel (mom.trd.opentheso.bdd.datas.ConceptGroupLabel)1 NodeConcept (mom.trd.opentheso.bdd.helper.nodes.concept.NodeConcept)1 NodeTermTraduction (mom.trd.opentheso.bdd.helper.nodes.term.NodeTermTraduction)1 StringPlus (mom.trd.opentheso.bdd.tools.StringPlus)1