You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ch...@apache.org on 2015/06/04 22:34:33 UTC
[45/51] [abbrv] [partial] airavata git commit: registry refactoring
http://git-wip-us.apache.org/repos/asf/airavata/blob/ec8c6202/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/AppEnvironmentResource.java
----------------------------------------------------------------------
diff --git a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/AppEnvironmentResource.java b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/AppEnvironmentResource.java
deleted file mode 100644
index 98f753f..0000000
--- a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/AppEnvironmentResource.java
+++ /dev/null
@@ -1,293 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-
-package org.apache.aiaravata.application.catalog.data.resources;
-
-import org.airavata.appcatalog.cpi.AppCatalogException;
-import org.apache.aiaravata.application.catalog.data.model.AppEnvironment;
-import org.apache.aiaravata.application.catalog.data.model.AppEnvironment_PK;
-import org.apache.aiaravata.application.catalog.data.model.ApplicationDeployment;
-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 AppEnvironmentResource extends AbstractResource {
- private final static Logger logger = LoggerFactory.getLogger(AppEnvironmentResource.class);
- private String deploymentId;
- private String name;
- private String value;
- private AppDeploymentResource appDeploymentResource;
-
- public String getDeploymentId() {
- return deploymentId;
- }
-
- public void setDeploymentId(String deploymentId) {
- this.deploymentId = deploymentId;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getValue() {
- return value;
- }
-
- public void setValue(String value) {
- this.value = value;
- }
-
- public AppDeploymentResource getAppDeploymentResource() {
- return appDeploymentResource;
- }
-
- public void setAppDeploymentResource(AppDeploymentResource appDeploymentResource) {
- this.appDeploymentResource = appDeploymentResource;
- }
-
- @Override
- 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(APP_ENVIRONMENT);
- generator.setParameter(AppEnvironmentConstants.DEPLOYMENT_ID, ids.get(AppEnvironmentConstants.DEPLOYMENT_ID));
- if (ids.get(AppEnvironmentConstants.NAME) != null){
- generator.setParameter(AppEnvironmentConstants.NAME, ids.get(AppEnvironmentConstants.NAME));
- }
-
- 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 {
- 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(APP_ENVIRONMENT);
- generator.setParameter(AppEnvironmentConstants.DEPLOYMENT_ID, ids.get(AppEnvironmentConstants.DEPLOYMENT_ID));
- generator.setParameter(AppEnvironmentConstants.NAME, ids.get(AppEnvironmentConstants.NAME));
- Query q = generator.selectQuery(em);
- AppEnvironment appEnvironment = (AppEnvironment) q.getSingleResult();
- AppEnvironmentResource resource =
- (AppEnvironmentResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.APP_ENVIRONMENT, appEnvironment);
- em.getTransaction().commit();
- em.close();
- return resource;
- } 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> appEnvironmentList = new ArrayList<Resource>();
- EntityManager em = null;
- try {
- em = AppCatalogJPAUtils.getEntityManager();
- em.getTransaction().begin();
- Query q;
- AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(APP_ENVIRONMENT);
- List results;
- if (fieldName.equals(AppEnvironmentConstants.DEPLOYMENT_ID)) {
- generator.setParameter(AppEnvironmentConstants.DEPLOYMENT_ID, value);
- q = generator.selectQuery(em);
- results = q.getResultList();
- if (results.size() != 0) {
- for (Object result : results) {
- AppEnvironment appEnvironment = (AppEnvironment) result;
- AppEnvironmentResource resource =
- (AppEnvironmentResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.APP_ENVIRONMENT, appEnvironment);
- appEnvironmentList.add(resource);
- }
- }
- } else if (fieldName.equals(AppEnvironmentConstants.NAME)) {
- generator.setParameter(AppEnvironmentConstants.NAME, value);
- q = generator.selectQuery(em);
- results = q.getResultList();
- if (results.size() != 0) {
- for (Object result : results) {
- AppEnvironment appEnvironment = (AppEnvironment) result;
- AppEnvironmentResource resource =
- (AppEnvironmentResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.APP_ENVIRONMENT, appEnvironment);
- appEnvironmentList.add(resource);
- }
- }
- }else {
- em.getTransaction().commit();
- em.close();
- logger.error("Unsupported field name for App Environment resource.", new IllegalArgumentException());
- throw new IllegalArgumentException("Unsupported field name for App Environment 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 appEnvironmentList;
- }
-
- @Override
- public List<Resource> getAll() throws AppCatalogException {
- return null;
- }
-
- @Override
- public List<String> getAllIds() throws AppCatalogException {
- return null;
- }
-
- @Override
- public List<String> getIds(String fieldName, Object value) throws AppCatalogException {
- logger.error("Unsupported for objects with a composite identifier");
- throw new AppCatalogException("Unsupported for objects with a composite identifier");
- }
-
- @Override
- public void save() throws AppCatalogException {
- EntityManager em = null;
- try {
- em = AppCatalogJPAUtils.getEntityManager();
- AppEnvironment existigAppEnv = em.find(AppEnvironment.class, new AppEnvironment_PK(deploymentId, name));
- em.close();
-
- em = AppCatalogJPAUtils.getEntityManager();
- em.getTransaction().begin();
-
- ApplicationDeployment deployment = em.find(ApplicationDeployment.class, deploymentId);
- if (existigAppEnv != null){
- existigAppEnv.setValue(value);
- existigAppEnv.setApplicationDeployment(deployment);
- em.merge(existigAppEnv);
- }else {
- AppEnvironment appEnvironment = new AppEnvironment();
- appEnvironment.setDeploymentID(deploymentId);
- appEnvironment.setName(name);
- appEnvironment.setValue(value);
- appEnvironment.setApplicationDeployment(deployment);
- em.persist(appEnvironment);
- }
- 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 {
- 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();
- AppEnvironment appEnvironment = em.find(AppEnvironment.class,
- new AppEnvironment_PK(ids.get(AppEnvironmentConstants.DEPLOYMENT_ID),
- ids.get(AppEnvironmentConstants.NAME)));
- em.close();
- return appEnvironment != 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();
- }
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/ec8c6202/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/AppInterfaceResource.java
----------------------------------------------------------------------
diff --git a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/AppInterfaceResource.java b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/AppInterfaceResource.java
deleted file mode 100644
index 3f6b60d..0000000
--- a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/AppInterfaceResource.java
+++ /dev/null
@@ -1,363 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-
-package org.apache.aiaravata.application.catalog.data.resources;
-
-import org.airavata.appcatalog.cpi.AppCatalogException;
-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.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 AppInterfaceResource extends AbstractResource {
- private final static Logger logger = LoggerFactory.getLogger(AppInterfaceResource.class);
- private String interfaceId;
- private String appName;
- private String appDescription;
- private Timestamp createdTime;
- private Timestamp updatedTime;
- private String gatewayId;
-
- public String getGatewayId() {
- return gatewayId;
- }
-
- public void setGatewayId(String gatewayId) {
- this.gatewayId = 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 getInterfaceId() {
- return interfaceId;
- }
-
- public void setInterfaceId(String interfaceId) {
- this.interfaceId = interfaceId;
- }
-
- public String getAppName() {
- return appName;
- }
-
- public void setAppName(String appName) {
- this.appName = appName;
- }
-
- public String getAppDescription() {
- return appDescription;
- }
-
- public void setAppDescription(String appDescription) {
- this.appDescription = appDescription;
- }
-
- @Override
- public void remove(Object identifier) throws AppCatalogException {
- EntityManager em = null;
- try {
- em = AppCatalogJPAUtils.getEntityManager();
- em.getTransaction().begin();
- AppCatalogQueryGenerator generator= new AppCatalogQueryGenerator(APPLICATION_INTERFACE);
- generator.setParameter(ApplicationInterfaceConstants.INTERFACE_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(APPLICATION_INTERFACE);
- generator.setParameter(ApplicationInterfaceConstants.INTERFACE_ID, identifier);
- Query q = generator.selectQuery(em);
- ApplicationInterface applicationInterface = (ApplicationInterface) q.getSingleResult();
- AppInterfaceResource resource =
- (AppInterfaceResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.APPLICATION_INTERFACE, applicationInterface);
- em.getTransaction().commit();
- em.close();
- return resource;
- } 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> resourceList = new ArrayList<Resource>();
- EntityManager em = null;
- try {
- em = AppCatalogJPAUtils.getEntityManager();
- em.getTransaction().begin();
- Query q;
- AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(APPLICATION_INTERFACE);
- List results;
- if (fieldName.equals(ApplicationInterfaceConstants.APPLICATION_NAME)) {
- generator.setParameter(ApplicationInterfaceConstants.APPLICATION_NAME, value);
- q = generator.selectQuery(em);
- results = q.getResultList();
- if (results.size() != 0) {
- for (Object result : results) {
- ApplicationInterface appInterface = (ApplicationInterface) result;
- AppInterfaceResource resource =
- (AppInterfaceResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.APPLICATION_INTERFACE, appInterface);
- resourceList.add(resource);
- }
- }
- } else {
- em.getTransaction().commit();
- em.close();
- logger.error("Unsupported field name for application interface.", new IllegalArgumentException());
- throw new IllegalArgumentException("Unsupported field name for application interface.");
- }
- 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 resourceList;
- }
-
- @Override
- public List<Resource> getAll() throws AppCatalogException {
- List<Resource> resourceList = new ArrayList<Resource>();
- EntityManager em = null;
- try {
- em = AppCatalogJPAUtils.getEntityManager();
- em.getTransaction().begin();
- AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(APPLICATION_INTERFACE);
- generator.setParameter(ApplicationInterfaceConstants.GATEWAY_ID, gatewayId);
- Query q = generator.selectQuery(em);
- List results = q.getResultList();
- if (results.size() != 0) {
- for (Object result : results) {
- ApplicationInterface appInterface = (ApplicationInterface) result;
- AppInterfaceResource resource =
- (AppInterfaceResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.APPLICATION_INTERFACE, appInterface);
- resourceList.add(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 resourceList;
- }
-
- @Override
- public List<String> getAllIds() throws AppCatalogException {
- List<String> resourceList = new ArrayList<String>();
- EntityManager em = null;
- try {
- em = AppCatalogJPAUtils.getEntityManager();
- em.getTransaction().begin();
- AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(APPLICATION_INTERFACE);
- Query q = generator.selectQuery(em);
- List results = q.getResultList();
- if (results.size() != 0) {
- for (Object result : results) {
- ApplicationInterface appInterface = (ApplicationInterface) result;
- resourceList.add(appInterface.getInterfaceID());
- }
- }
- 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 resourceList;
- }
-
- @Override
- public List<String> getIds(String fieldName, Object value) throws AppCatalogException {
- List<String> resourceList = new ArrayList<String>();
- EntityManager em = null;
- try {
- em = AppCatalogJPAUtils.getEntityManager();
- em.getTransaction().begin();
- Query q;
- AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(APPLICATION_INTERFACE);
- List results;
- if (fieldName.equals(ApplicationInterfaceConstants.APPLICATION_NAME)) {
- generator.setParameter(ApplicationInterfaceConstants.APPLICATION_NAME, value);
- q = generator.selectQuery(em);
- results = q.getResultList();
- if (results.size() != 0) {
- for (Object result : results) {
- ApplicationInterface appInterface = (ApplicationInterface) result;
- resourceList.add(appInterface.getInterfaceID());
- }
- }
- } else {
- em.getTransaction().commit();
- em.close();
- logger.error("Unsupported field name for application interface.", new IllegalArgumentException());
- throw new IllegalArgumentException("Unsupported field name for application interface.");
- }
- 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 resourceList;
- }
-
- @Override
- public void save() throws AppCatalogException {
- EntityManager em = null;
- try {
- em = AppCatalogJPAUtils.getEntityManager();
- ApplicationInterface existigAppInterface = em.find(ApplicationInterface.class, interfaceId);
- em.close();
-
- em = AppCatalogJPAUtils.getEntityManager();
- em.getTransaction().begin();
- if (existigAppInterface != null){
- existigAppInterface.setAppName(appName);
- existigAppInterface.setAppDescription(appDescription);
- existigAppInterface.setUpdateTime(AiravataUtils.getCurrentTimestamp());
- existigAppInterface.setGatewayId(gatewayId);
- em.merge(existigAppInterface);
- }else {
- ApplicationInterface applicationInterface = new ApplicationInterface();
- applicationInterface.setInterfaceID(interfaceId);
- applicationInterface.setAppName(appName);
- applicationInterface.setAppDescription(appDescription);
- applicationInterface.setCreationTime(AiravataUtils.getCurrentTimestamp());
- applicationInterface.setGatewayId(gatewayId);
- em.persist(applicationInterface);
- }
- 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();
- ApplicationInterface existigAppInterface = em.find(ApplicationInterface.class, identifier);
- em.close();
- return existigAppInterface != null;
- }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();
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/airavata/blob/ec8c6202/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/AppModuleMappingResource.java
----------------------------------------------------------------------
diff --git a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/AppModuleMappingResource.java b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/AppModuleMappingResource.java
deleted file mode 100644
index a44229d..0000000
--- a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/AppModuleMappingResource.java
+++ /dev/null
@@ -1,317 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-
-package org.apache.aiaravata.application.catalog.data.resources;
-
-import org.airavata.appcatalog.cpi.AppCatalogException;
-import org.apache.aiaravata.application.catalog.data.model.AppModuleMapping;
-import org.apache.aiaravata.application.catalog.data.model.AppModuleMapping_PK;
-import org.apache.aiaravata.application.catalog.data.model.ApplicationInterface;
-import org.apache.aiaravata.application.catalog.data.model.ApplicationModule;
-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 AppModuleMappingResource extends AbstractResource {
- private final static Logger logger = LoggerFactory.getLogger(AppModuleMappingResource.class);
- private String interfaceId;
- private String moduleId;
- private AppInterfaceResource appInterfaceResource;
- private AppModuleResource moduleResource;
-
-
- public String getModuleId() {
- return moduleId;
- }
-
- public void setModuleId(String moduleId) {
- this.moduleId = moduleId;
- }
-
- public String getInterfaceId() {
- return interfaceId;
- }
-
- public void setInterfaceId(String interfaceId) {
- this.interfaceId = interfaceId;
- }
-
- public AppInterfaceResource getAppInterfaceResource() {
- return appInterfaceResource;
- }
-
- public void setAppInterfaceResource(AppInterfaceResource appInterfaceResource) {
- this.appInterfaceResource = appInterfaceResource;
- }
-
- public AppModuleResource getModuleResource() {
- return moduleResource;
- }
-
- public void setModuleResource(AppModuleResource moduleResource) {
- this.moduleResource = moduleResource;
- }
-
- @Override
- 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(APP_MODULE_MAPPING);
- generator.setParameter(AppModuleMappingConstants.INTERFACE_ID, ids.get(AppModuleMappingConstants.INTERFACE_ID));
- if (ids.get(AppModuleMappingConstants.MODULE_ID) != null){
- generator.setParameter(AppModuleMappingConstants.MODULE_ID, ids.get(AppModuleMappingConstants.MODULE_ID));
- }
- 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 void removeAll() throws AppCatalogException {
- EntityManager em = null;
- try {
- em = AppCatalogJPAUtils.getEntityManager();
- em.getTransaction().begin();
- AppCatalogQueryGenerator generator= new AppCatalogQueryGenerator(APP_MODULE_MAPPING);
- 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 {
- 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(APP_MODULE_MAPPING);
- generator.setParameter(AppModuleMappingConstants.INTERFACE_ID, ids.get(AppModuleMappingConstants.INTERFACE_ID));
- generator.setParameter(AppModuleMappingConstants.MODULE_ID, ids.get(AppModuleMappingConstants.MODULE_ID));
- Query q = generator.selectQuery(em);
- AppModuleMapping result = (AppModuleMapping) q.getSingleResult();
- AppModuleMappingResource resource =
- (AppModuleMappingResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.APP_MODULE_MAPPING, result);
- em.getTransaction().commit();
- em.close();
- return resource;
- } 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> resourceList = new ArrayList<Resource>();
- EntityManager em = null;
- try {
- em = AppCatalogJPAUtils.getEntityManager();
- em.getTransaction().begin();
- Query q;
- AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(APP_MODULE_MAPPING);
- List results;
- if (fieldName.equals(AppModuleMappingConstants.INTERFACE_ID)) {
- generator.setParameter(AppModuleMappingConstants.INTERFACE_ID, value);
- q = generator.selectQuery(em);
- results = q.getResultList();
- if (results.size() != 0) {
- for (Object result : results) {
- AppModuleMapping moduleMapping = (AppModuleMapping) result;
- AppModuleMappingResource resource =
- (AppModuleMappingResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.APP_MODULE_MAPPING, moduleMapping);
- resourceList.add(resource);
- }
- }
- } else if (fieldName.equals(AppModuleMappingConstants.MODULE_ID)) {
- generator.setParameter(AppModuleMappingConstants.MODULE_ID, value);
- q = generator.selectQuery(em);
- results = q.getResultList();
- if (results.size() != 0) {
- for (Object result : results) {
- AppModuleMapping moduleMapping = (AppModuleMapping) result;
- AppModuleMappingResource resource =
- (AppModuleMappingResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.APP_MODULE_MAPPING, moduleMapping);
- resourceList.add(resource);
- }
- }
- }else {
- em.getTransaction().commit();
- em.close();
- logger.error("Unsupported field name for app module mapping resource.", new IllegalArgumentException());
- throw new IllegalArgumentException("Unsupported field name for app module mapping 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 resourceList;
- }
-
- @Override
- public List<Resource> getAll() throws AppCatalogException {
- return null;
- }
-
- @Override
- public List<String> getAllIds() throws AppCatalogException {
- return null;
- }
-
- @Override
- public List<String> getIds(String fieldName, Object value) throws AppCatalogException {
- logger.error("Unsupported for objects with a composite identifier");
- throw new AppCatalogException("Unsupported for objects with a composite identifier");
- }
-
- @Override
- public void save() throws AppCatalogException {
- EntityManager em = null;
- try {
- em = AppCatalogJPAUtils.getEntityManager();
- AppModuleMapping existngModuleMap = em.find(AppModuleMapping.class, new AppModuleMapping_PK(interfaceId, moduleId));
- em.close();
-
- em = AppCatalogJPAUtils.getEntityManager();
- em.getTransaction().begin();
- ApplicationInterface applicationInterface = em.find(ApplicationInterface.class, interfaceId);
- ApplicationModule applicationModule = em.find(ApplicationModule.class, moduleId);
- if (existngModuleMap != null){
- existngModuleMap.setApplicationInterface(applicationInterface);
- existngModuleMap.setApplicationModule(applicationModule);
- em.merge(existngModuleMap);
- }else {
- AppModuleMapping appModuleMapping = new AppModuleMapping();
- appModuleMapping.setInterfaceID(interfaceId);
- appModuleMapping.setApplicationInterface(applicationInterface);
- appModuleMapping.setModuleID(moduleId);
- appModuleMapping.setApplicationModule(applicationModule);
- em.persist(appModuleMapping);
- }
- 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 {
- 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();
- AppModuleMapping moduleMapping = em.find(AppModuleMapping.class,
- new AppModuleMapping_PK(ids.get(AppModuleMappingConstants.INTERFACE_ID),
- ids.get(AppModuleMappingConstants.MODULE_ID)));
- em.close();
- return moduleMapping != 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();
- }
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/ec8c6202/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/AppModuleResource.java
----------------------------------------------------------------------
diff --git a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/AppModuleResource.java b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/AppModuleResource.java
deleted file mode 100644
index 79803af..0000000
--- a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/AppModuleResource.java
+++ /dev/null
@@ -1,344 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-
-package org.apache.aiaravata.application.catalog.data.resources;
-
-import org.airavata.appcatalog.cpi.AppCatalogException;
-import org.apache.aiaravata.application.catalog.data.model.ApplicationModule;
-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 AppModuleResource extends AbstractResource {
- private final static Logger logger = LoggerFactory.getLogger(AppModuleResource.class);
- private String moduleId;
- private String moduleName;
- private String moduleVersion;
- private String moduleDesc;
- private Timestamp createdTime;
- private Timestamp updatedTime;
- private String gatewayId;
-
- public String getGatewayId() {
- return gatewayId;
- }
-
- public void setGatewayId(String gatewayId) {
- this.gatewayId = 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 getModuleId() {
- return moduleId;
- }
-
- public void setModuleId(String moduleId) {
- this.moduleId = moduleId;
- }
-
- public String getModuleName() {
- return moduleName;
- }
-
- public void setModuleName(String moduleName) {
- this.moduleName = moduleName;
- }
-
- public String getModuleVersion() {
- return moduleVersion;
- }
-
- public void setModuleVersion(String moduleVersion) {
- this.moduleVersion = moduleVersion;
- }
-
- public String getModuleDesc() {
- return moduleDesc;
- }
-
- public void setModuleDesc(String moduleDesc) {
- this.moduleDesc = moduleDesc;
- }
-
- @Override
- public void remove(Object identifier) throws AppCatalogException {
- EntityManager em = null;
- try {
- em = AppCatalogJPAUtils.getEntityManager();
- em.getTransaction().begin();
- AppCatalogQueryGenerator generator= new AppCatalogQueryGenerator(APPLICATION_MODULE);
- generator.setParameter(ApplicationModuleConstants.MODULE_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(APPLICATION_MODULE);
- generator.setParameter(ApplicationModuleConstants.MODULE_ID, identifier);
- Query q = generator.selectQuery(em);
- ApplicationModule applicationModule = (ApplicationModule) q.getSingleResult();
- AppModuleResource appModuleResource =
- (AppModuleResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.APPLICATION_MODULE, applicationModule);
- em.getTransaction().commit();
- em.close();
- return appModuleResource;
- } 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> moduleResources = new ArrayList<Resource>();
- EntityManager em = null;
- try {
- em = AppCatalogJPAUtils.getEntityManager();
- em.getTransaction().begin();
- Query q;
- AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(APPLICATION_MODULE);
- List results;
- if (fieldName.equals(ApplicationModuleConstants.MODULE_NAME)) {
- generator.setParameter(ApplicationModuleConstants.MODULE_NAME, value);
- q = generator.selectQuery(em);
- results = q.getResultList();
- if (results.size() != 0) {
- for (Object result : results) {
- ApplicationModule applicationModule = (ApplicationModule) result;
- AppModuleResource moduleResource =
- (AppModuleResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.APPLICATION_MODULE, applicationModule);
- moduleResources.add(moduleResource);
- }
- }
- } else {
- em.getTransaction().commit();
- em.close();
- logger.error("Unsupported field name for app module resource.", new IllegalArgumentException());
- throw new IllegalArgumentException("Unsupported field name for app module 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 moduleResources;
- }
-
- @Override
- public List<Resource> getAll() throws AppCatalogException {
- List<Resource> appModuleResources = new ArrayList<Resource>();
- EntityManager em = null;
- try {
- em = AppCatalogJPAUtils.getEntityManager();
- em.getTransaction().begin();
- AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(APPLICATION_MODULE);
- generator.setParameter(ApplicationModuleConstants.GATEWAY_ID, gatewayId);
- Query q = generator.selectQuery(em);
- List<?> results = q.getResultList();
- for (Object result : results) {
- ApplicationModule module = (ApplicationModule) result;
- AppModuleResource appModuleResource = (AppModuleResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.APPLICATION_MODULE, module);
- appModuleResources.add(appModuleResource);
- }
- 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 appModuleResources;
- }
-
- @Override
- public List<String> getAllIds() throws AppCatalogException {
- return null;
- }
-
- @Override
- public List<String> getIds(String fieldName, Object value) throws AppCatalogException {
- List<String> moduleResources = new ArrayList<String>();
- EntityManager em = null;
- try {
- em = AppCatalogJPAUtils.getEntityManager();
- em.getTransaction().begin();
- Query q;
- AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(APPLICATION_MODULE);
- List results;
- if (fieldName.equals(ApplicationModuleConstants.MODULE_NAME)) {
- generator.setParameter(ApplicationModuleConstants.MODULE_NAME, value);
- q = generator.selectQuery(em);
- results = q.getResultList();
- if (results.size() != 0) {
- for (Object result : results) {
- ApplicationModule applicationModule = (ApplicationModule) result;
- moduleResources.add(applicationModule.getModuleID());
- }
- }
- } else {
- em.getTransaction().commit();
- em.close();
- logger.error("Unsupported field name for app module resource.", new IllegalArgumentException());
- throw new IllegalArgumentException("Unsupported field name for app module 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 moduleResources;
- }
-
- @Override
- public void save() throws AppCatalogException {
- EntityManager em = null;
- try {
- em = AppCatalogJPAUtils.getEntityManager();
- ApplicationModule existingModule = em.find(ApplicationModule.class, moduleId);
- em.close();
-
- em = AppCatalogJPAUtils.getEntityManager();
- em.getTransaction().begin();
- if (existingModule != null){
- existingModule.setModuleName(moduleName);
- existingModule.setModuleVersion(moduleVersion);
- existingModule.setModuleDesc(moduleDesc);
- existingModule.setGatewayId(gatewayId);
- existingModule.setUpdateTime(AiravataUtils.getCurrentTimestamp());
- em.merge(existingModule);
- }else {
- ApplicationModule applicationModule = new ApplicationModule();
- applicationModule.setModuleID(moduleId);
- applicationModule.setModuleName(moduleName);
- applicationModule.setModuleVersion(moduleVersion);
- applicationModule.setModuleDesc(moduleDesc);
- applicationModule.setGatewayId(gatewayId);
- applicationModule.setCreationTime(AiravataUtils.getCurrentTimestamp());
- em.persist(applicationModule);
- }
- 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();
- ApplicationModule applicationModule = em.find(ApplicationModule.class, identifier);
- em.close();
- return applicationModule != 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();
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/airavata/blob/ec8c6202/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
deleted file mode 100644
index 3dcb6b4..0000000
--- a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/ApplicationInputResource.java
+++ /dev/null
@@ -1,454 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.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 appArgument;
- private String userFriendlyDesc;
- private int inputOrder;
- private boolean standardInput;
- private boolean isRequired;
- private boolean requiredToCMD;
- private boolean dataStaged;
-
- 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));
- if (ids.get(AppInputConstants.INPUT_KEY) != null){
- 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<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(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;
- }
-
- @Override
- public List<Resource> getAll() throws AppCatalogException {
- return null;
- }
-
- @Override
- public List<String> getAllIds() throws AppCatalogException {
- return null;
- }
-
- 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();
- ApplicationInput applicationInput;
- em = AppCatalogJPAUtils.getEntityManager();
- em.getTransaction().begin();
- if (existingApplicationInput == null) {
- applicationInput = new ApplicationInput();
- } else {
- applicationInput=existingApplicationInput;
- }
- ApplicationInterface applicationInterface = em.find(ApplicationInterface.class, interfaceID);
- applicationInput.setApplicationInterface(applicationInterface);
- applicationInput.setInterfaceID(applicationInterface.getInterfaceID());
- applicationInput.setDataType(dataType);
- applicationInput.setInputKey(inputKey);
- applicationInput.setInputVal(inputVal);
- applicationInput.setMetadata(metadata);
- applicationInput.setAppArgument(appArgument);
- applicationInput.setUserFriendlyDesc(userFriendlyDesc);
- applicationInput.setStandardInput(standardInput);
- applicationInput.setInputOrder(inputOrder);
- applicationInput.setRequiredToCMD(requiredToCMD);
- applicationInput.setRequired(isRequired);
- applicationInput.setDataStaged(dataStaged);
- if (existingApplicationInput == null) {
- em.persist(applicationInput);
- } else {
- em.merge(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<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();
- 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 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 AppInterfaceResource getAppInterfaceResource() {
- return appInterfaceResource;
- }
-
- public void setAppInterfaceResource(AppInterfaceResource appInterfaceResource) {
- this.appInterfaceResource = appInterfaceResource;
- }
-
- 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;
- }
-}