use of org.jbei.ice.lib.bulkupload.BulkUploadAuthorization in project ice by JBEI.
the class PermissionsController method addPermission.
public Permission addPermission(String userId, AccessPermission access) {
if (access.isEntry()) {
Entry entry = DAOFactory.getEntryDAO().get(access.getTypeId());
if (entry == null)
throw new IllegalArgumentException("Cannot find entry " + access.getTypeId());
EntryAuthorization authorization = new EntryAuthorization();
authorization.expectWrite(userId, entry);
return addPermission(access, entry, null, null);
}
if (access.isFolder()) {
Folder folder = folderDAO.get(access.getTypeId());
if (!hasWritePermission(userId, folder)) {
Logger.error(userId + " not allowed to add " + access.toString());
return null;
}
// propagate permissions
if (folder.isPropagatePermissions()) {
for (Entry folderContent : folder.getContents()) {
addPermission(access, folderContent, null, null);
}
}
return addPermission(access, null, folder, null);
}
// if bulk upload
if (access.isUpload()) {
BulkUpload upload = DAOFactory.getBulkUploadDAO().get(access.getTypeId());
if (upload == null)
throw new IllegalArgumentException("Cannot find upload " + access.getId());
BulkUploadAuthorization uploadAuthorization = new BulkUploadAuthorization();
uploadAuthorization.expectWrite(userId, upload);
return addPermission(access, null, null, upload);
}
return null;
}
use of org.jbei.ice.lib.bulkupload.BulkUploadAuthorization in project ice by JBEI.
the class Collection method getBulkUploadFolder.
/**
* Retrieves bulk import and entries associated with it that are referenced by the
* id in the parameter. Only owners or administrators are allowed to retrieve bulk imports
*
* @param id unique identifier for bulk import
* @param offset offset for upload entries (start)
* @param limit maximum number of entries to return with the upload
* @return data transfer object with the retrieved bulk import data and associated entries
* @throws PermissionException
*/
protected AbstractFolder getBulkUploadFolder(long id, int offset, int limit) {
BulkUploadDAO uploadDAO = DAOFactory.getBulkUploadDAO();
BulkUploadAuthorization authorization = new BulkUploadAuthorization();
BulkUpload draft = uploadDAO.get(id);
if (draft == null)
return null;
Account account = DAOFactory.getAccountDAO().getByEmail(userId);
authorization.expectRead(account.getEmail(), draft);
// retrieve the entries associated with the bulk import
BulkUploadInfo info = draft.toDataTransferObject();
List<Entry> list = uploadDAO.retrieveDraftEntries(id, offset, limit);
for (Entry entry : list) {
PartData partData = setFileData(userId, entry, ModelToInfoFactory.getInfo(entry));
// check if any links and convert
if (!entry.getLinkedEntries().isEmpty()) {
Entry linked = (Entry) entry.getLinkedEntries().toArray()[0];
PartData linkedData = partData.getLinkedParts().remove(0);
linkedData = setFileData(userId, linked, linkedData);
partData.getLinkedParts().add(linkedData);
}
info.getEntryList().add(partData);
}
info.setCount(uploadDAO.retrieveSavedDraftCount(id));
return info;
}
use of org.jbei.ice.lib.bulkupload.BulkUploadAuthorization in project ice by JBEI.
the class PermissionsController method removePermission.
public void removePermission(String userId, AccessPermission access) {
if (access.isEntry()) {
Entry entry = DAOFactory.getEntryDAO().get(access.getTypeId());
if (entry == null)
return;
EntryAuthorization authorization = new EntryAuthorization();
authorization.expectWrite(userId, entry);
// remove permission from entry
removePermission(access, entry, null, null);
return;
}
if (access.isFolder()) {
Folder folder = folderDAO.get(access.getTypeId());
FolderAuthorization folderAuthorization = new FolderAuthorization();
folderAuthorization.expectWrite(userId, folder);
// if folder is to be propagated, add removing permission from contained entries
if (folder.isPropagatePermissions()) {
for (Entry folderContent : folder.getContents()) {
removePermission(access, folderContent, null, null);
}
}
// remove permission from folder
removePermission(access, null, folder, null);
return;
}
if (access.isUpload()) {
BulkUpload upload = DAOFactory.getBulkUploadDAO().get(access.getTypeId());
if (upload == null)
throw new IllegalArgumentException("Could not retrieve upload " + access.getTypeId());
BulkUploadAuthorization uploadAuthorization = new BulkUploadAuthorization();
uploadAuthorization.expectWrite(userId, upload);
removePermission(access, null, null, upload);
}
}
Aggregations