use of org.jbei.ice.lib.group.GroupController in project ice by JBEI.
the class Entries method updateVisibility.
public boolean updateVisibility(List<Long> entryIds, Visibility visibility) {
Account account = accountDAO.getByEmail(userId);
List<Group> accountGroups = new GroupController().getAllGroups(account);
if (!new AccountController().isAdministrator(userId) && !permissionDAO.canWrite(account, accountGroups, entryIds))
return false;
for (long entryId : entryIds) {
Entry entry = dao.get(entryId);
if (entry.getVisibility() == visibility.getValue())
continue;
entry.setVisibility(visibility.getValue());
dao.update(entry);
}
return true;
}
use of org.jbei.ice.lib.group.GroupController in project ice by JBEI.
the class OwnerEntries method retrieveOwnerEntries.
public List<PartData> retrieveOwnerEntries(ColumnField sort, boolean asc, int start, int limit, String filter) {
List<Entry> entries;
if (this.isAdmin || this.isSelf) {
entries = entryDAO.retrieveOwnerEntries(this.ownerAccount.getEmail(), sort, asc, start, limit, filter);
} else {
Set<Group> accountGroups = new HashSet<>(account.getGroups());
GroupController controller = new GroupController();
Group everybodyGroup = controller.createOrRetrievePublicGroup();
accountGroups.add(everybodyGroup);
// retrieve entries for user that can be read by others
entries = entryDAO.retrieveUserEntries(account, this.ownerAccount.getEmail(), accountGroups, sort, asc, start, limit, filter);
}
ArrayList<PartData> data = new ArrayList<>();
for (Entry entry : entries) {
PartData info = ModelToInfoFactory.createTableViewData(account.getEmail(), entry, false);
data.add(info);
}
return data;
}
use of org.jbei.ice.lib.group.GroupController in project ice by JBEI.
the class SharedEntries method getEntries.
public List<PartData> getEntries(ColumnField field, boolean asc, int start, int limit, String filter) {
GroupController groupController = new GroupController();
Group publicGroup = groupController.createOrRetrievePublicGroup();
Set<Group> accountGroups = account.getGroups();
accountGroups.remove(publicGroup);
List<Entry> entries = this.entryDAO.sharedWithUserEntries(account, accountGroups, field, asc, start, limit, filter);
ArrayList<PartData> data = new ArrayList<>();
for (Entry entry : entries) {
PartData info = ModelToInfoFactory.createTableViewData(account.getEmail(), entry, false);
data.add(info);
}
return data;
}
use of org.jbei.ice.lib.group.GroupController in project ice by JBEI.
the class BulkUploadController method create.
/**
* Creates a new bulk upload. If upload type is not bulk edit, then the status is set to in progress.
* Default permissions consisting of read permissions for the public groups that the requesting user is
* a part of are added
*
* @param userId identifier for user making request
* @param info bulk upload data
* @return created upload
*/
public BulkUploadInfo create(String userId, BulkUploadInfo info) {
Account account = accountController.getByEmail(userId);
BulkUpload upload = new BulkUpload();
upload.setName(info.getName());
upload.setAccount(account);
upload.setCreationTime(new Date());
upload.setLastUpdateTime(upload.getCreationTime());
if (info.getStatus() == BulkUploadStatus.BULK_EDIT) {
// only one instance of bulk edit is allowed to remain
clearBulkEdits(userId);
upload.setStatus(BulkUploadStatus.BULK_EDIT);
} else
upload.setStatus(BulkUploadStatus.IN_PROGRESS);
upload.setImportType(info.getType());
// set default permissions
GroupController groupController = new GroupController();
ArrayList<Group> publicGroups = groupController.getAllPublicGroupsForAccount(account);
for (Group group : publicGroups) {
Permission permission = new Permission();
permission.setCanRead(true);
permission.setUpload(upload);
permission.setGroup(group);
permission = DAOFactory.getPermissionDAO().create(permission);
upload.getPermissions().add(permission);
}
upload = dao.create(upload);
if (info.getEntryList() != null) {
for (PartData data : info.getEntryList()) {
Entry entry = entryDAO.get(data.getId());
// todo if entry is in another bulk upload, then update will fail
if (entry == null)
continue;
upload.getContents().add(entry);
}
}
dao.update(upload);
return upload.toDataTransferObject();
}
use of org.jbei.ice.lib.group.GroupController in project ice by JBEI.
the class FolderController method getPublicEntries.
/**
* Retrieves entries that are made available publicly
*
* @param sort order of retrieval for the entries
* @param offset start of retrieval
* @param limit maximum number of entries to retrieve
* @param asc whether to retrieve the entries in ascending order
* @return wrapper around the retrieved entries
*/
public FolderDetails getPublicEntries(ColumnField sort, int offset, int limit, boolean asc) {
Group publicGroup = new GroupController().createOrRetrievePublicGroup();
Set<Group> groups = new HashSet<>();
groups.add(publicGroup);
EntryDAO entryDAO = DAOFactory.getEntryDAO();
List<Entry> results = entryDAO.retrieveVisibleEntries(null, groups, sort, asc, offset, limit, null);
long visibleCount = entryDAO.visibleEntryCount(null, groups, null);
FolderDetails details = new FolderDetails();
details.setCount(visibleCount);
for (Entry entry : results) {
try {
PartData info = ModelToInfoFactory.createTableViewData(null, entry, false);
info.setPublicRead(true);
details.getEntries().add(info);
} catch (Exception e) {
Logger.error(e);
}
}
return details;
}
Aggregations