You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ch...@apache.org on 2016/02/08 17:49:12 UTC
[30/50] [abbrv] airavata git commit: adding workflow related resource
layer
http://git-wip-us.apache.org/repos/asf/airavata/blob/2a2782a6/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/model/WorkflowInput.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/model/WorkflowInput.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/model/WorkflowInput.java
new file mode 100644
index 0000000..c9a319a
--- /dev/null
+++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/model/WorkflowInput.java
@@ -0,0 +1,167 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.registry.core.workflow.catalog.model;
+
+
+import javax.persistence.*;
+import java.io.Serializable;
+
+@Entity
+@Table(name = "WORKFLOW_INPUT")
+@IdClass(WorkflowInput_PK.class)
+public class WorkflowInput implements Serializable {
+ @Id
+ @Column(name = "TEMPLATE_ID")
+ private String templateID;
+ @Id
+ @Column(name = "INPUT_KEY")
+ private String inputKey;
+ @Lob
+ @Column(name = "INPUT_VALUE")
+ private char[] inputVal;
+ @Column(name = "DATA_TYPE")
+ private String dataType;
+ @Column(name = "METADATA")
+ private String metadata;
+ @Column(name = "APP_ARGUMENT")
+ private String appArgument;
+ @Column(name = "USER_FRIENDLY_DESC")
+ private String userFriendlyDesc;
+ @Column(name = "STANDARD_INPUT")
+ private boolean standardInput;
+ @Column(name="INPUT_ORDER")
+ private int inputOrder;
+ @Column(name="IS_REQUIRED")
+ private boolean isRequired;
+ @Column(name="REQUIRED_TO_COMMANDLINE")
+ private boolean requiredToCMD;
+ @Column(name = "DATA_STAGED")
+ private boolean dataStaged;
+
+ @ManyToOne(cascade= CascadeType.MERGE)
+ @JoinColumn(name = "TEMPLATE_ID")
+ private Workflow workflow;
+
+ public String getTemplateID() {
+ return templateID;
+ }
+
+ public void setTemplateID(String templateID) {
+ this.templateID = templateID;
+ }
+
+ public String getInputKey() {
+ return inputKey;
+ }
+
+ public void setInputKey(String inputKey) {
+ this.inputKey = inputKey;
+ }
+
+ public char[] getInputVal() {
+ return inputVal;
+ }
+
+ public void setInputVal(char[] inputVal) {
+ this.inputVal = inputVal;
+ }
+
+ public String getDataType() {
+ return dataType;
+ }
+
+ public void setDataType(String dataType) {
+ this.dataType = dataType;
+ }
+
+ public String getMetadata() {
+ return metadata;
+ }
+
+ public void setMetadata(String metadata) {
+ this.metadata = metadata;
+ }
+
+ public String getAppArgument() {
+ return appArgument;
+ }
+
+ public void setAppArgument(String appArgument) {
+ this.appArgument = appArgument;
+ }
+
+ public String getUserFriendlyDesc() {
+ return userFriendlyDesc;
+ }
+
+ public void setUserFriendlyDesc(String userFriendlyDesc) {
+ this.userFriendlyDesc = userFriendlyDesc;
+ }
+
+ public Workflow getWorkflow() {
+ return workflow;
+ }
+
+ public void setWorkflow(Workflow workflow) {
+ this.workflow = workflow;
+ }
+
+ public boolean isStandardInput() {
+ return standardInput;
+ }
+
+ public void setStandardInput(boolean standardInput) {
+ this.standardInput = standardInput;
+ }
+
+ public int getInputOrder() {
+ return inputOrder;
+ }
+
+ public void setInputOrder(int inputOrder) {
+ this.inputOrder = inputOrder;
+ }
+
+ public boolean isRequired() {
+ return isRequired;
+ }
+
+ public void setRequired(boolean isRequired) {
+ this.isRequired = isRequired;
+ }
+
+ public boolean isRequiredToCMD() {
+ return requiredToCMD;
+ }
+
+ public void setRequiredToCMD(boolean requiredToCMD) {
+ this.requiredToCMD = requiredToCMD;
+ }
+
+ public boolean isDataStaged() {
+ return dataStaged;
+ }
+
+ public void setDataStaged(boolean dataStaged) {
+ this.dataStaged = dataStaged;
+ }
+}
http://git-wip-us.apache.org/repos/asf/airavata/blob/2a2782a6/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/model/WorkflowIntInput.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/model/WorkflowIntInput.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/model/WorkflowIntInput.java
deleted file mode 100644
index c8d4952..0000000
--- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/model/WorkflowIntInput.java
+++ /dev/null
@@ -1,166 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-
-package org.apache.airavata.registry.core.workflow.catalog.model;
-
-
-import javax.persistence.*;
-import java.io.Serializable;
-
-@Entity
-@Table(name = "WORKFLOW_INPUT")
-@IdClass(WorkflowInput_PK.class)
-public class WorkflowIntInput implements Serializable {
- @Id
- @Column(name = "INTERFACE_ID")
- private String templateID;
- @Id
- @Column(name = "INPUT_KEY")
- private String inputKey;
- @Column(name = "INPUT_VALUE")
- private String inputVal;
- @Column(name = "DATA_TYPE")
- private String dataType;
- @Column(name = "METADATA")
- private String metadata;
- @Column(name = "APP_ARGUMENT")
- private String appArgument;
- @Column(name = "USER_FRIENDLY_DESC")
- private String userFriendlyDesc;
- @Column(name = "STANDARD_INPUT")
- private boolean standardInput;
- @Column(name="INPUT_ORDER")
- private int inputOrder;
- @Column(name="IS_REQUIRED")
- private boolean isRequired;
- @Column(name="REQUIRED_TO_COMMANDLINE")
- private boolean requiredToCMD;
- @Column(name = "DATA_STAGED")
- private boolean dataStaged;
-
- @ManyToOne(cascade= CascadeType.MERGE)
- @JoinColumn(name = "TEMPLATE_ID")
- private Workflow workflow;
-
- public String getTemplateID() {
- return templateID;
- }
-
- public void setTemplateID(String templateID) {
- this.templateID = templateID;
- }
-
- public String getInputKey() {
- return inputKey;
- }
-
- public void setInputKey(String inputKey) {
- this.inputKey = inputKey;
- }
-
- public String getInputVal() {
- return inputVal;
- }
-
- public void setInputVal(String inputVal) {
- this.inputVal = inputVal;
- }
-
- public String getDataType() {
- return dataType;
- }
-
- public void setDataType(String dataType) {
- this.dataType = dataType;
- }
-
- public String getMetadata() {
- return metadata;
- }
-
- public void setMetadata(String metadata) {
- this.metadata = metadata;
- }
-
- public String getAppArgument() {
- return appArgument;
- }
-
- public void setAppArgument(String appArgument) {
- this.appArgument = appArgument;
- }
-
- public String getUserFriendlyDesc() {
- return userFriendlyDesc;
- }
-
- public void setUserFriendlyDesc(String userFriendlyDesc) {
- this.userFriendlyDesc = userFriendlyDesc;
- }
-
- public Workflow getWorkflow() {
- return workflow;
- }
-
- public void setWorkflow(Workflow workflow) {
- this.workflow = workflow;
- }
-
- public boolean isStandardInput() {
- return standardInput;
- }
-
- public void setStandardInput(boolean standardInput) {
- this.standardInput = standardInput;
- }
-
- public int getInputOrder() {
- return inputOrder;
- }
-
- public void setInputOrder(int inputOrder) {
- this.inputOrder = inputOrder;
- }
-
- public boolean isRequired() {
- return isRequired;
- }
-
- public void setRequired(boolean isRequired) {
- this.isRequired = isRequired;
- }
-
- public boolean isRequiredToCMD() {
- return requiredToCMD;
- }
-
- public void setRequiredToCMD(boolean requiredToCMD) {
- this.requiredToCMD = requiredToCMD;
- }
-
- public boolean isDataStaged() {
- return dataStaged;
- }
-
- public void setDataStaged(boolean dataStaged) {
- this.dataStaged = dataStaged;
- }
-}
http://git-wip-us.apache.org/repos/asf/airavata/blob/2a2782a6/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/model/WorkflowOutput.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/model/WorkflowOutput.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/model/WorkflowOutput.java
index 2131557..4a79ce8 100644
--- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/model/WorkflowOutput.java
+++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/model/WorkflowOutput.java
@@ -35,8 +35,9 @@ public class WorkflowOutput implements Serializable {
@Id
@Column(name = "OUTPUT_KEY")
private String outputKey;
+ @Lob
@Column(name = "OUTPUT_VALUE")
- private String outputVal;
+ private char[] outputVal;
@Column(name = "DATA_TYPE")
private String dataType;
@Column(name = "IS_REQUIRED")
@@ -90,11 +91,11 @@ public class WorkflowOutput implements Serializable {
this.outputKey = outputKey;
}
- public String getOutputVal() {
+ public char[] getOutputVal() {
return outputVal;
}
- public void setOutputVal(String outputVal) {
+ public void setOutputVal(char[] outputVal) {
this.outputVal = outputVal;
}
http://git-wip-us.apache.org/repos/asf/airavata/blob/2a2782a6/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/resources/ComponentStatusResource.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/resources/ComponentStatusResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/resources/ComponentStatusResource.java
new file mode 100644
index 0000000..f6d2ce6
--- /dev/null
+++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/resources/ComponentStatusResource.java
@@ -0,0 +1,340 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.airavata.registry.core.workflow.catalog.resources;
+
+import org.apache.airavata.common.exception.ApplicationSettingsException;
+import org.apache.airavata.common.utils.AiravataUtils;
+import org.apache.airavata.registry.core.workflow.catalog.model.ComponentStatus;
+import org.apache.airavata.registry.core.workflow.catalog.model.Workflow;
+import org.apache.airavata.registry.core.workflow.catalog.utils.WorkflowCatalogJPAUtils;
+import org.apache.airavata.registry.core.workflow.catalog.utils.WorkflowCatalogQueryGenerator;
+import org.apache.airavata.registry.core.workflow.catalog.utils.WorkflowCatalogResourceType;
+import org.apache.airavata.registry.cpi.WorkflowCatalogException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.List;
+
+public class ComponentStatusResource extends WorkflowCatAbstractResource {
+ private final static Logger logger = LoggerFactory.getLogger(ComponentStatusResource.class);
+
+ private String statusId;
+ private String state;
+ private String reason;
+ private String templateId;
+ private Timestamp updatedTime;
+
+ public void remove(Object identifier) throws WorkflowCatalogException {
+ EntityManager em = null;
+ try {
+ em = WorkflowCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ WorkflowCatalogQueryGenerator generator = new WorkflowCatalogQueryGenerator(COMPONENT_STATUS);
+ generator.setParameter(ComponentStatusConstants.STATUS_ID, identifier.toString());
+ Query q = generator.deleteQuery(em);
+ q.executeUpdate();
+ em.getTransaction().commit();
+ if (em.isOpen()) {
+ if (em.getTransaction().isActive()){
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ } catch (ApplicationSettingsException e) {
+ logger.error(e.getMessage(), e);
+ throw new WorkflowCatalogException(e);
+ } finally {
+ if (em != null && em.isOpen()) {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ }
+ }
+
+ public WorkflowCatalogResource get(Object identifier) throws WorkflowCatalogException {
+ EntityManager em = null;
+ try {
+ em = WorkflowCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ WorkflowCatalogQueryGenerator generator = new WorkflowCatalogQueryGenerator(COMPONENT_STATUS);
+ generator.setParameter(ComponentStatusConstants.STATUS_ID, identifier.toString());
+ Query q = generator.selectQuery(em);
+ ComponentStatus status = (ComponentStatus) q.getSingleResult();
+ ComponentStatusResource statusResource =
+ (ComponentStatusResource) WorkflowCatalogJPAUtils.getResource(WorkflowCatalogResourceType.COMPONENT_STATUS
+ , status);
+ em.getTransaction().commit();
+ if (em.isOpen()) {
+ if (em.getTransaction().isActive()){
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ return statusResource;
+ } catch (ApplicationSettingsException e) {
+ logger.error(e.getMessage(), e);
+ throw new WorkflowCatalogException(e);
+ } finally {
+ if (em != null && em.isOpen()) {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ }
+ }
+
+ public List<WorkflowCatalogResource> get(String fieldName, Object value) throws WorkflowCatalogException {
+ List<WorkflowCatalogResource> statusResources = new ArrayList<WorkflowCatalogResource>();
+ EntityManager em = null;
+ try {
+ em = WorkflowCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ Query q;
+ WorkflowCatalogQueryGenerator generator = new WorkflowCatalogQueryGenerator(COMPONENT_STATUS);
+ List results;
+ if (fieldName.equals(ComponentStatusConstants.TEMPLATE_ID)) {
+ generator.setParameter(ComponentStatusConstants.TEMPLATE_ID, value);
+ q = generator.selectQuery(em);
+ results = q.getResultList();
+ if (results.size() != 0) {
+ for (Object result : results) {
+ ComponentStatus componentStatus = (ComponentStatus) result;
+ ComponentStatusResource statusResource =
+ (ComponentStatusResource) WorkflowCatalogJPAUtils.getResource(
+ WorkflowCatalogResourceType.COMPONENT_STATUS, componentStatus);
+ statusResources.add(statusResource);
+ }
+ }
+ }else {
+ em.getTransaction().commit();
+ if (em.isOpen()) {
+ if (em.getTransaction().isActive()){
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ logger.error("Unsupported field name for Component status Resource.", new IllegalArgumentException());
+ throw new IllegalArgumentException("Unsupported field name for Component status Resource.");
+ }
+ em.getTransaction().commit();
+ if (em.isOpen()) {
+ if (em.getTransaction().isActive()){
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ } catch (Exception e) {
+ logger.error(e.getMessage(), e);
+ throw new WorkflowCatalogException(e);
+ } finally {
+ if (em != null && em.isOpen()) {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ }
+ return statusResources;
+ }
+
+ public List<WorkflowCatalogResource> getAll() throws WorkflowCatalogException {
+ return null;
+ }
+
+ public List<String> getAllIds() throws WorkflowCatalogException {
+ return null;
+ }
+
+ public List<String> getIds(String fieldName, Object value) throws WorkflowCatalogException {
+ List<String> statusResourceIds = new ArrayList<String>();
+ EntityManager em = null;
+ try {
+ em = WorkflowCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ Query q;
+ WorkflowCatalogQueryGenerator generator = new WorkflowCatalogQueryGenerator(COMPONENT_STATUS);
+ List results;
+ if (fieldName.equals(ComponentStatusConstants.TEMPLATE_ID)) {
+ generator.setParameter(ComponentStatusConstants.TEMPLATE_ID, value);
+ q = generator.selectQuery(em);
+ results = q.getResultList();
+ if (results.size() != 0) {
+ for (Object result : results) {
+ ComponentStatus componentStatus = (ComponentStatus) result;
+ statusResourceIds.add(componentStatus.getTemplateId());
+ }
+ }
+ } else {
+ em.getTransaction().commit();
+ if (em.isOpen()) {
+ if (em.getTransaction().isActive()){
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ logger.error("Unsupported field name for Component Status resource.", new IllegalArgumentException());
+ throw new IllegalArgumentException("Unsupported field name for Component Status Resource.");
+ }
+ em.getTransaction().commit();
+ if (em.isOpen()) {
+ if (em.getTransaction().isActive()){
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ } catch (Exception e) {
+ logger.error(e.getMessage(), e);
+ throw new WorkflowCatalogException(e);
+ } finally {
+ if (em != null && em.isOpen()) {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ }
+ return statusResourceIds;
+ }
+
+ public void save() throws WorkflowCatalogException {
+ EntityManager em = null;
+ try {
+ em = WorkflowCatalogJPAUtils.getEntityManager();
+ ComponentStatus existingStatus = em.find(ComponentStatus.class,statusId);
+ if (em.isOpen()) {
+ if (em.getTransaction().isActive()){
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+
+ em = WorkflowCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ if (existingStatus != null) {
+ existingStatus.setTemplateId(templateId);
+ Workflow workflow = em.find(Workflow.class, templateId);
+ existingStatus.setWorkflow(workflow);
+ existingStatus.setReason(reason);
+ existingStatus.setState(state);
+ existingStatus.setUpdateTime(AiravataUtils.getCurrentTimestamp());
+ em.merge(existingStatus);
+ } else {
+ ComponentStatus status = new ComponentStatus();
+ status.setTemplateId(templateId);
+ Workflow workflow = em.find(Workflow.class, templateId);
+ status.setWorkflow(workflow);
+ status.setReason(reason);
+ status.setState(state);
+ status.setUpdateTime(AiravataUtils.getCurrentTimestamp());
+ em.persist(status);
+ }
+ em.getTransaction().commit();
+ if (em.isOpen()) {
+ if (em.getTransaction().isActive()){
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ } catch (Exception e) {
+ logger.error(e.getMessage(), e);
+ throw new WorkflowCatalogException(e);
+ } finally {
+ if (em != null && em.isOpen()) {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ }
+ }
+
+ public boolean isExists(Object identifier) throws WorkflowCatalogException {
+ EntityManager em = null;
+ try {
+ em = WorkflowCatalogJPAUtils.getEntityManager();
+ ComponentStatus status = em.find(ComponentStatus.class, identifier.toString());
+
+ if (em.isOpen()) {
+ if (em.getTransaction().isActive()){
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ return status != null;
+ } catch (ApplicationSettingsException e) {
+ logger.error(e.getMessage(), e);
+ throw new WorkflowCatalogException(e);
+ } finally {
+ if (em != null && em.isOpen()) {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ }
+ }
+
+ public String getStatusId() {
+ return statusId;
+ }
+
+ public void setStatusId(String statusId) {
+ this.statusId = statusId;
+ }
+
+ public String getState() {
+ return state;
+ }
+
+ public void setState(String state) {
+ this.state = state;
+ }
+
+ public String getReason() {
+ return reason;
+ }
+
+ public void setReason(String reason) {
+ this.reason = reason;
+ }
+
+ public String getTemplateId() {
+ return templateId;
+ }
+
+ public void setTemplateId(String templateId) {
+ this.templateId = templateId;
+ }
+
+ public Timestamp getUpdatedTime() {
+ return updatedTime;
+ }
+
+ public void setUpdatedTime(Timestamp updatedTime) {
+ this.updatedTime = updatedTime;
+ }
+}
http://git-wip-us.apache.org/repos/asf/airavata/blob/2a2782a6/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/resources/EdgeResource.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/resources/EdgeResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/resources/EdgeResource.java
new file mode 100644
index 0000000..1613943
--- /dev/null
+++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/resources/EdgeResource.java
@@ -0,0 +1,380 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.airavata.registry.core.workflow.catalog.resources;
+
+import org.apache.airavata.common.exception.ApplicationSettingsException;
+import org.apache.airavata.common.utils.AiravataUtils;
+import org.apache.airavata.registry.core.workflow.catalog.model.Workflow;
+import org.apache.airavata.registry.core.workflow.catalog.model.Edge;
+import org.apache.airavata.registry.core.workflow.catalog.model.Edge_PK;
+import org.apache.airavata.registry.core.workflow.catalog.utils.WorkflowCatalogJPAUtils;
+import org.apache.airavata.registry.core.workflow.catalog.utils.WorkflowCatalogQueryGenerator;
+import org.apache.airavata.registry.core.workflow.catalog.utils.WorkflowCatalogResourceType;
+import org.apache.airavata.registry.cpi.WorkflowCatalogException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class EdgeResource extends WorkflowCatAbstractResource {
+ private final static Logger logger = LoggerFactory.getLogger(EdgeResource.class);
+
+ private String edgeId;
+ private String name;
+ private String statusId;
+ private String templateId;
+ private Timestamp createdTime;
+ private String description;
+
+ public void remove(Object identifier) throws WorkflowCatalogException {
+ HashMap<String, String> ids;
+ if (identifier instanceof Map) {
+ ids = (HashMap) identifier;
+ } else {
+ logger.error("Identifier should be a map with the field name and it's value");
+ throw new WorkflowCatalogException("Identifier should be a map with the field name and it's value");
+ }
+
+ EntityManager em = null;
+ try {
+ em = WorkflowCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ WorkflowCatalogQueryGenerator generator = new WorkflowCatalogQueryGenerator(EDGE);
+ generator.setParameter(EdgeConstants.EDGE_ID, ids.get(EdgeConstants.EDGE_ID));
+ generator.setParameter(EdgeConstants.TEMPLATE_ID, ids.get(EdgeConstants.TEMPLATE_ID));
+ Query q = generator.deleteQuery(em);
+ q.executeUpdate();
+ em.getTransaction().commit();
+ if (em.isOpen()) {
+ if (em.getTransaction().isActive()){
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ } catch (ApplicationSettingsException e) {
+ logger.error(e.getMessage(), e);
+ throw new WorkflowCatalogException(e);
+ } finally {
+ if (em != null && em.isOpen()) {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ }
+ }
+
+ public WorkflowCatalogResource get(Object identifier) throws WorkflowCatalogException {
+ HashMap<String, String> ids;
+ if (identifier instanceof Map) {
+ ids = (HashMap<String, String>) identifier;
+ } else {
+ logger.error("Identifier should be a map with the field name and it's value");
+ throw new WorkflowCatalogException("Identifier should be a map with the field name and it's value");
+ }
+
+ EntityManager em = null;
+ try {
+ em = WorkflowCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ WorkflowCatalogQueryGenerator generator = new WorkflowCatalogQueryGenerator(EDGE);
+ generator.setParameter(EdgeConstants.EDGE_ID, ids.get(EdgeConstants.EDGE_ID));
+ generator.setParameter(EdgeConstants.TEMPLATE_ID, ids.get(EdgeConstants.TEMPLATE_ID));
+ Query q = generator.selectQuery(em);
+ Edge edge = (Edge) q.getSingleResult();
+ EdgeResource edgeResource =
+ (EdgeResource) WorkflowCatalogJPAUtils.getResource(WorkflowCatalogResourceType.EDGE
+ , edge);
+ em.getTransaction().commit();
+ if (em.isOpen()) {
+ if (em.getTransaction().isActive()){
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ return edgeResource;
+ } catch (ApplicationSettingsException e) {
+ logger.error(e.getMessage(), e);
+ throw new WorkflowCatalogException(e);
+ } finally {
+ if (em != null && em.isOpen()) {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ }
+ }
+
+ public List<WorkflowCatalogResource> get(String fieldName, Object value) throws WorkflowCatalogException {
+ List<WorkflowCatalogResource> edgeResources = new ArrayList<WorkflowCatalogResource>();
+ EntityManager em = null;
+ try {
+ em = WorkflowCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ Query q;
+ WorkflowCatalogQueryGenerator generator = new WorkflowCatalogQueryGenerator(EDGE);
+ List results;
+ if (fieldName.equals(EdgeConstants.TEMPLATE_ID)) {
+ generator.setParameter(EdgeConstants.TEMPLATE_ID, value);
+ q = generator.selectQuery(em);
+ results = q.getResultList();
+ if (results.size() != 0) {
+ for (Object result : results) {
+ Edge Edge = (Edge) result;
+ EdgeResource edgeResource =
+ (EdgeResource) WorkflowCatalogJPAUtils.getResource(
+ WorkflowCatalogResourceType.EDGE, Edge);
+ edgeResources.add(edgeResource);
+ }
+ }
+ }else {
+ em.getTransaction().commit();
+ if (em.isOpen()) {
+ if (em.getTransaction().isActive()){
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ logger.error("Unsupported field name for Edge Resource.", new IllegalArgumentException());
+ throw new IllegalArgumentException("Unsupported field name for Edge Resource.");
+ }
+ em.getTransaction().commit();
+ if (em.isOpen()) {
+ if (em.getTransaction().isActive()){
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ } catch (Exception e) {
+ logger.error(e.getMessage(), e);
+ throw new WorkflowCatalogException(e);
+ } finally {
+ if (em != null && em.isOpen()) {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ }
+ return edgeResources;
+ }
+
+ public List<WorkflowCatalogResource> getAll() throws WorkflowCatalogException {
+ return null;
+ }
+
+ public List<String> getAllIds() throws WorkflowCatalogException {
+ return null;
+ }
+
+ public List<String> getIds(String fieldName, Object value) throws WorkflowCatalogException {
+ List<String> edgeResourceIds = new ArrayList<String>();
+ EntityManager em = null;
+ try {
+ em = WorkflowCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ Query q;
+ WorkflowCatalogQueryGenerator generator = new WorkflowCatalogQueryGenerator(EDGE);
+ List results;
+ if (fieldName.equals(EdgeConstants.TEMPLATE_ID)) {
+ generator.setParameter(EdgeConstants.TEMPLATE_ID, value);
+ q = generator.selectQuery(em);
+ results = q.getResultList();
+ if (results.size() != 0) {
+ for (Object result : results) {
+ Edge edge = (Edge) result;
+ edgeResourceIds.add(edge.getTemplateId());
+ }
+ }
+ } else {
+ em.getTransaction().commit();
+ if (em.isOpen()) {
+ if (em.getTransaction().isActive()){
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ logger.error("Unsupported field name for Workflow Edge resource.", new IllegalArgumentException());
+ throw new IllegalArgumentException("Unsupported field name for Workflow Edge Resource.");
+ }
+ em.getTransaction().commit();
+ if (em.isOpen()) {
+ if (em.getTransaction().isActive()){
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ } catch (Exception e) {
+ logger.error(e.getMessage(), e);
+ throw new WorkflowCatalogException(e);
+ } finally {
+ if (em != null && em.isOpen()) {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ }
+ return edgeResourceIds;
+ }
+
+ public void save() throws WorkflowCatalogException {
+ EntityManager em = null;
+ try {
+ em = WorkflowCatalogJPAUtils.getEntityManager();
+ Edge existingEdge = em.find(Edge.class,new Edge_PK(templateId, edgeId));
+ if (em.isOpen()) {
+ if (em.getTransaction().isActive()){
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+
+ em = WorkflowCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ if (existingEdge != null) {
+ existingEdge.setTemplateId(templateId);
+ Workflow workflow = em.find(Workflow.class, templateId);
+ existingEdge.setWorkflow(workflow);
+ existingEdge.setComponentStatusId(statusId);
+ existingEdge.setDescription(description);
+ existingEdge.setName(name);
+ existingEdge.setCreatedTime(createdTime);
+ em.merge(existingEdge);
+ } else {
+ Edge edge = new Edge();
+ edge.setTemplateId(templateId);
+ Workflow workflow = em.find(Workflow.class, templateId);
+ edge.setWorkflow(workflow);
+ edge.setComponentStatusId(statusId);
+ edge.setDescription(description);
+ edge.setName(name);
+ edge.setCreatedTime(AiravataUtils.getCurrentTimestamp());
+ em.persist(edge);
+ }
+ em.getTransaction().commit();
+ if (em.isOpen()) {
+ if (em.getTransaction().isActive()){
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ } catch (Exception e) {
+ logger.error(e.getMessage(), e);
+ throw new WorkflowCatalogException(e);
+ } finally {
+ if (em != null && em.isOpen()) {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ }
+ }
+
+ public boolean isExists(Object identifier) throws WorkflowCatalogException {
+ HashMap<String, String> ids;
+ if (identifier instanceof Map) {
+ ids = (HashMap<String, String>) identifier;
+ } else {
+ logger.error("Identifier should be a map with the field name and it's value");
+ throw new WorkflowCatalogException("Identifier should be a map with the field name and it's value");
+ }
+
+ EntityManager em = null;
+ try {
+ em = WorkflowCatalogJPAUtils.getEntityManager();
+ Edge edge = em.find(Edge.class, new Edge_PK(ids.get(EdgeConstants.TEMPLATE_ID), ids.get(EdgeConstants.EDGE_ID)));
+
+ if (em.isOpen()) {
+ if (em.getTransaction().isActive()){
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ return edge != null;
+ } catch (ApplicationSettingsException e) {
+ logger.error(e.getMessage(), e);
+ throw new WorkflowCatalogException(e);
+ } finally {
+ if (em != null && em.isOpen()) {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ }
+ }
+
+ public String getStatusId() {
+ return statusId;
+ }
+
+ public void setStatusId(String statusId) {
+ this.statusId = statusId;
+ }
+
+ public String getTemplateId() {
+ return templateId;
+ }
+
+ public void setTemplateId(String templateId) {
+ this.templateId = templateId;
+ }
+
+ public Timestamp getCreatedTime() {
+ return createdTime;
+ }
+
+ public void setCreatedTime(Timestamp createdTime) {
+ this.createdTime = createdTime;
+ }
+
+ public String getEdgeId() {
+ return edgeId;
+ }
+
+ public void setEdgeId(String edgeId) {
+ this.edgeId = edgeId;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+}
http://git-wip-us.apache.org/repos/asf/airavata/blob/2a2782a6/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/resources/NodeResource.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/resources/NodeResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/resources/NodeResource.java
new file mode 100644
index 0000000..ea034e7
--- /dev/null
+++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/resources/NodeResource.java
@@ -0,0 +1,402 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.airavata.registry.core.workflow.catalog.resources;
+
+import org.apache.airavata.common.exception.ApplicationSettingsException;
+import org.apache.airavata.common.utils.AiravataUtils;
+import org.apache.airavata.registry.core.workflow.catalog.model.Node;
+import org.apache.airavata.registry.core.workflow.catalog.model.Node_PK;
+import org.apache.airavata.registry.core.workflow.catalog.model.Workflow;
+import org.apache.airavata.registry.core.workflow.catalog.utils.WorkflowCatalogJPAUtils;
+import org.apache.airavata.registry.core.workflow.catalog.utils.WorkflowCatalogQueryGenerator;
+import org.apache.airavata.registry.core.workflow.catalog.utils.WorkflowCatalogResourceType;
+import org.apache.airavata.registry.cpi.WorkflowCatalogException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class NodeResource extends WorkflowCatAbstractResource {
+ private final static Logger logger = LoggerFactory.getLogger(NodeResource.class);
+
+ private String nodeId;
+ private String name;
+ private String statusId;
+ private String templateId;
+ private String applicationId;
+ private String applicationName;
+ private Timestamp createdTime;
+ private String description;
+
+ public void remove(Object identifier) throws WorkflowCatalogException {
+ HashMap<String, String> ids;
+ if (identifier instanceof Map) {
+ ids = (HashMap) identifier;
+ } else {
+ logger.error("Identifier should be a map with the field name and it's value");
+ throw new WorkflowCatalogException("Identifier should be a map with the field name and it's value");
+ }
+
+ EntityManager em = null;
+ try {
+ em = WorkflowCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ WorkflowCatalogQueryGenerator generator = new WorkflowCatalogQueryGenerator(NODE);
+ generator.setParameter(NodeConstants.NODE_ID, ids.get(NodeConstants.NODE_ID));
+ generator.setParameter(NodeConstants.TEMPLATE_ID, ids.get(NodeConstants.TEMPLATE_ID));
+ Query q = generator.deleteQuery(em);
+ q.executeUpdate();
+ em.getTransaction().commit();
+ if (em.isOpen()) {
+ if (em.getTransaction().isActive()){
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ } catch (ApplicationSettingsException e) {
+ logger.error(e.getMessage(), e);
+ throw new WorkflowCatalogException(e);
+ } finally {
+ if (em != null && em.isOpen()) {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ }
+ }
+
+ public WorkflowCatalogResource get(Object identifier) throws WorkflowCatalogException {
+ HashMap<String, String> ids;
+ if (identifier instanceof Map) {
+ ids = (HashMap<String, String>) identifier;
+ } else {
+ logger.error("Identifier should be a map with the field name and it's value");
+ throw new WorkflowCatalogException("Identifier should be a map with the field name and it's value");
+ }
+
+ EntityManager em = null;
+ try {
+ em = WorkflowCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ WorkflowCatalogQueryGenerator generator = new WorkflowCatalogQueryGenerator(NODE);
+ generator.setParameter(NodeConstants.NODE_ID, ids.get(NodeConstants.NODE_ID));
+ generator.setParameter(NodeConstants.TEMPLATE_ID, ids.get(NodeConstants.TEMPLATE_ID));
+ Query q = generator.selectQuery(em);
+ Node node = (Node) q.getSingleResult();
+ NodeResource nodeResource =
+ (NodeResource) WorkflowCatalogJPAUtils.getResource(WorkflowCatalogResourceType.NODE
+ , node);
+ em.getTransaction().commit();
+ if (em.isOpen()) {
+ if (em.getTransaction().isActive()){
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ return nodeResource;
+ } catch (ApplicationSettingsException e) {
+ logger.error(e.getMessage(), e);
+ throw new WorkflowCatalogException(e);
+ } finally {
+ if (em != null && em.isOpen()) {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ }
+ }
+
+ public List<WorkflowCatalogResource> get(String fieldName, Object value) throws WorkflowCatalogException {
+ List<WorkflowCatalogResource> nodeResources = new ArrayList<WorkflowCatalogResource>();
+ EntityManager em = null;
+ try {
+ em = WorkflowCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ Query q;
+ WorkflowCatalogQueryGenerator generator = new WorkflowCatalogQueryGenerator(NODE);
+ List results;
+ if (fieldName.equals(NodeConstants.TEMPLATE_ID)) {
+ generator.setParameter(NodeConstants.TEMPLATE_ID, value);
+ q = generator.selectQuery(em);
+ results = q.getResultList();
+ if (results.size() != 0) {
+ for (Object result : results) {
+ Node node = (Node) result;
+ NodeResource nodeResource =
+ (NodeResource) WorkflowCatalogJPAUtils.getResource(
+ WorkflowCatalogResourceType.NODE, node);
+ nodeResources.add(nodeResource);
+ }
+ }
+ }else {
+ em.getTransaction().commit();
+ if (em.isOpen()) {
+ if (em.getTransaction().isActive()){
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ logger.error("Unsupported field name for Node Resource.", new IllegalArgumentException());
+ throw new IllegalArgumentException("Unsupported field name for Node Resource.");
+ }
+ em.getTransaction().commit();
+ if (em.isOpen()) {
+ if (em.getTransaction().isActive()){
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ } catch (Exception e) {
+ logger.error(e.getMessage(), e);
+ throw new WorkflowCatalogException(e);
+ } finally {
+ if (em != null && em.isOpen()) {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ }
+ return nodeResources;
+ }
+
+ public List<WorkflowCatalogResource> getAll() throws WorkflowCatalogException {
+ return null;
+ }
+
+ public List<String> getAllIds() throws WorkflowCatalogException {
+ return null;
+ }
+
+ public List<String> getIds(String fieldName, Object value) throws WorkflowCatalogException {
+ List<String> nodeResourceIds = new ArrayList<String>();
+ EntityManager em = null;
+ try {
+ em = WorkflowCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ Query q;
+ WorkflowCatalogQueryGenerator generator = new WorkflowCatalogQueryGenerator(NODE);
+ List results;
+ if (fieldName.equals(NodeConstants.TEMPLATE_ID)) {
+ generator.setParameter(NodeConstants.TEMPLATE_ID, value);
+ q = generator.selectQuery(em);
+ results = q.getResultList();
+ if (results.size() != 0) {
+ for (Object result : results) {
+ Node node = (Node) result;
+ nodeResourceIds.add(node.getTemplateId());
+ }
+ }
+ } else {
+ em.getTransaction().commit();
+ if (em.isOpen()) {
+ if (em.getTransaction().isActive()){
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ logger.error("Unsupported field name for Workflow node resource.", new IllegalArgumentException());
+ throw new IllegalArgumentException("Unsupported field name for Workflow node Resource.");
+ }
+ em.getTransaction().commit();
+ if (em.isOpen()) {
+ if (em.getTransaction().isActive()){
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ } catch (Exception e) {
+ logger.error(e.getMessage(), e);
+ throw new WorkflowCatalogException(e);
+ } finally {
+ if (em != null && em.isOpen()) {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ }
+ return nodeResourceIds;
+ }
+
+ public void save() throws WorkflowCatalogException {
+ EntityManager em = null;
+ try {
+ em = WorkflowCatalogJPAUtils.getEntityManager();
+ Node existingNode = em.find(Node.class,new Node_PK(templateId, nodeId));
+ if (em.isOpen()) {
+ if (em.getTransaction().isActive()){
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+
+ em = WorkflowCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ if (existingNode != null) {
+ existingNode.setTemplateId(templateId);
+ Workflow workflow = em.find(Workflow.class, templateId);
+ existingNode.setWorkflow(workflow);
+ existingNode.setComponentStatusId(statusId);
+ existingNode.setDescription(description);
+ existingNode.setName(name);
+ existingNode.setCreatedTime(createdTime);
+ existingNode.setApplicationName(applicationName);
+ existingNode.setApplicationId(applicationId);
+ em.merge(existingNode);
+ } else {
+ Node node = new Node();
+ node.setTemplateId(templateId);
+ Workflow workflow = em.find(Workflow.class, templateId);
+ node.setWorkflow(workflow);
+ node.setComponentStatusId(statusId);
+ node.setDescription(description);
+ node.setName(name);
+ node.setCreatedTime(AiravataUtils.getCurrentTimestamp());
+ node.setApplicationName(applicationName);
+ node.setApplicationId(applicationId);
+ em.persist(node);
+ }
+ em.getTransaction().commit();
+ if (em.isOpen()) {
+ if (em.getTransaction().isActive()){
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ } catch (Exception e) {
+ logger.error(e.getMessage(), e);
+ throw new WorkflowCatalogException(e);
+ } finally {
+ if (em != null && em.isOpen()) {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ }
+ }
+
+ public boolean isExists(Object identifier) throws WorkflowCatalogException {
+ HashMap<String, String> ids;
+ if (identifier instanceof Map) {
+ ids = (HashMap<String, String>) identifier;
+ } else {
+ logger.error("Identifier should be a map with the field name and it's value");
+ throw new WorkflowCatalogException("Identifier should be a map with the field name and it's value");
+ }
+
+ EntityManager em = null;
+ try {
+ em = WorkflowCatalogJPAUtils.getEntityManager();
+ Node port = em.find(Node.class, new Node_PK(ids.get(NodeConstants.TEMPLATE_ID), ids.get(NodeConstants.NODE_ID)));
+
+ if (em.isOpen()) {
+ if (em.getTransaction().isActive()){
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ return port != null;
+ } catch (ApplicationSettingsException e) {
+ logger.error(e.getMessage(), e);
+ throw new WorkflowCatalogException(e);
+ } finally {
+ if (em != null && em.isOpen()) {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ }
+ }
+
+ public String getStatusId() {
+ return statusId;
+ }
+
+ public void setStatusId(String statusId) {
+ this.statusId = statusId;
+ }
+
+ public String getTemplateId() {
+ return templateId;
+ }
+
+ public void setTemplateId(String templateId) {
+ this.templateId = templateId;
+ }
+
+ public Timestamp getCreatedTime() {
+ return createdTime;
+ }
+
+ public void setCreatedTime(Timestamp createdTime) {
+ this.createdTime = createdTime;
+ }
+
+ public String getNodeId() {
+ return nodeId;
+ }
+
+ public void setNodeId(String nodeId) {
+ this.nodeId = nodeId;
+ }
+
+ public String getApplicationId() {
+ return applicationId;
+ }
+
+ public void setApplicationId(String applicationId) {
+ this.applicationId = applicationId;
+ }
+
+ public String getApplicationName() {
+ return applicationName;
+ }
+
+ public void setApplicationName(String applicationName) {
+ this.applicationName = applicationName;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+}
http://git-wip-us.apache.org/repos/asf/airavata/blob/2a2782a6/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/resources/PortResource.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/resources/PortResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/resources/PortResource.java
new file mode 100644
index 0000000..9cdaebf
--- /dev/null
+++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/resources/PortResource.java
@@ -0,0 +1,380 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.airavata.registry.core.workflow.catalog.resources;
+
+import org.apache.airavata.common.exception.ApplicationSettingsException;
+import org.apache.airavata.common.utils.AiravataUtils;
+import org.apache.airavata.registry.core.workflow.catalog.model.Port;
+import org.apache.airavata.registry.core.workflow.catalog.model.Port_PK;
+import org.apache.airavata.registry.core.workflow.catalog.model.Workflow;
+import org.apache.airavata.registry.core.workflow.catalog.utils.WorkflowCatalogJPAUtils;
+import org.apache.airavata.registry.core.workflow.catalog.utils.WorkflowCatalogQueryGenerator;
+import org.apache.airavata.registry.core.workflow.catalog.utils.WorkflowCatalogResourceType;
+import org.apache.airavata.registry.cpi.WorkflowCatalogException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class PortResource extends WorkflowCatAbstractResource {
+ private final static Logger logger = LoggerFactory.getLogger(PortResource.class);
+
+ private String portId;
+ private String name;
+ private String statusId;
+ private String templateId;
+ private Timestamp createdTime;
+ private String description;
+
+ public void remove(Object identifier) throws WorkflowCatalogException {
+ HashMap<String, String> ids;
+ if (identifier instanceof Map) {
+ ids = (HashMap) identifier;
+ } else {
+ logger.error("Identifier should be a map with the field name and it's value");
+ throw new WorkflowCatalogException("Identifier should be a map with the field name and it's value");
+ }
+
+ EntityManager em = null;
+ try {
+ em = WorkflowCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ WorkflowCatalogQueryGenerator generator = new WorkflowCatalogQueryGenerator(PORT);
+ generator.setParameter(PortConstants.PORT_ID, ids.get(PortConstants.PORT_ID));
+ generator.setParameter(PortConstants.TEMPLATE_ID, ids.get(PortConstants.TEMPLATE_ID));
+ Query q = generator.deleteQuery(em);
+ q.executeUpdate();
+ em.getTransaction().commit();
+ if (em.isOpen()) {
+ if (em.getTransaction().isActive()){
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ } catch (ApplicationSettingsException e) {
+ logger.error(e.getMessage(), e);
+ throw new WorkflowCatalogException(e);
+ } finally {
+ if (em != null && em.isOpen()) {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ }
+ }
+
+ public WorkflowCatalogResource get(Object identifier) throws WorkflowCatalogException {
+ HashMap<String, String> ids;
+ if (identifier instanceof Map) {
+ ids = (HashMap<String, String>) identifier;
+ } else {
+ logger.error("Identifier should be a map with the field name and it's value");
+ throw new WorkflowCatalogException("Identifier should be a map with the field name and it's value");
+ }
+
+ EntityManager em = null;
+ try {
+ em = WorkflowCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ WorkflowCatalogQueryGenerator generator = new WorkflowCatalogQueryGenerator(PORT);
+ generator.setParameter(PortConstants.PORT_ID, ids.get(PortConstants.PORT_ID));
+ generator.setParameter(PortConstants.TEMPLATE_ID, ids.get(PortConstants.TEMPLATE_ID));
+ Query q = generator.selectQuery(em);
+ Port port = (Port) q.getSingleResult();
+ PortResource portResource =
+ (PortResource) WorkflowCatalogJPAUtils.getResource(WorkflowCatalogResourceType.PORT
+ , port);
+ em.getTransaction().commit();
+ if (em.isOpen()) {
+ if (em.getTransaction().isActive()){
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ return portResource;
+ } catch (ApplicationSettingsException e) {
+ logger.error(e.getMessage(), e);
+ throw new WorkflowCatalogException(e);
+ } finally {
+ if (em != null && em.isOpen()) {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ }
+ }
+
+ public List<WorkflowCatalogResource> get(String fieldName, Object value) throws WorkflowCatalogException {
+ List<WorkflowCatalogResource> portResources = new ArrayList<WorkflowCatalogResource>();
+ EntityManager em = null;
+ try {
+ em = WorkflowCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ Query q;
+ WorkflowCatalogQueryGenerator generator = new WorkflowCatalogQueryGenerator(PORT);
+ List results;
+ if (fieldName.equals(PortConstants.TEMPLATE_ID)) {
+ generator.setParameter(PortConstants.TEMPLATE_ID, value);
+ q = generator.selectQuery(em);
+ results = q.getResultList();
+ if (results.size() != 0) {
+ for (Object result : results) {
+ Port port = (Port) result;
+ PortResource portResource =
+ (PortResource) WorkflowCatalogJPAUtils.getResource(
+ WorkflowCatalogResourceType.PORT, port);
+ portResources.add(portResource);
+ }
+ }
+ }else {
+ em.getTransaction().commit();
+ if (em.isOpen()) {
+ if (em.getTransaction().isActive()){
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ logger.error("Unsupported field name for Port Resource.", new IllegalArgumentException());
+ throw new IllegalArgumentException("Unsupported field name for Port Resource.");
+ }
+ em.getTransaction().commit();
+ if (em.isOpen()) {
+ if (em.getTransaction().isActive()){
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ } catch (Exception e) {
+ logger.error(e.getMessage(), e);
+ throw new WorkflowCatalogException(e);
+ } finally {
+ if (em != null && em.isOpen()) {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ }
+ return portResources;
+ }
+
+ public List<WorkflowCatalogResource> getAll() throws WorkflowCatalogException {
+ return null;
+ }
+
+ public List<String> getAllIds() throws WorkflowCatalogException {
+ return null;
+ }
+
+ public List<String> getIds(String fieldName, Object value) throws WorkflowCatalogException {
+ List<String> portResourceIds = new ArrayList<String>();
+ EntityManager em = null;
+ try {
+ em = WorkflowCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ Query q;
+ WorkflowCatalogQueryGenerator generator = new WorkflowCatalogQueryGenerator(PORT);
+ List results;
+ if (fieldName.equals(PortConstants.TEMPLATE_ID)) {
+ generator.setParameter(PortConstants.TEMPLATE_ID, value);
+ q = generator.selectQuery(em);
+ results = q.getResultList();
+ if (results.size() != 0) {
+ for (Object result : results) {
+ Port port = (Port) result;
+ portResourceIds.add(port.getTemplateId());
+ }
+ }
+ } else {
+ em.getTransaction().commit();
+ if (em.isOpen()) {
+ if (em.getTransaction().isActive()){
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ logger.error("Unsupported field name for Workflow port resource.", new IllegalArgumentException());
+ throw new IllegalArgumentException("Unsupported field name for Workflow port Resource.");
+ }
+ em.getTransaction().commit();
+ if (em.isOpen()) {
+ if (em.getTransaction().isActive()){
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ } catch (Exception e) {
+ logger.error(e.getMessage(), e);
+ throw new WorkflowCatalogException(e);
+ } finally {
+ if (em != null && em.isOpen()) {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ }
+ return portResourceIds;
+ }
+
+ public void save() throws WorkflowCatalogException {
+ EntityManager em = null;
+ try {
+ em = WorkflowCatalogJPAUtils.getEntityManager();
+ Port existingPort = em.find(Port.class,new Port_PK(templateId, portId));
+ if (em.isOpen()) {
+ if (em.getTransaction().isActive()){
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+
+ em = WorkflowCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ if (existingPort != null) {
+ existingPort.setTemplateId(templateId);
+ Workflow workflow = em.find(Workflow.class, templateId);
+ existingPort.setWorkflow(workflow);
+ existingPort.setComponentStatusId(statusId);
+ existingPort.setDescription(description);
+ existingPort.setName(name);
+ existingPort.setCreatedTime(createdTime);
+ em.merge(existingPort);
+ } else {
+ Port edge = new Port();
+ edge.setTemplateId(templateId);
+ Workflow workflow = em.find(Workflow.class, templateId);
+ edge.setWorkflow(workflow);
+ edge.setComponentStatusId(statusId);
+ edge.setDescription(description);
+ edge.setName(name);
+ edge.setCreatedTime(AiravataUtils.getCurrentTimestamp());
+ em.persist(edge);
+ }
+ em.getTransaction().commit();
+ if (em.isOpen()) {
+ if (em.getTransaction().isActive()){
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ } catch (Exception e) {
+ logger.error(e.getMessage(), e);
+ throw new WorkflowCatalogException(e);
+ } finally {
+ if (em != null && em.isOpen()) {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ }
+ }
+
+ public boolean isExists(Object identifier) throws WorkflowCatalogException {
+ HashMap<String, String> ids;
+ if (identifier instanceof Map) {
+ ids = (HashMap<String, String>) identifier;
+ } else {
+ logger.error("Identifier should be a map with the field name and it's value");
+ throw new WorkflowCatalogException("Identifier should be a map with the field name and it's value");
+ }
+
+ EntityManager em = null;
+ try {
+ em = WorkflowCatalogJPAUtils.getEntityManager();
+ Port port = em.find(Port.class, new Port_PK(ids.get(PortConstants.TEMPLATE_ID), ids.get(PortConstants.PORT_ID)));
+
+ if (em.isOpen()) {
+ if (em.getTransaction().isActive()){
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ return port != null;
+ } catch (ApplicationSettingsException e) {
+ logger.error(e.getMessage(), e);
+ throw new WorkflowCatalogException(e);
+ } finally {
+ if (em != null && em.isOpen()) {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ }
+ }
+
+ public String getStatusId() {
+ return statusId;
+ }
+
+ public void setStatusId(String statusId) {
+ this.statusId = statusId;
+ }
+
+ public String getTemplateId() {
+ return templateId;
+ }
+
+ public void setTemplateId(String templateId) {
+ this.templateId = templateId;
+ }
+
+ public Timestamp getCreatedTime() {
+ return createdTime;
+ }
+
+ public void setCreatedTime(Timestamp createdTime) {
+ this.createdTime = createdTime;
+ }
+
+ public String getPortId() {
+ return portId;
+ }
+
+ public void setPortId(String portId) {
+ this.portId = portId;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+}
http://git-wip-us.apache.org/repos/asf/airavata/blob/2a2782a6/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/resources/WorkflowCatAbstractResource.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/resources/WorkflowCatAbstractResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/resources/WorkflowCatAbstractResource.java
new file mode 100644
index 0000000..cb90fe9
--- /dev/null
+++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/resources/WorkflowCatAbstractResource.java
@@ -0,0 +1,88 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.registry.core.workflow.catalog.resources;
+
+public abstract class WorkflowCatAbstractResource implements WorkflowCatalogResource {
+ // table names
+ public static final String WORKFLOW = "Workflow";
+ public static final String WORKFLOW_INPUT = "WorkflowInput";
+ public static final String WORKFLOW_OUTPUT = "WorkflowOutput";
+ public static final String EDGE = "Edge";
+ public static final String NODE = "Node";
+ public static final String PORT = "Port";
+ public static final String COMPONENT_STATUS = "ComponentStatus";
+ public static final String WORKFLOW_STATUS = "WorkflowStatus";
+
+ public final class WorkflowInputConstants {
+ public static final String WF_TEMPLATE_ID = "templateID";
+ public static final String INPUT_KEY = "inputKey";
+ public static final String INPUT_VALUE = "inputVal";
+ public static final String DATA_TYPE = "dataType";
+ public static final String METADATA = "metadata";
+ public static final String APP_ARGUMENT = "appArgument";
+ public static final String USER_FRIENDLY_DESC = "userFriendlyDesc";
+ public static final String STANDARD_INPUT = "standardInput";
+ }
+
+ public final class WorkflowOutputConstants {
+ public static final String WF_TEMPLATE_ID = "templateId";
+ public static final String OUTPUT_KEY = "outputKey";
+ public static final String OUTPUT_VALUE = "outputVal";
+ public static final String DATA_TYPE = "dataType";
+ }
+
+ // Workflow Table
+ public final class WorkflowConstants {
+ public static final String TEMPLATE_ID = "templateId";
+ public static final String GATEWAY_ID = "gatewayId";
+ public static final String WORKFLOW_NAME = "workflowName";
+ }
+
+ public final class ComponentStatusConstants {
+ public static final String STATUS_ID = "statusId";
+ public static final String TEMPLATE_ID = "templateId";
+ }
+
+ public final class WorkflowStatusConstants {
+ public static final String STATUS_ID = "statusId";
+ public static final String TEMPLATE_ID = "templateId";
+ }
+
+ public final class EdgeConstants {
+ public static final String STATUS_ID = "statusId";
+ public static final String TEMPLATE_ID = "templateId";
+ public static final String EDGE_ID = "edgeId";
+ }
+
+ public final class PortConstants {
+ public static final String STATUS_ID = "statusId";
+ public static final String TEMPLATE_ID = "templateId";
+ public static final String PORT_ID = "portId";
+ }
+
+ public final class NodeConstants {
+ public static final String STATUS_ID = "statusId";
+ public static final String TEMPLATE_ID = "templateId";
+ public static final String NODE_ID = "nodeId";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/airavata/blob/2a2782a6/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/resources/WorkflowCatalogResource.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/resources/WorkflowCatalogResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/resources/WorkflowCatalogResource.java
new file mode 100644
index 0000000..d536776
--- /dev/null
+++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/resources/WorkflowCatalogResource.java
@@ -0,0 +1,90 @@
+/*
+*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*
+*/
+package org.apache.airavata.registry.core.workflow.catalog.resources;
+
+
+import org.apache.airavata.registry.cpi.WorkflowCatalogException;
+
+import java.util.List;
+
+public interface WorkflowCatalogResource {
+
+ /**
+ * This method will remove the given resource from the database
+ *
+ * @param identifier identifier that can uniquely identify a single instance of the resource
+ */
+ void remove(Object identifier) throws WorkflowCatalogException;
+
+ /**
+ * This method will return the given resource from the database
+ *
+ * @param identifier identifier that can uniquely identify a single instance of the resource
+ * @return associate resource
+ */
+ WorkflowCatalogResource get(Object identifier) throws WorkflowCatalogException;
+
+ /**
+ * This method will list all the resources according to the filtering criteria
+ * @param fieldName field name
+ * @param value value of the field
+ * @return list of resources
+ */
+ List<WorkflowCatalogResource> get(String fieldName, Object value) throws WorkflowCatalogException;
+
+ /**
+ *
+ * @return
+ * @throws org.apache.airavata.registry.cpi.WorkflowCatalogException
+ */
+ List<WorkflowCatalogResource> getAll() throws WorkflowCatalogException;
+
+ /**
+ *
+ * @return
+ * @throws org.apache.airavata.registry.cpi.WorkflowCatalogException
+ */
+ List<String> getAllIds() throws WorkflowCatalogException;
+
+ /** This method will return list of resource ids according to given criteria
+ * @param fieldName field name
+ * @param value value of the field
+ * @return list of resource Ids
+ * @throws org.apache.airavata.registry.cpi.WorkflowCatalogException
+ */
+ List<String> getIds(String fieldName, Object value) throws WorkflowCatalogException;
+
+ /**
+ * This method will save the resource to the database.
+ */
+ void save() throws WorkflowCatalogException;
+
+ /**
+ * This method will check whether an entry from the given resource and resource name
+ * exists in the database
+ *
+ * @param identifier identifier that can uniquely identify a single instance of the resource
+ * @return whether the entry exists in the database or not
+ */
+ boolean isExists(Object identifier) throws WorkflowCatalogException;
+
+
+}