use of org.apache.airavata.registry.core.app.catalog.model.StorageResource in project airavata by apache.
the class StorageResourceResource method save.
@Override
public void save() throws AppCatalogException {
EntityManager em = null;
try {
em = AppCatalogJPAUtils.getEntityManager();
StorageResource existingStorageResource = em.find(StorageResource.class, storageResourceId);
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
StorageResource storageResource;
em = AppCatalogJPAUtils.getEntityManager();
em.getTransaction().begin();
if (existingStorageResource == null) {
storageResource = new StorageResource();
storageResource.setCreationTime(AiravataUtils.getCurrentTimestamp());
} else {
storageResource = existingStorageResource;
storageResource.setUpdateTime(AiravataUtils.getCurrentTimestamp());
}
storageResource.setDescription(getResourceDescription());
storageResource.setStorageResourceId(getStorageResourceId());
storageResource.setHostName(getHostName());
storageResource.setEnabled(isEnabled());
if (existingStorageResource == null) {
em.persist(storageResource);
} else {
em.merge(storageResource);
}
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 AppCatalogException(e);
} finally {
if (em != null && em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
}
}
use of org.apache.airavata.registry.core.app.catalog.model.StorageResource in project airavata by apache.
the class StorageResourceResource method getIds.
@Override
public List<String> getIds(String fieldName, Object value) throws AppCatalogException {
List<String> storageResourceResourceIDs = new ArrayList<String>();
EntityManager em = null;
try {
em = AppCatalogJPAUtils.getEntityManager();
em.getTransaction().begin();
AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(STORAGE_RESOURCE);
Query q;
if ((fieldName.equals(StorageResourceConstants.RESOURCE_DESCRIPTION)) || (fieldName.equals(StorageResourceConstants.RESOURCE_ID)) || (fieldName.equals(StorageResourceConstants.HOST_NAME))) {
generator.setParameter(fieldName, value);
q = generator.selectQuery(em);
List<?> results = q.getResultList();
for (Object result : results) {
StorageResource storageResource = (StorageResource) result;
StorageResourceResource storageResourceResource = (StorageResourceResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.STORAGE_RESOURCE, storageResource);
storageResourceResourceIDs.add(storageResourceResource.getStorageResourceId());
}
} else {
em.getTransaction().commit();
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
logger.error("Unsupported field name for Storage Resource Resource.", new IllegalArgumentException());
throw new IllegalArgumentException("Unsupported field name for Storage Resource Resource.");
}
em.getTransaction().commit();
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
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 storageResourceResourceIDs;
}
Aggregations