コード例 #1
0
    /**
     * Create a custom field ordering from a list of strings representing field labels. There may
     * also be one or more optionally-quoted strings, each indicating a value to be inserted into a
     * constant-valued column.
     *
     * @param labels a list of field labels and optionally constant string values
     * @throws CustomColumnOrderingException if there is an unrecognised field name or no id fields
     */
    public CustomColumnOrdering(List<String> labels) throws CustomColumnOrderingException {
      this.ordering = ReportColumn.fromStrings(labels);
      // Note we regenerate the labels from the ReportColumns so constant-valued
      // columns are consistently unquoted.
      this.orderedLabels = ReportColumn.getLabels(ordering);

      // Create the Field ordering
      this.fieldOrdering =
          new ArrayList<Field>() {
            {
              for (ReportColumn c : ordering) {
                if (c.isField()) add(c.field);
              }
            }
          };

      // Sanity checks
      // Are there any fields included?
      if (this.fieldOrdering.isEmpty())
        throw new CustomColumnOrderingException("", "No valid fields specified.");
      // Are there id fields included?
      if (!Field.idFields.clone().removeAll(this.fieldOrdering)) {
        String idFieldStr =
            String.format("(%s)", StringUtils.join(Field.getLabels(Field.idFields), ", "));
        throw new CustomColumnOrderingException(
            "",
            String.format(
                "No identifying fields specified. You must include one of %s.", idFieldStr));
      }
      // Set the field set if all is okay
      this.fields = EnumSet.copyOf(this.fieldOrdering);
    }
コード例 #2
0
 /**
  * Remove the named Fields from the ordering. Returns the ordering for convenience.
  *
  * @param fieldsToRemove a collection of fields
  * @return
  */
 protected CustomColumnOrdering removeFields(Collection<Field> fieldsToRemove) {
   List<ReportColumn> cols = ReportColumn.fromFields(fieldsToRemove);
   this.ordering.removeAll(cols);
   this.orderedLabels.removeAll(ReportColumn.getLabels(cols));
   this.fieldOrdering.removeAll(fieldsToRemove);
   this.fields.removeAll(fieldsToRemove);
   return this;
 }
コード例 #3
0
 /**
  * Remove the named columns from the ordering. Returns the ordering for convenience.
  *
  * @param columns a collection of labels
  * @return
  */
 protected CustomColumnOrdering remove(Collection<String> columns) {
   this.ordering.removeAll(ReportColumn.fromStrings(columns));
   this.orderedLabels.removeAll(columns);
   Collection<Field> flds = Field.getFields(columns);
   this.fieldOrdering.removeAll(flds);
   this.fields.removeAll(flds);
   return this;
 }
コード例 #4
0
 /**
  * Create a custom ordering without generating exceptions on invalid specification. This method
  * will create a custom ordering as per the list of labels. Labels that do not match fields will
  * be included as constant-valued columns, and there are no restrictions on whether id fields
  * are included (allowing for the creation of orderings leading to useless reports); nor are
  * there limits on the number of columns which can be included. This method should therefore
  * only be used in creating enumerated PredefinedFieldOrderings, or user-defined orderings
  * defined through the LOCKSS user interface.
  *
  * @param labels
  * @return
  */
 protected static CustomColumnOrdering createUnchecked(List<String> labels) {
   final List<ReportColumn> ordering = ReportColumn.fromStrings(labels);
   List<Field> fieldOrdering =
       new ArrayList<Field>() {
         {
           for (ReportColumn c : ordering) {
             if (c.isField()) add(c.field);
           }
         }
       };
   return new CustomColumnOrdering(ordering, fieldOrdering, labels);
 }
コード例 #5
0
 /**
  * Convenience method to create a custom field ordering from a list of Fields.
  *
  * @param fieldOrdering an ordered list of Fields
  */
 public static CustomColumnOrdering create(final List<Field> fieldOrdering) {
   final List<ReportColumn> ordering = ReportColumn.fromFields(fieldOrdering);
   return new CustomColumnOrdering(ordering, fieldOrdering);
 }