Search in sources :

Example 1 with ProcessInputPK

use of org.apache.airavata.registry.core.experiment.catalog.model.ProcessInputPK in project airavata by apache.

the class ProcessInputResource method save.

public void save() throws RegistryException {
    EntityManager em = null;
    try {
        if (processId == null) {
            throw new RegistryException("Does not have the process id");
        }
        em = ExpCatResourceUtils.getEntityManager();
        ProcessInput processInput;
        ProcessInputPK processInputPk = new ProcessInputPK();
        processInputPk.setProcessId(processId);
        processInputPk.setInputName(inputName);
        ProcessInput existingProInput = em.find(ProcessInput.class, processInputPk);
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        em = ExpCatResourceUtils.getEntityManager();
        em.getTransaction().begin();
        if (existingProInput == null) {
            processInput = new ProcessInput();
        } else {
            processInput = existingProInput;
        }
        processInput.setProcessId(processId);
        processInput.setInputName(inputName);
        processInput.setInputValue(inputValue);
        processInput.setDataType(dataType);
        processInput.setApplicationArgument(applicationArgument);
        processInput.setStandardInput(standardInput);
        processInput.setUserFriendlyDescription(userFriendlyDescription);
        processInput.setMetadata(metadata);
        processInput.setInputOrder(inputOrder);
        processInput.setIsRequired(isRequired);
        processInput.setRequiredToAddedToCmd(requiredToAddedToCmd);
        processInput.setDataStaged(dataStaged);
        processInput.setStorageResourceId(storageResourceId);
        processInput.setIsReadOnly(isReadOnly);
        if (existingProInput == null) {
            em.persist(processInput);
        } else {
            em.merge(processInput);
        }
        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();
        }
    }
}
Also used : EntityManager(javax.persistence.EntityManager) ProcessInput(org.apache.airavata.registry.core.experiment.catalog.model.ProcessInput) RegistryException(org.apache.airavata.registry.cpi.RegistryException) ProcessInputPK(org.apache.airavata.registry.core.experiment.catalog.model.ProcessInputPK) RegistryException(org.apache.airavata.registry.cpi.RegistryException)

Aggregations

EntityManager (javax.persistence.EntityManager)1 ProcessInput (org.apache.airavata.registry.core.experiment.catalog.model.ProcessInput)1 ProcessInputPK (org.apache.airavata.registry.core.experiment.catalog.model.ProcessInputPK)1 RegistryException (org.apache.airavata.registry.cpi.RegistryException)1