You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by sh...@apache.org on 2015/06/04 22:36:55 UTC
[09/52] [abbrv] [partial] airavata git commit: registry refactoring
http://git-wip-us.apache.org/repos/asf/airavata/blob/ec8c6202/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/HostIPAddressResource.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/HostIPAddressResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/HostIPAddressResource.java
new file mode 100644
index 0000000..683efec
--- /dev/null
+++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/HostIPAddressResource.java
@@ -0,0 +1,318 @@
+/**
+ * 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.ComputeResource;
+import org.apache.aiaravata.application.catalog.data.model.HostIPAddress;
+import org.apache.aiaravata.application.catalog.data.model.HostIPAddressPK;
+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 HostIPAddressResource extends AbstractResource{
+
+ private final static Logger logger = LoggerFactory.getLogger(HostIPAddressResource.class);
+
+ private String resourceID;
+ private String ipaddress;
+ private ComputeResourceResource computeHostResource;
+
+ public void remove(Object identifier) throws AppCatalogException {
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ AppCatalogQueryGenerator generator= new AppCatalogQueryGenerator(HOST_IPADDRESS);
+ generator.setParameter(HostIPAddressConstants.RESOURCE_ID, identifier);
+ Query q = generator.deleteQuery(em);
+ q.executeUpdate();
+ em.getTransaction().commit();
+ em.close();
+ } catch (ApplicationSettingsException e) {
+ logger.error(e.getMessage(), e);
+ throw new AppCatalogException(e);
+ } finally {
+ if (em != null && em.isOpen()) {
+ if (em.getTransaction().isActive()){
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ }
+
+ }
+
+ public Resource get(Object identifier) throws AppCatalogException {
+ 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(HOST_IPADDRESS);
+ generator.setParameter(HostIPAddressConstants.RESOURCE_ID, ids.get(HostIPAddressConstants.RESOURCE_ID));
+ generator.setParameter(HostIPAddressConstants.IP_ADDRESS, ids.get(HostIPAddressConstants.IP_ADDRESS));
+ Query q = generator.selectQuery(em);
+ HostIPAddress hostIPAddress = (HostIPAddress) q.getSingleResult();
+ HostIPAddressResource hostIPAddressResource =
+ (HostIPAddressResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.HOST_IPADDRESS, hostIPAddress);
+ em.getTransaction().commit();
+ em.close();
+ return hostIPAddressResource;
+ } catch (ApplicationSettingsException e) {
+ logger.error(e.getMessage(), e);
+ throw new AppCatalogException(e);
+ } finally {
+ if (em != null && em.isOpen()) {
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ }
+ }
+
+ public List<Resource> get(String fieldName, Object value) throws AppCatalogException {
+
+ List<Resource> hostIPAddressResources = new ArrayList<Resource>();
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ Query q;
+ AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(HOST_IPADDRESS);
+ List results;
+ if (fieldName.equals(HostIPAddressConstants.IP_ADDRESS)) {
+ generator.setParameter(HostIPAddressConstants.IP_ADDRESS, value);
+ q = generator.selectQuery(em);
+ results = q.getResultList();
+ if (results.size() != 0) {
+ for (Object result : results) {
+ HostIPAddress hostIPAddress = (HostIPAddress) result;
+ HostIPAddressResource hostIPAddressResource =
+ (HostIPAddressResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.HOST_IPADDRESS, hostIPAddress);
+ hostIPAddressResources.add(hostIPAddressResource);
+ }
+ }
+ } else if (fieldName.equals(HostIPAddressConstants.RESOURCE_ID)) {
+ generator.setParameter(HostIPAddressConstants.RESOURCE_ID, value);
+ q = generator.selectQuery(em);
+ results = q.getResultList();
+ if (results.size() != 0) {
+ for (Object result : results) {
+ HostIPAddress hostIPAddress = (HostIPAddress) result;
+ HostIPAddressResource hostIPAddressResource =
+ (HostIPAddressResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.HOST_IPADDRESS, hostIPAddress);
+ hostIPAddressResources.add(hostIPAddressResource);
+ }
+ }
+ } else {
+ em.getTransaction().commit();
+ em.close();
+ logger.error("Unsupported field name for Host IPAddress Resource.", new IllegalArgumentException());
+ throw new IllegalArgumentException("Unsupported field name for Host IPAddress 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 hostIPAddressResources;
+ }
+
+ @Override
+ public List<Resource> getAll() throws AppCatalogException {
+ return null;
+ }
+
+ @Override
+ public List<String> getAllIds() throws AppCatalogException {
+ return null;
+ }
+
+ public List<String> getIds(String fieldName, Object value) throws AppCatalogException {
+
+ List<String> hostIPAddressResourceIDs = new ArrayList<String>();
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ Query q;
+ AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(HOST_IPADDRESS);
+ List results;
+ if (fieldName.equals(HostIPAddressConstants.IP_ADDRESS)) {
+ generator.setParameter(HostIPAddressConstants.IP_ADDRESS, value);
+ q = generator.selectQuery(em);
+ results = q.getResultList();
+ if (results.size() != 0) {
+ for (Object result : results) {
+ HostIPAddress hostIPAddress = (HostIPAddress) result;
+ hostIPAddressResourceIDs.add(hostIPAddress.getResourceID());
+ }
+ }
+ } else if (fieldName.equals(HostIPAddressConstants.RESOURCE_ID)) {
+ generator.setParameter(HostIPAddressConstants.RESOURCE_ID, value);
+ q = generator.selectQuery(em);
+ results = q.getResultList();
+ if (results.size() != 0) {
+ for (Object result : results) {
+ HostIPAddress hostIPAddress = (HostIPAddress) result;
+ hostIPAddressResourceIDs.add(hostIPAddress.getResourceID());
+ }
+ }
+ } else {
+ em.getTransaction().commit();
+ em.close();
+ logger.error("Unsupported field name for Host IP Address resource.", new IllegalArgumentException());
+ throw new IllegalArgumentException("Unsupported field name for Host IPAddress 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 hostIPAddressResourceIDs;
+ }
+
+ public void save() throws AppCatalogException {
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ HostIPAddress existingHostIP = em.find(HostIPAddress.class, new HostIPAddressPK(resourceID,ipaddress));
+ em.close();
+
+ em = AppCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ ComputeResource computeResource = em.find(ComputeResource.class, resourceID);
+ if (existingHostIP != null){
+ existingHostIP.setIpaddress(ipaddress);
+ existingHostIP.setResourceID(resourceID);
+ existingHostIP.setComputeResource(computeResource);
+ em.merge(existingHostIP);
+ }else {
+ HostIPAddress hostIPAddress = new HostIPAddress();
+ hostIPAddress.setIpaddress(ipaddress);
+ hostIPAddress.setResourceID(resourceID);
+ hostIPAddress.setComputeResource(computeResource);
+ em.persist(hostIPAddress);
+ }
+ em.getTransaction().commit();
+ em.close();
+ } catch (Exception e) {
+ logger.error(e.getMessage(), e);
+ throw new AppCatalogException(e);
+ } finally {
+ if (em != null && em.isOpen()) {
+ if (em.getTransaction().isActive()){
+ em.getTransaction().rollback();
+ }
+ em.close();
+ }
+ }
+
+ }
+
+ public boolean isExists(Object identifier) throws AppCatalogException {
+ HashMap<String, String> ids;
+ if (identifier instanceof Map){
+ ids = (HashMap)identifier;
+ }else {
+ logger.error("Identifier should be a map with the field name and it's value");
+ throw new AppCatalogException("Identifier should be a map with the field name and it's value");
+ }
+
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ HostIPAddress hostIPAddress = em.find(HostIPAddress.class, new HostIPAddressPK(ids.get(HostIPAddressConstants.RESOURCE_ID),
+ ids.get(HostIPAddressConstants.IP_ADDRESS)));
+
+ em.close();
+ return hostIPAddress != 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 getResourceID() {
+ return resourceID;
+ }
+
+ public void setResourceID(String resourceID) {
+ this.resourceID = resourceID;
+ }
+
+ public String getIpaddress() {
+ return ipaddress;
+ }
+
+ public void setIpaddress(String ipaddress) {
+ this.ipaddress = ipaddress;
+ }
+
+ public ComputeResourceResource getComputeHostResource() {
+ return computeHostResource;
+ }
+
+ public void setComputeHostResource(ComputeResourceResource computeHostResource) {
+ this.computeHostResource = computeHostResource;
+ }
+}
http://git-wip-us.apache.org/repos/asf/airavata/blob/ec8c6202/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/JobManagerCommandAppCatalogResourceAppCat.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/JobManagerCommandAppCatalogResourceAppCat.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/JobManagerCommandAppCatalogResourceAppCat.java
new file mode 100644
index 0000000..a3c5e8f
--- /dev/null
+++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/JobManagerCommandAppCatalogResourceAppCat.java
@@ -0,0 +1,307 @@
+/*
+ *
+ * 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 java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+
+import org.apache.airavata.common.exception.ApplicationSettingsException;
+import org.apache.airavata.registry.core.app.catalog.model.JobManagerCommand;
+import org.apache.airavata.registry.core.app.catalog.model.JobManagerCommand_PK;
+import org.apache.airavata.registry.core.app.catalog.model.ResourceJobManager;
+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;
+
+public class JobManagerCommandAppCatalogResourceAppCat extends AppCatAbstractResource {
+ private final static Logger logger = LoggerFactory.getLogger(JobManagerCommandAppCatalogResourceAppCat.class);
+ private String resourceJobManagerId;
+ private ResourceJobManagerAppCatalogResourceAppCat resourceJobManagerResource;
+ private String commandType;
+ private String command;
+
+ @Override
+ public void remove(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(JOB_MANAGER_COMMAND);
+ generator.setParameter(JobManagerCommandConstants.RESOURCE_JOB_MANAGER_ID, ids.get(JobManagerCommandConstants.RESOURCE_JOB_MANAGER_ID));
+ generator.setParameter(JobManagerCommandConstants.COMMAND_TYPE, ids.get(JobManagerCommandConstants.COMMAND_TYPE));
+ 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 {
+ 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(JOB_MANAGER_COMMAND);
+ generator.setParameter(JobManagerCommandConstants.RESOURCE_JOB_MANAGER_ID, ids.get(JobManagerCommandConstants.RESOURCE_JOB_MANAGER_ID));
+ generator.setParameter(JobManagerCommandConstants.COMMAND_TYPE, ids.get(JobManagerCommandConstants.COMMAND_TYPE));
+ Query q = generator.selectQuery(em);
+ JobManagerCommand jobManagerCommand = (JobManagerCommand) q.getSingleResult();
+ JobManagerCommandAppCatalogResourceAppCat jobManagerCommandResource = (JobManagerCommandAppCatalogResourceAppCat) AppCatalogJPAUtils.getResource(AppCatalogResourceType.JOB_MANAGER_COMMAND, jobManagerCommand);
+ em.getTransaction().commit();
+ em.close();
+ return jobManagerCommandResource;
+ } 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> jobManagerCommandResources = new ArrayList<AppCatalogResource>();
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(JOB_MANAGER_COMMAND);
+ Query q;
+ if ((fieldName.equals(JobManagerCommandConstants.RESOURCE_JOB_MANAGER_ID)) || (fieldName.equals(JobManagerCommandConstants.COMMAND_TYPE)) || (fieldName.equals(JobManagerCommandConstants.COMMAND))) {
+ generator.setParameter(fieldName, value);
+ q = generator.selectQuery(em);
+ List<?> results = q.getResultList();
+ for (Object result : results) {
+ JobManagerCommand jobManagerCommand = (JobManagerCommand) result;
+ JobManagerCommandAppCatalogResourceAppCat jobManagerCommandResource = (JobManagerCommandAppCatalogResourceAppCat) AppCatalogJPAUtils.getResource(AppCatalogResourceType.JOB_MANAGER_COMMAND, jobManagerCommand);
+ jobManagerCommandResources.add(jobManagerCommandResource);
+ }
+ } else {
+ em.getTransaction().commit();
+ em.close();
+ logger.error("Unsupported field name for Job Manager Command Resource.", new IllegalArgumentException());
+ throw new IllegalArgumentException("Unsupported field name for Job Manager Command Resource.");
+ }
+ 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 jobManagerCommandResources;
+ }
+
+ @Override
+ public List<AppCatalogResource> getAll() throws AppCatalogException {
+ return null;
+ }
+
+ @Override
+ public List<String> getAllIds() throws AppCatalogException {
+ return null;
+ }
+
+ @Override
+ public List<String> getIds(String fieldName, Object value) throws AppCatalogException {
+ List<String> jobManagerCommandResourceIDs = new ArrayList<String>();
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(JOB_MANAGER_COMMAND);
+ Query q;
+ if ((fieldName.equals(JobManagerCommandConstants.RESOURCE_JOB_MANAGER_ID)) || (fieldName.equals(JobManagerCommandConstants.COMMAND_TYPE)) || (fieldName.equals(JobManagerCommandConstants.COMMAND))) {
+ generator.setParameter(fieldName, value);
+ q = generator.selectQuery(em);
+ List<?> results = q.getResultList();
+ for (Object result : results) {
+ JobManagerCommand jobManagerCommand = (JobManagerCommand) result;
+ JobManagerCommandAppCatalogResourceAppCat jobManagerCommandResource = (JobManagerCommandAppCatalogResourceAppCat) AppCatalogJPAUtils.getResource(AppCatalogResourceType.JOB_MANAGER_COMMAND, jobManagerCommand);
+ jobManagerCommandResourceIDs.add(jobManagerCommandResource.getResourceJobManagerId());
+ }
+ } else {
+ em.getTransaction().commit();
+ em.close();
+ logger.error("Unsupported field name for Job Manager Command Resource.", new IllegalArgumentException());
+ throw new IllegalArgumentException("Unsupported field name for Job Manager Command Resource.");
+ }
+ 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 jobManagerCommandResourceIDs;
+ }
+
+ @Override
+ public void save() throws AppCatalogException {
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ JobManagerCommand existingJobManagerCommand = em.find(JobManagerCommand.class, new JobManagerCommand_PK(resourceJobManagerId, commandType));
+ em.close();
+ JobManagerCommand jobManagerCommand;
+ em = AppCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ if (existingJobManagerCommand == null) {
+ jobManagerCommand = new JobManagerCommand();
+ } else {
+ jobManagerCommand = existingJobManagerCommand;
+ }
+ jobManagerCommand.setResourceJobManagerId(getResourceJobManagerId());
+ ResourceJobManager resourceJobManager = em.find(ResourceJobManager.class, getResourceJobManagerId());
+ jobManagerCommand.setResourceJobManager(resourceJobManager);
+ jobManagerCommand.setCommandType(getCommandType());
+ jobManagerCommand.setCommand(getCommand());
+ if (existingJobManagerCommand == null) {
+ em.persist(jobManagerCommand);
+ } else {
+ em.merge(jobManagerCommand);
+ }
+ 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<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();
+ JobManagerCommand jobManagerCommand = em.find(JobManagerCommand.class, new JobManagerCommand_PK(ids.get(JobManagerCommandConstants.RESOURCE_JOB_MANAGER_ID), ids.get(JobManagerCommandConstants.COMMAND_TYPE)));
+ em.close();
+ return jobManagerCommand != 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 getResourceJobManagerId() {
+ return resourceJobManagerId;
+ }
+
+ public ResourceJobManagerAppCatalogResourceAppCat getResourceJobManagerResource() {
+ return resourceJobManagerResource;
+ }
+
+ public String getCommandType() {
+ return commandType;
+ }
+
+ public String getCommand() {
+ return command;
+ }
+
+ public void setResourceJobManagerId(String resourceJobManagerId) {
+ this.resourceJobManagerId=resourceJobManagerId;
+ }
+
+ public void setResourceJobManagerResource(ResourceJobManagerAppCatalogResourceAppCat resourceJobManagerResource) {
+ this.resourceJobManagerResource=resourceJobManagerResource;
+ }
+
+ public void setCommandType(String commandType) {
+ this.commandType=commandType;
+ }
+
+ public void setCommand(String command) {
+ this.command=command;
+ }
+}
http://git-wip-us.apache.org/repos/asf/airavata/blob/ec8c6202/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/JobManagerCommandResource.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/JobManagerCommandResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/JobManagerCommandResource.java
new file mode 100644
index 0000000..e177cd3
--- /dev/null
+++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/JobManagerCommandResource.java
@@ -0,0 +1,307 @@
+/*
+ *
+ * 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 java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+
+import org.airavata.appcatalog.cpi.AppCatalogException;
+import org.apache.aiaravata.application.catalog.data.model.JobManagerCommand;
+import org.apache.aiaravata.application.catalog.data.model.JobManagerCommand_PK;
+import org.apache.aiaravata.application.catalog.data.model.ResourceJobManager;
+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;
+
+public class JobManagerCommandResource extends AbstractResource {
+ private final static Logger logger = LoggerFactory.getLogger(JobManagerCommandResource.class);
+ private String resourceJobManagerId;
+ private ResourceJobManagerResource resourceJobManagerResource;
+ private String commandType;
+ private String command;
+
+ @Override
+ public void remove(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(JOB_MANAGER_COMMAND);
+ generator.setParameter(JobManagerCommandConstants.RESOURCE_JOB_MANAGER_ID, ids.get(JobManagerCommandConstants.RESOURCE_JOB_MANAGER_ID));
+ generator.setParameter(JobManagerCommandConstants.COMMAND_TYPE, ids.get(JobManagerCommandConstants.COMMAND_TYPE));
+ 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<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(JOB_MANAGER_COMMAND);
+ generator.setParameter(JobManagerCommandConstants.RESOURCE_JOB_MANAGER_ID, ids.get(JobManagerCommandConstants.RESOURCE_JOB_MANAGER_ID));
+ generator.setParameter(JobManagerCommandConstants.COMMAND_TYPE, ids.get(JobManagerCommandConstants.COMMAND_TYPE));
+ Query q = generator.selectQuery(em);
+ JobManagerCommand jobManagerCommand = (JobManagerCommand) q.getSingleResult();
+ JobManagerCommandResource jobManagerCommandResource = (JobManagerCommandResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.JOB_MANAGER_COMMAND, jobManagerCommand);
+ em.getTransaction().commit();
+ em.close();
+ return jobManagerCommandResource;
+ } 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> jobManagerCommandResources = new ArrayList<Resource>();
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(JOB_MANAGER_COMMAND);
+ Query q;
+ if ((fieldName.equals(JobManagerCommandConstants.RESOURCE_JOB_MANAGER_ID)) || (fieldName.equals(JobManagerCommandConstants.COMMAND_TYPE)) || (fieldName.equals(JobManagerCommandConstants.COMMAND))) {
+ generator.setParameter(fieldName, value);
+ q = generator.selectQuery(em);
+ List<?> results = q.getResultList();
+ for (Object result : results) {
+ JobManagerCommand jobManagerCommand = (JobManagerCommand) result;
+ JobManagerCommandResource jobManagerCommandResource = (JobManagerCommandResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.JOB_MANAGER_COMMAND, jobManagerCommand);
+ jobManagerCommandResources.add(jobManagerCommandResource);
+ }
+ } else {
+ em.getTransaction().commit();
+ em.close();
+ logger.error("Unsupported field name for Job Manager Command Resource.", new IllegalArgumentException());
+ throw new IllegalArgumentException("Unsupported field name for Job Manager Command Resource.");
+ }
+ 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 jobManagerCommandResources;
+ }
+
+ @Override
+ public List<Resource> getAll() throws AppCatalogException {
+ return null;
+ }
+
+ @Override
+ public List<String> getAllIds() throws AppCatalogException {
+ return null;
+ }
+
+ @Override
+ public List<String> getIds(String fieldName, Object value) throws AppCatalogException {
+ List<String> jobManagerCommandResourceIDs = new ArrayList<String>();
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(JOB_MANAGER_COMMAND);
+ Query q;
+ if ((fieldName.equals(JobManagerCommandConstants.RESOURCE_JOB_MANAGER_ID)) || (fieldName.equals(JobManagerCommandConstants.COMMAND_TYPE)) || (fieldName.equals(JobManagerCommandConstants.COMMAND))) {
+ generator.setParameter(fieldName, value);
+ q = generator.selectQuery(em);
+ List<?> results = q.getResultList();
+ for (Object result : results) {
+ JobManagerCommand jobManagerCommand = (JobManagerCommand) result;
+ JobManagerCommandResource jobManagerCommandResource = (JobManagerCommandResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.JOB_MANAGER_COMMAND, jobManagerCommand);
+ jobManagerCommandResourceIDs.add(jobManagerCommandResource.getResourceJobManagerId());
+ }
+ } else {
+ em.getTransaction().commit();
+ em.close();
+ logger.error("Unsupported field name for Job Manager Command Resource.", new IllegalArgumentException());
+ throw new IllegalArgumentException("Unsupported field name for Job Manager Command Resource.");
+ }
+ 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 jobManagerCommandResourceIDs;
+ }
+
+ @Override
+ public void save() throws AppCatalogException {
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ JobManagerCommand existingJobManagerCommand = em.find(JobManagerCommand.class, new JobManagerCommand_PK(resourceJobManagerId, commandType));
+ em.close();
+ JobManagerCommand jobManagerCommand;
+ em = AppCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ if (existingJobManagerCommand == null) {
+ jobManagerCommand = new JobManagerCommand();
+ } else {
+ jobManagerCommand = existingJobManagerCommand;
+ }
+ jobManagerCommand.setResourceJobManagerId(getResourceJobManagerId());
+ ResourceJobManager resourceJobManager = em.find(ResourceJobManager.class, getResourceJobManagerId());
+ jobManagerCommand.setResourceJobManager(resourceJobManager);
+ jobManagerCommand.setCommandType(getCommandType());
+ jobManagerCommand.setCommand(getCommand());
+ if (existingJobManagerCommand == null) {
+ em.persist(jobManagerCommand);
+ } else {
+ em.merge(jobManagerCommand);
+ }
+ 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<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();
+ JobManagerCommand jobManagerCommand = em.find(JobManagerCommand.class, new JobManagerCommand_PK(ids.get(JobManagerCommandConstants.RESOURCE_JOB_MANAGER_ID), ids.get(JobManagerCommandConstants.COMMAND_TYPE)));
+ em.close();
+ return jobManagerCommand != 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 getResourceJobManagerId() {
+ return resourceJobManagerId;
+ }
+
+ public ResourceJobManagerResource getResourceJobManagerResource() {
+ return resourceJobManagerResource;
+ }
+
+ public String getCommandType() {
+ return commandType;
+ }
+
+ public String getCommand() {
+ return command;
+ }
+
+ public void setResourceJobManagerId(String resourceJobManagerId) {
+ this.resourceJobManagerId=resourceJobManagerId;
+ }
+
+ public void setResourceJobManagerResource(ResourceJobManagerResource resourceJobManagerResource) {
+ this.resourceJobManagerResource=resourceJobManagerResource;
+ }
+
+ public void setCommandType(String commandType) {
+ this.commandType=commandType;
+ }
+
+ public void setCommand(String command) {
+ this.command=command;
+ }
+}
http://git-wip-us.apache.org/repos/asf/airavata/blob/ec8c6202/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/JobSubmissionInterfaceAppCatalogResourceAppCat.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/JobSubmissionInterfaceAppCatalogResourceAppCat.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/JobSubmissionInterfaceAppCatalogResourceAppCat.java
new file mode 100644
index 0000000..ab34dff
--- /dev/null
+++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/JobSubmissionInterfaceAppCatalogResourceAppCat.java
@@ -0,0 +1,339 @@
+/*
+ *
+ * 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 java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+
+import org.apache.airavata.common.exception.ApplicationSettingsException;
+import org.apache.airavata.common.utils.AiravataUtils;
+import org.apache.airavata.registry.core.app.catalog.model.ComputeResource;
+import org.apache.airavata.registry.core.app.catalog.model.JobSubmissionInterface;
+import org.apache.airavata.registry.core.app.catalog.model.JobSubmissionInterface_PK;
+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;
+
+public class JobSubmissionInterfaceAppCatalogResourceAppCat extends AppCatAbstractResource {
+ private final static Logger logger = LoggerFactory.getLogger(JobSubmissionInterfaceAppCatalogResourceAppCat.class);
+ private String jobSubmissionInterfaceId;
+ private String computeResourceId;
+ private ComputeResourceAppCatalogResourceAppCat computeHostResource;
+ private String jobSubmissionProtocol;
+ private int priorityOrder;
+ private Timestamp createdTime;
+ private Timestamp updatedTime;
+
+ 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;
+ }
+
+ @Override
+ public void remove(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(JOB_SUBMISSION_INTERFACE);
+ generator.setParameter(JobSubmissionInterfaceConstants.JOB_SUBMISSION_INTERFACE_ID, ids.get(JobSubmissionInterfaceConstants.JOB_SUBMISSION_INTERFACE_ID));
+ generator.setParameter(JobSubmissionInterfaceConstants.COMPUTE_RESOURCE_ID, ids.get(JobSubmissionInterfaceConstants.COMPUTE_RESOURCE_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 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(JOB_SUBMISSION_INTERFACE);
+ generator.setParameter(JobSubmissionInterfaceConstants.JOB_SUBMISSION_INTERFACE_ID, ids.get(JobSubmissionInterfaceConstants.JOB_SUBMISSION_INTERFACE_ID));
+ generator.setParameter(JobSubmissionInterfaceConstants.COMPUTE_RESOURCE_ID, ids.get(JobSubmissionInterfaceConstants.COMPUTE_RESOURCE_ID));
+ Query q = generator.selectQuery(em);
+ JobSubmissionInterface jobSubmissionInterface = (JobSubmissionInterface) q.getSingleResult();
+ JobSubmissionInterfaceAppCatalogResourceAppCat jobSubmissionInterfaceResource = (JobSubmissionInterfaceAppCatalogResourceAppCat) AppCatalogJPAUtils.getResource(AppCatalogResourceType.JOB_SUBMISSION_INTERFACE, jobSubmissionInterface);
+ em.getTransaction().commit();
+ em.close();
+ return jobSubmissionInterfaceResource;
+ } 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> jobSubmissionInterfaceResources = new ArrayList<AppCatalogResource>();
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(JOB_SUBMISSION_INTERFACE);
+ Query q;
+ if ((fieldName.equals(JobSubmissionInterfaceConstants.JOB_SUBMISSION_INTERFACE_ID)) || (fieldName.equals(JobSubmissionInterfaceConstants.COMPUTE_RESOURCE_ID)) || (fieldName.equals(JobSubmissionInterfaceConstants.JOB_SUBMISSION_PROTOCOL)) || (fieldName.equals(JobSubmissionInterfaceConstants.PRIORITY_ORDER))) {
+ generator.setParameter(fieldName, value);
+ q = generator.selectQuery(em);
+ List<?> results = q.getResultList();
+ for (Object result : results) {
+ JobSubmissionInterface jobSubmissionInterface = (JobSubmissionInterface) result;
+ JobSubmissionInterfaceAppCatalogResourceAppCat jobSubmissionInterfaceResource = (JobSubmissionInterfaceAppCatalogResourceAppCat) AppCatalogJPAUtils.getResource(AppCatalogResourceType.JOB_SUBMISSION_INTERFACE, jobSubmissionInterface);
+ jobSubmissionInterfaceResources.add(jobSubmissionInterfaceResource);
+ }
+ } else {
+ em.getTransaction().commit();
+ em.close();
+ logger.error("Unsupported field name for Job Submission Interface Resource.", new IllegalArgumentException());
+ throw new IllegalArgumentException("Unsupported field name for Job Submission Interface Resource.");
+ }
+ 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 jobSubmissionInterfaceResources;
+ }
+
+ @Override
+ public List<AppCatalogResource> getAll() throws AppCatalogException {
+ return null;
+ }
+
+ @Override
+ public List<String> getAllIds() throws AppCatalogException {
+ return null;
+ }
+
+ @Override
+ public List<String> getIds(String fieldName, Object value) throws AppCatalogException {
+ List<String> jobSubmissionInterfaceResourceIDs = new ArrayList<String>();
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(JOB_SUBMISSION_INTERFACE);
+ Query q;
+ if ((fieldName.equals(JobSubmissionInterfaceConstants.JOB_SUBMISSION_INTERFACE_ID)) || (fieldName.equals(JobSubmissionInterfaceConstants.COMPUTE_RESOURCE_ID)) || (fieldName.equals(JobSubmissionInterfaceConstants.JOB_SUBMISSION_PROTOCOL)) || (fieldName.equals(JobSubmissionInterfaceConstants.PRIORITY_ORDER))) {
+ generator.setParameter(fieldName, value);
+ q = generator.selectQuery(em);
+ List<?> results = q.getResultList();
+ for (Object result : results) {
+ JobSubmissionInterface jobSubmissionInterface = (JobSubmissionInterface) result;
+ JobSubmissionInterfaceAppCatalogResourceAppCat jobSubmissionInterfaceResource = (JobSubmissionInterfaceAppCatalogResourceAppCat) AppCatalogJPAUtils.getResource(AppCatalogResourceType.JOB_SUBMISSION_INTERFACE, jobSubmissionInterface);
+ jobSubmissionInterfaceResourceIDs.add(jobSubmissionInterfaceResource.getComputeResourceId());
+ }
+ } else {
+ em.getTransaction().commit();
+ em.close();
+ logger.error("Unsupported field name for Job Submission Interface Resource.", new IllegalArgumentException());
+ throw new IllegalArgumentException("Unsupported field name for Job Submission Interface Resource.");
+ }
+ 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 jobSubmissionInterfaceResourceIDs;
+ }
+
+ @Override
+ public void save() throws AppCatalogException {
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ JobSubmissionInterface existingJobSubmissionInterface = em.find(JobSubmissionInterface.class, new JobSubmissionInterface_PK(jobSubmissionInterfaceId, computeResourceId));
+ em.close();
+ JobSubmissionInterface jobSubmissionInterface;
+ em = AppCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ if (existingJobSubmissionInterface == null) {
+ jobSubmissionInterface = new JobSubmissionInterface();
+ jobSubmissionInterface.setCreationTime(AiravataUtils.getCurrentTimestamp());
+ } else {
+ jobSubmissionInterface = existingJobSubmissionInterface;
+ jobSubmissionInterface.setUpdateTime(AiravataUtils.getCurrentTimestamp());
+ }
+ jobSubmissionInterface.setJobSubmissionInterfaceId(getJobSubmissionInterfaceId());
+ jobSubmissionInterface.setComputeResourceId(getComputeResourceId());
+ ComputeResource computeResource = em.find(ComputeResource.class, getComputeResourceId());
+ jobSubmissionInterface.setComputeResource(computeResource);
+ jobSubmissionInterface.setJobSubmissionProtocol(getJobSubmissionProtocol());
+ jobSubmissionInterface.setPriorityOrder(getPriorityOrder());
+ if (existingJobSubmissionInterface == null) {
+ em.persist(jobSubmissionInterface);
+ } else {
+ em.merge(jobSubmissionInterface);
+ }
+ 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<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();
+ JobSubmissionInterface jobSubmissionInterface = em.find(JobSubmissionInterface.class, new JobSubmissionInterface_PK(ids.get(JobSubmissionInterfaceConstants.JOB_SUBMISSION_INTERFACE_ID), ids.get(JobSubmissionInterfaceConstants.COMPUTE_RESOURCE_ID)));
+ em.close();
+ return jobSubmissionInterface != 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 getJobSubmissionInterfaceId() {
+ return jobSubmissionInterfaceId;
+ }
+
+ public String getComputeResourceId() {
+ return computeResourceId;
+ }
+
+ public ComputeResourceAppCatalogResourceAppCat getComputeHostResource() {
+ return computeHostResource;
+ }
+
+ public String getJobSubmissionProtocol() {
+ return jobSubmissionProtocol;
+ }
+
+ public int getPriorityOrder() {
+ return priorityOrder;
+ }
+
+ public void setJobSubmissionInterfaceId(String jobSubmissionInterfaceId) {
+ this.jobSubmissionInterfaceId=jobSubmissionInterfaceId;
+ }
+
+ public void setComputeResourceId(String computeResourceId) {
+ this.computeResourceId=computeResourceId;
+ }
+
+ public void setComputeHostResource(ComputeResourceAppCatalogResourceAppCat computeHostResource) {
+ this.computeHostResource=computeHostResource;
+ }
+
+ public void setJobSubmissionProtocol(String jobSubmissionProtocol) {
+ this.jobSubmissionProtocol=jobSubmissionProtocol;
+ }
+
+ public void setPriorityOrder(int priorityOrder) {
+ this.priorityOrder=priorityOrder;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/ec8c6202/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/JobSubmissionInterfaceResource.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/JobSubmissionInterfaceResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/JobSubmissionInterfaceResource.java
new file mode 100644
index 0000000..a5acbef
--- /dev/null
+++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/JobSubmissionInterfaceResource.java
@@ -0,0 +1,339 @@
+/*
+ *
+ * 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 java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+
+import org.airavata.appcatalog.cpi.AppCatalogException;
+import org.apache.aiaravata.application.catalog.data.model.ComputeResource;
+import org.apache.aiaravata.application.catalog.data.model.JobSubmissionInterface;
+import org.apache.aiaravata.application.catalog.data.model.JobSubmissionInterface_PK;
+import org.apache.aiaravata.application.catalog.data.util.AppCatalogJPAUtils;
+import org.apache.aiaravata.application.catalog.data.util.AppCatalogQueryGenerator;
+import org.apache.aiaravata.application.catalog.data.util.AppCatalogResourceType;
+import org.apache.airavata.common.exception.ApplicationSettingsException;
+import org.apache.airavata.common.utils.AiravataUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class JobSubmissionInterfaceResource extends AbstractResource {
+ private final static Logger logger = LoggerFactory.getLogger(JobSubmissionInterfaceResource.class);
+ private String jobSubmissionInterfaceId;
+ private String computeResourceId;
+ private ComputeResourceResource computeHostResource;
+ private String jobSubmissionProtocol;
+ private int priorityOrder;
+ private Timestamp createdTime;
+ private Timestamp updatedTime;
+
+ 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;
+ }
+
+ @Override
+ public void remove(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(JOB_SUBMISSION_INTERFACE);
+ generator.setParameter(JobSubmissionInterfaceConstants.JOB_SUBMISSION_INTERFACE_ID, ids.get(JobSubmissionInterfaceConstants.JOB_SUBMISSION_INTERFACE_ID));
+ generator.setParameter(JobSubmissionInterfaceConstants.COMPUTE_RESOURCE_ID, ids.get(JobSubmissionInterfaceConstants.COMPUTE_RESOURCE_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<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(JOB_SUBMISSION_INTERFACE);
+ generator.setParameter(JobSubmissionInterfaceConstants.JOB_SUBMISSION_INTERFACE_ID, ids.get(JobSubmissionInterfaceConstants.JOB_SUBMISSION_INTERFACE_ID));
+ generator.setParameter(JobSubmissionInterfaceConstants.COMPUTE_RESOURCE_ID, ids.get(JobSubmissionInterfaceConstants.COMPUTE_RESOURCE_ID));
+ Query q = generator.selectQuery(em);
+ JobSubmissionInterface jobSubmissionInterface = (JobSubmissionInterface) q.getSingleResult();
+ JobSubmissionInterfaceResource jobSubmissionInterfaceResource = (JobSubmissionInterfaceResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.JOB_SUBMISSION_INTERFACE, jobSubmissionInterface);
+ em.getTransaction().commit();
+ em.close();
+ return jobSubmissionInterfaceResource;
+ } 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> jobSubmissionInterfaceResources = new ArrayList<Resource>();
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(JOB_SUBMISSION_INTERFACE);
+ Query q;
+ if ((fieldName.equals(JobSubmissionInterfaceConstants.JOB_SUBMISSION_INTERFACE_ID)) || (fieldName.equals(JobSubmissionInterfaceConstants.COMPUTE_RESOURCE_ID)) || (fieldName.equals(JobSubmissionInterfaceConstants.JOB_SUBMISSION_PROTOCOL)) || (fieldName.equals(JobSubmissionInterfaceConstants.PRIORITY_ORDER))) {
+ generator.setParameter(fieldName, value);
+ q = generator.selectQuery(em);
+ List<?> results = q.getResultList();
+ for (Object result : results) {
+ JobSubmissionInterface jobSubmissionInterface = (JobSubmissionInterface) result;
+ JobSubmissionInterfaceResource jobSubmissionInterfaceResource = (JobSubmissionInterfaceResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.JOB_SUBMISSION_INTERFACE, jobSubmissionInterface);
+ jobSubmissionInterfaceResources.add(jobSubmissionInterfaceResource);
+ }
+ } else {
+ em.getTransaction().commit();
+ em.close();
+ logger.error("Unsupported field name for Job Submission Interface Resource.", new IllegalArgumentException());
+ throw new IllegalArgumentException("Unsupported field name for Job Submission Interface Resource.");
+ }
+ 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 jobSubmissionInterfaceResources;
+ }
+
+ @Override
+ public List<Resource> getAll() throws AppCatalogException {
+ return null;
+ }
+
+ @Override
+ public List<String> getAllIds() throws AppCatalogException {
+ return null;
+ }
+
+ @Override
+ public List<String> getIds(String fieldName, Object value) throws AppCatalogException {
+ List<String> jobSubmissionInterfaceResourceIDs = new ArrayList<String>();
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(JOB_SUBMISSION_INTERFACE);
+ Query q;
+ if ((fieldName.equals(JobSubmissionInterfaceConstants.JOB_SUBMISSION_INTERFACE_ID)) || (fieldName.equals(JobSubmissionInterfaceConstants.COMPUTE_RESOURCE_ID)) || (fieldName.equals(JobSubmissionInterfaceConstants.JOB_SUBMISSION_PROTOCOL)) || (fieldName.equals(JobSubmissionInterfaceConstants.PRIORITY_ORDER))) {
+ generator.setParameter(fieldName, value);
+ q = generator.selectQuery(em);
+ List<?> results = q.getResultList();
+ for (Object result : results) {
+ JobSubmissionInterface jobSubmissionInterface = (JobSubmissionInterface) result;
+ JobSubmissionInterfaceResource jobSubmissionInterfaceResource = (JobSubmissionInterfaceResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.JOB_SUBMISSION_INTERFACE, jobSubmissionInterface);
+ jobSubmissionInterfaceResourceIDs.add(jobSubmissionInterfaceResource.getComputeResourceId());
+ }
+ } else {
+ em.getTransaction().commit();
+ em.close();
+ logger.error("Unsupported field name for Job Submission Interface Resource.", new IllegalArgumentException());
+ throw new IllegalArgumentException("Unsupported field name for Job Submission Interface Resource.");
+ }
+ 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 jobSubmissionInterfaceResourceIDs;
+ }
+
+ @Override
+ public void save() throws AppCatalogException {
+ EntityManager em = null;
+ try {
+ em = AppCatalogJPAUtils.getEntityManager();
+ JobSubmissionInterface existingJobSubmissionInterface = em.find(JobSubmissionInterface.class, new JobSubmissionInterface_PK(jobSubmissionInterfaceId, computeResourceId));
+ em.close();
+ JobSubmissionInterface jobSubmissionInterface;
+ em = AppCatalogJPAUtils.getEntityManager();
+ em.getTransaction().begin();
+ if (existingJobSubmissionInterface == null) {
+ jobSubmissionInterface = new JobSubmissionInterface();
+ jobSubmissionInterface.setCreationTime(AiravataUtils.getCurrentTimestamp());
+ } else {
+ jobSubmissionInterface = existingJobSubmissionInterface;
+ jobSubmissionInterface.setUpdateTime(AiravataUtils.getCurrentTimestamp());
+ }
+ jobSubmissionInterface.setJobSubmissionInterfaceId(getJobSubmissionInterfaceId());
+ jobSubmissionInterface.setComputeResourceId(getComputeResourceId());
+ ComputeResource computeResource = em.find(ComputeResource.class, getComputeResourceId());
+ jobSubmissionInterface.setComputeResource(computeResource);
+ jobSubmissionInterface.setJobSubmissionProtocol(getJobSubmissionProtocol());
+ jobSubmissionInterface.setPriorityOrder(getPriorityOrder());
+ if (existingJobSubmissionInterface == null) {
+ em.persist(jobSubmissionInterface);
+ } else {
+ em.merge(jobSubmissionInterface);
+ }
+ 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<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();
+ JobSubmissionInterface jobSubmissionInterface = em.find(JobSubmissionInterface.class, new JobSubmissionInterface_PK(ids.get(JobSubmissionInterfaceConstants.JOB_SUBMISSION_INTERFACE_ID), ids.get(JobSubmissionInterfaceConstants.COMPUTE_RESOURCE_ID)));
+ em.close();
+ return jobSubmissionInterface != 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 getJobSubmissionInterfaceId() {
+ return jobSubmissionInterfaceId;
+ }
+
+ public String getComputeResourceId() {
+ return computeResourceId;
+ }
+
+ public ComputeResourceResource getComputeHostResource() {
+ return computeHostResource;
+ }
+
+ public String getJobSubmissionProtocol() {
+ return jobSubmissionProtocol;
+ }
+
+ public int getPriorityOrder() {
+ return priorityOrder;
+ }
+
+ public void setJobSubmissionInterfaceId(String jobSubmissionInterfaceId) {
+ this.jobSubmissionInterfaceId=jobSubmissionInterfaceId;
+ }
+
+ public void setComputeResourceId(String computeResourceId) {
+ this.computeResourceId=computeResourceId;
+ }
+
+ public void setComputeHostResource(ComputeResourceResource computeHostResource) {
+ this.computeHostResource=computeHostResource;
+ }
+
+ public void setJobSubmissionProtocol(String jobSubmissionProtocol) {
+ this.jobSubmissionProtocol=jobSubmissionProtocol;
+ }
+
+ public void setPriorityOrder(int priorityOrder) {
+ this.priorityOrder=priorityOrder;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/ec8c6202/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/JobSubmissionProtocolResource.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/JobSubmissionProtocolResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/JobSubmissionProtocolResource.java
new file mode 100644
index 0000000..c3c8315
--- /dev/null
+++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/JobSubmissionProtocolResource.java
@@ -0,0 +1,359 @@
+///**
+// * 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.apache.airavata.registry.cpi.AppCatalogException;
+//import org.apache.aiaravata.application.catalog.data.model.ComputeResource;
+//import org.apache.aiaravata.application.catalog.data.model.JobSubmissionProtocol;
+//import org.apache.aiaravata.application.catalog.data.model.JobSubmissionProtocolPK;
+//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 JobSubmissionProtocolResource extends AbstractResource {
+//
+// private final static Logger logger = LoggerFactory.getLogger(JobSubmissionProtocolResource.class);
+//
+// private String resourceID;
+// private String submissionID;
+// private String jobType;
+// private ComputeResourceResource computeHostResource;
+//
+// 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(JOB_SUBMISSION_PROTOCOL);
+// generator.setParameter(JobSubmissionProtocolConstants.RESOURCE_ID, ids.get(JobSubmissionProtocolConstants.RESOURCE_ID));
+// generator.setParameter(JobSubmissionProtocolConstants.SUBMISSION_ID, ids.get(JobSubmissionProtocolConstants.SUBMISSION_ID));
+// generator.setParameter(JobSubmissionProtocolConstants.JOB_TYPE, ids.get(JobSubmissionProtocolConstants.JOB_TYPE));
+// Query q = generator.deleteQuery(em);
+// q.executeUpdate();
+// em.getTransaction().commit();
+// em.close();
+// } catch (ApplicationSettingsException e) {
+// logger.error(e.getMessage(), e);
+// throw new AppCatalogException(e);
+// } finally {
+// if (em != null && em.isOpen()) {
+// if (em.getTransaction().isActive()) {
+// em.getTransaction().rollback();
+// }
+// em.close();
+// }
+// }
+// }
+//
+// public Resource get(Object identifier) throws AppCatalogException {
+// HashMap<String, String> ids;
+// if (identifier instanceof Map) {
+// ids = (HashMap) identifier;
+// } else {
+// logger.error("Identifier should be a map with the field name and it's value");
+// throw new AppCatalogException("Identifier should be a map with the field name and it's value");
+// }
+//
+// EntityManager em = null;
+// try {
+// em = AppCatalogJPAUtils.getEntityManager();
+// em.getTransaction().begin();
+// AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(JOB_SUBMISSION_PROTOCOL);
+// generator.setParameter(JobSubmissionProtocolConstants.RESOURCE_ID, ids.get(JobSubmissionProtocolConstants.RESOURCE_ID));
+// generator.setParameter(JobSubmissionProtocolConstants.SUBMISSION_ID, ids.get(JobSubmissionProtocolConstants.SUBMISSION_ID));
+// generator.setParameter(JobSubmissionProtocolConstants.JOB_TYPE, ids.get(JobSubmissionProtocolConstants.JOB_TYPE));
+// Query q = generator.selectQuery(em);
+// JobSubmissionProtocol jobSubmissionProtocol = (JobSubmissionProtocol) q.getSingleResult();
+// JobSubmissionProtocolResource jobSubmissionProtocolResource =
+// (JobSubmissionProtocolResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.JOB_SUBMISSION_PROTOCOL, jobSubmissionProtocol);
+// em.getTransaction().commit();
+// em.close();
+// return jobSubmissionProtocolResource;
+// } catch (ApplicationSettingsException e) {
+// logger.error(e.getMessage(), e);
+// throw new AppCatalogException(e);
+// } finally {
+// if (em != null && em.isOpen()) {
+// if (em.getTransaction().isActive()) {
+// em.getTransaction().rollback();
+// }
+// em.close();
+// }
+// }
+// }
+//
+// public List<Resource> get(String fieldName, Object value) throws AppCatalogException {
+// List<Resource> jobSubmissionProtocolResourceList = new ArrayList<Resource>();
+// EntityManager em = null;
+// try {
+// em = AppCatalogJPAUtils.getEntityManager();
+// em.getTransaction().begin();
+// Query q;
+// AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(JOB_SUBMISSION_PROTOCOL);
+// List results;
+// if (fieldName.equals(JobSubmissionProtocolConstants.SUBMISSION_ID)) {
+// generator.setParameter(JobSubmissionProtocolConstants.SUBMISSION_ID, value);
+// q = generator.selectQuery(em);
+// results = q.getResultList();
+// if (results.size() != 0) {
+// for (Object result : results) {
+// JobSubmissionProtocol jobSubmissionProtocol = (JobSubmissionProtocol) result;
+// JobSubmissionProtocolResource jobSubmissionProtocolResource =
+// (JobSubmissionProtocolResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.JOB_SUBMISSION_PROTOCOL, jobSubmissionProtocol);
+// jobSubmissionProtocolResourceList.add(jobSubmissionProtocolResource);
+// }
+// }
+// } else if (fieldName.equals(JobSubmissionProtocolConstants.JOB_TYPE)) {
+// generator.setParameter(JobSubmissionProtocolConstants.JOB_TYPE, value);
+// q = generator.selectQuery(em);
+// results = q.getResultList();
+// if (results.size() != 0) {
+// for (Object result : results) {
+// JobSubmissionProtocol jobSubmissionProtocol = (JobSubmissionProtocol) result;
+// JobSubmissionProtocolResource jobSubmissionProtocolResource =
+// (JobSubmissionProtocolResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.JOB_SUBMISSION_PROTOCOL, jobSubmissionProtocol);
+// jobSubmissionProtocolResourceList.add(jobSubmissionProtocolResource);
+// }
+// }
+// } else if (fieldName.equals(HostIPAddressConstants.RESOURCE_ID)) {
+// generator.setParameter(HostIPAddressConstants.RESOURCE_ID, value);
+// q = generator.selectQuery(em);
+// results = q.getResultList();
+// if (results.size() != 0) {
+// for (Object result : results) {
+// JobSubmissionProtocol jobSubmissionProtocol = (JobSubmissionProtocol) result;
+// JobSubmissionProtocolResource jobSubmissionProtocolResource =
+// (JobSubmissionProtocolResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.JOB_SUBMISSION_PROTOCOL, jobSubmissionProtocol);
+// jobSubmissionProtocolResourceList.add(jobSubmissionProtocolResource);
+// }
+// }
+// } else {
+// em.getTransaction().commit();
+// em.close();
+// logger.error("Unsupported field name for Job Submission Protocol Resource.", new IllegalArgumentException());
+// throw new IllegalArgumentException("Unsupported field name for Job Submission Protocol 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 jobSubmissionProtocolResourceList;
+// }
+//
+// @Override
+// public List<Resource> getAll() throws AppCatalogException {
+// return null;
+// }
+//
+// @Override
+// public List<String> getAllIds() throws AppCatalogException {
+// return null;
+// }
+//
+// public List<String> getIds(String fieldName, Object value) throws AppCatalogException {
+// List<String> jobSubmissionProtocolIDs = new ArrayList<String>();
+// EntityManager em = null;
+// try {
+// em = AppCatalogJPAUtils.getEntityManager();
+// em.getTransaction().begin();
+// Query q;
+// AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(JOB_SUBMISSION_PROTOCOL);
+// List results;
+// if (fieldName.equals(JobSubmissionProtocolConstants.SUBMISSION_ID)) {
+// generator.setParameter(JobSubmissionProtocolConstants.SUBMISSION_ID, value);
+// q = generator.selectQuery(em);
+// results = q.getResultList();
+// if (results.size() != 0) {
+// for (Object result : results) {
+// JobSubmissionProtocol jobSubmissionProtocol = (JobSubmissionProtocol) result;
+// jobSubmissionProtocolIDs.add(jobSubmissionProtocol.getSubmissionID());
+// }
+// }
+// } else if (fieldName.equals(JobSubmissionProtocolConstants.RESOURCE_ID)) {
+// generator.setParameter(JobSubmissionProtocolConstants.RESOURCE_ID, value);
+// q = generator.selectQuery(em);
+// results = q.getResultList();
+// if (results.size() != 0) {
+// for (Object result : results) {
+// JobSubmissionProtocol jobSubmissionProtocol = (JobSubmissionProtocol) result;
+// jobSubmissionProtocolIDs.add(jobSubmissionProtocol.getSubmissionID());
+// }
+// }
+// } else if (fieldName.equals(JobSubmissionProtocolConstants.JOB_TYPE)) {
+// generator.setParameter(JobSubmissionProtocolConstants.JOB_TYPE, value);
+// q = generator.selectQuery(em);
+// results = q.getResultList();
+// if (results.size() != 0) {
+// for (Object result : results) {
+// JobSubmissionProtocol jobSubmissionProtocol = (JobSubmissionProtocol) result;
+// jobSubmissionProtocolIDs.add(jobSubmissionProtocol.getSubmissionID());
+// }
+// }
+// } else {
+// em.getTransaction().commit();
+// em.close();
+// logger.error("Unsupported field name for Job Submission Protocol resource.", new IllegalArgumentException());
+// throw new IllegalArgumentException("Unsupported field name for Job Submission Protocol 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 jobSubmissionProtocolIDs;
+// }
+//
+// public void save() throws AppCatalogException {
+// EntityManager em = null;
+// try {
+// em = AppCatalogJPAUtils.getEntityManager();
+// JobSubmissionProtocol existingJobSubProtocol = em.find(JobSubmissionProtocol.class, new JobSubmissionProtocolPK(resourceID, submissionID, jobType));
+// em.close();
+//
+// em = AppCatalogJPAUtils.getEntityManager();
+// em.getTransaction().begin();
+// ComputeResource computeResource = em.find(ComputeResource.class, resourceID);
+// if (existingJobSubProtocol != null) {
+// existingJobSubProtocol.setJobType(jobType);
+// existingJobSubProtocol.setSubmissionID(submissionID);
+// existingJobSubProtocol.setComputeResource(computeResource);
+// existingJobSubProtocol.setResourceID(resourceID);
+// em.merge(existingJobSubProtocol);
+// } else {
+// JobSubmissionProtocol jobSubmissionProtocol = new JobSubmissionProtocol();
+// jobSubmissionProtocol.setJobType(jobType);
+// jobSubmissionProtocol.setSubmissionID(submissionID);
+// jobSubmissionProtocol.setResourceID(resourceID);
+// jobSubmissionProtocol.setComputeResource(computeResource);
+// em.persist(jobSubmissionProtocol);
+// }
+// em.getTransaction().commit();
+// em.close();
+// } catch (Exception e) {
+// logger.error(e.getMessage(), e);
+// throw new AppCatalogException(e);
+// } finally {
+// if (em != null && em.isOpen()) {
+// if (em.getTransaction().isActive()) {
+// em.getTransaction().rollback();
+// }
+// em.close();
+// }
+// }
+//
+// }
+//
+// public boolean isExists(Object identifier) throws AppCatalogException {
+// HashMap<String, String> ids;
+// if (identifier instanceof Map) {
+// ids = (HashMap) identifier;
+// } else {
+// logger.error("Identifier should be a map with the field name and it's value");
+// throw new AppCatalogException("Identifier should be a map with the field name and it's value");
+// }
+//
+// EntityManager em = null;
+// try {
+// em = AppCatalogJPAUtils.getEntityManager();
+// JobSubmissionProtocol jobSubmissionProtocol = em.find(JobSubmissionProtocol.class, new JobSubmissionProtocolPK(ids.get(JobSubmissionProtocolConstants.RESOURCE_ID),
+// ids.get(JobSubmissionProtocolConstants.SUBMISSION_ID), ids.get(JobSubmissionProtocolConstants.JOB_TYPE)));
+//
+// em.close();
+// return jobSubmissionProtocol != 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 getResourceID() {
+// return resourceID;
+// }
+//
+// public void setResourceID(String resourceID) {
+// this.resourceID = resourceID;
+// }
+//
+// public String getSubmissionID() {
+// return submissionID;
+// }
+//
+// public void setSubmissionID(String submissionID) {
+// this.submissionID = submissionID;
+// }
+//
+// public String getJobType() {
+// return jobType;
+// }
+//
+// public void setJobType(String jobType) {
+// this.jobType = jobType;
+// }
+//
+// public ComputeResourceResource getComputeHostResource() {
+// return computeHostResource;
+// }
+//
+// public void setComputeHostResource(ComputeResourceResource computeHostResource) {
+// this.computeHostResource = computeHostResource;
+// }
+//}