use of org.jbei.ice.storage.model.Entry in project ice by JBEI.
the class EntryLinks method removeLink.
/**
* Removes link specified entry id based on the specified type
*
* @param partToRemove unique identifier for part to remove
* @param linkType type of relationship that exists
* @return true, if entry is removed successfully.
*/
public boolean removeLink(long partToRemove, LinkType linkType) {
entryAuthorization.expectWrite(userId, entry);
Entry linkedEntry = entryDAO.get(partToRemove);
switch(linkType) {
case PARENT:
return linkedEntry.getLinkedEntries().remove(entry) && entryDAO.update(linkedEntry) != null;
case CHILD:
default:
return entry.getLinkedEntries().remove(linkedEntry) && entryDAO.update(entry) != null;
}
}
use of org.jbei.ice.storage.model.Entry in project ice by JBEI.
the class EntryLinks method getParents.
/**
* Retrieves list of this entry's parents that user has read access to
*
* @return list of parents of entry
*/
public List<PartData> getParents() {
List<Entry> parents = this.entryDAO.getParents(this.entry.getId());
List<PartData> parentData = new ArrayList<>(parents.size());
for (Entry parent : parents) {
if (!entryAuthorization.canRead(this.userId, parent))
continue;
parentData.add(parent.toDataTransferObject());
}
return parentData;
}
use of org.jbei.ice.storage.model.Entry 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.model.Entry in project ice by JBEI.
the class EntryLinks method addLink.
/**
* Adds a link for the specified entry (or creates a new entry) of the type specified
*
* @param partData data for entry to be linked. If the id does not point to an existing entry, a new one will be
* created and linked to this entry
* @param type type of link to create. If <code>CHILD</code> (default) is specified, then the entry in the parameter
* is added as a child in the hierarchy; if <code>PARENT</code> is specified, then the entry is
* add as a parent in the hierarchy.
* @return true, if the two entries are successfully linked. false, if the specified hierarchy is not compatible
* with the types of the link specified e.g. an plasmid cannot be added as a <code>PARENT</code> of a strain
* @throws org.jbei.ice.lib.access.PermissionException if the user does not have write permissions
* on at least one of the entries being linked
*/
public boolean addLink(PartData partData, LinkType type) {
long linkId = partData.getId();
Entry linkedEntry = this.entryDAO.get(linkId);
if (linkedEntry == null) {
// todo : create a new entry
Logger.error("Could not retrieve entry for linking: " + linkId);
return false;
}
if (linkedEntry.getId() == this.entry.getId())
throw new IllegalArgumentException("Cannot link and entry to itself");
// should have write permissions on the main entry but only read on the entry being linked
entryAuthorization.expectRead(userId, linkedEntry);
entryAuthorization.expectWrite(userId, entry);
// add as parent
switch(type) {
case PARENT:
return addParentEntry(linkedEntry);
// add as child. default behavior
case CHILD:
default:
return addChildEntry(linkedEntry);
}
}
use of org.jbei.ice.storage.model.Entry in project ice by JBEI.
the class FileResource method getSBOLVisual.
@GET
@Produces("image/png")
@Path("sbolVisual/{rid}")
public Response getSBOLVisual(@PathParam("rid") String recordId) {
final String tmpDir = Utils.getConfigValue(ConfigurationKey.TEMPORARY_DIRECTORY);
final Entry entry = DAOFactory.getEntryDAO().getByRecordId(recordId);
final Sequence sequence = entry.getSequence();
final String hash = sequence.getFwdHash();
final File png = Paths.get(tmpDir, hash + ".png").toFile();
if (png.exists()) {
return addHeaders(Response.ok(png), entry.getPartNumber() + ".png");
}
final URI uri = PigeonSBOLv.generatePigeonVisual(sequence);
if (uri != null) {
try (final InputStream in = uri.toURL().openStream();
final OutputStream out = new FileOutputStream(png)) {
ByteStreams.copy(in, out);
} catch (IOException e) {
Logger.error(e);
return respond(false);
}
return addHeaders(Response.ok(png), entry.getPartNumber() + ".png");
}
return respond(false);
}
Aggregations