Java Code Examples for org.alfresco.service.cmr.dictionary.Constraint#evaluate()
The following examples show how to use
org.alfresco.service.cmr.dictionary.Constraint#evaluate() .
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: 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 3
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; }