/** * 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); }