http://git-wip-us.apache.org/repos/asf/airavata/blob/ec8c6202/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/WorkflowInputAppCatalogResourceAppCat.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/WorkflowInputAppCatalogResourceAppCat.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/WorkflowInputAppCatalogResourceAppCat.java new file mode 100644 index 0000000..89a34f4 --- /dev/null +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/WorkflowInputAppCatalogResourceAppCat.java @@ -0,0 +1,451 @@ +/** + * 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.app.catalog.resources; + +import org.apache.airavata.common.exception.ApplicationSettingsException; +import org.apache.airavata.registry.core.app.catalog.model.Workflow; +import org.apache.airavata.registry.core.app.catalog.model.WorkflowInput; +import org.apache.airavata.registry.core.app.catalog.model.WorkflowInput_PK; +import org.apache.airavata.registry.core.app.catalog.util.AppCatalogJPAUtils; +import org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator; +import org.apache.airavata.registry.core.app.catalog.util.AppCatalogResourceType; +import org.apache.airavata.registry.cpi.AppCatalogException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.persistence.EntityManager; +import javax.persistence.Query; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class WorkflowInputAppCatalogResourceAppCat extends AppCatAbstractResource { + + private final static Logger logger = LoggerFactory.getLogger(WorkflowInputAppCatalogResourceAppCat.class); + + private String wfTemplateId; + private String inputKey; + private String dataType; + private String inputVal; + private String metadata; + private String appArgument; + private String userFriendlyDesc; + private boolean standardInput; + private int inputOrder; + private boolean isRequired; + private boolean requiredToCMD; + private boolean dataStaged; + + private WorkflowAppCatalogResourceAppCat workflowResource; + + public void remove(Object identifier) throws AppCatalogException { + 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 AppCatalogException("Identifier should be a map with the field name and it's value"); + } + + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(WORKFLOW_INPUT); + generator.setParameter(WFInputConstants.WF_TEMPLATE_ID, ids.get(WFInputConstants.WF_TEMPLATE_ID)); + generator.setParameter(WFInputConstants.INPUT_KEY, ids.get(WFInputConstants.INPUT_KEY)); + Query q = generator.deleteQuery(em); + q.executeUpdate(); + em.getTransaction().commit(); + em.close(); + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + public AppCatalogResource get(Object identifier) throws AppCatalogException { + 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 AppCatalogException("Identifier should be a map with the field name and it's value"); + } + + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(WORKFLOW_INPUT); + generator.setParameter(WFInputConstants.WF_TEMPLATE_ID, ids.get(WFInputConstants.WF_TEMPLATE_ID)); + generator.setParameter(WFInputConstants.INPUT_KEY, ids.get(WFInputConstants.INPUT_KEY)); + Query q = generator.selectQuery(em); + WorkflowInput workflowInput = (WorkflowInput) q.getSingleResult(); + WorkflowInputAppCatalogResourceAppCat workflowInputResource = + (WorkflowInputAppCatalogResourceAppCat) AppCatalogJPAUtils.getResource(AppCatalogResourceType.WORKFLOW_INPUT + , workflowInput); + em.getTransaction().commit(); + em.close(); + return workflowInputResource; + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + public List<AppCatalogResource> get(String fieldName, Object value) throws AppCatalogException { + List<AppCatalogResource> wfInputResources = new ArrayList<AppCatalogResource>(); + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + Query q; + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(WORKFLOW_INPUT); + List results; + if (fieldName.equals(WFInputConstants.WF_TEMPLATE_ID)) { + generator.setParameter(WFInputConstants.WF_TEMPLATE_ID, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + WorkflowInput workflowInput = (WorkflowInput) result; + WorkflowInputAppCatalogResourceAppCat workflowInputResource = + (WorkflowInputAppCatalogResourceAppCat) AppCatalogJPAUtils.getResource( + AppCatalogResourceType.WORKFLOW_INPUT, workflowInput); + wfInputResources.add(workflowInputResource); + } + } + } else if (fieldName.equals(WFInputConstants.INPUT_KEY)) { + generator.setParameter(WFInputConstants.INPUT_KEY, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + WorkflowInput workflowInput = (WorkflowInput) result; + WorkflowInputAppCatalogResourceAppCat workflowInputResource = + (WorkflowInputAppCatalogResourceAppCat) AppCatalogJPAUtils.getResource( + AppCatalogResourceType.WORKFLOW_INPUT, workflowInput); + wfInputResources.add(workflowInputResource); + } + } + } else if (fieldName.equals(WFInputConstants.DATA_TYPE)) { + generator.setParameter(WFInputConstants.DATA_TYPE, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + WorkflowInput workflowInput = (WorkflowInput) result; + WorkflowInputAppCatalogResourceAppCat workflowInputResource = + (WorkflowInputAppCatalogResourceAppCat) AppCatalogJPAUtils.getResource( + AppCatalogResourceType.WORKFLOW_INPUT, workflowInput); + wfInputResources.add(workflowInputResource); + } + } + } else { + em.getTransaction().commit(); + em.close(); + logger.error("Unsupported field name for WFInput Resource.", new IllegalArgumentException()); + throw new IllegalArgumentException("Unsupported field name for WFInput Resource."); + } + em.getTransaction().commit(); + em.close(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + return wfInputResources; + } + + public List<AppCatalogResource> getAll() throws AppCatalogException { + return null; + } + + public List<String> getAllIds() throws AppCatalogException { + return null; + } + + public List<String> getIds(String fieldName, Object value) throws AppCatalogException { + List<String> wfInputResourceIDs = new ArrayList<String>(); + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + Query q; + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(WORKFLOW_INPUT); + List results; + if (fieldName.equals(WFInputConstants.WF_TEMPLATE_ID)) { + generator.setParameter(WFInputConstants.WF_TEMPLATE_ID, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + WorkflowInput workflowInput = (WorkflowInput) result; + wfInputResourceIDs.add(workflowInput.getWfTemplateId()); + } + } + } else if (fieldName.equals(WFInputConstants.INPUT_KEY)) { + generator.setParameter(WFInputConstants.INPUT_KEY, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + WorkflowInput workflowInput = (WorkflowInput) result; + wfInputResourceIDs.add(workflowInput.getWfTemplateId()); + } + } + } else if (fieldName.equals(WFInputConstants.DATA_TYPE)) { + generator.setParameter(WFInputConstants.DATA_TYPE, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + WorkflowInput workflowInput = (WorkflowInput) result; + wfInputResourceIDs.add(workflowInput.getWfTemplateId()); + } + } + } else { + em.getTransaction().commit(); + em.close(); + logger.error("Unsupported field name for WFInput resource.", new IllegalArgumentException()); + throw new IllegalArgumentException("Unsupported field name for WFInput Resource."); + } + em.getTransaction().commit(); + em.close(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + return wfInputResourceIDs; + } + + public void save() throws AppCatalogException { + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + WorkflowInput existingWFInput = em.find(WorkflowInput.class, new WorkflowInput_PK(wfTemplateId, inputKey)); + em.close(); + WorkflowInput workflowInput; + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + if (existingWFInput == null) { + workflowInput = new WorkflowInput(); + } else { + workflowInput=existingWFInput; + } + workflowInput.setWfTemplateId(wfTemplateId); + Workflow workflow = em.find(Workflow.class, wfTemplateId); + workflowInput.setWorkflow(workflow); + workflowInput.setDataType(dataType); + workflowInput.setInputKey(inputKey); + if (inputVal != null){ + workflowInput.setInputVal(inputVal.toCharArray()); + } + workflowInput.setMetadata(metadata); + workflowInput.setAppArgument(appArgument); + workflowInput.setUserFriendlyDesc(userFriendlyDesc); + workflowInput.setStandardInput(standardInput); + workflowInput.setRequiredToCMD(requiredToCMD); + workflowInput.setRequired(isRequired); + workflowInput.setDataStaged(dataStaged); + if (existingWFInput == null) { + em.persist(workflowInput); + } else { + em.merge(workflowInput); + } + em.getTransaction().commit(); + em.close(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + public boolean isExists(Object identifier) throws AppCatalogException { + 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 AppCatalogException("Identifier should be a map with the field name and it's value"); + } + + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + WorkflowInput workflowInput = em.find(WorkflowInput.class, new WorkflowInput_PK( + ids.get(WFInputConstants.WF_TEMPLATE_ID), + ids.get(WFInputConstants.INPUT_KEY))); + + em.close(); + return workflowInput != null; + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + public String getWfTemplateId() { + return wfTemplateId; + } + + public void setWfTemplateId(String wfTemplateId) { + this.wfTemplateId = wfTemplateId; + } + + public String getInputKey() { + return inputKey; + } + + public void setInputKey(String inputKey) { + this.inputKey = inputKey; + } + + public String getDataType() { + return dataType; + } + + public void setDataType(String dataType) { + this.dataType = dataType; + } + + public String getInputVal() { + return inputVal; + } + + public void setInputVal(String inputVal) { + this.inputVal = inputVal; + } + + 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 WorkflowAppCatalogResourceAppCat getWorkflowResource() { + return workflowResource; + } + + public void setWorkflowResource(WorkflowAppCatalogResourceAppCat workflowResource) { + this.workflowResource = workflowResource; + } + + 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 getRequired() { + return isRequired; + } + + public void setRequired(boolean required) { + this.isRequired = required; + } + + public boolean getRequiredToCMD() { + 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/ec8c6202/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/WorkflowInputResource.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/WorkflowInputResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/WorkflowInputResource.java new file mode 100644 index 0000000..ac22744 --- /dev/null +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/WorkflowInputResource.java @@ -0,0 +1,451 @@ +/** + * 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.aiaravata.application.catalog.data.resources; + +import org.airavata.appcatalog.cpi.AppCatalogException; +import org.apache.aiaravata.application.catalog.data.model.Workflow; +import org.apache.aiaravata.application.catalog.data.model.WorkflowInput; +import org.apache.aiaravata.application.catalog.data.model.WorkflowInput_PK; +import org.apache.aiaravata.application.catalog.data.util.AppCatalogJPAUtils; +import org.apache.aiaravata.application.catalog.data.util.AppCatalogQueryGenerator; +import org.apache.aiaravata.application.catalog.data.util.AppCatalogResourceType; +import org.apache.airavata.common.exception.ApplicationSettingsException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.persistence.EntityManager; +import javax.persistence.Query; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class WorkflowInputResource extends AbstractResource { + + private final static Logger logger = LoggerFactory.getLogger(WorkflowInputResource.class); + + private String wfTemplateId; + private String inputKey; + private String dataType; + private String inputVal; + private String metadata; + private String appArgument; + private String userFriendlyDesc; + private boolean standardInput; + private int inputOrder; + private boolean isRequired; + private boolean requiredToCMD; + private boolean dataStaged; + + private WorkflowResource workflowResource; + + public void remove(Object identifier) throws AppCatalogException { + 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 AppCatalogException("Identifier should be a map with the field name and it's value"); + } + + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(WORKFLOW_INPUT); + generator.setParameter(WFInputConstants.WF_TEMPLATE_ID, ids.get(WFInputConstants.WF_TEMPLATE_ID)); + generator.setParameter(WFInputConstants.INPUT_KEY, ids.get(WFInputConstants.INPUT_KEY)); + Query q = generator.deleteQuery(em); + q.executeUpdate(); + em.getTransaction().commit(); + em.close(); + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + public Resource get(Object identifier) throws AppCatalogException { + 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 AppCatalogException("Identifier should be a map with the field name and it's value"); + } + + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(WORKFLOW_INPUT); + generator.setParameter(WFInputConstants.WF_TEMPLATE_ID, ids.get(WFInputConstants.WF_TEMPLATE_ID)); + generator.setParameter(WFInputConstants.INPUT_KEY, ids.get(WFInputConstants.INPUT_KEY)); + Query q = generator.selectQuery(em); + WorkflowInput workflowInput = (WorkflowInput) q.getSingleResult(); + WorkflowInputResource workflowInputResource = + (WorkflowInputResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.WORKFLOW_INPUT + , workflowInput); + em.getTransaction().commit(); + em.close(); + return workflowInputResource; + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + public List<Resource> get(String fieldName, Object value) throws AppCatalogException { + List<Resource> wfInputResources = new ArrayList<Resource>(); + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + Query q; + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(WORKFLOW_INPUT); + List results; + if (fieldName.equals(WFInputConstants.WF_TEMPLATE_ID)) { + generator.setParameter(WFInputConstants.WF_TEMPLATE_ID, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + WorkflowInput workflowInput = (WorkflowInput) result; + WorkflowInputResource workflowInputResource = + (WorkflowInputResource) AppCatalogJPAUtils.getResource( + AppCatalogResourceType.WORKFLOW_INPUT, workflowInput); + wfInputResources.add(workflowInputResource); + } + } + } else if (fieldName.equals(WFInputConstants.INPUT_KEY)) { + generator.setParameter(WFInputConstants.INPUT_KEY, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + WorkflowInput workflowInput = (WorkflowInput) result; + WorkflowInputResource workflowInputResource = + (WorkflowInputResource) AppCatalogJPAUtils.getResource( + AppCatalogResourceType.WORKFLOW_INPUT, workflowInput); + wfInputResources.add(workflowInputResource); + } + } + } else if (fieldName.equals(WFInputConstants.DATA_TYPE)) { + generator.setParameter(WFInputConstants.DATA_TYPE, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + WorkflowInput workflowInput = (WorkflowInput) result; + WorkflowInputResource workflowInputResource = + (WorkflowInputResource) AppCatalogJPAUtils.getResource( + AppCatalogResourceType.WORKFLOW_INPUT, workflowInput); + wfInputResources.add(workflowInputResource); + } + } + } else { + em.getTransaction().commit(); + em.close(); + logger.error("Unsupported field name for WFInput Resource.", new IllegalArgumentException()); + throw new IllegalArgumentException("Unsupported field name for WFInput Resource."); + } + em.getTransaction().commit(); + em.close(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + return wfInputResources; + } + + public List<Resource> getAll() throws AppCatalogException { + return null; + } + + public List<String> getAllIds() throws AppCatalogException { + return null; + } + + public List<String> getIds(String fieldName, Object value) throws AppCatalogException { + List<String> wfInputResourceIDs = new ArrayList<String>(); + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + Query q; + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(WORKFLOW_INPUT); + List results; + if (fieldName.equals(WFInputConstants.WF_TEMPLATE_ID)) { + generator.setParameter(WFInputConstants.WF_TEMPLATE_ID, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + WorkflowInput workflowInput = (WorkflowInput) result; + wfInputResourceIDs.add(workflowInput.getWfTemplateId()); + } + } + } else if (fieldName.equals(WFInputConstants.INPUT_KEY)) { + generator.setParameter(WFInputConstants.INPUT_KEY, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + WorkflowInput workflowInput = (WorkflowInput) result; + wfInputResourceIDs.add(workflowInput.getWfTemplateId()); + } + } + } else if (fieldName.equals(WFInputConstants.DATA_TYPE)) { + generator.setParameter(WFInputConstants.DATA_TYPE, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + WorkflowInput workflowInput = (WorkflowInput) result; + wfInputResourceIDs.add(workflowInput.getWfTemplateId()); + } + } + } else { + em.getTransaction().commit(); + em.close(); + logger.error("Unsupported field name for WFInput resource.", new IllegalArgumentException()); + throw new IllegalArgumentException("Unsupported field name for WFInput Resource."); + } + em.getTransaction().commit(); + em.close(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + return wfInputResourceIDs; + } + + public void save() throws AppCatalogException { + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + WorkflowInput existingWFInput = em.find(WorkflowInput.class, new WorkflowInput_PK(wfTemplateId, inputKey)); + em.close(); + WorkflowInput workflowInput; + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + if (existingWFInput == null) { + workflowInput = new WorkflowInput(); + } else { + workflowInput=existingWFInput; + } + workflowInput.setWfTemplateId(wfTemplateId); + Workflow workflow = em.find(Workflow.class, wfTemplateId); + workflowInput.setWorkflow(workflow); + workflowInput.setDataType(dataType); + workflowInput.setInputKey(inputKey); + if (inputVal != null){ + workflowInput.setInputVal(inputVal.toCharArray()); + } + workflowInput.setMetadata(metadata); + workflowInput.setAppArgument(appArgument); + workflowInput.setUserFriendlyDesc(userFriendlyDesc); + workflowInput.setStandardInput(standardInput); + workflowInput.setRequiredToCMD(requiredToCMD); + workflowInput.setRequired(isRequired); + workflowInput.setDataStaged(dataStaged); + if (existingWFInput == null) { + em.persist(workflowInput); + } else { + em.merge(workflowInput); + } + em.getTransaction().commit(); + em.close(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + public boolean isExists(Object identifier) throws AppCatalogException { + 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 AppCatalogException("Identifier should be a map with the field name and it's value"); + } + + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + WorkflowInput workflowInput = em.find(WorkflowInput.class, new WorkflowInput_PK( + ids.get(WFInputConstants.WF_TEMPLATE_ID), + ids.get(WFInputConstants.INPUT_KEY))); + + em.close(); + return workflowInput != null; + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + public String getWfTemplateId() { + return wfTemplateId; + } + + public void setWfTemplateId(String wfTemplateId) { + this.wfTemplateId = wfTemplateId; + } + + public String getInputKey() { + return inputKey; + } + + public void setInputKey(String inputKey) { + this.inputKey = inputKey; + } + + public String getDataType() { + return dataType; + } + + public void setDataType(String dataType) { + this.dataType = dataType; + } + + public String getInputVal() { + return inputVal; + } + + public void setInputVal(String inputVal) { + this.inputVal = inputVal; + } + + 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 WorkflowResource getWorkflowResource() { + return workflowResource; + } + + public void setWorkflowResource(WorkflowResource workflowResource) { + this.workflowResource = workflowResource; + } + + 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 getRequired() { + return isRequired; + } + + public void setRequired(boolean required) { + this.isRequired = required; + } + + public boolean getRequiredToCMD() { + 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/ec8c6202/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/WorkflowOutputAppCatalogResourceAppCat.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/WorkflowOutputAppCatalogResourceAppCat.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/WorkflowOutputAppCatalogResourceAppCat.java new file mode 100644 index 0000000..75f5f7e --- /dev/null +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/WorkflowOutputAppCatalogResourceAppCat.java @@ -0,0 +1,410 @@ +/** + * 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.app.catalog.resources; + +import org.apache.airavata.common.exception.ApplicationSettingsException; +import org.apache.airavata.registry.core.app.catalog.model.Workflow; +import org.apache.airavata.registry.core.app.catalog.model.WorkflowOutput; +import org.apache.airavata.registry.core.app.catalog.model.WorkflowOutput_PK; +import org.apache.airavata.registry.core.app.catalog.util.AppCatalogJPAUtils; +import org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator; +import org.apache.airavata.registry.core.app.catalog.util.AppCatalogResourceType; +import org.apache.airavata.registry.cpi.AppCatalogException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.persistence.EntityManager; +import javax.persistence.Query; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class WorkflowOutputAppCatalogResourceAppCat extends AppCatAbstractResource { + private final static Logger logger = LoggerFactory.getLogger(WorkflowOutputAppCatalogResourceAppCat.class); + + private String wfTemplateId; + private String outputKey; + private String outputVal; + private String dataType; + private String validityType; + private boolean dataMovement; + private String dataNameLocation; + + private WorkflowAppCatalogResourceAppCat workflowResource; + + public void remove(Object identifier) throws AppCatalogException { + 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 AppCatalogException("Identifier should be a map with the field name and it's value"); + } + + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(WORKFLOW_OUTPUT); + generator.setParameter(WFOutputConstants.WF_TEMPLATE_ID, ids.get(WFOutputConstants.WF_TEMPLATE_ID)); + generator.setParameter(WFOutputConstants.OUTPUT_KEY, ids.get(WFOutputConstants.OUTPUT_KEY)); + Query q = generator.deleteQuery(em); + q.executeUpdate(); + em.getTransaction().commit(); + em.close(); + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + public AppCatalogResource get(Object identifier) throws AppCatalogException { + 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 AppCatalogException("Identifier should be a map with the field name and it's value"); + } + + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(WORKFLOW_OUTPUT); + generator.setParameter(WFOutputConstants.WF_TEMPLATE_ID, ids.get(WFOutputConstants.WF_TEMPLATE_ID)); + generator.setParameter(WFOutputConstants.OUTPUT_KEY, ids.get(WFOutputConstants.OUTPUT_KEY)); + Query q = generator.selectQuery(em); + WorkflowOutput wfOutput = (WorkflowOutput) q.getSingleResult(); + WorkflowOutputAppCatalogResourceAppCat workflowOutputResource = + (WorkflowOutputAppCatalogResourceAppCat) AppCatalogJPAUtils.getResource(AppCatalogResourceType.WORKFLOW_OUTPUT + , wfOutput); + em.getTransaction().commit(); + em.close(); + return workflowOutputResource; + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + public List<AppCatalogResource> get(String fieldName, Object value) throws AppCatalogException { + List<AppCatalogResource> wfOutputResources = new ArrayList<AppCatalogResource>(); + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + Query q; + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(WORKFLOW_OUTPUT); + List results; + if (fieldName.equals(WFOutputConstants.WF_TEMPLATE_ID)) { + generator.setParameter(WFOutputConstants.WF_TEMPLATE_ID, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + WorkflowOutput wfOutput = (WorkflowOutput) result; + WorkflowOutputAppCatalogResourceAppCat workflowOutputResource = + (WorkflowOutputAppCatalogResourceAppCat) AppCatalogJPAUtils.getResource( + AppCatalogResourceType.WORKFLOW_OUTPUT, wfOutput); + wfOutputResources.add(workflowOutputResource); + } + } + } else if (fieldName.equals(WFOutputConstants.OUTPUT_KEY)) { + generator.setParameter(WFOutputConstants.OUTPUT_KEY, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + WorkflowOutput workflowOutput = (WorkflowOutput) result; + WorkflowOutputAppCatalogResourceAppCat workflowOutputResource = + (WorkflowOutputAppCatalogResourceAppCat) AppCatalogJPAUtils.getResource( + AppCatalogResourceType.WORKFLOW_OUTPUT, workflowOutput); + wfOutputResources.add(workflowOutputResource); + } + } + } else if (fieldName.equals(WFOutputConstants.DATA_TYPE)) { + generator.setParameter(WFOutputConstants.DATA_TYPE, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + WorkflowOutput workflowOutput = (WorkflowOutput) result; + WorkflowOutputAppCatalogResourceAppCat workflowOutputResource = + (WorkflowOutputAppCatalogResourceAppCat) AppCatalogJPAUtils.getResource( + AppCatalogResourceType.WORKFLOW_OUTPUT, workflowOutput); + wfOutputResources.add(workflowOutputResource); + } + } + } else { + em.getTransaction().commit(); + em.close(); + logger.error("Unsupported field name for WF Output Resource.", new IllegalArgumentException()); + throw new IllegalArgumentException("Unsupported field name for WF Output Resource."); + } + em.getTransaction().commit(); + em.close(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + return wfOutputResources; + } + + public List<AppCatalogResource> getAll() throws AppCatalogException { + return null; + } + + public List<String> getAllIds() throws AppCatalogException { + return null; + } + + public List<String> getIds(String fieldName, Object value) throws AppCatalogException { + List<String> wfOutputResourceIDs = new ArrayList<String>(); + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + Query q; + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(WORKFLOW_OUTPUT); + List results; + if (fieldName.equals(WFOutputConstants.WF_TEMPLATE_ID)) { + generator.setParameter(WFOutputConstants.WF_TEMPLATE_ID, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + WorkflowOutput workflowOutput = (WorkflowOutput) result; + wfOutputResourceIDs.add(workflowOutput.getWfTemplateId()); + } + } + } + if (fieldName.equals(WFOutputConstants.OUTPUT_KEY)) { + generator.setParameter(WFOutputConstants.OUTPUT_KEY, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + WorkflowOutput workflowOutput = (WorkflowOutput) result; + wfOutputResourceIDs.add(workflowOutput.getWfTemplateId()); + } + } + } else if (fieldName.equals(WFOutputConstants.DATA_TYPE)) { + generator.setParameter(WFOutputConstants.DATA_TYPE, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + WorkflowOutput workflowOutput = (WorkflowOutput) result; + wfOutputResourceIDs.add(workflowOutput.getWfTemplateId()); + } + } + } else { + em.getTransaction().commit(); + em.close(); + logger.error("Unsupported field name for WF Output resource.", new IllegalArgumentException()); + throw new IllegalArgumentException("Unsupported field name for WF Output Resource."); + } + em.getTransaction().commit(); + em.close(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + return wfOutputResourceIDs; + } + + public void save() throws AppCatalogException { + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + WorkflowOutput existingWorkflowOutput = em.find(WorkflowOutput.class, + new WorkflowOutput_PK(wfTemplateId, outputKey)); + em.close(); + + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + if (existingWorkflowOutput != null) { + existingWorkflowOutput.setWfTemplateId(wfTemplateId); + Workflow workflow = em.find(Workflow.class, wfTemplateId); + existingWorkflowOutput.setWorkflow(workflow); + existingWorkflowOutput.setDataType(dataType); + existingWorkflowOutput.setOutputKey(outputKey); + if (outputVal != null){ + existingWorkflowOutput.setOutputVal(outputVal.toCharArray()); + } + existingWorkflowOutput.setValidityType(validityType); + existingWorkflowOutput.setDataMovement(dataMovement); + existingWorkflowOutput.setDataNameLocation(dataNameLocation); + em.merge(existingWorkflowOutput); + } else { + WorkflowOutput workflowOutput = new WorkflowOutput(); + workflowOutput.setWfTemplateId(wfTemplateId); + Workflow workflow = em.find(Workflow.class, wfTemplateId); + workflowOutput.setWorkflow(workflow); + workflowOutput.setDataType(dataType); + workflowOutput.setOutputKey(outputKey); + if (outputVal != null){ + workflowOutput.setOutputVal(outputVal.toCharArray()); + } + workflowOutput.setValidityType(validityType); + workflowOutput.setDataMovement(dataMovement); + workflowOutput.setDataNameLocation(dataNameLocation); + em.persist(workflowOutput); + } + em.getTransaction().commit(); + em.close(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + public boolean isExists(Object identifier) throws AppCatalogException { + 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 AppCatalogException("Identifier should be a map with the field name and it's value"); + } + + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + WorkflowOutput workflowOutput = em.find(WorkflowOutput.class, new WorkflowOutput_PK( + ids.get(WFOutputConstants.WF_TEMPLATE_ID), + ids.get(WFOutputConstants.OUTPUT_KEY))); + + em.close(); + return workflowOutput != null; + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + public String getWfTemplateId() { + return wfTemplateId; + } + + public void setWfTemplateId(String wfTemplateId) { + this.wfTemplateId = wfTemplateId; + } + + public String getOutputKey() { + return outputKey; + } + + public void setOutputKey(String outputKey) { + this.outputKey = outputKey; + } + + public String getOutputVal() { + return outputVal; + } + + public void setOutputVal(String outputVal) { + this.outputVal = outputVal; + } + + public String getDataType() { + return dataType; + } + + public void setDataType(String dataType) { + this.dataType = dataType; + } + + public WorkflowAppCatalogResourceAppCat getWorkflowResource() { + return workflowResource; + } + + public void setWorkflowResource(WorkflowAppCatalogResourceAppCat workflowResource) { + this.workflowResource = workflowResource; + } + + public String getValidityType() { + return validityType; + } + + public void setValidityType(String validityType) { + this.validityType = validityType; + } + + public boolean isDataMovement() { + return dataMovement; + } + + public void setDataMovement(boolean dataMovement) { + this.dataMovement = dataMovement; + } + + public String getDataNameLocation() { + return dataNameLocation; + } + + public void setDataNameLocation(String dataNameLocation) { + this.dataNameLocation = dataNameLocation; + } +} http://git-wip-us.apache.org/repos/asf/airavata/blob/ec8c6202/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/WorkflowOutputResource.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/WorkflowOutputResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/WorkflowOutputResource.java new file mode 100644 index 0000000..7f180bd --- /dev/null +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/WorkflowOutputResource.java @@ -0,0 +1,410 @@ +/** + * 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.aiaravata.application.catalog.data.resources; + +import org.airavata.appcatalog.cpi.AppCatalogException; +import org.apache.aiaravata.application.catalog.data.model.Workflow; +import org.apache.aiaravata.application.catalog.data.model.WorkflowOutput; +import org.apache.aiaravata.application.catalog.data.model.WorkflowOutput_PK; +import org.apache.aiaravata.application.catalog.data.util.AppCatalogJPAUtils; +import org.apache.aiaravata.application.catalog.data.util.AppCatalogQueryGenerator; +import org.apache.aiaravata.application.catalog.data.util.AppCatalogResourceType; +import org.apache.airavata.common.exception.ApplicationSettingsException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.persistence.EntityManager; +import javax.persistence.Query; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class WorkflowOutputResource extends AbstractResource { + private final static Logger logger = LoggerFactory.getLogger(WorkflowOutputResource.class); + + private String wfTemplateId; + private String outputKey; + private String outputVal; + private String dataType; + private String validityType; + private boolean dataMovement; + private String dataNameLocation; + + private WorkflowResource workflowResource; + + public void remove(Object identifier) throws AppCatalogException { + 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 AppCatalogException("Identifier should be a map with the field name and it's value"); + } + + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(WORKFLOW_OUTPUT); + generator.setParameter(WFOutputConstants.WF_TEMPLATE_ID, ids.get(WFOutputConstants.WF_TEMPLATE_ID)); + generator.setParameter(WFOutputConstants.OUTPUT_KEY, ids.get(WFOutputConstants.OUTPUT_KEY)); + Query q = generator.deleteQuery(em); + q.executeUpdate(); + em.getTransaction().commit(); + em.close(); + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + public Resource get(Object identifier) throws AppCatalogException { + 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 AppCatalogException("Identifier should be a map with the field name and it's value"); + } + + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(WORKFLOW_OUTPUT); + generator.setParameter(WFOutputConstants.WF_TEMPLATE_ID, ids.get(WFOutputConstants.WF_TEMPLATE_ID)); + generator.setParameter(WFOutputConstants.OUTPUT_KEY, ids.get(WFOutputConstants.OUTPUT_KEY)); + Query q = generator.selectQuery(em); + WorkflowOutput wfOutput = (WorkflowOutput) q.getSingleResult(); + WorkflowOutputResource workflowOutputResource = + (WorkflowOutputResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.WORKFLOW_OUTPUT + , wfOutput); + em.getTransaction().commit(); + em.close(); + return workflowOutputResource; + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + public List<Resource> get(String fieldName, Object value) throws AppCatalogException { + List<Resource> wfOutputResources = new ArrayList<Resource>(); + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + Query q; + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(WORKFLOW_OUTPUT); + List results; + if (fieldName.equals(WFOutputConstants.WF_TEMPLATE_ID)) { + generator.setParameter(WFOutputConstants.WF_TEMPLATE_ID, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + WorkflowOutput wfOutput = (WorkflowOutput) result; + WorkflowOutputResource workflowOutputResource = + (WorkflowOutputResource) AppCatalogJPAUtils.getResource( + AppCatalogResourceType.WORKFLOW_OUTPUT, wfOutput); + wfOutputResources.add(workflowOutputResource); + } + } + } else if (fieldName.equals(WFOutputConstants.OUTPUT_KEY)) { + generator.setParameter(WFOutputConstants.OUTPUT_KEY, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + WorkflowOutput workflowOutput = (WorkflowOutput) result; + WorkflowOutputResource workflowOutputResource = + (WorkflowOutputResource) AppCatalogJPAUtils.getResource( + AppCatalogResourceType.WORKFLOW_OUTPUT, workflowOutput); + wfOutputResources.add(workflowOutputResource); + } + } + } else if (fieldName.equals(WFOutputConstants.DATA_TYPE)) { + generator.setParameter(WFOutputConstants.DATA_TYPE, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + WorkflowOutput workflowOutput = (WorkflowOutput) result; + WorkflowOutputResource workflowOutputResource = + (WorkflowOutputResource) AppCatalogJPAUtils.getResource( + AppCatalogResourceType.WORKFLOW_OUTPUT, workflowOutput); + wfOutputResources.add(workflowOutputResource); + } + } + } else { + em.getTransaction().commit(); + em.close(); + logger.error("Unsupported field name for WF Output Resource.", new IllegalArgumentException()); + throw new IllegalArgumentException("Unsupported field name for WF Output Resource."); + } + em.getTransaction().commit(); + em.close(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + return wfOutputResources; + } + + public List<Resource> getAll() throws AppCatalogException { + return null; + } + + public List<String> getAllIds() throws AppCatalogException { + return null; + } + + public List<String> getIds(String fieldName, Object value) throws AppCatalogException { + List<String> wfOutputResourceIDs = new ArrayList<String>(); + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + Query q; + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(WORKFLOW_OUTPUT); + List results; + if (fieldName.equals(WFOutputConstants.WF_TEMPLATE_ID)) { + generator.setParameter(WFOutputConstants.WF_TEMPLATE_ID, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + WorkflowOutput workflowOutput = (WorkflowOutput) result; + wfOutputResourceIDs.add(workflowOutput.getWfTemplateId()); + } + } + } + if (fieldName.equals(WFOutputConstants.OUTPUT_KEY)) { + generator.setParameter(WFOutputConstants.OUTPUT_KEY, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + WorkflowOutput workflowOutput = (WorkflowOutput) result; + wfOutputResourceIDs.add(workflowOutput.getWfTemplateId()); + } + } + } else if (fieldName.equals(WFOutputConstants.DATA_TYPE)) { + generator.setParameter(WFOutputConstants.DATA_TYPE, value); + q = generator.selectQuery(em); + results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + WorkflowOutput workflowOutput = (WorkflowOutput) result; + wfOutputResourceIDs.add(workflowOutput.getWfTemplateId()); + } + } + } else { + em.getTransaction().commit(); + em.close(); + logger.error("Unsupported field name for WF Output resource.", new IllegalArgumentException()); + throw new IllegalArgumentException("Unsupported field name for WF Output Resource."); + } + em.getTransaction().commit(); + em.close(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + return wfOutputResourceIDs; + } + + public void save() throws AppCatalogException { + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + WorkflowOutput existingWorkflowOutput = em.find(WorkflowOutput.class, + new WorkflowOutput_PK(wfTemplateId, outputKey)); + em.close(); + + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + if (existingWorkflowOutput != null) { + existingWorkflowOutput.setWfTemplateId(wfTemplateId); + Workflow workflow = em.find(Workflow.class, wfTemplateId); + existingWorkflowOutput.setWorkflow(workflow); + existingWorkflowOutput.setDataType(dataType); + existingWorkflowOutput.setOutputKey(outputKey); + if (outputVal != null){ + existingWorkflowOutput.setOutputVal(outputVal.toCharArray()); + } + existingWorkflowOutput.setValidityType(validityType); + existingWorkflowOutput.setDataMovement(dataMovement); + existingWorkflowOutput.setDataNameLocation(dataNameLocation); + em.merge(existingWorkflowOutput); + } else { + WorkflowOutput workflowOutput = new WorkflowOutput(); + workflowOutput.setWfTemplateId(wfTemplateId); + Workflow workflow = em.find(Workflow.class, wfTemplateId); + workflowOutput.setWorkflow(workflow); + workflowOutput.setDataType(dataType); + workflowOutput.setOutputKey(outputKey); + if (outputVal != null){ + workflowOutput.setOutputVal(outputVal.toCharArray()); + } + workflowOutput.setValidityType(validityType); + workflowOutput.setDataMovement(dataMovement); + workflowOutput.setDataNameLocation(dataNameLocation); + em.persist(workflowOutput); + } + em.getTransaction().commit(); + em.close(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + public boolean isExists(Object identifier) throws AppCatalogException { + 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 AppCatalogException("Identifier should be a map with the field name and it's value"); + } + + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + WorkflowOutput workflowOutput = em.find(WorkflowOutput.class, new WorkflowOutput_PK( + ids.get(WFOutputConstants.WF_TEMPLATE_ID), + ids.get(WFOutputConstants.OUTPUT_KEY))); + + em.close(); + return workflowOutput != null; + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + public String getWfTemplateId() { + return wfTemplateId; + } + + public void setWfTemplateId(String wfTemplateId) { + this.wfTemplateId = wfTemplateId; + } + + public String getOutputKey() { + return outputKey; + } + + public void setOutputKey(String outputKey) { + this.outputKey = outputKey; + } + + public String getOutputVal() { + return outputVal; + } + + public void setOutputVal(String outputVal) { + this.outputVal = outputVal; + } + + public String getDataType() { + return dataType; + } + + public void setDataType(String dataType) { + this.dataType = dataType; + } + + public WorkflowResource getWorkflowResource() { + return workflowResource; + } + + public void setWorkflowResource(WorkflowResource workflowResource) { + this.workflowResource = workflowResource; + } + + public String getValidityType() { + return validityType; + } + + public void setValidityType(String validityType) { + this.validityType = validityType; + } + + public boolean isDataMovement() { + return dataMovement; + } + + public void setDataMovement(boolean dataMovement) { + this.dataMovement = dataMovement; + } + + public String getDataNameLocation() { + return dataNameLocation; + } + + public void setDataNameLocation(String dataNameLocation) { + this.dataNameLocation = dataNameLocation; + } +} http://git-wip-us.apache.org/repos/asf/airavata/blob/ec8c6202/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/WorkflowResource.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/WorkflowResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/WorkflowResource.java new file mode 100644 index 0000000..3e52019 --- /dev/null +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/WorkflowResource.java @@ -0,0 +1,382 @@ +/* + * + * 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.aiaravata.application.catalog.data.resources; + +import org.airavata.appcatalog.cpi.AppCatalogException; +import org.apache.aiaravata.application.catalog.data.model.Workflow; +import org.apache.aiaravata.application.catalog.data.util.AppCatalogJPAUtils; +import org.apache.aiaravata.application.catalog.data.util.AppCatalogQueryGenerator; +import org.apache.aiaravata.application.catalog.data.util.AppCatalogResourceType; +import org.apache.airavata.common.exception.ApplicationSettingsException; +import org.apache.airavata.common.utils.AiravataUtils; +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 WorkflowResource extends AbstractResource { + private final static Logger logger = LoggerFactory.getLogger(WorkflowResource.class); + private String wfName; + private String createdUser; + private String graph; + private String wfTemplateId; + private Timestamp createdTime; + private Timestamp updatedTime; + private String image; + private String gatewayId; + + public Timestamp getCreatedTime() { + return createdTime; + } + + public void setCreatedTime(Timestamp createdTime) { + this.createdTime = createdTime; + } + + public Timestamp getUpdatedTime() { + return updatedTime; + } + + public void setUpdatedTime(Timestamp updatedTime) { + this.updatedTime = updatedTime; + } + + public String getImage() { + return image; + } + + public void setImage(String image) { + this.image = image; + } + + public String getGatewayId() { + return gatewayId; + } + + public void setGatewayId(String gatewayId) { + this.gatewayId = gatewayId; + } + + @Override + public void remove(Object identifier) throws AppCatalogException { + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(WORKFLOW); + generator.setParameter(WorkflowConstants.WF_TEMPLATE_ID, identifier); + Query q = generator.deleteQuery(em); + q.executeUpdate(); + em.getTransaction().commit(); + em.close(); + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + @Override + public Resource get(Object identifier) throws AppCatalogException { + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(WORKFLOW); + generator.setParameter(WorkflowConstants.WF_TEMPLATE_ID, identifier); + Query q = generator.selectQuery(em); + Workflow workflow = (Workflow) q.getSingleResult(); + WorkflowResource workflowResource = (WorkflowResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.WORKFLOW, workflow); + em.getTransaction().commit(); + em.close(); + return workflowResource; + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + @Override + public List<Resource> get(String fieldName, Object value) throws AppCatalogException { + List<Resource> workflowResources = new ArrayList<Resource>(); + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(WORKFLOW); + Query q; + if ((fieldName.equals(WorkflowConstants.WF_NAME)) || (fieldName.equals(WorkflowConstants.CREATED_USER)) || (fieldName.equals(WorkflowConstants.GRAPH)) || (fieldName.equals(WorkflowConstants.WF_TEMPLATE_ID))) { + generator.setParameter(fieldName, value); + q = generator.selectQuery(em); + List<?> results = q.getResultList(); + for (Object result : results) { + Workflow workflow = (Workflow) result; + WorkflowResource workflowResource = (WorkflowResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.WORKFLOW, workflow); + workflowResources.add(workflowResource); + } + } else { + em.getTransaction().commit(); + em.close(); + logger.error("Unsupported field name for Workflow Resource.", new IllegalArgumentException()); + throw new IllegalArgumentException("Unsupported field name for Workflow Resource."); + } + em.getTransaction().commit(); + em.close(); + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + return workflowResources; + } + + @Override + public List<Resource> getAll() throws AppCatalogException { + List<Resource> workflows = new ArrayList<Resource>(); + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(WORKFLOW); + generator.setParameter(WorkflowConstants.GATEWAY_ID, gatewayId); + Query q = generator.selectQuery(em); + List results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + Workflow workflow = (Workflow) result; + WorkflowResource wfResource = + (WorkflowResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.WORKFLOW, workflow); + workflows.add(wfResource); + } + } + em.getTransaction().commit(); + em.close(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + return workflows; + } + + @Override + public List<String> getAllIds() throws AppCatalogException { + List<String> workflowIds = new ArrayList<String>(); + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(WORKFLOW); + generator.setParameter(WorkflowConstants.GATEWAY_ID, gatewayId); + Query q = generator.selectQuery(em); + List results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + Workflow workflow = (Workflow) result; + workflowIds.add(workflow.getWfTemplateId()); + } + } + em.getTransaction().commit(); + em.close(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + return workflowIds; + } + + @Override + public List<String> getIds(String fieldName, Object value) throws AppCatalogException { + List<String> workflowResourceIDs = new ArrayList<String>(); + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(WORKFLOW); + Query q; + if ((fieldName.equals(WorkflowConstants.WF_NAME)) || (fieldName.equals(WorkflowConstants.CREATED_USER)) || (fieldName.equals(WorkflowConstants.GRAPH)) || (fieldName.equals(WorkflowConstants.WF_TEMPLATE_ID))) { + generator.setParameter(fieldName, value); + q = generator.selectQuery(em); + List<?> results = q.getResultList(); + for (Object result : results) { + Workflow workflow = (Workflow) result; + WorkflowResource workflowResource = (WorkflowResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.WORKFLOW, workflow); + workflowResourceIDs.add(workflowResource.getWfTemplateId()); + } + } else { + em.getTransaction().commit(); + em.close(); + logger.error("Unsupported field name for Workflow Resource.", new IllegalArgumentException()); + throw new IllegalArgumentException("Unsupported field name for Workflow Resource."); + } + em.getTransaction().commit(); + em.close(); + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + return workflowResourceIDs; + } + + @Override + public void save() throws AppCatalogException { + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + Workflow existingWorkflow = em.find(Workflow.class, wfTemplateId); + em.close(); + Workflow workflow; + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + if (existingWorkflow == null) { + workflow = new Workflow(); + workflow.setCreationTime(AiravataUtils.getCurrentTimestamp()); + } else { + workflow = existingWorkflow; + workflow.setUpdateTime(AiravataUtils.getCurrentTimestamp()); + } + workflow.setWfName(getWfName()); + workflow.setCreatedUser(getCreatedUser()); + workflow.setGatewayId(gatewayId); + if (getGraph() != null){ + workflow.setGraph(getGraph().toCharArray()); + } + if (image != null){ + workflow.setImage(image.getBytes()); + } + workflow.setWfTemplateId(getWfTemplateId()); + if (existingWorkflow == null) { + em.persist(workflow); + } else { + em.merge(workflow); + } + em.getTransaction().commit(); + em.close(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + @Override + public boolean isExists(Object identifier) throws AppCatalogException { + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + Workflow workflow = em.find(Workflow.class, identifier); + em.close(); + return workflow != null; + } catch (ApplicationSettingsException e) { + logger.error(e.getMessage(), e); + throw new AppCatalogException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + public String getWfName() { + return wfName; + } + + public String getCreatedUser() { + return createdUser; + } + + public String getGraph() { + return graph; + } + + public String getWfTemplateId() { + return wfTemplateId; + } + + public void setWfName(String wfName) { + this.wfName=wfName; + } + + public void setCreatedUser(String createdUser) { + this.createdUser=createdUser; + } + + public void setGraph(String graph) { + this.graph=graph; + } + + public void setWfTemplateId(String wfTemplateId) { + this.wfTemplateId=wfTemplateId; + } +}
