/** Note that details is the only optional field */ public String createEntity(EntityReference ref, Object entity, Map<String, Object> params) { Poll poll = (Poll) entity; poll.setCreationDate(new Date()); if (poll.getId() == null) { poll.setId(UUID.randomUUID().toString()); } if (poll.getOwner() == null) { poll.setOwner(developerHelperService.getCurrentUserId()); } String siteId = developerHelperService.getCurrentLocationId(); if (poll.getSiteId() == null) { poll.setSiteId(siteId); } else { siteId = poll.getSiteId(); } String userReference = developerHelperService.getCurrentUserReference(); String location = "/site/" + siteId; boolean allowed = developerHelperService.isUserAllowedInEntityReference( userReference, PollListManager.PERMISSION_ADD, location); if (!allowed) { throw new SecurityException( "Current user (" + userReference + ") cannot create polls in location (" + location + ")"); } pollListManager.savePoll(poll); return poll.getPollId() + ""; }
public void updateEntity(EntityReference ref, Object entity, Map<String, Object> params) { String id = ref.getId(); if (id == null) { throw new IllegalArgumentException( "The reference must include an id for updates (id is currently null)"); } String userReference = developerHelperService.getCurrentUserReference(); if (userReference == null) { throw new SecurityException("anonymous user cannot update poll: " + ref); } Poll current = getPollById(id); if (current == null) { throw new IllegalArgumentException("No poll found to update for the given reference: " + ref); } Poll poll = (Poll) entity; String siteId = developerHelperService.getCurrentLocationId(); if (poll.getSiteId() == null) { poll.setSiteId(siteId); } else { siteId = poll.getSiteId(); } String location = "/site/" + siteId; // should this check a different permission? boolean allowed = developerHelperService.isUserAllowedInEntityReference( userReference, PollListManager.PERMISSION_ADD, location); if (!allowed) { throw new SecurityException( "Current user (" + userReference + ") cannot update polls in location (" + location + ")"); } developerHelperService.copyBean( poll, current, 0, new String[] { "id", "pollId", "owner", "siteId", "creationDate", "reference", "url", "properties" }, true); pollListManager.savePoll(current); }