protected void handleAllContentTypes( ContentProfileProvider modelProvider, SubmissionTemplate template, Submission.Builder submissionBuilder, Attachment attachment, String actingAsId) throws PieceworkException { ContentDisposition contentDisposition = attachment.getContentDisposition(); MediaType mediaType = attachment.getContentType(); if (contentDisposition != null) { String contentType = mediaType.toString(); String name = sanitizer.sanitize(contentDisposition.getParameter("name")); String filename = sanitizer.sanitize(contentDisposition.getParameter("filename")); if (StringUtils.isNotEmpty(filename)) { if (LOG.isDebugEnabled()) LOG.debug( "Processing multipart with content type " + contentType + " content id " + attachment.getContentId() + " and filename " + filename); try { if (!submissionStorageService.store( modelProvider, template, submissionBuilder, name, filename, actingAsId, attachment.getDataHandler().getInputStream(), contentType)) { LOG.warn( "Submission included field (" + name + ") that is not acceptable, and no attachments are allowed for this template"); } } catch (IOException e) { LOG.warn( "Unable to store file with content type " + contentType + " and filename " + filename); } } else if (mediaType.equals(MediaType.TEXT_PLAIN_TYPE)) { handlePlaintext(modelProvider, template, submissionBuilder, attachment, actingAsId); } } }
@POST @Path("/") public Response addDatastreams( @PathParam("pid") final String pid, final List<Attachment> attachmentList) throws RepositoryException, IOException { final Session session = repo.login(); try { Long oldObjectSize = getObjectSize(session.getNode(getObjectJcrNodePath(pid))); for (final Attachment a : attachmentList) { final String dsid = a.getContentDisposition().getParameter("name"); final String dsPath = getDatastreamJcrNodePath(pid, dsid); createDatastreamNode( session, dsPath, a.getDataHandler().getContentType(), a.getDataHandler().getInputStream()); } session.save(); /* * we save before updating the repo size because the act of * persisting session state creates new system-curated nodes and * properties which contribute to the footprint of this resource */ updateRepositorySize( getObjectSize(session.getNode(getObjectJcrNodePath(pid))) - oldObjectSize, session); // now we save again to persist the repo size session.save(); } finally { session.logout(); } return created(uriInfo.getAbsolutePath()).build(); }