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 2014/06/28 04:53:31 UTC
git commit: adding more resource classes - AIRAVATA-1302
Repository: airavata
Updated Branches:
refs/heads/master 33a6d8b78 -> 2e36ba4af
adding more resource classes - AIRAVATA-1302
Project: http://git-wip-us.apache.org/repos/asf/airavata/repo
Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/2e36ba4a
Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/2e36ba4a
Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/2e36ba4a
Branch: refs/heads/master
Commit: 2e36ba4af4d416e2c0f854b7f1d04bf450254e30
Parents: 33a6d8b
Author: Chathuri Wimalasena <ka...@gmail.com>
Authored: Fri Jun 27 22:53:25 2014 -0400
Committer: Chathuri Wimalasena <ka...@gmail.com>
Committed: Fri Jun 27 22:53:25 2014 -0400
----------------------------------------------------------------------
.../data/resources/AppEnvironmentResource.java | 280 ++++++++++++++++++
.../data/resources/AppInterfaceResource.java | 253 +++++++++++++++++
.../resources/AppModuleMappingResource.java | 282 +++++++++++++++++++
.../resources/LibraryApendPathResource.java | 8 +-
.../catalog/data/util/AppCatalogJPAUtils.java | 50 +++-
5 files changed, 866 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/airavata/blob/2e36ba4a/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
new file mode 100644
index 0000000..50cb8d5
--- /dev/null
+++ b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/AppEnvironmentResource.java
@@ -0,0 +1,280 @@
+/*
+ *
+ * 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));
+ 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<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/2e36ba4a/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
new file mode 100644
index 0000000..9569049
--- /dev/null
+++ b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/AppInterfaceResource.java
@@ -0,0 +1,253 @@
+/*
+ *
+ * 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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+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;
+
+ 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;
+ }
+
+ @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<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);
+ em.merge(existigAppInterface);
+ }else {
+ ApplicationInterface applicationInterface = new ApplicationInterface();
+ applicationInterface.setInterfaceID(interfaceId);
+ applicationInterface.setAppName(appName);
+ 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/2e36ba4a/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
new file mode 100644
index 0000000..610350b
--- /dev/null
+++ b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/AppModuleMappingResource.java
@@ -0,0 +1,282 @@
+/*
+ *
+ * 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));
+ 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();
+ }
+ }
+ }
+
+ @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();
+ AppModuleResource resource =
+ (AppModuleResource) 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<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();
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/airavata/blob/2e36ba4a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/LibraryApendPathResource.java
----------------------------------------------------------------------
diff --git a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/LibraryApendPathResource.java b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/LibraryApendPathResource.java
index 7100c8f..6147d0f 100644
--- a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/LibraryApendPathResource.java
+++ b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/LibraryApendPathResource.java
@@ -129,8 +129,8 @@ public class LibraryApendPathResource extends AbstractResource {
generator.setParameter(LibraryApendPathConstants.NAME, ids.get(LibraryApendPathConstants.NAME));
Query q = generator.selectQuery(em);
LibraryApendPath libraryApendPath = (LibraryApendPath) q.getSingleResult();
- LibraryPrepandPathResource resource =
- (LibraryPrepandPathResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.LIBRARY_APEND_PATH, libraryApendPath);
+ LibraryApendPathResource resource =
+ (LibraryApendPathResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.LIBRARY_APEND_PATH, libraryApendPath);
em.getTransaction().commit();
em.close();
return resource;
@@ -261,8 +261,8 @@ public class LibraryApendPathResource extends AbstractResource {
try {
em = AppCatalogJPAUtils.getEntityManager();
LibraryApendPath apendPath = em.find(LibraryApendPath.class,
- new LibraryApendPath_PK(ids.get(LibraryPrepandPathConstants.DEPLOYMENT_ID),
- ids.get(LibraryPrepandPathConstants.NAME)));
+ new LibraryApendPath_PK(ids.get(LibraryApendPathConstants.DEPLOYMENT_ID),
+ ids.get(LibraryApendPathConstants.NAME)));
em.close();
return apendPath != null;
} catch (ApplicationSettingsException e) {
http://git-wip-us.apache.org/repos/asf/airavata/blob/2e36ba4a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/util/AppCatalogJPAUtils.java
----------------------------------------------------------------------
diff --git a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/util/AppCatalogJPAUtils.java b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/util/AppCatalogJPAUtils.java
index 3f427f2..157a51b 100644
--- a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/util/AppCatalogJPAUtils.java
+++ b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/util/AppCatalogJPAUtils.java
@@ -135,6 +135,27 @@ public class AppCatalogJPAUtils {
logger.error("Object should be a Library Apend path.", new IllegalArgumentException());
throw new IllegalArgumentException("Object should be a Library Apend.");
}
+ case APP_ENVIRONMENT:
+ if (o instanceof AppEnvironment){
+ return createAppEnvironmentResource((AppEnvironment) o);
+ }else {
+ logger.error("Object should be a Library Apend path.", new IllegalArgumentException());
+ throw new IllegalArgumentException("Object should be a Library Apend.");
+ }
+ case APPLICATION_INTERFACE:
+ if (o instanceof ApplicationInterface){
+ return createAppInterfaceResource((ApplicationInterface) o);
+ }else {
+ logger.error("Object should be a Library Apend path.", new IllegalArgumentException());
+ throw new IllegalArgumentException("Object should be a Library Apend.");
+ }
+ case APP_MODULE_MAPPING:
+ if (o instanceof ApplicationInterface){
+ return createAppModMappingResource((AppModuleMapping) o);
+ }else {
+ logger.error("Object should be a Library Apend path.", new IllegalArgumentException());
+ throw new IllegalArgumentException("Object should be a Library Apend.");
+ }
default:
logger.error("Illegal data type..", new IllegalArgumentException());
throw new IllegalArgumentException("Illegal data type..");
@@ -182,8 +203,8 @@ public class AppCatalogJPAUtils {
resource.setEnvModuleLoadCMD(o.getEnvModuleLoaString());
resource.setHostId(o.getHostID());
resource.setExecutablePath(o.getExecutablePath());
- resource.setModuleResource((AppModuleResource)createApplicationModule(o.getApplicationModule()));
- resource.setHostResource((ComputeHostResource)createComputeResource(o.getComputeResource()));
+ resource.setModuleResource((AppModuleResource) createApplicationModule(o.getApplicationModule()));
+ resource.setHostResource((ComputeHostResource) createComputeResource(o.getComputeResource()));
return resource;
}
@@ -192,7 +213,7 @@ public class AppCatalogJPAUtils {
resource.setDeploymentId(o.getDeploymentID());
resource.setName(o.getName());
resource.setValue(o.getValue());
- resource.setAppDeploymentResource((AppDeploymentResource)createApplicationDeployment(o.getApplicationDeployment()));
+ resource.setAppDeploymentResource((AppDeploymentResource) createApplicationDeployment(o.getApplicationDeployment()));
return resource;
}
@@ -204,4 +225,27 @@ public class AppCatalogJPAUtils {
resource.setAppDeploymentResource((AppDeploymentResource)createApplicationDeployment(o.getApplicationDeployment()));
return resource;
}
+
+ private static Resource createAppEnvironmentResource(AppEnvironment o) {
+ AppEnvironmentResource resource = new AppEnvironmentResource();
+ resource.setDeploymentId(o.getDeploymentID());
+ resource.setName(o.getName());
+ resource.setValue(o.getValue());
+ resource.setAppDeploymentResource((AppDeploymentResource)createApplicationDeployment(o.getApplicationDeployment()));
+ return resource;
+ }
+
+ private static Resource createAppInterfaceResource(ApplicationInterface o) {
+ AppInterfaceResource resource = new AppInterfaceResource();
+ resource.setInterfaceId(o.getInterfaceID());
+ resource.setAppName(o.getAppName());
+ return resource;
+ }
+
+ private static Resource createAppModMappingResource(AppModuleMapping o) {
+ AppModuleMappingResource resource = new AppModuleMappingResource();
+ resource.setInterfaceId(o.getInterfaceID());
+ resource.setModuleId(o.getModuleID());
+ return resource;
+ }
}