/** * * 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.ProcessOutput; import org.apache.airavata.registry.core.experiment.catalog.model.ProcessOutputPK; 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 ProcessOutputResource extends AbstractExpCatResource { private static final Logger logger = LoggerFactory.getLogger(ProcessOutputResource.class); private String processId; private String outputName; private String outputValue; private String dataType; private String applicationArgument; private boolean isRequired; private boolean requiredToAddedToCmd; private boolean dataMovement; private String location; private String searchQuery; private boolean outputStreaming; private String storageResourceId; public String getProcessId() { return processId; } public void setProcessId(String processId) { this.processId = processId; } public String getOutputName() { return outputName; } public void setOutputName(String outputName) { this.outputName = outputName; } public String getOutputValue() { return outputValue; } public void setOutputValue(String outputValue) { this.outputValue = outputValue; } public String getDataType() { return dataType; } public void setDataType(String dataType) { this.dataType = dataType; } public String getApplicationArgument() { return applicationArgument; } public void setApplicationArgument(String applicationArgument) { this.applicationArgument = applicationArgument; } public boolean getIsRequired() { return isRequired; } public void setIsRequired(boolean isRequired) { this.isRequired = isRequired; } public boolean getRequiredToAddedToCmd() { return requiredToAddedToCmd; } public void setRequiredToAddedToCmd(boolean requiredToAddedToCmd) { this.requiredToAddedToCmd = requiredToAddedToCmd; } public boolean getDataMovement() { return dataMovement; } public void setDataMovement(boolean dataMovement) { this.dataMovement = dataMovement; } public String getLocation() { return location; } public void setLocation(String location) { this.location = location; } public String getSearchQuery() { return searchQuery; } public void setSearchQuery(String searchQuery) { this.searchQuery = searchQuery; } public boolean isOutputStreaming() { return outputStreaming; } public void setOutputStreaming(boolean outputStreaming) { this.outputStreaming = outputStreaming; } public String getStorageResourceId() { return storageResourceId; } public void setStorageResourceId(String storageResourceId) { this.storageResourceId = storageResourceId; } public ExperimentCatResource create(ResourceType type) throws RegistryException { logger.error("Unsupported resource type for process output data resource.", new UnsupportedOperationException()); throw new UnsupportedOperationException(); } public void remove(ResourceType type, Object name) throws RegistryException { logger.error("Unsupported resource type for process output data resource.", new UnsupportedOperationException()); throw new UnsupportedOperationException(); } public ExperimentCatResource get(ResourceType type, Object name) throws RegistryException{ logger.error("Unsupported resource type for process output data resource.", new UnsupportedOperationException()); throw new UnsupportedOperationException(); } public List<ExperimentCatResource> get(ResourceType type) throws RegistryException{ logger.error("Unsupported resource type for process output data resource.", new UnsupportedOperationException()); throw new UnsupportedOperationException(); } public void save() throws RegistryException{ EntityManager em = null; try { if (processId == null || outputName == null) { throw new RegistryException("Primary keys must have not null values. ProcessId:" + processId + " OutputName:" + outputName); } em = ExpCatResourceUtils.getEntityManager(); ProcessOutput processOutput; ProcessOutputPK processOutputPK = new ProcessOutputPK(); processOutputPK.setProcessId(processId); processOutputPK.setOutputName(outputName); ProcessOutput existingProcessOutput = em.find(ProcessOutput.class, processOutputPK); if (em.isOpen()) { if (em.getTransaction().isActive()){ em.getTransaction().rollback(); } em.close(); } em = ExpCatResourceUtils.getEntityManager(); em.getTransaction().begin(); if(existingProcessOutput == null){ processOutput = new ProcessOutput(); }else { processOutput = existingProcessOutput; } processOutput.setProcessId(processId); processOutput.setOutputName(outputName); processOutput.setOutputValue(outputValue); processOutput.setDataType(dataType); processOutput.setApplicationArgument(applicationArgument); processOutput.setIsRequired(isRequired); processOutput.setRequiredToAddedToCmd(requiredToAddedToCmd); processOutput.setDataMovement(dataMovement); processOutput.setLocation(location); processOutput.setSearchQuery(searchQuery); processOutput.setOutputStreaming(outputStreaming); processOutput.setStorageResourceId(storageResourceId); if (existingProcessOutput == null){ em.persist(processOutput); }else { em.merge(processOutput); } em.getTransaction().commit(); if (em.isOpen()) { if (em.getTransaction().isActive()){ em.getTransaction().rollback(); } 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(); } } } }