use of org.irods.jargon.core.exception.JargonException in project metalnx-web by irods-contrib.
the class CollectionController method index.
/**
* Legacy index method used in other controllers, eventually factor out TODO:
* factor this out and make explicit via urls etc - mcc
*
* @param model
* @param request
* @return
*/
public String index(final Model model, final HttpServletRequest request) {
logger.info("index()");
try {
sourcePaths.clear();
if (!cs.isPathValid(currentPath)) {
currentPath = cs.getHomeDirectyForCurrentUser();
parentPath = currentPath;
} else if (cs.isDataObject(currentPath)) {
parentPath = currentPath.substring(0, currentPath.lastIndexOf("/") + 1);
}
DataGridUser loggedUser = loggedUserUtils.getLoggedDataGridUser();
String uiMode = (String) request.getSession().getAttribute("uiMode");
if (uiMode == null || uiMode.isEmpty()) {
boolean isUserAdmin = loggedUser != null && loggedUser.isAdmin();
uiMode = isUserAdmin ? UI_ADMIN_MODE : UI_USER_MODE;
}
if (uiMode.equals(UI_USER_MODE)) {
model.addAttribute("homePath", cs.getHomeDirectyForCurrentUser());
model.addAttribute("publicPath", cs.getHomeDirectyForPublic());
}
model.addAttribute("cameFromFilePropertiesSearch", cameFromFilePropertiesSearch);
model.addAttribute("cameFromMetadataSearch", cameFromMetadataSearch);
model.addAttribute("cameFromBookmarks", cameFromBookmarks);
model.addAttribute("uiMode", uiMode);
model.addAttribute("currentPath", currentPath);
model.addAttribute("encodedCurrentPath", URLEncoder.encode(currentPath));
model.addAttribute("parentPath", parentPath);
model.addAttribute("resources", resourceService.findAll());
model.addAttribute("overwriteFileOption", loggedUser != null && loggedUser.isForceFileOverwriting());
cameFromMetadataSearch = false;
cameFromFilePropertiesSearch = false;
cameFromBookmarks = false;
} catch (DataGridException | JargonException e) {
logger.error("Could not respond to request for collections: {}", e);
model.addAttribute("unexpectedError", true);
}
logger.info("returning to collections/collectionManagement");
return "collections/collectionManagement";
}
use of org.irods.jargon.core.exception.JargonException in project metalnx-web by irods-contrib.
the class UserController method addUser.
/**
* Controller method that executes action 'create user'
*
* @param user
* @return the name of the template to render
* @throws DataGridConnectionRefusedException
*/
@RequestMapping(value = "add/action/", method = RequestMethod.POST)
public String addUser(@ModelAttribute UserForm user, HttpServletRequest request, RedirectAttributes redirectAttributes) throws DataGridConnectionRefusedException {
logger.info("addUser()");
if (user == null) {
throw new IllegalArgumentException("null user");
}
DataGridUser newUser = new DataGridUser();
newUser.setAdditionalInfo(user.getAdditionalInfo());
newUser.setUsername(user.getUsername());
newUser.setFirstName(user.getFirstName());
newUser.setLastName(user.getLastName());
newUser.setEmail(user.getEmail());
newUser.setUserType(user.getUserType());
newUser.setOrganizationalRole(user.getOrganizationalRole() != null ? user.getOrganizationalRole() : "");
newUser.setCompany(user.getCompany() != null ? user.getCompany() : "");
newUser.setDepartment(user.getDepartment() != null ? user.getDepartment() : "");
logger.info("adding user:{}", newUser);
String selectedProfile = request.getParameter("selectedProfile");
String[] groupList = groupsToBeAdded.toArray(new String[groupsToBeAdded.size()]);
List<DataGridGroup> groups = new ArrayList<DataGridGroup>();
if (groupList != null && groupList.length != 0) {
groups = groupService.findByDataGridIdList(groupList);
}
boolean groupsUpdateSuccessful = false;
boolean creationSucessful = false;
try {
logger.info("creating the user...");
creationSucessful = userService.createUser(newUser, user.getPassword());
logger.info("creation successful? {}", creationSucessful);
// Updating the group list for the recently-created user
if (creationSucessful) {
// adding read, write and ownership permissions to a set of collections
userService.updateReadPermissions(newUser, addReadPermissionsOnDirs, removeReadPermissionsOnDirs);
userService.updateWritePermissions(newUser, addWritePermissionsOnDirs, removeWritePermissionsOnDirs);
userService.updateOwnership(newUser, addOwnerOnDirs, removeOwnerOnDirs);
cleanPermissionsSets();
DataGridUser userForGroups = userService.findByUsernameAndAdditionalInfo(newUser.getUsername(), newUser.getAdditionalInfo());
groupsUpdateSuccessful = userService.updateGroupList(userForGroups, groups);
if (selectedProfile != null && selectedProfile != "") {
UserProfile userProfile = userProfileService.findById(Long.valueOf(selectedProfile));
userService.applyProfileToUser(userProfile, userForGroups);
userForGroups.setUserProfile(userProfile);
} else {
user.setUserProfile(null);
}
// User bookmarks
updateBookmarksList(newUser.getUsername(), newUser.getAdditionalInfo());
userService.modifyUser(userForGroups);
redirectAttributes.addFlashAttribute("userAddedSuccessfully", user.getUsername());
}
} catch (DuplicateDataException e) {
redirectAttributes.addFlashAttribute("duplicateUser", ExceptionEnum.USERS_DATA_DUPLICATE_EXCEPTION.getCode());
logger.error("Could not create user: ", e);
} catch (JargonException e) {
redirectAttributes.addFlashAttribute("error", ExceptionEnum.JARGON_EXCEPTION.getCode());
logger.error("Could not create user: ", e);
}
return creationSucessful && groupsUpdateSuccessful ? "redirect:/users/" : "redirect:/users/add/";
}
use of org.irods.jargon.core.exception.JargonException in project metalnx-web by irods-contrib.
the class MetadataServiceImpl method findMetadataValuesByPath.
@Override
public List<DataGridMetadata> findMetadataValuesByPath(String path) throws DataGridConnectionRefusedException {
List<MetaDataAndDomainData> metadataList;
List<DataGridMetadata> dataGridMetadataList = new ArrayList<>();
List<MetaDataAndDomainData> resultingList;
CollectionAndDataObjectListAndSearchAO collectionAndDataObjectListAndSearchAO = irodsServices.getCollectionAndDataObjectListAndSearchAO();
try {
Object obj = collectionAndDataObjectListAndSearchAO.getFullObjectForType(path);
if (obj instanceof DataObject) {
DataObjectAO dataObjectAO = irodsServices.getDataObjectAO();
metadataList = dataObjectAO.findMetadataValuesForDataObject(path);
} else {
CollectionAO collectionAO = irodsServices.getCollectionAO();
metadataList = collectionAO.findMetadataValuesForCollection(path);
}
// TODO2: Making sure all AVUs are unique. Jargon should do that.
resultingList = new ArrayList<>();
Set<Integer> setOfAlreadyListedAVUs = new HashSet<>();
for (MetaDataAndDomainData avuForItem : metadataList) {
int avuId = avuForItem.getAvuId();
if (!setOfAlreadyListedAVUs.contains(avuId)) {
resultingList.add(avuForItem);
setOfAlreadyListedAVUs.add(avuId);
}
}
for (MetaDataAndDomainData metadata : resultingList) {
DataGridMetadata dataGridMetadata = new DataGridMetadata();
dataGridMetadata.setAttribute(metadata.getAvuAttribute());
dataGridMetadata.setValue(metadata.getAvuValue());
dataGridMetadata.setUnit(metadata.getAvuUnit());
dataGridMetadataList.add(dataGridMetadata);
}
Collections.sort(dataGridMetadataList);
} catch (JargonQueryException e) {
logger.error("Error getting metadata info from collection: " + e.toString());
} catch (JargonException e) {
logger.error("Error getting metadata info from dataobject: " + e.toString());
}
return dataGridMetadataList;
}
use of org.irods.jargon.core.exception.JargonException in project metalnx-web by irods-contrib.
the class MetadataServiceImpl method delMetadataFromPath.
@Override
public boolean delMetadataFromPath(String path, String attribute, String value, String unit) throws DataGridConnectionRefusedException {
CollectionAndDataObjectListAndSearchAO collectionAndDataObjectListAndSearchAO = irodsServices.getCollectionAndDataObjectListAndSearchAO();
try {
AvuData avuData = new AvuData(attribute, value, unit);
Object obj = collectionAndDataObjectListAndSearchAO.getFullObjectForType(path);
if (obj instanceof DataObject) {
DataObjectAO dataObjectAO = irodsServices.getDataObjectAO();
dataObjectAO.deleteAVUMetadata(path, avuData);
} else {
CollectionAO collectionAO = irodsServices.getCollectionAO();
collectionAO.deleteAVUMetadata(path, avuData);
}
} catch (JargonException e) {
logger.error("Error trying to delete metadata: " + e.toString());
return false;
}
return true;
}
use of org.irods.jargon.core.exception.JargonException in project metalnx-web by irods-contrib.
the class PreviewServiceImpl method filePreview.
@Override
public boolean filePreview(String path, String mimeType, HttpServletResponse response) {
logger.info("getting file preview for {} ::" + path + " and mimetype :: " + mimeType);
boolean isCopySuccessFul = true;
IRODSFileInputStream irodsFileInputStream = null;
IRODSFile irodsFile = null;
try {
IRODSFileFactory irodsFileFactory = irodsServices.getIRODSFileFactory();
irodsFile = irodsFileFactory.instanceIRODSFile(path);
irodsFileInputStream = irodsFileFactory.instanceIRODSFileInputStream(irodsFile);
response.setContentType(mimeType);
FileCopyUtils.copy(irodsFileInputStream, response.getOutputStream());
} catch (IOException | JargonException | DataGridConnectionRefusedException e) {
e.printStackTrace();
isCopySuccessFul = false;
} finally {
try {
if (irodsFileInputStream != null)
irodsFileInputStream.close();
if (irodsFile != null)
irodsFile.close();
} catch (Exception e) {
logger.error("Could not close stream(s): ", e.getMessage());
}
}
return isCopySuccessFul;
}
Aggregations