http://git-wip-us.apache.org/repos/asf/airavata/blob/4045c094/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/NotificationEmailResource.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/NotificationEmailResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/NotificationEmailResource.java new file mode 100644 index 0000000..47c8d83 --- /dev/null +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/NotificationEmailResource.java @@ -0,0 +1,119 @@ +/* +* +* 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.experiment.catalog.resources; + +import org.apache.airavata.registry.core.experiment.catalog.ExpCatResourceUtils; +import org.apache.airavata.registry.core.experiment.catalog.ExperimentCatResource; +import org.apache.airavata.registry.core.experiment.catalog.ResourceType; +import org.apache.airavata.registry.core.experiment.catalog.model.*; +import org.apache.airavata.registry.cpi.RegistryException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.persistence.EntityManager; +import java.util.List; + +public class NotificationEmailResource extends AbstractExpCatResource { + private static final Logger logger = LoggerFactory.getLogger(NotificationEmailResource.class); + + private int emailId = 0; + private String experimentId; + private String taskId; + private String emailAddress; + + + public String getEmailAddress() { + return emailAddress; + } + + public void setEmailAddress(String emailAddress) { + this.emailAddress = emailAddress; + } + + public String getExperimentId() { + return experimentId; + } + + public void setExperimentId(String experimentId) { + this.experimentId = experimentId; + } + + public String getTaskId() { + return taskId; + } + + public void setTaskId(String taskId) { + this.taskId = taskId; + } + + public ExperimentCatResource create(ResourceType type) throws RegistryException { + logger.error("Unsupported resource type for experiment input data resource.", new UnsupportedOperationException()); + throw new UnsupportedOperationException(); + } + + public void remove(ResourceType type, Object name) throws RegistryException{ + logger.error("Unsupported resource type for experiment input data resource.", new UnsupportedOperationException()); + throw new UnsupportedOperationException(); + } + + public ExperimentCatResource get(ResourceType type, Object name) throws RegistryException { + logger.error("Unsupported resource type for experiment input data resource.", new UnsupportedOperationException()); + throw new UnsupportedOperationException(); + } + + public List<ExperimentCatResource> get(ResourceType type) throws RegistryException { + logger.error("Unsupported resource type for experiment input data resource.", new UnsupportedOperationException()); + throw new UnsupportedOperationException(); + } + + public void save() throws RegistryException{ + EntityManager em = null; + try { + em = ExpCatResourceUtils.getEntityManager(); + em.getTransaction().begin(); + Notification_Email notification_email; + if (emailId != 0 ){ + notification_email = em.find(Notification_Email.class, emailId); + notification_email.setEmailId(emailId); + }else { + notification_email = new Notification_Email(); + } + notification_email.setExperiment_id(experimentId); + notification_email.setTaskId(taskId); + notification_email.setEmailAddress(emailAddress); + em.persist(notification_email); + emailId = notification_email.getEmailId(); + em.getTransaction().commit(); + em.close(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new RegistryException(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/experiment/catalog/resources/ProjectExperimentCatResource.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ProjectExperimentCatResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ProjectExperimentCatResource.java deleted file mode 100644 index ebfc799..0000000 --- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ProjectExperimentCatResource.java +++ /dev/null @@ -1,508 +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.experiment.catalog.resources; - -import org.apache.airavata.registry.core.experiment.catalog.ExpCatResourceUtils; -import org.apache.airavata.registry.core.experiment.catalog.ExperimentCatResource; -import org.apache.airavata.registry.core.experiment.catalog.ResourceType; -import org.apache.airavata.registry.core.experiment.catalog.model.*; -import org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator; -import org.apache.airavata.registry.cpi.RegistryException; -import org.apache.airavata.registry.cpi.ResultOrderType; -import org.apache.airavata.registry.cpi.utils.Constants; -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 ProjectExperimentCatResource extends AbstractExperimentCatResource { - private final static Logger logger = LoggerFactory.getLogger(ProjectExperimentCatResource.class); - private String name; - private String id; - private String gatewayId; - private WorkerExperimentCatResource worker; - private String description; - private Timestamp creationTime; - - /** - * - */ - public ProjectExperimentCatResource() { - } - - /** - * - * @param type child resource type - * @return child resource - */ - public ExperimentCatResource create(ResourceType type) throws RegistryException { - if (type == ResourceType.EXPERIMENT) { - ExperimentExperimentCatResource experimentResource = new ExperimentExperimentCatResource(); - experimentResource.setGatewayId(gatewayId); - experimentResource.setExecutionUser(worker.getUser()); - experimentResource.setProjectId(id); - return experimentResource; - } else if (type == ResourceType.PROJECT_USER){ - ProjectUserExperimentCatResource pr = new ProjectUserExperimentCatResource(); - pr.setProjectId(id); - pr.setUserName(worker.getUser()); - return pr; - } - else { - logger.error("Unsupported resource type for project resource.", new IllegalArgumentException()); - throw new IllegalArgumentException("Unsupported resource type for project resource."); - } - } - - /** - * - * @param type child resource type - * @param name child resource name - */ - public void remove(ResourceType type, Object name) throws RegistryException{ - EntityManager em = null; - try { - em = ExpCatResourceUtils.getEntityManager(); - em.getTransaction().begin(); - if (type == ResourceType.EXPERIMENT) { - QueryGenerator generator = new QueryGenerator(EXPERIMENT); - generator.setParameter(ExperimentConstants.EXPERIMENT_ID, name); - Query q = generator.deleteQuery(em); - q.executeUpdate(); - } else if (type == ResourceType.PROJECT_USER) { - QueryGenerator generator = new QueryGenerator(PROJECT_USER); - generator.setParameter(ProjectUserConstants.USERNAME, name); - generator.setParameter(ProjectUserConstants.PROJECT_ID, this.id); - Query q = generator.deleteQuery(em); - q.executeUpdate(); - } else { - logger.error("Unsupported resource type for project resource.", new IllegalArgumentException()); - throw new IllegalArgumentException("Unsupported resource type for project resource."); - } - em.getTransaction().commit(); - em.close(); - } catch (Exception e) { - logger.error(e.getMessage(), e); - throw new RegistryException(e); - } finally { - if (em != null && em.isOpen()) { - if (em.getTransaction().isActive()){ - em.getTransaction().rollback(); - } - em.close(); - } - } - } - - /** - * - * @param type child resource type - * @param name child resource name - * @return child resource - */ - public ExperimentCatResource get(ResourceType type, Object name) throws RegistryException { - EntityManager em = null; - try { - if (type == ResourceType.EXPERIMENT) { - em = ExpCatResourceUtils.getEntityManager(); - em.getTransaction().begin(); - QueryGenerator generator = new QueryGenerator(EXPERIMENT); - generator.setParameter(ExperimentConstants.EXPERIMENT_ID, name); - Query q = generator.selectQuery(em); - Experiment experiment = (Experiment) q.getSingleResult(); - ExperimentExperimentCatResource experimentResource = (ExperimentExperimentCatResource) - Utils.getResource(ResourceType.EXPERIMENT, experiment); - em.getTransaction().commit(); - em.close(); - return experimentResource; - } else if (type == ResourceType.PROJECT_USER) { - em = ExpCatResourceUtils.getEntityManager(); - em.getTransaction().begin(); - QueryGenerator generator = new QueryGenerator(PROJECT_USER); - generator.setParameter(ProjectUserConstants.USERNAME, name); - generator.setParameter(ProjectUserConstants.PROJECT_ID, this.id); - Query q = generator.selectQuery(em); - ProjectUser prUser = (ProjectUser) q.getSingleResult(); - ExperimentExperimentCatResource experimentResource = (ExperimentExperimentCatResource) - Utils.getResource(ResourceType.PROJECT_USER, prUser); - em.getTransaction().commit(); - em.close(); - return experimentResource; - } else { - logger.error("Unsupported resource type for project resource.", new IllegalArgumentException()); - throw new IllegalArgumentException("Unsupported resource type for project resource."); - } - } catch (Exception e) { - throw new RegistryException(e); - } finally { - if (em != null && em.isOpen()) { - if (em.getTransaction().isActive()){ - em.getTransaction().rollback(); - } - em.close(); - } - } - } - - /** - * - * @param type child resource type - * @return list of child resources - */ - @Override - public List<ExperimentCatResource> get(ResourceType type) throws RegistryException{ - List<ExperimentCatResource> resourceList = new ArrayList<ExperimentCatResource>(); - EntityManager em = null; - try { - if (type == ResourceType.EXPERIMENT) { - em = ExpCatResourceUtils.getEntityManager(); - em.getTransaction().begin(); - QueryGenerator generator = new QueryGenerator(EXPERIMENT); - generator.setParameter(ExperimentConstants.PROJECT_ID, id); - Query q = generator.selectQuery(em); - List<?> results = q.getResultList(); - if (results.size() != 0) { - for (Object result : results) { - Experiment experiment = (Experiment) result; - ExperimentExperimentCatResource experimentResource = (ExperimentExperimentCatResource) - Utils.getResource(ResourceType.EXPERIMENT, experiment); - resourceList.add(experimentResource); - } - } - em.getTransaction().commit(); - em.close(); - } else if (type == ResourceType.PROJECT_USER) { - em = ExpCatResourceUtils.getEntityManager(); - em.getTransaction().begin(); - QueryGenerator generator = new QueryGenerator(PROJECT_USER); - generator.setParameter(ProjectUserConstants.PROJECT_ID, id); - Query q = generator.selectQuery(em); - List<?> results = q.getResultList(); - if (results.size() != 0) { - for (Object result : results) { - ProjectUser projectUser = (ProjectUser) result; - ProjectUserExperimentCatResource pr = (ProjectUserExperimentCatResource) - Utils.getResource(ResourceType.PROJECT_USER, projectUser); - resourceList.add(pr); - } - } - em.getTransaction().commit(); - em.close(); - } else { - logger.error("Unsupported resource type for project resource.", new IllegalArgumentException()); - throw new IllegalArgumentException("Unsupported resource type for project resource."); - } - } catch (Exception e) { - logger.error(e.getMessage(), e); - throw new RegistryException(e); - } finally { - if (em != null && em.isOpen()) { - if (em.getTransaction().isActive()){ - em.getTransaction().rollback(); - } - em.close(); - } - } - return resourceList; - } - - /** - * Get results with pagination and ordering - * - * @param type - * @param limit - * @param offset - * @param orderByIdentifier - * @return - * @throws RegistryException - */ - public List<ExperimentCatResource> get(ResourceType type, int limit, int offset, Object orderByIdentifier, - ResultOrderType resultOrderType) throws RegistryException{ - List<ExperimentCatResource> resourceList = new ArrayList<ExperimentCatResource>(); - EntityManager em = null; - try { - if (type == ResourceType.EXPERIMENT) { - em = ExpCatResourceUtils.getEntityManager(); - em.getTransaction().begin(); - QueryGenerator generator = new QueryGenerator(EXPERIMENT); - generator.setParameter(ExperimentConstants.PROJECT_ID, id); - Query q; - //ordering - supported only by CREATION_TIME - if(orderByIdentifier != null && resultOrderType != null - && orderByIdentifier.equals(Constants.FieldConstants.ExperimentConstants.CREATION_TIME)) { - q = generator.selectQuery(em, ExperimentConstants.CREATION_TIME, resultOrderType); - }else{ - q = generator.selectQuery(em); - } - - //pagination - if(limit>0 && offset>=0){ - q.setFirstResult(offset); - q.setMaxResults(limit); - } - List<?> results = q.getResultList(); - if (results.size() != 0) { - for (Object result : results) { - Experiment experiment = (Experiment) result; - ExperimentExperimentCatResource experimentResource = (ExperimentExperimentCatResource) - Utils.getResource(ResourceType.EXPERIMENT, experiment); - resourceList.add(experimentResource); - } - } - em.getTransaction().commit(); - em.close(); - } else if (type == ResourceType.PROJECT_USER) { - em = ExpCatResourceUtils.getEntityManager(); - em.getTransaction().begin(); - QueryGenerator generator = new QueryGenerator(PROJECT_USER); - generator.setParameter(ProjectUserConstants.PROJECT_ID, id); - Query q; - //ordering - only supported only by CREATION_TIME - if(orderByIdentifier != null && resultOrderType != null - && orderByIdentifier.equals(Constants.FieldConstants.ProjectConstants.CREATION_TIME)) { - q = generator.selectQuery(em, ProjectConstants.CREATION_TIME, resultOrderType); - }else{ - q = generator.selectQuery(em); - } - - //pagination - if(limit>0 && offset>=0){ - q.setFirstResult(offset); - q.setMaxResults(limit); - } - List<?> results = q.getResultList(); - if (results.size() != 0) { - for (Object result : results) { - ProjectUser projectUser = (ProjectUser) result; - ProjectUserExperimentCatResource pr = (ProjectUserExperimentCatResource) - Utils.getResource(ResourceType.PROJECT_USER, projectUser); - resourceList.add(pr); - } - } - em.getTransaction().commit(); - em.close(); - } else { - logger.error("Unsupported resource type for project resource.", new IllegalArgumentException()); - throw new IllegalArgumentException("Unsupported resource type for project resource."); - } - } catch (Exception e) { - logger.error(e.getMessage(), e); - throw new RegistryException(e); - } finally { - if (em != null && em.isOpen()) { - if (em.getTransaction().isActive()){ - em.getTransaction().rollback(); - } - em.close(); - } - } - return resourceList; - } - - /** - * save project to the database - */ - public void save() throws RegistryException{ - EntityManager em = null; - try { - em = ExpCatResourceUtils.getEntityManager(); - Project existingProject = em.find(Project.class, id); - em.close(); - - em = ExpCatResourceUtils.getEntityManager(); - em.getTransaction().begin(); - Project project = new Project(); - project.setProject_id(id); - project.setProject_name(name); - project.setGateway_id(gatewayId); - Users user = em.find(Users.class, worker.getUser()); - project.setUsers(user); - project.setUser_name(user.getUser_name()); - project.setDescription(description); - project.setCreationTime(creationTime); - - if (existingProject != null) { - existingProject.setProject_name(name); - existingProject.setGateway_id(gatewayId); - existingProject.setUsers(user); - existingProject.setUser_name(user.getUser_name()); - existingProject.setDescription(description); - existingProject.setCreationTime(creationTime); - project = em.merge(existingProject); - } else { - em.persist(project); - } - - em.getTransaction().commit(); - em.close(); - } catch (Exception e) { - logger.error(e.getMessage(), e); - throw new RegistryException(e); - } finally { - if (em != null && em.isOpen()) { - if (em.getTransaction().isActive()){ - em.getTransaction().rollback(); - } - em.close(); - } - } - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - /** - * - * @return project name - */ - public String getName() { - return name; - } - - /** - * - * @param name project name - */ - public void setName(String name) { - this.name = name; - } - - /** - * - * @return gateway worker - */ - public WorkerExperimentCatResource getWorker() { - return worker; - } - - /** - * - * @param worker gateway worker - */ - public void setWorker(WorkerExperimentCatResource worker) { - this.worker = worker; - } - - public String getGatewayId() { - return gatewayId; - } - - public void setGatewayId(String gatewayId) { - this.gatewayId = gatewayId; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public Timestamp getCreationTime() { - return creationTime; - } - - public void setCreationTime(Timestamp creationTime) { - this.creationTime = creationTime; - } - - /** - * - * @param experimentId experiment ID - * @return whether the experiment exist - */ - public boolean isExperimentExists(String experimentId) throws RegistryException{ - return isExists(ResourceType.EXPERIMENT, experimentId); - } - - /** - * - * @param experimentId experiment ID - * @return experiment resource - */ - public ExperimentExperimentCatResource createExperiment(String experimentId) throws RegistryException{ - ExperimentExperimentCatResource experimentResource = (ExperimentExperimentCatResource)create(ResourceType.EXPERIMENT); - experimentResource.setExpID(experimentId); - return experimentResource; - } - - /** - * - * @param experimentId experiment ID - * @return experiment resource - */ - public ExperimentExperimentCatResource getExperiment(String experimentId) throws RegistryException{ - return (ExperimentExperimentCatResource)get(ResourceType.EXPERIMENT,experimentId); - } - - /** - * - * @return list of experiments - */ - public List<ExperimentExperimentCatResource> getExperiments() throws RegistryException{ - List<ExperimentCatResource> list = get(ResourceType.EXPERIMENT); - List<ExperimentExperimentCatResource> result=new ArrayList<ExperimentExperimentCatResource>(); - for (ExperimentCatResource resource : list) { - result.add((ExperimentExperimentCatResource) resource); - } - return result; - } - - public List<ExperimentExperimentCatResource> getExperiments(int limit, int offset, Object orderByIdentifier, - ResultOrderType resultOrderType) throws RegistryException{ - List<ExperimentCatResource> list = get(ResourceType.EXPERIMENT, limit, offset, orderByIdentifier, resultOrderType); - List<ExperimentExperimentCatResource> result=new ArrayList<ExperimentExperimentCatResource>(); - for (ExperimentCatResource resource : list) { - result.add((ExperimentExperimentCatResource) resource); - } - return result; - } - - /** - * - * @param experimentId experiment ID - */ - public void removeExperiment(String experimentId) throws RegistryException{ - remove(ResourceType.EXPERIMENT, experimentId); - } - - public List<ProjectUserExperimentCatResource> getProjectUserList () throws RegistryException{ - List<ExperimentCatResource> resources = get(ResourceType.PROJECT_USER); - List<ProjectUserExperimentCatResource> projectUserResources = new ArrayList<ProjectUserExperimentCatResource>(); - if (resources != null && !resources.isEmpty()){ - for (ExperimentCatResource r : resources){ - projectUserResources.add((ProjectUserExperimentCatResource)r); - } - } - return projectUserResources; - } - -} http://git-wip-us.apache.org/repos/asf/airavata/blob/4045c094/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ProjectResource.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ProjectResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ProjectResource.java new file mode 100644 index 0000000..f67b1b4 --- /dev/null +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ProjectResource.java @@ -0,0 +1,508 @@ +/* + * + * 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.experiment.catalog.resources; + +import org.apache.airavata.registry.core.experiment.catalog.ExpCatResourceUtils; +import org.apache.airavata.registry.core.experiment.catalog.ExperimentCatResource; +import org.apache.airavata.registry.core.experiment.catalog.ResourceType; +import org.apache.airavata.registry.core.experiment.catalog.model.*; +import org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator; +import org.apache.airavata.registry.cpi.RegistryException; +import org.apache.airavata.registry.cpi.ResultOrderType; +import org.apache.airavata.registry.cpi.utils.Constants; +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 ProjectResource extends AbstractExpCatResource { + private final static Logger logger = LoggerFactory.getLogger(ProjectResource.class); + private String name; + private String id; + private String gatewayId; + private WorkerResource worker; + private String description; + private Timestamp creationTime; + + /** + * + */ + public ProjectResource() { + } + + /** + * + * @param type child resource type + * @return child resource + */ + public ExperimentCatResource create(ResourceType type) throws RegistryException { + if (type == ResourceType.EXPERIMENT) { + ExperimentResource experimentResource = new ExperimentResource(); + experimentResource.setGatewayId(gatewayId); + experimentResource.setExecutionUser(worker.getUser()); + experimentResource.setProjectId(id); + return experimentResource; + } else if (type == ResourceType.PROJECT_USER){ + ProjectUserResource pr = new ProjectUserResource(); + pr.setProjectId(id); + pr.setUserName(worker.getUser()); + return pr; + } + else { + logger.error("Unsupported resource type for project resource.", new IllegalArgumentException()); + throw new IllegalArgumentException("Unsupported resource type for project resource."); + } + } + + /** + * + * @param type child resource type + * @param name child resource name + */ + public void remove(ResourceType type, Object name) throws RegistryException{ + EntityManager em = null; + try { + em = ExpCatResourceUtils.getEntityManager(); + em.getTransaction().begin(); + if (type == ResourceType.EXPERIMENT) { + QueryGenerator generator = new QueryGenerator(EXPERIMENT); + generator.setParameter(ExperimentConstants.EXPERIMENT_ID, name); + Query q = generator.deleteQuery(em); + q.executeUpdate(); + } else if (type == ResourceType.PROJECT_USER) { + QueryGenerator generator = new QueryGenerator(PROJECT_USER); + generator.setParameter(ProjectUserConstants.USERNAME, name); + generator.setParameter(ProjectUserConstants.PROJECT_ID, this.id); + Query q = generator.deleteQuery(em); + q.executeUpdate(); + } else { + logger.error("Unsupported resource type for project resource.", new IllegalArgumentException()); + throw new IllegalArgumentException("Unsupported resource type for project resource."); + } + em.getTransaction().commit(); + em.close(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new RegistryException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()){ + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + /** + * + * @param type child resource type + * @param name child resource name + * @return child resource + */ + public ExperimentCatResource get(ResourceType type, Object name) throws RegistryException { + EntityManager em = null; + try { + if (type == ResourceType.EXPERIMENT) { + em = ExpCatResourceUtils.getEntityManager(); + em.getTransaction().begin(); + QueryGenerator generator = new QueryGenerator(EXPERIMENT); + generator.setParameter(ExperimentConstants.EXPERIMENT_ID, name); + Query q = generator.selectQuery(em); + Experiment experiment = (Experiment) q.getSingleResult(); + ExperimentResource experimentResource = (ExperimentResource) + Utils.getResource(ResourceType.EXPERIMENT, experiment); + em.getTransaction().commit(); + em.close(); + return experimentResource; + } else if (type == ResourceType.PROJECT_USER) { + em = ExpCatResourceUtils.getEntityManager(); + em.getTransaction().begin(); + QueryGenerator generator = new QueryGenerator(PROJECT_USER); + generator.setParameter(ProjectUserConstants.USERNAME, name); + generator.setParameter(ProjectUserConstants.PROJECT_ID, this.id); + Query q = generator.selectQuery(em); + ProjectUser prUser = (ProjectUser) q.getSingleResult(); + ExperimentResource experimentResource = (ExperimentResource) + Utils.getResource(ResourceType.PROJECT_USER, prUser); + em.getTransaction().commit(); + em.close(); + return experimentResource; + } else { + logger.error("Unsupported resource type for project resource.", new IllegalArgumentException()); + throw new IllegalArgumentException("Unsupported resource type for project resource."); + } + } catch (Exception e) { + throw new RegistryException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()){ + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + /** + * + * @param type child resource type + * @return list of child resources + */ + @Override + public List<ExperimentCatResource> get(ResourceType type) throws RegistryException{ + List<ExperimentCatResource> resourceList = new ArrayList<ExperimentCatResource>(); + EntityManager em = null; + try { + if (type == ResourceType.EXPERIMENT) { + em = ExpCatResourceUtils.getEntityManager(); + em.getTransaction().begin(); + QueryGenerator generator = new QueryGenerator(EXPERIMENT); + generator.setParameter(ExperimentConstants.PROJECT_ID, id); + Query q = generator.selectQuery(em); + List<?> results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + Experiment experiment = (Experiment) result; + ExperimentResource experimentResource = (ExperimentResource) + Utils.getResource(ResourceType.EXPERIMENT, experiment); + resourceList.add(experimentResource); + } + } + em.getTransaction().commit(); + em.close(); + } else if (type == ResourceType.PROJECT_USER) { + em = ExpCatResourceUtils.getEntityManager(); + em.getTransaction().begin(); + QueryGenerator generator = new QueryGenerator(PROJECT_USER); + generator.setParameter(ProjectUserConstants.PROJECT_ID, id); + Query q = generator.selectQuery(em); + List<?> results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + ProjectUser projectUser = (ProjectUser) result; + ProjectUserResource pr = (ProjectUserResource) + Utils.getResource(ResourceType.PROJECT_USER, projectUser); + resourceList.add(pr); + } + } + em.getTransaction().commit(); + em.close(); + } else { + logger.error("Unsupported resource type for project resource.", new IllegalArgumentException()); + throw new IllegalArgumentException("Unsupported resource type for project resource."); + } + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new RegistryException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()){ + em.getTransaction().rollback(); + } + em.close(); + } + } + return resourceList; + } + + /** + * Get results with pagination and ordering + * + * @param type + * @param limit + * @param offset + * @param orderByIdentifier + * @return + * @throws RegistryException + */ + public List<ExperimentCatResource> get(ResourceType type, int limit, int offset, Object orderByIdentifier, + ResultOrderType resultOrderType) throws RegistryException{ + List<ExperimentCatResource> resourceList = new ArrayList<ExperimentCatResource>(); + EntityManager em = null; + try { + if (type == ResourceType.EXPERIMENT) { + em = ExpCatResourceUtils.getEntityManager(); + em.getTransaction().begin(); + QueryGenerator generator = new QueryGenerator(EXPERIMENT); + generator.setParameter(ExperimentConstants.PROJECT_ID, id); + Query q; + //ordering - supported only by CREATION_TIME + if(orderByIdentifier != null && resultOrderType != null + && orderByIdentifier.equals(Constants.FieldConstants.ExperimentConstants.CREATION_TIME)) { + q = generator.selectQuery(em, ExperimentConstants.CREATION_TIME, resultOrderType); + }else{ + q = generator.selectQuery(em); + } + + //pagination + if(limit>0 && offset>=0){ + q.setFirstResult(offset); + q.setMaxResults(limit); + } + List<?> results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + Experiment experiment = (Experiment) result; + ExperimentResource experimentResource = (ExperimentResource) + Utils.getResource(ResourceType.EXPERIMENT, experiment); + resourceList.add(experimentResource); + } + } + em.getTransaction().commit(); + em.close(); + } else if (type == ResourceType.PROJECT_USER) { + em = ExpCatResourceUtils.getEntityManager(); + em.getTransaction().begin(); + QueryGenerator generator = new QueryGenerator(PROJECT_USER); + generator.setParameter(ProjectUserConstants.PROJECT_ID, id); + Query q; + //ordering - only supported only by CREATION_TIME + if(orderByIdentifier != null && resultOrderType != null + && orderByIdentifier.equals(Constants.FieldConstants.ProjectConstants.CREATION_TIME)) { + q = generator.selectQuery(em, ProjectConstants.CREATION_TIME, resultOrderType); + }else{ + q = generator.selectQuery(em); + } + + //pagination + if(limit>0 && offset>=0){ + q.setFirstResult(offset); + q.setMaxResults(limit); + } + List<?> results = q.getResultList(); + if (results.size() != 0) { + for (Object result : results) { + ProjectUser projectUser = (ProjectUser) result; + ProjectUserResource pr = (ProjectUserResource) + Utils.getResource(ResourceType.PROJECT_USER, projectUser); + resourceList.add(pr); + } + } + em.getTransaction().commit(); + em.close(); + } else { + logger.error("Unsupported resource type for project resource.", new IllegalArgumentException()); + throw new IllegalArgumentException("Unsupported resource type for project resource."); + } + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new RegistryException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()){ + em.getTransaction().rollback(); + } + em.close(); + } + } + return resourceList; + } + + /** + * save project to the database + */ + public void save() throws RegistryException{ + EntityManager em = null; + try { + em = ExpCatResourceUtils.getEntityManager(); + Project existingProject = em.find(Project.class, id); + em.close(); + + em = ExpCatResourceUtils.getEntityManager(); + em.getTransaction().begin(); + Project project = new Project(); + project.setProject_id(id); + project.setProject_name(name); + project.setGateway_id(gatewayId); + Users user = em.find(Users.class, worker.getUser()); + project.setUsers(user); + project.setUser_name(user.getUser_name()); + project.setDescription(description); + project.setCreationTime(creationTime); + + if (existingProject != null) { + existingProject.setProject_name(name); + existingProject.setGateway_id(gatewayId); + existingProject.setUsers(user); + existingProject.setUser_name(user.getUser_name()); + existingProject.setDescription(description); + existingProject.setCreationTime(creationTime); + project = em.merge(existingProject); + } else { + em.persist(project); + } + + em.getTransaction().commit(); + em.close(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new RegistryException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()){ + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + /** + * + * @return project name + */ + public String getName() { + return name; + } + + /** + * + * @param name project name + */ + public void setName(String name) { + this.name = name; + } + + /** + * + * @return gateway worker + */ + public WorkerResource getWorker() { + return worker; + } + + /** + * + * @param worker gateway worker + */ + public void setWorker(WorkerResource worker) { + this.worker = worker; + } + + public String getGatewayId() { + return gatewayId; + } + + public void setGatewayId(String gatewayId) { + this.gatewayId = gatewayId; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Timestamp getCreationTime() { + return creationTime; + } + + public void setCreationTime(Timestamp creationTime) { + this.creationTime = creationTime; + } + + /** + * + * @param experimentId experiment ID + * @return whether the experiment exist + */ + public boolean isExperimentExists(String experimentId) throws RegistryException{ + return isExists(ResourceType.EXPERIMENT, experimentId); + } + + /** + * + * @param experimentId experiment ID + * @return experiment resource + */ + public ExperimentResource createExperiment(String experimentId) throws RegistryException{ + ExperimentResource experimentResource = (ExperimentResource)create(ResourceType.EXPERIMENT); + experimentResource.setExpID(experimentId); + return experimentResource; + } + + /** + * + * @param experimentId experiment ID + * @return experiment resource + */ + public ExperimentResource getExperiment(String experimentId) throws RegistryException{ + return (ExperimentResource)get(ResourceType.EXPERIMENT,experimentId); + } + + /** + * + * @return list of experiments + */ + public List<ExperimentResource> getExperiments() throws RegistryException{ + List<ExperimentCatResource> list = get(ResourceType.EXPERIMENT); + List<ExperimentResource> result=new ArrayList<ExperimentResource>(); + for (ExperimentCatResource resource : list) { + result.add((ExperimentResource) resource); + } + return result; + } + + public List<ExperimentResource> getExperiments(int limit, int offset, Object orderByIdentifier, + ResultOrderType resultOrderType) throws RegistryException{ + List<ExperimentCatResource> list = get(ResourceType.EXPERIMENT, limit, offset, orderByIdentifier, resultOrderType); + List<ExperimentResource> result=new ArrayList<ExperimentResource>(); + for (ExperimentCatResource resource : list) { + result.add((ExperimentResource) resource); + } + return result; + } + + /** + * + * @param experimentId experiment ID + */ + public void removeExperiment(String experimentId) throws RegistryException{ + remove(ResourceType.EXPERIMENT, experimentId); + } + + public List<ProjectUserResource> getProjectUserList () throws RegistryException{ + List<ExperimentCatResource> resources = get(ResourceType.PROJECT_USER); + List<ProjectUserResource> projectUserResources = new ArrayList<ProjectUserResource>(); + if (resources != null && !resources.isEmpty()){ + for (ExperimentCatResource r : resources){ + projectUserResources.add((ProjectUserResource)r); + } + } + return projectUserResources; + } + +} http://git-wip-us.apache.org/repos/asf/airavata/blob/4045c094/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ProjectUserExperimentCatResource.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ProjectUserExperimentCatResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ProjectUserExperimentCatResource.java deleted file mode 100644 index fca844a..0000000 --- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ProjectUserExperimentCatResource.java +++ /dev/null @@ -1,123 +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.experiment.catalog.resources; - -import org.apache.airavata.registry.core.experiment.catalog.ExpCatResourceUtils; -import org.apache.airavata.registry.core.experiment.catalog.ExperimentCatResource; -import org.apache.airavata.registry.core.experiment.catalog.ResourceType; -import org.apache.airavata.registry.core.experiment.catalog.model.*; -import org.apache.airavata.registry.cpi.RegistryException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.persistence.EntityManager; -import java.util.List; - -public class ProjectUserExperimentCatResource extends AbstractExperimentCatResource { - private String projectId; - private String userName; - - private static final Logger logger = LoggerFactory.getLogger(ProjectUserExperimentCatResource.class); - - public String getProjectId() { - return projectId; - } - - public void setProjectId(String projectId) { - this.projectId = projectId; - } - - public String getUserName() { - return userName; - } - - public void setUserName(String userName) { - this.userName = userName; - } - - - public ExperimentCatResource create(ResourceType type) throws RegistryException { - logger.error("Unsupported resource type for project resource data resource.", new UnsupportedOperationException()); - throw new UnsupportedOperationException(); - } - - - public void remove(ResourceType type, Object name) throws RegistryException{ - logger.error("Unsupported resource type for project resource data resource.", new UnsupportedOperationException()); - throw new UnsupportedOperationException(); - } - - - public ExperimentCatResource get(ResourceType type, Object name) throws RegistryException{ - logger.error("Unsupported resource type for project resource data resource.", new UnsupportedOperationException()); - throw new UnsupportedOperationException(); - } - - - public List<ExperimentCatResource> get(ResourceType type) throws RegistryException{ - logger.error("Unsupported resource type for project resource data resource.", new UnsupportedOperationException()); - throw new UnsupportedOperationException(); - } - - - public void save() throws RegistryException{ - EntityManager em = null; - try { - em = ExpCatResourceUtils.getEntityManager(); - ProjectUser existingPrUser = em.find(ProjectUser.class, new ProjectUser_PK(projectId, userName)); - em.close(); - - em = ExpCatResourceUtils.getEntityManager(); - em.getTransaction().begin(); - ProjectUser prUser = new ProjectUser(); - prUser.setProjectID(projectId); - prUser.setUserName(userName); - Users user = em.find(Users.class, userName); - prUser.setUser(user); - Project project = em.find(Project.class, projectId); - prUser.setProject(project); - - if (existingPrUser != null) { - existingPrUser.setProjectID(projectId); - existingPrUser.setUserName(userName); - existingPrUser.setUser(user); - existingPrUser.setProject(project); - prUser = em.merge(existingPrUser); - } else { - em.persist(prUser); - } - - em.getTransaction().commit(); - em.close(); - } catch (Exception e) { - logger.error(e.getMessage(), e); - throw new RegistryException(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/experiment/catalog/resources/ProjectUserResource.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ProjectUserResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ProjectUserResource.java new file mode 100644 index 0000000..3063990 --- /dev/null +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/ProjectUserResource.java @@ -0,0 +1,123 @@ +/* + * + * 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.experiment.catalog.resources; + +import org.apache.airavata.registry.core.experiment.catalog.ExpCatResourceUtils; +import org.apache.airavata.registry.core.experiment.catalog.ExperimentCatResource; +import org.apache.airavata.registry.core.experiment.catalog.ResourceType; +import org.apache.airavata.registry.core.experiment.catalog.model.*; +import org.apache.airavata.registry.cpi.RegistryException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.persistence.EntityManager; +import java.util.List; + +public class ProjectUserResource extends AbstractExpCatResource { + private String projectId; + private String userName; + + private static final Logger logger = LoggerFactory.getLogger(ProjectUserResource.class); + + public String getProjectId() { + return projectId; + } + + public void setProjectId(String projectId) { + this.projectId = projectId; + } + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + + public ExperimentCatResource create(ResourceType type) throws RegistryException { + logger.error("Unsupported resource type for project resource data resource.", new UnsupportedOperationException()); + throw new UnsupportedOperationException(); + } + + + public void remove(ResourceType type, Object name) throws RegistryException{ + logger.error("Unsupported resource type for project resource data resource.", new UnsupportedOperationException()); + throw new UnsupportedOperationException(); + } + + + public ExperimentCatResource get(ResourceType type, Object name) throws RegistryException{ + logger.error("Unsupported resource type for project resource data resource.", new UnsupportedOperationException()); + throw new UnsupportedOperationException(); + } + + + public List<ExperimentCatResource> get(ResourceType type) throws RegistryException{ + logger.error("Unsupported resource type for project resource data resource.", new UnsupportedOperationException()); + throw new UnsupportedOperationException(); + } + + + public void save() throws RegistryException{ + EntityManager em = null; + try { + em = ExpCatResourceUtils.getEntityManager(); + ProjectUser existingPrUser = em.find(ProjectUser.class, new ProjectUser_PK(projectId, userName)); + em.close(); + + em = ExpCatResourceUtils.getEntityManager(); + em.getTransaction().begin(); + ProjectUser prUser = new ProjectUser(); + prUser.setProjectID(projectId); + prUser.setUserName(userName); + Users user = em.find(Users.class, userName); + prUser.setUser(user); + Project project = em.find(Project.class, projectId); + prUser.setProject(project); + + if (existingPrUser != null) { + existingPrUser.setProjectID(projectId); + existingPrUser.setUserName(userName); + existingPrUser.setUser(user); + existingPrUser.setProject(project); + prUser = em.merge(existingPrUser); + } else { + em.persist(prUser); + } + + em.getTransaction().commit(); + em.close(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new RegistryException(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/experiment/catalog/resources/QosParamExperimentCatResource.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/QosParamExperimentCatResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/QosParamExperimentCatResource.java deleted file mode 100644 index 5d78249..0000000 --- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/QosParamExperimentCatResource.java +++ /dev/null @@ -1,144 +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.experiment.catalog.resources; - -import org.apache.airavata.registry.core.experiment.catalog.ExpCatResourceUtils; -import org.apache.airavata.registry.core.experiment.catalog.ExperimentCatResource; -import org.apache.airavata.registry.core.experiment.catalog.ResourceType; -import org.apache.airavata.registry.core.experiment.catalog.model.QosParam; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.apache.airavata.registry.cpi.RegistryException; - -import javax.persistence.EntityManager; -import java.util.List; - -public class QosParamExperimentCatResource extends AbstractExperimentCatResource { - private static final Logger logger = LoggerFactory.getLogger(QosParamExperimentCatResource.class); - private int qosId; - private String experimentId; - private String taskId; - private String startExecutionAt; - private String executeBefore; - private int noOfRetries; - - public int getQosId() { - return qosId; - } - - public void setQosId(int qosId) { - this.qosId = qosId; - } - - public String getExperimentId() { - return experimentId; - } - - public void setExperimentId(String experimentId) { - this.experimentId = experimentId; - } - - public String getTaskId() { - return taskId; - } - - public void setTaskId(String taskId) { - this.taskId = taskId; - } - - public String getStartExecutionAt() { - return startExecutionAt; - } - - public void setStartExecutionAt(String startExecutionAt) { - this.startExecutionAt = startExecutionAt; - } - - public String getExecuteBefore() { - return executeBefore; - } - - public void setExecuteBefore(String executeBefore) { - this.executeBefore = executeBefore; - } - - public int getNoOfRetries() { - return noOfRetries; - } - - public void setNoOfRetries(int noOfRetries) { - this.noOfRetries = noOfRetries; - } - - - public ExperimentCatResource create(ResourceType type) throws RegistryException{ - logger.error("Unsupported resource type for qos params resource.", new UnsupportedOperationException()); - throw new UnsupportedOperationException(); - } - - - public void remove(ResourceType type, Object name) throws RegistryException{ - logger.error("Unsupported resource type for qos params resource.", new UnsupportedOperationException()); - throw new UnsupportedOperationException(); - } - - - public ExperimentCatResource get(ResourceType type, Object name) throws RegistryException{ - logger.error("Unsupported resource type for qos params resource.", new UnsupportedOperationException()); - throw new UnsupportedOperationException(); - } - - - public List<ExperimentCatResource> get(ResourceType type) throws RegistryException{ - logger.error("Unsupported resource type for qos params resource.", new UnsupportedOperationException()); - throw new UnsupportedOperationException(); - } - - - public void save() throws RegistryException{ - EntityManager em = null; - try { - em = ExpCatResourceUtils.getEntityManager(); - em.getTransaction().begin(); - QosParam qosParam = new QosParam(); - qosParam.setTaskId(taskId); - qosParam.setExpId(experimentId); - qosParam.setStartExecutionAt(startExecutionAt); - qosParam.setExecuteBefore(executeBefore); - qosParam.setNoOfRetries(noOfRetries); - em.persist(qosParam); - qosId = qosParam.getQosId(); - em.getTransaction().commit(); - em.close(); - } catch (Exception e) { - logger.error(e.getMessage(), e); - throw new RegistryException(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/experiment/catalog/resources/QosParamResource.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/QosParamResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/QosParamResource.java new file mode 100644 index 0000000..5cb45bf --- /dev/null +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/QosParamResource.java @@ -0,0 +1,144 @@ +/* + * + * 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.experiment.catalog.resources; + +import org.apache.airavata.registry.core.experiment.catalog.ExpCatResourceUtils; +import org.apache.airavata.registry.core.experiment.catalog.ExperimentCatResource; +import org.apache.airavata.registry.core.experiment.catalog.ResourceType; +import org.apache.airavata.registry.core.experiment.catalog.model.QosParam; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.apache.airavata.registry.cpi.RegistryException; + +import javax.persistence.EntityManager; +import java.util.List; + +public class QosParamResource extends AbstractExpCatResource { + private static final Logger logger = LoggerFactory.getLogger(QosParamResource.class); + private int qosId; + private String experimentId; + private String taskId; + private String startExecutionAt; + private String executeBefore; + private int noOfRetries; + + public int getQosId() { + return qosId; + } + + public void setQosId(int qosId) { + this.qosId = qosId; + } + + public String getExperimentId() { + return experimentId; + } + + public void setExperimentId(String experimentId) { + this.experimentId = experimentId; + } + + public String getTaskId() { + return taskId; + } + + public void setTaskId(String taskId) { + this.taskId = taskId; + } + + public String getStartExecutionAt() { + return startExecutionAt; + } + + public void setStartExecutionAt(String startExecutionAt) { + this.startExecutionAt = startExecutionAt; + } + + public String getExecuteBefore() { + return executeBefore; + } + + public void setExecuteBefore(String executeBefore) { + this.executeBefore = executeBefore; + } + + public int getNoOfRetries() { + return noOfRetries; + } + + public void setNoOfRetries(int noOfRetries) { + this.noOfRetries = noOfRetries; + } + + + public ExperimentCatResource create(ResourceType type) throws RegistryException{ + logger.error("Unsupported resource type for qos params resource.", new UnsupportedOperationException()); + throw new UnsupportedOperationException(); + } + + + public void remove(ResourceType type, Object name) throws RegistryException{ + logger.error("Unsupported resource type for qos params resource.", new UnsupportedOperationException()); + throw new UnsupportedOperationException(); + } + + + public ExperimentCatResource get(ResourceType type, Object name) throws RegistryException{ + logger.error("Unsupported resource type for qos params resource.", new UnsupportedOperationException()); + throw new UnsupportedOperationException(); + } + + + public List<ExperimentCatResource> get(ResourceType type) throws RegistryException{ + logger.error("Unsupported resource type for qos params resource.", new UnsupportedOperationException()); + throw new UnsupportedOperationException(); + } + + + public void save() throws RegistryException{ + EntityManager em = null; + try { + em = ExpCatResourceUtils.getEntityManager(); + em.getTransaction().begin(); + QosParam qosParam = new QosParam(); + qosParam.setTaskId(taskId); + qosParam.setExpId(experimentId); + qosParam.setStartExecutionAt(startExecutionAt); + qosParam.setExecuteBefore(executeBefore); + qosParam.setNoOfRetries(noOfRetries); + em.persist(qosParam); + qosId = qosParam.getQosId(); + em.getTransaction().commit(); + em.close(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new RegistryException(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/experiment/catalog/resources/StatusExperimentCatResource.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/StatusExperimentCatResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/StatusExperimentCatResource.java deleted file mode 100644 index 1ed225a..0000000 --- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/StatusExperimentCatResource.java +++ /dev/null @@ -1,181 +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.experiment.catalog.resources; - -import org.apache.airavata.registry.core.experiment.catalog.ExpCatResourceUtils; -import org.apache.airavata.registry.core.experiment.catalog.ExperimentCatResource; -import org.apache.airavata.registry.core.experiment.catalog.ResourceType; -import org.apache.airavata.registry.core.experiment.catalog.model.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.apache.airavata.registry.cpi.RegistryException; - -import javax.persistence.EntityManager; -import java.sql.Timestamp; -import java.util.List; - -public class StatusExperimentCatResource extends AbstractExperimentCatResource { - private static final Logger logger = LoggerFactory.getLogger(StatusExperimentCatResource.class); - private int statusId = 0; - private String experimentId; - private String nodeId; - private String transferId; - private String taskId; - private String jobId; - private String state; - private Timestamp statusUpdateTime; - private String statusType; - - public int getStatusId() { - return statusId; - } - - public void setStatusId(int statusId) { - this.statusId = statusId; - } - - public String getExperimentId() { - return experimentId; - } - - public void setExperimentId(String experimentId) { - this.experimentId = experimentId; - } - - public String getNodeId() { - return nodeId; - } - - public void setNodeId(String nodeId) { - this.nodeId = nodeId; - } - - public String getTransferId() { - return transferId; - } - - public void setTransferId(String transferId) { - this.transferId = transferId; - } - - public String getTaskId() { - return taskId; - } - - public void setTaskId(String taskId) { - this.taskId = taskId; - } - - public String getJobId() { - return jobId; - } - - public void setJobId(String jobId) { - this.jobId = jobId; - } - - public String getState() { - return state; - } - - public void setState(String state) { - this.state = state; - } - - public Timestamp getStatusUpdateTime() { - return statusUpdateTime; - } - - public void setStatusUpdateTime(Timestamp statusUpdateTime) { - this.statusUpdateTime = statusUpdateTime; - } - - public String getStatusType() { - return statusType; - } - - public void setStatusType(String statusType) { - this.statusType = statusType; - } - - - public ExperimentCatResource create(ResourceType type) throws RegistryException{ - logger.error("Unsupported resource type for status resource.", new UnsupportedOperationException()); - throw new UnsupportedOperationException(); - } - - - public void remove(ResourceType type, Object name) throws RegistryException{ - logger.error("Unsupported resource type for status resource.", new UnsupportedOperationException()); - throw new UnsupportedOperationException(); - } - - - public ExperimentCatResource get(ResourceType type, Object name) throws RegistryException{ - logger.error("Unsupported resource type for status resource.", new UnsupportedOperationException()); - throw new UnsupportedOperationException(); - } - - - public List<ExperimentCatResource> get(ResourceType type) throws RegistryException{ - logger.error("Unsupported resource type for status resource.", new UnsupportedOperationException()); - throw new UnsupportedOperationException(); - } - - - public void save() throws RegistryException{ - EntityManager em = null; - try { - em = ExpCatResourceUtils.getEntityManager(); - em.getTransaction().begin(); - Status status; - if (statusId != 0) { - status = em.find(Status.class, statusId); - status.setStatusId(statusId); - } else { - status = new Status(); - } - status.setExpId(experimentId); - status.setTaskId(taskId); - status.setNodeId(nodeId); - status.setTransferId(transferId); - status.setJobId(jobId); - status.setState(state); - status.setStatusUpdateTime(statusUpdateTime); - status.setStatusType(statusType); - em.persist(status); - statusId = status.getStatusId(); - em.getTransaction().commit(); - em.close(); - } catch (Exception e) { - logger.error(e.getMessage(), e); - throw new RegistryException(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/experiment/catalog/resources/StatusResource.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/StatusResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/StatusResource.java new file mode 100644 index 0000000..f5553cc --- /dev/null +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/StatusResource.java @@ -0,0 +1,181 @@ +/* + * + * 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.experiment.catalog.resources; + +import org.apache.airavata.registry.core.experiment.catalog.ExpCatResourceUtils; +import org.apache.airavata.registry.core.experiment.catalog.ExperimentCatResource; +import org.apache.airavata.registry.core.experiment.catalog.ResourceType; +import org.apache.airavata.registry.core.experiment.catalog.model.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.apache.airavata.registry.cpi.RegistryException; + +import javax.persistence.EntityManager; +import java.sql.Timestamp; +import java.util.List; + +public class StatusResource extends AbstractExpCatResource { + private static final Logger logger = LoggerFactory.getLogger(StatusResource.class); + private int statusId = 0; + private String experimentId; + private String nodeId; + private String transferId; + private String taskId; + private String jobId; + private String state; + private Timestamp statusUpdateTime; + private String statusType; + + public int getStatusId() { + return statusId; + } + + public void setStatusId(int statusId) { + this.statusId = statusId; + } + + public String getExperimentId() { + return experimentId; + } + + public void setExperimentId(String experimentId) { + this.experimentId = experimentId; + } + + public String getNodeId() { + return nodeId; + } + + public void setNodeId(String nodeId) { + this.nodeId = nodeId; + } + + public String getTransferId() { + return transferId; + } + + public void setTransferId(String transferId) { + this.transferId = transferId; + } + + public String getTaskId() { + return taskId; + } + + public void setTaskId(String taskId) { + this.taskId = taskId; + } + + public String getJobId() { + return jobId; + } + + public void setJobId(String jobId) { + this.jobId = jobId; + } + + public String getState() { + return state; + } + + public void setState(String state) { + this.state = state; + } + + public Timestamp getStatusUpdateTime() { + return statusUpdateTime; + } + + public void setStatusUpdateTime(Timestamp statusUpdateTime) { + this.statusUpdateTime = statusUpdateTime; + } + + public String getStatusType() { + return statusType; + } + + public void setStatusType(String statusType) { + this.statusType = statusType; + } + + + public ExperimentCatResource create(ResourceType type) throws RegistryException{ + logger.error("Unsupported resource type for status resource.", new UnsupportedOperationException()); + throw new UnsupportedOperationException(); + } + + + public void remove(ResourceType type, Object name) throws RegistryException{ + logger.error("Unsupported resource type for status resource.", new UnsupportedOperationException()); + throw new UnsupportedOperationException(); + } + + + public ExperimentCatResource get(ResourceType type, Object name) throws RegistryException{ + logger.error("Unsupported resource type for status resource.", new UnsupportedOperationException()); + throw new UnsupportedOperationException(); + } + + + public List<ExperimentCatResource> get(ResourceType type) throws RegistryException{ + logger.error("Unsupported resource type for status resource.", new UnsupportedOperationException()); + throw new UnsupportedOperationException(); + } + + + public void save() throws RegistryException{ + EntityManager em = null; + try { + em = ExpCatResourceUtils.getEntityManager(); + em.getTransaction().begin(); + Status status; + if (statusId != 0) { + status = em.find(Status.class, statusId); + status.setStatusId(statusId); + } else { + status = new Status(); + } + status.setExpId(experimentId); + status.setTaskId(taskId); + status.setNodeId(nodeId); + status.setTransferId(transferId); + status.setJobId(jobId); + status.setState(state); + status.setStatusUpdateTime(statusUpdateTime); + status.setStatusType(statusType); + em.persist(status); + statusId = status.getStatusId(); + em.getTransaction().commit(); + em.close(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new RegistryException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()){ + em.getTransaction().rollback(); + } + em.close(); + } + } + } +}
