org.alfresco.service.cmr.dictionary.Constraint Java Examples
The following examples show how to use
org.alfresco.service.cmr.dictionary.Constraint.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CustomModelServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * Validates the properties' non-null default values against the defined property constraints. * * @param compiledModel the compiled model * @throws CustomModelException.CustomModelConstraintException if there is constraint evaluation * exception */ private void validatePropsDefaultValues(CompiledModel compiledModel) { for (PropertyDefinition propertyDef : compiledModel.getProperties()) { if (propertyDef.getDefaultValue() != null && propertyDef.getConstraints().size() > 0) { for (ConstraintDefinition constraintDef : propertyDef.getConstraints()) { Constraint constraint = constraintDef.getConstraint(); try { constraint.evaluate(propertyDef.getDefaultValue()); } catch (AlfrescoRuntimeException ex) { String message = getRootCauseMsg(ex, false, "cmm.service.constraint.default_prop_value_err"); throw new CustomModelException.CustomModelConstraintException(message); } } } } }
Example #2
Source File: RegisteredConstraint.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 5 votes |
/** * @return the constraint that matches the registered name */ public Constraint getRegisteredConstraint() { Constraint constraint = ConstraintRegistry.getInstance().getConstraint(registeredName); if (constraint == null) { throw new DictionaryException(ERR_NAME_NOT_REGISTERED, registeredName); } return constraint; }
Example #3
Source File: ConstraintRegistry.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 5 votes |
/** * Register the constraint by name */ public void register(String name, Constraint constraint) { if (this == instance) { constraints.put(name, constraint); } else { instance.register(name, constraint); } }
Example #4
Source File: ConstraintRegistry.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 5 votes |
/** * Get the constraint by name * * @param name the name by which the constraint was registered * @return Returns the constraint or <tt>null</tt> if it does not exist. */ public Constraint getConstraint(String name) { if (this == instance) { return constraints.get(name); } else { return instance.getConstraint(name); } }
Example #5
Source File: ConstraintsTest.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 5 votes |
private void evaluate(Constraint constraint, Object value, boolean expectFailure) throws Exception { try { constraint.evaluate(value); if (expectFailure) { // it should have failed fail("Failure did not occur: \n" + " constraint: " + constraint + "\n" + " value: " + value); } } catch (ConstraintException e) { // check if we expect an error if (expectFailure) { // expected - check message I18N checkI18NofExceptionMessage(e); } else { // didn't expect it throw e; } } }
Example #6
Source File: WorkflowModelBuilder.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
private Map<String, String> buildPropertyLabels(WorkflowTask task, Map<String, Object> properties) { TypeDefinition taskType = task.getDefinition().getMetadata(); final Map<QName, PropertyDefinition> propDefs = taskType.getProperties(); return CollectionUtils.transform(properties, new Function<Entry<String, Object>, Pair<String, String>>() { @Override public Pair<String, String> apply(Entry<String, Object> entry) { String propName = entry.getKey(); PropertyDefinition propDef = propDefs.get(qNameConverter.mapNameToQName(propName)); if(propDef != null ) { List<ConstraintDefinition> constraints = propDef.getConstraints(); for (ConstraintDefinition constraintDef : constraints) { Constraint constraint = constraintDef.getConstraint(); if (constraint instanceof ListOfValuesConstraint) { ListOfValuesConstraint listConstraint = (ListOfValuesConstraint) constraint; String label = listConstraint.getDisplayLabel(String.valueOf(entry.getValue()), dictionaryService); return new Pair<String, String>(propName, label); } } } return null; } }); }
Example #7
Source File: DirectoryAnalyserImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
private boolean isMetadataValid(ImportableItem importableItem) { if (!importableItem.getHeadRevision().metadataFileExists()) { return true; } if (metadataLoader != null) { MetadataLoader.Metadata result = new MetadataLoader.Metadata(); metadataLoader.loadMetadata(importableItem.getHeadRevision(), result); Map<QName, Serializable> metadataProperties = result.getProperties(); for (QName propertyName : metadataProperties.keySet()) { PropertyDefinition propDef = dictionaryService.getProperty(propertyName); if (propDef != null) { for (ConstraintDefinition constraintDef : propDef.getConstraints()) { Constraint constraint = constraintDef.getConstraint(); if (constraint != null) { try { constraint.evaluate(metadataProperties.get(propertyName)); } catch (ConstraintException e) { if (log.isWarnEnabled()) { log.warn("Skipping file '" + FileUtils.getFileName(importableItem.getHeadRevision().getContentFile()) +"' with invalid metadata: '" + FileUtils.getFileName(importableItem.getHeadRevision().getMetadataFile()) + "'.", e); } return false; } } } } } } return true; }
Example #8
Source File: PropertyFieldProcessor.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
private List<FieldConstraint> makeFieldConstraints(PropertyDefinition propDef) { List<FieldConstraint> fieldConstraints = null; List<ConstraintDefinition> constraints = propDef.getConstraints(); if (constraints != null && constraints.size() > 0) { fieldConstraints = new ArrayList<FieldConstraint>(constraints.size()); for (ConstraintDefinition constraintDef : constraints) { Constraint constraint = constraintDef.getConstraint(); String type = constraint.getType(); Map<String, Object> params = constraint.getParameters(); //ListOfValuesConstraints have special handling for localising their allowedValues. //If the constraint that we are currently handling is a registered constraint then //we need to examine the underlying constraint to see if it is a LIST constraint if (RegisteredConstraint.class.isAssignableFrom(constraint.getClass())) { constraint = ((RegisteredConstraint)constraint).getRegisteredConstraint(); } if (ListOfValuesConstraint.class.isAssignableFrom(constraint.getClass())) { ListOfValuesConstraint lovConstraint = (ListOfValuesConstraint) constraint; List<String> allowedValues = lovConstraint.getAllowedValues(); List<String> localisedValues = new ArrayList<String>(allowedValues.size()); // Look up each localised display-label in turn. for (String value : allowedValues) { String displayLabel = lovConstraint.getDisplayLabel(value, dictionaryService); // Change the allowedValue entry to the format the FormsService expects for localised strings: "value|label" // If there is no localisation defined for any value, then this will give us "value|value". localisedValues.add(value + "|" + displayLabel); } // Now replace the allowedValues param with our localised version. params.put(ListOfValuesConstraint.ALLOWED_VALUES_PARAM, localisedValues); } FieldConstraint fieldConstraint = new FieldConstraint(type, params); fieldConstraints.add(fieldConstraint); } } return fieldConstraints; }
Example #9
Source File: ConstraintRegistry.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 4 votes |
/** * Private constructor * @see #getInstance() */ private ConstraintRegistry() { constraints = new HashMap<String, Constraint>(13); }
Example #10
Source File: M2ConstraintDefinition.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 4 votes |
@Override public Constraint getConstraint() { return constraint; }
Example #11
Source File: M2ConstraintDefinition.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 4 votes |
@Override protected Constraint newInstance() { return new RegisteredConstraint(); }
Example #12
Source File: M2ConstraintDefinition.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 4 votes |
@Override protected Constraint newInstance() { return new RegexConstraint(); }
Example #13
Source File: M2ConstraintDefinition.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 4 votes |
@Override protected Constraint newInstance() { return new NumericRangeConstraint(); }
Example #14
Source File: M2ConstraintDefinition.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 4 votes |
@Override protected Constraint newInstance() { return new StringLengthConstraint(); }
Example #15
Source File: M2ConstraintDefinition.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 4 votes |
@Override protected Constraint newInstance() { return new ListOfValuesConstraint(); }
Example #16
Source File: M2ConstraintDefinition.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 2 votes |
/** * @return Returns the constraint implementation */ protected abstract Constraint newInstance();