use of org.apache.airavata.registry.core.app.catalog.model.UserStoragePreferencePK in project airavata by apache.
the class UserStoragePreferenceResource method isExists.
@Override
public boolean isExists(Object identifier) throws AppCatalogException {
CompositeIdentifier ids;
if (identifier instanceof CompositeIdentifier) {
ids = (CompositeIdentifier) identifier;
} else {
logger.error("Identifier should be a instance of CompositeIdentifier class");
throw new AppCatalogException("Identifier should be a instance of CompositeIdentifier class");
}
EntityManager em = null;
try {
em = AppCatalogJPAUtils.getEntityManager();
String storageResourceId = ids.getTopLevelIdentifier().toString();
String userId = ids.getSecondLevelIdentifier().toString();
String gatewayID = ids.getThirdLevelIdentifier().toString();
UserStoragePreference existingPreference = em.find(UserStoragePreference.class, new UserStoragePreferencePK(userId, gatewayID, storageResourceId));
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
return existingPreference != null;
} 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.UserStoragePreferencePK in project airavata by apache.
the class UserStoragePreferenceResource method save.
@Override
public void save() throws AppCatalogException {
EntityManager em = null;
try {
em = AppCatalogJPAUtils.getEntityManager();
UserStoragePreference existingPreference = em.find(UserStoragePreference.class, new UserStoragePreferencePK(userId, gatewayID, storageResourceId));
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
em = AppCatalogJPAUtils.getEntityManager();
em.getTransaction().begin();
UserResourceProfile userResourceProfile = em.find(UserResourceProfile.class, new UserResourceProfilePK(userId, gatewayID));
if (existingPreference != null) {
existingPreference.setStorageResourceId(storageResourceId);
existingPreference.setUserId(userId);
existingPreference.setGatewayID(gatewayID);
existingPreference.setUserResourceProfile(userResourceProfile);
existingPreference.setLoginUserName(loginUserName);
existingPreference.setComputeResourceCSToken(resourceCSToken);
existingPreference.setFsRootLocation(fsRootLocation);
em.merge(existingPreference);
} else {
UserStoragePreference resourcePreference = new UserStoragePreference();
resourcePreference.setStorageResourceId(storageResourceId);
resourcePreference.setGatewayID(gatewayID);
resourcePreference.setUserId(userId);
resourcePreference.setUserResourceProfile(userResourceProfile);
resourcePreference.setLoginUserName(loginUserName);
resourcePreference.setComputeResourceCSToken(resourceCSToken);
resourcePreference.setFsRootLocation(fsRootLocation);
em.persist(resourcePreference);
}
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();
}
}
}
Aggregations