/** * Handles object deletion via REST. * @param ids the list of object id's (keys) to delete if this is a bulk deletion. * See <a href="http://portofino.manydesigns.com/en/docs/reference/page-types/crud/rest">the CRUD action REST API documentation.</a> * @since 4.2 */ @DELETE @RequiresPermissions(permissions = PERMISSION_DELETE) @Guard(test = "isDeleteEnabled() && (getObject() != null || isBulkOperationsEnabled())", type = GuardType.VISIBLE) public int httpDelete(@QueryParam("id") List<String> ids) throws Exception { if(object == null) { return bulkDelete(ids); } if(ids != null && !ids.isEmpty()) { throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).entity( "DELETE requires either a /objectKey path parameter or a list of id query parameters").build()); } return delete(object); }
public static boolean doGuardsPass(Object actionBean, Method method, @Nullable GuardType type) { List<Guard> guards = getGuards(method, type); boolean pass = true; OgnlContext ognlContext = ElementsThreadLocals.getOgnlContext(); for(Guard guard : guards) { Object result = OgnlUtils.getValueQuietly(guard.test(), ognlContext, actionBean); pass &= result instanceof Boolean && ((Boolean) result); } return pass; }
public static List<Guard> getGuards(Method method, GuardType type) { List<Guard> guardList = new ArrayList<Guard>(); Guard guard = method.getAnnotation(Guard.class); if(guard != null && (type == null || type == guard.type())) { guardList.add(guard); } else { Guards guards = method.getAnnotation(Guards.class); if(guards != null) { for(Guard g : guards.value()) { if(type == null || type == g.type()) { guardList.add(g); } } } } return guardList; }
/** * Handles object update via REST; either a single object or several ones in bulk. * Note: this doesn't support blobs, see {@link #httpPutMultipart()} and * {@link #uploadBlob(String, String, InputStream)}. * See <a href="http://portofino.manydesigns.com/en/docs/reference/page-types/crud/rest">the CRUD action REST API documentation.</a> * @param jsonObject the object (in serialized JSON form) * @param ids the list of object id's (keys) to save if this is a bulk operation. * @since 4.2 * @return the updated object as JSON (in a JAX-RS Response). */ @PUT @RequiresPermissions(permissions = PERMISSION_EDIT) @Produces(MimeTypes.APPLICATION_JSON_UTF8) @Consumes(MimeTypes.APPLICATION_JSON_UTF8) @Guard(test = "isEditEnabled() && (getObject() != null || isBulkOperationsEnabled())", type = GuardType.VISIBLE) public Response httpPutJson(@QueryParam("id") List<String> ids, String jsonObject) { if(object == null) { return bulkUpdate(jsonObject, ids); } if(ids != null && !ids.isEmpty()) { return Response.status(Response.Status.BAD_REQUEST).entity( "You must either PUT a single object (/key) or PUT multiple objects (?ids=...), not both.").build(); } return update(jsonObject); }
public static boolean doGuardsPass(Object actionBean, Method method, @Nullable GuardType type) { List<Guard> guards = getGuards(method, type); boolean pass = true; OgnlContext ognlContext = ElementsThreadLocals.getOgnlContext(); for(Guard guard : guards) { Object result = OgnlUtils.getValueQuietly(guard.test(), ognlContext, actionBean); pass &= result instanceof Boolean && ((Boolean) result); } return pass; }
public static List<Guard> getGuards(Method method, GuardType type) { List<Guard> guardList = new ArrayList<Guard>(); Guard guard = method.getAnnotation(Guard.class); if(guard != null && (type == null || type == guard.type())) { guardList.add(guard); } else { Guards guards = method.getAnnotation(Guards.class); if(guards != null) { for(Guard g : guards.value()) { if(type == null || type == g.type()) { guardList.add(g); } } } } return guardList; }
@Button(key = "delete", list="table-selection-provider", order = 2) @Guard(test = "getSelectionProviderName() != null", type = GuardType.VISIBLE) public Resolution removeSelectionProvider() { table = findTable(); ModelSelectionProvider sp = DatabaseLogic.findSelectionProviderByName(table, selectionProviderName); table.getSelectionProviders().remove(sp); try { saveModel(); } catch (Exception e) { logger.error("Could not save model", e); SessionMessages.addErrorMessage(e.toString()); } return editTable(); }
public static boolean doGuardsPass(Object actionBean, Method method, @Nullable GuardType type) { List<Guard> guards = getGuards(method, type); boolean pass = true; OgnlContext ognlContext = ElementsThreadLocals.getOgnlContext(); for(Guard guard : guards) { Object result = OgnlUtils.getValueQuietly(guard.test(), ognlContext, actionBean); pass &= result instanceof Boolean && ((Boolean) result); } return pass; }
public static List<Guard> getGuards(Method method, GuardType type) { List<Guard> guardList = new ArrayList<Guard>(); Guard guard = method.getAnnotation(Guard.class); if(guard != null && (type == null || type == guard.type())) { guardList.add(guard); } else { Guards guards = method.getAnnotation(Guards.class); if(guards != null) { for(Guard g : guards.value()) { if(type == null || type == g.type()) { guardList.add(g); } } } } return guardList; }
@Produces(MimeTypes.APPLICATION_JSON_UTF8) @Consumes(MediaType.MULTIPART_FORM_DATA) @Guard(test = "isEditEnabled()", type = GuardType.VISIBLE) public Response httpPutMultipart() throws Throwable { if(object == null) {
@PUT @Path(":blob/{propertyName}") @RequiresPermissions(permissions = PERMISSION_EDIT) @Guard(test = "isEditEnabled()", type = GuardType.VISIBLE) public Response uploadBlob( @PathParam("propertyName") String propertyName, @QueryParam("filename") String filename,
@Button(list = "crud-search", key = "create.new", order = 1, type = Button.TYPE_SUCCESS, icon = Button.ICON_PLUS + Button.ICON_WHITE) @RequiresPermissions(permissions = PERMISSION_CREATE) @Guard(test = "isCreateEnabled()", type = GuardType.VISIBLE) public Resolution create() { preCreate(); form.readFromRequest(context.getRequest()); return getCreateView(); }
@Buttons({ @Button(list = "crud-read", key = "edit", order = 1 , icon = Button.ICON_EDIT + Button.ICON_WHITE, group = "crud", type = Button.TYPE_SUCCESS), @Button(list = "crud-read-default-button", key = "search") }) @RequiresPermissions(permissions = PERMISSION_EDIT) @Guard(test = "isEditEnabled()", type = GuardType.VISIBLE) public Resolution edit() { preEdit(); BlobUtils.loadBlobs(form, getBlobManager(), false); return getEditView(); }
@Button(list = "m2m-checkboxes-edit", key = "save", type = Button.TYPE_PRIMARY) @Guard(test = "onePk != null", type = GuardType.VISIBLE) @RequiresPermissions(permissions = ManyToManyAction.PERMISSION_UPDATE) public Resolution saveCheckboxes() throws Exception {
@Button(list = "crud-read", key = "delete", order = 2, icon = Button.ICON_TRASH) @RequiresPermissions(permissions = PERMISSION_DELETE) @Guard(test = "isDeleteEnabled()", type = GuardType.VISIBLE) public Resolution delete() { if(deleteValidate(object)) { try { doDelete(object); deletePostProcess(object); commitTransaction(); deleteBlobs(object); SessionMessages.addInfoMessage(ElementsThreadLocals.getText("object.deleted.successfully")); } catch (Exception e) { String rootCauseMessage = ExceptionUtils.getRootCauseMessage(e); logger.debug(rootCauseMessage, e); SessionMessages.addErrorMessage(rootCauseMessage); return read(); } } return getSuccessfulDeleteView(); }
@Button(list = "crud-bulk", key = "delete", order = 3, icon = Button.ICON_TRASH) }) @Guard(test = "isBulkOperationsEnabled() && isDeleteEnabled()", type = GuardType.VISIBLE) @RequiresPermissions(permissions = PERMISSION_DELETE) public Resolution bulkDelete() {
@Buttons({ @Button(list = "crud-search", key = "edit", order = 2, icon = Button.ICON_EDIT), @Button(list = "crud-bulk", key = "edit", order = 2, icon = Button.ICON_EDIT) }) @Guard(test = "isBulkOperationsEnabled() && isEditEnabled()", type = GuardType.VISIBLE) @RequiresPermissions(permissions = PERMISSION_EDIT) public Resolution bulkEdit() { if (selection == null || selection.length == 0) { SessionMessages.addWarningMessage(ElementsThreadLocals.getText("no.object.was.selected")); return new RedirectResolution(returnUrl, false); } if (selection.length == 1) { pk = selection[0].split("/"); String url = context.getActionPath() + "/" + getPkForUrl(pk); url = appendSearchStringParamIfNecessary(url); return new RedirectResolution(url) .addParameter("returnUrl", returnUrl) .addParameter("edit"); } setupForm(Mode.BULK_EDIT); disableBlobFields(); return getBulkEditView(); }
@Guard(test = "isBulkOperationsEnabled() && isEditEnabled()", type = GuardType.VISIBLE) @RequiresPermissions(permissions = PERMISSION_EDIT) public Resolution bulkUpdate() {
@Button(list = "crud-create", key = "save", order = 1, type = Button.TYPE_PRIMARY) @RequiresPermissions(permissions = PERMISSION_CREATE) @Guard(test = "isCreateEnabled()", type = GuardType.VISIBLE) public Resolution save() { preCreate();
@Button(list = "crud-edit", key = "update", order = 1, type = Button.TYPE_PRIMARY) @RequiresPermissions(permissions = PERMISSION_EDIT) @Guard(test = "isEditEnabled()", type = GuardType.VISIBLE) public Resolution update() { preEdit();