Search in sources :

Example 1 with EntryDAO

use of org.jbei.ice.storage.hibernate.dao.EntryDAO in project ice by JBEI.

the class EntryPermissionTask method execute.

@Override
public void execute() {
    // check if user has write privileges on entries
    Account account = DAOFactory.getAccountDAO().getByEmail(userId);
    List<Group> accountGroups = new GroupController().getAllGroups(account);
    boolean checkIndividual = false;
    if (account.getType() != AccountType.ADMIN && !permissionDAO.canWrite(account, accountGroups, entries)) {
        checkIndividual = true;
    }
    EntryDAO entryDAO = DAOFactory.getEntryDAO();
    EntryAuthorization entryAuthorization = new EntryAuthorization();
    for (long entryId : entries) {
        Entry entry = entryDAO.get(entryId);
        if (entry == null)
            continue;
        // check permission on individual entries
        if (checkIndividual && !entryAuthorization.canWrite(userId, entry)) {
            continue;
        }
        // add or remove permissions
        if (this.isAdd) {
            addPermissions(entry);
        } else {
            removePermissions(entry);
        }
    }
}
Also used : Account(org.jbei.ice.storage.model.Account) Group(org.jbei.ice.storage.model.Group) Entry(org.jbei.ice.storage.model.Entry) GroupController(org.jbei.ice.lib.group.GroupController) EntryDAO(org.jbei.ice.storage.hibernate.dao.EntryDAO)

Example 2 with EntryDAO

use of org.jbei.ice.storage.hibernate.dao.EntryDAO in project ice by JBEI.

the class Collections method getAllCounts.

public CollectionCounts getAllCounts() {
    String userId = this.account.getEmail();
    EntryDAO entryDAO = DAOFactory.getEntryDAO();
    CollectionCounts collection = new CollectionCounts();
    VisibleEntries visibleEntries = new VisibleEntries(userId);
    collection.setAvailable(visibleEntries.getEntryCount());
    collection.setDeleted(entryDAO.getDeletedCount(userId));
    long ownerEntryCount = DAOFactory.getEntryDAO().ownerEntryCount(userId);
    collection.setPersonal(ownerEntryCount);
    SharedEntries sharedEntries = new SharedEntries(userId);
    collection.setShared(sharedEntries.getNumberOfEntries(null));
    collection.setDrafts(entryDAO.getByVisibilityCount(userId, Visibility.DRAFT, null));
    if (account.getType() != AccountType.ADMIN)
        return collection;
    // admin only options
    collection.setPending(entryDAO.getByVisibilityCount(Visibility.PENDING));
    collection.setTransferred(entryDAO.getByVisibilityCount(Visibility.TRANSFERRED));
    return collection;
}
Also used : VisibleEntries(org.jbei.ice.lib.entry.VisibleEntries) SharedEntries(org.jbei.ice.lib.entry.SharedEntries) CollectionCounts(org.jbei.ice.lib.folder.CollectionCounts) EntryDAO(org.jbei.ice.storage.hibernate.dao.EntryDAO)

Example 3 with EntryDAO

use of org.jbei.ice.storage.hibernate.dao.EntryDAO in project ice by JBEI.

the class BulkUploadController method deleteEntry.

public boolean deleteEntry(String userId, long uploadId, long entryId) {
    try {
        BulkUpload upload = dao.get(uploadId);
        Entry entry = new EntryDAO().get(entryId);
        authorization.expectWrite(userId, upload);
        upload.getContents().remove(entry);
        return true;
    } catch (Exception e) {
        Logger.error(e);
        return false;
    }
}
Also used : IOException(java.io.IOException) PermissionException(org.jbei.ice.lib.access.PermissionException) EntryDAO(org.jbei.ice.storage.hibernate.dao.EntryDAO)

Example 4 with EntryDAO

use of org.jbei.ice.storage.hibernate.dao.EntryDAO in project ice by JBEI.

the class PartResource method getShotgunSequences.

@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/{id}/shotgunsequences")
public ArrayList<ShotgunSequenceDTO> getShotgunSequences(@Context final UriInfo info, @PathParam("id") final long partId, @DefaultValue("100") @QueryParam("limit") int limit, @DefaultValue("0") @QueryParam("start") int start) {
    getUserId();
    ShotgunSequenceDAO dao = DAOFactory.getShotgunSequenceDAO();
    final EntryDAO entryDAO = DAOFactory.getEntryDAO();
    final Entry entry = entryDAO.get(partId);
    if (entry == null) {
        return null;
    }
    ArrayList<ShotgunSequenceDTO> returns = new ArrayList<>();
    List<ShotgunSequence> results = dao.getByEntry(entry);
    for (ShotgunSequence ret : results) {
        returns.add(new ShotgunSequenceDTO(ret));
    }
    Logger.info("Shotgun Sequences requested for entry " + partId);
    return returns;
}
Also used : Entry(org.jbei.ice.storage.model.Entry) ShotgunSequence(org.jbei.ice.storage.model.ShotgunSequence) ArrayList(java.util.ArrayList) ShotgunSequenceDAO(org.jbei.ice.storage.hibernate.dao.ShotgunSequenceDAO) EntryDAO(org.jbei.ice.storage.hibernate.dao.EntryDAO) ShotgunSequenceDTO(org.jbei.ice.lib.dto.ShotgunSequenceDTO)

Example 5 with EntryDAO

use of org.jbei.ice.storage.hibernate.dao.EntryDAO in project ice by JBEI.

the class PartResource method addShotgunSequence.

@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("/{id}/shotgunsequences")
public Response addShotgunSequence(@PathParam("id") final long partId, @FormDataParam("file") final InputStream fileInputStream, @FormDataParam("file") final FormDataContentDisposition contentDispositionHeader) {
    final String userId = getUserId();
    final String fileName = contentDispositionHeader.getFileName();
    final EntryDAO entryDAO = DAOFactory.getEntryDAO();
    final Entry entry = entryDAO.get(partId);
    ShotgunSequenceDAO dao = DAOFactory.getShotgunSequenceDAO();
    try {
        String storageName = Utils.generateUUID();
        dao.writeSequenceFileToDisk(storageName, fileInputStream);
        dao.create(fileName, userId, entry, storageName, new Date());
    } catch (Exception e) {
        Logger.error(e);
        return respond(Response.Status.INTERNAL_SERVER_ERROR);
    }
    Logger.info("Uploaded shotgun sequence for entry " + entry.getId());
    return respond(Response.Status.OK);
}
Also used : Entry(org.jbei.ice.storage.model.Entry) ShotgunSequenceDAO(org.jbei.ice.storage.hibernate.dao.ShotgunSequenceDAO) Date(java.util.Date) IOException(java.io.IOException) PermissionException(org.jbei.ice.lib.access.PermissionException) EntryDAO(org.jbei.ice.storage.hibernate.dao.EntryDAO)

Aggregations

EntryDAO (org.jbei.ice.storage.hibernate.dao.EntryDAO)9 Entry (org.jbei.ice.storage.model.Entry)5 PermissionException (org.jbei.ice.lib.access.PermissionException)3 PartData (org.jbei.ice.lib.dto.entry.PartData)3 GroupController (org.jbei.ice.lib.group.GroupController)3 Account (org.jbei.ice.storage.model.Account)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 ShotgunSequenceDAO (org.jbei.ice.storage.hibernate.dao.ShotgunSequenceDAO)2 Group (org.jbei.ice.storage.model.Group)2 Test (org.junit.Test)2 CSVWriter (com.opencsv.CSVWriter)1 Path (java.nio.file.Path)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 ZipEntry (java.util.zip.ZipEntry)1 ZipOutputStream (java.util.zip.ZipOutputStream)1 ShotgunSequenceDTO (org.jbei.ice.lib.dto.ShotgunSequenceDTO)1 EntryField (org.jbei.ice.lib.dto.entry.EntryField)1 EntryType (org.jbei.ice.lib.dto.entry.EntryType)1