/** * saveEdit * * <p>Updates the object given the specified parameters, and form values. * * <pre> * Version Date Developer Description * 0.1 26/04/2012 Genevieve Turner (GT) Initial * 0.7 04/06/2012 Genevieve Turner (GT) Fixed an issue where the fedora object was not returned in the values map * 0.8 20/06/2012 Genevieve Turner (GT) Updated so that page retrieval is now using a map * 0.13 25/07/2012 Genevieve Turner (GT) Added removing of ready for review/publish * 0.16 27/08/2012 Genevieve Turner (GT) Fixed issue where group was not updated when editing * 0.22 06/11/2012 Genevieve Turner (GT) Updated to check if the user has permissions to update the group if not remove those permissions * 0.23 12/11/2012 Genevieve Turner (GT) Added the request id * </pre> * * @param fedoraObject The fedora object to get the page for * @param tmplt The template that determines the fields on the screen * @param form The form fields of the screen * @param rid The request id * @return Returns the viewable for the jsp file to pick up. */ @Override public Map<String, Object> saveEdit( FedoraObject fedoraObject, String tmplt, Map<String, List<String>> form, Long rid) { Map<String, Object> values = new HashMap<String, Object>(); ViewTransform viewTransform = new ViewTransform(); try { if (form.containsKey("ownerGroup")) { // TODO Update this so that an error is thrown if the user does not have permissions to // update the group if (!permissionService.hasSetGroupPermissionsForObject(fedoraObject)) { form.remove("ownerGroup"); } } fedoraObject = viewTransform.saveData(tmplt, fedoraObject, form, rid); removeReviewReady(fedoraObject); removePublishReady(fedoraObject); if (form.containsKey("ownerGroup")) { permissionService.saveObjectPermissions(fedoraObject); } } catch (JAXBException e) { LOGGER.error("Exception transforming jaxb", e); values.put("error", "true"); } catch (FedoraClientException e) { LOGGER.error("Exception creating/retrieving objects", e); values.put("error", "true"); } return values; }
/** * saveNew * * <p>Saves the information then displays a page with the given information * * <pre> * Version Date Developer Description * 0.1 26/04/2012 Genevieve Turner (GT) Initial * 0.8 20/06/2012 Genevieve Turner (GT) Updated so that page retrieval is now using a map * 0.15 20/08/2012 Genevieve Turner (GT) Updated to use permissionService rather than aclService * 0.23 12/11/2012 Genevieve Turner (GT) Added the request id * 0.25 02/01/2012 Genevieve Turner (GT) Updated to enforce records requriing an ownerGroup, type and name/title * </pre> * * @param layout The layout to display the page * @param tmplt The template that determines the fields on the screen * @param form Contains the parameters from the request * @param rid The request id * @return Returns the viewable for the jsp file to pick up. * @throws JAXBException * @throws FedoraClientException */ @Override public FedoraObject saveNew(String tmplt, Map<String, List<String>> form, Long rid) throws FedoraClientException, JAXBException { FedoraObject fedoraObject = null; ViewTransform viewTransform = new ViewTransform(); List<String> messages = new ArrayList<String>(); if (form.get("ownerGroup") == null || form.get("ownerGroup").size() == 0 || form.get("ownerGroup").get(0).trim().equals("")) { messages.add("No Group Affiliation"); } if (form.get("type") == null || form.get("type").size() == 0 || form.get("type").get(0).trim().equals("")) { messages.add("No item type has been set"); } if ((form.get("name") == null || form.get("name").size() == 0 || form.get("name").get(0).trim().equals("")) && (form.get("lastName") == null || form.get("lastName").size() == 0 || form.get("lastName").get(0).trim().equals(""))) { messages.add("No name/title has been set"); } if (messages.size() == 0) { // Check if the user has access to the ownerGroup String ownerGroup = form.get("ownerGroup").get(0); Long ownerGroupId = new Long(ownerGroup); List<Groups> groups = groupService.getCreateGroups(); boolean groupFound = false; for (Groups group : groups) { if (group.getId().equals(ownerGroupId)) { groupFound = true; break; } } if (groupFound == false) { throw new AccessDeniedException( format("You do not have permissions to create in group {0}", ownerGroup)); } } else { throw new ValidateException(messages); } fedoraObject = viewTransform.saveData(tmplt, null, form, rid); permissionService.saveObjectPermissions(fedoraObject); return fedoraObject; }