use of org.jbei.ice.lib.dto.folder.FolderDetails in project ice by JBEI.
the class FolderContents method remotelyAddEntrySelection.
// adds a specified entry to a folder. The entry was transferred earlier so already exists
public boolean remotelyAddEntrySelection(String remoteUserId, long folderId, String remoteUserToken, EntrySelection selection, RegistryPartner requestingPartner) {
// folder that the entry is contained in
Folder folder = folderDAO.get(folderId);
if (folder == null)
return false;
RemotePartner remotePartner = DAOFactory.getRemotePartnerDAO().getByUrl(requestingPartner.getUrl());
// check that the remote user has the right token
RemoteShareModel shareModel = DAOFactory.getRemoteShareModelDAO().get(remoteUserId, remotePartner, folder);
if (shareModel == null) {
Logger.error("Could not retrieve share model");
return false;
}
// folder must match
Permission permission = shareModel.getPermission();
if (permission.getFolder().getId() != folderId || !permission.isCanWrite()) {
throw new PermissionException("permission could not be verified");
}
// validate access token
TokenHash tokenHash = new TokenHash();
String secret = tokenHash.encrypt(remotePartner.getUrl() + remoteUserId, remoteUserToken);
if (!secret.equals(shareModel.getSecret())) {
throw new PermissionException("Secret does not match");
}
List<Long> entries = selection.getEntries();
DAOFactory.getEntryDAO().setEntryVisibility(entries, Visibility.OK);
// good to go?
FolderDetails details = addEntriesToTransferredFolder(entries, folder);
return details != null;
}
use of org.jbei.ice.lib.dto.folder.FolderDetails in project ice by JBEI.
the class FolderController method getSharedUserFolders.
/**
* Retrieves folders that have been shared with specified user as an individual or as part of a group.
*
* @param userId User whose shared folders are being retrieved
* @return list of folders meeting the shared criteria
*/
public ArrayList<FolderDetails> getSharedUserFolders(String userId) {
Account account = getAccount(userId);
ArrayList<FolderDetails> folderDetails = new ArrayList<>();
Set<Group> groups = account.getGroups();
groups.remove(groupController.createOrRetrievePublicGroup());
List<Folder> sharedFolders = DAOFactory.getPermissionDAO().retrieveFolderPermissions(account, groups);
if (sharedFolders == null)
return null;
for (Folder folder : sharedFolders) {
FolderDetails details = folder.toDataTransferObject();
details.setType(folder.getType());
long folderSize = dao.getFolderSize(folder.getId(), null, true);
details.setCount(folderSize);
if (folder.getCreationTime() != null)
details.setCreationTime(folder.getCreationTime().getTime());
folderDetails.add(details);
}
return folderDetails;
}
use of org.jbei.ice.lib.dto.folder.FolderDetails in project ice by JBEI.
the class FolderController method delete.
/**
* Deletes either a user folder or bulk upload (which is represented as a folder to the user)
*
* @param userId unique identifier for user requesting delete action
* @param folderId unique identifier for folder to be deleted
* @param type type of folder to be deleted (either "UPLOAD" or "PRIVATE")
* @return delete folder details
*/
public FolderDetails delete(String userId, long folderId, FolderType type) {
switch(type) {
case UPLOAD:
BulkUploadController controller = new BulkUploadController();
BulkUploadInfo info = controller.deleteDraftById(userId, folderId);
if (info == null) {
Logger.error("Could not locate bulk upload id " + folderId + " for deletion");
return null;
}
FolderDetails details = new FolderDetails();
details.setId(info.getId());
return details;
case PRIVATE:
case TRANSFERRED:
case SHARED:
Folder folder = dao.get(folderId);
if (folder == null)
return null;
if (!accountController.isAdministrator(userId) && !folder.getOwnerEmail().equalsIgnoreCase(userId)) {
String errorMsg = userId + ": insufficient permissions to delete folder " + folderId;
Logger.warn(errorMsg);
throw new PermissionException(errorMsg);
}
details = folder.toDataTransferObject();
long folderSize = dao.getFolderSize(folderId, null, true);
details.setCount(folderSize);
permissionDAO.clearPermissions(folder);
dao.delete(folder);
return details;
default:
Logger.error("Cannot delete folder of type " + type);
return null;
}
}
use of org.jbei.ice.lib.dto.folder.FolderDetails in project ice by JBEI.
the class FolderContents method getRemotelySharedContents.
// remote request for shared contents
public FolderDetails getRemotelySharedContents(String remoteUserId, String token, RegistryPartner partner, long folderId, PageParameters pageParameters) {
RemotePartner remotePartner = DAOFactory.getRemotePartnerDAO().getByUrl(partner.getUrl());
if (remotePartner == null) {
Logger.error("Cannot retrieve remote partner " + partner.getUrl());
return null;
}
Folder folder = folderDAO.get(folderId);
if (folder == null) {
Logger.error("Cannot retrieve folder with id " + folderId);
return null;
}
RemoteShareModelDAO shareModelDAO = DAOFactory.getRemoteShareModelDAO();
RemoteShareModel shareModel = shareModelDAO.get(remoteUserId, remotePartner, folder);
if (shareModel == null) {
Logger.error("Could not retrieve share model");
return null;
}
//verify access
TokenHash tokenHash = new TokenHash();
String secret = tokenHash.encrypt(folderId + remotePartner.getUrl() + remoteUserId, token);
if (!secret.equals(shareModel.getSecret())) {
Logger.error("Authorization failed for remote folder retrieve");
return null;
}
boolean canEdit = shareModel.getPermission().isCanWrite();
// todo : move everything above to folder permissions and folder authorization
FolderDetails details = folder.toDataTransferObject();
details.setCanEdit(canEdit);
long folderSize = folderDAO.getFolderSize(folderId, pageParameters.getFilter(), true);
details.setCount(folderSize);
// retrieve folder contents
List<Entry> results = folderDAO.retrieveFolderContents(folderId, pageParameters, true);
for (Entry entry : results) {
PartData info = ModelToInfoFactory.createTableViewData(null, entry, false);
info.setCanEdit(canEdit);
details.getEntries().add(info);
}
return details;
}
use of org.jbei.ice.lib.dto.folder.FolderDetails in project ice by JBEI.
the class FolderController method getPendingBulkUploads.
/**
* Retrieves information about submitted bulk uploads that have status "PENDING". Administrator only function
*
* @param userId unique identifier for user performing action. Must have admin privileges
* @return list of information about pending bulk uploads is user has administrative privileges, null otherwise
*/
public ArrayList<FolderDetails> getPendingBulkUploads(String userId) {
ArrayList<FolderDetails> folders = new ArrayList<>();
ArrayList<BulkUploadInfo> list = bulkUploadController.getPendingUploads(userId);
for (BulkUploadInfo info : list) {
FolderDetails details = new FolderDetails();
String name = info.getAccount() != null ? info.getAccount().getEmail() : info.getName();
details.setName(name);
details.setCount(info.getCount());
details.setId(info.getId());
details.setType(FolderType.UPLOAD);
folders.add(details);
}
return folders;
}
Aggregations