http://git-wip-us.apache.org/repos/asf/airavata/blob/4045c094/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/AppInterfaceResource.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/AppInterfaceResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/AppInterfaceResource.java new file mode 100644 index 0000000..ec15ed1 --- /dev/null +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/AppInterfaceResource.java @@ -0,0 +1,363 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package org.apache.airavata.registry.core.app.catalog.resources; + +import org.apache.airavata.common.exception.ApplicationSettingsException; +import org.apache.airavata.common.utils.AiravataUtils; +import org.apache.airavata.registry.core.app.catalog.model.ApplicationInterface; +import org.apache.airavata.registry.core.app.catalog.util.AppCatalogJPAUtils; +import org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator; +import org.apache.airavata.registry.core.app.catalog.util.AppCatalogResourceType; +import org.apache.airavata.registry.cpi.AppCatalogException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.persistence.EntityManager; +import javax.persistence.Query; +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.List; + +public class AppInterfaceResource extends AppCatAbstractResource { + 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 AppCatalogResource 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<AppCatalogResource> get(String fieldName, Object value) throws AppCatalogException { + List<AppCatalogResource> resourceList = new ArrayList<AppCatalogResource>(); + 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<AppCatalogResource> getAll() throws AppCatalogException { + List<AppCatalogResource> resourceList = new ArrayList<AppCatalogResource>(); + 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/4045c094/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/AppModuleAppCatalogResourceAppCat.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/AppModuleAppCatalogResourceAppCat.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/AppModuleAppCatalogResourceAppCat.java deleted file mode 100644 index 3021cee..0000000 --- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/AppModuleAppCatalogResourceAppCat.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.airavata.registry.core.app.catalog.resources; - -import org.apache.airavata.common.exception.ApplicationSettingsException; -import org.apache.airavata.common.utils.AiravataUtils; -import org.apache.airavata.registry.core.app.catalog.model.ApplicationModule; -import org.apache.airavata.registry.core.app.catalog.util.AppCatalogJPAUtils; -import org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator; -import org.apache.airavata.registry.core.app.catalog.util.AppCatalogResourceType; -import org.apache.airavata.registry.cpi.AppCatalogException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.persistence.EntityManager; -import javax.persistence.Query; -import java.sql.Timestamp; -import java.util.ArrayList; -import java.util.List; - -public class AppModuleAppCatalogResourceAppCat extends AppCatAbstractResource { - private final static Logger logger = LoggerFactory.getLogger(AppModuleAppCatalogResourceAppCat.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 AppCatalogResource 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(); - AppModuleAppCatalogResourceAppCat appModuleResource = - (AppModuleAppCatalogResourceAppCat) 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<AppCatalogResource> get(String fieldName, Object value) throws AppCatalogException { - List<AppCatalogResource> moduleResources = new ArrayList<AppCatalogResource>(); - 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; - AppModuleAppCatalogResourceAppCat moduleResource = - (AppModuleAppCatalogResourceAppCat) 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<AppCatalogResource> getAll() throws AppCatalogException { - List<AppCatalogResource> appModuleResources = new ArrayList<AppCatalogResource>(); - 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; - AppModuleAppCatalogResourceAppCat appModuleResource = (AppModuleAppCatalogResourceAppCat) 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/4045c094/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/AppModuleMappingAppCatalogResourceAppCat.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/AppModuleMappingAppCatalogResourceAppCat.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/AppModuleMappingAppCatalogResourceAppCat.java index 12d32a0..49cdd8b 100644 --- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/AppModuleMappingAppCatalogResourceAppCat.java +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/AppModuleMappingAppCatalogResourceAppCat.java @@ -44,8 +44,8 @@ public class AppModuleMappingAppCatalogResourceAppCat extends AppCatAbstractReso private final static Logger logger = LoggerFactory.getLogger(AppModuleMappingAppCatalogResourceAppCat.class); private String interfaceId; private String moduleId; - private AppInterfaceAppCatalogResourceAppCat appInterfaceResource; - private AppModuleAppCatalogResourceAppCat moduleResource; + private AppInterfaceResource appInterfaceResource; + private AppModuleResource moduleResource; public String getModuleId() { @@ -64,19 +64,19 @@ public class AppModuleMappingAppCatalogResourceAppCat extends AppCatAbstractReso this.interfaceId = interfaceId; } - public AppInterfaceAppCatalogResourceAppCat getAppInterfaceResource() { + public AppInterfaceResource getAppInterfaceResource() { return appInterfaceResource; } - public void setAppInterfaceResource(AppInterfaceAppCatalogResourceAppCat appInterfaceResource) { + public void setAppInterfaceResource(AppInterfaceResource appInterfaceResource) { this.appInterfaceResource = appInterfaceResource; } - public AppModuleAppCatalogResourceAppCat getModuleResource() { + public AppModuleResource getModuleResource() { return moduleResource; } - public void setModuleResource(AppModuleAppCatalogResourceAppCat moduleResource) { + public void setModuleResource(AppModuleResource moduleResource) { this.moduleResource = moduleResource; } http://git-wip-us.apache.org/repos/asf/airavata/blob/4045c094/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/AppModuleResource.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/AppModuleResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/AppModuleResource.java new file mode 100644 index 0000000..ea1400e --- /dev/null +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/AppModuleResource.java @@ -0,0 +1,344 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package org.apache.airavata.registry.core.app.catalog.resources; + +import org.apache.airavata.common.exception.ApplicationSettingsException; +import org.apache.airavata.common.utils.AiravataUtils; +import org.apache.airavata.registry.core.app.catalog.model.ApplicationModule; +import org.apache.airavata.registry.core.app.catalog.util.AppCatalogJPAUtils; +import org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator; +import org.apache.airavata.registry.core.app.catalog.util.AppCatalogResourceType; +import org.apache.airavata.registry.cpi.AppCatalogException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.persistence.EntityManager; +import javax.persistence.Query; +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.List; + +public class AppModuleResource extends AppCatAbstractResource { + 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 AppCatalogResource 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<AppCatalogResource> get(String fieldName, Object value) throws AppCatalogException { + List<AppCatalogResource> moduleResources = new ArrayList<AppCatalogResource>(); + 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<AppCatalogResource> getAll() throws AppCatalogException { + List<AppCatalogResource> appModuleResources = new ArrayList<AppCatalogResource>(); + 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/4045c094/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/ApplicationInputAppCatalogResourceAppCat.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/ApplicationInputAppCatalogResourceAppCat.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/ApplicationInputAppCatalogResourceAppCat.java deleted file mode 100644 index 412b2c1..0000000 --- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/ApplicationInputAppCatalogResourceAppCat.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.airavata.registry.core.app.catalog.resources; - -import org.apache.airavata.common.exception.ApplicationSettingsException; -import org.apache.airavata.registry.core.app.catalog.model.AppInput_PK; -import org.apache.airavata.registry.core.app.catalog.model.ApplicationInput; -import org.apache.airavata.registry.core.app.catalog.model.ApplicationInterface; -import org.apache.airavata.registry.core.app.catalog.util.AppCatalogJPAUtils; -import org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator; -import org.apache.airavata.registry.core.app.catalog.util.AppCatalogResourceType; -import org.apache.airavata.registry.cpi.AppCatalogException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.persistence.EntityManager; -import javax.persistence.Query; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class ApplicationInputAppCatalogResourceAppCat extends AppCatAbstractResource { - - private final static Logger logger = LoggerFactory.getLogger(ApplicationInputAppCatalogResourceAppCat.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 AppInterfaceAppCatalogResourceAppCat 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 AppCatalogResource get(Object identifier) throws AppCatalogException { - HashMap<String, String> ids; - if (identifier instanceof Map) { - ids = (HashMap<String, String>) identifier; - } else { - logger.error("Identifier should be a map with the field name and it's value"); - throw new AppCatalogException("Identifier should be a map with the field name and it's value"); - } - - EntityManager em = null; - try { - em = AppCatalogJPAUtils.getEntityManager(); - em.getTransaction().begin(); - AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(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(); - ApplicationInputAppCatalogResourceAppCat applicationInputResource = - (ApplicationInputAppCatalogResourceAppCat) 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<AppCatalogResource> get(String fieldName, Object value) throws AppCatalogException { - List<AppCatalogResource> appInputResources = new ArrayList<AppCatalogResource>(); - 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; - ApplicationInputAppCatalogResourceAppCat applicationInputResource = - (ApplicationInputAppCatalogResourceAppCat) 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; - ApplicationInputAppCatalogResourceAppCat applicationInputResource = - (ApplicationInputAppCatalogResourceAppCat) 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; - ApplicationInputAppCatalogResourceAppCat applicationInputResource = - (ApplicationInputAppCatalogResourceAppCat) 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<AppCatalogResource> 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 AppInterfaceAppCatalogResourceAppCat getAppInterfaceResource() { - return appInterfaceResource; - } - - public void setAppInterfaceResource(AppInterfaceAppCatalogResourceAppCat 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; - } -} http://git-wip-us.apache.org/repos/asf/airavata/blob/4045c094/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/ApplicationInputResource.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/ApplicationInputResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/ApplicationInputResource.java new file mode 100644 index 0000000..36c52a0 --- /dev/null +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/ApplicationInputResource.java @@ -0,0 +1,454 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.airavata.registry.core.app.catalog.resources; + +import org.apache.airavata.common.exception.ApplicationSettingsException; +import org.apache.airavata.registry.core.app.catalog.model.AppInput_PK; +import org.apache.airavata.registry.core.app.catalog.model.ApplicationInput; +import org.apache.airavata.registry.core.app.catalog.model.ApplicationInterface; +import org.apache.airavata.registry.core.app.catalog.util.AppCatalogJPAUtils; +import org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator; +import org.apache.airavata.registry.core.app.catalog.util.AppCatalogResourceType; +import org.apache.airavata.registry.cpi.AppCatalogException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.persistence.EntityManager; +import javax.persistence.Query; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class ApplicationInputResource extends AppCatAbstractResource { + + 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 AppCatalogResource get(Object identifier) throws AppCatalogException { + HashMap<String, String> ids; + if (identifier instanceof Map) { + ids = (HashMap<String, String>) identifier; + } else { + logger.error("Identifier should be a map with the field name and it's value"); + throw new AppCatalogException("Identifier should be a map with the field name and it's value"); + } + + EntityManager em = null; + try { + em = AppCatalogJPAUtils.getEntityManager(); + em.getTransaction().begin(); + AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(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<AppCatalogResource> get(String fieldName, Object value) throws AppCatalogException { + List<AppCatalogResource> appInputResources = new ArrayList<AppCatalogResource>(); + 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<AppCatalogResource> 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; + } +}
