diff --git a/pom.xml b/pom.xml index 45b42bcd6..a0873b6d1 100755 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.jbei ice war - 4.1.17 + 4.1.18 ice Inventory of Composable Elements (ICE) for Synthetic Biology diff --git a/src/main/java/org/jbei/ice/lib/dao/hibernate/PermissionDAO.java b/src/main/java/org/jbei/ice/lib/dao/hibernate/PermissionDAO.java index 11b384aff..523894837 100755 --- a/src/main/java/org/jbei/ice/lib/dao/hibernate/PermissionDAO.java +++ b/src/main/java/org/jbei/ice/lib/dao/hibernate/PermissionDAO.java @@ -347,6 +347,35 @@ public List getCanReadEntries(Account account, Set groups, Listall the entries specified in the parameter + */ + public boolean canWrite(Account account, Set groups, List entries) { + Criteria criteria = currentSession().createCriteria(Permission.class); + Disjunction disjunction = Restrictions.disjunction(); + disjunction.add(Restrictions.and(Restrictions.eq("account", account), Restrictions.eq("canWrite", true))); + disjunction.add(Restrictions.eq("entry.ownerEmail", account.getEmail())); + + if (!groups.isEmpty()) { + disjunction.add(Restrictions.and(Restrictions.in("group", groups), Restrictions.eq("canWrite", true))); + } + + criteria.createAlias("entry", "entry", JoinType.LEFT_OUTER_JOIN) + .add(Restrictions.in("entry.id", entries)) + .add(Restrictions.eq("entry.visibility", Visibility.OK.getValue())); + + criteria.add(disjunction); + criteria.setProjection(Projections.distinct(Projections.property("entry.id"))); + + Number number = (Number) criteria.setProjection(Projections.rowCount()).uniqueResult(); + return number.intValue() == entries.size(); + } + @Override public Permission get(long id) { return super.get(Permission.class, id); diff --git a/src/main/java/org/jbei/ice/lib/entry/Entries.java b/src/main/java/org/jbei/ice/lib/entry/Entries.java new file mode 100644 index 000000000..0b2aa89cb --- /dev/null +++ b/src/main/java/org/jbei/ice/lib/entry/Entries.java @@ -0,0 +1,45 @@ +package org.jbei.ice.lib.entry; + +import org.jbei.ice.lib.account.AccountController; +import org.jbei.ice.lib.account.model.Account; +import org.jbei.ice.lib.dao.DAOFactory; +import org.jbei.ice.lib.dao.hibernate.EntryDAO; +import org.jbei.ice.lib.dao.hibernate.PermissionDAO; +import org.jbei.ice.lib.dto.entry.Visibility; +import org.jbei.ice.lib.entry.model.Entry; +import org.jbei.ice.lib.group.Group; +import org.jbei.ice.lib.group.GroupController; + +import java.util.List; +import java.util.Set; + +/** + * @author Hector Plahar + */ +public class Entries { + + private final EntryDAO dao; + + public Entries() { + this.dao = DAOFactory.getEntryDAO(); + } + + public boolean updateVisibility(String userId, List entryIds, Visibility visibility) { + Account account = DAOFactory.getAccountDAO().getByEmail(userId); + Set accountGroups = new GroupController().getAllGroups(account); + PermissionDAO permissionDAO = DAOFactory.getPermissionDAO(); + if (!new AccountController().isAdministrator(userId) && !permissionDAO.canWrite(account, accountGroups, entryIds)) + return false; + + for (long entryId : entryIds) { + Entry entry = dao.get(entryId); + if (entry.getVisibility() == visibility.getValue()) + continue; + + entry.setVisibility(visibility.getValue()); + dao.update(entry); + } + + return true; + } +} diff --git a/src/main/java/org/jbei/ice/lib/entry/EntryController.java b/src/main/java/org/jbei/ice/lib/entry/EntryController.java index 391e29c0a..cdaf81f7b 100755 --- a/src/main/java/org/jbei/ice/lib/entry/EntryController.java +++ b/src/main/java/org/jbei/ice/lib/entry/EntryController.java @@ -173,6 +173,50 @@ public long getNumberOfOwnerEntries(String requesterUserEmail, String ownerEmail return dao.ownerEntryCount(account, ownerEmail, accountGroups); } + /** + * Determines if the two entries can be linked + * + * @param entry parent in link hierarchy + * @param link child in link hierarchy + * @return true if the two entries can be linked in the hierarchy specified + */ + private boolean canLink(Entry entry, Entry link) { + if (entry == null || link == null || entry.getId() == link.getId()) + return false; + + if (link.getLinkedEntries().contains(entry)) + return false; + + EntryType linkedType = EntryType.nameToType(link.getRecordType()); + EntryType type = EntryType.nameToType(entry.getRecordType()); + if (type == null || linkedType == null) + return false; + + switch (type) { + case PLASMID: + if (linkedType != type && linkedType != EntryType.PART) + return false; + break; + + case PART: + if (linkedType != type) + return false; + break; + + case STRAIN: + if (linkedType != type && linkedType != EntryType.PLASMID && linkedType != EntryType.PART) + return false; + break; + + case ARABIDOPSIS: + if (linkedType != type && linkedType != EntryType.PART) + return false; + break; + } + + return true; + } + public long updatePart(String userId, long partId, PartData part) { Entry existing = dao.get(partId); authorization.expectWrite(userId, existing); @@ -182,13 +226,15 @@ public long updatePart(String userId, long partId, PartData part) { if (part.getLinkedParts() != null && part.getLinkedParts().size() > 0) { for (PartData data : part.getLinkedParts()) { Entry linked = dao.getByPartNumber(data.getPartId()); - if (linked == null) - continue; + // check permissions on link if (!authorization.canRead(userId, linked)) { continue; } + if (!canLink(entry, linked)) + continue; + entry.getLinkedEntries().add(linked); } } diff --git a/src/main/java/org/jbei/ice/services/rest/ArrayDataJSONHandler.java b/src/main/java/org/jbei/ice/services/rest/ArrayDataJSONHandler.java index 0d8b33feb..80c7ec856 100644 --- a/src/main/java/org/jbei/ice/services/rest/ArrayDataJSONHandler.java +++ b/src/main/java/org/jbei/ice/services/rest/ArrayDataJSONHandler.java @@ -1,15 +1,9 @@ package org.jbei.ice.services.rest; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.Reader; -import java.io.Writer; -import java.lang.annotation.Annotation; -import java.lang.reflect.Type; -import java.util.ArrayList; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import org.jbei.ice.lib.dao.IDataTransferModel; + import javax.ws.rs.Consumes; import javax.ws.rs.Produces; import javax.ws.rs.WebApplicationException; @@ -18,13 +12,10 @@ import javax.ws.rs.ext.MessageBodyReader; import javax.ws.rs.ext.MessageBodyWriter; import javax.ws.rs.ext.Provider; - -import org.jbei.ice.lib.dao.IDataTransferModel; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonElement; -import com.google.gson.reflect.TypeToken; +import java.io.*; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; +import java.util.ArrayList; /** * @author Hector Plahar diff --git a/src/main/java/org/jbei/ice/services/rest/PartDataJSONHandler.java b/src/main/java/org/jbei/ice/services/rest/PartDataJSONHandler.java index 72f2bb9dc..267fc47b2 100644 --- a/src/main/java/org/jbei/ice/services/rest/PartDataJSONHandler.java +++ b/src/main/java/org/jbei/ice/services/rest/PartDataJSONHandler.java @@ -1,14 +1,9 @@ package org.jbei.ice.services.rest; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.Reader; -import java.io.Writer; -import java.lang.annotation.Annotation; -import java.lang.reflect.Type; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import org.jbei.ice.lib.dao.IDataTransferModel; + import javax.ws.rs.Consumes; import javax.ws.rs.Produces; import javax.ws.rs.WebApplicationException; @@ -17,11 +12,9 @@ import javax.ws.rs.ext.MessageBodyReader; import javax.ws.rs.ext.MessageBodyWriter; import javax.ws.rs.ext.Provider; - -import org.jbei.ice.lib.dao.IDataTransferModel; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; +import java.io.*; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; /** * Custom Writer and Reader for classes that extend {@link IDataTransferModel} using GSON for JSON conversion @@ -36,8 +29,6 @@ public class PartDataJSONHandler @Override public boolean isWriteable(Class type, Type genericType, Annotation[] annotations, MediaType mediaType) { -// return type == PartData.class || type == PlasmidData.class || type == StrainData.class || type == -// ArabidopsisSeedData.class; return true; } @@ -59,8 +50,6 @@ public void writeTo(IDataTransferModel data, Class type, Type genericType, An @Override public boolean isReadable(Class type, Type genericType, Annotation[] annotations, MediaType mediaType) { -// return type == PartData.class || type == PlasmidData.class || type == StrainData.class || type == -// ArabidopsisSeedData.class; return true; } diff --git a/src/main/java/org/jbei/ice/services/rest/PartResource.java b/src/main/java/org/jbei/ice/services/rest/PartResource.java index ac7d6d5a9..4ae1e0b0d 100644 --- a/src/main/java/org/jbei/ice/services/rest/PartResource.java +++ b/src/main/java/org/jbei/ice/services/rest/PartResource.java @@ -17,6 +17,7 @@ import org.jbei.ice.lib.dto.entry.*; import org.jbei.ice.lib.dto.permission.AccessPermission; import org.jbei.ice.lib.dto.sample.PartSample; +import org.jbei.ice.lib.entry.Entries; import org.jbei.ice.lib.entry.EntryController; import org.jbei.ice.lib.entry.EntryCreator; import org.jbei.ice.lib.entry.EntryRetriever; @@ -39,6 +40,7 @@ import java.lang.reflect.Type; import java.nio.file.Paths; import java.util.ArrayList; +import java.util.List; import java.util.Set; /** @@ -59,8 +61,8 @@ public class PartResource extends RestResource { @Produces(MediaType.APPLICATION_JSON) @Path("/autocomplete") public ArrayList autoComplete(@QueryParam("val") String val, - @DefaultValue("SELECTION_MARKERS") @QueryParam("field") String field, - @DefaultValue("8") @QueryParam("limit") int limit) { + @DefaultValue("SELECTION_MARKERS") @QueryParam("field") String field, + @DefaultValue("8") @QueryParam("limit") int limit) { AutoCompleteField autoCompleteField = AutoCompleteField.valueOf(field.toUpperCase()); Set result = retriever.getMatchingAutoCompleteField(autoCompleteField, val, limit); return new ArrayList<>(result); @@ -70,7 +72,7 @@ public ArrayList autoComplete(@QueryParam("val") String val, @Produces(MediaType.APPLICATION_JSON) @Path("/autocomplete/partid") public ArrayList autoComplete(@QueryParam("token") String token, - @DefaultValue("8") @QueryParam("limit") int limit) { + @DefaultValue("8") @QueryParam("limit") int limit) { return retriever.getMatchingPartNumber(token, limit); } @@ -82,8 +84,8 @@ public ArrayList autoComplete(@QueryParam("token") String token, @Produces(MediaType.APPLICATION_JSON) @Path("/{id}") public Response read(@Context UriInfo info, - @PathParam("id") String id, - @HeaderParam(value = "X-ICE-Authentication-SessionId") String sessionId) { + @PathParam("id") String id, + @HeaderParam(value = "X-ICE-Authentication-SessionId") String sessionId) { String userId = SessionHandler.getUserIdBySession(sessionId); try { log(userId, "retrieving details for " + id); @@ -104,7 +106,7 @@ public Response read(@Context UriInfo info, @Produces(MediaType.APPLICATION_JSON) @Path("/{id}/tooltip") public PartData getTooltipDetails(@PathParam("id") String id, - @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader) { + @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader) { String userId = SessionHandler.getUserIdBySession(userAgentHeader); return controller.retrieveEntryTipDetails(userId, id); } @@ -113,7 +115,7 @@ public PartData getTooltipDetails(@PathParam("id") String id, @Produces(MediaType.APPLICATION_JSON) @Path("/{id}/permissions") public ArrayList getPermissions(@Context UriInfo info, @PathParam("id") String id, - @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader) { + @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader) { String userId = getUserIdFromSessionHeader(userAgentHeader); return retriever.getEntryPermissions(userId, id); } @@ -122,8 +124,8 @@ public ArrayList getPermissions(@Context UriInfo info, @PathPa @Produces(MediaType.APPLICATION_JSON) @Path("/{id}/permissions") public PartData setPermissions(@Context UriInfo info, @PathParam("id") long partId, - ArrayList permissions, - @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader) { + ArrayList permissions, + @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader) { String userId = getUserIdFromSessionHeader(userAgentHeader); return permissionsController.setEntryPermissions(userId, partId, permissions); } @@ -132,7 +134,7 @@ public PartData setPermissions(@Context UriInfo info, @PathParam("id") long part @Produces(MediaType.APPLICATION_JSON) @Path("/{id}/experiments") public Response getPartExperiments(@PathParam("id") long partId, - @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader) { + @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader) { String userId = getUserIdFromSessionHeader(userAgentHeader); ArrayList studies = experimentController.getPartStudies(userId, partId); if (studies == null) @@ -144,8 +146,8 @@ public Response getPartExperiments(@PathParam("id") long partId, @Produces(MediaType.APPLICATION_JSON) @Path("/{id}/experiments") public Response getPartExperiments(@PathParam("id") long partId, - @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader, - Study study) { + @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader, + Study study) { String userId = getUserIdFromSessionHeader(userAgentHeader); study = experimentController.createStudy(userId, partId, study); return respond(Response.Status.OK, study); @@ -155,7 +157,7 @@ public Response getPartExperiments(@PathParam("id") long partId, @Produces(MediaType.APPLICATION_JSON) @Path("/{id}/permissions/public") public Response enablePublicAccess(@Context UriInfo info, @PathParam("id") long partId, - @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader) { + @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader) { String userId = getUserIdFromSessionHeader(userAgentHeader); if (permissionsController.enablePublicReadAccess(userId, partId)) return respond(Response.Status.OK); @@ -166,7 +168,7 @@ public Response enablePublicAccess(@Context UriInfo info, @PathParam("id") long @Produces(MediaType.APPLICATION_JSON) @Path("/{id}/permissions/public") public Response disablePublicAccess(@Context UriInfo info, @PathParam("id") long partId, - @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader) { + @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader) { String userId = getUserIdFromSessionHeader(userAgentHeader); if (permissionsController.disablePublicReadAccess(userId, partId)) return respond(Response.Status.OK); @@ -177,8 +179,8 @@ public Response disablePublicAccess(@Context UriInfo info, @PathParam("id") long @Produces(MediaType.APPLICATION_JSON) @Path("/{id}/permissions") public AccessPermission createPermission(@Context UriInfo info, @PathParam("id") long partId, - AccessPermission permission, - @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader) { + AccessPermission permission, + @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader) { String userId = getUserIdFromSessionHeader(userAgentHeader); return permissionsController.createPermission(userId, partId, permission); } @@ -187,9 +189,9 @@ public AccessPermission createPermission(@Context UriInfo info, @PathParam("id") @Produces(MediaType.APPLICATION_JSON) @Path("/{id}/permissions/{permissionId}") public Response removePermission(@Context UriInfo info, - @PathParam("id") long partId, - @PathParam("permissionId") long permissionId, - @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader) { + @PathParam("id") long partId, + @PathParam("permissionId") long permissionId, + @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader) { String userId = getUserIdFromSessionHeader(userAgentHeader); permissionsController.removeEntryPermission(userId, partId, permissionId); return Response.ok().build(); @@ -199,7 +201,7 @@ public Response removePermission(@Context UriInfo info, @Produces(MediaType.APPLICATION_JSON) @Path("/{id}/statistics") public PartStatistics getStatistics(@PathParam("id") long partId, - @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader) { + @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader) { String userId = SessionHandler.getUserIdBySession(userAgentHeader); return controller.retrieveEntryStatistics(userId, partId); } @@ -208,7 +210,7 @@ public PartStatistics getStatistics(@PathParam("id") long partId, @Produces(MediaType.APPLICATION_JSON) @Path("/{id}/comments") public ArrayList getComments(@Context UriInfo info, @PathParam("id") long partId, - @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader) { + @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader) { String userId = SessionHandler.getUserIdBySession(userAgentHeader); return controller.retrieveEntryComments(userId, partId); } @@ -217,8 +219,8 @@ public ArrayList getComments(@Context UriInfo info, @PathParam("id" @Produces(MediaType.APPLICATION_JSON) @Path("/{id}/comments") public Response createComment(@PathParam("id") long partId, - @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader, - UserComment userComment) { + @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader, + UserComment userComment) { // if(userComment == null || userComment.getMessage() == null) // throw new Web // todo : check for null @@ -232,9 +234,9 @@ public Response createComment(@PathParam("id") long partId, @Produces(MediaType.APPLICATION_JSON) @Path("/{id}/comments/{commentId}") public UserComment updateComment(@PathParam("id") long partId, - @PathParam("commentId") long commentId, - @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader, - UserComment userComment) { + @PathParam("commentId") long commentId, + @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader, + UserComment userComment) { String userId = getUserIdFromSessionHeader(userAgentHeader); return controller.updateEntryComment(userId, partId, commentId, userComment); } @@ -244,8 +246,8 @@ public UserComment updateComment(@PathParam("id") long partId, @Consumes(MediaType.APPLICATION_JSON) @Path("/{id}/attachments") public AttachmentInfo addAttachment(@PathParam("id") long partId, - @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader, - AttachmentInfo attachment) { + @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader, + AttachmentInfo attachment) { // todo : check for null String userId = getUserIdFromSessionHeader(userAgentHeader); AttachmentController attachmentController = new AttachmentController(); @@ -256,7 +258,7 @@ public AttachmentInfo addAttachment(@PathParam("id") long partId, @Produces(MediaType.APPLICATION_JSON) @Path("/{id}/attachments") public ArrayList getAttachments(@PathParam("id") long partId, - @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader) { + @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader) { String userId = SessionHandler.getUserIdBySession(userAgentHeader); return attachmentController.getByEntry(userId, partId); } @@ -264,9 +266,9 @@ public ArrayList getAttachments(@PathParam("id") long partId, @DELETE @Path("/{id}/attachments/{attachmentId}") public Response deleteAttachment(@Context UriInfo info, - @PathParam("id") long partId, - @PathParam("attachmentId") long attachmentId, - @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader) { + @PathParam("id") long partId, + @PathParam("attachmentId") long attachmentId, + @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader) { String userId = getUserIdFromSessionHeader(userAgentHeader); if (!attachmentController.delete(userId, partId, attachmentId)) return Response.notModified().build(); // todo : use 404 ? @@ -277,9 +279,9 @@ public Response deleteAttachment(@Context UriInfo info, @Produces(MediaType.APPLICATION_JSON) @Path("/{id}/history") public ArrayList getHistory(@Context UriInfo info, - @PathParam("id") long partId, - @QueryParam("sid") String sessionId, - @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader) { + @PathParam("id") long partId, + @QueryParam("sid") String sessionId, + @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader) { if (StringUtils.isEmpty(userAgentHeader)) userAgentHeader = sessionId; String userId = getUserIdFromSessionHeader(userAgentHeader); @@ -290,8 +292,8 @@ public ArrayList getHistory(@Context UriInfo info, @Produces(MediaType.APPLICATION_JSON) @Path("/{id}/history/{historyId}") public Response delete(@PathParam("id") long partId, - @PathParam("historyId") long historyId, - @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader) { + @PathParam("historyId") long historyId, + @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader) { String userId = getUserIdFromSessionHeader(userAgentHeader); boolean success = controller.deleteHistory(userId, partId, historyId); return super.respond(success); @@ -301,9 +303,9 @@ public Response delete(@PathParam("id") long partId, @Produces(MediaType.APPLICATION_JSON) @Path("/{id}/traces") public ArrayList getTraces(@Context UriInfo info, - @PathParam("id") long partId, - @QueryParam("sid") String sessionId, - @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader) { + @PathParam("id") long partId, + @QueryParam("sid") String sessionId, + @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader) { if (StringUtils.isEmpty(userAgentHeader)) userAgentHeader = sessionId; String userId = SessionHandler.getUserIdBySession(userAgentHeader); @@ -314,10 +316,10 @@ public ArrayList getTraces(@Context UriInfo info, @Produces(MediaType.APPLICATION_JSON) @Path("/{id}/traces") public Response addTraceSequence(@PathParam("id") long partId, - @FormDataParam("file") InputStream fileInputStream, - @FormDataParam("file") FormDataContentDisposition contentDispositionHeader, - @QueryParam("sid") String sessionId, - @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader) { + @FormDataParam("file") InputStream fileInputStream, + @FormDataParam("file") FormDataContentDisposition contentDispositionHeader, + @QueryParam("sid") String sessionId, + @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader) { if (StringUtils.isEmpty(userAgentHeader)) userAgentHeader = sessionId; String userId = getUserIdFromSessionHeader(userAgentHeader); @@ -337,8 +339,8 @@ public Response addTraceSequence(@PathParam("id") long partId, @DELETE @Path("/{id}/traces/{traceId}") public Response deleteTrace(@Context UriInfo info, @PathParam("id") long partId, - @PathParam("traceId") long traceId, - @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader) { + @PathParam("traceId") long traceId, + @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader) { String userId = getUserIdFromSessionHeader(userAgentHeader); if (!controller.deleteTraceSequence(userId, partId, traceId)) return super.respond(Response.Status.UNAUTHORIZED); @@ -349,7 +351,7 @@ public Response deleteTrace(@Context UriInfo info, @PathParam("id") long partId, @Produces(MediaType.APPLICATION_JSON) @Path("/{id}/samples") public ArrayList getSamples(@Context UriInfo info, @PathParam("id") long partId, - @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader) { + @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader) { String userId = SessionHandler.getUserIdBySession(userAgentHeader); return sampleController.retrieveEntrySamples(userId, partId); } @@ -359,8 +361,8 @@ public ArrayList getSamples(@Context UriInfo info, @PathParam("id") @Path("/{id}/samples") public ArrayList addSample(@Context UriInfo info, @PathParam("id") long partId, @QueryParam("strainNamePrefix") String strainNamePrefix, - @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader, - PartSample partSample) { + @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader, + PartSample partSample) { String userId = SessionHandler.getUserIdBySession(userAgentHeader); log(userId, "creating sample for part " + partId); sampleController.createSample(userId, partId, partSample, strainNamePrefix); @@ -371,8 +373,8 @@ public ArrayList addSample(@Context UriInfo info, @PathParam("id") l @Produces(MediaType.APPLICATION_JSON) @Path("/{id}/samples/{sampleId}") public Response deleteSample(@Context UriInfo info, @PathParam("id") long partId, - @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader, - @PathParam("sampleId") long sampleId) { + @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader, + @PathParam("sampleId") long sampleId) { String userId = SessionHandler.getUserIdBySession(userAgentHeader); boolean success = sampleController.delete(userId, partId, sampleId); return super.respond(success); @@ -382,8 +384,8 @@ public Response deleteSample(@Context UriInfo info, @PathParam("id") long partId @Produces(MediaType.APPLICATION_JSON) @Path("/{id}/sequence") public Response getSequence(@PathParam("id") long partId, - @QueryParam("sid") String sessionId, - @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader) { + @QueryParam("sid") String sessionId, + @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader) { if (StringUtils.isEmpty(userAgentHeader)) userAgentHeader = sessionId; @@ -398,9 +400,9 @@ public Response getSequence(@PathParam("id") long partId, @Produces(MediaType.APPLICATION_JSON) @Path("/{id}/sequence") public FeaturedDNASequence updateSequence(@PathParam("id") long partId, - @QueryParam("sid") String sessionId, - FeaturedDNASequence sequence, - @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader) { + @QueryParam("sid") String sessionId, + FeaturedDNASequence sequence, + @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader) { if (StringUtils.isEmpty(userAgentHeader)) userAgentHeader = sessionId; @@ -411,8 +413,8 @@ public FeaturedDNASequence updateSequence(@PathParam("id") long partId, @DELETE @Path("/{id}/sequence") public Response deleteSequence(@PathParam("id") long partId, - @QueryParam("sid") String sessionId, - @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader) { + @QueryParam("sid") String sessionId, + @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader) { String userId = getUserIdFromSessionHeader(userAgentHeader); try { if (sequenceController.deleteSequence(userId, partId)) @@ -424,12 +426,12 @@ public Response deleteSequence(@PathParam("id") long partId, } } - @PUT + @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public PartData create(@Context UriInfo info, - @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader, - PartData partData) { + @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader, + PartData partData) { String userId = getUserIdFromSessionHeader(userAgentHeader); EntryCreator creator = new EntryCreator(); long id = creator.createPart(userId, partData); @@ -453,9 +455,9 @@ public Response transfer(PartData partData) { @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public PartData update(@Context UriInfo info, - @PathParam("id") long partId, - @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader, - PartData partData) { + @PathParam("id") long partId, + @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader, + PartData partData) { String userId = getUserIdFromSessionHeader(userAgentHeader); long id = controller.updatePart(userId, partId, partData); log(userId, "updated entry " + id); @@ -473,7 +475,7 @@ public void delete(@PathParam("id") long id) { @Path("/trash") @Consumes(MediaType.APPLICATION_JSON) public Response moveToTrash(ArrayList list, - @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader) { + @HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader) { String userId = getUserIdFromSessionHeader(userAgentHeader); Type fooType = new TypeToken>() { }.getType(); @@ -494,11 +496,27 @@ public Response moveToTrash(ArrayList list, @DELETE @Path("/{id}/links/{linkedId}") public Response deleteLink(@PathParam("id") long partId, - @PathParam("linkedId") long linkedPart, - @HeaderParam(value = "X-ICE-Authentication-SessionId") String sessionId) { + @PathParam("linkedId") long linkedPart, + @HeaderParam(value = "X-ICE-Authentication-SessionId") String sessionId) { String userId = getUserIdFromSessionHeader(sessionId); log(userId, "removing link " + linkedPart + " from " + partId); boolean success = controller.removeLink(userId, partId, linkedPart); return respond(success); } + + @PUT + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public Response updateEntries(@HeaderParam(value = "X-ICE-Authentication-SessionId") String sessionId, + @QueryParam(value = "visibility") Visibility visibility, + List entryIds) { + String userId = getUserIdFromSessionHeader(sessionId); + log(userId, "updating visibility of " + entryIds.size() + " entries to " + visibility); + Entries entries = new Entries(); + List arrayList = new ArrayList<>(); + for (Number id : entryIds) + arrayList.add(id.longValue()); + boolean success = entries.updateVisibility(userId, arrayList, visibility); + return super.respond(success); + } } diff --git a/src/main/java/org/jbei/ice/servlet/InfoToModelFactory.java b/src/main/java/org/jbei/ice/servlet/InfoToModelFactory.java index 668077cdb..6b1a34a90 100755 --- a/src/main/java/org/jbei/ice/servlet/InfoToModelFactory.java +++ b/src/main/java/org/jbei/ice/servlet/InfoToModelFactory.java @@ -153,7 +153,7 @@ protected static Entry setSeedFields(ArabidopsisSeedData seedData, Entry entry) public static Entry updateEntryField(PartData data, Entry entry) { EntryType type = data.getType(); if (type == null) - return null; + return entry; switch (type) { case PLASMID: @@ -170,9 +170,6 @@ public static Entry updateEntryField(PartData data, Entry entry) { case ARABIDOPSIS: entry = setSeedFields(data.getArabidopsisSeedData(), entry); break; - - default: - return null; } entry = setCommon(entry, data); diff --git a/src/main/webapp/index.html b/src/main/webapp/index.html index 91495de9c..e3b562744 100755 --- a/src/main/webapp/index.html +++ b/src/main/webapp/index.html @@ -38,6 +38,7 @@ + @@ -133,7 +134,7 @@ Help -
  |   v4.1.17
+
  |   v4.1.18
diff --git a/src/main/webapp/scripts/admin/adminController.js b/src/main/webapp/scripts/admin/adminController.js index 7795ed41c..e474e58dd 100644 --- a/src/main/webapp/scripts/admin/adminController.js +++ b/src/main/webapp/scripts/admin/adminController.js @@ -138,18 +138,25 @@ angular.module('ice.admin.controller', []) }); }; }) - .controller('AdminTransferredEntriesController', function ($rootScope, $cookieStore, $filter, $location, $scope, Folders, Entry) { + .controller('AdminTransferredEntriesController', function ($rootScope, $cookieStore, $filter, $location, $scope, Folders, Entry, Util) { $scope.maxSize = 5; $scope.currentPage = 1; + $scope.selectedTransferredEntries = []; + var params = {folderId: 'transferred'}; // get all entries that are transferred $scope.transferredEntries = undefined; - Folders().folder(params, function (result) { - $scope.transferredEntries = result; - }, function (error) { - console.error(error); - }); + + var getTransferredEntries = function () { + Folders().folder(params, function (result) { + $scope.transferredEntries = result; + $scope.selectedTransferredEntries = []; + }, function (error) { + console.error(error); + }); + }; + getTransferredEntries(); $scope.setPage = function (pageNo) { if (pageNo == undefined || isNaN(pageNo)) @@ -168,9 +175,30 @@ angular.module('ice.admin.controller', []) }; $scope.acceptEntries = function () { + var successHandler = function (result) { + getTransferredEntries(); + }; + + Util.update("/rest/parts", $scope.selectedTransferredEntries, {visibility: "OK"}, successHandler); }; $scope.rejectEntries = function () { + var successHandler = function (result) { + getTransferredEntries(); + }; + + Util.update("/rest/parts", $scope.selectedTransferredEntries, {visibility: "DELETED"}, successHandler); + }; + + $scope.selectTransferredEntry = function (entry) { + var index = $scope.selectedTransferredEntries.indexOf(entry.id); + if (index != -1) { + $scope.selectedTransferredEntries.splice(index, 1); + return; + } + + // add to selected + $scope.selectedTransferredEntries.push(entry.id); }; $scope.showEntryDetails = function (entry, index) { diff --git a/src/main/webapp/scripts/admin/transferred.html b/src/main/webapp/scripts/admin/transferred.html index c6e615bee..607406b09 100644 --- a/src/main/webapp/scripts/admin/transferred.html +++ b/src/main/webapp/scripts/admin/transferred.html @@ -1,10 +1,12 @@
-   -
@@ -15,11 +17,11 @@ - + + + {{selection.length}} + ng-show="selectedTransferredEntries.length>0">{{selectedTransferredEntries.length}} - + {{entry.type | capitalize}} -

Link Entry

+

  Link Entry