@GET public Blob convert(@QueryParam("converter") String converter, @QueryParam("type") String type, @QueryParam("format") String format, @Context UriInfo uriInfo) { BlobHolder bh = getBlobHolderToConvert(); if (StringUtils.isNotBlank(converter)) { return convertWithConverter(bh, converter, uriInfo); } else if (StringUtils.isNotBlank(type)) { return convertWithMimeType(bh, type, uriInfo); } else if (StringUtils.isNotBlank(format)) { return convertWithFormat(bh, format, uriInfo); } else { throw new IllegalParameterException("No converter, type or format parameter specified"); } }
protected void validateParameters() { if (user == null && (users == null || users.isEmpty()) && email == null) { throw new IllegalParameterException("'users' or 'email' parameters must be set"); } else if (email != null && end == null) { throw new IllegalParameterException("'end' parameter must be set when adding a permission for an 'email'"); } ensureUserListIsUsed(); ConfigurationService configService = Framework.getService(ConfigurationService.class); if (configService.isBooleanPropertyFalse(ALLOW_VIRTUAL_USER)) { UserManager userManager = Framework.getService(UserManager.class); List<String> unknownNames = users.stream() .filter(userOrGroupName -> !isTransientUsername(userOrGroupName) && userManager.getUserModel(userOrGroupName) == null && userManager.getGroupModel(userOrGroupName) == null) .collect(toList()); if (!unknownNames.isEmpty()) { String errorMsg = String.format( "The following set of User or Group names do not exist: [%s]. Please provide valid ones.", String.join(",", unknownNames)); throw new IllegalParameterException(errorMsg); } } }
@GET public DocumentModel getEmptyDocumentModel(@QueryParam("type") String type, @QueryParam("name") String name) { DocumentModel doc = getTarget().getAdapter(DocumentModel.class); CoreSession session = ctx.getCoreSession(); if (StringUtils.isBlank(type)) { throw new IllegalParameterException("Missing type parameter"); } DocumentModel emptyDoc = session.createDocumentModel(doc != null ? doc.getPathAsString() : null, name, type); emptyDoc.detach(false); return emptyDoc; } }
protected Blob convertWithConverter(BlobHolder bh, String converter, UriInfo uriInfo) { ConversionService conversionService = Framework.getService(ConversionService.class); if (!conversionService.isConverterAvailable(converter).isAvailable()) { throw new IllegalParameterException(String.format("The '%s' converter is not available", converter)); } Map<String, Serializable> parameters = computeConversionParameters(uriInfo); BlobHolder blobHolder = conversionService.convert(converter, bh, parameters); Blob conversionBlob = blobHolder.getBlob(); if (conversionBlob == null) { throw new WebResourceNotFoundException(String.format("No converted Blob using '%s' converter", converter)); } return conversionBlob; }
conversionId = conversionService.scheduleConversionToMimeType(mimeType, bh, parameters); } else { throw new IllegalParameterException("No converter, type or format parameter specified");
private String extractQueryFromRequest(final HttpServletRequest request) { String query = request.getParameter("query"); if (query == null) { String fullText = request.getParameter("fullText"); if (fullText == null) { throw new IllegalParameterException("Expecting a query or a fullText parameter"); } String orderBy = request.getParameter("orderBy"); String orderClause = ""; if (orderBy != null) { orderClause = " ORDER BY " + orderBy; } String path; DocumentModel doc = getTarget().getAdapter(DocumentModel.class); if (doc.isFolder()) { path = doc.getPathAsString(); } else { path = doc.getPath().removeLastSegments(1).toString(); } query = "SELECT * FROM Document WHERE (ecm:fulltext = \"" + fullText + "\") AND (ecm:isVersion = 0) AND (ecm:path STARTSWITH \"" + path + "\")" + orderClause; } return query; }
fileSize = Long.parseLong(fileSizeHeader); } catch (NumberFormatException e) { throw new IllegalParameterException( "X-Upload-Chunk-Index, X-Upload-Chunk-Count and X-File-Size headers must be numbers");
@GET @Path("@search") public Object search() { final HttpServletRequest request = ctx.getRequest(); String query = request.getParameter("query"); if (query == null) { String fullText = request.getParameter("fullText"); if (fullText == null) { throw new IllegalParameterException("Expecting a query or a fullText parameter"); } String orderBy = request.getParameter("orderBy"); String orderClause = ""; if (orderBy != null) { orderClause = " ORDER BY " + orderBy; } String path; if (doc.isFolder()) { path = doc.getPathAsString(); } else { path = doc.getPath().removeLastSegments(1).toString(); } query = "SELECT * FROM Document WHERE (ecm:fulltext = \"" + fullText + "\") AND (ecm:isVersion = 0) AND (ecm:path STARTSWITH \"" + path + "\")" + orderClause; } DocumentModelList docs = ctx.getCoreSession().query(query); return getView("search").arg("query", query).arg("result", docs); }
@POST public Response doPost(@FormParam("text") String cText) { if (cText == null) { throw new IllegalParameterException("Expecting a 'text' parameter"); } DocumentObject dobj = (DocumentObject) getTarget(); CoreSession session = dobj.getCoreSession(); DocumentModel pageDoc = dobj.getDocument(); DocumentModel comment = session.createDocumentModel("Comment"); comment.setPropertyValue("comment:author", session.getPrincipal().getName()); comment.setPropertyValue("comment:text", cText); comment.setPropertyValue("comment:creationDate", new Date()); comment = createCommentDocument(session, pageDoc, comment); session.save(); publishComment(session, pageDoc, comment); return redirect(getTarget().getPath()); }
xpath = "file:content"; } else { throw new IllegalParameterException( "Missing request parameter named 'property' that specify the blob property xpath to fetch");
protected void removePermission(DocumentModel doc) { if (id == null && user == null) { throw new IllegalParameterException("'id' or 'user' parameter must be set"); } ACP acp = doc.getACP() != null ? doc.getACP() : new ACPImpl(); boolean permissionChanged = false; if (user != null) { permissionChanged = acp.removeACEsByUsername(aclName, user); } else if (id != null) { ACE ace = ACE.fromId(id); permissionChanged = acp.removeACE(aclName, ace); } if (permissionChanged) { doc.setACP(acp, true); } }
protected BlobHolder getBlobHolderToConvert() { Blob blob = getTarget().getAdapter(Blob.class); BlobHolder bh = null; if (blob == null) { DocumentModel doc = getTarget().getAdapter(DocumentModel.class); if (doc != null) { bh = doc.getAdapter(BlobHolder.class); if (bh != null) { blob = bh.getBlob(); } } } if (blob == null) { throw new IllegalParameterException("No Blob found"); } if (getTarget().isInstanceOf("blob")) { bh = ((BlobObject) getTarget()).getBlobHolder(); } if (bh == null) { bh = new SimpleBlobHolder(blob); } return bh; }