On Tue, Feb 18, 2014 at 2:21 PM, <[email protected]> wrote:

> Repository: airavata
> Updated Branches:
>   refs/heads/master 0e2e21ce5 -> e8ac03899
>
>
> added resource functions
>
> Project: http://git-wip-us.apache.org/repos/asf/airavata/repo
> Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/4066c477
> Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/4066c477
> Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/4066c477
>
> Branch: refs/heads/master
> Commit: 4066c4777255661250f7237c319c2870d3b88149
> Parents: a584c2c
> Author: raminder <[email protected]>
> Authored: Tue Feb 18 13:33:36 2014 -0500
> Committer: raminder <[email protected]>
> Committed: Tue Feb 18 13:33:36 2014 -0500
>
> ----------------------------------------------------------------------
>  .../jpa/resources/ApplicationInputResource.java | 57 +++++++++++++++++---
>  .../resources/ApplicationOutputResource.java    | 57 +++++++++++++++++---
>  .../jpa/resources/NodeInputResource.java        | 31 ++++++++---
>  3 files changed, 124 insertions(+), 21 deletions(-)
> ----------------------------------------------------------------------
>
>
>
> http://git-wip-us.apache.org/repos/asf/airavata/blob/4066c477/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ApplicationInputResource.java
> ----------------------------------------------------------------------
> diff --git
> a/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ApplicationInputResource.java
> b/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ApplicationInputResource.java
> index 833ba91..ca3245a 100644
> ---
> a/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ApplicationInputResource.java
> +++
> b/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ApplicationInputResource.java
> @@ -21,13 +21,23 @@
>
>  package org.apache.airavata.persistance.registry.jpa.resources;
>
> +import java.util.List;
> +
> +import javax.persistence.EntityManager;
> +
>  import org.apache.airavata.persistance.registry.jpa.Resource;
>  import org.apache.airavata.persistance.registry.jpa.ResourceType;
> -
> -import java.util.List;
> +import org.apache.airavata.persistance.registry.jpa.ResourceUtils;
> +import
> org.apache.airavata.persistance.registry.jpa.model.ApplicationInput;
> +import
> org.apache.airavata.persistance.registry.jpa.model.ApplicationInput_PK;
> +import org.apache.airavata.persistance.registry.jpa.model.TaskDetail;
> +import org.slf4j.Logger;
> +import org.slf4j.LoggerFactory;
>
>  public class ApplicationInputResource extends AbstractResource {
> -    private String taskId;
> +       private static final Logger logger =
> LoggerFactory.getLogger(ApplicationInputResource.class);
> +
> +       private String taskId;
>      private String inputKey;
>      private String inputType;
>      private String metadata;
> @@ -75,26 +85,57 @@ public class ApplicationInputResource extends
> AbstractResource {
>
>      @Override
>      public Resource create(ResourceType type) {
> -        return null;
> +        logger.error("Unsupported resource type for application input
> data resource.", new UnsupportedOperationException());
> +        throw new UnsupportedOperationException();
>      }
>
>      @Override
>      public void remove(ResourceType type, Object name) {
> -
> +        logger.error("Unsupported resource type for application input
> data resource.", new UnsupportedOperationException());
> +        throw new UnsupportedOperationException();
>
I think we need to embed the error message to the exception itself before
throwing it up. And why are we creating two exception objects ?

Regards
Lahiru

>      }
>
>      @Override
>      public Resource get(ResourceType type, Object name) {
> -        return null;
> +        logger.error("Unsupported resource type for application input
> data resource.", new UnsupportedOperationException());
> +        throw new UnsupportedOperationException();
>      }
>
>      @Override
>      public List<Resource> get(ResourceType type) {
> -        return null;
> +        logger.error("Unsupported resource type for application input
> data resource.", new UnsupportedOperationException());
> +        throw new UnsupportedOperationException();
>      }
>
>      @Override
>      public void save() {
> -
> +        EntityManager em = ResourceUtils.getEntityManager();
> +        ApplicationInput existingInput = em.find(ApplicationInput.class,
> new ApplicationInput_PK(inputKey, taskId));
> +        em.close();
> +
> +        em = ResourceUtils.getEntityManager();
> +        em.getTransaction().begin();
> +        ApplicationInput applicationInput = new ApplicationInput();
> +        TaskDetail taskDetail = em.find(TaskDetail.class, taskId);
> +        applicationInput.setTask(taskDetail);
> +        applicationInput.setTaskId(taskDetail.getTaskId());
> +        applicationInput.setInputKey(inputKey);
> +        applicationInput.setInputKeyType(inputType);
> +        applicationInput.setValue(value);
> +        applicationInput.setMetadata(metadata);
> +
> +        if (existingInput != null){
> +            existingInput.setTask(taskDetail);
> +            existingInput.setTaskId(taskDetail.getTaskId());
> +            existingInput.setInputKey(inputKey);
> +            existingInput.setInputKeyType(inputType);
> +            existingInput.setValue(value);
> +            existingInput.setMetadata(metadata);
> +            applicationInput = em.merge(existingInput);
> +        }else {
> +            em.persist(applicationInput);
> +        }
> +        em.getTransaction().commit();
> +        em.close();
>      }
>  }
>
>
> http://git-wip-us.apache.org/repos/asf/airavata/blob/4066c477/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ApplicationOutputResource.java
> ----------------------------------------------------------------------
> diff --git
> a/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ApplicationOutputResource.java
> b/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ApplicationOutputResource.java
> index 9a7bf2f..7fe7b3d 100644
> ---
> a/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ApplicationOutputResource.java
> +++
> b/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ApplicationOutputResource.java
> @@ -21,13 +21,23 @@
>
>  package org.apache.airavata.persistance.registry.jpa.resources;
>
> +import java.util.List;
> +
> +import javax.persistence.EntityManager;
> +
>  import org.apache.airavata.persistance.registry.jpa.Resource;
>  import org.apache.airavata.persistance.registry.jpa.ResourceType;
> -
> -import java.util.List;
> +import org.apache.airavata.persistance.registry.jpa.ResourceUtils;
> +import
> org.apache.airavata.persistance.registry.jpa.model.ApplicationOutput;
> +import
> org.apache.airavata.persistance.registry.jpa.model.ApplicationOutput_PK;
> +import org.apache.airavata.persistance.registry.jpa.model.TaskDetail;
> +import org.slf4j.Logger;
> +import org.slf4j.LoggerFactory;
>
>  public class ApplicationOutputResource extends AbstractResource {
> -    private String taskId;
> +       private static final Logger logger =
> LoggerFactory.getLogger(ApplicationOutputResource.class);
> +
> +       private String taskId;
>      private String outputKey;
>      private String outputType;
>      private String metadata;
> @@ -75,26 +85,59 @@ public class ApplicationOutputResource extends
> AbstractResource {
>
>      @Override
>      public Resource create(ResourceType type) {
> -        return null;
> +        logger.error("Unsupported resource type for application output
> data resource.", new UnsupportedOperationException());
> +        throw new UnsupportedOperationException();
>      }
>
>      @Override
>      public void remove(ResourceType type, Object name) {
> -
> +        logger.error("Unsupported resource type for application output
> data resource.", new UnsupportedOperationException());
> +        throw new UnsupportedOperationException();
>      }
>
>      @Override
>      public Resource get(ResourceType type, Object name) {
> -        return null;
> +        logger.error("Unsupported resource type for application output
> data resource.", new UnsupportedOperationException());
> +        throw new UnsupportedOperationException();
>      }
>
>      @Override
>      public List<Resource> get(ResourceType type) {
> -        return null;
> +        logger.error("Unsupported resource type for application output
> data resource.", new UnsupportedOperationException());
> +        throw new UnsupportedOperationException();
>      }
>
>      @Override
>      public void save() {
> +        EntityManager em = ResourceUtils.getEntityManager();
> +        ApplicationOutput existingOutput =
> em.find(ApplicationOutput.class, new ApplicationOutput_PK(outputKey,
> taskId));
> +        em.close();
> +
> +        em = ResourceUtils.getEntityManager();
> +        em.getTransaction().begin();
> +        ApplicationOutput applicationOutput = new ApplicationOutput();
> +        TaskDetail taskDetail = em.find(TaskDetail.class, taskId);
> +        applicationOutput.setTask(taskDetail);
> +        applicationOutput.setTaskId(taskDetail.getTaskId());
> +        applicationOutput.setOutputKey(outputKey);
> +        applicationOutput.setOutputKeyType(outputType);
> +        applicationOutput.setValue(value);
> +        applicationOutput.setMetadata(metadata);
> +
> +        if (existingOutput != null){
> +               existingOutput.setTask(taskDetail);
> +               existingOutput.setTaskId(taskDetail.getTaskId());
> +               existingOutput.setOutputKey(outputKey);
> +               existingOutput.setOutputKeyType(outputType);
> +               existingOutput.setValue(value);
> +               existingOutput.setMetadata(metadata);
> +               applicationOutput = em.merge(existingOutput);
> +        }else {
> +            em.persist(applicationOutput);
> +        }
> +        em.getTransaction().commit();
> +        em.close();
> +
>
>      }
>  }
>
>
> http://git-wip-us.apache.org/repos/asf/airavata/blob/4066c477/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/NodeInputResource.java
> ----------------------------------------------------------------------
> diff --git
> a/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/NodeInputResource.java
> b/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/NodeInputResource.java
> index dd7d484..e483d8f 100644
> ---
> a/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/NodeInputResource.java
> +++
> b/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/NodeInputResource.java
> @@ -21,12 +21,21 @@
>
>  package org.apache.airavata.persistance.registry.jpa.resources;
>
> +import java.util.List;
> +
> +import javax.persistence.EntityManager;
> +
>  import org.apache.airavata.persistance.registry.jpa.Resource;
>  import org.apache.airavata.persistance.registry.jpa.ResourceType;
> -
> -import java.util.List;
> +import org.apache.airavata.persistance.registry.jpa.ResourceUtils;
> +import org.apache.airavata.persistance.registry.jpa.model.NodeInput;
> +import org.apache.airavata.persistance.registry.jpa.model.NodeInput_PK;
> +import org.slf4j.Logger;
> +import org.slf4j.LoggerFactory;
>
>  public class NodeInputResource extends AbstractResource {
> +       private static final Logger logger =
> LoggerFactory.getLogger(NodeInputResource.class);
> +
>      private String nodeInstanceId;
>      private String inputKey;
>      private String inputType;
> @@ -75,26 +84,36 @@ public class NodeInputResource extends
> AbstractResource {
>
>      @Override
>      public Resource create(ResourceType type) {
> -        return null;
> +        logger.error("Unsupported resource type for node input data
> resource.", new UnsupportedOperationException());
> +        throw new UnsupportedOperationException();
>      }
>
>      @Override
>      public void remove(ResourceType type, Object name) {
> -
> +        logger.error("Unsupported resource type for node input data
> resource.", new UnsupportedOperationException());
> +        throw new UnsupportedOperationException();
>      }
>
>      @Override
>      public Resource get(ResourceType type, Object name) {
> -        return null;
> +        logger.error("Unsupported resource type for node input data
> resource.", new UnsupportedOperationException());
> +        throw new UnsupportedOperationException();
>      }
>
>      @Override
>      public List<Resource> get(ResourceType type) {
> -        return null;
> +        logger.error("Unsupported resource type for node input data
> resource.", new UnsupportedOperationException());
> +        throw new UnsupportedOperationException();
>      }
>
>      @Override
>      public void save() {
> +        EntityManager em = ResourceUtils.getEntityManager();
> +        NodeInput existingInput = em.find(NodeInput.class, new
> NodeInput_PK(inputKey, nodeInstanceId));
> +        em.close();
>
> +        em = ResourceUtils.getEntityManager();
> +        em.getTransaction().begin();
> +
>      }
>  }
>
>


-- 
System Analyst Programmer
PTI Lab
Indiana University

Reply via email to