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);
}
}
}
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;
}
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;
}
}
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;
}
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);
}
Aggregations