use of org.jbei.ice.lib.access.PermissionException in project ice by JBEI.
the class FolderContents method addEntrySelection.
/**
* Adds entries in the selection context, to specified folders
*
* @param userId unique identifier for user making request
* @param entryLocation entry selection context which also contains the folders to
* add the entries obtained from the context to
* @return list of folders that the entries where added to. They should correspond to the specified
* folders in the selection context
*/
public List<FolderDetails> addEntrySelection(String userId, EntrySelection entryLocation) {
Entries retriever = new Entries(userId);
if (entryLocation.getRemoteEntries() != null && !entryLocation.getRemoteEntries().isEmpty())
return addRemoteEntries(userId, entryLocation.getRemoteEntries(), entryLocation.getDestination());
List<Long> entries = retriever.getEntriesFromSelectionContext(entryLocation);
if (StringUtils.isEmpty(userId)) {
List<FolderDetails> destination = entryLocation.getDestination();
// check that folder is transferred before rejecting
if (destination == null || destination.isEmpty())
throw new IllegalArgumentException("Cannot add without valid user id or destination");
Folder folder = folderDAO.get(destination.get(0).getId());
if (folder == null)
throw new IllegalArgumentException("Cannot find folder");
if (folder.getType() != FolderType.TRANSFERRED)
throw new PermissionException("Can only add to transferred folder without id");
FolderDetails details = addEntriesToTransferredFolder(entries, folder);
List<FolderDetails> result = new ArrayList<>();
result.add(details);
return result;
}
return addEntriesToFolders(userId, entries, entryLocation.getDestination());
}
use of org.jbei.ice.lib.access.PermissionException in project ice by JBEI.
the class CollectionEntries method getPersonalEntries.
/**
* Retrieves entries owned by user
*
* @param field sort field
* @param asc sort order
* @param offset paging start
* @param limit maximum number of entries to retrieve
* @param filter optional text to filter entries by
* @return wrapper around list of parts that conform to the parameters and the maximum number
* of such entries that are available
* @throws PermissionException on null user id which is required for owner entries
*/
private Results<PartData> getPersonalEntries(ColumnField field, boolean asc, int offset, int limit, String filter, List<String> fields) {
if (userId == null || userId.isEmpty())
throw new PermissionException("User id is required to retrieve owner entries");
OwnerEntries ownerEntries = new OwnerEntries(userId, userId);
final List<PartData> entries = ownerEntries.retrieveOwnerEntries(field, asc, offset, limit, filter, fields);
final long count = ownerEntries.getNumberOfOwnerEntries();
Results<PartData> results = new Results<>();
results.setResultCount(count);
results.setData(entries);
return results;
}
use of org.jbei.ice.lib.access.PermissionException in project ice by JBEI.
the class Annotations method curate.
/**
* Curates a specified set of annotations. The curation properties are contained in each annotation (feature)
* object
*
* @param features set of features to be curated
*/
public void curate(List<DNAFeature> features) {
if (!isAdministrator())
throw new PermissionException("Administrative privileges required to curate features");
for (DNAFeature dnaFeature : features) {
if (dnaFeature.getCuration() == null)
continue;
Feature feature = featureDAO.get(dnaFeature.getId());
if (feature == null)
continue;
FeatureCurationModel curationModel = feature.getCuration();
if (feature.getCuration() == null) {
if (dnaFeature.getCuration().isExclude()) {
curationModel = new FeatureCurationModel();
curationModel.setFeature(feature);
curationModel.setExclude(true);
curationModel = curationModelDAO.create(curationModel);
}
} else {
curationModel.setExclude(dnaFeature.getCuration().isExclude());
curationModel = curationModelDAO.update(curationModel);
}
if (curationModel != null) {
feature.setCuration(curationModel);
featureDAO.update(feature);
}
}
}
use of org.jbei.ice.lib.access.PermissionException in project ice by JBEI.
the class Annotations method get.
/**
* Retrieves list of annotations that are available
*
* @param offset paging start
* @param limit maximum number of annotations to return
* @param sort paging sort
* @return available annotations that conform to parameters along with the total number that are available
* @throws PermissionException if the requesting user's account does not have administrative privileges
*/
public Results<DNAFeatures> get(int offset, int limit, String sort) {
if (!isAdministrator())
throw new PermissionException("Administrative privileges required to retrieve features");
long count = this.featureDAO.getFeaturesGroupByCount();
Results<DNAFeatures> results = new Results<>();
results.setResultCount(count);
Map<String, List<Feature>> map = this.featureDAO.getFeaturesGroupBy(offset, limit);
for (String key : map.keySet()) {
DNAFeatures features = new DNAFeatures(key);
for (Feature feature : map.get(key)) {
DNAFeature dnaFeature = feature.toDataTransferObject();
dnaFeature.setSequence(feature.getSequence());
List<Long> entries = this.sequenceFeatureDAO.getEntryIdsByFeature(feature);
if (entries != null)
dnaFeature.getEntries().addAll(entries);
features.getFeatures().add(dnaFeature);
}
results.getData().add(features);
}
return results;
}
use of org.jbei.ice.lib.access.PermissionException in project ice by JBEI.
the class AccountController method updateAccount.
/**
* @param requester
* @param userId
* @param transfer
* @return updated account object
*/
public AccountTransfer updateAccount(final String requester, final long userId, final AccountTransfer transfer) {
final Account account = dao.get(userId);
boolean requesterIsAdmin = isAdministrator(requester);
if (!account.getEmail().equalsIgnoreCase(requester) && !requesterIsAdmin) {
return null;
}
// if transfer has password then it is a password change
if (!StringUtils.isEmpty(transfer.getFirstName())) {
account.setFirstName(transfer.getFirstName());
}
if (!StringUtils.isEmpty(transfer.getLastName())) {
account.setLastName(transfer.getLastName());
}
if (!StringUtils.isEmpty(transfer.getDescription())) {
account.setDescription(transfer.getDescription());
}
if (!StringUtils.isEmpty(transfer.getInstitution())) {
account.setInstitution(transfer.getInstitution());
}
if (transfer.getAccountType() != null) {
if (transfer.getAccountType() != account.getType() && !requesterIsAdmin)
throw new PermissionException("Only admins can change account type");
account.setType(transfer.getAccountType());
}
AccountTransfer result = dao.update(account).toDataTransferObject();
result.setAdmin(isAdministrator(account.getEmail()));
return result;
}
Aggregations