utilties implemened
Project: http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/commit/2413a11e Tree: http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/tree/2413a11e Diff: http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/diff/2413a11e Branch: refs/heads/cwl-browse Commit: 2413a11e46a2eea01516c67f8cfe9f2bc200f67c Parents: 8e57230 Author: ThilinaManamgoda <[email protected]> Authored: Wed Jun 22 19:37:32 2016 +0530 Committer: ThilinaManamgoda <[email protected]> Committed: Wed Jun 22 19:37:32 2016 +0530 ---------------------------------------------------------------------- .../taverna/cwl/utilities/PortDetail.java | 42 ++++ .../apache/taverna/cwl/utilities/Utility.java | 194 +++++++++++++++++++ 2 files changed, 236 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/2413a11e/taverna-cwl-utilities/src/main/java/org/apache/taverna/cwl/utilities/PortDetail.java ---------------------------------------------------------------------- diff --git a/taverna-cwl-utilities/src/main/java/org/apache/taverna/cwl/utilities/PortDetail.java b/taverna-cwl-utilities/src/main/java/org/apache/taverna/cwl/utilities/PortDetail.java new file mode 100644 index 0000000..9871a58 --- /dev/null +++ b/taverna-cwl-utilities/src/main/java/org/apache/taverna/cwl/utilities/PortDetail.java @@ -0,0 +1,42 @@ +package org.apache.taverna.cwl.utilities; + +import java.util.ArrayList; + +public class PortDetail { + + + private String label; + + private int depth; + private String description; + private ArrayList<String> format; + public int getDepth() { + return depth; + } + public void setDepth(int depth) { + this.depth = depth; + } + public String getDescription() { + return description; + } + public void setDescription(String description) { + this.description = description; + } + public String getLabel() { + return label; + } + public void setLabel(String label) { + this.label = label; + } + public ArrayList<String> getFormat() { + return format; + } + public void setFormat(ArrayList<String> format) { + this.format = format; + } + + public void addFormat(String format){ + this.format.add(format); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/2413a11e/taverna-cwl-utilities/src/main/java/org/apache/taverna/cwl/utilities/Utility.java ---------------------------------------------------------------------- diff --git a/taverna-cwl-utilities/src/main/java/org/apache/taverna/cwl/utilities/Utility.java b/taverna-cwl-utilities/src/main/java/org/apache/taverna/cwl/utilities/Utility.java new file mode 100644 index 0000000..e39340c --- /dev/null +++ b/taverna-cwl-utilities/src/main/java/org/apache/taverna/cwl/utilities/Utility.java @@ -0,0 +1,194 @@ +package org.apache.taverna.cwl.utilities; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; + + +public class Utility { + + private static final String INPUTS = "inputs"; + private static final String OUTPUTS = "outputs"; + private static final String ID = "id"; + private static final String TYPE = "type"; + private static final String ARRAY = "array"; + private static final String DESCRIPTION = "description"; + private static final int DEPTH_0 = 0; + private static final int DEPTH_1 = 1; + private static final int DEPTH_2 = 2; + + private static final String FLOAT = "float"; + private static final String NULL = "null"; + private static final String LABEL = "label"; + private static final String FORMAT = "format"; + private LinkedHashMap nameSpace; + private Map cwlFile; + + + public Utility(Map cwlFile) { + this.cwlFile = cwlFile; + processNameSpace(); + } + public void processNameSpace() { + + if (cwlFile.containsKey("$namespaces")) { + nameSpace = (LinkedHashMap) cwlFile.get("$namespaces"); + } + + } + + public HashMap<String, Integer> processInputDepths(){ + return process(cwlFile.get(INPUTS)); + } + public HashMap<String, Integer> processOutputDepths(){ + return process(cwlFile.get(OUTPUTS)); + } + public HashMap<String, PortDetail> processInputDetails(){ + return processdetails(cwlFile.get(INPUTS)); + } + public HashMap<String, PortDetail> processOutputDetails(){ + return processdetails(cwlFile.get(OUTPUTS)); + } + private HashMap<String, Integer> process(Object inputs) { + + HashMap<String, Integer> result = new HashMap<>(); + + if (inputs.getClass() == ArrayList.class) { + + for (Map input : (ArrayList<Map>) inputs) { + String currentInputId = (String) input.get(ID); + + + Object typeConfigurations; + try { + + typeConfigurations = input.get(TYPE); + // if type :single argument + if (typeConfigurations.getClass() == String.class) { + + + result.put(currentInputId, DEPTH_0); + // type : defined as another map which contains type: + } else if (typeConfigurations.getClass() == LinkedHashMap.class) { + String inputType = (String) ((Map) typeConfigurations).get(TYPE); + if (inputType.equals(ARRAY)) { + result.put(currentInputId, DEPTH_1); + + } + } else if (typeConfigurations.getClass() == ArrayList.class) { + if (isValidDataType((ArrayList) typeConfigurations)) { + result.put(currentInputId, DEPTH_0); + } + + } + + } catch (ClassCastException e) { + + System.out.println("Class cast exception !!!"); + } + + } + } else if (inputs.getClass() == LinkedHashMap.class) { + for (Object parameter : ((Map) inputs).keySet()) { + if (parameter.toString().startsWith("$")) + System.out.println("Exception"); + } + } + return result; + } + private HashMap<String, PortDetail> processdetails(Object inputs) { + + HashMap<String, PortDetail> result = new HashMap<>(); + + if (inputs.getClass() == ArrayList.class) { + + for (Map input : (ArrayList<Map>) inputs) { + PortDetail detail = new PortDetail(); + String currentInputId = (String) input.get(ID); + + extractDescription(input, detail); + + extractFormat(input, detail); + + extractLabel(input, detail); + result.put(currentInputId, detail); + + + } + } else if (inputs.getClass() == LinkedHashMap.class) { + for (Object parameter : ((Map) inputs).keySet()) { + if (parameter.toString().startsWith("$")) + System.out.println("Exception"); + } + } + return result; + } + private void extractLabel(Map input, PortDetail detail) { + if (input != null) + if (input.containsKey(LABEL)) { + detail.setLabel((String) input.get(LABEL)); + } else { + detail.setLabel(null); + } + } + + private void extractDescription(Map input, PortDetail detail) { + if (input != null) + if (input.containsKey(DESCRIPTION)) { + detail.setDescription((String) input.get(DESCRIPTION)); + } else { + detail.setDescription(null); + } + } + + private void extractFormat(Map input, PortDetail detail) { + if (input != null) + if (input.containsKey(FORMAT)) { + + Object formatInfo = input.get(FORMAT); + + ArrayList<String> format = new ArrayList<>(); + detail.setFormat(format); + + if (formatInfo.getClass() == String.class) { + + extractThisFormat(formatInfo.toString(), detail); + } else if (formatInfo.getClass() == ArrayList.class) { + for (Object eachFormat : (ArrayList) formatInfo) { + extractThisFormat(eachFormat.toString(), detail); + } + } + + } + } + + private void extractThisFormat(String formatInfoString, PortDetail detail) { + if (formatInfoString.startsWith("$")) { + + detail.addFormat(formatInfoString); + } else if (formatInfoString.contains(":")) { + String format[] = formatInfoString.split(":"); + String namespaceKey = format[0]; + String urlAppednd = format[1]; + if (!nameSpace.isEmpty()) { + if (nameSpace.containsKey(namespaceKey)) + detail.addFormat(nameSpace.get(namespaceKey) + urlAppednd); + else + + detail.addFormat(formatInfoString); + } else { + detail.addFormat(formatInfoString); + } + } else { + detail.addFormat(formatInfoString); + } + } + public boolean isValidDataType(ArrayList typeConfigurations) { + for (Object type : typeConfigurations) { + if (!(((String) type).equals(FLOAT) || ((String) type).equals(NULL))) + return false; + } + return true; + } +}
