Ejemplo n.º 1
0
  /**
   * getPage
   *
   * <p>Retrieves a page for the given values
   *
   * <pre>
   * Version	Date		Developer				Description
   * 0.1		26/04/2012	Genevieve Turner (GT)	Initial
   * 0.2		03/05/2012	Genevieve Turner (GT)	Updated to add related links to the page
   * 0.8		20/06/2012	Genevieve Turner (GT)	Updated so that page retrieval is now using a map
   * 0.10		11/07/2012	Genevieve Turner (GT)	Updated to allow or deny access to unpublished pages
   * 0.11		13/07/2012	Rahul Khanna (RK)		Updated filelist displayed on collection page
   * 0.15		20/08/2012	Genevieve Turner (GT)	Updated to use permissionService rather than aclService
   * 0.23		13/11/2012	Genevieve Turner (GT)	Added whether edit mode should be used in retrieving the page (i.e. no published information is retrieved)
   * </pre>
   *
   * @param layout The layout to use with display (i.e. the xsl stylesheet)
   * @param tmplt The template that determines the fields on the screen
   * @param fedoraObject The object of the page to retrieve
   * @param editMode Indicates whether published information should be returned or not
   * @return Returns the viewable for the jsp file to pick up.
   */
  private Map<String, Object> getPage(
      String layout, String template, FedoraObject fedoraObject, boolean editMode) {
    boolean hasPermission = false;
    if (fedoraObject == null) {
      hasPermission = true;
    } else {
      hasPermission = permissionService.checkViewPermission(fedoraObject);
    }
    Map<String, Object> values = new HashMap<String, Object>();
    values.put("topage", "/page.jsp");
    ViewTransform viewTransform = new ViewTransform();
    try {
      if (fedoraObject != null) {
        // Add bag summary to model.
        try {
          RecordDataSummary rdi =
              storageController.getRecordDataSummary(fedoraObject.getObject_id());
          values.put("rdi", rdi);
        } catch (IOException | StorageException e) {
          LOGGER.error(e.getMessage(), e);
        }
      }
      if (hasPermission) {
        values.putAll(viewTransform.getPage(layout, template, fedoraObject, null, editMode, false));
      } else if (fedoraObject.getPublished()) {
        values.putAll(viewTransform.getPage(layout, template, fedoraObject, null, false, true));
      } else {
        throw new AccessDeniedException(
            format(
                "User does not have permission to view page for record {0}",
                fedoraObject.getObject_id()));
      }
    } catch (FedoraClientException e) {
      LOGGER.error("Exception: ", e);
      values.put("topage", "/error.jsp");
    }

    if (!values.containsKey("page")) {
      values.put("topage", "/error.jsp");
    }

    if (fedoraObject != null) {
      // TODO This is should probably be modified
      values.put("fedoraObject", fedoraObject);

      String sidepage = "buttons.jsp";
      values.put("sidepage", sidepage);

      // SparqlResultSet resultSet = getLinks(fedoraObject);
      List<Result> resultSet = getLinks(fedoraObject);
      values.put("resultSet", resultSet);
    }

    return values;
  }