/** * Returns true if the metadata contains the specified constraint */ public static boolean hasConstraint(Metadata meta, String id) { boolean result = false; if (meta != null && meta.getConstraints() != null) { result = containsConstraint(meta.getConstraints(), id); } return result; }
/** * Use to determine if the field is required for the next state. * * @param meta * @return */ public static boolean isRequiredForNextState(Metadata meta){ boolean required = false; if(meta == null){ return false; } //This flag is only set when using the new dictionary, in which case there should //never be more than one constraint. if (meta.getConstraints() != null && meta.getConstraints().size() == 1){ ConstraintMetadata constraint = meta.getConstraints().get(0); required = constraint.isRequiredForNextState(); } return required; }
/** * Use to determine if the field is required for the next state. * * @param meta * @return */ public static String getNextState(Metadata meta){ String state = null; if(meta == null){ return state; } //This flag is only set when using the new dictionary, in which case there should //never be more than one constraint. if (meta.getConstraints() != null && meta.getConstraints().size() == 1){ ConstraintMetadata constraint = meta.getConstraints().get(0); state = constraint.getNextState(); } return state; }
private static boolean hasRepeatingConstraint(Metadata meta) { boolean isRepeating = false; for (ConstraintMetadata cons : meta.getConstraints()) { if ("repeating".equals(cons.getId())){ isRepeating = true; } } return isRepeating; }
@Override public void exec(Metadata result) { searchProgramMetadata = result; searchProgramMetadata.getProperties().get(CommonWidgetConstants.CLU_SET_APPROVED_CLUS_FIELD).getConstraints().get(0).setMaxOccurs(1); searchProgramMetadata.getProperties().get(CommonWidgetConstants.CLU_SET_PROPOSED_CLUS_FIELD).getConstraints().get(0).setMaxOccurs(1); searchProgramMetadata.getProperties().get(CommonWidgetConstants.CLU_SET_APPROVED_CLUS_FIELD).getConstraints().get(0).setId("single"); searchProgramMetadata.getProperties().get(CommonWidgetConstants.CLU_SET_PROPOSED_CLUS_FIELD).getConstraints().get(0).setId("single"); KSBlockingProgressIndicator.removeTask(initializeTask); if (previousProgramCode == null) { programTypeWidget.selectItem(CommonWidgetConstants.CLU_SET_APPROVED_CLUS_FIELD); addProgramListWidget(true, programTypeWidget.getSelectedItem()); } } });
public static Date getLargestMinValueDate(Metadata meta, DateParser parser, Object dataValue) { if (meta == null) { return null; } Date result = null; for (ConstraintMetadata cons : meta.getConstraints()) { Date min = tryParseDate(cons.getMinValue(), parser); if (min != null) { if (result == null || min.getTime() > result.getTime()) { result = min; } } } if (dataValue != null && dataValue instanceof Date){ if (result == null || (((Date)dataValue).getTime() > result.getTime())){ result = (Date)dataValue; } } return result; }
public static Date getSmallestMaxValueDate(Metadata meta, DateParser parser, Object dataValue) { if (meta == null) { return null; } Date result = null; for (ConstraintMetadata cons : meta.getConstraints()) { Date max = tryParseDate(cons.getMaxValue(), parser); if (max != null) { if (result == null || max.getTime() < result.getTime()) { result = max; } } } if (dataValue != null && dataValue instanceof Date){ if (result==null || (((Date)dataValue).getTime() < result.getTime())){ result = (Date)dataValue; } } return result; }
public static Double getLargestMinValueDouble(Metadata meta) { if (meta == null) { return null; } Double result = null; for (ConstraintMetadata cons : meta.getConstraints()) { Double min = tryParseDouble(cons.getMinValue()); if (min != null) { if (result == null || min > result) { result = min; } } } return result; }
@Override public void exec(Metadata result) { searchCourseMetadata = result; searchCourseMetadata.getProperties().get(CommonWidgetConstants.CLU_SET_APPROVED_CLUS_FIELD).getConstraints().get(0).setMaxOccurs(1); searchCourseMetadata.getProperties().get(CommonWidgetConstants.CLU_SET_PROPOSED_CLUS_FIELD).getConstraints().get(0).setMaxOccurs(1); searchCourseMetadata.getProperties().get(CommonWidgetConstants.CLU_SET_APPROVED_CLUS_FIELD).getConstraints().get(0).setId("single"); searchCourseMetadata.getProperties().get(CommonWidgetConstants.CLU_SET_PROPOSED_CLUS_FIELD).getConstraints().get(0).setId("single"); KSBlockingProgressIndicator.removeTask(initializeTask); if (previousCourseCode == null) { courseTypeWidget.selectItem(CommonWidgetConstants.CLU_SET_APPROVED_CLUS_FIELD); addCourseListWidget(true, courseTypeWidget.getSelectedItem()); } } });
public static Long getLargestMinValue(Metadata meta) { if (meta == null) { return null; } Long result = null; for (ConstraintMetadata cons : meta.getConstraints()) { Long min = tryParseLong(cons.getMinValue()); if (min != null) { if (result == null || min > result) { result = min; } } } return result; }
public static Long getSmallestMaxValue(Metadata meta) { if (meta == null) { return null; } Long result = null; for (ConstraintMetadata cons : meta.getConstraints()) { Long max = tryParseLong(cons.getMaxValue()); if (max != null) { if (result == null || max < result) { result = max; } } } return result; }
public static Double getSmallestMaxValueDouble(Metadata meta) { if (meta == null) { return null; } Double result = null; for (ConstraintMetadata cons : meta.getConstraints()) { Double max = tryParseDouble(cons.getMaxValue()); if (max != null) { if (result == null || max < result) { result = max; } } } return result; }
/** * Reset the requiredness of the field descriptor. Note doing this will also dynamically change * the underlying metadata so ui validation for requiredness works as well. * */ public void setRequired(Boolean isRequired){ fieldElement.setRequiredString("requiredMarker", "ks-form-module-elements-required"); fieldElement.setRequired(isRequired); //FIXME: This could be problematic if minOccurs should be something other than 1 if (isRequired){ getMetadata().getConstraints().get(0).setMinOccurs(1); } else { getMetadata().getConstraints().get(0).setMinOccurs(0); } }
private String calcValidChars(Metadata fieldMeta) { for (ConstraintMetadata cons : fieldMeta.getConstraints()) { if (cons.getValidChars() == null) { continue; } String validChars = escapeWiki(cons.getValidChars()); String descr = "[" + "See" + "|" + LINK_TO_DEFINITIONS + "]" + "\\\\\n" + validChars; return descr; } return " "; }
private String calcRequired(Metadata fieldMeta) { for (ConstraintMetadata cons : fieldMeta.getConstraints()) { if (cons.getMaxOccurs() != null) { if (cons.getMaxOccurs() == 0) { return "NOT USED"; } } if (cons.getMinOccurs() != null) { if (cons.getMinOccurs() >= 1) { return "required"; } } } return " "; // return "optional"; }
private Object getCrossFieldMinValue(DataModel model, QueryPath path, Metadata meta) { Object v = null; List<ConstraintMetadata> constraints = meta.getConstraints(); for (int i = 0; i < constraints.size(); i++) { ConstraintMetadata cons = constraints.get(i); if (cons.getMinValue() != null && cons.getMinValue().contains("../")) { QueryPath crossFieldPath = QueryPath.parse(path.toString()); String crossFieldKey = cons.getMinValue().substring(3); crossFieldPath.remove(crossFieldPath.size() - 1); crossFieldPath.add(new StringKey(crossFieldKey)); v = model.get(crossFieldPath); } } return v; }
public static Integer getSmallestMaxLength(Metadata meta) { if (meta == null) { return null; } Integer smallestMaxLength = null; // TODO: worry aboutg special validators // TODO: worry about how this applies to non-strings? for (ConstraintMetadata cons : meta.getConstraints()) { if (cons.getMaxLength() != null) { if (smallestMaxLength == null) { smallestMaxLength = cons.getMaxLength(); } else if (cons.getMaxLength() < smallestMaxLength) { smallestMaxLength = cons.getMaxLength(); } } } return smallestMaxLength; }
private Object getCrossFieldMaxValue(DataModel model, QueryPath path, Metadata meta) { Object v = null; List<ConstraintMetadata> constraints = meta.getConstraints(); for (int i = 0; i < constraints.size(); i++) { ConstraintMetadata cons = constraints.get(i); if (cons.getMaxValue() != null && cons.getMaxValue().contains("../")) { QueryPath crossFieldPath = QueryPath.parse(path.toString()); String crossFieldKey = cons.getMinValue().substring(3); crossFieldPath.remove(crossFieldPath.size() - 1); crossFieldPath.add(new StringKey(crossFieldKey)); v = model.get(crossFieldPath); } } return v; }
/** * get the largest min occurs value * * @return null if none specified */ public static Integer getLargestMinOccurs(Metadata meta) { if (meta == null) { return null; } Integer largestMinOccurs = null; // TODO: worry aboutg special validators // TODO: worry about how this applies to non-strings? for (ConstraintMetadata cons : meta.getConstraints()) { if (cons.getMinOccurs() != null) { if (largestMinOccurs == null) { largestMinOccurs = cons.getMinOccurs(); } else if (cons.getMinOccurs() > largestMinOccurs) { largestMinOccurs = cons.getMinOccurs(); } } } return largestMinOccurs; }
/** * get the largest min occurs value * * @return null if none specified */ public static Integer getLargestMinLength(Metadata meta) { if (meta == null) { return null; } Integer largestMinLength = null; // TODO: worry aboutg special validators // TODO: worry about how this applies to non-strings? for (ConstraintMetadata cons : meta.getConstraints()) { if (cons.getMinLength() != null) { if (largestMinLength == null) { largestMinLength = cons.getMinLength(); } else if (cons.getMinLength() > largestMinLength) { largestMinLength = cons.getMinLength(); } } } return largestMinLength; }