Search in sources :

Example 1 with WebEntries

use of org.jbei.ice.lib.dto.web.WebEntries in project ice by JBEI.

the class EntryController method retrieveEntryDetails.

protected PartData retrieveEntryDetails(String userId, Entry entry) throws PermissionException {
    if (entry.getVisibility() == Visibility.REMOTE.getValue()) {
        WebEntries webEntries = new WebEntries();
        PartData partData = webEntries.getPart(entry.getRecordId());
        partData.setVisibility(Visibility.REMOTE);
        // id returned from remote is different from the local id
        partData.setId(entry.getId());
        // need to map parents to local
        partData.getParents().clear();
        // todo : sequence data
        return partData;
    }
    PartData partData = ModelToInfoFactory.getInfo(entry);
    if (partData == null)
        return null;
    // retrieve sequence information
    boolean hasSequence = sequenceDAO.hasSequence(entry.getId());
    partData.setHasSequence(hasSequence);
    boolean hasOriginalSequence = sequenceDAO.hasOriginalSequence(entry.getId());
    partData.setHasOriginalSequence(hasOriginalSequence);
    Optional<String> sequenceString = sequenceDAO.getSequenceString(entry);
    if (sequenceString.isPresent())
        partData.setBasePairCount(sequenceString.get().trim().length());
    else
        partData.setBasePairCount(0);
    // todo : remote access check
    if (userId != null && authorization.getOwner(entry) != null && !authorization.getOwner(entry).equalsIgnoreCase(userId)) {
        EntryHistory entryHistory = new EntryHistory(userId, entry.getId());
        entryHistory.add();
    }
    // retrieve more information about linked entries if any (default only contains id)
    if (partData.getLinkedParts() != null) {
        ArrayList<PartData> newLinks = new ArrayList<>();
        for (PartData link : partData.getLinkedParts()) {
            Entry linkedEntry = dao.get(link.getId());
            if (!authorization.canRead(userId, linkedEntry))
                continue;
            link = ModelToInfoFactory.createTipView(linkedEntry);
            Optional<String> linkedSequenceString = sequenceDAO.getSequenceString(linkedEntry);
            if (linkedSequenceString.isPresent()) {
                link.setBasePairCount(linkedSequenceString.get().trim().length());
                link.setFeatureCount(DAOFactory.getSequenceFeatureDAO().getFeatureCount(linkedEntry));
            }
            newLinks.add(link);
        }
        partData.getLinkedParts().clear();
        partData.getLinkedParts().addAll(newLinks);
    }
    // check if there is a parent available
    List<Entry> parents = dao.getParents(entry.getId());
    if (parents == null)
        return partData;
    for (Entry parent : parents) {
        if (!authorization.canRead(userId, parent))
            continue;
        if (parent.getVisibility() != Visibility.OK.getValue() && !authorization.canWrite(userId, entry))
            continue;
        EntryType type = EntryType.nameToType(parent.getRecordType());
        PartData parentData = new PartData(type);
        parentData.setId(parent.getId());
        parentData.setName(parent.getName());
        parentData.setVisibility(Visibility.valueToEnum(parent.getVisibility()));
        partData.getParents().add(parentData);
    }
    return partData;
}
Also used : WebEntries(org.jbei.ice.lib.dto.web.WebEntries)

Example 2 with WebEntries

use of org.jbei.ice.lib.dto.web.WebEntries in project ice by JBEI.

the class SequenceController method retrievePartSequence.

public FeaturedDNASequence retrievePartSequence(String userId, String recordId) {
    Entry entry = getEntry(recordId);
    if (entry == null)
        throw new IllegalArgumentException("The part " + recordId + " could not be located");
    if (entry.getVisibility() == Visibility.REMOTE.getValue()) {
        WebEntries webEntries = new WebEntries();
        return webEntries.getSequence(recordId);
    }
    if (!new PermissionsController().isPubliclyVisible(entry))
        authorization.expectRead(userId, entry);
    boolean canEdit = authorization.canWrite(userId, entry);
    return getFeaturedSequence(entry, canEdit);
}
Also used : HasEntry(org.jbei.ice.lib.entry.HasEntry) WebEntries(org.jbei.ice.lib.dto.web.WebEntries) PermissionsController(org.jbei.ice.lib.access.PermissionsController)

Example 3 with WebEntries

use of org.jbei.ice.lib.dto.web.WebEntries in project ice by JBEI.

the class WebResource method getWebEntry.

@GET
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Path("/entries/{id}")
public Response getWebEntry(@PathParam("id") String entryId) {
    try {
        requireUserId();
        WebEntries webEntries = new WebEntries();
        return super.respond(webEntries.getPart(entryId));
    } catch (Exception e) {
        Logger.error(e);
        throw new WebApplicationException(e);
    }
}
Also used : WebEntries(org.jbei.ice.lib.dto.web.WebEntries)

Aggregations

WebEntries (org.jbei.ice.lib.dto.web.WebEntries)3 PermissionsController (org.jbei.ice.lib.access.PermissionsController)1 HasEntry (org.jbei.ice.lib.entry.HasEntry)1