You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by sa...@apache.org on 2014/06/28 18:09:53 UTC
git commit: adding missing app catalog resource layer classes
Repository: airavata
Updated Branches:
refs/heads/master f048c8a61 -> 856b557fe
adding missing app catalog resource layer classes
Project: http://git-wip-us.apache.org/repos/asf/airavata/repo
Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/856b557f
Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/856b557f
Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/856b557f
Branch: refs/heads/master
Commit: 856b557fe7186e9308ad35afe571c6dc2a246a92
Parents: f048c8a
Author: Sachith Withana <sa...@apache.org>
Authored: Sat Jun 28 21:42:01 2014 +0530
Committer: Sachith Withana <sa...@apache.org>
Committed: Sat Jun 28 21:42:01 2014 +0530
----------------------------------------------------------------------
.../resources/ApplicationInputResource.java | 380 +++++++++++++++++++
.../resources/ApplicationOutputResource.java | 359 ++++++++++++++++++
.../data/resources/GatewayProfileResource.java | 271 +++++++++++++
3 files changed, 1010 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/airavata/blob/856b557f/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/ApplicationInputResource.java
----------------------------------------------------------------------
diff --git a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/ApplicationInputResource.java b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/ApplicationInputResource.java
new file mode 100644
index 0000000..d4f2be0
--- /dev/null
+++ b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/ApplicationInputResource.java
@@ -0,0 +1,380 @@
+package org.apache.aiaravata.application.catalog.data.resources;
+
+import org.airavata.appcatalog.cpi.AppCatalogException;
+import org.apache.aiaravata.application.catalog.data.model.AppInput_PK;
+import org.apache.aiaravata.application.catalog.data.model.ApplicationInput;
+import org.apache.aiaravata.application.catalog.data.model.ApplicationInterface;
+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 ApplicationInputResource extends AbstractResource {
+
+ private final static Logger logger = LoggerFactory.getLogger(ApplicationInputResource.class);
+
+ private String interfaceID;
+ private String inputKey;
+ private String dataType;
+ private String inputVal;
+ private String metadata;
+ private String appParameter;
+ private String appUIDesc;
+
+ private AppInterfaceResource appInterfaceResource;
+
+ 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(APPLICATION_INPUT);
+ generator.setParameter(AppInputConstants.INTERFACE_ID, ids.get(AppInputConstants.INTERFACE_ID));
+ generator.setParameter(AppInputConstants.INPUT_KEY, ids.get(AppInputConstants.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) 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(APPLICATION_INPUT);
+ generator.setParameter(AppInputConstants.INTERFACE_ID, ids.get(AppInputConstants.INTERFACE_ID));
+ generator.setParameter(AppInputConstants.INPUT_KEY, ids.get(AppInputConstants.INPUT_KEY));
+ Query q = generator.selectQuery(em);
+ ApplicationInput applicationInput = (ApplicationInput) q.getSingleResult();
+ ApplicationInputResource applicationInputResource =
+ (ApplicationInputResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.APPLICATION_INPUT
+ , applicationInput);
+ em.getTransaction().commit();
+ em.close();
+ return applicationInputResource;
+ } 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> appInputResources = new ArrayList<Resource>();
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ Query q;
+ AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(APPLICATION_INPUT);
+ List results;
+ if (fieldName.equals(AppInputConstants.INTERFACE_ID)) {
+ generator.setParameter(AppInputConstants.INTERFACE_ID, value);
+ q = generator.selectQuery(em);
+ results = q.getResultList();
+ if (results.size() != 0) {
+ for (Object result : results) {
+ ApplicationInput applicationInput = (ApplicationInput) result;
+ ApplicationInputResource applicationInputResource =
+ (ApplicationInputResource) AppCatalogJPAUtils.getResource(
+ AppCatalogResourceType.APPLICATION_INPUT, applicationInput);
+ appInputResources.add(applicationInputResource);
+ }
+ }
+ } else if (fieldName.equals(AppInputConstants.INPUT_KEY)) {
+ generator.setParameter(AppInputConstants.INPUT_KEY, value);
+ q = generator.selectQuery(em);
+ results = q.getResultList();
+ if (results.size() != 0) {
+ for (Object result : results) {
+ ApplicationInput applicationInput = (ApplicationInput) result;
+ ApplicationInputResource applicationInputResource =
+ (ApplicationInputResource) AppCatalogJPAUtils.getResource(
+ AppCatalogResourceType.APPLICATION_INPUT, applicationInput);
+ appInputResources.add(applicationInputResource);
+ }
+ }
+ } else if (fieldName.equals(AppInputConstants.DATA_TYPE)) {
+ generator.setParameter(AppInputConstants.DATA_TYPE, value);
+ q = generator.selectQuery(em);
+ results = q.getResultList();
+ if (results.size() != 0) {
+ for (Object result : results) {
+ ApplicationInput applicationInput = (ApplicationInput) result;
+ ApplicationInputResource applicationInputResource =
+ (ApplicationInputResource) AppCatalogJPAUtils.getResource(
+ AppCatalogResourceType.APPLICATION_INPUT, applicationInput);
+ appInputResources.add(applicationInputResource);
+ }
+ }
+ } else {
+ em.getTransaction().commit();
+ em.close();
+ logger.error("Unsupported field name for AppInput Resource.", new IllegalArgumentException());
+ throw new IllegalArgumentException("Unsupported field name for AppInput 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 appInputResources;
+ }
+
+ public List<String> getIds(String fieldName, Object value) throws AppCatalogException {
+ List<String> appInputResourceIDs = new ArrayList<String>();
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ Query q;
+ AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(APPLICATION_INPUT);
+ List results;
+ if (fieldName.equals(AppInputConstants.INTERFACE_ID)) {
+ generator.setParameter(AppInputConstants.INTERFACE_ID, value);
+ q = generator.selectQuery(em);
+ results = q.getResultList();
+ if (results.size() != 0) {
+ for (Object result : results) {
+ ApplicationInput applicationInput = (ApplicationInput) result;
+ appInputResourceIDs.add(applicationInput.getInterfaceID());
+ }
+ }
+ } else if (fieldName.equals(AppInputConstants.INPUT_KEY)) {
+ generator.setParameter(AppInputConstants.INPUT_KEY, value);
+ q = generator.selectQuery(em);
+ results = q.getResultList();
+ if (results.size() != 0) {
+ for (Object result : results) {
+ ApplicationInput applicationInput = (ApplicationInput) result;
+ appInputResourceIDs.add(applicationInput.getInterfaceID());
+ }
+ }
+ } else if (fieldName.equals(AppInputConstants.DATA_TYPE)) {
+ generator.setParameter(AppInputConstants.DATA_TYPE, value);
+ q = generator.selectQuery(em);
+ results = q.getResultList();
+ if (results.size() != 0) {
+ for (Object result : results) {
+ ApplicationInput applicationInput = (ApplicationInput) result;
+ appInputResourceIDs.add(applicationInput.getInterfaceID());
+ }
+ }
+ } else {
+ em.getTransaction().commit();
+ em.close();
+ logger.error("Unsupported field name for AppInput resource.", new IllegalArgumentException());
+ throw new IllegalArgumentException("Unsupported field name for AppInput 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 appInputResourceIDs;
+ }
+
+ public void save() throws AppCatalogException {
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ ApplicationInput existingApplicationInput = em.find(ApplicationInput.class, new AppInput_PK(interfaceID, inputKey));
+ em.close();
+
+ em = AppCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ if (existingApplicationInput != null) {
+ existingApplicationInput.setInterfaceID(interfaceID);
+ ApplicationInterface applicationInterface = em.find(ApplicationInterface.class, interfaceID);
+ existingApplicationInput.setApplicationInterface(applicationInterface);
+ existingApplicationInput.setDataType(dataType);
+ existingApplicationInput.setInputKey(inputKey);
+ existingApplicationInput.setInputVal(inputVal);
+ existingApplicationInput.setMetadata(metadata);
+ existingApplicationInput.setAppParameter(appParameter);
+ existingApplicationInput.setAppUIDesc(appUIDesc);
+
+ em.merge(existingApplicationInput);
+ } else {
+ ApplicationInput applicationInput = new ApplicationInput();
+ applicationInput.setInterfaceID(interfaceID);
+ ApplicationInterface applicationInterface = em.find(ApplicationInterface.class, interfaceID);
+ applicationInput.setApplicationInterface(applicationInterface);
+ applicationInput.setDataType(dataType);
+ applicationInput.setInputKey(inputKey);
+ applicationInput.setInputVal(inputVal);
+ applicationInput.setMetadata(metadata);
+ applicationInput.setAppParameter(appParameter);
+ applicationInput.setAppUIDesc(appUIDesc);
+
+ em.persist(applicationInput);
+ }
+ 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();
+ ApplicationInput applicationInput = em.find(ApplicationInput.class, new AppInput_PK(
+ ids.get(AppInputConstants.INTERFACE_ID),
+ ids.get(AppInputConstants.INPUT_KEY)));
+
+ em.close();
+ return applicationInput != 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 getInterfaceID() {
+ return interfaceID;
+ }
+
+ public void setInterfaceID(String interfaceID) {
+ this.interfaceID = interfaceID;
+ }
+
+ 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 getAppParameter() {
+ return appParameter;
+ }
+
+ public void setAppParameter(String appParameter) {
+ this.appParameter = appParameter;
+ }
+
+ public String getAppUIDesc() {
+ return appUIDesc;
+ }
+
+ public void setAppUIDesc(String appUIDesc) {
+ this.appUIDesc = appUIDesc;
+ }
+
+ public AppInterfaceResource getAppInterfaceResource() {
+ return appInterfaceResource;
+ }
+
+ public void setAppInterfaceResource(AppInterfaceResource appInterfaceResource) {
+ this.appInterfaceResource = appInterfaceResource;
+ }
+}
http://git-wip-us.apache.org/repos/asf/airavata/blob/856b557f/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/ApplicationOutputResource.java
----------------------------------------------------------------------
diff --git a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/ApplicationOutputResource.java b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/ApplicationOutputResource.java
new file mode 100644
index 0000000..7046fd7
--- /dev/null
+++ b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/ApplicationOutputResource.java
@@ -0,0 +1,359 @@
+package org.apache.aiaravata.application.catalog.data.resources;
+
+import org.airavata.appcatalog.cpi.AppCatalogException;
+import org.apache.aiaravata.application.catalog.data.model.AppOutput_PK;
+import org.apache.aiaravata.application.catalog.data.model.ApplicationInterface;
+import org.apache.aiaravata.application.catalog.data.model.ApplicationOutput;
+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 ApplicationOutputResource extends AbstractResource {
+ private final static Logger logger = LoggerFactory.getLogger(ApplicationOutputResource.class);
+
+ private String interfaceID;
+ private String outputKey;
+ private String outputVal;
+ private String dataType;
+ private String metadata;
+
+ private AppInterfaceResource appInterfaceResource;
+
+ 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(APPLICATION_OUTPUT);
+ generator.setParameter(AppOutputConstants.INTERFACE_ID, ids.get(AppOutputConstants.INTERFACE_ID));
+ generator.setParameter(AppOutputConstants.OUTPUT_KEY, ids.get(AppOutputConstants.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(APPLICATION_OUTPUT);
+ generator.setParameter(AppOutputConstants.INTERFACE_ID, ids.get(AppOutputConstants.INTERFACE_ID));
+ generator.setParameter(AppOutputConstants.OUTPUT_KEY, ids.get(AppOutputConstants.OUTPUT_KEY));
+ Query q = generator.selectQuery(em);
+ ApplicationOutput applicationOutput = (ApplicationOutput) q.getSingleResult();
+ ApplicationOutputResource applicationOutputResource =
+ (ApplicationOutputResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.APPLICATION_OUTPUT
+ , applicationOutput);
+ em.getTransaction().commit();
+ em.close();
+ return applicationOutputResource;
+ } 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> appInputResources = new ArrayList<Resource>();
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ Query q;
+ AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(APPLICATION_OUTPUT);
+ List results;
+ if (fieldName.equals(AppOutputConstants.INTERFACE_ID)) {
+ generator.setParameter(AppOutputConstants.INTERFACE_ID, value);
+ q = generator.selectQuery(em);
+ results = q.getResultList();
+ if (results.size() != 0) {
+ for (Object result : results) {
+ ApplicationOutput applicationOutput = (ApplicationOutput) result;
+ ApplicationOutputResource applicationOutputResource =
+ (ApplicationOutputResource) AppCatalogJPAUtils.getResource(
+ AppCatalogResourceType.APPLICATION_OUTPUT, applicationOutput);
+ appInputResources.add(applicationOutputResource);
+ }
+ }
+ } else if (fieldName.equals(AppOutputConstants.OUTPUT_KEY)) {
+ generator.setParameter(AppOutputConstants.OUTPUT_KEY, value);
+ q = generator.selectQuery(em);
+ results = q.getResultList();
+ if (results.size() != 0) {
+ for (Object result : results) {
+ ApplicationOutput applicationOutput = (ApplicationOutput) result;
+ ApplicationOutputResource applicationOutputResource =
+ (ApplicationOutputResource) AppCatalogJPAUtils.getResource(
+ AppCatalogResourceType.APPLICATION_OUTPUT, applicationOutput);
+ appInputResources.add(applicationOutputResource);
+ }
+ }
+ } else if (fieldName.equals(AppOutputConstants.DATA_TYPE)) {
+ generator.setParameter(AppOutputConstants.DATA_TYPE, value);
+ q = generator.selectQuery(em);
+ results = q.getResultList();
+ if (results.size() != 0) {
+ for (Object result : results) {
+ ApplicationOutput applicationOutput = (ApplicationOutput) result;
+ ApplicationOutputResource applicationOutputResource =
+ (ApplicationOutputResource) AppCatalogJPAUtils.getResource(
+ AppCatalogResourceType.APPLICATION_OUTPUT, applicationOutput);
+ appInputResources.add(applicationOutputResource);
+ }
+ }
+ } else {
+ em.getTransaction().commit();
+ em.close();
+ logger.error("Unsupported field name for App Output Resource.", new IllegalArgumentException());
+ throw new IllegalArgumentException("Unsupported field name for App 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 appInputResources;
+ }
+
+ public List<String> getIds(String fieldName, Object value) throws AppCatalogException {
+ List<String> appOutputResourceIDs = new ArrayList<String>();
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ Query q;
+ AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(APPLICATION_OUTPUT);
+ List results;
+ if (fieldName.equals(AppOutputConstants.INTERFACE_ID)) {
+ generator.setParameter(AppOutputConstants.INTERFACE_ID, value);
+ q = generator.selectQuery(em);
+ results = q.getResultList();
+ if (results.size() != 0) {
+ for (Object result : results) {
+ ApplicationOutput applicationOutput = (ApplicationOutput) result;
+ appOutputResourceIDs.add(applicationOutput.getInterfaceID());
+ }
+ }
+ }
+ if (fieldName.equals(AppOutputConstants.OUTPUT_KEY)) {
+ generator.setParameter(AppOutputConstants.OUTPUT_KEY, value);
+ q = generator.selectQuery(em);
+ results = q.getResultList();
+ if (results.size() != 0) {
+ for (Object result : results) {
+ ApplicationOutput applicationOutput = (ApplicationOutput) result;
+ appOutputResourceIDs.add(applicationOutput.getInterfaceID());
+ }
+ }
+ } else if (fieldName.equals(AppOutputConstants.DATA_TYPE)) {
+ generator.setParameter(AppOutputConstants.DATA_TYPE, value);
+ q = generator.selectQuery(em);
+ results = q.getResultList();
+ if (results.size() != 0) {
+ for (Object result : results) {
+ ApplicationOutput applicationOutput = (ApplicationOutput) result;
+ appOutputResourceIDs.add(applicationOutput.getInterfaceID());
+ }
+ }
+ } else {
+ em.getTransaction().commit();
+ em.close();
+ logger.error("Unsupported field name for App Output resource.", new IllegalArgumentException());
+ throw new IllegalArgumentException("Unsupported field name for App 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 appOutputResourceIDs;
+ }
+
+ public void save() throws AppCatalogException {
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ ApplicationOutput existingApplicationOutput = em.find(ApplicationOutput.class,
+ new AppOutput_PK(interfaceID, outputKey));
+ em.close();
+
+ em = AppCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ if (existingApplicationOutput != null) {
+ existingApplicationOutput.setInterfaceID(interfaceID);
+ ApplicationInterface applicationInterface = em.find(ApplicationInterface.class, interfaceID);
+ existingApplicationOutput.setApplicationInterface(applicationInterface);
+ existingApplicationOutput.setDataType(dataType);
+ existingApplicationOutput.setOutputKey(outputKey);
+ existingApplicationOutput.setOutputVal(outputVal);
+ existingApplicationOutput.setMetadata(metadata);
+
+ em.merge(existingApplicationOutput);
+ } else {
+ ApplicationOutput applicationOutput = new ApplicationOutput();
+ applicationOutput.setInterfaceID(interfaceID);
+ ApplicationInterface applicationInterface = em.find(ApplicationInterface.class, interfaceID);
+ applicationOutput.setApplicationInterface(applicationInterface);
+ applicationOutput.setDataType(dataType);
+ applicationOutput.setOutputKey(outputKey);
+ applicationOutput.setOutputVal(outputVal);
+ applicationOutput.setMetadata(metadata);
+
+ em.persist(applicationOutput);
+ }
+ 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();
+ ApplicationOutput applicationOutput = em.find(ApplicationOutput.class, new AppOutput_PK(
+ ids.get(AppOutputConstants.INTERFACE_ID),
+ ids.get(AppOutputConstants.OUTPUT_KEY)));
+
+ em.close();
+ return applicationOutput != 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 getInterfaceID() {
+ return interfaceID;
+ }
+
+ public void setInterfaceID(String interfaceID) {
+ this.interfaceID = interfaceID;
+ }
+
+ 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 String getMetadata() {
+ return metadata;
+ }
+
+ public void setMetadata(String metadata) {
+ this.metadata = metadata;
+ }
+
+ public AppInterfaceResource getAppInterfaceResource() {
+ return appInterfaceResource;
+ }
+
+ public void setAppInterfaceResource(AppInterfaceResource appInterfaceResource) {
+ this.appInterfaceResource = appInterfaceResource;
+ }
+}
http://git-wip-us.apache.org/repos/asf/airavata/blob/856b557f/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/GatewayProfileResource.java
----------------------------------------------------------------------
diff --git a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/GatewayProfileResource.java b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/GatewayProfileResource.java
new file mode 100644
index 0000000..9a2ac65
--- /dev/null
+++ b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/GatewayProfileResource.java
@@ -0,0 +1,271 @@
+package org.apache.aiaravata.application.catalog.data.resources;
+
+import org.airavata.appcatalog.cpi.AppCatalogException;
+import org.apache.aiaravata.application.catalog.data.model.GatewayProfile;
+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.List;
+
+public class GatewayProfileResource extends AbstractResource {
+ private final static Logger logger = LoggerFactory.getLogger(GatewayProfileResource.class);
+
+ private String gatewayID;
+ private String gatewayName;
+ private String gatewayDesc;
+ private String preferedResource;
+
+ public void remove(Object identifier) throws AppCatalogException {
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(GATEWAY_PROFILE);
+ generator.setParameter(GatewayProfileConstants.GATEWAY_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();
+ }
+ }
+ }
+
+ public Resource get(Object identifier) throws AppCatalogException {
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(GATEWAY_PROFILE);
+ generator.setParameter(GatewayProfileConstants.GATEWAY_ID, identifier);
+ Query q = generator.selectQuery(em);
+ GatewayProfile gatewayProfile = (GatewayProfile) q.getSingleResult();
+ GatewayProfileResource gatewayProfileResource =
+ (GatewayProfileResource) AppCatalogJPAUtils.getResource(
+ AppCatalogResourceType.GATEWAY_PROFILE, gatewayProfile);
+ em.getTransaction().commit();
+ em.close();
+ return gatewayProfileResource;
+ } 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> gatewayProfileResources = new ArrayList<Resource>();
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ Query q;
+ AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(GATEWAY_PROFILE);
+ List results;
+ if (fieldName.equals(GatewayProfileConstants.GATEWAY_ID)) {
+ generator.setParameter(GatewayProfileConstants.GATEWAY_ID, value);
+ q = generator.selectQuery(em);
+ results = q.getResultList();
+ if (results.size() != 0) {
+ for (Object result : results) {
+ GatewayProfile gatewayProfile = (GatewayProfile) result;
+ GatewayProfileResource gatewayProfileResource =
+ (GatewayProfileResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.GATEWAY_PROFILE, gatewayProfile);
+ gatewayProfileResources.add(gatewayProfileResource);
+ }
+ }
+ } else if (fieldName.equals(GatewayProfileConstants.GATEWAY_NAME)) {
+ generator.setParameter(GatewayProfileConstants.GATEWAY_NAME, value);
+ q = generator.selectQuery(em);
+ results = q.getResultList();
+ if (results.size() != 0) {
+ for (Object result : results) {
+ GatewayProfile gatewayProfile = (GatewayProfile) result;
+ GatewayProfileResource gatewayProfileResource =
+ (GatewayProfileResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.GATEWAY_PROFILE, gatewayProfile);
+ gatewayProfileResources.add(gatewayProfileResource);
+ }
+ }
+ } else {
+ em.getTransaction().commit();
+ em.close();
+ logger.error("Unsupported field name for Gateway Profile resource.", new IllegalArgumentException());
+ throw new IllegalArgumentException("Unsupported field name for Gateway Profile 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 gatewayProfileResources;
+ }
+
+ public List<String> getIds(String fieldName, Object value) throws AppCatalogException {
+ List<String> gatewayProfileResourceIDs = new ArrayList<String>();
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ Query q;
+ AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(GATEWAY_PROFILE);
+ List results;
+ if (fieldName.equals(GatewayProfileConstants.GATEWAY_ID)) {
+ generator.setParameter(GatewayProfileConstants.GATEWAY_ID, value);
+ q = generator.selectQuery(em);
+ results = q.getResultList();
+ if (results.size() != 0) {
+ for (Object result : results) {
+ GatewayProfile gatewayProfile = (GatewayProfile) result;
+ gatewayProfileResourceIDs.add(gatewayProfile.getGatewayID());
+ }
+ }
+ } else if (fieldName.equals(GatewayProfileConstants.GATEWAY_NAME)) {
+ generator.setParameter(GatewayProfileConstants.GATEWAY_NAME, value);
+ q = generator.selectQuery(em);
+ results = q.getResultList();
+ if (results.size() != 0) {
+ for (Object result : results) {
+ GatewayProfile gatewayProfile = (GatewayProfile) result;
+ gatewayProfileResourceIDs.add(gatewayProfile.getGatewayID());
+ }
+ }
+ } else {
+ em.getTransaction().commit();
+ em.close();
+ logger.error("Unsupported field name for Gateway Profile resource.", new IllegalArgumentException());
+ throw new IllegalArgumentException("Unsupported field name for Gateway Profile 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 gatewayProfileResourceIDs;
+ }
+
+ public void save() throws AppCatalogException {
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ GatewayProfile existingGatewayProfile = em.find(GatewayProfile.class, gatewayID);
+ em.close();
+
+ em = AppCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ if (existingGatewayProfile != null) {
+ existingGatewayProfile.setGatewayDesc(gatewayDesc);
+ existingGatewayProfile.setGatewayName(gatewayName);
+ existingGatewayProfile.setPreferedResource(preferedResource);
+ em.merge(existingGatewayProfile);
+ } else {
+ GatewayProfile gatewayProfile = new GatewayProfile();
+ gatewayProfile.setGatewayID(gatewayID);
+ gatewayProfile.setGatewayName(gatewayName);
+ gatewayProfile.setGatewayDesc(gatewayDesc);
+ gatewayProfile.setPreferedResource(preferedResource);
+ em.persist(gatewayProfile);
+ }
+ 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 {
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ GatewayProfile gatewayProfile = em.find(GatewayProfile.class, identifier);
+ em.close();
+ return gatewayProfile != 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 getGatewayID() {
+ return gatewayID;
+ }
+
+ public void setGatewayID(String gatewayID) {
+ this.gatewayID = gatewayID;
+ }
+
+ public String getGatewayName() {
+ return gatewayName;
+ }
+
+ public void setGatewayName(String gatewayName) {
+ this.gatewayName = gatewayName;
+ }
+
+ public String getGatewayDesc() {
+ return gatewayDesc;
+ }
+
+ public void setGatewayDesc(String gatewayDesc) {
+ this.gatewayDesc = gatewayDesc;
+ }
+
+ public String getPreferedResource() {
+ return preferedResource;
+ }
+
+ public void setPreferedResource(String preferedResource) {
+ this.preferedResource = preferedResource;
+ }
+}