Ejemplo n.º 1
0
  /**
   * 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;
  }