예제 #1
0
  private static DirectoryEntry getDirectoryEntryFromNode(
      JsonNode propertiesNode, Directory directory) throws DirectoryException, IOException {

    String schema = directory.getSchema();
    String id = propertiesNode.get(directory.getIdField()).getTextValue();

    try (Session session = directory.getSession()) {
      DocumentModel entry = session.getEntry(id);

      if (entry == null) {
        entry = BaseSession.createEntryModel(null, schema, id, new HashMap<>());
      }

      Properties props = new Properties();
      Iterator<Entry<String, JsonNode>> fields = propertiesNode.getFields();
      while (fields.hasNext()) {
        Entry<String, JsonNode> fieldEntry = fields.next();
        props.put(schema + ":" + fieldEntry.getKey(), fieldEntry.getValue().getTextValue());
      }

      DocumentHelper.setProperties(null, entry, props);

      return new DirectoryEntry(directory.getName(), entry);
    }
  }
예제 #2
0
  @SuppressWarnings("unchecked")
  @OperationMethod
  public Paginable<LogEntry> run() throws IOException {

    List<SortInfo> sortInfos = null;
    if (sortInfoAsStringList != null) {
      sortInfos = new ArrayList<SortInfo>();
      for (String sortInfoDesc : sortInfoAsStringList) {
        SortInfo sortInfo;
        if (sortInfoDesc.contains(SORT_PARAMETER_SEPARATOR)) {
          String[] parts = sortInfoDesc.split(SORT_PARAMETER_SEPARATOR);
          sortInfo = new SortInfo(parts[0], Boolean.parseBoolean(parts[1]));
        } else {
          sortInfo = new SortInfo(sortInfoDesc, true);
        }
        sortInfos.add(sortInfo);
      }
    } else {
      // Sort Info Management
      if (!StringUtils.isBlank(sortBy)) {
        sortInfos = new ArrayList<>();
        String[] sorts = sortBy.split(",");
        String[] orders = null;
        if (!StringUtils.isBlank(sortOrder)) {
          orders = sortOrder.split(",");
        }
        for (int i = 0; i < sorts.length; i++) {
          String sort = sorts[i];
          boolean sortAscending =
              (orders != null && orders.length > i && "asc".equals(orders[i].toLowerCase()));
          sortInfos.add(new SortInfo(sort, sortAscending));
        }
      }
    }

    Object[] parameters = null;

    if (strParameters != null && !strParameters.isEmpty()) {
      parameters = strParameters.toArray(new String[strParameters.size()]);
      // expand specific parameters
      for (int idx = 0; idx < parameters.length; idx++) {
        String value = (String) parameters[idx];
        if (value.equals(CURRENT_USERID_PATTERN)) {
          parameters[idx] = session.getPrincipal().getName();
        } else if (value.equals(CURRENT_REPO_PATTERN)) {
          parameters[idx] = session.getRepositoryName();
        }
      }
    }
    if (parameters == null) {
      parameters = new Object[0];
    }

    Map<String, Serializable> props = new HashMap<String, Serializable>();
    props.put(CoreQueryDocumentPageProvider.CORE_SESSION_PROPERTY, (Serializable) session);

    if (query == null && (providerName == null || providerName.length() == 0)) {
      // provide a defaut provider
      providerName = "AUDIT_BROWSER";
    }

    Long targetPage = null;
    if (page != null) {
      targetPage = page.longValue();
    }
    if (currentPageIndex != null) {
      targetPage = currentPageIndex.longValue();
    }
    Long targetPageSize = null;
    if (pageSize != null) {
      targetPageSize = pageSize.longValue();
    }

    if (query != null) {

      AuditPageProvider app = new AuditPageProvider();
      app.setProperties(props);
      GenericPageProviderDescriptor desc = new GenericPageProviderDescriptor();
      desc.setPattern(query);
      app.setParameters(parameters);
      app.setDefinition(desc);
      app.setSortInfos(sortInfos);
      app.setPageSize(targetPageSize);
      app.setCurrentPage(targetPage);
      return new LogEntryList(app);
    } else {

      DocumentModel searchDoc = null;
      if (namedQueryParams != null && namedQueryParams.size() > 0) {
        String docType =
            ppService.getPageProviderDefinition(providerName).getWhereClause().getDocType();
        searchDoc = session.createDocumentModel(docType);
        DocumentHelper.setProperties(session, searchDoc, namedQueryParams);
      }

      PageProvider<LogEntry> pp =
          (PageProvider<LogEntry>)
              ppService.getPageProvider(
                  providerName,
                  searchDoc,
                  sortInfos,
                  targetPageSize,
                  targetPage,
                  props,
                  parameters);
      // return new PaginablePageProvider<LogEntry>(pp);
      return new LogEntryList(pp);
    }
  }