From dd35823e28a6a989722aff0b15b073dd94ad01e8 Mon Sep 17 00:00:00 2001 From: sernadela Date: Tue, 18 Jun 2013 16:56:25 +0100 Subject: [PATCH 01/52] - Remove unused DiseaseCard code --- .../coeus/api/plugins/OMIMPlugin.java | 314 ------------------ .../bioinformatics/coeus/common/Builder.java | 5 +- .../coeus/data/connect/PluginFactory.java | 86 ----- .../coeus/ext/COEUSActionBeanContext.java | 62 ---- .../diseasecard/domain/Disease.java | 122 ------- 5 files changed, 1 insertion(+), 588 deletions(-) delete mode 100755 src/main/java/pt/ua/bioinformatics/coeus/api/plugins/OMIMPlugin.java delete mode 100755 src/main/java/pt/ua/bioinformatics/coeus/data/connect/PluginFactory.java delete mode 100755 src/main/java/pt/ua/bioinformatics/coeus/ext/COEUSActionBeanContext.java delete mode 100755 src/main/java/pt/ua/bioinformatics/diseasecard/domain/Disease.java diff --git a/src/main/java/pt/ua/bioinformatics/coeus/api/plugins/OMIMPlugin.java b/src/main/java/pt/ua/bioinformatics/coeus/api/plugins/OMIMPlugin.java deleted file mode 100755 index 4e199b7..0000000 --- a/src/main/java/pt/ua/bioinformatics/coeus/api/plugins/OMIMPlugin.java +++ /dev/null @@ -1,314 +0,0 @@ -package pt.ua.bioinformatics.coeus.api.plugins; - -import au.com.bytecode.opencsv.CSVReader; -import java.io.BufferedReader; -import java.io.InputStreamReader; -import java.net.URL; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import pt.ua.bioinformatics.coeus.api.API; -import pt.ua.bioinformatics.coeus.api.PrefixFactory; -import pt.ua.bioinformatics.coeus.common.Boot; -import pt.ua.bioinformatics.coeus.common.Config; -import pt.ua.bioinformatics.coeus.data.Predicate; -import pt.ua.bioinformatics.coeus.domain.Resource; -import pt.ua.bioinformatics.diseasecard.domain.Disease; - -/** - * DiseaseCard plugin for OMIM data handling. - *

Generates initial gene and disease dataset based on OMIM's morbid map. - *

- * - * @author pedrolopes - */ -public class OMIMPlugin { - - private Resource res; - private API api; - private HashMap diseases; - private HashMap genotypes; - - public HashMap getGenotypes() { - return genotypes; - } - - public void setGenotypes(HashMap genotypes) { - this.genotypes = genotypes; - } - - public HashMap getDiseases() { - return diseases; - } - - public void setDiseases(HashMap diseases) { - this.diseases = diseases; - } - - public Resource getRes() { - return res; - } - - public void setRes(Resource res) { - this.res = res; - } - - public OMIMPlugin(Resource res) { - this.res = res; - this.diseases = new HashMap(); - this.genotypes = new HashMap(); - this.api = Boot.getAPI(); - } - - /** - * OMIMPlugin controller. - *

Workflow:

    - *
  • Load genotype information from OMIM genemap
  • - *
  • Load phenotype information from OMIM morbidmap
  • - *
  • Import loaded dataset into COEUS SDB
  • - *

- * - */ - public void itemize() { - if (loadGenotype() && loadPhenotype()) { - triplify(); - } - } - - /** - * Loads genotype information from OMIM genemap into internal memory. - * - * @return success of the operation. - */ - private boolean loadGenotype() { - boolean success = true; - try { - //URL u = new URL("ftp://ftp.ncbi.nih.gov/repository/OMIM/ARCHIVE/genemap"); - URL u = new URL("http://localhost/~pedrolopes/omim/genemap_small"); - BufferedReader in = new BufferedReader(new InputStreamReader(u.openStream())); - CSVReader reader = new CSVReader(in, '|'); - List genemap = reader.readAll(); - for (String[] genes : genemap) { - Disease d = new Disease(genes[7], genes[9]); - d.setLocation(genes[4]); - genotypes.put(d.getOmimId(), d); - String[] genelist = genes[5].split(", "); - d.getGenes().addAll(Arrays.asList(genelist)); - } - success = true; - } catch (Exception ex) { - if (Config.isDebug()) { - System.out.println("[COEUS][OMIM] Unable to load genotype information from OMIM"); - Logger.getLogger(OMIMPlugin.class.getName()).log(Level.SEVERE, null, ex); - } - } - return success; - - } - - /** - * Loads phenotype information from OMIM morbid into internal memory. - * - * @return success of the operation. - */ - private boolean loadPhenotype() { - boolean success = false; - try { - //URL u = new URL("ftp://ftp.ncbi.nih.gov/repository/OMIM/ARCHIVE/morbidmap"); - URL u = new URL("http://localhost/~pedrolopes/omim/morbidmap_small"); - BufferedReader in = new BufferedReader(new InputStreamReader(u.openStream())); - CSVReader reader = new CSVReader(in, '|'); - List morbidmap = reader.readAll(); - Pattern p = Pattern.compile("[0-9]{6}"); - - for (String[] disease : morbidmap) { - Disease d; - Matcher m = p.matcher(disease[0]); - String pheno_omim = ""; - String dis_name = ""; - - try { - if (m.find()) { - pheno_omim = m.group(0); - dis_name = disease[0].substring(0, disease[0].length() - 14); - - // check if disease is already on list - if (diseases.containsKey(pheno_omim)) { - d = diseases.get(pheno_omim); - d.getNames().add(dis_name); - Disease genotype = genotypes.get(disease[2]); - if (!d.getGenotypes().contains(genotype)) { - d.getGenotypes().add(genotype); - } - if (!genotype.getPhenotypes().contains(d)) { - genotype.getPhenotypes().add(d); - } - String[] genelist = disease[1].split(", "); - d.getGenes().addAll(Arrays.asList(genelist)); - } else { - d = new Disease(dis_name, pheno_omim); - d.setLocation(disease[3]); - d.getNames().add(dis_name); - diseases.put(pheno_omim, d); - Disease genotype = genotypes.get(disease[2]); - if (!d.getGenotypes().contains(genotype)) { - d.getGenotypes().add(genotype); - } - if (!genotype.getPhenotypes().contains(d)) { - genotype.getPhenotypes().add(d); - } - String[] genelist = disease[1].split(", "); - d.getGenes().addAll(Arrays.asList(genelist)); - } - // not a phenotype, add to only genotypes list - } else { - Disease genotype = genotypes.get(disease[2]); - d = new Disease(disease[0], genotype.getOmimId()); - d.getNames().add(disease[0]); - d.setLocation(disease[3]); - if (!d.getGenotypes().contains(genotype)) { - d.getGenotypes().add(genotype); - } - if (!genotype.getPhenotypes().contains(d)) { - genotype.getPhenotypes().add(d); - } - diseases.put(d.getOmimId(), d); - } - } catch (Exception ex) { - if (Config.isDebug()) { - System.out.println("[COEUS][OMIM] Unable to load phenotype information from OMIM for " + disease[0]); - Logger.getLogger(OMIMPlugin.class.getName()).log(Level.SEVERE, null, ex); - } - } - } - success = true; - } catch (Exception ex) { - if (Config.isDebug()) { - System.out.println("[COEUS][OMIM] Unable to load phenotype information from OMIM"); - Logger.getLogger(OMIMPlugin.class.getName()).log(Level.SEVERE, null, ex); - } - } - return success; - } - - /** - * Loads the in-memory data into COEUS SDB. - *

Workflow

    - *
  • Loads genotypes
  • - *
  • Loads genes for each genotype
  • - *
  • Loads genotypes for each genotype
  • - *
  • Loads genes for each phenotype
  • - *

- * - */ - public void triplify() { - for (Disease genotype : genotypes.values()) { - if (!genotype.getOmimId().equals("")) { - try { - String[] itemTmp = res.getIsResourceOf().getLabel().split("_"); - com.hp.hpl.jena.rdf.model.Resource geno_item = api.createResource(PrefixFactory.getURIForPrefix(Config.getKeyPrefix()) + itemTmp[1] + "_" + genotype.getOmimId()); - com.hp.hpl.jena.rdf.model.Resource geno_obj = api.createResource(PrefixFactory.getURIForPrefix(Config.getKeyPrefix()) + "Item"); - api.addStatement(geno_item, Predicate.get("rdf:type"), geno_obj); - - // set Item label - api.addStatement(geno_item, Predicate.get("rdfs:label"), "omim_" + genotype.getOmimId()); - - // associate Item with Concept - com.hp.hpl.jena.rdf.model.Resource con = api.getResource(res.getIsResourceOf().getUri()); - api.addStatement(geno_item, Predicate.get("coeus:hasConcept"), con); - api.addStatement(con, Predicate.get("coeus:isConceptOf"), geno_item); - - // add name/comment - api.addStatement(geno_item, Predicate.get("rdfs:comment"), genotype.getName()); - api.addStatement(geno_item, Predicate.get("dc:description"), genotype.getName()); - for (String name : genotype.getNames()) { - api.addStatement(geno_item, Predicate.get("diseasecard:name"), name); - } - - api.addStatement(geno_item, Predicate.get("diseasecard:omim"), genotype.getOmimId()); - api.addStatement(geno_item, Predicate.get("diseasecard:chromosomalLocation"), genotype.getLocation()); - - triplifyGenes(genotype.getGenes(), geno_item); - - for (Disease phenotype : genotype.getPhenotypes()) { - com.hp.hpl.jena.rdf.model.Resource pheno_item = api.createResource(PrefixFactory.getURIForPrefix(Config.getKeyPrefix()) + itemTmp[1] + "_" + phenotype.getOmimId()); - com.hp.hpl.jena.rdf.model.Resource pheno_obj = api.createResource(PrefixFactory.getURIForPrefix(Config.getKeyPrefix()) + "Item"); - api.addStatement(pheno_item, Predicate.get("rdf:type"), pheno_obj); - - // set Item label - api.addStatement(pheno_item, Predicate.get("rdfs:label"), "hgnc_" + phenotype.getOmimId()); - - // associate Item with Concept - com.hp.hpl.jena.rdf.model.Resource pheno_concept = api.getResource(res.getIsResourceOf().getUri()); - api.addStatement(pheno_item, Predicate.get("coeus:hasConcept"), pheno_concept); - api.addStatement(pheno_concept, Predicate.get("coeus:isConceptOf"), pheno_item); - - // add name/comment - api.addStatement(pheno_item, Predicate.get("rdfs:comment"), phenotype.getName()); - api.addStatement(pheno_item, Predicate.get("dc:description"), phenotype.getName()); - for (String name : phenotype.getNames()) { - api.addStatement(pheno_item, Predicate.get("diseasecard:name"), name); - } - api.addStatement(pheno_item, Predicate.get("diseasecard:omim"), phenotype.getOmimId()); - api.addStatement(pheno_item, Predicate.get("diseasecard:chromosomalLocation"), phenotype.getLocation()); - - //add diseasecard-specific info - api.addStatement(pheno_item, Predicate.get("diseasecard:phenotype"), "true"); - api.addStatement(pheno_item, Predicate.get("diseasecard:hasGenotype"), geno_item); - api.addStatement(geno_item, Predicate.get("diseasecard:hasPhenotype"), pheno_item); - - triplifyGenes(phenotype.getGenes(), pheno_item); - } - - api.addStatement(geno_item, Predicate.get("diseasecard:genotype"), "true"); - } catch (Exception ex) { - if (Config.isDebug()) { - System.out.println("[COEUS][OMIM] Unable to triplify inmemory data"); - Logger.getLogger(OMIMPlugin.class.getName()).log(Level.SEVERE, null, ex); - } - } - } - } - } - - /** - * Handles gene writing into COEUS SDB. - * - * @param genes the list of genes to insert. - * @param item the item where the genes will be associated - * (coeus:isAssociatedTo). - */ - private void triplifyGenes(ArrayList genes, com.hp.hpl.jena.rdf.model.Resource item) { - for (String gene : genes) { - try { - com.hp.hpl.jena.rdf.model.Resource gene_item = api.createResource(PrefixFactory.getURIForPrefix(Config.getKeyPrefix()) + "hgnc_" + gene); - com.hp.hpl.jena.rdf.model.Resource gene_obj = api.createResource(PrefixFactory.getURIForPrefix(Config.getKeyPrefix()) + "Item"); - api.addStatement(gene_item, Predicate.get("rdf:type"), gene_obj); - - // set Item label - api.addStatement(gene_item, Predicate.get("rdfs:label"), api.createResource("item_" + gene)); - - // set Item title - api.addStatement(gene_item, Predicate.get("dc:title"), gene.toUpperCase()); - - // associate Item with Concept - com.hp.hpl.jena.rdf.model.Resource gene_concept = api.getResource(PrefixFactory.getURIForPrefix(Config.getKeyPrefix()) + "concept_HGNC"); - api.addStatement(gene_item, Predicate.get("coeus:hasConcept"), gene_concept); - api.addStatement(gene_concept, Predicate.get("coeus:isConceptOf"), gene_item); - api.addStatement(gene_item, Predicate.get("coeus:isAssociatedTo"), item); - api.addStatement(item, Predicate.get("coeus:isAssociatedTo"), gene_item); - - } catch (Exception ex) { - if (Config.isDebug()) { - System.out.println("[COEUS][OMIM] Unable to triplify gene information"); - Logger.getLogger(OMIMPlugin.class.getName()).log(Level.SEVERE, null, ex); - } - } - } - } -} diff --git a/src/main/java/pt/ua/bioinformatics/coeus/common/Builder.java b/src/main/java/pt/ua/bioinformatics/coeus/common/Builder.java index 0d53f1b..31d1816 100755 --- a/src/main/java/pt/ua/bioinformatics/coeus/common/Builder.java +++ b/src/main/java/pt/ua/bioinformatics/coeus/common/Builder.java @@ -10,7 +10,6 @@ import org.json.simple.parser.JSONParser; import pt.ua.bioinformatics.coeus.data.connect.CSVFactory; import pt.ua.bioinformatics.coeus.data.connect.LinkedDataFactory; -import pt.ua.bioinformatics.coeus.data.connect.PluginFactory; import pt.ua.bioinformatics.coeus.data.connect.RDFFactory; import pt.ua.bioinformatics.coeus.data.connect.ResourceFactory; import pt.ua.bioinformatics.coeus.data.connect.SPARQLFactory; @@ -158,9 +157,7 @@ public static boolean readData(Resource r) { ResourceFactory factory; try { if (!r.isBuilt()) { - if (r.getPublisher().equalsIgnoreCase("plugin")) { - factory = new PluginFactory(r); - } else if (r.getPublisher().equalsIgnoreCase("csv")) { + if (r.getPublisher().equalsIgnoreCase("csv")) { factory = new CSVFactory(r); } else if (r.getPublisher().equalsIgnoreCase("xml")) { factory = new XMLFactory(r); diff --git a/src/main/java/pt/ua/bioinformatics/coeus/data/connect/PluginFactory.java b/src/main/java/pt/ua/bioinformatics/coeus/data/connect/PluginFactory.java deleted file mode 100755 index 2a68860..0000000 --- a/src/main/java/pt/ua/bioinformatics/coeus/data/connect/PluginFactory.java +++ /dev/null @@ -1,86 +0,0 @@ -package pt.ua.bioinformatics.coeus.data.connect; - -import java.util.logging.Level; -import java.util.logging.Logger; -import pt.ua.bioinformatics.coeus.api.API; -import pt.ua.bioinformatics.coeus.api.plugins.OMIMPlugin; -import pt.ua.bioinformatics.coeus.common.Boot; -import pt.ua.bioinformatics.coeus.common.Config; -import pt.ua.bioinformatics.coeus.data.Predicate; -import pt.ua.bioinformatics.coeus.domain.Resource; - -/** - * Data factory for transforming SPARQL data into RDF items using generic - * Triplify. - * - * @author pedrolopes - */ -public class PluginFactory implements ResourceFactory { - - private Resource res; - - public Resource getRes() { - return res; - } - - public void setRes(Resource res) { - this.res = res; - } - - public PluginFactory(Resource r) { - this.res = r; - } - - /** - * Reads SPARQL data according to Resource information. - *

Workflow

    - *
  1. Check if resource is starter/extends
  2. - *
  3. Load SPARQL resource into ResultSet
  4. - *
  5. Start Triplify with factory Resource
  6. - *
  7. Get data for Item key into Triplify
  8. - *
  9. Load data for each InheritedResource property into Triplify hashmap - * based on SPARQL elements
  10. - *
  11. Itemize single item
  12. - *

- */ - public void read() { - String[] divide = res.getEndpoint().split("://"); - String type = divide[0]; - try { - if (type.equals("omim")) { - OMIMPlugin omim = new OMIMPlugin(res); - omim.itemize(); - } - } catch (Exception ex) { - if (Config.isDebug()) { - System.out.println("[COEUS][SPARQLFactory] unable to load data for " + res.getUri()); - Logger.getLogger(PluginFactory.class.getName()).log(Level.SEVERE, null, ex); - } - } - } - - /** - * Updates the resource coeus:built property once the resource finished - * building. - * - * @return success of the operation - */ - public boolean save() { - boolean success = false; - try { - API api = Boot.getAPI(); - com.hp.hpl.jena.rdf.model.Resource resource = api.getResource(this.res.getUri()); - api.addStatement(resource, Predicate.get("coeus:built"), true); - success = true; - if (Config.isDebug()) { - System.out.println("[COEUS][API] Saved resource " + res.getUri()); - } - } catch (Exception ex) { - if (Config.isDebug()) { - System.out.println("[COEUS][API] Unable to save resource " + res.getUri()); - Logger.getLogger(PluginFactory.class.getName()).log(Level.SEVERE, null, ex); - } - } - return success; - } -} diff --git a/src/main/java/pt/ua/bioinformatics/coeus/ext/COEUSActionBeanContext.java b/src/main/java/pt/ua/bioinformatics/coeus/ext/COEUSActionBeanContext.java deleted file mode 100755 index 9ba40d1..0000000 --- a/src/main/java/pt/ua/bioinformatics/coeus/ext/COEUSActionBeanContext.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package pt.ua.bioinformatics.coeus.ext; - -import java.util.ArrayList; -import net.sourceforge.stripes.action.ActionBeanContext; -import pt.ua.bioinformatics.diseasecard.domain.Disease; - -/** - * Context Extender for COEUS Default Actions. - *

Enables the creation of custom context actions in ActionBeans, check - * Stripes Docs for further information.

- * - * @author pedrolopes - */ -public class COEUSActionBeanContext extends ActionBeanContext { - - private static final String DISEASE = "disease"; - - public void setDisease(String key, Object value) { - getRequest().getSession().setAttribute(key, value); - } - - public void setDisease(Object value) { - getRequest().getSession().setAttribute(DISEASE, value); - } - - public T getDisease() { - return (T) getRequest().getSession().getAttribute(DISEASE); - } - - public T getDisease(String key) { - return (T) getRequest().getSession().getAttribute(key); - } - - public T getDiseases() { - return (T) getRequest().getSession().getAttribute(DISEASE); - } - - public T getDiseases(String key) { - return (T) getRequest().getSession().getAttribute(key); - } - - public void setSearchResults(String key, ArrayList value) { - getRequest().getSession().setAttribute(key, value); - } - - public ArrayList getSearchResults(String key) { - return (ArrayList) getRequest().getSession().getAttribute(key); - } - - public void setCurrent(String key, Object value) { - getRequest().getSession().setAttribute(key, value); - } - - @SuppressWarnings("unchecked") - public T getCurrent(String key) { - return (T) getRequest().getSession().getAttribute(key); - } -} diff --git a/src/main/java/pt/ua/bioinformatics/diseasecard/domain/Disease.java b/src/main/java/pt/ua/bioinformatics/diseasecard/domain/Disease.java deleted file mode 100755 index 4045d22..0000000 --- a/src/main/java/pt/ua/bioinformatics/diseasecard/domain/Disease.java +++ /dev/null @@ -1,122 +0,0 @@ -package pt.ua.bioinformatics.diseasecard.domain; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.logging.Level; -import java.util.logging.Logger; -import pt.ua.bioinformatics.coeus.domain.Item; - -/** - * - * @author pedrolopes - */ -public class Disease { - - private int id; - private String name; - private String omimId; - private String location; - private ArrayList genes = new ArrayList(); - private ArrayList names = new ArrayList(); - private ArrayList genotypes = new ArrayList(); - private ArrayList phenotypes = new ArrayList(); - - public ArrayList getGenes() { - return genes; - } - - public String getOmimId() { - return omimId; - } - - public void setOmimId(String omim_id) { - this.omimId = omim_id; - } - - public void setGenes(ArrayList genes) { - this.genes = genes; - } - - public String getLocation() { - return location; - } - - public void setLocation(String location) { - this.location = location; - } - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public ArrayList getPhenotypes() { - return phenotypes; - } - - public void setPhenotypes(ArrayList phenotypes) { - this.phenotypes = phenotypes; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public ArrayList getNames() { - return names; - } - - public void setNames(ArrayList names) { - this.names = names; - } - - /** - * Loads Disease information from SDB based on its key - OMIM code. - * - * @param key - */ - public Disease(int key) { - this.id = key; - this.omimId = String.valueOf(key); - // this.omim = String.valueOf(key); - try { - } catch (Exception ex) { - Logger.getLogger(Item.class.getName()).log(Level.SEVERE, null, ex); - } - } - - public Disease(String name, String omim) { - this.name = name; - this.genotypes = new ArrayList(); - this.phenotypes = new ArrayList(); - this.names = new ArrayList(); - } - - public ArrayList getGenotypes() { - return genotypes; - } - - public void setGenotypes(ArrayList genotypes) { - this.genotypes = genotypes; - } - - @Override - public String toString() { - String response = ""; - - response += this.omimId + "\t" + this.name; - for (Disease s : genotypes) { - response += "\n\t" + s.getName() + " > " + s.getOmimId(); - } - response += "\n\tGenes"; - - return response; - } -} From f0f1f58baa742cfed7ecb999c91084645bb0cbce Mon Sep 17 00:00:00 2001 From: sernadela Date: Thu, 20 Jun 2013 15:05:09 +0100 Subject: [PATCH 02/52] - Add security login to the manager setup --- .../coeus/actions/SeedActionBean.java | 2 +- src/main/resources/config.js | 14 ++-- src/main/resources/joseki.ttl | 2 +- src/main/webapp/WEB-INF/web.xml | 42 +++++++++-- src/main/webapp/login.jsp | 72 +++++++++++++++++++ src/main/webapp/setup/html.jsp | 6 +- src/main/webapp/setup/index.jsp | 1 - 7 files changed, 121 insertions(+), 18 deletions(-) create mode 100644 src/main/webapp/login.jsp diff --git a/src/main/java/pt/ua/bioinformatics/coeus/actions/SeedActionBean.java b/src/main/java/pt/ua/bioinformatics/coeus/actions/SeedActionBean.java index 61d2aaa..0f1d77b 100644 --- a/src/main/java/pt/ua/bioinformatics/coeus/actions/SeedActionBean.java +++ b/src/main/java/pt/ua/bioinformatics/coeus/actions/SeedActionBean.java @@ -17,7 +17,7 @@ * * @author sernadela */ -@UrlBinding("/seed/") +@UrlBinding("/manager/") public class SeedActionBean implements ActionBean{ private static final String VIEW="/setup/index.jsp"; private String name; diff --git a/src/main/resources/config.js b/src/main/resources/config.js index 481bca1..07f0d06 100644 --- a/src/main/resources/config.js +++ b/src/main/resources/config.js @@ -1,14 +1,14 @@ { "config": { -"name": "proteinator", - "description": "COEUS Protein Data Aggregator (Proteinator)", +"name": "coeus.NA", + "description": "COEUS News Aggregator", "keyprefix":"coeus", "version": "1.0a", - "ontology": "http://bioinformatics.ua.pt/diseasecard/diseasecard.owl", - "setup": "proteinator/setup.rdf", - "sdb":"proteinator/sdb.ttl", - "predicates":"proteinator/predicates.csv", - "built": false, + "ontology": "http://bioinformatics.ua.pt/coeus/ontology/", + "setup": "newsaggregator/setup.rdf", + "sdb":"newsaggregator/sdb.ttl", + "predicates":"newsaggregator/predicates.csv", + "built": true, "debug": true, "apikey":"coeus|uavr", "environment": "production" diff --git a/src/main/resources/joseki.ttl b/src/main/resources/joseki.ttl index 8f1b04f..c40d69c 100644 --- a/src/main/resources/joseki.ttl +++ b/src/main/resources/joseki.ttl @@ -43,7 +43,7 @@ sdb:Model rdfs:subClassOf ja:Model . <#sdb> rdf:type sdb:DatasetStore ; ## Number of concurrent connections allowed to this dataset. - joseki:poolSize 200; + joseki:poolSize 2; sdb:store <#store> . <#store> rdf:type sdb:Store ; diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index a12d0c5..1008314 100755 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -34,7 +34,8 @@ org.joseki.http.Servlet org.joseki.rdfserver.config - joseki.ttl + + joseki.ttl @@ -49,7 +50,8 @@ config-file - classes/pubby.ttl + + classes/pubby.ttl @@ -64,13 +66,13 @@ de.fuberlin.wiwiss.pubby.servlets.PageURLServlet 1 - + WebURLServlet de.fuberlin.wiwiss.pubby.servlets.PageURLServlet 1 - + WebURLServlet /resource/* @@ -120,9 +122,39 @@ - pt.ua.bioinformatics.coeus.common.HttpListener + pt.ua.bioinformatics.coeus.common.HttpListener + + + + + Secured Setup + + /setup/* + /manager/* + GET + POST + + + + Only managers use this app + + manager-gui + + + + manager-gui + + + FORM + + /login.jsp + /login.jsp?f=error + + + + index.jsp diff --git a/src/main/webapp/login.jsp b/src/main/webapp/login.jsp new file mode 100644 index 0000000..456304f --- /dev/null +++ b/src/main/webapp/login.jsp @@ -0,0 +1,72 @@ + +<%@include file="/layout/style.jsp" %> + + +<% + String err = request.getParameter("f"); +%> + + + + + Setup Login + + + + +
+ + + +
+ + \ No newline at end of file diff --git a/src/main/webapp/setup/html.jsp b/src/main/webapp/setup/html.jsp index 5e2b6ca..b2cb90a 100644 --- a/src/main/webapp/setup/html.jsp +++ b/src/main/webapp/setup/html.jsp @@ -25,9 +25,9 @@ @@ -701,7 +742,7 @@ diff --git a/src/main/webapp/setup/addseed.jsp b/src/main/webapp/setup/addseed.jsp index db064f6..b6c9a4d 100644 --- a/src/main/webapp/setup/addseed.jsp +++ b/src/main/webapp/setup/addseed.jsp @@ -23,7 +23,7 @@ //if the type mode is EDIT if (penulPath() === 'edit') { $('#type').html("Edit Seed"); - $('#submit').html('Edit '); + $('#submit').html('Save '); var query = initSparqlerQuery(); var q = "SELECT ?label ?title {" + path + " dc:title ?title . " + path + " rdfs:label ?label . }"; @@ -126,6 +126,11 @@ +

Seed URI - coeus:

@@ -147,7 +152,7 @@
- +
diff --git a/src/main/webapp/setup/concepts.jsp b/src/main/webapp/setup/concepts.jsp index 984f1d1..7fbef9e 100644 --- a/src/main/webapp/setup/concepts.jsp +++ b/src/main/webapp/setup/concepts.jsp @@ -32,7 +32,8 @@ var seed = result[0].seed.value; seed = "coeus:" + splitURIPrefix(seed).value; $('#breadSeed').html('Seed /'); - $('#breadEntity').html('Entities /'); + $('#breadEntities').html('Entities /'); + } function fillListOfConcepts(result) { for (var key in result) { @@ -41,10 +42,10 @@ + result[key].concept.value + '' + result[key].c.value + '' + '
' - + 'Edit' - + '' + + 'Edit ' + + '' + '
' - + ' Resources' + + ' Show Resources ' +' ' +' - + diff --git a/src/main/webapp/setup/config.jsp b/src/main/webapp/setup/config.jsp index f3887b1..7a841d3 100644 --- a/src/main/webapp/setup/config.jsp +++ b/src/main/webapp/setup/config.jsp @@ -147,7 +147,7 @@ "version": $('#Version').val(), "ontology": $('#Ontology').val(), "setup": $('#Setup').val(), - "sdb": "newsaggregator/sdb.ttl", + "sdb": "sdb.ttl", "predicates": "predicates.csv", "built": $('#Built').is(':checked'), "debug": $('#Debug').is(':checked'), @@ -289,10 +289,10 @@

In this section you will give some information to complete some setup files for COEUS.

To begin press the Start Wizard button.

- Start Wizard + Start Wizard

If you do not want to change the configurations files, please skip this wizard.

- Skip + Skip
@@ -314,7 +314,7 @@ @@ -431,7 +431,7 @@
@@ -525,7 +525,7 @@
@@ -557,10 +557,10 @@
- +
@@ -569,14 +569,14 @@

In order to save your progress press the Save button, please.

Warning: If you leaves this wizard without save it, some configurations will be lost.

- +

After saving the configurations you can start build the model for your application:

- Build Model + Build Model
@@ -608,7 +608,7 @@ diff --git a/src/main/webapp/setup/entities.jsp b/src/main/webapp/setup/entities.jsp index eff58a5..3e165eb 100644 --- a/src/main/webapp/setup/entities.jsp +++ b/src/main/webapp/setup/entities.jsp @@ -44,10 +44,10 @@ + json.results.bindings[key].entity.value + '' + json.results.bindings[key].e.value + '' + '
' - + 'Edit' - + '' + + 'Edit ' + + '' + '
' - + ' View Concepts' + + ' Show Concepts ' //+ 'Remove' + ''; $('#entities').append(a); @@ -77,6 +77,8 @@ @@ -89,7 +91,7 @@ @@ -129,7 +131,7 @@ diff --git a/src/main/webapp/setup/environments.jsp b/src/main/webapp/setup/environments.jsp index 979e445..d6d47e4 100644 --- a/src/main/webapp/setup/environments.jsp +++ b/src/main/webapp/setup/environments.jsp @@ -27,10 +27,11 @@ var n = parseInt(r) + 1; $('#environments').append('' + (n) + '' + value + 'DISABLED' + '
' - + '' + + '' + '
' - + 'Configuration ' - + 'Enable' + + 'Configuration ' + + 'Clean DB ' + + 'Enable ' + ''); } callURL("../../config/getconfig/", changeStatus); @@ -78,9 +79,8 @@ } function selectEnv(env) { - + $('#cleanModalLabel').html(env); $('#removeModalLabel').html(env); - console.log($('#removeModalLabel').html()); } function removeEnv() { callURL("../../config/delenv/" + $('#removeModalLabel').html(), removeEnvResult); @@ -88,6 +88,16 @@ function removeEnvResult(result) { callURL("../../config/listenv/", fillEnvironments); } + function cleanDB() { + callURL("../../config/cleandb/" + $('#cleanModalLabel').html(), cleanDBResult); + } + function cleanDBResult(result) { + if (result.status === 100) { + $('#info').html(generateHtmlMessage("Success!", result.message, "alert-success")); + } else { + $('#info').html(generateHtmlMessage("Warning!", result.message)); + } + } @@ -105,16 +115,17 @@
- +
+

ATTENTION: Every change in this page needs a server restart.

List of Environments

@@ -158,6 +169,28 @@
+ + + @@ -220,7 +224,7 @@ diff --git a/src/main/webapp/setup/resources.jsp b/src/main/webapp/setup/resources.jsp index 2b45299..dac5f8a 100644 --- a/src/main/webapp/setup/resources.jsp +++ b/src/main/webapp/setup/resources.jsp @@ -34,8 +34,8 @@ seed = "coeus:" + splitURIPrefix(seed).value; entity = "coeus:" + splitURIPrefix(entity).value; $('#breadSeed').html('Seed /'); - $('#breadEntity').html('Entities /'); - $('#breadConcept').html('Concepts /'); + $('#breadEntities').html('Entities /'); + $('#breadConcepts').html('Concepts /'); } function fillListOfResources(result) { for (var key = 0, size = result.length; key < size; key++) { @@ -47,8 +47,8 @@ + result[key].c.value + '' + result[key].order.value + '' //+ '
' - + ' ' - + 'Configuration ' + + ' ' + + 'Configuration ' //+ '
' //+ ' Selectors' //+ 'Remove' @@ -85,9 +85,11 @@
@@ -96,7 +98,7 @@
@@ -137,7 +139,7 @@ diff --git a/src/main/webapp/setup/seeds.jsp b/src/main/webapp/setup/seeds.jsp index 5cd39f6..8418f14 100644 --- a/src/main/webapp/setup/seeds.jsp +++ b/src/main/webapp/setup/seeds.jsp @@ -28,7 +28,7 @@ var seed=getPrefix(splitedURI.namespace)+':'+splitedURI.value; var a = '
  • ' - +'Select' + +'Choose ' +'

    '+result[key].s.value+'

    ' +'URI: '+seed+'' +'' @@ -72,12 +72,16 @@

    Please, choose the seed:

    +
      @@ -104,7 +108,7 @@
    From d1ffbeda7905811b89da9088d47851fed4a29634 Mon Sep 17 00:00:00 2001 From: sernadela Date: Thu, 29 Aug 2013 17:56:52 +0100 Subject: [PATCH 28/52] - Setup: Add Enter keyboard key when add or edit - Setup: Fix Resource extensions to only allow concepts from same seed - Setup: Fix LinkedData links to local instance - Setup: Show the selected environment on all pages --- src/main/webapp/setup/addconcept.jsp | 41 +++++-- src/main/webapp/setup/addentity.jsp | 31 ++++-- src/main/webapp/setup/addresource.jsp | 53 +++++---- src/main/webapp/setup/addseed.jsp | 26 +++-- src/main/webapp/setup/concepts.jsp | 13 +-- src/main/webapp/setup/entities.jsp | 15 ++- src/main/webapp/setup/index.jsp | 11 +- src/main/webapp/setup/resources.jsp | 12 ++- src/main/webapp/setup/seeds.jsp | 150 +++++++++++++------------- 9 files changed, 214 insertions(+), 138 deletions(-) diff --git a/src/main/webapp/setup/addconcept.jsp b/src/main/webapp/setup/addconcept.jsp index 5dad22f..047585d 100644 --- a/src/main/webapp/setup/addconcept.jsp +++ b/src/main/webapp/setup/addconcept.jsp @@ -18,14 +18,17 @@ //header name var path = lastPath(); - $('#header').html('

    ' + path + ' env..

    '); - var qconcept = "SELECT DISTINCT ?seed {" + path + " coeus:isIncludedIn ?seed }"; - queryToResult(qconcept, fillBreadcumb); + callURL("../../../config/getconfig/", fillHeader); + //Associate Enter key: + document.onkeypress = keyboard; //if the type mode is EDIT if (penulPath() === 'edit') { $('#type').html("Edit Concept"); $('#submit').html('Save '); + + var qconcept = "SELECT DISTINCT ?seed ?entity {" + path + " coeus:hasEntity ?entity . ?entity coeus:isIncludedIn ?seed }"; + queryToResult(qconcept, fillBreadcumbEdit); var query = initSparqlerQuery(); var q = "SELECT ?title ?label {" + path + " dc:title ?title . " + path + " rdfs:label ?label . }"; @@ -33,7 +36,6 @@ {success: function(json) { //var resultTitle = json.results.bindings[0].title; console.log(json); - $('#header').html('

    ' + path + ' env..

    '); //PUT VALUES IN THE INPUT FIELD $('#title').val(json.results.bindings[0].title.value); changeURI(json.results.bindings[0].title.value); @@ -46,14 +48,23 @@ //$('#commentForm').append(''); }} ); + }else{ + var qconcept = "SELECT DISTINCT ?seed {" + path + " coeus:isIncludedIn ?seed }"; + queryToResult(qconcept, fillBreadcumbAdd); } //end of EDIT //activate tooltip (bootstrap-tooltip.js is need) $('.icon-question-sign').tooltip(); }); + + // Callback to generate the pages header + function fillHeader(result) { + $('#header').html('

    ' + lastPath() + ' ' + result.config.environment + '

    '); + } - $('#submit').click(function() { + $('#submit').click(testMode); + function testMode() { //EDIT if (penulPath() === 'edit') { update(); @@ -69,7 +80,7 @@ window.location = document.referrer; } - }); + } function submit() { @@ -124,13 +135,27 @@ //var specialChars = "!@#$^&%*()+=-[]\/{}|:<>?,. "; document.getElementById('uri').innerHTML = 'coeus:concept_' + value.split(' ').join('_'); } - function fillBreadcumb(result) { + function fillBreadcumbAdd(result) { var seed = result[0].seed.value; seed = "coeus:" + splitURIPrefix(seed).value; $('#breadSeed').html('Seed /'); $('#breadEntities').html('Entities /'); $('#breadConcepts').html('Concepts /'); } + function fillBreadcumbEdit(result) { + var seed = result[0].seed.value; + seed = "coeus:" + splitURIPrefix(seed).value; + var entity = result[0].entity.value; + entity = "coeus:" + splitURIPrefix(entity).value; + $('#breadSeed').html('Dashboard /'); + $('#breadEntities').html('Entities /'); + $('#breadConcepts').html('Concepts /'); + } + function keyboard(event) { + //Enter key pressed + if (event.charCode === 13) + testMode(); + } @@ -148,7 +173,7 @@
  • Concept
  • -

    Concept URI - coeus:

    +

    Concept URI - coeus:

    New Concept

    diff --git a/src/main/webapp/setup/addentity.jsp b/src/main/webapp/setup/addentity.jsp index 765c3c3..9f60152 100644 --- a/src/main/webapp/setup/addentity.jsp +++ b/src/main/webapp/setup/addentity.jsp @@ -18,10 +18,12 @@ //header name var path = lastPath(); - $('#header').html('

    ' + path + ' env..

    '); - $('#breadSeed').html('Seed / '); - $('#breadEntities').html('Entities / '); - + callURL("../../../config/getconfig/", fillHeader); + $('#breadSeed').html('Dashboard / '); + $('#breadEntities').html('Entities / '); + + //Associate Enter key: + document.onkeypress = keyboard; //if the type mode is EDIT if (penulPath() === 'edit') { @@ -34,7 +36,6 @@ {success: function(json) { //var resultTitle = json.results.bindings[0].title; console.log(json); - $('#header').html('

    ' + path + ' env..

    '); //PUT VALUES IN THE INPUT FIELD $('#title').val(json.results.bindings[0].title.value); changeURI(json.results.bindings[0].title.value); @@ -54,7 +55,13 @@ $('.icon-question-sign').tooltip(); }); - $('#submit').click(function() { + // Callback to generate the pages header + function fillHeader(result) { + $('#header').html('

    ' + lastPath() + ' ' + result.config.environment + '

    '); + } + + $('#submit').click(testMode); + function testMode() { //EDIT if (penulPath() === 'edit') { update(); @@ -70,8 +77,7 @@ window.location = document.referrer; } - }); - + } function submit() { var type = 'Entity'; @@ -133,6 +139,11 @@ //var specialChars = "!@#$^&%*()+=-[]\/{}|:<>?,. "; document.getElementById('uri').innerHTML = 'coeus:entity_' + value.split(' ').join('_'); } + function keyboard(event) { + //Enter key pressed + if (event.charCode === 13) + testMode(); + } @@ -142,14 +153,14 @@ - -

    Resource URI - coeus:

    +

    Resource URI - coeus:

    @@ -600,12 +615,12 @@
    - - + + +
    diff --git a/src/main/webapp/setup/addseed.jsp b/src/main/webapp/setup/addseed.jsp index b6c9a4d..eb1e642 100644 --- a/src/main/webapp/setup/addseed.jsp +++ b/src/main/webapp/setup/addseed.jsp @@ -16,6 +16,9 @@ $(document).ready(function() { + //Associate Enter key: + document.onkeypress = keyboard; + //header name var path = lastPath(); $('#header').html('

    COEUS env..

    '); @@ -51,7 +54,9 @@ $('.icon-question-sign').tooltip(); }); - $('#submit').click(function() { + $('#submit').click(testMode); + + function testMode() { //EDIT if (penulPath() === 'edit') { update(); @@ -67,7 +72,7 @@ window.location = document.referrer; } - }); + } function submit() { @@ -110,13 +115,18 @@ var urlUpdate = "../../../api/" + getApiKey() + "/update/"; if ($('#oldLabel').val() !== $('#label').val()) callAPI(urlUpdate + lastPath() + "/" + "rdfs:label" + "/xsd:string:" + $('#oldLabel').val() + ",xsd:string:" + $('#label').val(), '#result'); - + } function changeURI(value) { //var specialChars = "!@#$^&%*()+=-[]\/{}|:<>?,. "; document.getElementById('uri').innerHTML = 'coeus:seed_' + value.split(' ').join('_'); } + function keyboard(event) { + //Enter key pressed + if (event.charCode === 13) + testMode(); + } @@ -131,7 +141,7 @@
  • Seeds /
  • Seed
  • -

    Seed URI - coeus:

    +

    Seed URI - coeus:

    New Seed:

    @@ -156,10 +166,10 @@
    - +
    diff --git a/src/main/webapp/setup/concepts.jsp b/src/main/webapp/setup/concepts.jsp index 7fbef9e..de5bcbe 100644 --- a/src/main/webapp/setup/concepts.jsp +++ b/src/main/webapp/setup/concepts.jsp @@ -12,7 +12,10 @@ @@ -79,55 +79,55 @@
    -
    +
      - +
    - - - - - -
    - +
    +
    + + + Driver: + +
    + Host: + +
    + DB Name: + + Port: + +
    + Login: + + + +
    +
    + + + + +
    From 893741cc6000fe75e8738f38bdf57108eac09f02 Mon Sep 17 00:00:00 2001 From: sernadela Date: Wed, 4 Sep 2013 10:04:58 +0100 Subject: [PATCH 30/52] - Setup: Fix footer --- src/main/webapp/layout/html.jsp | 9 ++--- src/main/webapp/setup/addresource.jsp | 50 +++++++++++++++------------ src/main/webapp/setup/concepts.jsp | 2 +- src/main/webapp/setup/config.jsp | 2 +- src/main/webapp/setup/entities.jsp | 2 +- src/main/webapp/setup/html.jsp | 41 +++++++++++----------- src/main/webapp/setup/resources.jsp | 2 +- 7 files changed, 57 insertions(+), 51 deletions(-) diff --git a/src/main/webapp/layout/html.jsp b/src/main/webapp/layout/html.jsp index 667d9d5..fe267aa 100644 --- a/src/main/webapp/layout/html.jsp +++ b/src/main/webapp/layout/html.jsp @@ -51,7 +51,7 @@
    - + diff --git a/src/main/webapp/setup/config.jsp b/src/main/webapp/setup/config.jsp index 7a841d3..78938a1 100644 --- a/src/main/webapp/setup/config.jsp +++ b/src/main/webapp/setup/config.jsp @@ -613,7 +613,7 @@ - + diff --git a/src/main/webapp/setup/entities.jsp b/src/main/webapp/setup/entities.jsp index aaa439a..8c6c7a8 100644 --- a/src/main/webapp/setup/entities.jsp +++ b/src/main/webapp/setup/entities.jsp @@ -143,6 +143,6 @@ - + diff --git a/src/main/webapp/setup/html.jsp b/src/main/webapp/setup/html.jsp index 0ce55a6..8a7f20a 100644 --- a/src/main/webapp/setup/html.jsp +++ b/src/main/webapp/setup/html.jsp @@ -6,7 +6,7 @@ " /> "> - + <s:layout-component name="title">COEUS Setup</s:layout-component> @@ -34,7 +34,7 @@ @@ -59,8 +59,7 @@ - - + + + + \ No newline at end of file diff --git a/src/main/webapp/setup/resources.jsp b/src/main/webapp/setup/resources.jsp index 66d879a..b1df7c2 100644 --- a/src/main/webapp/setup/resources.jsp +++ b/src/main/webapp/setup/resources.jsp @@ -148,6 +148,6 @@ - + From cb6881a4f21050bb2502f7c43a341510dcce1eba Mon Sep 17 00:00:00 2001 From: sernadela Date: Wed, 4 Sep 2013 16:00:29 +0100 Subject: [PATCH 31/52] - Setup: Fix resource duplication (done by built property) --- .../pt/ua/bioinformatics/coeus/data/connect/SQLFactory.java | 3 +++ src/main/webapp/setup/config.jsp | 6 +++--- src/main/webapp/setup/html.jsp | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/pt/ua/bioinformatics/coeus/data/connect/SQLFactory.java b/src/main/java/pt/ua/bioinformatics/coeus/data/connect/SQLFactory.java index 3cbb8fa..6450b48 100755 --- a/src/main/java/pt/ua/bioinformatics/coeus/data/connect/SQLFactory.java +++ b/src/main/java/pt/ua/bioinformatics/coeus/data/connect/SQLFactory.java @@ -1,5 +1,6 @@ package pt.ua.bioinformatics.coeus.data.connect; +import com.hp.hpl.jena.rdf.model.Statement; import java.sql.ResultSet; import java.util.ArrayList; import java.util.HashMap; @@ -212,6 +213,8 @@ public boolean save() { try { API api = Boot.getAPI(); com.hp.hpl.jena.rdf.model.Resource resource = api.getResource(this.res.getUri()); + Statement statementToRemove=api.getModel().createLiteralStatement(resource, Predicate.get("coeus:built"), false); + api.removeStatement(statementToRemove); api.addStatement(resource, Predicate.get("coeus:built"), true); success = true; if (Config.isDebug()) { diff --git a/src/main/webapp/setup/config.jsp b/src/main/webapp/setup/config.jsp index 78938a1..e129bfd 100644 --- a/src/main/webapp/setup/config.jsp +++ b/src/main/webapp/setup/config.jsp @@ -284,9 +284,9 @@
  • Prefixes
  • Finish
  • -
    -
    -
    +
    +
    +

    In this section you will give some information to complete some setup files for COEUS.

    To begin press the Start Wizard button.

    Start Wizard diff --git a/src/main/webapp/setup/html.jsp b/src/main/webapp/setup/html.jsp index 8a7f20a..0f5e95b 100644 --- a/src/main/webapp/setup/html.jsp +++ b/src/main/webapp/setup/html.jsp @@ -83,7 +83,7 @@
    -
    +
    Back to top

     

    COEUS Setup Beta From 4eb8a7947998ddedaa5ac933ce5c02ea15e01eb3 Mon Sep 17 00:00:00 2001 From: sernadela Date: Thu, 5 Sep 2013 15:03:28 +0100 Subject: [PATCH 32/52] - Setup: Added Rebuild and Unbuild options - Setup: Changed apikey to work correctly from the config.js file - Setup: Fix the resource build duplication in all Factories. - Setup: Changed CSVFactory to use always the guessDelimiter function. --- .../coeus/actions/ConfigActionBean.java | 20 +++++++- .../coeus/actions/UpdateActionBean.java | 2 +- .../coeus/data/connect/CSVFactory.java | 51 ++++--------------- .../coeus/data/connect/JSONFactory.java | 3 ++ .../coeus/data/connect/LinkedDataFactory.java | 3 ++ .../coeus/data/connect/RDFFactory.java | 3 ++ .../coeus/data/connect/SPARQLFactory.java | 3 ++ .../coeus/data/connect/XMLFactory.java | 3 ++ src/main/webapp/assets/js/coeus.api.js | 8 ++- src/main/webapp/setup/addconcept.jsp | 2 + src/main/webapp/setup/addentity.jsp | 2 + src/main/webapp/setup/addresource.jsp | 44 ++++++++-------- src/main/webapp/setup/addseed.jsp | 9 +++- src/main/webapp/setup/concepts.jsp | 2 + src/main/webapp/setup/entities.jsp | 3 +- src/main/webapp/setup/index.jsp | 37 ++++++++++++-- src/main/webapp/setup/resources.jsp | 2 + src/main/webapp/setup/seeds.jsp | 7 ++- 18 files changed, 132 insertions(+), 72 deletions(-) diff --git a/src/main/java/pt/ua/bioinformatics/coeus/actions/ConfigActionBean.java b/src/main/java/pt/ua/bioinformatics/coeus/actions/ConfigActionBean.java index afb72fe..0dcc9ab 100644 --- a/src/main/java/pt/ua/bioinformatics/coeus/actions/ConfigActionBean.java +++ b/src/main/java/pt/ua/bioinformatics/coeus/actions/ConfigActionBean.java @@ -103,9 +103,27 @@ public Resolution handle() { * @return */ public Resolution getconfig() { - Boot.start(); + Config.load(); return new StreamingResolution("application/json", Config.getFile().toJSONString()); } + + /** + * Build (Boot.start() call) + * + * @return + */ + public Resolution build() { + JSONObject result = new JSONObject(); + try { + Boot.start(); + result.put("status", 100); + result.put("message", "[COEUS][API][ConfigActionBean] Build done. "); + } catch (Exception e) { + result.put("status", 201); + result.put("message", "[COEUS][API][ConfigActionBean] Exception: "+e); + } + return new StreamingResolution("application/json", result.toJSONString()); + } /** * Cleans the DB of one environment (method) diff --git a/src/main/java/pt/ua/bioinformatics/coeus/actions/UpdateActionBean.java b/src/main/java/pt/ua/bioinformatics/coeus/actions/UpdateActionBean.java index c89a702..7174ecb 100644 --- a/src/main/java/pt/ua/bioinformatics/coeus/actions/UpdateActionBean.java +++ b/src/main/java/pt/ua/bioinformatics/coeus/actions/UpdateActionBean.java @@ -108,7 +108,7 @@ public Resolution handle() { if (sub.indexOf(":") > 1) { try { if (pred.indexOf(":") > 1) { - System.err.println(old_obj+","+new_obj); + System.err.println(old_obj+" , "+new_obj); // test old_obj String xsd = "http://www.w3.org/2001/XMLSchema#"; Statement statToRemove = null; diff --git a/src/main/java/pt/ua/bioinformatics/coeus/data/connect/CSVFactory.java b/src/main/java/pt/ua/bioinformatics/coeus/data/connect/CSVFactory.java index 961f554..b21a0fb 100755 --- a/src/main/java/pt/ua/bioinformatics/coeus/data/connect/CSVFactory.java +++ b/src/main/java/pt/ua/bioinformatics/coeus/data/connect/CSVFactory.java @@ -1,6 +1,7 @@ package pt.ua.bioinformatics.coeus.data.connect; import au.com.bytecode.opencsv.CSVReader; +import com.hp.hpl.jena.rdf.model.Statement; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; @@ -91,17 +92,9 @@ public void read() { reader = new CSVReader(in, csvDelimiter, defaultCsvQuotes, defaultCsvHeader); } else { String[] csvKeys = res.getQuery().split("\\|"); - char querySeparator = csvKeys[0].charAt(0); char queryQuotes = csvKeys[1].charAt(0); - char queryLinesSkip = csvKeys[2].charAt(0); - - //Fix that - if (querySeparator == 't') { - querySeparator = '\t'; - } - if (querySeparator == 'n') { - querySeparator = '\n'; - } + char queryLinesSkip = csvKeys[0].charAt(0); + char querySeparator = guessDelimiter(u, queryQuotes, queryLinesSkip); //System.out.println(res.getQuery() + " - " +querySeparator+ queryQuotes + queryLinesSkip); reader = new CSVReader(in, querySeparator, queryQuotes, queryLinesSkip); @@ -147,17 +140,9 @@ public void read() { reader = new CSVReader(in, csvDelimiter, defaultCsvQuotes, defaultCsvHeader); } else { String[] csvKeys = res.getQuery().split("\\|"); - char querySeparator = csvKeys[0].charAt(0); char queryQuotes = csvKeys[1].charAt(0); - char queryLinesSkip = csvKeys[2].charAt(0); - - //Fix that - if (querySeparator == 't') { - querySeparator = '\t'; - } - if (querySeparator == 'n') { - querySeparator = '\n'; - } + char queryLinesSkip = csvKeys[0].charAt(0); + char querySeparator = guessDelimiter(u, queryQuotes, queryLinesSkip); //System.out.println(res.getQuery() + " - " +querySeparator+ queryQuotes + queryLinesSkip); reader = new CSVReader(in, querySeparator, queryQuotes, queryLinesSkip); @@ -195,17 +180,9 @@ public void read() { reader = new CSVReader(in, csvDelimiter, defaultCsvQuotes, defaultCsvHeader); } else { String[] csvKeys = res.getQuery().split("\\|"); - char querySeparator = csvKeys[0].charAt(0); char queryQuotes = csvKeys[1].charAt(0); - char queryLinesSkip = csvKeys[2].charAt(0); - - //Fix that - if (querySeparator == 't') { - querySeparator = '\t'; - } - if (querySeparator == 'n') { - querySeparator = '\n'; - } + char queryLinesSkip = csvKeys[0].charAt(0); + char querySeparator = guessDelimiter(u, queryQuotes, queryLinesSkip); //System.out.println(res.getQuery() + " - " +querySeparator+ queryQuotes + queryLinesSkip); reader = new CSVReader(in, querySeparator, queryQuotes, queryLinesSkip); @@ -258,17 +235,9 @@ public void read() { reader = new CSVReader(in, csvDelimiter, defaultCsvQuotes, defaultCsvHeader); } else { String[] csvKeys = res.getQuery().split("\\|"); - char querySeparator = csvKeys[0].charAt(0); char queryQuotes = csvKeys[1].charAt(0); - char queryLinesSkip = csvKeys[2].charAt(0); - - //Fix that - if (querySeparator == 't') { - querySeparator = '\t'; - } - if (querySeparator == 'n') { - querySeparator = '\n'; - } + char queryLinesSkip = csvKeys[0].charAt(0); + char querySeparator = guessDelimiter(u, queryQuotes, queryLinesSkip); //System.out.println(res.getQuery() + " - " + querySeparator + queryQuotes + queryLinesSkip); reader = new CSVReader(in, querySeparator, queryQuotes, queryLinesSkip); @@ -325,6 +294,8 @@ public boolean save() { try { API api = Boot.getAPI(); com.hp.hpl.jena.rdf.model.Resource resource = api.getResource(this.res.getUri()); + Statement statementToRemove=api.getModel().createLiteralStatement(resource, Predicate.get("coeus:built"), false); + api.removeStatement(statementToRemove); api.addStatement(resource, Predicate.get("coeus:built"), true); success = true; if (Config.isDebug()) { diff --git a/src/main/java/pt/ua/bioinformatics/coeus/data/connect/JSONFactory.java b/src/main/java/pt/ua/bioinformatics/coeus/data/connect/JSONFactory.java index 04b15e5..4d4ee47 100644 --- a/src/main/java/pt/ua/bioinformatics/coeus/data/connect/JSONFactory.java +++ b/src/main/java/pt/ua/bioinformatics/coeus/data/connect/JSONFactory.java @@ -4,6 +4,7 @@ */ package pt.ua.bioinformatics.coeus.data.connect; +import com.hp.hpl.jena.rdf.model.Statement; import com.jayway.jsonpath.JsonPath; import java.io.InputStreamReader; import java.net.URL; @@ -270,6 +271,8 @@ public boolean save() { try { API api = Boot.getAPI(); com.hp.hpl.jena.rdf.model.Resource resource = api.getResource(this.res.getUri()); + Statement statementToRemove=api.getModel().createLiteralStatement(resource, Predicate.get("coeus:built"), false); + api.removeStatement(statementToRemove); api.addStatement(resource, Predicate.get("coeus:built"), true); success = true; if (Config.isDebug()) { diff --git a/src/main/java/pt/ua/bioinformatics/coeus/data/connect/LinkedDataFactory.java b/src/main/java/pt/ua/bioinformatics/coeus/data/connect/LinkedDataFactory.java index 9293483..7663441 100644 --- a/src/main/java/pt/ua/bioinformatics/coeus/data/connect/LinkedDataFactory.java +++ b/src/main/java/pt/ua/bioinformatics/coeus/data/connect/LinkedDataFactory.java @@ -4,6 +4,7 @@ */ package pt.ua.bioinformatics.coeus.data.connect; +import com.hp.hpl.jena.rdf.model.Statement; import java.net.URL; import java.net.URLConnection; import java.util.HashMap; @@ -115,6 +116,8 @@ public boolean save() { try { API api = Boot.getAPI(); com.hp.hpl.jena.rdf.model.Resource resource = api.getResource(this.res.getUri()); + Statement statementToRemove=api.getModel().createLiteralStatement(resource, Predicate.get("coeus:built"), false); + api.removeStatement(statementToRemove); api.addStatement(resource, Predicate.get("coeus:built"), true); success = true; if (Config.isDebug()) { diff --git a/src/main/java/pt/ua/bioinformatics/coeus/data/connect/RDFFactory.java b/src/main/java/pt/ua/bioinformatics/coeus/data/connect/RDFFactory.java index fb55b8c..c1e6ab2 100644 --- a/src/main/java/pt/ua/bioinformatics/coeus/data/connect/RDFFactory.java +++ b/src/main/java/pt/ua/bioinformatics/coeus/data/connect/RDFFactory.java @@ -8,6 +8,7 @@ import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.ModelFactory; +import com.hp.hpl.jena.rdf.model.Statement; import com.hp.hpl.jena.util.iterator.ExtendedIterator; import java.net.URL; import java.net.URLConnection; @@ -158,6 +159,8 @@ public boolean save() { boolean success = false; try { com.hp.hpl.jena.rdf.model.Resource resource = api.getResource(this.res.getUri()); + Statement statementToRemove=api.getModel().createLiteralStatement(resource, Predicate.get("coeus:built"), false); + api.removeStatement(statementToRemove); api.addStatement(resource, Predicate.get("coeus:built"), true); success = true; if (Config.isDebug()) { diff --git a/src/main/java/pt/ua/bioinformatics/coeus/data/connect/SPARQLFactory.java b/src/main/java/pt/ua/bioinformatics/coeus/data/connect/SPARQLFactory.java index 4b814ae..d178ab2 100755 --- a/src/main/java/pt/ua/bioinformatics/coeus/data/connect/SPARQLFactory.java +++ b/src/main/java/pt/ua/bioinformatics/coeus/data/connect/SPARQLFactory.java @@ -6,6 +6,7 @@ import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.query.Syntax; +import com.hp.hpl.jena.rdf.model.Statement; import java.util.ArrayList; import java.util.HashMap; import java.util.logging.Level; @@ -159,6 +160,8 @@ public boolean save() { try { API api = Boot.getAPI(); com.hp.hpl.jena.rdf.model.Resource resource = api.getResource(this.res.getUri()); + Statement statementToRemove=api.getModel().createLiteralStatement(resource, Predicate.get("coeus:built"), false); + api.removeStatement(statementToRemove); api.addStatement(resource, Predicate.get("coeus:built"), true); success = true; if (Config.isDebug()) { diff --git a/src/main/java/pt/ua/bioinformatics/coeus/data/connect/XMLFactory.java b/src/main/java/pt/ua/bioinformatics/coeus/data/connect/XMLFactory.java index ac18057..918921e 100755 --- a/src/main/java/pt/ua/bioinformatics/coeus/data/connect/XMLFactory.java +++ b/src/main/java/pt/ua/bioinformatics/coeus/data/connect/XMLFactory.java @@ -1,5 +1,6 @@ package pt.ua.bioinformatics.coeus.data.connect; +import com.hp.hpl.jena.rdf.model.Statement; import java.net.URL; import java.net.URLEncoder; import java.util.HashMap; @@ -277,6 +278,8 @@ public boolean save() { try { API api = Boot.getAPI(); com.hp.hpl.jena.rdf.model.Resource resource = api.getResource(this.res.getUri()); + Statement statementToRemove=api.getModel().createLiteralStatement(resource, Predicate.get("coeus:built"), false); + api.removeStatement(statementToRemove); api.addStatement(resource, Predicate.get("coeus:built"), true); success = true; if (Config.isDebug()) { diff --git a/src/main/webapp/assets/js/coeus.api.js b/src/main/webapp/assets/js/coeus.api.js index c992104..189cebc 100644 --- a/src/main/webapp/assets/js/coeus.api.js +++ b/src/main/webapp/assets/js/coeus.api.js @@ -158,8 +158,12 @@ function callAPI(url, html) { // Server communication error function handler. }); } +/** +* Return the first apikey +* + * @returns {unresolved} */ function getApiKey() { - return "coeus"; + return document.getElementById('apikey').innerHTML.split('|')[0]; } /** * Return last element divided by / of url @@ -443,7 +447,7 @@ function removeById(childDiv, parentDiv) } function callURL(url, success, error) { - url = encodeURI(url); + url = encodeURI(url);console.log(url); $.ajax({url: url, dataType: 'json'}).done(success).fail(error); } diff --git a/src/main/webapp/setup/addconcept.jsp b/src/main/webapp/setup/addconcept.jsp index 047585d..00b01be 100644 --- a/src/main/webapp/setup/addconcept.jsp +++ b/src/main/webapp/setup/addconcept.jsp @@ -61,6 +61,7 @@ // Callback to generate the pages header function fillHeader(result) { $('#header').html('

    ' + lastPath() + ' ' + result.config.environment + '

    '); + $('#apikey').html(result.config.apikey); } $('#submit').click(testMode); @@ -165,6 +166,7 @@ +
    - - + +
    @@ -811,7 +813,7 @@

    Add Selector

    diff --git a/src/main/webapp/setup/resources.jsp b/src/main/webapp/setup/resources.jsp index b1df7c2..aa5af25 100644 --- a/src/main/webapp/setup/resources.jsp +++ b/src/main/webapp/setup/resources.jsp @@ -60,6 +60,7 @@ // Callback to generate the pages header function fillHeader(result) { $('#header').html('

    ' + lastPath() + ' ' + result.config.environment + '

    '); + $('#apikey').html(result.config.apikey); } $(document).ready(function() { @@ -88,6 +89,7 @@ +
    -
    +
    - + +
    + + + +
    +
    diff --git a/src/main/webapp/setup/index.jsp b/src/main/webapp/setup/index.jsp index 44372dd..6b802fa 100644 --- a/src/main/webapp/setup/index.jsp +++ b/src/main/webapp/setup/index.jsp @@ -157,32 +157,33 @@ function changeEnvError(result, text) { $('#info').html(generateHtmlMessage("ERROR!", text, "alert-error")); } - function build(){ + function build() { callURL("../../config/build/", buildResult); } - function buildResult(result){ + function buildResult(result) { console.log(result); } - function unbuild(){ + function unbuild() { var qresource = "SELECT DISTINCT ?resource {" + lastPath() + " coeus:includes ?entity . ?entity coeus:isEntityOf ?concept . ?concept coeus:hasResource ?resource }"; queryToResult(qresource, unbuildResult); } - function unbuildResult(result){ + function unbuildResult(result) { var urlPrefix = "../../api/" + getApiKey(); console.log(result); - for(var r in result){ - var res=splitURIPrefix(result[r].resource.value); - var resource=getPrefix(res.namespace)+":"+res.value; - callURL(urlPrefix+"/update/"+resource+"/coeus:built/xsd:boolean:true,xsd:boolean:false",unbuiltResource.bind(this,resource)); + for (var r in result) { + var res = splitURIPrefix(result[r].resource.value); + var resource = getPrefix(res.namespace) + ":" + res.value; + callURL(urlPrefix + "/update/" + resource + "/coeus:built/xsd:boolean:true,xsd:boolean:false", unbuiltResource.bind(this, resource)); } - + + } + function unbuiltResource(resource, result) { + if (result.status === 100) + console.log("The " + resource + " has been changed. "); + else + console.log("The " + resource + " has already unbuild. "); } - function unbuiltResource(resource,result){ - if(result.status===100) - console.log("The "+resource+" has been changed. "); - else console.log("The "+resource+" has already unbuild. "); - } - + @@ -193,7 +194,7 @@ -
    +
    +
    +
    +
    +
    + +
    +
    +
    + + Export + + + +
    +
    +
    + + +
    From 27eae335f117afef3d7abf3cb90ec0d8df0a0cf1 Mon Sep 17 00:00:00 2001 From: sernadela Date: Mon, 9 Sep 2013 18:43:08 +0100 Subject: [PATCH 34/52] - Setup: Fix autocomplete for property (selectors) when edit. --- src/main/webapp/setup/addresource.jsp | 33 +++++++++++++++++++-------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/main/webapp/setup/addresource.jsp b/src/main/webapp/setup/addresource.jsp index 13b7b59..7973f84 100644 --- a/src/main/webapp/setup/addresource.jsp +++ b/src/main/webapp/setup/addresource.jsp @@ -249,7 +249,8 @@ $('#querySelectorsForm').append(''); $('#regexSelectorsForm').append(''); $('#titleSelectorsForm').append(''); - + //fill the properties + buildSelectoresProperties(); }); //$('#callSelectorsModal').click(); @@ -623,20 +624,32 @@ function updateSelectorProperties() { var typeahead = $('#typeahead').val(); var prop = $('#propertySelectors').val(); - if (typeahead !== "") { + + if (typeahead !== "" && prop.indexOf(typeahead) === -1) { if (prop !== "") prop = prop + "|"; $('#propertySelectors').val(prop + typeahead); $('#typeahead').val(""); - var array = $('#propertySelectors').val().split("|"); - console.log(array); - $('#dropdownprop').html('
  • Properties Added
  • '); - for (var i in array) { - $('#dropdownprop').append('
  • ' + array[i] + '
  • '); - } - } + buildSelectoresProperties(); + } + } + function buildSelectoresProperties() { + var array = $('#propertySelectors').val().split("|"); + console.log(array); + $('#dropdownprop').html('
  • Properties Added
  • '); + for (var i in array) { + $('#dropdownprop').append('
  • ' + array[i] + '
  • '); + } + } + function removeSelectorProperty(value) { + removeById(value, "dropdownprop"); + var q = $('#propertySelectors').val(); + q = q.replace("|" + value, ""); + q = q.replace(value + "|", ""); + q = q.replace(value, ""); + $('#propertySelectors').val(q); } @@ -864,7 +877,7 @@
    From c01c2d30566103a8d74f0150c4e24652949c4e8a Mon Sep 17 00:00:00 2001 From: sernadela Date: Tue, 10 Sep 2013 10:53:43 +0100 Subject: [PATCH 35/52] - Setup: Fix when change from edit to add in selectors. --- src/main/webapp/setup/addresource.jsp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/webapp/setup/addresource.jsp b/src/main/webapp/setup/addresource.jsp index 7973f84..d840038 100644 --- a/src/main/webapp/setup/addresource.jsp +++ b/src/main/webapp/setup/addresource.jsp @@ -255,6 +255,19 @@ //$('#callSelectorsModal').click(); } + function resetSelectorModal(){ + $('#selectorUri').html("coeus:" ); + $('#selectorsModalLabel').html("Add Selector"); + $('#addSelectorButton').html('Add '); + $('#titleSelectors').val(""); + document.getElementById('titleSelectors').removeAttribute("disabled"); + $('#labelSelectors').val(""); + $('#propertySelectors').val(""); + $('#querySelectors').val(""); + $('#regexSelectors').val(""); + $('#keySelectorsForm').prop('checked', false); + buildSelectoresProperties(); + } function removeSelector() { var selector = $('#removeModalLabel').html(); //var query = initSparqlerQuery(); @@ -692,7 +705,7 @@
    - +
    From e8890350c60939c3a4f8151703ff9233e220d52a Mon Sep 17 00:00:00 2001 From: sernadela Date: Wed, 11 Sep 2013 09:42:59 +0100 Subject: [PATCH 36/52] - Setup: Completed tree with shortcut actions. --- src/main/webapp/setup/addresource.jsp | 2 +- src/main/webapp/setup/index.jsp | 143 +++++++++++++++++--------- 2 files changed, 93 insertions(+), 52 deletions(-) diff --git a/src/main/webapp/setup/addresource.jsp b/src/main/webapp/setup/addresource.jsp index d840038..5e7d375 100644 --- a/src/main/webapp/setup/addresource.jsp +++ b/src/main/webapp/setup/addresource.jsp @@ -526,7 +526,7 @@ var entity = result[0].entity.value; seed = "coeus:" + splitURIPrefix(seed).value; entity = "coeus:" + splitURIPrefix(entity).value; - $('#breadSeed').html('Seed /'); + $('#breadSeed').html('Dashboard /'); $('#breadEntities').html('Entities /'); $('#breadConcepts').html('Concepts /'); $('#breadResources').html('Resources /'); diff --git a/src/main/webapp/setup/index.jsp b/src/main/webapp/setup/index.jsp index 6b802fa..0716402 100644 --- a/src/main/webapp/setup/index.jsp +++ b/src/main/webapp/setup/index.jsp @@ -55,17 +55,55 @@ }); }*/ - function queryConcepts(entity, query) { - var qConcepts = "SELECT DISTINCT ?c ?concept {?concept coeus:hasEntity coeus:entity_" + entity + " . ?concept dc:title ?c }"; + function queryConcepts(entity) { + var qConcepts = "SELECT DISTINCT ?concept {?concept coeus:hasEntity coeus:" + entity + " }"; + queryToResult(qConcepts, fillConcepts.bind(this, entity)); + } + function queryResources(concept) { + var qResources = "SELECT DISTINCT ?resource {?resource coeus:isResourceOf coeus:" + concept + " }"; + queryToResult(qResources, fillResources.bind(this, concept)); + } + + function fillResources(concept, result) { + var arrayOfConcepts = new Array(); + var c = ''; + for (var i in result) { + var auxResource = splitURIPrefix(result[i].resource.value); + var resource = auxResource.value; + var prefix = getPrefix(auxResource.namespace); + arrayOfConcepts[i] = resource; + c += '

    ' + + prefix + ":" + resource + '

    '; + } + //console.log(entity); + $('#' + concept).append(c); + //console.log('Append on #' + entity + ': ' + c); + + } + + function fillConcepts(entity, result) { + var arrayOfConcepts = new Array(); var c = ''; - query.query(qConcepts, {success: function(json) { - for (var i = 0, s = json.results.bindings.length; i < s; i++) { - c += '

    ' + json.results.bindings[i].c.value + '

    '; - - } - $('#entity_' + entity).append(c); - console.log('Append on #' + entity + ': ' + c); - }}); + for (var i in result) { + var auxConcept = splitURIPrefix(result[i].concept.value); + var concept = auxConcept.value; + var prefix = getPrefix(auxConcept.namespace); + arrayOfConcepts[i] = concept; + c += '

    ' + +' ' + + prefix + ":" + concept + + ' ' + + ' ' + +'

      '; + } + //console.log(entity); + $('#' + entity).append(c); + //console.log('Append on #' + entity + ': ' + c); + + for (i in arrayOfConcepts) { + queryResources(arrayOfConcepts[i]); + } } function selectEntity() { @@ -89,54 +127,57 @@ $('#apikey').html(result.config.apikey); } + function fillEntities(result) { + // fill Entities + console.log(result); + var arrayOfEntities = new Array(); + var e = ''; + for (var key in result) { + var auxEntity = splitURIPrefix(result[key].entity.value); + var entity = auxEntity.value; + var prefix = getPrefix(auxEntity.namespace); + arrayOfEntities[key] = entity; + + e += '

      ' + +' ' + + prefix + ":" + entity + +' ' + +' ' + +'

        '; + + } + $('#kb').append(e); + + // fill Concepts + for (var k = 0, s = arrayOfEntities.length; k < s; k++) { + //$('#addentity').append(''); + queryConcepts(arrayOfEntities[k]); + } + } + $(document).ready(function() { //get seed from url var seed = lastPath(); callURL("../../config/getconfig/", fillHeader); callURL("../../config/listenv/", fillEnvironments); - var query = initSparqlerQuery(); - // passes standard JSON results object to success callback - var qEntities = "SELECT DISTINCT ?entity ?e ?s {" + seed + " coeus:includes ?entity . ?concept coeus:hasEntity ?entity . ?entity dc:title ?e . }"; - - query.query(qEntities, - {success: function(json) { - // fill Entities - var arrayOfEntities = new Array(); - var e = ''; - for (var key = 0, size = json.results.bindings.length; key < size; key++) { - arrayOfEntities[key] = json.results.bindings[key].e.value; - - e += '

        ' - + arrayOfEntities[key] + '

          '; - - } - $('#concepts').append(e); - - // fill Concepts - for (var k = 0, s = arrayOfEntities.length; k < s; k++) { - //$('#addentity').append(''); - queryConcepts(arrayOfEntities[k], query); - } - }} - ); - //header name - //$.get('../home/config', function(config, status) { - // console.log(config); - - // }, 'json'); + var qEntities = "SELECT DISTINCT ?entity {" + seed + " coeus:includes ?entity }"; + queryToResult(qEntities, fillEntities); var qseeds = "SELECT DISTINCT ?seed ?s {?seed a coeus:Seed . ?seed dc:title ?s . }"; - - query.query(qseeds, - {success: function(json) { - // fill Concepts - for (var k = 0, s = json.results.bindings.length; k < s; k++) { - $('#seeds').append(''); - } - $('#seeds option:contains(' + lastPath().split('coeus:')[1] + ')').prop({selected: true}); - }} + queryToResult(qseeds, function(result) { + for (var k in result) { + $('#seeds').append(''); + } + $('#seeds option:contains(' + lastPath().split('coeus:')[1] + ')').prop({selected: true}); + } ); + + var qEntities = "SELECT (COUNT(*) AS ?triples) {?s ?p ?o}"; + queryToResult(qEntities, function(result) { + $('#triples').html(result[0].triples.value); + }); + }); function changeSeed() { @@ -201,8 +242,8 @@
          -
          -

          Knowledge Base (Entity-Concept)

          +
          +

          Knowledge Base (Entity-Concept) 0

          -
          +

          Actions

          -
          -
          - Seeds -
          -
          - -
          -
          - -
          + - -
          -
          - Environments -
          -
          - -
          - -
          - -
          - -
          - -
          -
          - - -
          -
          - -
          -
          -
          -
          - -
          -
          -
          - - Export - - - -
          + + From 8169e742ba3af3c74d3aa00b482979baf6181df7 Mon Sep 17 00:00:00 2001 From: sernadela Date: Fri, 4 Oct 2013 14:53:31 +0100 Subject: [PATCH 40/52] - Add Executor Thread to run integration process in different thread - Fix Storage running threads. - Fix csv guessDelimiter function - Add a default environment - Setup: Change build and unbuild options. --- .../coeus/actions/ConfigActionBean.java | 129 +- .../ua/bioinformatics/coeus/common/Boot.java | 97 +- .../bioinformatics/coeus/common/Config.java | 47 +- .../coeus/common/ExecutorContextListener.java | 47 + .../coeus/common/HttpListener.java | 1 - .../ua/bioinformatics/coeus/common/Run.java | 1 + .../bioinformatics/coeus/common/Worker.java | 29 + .../ua/bioinformatics/coeus/data/Storage.java | 25 +- .../coeus/data/connect/CSVFactory.java | 24 +- src/main/resources/config.js | 2 +- src/main/resources/env_default/joseki.ttl | 97 ++ src/main/resources/env_default/map.js | 15 + src/main/resources/env_default/pubby.ttl | 91 ++ src/main/resources/env_default/sdb.ttl | 19 + src/main/resources/setup.rdf | 1207 +++++++++++++++++ src/main/webapp/WEB-INF/web.xml | 9 +- src/main/webapp/docs/ontology.jsp | 2 +- src/main/webapp/setup/addentity.jsp | 4 + src/main/webapp/setup/config.jsp | 4 +- src/main/webapp/setup/index.jsp | 54 +- 20 files changed, 1802 insertions(+), 102 deletions(-) create mode 100644 src/main/java/pt/ua/bioinformatics/coeus/common/ExecutorContextListener.java create mode 100644 src/main/java/pt/ua/bioinformatics/coeus/common/Worker.java create mode 100644 src/main/resources/env_default/joseki.ttl create mode 100644 src/main/resources/env_default/map.js create mode 100644 src/main/resources/env_default/pubby.ttl create mode 100644 src/main/resources/env_default/sdb.ttl create mode 100644 src/main/resources/setup.rdf diff --git a/src/main/java/pt/ua/bioinformatics/coeus/actions/ConfigActionBean.java b/src/main/java/pt/ua/bioinformatics/coeus/actions/ConfigActionBean.java index 205faed..dfa5c6e 100644 --- a/src/main/java/pt/ua/bioinformatics/coeus/actions/ConfigActionBean.java +++ b/src/main/java/pt/ua/bioinformatics/coeus/actions/ConfigActionBean.java @@ -36,6 +36,7 @@ import java.util.Map.Entry; import java.util.Set; import java.util.TreeSet; +import java.util.concurrent.ExecutorService; import java.util.logging.Level; import java.util.logging.Logger; import net.sourceforge.stripes.action.ActionBean; @@ -52,8 +53,8 @@ import pt.ua.bioinformatics.coeus.api.DB; import pt.ua.bioinformatics.coeus.common.Boot; import pt.ua.bioinformatics.coeus.common.Config; +import pt.ua.bioinformatics.coeus.common.Worker; import pt.ua.bioinformatics.coeus.data.Predicate; -import pt.ua.bioinformatics.coeus.data.Storage; /** * @@ -104,26 +105,28 @@ public Resolution handle() { * @return */ public Resolution getconfig() { - Config.load(); + Boot.start(); return new StreamingResolution("application/json", Config.getFile().toJSONString()); } - - /** + + /** * return existent properties that matches with $method * * @return */ public Resolution properties() { - JSONArray array=new JSONArray(); - String matchingStr=method; + JSONArray array = new JSONArray(); + String matchingStr = method; //HashMap map= PrefixFactory.getPrefixes(); - HashMap map= Predicate.getPredicates(); - + HashMap map = Predicate.getPredicates(); + for (Entry e : map.entrySet()) { - String key=e.getKey(); - if(matchingStr!=null){ - if(key.contains(matchingStr)) array.add(key); - }else{ + String key = e.getKey(); + if (matchingStr != null) { + if (key.contains(matchingStr)) { + array.add(key); + } + } else { array.add(key); } } @@ -131,11 +134,12 @@ public Resolution properties() { //System.out.println(array.toJSONString()); return new StreamingResolution("application/json", array.toJSONString()); } - + /** - * Export the database content + * Export the database content + * * @return - * @throws FileNotFoundException + * @throws FileNotFoundException */ public Resolution export() throws FileNotFoundException { StringWriter outs = new StringWriter(); @@ -147,25 +151,65 @@ public Resolution export() throws FileNotFoundException { } return new StreamingResolution("application/rdf+xml", outs.toString()); } - - /** - * Build (Boot.start() call) + + /** + * Build (Boot.build() call in a different thread) * * @return */ public Resolution build() { JSONObject result = new JSONObject(); + String value = method; try { - Boot.start(); + + ExecutorService executor = (ExecutorService) context.getServletContext().getAttribute("INTEGRATION_EXECUTOR"); + Runnable worker = new Worker("worker" + System.currentTimeMillis()); + executor.execute(worker); + + result.put("status", 100); + result.put("message", "[COEUS][API][ConfigActionBean] Build done."); + } catch (Exception e) { + result.put("status", 201); + result.put("message", "[COEUS][API][ConfigActionBean] Build fail. Exception: " + e); + } + return new StreamingResolution("application/json", result.toJSONString()); + } + + /** + * Change built property in config.js file. The method value only can be true or false. + * + * @return + */ + public Resolution changebuilt() { + JSONObject result = new JSONObject(); + try { + JSONObject f = Config.getFile(); + JSONObject config = (JSONObject) f.get("config"); + + config.put("built", Boolean.parseBoolean(method)); + f.put("config", config); + + updateFile(f.toJSONString(), Config.getPath() + "config.js"); + //apply values + Boot.resetConfig(); + result.put("status", 100); - result.put("message", "[COEUS][API][ConfigActionBean] Build done. "); + result.put("message", "[COEUS][API][ConfigActionBean] Built property changed."); } catch (Exception e) { result.put("status", 201); - result.put("message", "[COEUS][API][ConfigActionBean] Exception: "+e); + result.put("message", "[COEUS][API][ConfigActionBean] Built not property changed. Exception: " + e); } return new StreamingResolution("application/json", result.toJSONString()); } +// public Resolution executor(){ +// JSONObject result = new JSONObject(); +// ExecutorService executor = (ExecutorService )context.getServletContext().getAttribute("INTEGRATION_EXECUTOR"); +// +// result.put("executor.isShutdown()", executor.isShutdown()); +// result.put("executor.isTerminated()", executor.isTerminated()); +// return new StreamingResolution("application/json", result.toJSONString()); +// } /** * Cleans the DB of one environment (method) * @@ -181,8 +225,8 @@ public Resolution cleandb() { JSONParser parser = new JSONParser(); String json = readToString(map); result = (JSONObject) parser.parse(json); - int index=result.get("$sdb:jdbcURL").toString().lastIndexOf("/"); - String dbName=result.get("$sdb:jdbcURL").toString().substring(index); + int index = result.get("$sdb:jdbcURL").toString().lastIndexOf("/"); + String dbName = result.get("$sdb:jdbcURL").toString().substring(index); DB db = new DB(dbName, result.get("$sdb:jdbcURL") + "&user=" + result.get("$sdb:sdbUser").toString() + "&password=" + result.get("$sdb:sdbPassword").toString()); // test db connection boolean success = db.connectX(); @@ -281,19 +325,16 @@ public void updateFilesFromMap(String path) throws ParseException, IOException { public Resolution upenv() { JSONObject result = new JSONObject(); try { - Config.load(); + Boot.start(); String path = Config.getPath() + "env_" + method + "/"; updateFilesFromMap(path); changeEnvironment(path, Config.getPath(), "env_" + method); //Load new settings - Config.setLoaded(false); - Boot.setStarted(false); - Config.load(); + Boot.resetConfig(); + Boot.resetStorage(); //TODO: FIX THAT - NEEDS SERVERS RESTART TO APPLY NEW CONFIGS - Storage.connect(); - Boot.start(); result.put("status", 100); result.put("message", "[COEUS][API][ConfigActionBean] Environment updated: " + method); @@ -344,8 +385,8 @@ public void changeEnvironment(String src, String dest, String environment) throw public Resolution newenv() { JSONObject result = new JSONObject(); try { + Boot.start(); String name = "env_" + method; - Config.load(); String envStr = Config.getPath() + name; String initStr = Config.getPath() + "init"; File env = new File(envStr); @@ -377,7 +418,7 @@ public Resolution newenv() { public Resolution getmap() { JSONObject result = new JSONObject(); try { - Config.load(); + Boot.start(); String environment = "env_" + method; String path = Config.getPath() + environment + "/"; String map = path + "map.js"; @@ -389,7 +430,7 @@ public Resolution getmap() { } return new StreamingResolution("application/json", result.toJSONString()); } - + /** * Receives a map.js file and update it in according to the environment key * in config.js. @@ -399,15 +440,15 @@ public Resolution getmap() { public Resolution putmap() { JSONObject result = new JSONObject(); try { - Config.load(); + Boot.start(); JSONParser parser = new JSONParser(); System.out.println(method); JSONObject env = (JSONObject) parser.parse(method); //create the DB if not exists - DB creator=new DB(); + DB creator = new DB(); creator.createDB(env.get("$sdb:jdbcURL").toString(), env.get("$sdb:sdbUser").toString(), env.get("$sdb:sdbPassword").toString()); - + String environment = "env_" + env.get("$environment").toString(); String path = Config.getPath() + environment + "/"; String map = path + "map.js"; @@ -416,18 +457,17 @@ public Resolution putmap() { //update files on the environment updateFilesFromMap(path); //change it to use - changeEnvironment(path, Config.getPath(), environment); + //changeEnvironment(path, Config.getPath(), environment); //apply values - Config.setLoaded(false); - Config.load(); + Boot.resetConfig(); } catch (ParseException ex) { result.put("status", 200); result.put("message", "[COEUS][API][ConfigActionBean] ERROR: On parse map.js, check exception."); Logger.getLogger(ConfigActionBean.class.getName()).log(Level.SEVERE, null, ex); - } catch(SQLException ex){ + } catch (SQLException ex) { result.put("status", 200); - result.put("message", "[COEUS][API][ConfigActionBean] ERROR: On creating database, check exception: "+ex); + result.put("message", "[COEUS][API][ConfigActionBean] ERROR: On creating database, check exception: " + ex); Logger.getLogger(ConfigActionBean.class.getName()).log(Level.SEVERE, null, ex); } catch (Exception ex) { result.put("status", 200); @@ -445,7 +485,7 @@ public Resolution putmap() { public Resolution delenv() { JSONObject result = new JSONObject(); try { - Config.load(); + Boot.start(); String envStr = Config.getPath() + "env_" + method; File env = new File(envStr); if (env.exists()) { @@ -501,7 +541,7 @@ public Resolution readrdf() throws MalformedURLException, IOException { */ public Resolution getprop() { - Config.load(); + Boot.start(); Set set = new TreeSet(); StringBuilder sb = new StringBuilder(); //get all proprieties for each prefix @@ -528,9 +568,8 @@ public Resolution putconfig() { //update config.js String jsonString = method; - JSONObject result = updateFile(jsonString, Config.getPath()+"config.js"); - Config.setLoaded(false); - Config.load(); + JSONObject result = updateFile(jsonString, Config.getPath() + "config.js"); + Boot.resetConfig(); //update predicates.csv Set set = new TreeSet(); diff --git a/src/main/java/pt/ua/bioinformatics/coeus/common/Boot.java b/src/main/java/pt/ua/bioinformatics/coeus/common/Boot.java index cf38f7b..17960dd 100755 --- a/src/main/java/pt/ua/bioinformatics/coeus/common/Boot.java +++ b/src/main/java/pt/ua/bioinformatics/coeus/common/Boot.java @@ -31,6 +31,74 @@ public static void setAPI(API api) { Boot.api = api; } + /** + * Reset and load COEUS config.js. + */ + public static void resetConfig() { + try { + Config.setLoaded(false); + Config.load(); + } catch (Exception e) { + if (Config.isDebug()) { + System.out.println("[COEUS][Boot] Unable to reset COEUS instance"); + } + Logger.getLogger(Boot.class.getName()).log(Level.SEVERE, null, e); + } + + } + + /** + * Reset and load COEUS Storage information (connect, ontology, setup, + * predicates). + *

            + *
          1. Reset and load
          2. + *
          3. Reset and load config.js
          4. + *

          + */ + public static void resetStorage() { + try { + Storage.setLoaded(false); + Storage.load(); + Storage.loadPredicates(); + } catch (Exception e) { + if (Config.isDebug()) { + System.out.println("[COEUS][Boot] Unable to reset COEUS instance"); + } + Logger.getLogger(Boot.class.getName()).log(Level.SEVERE, null, e); + } + + } + + /** + * Build COEUS instance. + *

            + *
          1. Load Storage information (connect, ontology, setup, predicates)
          2. + *
          3. Build instance
          4. + *
          5. Save and restart
          6. + *

          + */ + public synchronized static void build() { + try { + Boot.start(); + if (!Config.isBuilt()) { + long i = System.currentTimeMillis(); + Builder.build(); + Builder.save(); + long f = System.currentTimeMillis(); + System.out.println("\n\t[COEUS] " + Config.getName() + " Integration done in " + ((f - i) / 1000) + " seconds.\n"); + Config.setBuiltOnFile(true); + } else { + System.out.println("\n\t[COEUS] " + Config.getName() + " Integration Already done.\n"); + } + } catch (Exception e) { + if (Config.isDebug()) { + System.out.println("[COEUS][Boot] Unable to build COEUS instance"); + } + Logger.getLogger(Boot.class.getName()).log(Level.SEVERE, null, e); + } + + } + /** * Starts the configured COEUS instance. *

          Built workflow

            @@ -46,30 +114,11 @@ public static void setAPI(API api) { public static void start() { if (!started) { try { - try { - Config.load(); - } catch (Exception ex) { - if (Config.isDebug()) { - System.out.println("[COEUS][Boot] Unable to load configuration"); - } - Logger.getLogger(Boot.class.getName()).log(Level.SEVERE, null, ex); - } - if (!Config.isBuilt()) { - Storage.load(); - api = new API(); - Storage.loadPredicates(); - Builder.build(); - Builder.save(); - //remove - Config.setBuilt(true); - start(); - } else { - Storage.connect(); - api = new API(); - Storage.loadPredicates(); - System.out.println("\n\t[COEUS] " + Config.getName() + " Online\n"); - } - + Config.load(); + Storage.load(); + api = new API(); + Storage.loadPredicates(); + System.out.println("\n\t[COEUS] " + Config.getName() + " Online\n"); started = true; } catch (Exception ex) { if (Config.isDebug()) { diff --git a/src/main/java/pt/ua/bioinformatics/coeus/common/Config.java b/src/main/java/pt/ua/bioinformatics/coeus/common/Config.java index 1862736..d7fbf28 100755 --- a/src/main/java/pt/ua/bioinformatics/coeus/common/Config.java +++ b/src/main/java/pt/ua/bioinformatics/coeus/common/Config.java @@ -3,6 +3,7 @@ import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; +import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; @@ -11,6 +12,7 @@ import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; +import pt.ua.bioinformatics.coeus.actions.ConfigActionBean; import pt.ua.bioinformatics.coeus.api.PrefixFactory; /** @@ -51,7 +53,6 @@ public static void setApikeys(ArrayList apikeys) { // public static void setEnvironment(String environment) { // Config.environment = environment; // } - public static String getPath() { return path; } @@ -238,4 +239,48 @@ private static String readFile() { } return new String(buffer); } + + /** + * Write new config.js file + * + * @param file + */ + static void writeFile(JSONObject file) { + try { + FileWriter writer = new FileWriter(path + "config.js"); + writer.write(file.toJSONString()); + writer.flush(); + writer.close(); + + if (Config.isDebug()) { + System.out.println("[COEUS][Config] config.js file updated."); + } + } catch (Exception ex) { + if (Config.isDebug()) { + System.out.println("[COEUS][Config] ERROR: updating config.js."); + } + Logger.getLogger(Config.class.getName()).log(Level.SEVERE, null, ex); + } + } + + /** + * Change built property on config file + * + * @param builder + */ + static void setBuiltOnFile(boolean builder) { + try { + JSONObject f = Config.getFile(); + JSONObject config = (JSONObject) f.get("config"); + config.put("built", builder); + f.put("config", config); + writeFile(f); + Config.setBuilt(builder); + } catch (Exception ex) { + if (Config.isDebug()) { + System.out.println("[COEUS][Config] ERROR: setBuiltOnFile."); + } + Logger.getLogger(Config.class.getName()).log(Level.SEVERE, null, ex); + } + } } \ No newline at end of file diff --git a/src/main/java/pt/ua/bioinformatics/coeus/common/ExecutorContextListener.java b/src/main/java/pt/ua/bioinformatics/coeus/common/ExecutorContextListener.java new file mode 100644 index 0000000..62a13a9 --- /dev/null +++ b/src/main/java/pt/ua/bioinformatics/coeus/common/ExecutorContextListener.java @@ -0,0 +1,47 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package pt.ua.bioinformatics.coeus.common; + +import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import javax.servlet.ServletContext; +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; + +/** + * + * @author sernadela + */ +public class ExecutorContextListener implements ServletContextListener{ + private ExecutorService executor; + + @Override + public void contextInitialized(ServletContextEvent sce) { + ServletContext context = sce.getServletContext(); + executor = Executors.newFixedThreadPool(4); + context.setAttribute("INTEGRATION_EXECUTOR", executor); + Boot.start(); + System.out.println("ServletContextListener started"); + } + + @Override + public void contextDestroyed(ServletContextEvent sce) { + ServletContext context = sce.getServletContext(); + System.out.println("ServletContextListener destroyed"); + List list=executor.shutdownNow(); + //System.err.println("\n\n\nList of runnables:\n\n"); + //for(Runnable r : list){ + // System.err.println(r.toString()); + //} +// System.err.println("\n\n\nList of Threads:\n\n"); +// Set threadSet = Thread.getAllStackTraces().keySet(); +// Thread[] threadArray = threadSet.toArray(new Thread[threadSet.size()]); +// for(Thread t:threadArray) { +// System.err.println(t.getName()); +// } + } + +} diff --git a/src/main/java/pt/ua/bioinformatics/coeus/common/HttpListener.java b/src/main/java/pt/ua/bioinformatics/coeus/common/HttpListener.java index ef30aa3..04c9f59 100644 --- a/src/main/java/pt/ua/bioinformatics/coeus/common/HttpListener.java +++ b/src/main/java/pt/ua/bioinformatics/coeus/common/HttpListener.java @@ -20,7 +20,6 @@ public void sessionCreated(HttpSessionEvent se) { @Override public void sessionDestroyed(HttpSessionEvent se) { - } } diff --git a/src/main/java/pt/ua/bioinformatics/coeus/common/Run.java b/src/main/java/pt/ua/bioinformatics/coeus/common/Run.java index ec79b1c..25be558 100755 --- a/src/main/java/pt/ua/bioinformatics/coeus/common/Run.java +++ b/src/main/java/pt/ua/bioinformatics/coeus/common/Run.java @@ -2,6 +2,7 @@ import java.util.logging.Level; import java.util.logging.Logger; +import org.json.simple.JSONObject; /** * diff --git a/src/main/java/pt/ua/bioinformatics/coeus/common/Worker.java b/src/main/java/pt/ua/bioinformatics/coeus/common/Worker.java new file mode 100644 index 0000000..b9d77e9 --- /dev/null +++ b/src/main/java/pt/ua/bioinformatics/coeus/common/Worker.java @@ -0,0 +1,29 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package pt.ua.bioinformatics.coeus.common; + +/** + * + * @author sernadela + */ +public class Worker implements Runnable{ + String name; + + public Worker(String name){ + this.name=name; + } + + @Override + public void run() { + System.out.println("worker run call"); + Boot.build(); + } + + @Override + public String toString(){ + return name; + } + +} diff --git a/src/main/java/pt/ua/bioinformatics/coeus/data/Storage.java b/src/main/java/pt/ua/bioinformatics/coeus/data/Storage.java index 06123d2..2cc2241 100755 --- a/src/main/java/pt/ua/bioinformatics/coeus/data/Storage.java +++ b/src/main/java/pt/ua/bioinformatics/coeus/data/Storage.java @@ -98,6 +98,7 @@ public static void setStore(Store store) { */ public static boolean connect() { try { + Storage.close(); store = (Store) SDBFactory.connectStore(Config.getPath() + Config.getSdb()); model = SDBFactory.connectDefaultModel(store); infmodel = ModelFactory.createInfModel(reasoner, model); @@ -125,6 +126,7 @@ public static boolean connect() { */ public static boolean connectX() { try { + Storage.close(); store = (Store) SDBFactory.connectStore(Config.getPath() + Config.getSdb()); model = SDBFactory.connectDefaultModel(store); connected = true; @@ -189,7 +191,7 @@ private static boolean loadSetup() { } catch (Exception ex) { if (Config.isDebug()) { System.out.println("[COEUS][Storage] Unable to load " + Config.getName() + " setup"); - //Logger.getLogger(Storage.class.getName()).log(Level.SEVERE, null, ex); + Logger.getLogger(Storage.class.getName()).log(Level.SEVERE, null, ex); } } return success; @@ -388,4 +390,25 @@ private static boolean reset() { } return success; } + + /** + * Close COEUS Store connection if is not closed: + * + * Prevent the launch of new threads if already exists. + * + * @return + */ + private static boolean close() { + boolean success = true; + try { + if(store!=null && !store.isClosed()) store.close(); + success = true; + } catch (Exception ex) { + if (Config.isDebug()) { + System.out.println("[COEUS][Storage] unable to close COEUS SDB"); + } + Logger.getLogger(Storage.class.getName()).log(Level.SEVERE, null, ex); + } + return success; + } } diff --git a/src/main/java/pt/ua/bioinformatics/coeus/data/connect/CSVFactory.java b/src/main/java/pt/ua/bioinformatics/coeus/data/connect/CSVFactory.java index b21a0fb..57cc34b 100755 --- a/src/main/java/pt/ua/bioinformatics/coeus/data/connect/CSVFactory.java +++ b/src/main/java/pt/ua/bioinformatics/coeus/data/connect/CSVFactory.java @@ -294,7 +294,7 @@ public boolean save() { try { API api = Boot.getAPI(); com.hp.hpl.jena.rdf.model.Resource resource = api.getResource(this.res.getUri()); - Statement statementToRemove=api.getModel().createLiteralStatement(resource, Predicate.get("coeus:built"), false); + Statement statementToRemove = api.getModel().createLiteralStatement(resource, Predicate.get("coeus:built"), false); api.removeStatement(statementToRemove); api.addStatement(resource, Predicate.get("coeus:built"), true); success = true; @@ -327,10 +327,9 @@ public char guessDelimiter(URL urlLocation, char quotes, int headerSkip) { int minColums = 1; int linesToCheck = 4; - try { - - for (int a = 0; a < delimiters.length; a++) { - boolean b = true; + for (int a = 0; a < delimiters.length; a++) { + boolean b = true; + try { BufferedReader br = new BufferedReader(new InputStreamReader(urlLocation.openStream())); CSVReader testReader = new CSVReader(br, delimiters[a], quotes, headerSkip); @@ -352,17 +351,16 @@ public char guessDelimiter(URL urlLocation, char quotes, int headerSkip) { } } - if (b) { - //System.out.println("Find:" + delimiters[a]); - return delimiters[a]; - } + } catch (Exception e) { + b = false; } - } catch (IOException ex) { - Logger.getLogger(CSVFactory.class.getName()).log(Level.SEVERE, null, ex); - } catch (NullPointerException ex) { - Logger.getLogger(CSVFactory.class.getName()).log(Level.SEVERE, null, ex); + if (b) { + //System.out.println("Find:" + delimiters[a]); + return delimiters[a]; + } } + return failReturn; } } diff --git a/src/main/resources/config.js b/src/main/resources/config.js index 99677a4..d700950 100644 --- a/src/main/resources/config.js +++ b/src/main/resources/config.js @@ -11,7 +11,7 @@ "built": false, "debug": true, "apikey":"coeus|uavr", - "environment":"" + "environment":"default" }, "prefixes" : { "coeus": "http://bioinformatics.ua.pt/coeus/resource/", diff --git a/src/main/resources/env_default/joseki.ttl b/src/main/resources/env_default/joseki.ttl new file mode 100644 index 0000000..19b8e38 --- /dev/null +++ b/src/main/resources/env_default/joseki.ttl @@ -0,0 +1,97 @@ +@prefix rdfs: . +@prefix rdf: . +@prefix xsd: . +@prefix coeus: . +@prefix module: . +@prefix joseki: . +@prefix ja: . +@prefix sdb: . + +<> rdfs:label "Joseki Configuration File - SDB example" . +# Stripped down to support one service that exposes an +# SDB store as a SPARQL endpoint for query and one for +# one of the graphs in an SDB store. + +[] rdf:type joseki:Server . + +## -------------------------------------------------------------- +## Services + +# Service publishes the whole of the SDB store - this is the usual way to use SDB. +<#service1> + rdf:type joseki:Service ; + rdfs:label "SPARQL-SDB" ; + joseki:serviceRef "sparql" ; # web.xml must route this name to Joseki + joseki:dataset <#sdb> ; + joseki:processor joseki:ProcessorSPARQL_FixedDS ; + . + + +## -------------------------------------------------------------- +## Datasets + +## See also SDB documentation -- http://jena.hpl.hp.com/wiki/SDB +## Special declarations to cause SDB to be used. + +## Initialize SDB. +## Tell the system that sdb:DatasetStore is an implementation of ja:RDFDataset . +## Tell the system that sdb:Model is an implementation of ja:RDFDataset . + +[] ja:loadClass "com.hp.hpl.jena.sdb.SDB" . +sdb:DatasetStore rdfs:subClassOf ja:RDFDataset . +sdb:Model rdfs:subClassOf ja:Model . + +<#sdb> rdf:type sdb:DatasetStore ; + ## Number of concurrent connections allowed to this dataset. + joseki:poolSize 2; + sdb:store <#store> . + +<#store> rdf:type sdb:Store ; + rdfs:label "SDB" ; + sdb:layout "layout2" ; + sdb:connection + [ rdf:type sdb:SDBConnection ; + sdb:sdbType "mysql" ; + #sdb:sdbHost "localhost:3306" ; + #sdb:sdbName "coeus" ; + sdb:jdbcURL "$sdb:jdbcURL" ; + sdb:sdbUser "$sdb:sdbUser" ; + sdb:sdbPassword "$sdb:sdbPassword" ; + ] + . + +# Pick one graph out of the SDB store. +# Do not assemble the whole of the store this way - it is less efficient for that. +<#sdb-part> rdf:type ja:RDFDataset ; + # If ja:namedGraph is used here, there is no correspondence + # with the name in the SDB store. + ja:defaultGraph <#sdb-one-graph> ; + . + +<#sdb-one-graph> a sdb:Model ; + sdb:dataset <#sdb> ; + # Uncomment to pick out a named graph from the store. + # If no "sdb:namedGraph" appearsm the store's default graph is used. + # is used as default graph of the dataset publically visible. + #sdb:graphName ; + # Or even the merge of all named graphs + #sdb:graphName ; + . + +## -------------------------------------------------------------- +## Processors + +joseki:ProcessorSPARQL_FixedDS + rdfs:label "SPARQL processor for fixed datasets" ; + rdf:type joseki:Processor ; + module:implementation + [ rdf:type joseki:ServiceImpl ; + module:className + ] ; + + # This processor does not accept queries with FROM/FROM NAMED + joseki:allowExplicitDataset "false"^^xsd:boolean ; + joseki:allowWebLoading "false"^^xsd:boolean ; + # The database is safe for MRSW (multiple-reader, single-writer). + joseki:lockingPolicy joseki:lockingPolicyMRSW ; + . \ No newline at end of file diff --git a/src/main/resources/env_default/map.js b/src/main/resources/env_default/map.js new file mode 100644 index 0000000..43e9dee --- /dev/null +++ b/src/main/resources/env_default/map.js @@ -0,0 +1,15 @@ +{ + "$sdb:jdbcURL" : "jdbc:mysql://localhost:3306/coeus?autoReconnect=true", + "$sdb:sdbUser" : "demo", + "$sdb:sdbPassword" :"demo", + + "$conf:projectName" :"coeus.demo", + "$conf:projectHomepage" :"http://bioinformatics.ua.pt/coeus/", + "$conf:webBase" :"http://localhost:8080/coeus/", + "$conf:sparqlEndpoint" :"http://localhost:8080/coeus/sparql", + "$conf:datasetBase" :"http://bioinformatics.ua.pt/coeus/resource/", + "$conf:webResourcePrefix" :"resource/", + + "$environment" :"", + +} \ No newline at end of file diff --git a/src/main/resources/env_default/pubby.ttl b/src/main/resources/env_default/pubby.ttl new file mode 100644 index 0000000..1a5d679 --- /dev/null +++ b/src/main/resources/env_default/pubby.ttl @@ -0,0 +1,91 @@ +# Pubby Example Configuration +# +# This configuration connects to the DBpedia SPARQL endpoint and +# re-publishes on your local machine, with dereferenceable +# localhost URIs. +# +# This assumes you already have a servlet container running +# on your machine at http://localhost:8080/ . +# +# Install Pubby as the root webapp of your servlet container, +# and make sure the config-file parameter in Pubby's web.xml +# points to this configuration file. +# +# Then browse to http://localhost:8080/ . + +# Prefix declarations to be used in RDF output +@prefix conf: . +@prefix meta: . +@prefix rdf: . +@prefix rdfs: . +@prefix xsd: . +@prefix owl: . +@prefix dc: . +@prefix dcterms: . +@prefix foaf: . +@prefix skos: . +@prefix geo: . +@prefix dbpedia: . +@prefix p: . +@prefix yago: . +@prefix units: . +@prefix geonames: . +@prefix prv: . +@prefix prvTypes: . +@prefix doap: . +@prefix void: . +@prefix ir: . +@prefix coeus: . + +# Server configuration section +<> a conf:Configuration; + # Project name for display in page titles + conf:projectName "$conf:projectName"; + # Homepage with description of the project for the link in the page header + conf:projectHomepage <$conf:projectHomepage>; + # The Pubby root, where the webapp is running inside the servlet container. + conf:webBase <$conf:webBase>; + # URL of an RDF file whose prefix mapping is to be used by the + # server; defaults to <>, which is *this* file. + conf:usePrefixesFrom <>; + # If labels and descriptions are available in multiple languages, + # prefer this one. + conf:defaultLanguage "en"; + # When the homepage of the server is accessed, this resource will + # be shown. + #conf:indexResource ; + +# Dataset configuration section #1 (for DBpedia resources) +# +# URIs in the SPARQL endpoint: http://dbpedia.org/resource/* +# URIs on the Web: http://localhost:8080/resource/* + conf:dataset [ + # SPARQL endpoint URL of the dataset + conf:sparqlEndpoint <$conf:sparqlEndpoint>; + #conf:sparqlEndpoint ; + # Default graph name to query (not necessary for most endpoints) + # conf:sparqlDefaultGraph <>; + # Common URI prefix of all resource URIs in the SPARQL dataset + conf:datasetBase <$conf:datasetBase>; + # Will be appended to the conf:webBase to form the public + # resource URIs; if not present, defaults to "" + conf:webResourcePrefix "$conf:webResourcePrefix"; + # Fixes an issue with the server running behind an Apache proxy; + # can be ignored otherwise + conf:fixUnescapedCharacters "(),'!$&*+;=@"; + + # include metadata + #conf:metadataTemplate "metadata.ttl"; + + # configure your metadata here + # Use properties with the meta: prefix where the property name + # corresponds to the placeholder URIs in metadata.ttl that begin + # with about:metadata:metadata: + # Examples for such properties are: +# meta:pubbyUser ; +# meta:pubbyOperator ; +# meta:endpointUser ; +# meta:endpointOperator ; +# meta:endpointDataset ; + ]; + . diff --git a/src/main/resources/env_default/sdb.ttl b/src/main/resources/env_default/sdb.ttl new file mode 100644 index 0000000..ac180fd --- /dev/null +++ b/src/main/resources/env_default/sdb.ttl @@ -0,0 +1,19 @@ +@prefix sdb: . +@prefix rdfs: . +@prefix rdf: . +@prefix ja: . +@prefix coeus: . + +<#store> rdf:type sdb:Store ; + sdb:layout "layout2" ; + sdb:connection <#conn> ; + sdb:engine "InnoDB" ; +. + +<#conn> rdf:type sdb:SDBConnection ; + sdb:sdbType "MySQL" ; + sdb:jdbcURL "$sdb:jdbcURL" ; + sdb:sdbUser "$sdb:sdbUser" ; + sdb:sdbPassword "$sdb:sdbPassword" ; + sdb:driver "com.mysql.jdbc.Driver" ; + . \ No newline at end of file diff --git a/src/main/resources/setup.rdf b/src/main/resources/setup.rdf new file mode 100644 index 0000000..a518ecb --- /dev/null +++ b/src/main/resources/setup.rdf @@ -0,0 +1,1207 @@ + + + + + + + + + +]> + + + + + coeusna + 1.0b + 2013-03-15 + COEUS and COEUS Ontology are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA. + Pedro Lopes pedrolopes@ua.pt + coeus.NA + coeus.NA + coeus.NA + en + http://bioinformatics.ua.pt + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + objectproperty_extends + 1.0a + 2011-01-20 + A Resource extends a Concept - items are source for data loading + A Resource extends a Concept - items are source for data loading + Pedro Lopes pedrolopes@ua.pt + extends + + + + + + + + + + objectproperty_hasbridge + 1.0a + 2011-01-19 + A Concept has a Bridge + A Concept has a Bridge + Pedro Lopes pedrolopes@ua.pt + hasBridge + + + + + + + + + + objectproperty_hasconcept + 1.0a + 2011-01-14 + Item individuals belong to Concept individuals + Item individuals belong to Concept individuals + Pedro Lopes pedrolopes@ua.pt + hasConcept + + + + + + + + + + objectproperty_hasentity + 1.0a + 2011-01-14 + Concept individuals has Entity individuals + Concept individuals has Entity individuals + Pedro Lopes pedrolopes@ua.pt + hasEntity + + + + + + + + + + objectproperty_haskey + 1.0a + 2011-01-27 + Defines the key for a given Resource + Defines the key for a given Resource + Pedro Lopes pedrolopes@ua.pt + hasKey + + + + + + + + + + + + + objectproperty_hasmodule + 1.0a + 2011-01-19 + A Seed has a Module + A Seed has a Module + Pedro Lopes pedrolopes@ua.pt + hasModule + + + + + + + + + + objectproperty_hasresource + 1.0a + 2011-01-19 + A Concept has a Resource + A Concept has a Resource + Pedro Lopes pedrolopes@ua.pt + hasResource + + + + + + + + + + objectproperty_includes + 1.0a + 2011-01-14 + Defines which Entity individuals are included in Seed individuals + Defines which Entity individuals are included in Seed individuals + Pedro Lopes pedrolopes@ua.pt + includes + + + + + + + + + + + + + objectproperty_isassociatedto + 1.0a + 2011-01-19 + Pedro Lopes pedrolopes@ua.pt + Relationship between two "Item" individuals + Relationship between two "Item" individuals + isAssociatedTo + + + + + + + + + + + iobjectproperty_sbridgedto + 1.0a + 2011-01-19 + A Briged is bridged to a Concept + A Briged is bridged to a Concept + Pedro Lopes pedrolopes@ua.pt + isBridgedTo + + + + + + + + + + + objectproperty_isconceptof + 1.0a + 2011-01-19 + A Concept has an Item + A Concept has an Item + Pedro Lopes pedrolopes@ua.pt + isConceptOf + + + + + + + + + + + + + objectproperty_isconnectedto + 1.0a + 2011-01-14 + Defines connection between two Concept individuals + Defines connection between two Concept individuals + Pedro Lopes pedrolopes@ua.pt + isConnectedTo + + + + + + + + + + + objectproperty_isentityof + 1.0a + 2011-01-19 + An Entity is of a Concept + An Entity is of a Concept + Pedro Lopes pedrolopes@ua.pt + isEntityOf + + + + + + + + + + + objectproperty_isextendedby + 1.0a + 2011-01-27 + A Resource extends a Concept - items are source for data loading + A Resource extends a Concept - items are source for data loading + Pedro Lopes pedrolopes@ua.pt + isExtendedBy + + + + + + + + + + + objectproperty_isincludedin + 1.0a + 2011-01-14 + Defines which Entity individuals are included in Seed individuals + Defines which Entity individuals are included in Seed individuals + Pedro Lopes pedrolopes@ua.pt + isIncludedIn + + + + + + + + + + objectproperty_iskeyof + 1.0a + 2011-01-27 + Defines the key for a given Resource + Defines the key for a given Resource + Pedro Lopes pedrolopes@ua.pt + isKeyOf + + + + + + + + + + + + + + objectproperty_ismoduleof + 1.0a + 2011-01-19 + A Module is of a Seed + A Module is of a Seed + Pedro Lopes pedrolopes@ua.pt + isModuleOf + + + + + + + + + + + objectproperty_isresourceof + 1.0a + 2011-01-19 + A Resource is of a Concept + A Resource is of a Concept + Pedro Lopes pedrolopes@ua.pt + isResourceOf + + + + + + + + + + + objectproperty_loadsfor + 1.0a + 2011-01-20 + A CSV,XML,SQL loads data for a Resource + A CSV,XML,SQL loads data for a Resource + Pedro Lopes pedrolopes@ua.pt + loadsFor + + + + + + + + + + + + + + objectproperty_loadsfrom + 1.0a + 2011-01-20 + A Resource loads data from a CSV, XML, SQL, SPARQL + A Resource loads data from a CSV, XML, SQL, SPARQL + Pedro Lopes pedrolopes@ua.pt + loadsFrom + + + + + + + + + + + + + objectproperty_mappedfrom + 1.0b + 2011-03-24 + Defines a mapping destination (Concept) for a given Resource + Defines a mapping destination (Concept) for a given Resource + Pedro Lopes pedrolopes@ua.pt + mappedFrom + + + + + + + + + + + objectproperty_mapsto + 1.0b + 2011-03-24 + Defines a mapping destination (Concept) for a given Resource + Defines a mapping destination (Concept) for a given Resource + Pedro Lopes pedrolopes@ua.pt + mapsTo + + + + + + + + + + + + + + + dataproperty_loaded + 1.0b + 2011-03-31 + Defines that a Seed, Entity, Concept is or is not built. + Defines that a Seed, Entity, Concept is or is not built. + Pedro Lopes pedrolopes@ua.pt + loaded + + + + + + + + + + + + + + + + + + + + dataproperty_database + 1.0b + 2011-03-24 + Database identifier for connectionn info in .js config file + Database identifier for connectionn info in .js config file + Pedro Lopes pedrolopes@ua.pt + database + + + + + + + + + + dataproperty_delimiter + 1.0a + 2011-01-19 + Column separator in CSV file + Column separator in CSV file + Pedro Lopes pedrolopes@ua.pt + delimiter + + + + + + + + + + dataproperty_enabled + 1.0a + 2011-01-14 + Defines if an individual is enabled or not + Defines if an individual is enabled or not + Pedro Lopes pedrolopes@ua.pt + enabled + + + + + + + + + dataproperty_endpoint + 1.0b + 2011-04-04 + Endpoint for a given Resource. + Endpoint for a given Resource. + Pedro Lopes pedrolopes@ua.pt + endpoint + + + + + + + + dataproperty_extension + 1.0b + 2011-03-24 + Defines the source for a Resource extension + Defines the source for a Resource extension + Pedro Lopes pedrolopes@ua.pt + extension + + + + + + + + + + dataproperty_host + 1.0a + 2011-01-14 + Defines a Seed individual host + Defines a Seed individual host + Pedro Lopes pedrolopes@ua.pt + host + + + + + + + + + + dataproperty_line + 1.0a + 2011-01-19 + Pedro Lopes pedrolopes@ua.pt + The line where the CSV reader will start + The line where the CSV reader will start + line + + + + + + + + + + dataproperty_method + 1.0a + 2011-01-19 + A Resource access method or Bridge method + A Resource access method or Bridge method + Pedro Lopes pedrolopes@ua.pt + method + + + + + + + + + + + dataproperty_order + 1.0a + 2011-02-21 + Defines resource load order, useful for data-dependencies. + Defines resource load order, useful for data-dependencies. + Pedro Lopes pedrolopes@ua.pt + order + + + + + + + + + + dataproperty_plugin + 1.0a + 2011-01-20 + Defines if a module is a plugin or not + Defines if a module is a plugin or not + Pedro Lopes pedrolopes@ua.pt + plugin + + + + + + + + + + dataproperty_property + 1.0a + 2011-01-19 + An Item predicate where Resource will be loaded into + An Item predicate where Resource will be loaded into + Pedro Lopes pedrolopes@ua.pt + property + + + + + + + + + + + + + dataproperty_public + 1.0a + 2011-01-14 + Defines if a Seed data is publishable or not + Defines if a Seed data is publishable or not + Pedro Lopes pedrolopes@ua.pt + public + + + + + + + + + dataproperty_query + 1.0a + 2011-01-27 + A Column selector for the associated Resource + A Column selector for the associated Resource + Pedro Lopes pedrolopes@ua.pt + query + + + + + + + + + + + + + dataproperty_regex + 1.0b + 2011-05-03 + Description for used regular expressions. + Description for used regular expressions. + Pedro Lopes pedrolopes@ua.pt + regex + + + + + + + + + dataproperty_replace + 1.0a + 2011-01-19 + Pedro Lopes pedrolopes@ua.pt + The replaceable token in a Resource + The replaceable token in a Resource + replace + + + + + + + + + + + + + dataproperty_select + 1.0a + 2011-01-27 + Pedro Lopes pedrolopes@ua.pt + The select statement to get data from a Resource + The select statement to get data from a Resource + select + + + + + + + + + + + + + + + class_bridge + + 1.0a + 2011-01-19 + Bridge individuals are connections to external resources. They are used to interact with these resources. A Bridge can be a composeable URL or simple text to be replaced with data from the 3SDB. + Bridge individuals are connections to external resources. They are used to interact with these resources. A Bridge can be a composeable URL or simple text to be replaced with data from the 3SDB. + Pedro Lopes pedrolopes@ua.pt + Title + + + + + + + + class_csv + + 1.0a + 2011-01-18 + CSV + Class for CSV resource individuals and definitions + Class for CSV resource individuals and definitions + Pedro Lopes pedrolopes@ua.pt + + + + + + + + class_concept + + 1.0a + 2011-01-14 + Concept + Concept element are used to organize distinct resources. + + Examples: + - HGNC + - UniProt + Concept element are used to organize distinct resources. + + Examples: + - HGNC + - UniProt + Pedro Lopes pedrolopes@ua.pt + + + + + + + + class_entity + + 1.0a + 2011-01-14 + Entity + Entity elements are the main data organizational class inside COEUS. Entities act as upper classes to all other elements in the Seed. + + Everything is an Entity. + + Example: + - Gene + - Protein + Entity elements are the main data organizational class inside COEUS. Entities act as upper classes to all other elements in the Seed. + + Everything is an Entity. + + Example: + - Gene + - Protein + Pedro Lopes pedrolopes@ua.pt + + + + + + + + class_item + + 1.0a + 2011-01-14 + Item + Item elements are the most atomic information units in COEUS. + Item elements are the most atomic information units in COEUS. + Pedro Lopes pedrolopes@ua.pt + + + + + + + + class_module + + 1.0a + 2011-01-19 + Class for platform modules: "Module" individual + Class for platform modules: "Module" individual + Module + Pedro Lopes pedrolopes@ua.pt + + + + + + + + class_resource + + 1.0a + 2011-01-18 + Pedro Lopes pedrolopes@ua.pt + Resource + Resource individuals reflect the data, information or knowledge sources for each Seed Concept + Resource individuals reflect the data, information or knowledge sources for each Seed Concept + + + + + + + + class_sparql + + 1.0a + 2011-01-26 + Class for SPARQL resource individuals and definitions + Class for SPARQL resource individuals and definitions + Pedro Lopes pedrolopes@ua.pt + SPARQL + + + + + + + + class_sql + + 1.0a + 2011-01-18 + Class for SQL resource individuals and definitions + Class for SQL resource individuals and definitions + Pedro Lopes pedrolopes@ua.pt + SQL + + + + + + + + class_seed + 1.0a + 2011-01-14 + Pedro Lopes pedrolopes@ua.pt + Seed + This class is used to store Seed information such has host features or availability. + This class is used to store Seed information such has host features or availability. + + + + + + + + class_xml + + 1.0a + 2011-01-18 + Class for XML resource individuals and definitions + Class for XML resource individuals and definitions + Pedro Lopes pedrolopes@ua.pt + XML + + + + + + + + + + + + + + + + + News Aggregator + + News Aggregator + + + + + News + Entity News + + + + + + News + + + + + + Reuters + + + Reuters + + + + + + Marca + + + Marca + + + + + + Abola + + + Abola + + + + + + BBC + + + BBC + + + + + + + + + + + + Abola + Resource loader for A Bola XML feeds. + + 1 + cache + http://www.abola.pt/rss/index.aspx + + //item + xml + Abola + + + + + + + + + + + Reuters + Resource loader for Reuters XML feeds. + + 4 + cache + http://feeds.reuters.com/reuters/sportsNews + + //item + xml + Reuters + + + + + + + + + + + Marca + Resource loader for Marca XML feeds. + + 2 + cache + http://estaticos.marca.com/rss/portada.xml + + //item + xml + Marca + + + + + + + + + + + BBC + Resource loader for BBC XML feeds. + + 3 + cache + http://feeds.bbci.co.uk/sport/0/rss.xml + + //item + xml + BBC + + + + + xml_link + + + + + dc:publisher + link + xml_link + + + + + xml_Reuters_id + + dc:identifier + guid + + xml_Reuters_id + [0-9]{5,} + + + + + xml_BBC_id + + dc:identifier + guid + + xml_BBC_id + [0-9]{5,} + + + + + xml_description + + + + + dc:description + description + xml_description + + + + + xml_date + + + + + dc:date + pubDate + xml_date + + + + + xml_Marca_id + + dc:identifier + guid + + xml_Marca_id + [0-9]{5,} + + + + + xml_title + + + + + dc:title + title + xml_title + + + + + xml_Abola_id + + dc:identifier + guid + + xml_Abola_id + [0-9]{5,} + + + + + + + + diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index 21452de..a08d544 100755 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -124,14 +124,17 @@ pt.ua.bioinformatics.coeus.common.HttpListener + + pt.ua.bioinformatics.coeus.common.ExecutorContextListener + - + + /config/* /setup/* /manager/* GET @@ -153,7 +156,7 @@ /login.jsp /login.jsp?f=error - + --> diff --git a/src/main/webapp/docs/ontology.jsp b/src/main/webapp/docs/ontology.jsp index 3200b96..976a167 100644 --- a/src/main/webapp/docs/ontology.jsp +++ b/src/main/webapp/docs/ontology.jsp @@ -328,7 +328,7 @@
          1. For resources, this means the global object query. For each individual answer to this query, new Item individuals will be created.
              -
            • For CSV resources, query is the combination of the column delimiter with the quotes delimiter and with the headers skip number (Ex: t|"|1) [1].
            • +
            • For CSV resources, query is the combination of the headers skip number with the quotes delimiter (Ex: 1|") [1].
            • For XML resources, query is the global XPath query (//entry).
            • diff --git a/src/main/webapp/setup/addentity.jsp b/src/main/webapp/setup/addentity.jsp index 275b7a4..7d0aca4 100644 --- a/src/main/webapp/setup/addentity.jsp +++ b/src/main/webapp/setup/addentity.jsp @@ -44,6 +44,10 @@ $('#titleForm').append(''); $('#labelForm').append(''); $('#commentForm').append(''); + + $('#breadSeed').html('Dashboard / '); + $('#breadEntities').html('Entities / '); + } ); } diff --git a/src/main/webapp/setup/config.jsp b/src/main/webapp/setup/config.jsp index 87d9861..57d7396 100644 --- a/src/main/webapp/setup/config.jsp +++ b/src/main/webapp/setup/config.jsp @@ -94,7 +94,7 @@ //$('#Environment').val(result.config.environment); $('#ApiKey').val(result.config.apikey); $('#Ontology').val(result.config.ontology); - $('#Setup').val(result.config.setup); + $('#SetupFile').val(result.config.setup); if (result.config.built.toString() === "true") $('#Built').prop('checked', true); @@ -146,7 +146,7 @@ "keyprefix": $('#KeyPrefix').val(), "version": $('#Version').val(), "ontology": $('#Ontology').val(), - "setup": $('#Setup').val(), + "setup": $('#SetupFile').val(), "sdb": "sdb.ttl", "predicates": "predicates.csv", "built": $('#Built').is(':checked'), diff --git a/src/main/webapp/setup/index.jsp b/src/main/webapp/setup/index.jsp index 7b080fd..48d9d8b 100644 --- a/src/main/webapp/setup/index.jsp +++ b/src/main/webapp/setup/index.jsp @@ -125,6 +125,14 @@ function fillHeader(result) { $('#header').html('

              ' + lastPath() + ' ' + result.config.environment + '

              '); $('#apikey').html(result.config.apikey); + var built = result.config.built; + if (built == false) { + $('#btnUnbuild').removeClass("active"); + $('#btnBuild').addClass("active"); + } else { + $('#btnUnbuild').addClass("active"); + $('#btnBuild').removeClass("active"); + } } function fillEntities(result) { @@ -142,7 +150,7 @@ + ' ' + prefix + ":" + entity + ' ' - + ' ' + + ' ' + '

                '; } @@ -173,7 +181,7 @@ } ); - var qEntities = "SELECT (COUNT(*) AS ?triples) {?s a coeus:Item}"; + var qEntities = "SELECT (COUNT(*) AS ?triples) {?s a coeus:Item . ?s coeus:hasConcept ?concept . ?concept coeus:hasEntity ?entity . ?entity coeus:isIncludedIn " + seed + "}"; queryToResult(qEntities, function(result) { $('#triples').html(result[0].triples.value); }); @@ -187,7 +195,7 @@ function changeEnv() { var env = $('#environments').val(); - callURL("../../config/upenv/" + env, changeEnvResult, changeEnvResult, changeEnvError); + callURL("../../config/upenv/" + env, changeEnvResult, changeEnvResult, showError); } function changeEnvResult(result) { if (result.status === 100) @@ -195,7 +203,7 @@ else $('#info').html(generateHtmlMessage("Warning!", result.message)); } - function changeEnvError(result, text) { + function showError(result, text) { $('#info').html(generateHtmlMessage("ERROR!", text, "alert-error")); } function build() { @@ -211,6 +219,7 @@ function unbuildResult(result) { var urlPrefix = "../../api/" + getApiKey(); console.log(result); + $('#info').html(''); for (var r in result) { var res = splitURIPrefix(result[r].resource.value); var resource = getPrefix(res.namespace) + ":" + res.value; @@ -219,13 +228,32 @@ } function unbuiltResource(resource, result) { - if (result.status === 100) - console.log("The " + resource + " has been changed. "); - else - console.log("The " + resource + " has already unbuild. "); + if (result.status === 100) { + var text = "The " + resource + " has been changed. "; + console.log(text); + $('#info').append(generateHtmlMessage("Success!", text, "alert-success")); + } + else { + var text = "The " + resource + " has already unbuild. "; + console.log(text); + $('#info').append(generateHtmlMessage("Alert!", text, "alert-warning")); + } + } + function changeBuiltResult(bool, result) { + if (result.status === 100) { + var text = "The property built has been changed to " + bool + "."; + console.log(text); + $('#info').html(generateHtmlMessage("Success!", text, "alert-success")); + } + else { + var text = "The property built has not been changed to " + bool + "."; + console.log(text); + $('#info').html(generateHtmlMessage("Alert!", text, "alert-warning")); + } } + @@ -262,8 +290,14 @@ Explorer
            - Rebuild - Unbuild + (Re)Build + + + Change all Resources to unbuild
            Export From 66ddd32be3991d7dfa062b6ece9b438775560e58 Mon Sep 17 00:00:00 2001 From: sernadela Date: Tue, 8 Oct 2013 14:04:59 +0100 Subject: [PATCH 41/52] - Setup: Fix remove seed. - Setup: Add SWAT4LS workshop. - Change Add/Edit Seeds to modals. --- src/main/webapp/assets/js/coeus.api.js | 95 +++++----- src/main/webapp/index.jsp | 7 +- src/main/webapp/science.jsp | 27 ++- src/main/webapp/setup/addseed.jsp | 36 ++-- src/main/webapp/setup/seeds.jsp | 246 ++++++++++++++++++++++--- 5 files changed, 323 insertions(+), 88 deletions(-) diff --git a/src/main/webapp/assets/js/coeus.api.js b/src/main/webapp/assets/js/coeus.api.js index 007601d..3807af8 100644 --- a/src/main/webapp/assets/js/coeus.api.js +++ b/src/main/webapp/assets/js/coeus.api.js @@ -159,8 +159,8 @@ function callAPI(url, html) { }); } /** -* Return the first apikey -* + * Return the first apikey + * * @returns {unresolved} */ function getApiKey() { return document.getElementById('apikey').innerHTML.split('|')[0]; @@ -198,37 +198,34 @@ function redirect(location) { * @param {type} object * @returns {undefined} */ -function removeAllTriplesFromObject(urlPrefix, object) { +function removeAllTriplesFromObject(urlPrefix, object, showResult, showError) { var qObject = "SELECT ?subject ?predicate {?subject ?predicate " + object + " . }"; - queryToResult(qObject, function(result) { - console.log(result); - for (var r in result) { - var subject = resultToObject(result[r].subject); - var predicate = resultToPredicate(result[r].predicate); - - var url = "/delete/" + subject.prefix + subject.value + '/' + predicate.prefix + predicate.value + '/' + object; - - //console.log("Delete call: " + urlPrefix + url); - callAPI(urlPrefix + url, "#result"); - // if ((predicate.value !== "includes") & (predicate.value !== "isEntityOf") & (predicate.value !== "isConceptOf") & (predicate.value !== "isResourceOf")) - //removeRecursive(urlPrefix, subject.prefix + subject.value); - } + queryToResult(qObject, foreachRemoveObjects.bind(this, urlPrefix, object, showResult, showError)); +} +function foreachRemoveObjects(urlPrefix, object, showResult, showError, result) { + console.log(result); + for (var r in result) { + var subject = resultToObject(result[r].subject); + var predicate = resultToPredicate(result[r].predicate); + var url = "/delete/" + subject.prefix + subject.value + '/' + predicate.prefix + predicate.value + '/' + object; + console.log("Delete call: " + urlPrefix + url); + callURL(urlPrefix + url, showResult, showError); } - ); - } -function cleanUnlikedTriples(urlPrefix) { + +function cleanUnlikedTriples(urlPrefix, showResult, showError) { + console.log("cleanUnlikedTriples call"); //Clean unlinked entities var qEntities = "SELECT * {{ ?entity a coeus:Entity . FILTER NOT EXISTS{ ?entity coeus:isIncludedIn ?seed }}UNION {?entity a coeus:Entity . FILTER NOT EXISTS { ?seed coeus:includes ?entity }} }"; queryToResult(qEntities, function(result) { for (var r in result) { var entity = splitURIPrefix(result[r].entity.value); var prefix = getPrefix(entity.namespace) + ":"; - removeAllTriplesFromSubject(urlPrefix, prefix + entity.value); + removeAllTriplesFromSubject(urlPrefix, prefix + entity.value, showResult, showError); } }); //Clean unlinked concepts @@ -237,7 +234,7 @@ function cleanUnlikedTriples(urlPrefix) { for (var r in result) { var concept = splitURIPrefix(result[r].concept.value); var prefix = getPrefix(concept.namespace) + ":"; - removeAllTriplesFromSubject(urlPrefix, prefix + concept.value); + removeAllTriplesFromSubject(urlPrefix, prefix + concept.value, showResult, showError); } }); //Clean unlinked resources @@ -246,7 +243,7 @@ function cleanUnlikedTriples(urlPrefix) { for (var r in result) { var resource = splitURIPrefix(result[r].resource.value); var prefix = getPrefix(resource.namespace) + ":"; - removeAllTriplesFromSubject(urlPrefix, prefix + resource.value); + removeAllTriplesFromSubject(urlPrefix, prefix + resource.value, showResult, showError); } }); //Clean unlinked selectores @@ -255,7 +252,7 @@ function cleanUnlikedTriples(urlPrefix) { for (var r in result) { var selector = splitURIPrefix(result[r].selector.value); var prefix = getPrefix(selector.namespace) + ":"; - removeAllTriplesFromSubject(urlPrefix, prefix + selector.value); + removeAllTriplesFromSubject(urlPrefix, prefix + selector.value, showResult, showError); } }); } @@ -298,27 +295,30 @@ function cleanUnlikedTriples(urlPrefix) { // ); //} -function removeAllTriplesFromSubject(urlPrefix, subject) { +/** + * Remove all triples associated with the subject + * + * @param {type} urlPrefix + * @param {type} subject + * @param {type} showResult + * @param {type} showError + * @returns {undefined} + */ +function removeAllTriplesFromSubject(urlPrefix, subject, showResult, showError) { var qSubject = "SELECT ?predicate ?object {" + subject + " ?predicate ?object . }"; - queryToResult(qSubject, function(result) { - console.log(result); - for (var r in result) { - var object = resultToObject(result[r].object); - var predicate = resultToPredicate(result[r].predicate); - - var url = "/delete/" + subject + '/' + predicate.prefix + predicate.value + '/' + object.prefix + object.value; - //console.log(url); - callAPI(urlPrefix + url, "#result"); - } - - //if success refresh page - if (document.getElementById('result').className !== 'alert alert-error') { - // window.location="../entity/"+lastPath(); - console.log("REDIRECTING..."); - //window.location.reload(true); - } + queryToResult(qSubject, foreachRemoveSubjects.bind(this, urlPrefix, subject, showResult, showError) + ); +} +function foreachRemoveSubjects(urlPrefix, subject, showResult, showError, result) { + console.log(result); + for (var r in result) { + var object = resultToObject(result[r].object); + var predicate = resultToPredicate(result[r].predicate); + + var url = "/delete/" + subject + '/' + predicate.prefix + predicate.value + '/' + object.prefix + object.value; + console.log("Deleting: " + url); + callURL(urlPrefix + url, showResult, showError); } - ); } function removeAllTriplesFromSubjectAndPredicate(urlPrefix, subject, predicate) { @@ -447,8 +447,17 @@ function removeById(childDiv, parentDiv) } } +/** + * Call a url with 2 callbacks functions (success or error) + * + * @param {type} url + * @param {type} success + * @param {type} error + * @returns {undefined} + */ function callURL(url, success, error) { - url = encodeURI(url);console.log(url); + url = encodeURI(url); + console.log(url); $.ajax({url: url, dataType: 'json'}).done(success).fail(error); } diff --git a/src/main/webapp/index.jsp b/src/main/webapp/index.jsp index 20e6f68..ab1e907 100644 --- a/src/main/webapp/index.jsp +++ b/src/main/webapp/index.jsp @@ -23,7 +23,12 @@
            - +
            +

            SWAT4LS Workshop New!!

            +

            A COEUS Workshop/Tutorial will be presented in the next edition of SWAT4LS.

            +

            This workshop will be helded in Edinburgh, UK, December 9-12, 2013.

            +

            View more »

            +

            Hello, Semantic Web!

            diff --git a/src/main/webapp/science.jsp b/src/main/webapp/science.jsp index 35b7382..f2237ab 100644 --- a/src/main/webapp/science.jsp +++ b/src/main/webapp/science.jsp @@ -17,7 +17,8 @@ @@ -46,6 +47,30 @@

            ">Get Whitepaper

            +
            + +

            Visit website
            + December 9-12, 2013 Edinburgh, United Kingdom

            +

            Intro

            +

            Since 2008, the SWAT4LS Workshop (http://www.swat4ls.org) has provided a platform for the presentation and discussion of the benefits and limits of applying web-based information systems and semantic technologies in the domains of health care and life sciences. The next edition of SWAT4LS will be held in Edinburgh, UK, December 9-12, 2013, preceded by tutorials and followed by hackathon / model-a-thin. All information can be found at http://www.swat4ls.org/workshops/edinburgh2013/.

            +

            The COEUS Platform

            +

            On the tutorial day, the COEUS - Semantic Web Application Framework will be presented. This platform targets the quick creation of new biomedical applications. The framework combines the latest Semantic Web technologies with Rapid Application Development ideals to provide, in a single package, the required tools and algorithms to build a new semantic web information system from scratch. +

            In this tutorial/hands-on session, we will guide you through the process of creating your own custom COEUS knowledge base. You will learn how to:

            +
              +
            1. Create a new COEUS instance
            2. +
            3. From GitHub download to web deployment
            4. +
            5. Integrate data from heterogeneous *omics sources into your COEUS knowledge base
            6. +
            7. Create your mashup merging multiple datasets
            8. +
            9. Explore COEUS API to access aggregated data
            10. +
            11. Build new rich web information systems using the API
            12. +
            13. Access knowledge federation through the SPARQL and LinkedData interfaces +
            14. +
            + Further information regarding this tutorial is available online at http://www.swat4ls.org/workshops/edinburgh2013/scientific-programme/

            +
            +
            - +
            @@ -197,21 +205,7 @@
            - +
            + + diff --git a/src/main/webapp/setup/entities.jsp b/src/main/webapp/setup/entities.jsp index b51a7ba..dba1030 100644 --- a/src/main/webapp/setup/entities.jsp +++ b/src/main/webapp/setup/entities.jsp @@ -1,4 +1,4 @@ -<%-- +<%-- Document : index Created on : May 28, 2013, 11:20:32 AM Author : sernadela @@ -11,9 +11,58 @@ + @@ -83,7 +253,7 @@ -
            +
            - @@ -118,9 +287,6 @@ - - - -
            - - + + + + diff --git a/src/main/webapp/setup/seeds.jsp b/src/main/webapp/setup/seeds.jsp index 2b13a8a..866091c 100644 --- a/src/main/webapp/setup/seeds.jsp +++ b/src/main/webapp/setup/seeds.jsp @@ -16,7 +16,7 @@ $(document).ready(function() { callURL("../../config/getconfig/", fillHeader); - refreshSeeds(); + refresh(); //activate tooltip (bootstrap-tooltip.js is need) $('.icon-question-sign').tooltip(); @@ -26,8 +26,8 @@ if (event.charCode === 13) if (document.getElementById('addModal').style.display === "block" && document.activeElement.getAttribute('id') === "addModal") add(); - if (document.getElementById('editModal').style.display === "block" && document.activeElement.getAttribute('id') === "editModal") - edit(); + if (document.getElementById('editModal').style.display === "block" && document.activeElement.getAttribute('id') === "editModal") + edit(); }; }); @@ -41,7 +41,7 @@ var urlPrefix = "../../api/" + getApiKey(); cleanUnlikedTriples(urlPrefix); } - function refreshSeeds() { + function refresh() { var qSeeds = "SELECT DISTINCT ?seed ?s {?seed a coeus:Seed . ?seed dc:title ?s . }"; console.log(qSeeds); queryToResult(qSeeds, fillSeeds); @@ -59,7 +59,7 @@ + '

            ' + result[key].s.value + '

            ' + 'URI: ' + seed + '' + '' - + ' ' + + ' ' + '
            '; $('#seeds').append(a); @@ -67,51 +67,58 @@ } //Edit functions - function prepareEditSeed(seed) { + function prepareEdit(individual) { //reset values $('#editResult').html(""); - document.getElementById('editURI').innerHTML = seed; + document.getElementById('editURI').innerHTML = individual; $('#editTitle').val(""); $('#editLabel').val(""); $('#editComment').val(""); - - var q = "SELECT ?label ?title ?comment {" + seed + " dc:title ?title . " + seed + " rdfs:label ?label . " + seed + " rdfs:comment ?comment }"; - queryToResult(q, fillEditSeed); + + var q = "SELECT ?label ?title ?comment {" + individual + " dc:title ?title . " + individual + " rdfs:label ?label . " + individual + " rdfs:comment ?comment }"; + queryToResult(q, fillEdit); } - function fillEditSeed(result) { + function fillEdit(result) { //var resultTitle = json.results.bindings[0].title; console.log(result); - //PUT VALUES IN THE INPUT FIELD - $('#editTitle').val(result[0].title.value); - //document.getElementById('title').setAttribute("disabled"); - $('#editLabel').val(result[0].label.value); - $('#editComment').val(result[0].comment.value); + try + { + //PUT VALUES IN THE INPUT FIELD + $('#editTitle').val(result[0].title.value); + //document.getElementById('title').setAttribute("disabled"); + $('#editLabel').val(result[0].label.value); + $('#editComment').val(result[0].comment.value); + } + catch (err) + { + $('#editResult').append(generateHtmlMessage("Error!", "Some fields do not exist." + err, "alert-error")); + } //PUT OLD VALUES IN THE STATIC FIELD $('#oldTitle').val($('#editTitle').val()); $('#oldLabel').val($('#editLabel').val()); $('#oldComment').val($('#editComment').val()); } - function edit(){ - var individual=$('#editURI').html(); + function edit() { + var individual = $('#editURI').html(); var urlUpdate = "../../api/" + getApiKey() + "/update/"; var url; timer = setTimeout(function() { - $('#closeEditModal').click(); - refreshSeeds(); - }, delay); - - if ($('#oldLabel').val() !== $('#editLabel').val()){ - url=urlUpdate + individual + "/" + "rdfs:label" + "/xsd:string:" + $('#oldLabel').val() + ",xsd:string:" + $('#editLabel').val(); - callURL(url, showResult.bind(this,"#editResult",url),(this,"#editResult",url)); + $('#closeEditModal').click(); + refresh(); + }, delay); + + if ($('#oldLabel').val() !== $('#editLabel').val()) { + url = urlUpdate + individual + "/" + "rdfs:label" + "/xsd:string:" + $('#oldLabel').val() + ",xsd:string:" + $('#editLabel').val(); + callURL(url, showResult.bind(this, "#editResult", url), (this, "#editResult", url)); } - if ($('#oldTitle').val() !== $('#editTitle').val()){ - url=urlUpdate + individual + "/" + "dc:title" + "/xsd:string:" + $('#oldTitle').val() + ",xsd:string:" + $('#editTitle').val(); - callURL(url, showResult.bind(this,"#editResult",url),(this,"#editResult",url)); + if ($('#oldTitle').val() !== $('#editTitle').val()) { + url = urlUpdate + individual + "/" + "dc:title" + "/xsd:string:" + $('#oldTitle').val() + ",xsd:string:" + $('#editTitle').val(); + callURL(url, showResult.bind(this, "#editResult", url), (this, "#editResult", url)); } - if ($('#oldComment').val() !== $('#editComment').val()){ - url=urlUpdate + individual + "/" + "rdfs:comment" + "/xsd:string:" + $('#oldComment').val() + ",xsd:string:" + $('#editComment').val(); - callURL(url, showResult.bind(this,"#editResult",url),(this,"#editResult",url)); + if ($('#oldComment').val() !== $('#editComment').val()) { + url = urlUpdate + individual + "/" + "rdfs:comment" + "/xsd:string:" + $('#oldComment').val() + ",xsd:string:" + $('#editComment').val(); + callURL(url, showResult.bind(this, "#editResult", url), (this, "#editResult", url)); } } //End of Edit functions @@ -120,25 +127,25 @@ $('#removeResult').html(""); $('#removeModalLabel').html(seed); } - function removeSeed() { + function remove() { var seed = $('#removeModalLabel').html(); //var query = initSparqlerQuery(); console.log('Remove: ' + seed); var urlPrefix = "../../api/" + getApiKey(); //remove all subjects and predicates associated. - removeAllTriplesFromObject(urlPrefix, seed, showResult.bind(this,"#removeResult",""), showError.bind(this,"#removeResult","")); + removeAllTriplesFromObject(urlPrefix, seed, showResult.bind(this, "#removeResult", ""), showError.bind(this, "#removeResult", "")); //remove all predicates and objects associated. - removeAllTriplesFromSubject(urlPrefix, seed, showResult.bind(this,"#removeResult",""), showError.bind(this,"#removeResult","")); + removeAllTriplesFromSubject(urlPrefix, seed, showResult.bind(this, "#removeResult", ""), showError.bind(this, "#removeResult", "")); timer = setTimeout(function() { $('#closeRemoveModal').click(); - refreshSeeds(); + refresh(); }, delay); } //End of Remove functions - function changeURI(id,value) { + function changeURI(id, value) { document.getElementById(id).innerHTML = 'coeus:seed_' + value.split(' ').join('_'); } function add() { @@ -184,15 +191,15 @@ console.log(result[0].total.value); if (result[0].total.value == 0) { array.forEach(function(url) { - callURL(url, showResult.bind(this,"#addResult", url), showError.bind(this,"#addResult", url)); + callURL(url, showResult.bind(this, "#addResult", url), showError.bind(this, "#addResult", url)); }); timer = setTimeout(function() { $('#closeAddModal').click(); - refreshSeeds(); + refresh(); }, delay); } else { $('#addResult').append(generateHtmlMessage("Warning!", "This individual already exists.", "alert-warning")); - refreshSeeds(); + refresh(); } }); } @@ -264,7 +271,7 @@
            @@ -281,7 +288,7 @@
            - +
            From 8fc857b55cad7789170edfd8e21be40a771e8f8c Mon Sep 17 00:00:00 2001 From: sernadela Date: Wed, 16 Oct 2013 11:58:41 +0100 Subject: [PATCH 43/52] - Setup: Change Edit/Add/Remove Resources to modals. - Setup: Code improvements. --- src/main/webapp/assets/js/coeus.api.js | 405 +----- src/main/webapp/assets/js/coeus.setup.js | 1162 +++++++++++++++++ src/main/webapp/setup/addresource.jsp | 140 +- src/main/webapp/setup/concepts.jsp | 344 +---- src/main/webapp/setup/config.jsp | 2 +- src/main/webapp/setup/editenvironment.jsp | 2 +- src/main/webapp/setup/entities.jsp | 284 +--- src/main/webapp/setup/environments.jsp | 2 +- src/main/webapp/setup/index.jsp | 180 +-- src/main/webapp/setup/management.jsp | 78 -- src/main/webapp/setup/modals/add.jsp | 34 + src/main/webapp/setup/modals/addResource.jsp | 113 ++ src/main/webapp/setup/modals/edit.jsp | 35 + src/main/webapp/setup/modals/editResource.jsp | 131 ++ src/main/webapp/setup/modals/remove.jsp | 21 + src/main/webapp/setup/resources.jsp | 122 +- src/main/webapp/setup/seeds.jsp | 271 +--- 17 files changed, 1713 insertions(+), 1613 deletions(-) create mode 100644 src/main/webapp/assets/js/coeus.setup.js delete mode 100644 src/main/webapp/setup/management.jsp create mode 100644 src/main/webapp/setup/modals/add.jsp create mode 100644 src/main/webapp/setup/modals/addResource.jsp create mode 100644 src/main/webapp/setup/modals/edit.jsp create mode 100644 src/main/webapp/setup/modals/editResource.jsp create mode 100644 src/main/webapp/setup/modals/remove.jsp diff --git a/src/main/webapp/assets/js/coeus.api.js b/src/main/webapp/assets/js/coeus.api.js index 3807af8..1380531 100644 --- a/src/main/webapp/assets/js/coeus.api.js +++ b/src/main/webapp/assets/js/coeus.api.js @@ -70,407 +70,4 @@ function deleteTriple(subject, predicate, object, key) { console.log('[COEUS] unable to complete data delete request. ' + textStatus); // Server communication error function handler. }); -} -/** - * init service prefix - * @returns {query} */ -function initSparqlerQuery() { - var sparqler = new SPARQL.Service("/coeus/sparql"); - - var prefixes = getPrefixURI(); - for (var key in prefixes) { - sparqler.setPrefix(key, prefixes[key]); - } - - var query = sparqler.createQuery(); - return query; -} - -function getPrefixURI() { - var prefixes = { - dc: "http://purl.org/dc/elements/1.1/", - rdf: "http://www.w3.org/1999/02/22-rdf-syntax-ns#", - rdfs: "http://www.w3.org/2000/01/rdf-schema#", - coeus: "http://bioinformatics.ua.pt/coeus/resource/", - owl: "http://www.w3.org/2002/07/owl#" - }; - return prefixes; -} - -/** - * Get the namespace prefix - * - * @param {type} uri - * @returns {undefined} - */ -function getPrefix(uri) { - var prefixes = getPrefixURI(); - - for (var key in prefixes) { - if (prefixes[key] === uri) - return key; - } - return ''; -} - -/** - * Split the URI to give the namespace - * @param {type} uri - * @returns {splitURIPrefix.mapping} - */ -function splitURIPrefix(uri) { - var value; - var uriToSlit = uri; - if (uriToSlit.indexOf("#") !== -1) - value = uriToSlit.split('#').pop(); - else - value = uriToSlit.split('/').pop(); - var namespace = uri.substr(0, uri.length - value.length); - - var mapping = { - "namespace": namespace, - "value": value - }; - - return mapping; -} -/** - * Call api through URL and change the HTML (component id) according to the result. - * @param {type} url - * @param {type} html - * @returns {undefined} - */ -function callAPI(url, html) { - url = encodeURI(url); - $.ajax({url: url, async: false, dataType: 'json'}).done(function(data) { - console.log(url + ' ' + data.status); - if (data.status === 100) { - //$(html).append('Call: ' + url + '
            Message: ' + data.message+'

            '); - $(html).addClass('alert alert-success'); - } else { - $(html).addClass('alert alert-error'); - $(html).append('Call: ' + url + '
            Status: ' + data.status + ' Message: ' + data.message + '

            '); - } - - }).fail(function(jqXHR, textStatus) { - $(html).addClass('alert alert-error'); - $(html).append('Call: ' + url + '
            ' + 'ERROR: ' + textStatus + '

            '); - // Server communication error function handler. - }); -} -/** - * Return the first apikey - * - * @returns {unresolved} */ -function getApiKey() { - return document.getElementById('apikey').innerHTML.split('|')[0]; -} -/** - * Return last element divided by / of url - * @returns {unresolved} - */ -function lastPath() { - var pathArray = window.location.pathname.split('/'); - var path = pathArray[pathArray.length - 1]; - return path; -} - -/** - * Return penultimate element divided by / of url - * @returns {unresolved} - */ -function penulPath() { - var pathArray = window.location.pathname.split('/'); - var path = pathArray[pathArray.length - 2]; - return path; -} - -function redirect(location) { - window.location = location; -} -/** - * - * remove all subjects and predicates associated. - * - * example urlPrefix = "../../api/" + getApiKey() ; - * - * @param {type} urlPrefix - * @param {type} object - * @returns {undefined} - */ -function removeAllTriplesFromObject(urlPrefix, object, showResult, showError) { - - var qObject = "SELECT ?subject ?predicate {?subject ?predicate " + object + " . }"; - queryToResult(qObject, foreachRemoveObjects.bind(this, urlPrefix, object, showResult, showError)); -} -function foreachRemoveObjects(urlPrefix, object, showResult, showError, result) { - console.log(result); - for (var r in result) { - var subject = resultToObject(result[r].subject); - var predicate = resultToPredicate(result[r].predicate); - - var url = "/delete/" + subject.prefix + subject.value + '/' + predicate.prefix + predicate.value + '/' + object; - - console.log("Delete call: " + urlPrefix + url); - callURL(urlPrefix + url, showResult, showError); - } -} - - -function cleanUnlikedTriples(urlPrefix, showResult, showError) { - console.log("cleanUnlikedTriples call"); - //Clean unlinked entities - var qEntities = "SELECT * {{ ?entity a coeus:Entity . FILTER NOT EXISTS{ ?entity coeus:isIncludedIn ?seed }}UNION {?entity a coeus:Entity . FILTER NOT EXISTS { ?seed coeus:includes ?entity }} }"; - queryToResult(qEntities, function(result) { - for (var r in result) { - var entity = splitURIPrefix(result[r].entity.value); - var prefix = getPrefix(entity.namespace) + ":"; - removeAllTriplesFromSubject(urlPrefix, prefix + entity.value, showResult, showError); - } - }); - //Clean unlinked concepts - var qConcepts = "SELECT * {{ ?concept a coeus:Concept . FILTER NOT EXISTS{ ?concept coeus:hasEntity ?entity }}UNION {?concept a coeus:Concept . FILTER NOT EXISTS { ?entity coeus:isEntityOf ?concept }} }"; - queryToResult(qConcepts, function(result) { - for (var r in result) { - var concept = splitURIPrefix(result[r].concept.value); - var prefix = getPrefix(concept.namespace) + ":"; - removeAllTriplesFromSubject(urlPrefix, prefix + concept.value, showResult, showError); - } - }); - //Clean unlinked resources - var qResources = "SELECT * {{ ?resource a coeus:Resource . FILTER NOT EXISTS{ ?resource coeus:isResourceOf ?concept} }UNION {?resource a coeus:Resource . FILTER NOT EXISTS { ?concept coeus:hasResource ?resource}} }"; - queryToResult(qResources, function(result) { - for (var r in result) { - var resource = splitURIPrefix(result[r].resource.value); - var prefix = getPrefix(resource.namespace) + ":"; - removeAllTriplesFromSubject(urlPrefix, prefix + resource.value, showResult, showError); - } - }); - //Clean unlinked selectores - var qSelectores = "SELECT * {{ ?selector coeus:property ?property . FILTER NOT EXISTS { ?selector coeus:loadsFor ?resource } }UNION {?selector coeus:property ?property . FILTER NOT EXISTS { ?resource coeus:loadsFrom ?selector}}}"; - queryToResult(qSelectores, function(result) { - for (var r in result) { - var selector = splitURIPrefix(result[r].selector.value); - var prefix = getPrefix(selector.namespace) + ":"; - removeAllTriplesFromSubject(urlPrefix, prefix + selector.value, showResult, showError); - } - }); -} - -//function isModel(key) { -// var b = false; -// -// if (key.indexOf("coeus:seed_") !== -1 | key.indexOf("coeus:entity_") !== -1 | key.indexOf("coeus:concept_") !== -1 | key.indexOf("coeus:resource_") !== -1) -// b = true; -// -// console.log(key + ' ' + b); -// return b; -// -//} -// -//function removeRecursive(urlPrefix, subject) { -// var query = initSparqlerQuery(); -// var qObject = "SELECT ?predicate ?object {" + subject + " ?predicate ?object . }"; -// console.log("Recursive call: " + qObject); -// query.query(qObject, -// {success: function(json) { -// var result = json.results.bindings; -// -// for (var r in result) { -// var object = resultToObject(result[r].object); -// var predicate = resultToPredicate(result[r].predicate); -// -// var url = "/delete/" + subject + '/' + predicate.prefix + predicate.value + '/' + object.prefix + object.value; -// console.log("Recursive Delete call: " + urlPrefix + url); -// //callAPI(urlPrefix + url, "#result"); -// if (isModel(object.prefix + object.value)) { -// // console.log("Another recursive call: "+url); -// //removeRecursive(urlPrefix, object.prefix + object.value); -// } -// -// } -// -// -// }} -// ); -//} - -/** - * Remove all triples associated with the subject - * - * @param {type} urlPrefix - * @param {type} subject - * @param {type} showResult - * @param {type} showError - * @returns {undefined} - */ -function removeAllTriplesFromSubject(urlPrefix, subject, showResult, showError) { - var qSubject = "SELECT ?predicate ?object {" + subject + " ?predicate ?object . }"; - queryToResult(qSubject, foreachRemoveSubjects.bind(this, urlPrefix, subject, showResult, showError) - ); -} -function foreachRemoveSubjects(urlPrefix, subject, showResult, showError, result) { - console.log(result); - for (var r in result) { - var object = resultToObject(result[r].object); - var predicate = resultToPredicate(result[r].predicate); - - var url = "/delete/" + subject + '/' + predicate.prefix + predicate.value + '/' + object.prefix + object.value; - console.log("Deleting: " + url); - callURL(urlPrefix + url, showResult, showError); - } -} - -function removeAllTriplesFromSubjectAndPredicate(urlPrefix, subject, predicate) { - var qSubject = "SELECT ?object {" + subject + " " + predicate + " ?object . }"; - console.log(qSubject); - queryToResult(qSubject, function(result) { - console.log(result); - for (var r in result) { - var object = resultToObject(result[r].object); - - var url = "/delete/" + subject + '/' + predicate + '/' + object.prefix + object.value; - console.log(url); - callAPI(urlPrefix + url, "#result"); - } - - //if success refresh page - if (document.getElementById('result').className !== 'alert alert-error') { - // window.location="../entity/"+lastPath(); - console.log("REDIRECTING..."); - //window.location.reload(true); - } - } - ); -} -function removeAllTriplesFromPredicateAndObject(urlPrefix, predicate, object) { - var qSubject = "SELECT ?subject {?subject " + predicate + " " + object + " . }"; - console.log(qSubject); - queryToResult(qSubject, function(result) { - console.log(result); - for (var r in result) { - var subject = resultToPredicate(result[r].subject); - - var url = "/delete/" + subject.prefix + subject.value + '/' + predicate + '/' + object; - //console.log(url); - callAPI(urlPrefix + url, "#result"); - } - } - ); -} - -/** - * Converts a object from the json result to a url usage - * @param {type} object - * @returns {resultToObject.mapping} - */ -function resultToObject(object) { - var val = object.value; - var objectPrefix = ''; - - if (object.type === "uri") { - var splitedObject = splitURIPrefix(val); - val = splitedObject.value; - objectPrefix = getPrefix(splitedObject.namespace); - } - - if (objectPrefix !== '') - objectPrefix = objectPrefix + ':'; - else - objectPrefix = 'xsd:' + splitURIPrefix(object.datatype).value + ':' + objectPrefix; - //TO ALLOW '/' in the string call encodeBars(string); - var mapping = { - "prefix": objectPrefix, - "value": encodeBars(val) - }; - return mapping; -} -/** - * Converts a predicate from the json result to a url usage - * @param {type} pred - * @returns {resultToPredicate.mapping} - */ -function resultToPredicate(pred) { - var splitedPredicate = splitURIPrefix(pred.value); - var predicatePrefix = getPrefix(splitedPredicate.namespace); - if (predicatePrefix !== '') - predicatePrefix = predicatePrefix + ':'; - - var mapping = { - "prefix": predicatePrefix, - "value": splitedPredicate.value - }; - - return mapping; - -} -/** - * Do a query to retrive the result in a callback way - * - * return callback(result); - * - * @param {type} selectQuery - * @param {type} callback - * @returns {undefined} - */ -function queryToResult(selectQuery, callback) { - var query = initSparqlerQuery(); - query.query(selectQuery, - {success: function(json) { - var result = json.results.bindings; - //console.log(result); - callback(result); - }} - ); -} - -function encodeBars(value) { - value = value.split(';').join('%3B'); - value = value.split('/').join('%2F'); - value = value.split('#').join('%23'); - value = value.split('?').join('%3F'); - return value; -} -function removeById(childDiv, parentDiv) -{ - console.log(childDiv + ' ' + parentDiv); - if (childDiv === parentDiv) { - alert("The parent div cannot be removed."); - } - else if (document.getElementById(childDiv)) { - var child = document.getElementById(childDiv); - var parent = document.getElementById(parentDiv); - parent.removeChild(child); - } - else { - alert("Child div has already been removed or does not exist."); - } -} - -/** - * Call a url with 2 callbacks functions (success or error) - * - * @param {type} url - * @param {type} success - * @param {type} error - * @returns {undefined} - */ -function callURL(url, success, error) { - url = encodeURI(url); - console.log(url); - $.ajax({url: url, dataType: 'json'}).done(success).fail(error); -} - -/** - * Generate a html code message - * Ex: var htmlMessage=generateHtmlMessage("Error!", "It already exists!","alert-error"); - * - * @param {type} strong - * @param {type} message - * @param {type} type - * @returns {String} - */ -function generateHtmlMessage(strong, message, type) { - var error = '
            ' + strong + ' ' + message + '
            '; - return error; -} +} \ No newline at end of file diff --git a/src/main/webapp/assets/js/coeus.setup.js b/src/main/webapp/assets/js/coeus.setup.js new file mode 100644 index 0000000..c58631e --- /dev/null +++ b/src/main/webapp/assets/js/coeus.setup.js @@ -0,0 +1,1162 @@ +/** + * COEUS Setup JS functions (included in most pages..) + */ + +/** + * init service prefix + * @returns {query} */ +function initSparqlerQuery() { + var sparqler = new SPARQL.Service("/coeus/sparql"); + + var prefixes = getPrefixURI(); + for (var key in prefixes) { + sparqler.setPrefix(key, prefixes[key]); + } + + var query = sparqler.createQuery(); + return query; +} + +function getPrefixURI() { + var prefixes = { + dc: "http://purl.org/dc/elements/1.1/", + rdf: "http://www.w3.org/1999/02/22-rdf-syntax-ns#", + rdfs: "http://www.w3.org/2000/01/rdf-schema#", + coeus: "http://bioinformatics.ua.pt/coeus/resource/", + owl: "http://www.w3.org/2002/07/owl#" + }; + return prefixes; +} + +/** + * Get the namespace prefix + * + * @param {type} uri + * @returns {undefined} + */ +function getPrefix(uri) { + var prefixes = getPrefixURI(); + + for (var key in prefixes) { + if (prefixes[key] === uri) + return key; + } + return ''; +} + +/** + * Split the URI to give the namespace + * @param {type} uri + * @returns {splitURIPrefix.mapping} + */ +function splitURIPrefix(uri) { + var value; + var uriToSlit = uri; + if (uriToSlit.indexOf("#") !== -1) + value = uriToSlit.split('#').pop(); + else + value = uriToSlit.split('/').pop(); + var namespace = uri.substr(0, uri.length - value.length); + + var mapping = { + "namespace": namespace, + "value": value + }; + + return mapping; +} +/** + * Call api through URL and change the HTML (component id) according to the result. + * @param {type} url + * @param {type} html + * @returns {undefined} + */ +//function callAPI(url, html) { +// url = encodeURI(url); +// $.ajax({url: url, async: false, dataType: 'json'}).done(function(data) { +// console.log(url + ' ' + data.status); +// if (data.status === 100) { +// //$(html).append('Call: ' + url + '
            Message: ' + data.message+'

            '); +// $(html).addClass('alert alert-success'); +// } else { +// $(html).addClass('alert alert-error'); +// $(html).append('Call: ' + url + '
            Status: ' + data.status + ' Message: ' + data.message + '

            '); +// } +// +// }).fail(function(jqXHR, textStatus) { +// $(html).addClass('alert alert-error'); +// $(html).append('Call: ' + url + '
            ' + 'ERROR: ' + textStatus + '

            '); +// // Server communication error function handler. +// }); +//} +/** + * Return the first apikey + * + * @returns {unresolved} */ +function getApiKey() { + return document.getElementById('apikey').innerHTML.split('|')[0]; +} +/** + * Return last element divided by / of url + * @returns {unresolved} + */ +function lastPath() { + var pathArray = window.location.pathname.split('/'); + var path = pathArray[pathArray.length - 1]; + return path; +} + +/** + * Return penultimate element divided by / of url + * @returns {unresolved} + */ +function penulPath() { + var pathArray = window.location.pathname.split('/'); + var path = pathArray[pathArray.length - 2]; + return path; +} + +function redirect(location) { + window.location = location; +} +/** + * + * remove all subjects and predicates associated. + * + * example urlPrefix = "../../api/" + getApiKey() ; + * + * @param {type} urlPrefix + * @param {type} object + * @returns {undefined} + */ +function removeAllTriplesFromObject(urlPrefix, object, showResult, showError) { + + var qObject = "SELECT ?subject ?predicate {?subject ?predicate " + object + " . }"; + queryToResult(qObject, foreachRemoveObjects.bind(this, urlPrefix, object, showResult, showError)); +} +function foreachRemoveObjects(urlPrefix, object, showResult, showError, result) { + console.log(result); + for (var r in result) { + var subject = resultToObject(result[r].subject); + var predicate = resultToPredicate(result[r].predicate); + + var url = "/delete/" + subject.prefix + subject.value + '/' + predicate.prefix + predicate.value + '/' + object; + + console.log("Delete call: " + urlPrefix + url); + callURL(urlPrefix + url, showResult, showError); + } +} + +/** + * Clears all unlinked triples in the DB + * @param {type} urlPrefix + * @param {type} showResult + * @param {type} showError + * @returns {undefined} + */ +function cleanUnlikedTriples(urlPrefix, showResult, showError) { + console.log("cleanUnlikedTriples call"); + //Clean unlinked entities + var qEntities = "SELECT * {{ ?entity a coeus:Entity . FILTER NOT EXISTS{ ?entity coeus:isIncludedIn ?seed }}UNION {?entity a coeus:Entity . FILTER NOT EXISTS { ?seed coeus:includes ?entity }} }"; + queryToResult(qEntities, function(result) { + for (var r in result) { + var entity = splitURIPrefix(result[r].entity.value); + var prefix = getPrefix(entity.namespace) + ":"; + removeAllTriplesFromSubject(urlPrefix, prefix + entity.value, showResult, showError); + } + }); + //Clean unlinked concepts + var qConcepts = "SELECT * {{ ?concept a coeus:Concept . FILTER NOT EXISTS{ ?concept coeus:hasEntity ?entity }}UNION {?concept a coeus:Concept . FILTER NOT EXISTS { ?entity coeus:isEntityOf ?concept }} }"; + queryToResult(qConcepts, function(result) { + for (var r in result) { + var concept = splitURIPrefix(result[r].concept.value); + var prefix = getPrefix(concept.namespace) + ":"; + removeAllTriplesFromSubject(urlPrefix, prefix + concept.value, showResult, showError); + } + }); + //Clean unlinked resources + var qResources = "SELECT * {{ ?resource a coeus:Resource . FILTER NOT EXISTS{ ?resource coeus:isResourceOf ?concept} }UNION {?resource a coeus:Resource . FILTER NOT EXISTS { ?concept coeus:hasResource ?resource}} }"; + queryToResult(qResources, function(result) { + for (var r in result) { + var resource = splitURIPrefix(result[r].resource.value); + var prefix = getPrefix(resource.namespace) + ":"; + removeAllTriplesFromSubject(urlPrefix, prefix + resource.value, showResult, showError); + } + }); + //Clean unlinked selectores + var qSelectores = "SELECT * {{ ?selector coeus:property ?property . FILTER NOT EXISTS { ?selector coeus:loadsFor ?resource } }UNION {?selector coeus:property ?property . FILTER NOT EXISTS { ?resource coeus:loadsFrom ?selector}}}"; + queryToResult(qSelectores, function(result) { + for (var r in result) { + var selector = splitURIPrefix(result[r].selector.value); + var prefix = getPrefix(selector.namespace) + ":"; + removeAllTriplesFromSubject(urlPrefix, prefix + selector.value, showResult, showError); + } + }); +} + +//function isModel(key) { +// var b = false; +// +// if (key.indexOf("coeus:seed_") !== -1 | key.indexOf("coeus:entity_") !== -1 | key.indexOf("coeus:concept_") !== -1 | key.indexOf("coeus:resource_") !== -1) +// b = true; +// +// console.log(key + ' ' + b); +// return b; +// +//} +// +//function removeRecursive(urlPrefix, subject) { +// var query = initSparqlerQuery(); +// var qObject = "SELECT ?predicate ?object {" + subject + " ?predicate ?object . }"; +// console.log("Recursive call: " + qObject); +// query.query(qObject, +// {success: function(json) { +// var result = json.results.bindings; +// +// for (var r in result) { +// var object = resultToObject(result[r].object); +// var predicate = resultToPredicate(result[r].predicate); +// +// var url = "/delete/" + subject + '/' + predicate.prefix + predicate.value + '/' + object.prefix + object.value; +// console.log("Recursive Delete call: " + urlPrefix + url); +// //callAPI(urlPrefix + url, "#result"); +// if (isModel(object.prefix + object.value)) { +// // console.log("Another recursive call: "+url); +// //removeRecursive(urlPrefix, object.prefix + object.value); +// } +// +// } +// +// +// }} +// ); +//} + +/** + * Remove all triples associated with the subject + * + * @param {type} urlPrefix + * @param {type} subject + * @param {type} showResult + * @param {type} showError + * @returns {undefined} + */ +function removeAllTriplesFromSubject(urlPrefix, subject, showResult, showError) { + var qSubject = "SELECT ?predicate ?object {" + subject + " ?predicate ?object . }"; + queryToResult(qSubject, foreachRemoveSubjects.bind(this, urlPrefix, subject, showResult, showError) + ); +} +function foreachRemoveSubjects(urlPrefix, subject, showResult, showError, result) { + console.log(result); + for (var r in result) { + var object = resultToObject(result[r].object); + var predicate = resultToPredicate(result[r].predicate); + + var url = "/delete/" + subject + '/' + predicate.prefix + predicate.value + '/' + object.prefix + object.value; + console.log("Deleting: " + url); + callURL(urlPrefix + url, showResult, showError); + } +} + +//function removeAllTriplesFromSubjectAndPredicate(urlPrefix, subject, predicate) { +// var qSubject = "SELECT ?object {" + subject + " " + predicate + " ?object . }"; +// console.log(qSubject); +// queryToResult(qSubject, function(result) { +// console.log(result); +// for (var r in result) { +// var object = resultToObject(result[r].object); +// +// var url = "/delete/" + subject + '/' + predicate + '/' + object.prefix + object.value; +// console.log(url); +// callAPI(urlPrefix + url, "#result"); +// } +// +// //if success refresh page +// if (document.getElementById('result').className !== 'alert alert-error') { +// // window.location="../entity/"+lastPath(); +// console.log("REDIRECTING..."); +// //window.location.reload(true); +// } +// } +// ); +//} +//function removeAllTriplesFromPredicateAndObject(urlPrefix, predicate, object) { +// var qSubject = "SELECT ?subject {?subject " + predicate + " " + object + " . }"; +// console.log(qSubject); +// queryToResult(qSubject, function(result) { +// console.log(result); +// for (var r in result) { +// var subject = resultToPredicate(result[r].subject); +// +// var url = "/delete/" + subject.prefix + subject.value + '/' + predicate + '/' + object; +// //console.log(url); +// callAPI(urlPrefix + url, "#result"); +// } +// } +// ); +//} + +/** + * Converts a object from the json result to a url usage + * @param {type} object + * @returns {resultToObject.mapping} + */ +function resultToObject(object) { + var val = object.value; + var objectPrefix = ''; + + if (object.type === "uri") { + var splitedObject = splitURIPrefix(val); + val = splitedObject.value; + objectPrefix = getPrefix(splitedObject.namespace); + } + + if (objectPrefix !== '') + objectPrefix = objectPrefix + ':'; + else + objectPrefix = 'xsd:' + splitURIPrefix(object.datatype).value + ':' + objectPrefix; + //TO ALLOW '/' in the string call encodeBars(string); + var mapping = { + "prefix": objectPrefix, + "value": encodeBars(val) + }; + return mapping; +} +/** + * Converts a predicate from the json result to a url usage + * @param {type} pred + * @returns {resultToPredicate.mapping} + */ +function resultToPredicate(pred) { + var splitedPredicate = splitURIPrefix(pred.value); + var predicatePrefix = getPrefix(splitedPredicate.namespace); + if (predicatePrefix !== '') + predicatePrefix = predicatePrefix + ':'; + + var mapping = { + "prefix": predicatePrefix, + "value": splitedPredicate.value + }; + + return mapping; + +} +/** + * Do a query to retrive the result in a callback way + * + * return callback(result); + * + * @param {type} selectQuery + * @param {type} callback + * @returns {undefined} + */ +function queryToResult(selectQuery, callback) { + var query = initSparqlerQuery(); + query.query(selectQuery, + {success: function(json) { + var result = json.results.bindings; + //console.log(result); + callback(result); + }} + ); +} + +/** + * Manually encode of some chars (;/#?) + * @param {type} value + * @returns {unresolved} + */ +function encodeBars(value) { + value = value.split(';').join('%3B'); + value = value.split('/').join('%2F'); + value = value.split('#').join('%23'); + value = value.split('?').join('%3F'); + return value; +} +/** + * Remove an component by id + * @param {type} childDiv + * @param {type} parentDiv + * @returns {undefined} + */ +function removeById(childDiv, parentDiv) +{ + console.log(childDiv + ' ' + parentDiv); + if (childDiv === parentDiv) { + alert("The parent div cannot be removed."); + } + else if (document.getElementById(childDiv)) { + var child = document.getElementById(childDiv); + var parent = document.getElementById(parentDiv); + parent.removeChild(child); + } + else { + alert("Child div has already been removed or does not exist."); + } +} + +/** + * Call a url with 2 callbacks functions (success or error) + * + * @param {type} url + * @param {type} success + * @param {type} error + * @returns {undefined} + */ +function callURL(url, success, error) { + url = encodeURI(url); + console.log(url); + $.ajax({url: url, dataType: 'json'}).done(success).fail(error); +} + +/** + * Generate a html code message + * Ex: var htmlMessage=generateHtmlMessage("Error!", "It already exists!","alert-error"); + * + * @param {type} strong + * @param {type} message + * @param {type} type + * @returns {String} + */ +function generateHtmlMessage(strong, message, type) { + var error = '
            ' + strong + ' ' + message + '
            '; + return error; +} + +/** + * Begin of the code used to manage the modals (Seed,Entity,Concept) + */ + +/** + * Associate click event to loading btn's. + */ +$('.loading').click(function() { + var text = $(this).html(); + $(this).html('Waiting...'); + $(this).addClass('disabled'); + setTimeout(btnInit.bind(this, text), 1500); + + function btnInit(text) { + $(this).html(text); + $(this).removeClass('disabled'); + } +}); +//timer for manage success or errors on modals +var timer; +var delay = 1000; + +/** + * Remove the link between the triples and the triples + * @returns {undefined} + */ +function remove() { + var individual = $('#removeModalLabel').html(); + //var query = initSparqlerQuery(); + console.log('Remove: ' + individual); + + var urlPrefix = "../../api/" + getApiKey(); + //remove all subjects and predicates associated. + removeAllTriplesFromObject(urlPrefix, individual, showResult.bind(this, "#removeResult", ""), showError.bind(this, "#removeResult", "")); + //remove all predicates and objects associated. + removeAllTriplesFromSubject(urlPrefix, individual, showResult.bind(this, "#removeResult", ""), showError.bind(this, "#removeResult", "")); + + timer = setTimeout(function() { + $('#closeRemoveModal').click(); + refresh(); + }, delay); + +} +/** + * remove preview - called before remove + * @param {type} individual + * @returns {undefined} + */ +function selectToRemove(individual) { + $('#removeResult').html(""); + $('#removeModalLabel').html(individual); + if (individual.indexOf('coeus:entity') === 0) { + $('#removeType').html("Entity"); + } else if (individual.indexOf('coeus:concept') === 0) { + $('#removeType').html("Concept"); + } else if (individual.indexOf('coeus:seed') === 0) { + $('#removeType').html("Seed"); + } else if (individual.indexOf('coeus:resource') === 0) { + $('#removeType').html("Resource"); + } else { + } +} +//End of Remove functions +//Edit functions +/** + * Edit preview for Seed,Entity or Concept + * @param {type} individual + * @returns {undefined} + */ +function prepareEdit(individual) { + //reset values + $('#editResult').html(""); + document.getElementById('editURI').innerHTML = individual; + if (individual.indexOf('coeus:entity') === 0) { + $('#editType').html("Entity"); + $('#helpEdit').html("Entity individuals match the general data terms. These elements grouping concepts with a common set of properties."); + } else if (individual.indexOf('coeus:concept') === 0) { + $('#editType').html("Concept"); + $('#helpEdit').html("Concept individuals are area-specific terms, aggregating any number of items and belonging to a unique entity. Concept individuals are also connected to Resources."); + } else if (individual.indexOf('coeus:seed') === 0) { + $('#editType').html("Seed"); + $('#helpEdit').html("A Seed defines a single framework instance that permits access to all data available in the seed, providing an over-arching entry point to the system information. Seed individuals are also connected to included entities. "); + } else { + } + + $('#editTitle').val(""); + $('#editLabel').val(""); + $('#editComment').val(""); + + var q = "SELECT ?label ?title ?comment {" + individual + " dc:title ?title . " + individual + " rdfs:label ?label . " + individual + " rdfs:comment ?comment }"; + queryToResult(q, fillEdit); +} +function fillEdit(result) { + //var resultTitle = json.results.bindings[0].title; + console.log(result); + try + { + //PUT VALUES IN THE INPUT FIELD + $('#editTitle').val(result[0].title.value); + //document.getElementById('title').setAttribute("disabled"); + $('#editLabel').val(result[0].label.value); + $('#editComment').val(result[0].comment.value); + } + catch (err) + { + $('#editResult').append(generateHtmlMessage("Error!", "Some fields do not exist." + err, "alert-error")); + } + //PUT OLD VALUES IN THE STATIC FIELD + $('#oldTitle').val($('#editTitle').val()); + $('#oldLabel').val($('#editLabel').val()); + $('#oldComment').val($('#editComment').val()); + +} +/** + * Function to edit a Seed, Entity or Concept + * @returns {undefined} + */ +function edit() { + var individual = $('#editURI').html(); + var urlUpdate = "../../api/" + getApiKey() + "/update/"; + var url; + timer = setTimeout(function() { + $('#closeEditModal').click(); + refresh(); + }, delay); + + if ($('#oldLabel').val() !== $('#editLabel').val()) { + url = urlUpdate + individual + "/" + "rdfs:label" + "/xsd:string:" + $('#oldLabel').val() + ",xsd:string:" + $('#editLabel').val(); + callURL(url, showResult.bind(this, "#editResult", url), (this, "#editResult", url)); + } + if ($('#oldTitle').val() !== $('#editTitle').val()) { + url = urlUpdate + individual + "/" + "dc:title" + "/xsd:string:" + $('#oldTitle').val() + ",xsd:string:" + $('#editTitle').val(); + callURL(url, showResult.bind(this, "#editResult", url), (this, "#editResult", url)); + } + if ($('#oldComment').val() !== $('#editComment').val()) { + url = urlUpdate + individual + "/" + "rdfs:comment" + "/xsd:string:" + $('#oldComment').val() + ",xsd:string:" + $('#editComment').val(); + callURL(url, showResult.bind(this, "#editResult", url), (this, "#editResult", url)); + } +} +//End of Edit functions + +/** + * change the uri when the user fill the title box. + * @param {type} type + * @param {type} link + * @returns {undefined} + */ +function changeURI(id, type, value) { + document.getElementById(id).innerHTML = 'coeus:' + type.toLowerCase() + '_' + value.split(' ').join('_'); +} +/** + * Function to be called before add a Seed, Entity or Concept + * @param {type} type + * @param {type} link + * @returns {undefined} + */ +function prepareAdd(type, link) { + $('#addResult').html(""); + $('#title').val(""); + $('#label').val(""); + $('#comment').val(""); + $('#linkedWith').val(link); + //$('#addType').html(type); + var individual = 'coeus:' + type.toLowerCase(); + document.getElementById('uri').innerHTML = individual; + + if (individual.indexOf('coeus:entity') === 0) { + $('#addType').html("Entity"); + $('#helpAdd').html("Entity individuals match the general data terms. These elements grouping concepts with a common set of properties."); + } else if (individual.indexOf('coeus:concept') === 0) { + $('#addType').html("Concept"); + $('#helpAdd').html("Concept individuals are area-specific terms, aggregating any number of items and belonging to a unique entity. Concept individuals are also connected to Resources."); + } else if (individual.indexOf('coeus:seed') === 0) { + $('#addType').html("Seed"); + $('#helpAdd').html("A Seed defines a single framework instance that permits access to all data available in the seed, providing an over-arching entry point to the system information. Seed individuals are also connected to included entities. "); + } else { + } + +} +/** + * Function to add a Seed, Entity or Concept + * @param {type} id + * @param {type} url + * @param {type} result + * @returns {undefined} + */ +function add() { + + var individual = $('#uri').html(); + var type = $('#addType').html(); + console.log("Adding type: " + type); + var title = $('#title').val(); + var label = $('#label').val(); + var comment = $('#comment').val(); + var urlWrite = "../../api/" + getApiKey() + "/write/"; + var link = $('#linkedWith').val(); + + // verify all fields: + var empty = false; + if (title === '') { + $('#titleForm').addClass('controls control-group error'); + empty = true; + } else + $('#titleForm').removeClass('controls control-group error'); + if (label === '') { + $('#labelForm').addClass('controls control-group error'); + empty = true; + } else + $('#labelForm').removeClass('controls control-group error'); + if (comment === '') { + $('#commentForm').addClass('controls control-group error'); + empty = true; + } else + $('#commentForm').removeClass('controls control-group error'); + if (!empty) { + var array = new Array(); + var urlIndividual = urlWrite + individual + "/rdf:type/owl:NamedIndividual"; + var urlType = urlWrite + individual + "/rdf:type/coeus:" + type; + var urlTitle = urlWrite + individual + "/dc:title/xsd:string:" + title; + var urlLabel = urlWrite + individual + "/rdfs:label/xsd:string:" + label; + var urlComment = urlWrite + individual + "/rdfs:comment/xsd:string:" + comment; + if (type === 'Entity') { + var urlIsIncludedIn = urlWrite + individual + "/coeus:isIncludedIn/" + link; + var urlIncludes = urlWrite + link + "/coeus:includes/" + individual; + array.push(urlIndividual, urlType, urlTitle, urlLabel, urlComment, urlIsIncludedIn, urlIncludes); + } else if (type === 'Concept') { + var urlHasEntity = urlWrite + individual + "/coeus:hasEntity/" + link; + var urlIsEntityOf = urlWrite + link + "/coeus:isEntityOf/" + individual; + array.push(urlIndividual, urlType, urlTitle, urlLabel, urlComment, urlHasEntity, urlIsEntityOf); + } else { + array.push(urlIndividual, urlType, urlTitle, urlLabel, urlComment); + } + submitIfNotExists(array, individual); + } +} +function submitIfNotExists(array, individual) { + var qSeeds = "SELECT (COUNT(*) AS ?total) {" + individual + " ?p ?o }"; + queryToResult(qSeeds, function(result) { + if (result[0].total.value == 0) { + + timer = setTimeout(function() { + if (individual.indexOf('coeus:resource') === 0) { + $('#closeAddResourceModal').click(); + refresh(); + } + else { + $('#closeAddModal').click(); + refresh(); + } + }, delay); + + if (individual.indexOf('coeus:resource') !== 0) { + var idResult = "#addResult"; + } else { + var idResult = "#addResourceResult"; + } + //call the service + array.forEach(function(url) { + callURL(url, showResult.bind(this, idResult, url), showError.bind(this, idResult, url)); + + }); + } else { + console.log('This individual ' + individual + ' already exists.'); + if (individual.indexOf('coeus:resource') !== 0) { + $('#addResult').append(generateHtmlMessage("Warning!", "This individual already exists. Try another title.", "alert-warning")); + } else { + $('#addResourceResult').append(generateHtmlMessage("Warning!", "This individual already exists. Try another title.", "alert-warning")); + } + } + }); +} +/** + * show the retrived result in the div (id) + * + * @param {type} id + * @param {type} url + * @param {type} result + * @returns {undefined} + */ +function showResult(id, url, result) { + if (result.status === 100) { + $(id).append(generateHtmlMessage("Success!", url + "
            " + result.message, "alert-success")); + } + else { + clearTimeout(timer); + $(id).append(generateHtmlMessage("Warning!", url + "
            Status Code:" + result.status + " " + result.message, "alert-warning")); + } +} +/** + * show the error result in the div (id) + * @param {type} id + * @param {type} url + * @param {type} jqXHR + * @param {type} result + * @returns {undefined} + */ +function showError(id, url, jqXHR, result) { + clearTimeout(timer); + $(id).append(generateHtmlMessage("Server error!", url + "
            Status Code:" + result.status + " " + result.message, "alert-error")); +} + +/** + * End of the code used to manage the modals (Seed,Entity,Concept) + */ + +/** + * Begin of the code used to manage the modals (Resource) + */ + +/** + * called before add resource to clean input fields + * @param {type} link + * @returns {undefined} + */ +function prepareAddResourceModal(link) { + $('#addResourceResult').html(""); + $('#titleResource').val(""); + $('#labelResource').val(""); + $('#commentResource').val(""); + document.getElementById('resourceURI').innerHTML = 'coeus:resource'; + $('#method').val(""); + $('#publisher').val(""); + $('#endpoint').val(""); + $('#query').val(""); + $('#order').val(""); + $('#extends').val(""); + $('#resourceLink').val(link); + var q = "SELECT ?concept ?c {?entity coeus:isEntityOf " + link + " . ?seed coeus:includes ?entity . ?concept coeus:hasEntity ?ent . ?ent coeus:isIncludedIn ?seed . ?concept dc:title ?c}"; + queryToResult(q, fillConceptsExtension); +} +function fillConceptsExtension(result) { + $('#extends').html(""); + $('#editExtends').html(""); + for (var r in result) { + var concept = splitURIPrefix(result[r].concept.value); + $('#extends').append(''); + $('#editExtends').append(''); + } +} +/** + * Add a Resource + * @returns {undefined} + */ +function addResource() { + + var type = 'Resource'; + var individual = $('#resourceURI').html(); + var title = $('#titleResource').val(); + var label = $('#labelResource').val(); + var comment = $('#commentResource').val(); + var method = $('#method').val(); + var publisher = $('#publisher').val(); + var endpoint = $('#endpoint').val(); + var query = $('#query').val(); + var order = $('#order').val(); + var concept_ext = $('#extends').val(); + var link = $('#resourceLink').val(); + var urlWrite = "../../api/" + getApiKey() + "/write/"; + + // verify all fields: + var empty = false; + if (title === '') { + $('#resourceTitleForm').addClass('controls control-group error'); + empty = true; + } else + $('#resourceTitleForm').removeClass('controls control-group error'); + if (label === '') { + $('#resourceLabelForm').addClass('controls control-group error'); + empty = true; + } else + $('#resourceLabelForm').removeClass('controls control-group error'); + if (comment === '') { + $('#resourceCommentForm').addClass('controls control-group error'); + empty = true; + } else + $('#resourceCommentForm').removeClass('controls control-group error'); + if (endpoint === '') { + $('#endpointForm').addClass('controls control-group error'); + empty = true; + } else + $('#endpointForm').removeClass('controls control-group error'); + if (query === '' && publisher !== ("csv")) { + $('#queryForm').addClass('controls control-group error'); + empty = true; + } else + $('#queryForm').removeClass('controls control-group error'); + if (order === '') { + $('#orderForm').addClass('controls control-group error'); + empty = true; + } else + $('#orderForm').removeClass('controls control-group error'); + if (!empty) { + var array = new Array(); + var urlIndividual = urlWrite + individual + "/rdf:type/owl:NamedIndividual"; + var urlType = urlWrite + individual + "/rdf:type/coeus:" + type; + var urlTitle = urlWrite + individual + "/dc:title/xsd:string:" + title; + var urlLabel = urlWrite + individual + "/rdfs:label/xsd:string:" + label; + var urlComment = urlWrite + individual + "/rdfs:comment/xsd:string:" + comment; + var urlIsResourceOf = urlWrite + individual + "/" + "coeus:isResourceOf" + "/" + link; + var urlHasResource = urlWrite + link + "/" + "coeus:hasResource" + "/" + individual; + var urlMethod = urlWrite + individual + "/" + "coeus:method" + "/xsd:string:" + method; + var urlPublisher = urlWrite + individual + "/" + "dc:publisher" + "/xsd:string:" + publisher; + var urlEndpoint = urlWrite + individual + "/" + "coeus:endpoint" + "/xsd:string:" + encodeBars(endpoint); + var urlQuery = urlWrite + individual + "/" + "coeus:query" + "/xsd:string:" + encodeBars(query); + var urlOrder = urlWrite + individual + "/" + "coeus:order" + "/xsd:string:" + order; + var urlExtends = urlWrite + individual + "/" + "coeus:extends" + "/coeus:" + concept_ext; + var urlIsExtendedBy = urlWrite + "coeus:" + concept_ext + "/" + "coeus:isExtendedBy" + "/" + individual; + var urlBuilt = urlWrite + individual + "/" + "coeus:built" + "/xsd:boolean:false"; + + array.push(urlIndividual, urlType, urlTitle, urlLabel, urlComment, urlIsResourceOf, urlHasResource, urlMethod, urlPublisher, urlEndpoint, urlQuery, urlOrder, urlExtends, urlIsExtendedBy, urlBuilt); + submitIfNotExists(array, individual); + } +} +/** + * Called when user change publisher in the modal Resource + * @param {type} mode + * @returns {undefined} + */ +function publisherChange(mode) { + + if (mode === 'edit') { + //sql + var publisher = $('#editPublisher').val(); + var sqlEnpointForm = '#editSqlEndpointForm'; + var enpointForm = '#editEndpointForm'; + var endpoint = '#editEndpoint'; + var driverEndpoint = '#editDriverEndpoint'; + var hostEndpoint = '#editHostEndpoint'; + var dbEndpoint = '#editBbEndpoint'; + var portEndpoint = '#editPortEndpoint'; + var userEndpoint = '#editUserEndpoint'; + var passwordEndpoint = '#editPasswordEndpoint'; + //csv + var query = '#editQuery'; + var queryForm = '#editQueryForm'; + var csvQueryForm = '#editCsvQueryForm'; + var csvQueryDelimiter = '#editCsvQueryDelimiter'; + var csvQueryHeaderSkip = '#editCsvQueryHeaderSkip'; + } else { + //sql + var publisher = $('#publisher').val(); + var sqlEnpointForm = '#sqlEndpointForm'; + var enpointForm = '#endpointForm'; + var endpoint = '#endpoint'; + var driverEndpoint = '#driverEndpoint'; + var hostEndpoint = '#hostEndpoint'; + var dbEndpoint = '#dbEndpoint'; + var portEndpoint = '#portEndpoint'; + var userEndpoint = '#userEndpoint'; + var passwordEndpoint = '#passwordEndpoint'; + //csv + var query = '#query'; + var queryForm = '#queryForm'; + var csvQueryForm = '#csvQueryForm'; + var csvQueryDelimiter = '#csvQueryDelimiter'; + var csvQueryHeaderSkip = '#csvQueryHeaderSkip'; + } + + if (publisher === "sql") { + $(sqlEnpointForm).removeClass('hide'); + $(enpointForm).addClass('hide'); + var endpoint = $(endpoint).val(); + //Endpoint example: jdbc:mysql://host:3306;database=name;user=user;password=pass + + if (endpoint !== "") { + try { + var url = endpoint.split("://"); + var driver = url[0].split("jdbc:")[1]; + var cut = url[1].split(":"); + var host = cut[0]; + var cut2 = cut[1].split(";"); + var port = cut2[0]; + var db = cut2[1].split("database=")[1]; + var user = cut2[2].split("user=")[1]; + var password = cut2[3].split("password=")[1]; + } catch (e) { + //ignore errors + } + + $(driverEndpoint).val(driver); + $(hostEndpoint).val(host); + $(dbEndpoint).val(db); + $(portEndpoint).val(port); + $(userEndpoint).val(user); + $(passwordEndpoint).val(password); + } + + } else { + $(sqlEnpointForm).addClass('hide'); + $(enpointForm).removeClass('hide'); + } + + if (publisher === "csv") { + $(queryForm).addClass('hide'); + $(csvQueryForm).removeClass('hide'); + + query = $(query).val(); + + if (query !== "") { + var q = query.split("|"); + + $(csvQueryDelimiter).val(q[1]); + $(csvQueryHeaderSkip).val(q[0]); + } else { + $(csvQueryHeaderSkip).val("1"); + refreshQuery(); + } + + } + else { + $(csvQueryForm).addClass('hide'); + $(queryForm).removeClass('hide'); + } +} + +/** + * Called when user change endpoint in the modal Resource + * @param {type} mode + * @returns {undefined} + */ +function refreshEnpoint(mode) { + + if (mode === 'edit') { + var portEndpoint = '#editPortEndpoint'; + var userEndpoint = '#editUserEndpoint'; + var passwordEndpoint = '#editPasswordEndpoint'; + var driverEndpoint = '#editDriverEndpoint'; + var hostEndpoint = '#editHostEndpoint'; + var dbEndpoint = '#editDbEndpoint'; + var endpoint = '#editEndpoint'; + } else { + var portEndpoint = '#portEndpoint'; + var userEndpoint = '#userEndpoint'; + var passwordEndpoint = '#passwordEndpoint'; + var driverEndpoint = '#driverEndpoint'; + var hostEndpoint = '#hostEndpoint'; + var dbEndpoint = '#dbEndpoint'; + var endpoint = '#endpoint'; + } + + var port = $(portEndpoint).val(); + if (port !== "") + port = ":" + port; + var user = $(userEndpoint).val(); + if (user !== "") + user = ";user=" + user; + var password = $(passwordEndpoint).val(); + if (password !== "") + password = ";password=" + password; + var endpointFinal = "jdbc:" + $(driverEndpoint).val() + "://" + $(hostEndpoint).val() + port + ";database=" + $(dbEndpoint).val() + user + password; + $(endpoint).val(endpointFinal); +} + +/** + * Called when user change query in the modal Resource + * @param {type} mode + * @returns {undefined} + */ +function refreshQuery(mode) { + if (mode === 'edit') { + var delimiter = $('#editCsvQueryDelimiter').val(); + var header = $('#editCsvQueryHeaderSkip').val(); + $('#editQuery').val(header + "|" + delimiter); + } else { + var delimiter = $('#csvQueryDelimiter').val(); + var header = $('#csvQueryHeaderSkip').val(); + $('#query').val(header + "|" + delimiter); + + } +} +/** + * Called before the edit of a Resource + * @param {type} individual + * @returns {undefined} + */ +function prepareResourceEdit(individual) { + //reset values + $('#editResourceResult').html(""); + document.getElementById('editResourceURI').innerHTML = individual; + //CLEAN THE INPUT FIELDS + $('#editResourceTitle').val(""); + $('#editResourceLabel').val(""); + $('#editResourceComment').val(""); + $('#editMethod').val(""); + $('#editPublisher').val(""); + $('#editEndpoint').val(""); + $('#editQuery').val(""); + $('#editOrder').val(""); + $('#editExtends').val(""); + $('#built').prop('checked', false); + + //CLEAN ALSO OLD VALUES IN THE STATIC FIELD + $('#oldTitle').val(""); + $('#oldLabel').val(""); + $('#oldComment').val(""); + $('#oldMethod').val(""); + $('#oldPublisher').val(""); + $('#oldEndpoint').val(""); + $('#oldQuery').val(""); + $('#oldOrder').val(""); + $('#oldExtends').val(""); + $('#oldBuilt').val("false"); + + var q = "SELECT ?concept ?c {?concep coeus:hasResource " + individual + " . ?entity coeus:isEntityOf ?concep . ?seed coeus:includes ?entity . ?concept coeus:hasEntity ?ent . ?ent coeus:isIncludedIn ?seed . ?concept dc:title ?c}"; + queryToResult(q, fillConceptsExtension); + var q = "SELECT ?title ?label ?comment ?method ?publisher ?endpoint ?query ?order ?extends ?built {" + individual + " dc:title ?title . " + individual + " rdfs:label ?label . " + individual + " rdfs:comment ?comment . " + individual + " coeus:method ?method . " + individual + " dc:publisher ?publisher . " + individual + " coeus:endpoint ?endpoint . " + individual + " coeus:query ?query . " + individual + " coeus:order ?order . " + individual + " coeus:extends ?extends . OPTIONAL{" + individual + " coeus:built ?built } }"; + queryToResult(q, fillResourceEdit); + +} +function fillResourceEdit(result) { + console.log(result); + try + { + //PUT VALUES IN THE INPUT FIELD + $('#editResourceTitle').val(result[0].title.value); + $('#editResourceLabel').val(result[0].label.value); + $('#editResourceComment').val(result[0].comment.value); + $('#editMethod').val(result[0].method.value); + $('#editPublisher option:contains(' + result[0].publisher.value + ')').prop({selected: true}); + $('#editEndpoint').val(result[0].endpoint.value); + $('#editQuery').val(result[0].query.value); + $('#editOrder').val(result[0].order.value); + $('#editExtends option:contains(' + splitURIPrefix(result[0].extends.value).value + ')').prop({selected: true}); + if (result[0].built !== undefined && result[0].built.value === "true") + $('#built').prop('checked', true); + else + $('#built').prop('checked', false); + } + catch (err) + { + $('#editResourceResult').append(generateHtmlMessage("Error!", "Some fields do not exist." + err, "alert-error")); + } + //PUT OLD VALUES IN THE STATIC FIELD + $('#oldResourceTitle').val($('#editResourceTitle').val()); + $('#oldResourceLabel').val($('#editResourceLabel').val()); + $('#oldResourceComment').val($('#editResourceComment').val()); + $('#oldMethod').val($('#editMethod').val()); + $('#oldPublisher').val($('#editPublisher').val()); + $('#oldEndpoint').val($('#editEndpoint').val()); + $('#oldQuery').val($('#editQuery').val()); + $('#oldOrder').val($('#editOrder').val()); + $('#oldExtends').val(splitURIPrefix(result[0].extends.value).value); + $('#oldBuilt').val($('#built').is(':checked')); + //change publisher according to the result + publisherChange('edit'); + +} + +/** + * Called when a Resource is edited / updated + * @returns {undefined} + */ +function editResource() { + var individual = $('#editResourceURI').html(); + var urlUpdate = "../../api/" + getApiKey() + "/update/"; + var urlDelete = "../../api/" + getApiKey() + "/delete/"; + var urlWrite = "../../api/" + getApiKey() + "/write/"; + var url; + var array = new Array(); + + if ($('#oldResourceLabel').val() !== $('#editResourceLabel').val()) { + url = urlUpdate + individual + "/" + "rdfs:label" + "/xsd:string:" + $('#oldResourceLabel').val() + ",xsd:string:" + $('#editResourceLabel').val(); + array.push(url); + } + if ($('#oldResourceTitle').val() !== $('#editResourceTitle').val()) { + url = urlUpdate + individual + "/" + "dc:title" + "/xsd:string:" + $('#oldResourceTitle').val() + ",xsd:string:" + $('#editResourceTitle').val(); + array.push(url); + } + if ($('#oldResourceComment').val() !== $('#editResourceComment').val()) { + url = urlUpdate + individual + "/" + "rdfs:comment" + "/xsd:string:" + $('#oldResourceComment').val() + ",xsd:string:" + $('#editResourceComment').val(); + array.push(url); + } + if ($('#oldMethod').val() !== $('#editMethod').val()) { + url = urlUpdate + individual + "/" + "coeus:method" + "/xsd:string:" + $('#oldMethod').val() + ",xsd:string:" + $('#editMethod').val(); + array.push(url); + } + if ($('#oldEndpoint').val() !== $('#editEndpoint').val()) { + url = urlUpdate + individual + "/" + "coeus:endpoint" + "/xsd:string:" + encodeBars($('#oldEndpoint').val()) + ",xsd:string:" + encodeBars($('#editEndpoint').val()); + array.push(url); + } + if ($('#oldQuery').val() !== $('#editQuery').val()) { + url = urlUpdate + individual + "/" + "coeus:query" + "/xsd:string:" + encodeBars($('#oldQuery').val()) + ",xsd:string:" + encodeBars($('#editQuery').val()); + array.push(url); + } + if ($('#oldOrder').val() !== $('#editOrder').val()) { + url = urlUpdate + individual + "/" + "coeus:order" + "/xsd:string:" + $('#oldOrder').val() + ",xsd:string:" + $('#editOrder').val(); + array.push(url); + } + if ($('#oldExtends').val() !== $('#editExtends').val()) { + url = urlUpdate + individual + "/" + "coeus:extends" + "/coeus:" + $('#oldExtends').val() + ",coeus:" + $('#editExtends').val(); + array.push(url); + url = urlDelete + "coeus:" + $('#oldExtends').val() + "/" + "coeus:isExtendedBy" + "/" + individual; + array.push(url); + url = urlWrite + "coeus:" + $('#editExtends').val() + "/" + "coeus:isExtendedBy" + "/" + individual; + array.push(url); + } + if ($('#oldPublisher').val() !== $('#editPublisher').val()) { + url = urlUpdate + individual + "/" + "dc:publisher" + "/xsd:string:" + $('#oldPublisher').val() + ",xsd:string:" + $('#editPublisher').val(); + updatePublisherOnSelectores(urlUpdate, individual, $('#oldPublisher').val(), $('#editPublisher').val()); + array.push(url); + } + if ($('#oldBuilt').val().toString() !== $('#built').is(':checked').toString()) { + url = urlUpdate + individual + "/" + "coeus:built" + "/xsd:boolean:" + $('#oldBuilt').val() + ",xsd:boolean:" + $('#built').is(':checked'); + array.push(url); + } + + timer = setTimeout(function() { + $('#closeEditResourceModal').click(); + refresh(); + }, delay); + + array.forEach(function(url) { + callURL(url, showResult.bind(this, "#editResourceResult", url), showError.bind(this, "#editResourceResult", url)); + }); +} +/** + * Update all selectors type (csv,xml,sql,..) of the resource when the resource publisher change. + * @param {type} urlUpdate + * @param {type} res + * @param {type} oldPublisher + * @param {type} newPublisher + * @returns {undefined} + */ +function updatePublisherOnSelectores(urlUpdate, res, oldPublisher, newPublisher) { + var q = "SELECT * {" + res + " coeus:loadsFrom ?selector}"; + queryToResult(q, function(result) { + for (var r in result) { + var res = splitURIPrefix(result[r].selector.value); + var url = urlUpdate + "coeus:" + res.value + "/rdf:type/coeus:" + oldPublisher.toUpperCase() + ",coeus:" + newPublisher.toUpperCase(); + callURL(url, showResult.bind(this, "#editResourceResult", url), showError.bind(this, "#editResourceResult", url)); + } + }); +} + +/** + * End of the code used to manage the modals (Resource) + */ \ No newline at end of file diff --git a/src/main/webapp/setup/addresource.jsp b/src/main/webapp/setup/addresource.jsp index 96dea78..a5da2a4 100644 --- a/src/main/webapp/setup/addresource.jsp +++ b/src/main/webapp/setup/addresource.jsp @@ -715,121 +715,7 @@
            - -
            -

            New Resource

            -
            - -
            - -
            -
            - - -
            -
            - - -
            - -
            - - -
            -
            - - -
            -
            - - -
            -
            -
            - -
            -
            - -
            -


            -
            - -
            - - -
            -
            - - -
            -
            - - - jdbc: - - :// - - : - - / - - -
            - Login: - - - -
            -
            - - -
            -
            - - - - -
            -
            - - -
            - -
            - - - - - - -
            - + @@ -917,29 +803,7 @@ - - + @@ -294,92 +146,12 @@ - - - - - - - - - - - + + + + <%@include file="/setup/modals/add.jsp" %> + <%@include file="/setup/modals/addResource.jsp" %> + <%@include file="/setup/modals/edit.jsp" %> + <%@include file="/setup/modals/remove.jsp" %> + + diff --git a/src/main/webapp/setup/config.jsp b/src/main/webapp/setup/config.jsp index 57d7396..ed5e2a0 100644 --- a/src/main/webapp/setup/config.jsp +++ b/src/main/webapp/setup/config.jsp @@ -10,7 +10,7 @@ - + - + - + @@ -268,7 +100,7 @@ @@ -286,92 +118,10 @@ - - - - - - - - - + + + <%@include file="/setup/modals/add.jsp" %> + <%@include file="/setup/modals/edit.jsp" %> + <%@include file="/setup/modals/remove.jsp" %> diff --git a/src/main/webapp/setup/environments.jsp b/src/main/webapp/setup/environments.jsp index d6d47e4..14637d1 100644 --- a/src/main/webapp/setup/environments.jsp +++ b/src/main/webapp/setup/environments.jsp @@ -10,7 +10,7 @@ - + - + - - -
            -

            - - -

            Knowledge Base

            -
            -
            -

            Triples

            -
            -
            - 0 -
            -
            -

            Environment

            -
            - - -
            - -

            Actions

            -
            -
            - -
            -
            - -
            -
            -
            - - Export - - - -
            -
            -
            - - - -
            -
            - diff --git a/src/main/webapp/setup/modals/add.jsp b/src/main/webapp/setup/modals/add.jsp new file mode 100644 index 0000000..6956574 --- /dev/null +++ b/src/main/webapp/setup/modals/add.jsp @@ -0,0 +1,34 @@ + + \ No newline at end of file diff --git a/src/main/webapp/setup/modals/addResource.jsp b/src/main/webapp/setup/modals/addResource.jsp new file mode 100644 index 0000000..9bbbd29 --- /dev/null +++ b/src/main/webapp/setup/modals/addResource.jsp @@ -0,0 +1,113 @@ +<%-- + Document : addResource + Created on : Oct 14, 2013, 3:41:38 PM + Author : sernadela +--%> + + + \ No newline at end of file diff --git a/src/main/webapp/setup/modals/edit.jsp b/src/main/webapp/setup/modals/edit.jsp new file mode 100644 index 0000000..72d534d --- /dev/null +++ b/src/main/webapp/setup/modals/edit.jsp @@ -0,0 +1,35 @@ + + \ No newline at end of file diff --git a/src/main/webapp/setup/modals/editResource.jsp b/src/main/webapp/setup/modals/editResource.jsp new file mode 100644 index 0000000..ea90697 --- /dev/null +++ b/src/main/webapp/setup/modals/editResource.jsp @@ -0,0 +1,131 @@ +<%-- + Document : addResource + Created on : Oct 14, 2013, 3:41:38 PM + Author : sernadela +--%> + + \ No newline at end of file diff --git a/src/main/webapp/setup/modals/remove.jsp b/src/main/webapp/setup/modals/remove.jsp new file mode 100644 index 0000000..34da719 --- /dev/null +++ b/src/main/webapp/setup/modals/remove.jsp @@ -0,0 +1,21 @@ + + \ No newline at end of file diff --git a/src/main/webapp/setup/resources.jsp b/src/main/webapp/setup/resources.jsp index aa5af25..f6ba02b 100644 --- a/src/main/webapp/setup/resources.jsp +++ b/src/main/webapp/setup/resources.jsp @@ -10,23 +10,35 @@ - + + @@ -91,7 +101,7 @@