Search in sources :

Example 41 with PermissionException

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());
}
Also used : PermissionException(org.jbei.ice.lib.access.PermissionException) ArrayList(java.util.ArrayList) FolderDetails(org.jbei.ice.lib.dto.folder.FolderDetails) Entries(org.jbei.ice.lib.entry.Entries)

Example 42 with PermissionException

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;
}
Also used : PermissionException(org.jbei.ice.lib.access.PermissionException) Results(org.jbei.ice.lib.dto.common.Results) PartData(org.jbei.ice.lib.dto.entry.PartData) OwnerEntries(org.jbei.ice.lib.entry.OwnerEntries)

Example 43 with PermissionException

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);
        }
    }
}
Also used : PermissionException(org.jbei.ice.lib.access.PermissionException) DNAFeature(org.jbei.ice.lib.dto.DNAFeature) DNAFeature(org.jbei.ice.lib.dto.DNAFeature)

Example 44 with PermissionException

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;
}
Also used : PermissionException(org.jbei.ice.lib.access.PermissionException) DNAFeatures(org.jbei.ice.lib.dto.DNAFeatures) Results(org.jbei.ice.lib.dto.common.Results) List(java.util.List) DNAFeature(org.jbei.ice.lib.dto.DNAFeature) DNAFeature(org.jbei.ice.lib.dto.DNAFeature)

Example 45 with PermissionException

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;
}
Also used : PermissionException(org.jbei.ice.lib.access.PermissionException) Account(org.jbei.ice.storage.model.Account)

Aggregations

PermissionException (org.jbei.ice.lib.access.PermissionException)49 Account (org.jbei.ice.storage.model.Account)10 AccountController (org.jbei.ice.lib.account.AccountController)7 RemotePartner (org.jbei.ice.storage.model.RemotePartner)6 FolderDetails (org.jbei.ice.lib.dto.folder.FolderDetails)5 TokenHash (org.jbei.ice.lib.account.TokenHash)4 Results (org.jbei.ice.lib.dto.common.Results)4 UserGroup (org.jbei.ice.lib.dto.group.UserGroup)4 Configuration (org.jbei.ice.storage.model.Configuration)4 Group (org.jbei.ice.storage.model.Group)4 ArrayList (java.util.ArrayList)3 AccountTransfer (org.jbei.ice.lib.account.AccountTransfer)3 DNAFeature (org.jbei.ice.lib.dto.DNAFeature)3 PartData (org.jbei.ice.lib.dto.entry.PartData)3 RegistryPartner (org.jbei.ice.lib.dto.web.RegistryPartner)3 HasEntry (org.jbei.ice.lib.entry.HasEntry)3 Annotations (org.jbei.ice.lib.entry.sequence.annotation.Annotations)3 ApiKey (org.jbei.ice.storage.model.ApiKey)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2