/**
   * @throws Exception
   * @see DescriptionTraverserAgent#apply(SimpleDescriptionObject, List)
   */
  public AccessRestrictNotifierResult apply(
      SimpleDescriptionObject sdo, List<AccessRestrictNotifierResult> childResults)
      throws Exception {

    AccessRestrictNotifierResult result = new AccessRestrictNotifierResult();

    if (childResults != null) {
      // Add the results from the children
      for (AccessRestrictNotifierResult childResult : childResults) {
        if (childResult.getDescriptionObjects().size() > 0) {
          result.addDescriptionObjects(childResult.getDescriptionObjects());
        }
      }
    }

    if (sdo.getSubElementsCount() == 0
        && (sdo.getLevel().equals(DescriptionLevel.FILE)
            || sdo.getLevel().equals(DescriptionLevel.ITEM))) {

      DescriptionObject descriptionObject = browserService.getDescriptionObject(sdo.getPid());

      String accessrestrict = descriptionObject.getAccessrestrict();

      if (!StringUtils.isBlank(accessrestrict)) {

        Date currentDate = new Date();

        Date representationDate = DateParser.parse(descriptionObject.getDateFinal());

        Calendar representationCalendar = Calendar.getInstance();
        representationCalendar.setTime(representationDate);

        if (accessrestrict.toLowerCase().startsWith("segredo de estado")) {

          // segredo de estado => 25 years
          representationCalendar.add(Calendar.YEAR, 25);

        } else if (accessrestrict.equalsIgnoreCase("Dados pessoais")) {

          // Dados pessoais => 75 years
          representationCalendar.add(Calendar.YEAR, 75);

        } else if (accessrestrict.equalsIgnoreCase("Dados sensíveis de pessoas colectivas")) {

          // Dados sensíveis de pessoas colectivas => 50 years
          representationCalendar.add(Calendar.YEAR, 50);

        } else {
          logger.warn(
              "DO "
                  + sdo.getPid()
                  + " accessrestrict '"
                  + accessrestrict
                  + "' is not a recognized value.");
          representationCalendar = null;
        }

        if (representationCalendar != null
            && currentDate.compareTo(representationCalendar.getTime()) > 0) {
          result.addDescriptionObject(descriptionObject);
        }

      } else {
        // DO doesn't have accessrestrict value
      }
    }

    return result;
  }
Пример #2
0
  /** @param args */
  public static void main(String[] args) {

    try {

      RODAClient rodaClient = null;

      if (args.length == 3) {

        // http://localhost:8180/
        String hostUrl = args[0];
        String username = args[1];
        String password = args[2];
        rodaClient = new RODAClient(new URL(hostUrl), username, password);

      } else {
        System.err.println(
            BrowserSimpleROTest.class.getSimpleName()
                + " protocol://hostname:port/core-service [username password]");
        System.exit(1);
      }

      Browser browserService = rodaClient.getBrowserService();

      System.out.println("\n**************************************");
      System.out.println("Number of Event Preservation Objects");
      System.out.println("**************************************");

      int count = browserService.getSimpleEventPreservationObjectCount(null);
      System.out.println(count + " event preservation objects in the repository");

      System.out.println("\n**************************************");
      System.out.println("Number of Event Preservation Objects (Inactive)");
      System.out.println("**************************************");

      Filter filterInactive = new Filter();
      filterInactive.add(new SimpleFilterParameter("state", RODAObject.STATE_INACTIVE));

      count = browserService.getSimpleEventPreservationObjectCount(filterInactive);
      System.out.println(count + " inactive event preservation objects in the repository");

      SimpleEventPreservationObject[] simpleEPOs =
          browserService.getSimpleEventPreservationObjects(null);

      System.out.println("\n**************************************");
      System.out.println("List of Event Preservation Objects");
      System.out.println("**************************************");

      for (int i = 0; simpleEPOs != null && i < simpleEPOs.length; i++) {
        System.out.println(simpleEPOs[i]);
      }

      if (simpleEPOs != null && simpleEPOs.length > 0) {

        System.out.println("\n*********************************************");
        System.out.println(
            "Getting EventPreservationObject of the first representation ("
                + simpleEPOs[0].getPid()
                + ")");
        System.out.println("*********************************************");

        EventPreservationObject rObject =
            browserService.getEventPreservationObject(simpleEPOs[0].getPid());
        System.out.println(rObject);
      }

    } catch (Throwable e) {
      e.printStackTrace();
      if (e.getCause() != null) {
        System.err.println("Cause exception:");
        e.getCause().printStackTrace();
      }
    }
  }