use of com.emc.metalnx.core.domain.exceptions.DataGridException in project metalnx-web by irods-contrib.
the class CollectionServiceImpl method createCollection.
@Override
public boolean createCollection(DataGridCollectionAndDataObject collection) throws DataGridException {
logger.info("createCollection()");
boolean collCreated;
try {
IRODSFileSystemAO irodsFileSystemAO = irodsServices.getIRODSFileSystemAO();
IRODSFileFactory irodsFileFactory = irodsServices.getIRODSFileFactory();
IRODSFile newFile = irodsFileFactory.instanceIRODSFile(collection.getParentPath(), collection.getName());
irodsFileSystemAO.mkdir(newFile, false);
// Updating inheritance option on the collection, if needed
CollectionAO collectionAO = irodsServices.getCollectionAO();
String zoneName = irodsFileSystemAO.getIRODSServerProperties().getRodsZone();
// enable inheritance for this collection
if (collection.isInheritanceOption()) {
collectionAO.setAccessPermissionInherit(zoneName, collection.getPath(), false);
} else // disable inheritance for this collection
if ("own".equals(getPermissionsForPath(collection.getParentPath()))) {
collectionAO.setAccessPermissionToNotInherit(zoneName, collection.getPath(), false);
}
collCreated = true;
} catch (JargonException e) {
logger.debug("Could not create a collection in the data grid: {}", e.getMessage());
throw new DataGridException(e.getMessage());
}
return collCreated;
}
use of com.emc.metalnx.core.domain.exceptions.DataGridException in project metalnx-web by irods-contrib.
the class GroupServiceImpl method updateWritePermissions.
@Override
public boolean updateWritePermissions(DataGridGroup group, Map<String, Boolean> addCollectionsToWrite, Map<String, Boolean> removeCollectionsToWrite) throws DataGridConnectionRefusedException {
DataObjectAO dataObjectAO = irodsServices.getDataObjectAO();
CollectionAO collectionAO = irodsServices.getCollectionAO();
try {
for (String path : addCollectionsToWrite.keySet()) {
if (collectionService.isCollection(path)) {
collectionAO.setAccessPermissionWriteAsAdmin(group.getAdditionalInfo(), path, group.getGroupname(), addCollectionsToWrite.get(path));
} else {
dataObjectAO.setAccessPermissionWriteInAdminMode(group.getAdditionalInfo(), path, group.getGroupname());
}
}
for (String path : removeCollectionsToWrite.keySet()) {
if (collectionService.isCollection(path)) {
collectionAO.removeAccessPermissionForUserAsAdmin(group.getAdditionalInfo(), path, group.getGroupname(), removeCollectionsToWrite.get(path));
} else {
dataObjectAO.removeAccessPermissionsForUserInAdminMode(group.getAdditionalInfo(), path, group.getGroupname());
}
}
return true;
} catch (JargonException | DataGridException e) {
logger.error("Could not set read permission:", e);
}
return false;
}
use of com.emc.metalnx.core.domain.exceptions.DataGridException in project metalnx-web by irods-contrib.
the class PermissionsServiceImpl method resolveMostPermissiveAccessForUser.
@Override
public void resolveMostPermissiveAccessForUser(DataGridCollectionAndDataObject obj, DataGridUser user) throws DataGridException {
if (obj == null || user == null)
return;
List<UserGroup> userGroups;
List<UserFilePermission> acl;
try {
userGroups = irodsServices.getGroupAO().findUserGroupsForUser(user.getUsername());
acl = getFilePermissionListForObject(obj.getPath());
} catch (JargonException e) {
throw new DataGridException();
}
// Building set containing group names for current user
Set<String> userGroupsSet = new HashSet<>();
for (UserGroup g : userGroups) {
userGroupsSet.add(g.getUserGroupName());
}
// Instantiating comparison matrix for permissions
List<String> permissions = new ArrayList<>();
permissions.add("NONE");
permissions.add("READ");
permissions.add("WRITE");
permissions.add("OWN");
String resultingPermission = "NONE";
for (UserFilePermission perm : acl) {
String permUserName = perm.getUserName();
// Checking if current permission is related to logged user
if (permUserName.compareTo(user.getUsername()) == 0 || userGroupsSet.contains(permUserName)) {
String permissionName = perm.getFilePermissionEnum().name();
int userOrGroupPerm = permissions.indexOf(permissionName);
int currentPermission = permissions.indexOf(resultingPermission);
if (userOrGroupPerm > currentPermission) {
resultingPermission = permissionName;
}
}
if (resultingPermission.compareToIgnoreCase("OWN") == 0) {
break;
}
}
obj.setMostPermissiveAccessForCurrentUser(resultingPermission.toLowerCase());
}
use of com.emc.metalnx.core.domain.exceptions.DataGridException 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());
}
}
}
Aggregations