use of org.irods.jargon.core.exception.JargonException in project metalnx-web by irods-contrib.
the class RuleDeploymentServiceImpl method deployRule.
@Override
public void deployRule(MultipartFile file) throws DataGridException, JargonException {
logger.info("Deploying rule");
if (file == null) {
logger.error("File could not be sent to the data grid. Rule file is null.");
throw new DataGridException("Rule file is null.");
}
if (!ruleCacheExists()) {
logger.info("Rule cache does not exist. Creating one.");
createRuleCache();
}
InputStream inputStream;
try {
inputStream = file.getInputStream();
} catch (IOException e) {
logger.error("Could not get input stream from rule file: ", e.getMessage());
throw new DataGridException("Could not get input stream from ruleFile.");
}
// Getting DataObjectAO in order to create the new rule file
IRODSFileFactory irodsFileFactory = irodsServices.getIRODSFileFactory();
Stream2StreamAO stream2StreamA0 = irodsServices.getStream2StreamAO();
IRODSFile targetFile = null;
try {
String ruleCacheDirPath = getRuleCachePath();
String ruleName = file.getOriginalFilename().isEmpty() ? file.getName() : file.getOriginalFilename();
targetFile = irodsFileFactory.instanceIRODSFile(ruleCacheDirPath, ruleName);
stream2StreamA0.transferStreamToFileUsingIOStreams(inputStream, (File) targetFile, 0, BUFFER_SIZE);
String resourceName = irodsServices.getDefaultStorageResource();
Resource resc = irodsServices.getResourceAO().findByName(resourceName);
String vaultPath = resc.getVaultPath();
String host = resc.getLocation();
String ruleVaultPath = String.format("%s/%s/%s", vaultPath, RULE_CACHE_DIR_NAME, ruleName);
String ruleNameWithoutExtension = FilenameUtils.removeExtension(ruleName);
ruleService.execDeploymentRule(host, ruleNameWithoutExtension, ruleVaultPath);
} catch (JargonException e) {
if (targetFile != null)
fos.deleteDataObject(targetFile.getPath(), true);
logger.error("Upload stream failed from Metalnx to the data grid. {}", e.getMessage());
throw new DataGridException("Upload failed. Resource(s) might be full.");
} finally {
try {
// Closing streams opened
inputStream.close();
} catch (IOException e) {
logger.error("Could close stream: ", e.getMessage());
}
}
}
use of org.irods.jargon.core.exception.JargonException in project metalnx-web by irods-contrib.
the class SpecQueryServiceImpl method searchByMetadata.
@Override
public SpecificQueryResultSet searchByMetadata(List<DataGridMetadataSearch> metadataSearch, String zone, boolean searchAgainstColls, DataGridPageContext pageContext, int offset, int limit) throws DataGridConnectionRefusedException, JargonException {
SpecificQueryAO specificQueryAO = null;
SpecificQuery specQuery = null;
SpecificQueryResultSet queryResultSet = null;
String userSQLAlias = "metalnxUserQuery_" + System.currentTimeMillis();
try {
specificQueryAO = adminServices.getSpecificQueryAO();
ClientHints clientHints = this.irodsServices.getEnvironmentalInfoAO().retrieveClientHints(false);
SpecificQueryProvider provider = specificQueryProviderFactory.instance(clientHints.whatTypeOfIcatIsIt());
String query = provider.buildSpecificQueryForMetadataSearch(metadataSearch, zone, searchAgainstColls);
// Creating Specific Query instance
SpecificQueryDefinition queryDef = new SpecificQueryDefinition();
queryDef.setAlias(userSQLAlias);
queryDef.setSql(query);
// Creating spec query on iRODS
specificQueryAO.addSpecificQuery(queryDef);
specQuery = SpecificQuery.instanceWithNoArguments(userSQLAlias, 0, zone);
logger.info("Specific query: {}", query.toString());
queryResultSet = specificQueryAO.executeSpecificQueryUsingAlias(specQuery, 99999, 0);
} catch (JargonException e) {
logger.error("Could not get specific query: ", e);
throw e;
} catch (JargonQueryException e) {
logger.error("Could not get specific query: ", e);
throw new JargonException(e);
} catch (UnsupportedDataGridFeatureException e) {
logger.error("Could not get specific query: ", e);
throw new JargonException(e);
} finally {
try {
// after running the user specific query, we need to remove from the database
specificQueryAO.removeSpecificQueryByAlias(userSQLAlias);
} catch (JargonException e) {
logger.error("Could not remove specific query {}: ", userSQLAlias, e.getMessage());
}
}
return queryResultSet;
}
use of org.irods.jargon.core.exception.JargonException in project metalnx-web by irods-contrib.
the class SpecQueryServiceImpl method deleteSpecQueryByAlias.
@Override
public void deleteSpecQueryByAlias(String specQueryAlias) throws DataGridConnectionRefusedException {
SpecificQueryAO specificQueryAO = null;
try {
specificQueryAO = adminServices.getSpecificQueryAO();
specificQueryAO.removeSpecificQueryByAlias(specQueryAlias);
} catch (JargonException e) {
logger.error("Could not get specific query: ", e.getMessage());
}
}
use of org.irods.jargon.core.exception.JargonException in project metalnx-web by irods-contrib.
the class UserServiceImpl method updateWritePermissions.
@Override
public boolean updateWritePermissions(DataGridUser user, Map<String, Boolean> addCollectionsToWrite, Map<String, Boolean> removeCollectionsToWrite) throws DataGridConnectionRefusedException {
CollectionAO collectionAO = null;
DataObjectAO dataObjectAO = null;
IRODSFile irodsFile = null;
IRODSFileFactory irodsFileFactory = null;
boolean writePermissionsUpdated = false;
try {
collectionAO = irodsServices.getCollectionAO();
dataObjectAO = irodsServices.getDataObjectAO();
irodsFileFactory = irodsServices.getIRODSFileFactory();
for (String path : addCollectionsToWrite.keySet()) {
irodsFile = irodsFileFactory.instanceIRODSFile(path);
if (irodsFile.isDirectory()) {
collectionAO.setAccessPermissionWriteAsAdmin(user.getAdditionalInfo(), path, user.getUsername(), addCollectionsToWrite.get(path));
} else {
dataObjectAO.setAccessPermissionWriteInAdminMode(user.getAdditionalInfo(), path, user.getUsername());
}
}
removeAccessPermissionForUserAsAdmin(user, removeCollectionsToWrite);
writePermissionsUpdated = true;
} catch (JargonException e) {
logger.error("Could not set write permission:", e);
}
return writePermissionsUpdated;
}
use of org.irods.jargon.core.exception.JargonException in project metalnx-web by irods-contrib.
the class UserServiceImpl method modifyUser.
@Override
public boolean modifyUser(DataGridUser modifyUser) throws DataGridConnectionRefusedException {
UserAO userAO = irodsServices.getUserAO();
try {
User iRodsUser = userAO.findById(String.valueOf(modifyUser.getDataGridId()));
boolean iRodsFieldsModified = false;
// check which fields were modified (iRODS)
if (iRodsUser.getZone().compareTo(modifyUser.getAdditionalInfo()) != 0) {
iRodsUser.setZone(modifyUser.getAdditionalInfo());
iRodsFieldsModified = true;
}
if (!iRodsUser.getUserType().getTextValue().equals(modifyUser.getUserType())) {
if (modifyUser.getUserType().compareTo(UserTypeEnum.RODS_ADMIN.getTextValue()) == 0) {
iRodsUser.setUserType(UserTypeEnum.RODS_ADMIN);
} else {
iRodsUser.setUserType(UserTypeEnum.RODS_USER);
}
iRodsFieldsModified = true;
}
// updating user in iRODS if any field was modified
if (iRodsFieldsModified) {
userAO.updateUser(iRodsUser);
}
DataGridUser applicationUser = userDao.findByUsernameAndZone(modifyUser.getUsername(), modifyUser.getAdditionalInfo());
// check which fields were modified (our database)
if (applicationUser.getAdditionalInfo() == null || applicationUser.getAdditionalInfo().compareTo(modifyUser.getAdditionalInfo()) != 0) {
applicationUser.setAdditionalInfo(modifyUser.getAdditionalInfo());
}
if (applicationUser.getFirstName() == null || applicationUser.getFirstName().compareTo(modifyUser.getFirstName()) != 0) {
applicationUser.setFirstName(modifyUser.getFirstName());
}
if (applicationUser.getLastName() == null || applicationUser.getLastName().compareTo(modifyUser.getLastName()) != 0) {
applicationUser.setLastName(modifyUser.getLastName());
}
if (applicationUser.getEmail() == null || applicationUser.getEmail().compareTo(modifyUser.getEmail()) != 0) {
applicationUser.setEmail(modifyUser.getEmail());
}
if (applicationUser.getCompany() == null || applicationUser.getCompany().compareTo(modifyUser.getCompany()) != 0) {
applicationUser.setCompany(modifyUser.getCompany());
}
if (applicationUser.getDepartment() == null || applicationUser.getDepartment().compareTo(modifyUser.getDepartment()) != 0) {
applicationUser.setDepartment(modifyUser.getDepartment());
}
applicationUser.setUserProfile(modifyUser.getUserProfile());
applicationUser.setLocale(modifyUser.getLocale());
applicationUser.setOrganizationalRole(modifyUser.getOrganizationalRole());
applicationUser.setUserType(modifyUser.getUserType());
applicationUser.setForceFileOverwriting(modifyUser.isForceFileOverwriting());
applicationUser.setAdvanceView(modifyUser.isAdvancedView());
userDao.merge(applicationUser);
// Changing password if a new password is set
String newPassword = modifyUser.getPassword();
if (newPassword != null && !newPassword.isEmpty()) {
userAO.changeAUserPasswordByAnAdmin(modifyUser.getUsername(), newPassword);
}
return true;
} catch (JargonException e) {
e.printStackTrace();
}
return false;
}
Aggregations