private Object myDoubleAction(EntityView view) { MyEntity me = (MyEntity) getEntity(view.getEntityReference()); MyEntity togo = me.copy(); togo.setNumber(togo.getNumber() * 2); return new ActionReturn( new EntityData(view.getEntityReference().toString(), togo.getStuff(), togo), (String) null); }
public Object executeActions( EntityView entityView, String action, Map<String, Object> actionParams, OutputStream outputStream) { Object result = null; if ("double".equals(action)) { result = myDoubleAction(entityView); } else if ("xxx".equals(action)) { MyEntity me = (MyEntity) getEntity(entityView.getEntityReference()); me.extra = "xxx"; me.setStuff("xxx"); myEntities.put(me.getId(), me); } else if ("clear".equals(action)) { myEntities.clear(); } return result; }
/** * This handles the paths: * * <p>/direct/forums/site/SITEID.json /direct/forums/site/SITEID/forum/FORUMID.json * /direct/forums/site/SITEID/forum/FORUMID/topic/TOPICID.json * /direct/forums/site/SITEID/forum/FORUMID/topic/TOPICID/message/MESSAGEID.json * * @param view * @param params * @return */ @EntityCustomAction(action = "site", viewKey = EntityView.VIEW_LIST) public Object handleSite(EntityView view, Map<String, Object> params) { if (LOG.isDebugEnabled()) { LOG.debug("handleSite"); } String userId = developerHelperService.getCurrentUserId(); if (userId == null) { LOG.error("Not logged in"); throw new EntityException( "You must be logged in to retrieve fora.", "", HttpServletResponse.SC_UNAUTHORIZED); } String siteId = view.getPathSegment(2); if (siteId == null) { LOG.error("Bad request. No SITEID supplied on path."); throw new EntityException( "Bad request: To get the fora in a site you need a url like '/direct/forum/site/SITEID.json'", "", HttpServletResponse.SC_BAD_REQUEST); } checkSiteAndToolAccess(siteId); String[] pathSegments = view.getPathSegments(); if (pathSegments.length == 3) { // This is a request for all the fora in the site return getAllForaForSite(siteId, userId); } else if (pathSegments.length == 5) { // This is a request for a particular forum in the site Long forumId = -1L; try { forumId = Long.parseLong(view.getPathSegment(4)); } catch (NumberFormatException nfe) { LOG.error("Bad request. FORUMID must be an integer."); throw new EntityException( "The forum id must be an integer.", "", HttpServletResponse.SC_BAD_REQUEST); } return getForum(forumId, siteId, userId); } else if (pathSegments.length == 7) { // This is a request for a particular topic in the forum Long topicId = -1L; try { topicId = Long.parseLong(view.getPathSegment(6)); } catch (NumberFormatException nfe) { LOG.error("Bad request. TOPICID must be an integer."); throw new EntityException( "The topic id must be an integer.", "", HttpServletResponse.SC_BAD_REQUEST); } return getTopic(topicId, siteId, userId); } else if (pathSegments.length == 9) { Long messageId = -1L; try { messageId = Long.parseLong(view.getPathSegment(8)); } catch (NumberFormatException nfe) { LOG.error("Bad request. MESSAGEID must be an integer."); throw new EntityException( "The message id must be an integer.", "", HttpServletResponse.SC_BAD_REQUEST); } return getMessage(messageId, siteId, userId); } else { return null; } }