diff --git a/bibimainapp/pom.xml b/bibimainapp/pom.xml index 67fdba7..4d88467 100644 --- a/bibimainapp/pom.xml +++ b/bibimainapp/pom.xml @@ -117,6 +117,12 @@ uasparser 0.6.2 + + + commons-fileupload + commons-fileupload + 1.2.2 + diff --git a/libs/bibitools/src/main/java/de/unibi/techfak/bibiserv/BiBiTools.java b/libs/bibitools/src/main/java/de/unibi/techfak/bibiserv/BiBiTools.java index edec154..f5f05a2 100644 --- a/libs/bibitools/src/main/java/de/unibi/techfak/bibiserv/BiBiTools.java +++ b/libs/bibitools/src/main/java/de/unibi/techfak/bibiserv/BiBiTools.java @@ -22,15 +22,9 @@ */ package de.unibi.techfak.bibiserv; -import de.unibi.techfak.bibiserv.cms.TenumParam; -import de.unibi.techfak.bibiserv.cms.TenumValue; -import de.unibi.techfak.bibiserv.cms.Tfunction; -import de.unibi.techfak.bibiserv.cms.TinputOutput; -import de.unibi.techfak.bibiserv.cms.Tparam; +import de.unibi.techfak.bibiserv.cms.*; import de.unibi.techfak.bibiserv.cms.Tparam.Max; import de.unibi.techfak.bibiserv.cms.Tparam.Min; -import de.unibi.techfak.bibiserv.cms.TparamGroup; -import de.unibi.techfak.bibiserv.cms.TrunnableItem; import de.unibi.techfak.bibiserv.debug.DDataSource; import de.unibi.techfak.bibiserv.exception.BiBiToolsException; import de.unibi.techfak.bibiserv.exception.DBConnectionException; @@ -932,8 +926,8 @@ public File getTmpDir() throws FileNotFoundException { * * @return */ - public Element getToolDescription() { - return (Element) runnableitem; + public TrunnableItem getToolDescription() { + return runnableitem; } /** @@ -2285,7 +2279,7 @@ public String generateCmdLineString(String id, Map hash, String StringBuffer cmdline = new StringBuffer(getExecCmd()); // test if cmdline describe a valid executable (only if 'UseDocker' is unset) - if (getProperty("UseDocker") == null || !getProperty("UseDocker").equalsIgnoreCase("true")) { + if (!getToolDescription().getExecutable().getExecInfo().getExecutableType().equalsIgnoreCase("docker")) { File test = new File(cmdline.toString()); if (testexec && !(test.exists() && test.isFile() && test.canExecute())) { @@ -2949,35 +2943,31 @@ private TinputOutput search_for_input(String id) { */ private String getExecCmd() { StringBuffer cmdbuf = new StringBuffer(); - if (getProperty("UseDocker") == null || !getProperty("UseDocker").equalsIgnoreCase("true")) { - if (getProperty("executable.rootpath") != null) { - cmdbuf.append(getProperty("executable.rootpath")); - if (!endWithFileSeparator(cmdbuf)) { - cmdbuf.append(this.separator); - } - if (getProperty("executable.path.isrelativ").equalsIgnoreCase("true")) { - cmdbuf.append(runnableitem.getExecutable().getExecInfo().getPath()); - if (!endWithFileSeparator(cmdbuf)) { - cmdbuf.append(this.separator); - } - } - } else { + + Texecutable executable = getToolDescription().getExecutable(); + boolean isDocker = getToolDescription().getExecutable().getExecInfo().getExecutableType().equalsIgnoreCase("docker"); + if (getProperty("executable.rootpath") != null && !isDocker) { + cmdbuf.append(getProperty("executable.rootpath")); + if (!endWithFileSeparator(cmdbuf)) { + cmdbuf.append(this.separator); + } + if (getProperty("executable.path.isrelativ").equalsIgnoreCase("true")) { cmdbuf.append(runnableitem.getExecutable().getExecInfo().getPath()); if (!endWithFileSeparator(cmdbuf)) { cmdbuf.append(this.separator); } } } else { - String orga = getProperty("DockerHubOrganization"); - if (orga != null) { - cmdbuf.append("docker run "); - cmdbuf.append(" --rm=true"); - cmdbuf.append(" -v ").append(getProperty("spooldir.base")).append(":").append(getProperty("spooldir.base")); - cmdbuf.append(" ").append(orga).append("/").append(runnableitem.getId()); - cmdbuf.append(" /usr/local/bin/"); - } else { - cmdbuf.append("# BiBiTool.properties doesn't contain a property named 'DockerHubOrganization'!"); + cmdbuf.append("docker "); + cmdbuf.append("run "); + cmdbuf.append("--entrypoint='" + runnableitem.getExecutable().getExecInfo().getPath() + "' "); + try { + cmdbuf.append("-v "); + cmdbuf.append(getSpoolDir().toString() + ":" + getSpoolDir().toString() + ":rw "); + } catch (FileNotFoundException e) { + e.printStackTrace(); } + cmdbuf.append(executable.getExecInfo().getImage() + " "); } cmdbuf.append(runnableitem.getExecutable().getExecInfo().getCallingInformation()); return cmdbuf.toString(); diff --git a/libs/bibitools/src/main/java/de/unibi/techfak/bibiserv/impl/JobProxyCall.java b/libs/bibitools/src/main/java/de/unibi/techfak/bibiserv/impl/JobProxyCall.java index d1ce444..a826e86 100644 --- a/libs/bibitools/src/main/java/de/unibi/techfak/bibiserv/impl/JobProxyCall.java +++ b/libs/bibitools/src/main/java/de/unibi/techfak/bibiserv/impl/JobProxyCall.java @@ -29,7 +29,6 @@ import de.unibi.techfak.bibiserv.exception.IdNotFoundException; import java.io.File; import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStream; @@ -39,7 +38,6 @@ import java.net.URI; import java.net.URISyntaxException; import java.net.URL; -import java.util.logging.Level; import org.apache.log4j.Logger; import org.json.*; @@ -77,7 +75,16 @@ public JobProxyCall() { */ public JobProxyCall(BiBiTools wsstools) { this(wsstools, wsstools.getStatus()); - // get servr JobProxyServer from + setUri(wsstools); + } + + @Override + public void setBiBiTools(BiBiTools bibitools) { + super.setBiBiTools(bibitools); + setUri(bibitools); + } + + private void setUri(BiBiTools biBiTools){ try { uri = new URI(wsstools.getProperty("JobProxyServer.URI", "http://localhost:9999/")); } catch (URISyntaxException e) { @@ -88,7 +95,6 @@ public JobProxyCall(BiBiTools wsstools) { // should not occure } } - } public JobProxyCall(BiBiTools submitted_wsstools, Status submitted_status) { diff --git a/libs/bibitools/src/main/java/de/unibi/techfak/bibiserv/impl/LocalCall.java b/libs/bibitools/src/main/java/de/unibi/techfak/bibiserv/impl/LocalCall.java index 4ff17a6..af8f0f7 100644 --- a/libs/bibitools/src/main/java/de/unibi/techfak/bibiserv/impl/LocalCall.java +++ b/libs/bibitools/src/main/java/de/unibi/techfak/bibiserv/impl/LocalCall.java @@ -29,7 +29,6 @@ import de.unibi.techfak.bibiserv.exception.DBConnectionException; import java.io.File; -import java.io.FileInputStream; /** * Implements the Call interface executing a program directly on the local diff --git a/libs/dependencyparser/README.md b/libs/dependencyparser/README.md new file mode 100644 index 0000000..6d95596 --- /dev/null +++ b/libs/dependencyparser/README.md @@ -0,0 +1,29 @@ +#Dependency Parser + +A parser written in JavaCC 4.0+ for describing dependencies if bibiserv application function. + + +In some cases not all parameters of a function are needed at the same time or, in other cases, some parameters are exclusive to each other. Via dependencies, restrictions to the defined parameters of a function can be made using standard logical operators. + +A dependency can only contain parameters that are actually defined in the function. References to parameters are set using the id of the parameter. + +The definition below describes all possible interactions using standard BNF notation: + +``` + ::= | | | | | | def() | | | | | + ::= and(,) // conjunction + ::= or(,) // disjunction + ::= xor(,) // exclusive disjunction + ::= not() // denial + ::= impl(,) // implication + ::= logeq(,) // equivalence + ::= eq(, | ) + ::= gt(, |) +::= ge(, |) + ::= lt(, |) + ::= le(, |) + ::= @[A-Z,a-z,0-9]+ + ::= [0-9]+[.]?[0-9]*|[A-Z,a-z,0-9,...] +``` + +See also the [BiBiServ Wiki](https://wiki.cebitec.uni-bielefeld.de/bibiserv-1.25.2/index.php/Dependency_Language_Dev) which may contain some additional informations. diff --git a/libs/dependencyparser/README.txt b/libs/dependencyparser/README.txt new file mode 100644 index 0000000..41cecbf --- /dev/null +++ b/libs/dependencyparser/README.txt @@ -0,0 +1,30 @@ +Dependency Parser + +Der Dependency Parser ist ein in JavaCC 4.0 geschriebener Parser um Abhaengigkeiten zwischen +Parameter bzw. Parametergruppen beschreiben zu koennen. Eine Beschreibung zu dem Parser +bzw. der BNF findet sich im Wiki unter : + +http://wiki.techfak.uni-bielefeld.de/bibiserv/BiBiServ_V2_XMLSServerDescription + +Vorraussetzungen : + +Java 1.5 oder neuer +JavaCC 4 oder neuer +Netbeans 6.x oder neuer fuer das TreeBeispiel +Xerces im Pfad fuer das Commandline Beispiel + +Dateien im Repository: + +DependencyParser.jj - DependencyParser in JacaCC 4.0 Syntax +build.xml - zentrales Build um aus dem .jj File den Parser zu bauen + - unterstuetzte Targets: + package (default) compiliert und erzeugt ein Jar File im dist ordner + compile compiliert den Parser (javacc und javac) + clean loescht die generierten Sourcen und Klassen + clean_dist loescht alles (clean + pakcage distribution) + run (ruft compile auf) startet einen builtin CMDLine Client auf den Beispiel + Daten (unter sample) +sample - enthaelt zwei Beispieldateien fuer den CMDline Client und ein NetbeansProjekt + (Netbeans >= 6.x) + +(jkrueger@techfak.uni-bielefeld.de) diff --git a/libs/dependencyparser/build.xml b/libs/dependencyparser/build.xml new file mode 100644 index 0000000..67f1054 --- /dev/null +++ b/libs/dependencyparser/build.xml @@ -0,0 +1,176 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Loading Ivy Settings from BiBiServ ... + + + + BiBiserv not available, load Ivy settings from ${user.home}/ivy-rep/ivy-settings.xml or if this file does not exist load default settings file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/dependencyparser/pom.xml b/libs/dependencyparser/pom.xml new file mode 100644 index 0000000..b5275cc --- /dev/null +++ b/libs/dependencyparser/pom.xml @@ -0,0 +1,123 @@ + + + 4.0.0 + de.unibi.cebitec.bibiserv + dependencyparser + 1.1 + jar + DependencyParser + + + de.unibi.techfak.bibiserv.util.dependencyparser.javacc + de/unibi/techfak/bibiserv/util/dependencyparser/javacc + \n + + + + + + com.helger.maven + ph-javacc-maven-plugin + 2.8.1 + + + step1 + generate-sources + + javacc + + + 1.5 + UTF-8 + true + ${javacc.package} + src/main/javacc + ${project.build.directory}/generated-sources/javacc/${javacc.package.dir} + + + + + + maven-antrun-plugin + 1.8 + + + step2 + generate-sources + + run + + + + + postprocess files generated by JavaCC (correct package declaration) + + + + + + + + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.12 + + + add-source + generate-sources + + add-source + + + + ${project.build.directory}/generated-sources/javacc + src/main/java + + + + + + + + + + + + + snapshot-repository.java.net + Java.net Snapshot Repository for Maven + https://maven.java.net/content/repositories/snapshots/ + default + + + jitpack.io + https://jitpack.io + + + + + + + + ${project.groupId} + bibitools + 2.0 + + + + + junit + junit + 4.12 + test + + + diff --git a/libs/dependencyparser/src/main/java/de/unibi/techfak/bibiserv/util/dependencyparser/CmpOpNode.java b/libs/dependencyparser/src/main/java/de/unibi/techfak/bibiserv/util/dependencyparser/CmpOpNode.java new file mode 100644 index 0000000..9d6e1d0 --- /dev/null +++ b/libs/dependencyparser/src/main/java/de/unibi/techfak/bibiserv/util/dependencyparser/CmpOpNode.java @@ -0,0 +1,172 @@ +/* +DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + +Copyright 2010 BiBiServ Curator Team, http://bibiserv.cebitec.uni-bielefeld.de, +All rights reserved. + +The contents of this file are subject to the terms of the Common +Development and Distribution License("CDDL") (the "License"). You +may not use this file except in compliance with the License. You can +obtain a copy of the License at http://www.sun.com/cddl/cddl.html + +See the License for the specific language governing permissions and +limitations under the License. When distributing the software, include +this License Header Notice in each file. If applicable, add the following +below the License Header, with the fields enclosed by brackets [] replaced +by your own identifying information: + +"Portions Copyrighted 2011 BiBiServ" + +Contributor(s): + */ +package de.unibi.techfak.bibiserv.util.dependencyparser; + +import java.util.List; + +/** + * + * @author Jan Krueger - jkrueger(at)cebitec.uni-bielefeld.de + */ +public class CmpOpNode extends OpNode { + + public CmpOpNode(Operations operation) { + super(operation); + } + + public CmpOpNode(Operations operation, LeafNode a) { + super(operation, a); + } + + public CmpOpNode(Operations operation, LeafNode a, LeafNode b) { + super(operation, a, b); + } + + @Override + public boolean evaluate() throws DependencyException { + missingconstraints.clear(); + fullfilledconstraints.clear(); + + boolean t_a = a.evaluate(); + boolean t_b = b.evaluate(); + + boolean result = true; + + if (t_a & t_b) { + + List v_a_l = ((LeafNode) a).getValues(); + List v_b_l = ((LeafNode) b).getValues(); + + for (Object v_a : v_a_l) { + for (Object v_b : v_b_l) { + boolean intermediate_result; + switch (operation) { + case EQ: + intermediate_result = compare(v_a, v_b, 0); + break; + case NE: + intermediate_result = !compare(v_a, v_b, 0); + break; + case LT: + intermediate_result = compare(v_a, v_b, -1); + break; + case LE: + intermediate_result = (compare(v_a, v_b, 0) | compare(v_a, v_b, -1)); + break; + case GT: + intermediate_result = compare(v_a, v_b, 1); + break; + case GE: + intermediate_result = (compare(v_a, v_b, 0) | compare(v_a, v_b, 1)); + break; + default: + throw new DependencyException("Unsupported Operation '" + operation.name() + "'", DependencyExceptionEnum.unsupportedOperation, operation.name()); + } + if (!intermediate_result && a.getClass().equals(Const.class) && b.getClass().equals(Const.class)) { + throw new DependencyException("Dependency can't be solved (" + v_a + " " + operation.name() + " " + v_b + ")!", DependencyExceptionEnum.unsolveableDependency, v_a + " " + operation.name() + " " + v_b); + } + result = result & intermediate_result; + } + } + } else { + result = false; + } + + // Nach Definition sind moegliche Kindsknoten fuer a nur ID's und fuer b LeafKnoten (also ID's oder Konstanten) + + fullfilledconstraints.putAll(a.getFullfilledConstraints()); + fullfilledconstraints.putAll(b.getFullfilledConstraints()); + missingconstraints.putAll(a.getMissingConstraints()); + missingconstraints.putAll(b.getMissingConstraints()); + + if (result) { + fullfilledconstraints.put((Id) a, new Constraints(operation, (LeafNode) b)); + } else { + missingconstraints.put((Id) a, new Constraints(operation, (LeafNode) b)); + } + + return result; + } + + /** + Helper method, to represent a clear Source structure ;-) + @param a - Object representing an id + @param b - Object representing an id + + @param comp - one of 0(equals), <0(lesserthan) , >0 (greater than) + + @return Returns true if a matches b or c */ + private boolean compare(Object a, Object b, int comp) throws DependencyException { + + if (a == null || b == null) { + return false; + } + + String n_a = a.getClass().getName(); + String n_b = b.getClass().getName(); + + + if (n_a.equals(n_b)) { + return (Integer.signum(((Comparable) a).compareTo((Comparable) b)) == comp); + } else { + // compare int with float + if (a instanceof Integer) { + if (b instanceof Float) { + return (Integer.signum((new Float(((Integer) a).floatValue())).compareTo((Float) b)) == comp); + } else if (b instanceof String) { + return (Integer.signum((a.toString()).compareTo((String) b)) == comp); + } else if (b instanceof Boolean) { + return ((Integer) a == 0 ? false : true) & (Boolean) b; + } else { + throw new DependencyException("Unsupported type \"" + n_b + "\" can't compared to \"" + n_a + "\"!", DependencyExceptionEnum.unsupportedCompare, n_b+":"+n_a); + } + } else if (a instanceof Float) { + if (b instanceof Integer) { + return (Integer.signum(((Float) a).compareTo(new Float(((Integer) b).floatValue()))) == comp); + } else if (b instanceof String) { + return (Integer.signum((a.toString()).compareTo((String) b)) == comp); + } else if (b instanceof Boolean) { + return ((Float) a == 0f ? false : true) & (Boolean) b; + } else { + throw new DependencyException("Unsupported type \"" + n_b + "\" can't compared to \"" + n_a + "\"!", DependencyExceptionEnum.unsupportedCompare, n_b+":"+n_a); + } + + } else if (a instanceof String) { + return (Integer.signum(((String) a).compareTo(b.toString())) == comp); + } else if (a instanceof Boolean) { + if (b instanceof Integer) { + return !((Boolean) a ^ ((Integer) b == 0 ? false : true)); + } else if (b instanceof Float) { + return !((Boolean) a ^ ((Float) b == 0 ? false : true)); + } else if (b instanceof String) { + return !((Boolean) a ^ Boolean.parseBoolean((String) b)); + } else { + throw new DependencyException("Unsupported type \"" + n_b + "\" can't compared to \"" + n_a + "\"!", DependencyExceptionEnum.unsupportedCompare, n_b+":"+n_a); + } + + } else { + throw new DependencyException("Unsupported type \"" + n_a + "\" can't compared to \"" + n_b + "\"!", DependencyExceptionEnum.unsupportedCompare, n_b+":"+n_a); + } + } + + } +} diff --git a/libs/dependencyparser/src/main/java/de/unibi/techfak/bibiserv/util/dependencyparser/Const.java b/libs/dependencyparser/src/main/java/de/unibi/techfak/bibiserv/util/dependencyparser/Const.java new file mode 100644 index 0000000..bd6fc6e --- /dev/null +++ b/libs/dependencyparser/src/main/java/de/unibi/techfak/bibiserv/util/dependencyparser/Const.java @@ -0,0 +1,45 @@ +/* +DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + +Copyright 2010 BiBiServ Curator Team, http://bibiserv.cebitec.uni-bielefeld.de, +All rights reserved. + +The contents of this file are subject to the terms of the Common +Development and Distribution License("CDDL") (the "License"). You +may not use this file except in compliance with the License. You can +obtain a copy of the License at http://www.sun.com/cddl/cddl.html + +See the License for the specific language governing permissions and +limitations under the License. When distributing the software, include +this License Header Notice in each file. If applicable, add the following +below the License Header, with the fields enclosed by brackets [] replaced +by your own identifying information: + +"Portions Copyrighted 2011 BiBiServ" + +Contributor(s): + */ +package de.unibi.techfak.bibiserv.util.dependencyparser; + +/** + * Represents a Const, which itself is a LeafNode. The Constructor supports a single + * const value. + * + * @author Jan Krueger - jkrueger(at)cebitec.uni-bielefeld.de + */ +public class Const extends LeafNode { + + public Const(Object value) { + valuelist.add(value); + } + + @Override + public boolean evaluate() throws DependencyException { + return true; + } + + @Override + public String toString() { + return valuelist.get(0).toString(); + } +} diff --git a/libs/dependencyparser/src/main/java/de/unibi/techfak/bibiserv/util/dependencyparser/ConstraintHashMap.java b/libs/dependencyparser/src/main/java/de/unibi/techfak/bibiserv/util/dependencyparser/ConstraintHashMap.java new file mode 100644 index 0000000..44c795b --- /dev/null +++ b/libs/dependencyparser/src/main/java/de/unibi/techfak/bibiserv/util/dependencyparser/ConstraintHashMap.java @@ -0,0 +1,111 @@ +/* +DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + +Copyright 2010 BiBiServ Curator Team, http://bibiserv.cebitec.uni-bielefeld.de, +All rights reserved. + +The contents of this file are subject to the terms of the Common +Development and Distribution License("CDDL") (the "License"). You +may not use this file except in compliance with the License. You can +obtain a copy of the License at http://www.sun.com/cddl/cddl.html + +See the License for the specific language governing permissions and +limitations under the License. When distributing the software, include +this License Header Notice in each file. If applicable, add the following +below the License Header, with the fields enclosed by brackets [] replaced +by your own identifying information: + +"Portions Copyrighted 2011 BiBiServ" + +Contributor(s): + */ +package de.unibi.techfak.bibiserv.util.dependencyparser; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +/** + * + * @author Jan Krueger - jkrueger(at)cebitec.uni-bielefeld.de + */ +public class ConstraintHashMap extends HashMap> { + + public List put(Id key, Constraints value) { + // if value is null (which means, that Constraint is missing/fullfilled without special value + if (value == null) { + // and key already known , we shouldn't do nothing + if (containsKey(key)){ + return super.get(key); + } else { + return super.put(key,null); + } + } + // otherwise we should + List _value = get(key); + if (_value == null) { + _value = new ArrayList(); + _value.add(value); + super.put(key, _value); + } else { + _value.add(value); + } + return _value; + } + + @Override + public List put(Id key, List valuelist) { + if (valuelist == null || valuelist.isEmpty()){ + return put(key,(Constraints)null); + } + for (Constraints tmp : valuelist){ + put (key,tmp); + } + return get(key); + } + + public void putAll(ConstraintHashMap chm) { + for (Id id : chm.keySet()) { +// if (containsKey(id)) { +// List _value = get(id); +// if (_value == null) { +// _value = new ArrayList(); +// _value.addAll(chm.get(id)); +// put(id, _value); +// } else { +// _value.addAll(chm.get(id)); +// } +// put +// } else { +// put(id, get(id)); +// } + put(id,chm.get(id)); + } + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + + for (Id key : keySet()) { + sb.append(key).append("->("); + boolean first = true; + if (get(key) != null) { + for (Constraints c : get(key)) { + if (first) { + first = false; + } else { + sb.append(","); + } + if (c.getOperation() != null) { + sb.append(c.getOperation()); + sb.append(c.getValue()); + + } + } + } + sb.append(")"); + } + return sb.toString(); + } +} diff --git a/libs/dependencyparser/src/main/java/de/unibi/techfak/bibiserv/util/dependencyparser/Constraints.java b/libs/dependencyparser/src/main/java/de/unibi/techfak/bibiserv/util/dependencyparser/Constraints.java new file mode 100644 index 0000000..147df1d --- /dev/null +++ b/libs/dependencyparser/src/main/java/de/unibi/techfak/bibiserv/util/dependencyparser/Constraints.java @@ -0,0 +1,262 @@ +/* +DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + +Copyright 2010 BiBiServ Curator Team, http://bibiserv.cebitec.uni-bielefeld.de, +All rights reserved. + +The contents of this file are subject to the terms of the Common +Development and Distribution License("CDDL") (the "License"). You +may not use this file except in compliance with the License. You can +obtain a copy of the License at http://www.sun.com/cddl/cddl.html + +See the License for the specific language governing permissions and +limitations under the License. When distributing the software, include +this License Header Notice in each file. If applicable, add the following +below the License Header, with the fields enclosed by brackets [] replaced +by your own identifying information: + +"Portions Copyrighted 2011 BiBiServ" + +Contributor(s): + */ +package de.unibi.techfak.bibiserv.util.dependencyparser; + +import de.unibi.techfak.bibiserv.util.dependencyparser.OpNode.Operations; +import java.util.List; + +/** + * + * @author Jan krueger - jkrueger(at)cebitec.uni-bielefeld.de + */ +public class Constraints implements Comparable { + + private OpNode.Operations operation = OpNode.Operations.NULL; + private LeafNode value = null; + + public Constraints(OpNode.Operations operation, LeafNode value) { + this.operation = operation; + this.value = value; + + } + + public void setOperation(OpNode.Operations operation) { + this.operation = operation; + } + + public Operations getOperation() { + return operation; + } + + public void setValue(LeafNode value) { + this.value = value; + } + + public LeafNode getValue() { + return value; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(operation); + sb.append(" "); + sb.append(value.toString()); + + return sb.toString(); + + } + + public int compareTo(Constraints o) { + // 1st critera its the operation + int cmp = operation.compareTo(o.getOperation()); + if (cmp != 0) { + return cmp; + } + // 2nd criteria is the value + if (value.getClass().getName().equals(o.getValue().getClass().getName())) { + // compare types + if ((value instanceof Id) && o.getValue() instanceof Id) { + return ((Id) value).compareTo((Id) o.getValue()); + } + if ((value instanceof Id) && o.getValue() instanceof Const) { + return -1; + } + if ((value instanceof Const) && o.getValue() instanceof Id) { + return 1; + } + List la = ((Const) value).getValues(); + List lb = ((Const) (o.getValue())).getValues(); + // both constants (critera length) + if (la.size() < lb.size()) { + return -1; + } + + if (la.size() > lb.size()) { + return 1; + } + + // same length -> compare list elements + for (int c = 0; c < la.size(); ++c) { + // + Object a = la.get(c); + Object b = lb.get(c); + if (a instanceof Integer) { + if (b instanceof Integer) { + if ((Integer) a < (Integer) b) { + return -1; + } else if ((Integer) a > (Integer) b) { + return 1; + + } + } else if (b instanceof Float) { + if ((Integer) a < (Float) b) { + return -1; + } else if ((Integer) a > (Float) b) { + return 1; + } + } else if (b instanceof String) { + cmp = ((Integer) a).toString().compareTo((String) b); + if (cmp != 0) { + return cmp; + } + } else if (b instanceof Boolean) { + return -1; + } else { + throw new RuntimeException("Unsupported Type '" + b.getClass().getCanonicalName() + "'."); + } + } else if (a instanceof Float) { + if (b instanceof Integer) { + if ((Float) a < (Integer) b) { + return -1; + } else if ((Float) a > (Integer) b) { + return 1; + + } + } else if (b instanceof Float) { + if ((Float) a < (Float) b) { + return -1; + } else if ((Float) a > (Float) b) { + return 1; + } + } else if (b instanceof String) { + cmp = ((Float) a).toString().compareTo((String) b); + if (cmp != 0) { + return cmp; + } + } else if (b instanceof Boolean) { + return -1; + } else { + throw new RuntimeException("Unsupported Type '" + b.getClass().getCanonicalName() + "'."); + } + + } else if (a instanceof String) { + if (b instanceof Integer) { + cmp = ((String) a).compareTo(((Integer) b).toString()); + if (cmp != 0) { + return cmp; + } + } else if (b instanceof Float) { + cmp = ((String) a).compareTo(((Float) b).toString()); + if (cmp != 0) { + return cmp; + } + } else if (b instanceof String) { + cmp = ((String) a).compareTo((String) b); + if (cmp != 0) { + return cmp; + } + } else if (b instanceof Boolean) { + cmp = ((String) a).compareTo(((Boolean) b).toString()); + if (cmp != 0) { + return cmp; + } + } else { + throw new RuntimeException("Unsupported Type '" + b.getClass().getCanonicalName() + "'."); + } + + } else if (a instanceof Boolean) { + if (b instanceof Integer) { + return 1; + } else if (b instanceof Float) { + return 1; + } else if (b instanceof String) { + cmp = ((String) a).compareTo((String) b); + if (cmp != 0) { + return cmp; + } + } else if (b instanceof Boolean) { + cmp = ((String) a).compareTo(((Boolean) b).toString()); + if (cmp != 0) { + return cmp; + } + } else { + throw new RuntimeException("Unsupported Type '" + b.getClass().getCanonicalName() + "'."); + } + } else { + throw new RuntimeException("Unsupported Type '" + b.getClass().getCanonicalName() + "'."); + } + } + + + return 0; + + } + // maybe it's bett to throw an exception ... + System.err.println("Type isn't equal ..."); + return -1; + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof Constraints)) { + return false; + } + + // compare operation + if (!operation.equals(((Constraints) obj).getOperation())) { + return false; + } + + // test kind of value + + LeafNode otherValue = ((Constraints) obj).getValue(); + + + // value type must be the same + if (!value.getClass().equals(otherValue.getClass())) { + return false; + } + + if (value instanceof Id) { + return value.equals(otherValue); + } else { + + // compare values + List l1 = value.getValues(); + List l2 = otherValue.getValues(); + + if (l1.size() != l2.size()) { + return false; + } + + for (int c = 0; c < l1.size(); ++c) { + Object e1 = l1.get(c); + Object e2 = l2.get(c); + if (!e1.equals(e2)) { + return false; + } + } + return true; + } + + + } + + @Override + public int hashCode() { + int hash = 7; + hash = 97 * hash + (this.operation != null ? this.operation.hashCode() : 0); + hash = 97 * hash + (this.value != null ? this.value.hashCode() : 0); + return hash; + } +} diff --git a/libs/dependencyparser/src/main/java/de/unibi/techfak/bibiserv/util/dependencyparser/DependencyException.java b/libs/dependencyparser/src/main/java/de/unibi/techfak/bibiserv/util/dependencyparser/DependencyException.java new file mode 100644 index 0000000..04f7f64 --- /dev/null +++ b/libs/dependencyparser/src/main/java/de/unibi/techfak/bibiserv/util/dependencyparser/DependencyException.java @@ -0,0 +1,69 @@ +/* +DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + +Copyright 2010 BiBiServ Curator Team, http://bibiserv.cebitec.uni-bielefeld.de, +All rights reserved. + +The contents of this file are subject to the terms of the Common +Development and Distribution License("CDDL") (the "License"). You +may not use this file except in compliance with the License. You can +obtain a copy of the License at http://www.sun.com/cddl/cddl.html + +See the License for the specific language governing permissions and +limitations under the License. When distributing the software, include +this License Header Notice in each file. If applicable, add the following +below the License Header, with the fields enclosed by brackets [] replaced + by your own identifying information: + +"Portions Copyrighted 2011 BiBiServ" + +Contributor(s): +*/ +package de.unibi.techfak.bibiserv.util.dependencyparser; + +/** + * + * @author Jan Krueger - jkrueger(at)cebitec.uni-bielefeld.de + */ +public class DependencyException extends Exception{ + + /** + * What is the exception that occured. + */ + private DependencyExceptionEnum exceptionType; + /** + * Extra information of the exception, p.e. the function id. + */ + private String value; + + public DependencyException(){ + super(); + } + + public DependencyException(String message, DependencyExceptionEnum type, String value){ + super(message); + this.exceptionType = type; + this.value = value; + } + + public DependencyException( Throwable t, DependencyExceptionEnum type, String value){ + super(t); + this.exceptionType = type; + this.value = value; + } + + public DependencyException(String message, Throwable t, DependencyExceptionEnum type, String value){ + super(message,t); + this.exceptionType = type; + this.value = value; + } + + public DependencyExceptionEnum getExceptionType() { + return exceptionType; + } + + public String getValue() { + return value; + } + +} diff --git a/libs/dependencyparser/src/main/java/de/unibi/techfak/bibiserv/util/dependencyparser/DependencyExceptionEnum.java b/libs/dependencyparser/src/main/java/de/unibi/techfak/bibiserv/util/dependencyparser/DependencyExceptionEnum.java new file mode 100644 index 0000000..3f2912a --- /dev/null +++ b/libs/dependencyparser/src/main/java/de/unibi/techfak/bibiserv/util/dependencyparser/DependencyExceptionEnum.java @@ -0,0 +1,76 @@ +/* +DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + +Copyright 2010 BiBiServ Curator Team, http://bibiserv.cebitec.uni-bielefeld.de, +All rights reserved. + +The contents of this file are subject to the terms of the Common +Development and Distribution License("CDDL") (the "License"). You +may not use this file except in compliance with the License. You can +obtain a copy of the License at http://www.sun.com/cddl/cddl.html + +See the License for the specific language governing permissions and +limitations under the License. When distributing the software, include +this License Header Notice in each file. If applicable, add the following +below the License Header, with the fields enclosed by brackets [] replaced +by your own identifying information: + +"Portions Copyrighted 2011 BiBiServ" + +Contributor(s): + */ + +package de.unibi.techfak.bibiserv.util.dependencyparser; + +/** + * Type of exceptions for DependencyException for better machine interpreting. + * @author Thomas Gatter + */ +public enum DependencyExceptionEnum { + + /** + * The function to test was not specified. + */ + noFunctionId, + /** + * The tooldescription was not set. + */ + noRunnableItem, + /** + * The dependency could not be extracted. + */ + dependencyExtractionError, + /** + * Parameter wrapper was not set. + */ + noParameterWrapper, + /** + * Error in setTooldescription in dependencyparser.java + */ + setTooldescriptionException, + /** + * An operation is not supported. + */ + unsupportedOperation, + /** + * The type is not implemented or supported. + */ + unsupportedType, + /** + * An operation combination can't be solved. + */ + unsolveableDependency, + /** + * Comparing of types that can't be compared. + */ + unsupportedCompare, + /* + * A string input could not be casted to the correct type. + */ + stringToTypeCastFailed, + /** + * Error in function setparameter in dependencyparser.java + */ + setParameter; + +} diff --git a/libs/dependencyparser/src/main/java/de/unibi/techfak/bibiserv/util/dependencyparser/DependencyParser.java b/libs/dependencyparser/src/main/java/de/unibi/techfak/bibiserv/util/dependencyparser/DependencyParser.java new file mode 100644 index 0000000..01a625d --- /dev/null +++ b/libs/dependencyparser/src/main/java/de/unibi/techfak/bibiserv/util/dependencyparser/DependencyParser.java @@ -0,0 +1,33 @@ +/* +DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + +Copyright 2010 BiBiServ Curator Team, http://bibiserv.cebitec.uni-bielefeld.de, +All rights reserved. + +The contents of this file are subject to the terms of the Common +Development and Distribution License("CDDL") (the "License"). You +may not use this file except in compliance with the License. You can +obtain a copy of the License at http://www.sun.com/cddl/cddl.html + +See the License for the specific language governing permissions and +limitations under the License. When distributing the software, include +this License Header Notice in each file. If applicable, add the following +below the License Header, with the fields enclosed by brackets [] replaced +by your own identifying information: + +"Portions Copyrighted 2011 BiBiServ" + +Contributor(s): Jan Krueger + */ +package de.unibi.techfak.bibiserv.util.dependencyparser; + + +/** + * Wrapper class for javaCC generated Classes. + * + * + * @author Jan Krueger - jkrueger(at)cebitec.uni-bielefeld.de + */ +public class DependencyParser extends de.unibi.techfak.bibiserv.util.dependencyparser.javacc.DependencyParser{ + +} diff --git a/libs/dependencyparser/src/main/java/de/unibi/techfak/bibiserv/util/dependencyparser/EmptyNode.java b/libs/dependencyparser/src/main/java/de/unibi/techfak/bibiserv/util/dependencyparser/EmptyNode.java new file mode 100644 index 0000000..9a5a244 --- /dev/null +++ b/libs/dependencyparser/src/main/java/de/unibi/techfak/bibiserv/util/dependencyparser/EmptyNode.java @@ -0,0 +1,60 @@ +/* +DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + +Copyright 2010 BiBiServ Curator Team, http://bibiserv.cebitec.uni-bielefeld.de, +All rights reserved. + +The contents of this file are subject to the terms of the Common +Development and Distribution License("CDDL") (the "License"). You +may not use this file except in compliance with the License. You can +obtain a copy of the License at http://www.sun.com/cddl/cddl.html + +See the License for the specific language governing permissions and +limitations under the License. When distributing the software, include +this License Header Notice in each file. If applicable, add the following +below the License Header, with the fields enclosed by brackets [] replaced +by your own identifying information: + +"Portions Copyrighted 2011 BiBiServ" + +Contributor(s): + */ +package de.unibi.techfak.bibiserv.util.dependencyparser; + +import java.util.ArrayList; +import java.util.List; + +/** + * EmptyNode - represents an empty tree. Only used in the case no dependency string is set. + * + * @author Jan Krueger - jkrueger(at)cebitec.uni-bielefeld.de + */ +public class EmptyNode extends Node{ + + @Override + public boolean evaluate() throws DependencyException { + return true; + } + + @Override + public List getChildNodes() { + return new ArrayList(); + } + + @Override + public boolean hasChildNodes() { + return false; + } + + @Override + public String toString() { + return "empty"; + } + + + + + + + +} diff --git a/libs/dependencyparser/src/main/java/de/unibi/techfak/bibiserv/util/dependencyparser/Id.java b/libs/dependencyparser/src/main/java/de/unibi/techfak/bibiserv/util/dependencyparser/Id.java new file mode 100644 index 0000000..9fa58da --- /dev/null +++ b/libs/dependencyparser/src/main/java/de/unibi/techfak/bibiserv/util/dependencyparser/Id.java @@ -0,0 +1,150 @@ +/* +DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + +Copyright 2010 BiBiServ Curator Team, http://bibiserv.cebitec.uni-bielefeld.de, +All rights reserved. + +The contents of this file are subject to the terms of the Common +Development and Distribution License("CDDL") (the "License"). You +may not use this file except in compliance with the License. You can +obtain a copy of the License at http://www.sun.com/cddl/cddl.html + +See the License for the specific language governing permissions and +limitations under the License. When distributing the software, include +this License Header Notice in each file. If applicable, add the following +below the License Header, with the fields enclosed by brackets [] replaced +by your own identifying information: + +"Portions Copyrighted 2011 BiBiServ" + +Contributor(s): + */ +package de.unibi.techfak.bibiserv.util.dependencyparser; + +import java.util.ArrayList; +import java.util.List; + +/** + * IdNode - represents an Id (aka parameter id) + * + * @author Jan Krueger - jkrueger(at)cebitec.uni-bielefeld.de + */ +public class Id extends LeafNode implements Comparable { + + private String id; + private ParameterWrapper pw; + + + public Id(String id, TYPE type) { + this.id = id; + this.type = type; + } + + public Id(String id, TYPE type, ParameterWrapper pw) { + this.id = id; + this.type = type; + this.pw = pw; + } + + + + public String getId(){ + return id; + } + + public TYPE getType(){ + return type; + } + + + + @Override + public int hashCode() { + int hash = 3; + hash = 13 * hash + (this.id != null ? this.id.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final Id other = (Id) obj; + if ((this.id == null) ? (other.id != null) : !this.id.equals(other.id)) { + return false; + } + return true; + } + + @Override + public boolean evaluate() throws DependencyException { + if (pw == null) { + throw new DependencyException("Call evaluate with non set parameterwrapper ...", DependencyExceptionEnum.noParameterWrapper, ""); + + } + missingconstraints.clear(); + fullfilledconstraints.clear(); + valuelist.clear(); + + if (pw.idExists(id)) { + /* Remark : + * + * A parameter can be occurred more than once (e.g. for multiple select lists). + * + * + */ + List tmplist = pw.getValue(id); + + for (String tmp : tmplist) { + switch (type) { + case STRING: + valuelist.add(tmp); + break; + case INT: + try { + valuelist.add(Integer.parseInt(tmp)); + } catch (NumberFormatException e) { + throw new DependencyException(e, DependencyExceptionEnum.stringToTypeCastFailed, "Integer: "+tmp); + } + break; + case FLOAT: + try { + valuelist.add(Float.parseFloat(tmp)); + } catch (NumberFormatException e) { + throw new DependencyException(e, DependencyExceptionEnum.stringToTypeCastFailed, "Float: "+tmp); + } + break; + case BOOLEAN: + valuelist.add(Boolean.parseBoolean(tmp)); + break; + default: + throw new DependencyException("Type " + type + " not supported or yet implemented ...", DependencyExceptionEnum.unsupportedType, type.toString()); + } + } + fullfilledconstraints.put(this,new ArrayList ()); + return true; + } + missingconstraints.put(this,new ArrayList ()); + return false; + } + + + + @Override + public String toString(){ + return id; + } + + + + @Override + public int compareTo(Id o) { + return id.compareTo(o.getId()); + } + + +} diff --git a/libs/dependencyparser/src/main/java/de/unibi/techfak/bibiserv/util/dependencyparser/LeafNode.java b/libs/dependencyparser/src/main/java/de/unibi/techfak/bibiserv/util/dependencyparser/LeafNode.java new file mode 100644 index 0000000..e9388f9 --- /dev/null +++ b/libs/dependencyparser/src/main/java/de/unibi/techfak/bibiserv/util/dependencyparser/LeafNode.java @@ -0,0 +1,60 @@ +/* +DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + +Copyright 2010 BiBiServ Curator Team, http://bibiserv.cebitec.uni-bielefeld.de, +All rights reserved. + +The contents of this file are subject to the terms of the Common +Development and Distribution License("CDDL") (the "License"). You +may not use this file except in compliance with the License. You can +obtain a copy of the License at http://www.sun.com/cddl/cddl.html + +See the License for the specific language governing permissions and +limitations under the License. When distributing the software, include +this License Header Notice in each file. If applicable, add the following +below the License Header, with the fields enclosed by brackets [] replaced + by your own identifying information: + +"Portions Copyrighted 2011 BiBiServ" + +Contributor(s): Jan Krueger +*/ +package de.unibi.techfak.bibiserv.util.dependencyparser; + +import java.util.ArrayList; +import java.util.List; + +/** + * Represents a leaf in the dependency. This abstract is implemented by Id and Const. + * + * Remember, since it isn't forbidden to use an parameter more than once, we've to support a list + * of values for each + * + * + * @author Jan Krueger - jkrueger(at)cebitec.uni-bielefeld.de + */ +public abstract class LeafNode extends Node { + + public enum TYPE { + + STRING, INT, FLOAT, BOOLEAN + } + + protected List valuelist = new ArrayList(); + protected TYPE type; + + public List getValues(){ + return valuelist; + } + + @Override + public List getChildNodes(){ + return new ArrayList(); + } + + @Override + public boolean hasChildNodes() { + return false; + } + +} diff --git a/libs/dependencyparser/src/main/java/de/unibi/techfak/bibiserv/util/dependencyparser/LogOpNode.java b/libs/dependencyparser/src/main/java/de/unibi/techfak/bibiserv/util/dependencyparser/LogOpNode.java new file mode 100644 index 0000000..729e888 --- /dev/null +++ b/libs/dependencyparser/src/main/java/de/unibi/techfak/bibiserv/util/dependencyparser/LogOpNode.java @@ -0,0 +1,139 @@ +/* +DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + +Copyright 2010 BiBiServ Curator Team, http://bibiserv.cebitec.uni-bielefeld.de, +All rights reserved. + +The contents of this file are subject to the terms of the Common +Development and Distribution License("CDDL") (the "License"). You +may not use this file except in compliance with the License. You can +obtain a copy of the License at http://www.sun.com/cddl/cddl.html + +See the License for the specific language governing permissions and +limitations under the License. When distributing the software, include +this License Header Notice in each file. If applicable, add the following +below the License Header, with the fields enclosed by brackets [] replaced +by your own identifying information: + +"Portions Copyrighted 2011 BiBiServ" + +Contributor(s): + */ +package de.unibi.techfak.bibiserv.util.dependencyparser; + +/** + * + * @author Jan Krueger - jkrueger(at)cebitec.uni-bielefeld.de + */ +public class LogOpNode extends OpNode { + + public LogOpNode(Operations operation) { + super(operation); + } + + public LogOpNode(Operations operation, Node a) { + super(operation, a); + } + + public LogOpNode(Operations operation, Node a, Node b) { + super(operation, a, b); + } + + @Override + public boolean evaluate() throws DependencyException { + // evaluate child node + boolean t_a, t_b = false; + + ConstraintHashMap local_fullfilledConstraints = new ConstraintHashMap(); + ConstraintHashMap local_missingConstraints = new ConstraintHashMap(); + + // ---------- node 1 ----------- + t_a = a.evaluate(); + // local_fullfilledConstraints.put(null, null) @ToDO Verknuepfungen von Teilelementen evtl. ebenfalls abspeichern dafuer + + local_fullfilledConstraints.putAll(a.getFullfilledConstraints()); + local_missingConstraints.putAll(a.getMissingConstraints()); + + // ----------- node 2 ---------- + if (b != null) { + t_b = b.evaluate(); + local_fullfilledConstraints.putAll(b.getFullfilledConstraints()); + local_missingConstraints.putAll(b.getMissingConstraints()); + + } + + boolean result = false; + switch (operation) { + case AND: + result = t_a & t_b; + missingconstraints = local_missingConstraints; + fullfilledconstraints = local_fullfilledConstraints; + break; + case OR: + result = t_a | t_b; + missingconstraints = local_missingConstraints; + fullfilledconstraints = local_fullfilledConstraints; + break; + case XOR: + result = t_a ^ t_b; + missingconstraints = local_missingConstraints; + fullfilledconstraints = local_fullfilledConstraints; + break; + case NOT: + result = !t_a; + missingconstraints = local_fullfilledConstraints; + swap_cmp(missingconstraints); + fullfilledconstraints = local_missingConstraints; + swap_cmp(fullfilledconstraints); + break; + + default: + throw new DependencyException("Unsupported Operation '" + operation.name() + "'", DependencyExceptionEnum.unsupportedOperation, operation.name()); + + } + + return result; + } + + + + + + + /** + * private helper function that negates cmp operations (needed for logop not) + * + * + * @param chm + */ + private void swap_cmp(ConstraintHashMap chm) { + for (Id id : chm.keySet()) { + if (chm.get(id) != null) { + for (Constraints c : chm.get(id)) { + switch (c.getOperation()) { + case EQ: + c.setOperation(Operations.NE); + break; + case NE: + c.setOperation(Operations.EQ); + break; + case GT: + c.setOperation(Operations.LE); + break; + case GE: + c.setOperation(Operations.LT); + break; + case LT: + c.setOperation(Operations.GE); + break; + case LE: + c.setOperation(Operations.GT); + break; + } + } + } + } + + + } +} diff --git a/libs/dependencyparser/src/main/java/de/unibi/techfak/bibiserv/util/dependencyparser/Node.java b/libs/dependencyparser/src/main/java/de/unibi/techfak/bibiserv/util/dependencyparser/Node.java new file mode 100644 index 0000000..c8471ad --- /dev/null +++ b/libs/dependencyparser/src/main/java/de/unibi/techfak/bibiserv/util/dependencyparser/Node.java @@ -0,0 +1,85 @@ +/* +DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + +Copyright 2010 BiBiServ Curator Team, http://bibiserv.cebitec.uni-bielefeld.de, +All rights reserved. + +The contents of this file are subject to the terms of the Common +Development and Distribution License("CDDL") (the "License"). You +may not use this file except in compliance with the License. You can +obtain a copy of the License at http://www.sun.com/cddl/cddl.html + +See the License for the specific language governing permissions and +limitations under the License. When distributing the software, include +this License Header Notice in each file. If applicable, add the following +below the License Header, with the fields enclosed by brackets [] replaced + by your own identifying information: + +"Portions Copyrighted 2011 BiBiServ" + +Contributor(s): +*/ +package de.unibi.techfak.bibiserv.util.dependencyparser; + +import java.util.List; + + +/** + * + * @author Jan Krueger - jkrueger(at)cebitec.uni-bielefeld.de + */ +public abstract class Node { + + ConstraintHashMap missingconstraints = new ConstraintHashMap (); + + ConstraintHashMap fullfilledconstraints = new ConstraintHashMap (); + + /** Evaluate generated Tree. If the given parameter set fulfill dependency + * tree return true, false otherwise + * @return + * @throws de.unibi.techfak.bibiserv.util.dependencyparser.DependencyException */ + public abstract boolean evaluate() throws DependencyException; + + /** + * Returns a list of id's, describing the missing parameter constraints, from the last evaluate run. + * + * @return + */ + public ConstraintHashMap getMissingConstraints() { + return missingconstraints; + } + + /** + * Returns a list of id's, describing the fulfilled parameter constraints, from the last evaluate run. + * + * @return + */ + public ConstraintHashMap getFullfilledConstraints() { + return fullfilledconstraints; + } + + /** + * Return all childnodes of current Node. This function isn't neccessary to evaluate current Node, + * but helpful to transform current to to another represenation. + * + * @return Return all child nodes of current node. + */ + public abstract List getChildNodes(); + + + /** + * Return true in the case current Node has one ore more child nodes, false otherwise. + * This function isn't neccessary to evaluate current Node, but helpful to + * transform current to to another represenation. + * + * @return Return true in the case current Node has one ore more child nodes, false otherwise. + */ + public abstract boolean hasChildNodes(); + + + /** + * Return a String representation of current node + */ + public abstract String toString(); + +} diff --git a/libs/dependencyparser/src/main/java/de/unibi/techfak/bibiserv/util/dependencyparser/NodeUtility.java b/libs/dependencyparser/src/main/java/de/unibi/techfak/bibiserv/util/dependencyparser/NodeUtility.java new file mode 100644 index 0000000..9def852 --- /dev/null +++ b/libs/dependencyparser/src/main/java/de/unibi/techfak/bibiserv/util/dependencyparser/NodeUtility.java @@ -0,0 +1,72 @@ +/* +DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + +Copyright 2010 BiBiServ Curator Team, http://bibiserv.cebitec.uni-bielefeld.de, +All rights reserved. + +The contents of this file are subject to the terms of the Common +Development and Distribution License("CDDL") (the "License"). You +may not use this file except in compliance with the License. You can +obtain a copy of the License at http://www.sun.com/cddl/cddl.html + +See the License for the specific language governing permissions and +limitations under the License. When distributing the software, include +this License Header Notice in each file. If applicable, add the following +below the License Header, with the fields enclosed by brackets [] replaced +by your own identifying information: + +"Portions Copyrighted 2011 BiBiServ" + +Contributor(s): Jan Krueger + */ +package de.unibi.techfak.bibiserv.util.dependencyparser; + +/** + * Provides some static utility functions. + * + * + * @author jkrueger - jkrueger(at)cebitec.uni-bielefeld.de + */ +public class NodeUtility { + + /** + * Converts a given Dependency node(tree) into its string representation + * + * @param n - Dependency Node + * @return Returns String representation of give node. + */ + public static String Node2String(Node n) { + return Node2StringHelper(n, null); + + } + + + private static String Node2StringHelper(Node n, Node p) { + String ret = ""; + if (n instanceof OpNode) { + //work on childs + if (n.hasChildNodes()) { + for (int i = 0; i < n.getChildNodes().size(); ++i) { + if (i > 0) { + ret = ret + ","; + } + ret = ret + Node2StringHelper(n.getChildNodes().get(i),n); + } + } + OpNode on = (OpNode) n; + ret = on.getOperation().toString().toLowerCase() + "(" + ret + ")"; + } else if (n instanceof Id) { + ret = "@"+((Id)n).getId(); + if (p != null && !(p instanceof CmpOpNode)) { + ret = "def("+ret+")"; + } + + } else if (n instanceof Const) { + ret = ((Const)n).getValues().get(0).toString(); + + } else if (n instanceof EmptyNode) { + ret = "EMPTY"; + } + return ret; + } +} diff --git a/libs/dependencyparser/src/main/java/de/unibi/techfak/bibiserv/util/dependencyparser/OpNode.java b/libs/dependencyparser/src/main/java/de/unibi/techfak/bibiserv/util/dependencyparser/OpNode.java new file mode 100644 index 0000000..b3f8d39 --- /dev/null +++ b/libs/dependencyparser/src/main/java/de/unibi/techfak/bibiserv/util/dependencyparser/OpNode.java @@ -0,0 +1,96 @@ +/* +DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + +Copyright 2010 BiBiServ Curator Team, http://bibiserv.cebitec.uni-bielefeld.de, +All rights reserved. + +The contents of this file are subject to the terms of the Common +Development and Distribution License("CDDL") (the "License"). You +may not use this file except in compliance with the License. You can +obtain a copy of the License at http://www.sun.com/cddl/cddl.html + +See the License for the specific language governing permissions and +limitations under the License. When distributing the software, include +this License Header Notice in each file. If applicable, add the following +below the License Header, with the fields enclosed by brackets [] replaced + by your own identifying information: + +"Portions Copyrighted 2011 BiBiServ" + +Contributor(s): +*/ +package de.unibi.techfak.bibiserv.util.dependencyparser; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Jan Krueger - jkrueger(at)cebitec.uni-bielefeld.de + */ +public abstract class OpNode extends Node { + + public enum Operations {AND,OR,XOR,NOT,IMPL,LOGEQ,EQ,NE,GT,GE,LT,LE,NULL} + + + protected Operations operation = null; + + protected Node a = null; + protected Node b = null; + + + public OpNode(Operations operation){ + this.operation = operation; + } + + public OpNode(Operations operation, Node a){ + this.operation = operation; + this.a = a; + } + + public OpNode(Operations operation, Node a,Node b){ + this.operation = operation; + this.a = a; + this.b = b; + } + + public void add_A(Node node){ + a = node; + } + + public void add_B(Node node){ + b = node; + } + + public void setOperation(Operations operation){ + this.operation = operation; + } + + public Operations getOperation(){ + return operation; + } + + @Override + public List getChildNodes() { + List l = new ArrayList(); + if (a != null) { + l.add(a); + } + if (b != null) { + l.add(b); + } + return l; + } + + @Override + public boolean hasChildNodes() { + return getChildNodes().size() > 0; + } + + + @Override + public String toString() { + return operation.name(); + } + + +} diff --git a/libs/dependencyparser/src/main/java/de/unibi/techfak/bibiserv/util/dependencyparser/ParameterWrapper.java b/libs/dependencyparser/src/main/java/de/unibi/techfak/bibiserv/util/dependencyparser/ParameterWrapper.java new file mode 100644 index 0000000..ecbd416 --- /dev/null +++ b/libs/dependencyparser/src/main/java/de/unibi/techfak/bibiserv/util/dependencyparser/ParameterWrapper.java @@ -0,0 +1,127 @@ +/* +DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + +Copyright 2010 BiBiServ Curator Team, http://bibiserv.cebitec.uni-bielefeld.de, +All rights reserved. + +The contents of this file are subject to the terms of the Common +Development and Distribution License("CDDL") (the "License"). You +may not use this file except in compliance with the License. You can +obtain a copy of the License at http://www.sun.com/cddl/cddl.html + +See the License for the specific language governing permissions and +limitations under the License. When distributing the software, include +this License Header Notice in each file. If applicable, add the following +below the License Header, with the fields enclosed by brackets [] replaced +by your own identifying information: + +"Portions Copyrighted 2011 BiBiServ" + +Contributor(s): + */ +package de.unibi.techfak.bibiserv.util.dependencyparser; + +import de.unibi.techfak.bibiserv.util.Pair; +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Set; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathFactory; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +/** + * + * @author Jan Krueger - jkrueger(at)cebitec.uni-bielefeld.de + */ +public class ParameterWrapper { + + private HashMap> paramcon = new HashMap>(); + + public void setParameter(List> parampairlist) { + paramcon.clear(); + if (parampairlist == null) { + return; + } + for (Pair p : parampairlist) { + put(p); + } + } + + public void setParameter(File file) throws DependencyException { + try { + /* read param from (xml-file)*/ + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setNamespaceAware(true); + DocumentBuilder db = dbf.newDocumentBuilder(); + /* read param from file */ + Document param = db.parse(file); + setParameter(param.getDocumentElement()); + } catch (Exception e) { + throw new DependencyException(e, DependencyExceptionEnum.setParameter, ""); + } + } + + public void setParameter(Element param) throws DependencyException { + paramcon.clear(); + try { + XPathFactory xpf = XPathFactory.newInstance(); + XPath xpath = xpf.newXPath(); + NodeList nl = (NodeList) xpath.evaluate("//*/@id", param, XPathConstants.NODESET); + + for (int i = 0; i < nl.getLength(); ++i) { + Element id_e = (Element) nl.item(i); + + String id = id_e.getTextContent(); + + Element e = (Element) xpath.evaluate("//*[@id='" + id + "']", param, XPathConstants.NODE); + if (e == null) { + put(id, ""); + } else { + put(id, e.getTextContent()); + } + + } + } catch (Exception e) { + throw new DependencyException(e,DependencyExceptionEnum.setParameter, ""); + } + } + + public boolean idExists(String id) { + return paramcon.containsKey(id); + } + + public List getValue(String id) { + return paramcon.get(id); + } + + public Set getIdList() { + return paramcon.keySet(); + } + + public void clear() { + paramcon.clear(); + } + + /* ----------- private methods --------------- */ + private void put(String key, String value) { + put(new Pair(key, value)); + } + + private void put(Pair p) { + List values; + if (paramcon.containsKey(p.getKey())) { + values = paramcon.get(p.getKey()); + } else { + values = new ArrayList(); + paramcon.put(p.getKey(), values); + } + values.add(p.getValue()); + } +} diff --git a/libs/dependencyparser/src/main/java/de/unibi/techfak/bibiserv/util/dependencyparser/ParseExceptionMessageEnum.java b/libs/dependencyparser/src/main/java/de/unibi/techfak/bibiserv/util/dependencyparser/ParseExceptionMessageEnum.java new file mode 100644 index 0000000..0edf419 --- /dev/null +++ b/libs/dependencyparser/src/main/java/de/unibi/techfak/bibiserv/util/dependencyparser/ParseExceptionMessageEnum.java @@ -0,0 +1,88 @@ +/* +DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + +Copyright 2010 BiBiServ Curator Team, http://bibiserv.cebitec.uni-bielefeld.de, +All rights reserved. + +The contents of this file are subject to the terms of the Common +Development and Distribution License("CDDL") (the "License"). You +may not use this file except in compliance with the License. You can +obtain a copy of the License at http://www.sun.com/cddl/cddl.html + +See the License for the specific language governing permissions and +limitations under the License. When distributing the software, include +this License Header Notice in each file. If applicable, add the following +below the License Header, with the fields enclosed by brackets [] replaced +by your own identifying information: + +"Portions Copyrighted 2011 BiBiServ" + +Contributor(s): + */ + +package de.unibi.techfak.bibiserv.util.dependencyparser; + +import de.unibi.techfak.bibiserv.util.dependencyparser.javacc.ParseException; + +/** + * @author Thomas Gatter + */ +public enum ParseExceptionMessageEnum { + + noParameterWidthId("No Parameter with ID: "), + noTypeChildParameter("No Type in Parameter: "), + notSupportedOrImplemented("Not supported or implemented: "), + unknownConstantValue("Unkown Constant Value: "), // Expected Values are String ('string'), Boolean (true,false), Integer ([+|-]\\d+) and Float ([+|-]\\d+\\.\\d+)!" + empty(""), + onToken(""); + + private String message; + + private ParseExceptionMessageEnum(String message){ + this.message = message; + } + + /** + * Find out what type of exception occured. + * @param e the caught exception + * @return ParseExceptionMessageEnum corresponding to exception + */ + public static ParseExceptionMessageEnum getType(ParseException e){ + String message = e.getMessage(); + + if(message.startsWith(noParameterWidthId.message)){ + return noParameterWidthId; + } else if(message.startsWith(noTypeChildParameter.message)){ + return noTypeChildParameter; + } else if(message.startsWith(notSupportedOrImplemented.message)){ + return notSupportedOrImplemented; + } else if(message.startsWith(unknownConstantValue.message)){ + return unknownConstantValue; + } else { + if(e.currentToken!=null){ + return onToken; + } else { + return empty; + } + } + } + + /** + * Return the value passed in the message of a ParseException. + * Return Empty String if no Value or no correct message. + * @param message Message to get Value out of. + * @return the passed Value + */ + public static String getValue(String message){ + String[] splitted = message.split(": ", 2); + if(splitted.length>1){ + return splitted[1]; + } + return ""; + } + + public String getMessage() { + return message; + } + +} diff --git a/libs/dependencyparser/src/main/javacc/DependencyParser.jj b/libs/dependencyparser/src/main/javacc/DependencyParser.jj new file mode 100644 index 0000000..ac0c62b --- /dev/null +++ b/libs/dependencyparser/src/main/javacc/DependencyParser.jj @@ -0,0 +1,626 @@ + options { + STATIC=false; + +} + +PARSER_BEGIN(DependencyParser) + + +/* +DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + +Copyright 2010 BiBiServ Curator Team, http://bibiserv.cebitec.uni-bielefeld.de, +All rights reserved. + +The contents of this file are subject to the terms of the Common +Development and Distribution License("CDDL") (the "License"). You +may not use this file except in compliance with the License. You can +obtain a copy of the License at http://www.sun.com/cddl/cddl.html + +See the License for the specific language governing permissions and +limitations under the License. When distributing the software, include +this License Header Notice in each file. If applicable, add the following +below the License Header, with the fields enclosed by brackets [] replaced +by your own identifying information: + +"Portions Copyrighted 2011-2013 BiBiServ" + +Contributor(s): Jan Krueger + */ + +import de.unibi.techfak.bibiserv.util.dependencyparser.*; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.InputStream; +import java.io.StringReader; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import javax.xml.namespace.NamespaceContext; + + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathFactory; + +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + + +/** + Dependency Parser +

+ This class parses a dependency string (as defined by the bibiserv2 dependency + language) and returns a tree representation from it. One of the biggest problem + we have with the first implementation of the BiBiServ was a general possibility to + describe dependencies between parameters authors used within their tools. + Normally this must be done by the authors code itself and often this important + feature is left out due to missing time or fast development. + + With the BiBiServAbstraction schema we can describe all kind of parameters a tool + can have with the possibility to restrict the range of values (e.g. a numeric + parameter is from typ int and its range of values is between 0 and 10, or a + string parameter must match a given regular expression) + + But often one parameter depends from an other one (e.g. if parameter x is + given parameter y must be also defined) +

+		isDefined(x) and isDefined(y)
+	
+ + Or, more special, one parameter x depends from another parameter with a + defined value (e.g. if parameter x is given parameter y must be between 1 and 4) +
+		isDefined(x) and isDefined(y) and (y ≥ 1) and (y ≤ 4)
+	
+

+

+ A language, which fullfill our requirements is given by the following + grammar (in BNF notation): +

+<Function>     ::= <AND> | <OR> | <XOR>| <NOT> | <IMPL> | def(<id>) | <EQUALS> | <GREATER> | <GREATEREQUALS> | <LESSER> | <LESSEREQUALS>
+<AND>          ::= and(<Function>,<Function>)      // logical conjunction : and(@a,@b) ≡ @a ∧ &b
+<OR>           ::= or(<Function>,<Function>)       // logical disjunction : or(@a,@b) ≡ @a ∨ &b
+<XOR>          ::= xor(<Function>,<Function>)      // exclusive disjunction : xor(@a,@b) ≡ @a ⊕ @b  ≡ @a + @b
+<NOT>          ::= not(<Function>)                       // logical not : not(@a) ≡ ¬@a
+<IMPL>         ::= impl(<Function>,<Function>)     // logical implication : impl(@a,@b) ≡ @a   ↔ @b
+<LOGEQ>        ::= logeq(@lt;Function>,<Function>)    // logical equality :logeq(@a,@n) ≡ @a → @b
+<EQUALS>       ::= eq(<id>,<id> | <value>)
+<GREATER>      ::= gt(<id>,<id> |<value>)
+<GREATEREQUALS>::= ge(<id>,<id> |<value>)
+<LESSER>       ::= lt(<id>,<id> |<value>)
+<LESSEREQUALS> ::= le(<id>,<id> |<value>)
+<id>           ::= @[A-Z,a-z][A-Z,a-z,0-9]*
+<value>        ::= [+,-]?[0-9]+[.]?[0-9]* | '([A-Z,a-z,0-9,_,-,+,.,\,,/,?])*'
+	
+ + + A Java based compilercompiler is used to generate the parser (javacc-4.x). +

+

+ Using the parser is quite simple : + +

+
+        ...
+
+        DependencyParser dp = new DependencyParser();
+        dp.setTooldescription(...);  // from a file or from a resource stream or DOM element
+        ParameterWrapper pw = new ParameterWrapper();
+
+        pw.setParameter(...) // from a file, a Properties object or DOM element
+        dp.setParameterWrapper(pw);
+
+        dp.setFunctionId(...); // id of function within tooldescription to be evaluted
+
+
+        // parse Dependency string and generate tree
+        Node node = dp.generate();
+
+        // evaluate parameter set against dependency tree
+        if (!node.evaluate()) {
+            // get list of missing parameter id's
+            List missingParamIdList = node.getMissingConstraints()
+        }
+
+
+        ...
+        
+ + +

+ +*/ +public class DependencyParser { + + + private Element tooldescription = null; + private ParameterWrapper parameterwrapper = null; + private String fct_id = null; + + private final String ToolDescriptionNS = "bibiserv:de.unibi.techfak.bibiserv.cms"; + + + + + /* ---------------------- public methods ------------------------------ */ + + + public DependencyParser(){ + this(new StringReader("")); + } + + /** + * Set a reference to a tooldescripton DOM element to current parser instance. + * + * @param Element tooldescription + */ + public void setTooldescription(Element tooldescription){ + this.tooldescription = tooldescription; + } + + + /** + * Read tooldescription from a file. + * + * @param file + * @throws DependencyException + * @throws FileNotFoundException + */ + public void setTooldescription(File file) throws DependencyException, FileNotFoundException { + setTooldescription(new FileInputStream(file)); + } + + /** + * Read Tooldescription from an Inputstream. + * + * @param is + * @throws DependencyException + */ + public void setTooldescription(InputStream is) throws DependencyException{ + try { + /* read param from (xml-file)*/ + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setNamespaceAware(true); + DocumentBuilder db = dbf.newDocumentBuilder(); + /* read description from file */ + tooldescription = db.parse(is).getDocumentElement(); + + } catch(Exception e){ + throw new DependencyException(e,DependencyExceptionEnum.setTooldescriptionException,""); + } + } + + public void setFunctionId(String id) { + this.fct_id = id; + } + + /** Set a ParameterWrapper object */ + public void setParameterWrapper(ParameterWrapper parameterwrapper){ + this.parameterwrapper = parameterwrapper; + } + + /** + * Extract dependency strings from tooldescription and set function id. + * + * @return List of Dependency Strings + */ + public List getDependencyStrings() throws DependencyException { + + + if (fct_id == null) { + throw new DependencyException("No fct_id set!", DependencyExceptionEnum.noFunctionId, ""); + } + if (tooldescription == null) { + throw new DependencyException("No ToolDescription (runnableitem) element set!", DependencyExceptionEnum.noRunnableItem, ""); + } + + /* extract dependency defintion*/ + try { + XPathFactory xpf = XPathFactory.newInstance(); + XPath xpath = xpf.newXPath(); + xpath.setNamespaceContext(new MyNSContext()); + NodeList nl = (NodeList) xpath.evaluate("//bibi:dependency[@id=//bibi:function[@id='" + fct_id + "']/bibi:depref/@ref]/bibi:dependencyDefinition", tooldescription, XPathConstants.NODESET); + + List l = new ArrayList(); + for (int i = 0; i < nl.getLength(); i++) { + Element e = (Element) nl.item(i); + if (e != null) { + String dep = e.getTextContent(); + if (dep != null && !dep.isEmpty()) { + l.add(dep); + } + } + } + return l; + } catch (Exception e) { + throw new DependencyException("Exception occured while extraxting dependency defintion from function [@id='" + fct_id + "']!", e, DependencyExceptionEnum.dependencyExtractionError, fct_id); + } + + + + } + + + /** + * Initiate a parser run and return true if expression is valid, false + * otherwise + * + * @return Returns true in the case the expression is evaluate to true, + * false otherwise + * @throws ParseException if the expression is false + */ + public Node generate() throws ParseException, DependencyException { + + if (parameterwrapper == null) { + throw new DependencyException("No parameter wrapper set!", DependencyExceptionEnum.noParameterWrapper, ""); + } + + + List depdeflist = getDependencyStrings(); + + /* if list is empty return Empty Node */ + if (depdeflist.isEmpty()) { + return new EmptyNode(); + } + + + /* (re) initalize Parser */ + ReInit(new StringReader(depdeflist.get(0))); + /* parse input and generate Treerepresentation */ + Node n = fct(); + + + + for (int i = 1; i < depdeflist.size(); i++) { + /* (re) initalize Parser */ + ReInit(new StringReader(depdeflist.get(1))); + n = new LogOpNode(OpNode.Operations.AND, n, fct()); + } + return n; + } + + /* ---------------------- private methods ----------------------------- */ + private Element getElementById(Element elem, String id){ + try { + XPathFactory xpf = XPathFactory.newInstance(); + XPath xpath = xpf.newXPath(); + return (Element)xpath.evaluate("//*[@id='"+id+"']", elem ,XPathConstants.NODE); + } catch (Exception e){ + System.err.println(e.getMessage()); + return null; + } + + } + + + /* ------------------------ inner class ------------------------------- */ + + /** Very simple Implementation for a NamespaceContext. MyNSContext knows only + one Prefix "bibi..." URI "bibiserv:de.unibi.techfak.bibiserv.cms" combination. */ + + class MyNSContext implements NamespaceContext{ + + public String getNamespaceURI(String prefix) { + if (prefix.startsWith("bibi") ){ + return ToolDescriptionNS ; + } + throw new UnsupportedOperationException("Unsupported Prefix '"+prefix+"'."); + } + + public String getPrefix(String namespaceURI) { + if (namespaceURI.equals(ToolDescriptionNS)) { + return "bibi"; + } + throw new UnsupportedOperationException("Unsupported URI : '"+namespaceURI+"'."); + } + + public Iterator getPrefixes(String namespaceURI) { + throw new UnsupportedOperationException("Not supported yet."); + } + } +} +PARSER_END(DependencyParser) + + +/* The defintion of Token, Terminal and Non-Terminal Symbols follows the + BNF Notation. I used the javacc feature to integrate Java code to + parse and interpret on the fly ... */ + + +SKIP : +{ + " " + | "\t" + | "\n" + | "\r" +} + + +TOKEN : +{ + +| +| +} + + + + +Node fct() : +{ + Node a; +} +{ + (a=xor()|a=not()|a=or()|a=and()|a=impl()|a=logeq()|a=eq()|a=ne()|a=le()|a=ge()|a=lt()|a=gt()|"def" "(" a=id() ")") + { + return a; + } +} + +Node and() : +{ + LogOpNode n = new LogOpNode(OpNode.Operations.AND); + Node a,b; +} +{ + "and" "(" a=fct() "," b=fct() ")" + { + n.add_A(a); + n.add_B(b); + return n; + } +} + +Node or() : +{ + LogOpNode n = new LogOpNode(OpNode.Operations.OR); + Node a,b; +} +{ + "or" "(" a=fct() "," b=fct() ")" + { + n.add_A(a); + n.add_B(b); + return n; + } +} + +Node not() : +{ + LogOpNode n = new LogOpNode(OpNode.Operations.NOT); + Node a; +} +{ + "not" "(" a=fct() ")" + { + n.add_A(a); + return n; + } + +} + +Node xor() : +{ + LogOpNode n = new LogOpNode(OpNode.Operations.XOR); + Node a,b; +} +{ + "xor" "(" a=fct() "," b=fct() ")" + { + n.add_A(a); + n.add_B(b); + return n; + } +} + +Node impl() : +{ + // impl can be represented as or(not(A),B) + LogOpNode n = new LogOpNode(OpNode.Operations.OR); + LogOpNode n1 = new LogOpNode(OpNode.Operations.NOT); + Node a,b; +} +{ + "impl" "(" a=fct() "," b=fct() ")" + { + n1.add_A(a); + n.add_A(n1); + n.add_B(b); + return n; + } + } + +Node logeq() : +{ + // logeq can be represented as and(or(not(A),B),or(not(B),A)) + LogOpNode n = new LogOpNode(OpNode.Operations.AND); + LogOpNode n1 = new LogOpNode(OpNode.Operations.OR); + LogOpNode n11 = new LogOpNode(OpNode.Operations.NOT); + LogOpNode n2 = new LogOpNode(OpNode.Operations.OR); + LogOpNode n21 = new LogOpNode(OpNode.Operations.NOT); + + Node a,b; +} +{ + "logeq" "(" a=fct() "," b=fct() ")" + { + n11.add_A(a); + n1.add_A(n11); + n1.add_B(b); + + n21.add_A(b); + n2.add_A(n21); + n2.add_B(a); + + n.add_A(n1); + n.add_B(n2); + + return n; + } + } + +Node eq() : +{ + CmpOpNode n = new CmpOpNode(OpNode.Operations.EQ); + Node a,b; +} +{ + "eq" "(" a=id() "," ( b=id() | b=value() ) ")" + { + n.add_A(a); + n.add_B(b); + return n; + } +} + +Node ne() : +{ + CmpOpNode n = new CmpOpNode(OpNode.Operations.NE); + Node a,b; +} +{ + "ne" "(" a=id() "," ( b=id() | b=value() ) ")" + { + n.add_A(a); + n.add_B(b); + return n; + } +} + + +Node lt() : +{ + CmpOpNode n = new CmpOpNode(OpNode.Operations.LT); + Node a,b; +} +{ + "lt" "(" a=id() "," ( b=id() | b=value() ) ")" + { + n.add_A(a); + n.add_B(b); + return n; + } +} + + +Node gt() : +{ + CmpOpNode n = new CmpOpNode(OpNode.Operations.GT); + Node a,b; +} +{ + "gt" "(" a=id() "," ( b=id() | b=value() ) ")" + { + n.add_A(a); + n.add_B(b); + return n; + } +} + + +Node le() : +{ + CmpOpNode n = new CmpOpNode(OpNode.Operations.LE); + Node a,b; +} +{ + "le" "(" a=id() "," ( b=id() | b=value() ) ")" + { + n.add_A(a); + n.add_B(b); + return n; + } +} + + +Node ge() : +{ + CmpOpNode n = new CmpOpNode(OpNode.Operations.GE); + Node a,b; +} +{ + "ge" "(" a=id() "," ( b=id() | b=value() ) ")" + { + n.add_A(a); + n.add_B(b); + return n; + } +} + + +Node id() : +{ Node n; +} +{ + + { + /* real id is token without the first char '@'*/ + String id = token.image.substring(1); + /* if tool_description != null, evaluate the expression .. */ + if ( tooldescription != null) { + + /* get typ of element */ + Element tool_elem = getElementById(tooldescription,id); + if (tool_elem == null) { + throw new ParseException(ParseExceptionMessageEnum.noParameterWidthId.getMessage()+id); + + } + Element tmp = (Element)tool_elem.getElementsByTagNameNS(ToolDescriptionNS,"type").item(0); + if (tmp == null) { + throw new ParseException(ParseExceptionMessageEnum.noTypeChildParameter.getMessage()+id); + } + String type = tmp.getTextContent(); + /* create new Id.Node with type of parameter */ + if (type.equalsIgnoreCase("String")) { + n = new Id(id,LeafNode.TYPE.STRING,parameterwrapper); + return n; + } else if (type.equalsIgnoreCase("int")) { + n = new Id(id,LeafNode.TYPE.INT,parameterwrapper); + return n; + } else if (type.equalsIgnoreCase("float")) { + n = new Id(id,LeafNode.TYPE.FLOAT,parameterwrapper); + return n; + } else if (type.equalsIgnoreCase("boolean")) { + n = new Id(id,LeafNode.TYPE.BOOLEAN,parameterwrapper); + return n; + } else { + /* remark Jan : type date_time is not supported at moment */ + throw new ParseException(ParseExceptionMessageEnum.notSupportedOrImplemented.getMessage()+type); + } + } + return null; + } +} + +Node value() : +{ Node n;} +{ + ( | ) + { + String value = token.image; + + + + /* String */ + if (value.startsWith("'")) { + n = new Const(value.substring(1,value.length()-1)); + } else if (value.equalsIgnoreCase("true") | value.equalsIgnoreCase("false")) { + n = new Const(Boolean.parseBoolean(value.toLowerCase())); + } else if (value.matches("[+|-]?\\d+")) { + n = new Const(Integer.parseInt(value)); + } else if (value.matches("[+|-]?\\d+\\.\\d+[f]?")) { + n = new Const(Float.parseFloat(value)); + } else { + throw new ParseException(ParseExceptionMessageEnum.unknownConstantValue.getMessage()+value); + } + + return n; + } +} + + diff --git a/libs/dependencyparser/src/test/java/de/unibi/techfak/bibiserv/util/dependencyparser/DependencyParserTest.java b/libs/dependencyparser/src/test/java/de/unibi/techfak/bibiserv/util/dependencyparser/DependencyParserTest.java new file mode 100644 index 0000000..9e319f4 --- /dev/null +++ b/libs/dependencyparser/src/test/java/de/unibi/techfak/bibiserv/util/dependencyparser/DependencyParserTest.java @@ -0,0 +1,802 @@ +/* +DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + +Copyright 2010 BiBiServ Curator Team, http://bibiserv.cebitec.uni-bielefeld.de, +All rights reserved. + +The contents of this file are subject to the terms of the Common +Development and Distribution License("CDDL") (the "License"). You +may not use this file except in compliance with the License. You can +obtain a copy of the License at http://www.sun.com/cddl/cddl.html + +See the License for the specific language governing permissions and +limitations under the License. When distributing the software, include +this License Header Notice in each file. If applicable, add the following +below the License Header, with the fields enclosed by brackets [] replaced +by your own identifying information: + +"Portions Copyrighted 2011 BiBiServ" + +Contributor(s): + */ +package de.unibi.techfak.bibiserv.util.dependencyparser; + +import de.unibi.techfak.bibiserv.util.dependencyparser.LeafNode.TYPE; +import java.util.Set; +import de.unibi.techfak.bibiserv.util.Pair; +import de.unibi.techfak.bibiserv.util.dependencyparser.javacc.ParseException; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.util.Collections; +import java.util.List; +import java.util.Collection; + +import java.util.ArrayList; +import java.util.Arrays; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * JUnit Test class. Test generated Parser and build Tree using the sample tool + * description containing + * + * @author jkrueger + */ +public class DependencyParserTest { + + private DependencyParser dp; + private ParameterWrapper pw; + private List> pl; + + public DependencyParserTest() throws DependencyException, FileNotFoundException { + dp = new DependencyParser(); + dp.setTooldescription(new FileInputStream("src/test/xml/sample.xml")); + pw = new ParameterWrapper(); + dp.setParameterWrapper(pw); + + } + + @BeforeClass + public static void setUpClass() throws Exception { + } + + @AfterClass + public static void tearDownClass() throws Exception { + } + + @Test + public void test_ConstraintHashMap() { + + ConstraintHashMap chm = new ConstraintHashMap(); + + chm.put(new Id("A", TYPE.INT), (Constraints) null); + + chm.put(new Id("B", TYPE.FLOAT), Arrays.asList(new Constraints[]{new Constraints(OpNode.Operations.GT, new Const(20f))})); + + ConstraintHashMap chm2 = new ConstraintHashMap(); + + chm2.put(new Id("C", TYPE.INT), new Constraints(OpNode.Operations.EQ, new Const(1))); + + ConstraintHashMap chm3 = new ConstraintHashMap(); + chm3.putAll(chm); + chm3.putAll(chm2); + + assertTrue(true); + + } + + @Test + public void test_NodeUtility() throws ParseException, DependencyException { + dp.setFunctionId("fct_1"); + String expectedString = dp.getDependencyStrings().get(0); + Node node = dp.generate(); + String string = NodeUtility.Node2String(node); + System.err.println("DPStr : " + string); + assertEquals(expectedString, string); + + dp.setFunctionId("fct_10"); + expectedString = dp.getDependencyStrings().get(0); + node = dp.generate(); + string = NodeUtility.Node2String(node); + System.err.println("DPStr : " + string); + assertEquals(expectedString, string); + + dp.setFunctionId("fct_17"); + + List l = dp.getDependencyStrings(); + expectedString = "and(" + l.get(0) + "," + l.get(1) + ")"; + node = dp.generate(); + string = NodeUtility.Node2String(node); + System.err.println("DPStr : " + string); + assertEquals(expectedString, string); + + } + + // fct1 has three parameters (A,B,C) and dependency (A & B & C) + @Test + public void test_fct_1() throws ParseException, DependencyException { + dp.setFunctionId("fct_1"); + + pl = new ArrayList>(); + pw.setParameter(pl); + // generate tree + Node node = dp.generate(); + + assertFalse(node.evaluate()); + + assertHashEquals("Expected [A,B,C] but got " + node.getMissingConstraints().keySet().toString() + "!", + node.getMissingConstraints(), createHashfromArray(new Object[]{ + new Id("A", LeafNode.TYPE.INT), null, + new Id("B", LeafNode.TYPE.FLOAT), null, + new Id("C", LeafNode.TYPE.INT), null + })); + pl.add(new Pair("A", "10")); + pl.add(new Pair("C", "5")); + pw.setParameter(pl); + + assertFalse(node.evaluate()); + + assertHashEquals("Expected [B] but got " + node.getMissingConstraints().keySet().toString() + "!", + node.getMissingConstraints(), createHashfromArray(new Object[]{ + new Id("B", LeafNode.TYPE.FLOAT), null + })); + + pl.add(new Pair("B", "20")); + pw.setParameter(pl); + + assertTrue(node.evaluate()); + } + + // fct2 has three parameters (A,B,C) and dependency (A | B | C) + @Test + public void test_fct_2() throws ParseException, DependencyException { + dp.setFunctionId("fct_2"); + + pl = new ArrayList>(); + pw.setParameter(pl); + // generate tree + Node node = dp.generate(); + + assertFalse(node.evaluate()); + assertHashEquals("Expected [A,B,C] but got " + node.getMissingConstraints().keySet().toString() + "!", + node.getMissingConstraints(), createHashfromArray(new Object[]{ + new Id("A", LeafNode.TYPE.INT), null, + new Id("B", LeafNode.TYPE.FLOAT), null, + new Id("C", LeafNode.TYPE.INT), null + })); + + pl.add(new Pair("B", "20")); + pw.setParameter(pl); + + assertTrue(node.evaluate()); + + } + + // fct3 has three parameters (A,B,C) and dependency ((A & B) | C) + @Test + public void test_fct_3() throws ParseException, DependencyException { + dp.setFunctionId("fct_3"); + + pl = new ArrayList>(); + pw.setParameter(pl); + // generate tree + Node node = dp.generate(); + + assertFalse(node.evaluate()); + assertHashEquals("Expected [A,B,C] but got " + node.getMissingConstraints().keySet().toString() + "!", + node.getMissingConstraints(), createHashfromArray(new Object[]{ + new Id("A", LeafNode.TYPE.INT), null, + new Id("B", LeafNode.TYPE.FLOAT), null, + new Id("C", LeafNode.TYPE.INT), null + })); + pl.add(new Pair("A", "10")); + pl.add(new Pair("B", "20")); + pw.setParameter(pl); + assertTrue(node.evaluate()); + + pl.clear(); + pl.add(new Pair("C", "5")); + pw.setParameter(pl); + assertTrue(node.evaluate()); + } + + // fct4 has five parameters (A,B,C,D,E) and dependency ((A & B) | (C & D) | E) + @Test + public void test_fct_4() throws ParseException, DependencyException { + dp.setFunctionId("fct_4"); + + pl = new ArrayList>(); + pw.setParameter(pl); + // generate tree + Node node = dp.generate(); + + assertFalse(node.evaluate()); + + assertHashEquals("Expected [A,B,C,D,E] but got " + node.getMissingConstraints().keySet().toString() + "!", + node.getMissingConstraints(), createHashfromArray(new Object[]{ + new Id("A", LeafNode.TYPE.INT), null, + new Id("B", LeafNode.TYPE.FLOAT), null, + new Id("C", LeafNode.TYPE.INT), null, + new Id("D", LeafNode.TYPE.FLOAT), null, + new Id("E", LeafNode.TYPE.INT), null + })); + + pl.add(new Pair("E", "5")); + pw.setParameter(pl); + assertTrue(node.evaluate()); + } + + // fct5 has two parameters (A,B) and dependency (A & NOT(B)) + @Test + public void test_fct_5() throws ParseException, DependencyException { + dp.setFunctionId("fct_5"); + + pl = new ArrayList>(); + pw.setParameter(pl); + // generate tree + Node node = dp.generate(); + + assertFalse(node.evaluate()); + assertHashEquals("Expected [A] but got " + node.getMissingConstraints().keySet().toString() + "!", + node.getMissingConstraints(), createHashfromArray(new Object[]{ + new Id("A", LeafNode.TYPE.INT), null + })); + pl.add(new Pair("A", "10")); + pw.setParameter(pl); + + assertTrue(node.evaluate()); + + pl.add(new Pair("B", "20")); + pw.setParameter(pl); + + assertFalse(node.evaluate()); + assertHashEquals("Expected [B] but got " + node.getMissingConstraints().keySet().toString() + "!", + node.getMissingConstraints(), createHashfromArray(new Object[]{ + new Id("B", LeafNode.TYPE.FLOAT), null + })); + } + + // fct6 has two parameters (A,B) and dependency (A -> B) + @Test + public void test_fct_6() throws ParseException, DependencyException { + dp.setFunctionId("fct_6"); + + pl = new ArrayList>(); + pw.setParameter(pl); + // generate tree + Node node = dp.generate(); + + assertTrue(node.evaluate()); + + pl.add(new Pair("A", "10")); + pw.setParameter(pl); + + assertFalse(node.evaluate()); + assertHashEquals("Expected [A,B] but got " + node.getMissingConstraints().keySet().toString() + "!", + node.getMissingConstraints(), createHashfromArray(new Object[]{ + new Id("A", LeafNode.TYPE.INT), null, + new Id("B", LeafNode.TYPE.FLOAT), null + })); + pl.add(new Pair("B", "20")); + pw.setParameter(pl); + + assertTrue(node.evaluate()); + } + + // fct7 has two parameters (A,B) and dependency ((A == 10) -> B) + @Test + public void test_fct_7() throws ParseException, DependencyException { + dp.setFunctionId("fct_7"); + + pl = new ArrayList>(); + pw.setParameter(pl); + // generate tree + Node node = dp.generate(); + + assertTrue(node.evaluate()); + + pl.add(new Pair("A", "10")); + pw.setParameter(pl); + + assertFalse(node.evaluate()); + assertHashEquals( + node.getMissingConstraints(), createHashfromArray(new Object[]{ + new Id("A", LeafNode.TYPE.INT), null, + new Id("B", LeafNode.TYPE.FLOAT), null + })); + + pl.add(new Pair("B", "20")); + pw.setParameter(pl); + + assertTrue(node.evaluate()); + + // it is not forbidden to assign more than value to a parameter + pl.add(new Pair("A", "11")); // should be ok also + pw.setParameter(pl); + + assertTrue(node.evaluate()); + + } + + // fct8 has two parameters (A,B) and dependency (A <-> B) + @Test + public void test_fct_8() throws ParseException, DependencyException { + dp.setFunctionId("fct_8"); + + pl = new ArrayList>(); + pw.setParameter(pl); + // generate tree + Node node = dp.generate(); + + assertTrue(node.evaluate()); + + pl.add(new Pair("A", "10")); + pw.setParameter(pl); + assertFalse(node.evaluate()); + + assertHashEquals("Expected [A,B] but got " + node.getMissingConstraints().keySet().toString() + "!", + node.getMissingConstraints(), createHashfromArray(new Object[]{ + new Id("A", LeafNode.TYPE.INT), null, + new Id("B", LeafNode.TYPE.FLOAT), null + })); + pl.clear(); + pl.add(new Pair("B", "10")); + pw.setParameter(pl); + assertFalse(node.evaluate()); + assertHashEquals("Expected [A,B] but got " + node.getMissingConstraints().keySet().toString() + "!", + node.getMissingConstraints(), createHashfromArray(new Object[]{ + new Id("A", LeafNode.TYPE.INT), null, + new Id("B", LeafNode.TYPE.FLOAT), null + })); + pl.clear(); + pl.add(new Pair("A", "10")); + pl.add(new Pair("B", "20")); + pw.setParameter(pl); + assertTrue(node.evaluate()); + } + + // fct9 has two parameters (A,B) and dependency ((A > 10) And (B > 10.0)) + @Test + public void test_fct_9() throws ParseException, DependencyException { + dp.setFunctionId("fct_9"); + + pl = new ArrayList>(); + pw.setParameter(pl); + // generate tree + Node node = dp.generate(); + + pl.add(new Pair("A", "10")); + pl.add(new Pair("B", "10")); + pw.setParameter(pl); + assertFalse(node.evaluate()); + assertHashEquals(node.getMissingConstraints(), createHashfromArray(new Object[]{ + new Id("A", LeafNode.TYPE.INT), OpNode.Operations.GT, new Const(new Integer(10)), + new Id("B", LeafNode.TYPE.FLOAT), OpNode.Operations.GT, new Const(new Float(10)) + })); + pl.clear(); + pl.add(new Pair("A", "11")); + pl.add(new Pair("B", "11")); + pw.setParameter(pl); + + assertTrue(node.evaluate()); + } + + // fct10 has two parameters (A,B) and dependency ((A = 10) And (B = 10.0)) + @Test + public void test_fct_10() throws ParseException, DependencyException { + dp.setFunctionId("fct_10"); + + pl = new ArrayList>(); + pw.setParameter(pl); + // generate tree + Node node = dp.generate(); + + pl.add(new Pair("A", "11")); + pl.add(new Pair("B", "11")); + pw.setParameter(pl); + + assertFalse(node.evaluate()); + assertHashEquals(node.getMissingConstraints(), createHashfromArray(new Object[]{ + new Id("A", LeafNode.TYPE.INT), OpNode.Operations.EQ, new Const(new Integer(10)), + new Id("B", LeafNode.TYPE.FLOAT), OpNode.Operations.EQ, new Const(new Float(10)) + })); + + pl.clear(); + pl.add(new Pair("A", "10")); + pl.add(new Pair("B", "10")); + pw.setParameter(pl); + + assertTrue(node.evaluate()); + } + + // fct11 has two parameters (A,B) and dependency ((A < 10) And (B < 10.0)) + @Test + public void test_fct_11() throws ParseException, DependencyException { + dp.setFunctionId("fct_11"); + + pl = new ArrayList>(); + pw.setParameter(pl); + // generate tree + Node node = dp.generate(); + + pw.setParameter(pl); + pl.add(new Pair("A", "10")); + pl.add(new Pair("B", "10")); + pw.setParameter(pl); + + assertFalse(node.evaluate()); + assertHashEquals("Expected values [A<10, B<10], but got [" + node.getMissingConstraints().toString() + "]", node.getMissingConstraints(), createHashfromArray(new Object[]{ + new Id("A", LeafNode.TYPE.INT), OpNode.Operations.LT, new Const(new Integer(10)), + new Id("B", LeafNode.TYPE.FLOAT), OpNode.Operations.LT, new Const(new Float(10)) + })); + + pl.clear(); + pl.add(new Pair("A", "9")); + pl.add(new Pair("B", "9")); + pw.setParameter(pl); + + assertTrue(node.evaluate()); + } + + // fct9 has two parameters (A,B) and dependency ((A >= 10) And (B >= 10.0)) + @Test + public void test_fct_12() throws ParseException, DependencyException { + dp.setFunctionId("fct_12"); + + pl = new ArrayList>(); + pw.setParameter(pl); + // generate tree + Node node = dp.generate(); + + pl.clear(); + pl.add(new Pair("A", "9")); + pl.add(new Pair("B", "9")); + pw.setParameter(pl); + + assertFalse(node.evaluate()); + assertHashEquals(node.getMissingConstraints(), createHashfromArray(new Object[]{ + new Id("A", LeafNode.TYPE.INT), OpNode.Operations.GE, new Const(new Integer(10)), + new Id("B", LeafNode.TYPE.FLOAT), OpNode.Operations.GE, new Const(new Float(10)) + })); + + pl.clear(); + pl.add(new Pair("A", "10")); + pl.add(new Pair("B", "10")); + pw.setParameter(pl); + + assertTrue(node.evaluate()); + } + + // fct10 has two parameters (A,B) and dependency ((A != 10) And (B != 10.0)) + @Test + public void test_fct_13() throws ParseException, DependencyException { + dp.setFunctionId("fct_13"); + + pl = new ArrayList>(); + pw.setParameter(pl); + // generate tree + Node node = dp.generate(); + + pl.clear(); + pl.add(new Pair("A", "10")); + pl.add(new Pair("B", "10")); + pw.setParameter(pl); + + assertFalse(node.evaluate()); + assertHashEquals(node.getMissingConstraints(), createHashfromArray(new Object[]{ + new Id("A", LeafNode.TYPE.INT), OpNode.Operations.NE, new Const(new Integer(10)), + new Id("B", LeafNode.TYPE.FLOAT), OpNode.Operations.NE, new Const(new Float(10)) + })); + + pl.clear(); + pl.add(new Pair("A", "11")); + pl.add(new Pair("B", "11")); + pw.setParameter(pl); + + assertTrue(node.evaluate()); + } + + // fct11 has two parameters (A,B) and dependency ((A <= 10) And (B <= 10.0)) + @Test + public void test_fct_14() throws ParseException, DependencyException { + dp.setFunctionId("fct_14"); + + pl = new ArrayList>(); + pw.setParameter(pl); + // generate tree + Node node = dp.generate(); + + pl.clear(); + pl.add(new Pair("A", "11")); + pl.add(new Pair("B", "11")); + pw.setParameter(pl); + + assertFalse(node.evaluate()); + assertHashEquals(node.getMissingConstraints(), createHashfromArray(new Object[]{ + new Id("A", LeafNode.TYPE.INT), OpNode.Operations.LE, new Const(new Integer(10)), + new Id("B", LeafNode.TYPE.FLOAT), OpNode.Operations.LE, new Const(new Float(10)) + })); + + pl.clear(); + pl.add(new Pair("A", "10")); + pl.add(new Pair("B", "10")); + pw.setParameter(pl); + assertTrue(node.evaluate()); + } + + // fct11 has two parameters (A,B) and dependency ((A > B)) + @Test + public void test_fct_15() throws ParseException, DependencyException { + dp.setFunctionId("fct_15"); + + pl = new ArrayList>(); + pw.setParameter(pl); + // generate tree + Node node = dp.generate(); + + assertFalse(node.evaluate()); + assertHashEquals(node.getMissingConstraints(), createHashfromArray(new Object[]{new Id("A", LeafNode.TYPE.INT), null, new Id("B", LeafNode.TYPE.FLOAT), null})); + + pl.clear(); + pl.add(new Pair("A", "10")); + pl.add(new Pair("B", "10")); + pw.setParameter(pl); + + assertFalse(node.evaluate()); + assertHashEquals(node.getMissingConstraints(), createHashfromArray(new Object[]{new Id("A", LeafNode.TYPE.INT), OpNode.Operations.GT, new Id("B", LeafNode.TYPE.FLOAT)})); + + pl.clear(); + pl.add(new Pair("A", "11")); + pl.add(new Pair("B", "10")); + pw.setParameter(pl); + + assertTrue(node.evaluate()); + } + + // fct16 has two parameters (A,B) and dependency (A and (not (B > 10)) + @Test + public void test_fct_16() throws ParseException, DependencyException { + dp.setFunctionId("fct_16"); + + pl = new ArrayList>(); + pw.setParameter(pl); + // generate tree + Node node = dp.generate(); + + assertFalse(node.evaluate()); + assertHashEquals(node.getMissingConstraints(), createHashfromArray(new Object[]{new Id("A", LeafNode.TYPE.INT), null})); + + pl.clear(); + pl.add(new Pair("A", "10")); + pl.add(new Pair("B", "10")); + pw.setParameter(pl); + + assertTrue(node.evaluate()); + + pl.clear(); + pl.add(new Pair("A", "10")); + pl.add(new Pair("B", "11")); + pw.setParameter(pl); + + assertFalse(node.evaluate()); + assertHashEquals(node.getMissingConstraints(), createHashfromArray(new Object[]{new Id("B", LeafNode.TYPE.INT), OpNode.Operations.LE, new Const(new Integer(10))})); + } + + @Test + public void test_fct_17() throws ParseException, DependencyException { + dp.setFunctionId("fct_17"); + + pl = new ArrayList>(); + pw.setParameter(pl); + // generate tree + Node node = dp.generate(); + + pl.clear(); + pl.add(new Pair("A", "10")); + pl.add(new Pair("B", "10")); + pl.add(new Pair("C", "TRUE")); + pl.add(new Pair("D", "Hello World")); + pw.setParameter(pl); + + assertTrue(node.evaluate()); + + pl.clear(); + pl.add(new Pair("A", "10")); + pl.add(new Pair("B", "10")); + pl.add(new Pair("C", "FALSE")); + pw.setParameter(pl); + + assertFalse(node.evaluate()); + } + + @Test + public void test_fct_18() throws ParseException, DependencyException { + /* + * Test Funktion entspricht der Abhaengigkeitbeschreibung von dem Tool + * RNAhybrid. + */ + dp.setFunctionId("fct_18"); + + pl = new ArrayList(); + + pw.setParameter(pl); + + Node node = dp.generate(); + + System.err.println("cum. dep : " + NodeUtility.Node2String(node)); + + // no parameter set should return true + assertTrue(node.evaluate()); + + pl.clear(); + pl.add(new Pair("A", "10")); + pl.add(new Pair("B", "11")); + pw.setParameter(pl); + + // Parameter A,B : A < B should return true + assertTrue(node.evaluate()); + + } + + @Test + public void test_fct_19() throws ParseException, DependencyException { + /* + * Test Funktion entspricht der Abhaengigkeitbeschreibung von dem Tool + * RNAhybrid. + */ + dp.setFunctionId("fct_19"); + + pl = new ArrayList(); + pl.add(new Pair("C", "false")); + pw.setParameter(pl); + + Node node = dp.generate(); + + // no parameter set should return true + boolean result = node.evaluate(); + String missedConstraints = "none"; + if (!result) { + missedConstraints = ConstraintHashMaptoString(node.getMissingConstraints()); + } + assertTrue("Missed constraints:" + missedConstraints, result); + + pl.clear(); + pl.add(new Pair("C", "true")); + pw.setParameter(pl); + + result = node.evaluate(); + missedConstraints = "none"; + if (!result) { + missedConstraints = ConstraintHashMaptoString(node.getMissingConstraints()); + } + assertFalse("Missed constraints:" + missedConstraints, result); + + pl.clear(); + pl.add(new Pair("C", "true")); + pl.add(new Pair("A", "10")); + + pw.setParameter(pl); + + // should return true + assertTrue(node.evaluate()); + + } + + public static void assertListEquals(Collection result, Collection expected) { + assertListEquals("", result, expected); + + } + + public static void assertListEquals(String message, Collection result, Collection expected) { + + if (result == null && expected == null) { + return; + } + + if (result == null) { + fail("Result Set is null ! Expected " + expected.toString()); + } + + // if expected value is null it doesn't matter what the result contains ... + if (expected == null) { + return; + } + + if (result.size() != expected.size()) { + fail("Size of expected Set (" + expected.size() + ") differs from result Set (" + result.size() + ")."); + } + List a = new ArrayList(result); + Collections.sort(a); + + List b = new ArrayList(expected); + Collections.sort(b); + + for (int c = 0; c < a.size(); ++c) { + assertEquals("[" + a.get(c) + "] differs from [" + b.get(c) + "] " + message, a.get(c), b.get(c)); + + } + } + + public static void assertHashEquals(String message, ConstraintHashMap result, Collection expected) { + assertListEquals(message, result.keySet(), expected); + } + + public static void assertHashEquals(ConstraintHashMap result, ConstraintHashMap expected) { + assertHashEquals("", result, expected); + } + + public static void assertHashEquals(String message, ConstraintHashMap result, ConstraintHashMap expected) { + Set s_a = result.keySet(); + + Set s_b = expected.keySet(); + + if (s_a.size() != s_b.size()) { + fail("Number of expected keys (" + s_a.size() + ") differs from keys in result map (" + s_b.size() + ")."); + } + + for (Id id_a : s_a) { + if (!s_b.contains(id_a)) { + fail("Expected id (" + id_a + ") not found in result map!"); + } else { + assertListEquals(result.get(id_a), expected.get(id_a)); + } + } + + } + + public static ConstraintHashMap createHashfromArray(Object[] ts) { + ConstraintHashMap r = new ConstraintHashMap(); + + int s = 0; + Id id = null; + OpNode.Operations op = OpNode.Operations.NULL; + LeafNode ln = null; + for (Object t : ts) { + switch (s) { + case 0: { + id = (Id) t; + s = 1; + break; + } + case 1: { + if (t == null || t.equals(OpNode.Operations.NULL)) { + r.put(id, (List) null); + s = 0; + } else { + op = (OpNode.Operations) t; + s = 2; + } + break; + } + case 2: { + ln = (LeafNode) t; + r.put(id, new Constraints(op, ln)); + s = 0; + } + } + } + + return r; + } + + public static String ConstraintHashMaptoString(ConstraintHashMap map) { + StringBuilder sb = new StringBuilder(); + for (Id id : map.keySet()) { + System.err.println("."); + sb.append(id.getId()).append("[").append(id.getType()).append("]:"); + // cronstraints could be null if not defined + if (map.get(id) == null) { + sb.append("defined"); + } else { + for (Constraints c : map.get(id)) { + sb.append(c.toString()); + sb.append(","); + } + sb.setLength(sb.length() - 1); + } + } + return sb.toString(); + } +} diff --git a/libs/dependencyparser/src/test/java/de/unibi/techfak/bibiserv/util/dependencyparser/DependencyParserTest2.java b/libs/dependencyparser/src/test/java/de/unibi/techfak/bibiserv/util/dependencyparser/DependencyParserTest2.java new file mode 100644 index 0000000..9ea35c8 --- /dev/null +++ b/libs/dependencyparser/src/test/java/de/unibi/techfak/bibiserv/util/dependencyparser/DependencyParserTest2.java @@ -0,0 +1,70 @@ +/* +DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + +Copyright 2010 BiBiServ Curator Team, http://bibiserv.cebitec.uni-bielefeld.de, +All rights reserved. + +The contents of this file are subject to the terms of the Common +Development and Distribution License("CDDL") (the "License"). You +may not use this file except in compliance with the License. You can +obtain a copy of the License at http://www.sun.com/cddl/cddl.html + +See the License for the specific language governing permissions and +limitations under the License. When distributing the software, include +this License Header Notice in each file. If applicable, add the following +below the License Header, with the fields enclosed by brackets [] replaced +by your own identifying information: + +"Portions Copyrighted 2011 BiBiServ" + +Contributor(s): + */ +package de.unibi.techfak.bibiserv.util.dependencyparser; + +import de.unibi.techfak.bibiserv.util.Pair; +import de.unibi.techfak.bibiserv.util.dependencyparser.javacc.ParseException; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.util.List; +import java.util.ArrayList; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * JUnit Test class. Test generated Parser with broken dependency string + * @author jkrueger + */ +public class DependencyParserTest2 { + + private DependencyParser dp; + private ParameterWrapper pw; + private List> pl; + + public DependencyParserTest2() throws DependencyException, FileNotFoundException { + dp = new DependencyParser(); + dp.setTooldescription(new FileInputStream("src/test/xml/broken.xml")); + pw = new ParameterWrapper(); + dp.setParameterWrapper(pw); + } + + @BeforeClass + public static void setUpClass() throws Exception { + } + + @AfterClass + public static void tearDownClass() throws Exception { + } + + // fct1 has three parameters (A,B,C) and dependency (A & B & C) + @Test + public void test_fct_1() throws ParseException, DependencyException { + dp.setFunctionId("fct_1"); + pl = new ArrayList>(); + pw.setParameter(pl); + // generate tree + Node node = dp.generate(); + assertFalse(node.evaluate()); + } +} diff --git a/libs/dependencyparser/src/test/xml/broken.xml b/libs/dependencyparser/src/test/xml/broken.xml new file mode 100644 index 0000000..580d189 --- /dev/null +++ b/libs/dependencyparser/src/test/xml/broken.xml @@ -0,0 +1,93 @@ + + + Example 1 + Example 1 describing some parameters and its dependencies between them + This is one of the example description describing some parameters and its dependencies between them + + + + Jan + Krueger + CeBiTeC + jkrueger@cebitec.uni-bielefeld.de + +49 521 106 2494 + + + Jan + Krueger + CeBiTeC + jkrueger@cebitec.uni-bielefeld.de + +49 521 106 2494 + + + + + + binary + /bin/echo + + + + Output + + + String + STDOUT + + + + A + A :: int + parameter A :: int + int + + + + B + B :: float + parameter B :: float + float + + + + + + DepFun1 + dependency for function 1 + Dependency description for function 1. + and(def(@A),and(def(@B),def(@C))) + + + + + + + function1 + function 1 with dependency 1 (A and B and C) + + + + + + + + + + A + B + + + + + + + + + + + + + + diff --git a/libs/dependencyparser/src/test/xml/sample.xml b/libs/dependencyparser/src/test/xml/sample.xml new file mode 100644 index 0000000..a983c7b --- /dev/null +++ b/libs/dependencyparser/src/test/xml/sample.xml @@ -0,0 +1,550 @@ + + + Example 1 + Example 1 describing some parameters and its dependencies between them + This is one of the example description describing some parameters and its dependencies between them + + + + Jan + Krueger + CeBiTeC + jkrueger@cebitec.uni-bielefeld.de + +49 521 106 2494 + + + Jan + Krueger + CeBiTeC + jkrueger@cebitec.uni-bielefeld.de + +49 521 106 2494 + + + + + + binary + /bin/echo + + + + Output + + + String + STDOUT + + + + A + A :: int + parameter A :: int + int + + + + B + B :: float + parameter B :: float + float + + + + C + C :: boolean + parameter C :: boolean + boolean + + + + D + D :: string + parameter D :: string + string + + + + E + E :: int + parameter e :: int + int + + + + + DepFun1 + dependency for function 1 + Dependency description for function 1. + and(def(@A),and(def(@B),def(@C))) + + + DepFun2 + dependency for function 2 + Dependency description for function 2. + or(def(@A),or(def(@B),def(@C))) + + + DepFun3 + dependency for function 3 + Dependency description for function 3. + or(and(def(@A),def(@B)),def(@C)) + + + DepFun4 + dependency for function 4 + Dependency description for function 4. + or(and(def(@A),def(@B)),or(def(@E),and(def(@C),def(@D)))) + + + DepFun5 + dependency for function 5 + Dependency description for function 5. + and(def(@A),not(def(@B))) + + + DepFun6 + dependency for function 6 + Dependency description for function 6. + impl(def(@A),def(@B)) + + + DepFun7 + dependency for function 7 + Dependency description for function 7. + impl(ge(@A,10),def(@B)) + + + DepFun8 + dependency for function 8 + Dependency description for function 8. + logeq(def(@A),def(@B)) + + + DepFun9 + dependency for function 9 + Dependency description for function 9. + and(gt(@A,10),gt(@B,10.0)) + + + DepFun10 + dependency for function 10 + Dependency description for function 10. + and(eq(@A,10),eq(@B,10.0)) + + + DepFun11 + dependency for function 11 + Dependency description for function 11. + and(lt(@A,10),lt(@B,10.0)) + + + DepFun12 + dependency for function 9 + Dependency description for function 9. + and(ge(@A,10),ge(@B,10.0)) + + + DepFun13 + dependency for function 10 + Dependency description for function 10. + and(ne(@A,10),ne(@B,10.0)) + + + DepFun14 + dependency for function 11 + Dependency description for function 11. + and(le(@A,10),le(@B,10.0)) + + + DepFun15 + dependency for function 15 + Dependency description for function 15. + gt(@A,@B) + + + DepFun16 + dependency for function 16 + Dependency description for function 16. + and(def(@A),not(gt(@B,10))) + + + + DepFun17a + 1st dependency for function 17 + 1st Dependency description for function 17. + and(def(@A),def(@B)) + + + + DepFun17b + 2nd dependency for function 17 + 2nd Dependency description for function 17. + and(def(@C),def(@D)) + + + + + CwithA + wenn C dann muss A definiert sein + wenn C dann muss A definiert sein + or(not(def(@C)),and(def(@C),def(@A))) + + + + DNOTA + wenn D dann darf A nicht definiert sein + wenn D dann darf A nicht definiert sein + or(not(def(@D)),and(def(@D),not(def(@A)))) + + + + AwithB_BwithA_AleB + wenn A dann muss B definiert sein (und umgekehrt) und A muss kleiner gleich B sein + wenn A dann muss B definiert sein (und umgekehrt) und A muss kleiner gleich B sein + or(not(or(def(@A),def(@B))),le(@A,@B)) + + + + + boolean test + wenn C wahr ist muss A definiert sein + wenn C wahr ist muss A definiert sein + or(eq(@C,'false'),and(eq(@C,'true'),def(@A))) + + + + + function1 + function 1 with dependency 1 (A and B and C) + + + + + + + + + + A + B + C + + + + + function2 + function 2 with dependency 2 (A or B or C) + + + + + + + + + + A + B + C + + + + + function3 + function 3 with dependency 3 ((A and B) or C) + + + + + + + + + + A + B + C + + + + + function3 + function 4 with dependency 4 ((A and B) or (C and D) or E) + + + + + + + + + + + + A + B + C + D + E + + + + + function5 + function 5 with dependency 5 (A and (not B)) + + + + + + + + + A + B + + + + + function6 + function 6 with dependency 6 (A -> B) + + + + + + + + + A + B + + + + + function7 + function 7 with dependency 7 ((A==10) -> B) + + + + + + + + + A + B + + + + + function8 + function 8 with dependency 8 (A <-> B) + + + + + + + + + A + B + + + + + function9 + function 9 with dependency 9 ((@A > 10) and (@B > 10.0)) + + + + + + + + + A + B + + + + + function10 + function 10 with dependency 10 ((@A == 10) and (@B == 10.0)) + + + + + + + + + A + B + + + + + function11 + function 11 with dependency 11 ((@A < 10) and (@B < 10.0)) + + + + + + + + + A + B + + + + + function12 + function 12 with dependency 12 ((@A => 10) and (@B => 10.0)) + + + + + + + + + A + B + + + + + function13 + function 13 with dependency 13 ((@A != 10) and (@B != 10.0)) + + + + + + + + + A + B + + + + + function14 + function 14 with dependency 14 ((@A <= 10) and (@B <= 10.0)) + + + + + + + + + A + B + + + + + function15 + function 15 with dependency 15 (@A >@B) + + + + + + + + + A + B + + + + function16 + function 16 with dependency 16 (A and ( not (@A > 10))) + + + + + + + + + A + B + + + + + function17 + function 17 with dependency 17a and 17b + + + + + + + + + + + + A + B + C + D + + + + + + function 18 + entspricht im wesentlichen RNAhybrid + + + + + + + + + + + + + A + B + C + D + + + + + + function 19 + tested den Typen boolean + + + + + + + + C + + + + + + + + + + diff --git a/libs/ontoaccess/pom.xml b/libs/ontoaccess/pom.xml index 525c373..daf16a1 100644 --- a/libs/ontoaccess/pom.xml +++ b/libs/ontoaccess/pom.xml @@ -34,13 +34,13 @@ org.apache.jena jena-core - 2.10.1 + 2.7.1 com.github.ansell.pellet pellet-jena - 2.3.6-ansell + 2.3.2 diff --git a/libs/pom.xml b/libs/pom.xml index 7f5aa0e..687b56f 100644 --- a/libs/pom.xml +++ b/libs/pom.xml @@ -16,6 +16,7 @@ validator viewer bibiservsearch + dependencyparser Libs diff --git a/pom.xml b/pom.xml index 343b86e..1ce23a3 100644 --- a/pom.xml +++ b/pom.xml @@ -1,5 +1,7 @@ - + 4.0.0 de.unibi.cebitec.bibiserv bibiserv @@ -19,9 +21,10 @@ - schemas - libs bibimainapp + libs + tools + schemas UTF-8 diff --git a/schemas/bibiservabstraction/src/main/xsd/BiBiServAbstraction.xsd b/schemas/bibiservabstraction/src/main/xsd/BiBiServAbstraction.xsd index 272cefb..ea5d33f 100644 --- a/schemas/bibiservabstraction/src/main/xsd/BiBiServAbstraction.xsd +++ b/schemas/bibiservabstraction/src/main/xsd/BiBiServAbstraction.xsd @@ -139,15 +139,15 @@ - + - Order all elements lexographical, wether they are + Order all elements lexicographical, wether they are category or itemRef elements - + - Order all elements lexographical, first all categories second all itemRefs + Order all elements lexicographical, first all categories second all itemRefs @@ -481,15 +481,23 @@ to be sufficient to call the executable resource. - + - Optional DEPRECATED tag: The 'executableType' element specified which - kind of supported executable type was described here. + Optional tag: The 'executableType' element specified which + kind of supported executable type was described here. Could be used by implemting call class + - + + + Optional tag: The 'image' element specifies [docker] image container used + for execution. + + + + - The 'path' element contains the + Optional tag: The 'path' element contains the filesystem path of an executable file. This has to be given in order for the server to be able to call the external executable program. diff --git a/tools/DeployTools/build.xml b/tools/DeployTools/build.xml new file mode 100644 index 0000000..d9c2263 --- /dev/null +++ b/tools/DeployTools/build.xml @@ -0,0 +1,209 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Loading Ivy Settings from BiBiServ ... + + + + BiBiserv not available, load Ivy settings from ${user.home}/ivy-rep/ivy-settings.xml or if this file does not exist load default settings file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tools/DeployTools/ivy.xml b/tools/DeployTools/ivy.xml new file mode 100644 index 0000000..eab4060 --- /dev/null +++ b/tools/DeployTools/ivy.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tools/DeployTools/pom.xml b/tools/DeployTools/pom.xml new file mode 100644 index 0000000..627603f --- /dev/null +++ b/tools/DeployTools/pom.xml @@ -0,0 +1,68 @@ + + + 4.0.0 + de.unibi.cebitec.bibiserv + deploytools + stable.release + jar + DeployTools + + + + snapshot-repository.java.net + Java.net Snapshot Repository for Maven + https://maven.java.net/content/repositories/snapshots/ + default + + + jitpack.io + https://jitpack.io + + + + + + + junit + junit + 4.12 + test + + + + org.apache.ant + ant + 1.9.0 + compile + + + + ${project.groupId} + bibiservabstraction + 1.0 + + + + ${project.groupId} + ontoaccess + 0.9 + + + + ${project.groupId} + bibitools + 2.0 + + + + + + + UTF-8 + 1.8 + 1.8 + + + diff --git a/tools/DeployTools/src/main/java/de/unibi/techfak/bibiserv/deploy/tools/AbstractVerifyTask.java b/tools/DeployTools/src/main/java/de/unibi/techfak/bibiserv/deploy/tools/AbstractVerifyTask.java new file mode 100644 index 0000000..f84df8d --- /dev/null +++ b/tools/DeployTools/src/main/java/de/unibi/techfak/bibiserv/deploy/tools/AbstractVerifyTask.java @@ -0,0 +1,117 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2010 BiBiServ Curator Team, http://bibiserv.cebitec.uni-bielefeld.de, + * All rights reserved. + * + * The contents of this file are subject to the terms of the Common + * Development and Distribution License("CDDL") (the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at http://www.sun.com/cddl/cddl.html + * + * See the License for the specific language governing permissions and + * limitations under the License. When distributing the software, include + * this License Header Notice in each file. If applicable, add the following + * below the License Header, with the fields enclosed by brackets [] replaced + * by your own identifying information: + * + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + */ +package de.unibi.techfak.bibiserv.deploy.tools; + +import de.unibi.techfak.bibiserv.cms.TrunnableItem; +import java.io.File; +import java.io.IOException; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Marshaller; +import javax.xml.bind.Unmarshaller; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Task; +import org.w3c.dom.Document; + +/** + * AbstractVerfifyTask is an abstraced class used as base for all implementing + * classes. + * + * This class extends the ant Task class. + * + * + * @author Jan Krueger - jkrueger(at)techfak.uni-bielefeld.de + */ +public abstract class AbstractVerifyTask extends Task { + + private File runnableitemfile; + private TrunnableItem runnableitem; + private JAXBElement jaxbe; + + @Override + public void execute() throws BuildException { + if (getRunnableitemfile() == null) { + throw new BuildException("Attribute runnableitemfile is mandatory!"); + } + } + + /** + * Set Tooldescription (=runnableitem) file. Function load file and create a + * corresponding JAXB object. + * + * + * @param file + * @throws JAXBException, if file can't be marshalled to a JAXB object + * @throws IOException if file doesn't ecists or can't be read + */ + public void setRunnableitemfile(File file) throws JAXBException, IOException { + runnableitemfile = file; + if (!runnableitemfile.isFile() || !runnableitemfile.canRead()) { + throw new IOException("File " + runnableitemfile.toString() + " can't read!"); + } + JAXBContext ctx = JAXBContext.newInstance(de.unibi.techfak.bibiserv.cms.TrunnableItem.class); + Unmarshaller um = ctx.createUnmarshaller(); + jaxbe = (JAXBElement) um.unmarshal(file); + runnableitem = jaxbe.getValue(); + } + + /** + * Get tooldescription (=runnableitem) file. + * + * @return Return tooldesription file + */ + public File getRunnableitemfile() { + return runnableitemfile; + } + + /** + * Get tooldescription (JAXB) object + * + * @return Return tooldescription object. + */ + public TrunnableItem getRunnableitem() { + return runnableitem; + } + + /** + * Return W3C DOM document representatiopn from tooldescription. + * + * @return Return W3C DOM document representation from tooldescription. + * @throws JAXBException, if JAXB object can't be marshalled to DOM document + * @throws ParserConfigurationException, if + */ + public Document getRunnableitemAsDocument() throws JAXBException, ParserConfigurationException { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setNamespaceAware(true); + Document document = dbf.newDocumentBuilder().newDocument(); + + JAXBContext ctx = JAXBContext.newInstance(de.unibi.techfak.bibiserv.cms.TrunnableItem.class); + Marshaller m = ctx.createMarshaller(); + m.marshal(jaxbe, document); + + return document; + } +} diff --git a/tools/DeployTools/src/main/java/de/unibi/techfak/bibiserv/deploy/tools/VerifyDownload.java b/tools/DeployTools/src/main/java/de/unibi/techfak/bibiserv/deploy/tools/VerifyDownload.java new file mode 100644 index 0000000..5fd892f --- /dev/null +++ b/tools/DeployTools/src/main/java/de/unibi/techfak/bibiserv/deploy/tools/VerifyDownload.java @@ -0,0 +1,266 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2010 BiBiServ Curator Team, http://bibiserv.cebitec.uni-bielefeld.de, + * All rights reserved. + * + * The contents of this file are subject to the terms of the Common + * Development and Distribution License("CDDL") (the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at http://www.sun.com/cddl/cddl.html + * + * See the License for the specific language governing permissions and + * limitations under the License. When distributing the software, include + * this License Header Notice in each file. If applicable, add the following + * below the License Header, with the fields enclosed by brackets [] replaced + * by your own identifying information: + * + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + */ +package de.unibi.techfak.bibiserv.deploy.tools; + + +import de.unibi.techfak.bibiserv.cms.Tfile; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import javax.xml.bind.JAXBException; +import org.apache.tools.ant.BuildException; + +/** + * VerifyDownload is small tool class that compares file within a directory + * and described by the download within the tool description. + * + * This class extends the ant Task class and overwrites its execute class. + * + * + * @author Jan Krueger - jkrueger(at)techfak.uni-bielefeld.de + */ +public class VerifyDownload extends AbstractVerifyTask { + + + List download_xml_list = new ArrayList(); + List download_dir_list = new ArrayList(); + private File downloaddir; + + + + /** + * Default Constructor + */ + public VerifyDownload() { + } + + /** + * Constructor of class. + * + * @param runnableitemfile + * @param downloaddir + * @throws IOException in the case the runnableitem file or download dir doesn't exist or can't be read + * + */ + public VerifyDownload(File runnableitemfile, File downloaddir) throws IOException, JAXBException { + setRunnableitemfile(runnableitemfile); + setDownloaddir(downloaddir); + } + + @Override + public void execute() throws BuildException { + super.execute(); + + if (downloaddir == null) { + throw new BuildException("Attribute downloaddir is mandatory!"); + } + + + // if (downloaddir.exists() && !downloaddir.isDirectory() && !downloaddir.canRead()) { + + try { + initialize(); + } catch (JAXBException e){ + throw new BuildException(e); + } + + List resultlist = new ArrayList(); + if (compareEntries(download_xml_list, download_dir_list, resultlist)){ + System.out.println("Found "+printList(resultlist)+" download elements!"); + } else { + if (download_xml_list.size() > 0) { + throw new BuildException("The tooldescription contains downloadable " + + "items ("+printList(download_xml_list)+") which are NOT " + + "available in the resource directory '"+downloaddir+"' !"); + } else if (download_dir_list.size() > 0) { + throw new BuildException("The resource directory '"+downloaddir+"' " + + "contains items ("+printList(download_dir_list)+") which " + + "are NOT described in the tool description!"); + } else { + throw new BuildException("Should never occure ...."); + } + } + + + } + + /** + * Initize object using init() method. Method fill the both FileNameList with + * content. + * + * @throws JAXBException in the case RunnableItemFile can't be parsed into an JAXB class. + */ + public void initialize() throws JAXBException { + getDownloadableEntries(download_xml_list); + + if (downloaddir.exists() && downloaddir.isDirectory() && downloaddir.canRead()) { + getDirEntries(downloaddir, download_dir_list); + } + } + + public File getDownloaddir() { + return downloaddir; + } + + public void setDownloaddir(File downloaddir) throws IOException{ + /* get all entries within download dir */ + this.downloaddir = downloaddir; + + + } + + + + /** + * Function compareEntries compares two lists (list1 and list2) and return + * true if both lists are equal, false otherwise. Attention! Elements that + * occurrs in both list are removed from it and append to the result list. + * + * @param list1 - list containing strings + * @param list2 - list containing strings + * @param list3 - an empty, but initalized list + * + * @return + */ + public static boolean compareEntries(List list1, List list2, List list3) { + int counter = 0; + while (counter < list1.size()) { + String elem = list1.get(counter); + if (list2.contains(elem)) { + // remove from both lists ... + list1.remove(elem); + list2.remove(elem); + // ... and add to result list + list3.add(elem); + } else { + counter++; + } + } + if (list1.isEmpty() && list2.isEmpty()) { + return true; + } + return false; + } + + + + /** + * Static Function getDownloadableEntries determins all downloadable (filename) + * and pack them into a list. + * + + * @param list - append all found Downloadable filenames to list + */ + public void getDownloadableEntries(List list) throws BuildException { + List lod = getRunnableitem().getDownloadable(); + for (Tfile d : lod) { + if (d.isSetFilename()) { //local resource + list.add(d.getFilename()); + } else { // must be an external resource + + // check url + try { + URL url = new URL(d.getUrl()); + URLConnection connection = url.openConnection(); + connection.connect(); + InputStream in = connection.getInputStream(); + } catch (MalformedURLException e) { + throw new BuildException("Malformed URL : '"+d.getUrl()+"'"); + + } catch (IOException e){ + throw new BuildException("IOException while open connection to '"+d.getUrl()+ "': "+e.getMessage()); + } + + + } + } + } + + /** + * Function getDirEntries determins a list of files within a given + * directory. Subdirectories are also considered. + * + * + * @param file - Directory to be searched + * @param list - List all found files + */ + public static void getDirEntries(File file, List list) { + getDirEntries(file, file.toString().length() > 0 ? file.toString() + "/" : "", list); + } + + /** + * Private Helper function used by fct getDirEntries for recursion steps ... + * + * @param file + * @param prefix + * @param list + */ + private static void getDirEntries(File file, String prefix, List list) { + if (file.isFile()) { + String fn = file.toString().substring(prefix.length()); + list.add(fn); + } else if (file.isDirectory()) { + File[] file_list = file.listFiles(); + for (File f : file_list) { + getDirEntries(f, prefix, list); + } + } + } + + + + /** + * Helper function, returns all elements of list as String + * + * @param l + * @return + */ + public static String printList(List l) { + return printList(l,false); + } + + + public static String printList(List l, boolean br) { + String s = null; + StringBuilder sb = new StringBuilder(); + Iterator i = l.iterator(); + while (i.hasNext()) { + s = i.next(); + sb.append(s); + if (i.hasNext()) { + if (br) { + sb.append("\n"); + } else { + sb.append(","); + } + } + } + return sb.toString(); + } +} diff --git a/tools/DeployTools/src/main/java/de/unibi/techfak/bibiserv/deploy/tools/VerifyFunction.java b/tools/DeployTools/src/main/java/de/unibi/techfak/bibiserv/deploy/tools/VerifyFunction.java new file mode 100644 index 0000000..8141dc9 --- /dev/null +++ b/tools/DeployTools/src/main/java/de/unibi/techfak/bibiserv/deploy/tools/VerifyFunction.java @@ -0,0 +1,226 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2010 BiBiServ Curator Team, http://bibiserv.cebitec.uni-bielefeld.de, + * All rights reserved. + * + * The contents of this file are subject to the terms of the Common + * Development and Distribution License("CDDL") (the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at http://www.sun.com/cddl/cddl.html + * + * See the License for the specific language governing permissions and + * limitations under the License. When distributing the software, include + * this License Header Notice in each file. If applicable, add the following + * below the License Header, with the fields enclosed by brackets [] replaced + * by your own identifying information: + * + * "Portions Copyrighted 2010 BiBiServ Curator Team, http://bibiserv.cebitec.uni-bielefeld.de" + * + * Contributor(s): + * + */ +package de.unibi.techfak.bibiserv.deploy.tools; + +import de.unibi.techfak.bibiserv.cms.TenumParam; +import de.unibi.techfak.bibiserv.cms.Texample; +import de.unibi.techfak.bibiserv.cms.Texample.Prop; +import de.unibi.techfak.bibiserv.cms.Tfunction; +import de.unibi.techfak.bibiserv.cms.Tfunction.Inputref; +import de.unibi.techfak.bibiserv.cms.TinputOutput; +import de.unibi.techfak.bibiserv.cms.Tparam; +import de.unibi.techfak.bibiserv.cms.TparamGroup; +import java.util.ArrayList; +import java.util.List; +import javax.xml.bind.JAXBElement; +import org.apache.tools.ant.BuildException; + +/** + * VerifyFucntion is small tool class that check if every param, input and ouput + * is referenced by the inputAndOutputOrder. + * + * This class extends the ant Task class and overwrites its execute class. + * + * + * @author Jan Krueger - jkrueger(at)techfak.uni-bielefeld.de + */ +public class VerifyFunction extends AbstractVerifyTask { + + @Override + public void execute() throws BuildException { + super.execute(); + if (getRunnableitem().isSetExecutable()) { + + // for all functions ... + for (Tfunction tf : getRunnableitem().getExecutable().getFunction()) { + System.out.println("Found function :" + tf.getId()); + List> paramAndInputOutputOrderList = tf.getParamAndInputOutputOrder().getReferenceOrAdditionalString(); + List paramAndInputOutputOrderidList = new ArrayList(); + for (JAXBElement jaxbe : paramAndInputOutputOrderList) { + if (jaxbe.getValue() instanceof TinputOutput) { + paramAndInputOutputOrderidList.add(((TinputOutput) jaxbe.getValue()).getId()); + } else if (jaxbe.getValue() instanceof Tparam) { + paramAndInputOutputOrderidList.add(((Tparam) jaxbe.getValue()).getId()); + } else if (jaxbe.getValue() instanceof TenumParam) { + paramAndInputOutputOrderidList.add(((TenumParam) jaxbe.getValue()).getId()); + } else { + System.out.println("ignore unsupported type :" + jaxbe.getValue().getClass().getName()); + } + } + List paramAndInputOutputReferenceIdList = getInputOutputIdList(tf.getId()); + try { + paramAndInputOutputReferenceIdList.addAll(getParamIdList(tf.getId())); + } catch (Exception e) { + throw new BuildException(e); + } + + // check if example(s) exists and all refid are valid and all values are valid + for (Texample te : tf.getExample()) { + for (Prop p : te.getProp()) { + if (!paramAndInputOutputOrderidList.contains(p.getIdref())) { + throw new BuildException("The example tag named '"+te.getName()+"' of function '"+tf.getId()+"' has an unknown reference '"+p.getIdref()+"'!"); + } + } + } + + if(!VerifyDownload.compareEntries(paramAndInputOutputOrderidList, paramAndInputOutputReferenceIdList, new ArrayList())){ + if (!paramAndInputOutputOrderidList.isEmpty()) { + throw new BuildException("The ParamAndInputOutputOrder tag of function '"+tf.getId()+" contains refId(s) ["+VerifyDownload.printList(paramAndInputOutputOrderidList)+"] which are not part of this function!"); + } else { + throw new BuildException("The ParamAndInputOutputOrder tag of function '"+tf.getId()+" misses refId(s) ["+VerifyDownload.printList(paramAndInputOutputReferenceIdList)+"] !"); + } + } + System.out.println(" -> References seems to be ok!"); + + + } + } else { + System.out.println("No Executable found ..."); + } + } + + public List getInputIdList(String function_id) { + List list = new ArrayList(); + for (TinputOutput input : getInputList(function_id)) { + list.add(input.getId()); + } + return list; + } + + /** + * Return a list of input(s) used/referenced by given function id. + * + * @param function_id + * @return Return a list of inputs + */ + public List getInputList(String function_id) { + List list = new ArrayList(); + for (Inputref ref : getFunction(function_id).getInputref()) { + list.add((TinputOutput) ref.getRef()); + } + return list; + } + + public String getOutputId(String function_id) { + return getOutput(function_id).getId(); + } + + /** Return an output used/referenced by given function id/ + * + * @param function_id + * @return return output + */ + public TinputOutput getOutput(String function_id) { + return (TinputOutput) (getFunction(function_id).getOutputref().getRef()); + } + + public List getInputOutputIdList(String function_id) { + List list = getInputIdList(function_id); + list.add(getOutputId(function_id)); + return list; + } + + /** + * Return a list of input(s) and ouput used/referenced by given function id. + * + * @param function_id + * @return + */ + public List getInputOutputList(String function_id) { + List list = getInputList(function_id); + list.add(getOutput(function_id)); + return list; + } + + /** + * Return a list of parameterIds used/referenced by given function id. + * + * @param function_id + * @return Return a list of parameterIds. + */ + public List getParamList(String function_id) throws Exception { + List list = new ArrayList(); + if (getFunction(function_id).isSetParamGroup()) { + buildParamList(getFunction(function_id).getParamGroup(), list); + } + + return list; + } + + /** + * Return a list of parameterIds used/referenced by given function id. + * + * @param function_id + * @return Return a list of parameterIds. + */ + public List getParamIdList(String function_id) throws Exception { + List list = new ArrayList(); + for (Object o : getParamList(function_id)) { + if (o instanceof Tparam) { + list.add(((Tparam)o).getId()); + } else { + list.add(((TenumParam)o).getId()); + } + } + return list; + } + + /** + * Private helper method, search recursvily for parameter + * + * @param c an object of type Tparam or TparamGroup + * @param l + * @throws Exception if an unknown object + */ + private void buildParamList(Object c, List l) throws Exception { + if (c instanceof Tparam || c instanceof TenumParam ) { + l.add( c); + } else if (c instanceof TparamGroup) { + TparamGroup tpg = (TparamGroup) c; + for (Object o : tpg.getParamrefOrParamGroupref()) { + if (o instanceof TparamGroup.Paramref) { + buildParamList(((TparamGroup.Paramref) o).getRef(), l); + } else { + buildParamList(((TparamGroup.ParamGroupref) o).getRef(), l); + } + } + } else { + throw new Exception("Unkown object of type '" + c.getClass().getName() + "'. Aborting!"); + } + } + + /** + * Return the function with given id (if exists) + * + * @param function_id + * @return + */ + public Tfunction getFunction(String function_id) { + for (Tfunction tf : getRunnableitem().getExecutable().getFunction()) { + if (tf.isSetId() && tf.getId().equals(function_id)) { + return tf; + } + } + return null; + } +} diff --git a/tools/DeployTools/src/main/java/de/unibi/techfak/bibiserv/deploy/tools/VerifyImage.java b/tools/DeployTools/src/main/java/de/unibi/techfak/bibiserv/deploy/tools/VerifyImage.java new file mode 100644 index 0000000..c691e4f --- /dev/null +++ b/tools/DeployTools/src/main/java/de/unibi/techfak/bibiserv/deploy/tools/VerifyImage.java @@ -0,0 +1,62 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2010-2012 BiBiServ Curator Team, http://bibiserv.cebitec.uni-bielefeld.de, + * All rights reserved. + * + * The contents of this file are subject to the terms of the Common + * Development and Distribution License("CDDL") (the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at http://www.sun.com/cddl/cddl.html + * + * See the License for the specific language governing permissions and + * limitations under the License. When distributing the software, include + * this License Header Notice in each file. If applicable, add the following + * below the License Header, with the fields enclosed by brackets [] replaced + * by your own identifying information: + * + * "Portions Copyrighted 2010-2012 BiBiServ Curator Team" + * + * Contributor(s): Jan Krueger + * + */ +package de.unibi.techfak.bibiserv.deploy.tools; + +import java.io.File; + +/** + * + * Deprecated class. Only for compatibility reason for generated tools before than 03/07/2012. + * + * Class is replaced by VerifyLinks. + * + * @author Jan Krueger - jkrueger(at)cebitec.uni-bielefeld.de + */ +@Deprecated +public class VerifyImage extends VerifyLinks { + + @Deprecated + public void setImagedir(String imagedir) { + super.setResourcedir(imagedir); + } + + @Deprecated + public void setImageDir(String imagedir) { + super.setResourcedir(imagedir); + } + + @Deprecated + public void setImagedir(File imagedir) { + super.setResourcedir(imagedir); + } + + @Deprecated + public void setImageDir(File imagedir) { + super.setResourcedir(imagedir); + } + + @Deprecated + public void setIgnorePattern(String pattern) { + ignore_list.add(new Ignore(pattern)); + } +} diff --git a/tools/DeployTools/src/main/java/de/unibi/techfak/bibiserv/deploy/tools/VerifyLinks.java b/tools/DeployTools/src/main/java/de/unibi/techfak/bibiserv/deploy/tools/VerifyLinks.java new file mode 100644 index 0000000..9a2b2f4 --- /dev/null +++ b/tools/DeployTools/src/main/java/de/unibi/techfak/bibiserv/deploy/tools/VerifyLinks.java @@ -0,0 +1,395 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2010-2012 BiBiServ Curator Team, http://bibiserv.cebitec.uni-bielefeld.de, + * All rights reserved. + * + * The contents of this file are subject to the terms of the Common + * Development and Distribution License("CDDL") (the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at http://www.sun.com/cddl/cddl.html + * + * See the License for the specific language governing permissions and + * limitations under the License. When distributing the software, include + * this License Header Notice in each file. If applicable, add the following + * below the License Header, with the fields enclosed by brackets [] replaced + * by your own identifying information: + * + * "Portions Copyrighted 2010-2012 BiBiServ Curator Team" + * + * Contributor(s): Jan Krueger + * + */ +package de.unibi.techfak.bibiserv.deploy.tools; + +import de.unibi.techfak.bibiserv.xml.NamespaceContext; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.OutputStream; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.List; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.Result; +import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpression; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Task; +import org.w3c.dom.Attr; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +/** + * VerifyImage is small tool class that compares all href/src links from the + * tool description with + * + * + * This class extends the ant Task class and overwrites its execute class. + * + * + * @author Jan Krueger - jkrueger(at)techfak.uni-bielefeld.de + */ +public class VerifyLinks extends AbstractVerifyTask { + + List node_list = new ArrayList(); + List resource_dir_list = new ArrayList(); + List ignore_list = new ArrayList(); + private File resourcedir; + private File out; + + /** + * Default Constructor + */ + public VerifyLinks() { + } + + public VerifyLinks(File runnableitemfile, File resourcedir) throws Exception { + setRunnableitemfile(runnableitemfile); + setResourcedir(resourcedir); + + } + + @Override + public void execute() throws BuildException { + + super.execute(); + + + // add ignore elements from nested ignore elements + if (ignore_list != null && !ignore_list.isEmpty()) { + System.out.println("Ignore list : "); + for (Ignore i : ignore_list){ + System.out.print( i + " "); + } + System.out.println(""); + } + + // check if image dir is set , a directory and readable + if (resourcedir == null || !resourcedir.isDirectory() || !resourcedir.canRead()) { + throw new BuildException("ImageDir '" + resourcedir + "' must be set, a directory and readable!"); + } + // get all file entries + VerifyDownload.getDirEntries(resourcedir, resource_dir_list); + + Document runnableitem; + try { + runnableitem = getRunnableitemAsDocument(); + } catch (Exception e) { + throw new BuildException("An Exception occurred while converting a JAXB representation to W3C DOM document." + e.getMessage()); + } + + + + // get all image entries + try { + node_list = VerifyLinks.getImagesEntries(runnableitem, ignore_list); + System.out.println("Found images (XML): " + list2list(node_list)); + } catch (XPathExpressionException e) { + throw new BuildException(e); + } + + List result_list = new ArrayList(); + List image_xml_list = list2list(node_list); + if (!compareEntries(image_xml_list, resource_dir_list, result_list)) { + image_xml_list.removeAll(result_list); + throw new BuildException("Entr(y|ies) (" + VerifyDownload.printList(image_xml_list) + ") missed in resource dir (" + resourcedir + ")!"); + } + + if (out == null) { + System.out.println("Attribute 'out' not set, don't modify " + getRunnableitemfile() + " !"); + } else { + addPrefix(node_list, "applications/" + ((Attr) (runnableitem.getDocumentElement().getAttributes().getNamedItem("id"))).getValue() + "/resources/"); + try { + NodetoStream(runnableitem, new FileOutputStream(out)); + } catch (FileNotFoundException e) { + throw new BuildException(e); + } + System.out.println("Update runnableitem entries ..."); + } + } + + + + public final void setResourcedir(String resourcedir){ + this.resourcedir = new File(resourcedir); + } + + + public final void setResourcedir(File resourcedir) { + this.resourcedir =resourcedir; + } + + public void setIgnorepattern(String pattern) { + ignore_list.add(new Ignore(pattern)); + } + + + + + + public void setOut(File out) { + this.out = out; + } + + public void setOut(String out) { + this.out = new File(out); + } + + public List getImagesDirList() { + return resource_dir_list; + } + + /** + * Return a list of nodes (DOM) describing an image source (AttributeNode). + * + * @param runnableitem - Tooldescriptiion to be searched. + * @return Return a list of nodes (DOM) + * @throws XPathExpressionException + */ + public static List getImagesEntries(Document runnableitem) throws XPathExpressionException { + return getImagesEntries(runnableitem, null); + } + + /** + * Return a list of nodes (DOM) describing an image source (AttributeNodes) + * and not matching a pattern from the ingnorelist. + * + * @param runnableitem - Tooldescriptiion to be searched. + * @param ignorelist - List of regexp pattern + * @return Return a list of nodes (DOM) + * @throws XPathExpressionException + */ + public static List getImagesEntries(Document runnableitem, List ignorelist) throws XPathExpressionException { + + + XPathFactory xpathfactory = XPathFactory.newInstance(); + XPath xpath = xpathfactory.newXPath(); + NamespaceContext nsc = new NamespaceContext(); + + /** + * Set Namespaces + */ + nsc.addNamespace("http://www.w3.org/XML/1998/namespace", "xml"); + nsc.addNamespace("bibiserv:de.unibi.techfak.bibiserv.cms.microhtml", "microhtml"); + nsc.addNamespace("bibiserv:de.unibi.techfak.bibiserv.cms.minihtml", "minihtml"); + nsc.addNamespace("bibiserv:de.unibi.techfak.bibiserv.cms", "cms"); + + + xpath.setNamespaceContext(nsc); + XPathExpression expr_src = xpath.compile("//*/@src"); //images + XPathExpression expr_href = xpath.compile("//*/@href"); // all other href + + + //minihtml + List nodelist = nodelist2list((NodeList) expr_src.evaluate(runnableitem, XPathConstants.NODESET)); + //microhtml + nodelist.addAll(nodelist2list((NodeList) expr_href.evaluate(runnableitem, XPathConstants.NODESET))); + + // if ignorelist is empty then we are finished and return the nodelist + if ((ignorelist == null) || ignorelist.isEmpty()) { + return nodelist; + } + + // otherwise if have to check each node against the pattern from the ignorelist + + List resultlist = new ArrayList(); + + for (Node n : nodelist) { + boolean t = true; + for (Ignore ignore : ignorelist) { + + if (n.getTextContent().matches(ignore.getRegexp())) { + t = false; + break; + } + + + } + if (t) { + resultlist.add(n); + } + } + + return resultlist; + } + + /** + * Take care that all list elements (Strings) from entries_from_xml are + * contained in entries_from_dir, but not vice versa. All found elements in + * stored in the resultlist. + * + * + * @param entries_from_xml + * @param entries_from_dir + * @param resultlist - EMPTY! list + * @return + */ + public static boolean compareEntries(List entries_from_xml, List entries_from_dir, List resultlist) { + for (String entry_xml : entries_from_xml) { + if (inList(entries_from_dir, entry_xml)) { + resultlist.add(entry_xml); + } + } + return entries_from_xml.containsAll(resultlist) && entries_from_xml.size() == resultlist.size(); + } + + private static boolean inList(List l, String s) { + for (String e : l) { + if (s.equals(e)) { + return true; + } + } + return false; + } + + /** + * Add a prefix for each node of the nodelist. + * + * @param nl + * @param prefix + */ + public static void addPrefix(List nl, String prefix) { + for (Node n : nl) { + n.setTextContent(prefix + n.getTextContent()); + } + } + + public static void NodetoStream(Node node, OutputStream out) { + try { + Source source = new DOMSource(node); + + Result result = new StreamResult(out); + TransformerFactory factory = TransformerFactory.newInstance(); + Transformer transformer = factory.newTransformer(); + transformer.transform(source, result); + + } catch (TransformerConfigurationException e) { + e.printStackTrace(); + } catch (TransformerException e) { + e.printStackTrace(); + } + } + + public static String NodeToString(Node node) { + try { + Source source = new DOMSource(node); + StringWriter stringWriter = new StringWriter(); + Result result = new StreamResult(stringWriter); + TransformerFactory factory = TransformerFactory.newInstance(); + Transformer transformer = factory.newTransformer(); + transformer.transform(source, result); + return stringWriter.getBuffer().toString(); + } catch (TransformerConfigurationException e) { + e.printStackTrace(); + } catch (TransformerException e) { + e.printStackTrace(); + } + return null; + } + + /** + * private helper method, convert a unmodifyable nodelist (DOM) to a List of + * Nodes. \ + * + * @param nl - nodelist (DOM) + * @return Return a list of nodes + */ + private static List nodelist2list(NodeList nl) { + List tmp = new ArrayList(); + for (int i = 0; i < nl.getLength(); ++i) { + tmp.add(nl.item(i)); + } + return tmp; + } + + /** + * private Helper method . Converts a list of Nodes to a list of Strings + * (Node textcontent) + * + * @param nl + * @return + */ + public static List list2list(List nl) { + List r = new ArrayList(); + for (Node n : nl) { + r.add(n.getTextContent()); + } + return r; + } + + + /** + * Own static inner class for nested ignore elements + */ + public static class Ignore { + + private String regexp; + + public Ignore(){ + + } + + public Ignore(String regexp){ + this.regexp = regexp; + } + + public void setRegexp(String rexexp) { + this.regexp = rexexp; + } + + public String getRegexp() { + return regexp; + } + + @Override + public String toString() { + return regexp; + } + + + + } + + + + public Ignore createIgnore(){ + Ignore ignore = new Ignore(); + ignore_list.add(ignore); + return ignore; + + } +} diff --git a/tools/DeployTools/src/main/java/de/unibi/techfak/bibiserv/deploy/tools/VerifyReferences.java b/tools/DeployTools/src/main/java/de/unibi/techfak/bibiserv/deploy/tools/VerifyReferences.java new file mode 100644 index 0000000..b9f921a --- /dev/null +++ b/tools/DeployTools/src/main/java/de/unibi/techfak/bibiserv/deploy/tools/VerifyReferences.java @@ -0,0 +1,82 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2010 BiBiServ Curator Team, http://bibiserv.cebitec.uni-bielefeld.de, + * All rights reserved. + * + * The contents of this file are subject to the terms of the Common + * Development and Distribution License("CDDL") (the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at http://www.sun.com/cddl/cddl.html + * + * See the License for the specific language governing permissions and + * limitations under the License. When distributing the software, include + * this License Header Notice in each file. If applicable, add the following + * below the License Header, with the fields enclosed by brackets [] replaced + * by your own identifying information: + * + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + */ +package de.unibi.techfak.bibiserv.deploy.tools; + +import de.unibi.cebitec.bibiserv.util.bibtexparser.BibtexParser; +import de.unibi.cebitec.bibiserv.util.bibtexparser.ParseException; +import de.unibi.techfak.bibiserv.util.ontoaccess.bibiontotypes.BiBiPublication; +import java.io.File; +import java.io.StringReader; +import java.util.ArrayList; +import java.util.List; + +import org.apache.tools.ant.BuildException; + +/** + * + * @author jkrueger + */ +public class VerifyReferences extends AbstractVerifyTask { + + public VerifyReferences() { + } + + public VerifyReferences(File file) { + try { + setRunnableitemfile(file); + } catch (Exception ex) { + throw new BuildException(ex); + } + } + + + + @Override + public void execute() throws BuildException { + super.execute(); + + + //extract all references from runnableitem + + if (getRunnableitem().isSetReferences() && getRunnableitem().getReferences().isSetReference()) { + + + + List retlist = new ArrayList<>(); + StringBuilder refbuf = new StringBuilder(); + for (String string : getRunnableitem().getReferences().getReference()) { + refbuf.append(string); + refbuf.append("\n"); + } + BibtexParser parser = new BibtexParser(new StringReader(refbuf.toString())); + try { + parser.parse(); + retlist = parser.getPublicationObjects(); + } catch (ParseException ex) { + System.err.println("Given String could not be parsed as bibreference. Error was:\n" + ex.getLocalizedMessage()); + throw new BuildException(ex); + } + } + + } +} \ No newline at end of file diff --git a/tools/DeployTools/src/test/java/de/unibi/techfak/bibiserv/deploy/tools/VerifyDownloadTest.java b/tools/DeployTools/src/test/java/de/unibi/techfak/bibiserv/deploy/tools/VerifyDownloadTest.java new file mode 100644 index 0000000..918cd11 --- /dev/null +++ b/tools/DeployTools/src/test/java/de/unibi/techfak/bibiserv/deploy/tools/VerifyDownloadTest.java @@ -0,0 +1,155 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2010-2016 BiBiServ Curator Team, http://bibiserv.cebitec.uni-bielefeld.de, + * All rights reserved. + * + * The contents of this file are subject to the terms of the Common + * Development and Distribution License("CDDL") (the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at http://www.sun.com/cddl/cddl.html + * + * See the License for the specific language governing permissions and + * limitations under the License. When distributing the software, include + * this License Header Notice in each file. If applicable, add the following + * below the License Header, with the fields enclosed by brackets [] replaced + * by your own identifying information: + * + * "Portions Copyrighted 2016 BiBiServ" + * + * Contributor(s): Jan Krüger + * + */ +package de.unibi.techfak.bibiserv.deploy.tools; + +import java.util.Iterator; +import java.util.ArrayList; +import java.util.List; +import java.io.File; +import java.io.IOException; +import javax.xml.bind.JAXBException; +import org.apache.tools.ant.BuildException; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * Class providing test methods for VerifyDownload Class. + * + * + * @author Jan Krueger - jkrueger(at)cebitec.uni-bielefeld.de + */ +public class VerifyDownloadTest { + + VerifyDownload vd; + File runnableitem = new File("src/test/resources/paramtesttool.bs2"); + File downloaddir = new File("src/test/resources/resources/downloads"); + +// File runnableitem = new File("/vol/bibi/share/bibiserv2_central/jkrueger/apps/guugle_20120207135611/config/runnableitem.xml"); +// File downloaddir = new File("/vol/bibi/share/bibiserv2_central/jkrueger/apps/guugle_20120207135611/resources/downloads"); + + public VerifyDownloadTest() { + try { + vd = new VerifyDownload(runnableitem, downloaddir); + vd.initialize(); + } catch (IOException e) { + fail(e.getMessage()); + } catch (JAXBException e) { + fail(e.getMessage()); + } + } + + @BeforeClass + public static void setUpClass() throws Exception { + } + + @AfterClass + public static void tearDownClass() throws Exception { + } + + @Test + public void testDirEntries() { + List resultlist = new ArrayList(); + VerifyDownload.getDirEntries(downloaddir, resultlist); + // list should contain three entries + + List expected_resultlist = new ArrayList(); + expected_resultlist.add("file1.txt"); + expected_resultlist.add("file2.txt"); + expected_resultlist.add("subdir/file3.txt"); + + + if (!resultlist.containsAll(expected_resultlist)) { + fail("resultlist (" + VerifyDownload.printList(resultlist) + ") isn't equal to expected result list (" + VerifyDownload.printList(expected_resultlist)); + } + + } + + @Test + public void testDownloadEntries() { + List resultlist = new ArrayList(); + vd.getDownloadableEntries(resultlist); + + List expected_resultlist = new ArrayList(); + expected_resultlist.add("file1.txt"); + + if (!resultlist.containsAll(expected_resultlist)) { + fail("resultlist (" + VerifyDownload.printList(resultlist) + ") isn't equal to expected result list (" + VerifyDownload.printList(expected_resultlist)); + } + + } + + @Test + public void testCompareEntries() { + List list1 = new ArrayList(); + List list2 = new ArrayList(); + List resultlist = new ArrayList(); + + VerifyDownload.getDirEntries(downloaddir, list1); + vd.getDownloadableEntries(list2); + + System.out.println("list 1 ::"+VerifyDownload.printList(list1)); + System.out.println("list 2 ::"+VerifyDownload.printList(list2)); + + // compareEntries should return false + if (VerifyDownload.compareEntries(list1, list2, resultlist)) { + fail("Since list1 and list2 aren't equal, compareEntries should return false!"); + } + + // list1 should contain two elements + if (list1.size() != 2) { + fail("List1 should contain two list elements, but contains (" + VerifyDownload.printList(list1) + ")"); + } + + // list2 should be empty + if (!list2.isEmpty()) { + fail("List2 should be empty, but contains (" + VerifyDownload.printList(list2) + ")"); + } + + // resultlist shoudl could contain one elment ("file1.txt") + if (resultlist.size() != 1 && !resultlist.get(0).equals("file1.txt")) { + fail("Expected one element named \"file1.txt\" in resultlist, got " + resultlist.size() + " element(s) containing " + VerifyDownload.printList(resultlist)); + } + + + + + } + + @Test + public void testExecute() { + vd = new VerifyDownload(); + try { + vd.setDownloaddir(downloaddir); + vd.setRunnableitemfile(runnableitem); + vd.execute(); + } catch (IOException e) { + fail(e.getMessage()); + } catch (JAXBException e) { + fail(e.getMessage()); + } catch (BuildException e) { + System.out.println(e.getMessage()); + } + } +} diff --git a/tools/DeployTools/src/test/java/de/unibi/techfak/bibiserv/deploy/tools/VerifyLinksTest.java b/tools/DeployTools/src/test/java/de/unibi/techfak/bibiserv/deploy/tools/VerifyLinksTest.java new file mode 100644 index 0000000..3d02f01 --- /dev/null +++ b/tools/DeployTools/src/test/java/de/unibi/techfak/bibiserv/deploy/tools/VerifyLinksTest.java @@ -0,0 +1,191 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2010-2016 BiBiServ Curator Team, http://bibiserv.cebitec.uni-bielefeld.de, + * All rights reserved. + * + * The contents of this file are subject to the terms of the Common + * Development and Distribution License("CDDL") (the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at http://www.sun.com/cddl/cddl.html + * + * See the License for the specific language governing permissions and + * limitations under the License. When distributing the software, include + * this License Header Notice in each file. If applicable, add the following + * below the License Header, with the fields enclosed by brackets [] replaced + * by your own identifying information: + * + * "Portions Copyrighted 2016 BiBiServ" + * + * Contributor(s): Jan Krüger + * + */ +package de.unibi.techfak.bibiserv.deploy.tools; + +import de.unibi.techfak.bibiserv.deploy.tools.VerifyLinks.Ignore; +import org.w3c.dom.Document; +import org.w3c.dom.Attr; +import org.w3c.dom.Node; +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.w3c.dom.NamedNodeMap; +import static org.junit.Assert.*; + +/** + * Class providing tests for validating links. + * + * + * @author @author Jan Krueger - jkrueger(at)cebitec.uni-bielefeld.de + */ +public class VerifyLinksTest { + + VerifyLinks vi; + final static File runnableitem = new File("src/test/resources/paramtesttool.bs2"); + final static File resourcedir = new File("src/test/resources/resources"); + final static List ignorelist = Arrays.asList(new Ignore("http.*"),new Ignore("/.*"), new Ignore("#.*$") ); + + public VerifyLinksTest() { + try { + vi = new VerifyLinks(runnableitem, resourcedir); + } catch (Exception e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } + + @BeforeClass + public static void setUpClass() throws Exception { + } + + @AfterClass + public static void tearDownClass() throws Exception { + } + + @Test + public void testGetImagesEntries_without_ignorelist() { + try { + System.out.println("test getImagesEntries(doc)"); + + List result_1 = VerifyLinks.list2list(VerifyLinks.getImagesEntries(vi.getRunnableitemAsDocument())); + List expected_result_1 = Arrays.asList( + "images/parameter_block.png", + "images/parameter_block.png", + "images/The_Earth_seen_from_Apollo_17.jpg", + "http://en.wikipedia.org/wiki/ICEfaces", + "http://de.wikipedia.org/wiki/ICEfaces", + "/cg-cat?viewType=manual", + "/cg-cat?viewType=references", + "http://java.sun.com/products/javawebstart/download.jsp", + "http://java.sun.com/javase/6/webnotes/6u11.html#rootcertificates-1.6.0_11", + "http://mailhide.recaptcha.net/d?k=01SmXl276guo9S44_bhjUwPA==&c=K12sZO1-T7B5Py34tWDH9eiSTcMzz6gz6z5BdAF9MCMK6wRoGjVn801PpJHHfeT6", + "http://www.gnu.org/licenses/gpl-3.0-standalone.html", + "http://mailhide.recaptcha.net/d?k=01SmXl276guo9S44_bhjUwPA==&c=K12sZO1-T7B5Py34tWDH9eiSTcMzz6gz6z5BdAF9MCMK6wRoGjVn801PpJHHfeT6", + "/cgi-bin/treecat_start", + "webstart/treecat_splash64px.gif", + "webstart/treecat_splash64px.gif", + "http://java.sun.com/products/autodl/j2se", + "webstart/cg-cat.jar", + "http://bibiserv.cebitec.uni-bielefeld.de", + "#test", + "/rnamovies?viewType=references", + "example/test.fas"); + + if (!expected_result_1.containsAll(result_1)) { + fail("resultlist \n(" + VerifyDownload.printList(result_1) + ")\n isn't equal to expected result list \n(" + VerifyDownload.printList(expected_result_1) + ")"); + } + } catch (Exception ex) { + ex.printStackTrace(); + fail(ex.getMessage()); + } + } + + @Test + public void testGetImagesEntries_with_ignorelist() throws Exception { + System.out.println("test getImagesEntries(dox,ignorelist)"); + + + + + List result_2 = VerifyLinks.list2list(VerifyLinks.getImagesEntries(vi.getRunnableitemAsDocument(), ignorelist)); + List expected_result_2 = Arrays.asList( + "images/parameter_block.png", + "images/parameter_block.png", + "images/The_Earth_seen_from_Apollo_17.jpg", + "webstart/treecat_splash64px.gif", + "webstart/treecat_splash64px.gif", + "webstart/cg-cat.jar", + "example/test.fas"); + + + + if (!expected_result_2.containsAll(result_2)) { + fail("resultlist (" + VerifyDownload.printList(result_2) + ") isn't equal to expected result list (" + VerifyDownload.printList(expected_result_2) + ")"); + } + + + } + + @Test + public void testCompareEntries() throws Exception { + System.out.println("test compareEntries() [with ignorelist]"); + List result_3a = VerifyLinks.list2list(VerifyLinks.getImagesEntries(vi.getRunnableitemAsDocument(), ignorelist)); + List result_3b = new ArrayList<>(); + VerifyDownload.getDirEntries(resourcedir, result_3b); + List result_3c = new ArrayList<>(); + + if (!VerifyLinks.compareEntries(result_3a, result_3b, result_3c)) { + + + + System.out.println("a:" + VerifyDownload.printList(result_3a)); + System.out.println("b:" + VerifyDownload.printList(result_3b)); + System.out.println("c:" + VerifyDownload.printList(result_3c)); + + result_3a.removeAll(result_3c); + fail("Entr(y|ies) " + VerifyDownload.printList(result_3a) + " missed in download dir!"); + } + + + + + + + } + + @Test + public void testReplace() throws Exception { + System.out.println("testReplace()"); + + Document doc = vi.getRunnableitemAsDocument(); + + NamedNodeMap nnm = doc.getDocumentElement().getAttributes(); + Node n = nnm.getNamedItem("id"); + String id = ((Attr) n).getValue(); + + + List result_4 = VerifyLinks.getImagesEntries(doc,ignorelist); + VerifyLinks.addPrefix(result_4, "applications/" + id + "/"); + + System.out.println(VerifyLinks.NodeToString(doc)); + + } + + + @Test + public void testRegExp(){ + String pattern = "http.*"; + + String text1 = "http://bibiserv"; + String text2 = "/http/bibiserv"; + + assertTrue(text1.matches(pattern)); + + assertFalse(text2.matches(pattern)); + + } +} diff --git a/tools/DeployTools/src/test/java/de/unibi/techfak/bibiserv/deploy/tools/VerifyReferencesTest.java b/tools/DeployTools/src/test/java/de/unibi/techfak/bibiserv/deploy/tools/VerifyReferencesTest.java new file mode 100644 index 0000000..5ac06c0 --- /dev/null +++ b/tools/DeployTools/src/test/java/de/unibi/techfak/bibiserv/deploy/tools/VerifyReferencesTest.java @@ -0,0 +1,100 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2010-2016 BiBiServ Curator Team, http://bibiserv.cebitec.uni-bielefeld.de, + * All rights reserved. + * + * The contents of this file are subject to the terms of the Common + * Development and Distribution License("CDDL") (the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at http://www.sun.com/cddl/cddl.html + * + * See the License for the specific language governing permissions and + * limitations under the License. When distributing the software, include + * this License Header Notice in each file. If applicable, add the following + * below the License Header, with the fields enclosed by brackets [] replaced + * by your own identifying information: + * + * "Portions Copyrighted 2016 BiBiServ" + * + * Contributor(s): Jan Krüger + * + */ +package de.unibi.techfak.bibiserv.deploy.tools; + +import java.io.File; +import org.apache.tools.ant.BuildException; +import org.junit.*; +import static org.junit.Assert.*; + +/** + * + * @author Jan Krueger - jkrueger(at)cebitec.uni-bielefeld.de + */ +public class VerifyReferencesTest { + + VerifyReferences vr; + final static File runnableitemOk = new File("src/test/resources/rnamovies.bs2"); + final static File runnableitemFail = new File("src/test/resources/ceged.bs2"); + + public VerifyReferencesTest() { + + } + + @BeforeClass + public static void setUpClass() throws Exception { + } + + @AfterClass + public static void tearDownClass() throws Exception { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of execute method, of class VerifyReferences. + */ + @Test + public void testExecute() { + + // should be ok + try { + vr = new VerifyReferences(runnableitemOk); + + } catch (BuildException e) { + e.printStackTrace(); + fail(e.getMessage()); + } + + try { + vr.execute(); + } catch (BuildException e) { + e.printStackTrace(); + fail(e.getMessage()); + } + + // should be failed + try { + vr = new VerifyReferences(runnableitemFail); + + } catch (BuildException e) { + e.printStackTrace(); + fail(e.getMessage()); + } + + try { + vr.execute(); + fail("Broken reference are ok ???"); + } catch (BuildException e) { + e.printStackTrace(); + + } + + } +} diff --git a/tools/DeployTools/src/test/resources/ceged.bs2 b/tools/DeployTools/src/test/resources/ceged.bs2 new file mode 100644 index 0000000..089f346 --- /dev/null +++ b/tools/DeployTools/src/test/resources/ceged.bs2 @@ -0,0 +1,175 @@ + + + CEGeD + Calculate Evolutionary Genome Distances + + CEGeD (Calculate Evolutionary Genome Distances) computes the Inversion distance, + the Translocation distance and the Double-Cut-and-Join distance of genomes. The genome + data can be read from files or typed in manually in the program. The comparisons are + shown as text and as graphic, and can be saved to files. CEGeD is an extension of the + DCJ tool. + The Double-Cut-and-Join operation was first introduced by Yancopoulos et al. + [YAN:ATT:FRI:2005]. + A simpler treatment and a more concise model, presented in [BEG:MIX:STO:2006], is + implemented in our CEGeD tool. + + Calculate Evolutionary Genome Distances + Evolutionary Genome Distances + + Rafael + Friesen + Bielefeld university, CeBiTec, IFB, GI + rfriesen@cebitec.uni-bielefeld.de + + + Julia + Mixtacki + unknown + + + Jens + Stoye + Bielefeld university, CeBiTeC, IFB, GI + stoye@techfak.uni-bielefeld.de + + + BiBiServ + administrators + Bielefeld university, CeBiTeC, IFB, BiBiServ + bibiadm@cebitec.uni-bielefeld.de + + + + @article{BEG:MIX:STO:2006, author={A. Bergeron and J. Mixtacki and J. Stoye}, + title={A unifying view of genome rearrangements.}, year=2006, journal={Proceedings of + WABI 2006}, doi={10.1007/11851561} } + + @article{YAN:ATT:FRI:2005, author={S. Yancopoulos and O. Attie and R. Friedberg}, + title={Efficient sorting of genomic permutations by translocation, inversion and block + interchange}, year=2005, journal={Bioinformatics}, doi={10.1093/bioinformatics/bti535} + + + + + + + + + Webstart + CEGeD uses Java WebStart facilities to allow full-featured applications + to be launched with just a single-click of a mouse. At least Java 1.5 or newer is needed + to run CEGeD. + + + CEGeD online version is based on Java + WebStart version 1.0.1 or higher. + If you do not have a Java Runtime Environment version 1.5.0 or higher + installed, or if you are working on Solaris/Linux and never previously used Java + WebStart, please follow these installation + instructions. + The file size of the CEGeD program is about 48 KBytes. + + + + + CEGeD + Rafael Friesen + CEGeD - Calculate Evolutionary Genome Distances + + + + + + + + + + + + + + + Genome Representation + + Every file can contain several genomes. + Every genome starts with a name line: > followed by the genome + name. + In the following line(s) come the genes separated by + whitespaces. + Each chromosome is concluded by ) or |. A ) concludes a circular + chromosome, a | concludes a linear chromosome. + The gene names can contain all signs except whitespaces. A minus (-) + before a gene name means that the gene direction is backwards. + Every line that starts with // has no function and is a comment-line. + Everything before the first genome is a comment, too. + Example for a Genome: + + + Genome1 a c -d | b e ) f g | + + + + + + + + A simple example file can be found here. A more complex example file that shows more possibilities + (comments and more) can be found here. + DCJ Sorting The program computes DCJ - distance and an optimal + sorting scenario. DCJ Sorting example: + + + a c -d | b e ) f g | a g | b e ) d -c -f | + a g ) b e ) d -c -f | a b e g ) d -c -f | d -b -a + -g -e -c -f | c f ) d -b -a -g -e | a e g ) b -d | + c f ) + + + + + DCJ-operations in the example: Translocation + Closure Fusion of two circular chromosomes Fusion of + linear and circular chromosome Fission with closure + Fission with closure + + For more explanation how the DCJ operations are defined look at . Program Usage - Step By + Step + + To load genomes from file click on Load Genomes and choose one or more + files that contains at least one genome. + If you want to compare example genomes click on Example + Genomes. + If you want to open a genome editor to type in genomes manually click on + Editor, then + Type in the genomes in the editor window + Click on Add to add the typed genomes to the genome list of + CEGeD + To remove genomes from that list you can also use the editor + window: choose a genome and click on Remove. + + + Choose the genomes to compare in the lists in the main window + By pressing the Button Run the genomes will be compared + The results are shown in the tabs. The top tab row is for choosing the + comparison method. The second tab row is for switching between graphic result + and text result. + After running a comparison you can save the results by first opening the + Save Results window and then choosing which results should be saved by clicking + on the corresponding Buttons. Graphic results will be saved as PNG + graphics. + All values can be cleared with the Clear button. + + + + + + \ No newline at end of file diff --git a/tools/DeployTools/src/test/resources/paramtesttool.bs2 b/tools/DeployTools/src/test/resources/paramtesttool.bs2 new file mode 100644 index 0000000..8ea571d --- /dev/null +++ b/tools/DeployTools/src/test/resources/paramtesttool.bs2 @@ -0,0 +1,617 @@ + + + ParameterTestTool + ParameterTestWerkzeug + This is a tool for testing all parameter possibilities + Dieses Werkzeug dient ausschließlich dem Test aller Parameter Möglichkeiten, die + derzeit von dem BiBiServ2 Framework unterstützt werden. + This a testing tool. It's only purpose is to test all parameter combinations with different types and views, which are + supported by the BiBiServ2 framework. + Dieses Werkzeug ist ein Testtool. Es dient ausschliesslich dem Test aller Parameter Kombinationen und deren Darstellung im Browser. + Aus bioinformatischer Sicht macht das Werkzeug dementsprechend keine Sinn. + + + + Jan + Krüger + BiBiServ - CeBiTec - Bielefeld University + jkrueger@cebitec.uni-bielefeld.de + + + Joe + User + Faculty of Dummy Users - Bielefeld University + + + + + BiBiServ + Mitarbeiter + bibi-help@cebitec.uni-bielefeld.de + + This is sample text inside a custom conten field. The text make absolutly no sense, beside filling the field with content. + + ICEfaces is an open source Ajax framework that enables Java EE application developers to create and deploy server-based rich Internet application + (RIA) using the Java language. ICEfaces leverages the entire standards-based Java EE ecosystem of tools and execution environments. Rich enterprise + application features are developed in pure Java, and in a pure thin-client model. There are no Applets or proprietary browser plug-ins required. + ICEfaces applications are JavaServer Faces (JSF) applications, so Java EE application development skills apply directly and Java developers are + isolated from doing any JavaScript related development. (text copied from wikipedia). + + + + + ICEfaces ist ein auf JavaServer Faces (JSF) basierendes Ajax-Framework für Java, welches durch ICEsoft entwickelt wird. Seit November 2006 steht + das Projekt neben einer kommerziellen Lizenz auch unter der Mozilla Public License (MPL) zur Verfügung. + ICEfaces verfügt über eine umfangreiche Bibliothek an Komponenten für die Benutzerschnittstelle mit eingebauter Ajax-Funktionalität. Dazu gehören + beispielsweise Bäume, Tabs und Menüs. Diese Komponenten können in einer standardkonformen JSF-Seite verwendet werden. Im Gegensatz zu den üblichen + Komponenten einer Webseite können diese jedoch über Ajax mit dem Webcontainer kommunizieren und bei Bedarf Daten nachladen ohne dass die gesamte + Webseite neu geladen wird. Der Entwickler muss sich dabei nicht um die Details dieser Kommunikation kümmern, da diese im Hintergrund transparent + abläuft. Mit ICEfaces lassen sich so Rich Internet Application (RIA) entwickeln, ohne JavaScript programmieren zu müssen. Der schlussendlich im + Browser ausgeführte JavaScript-Code wird durch das Framework zur Laufzeit generiert. (Text von WikiPedia + kopiert). + + + + 1.0 + + binary + + echo + + + echo + Returns an echo of parameter inputs + Gibt die übergebenen Parameter als "echo" zurück. + The output is tool specific. All input parameter values are returned like + an echo. + Die Rückgabe ist Werkzeug spezifisch. Alle an das Werkzeug übergebenen Parameter werden als Liste zurückgeben. + ToolDependentRepresentation + STDOUT + + + + boolean + boolean test parameter + This a boolean test parameter using the SELECTBOOLEANCHECKBOX. + boolean + -boolean + SELECTBOOLEANCHECKBOX + + + boolean(2) + boolean test parameter (2) + This a boolean test parameter using the INPUTTEXT. + boolean + -boolean2 + INPUTTEXT + + + int + int test parameter + int test parameter with gui element inputtext. + int + -int + INPUTTEXT + + + int_min_max_default + int min max test parameter + int min max test parameter with gui element inputtext. + int + -int_max_min_default + 50 + 0 + 100 + INPUTTEXT + + + float + float test parameter + Float test parameter with gui element inputext. + float + -float + + INPUTTEXT + + + float_max_min_default + float test parameter with default value and min / max constraints + float test parameter with default value and min / max constraints and GUI +element INPUTTEXT. + float + -float_min_max + 99.9 + 90.5 + 99.99 + INPUTTEXT + + + string + string test parameter + string test parameter with gui element inputtext. + string + -string + INPUTTEXT + + + string_regexp + string test parameter with regexp constraint + string test parameter with regexp constraint and gui element inputtext. + string + -string_regexp + \d{0,5}\s.+ + INPUTTEXT + + + string_min_max + string test parameter with min / max length restrictions + string test parameter with min / max length restrictions and gui element inputext. + string + 10 + 100 + INPUTTEXT + + + string_regexp_default + string test parameter with regexp restriction and default value + string test parameter with regexp restriction and default value and gui +element textarea. + string + -string_regexp_default + ACGU + [ACGU]* + INPUTTEXTAREA + + + Enum SelectOneRadio + Enumaration test parameter. Choose one country selecting a radio button. + Enumeration test parameter using GUI element SELECTONERADIO. Choose one country selecting a radio button. + string + -lang_sor + + DE + DE + German + Deutsch + + + US + US + United States of America + Vereinigte Staaten von Amerika + + + SE + SE + Sweden + Schweden + + + NL + NL + Netherland + Holland + + SELECTONERADIO + + + Enum SelectOneListBox + Enumaration test parameter. Choose one country from the list box. + Enumeration test parameter using GUI element SELECTONELISTBOX. Choose one country from the list box. + string + -lang_sol + + DE + DE + German + Deutsch + + + US + US + United States of America + Vereinigte Staaten von Amerika + + + SE + SE + Sweden + Schweden + + + NL + NL + Netherland + Holland + + SELECTONELISTBOX + + + Enum SelectOneMenu + Enumaration test parameter. Choose one country from the menu. + Enumeration test parameter using GUI element SELECTONEMENU. Choose one country from the menu. + string + -lang_som + + DE + DE + German + Deutsch + + + US + US + United States of America + Vereinigte Staaten von Amerika + + + SE + SE + Sweden + Schweden + + + NL + NL + Netherland + Holland + + SELECTONEMENU + + + Enum SelectManyListBox + Enumaration test parameter. Choose one or more countries from the list box. + Enumeration test parameter using GUI element SELECTMANYLISTBOX. Choose one or more countries from the list box. + string + -lang_sml + + DE + DE + German + Deutsch + + + US + US + United States of America + Vereinigte Staaten von Amerika + + + SE + SE + Sweden + Schweden + + + NL + NL + Netherland + Holland + + SELECTMANYLISTBOX + + + Enum SelectManyMenu + Enumaration test parameter. Choose one or more countries from the menu. + Enumeration test parameter using GUI element SELECTMANYMENU. Choose one or more countries from the menu. + string + -lang_smm + + DE + DE + German + Deutsch + + + US + US + United States of America + Vereinigte Staaten von Amerika + + + SE + SE + Sweden + Schweden + + + NL + NL + Netherland + Holland + + SELECTMANYMENU + + + Enum SelectManyCheckBox + Enumeration test parameter. Select one or more countries from the checkboxes. + Enumeration test parameter using GUI element SELECTMANYCHECKBOX. Select one or more countries from the checkboxes. + string + -lang_smc + + DE + DE + German + Deutsch + + + US + US + United States of America + Vereinigte Staaten von Amerika + + + SE + SE + Sweden + Schweden + + + NL + NL + Netherland + Holland + + SELECTMANYCHECKBOX + + + all normal + Parameter group containing all "normal" parameters. + + + + + + + + + + + + + + all enum + Parameter group containing all "enumeration" parameters. + + + + + + + + + + + + Param Test Function + Function using a combination of all 'normal' parameter. All parameter values are returned as result. + + The ParameterTestTool function Param Test Function is a simple echo function to test and explain all supported parameters. For simplicity this function hasn't + any input value. The BiBiServ2 CodeGen package currently support the following parameter: + + boolean - checkbox/inputbox + int - inputbox with a default value and a restriction to a minimum/maximum value. + float - inputbox with a default value and a restriction to a minimum/maximum value. + string - inputbox with a restriction to a regular expression or to a minimum/maximum string length. + + Currently only two(three) different views are supported. CheckBox for boolean based parameter and Inputbox + for all parameters independent of their type. + InputBoxes can be a single line textfield or textarea (latter makes only sense for string based parameters). + Each parameter is described by a so called parameter block element. + + A parameter block consists of a parameter name (1), a parameter help action (2), which shows/hides the parameter help (3) + containing the parameter short description and all constraints/restrictions to this parameters, the parameter view itsself (4) + and an message block (5), which appears when validate the entered content. + + + Die ParameterTestWerkzeug Funktion Param Test Funktion ist eine Echo Funktion, um alle unterstützten parameter + darzustellen und zu testen. Um das Ganze möglichst einfach zu gestalten hat diese Funktion keine Eingabe Argumente. Das BiBiServ2 CodeGen + Paket unterstützt derzeit die folgenden Parameter : + + + boolean - checkbox/inputbox + int - inputbox with a default value and a restriction to a minimum/maximum value. + float - inputbox with a default value and a restriction to a minimum/maximum value. + string - inputbox with a restriction to a regular expression or to a minimum/maximum string length. + + + Derzeit werden nur zwei (bzw. drei) verschiedenen Ansichten unterstützt. CheckBoxen für Wahrheitswerte und Eingabefelder für + alle Parameter unabhängig von Ihrem Typ. Eingabefelder können ein- oder mehrzeilig sein. Jeder Parameter wird in der + xhtml (faces) Datei durch einen Parameterblock beschrieben : + + + Ein Parameterblock besteht aus einem Namen (1), einer Hilfe Schaltfläche (2), der Hilfe zu dem Parameter (3), der Parameter + Darstellung (4) und einem Nachrichten Block(5). + + + + dummy + + + + + + parametertesttool_output_echo + parametertesttool_param_boolean + parametertesttool_param_boolean2 + parametertesttool_param_int + parametertesttool_param_int_min_max_default + parametertesttool_param_float + parametertesttool_param_float_max_min_default + parametertesttool_param_string + parametertesttool_param_string_regexp + parametertesttool_param_string_min_max + parametertesttool_param_string_regexp_default + + + + Enumeration parameter test function + Function using a combination of all supported 'enum' parameter. All selected values are returned as result. + + The ParameterTestTool function1 is an simple "echo" function to test and explain all supported enum parameters. For simplicity this function hasn't + any input value. The BiBiServ2 CodeGen package should currently support the following enumeration based parameter. + + Select One Radiobutton + Select One ListBox + Select One Menu + Select Many Checkbox + Select Many ListBox + Select Many Menu + + The only difference between all the Select One ... parameter is the view on the submission page. The function is the same. The user + select one key and the corresponding value is returned (optional leading with the content of the <option> tag. While the + Select One ... parameter return only one value (well, that's the reason why they are called Select One ...), all + Select Many ... parameter could return a list of values (as comma separated values in one string). + + + + dummy2 + + + + + + parametertesttool_enum_selectoneradio + parametertesttool_enum_selectonelistbox + parametertesttool_enum_selectonemenu + parametertesttool_enum_selectmanycheckbox + parametertesttool_enum_selectmanylistbox + parametertesttool_enum_selectmanymenu + parametertesttool_output_echo + + + + + Sample Text File + file1.txt + This is sample short description for a simple text file. + + + + + Submission Page + Submission Seite + + This Submission page is similar to the tool itself written for +test purpose only. + This tool makes - from the view of bioinformatican - absolutely no +sense. This text also is absolute nonsense and is only +an bullshit sample for free content. + + + Diese Submission Seite ist ähnlich wie das Tool selbst nur für reine Testzwecke erstellt worden. Das + Werkzeug macht auch bioinformatischer Sicht absolut keinen Sinn und auch dieser Text + ist nur eine sinnfreie Buchstabenmenge, die (zufälligerweise) Wörter bilden. + + + + + + Download Page + Download Seite + + + + + WebService Page + WebService Seite + No Custom Content + + + + + On this page you can start treecat to run locally on your computer. Just + click on the graphic or the link below: + + On the manual page it is + described how to use this program. + If the program was useful for you, please cite it in your work. + Webstart + This program can be executed to run locally on your computer using the Java + WebStart technology. The download size to start the program is approximately 1 + MByte. + + If an error is issued during WebStart it is quite likely that your Java + version is too old. The program uses features of Java 1.6 (SE 6). + If you do not have a Java Runtime Environment version 1.6 or higher + installed, or if you are working on Solaris/Linux and never previously used Java + WebStart, please follow these installation + instructions. + Java WebStart might complain that it cannot verify the digital signature. + Our certificate is signed by Deutsche Telekom Root CA 2 which has been added to + the trusted certificates since Java Version 6 Update 11. + + About + treecat was developed by Peter Husemann, Bielefeld University. The source code is available + under + GPL3. Please contact the author. + Acknowledgements + Thanks to Pina Krell and Roland Wittler for the Newick + parser. + + + treecat + Peter Husemann, Bielefeld University + treecat - Phylogenetic Tree based Contig Arrangement Tool + This is the tool treecat, which estimates a layout for a + set of contigs based on several related reference genomes and a phylogenetic + tree of the involved species. + + + + + + + + + + + + + + + + + + + + This is an introduction text for the tools manual. At this place normally +all parameter, enumerations, inputs and functions are listed with their description and constraints. If this is not the +case it isn't implemented, yet. + Die ist ein beispielhafter Einführungstext für die Anleitung des Tools. An dieser + Stelle sollten normalerweise alle Parameter, Aufzählungen und Ein-/Ausgabetypen und Funktionen erläutert werden. Falls + dies nicht der Fall, das ist diese Funktionalität leider noch nicht implementiert. + Every Manual page also supports a custom content area at the end of page. The author every + or any other authorized person can place additional explanation/description there. This a good place for e.g. a (short) description + of the algorithm of the tool. + Jede Beschreibungsseite enthält am Ende einen Bereich der vom Autor individuell mit Inhalt + versehen werden kann. Das ist u.a. eine gute Stelle um z.B. kurz den Algorithmus zu erklären der hinter dem Tool steckt. Die + Betonung liegt aber auf kurz, weitreichende wissenschaftliche Ergüsse sollte lieber in einem separaten Dokument im Downloadbereich + hinterlegt werden.Eine Liste von absoluten und relativen Links : + + BiBiServ + GoTo start (relativer Link on same page to named anchor) + GoTo rnamovies references (absolute Link on same page) + Get test sequence data (relativer link) + + + + diff --git a/tools/DeployTools/src/test/resources/resources/downloads/file1.txt b/tools/DeployTools/src/test/resources/resources/downloads/file1.txt new file mode 100644 index 0000000..e69de29 diff --git a/tools/DeployTools/src/test/resources/resources/downloads/file2.txt b/tools/DeployTools/src/test/resources/resources/downloads/file2.txt new file mode 100644 index 0000000..e69de29 diff --git a/tools/DeployTools/src/test/resources/resources/downloads/subdir/file3.txt b/tools/DeployTools/src/test/resources/resources/downloads/subdir/file3.txt new file mode 100644 index 0000000..0cd29f4 --- /dev/null +++ b/tools/DeployTools/src/test/resources/resources/downloads/subdir/file3.txt @@ -0,0 +1 @@ +file3.txt ... diff --git a/tools/DeployTools/src/test/resources/resources/downloads2/file1.txt b/tools/DeployTools/src/test/resources/resources/downloads2/file1.txt new file mode 100644 index 0000000..e69de29 diff --git a/tools/DeployTools/src/test/resources/resources/example/test.fas b/tools/DeployTools/src/test/resources/resources/example/test.fas new file mode 100644 index 0000000..8c57564 --- /dev/null +++ b/tools/DeployTools/src/test/resources/resources/example/test.fas @@ -0,0 +1,2 @@ +>id descr +ACGAUGCUCGAUCGUACGAUCGUACAUCAU diff --git a/tools/DeployTools/src/test/resources/resources/images/The_Earth_seen_from_Apollo_17.jpg b/tools/DeployTools/src/test/resources/resources/images/The_Earth_seen_from_Apollo_17.jpg new file mode 100644 index 0000000..e69de29 diff --git a/tools/DeployTools/src/test/resources/resources/images/parameter_block.png b/tools/DeployTools/src/test/resources/resources/images/parameter_block.png new file mode 100644 index 0000000..e69de29 diff --git a/tools/DeployTools/src/test/resources/resources/webstart/cg-cat.jar b/tools/DeployTools/src/test/resources/resources/webstart/cg-cat.jar new file mode 100644 index 0000000..378ab68 Binary files /dev/null and b/tools/DeployTools/src/test/resources/resources/webstart/cg-cat.jar differ diff --git a/tools/DeployTools/src/test/resources/resources/webstart/treecat_splash64px.gif b/tools/DeployTools/src/test/resources/resources/webstart/treecat_splash64px.gif new file mode 100644 index 0000000..9a0a75d Binary files /dev/null and b/tools/DeployTools/src/test/resources/resources/webstart/treecat_splash64px.gif differ diff --git a/tools/DeployTools/src/test/resources/rnamovies.bs2 b/tools/DeployTools/src/test/resources/rnamovies.bs2 new file mode 100644 index 0000000..fa0d41d --- /dev/null +++ b/tools/DeployTools/src/test/resources/rnamovies.bs2 @@ -0,0 +1,296 @@ + + + RNA Movies + RNA Movies is a system for the visualization of RNA secondary structure landscapes. + Its input is a script consisting of structures from which animated graphical structure representations + are generated. In this way, it creates the impression of an RNA-molecule moving through its own 2D + structure space. + + + Sequential Animation of RNA secondary structure + including pseudoknots and entangled helices + + + RNAMovies is a system for the visualization of RNA secondary structure spaces, i.e. multiple sets of + secondary structure data. The program creates an interpolated animation of the data using the well-known + NAVIEW-routines. The highlighting of pseudo-knotted regions is also supported. + + + This page relates to the Java version of RNA Movies that replaces the former online-version as well + as the standalone-versions. + + The new version features SVG-export for high quality graphics as well as several image formats + (JPEG,PNG and GIF). Single or multiple image export is supported. Additionally to its own formats RNAMovies supports DSCE and RNAStructML as input format + + + RNA Movies is a system for the visualization of RNA secondary structure landscapes. + RNA secondary structure visualisation + + Alexander + Kaiser + Bielefeld university, technical faculty + akaiser@techfak.uni-bielefeld.de + + + Dirk + Evers + dirk.evers@cebitec.uni-bielefeld.de + + + Jan + Krueger + Bielefeld university, CeBiTec, BiBiServ + jkrueger@cebitec.uni-bielefeld.de + + + BiBiServ + Administrators + Bielefeld university, CeBiTec, BiBiServ + bibi-help@cebitec.uni-bielefeld.de + + + @article{KAI:KRUE:EVE:2007, + author={Kaiser, Alexander and Krueger, Jan and Evers, Dirk}, + title={RNA Movies 2 : sequential animation of RNA secondary structures}, + year=2007, + journal={Nucleic Acids Research}, + doi={10.1093/nar/gkm309} + } + + @article{EVE:GIE:1999, + author={Evers, Dirk and Giegerich, Robert}, + title={RNA movies: visualizing RNA secondary structure spaces}, + year=1999, + journal={BioInformatics}, + doi={10.1093/bioinformatics/15.1.32} + } + + + + + + RNAMovies + 2.04 + rnamovies_src.tar.gz + Java Source package + Source/Java + + + + RNAMovies + rnamovies.jar + Java 5 Binary package + Java 5 + + + Download + + Comment: Most of downloaded tools are compressed with gzip and + merged in a TAR - archive. They can be unpacked using gzip and tar on an unix like system or a + tool like winzip on a windows system. + + + Example using gzip/tar: gzip -cd "TOOL".tar.gz | tar xvf - + + + The BiBiServ team does not provide any support for compiling or using a tool from the download section. + Please contact the author directly in case of any problem. + + + + + Webstart + + RNAMovies uses Java WebStart facilities to allow full-featured applications to be launched with just a single-click of a mouse. + At least Java 1.5 or newer is needed to run RNAMovies. + + + + RNAMovies online version is based on Java WebStart + version 1.0.1 or higher. + If you do not have a Java Runtime Environment version 1.5.0 or higher installed, or + if you are working on Solaris/Linux and never previously used Java WebStart, please follow + these installation instructions. + The file size of the RNAMovies program is about 410 KBytes. + + + + + RNAMovies2 + Alexander Kaiser + RNAMovies:Sequential Animation of RNA secondary structure + including pseudoknots and entangled helices + + + + + + + + + + + + + + + + The original RNA Movies, which is + available for download, is available for Unix-like systems only. + The new Java version is available for the Microsoft Windows platform as well. + The online version of RNA Movies is + available as applet (embedded into a website that features a + submission form) and WebStart application. + + Menu and Toolbar + + Most functions are self explainatory. The tool bar at the + bottom of the applet provides the following functionality (from + left to right): + + + Open movie + + Play movie + + Stop movie + + Skip one frame + back + + Skip one frame + + + File: + + + Open ...Open a movie in DSCE/RNM format + + + Import ...Import a movie in RNAStructML format + + + Export ...Export current movie as PNG/JPEG/SVG/(animated)GIF + + + Configure...Show the configuration panel + + + + + Movie: + + + PlayStart the animation + + + StopStop/Pause the animation + + + PreviousStep one frame back + + + NextSkip one frame + + + Goto Frame ...Goto a specific frame + + + View: + + + + + Zoom In + Zoom in by 25% + + + Zoom Out + Zoom out by 25% + + + Reset view + Reset zoom, rotation and moving + + + + + Help: + + + About... + Show references/credits + + + + Mouse actions: + + + Left button + Move + + + Right button + Rotate + + + Mouse wheel + Zoom + + + + + + + + Security + + As mentioned before the 'online' RNA + Movies client is written in Java language and runs as an + applet in your browser's restricted enviroment called + sandbox. The access control policies + of such an enviroment are typically restricted in many ways. In + general applets cannot write files. Therefore we have digitally + signed the applet to enable users to use its import and export + functionality. This means that a warning dialog asks the user to + accept the applet's signature. For now we use a selfmade security + certificate which is not trusted. + + Input data format + + Since release 1.2 RNA Movies + supports two input formats. The RNAfold / Vienna format and DCSE + format. Both formats have been extended to include pseudoknots, + entangled helices, and structure description. The RNM format is + simpler and more intuitive while the DCSE format has more + possibilities. The current version (2.x) supports additionally to + its own format the DCSE format and RNAStructML + as input format. + + + Some Examples + + + BeetSoil-BorneVirus + + + LeptomonasCollosoma5'-Ende + + + HIV1-leader.3 + + + Odontoglossum + + + + + \ No newline at end of file diff --git a/tools/ManagerClient/ivy.xml b/tools/ManagerClient/ivy.xml new file mode 100644 index 0000000..a1090f9 --- /dev/null +++ b/tools/ManagerClient/ivy.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + diff --git a/tools/ManagerClient/pom.xml b/tools/ManagerClient/pom.xml new file mode 100644 index 0000000..19b2eb0 --- /dev/null +++ b/tools/ManagerClient/pom.xml @@ -0,0 +1,48 @@ + + + 4.0.0 + de.unibi.cebitec.bibiserv + managerclient + stable.release + jar + ManagerClient + + + + snapshot-repository.java.net + Java.net Snapshot Repository for Maven + https://maven.java.net/content/repositories/snapshots/ + default + + + jitpack.io + https://jitpack.io + + + + + + + com.sun.jersey + jersey-client + 1.19.2 + + + + + org.apache.ant + ant + 1.9.0 + compile + + + + + UTF-8 + 1.8 + 1.8 + + + diff --git a/tools/ManagerClient/src/main/java/de/unibi/cebitec/bibiserv/client/manager/AntTaskDefClassLoader.java b/tools/ManagerClient/src/main/java/de/unibi/cebitec/bibiserv/client/manager/AntTaskDefClassLoader.java new file mode 100644 index 0000000..d5e4852 --- /dev/null +++ b/tools/ManagerClient/src/main/java/de/unibi/cebitec/bibiserv/client/manager/AntTaskDefClassLoader.java @@ -0,0 +1,23 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package de.unibi.cebitec.bibiserv.client.manager; + +/** + * + * @author jkrueger + */ +public class AntTaskDefClassLoader extends ClassLoader{ + + @Override + protected Class findClass(String name) throws ClassNotFoundException { + System.err.println(System.getProperty("java.class.path")); + + return super.findClass(name); + } + + + +} diff --git a/tools/ManagerClient/src/main/java/de/unibi/cebitec/bibiserv/client/manager/ManagerClient.java b/tools/ManagerClient/src/main/java/de/unibi/cebitec/bibiserv/client/manager/ManagerClient.java new file mode 100644 index 0000000..222667a --- /dev/null +++ b/tools/ManagerClient/src/main/java/de/unibi/cebitec/bibiserv/client/manager/ManagerClient.java @@ -0,0 +1,267 @@ +package de.unibi.cebitec.bibiserv.client.manager; + +import com.sun.jersey.api.client.Client; +import com.sun.jersey.api.client.UniformInterfaceException; +import com.sun.jersey.api.client.WebResource; +import com.sun.jersey.api.client.config.ClientConfig; +import com.sun.jersey.api.client.config.DefaultClientConfig; +import com.sun.jersey.client.urlconnection.HTTPSProperties; +import java.io.BufferedReader; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.security.SecureRandom; +import java.security.cert.X509Certificate; +import java.util.Properties; +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSession; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; +import javax.ws.rs.core.MediaType; + +/** + * + * @author jkrueger + */ +public class ManagerClient { + + private Properties bibiserv2_manager; + private static File pwdfile = new File(System.getProperty("user.home") + "/.bibiserv2_manager"); + private WebResource res = null; + + public ManagerClient() throws Exception { + this(null, null, null); + } + + /** + * Initialize the ManagerClient + * + * + * @param server - server to be used, overwrites ~/.bibiserv2_manager + * settings + * @param port - server to be used, overwrites ~/.bibiserv2_manager settings + * @param ssl - server to be used, overwrites ~/.bibiserv2_manager settings + * @throws Exception + */ + public ManagerClient(String server, String port, Boolean ssl) throws Exception { + bibiserv2_manager = readBiBiServ2PropertiesFile(); + if (server == null || port == null || ssl == null) { + server = bibiserv2_manager.getProperty("server"); + port = bibiserv2_manager.getProperty("port"); + ssl = new Boolean(bibiserv2_manager.getProperty("ssl")); + if (server == null || port == null || ssl == null) { + System.err.println("Properties 'server', 'port' and 'ssl' must be set within the '" + pwdfile + "'!"); + System.exit(1); + + } + } + + // create url + String url = (ssl ? "https" : "http") + "://" + server + ":" + port + "/rest"; + + Client client = Client.create(createClientConfig()); + + res = client.resource(url); + + } + + /** + * Deploy an application to server + * + * @param zipfile + * @throws Exception + */ + public void deploy(File zipfile) throws Exception { + /* read zipfile into bytestream */ + InputStream in = new FileInputStream(zipfile); + byte[] bytes = new byte[(int) zipfile.length()]; + + int offset = 0; + int numRead = 0; + while (offset < bytes.length + && (numRead = in.read(bytes, offset, bytes.length - offset)) >= 0) { + offset += numRead; + } + in.close(); + + try { + res.path("manager"). + type(MediaType.APPLICATION_OCTET_STREAM). + header("authorization", "basic "+bibiserv2_manager.get("role") + ":" + bibiserv2_manager.get("password")). + put(bytes); + System.out.println("successful!"); + } catch (UniformInterfaceException e) { + String answer = is2string(e.getResponse().getEntityInputStream()); + if (answer == null || answer.isEmpty()) { + System.err.println(e.getMessage()); + } else { + System.err.println(answer); + } + } + + } + + /** + * Undeploy an application from server + * + * @param name + * @throws ManagerException_Exception + */ + public void undeploy(String name) { + try { + res.path("manager"). + type(MediaType.TEXT_PLAIN). + header("authorization", "basic "+bibiserv2_manager.get("role") + ":" + bibiserv2_manager.get("password")). + put(name); + System.out.println("successful!"); + } catch (UniformInterfaceException e) { + String answer = is2string(e.getResponse().getEntityInputStream()); + if (answer == null || answer.isEmpty()) { + System.err.println(e.getMessage()); + } else { + System.err.println(answer); + } + } + } + + /** + * Static method that look for an Java Properties file + * (System.getProperty("user.home") + "/.bibiserv2_manager") containing two + * Java properties 'role' and 'password'. Throws an exception with enhanced + * error message, if properties file doesn't exists, can't be read as + * property file or doesn;t contain not all the both necessary properties. + * Return a Properties object with at least two properties ('role' and + * 'password'). + * + * + * + * @return Return a Properties object with at least two properties ('role' + * and 'password'). + * @throws Throws an Exception if properties file can't be read (see above). + */ + public static Properties readBiBiServ2PropertiesFile() throws Exception { + + // check if ~/.bibiserv2_manager file exists and contains a user, passwort pair + + + String message = "Create a password(property)file '" + pwdfile.toString() + "' containing two Java properties;\n" + + "role and password\n\n" + + "Example:\n" + + "# bibimainapp manager admin role [required] \n" + + "role=dummy\n" + + "# bibimainapp manager admin role password [required] \n" + + "password=my_password\n" + + "# server host name \n" + + "server=bibiserv2.cebitec.uni-bielefeld.de\n" + + "# server port\n" + + "port=443\n" + + "# use ssl\n" + + "ssl=true\n\n"; + + + if (!pwdfile.exists() || !pwdfile.isFile()) { + throw new Exception("Passwordfile '" + pwdfile.toString() + "' not found ...\n" + message); + } + Properties pwdprop = new Properties(); + pwdprop.load(new FileReader(pwdfile)); + + if (!(pwdprop.containsKey("role") && pwdprop.containsKey("password"))) { + throw new Exception("Passwordfile '" + pwdfile.toString() + "' found, but contains wrong or no properties ...\n" + message); + } + if (pwdprop.containsKey("server")) { + if (!pwdprop.containsKey("port")) { + pwdprop.setProperty("port", "80"); + } + + } + + return pwdprop; + } + + public static void main(String args[]) { + try { + // get home dir + + + if (!(args.length == 2 || args.length == 5)) { + System.err.println("usage: java " + ManagerClient.class.getName() + "\n" + + "\t deploy ( )\n" + + "\t undeploy name/id ( )\n\n" + + "(If server, port and ssl are not given the values from ~/.bibiserv2_manager are used instead!"); + System.exit(1); + } + + ManagerClient app; + if (args.length == 2) { + app = new ManagerClient(); + } else { + app = new ManagerClient(args[2], args[3], new Boolean(args[4])); + } + switch (args[0]) { + case "deploy": + app.deploy(new File(args[1])); + break; + case "undeploy": + app.undeploy(args[1]); + break; + default: + System.err.println("Unsupported command '" + args[0] + "'!"); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + private ClientConfig createClientConfig() throws Exception { + // Create a trust manager that does not validate certificate chains + TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() { + public X509Certificate[] getAcceptedIssuers() { + return null; + } + + public void checkClientTrusted(X509Certificate[] certs, String authType) { + } + + public void checkServerTrusted(X509Certificate[] certs, String authType) { + } + }}; + +// Install the all-trusting trust manager + + SSLContext sc = SSLContext.getInstance("TLS"); + sc.init(null, trustAllCerts, new SecureRandom()); + HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); + + + ClientConfig config = new DefaultClientConfig(); + config.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties( + new HostnameVerifier() { + @Override + public boolean verify(String s, SSLSession sslSession) { + return true; + } + }, sc)); + return config; + } + + private static String is2string(InputStream is) { + + try { + BufferedReader br = new BufferedReader(new InputStreamReader(is)); + String line; + StringBuilder sb = new StringBuilder(); + while ((line = br.readLine()) != null) { + sb.append(line); + } + return sb.toString(); + } catch (IOException e) { + return e.getMessage(); + } + } +} diff --git a/tools/ManagerClient/src/main/java/de/unibi/cebitec/bibiserv/client/manager/ManagerClientTask.java b/tools/ManagerClient/src/main/java/de/unibi/cebitec/bibiserv/client/manager/ManagerClientTask.java new file mode 100644 index 0000000..9514cf0 --- /dev/null +++ b/tools/ManagerClient/src/main/java/de/unibi/cebitec/bibiserv/client/manager/ManagerClientTask.java @@ -0,0 +1,84 @@ +package de.unibi.cebitec.bibiserv.client.manager; + +import java.io.File; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Task; + +/** + * + * @author Jan Krueger - jkrueger(at)cebitec.uni-bielefeld.de + */ +public class ManagerClientTask extends Task { + + private String action; + private String server; + private String port; + private String file; + private String name; + private Boolean ssl; + private String usage = ""; + private ManagerClient managerclient; + + @Override + public void execute() throws BuildException { + + try { + // initialize ManagerApplication + if (server != null) { + managerclient = new ManagerClient("server", (port == null) ? "80" : port, false); + } else { + managerclient = new ManagerClient(); + } + + + if (action != null) { + if (action.equals("deploy")) { + if (file != null && (new File(file).exists())) { + managerclient.deploy(new File(file)); + } else { + new BuildException(usage); + } + } else if (action.equals("undeploy")) { + if (name != null) { + managerclient.undeploy(name); + } else { + new BuildException(usage); + } + } else { + new BuildException("no Action given :" +usage); + } + } else { + new BuildException(usage); + } + } catch (Exception e) { + throw new BuildException(e); + } + + + + } + + public void setAction(String action) { + this.action = action; + } + + public void setFile(String file) { + this.file = file; + } + + public void setName(String name) { + this.name = name; + } + + public void setPort(String port) { + this.port = port; + } + + public void setServer(String server) { + this.server = server; + } + + public void setSsl(Boolean ssl){ + this.ssl = ssl; + } +} diff --git a/tools/ManagerClient/src/main/rescources/config/log4j.properties b/tools/ManagerClient/src/main/rescources/config/log4j.properties new file mode 100644 index 0000000..e9bc17a --- /dev/null +++ b/tools/ManagerClient/src/main/rescources/config/log4j.properties @@ -0,0 +1,12 @@ +log4j.rootLogger=error, stdout + +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%-5p (%d) %m [%F:%L]%n + +log4j.appender.file=org.apache.log4j.DailyRollingFileAppender +log4j.appender.file.File=/vol/bibiwssv/spool/dialign/dialign.log +log4j.appender.file.DatePattern=.yyyy-MM-dd +log4j.appender.file.layout=org.apache.log4j.PatternLayout +log4j.appender.file.layout.ConversionPattern=%-5p (%d) %m [%F:%L]%n + diff --git a/tools/pom.xml b/tools/pom.xml new file mode 100644 index 0000000..8b23a5a --- /dev/null +++ b/tools/pom.xml @@ -0,0 +1,34 @@ + + + 4.0.0 + de.unibi.cebitec.bibiserv + tools + stable.release + pom + Tools + + + + snapshot-repository.java.net + Java.net Snapshot Repository for Maven + https://maven.java.net/content/repositories/snapshots/ + default + + + jitpack.io + https://jitpack.io + + + + DeployTools + ManagerClient + + + UTF-8 + 1.8 + 1.8 + + +