org.alfresco.service.cmr.dictionary.ConstraintDefinition Java Examples
The following examples show how to use
org.alfresco.service.cmr.dictionary.ConstraintDefinition.
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: AbstractDictionaryRegistry.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 6 votes |
protected ConstraintDefinition getConstraintImpl(QName constraintQName) { ConstraintDefinition constraintDef = null; List<CompiledModel> models = getModelsForUri(constraintQName.getNamespaceURI()); if(models != null && models.size() > 0) { for (CompiledModel model : models) { constraintDef = model.getConstraint(constraintQName); if(constraintDef != null) { break; } } } return constraintDef; }
Example #3
Source File: NameChecker.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 6 votes |
/** * Loads filename constraint from dictionary */ @Override public void afterPropertiesSet() throws Exception { PropertyCheck.mandatory(this, "dictionaryService", dictionaryService); QName qNameConstraint = QName.createQName(namespaceURI, constraintLocalName); ConstraintDefinition constraintDef = dictionaryService.getConstraint(qNameConstraint); if (constraintDef == null) { throw new AlfrescoRuntimeException("Constraint definition does not exist: " + qNameConstraint); } nameConstraint = constraintDef.getConstraint(); if (nameConstraint == null) { throw new AlfrescoRuntimeException("Constraint does not exist: " + qNameConstraint); } }
Example #4
Source File: CustomModelsImpl.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
@Override public CustomModelConstraint getCustomModelConstraint(String modelName, String constraintName, Parameters parameters) { if (constraintName == null) { throw new InvalidArgumentException(CONSTRAINT_NAME_NULL_ERR); } final CustomModelDefinition modelDef = getCustomModelImpl(modelName); QName constraintQname = QName.createQName(modelDef.getName().getNamespaceURI(), constraintName); ConstraintDefinition constraintDef = customModelService.getCustomConstraint(constraintQname); if (constraintDef == null) { throw new EntityNotFoundException(constraintName); } return new CustomModelConstraint(constraintDef, dictionaryService); }
Example #5
Source File: CustomModelsImpl.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
@Override public CollectionWithPagingInfo<CustomModelConstraint> getCustomModelConstraints(String modelName, Parameters parameters) { CustomModelDefinition modelDef = getCustomModelImpl(modelName); Collection<ConstraintDefinition> constraintDefinitions = modelDef.getModelDefinedConstraints(); // TODO Should we support paging? Paging paging = Paging.DEFAULT; List<CustomModelConstraint> customModelConstraints = convertToCustomModelConstraints(constraintDefinitions); return CollectionWithPagingInfo.asPaged(paging, customModelConstraints, false, constraintDefinitions.size()); }
Example #6
Source File: M2PropertyDefinition.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 5 votes |
M2PropertyDefinition( ClassDefinition classDef, PropertyDefinition propertyDef, M2PropertyOverride override, NamespacePrefixResolver prefixResolver, Map<QName, ConstraintDefinition> modelConstraints) { this.classDef = classDef; this.name = propertyDef.getName(); this.dataType = propertyDef.getDataType(); this.propertyTypeName = this.dataType.getName(); this.m2Property = createOverriddenProperty(propertyDef, override, prefixResolver, modelConstraints); }
Example #7
Source File: M2PropertyDefinition.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 5 votes |
void resolveDependencies( ModelQuery query, NamespacePrefixResolver prefixResolver, Map<QName, ConstraintDefinition> modelConstraints) { if (propertyTypeName == null) { throw new DictionaryException( "d_dictionary.property.err.property_type_not_specified", name.toPrefixString()); } dataType = query.getDataType(propertyTypeName); if (dataType == null) { throw new DictionaryException( "d_dictionary.property.err.property_type_not_found", propertyTypeName.toPrefixString(), name.toPrefixString()); } // ensure content properties are not multi-valued if (propertyTypeName.equals(DataTypeDefinition.CONTENT) && isMultiValued()) { throw new DictionaryException("d_dictionary.property.err.single_valued_content"); } // Construct constraints constraintDefs = buildConstraints( m2Property.getConstraints(), this, prefixResolver, modelConstraints); }
Example #8
Source File: CustomModelDefinitionImpl.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 5 votes |
/** * Removes the inline constraints (i.e. defined within the property) from * all constraints. The result will be constraints that have been defined * within the model (Top level) itself. * * @param compiledModel the compiled model * @return list of model defined constraints */ public static List<ConstraintDefinition> removeInlineConstraints(CompiledModel compiledModel) { List<ConstraintDefinition> modelConstraints = new ArrayList<>(); Set<QName> propertyConstraints = new HashSet<>(); for(PropertyDefinition propDef : compiledModel.getProperties()) { if (propDef.getConstraints().size() > 0) { for (ConstraintDefinition propConst : propDef.getConstraints()) { propertyConstraints.add(propConst.getName()); } } } for (ConstraintDefinition constraint : compiledModel.getConstraints()) { if (!propertyConstraints.contains(constraint.getName())) { modelConstraints.add(constraint); } } return modelConstraints; }
Example #9
Source File: DictionaryDAOTest.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void testConstraintsOverrideInheritance() { QName baseQName = QName.createQName(TEST_URL, "base"); QName fileQName = QName.createQName(TEST_URL, "file"); QName folderQName = QName.createQName(TEST_URL, "folder"); QName prop1QName = QName.createQName(TEST_URL, "prop1"); // get the base property PropertyDefinition prop1Def = service.getProperty(baseQName, prop1QName); assertNotNull(prop1Def); List<ConstraintDefinition> prop1Constraints = prop1Def.getConstraints(); assertEquals("Incorrect number of constraints", 3, prop1Constraints.size()); assertTrue("Constraint instance incorrect", prop1Constraints.get(0).getConstraint() instanceof RegexConstraint); assertTrue("Constraint instance incorrect", prop1Constraints.get(1).getConstraint() instanceof StringLengthConstraint); assertTrue("Constraint instance incorrect", prop1Constraints.get(2).getConstraint() instanceof RegisteredConstraint); // check the inherited property on folder (must be same as above) prop1Def = service.getProperty(folderQName, prop1QName); assertNotNull(prop1Def); prop1Constraints = prop1Def.getConstraints(); assertEquals("Incorrect number of constraints", 3, prop1Constraints.size()); assertTrue("Constraint instance incorrect", prop1Constraints.get(0).getConstraint() instanceof RegexConstraint); assertTrue("Constraint instance incorrect", prop1Constraints.get(1).getConstraint() instanceof StringLengthConstraint); assertTrue("Constraint instance incorrect", prop1Constraints.get(2).getConstraint() instanceof RegisteredConstraint); // check the overridden property on file (must be reverse of above) prop1Def = service.getProperty(fileQName, prop1QName); assertNotNull(prop1Def); prop1Constraints = prop1Def.getConstraints(); assertEquals("Incorrect number of constraints", 3, prop1Constraints.size()); assertTrue("Constraint instance incorrect", prop1Constraints.get(0).getConstraint() instanceof StringLengthConstraint); assertTrue("Constraint instance incorrect", prop1Constraints.get(1).getConstraint() instanceof RegexConstraint); assertTrue("Constraint instance incorrect", prop1Constraints.get(2).getConstraint() instanceof RegisteredConstraint); }
Example #10
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 #11
Source File: CustomModelConstraint.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
public CustomModelConstraint(ConstraintDefinition constraintDefinition, MessageLookup messageLookup) { this.name = constraintDefinition.getName().getLocalName(); this.prefixedName = constraintDefinition.getConstraint().getShortName(); this.type = constraintDefinition.getConstraint().getType(); this.title = constraintDefinition.getTitle(messageLookup); this.description = constraintDefinition.getDescription(messageLookup); this.parameters = convertToNamedValue(constraintDefinition.getConstraint().getParameters()); }
Example #12
Source File: CompiledModel.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 5 votes |
/** * Construct * * @param model model definition * @param dictionaryDAO dictionary DAO * @param namespaceDAO namespace DAO */ /*package*/ CompiledModel(M2Model model, DictionaryDAO dictionaryDAO, NamespaceDAO namespaceDAO, boolean enableConstraintClassLoading) { try { // Phase 1: Construct model definitions from model entries // resolving qualified names this.model = model; constructDefinitions(model, namespaceDAO, dictionaryDAO); // Phase 2: Resolve dependencies between model definitions ModelQuery query = new DelegateModelQuery(this, dictionaryDAO); resolveDependencies(query, namespaceDAO); // Phase 3: Resolve inheritance of values within class hierachy NamespacePrefixResolver localPrefixes = createLocalPrefixResolver(model, namespaceDAO); resolveInheritance(query, localPrefixes, constraints); // Phase 4: Resolve constraint dependencies for (ConstraintDefinition def : constraints.values()) { ((M2ConstraintDefinition)def).resolveDependencies(query, enableConstraintClassLoading); } } catch(Exception e) { if (logger.isDebugEnabled()) { logger.debug("Failed to compile model: " + model.getName(), e); } throw new DictionaryException(ERR_COMPILE_MODEL_FAILURE, e, model.getName()); } }
Example #13
Source File: CustomModelProperty.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
public CustomModelProperty(PropertyDefinition propertyDefinition, MessageLookup messageLookup) { this.name = propertyDefinition.getName().getLocalName(); this.prefixedName = propertyDefinition.getName().toPrefixString(); this.title = propertyDefinition.getTitle(messageLookup); this.dataType = propertyDefinition.getDataType().getName().toPrefixString(); this.description = propertyDefinition.getDescription(messageLookup); this.isMandatory = propertyDefinition.isMandatory(); this.isMandatoryEnforced = propertyDefinition.isMandatoryEnforced(); this.isMultiValued = propertyDefinition.isMultiValued(); this.defaultValue = propertyDefinition.getDefaultValue(); this.isIndexed = propertyDefinition.isIndexed(); this.facetable = propertyDefinition.getFacetable(); this.indexTokenisationMode = propertyDefinition.getIndexTokenisationMode(); List<ConstraintDefinition> constraintDefs = propertyDefinition.getConstraints(); if (constraintDefs.size() > 0) { this.constraintRefs = new ArrayList<>(); this.constraints = new ArrayList<>(); for (ConstraintDefinition cd : constraintDefs) { if (cd.getRef() != null) { constraintRefs.add(cd.getRef().toPrefixString()); } else { constraints.add(new CustomModelConstraint(cd, messageLookup)); } } } }
Example #14
Source File: NodeDefinitionMapperImpl.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
private List<NodeDefinitionConstraint> getConstraints( Collection<ConstraintDefinition> constraintDefinitions, MessageLookup messageLookup) { return constraintDefinitions.stream() .filter(constraint -> constraint.getConstraint() != null) .map(constraint -> fromConstraintDefinitionToConstraint(constraint, messageLookup)) .collect(Collectors.toList()); }
Example #15
Source File: NodeDefinitionMapperImpl.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
private NodeDefinitionConstraint fromConstraintDefinitionToConstraint(ConstraintDefinition constraintDefinition, MessageLookup messageLookup) { NodeDefinitionConstraint constraint = new NodeDefinitionConstraint(); constraint.setId(constraintDefinition.getConstraint().getShortName()); constraint.setType(constraintDefinition.getConstraint().getType()); constraint.setTitle(constraintDefinition.getTitle(messageLookup)); constraint.setDescription(constraintDefinition.getDescription(messageLookup)); constraint.setParameters(constraintDefinition.getConstraint().getParameters()); return constraint; }
Example #16
Source File: DelegateModelQuery.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 5 votes |
public ConstraintDefinition getConstraint(QName name) { ConstraintDefinition def = query.getConstraint(name); if (def == null) { def = delegate.getConstraint(name); } return def; }
Example #17
Source File: DictionaryDAOImpl.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 5 votes |
private Collection<ConstraintDefinition> getReferenceableConstraintDefs( CompiledModel model) { Collection<ConstraintDefinition> conDefs = model.getConstraints(); Collection<PropertyDefinition> propDefs = model.getProperties(); for (PropertyDefinition propDef : propDefs) { for (ConstraintDefinition conDef : propDef.getConstraints()) { conDefs.remove(conDef); } } return conDefs; }
Example #18
Source File: DictionaryDAOImpl.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 5 votes |
public Collection<ConstraintDefinition> getConstraints(QName modelName, boolean referenceableDefsOnly) { CompiledModel model = getCompiledModel(modelName); if (referenceableDefsOnly) { return getReferenceableConstraintDefs(model); } else { return model.getConstraints(); } }
Example #19
Source File: CustomModelsImpl.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
private List<CustomModelConstraint> convertToCustomModelConstraints(Collection<ConstraintDefinition> constraintDefinitions) { List<CustomModelConstraint> constraints = new ArrayList<>(constraintDefinitions.size()); for (ConstraintDefinition definition : constraintDefinitions) { constraints.add(new CustomModelConstraint(definition, dictionaryService)); } return constraints; }
Example #20
Source File: DictionaryDAOImpl.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 5 votes |
@Override public ConstraintDefinition getConstraint(QName constraintQName) { ConstraintDefinition constraintDef = null; if (constraintQName != null) { constraintDef = getTenantDictionaryRegistry().getConstraint( constraintQName); } return constraintDef; }
Example #21
Source File: RepoDictionaryDAOTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public void testConstraintsOverrideInheritance() { QName baseQName = QName.createQName(TEST_URL, "base"); QName fileQName = QName.createQName(TEST_URL, "file"); QName folderQName = QName.createQName(TEST_URL, "folder"); QName prop1QName = QName.createQName(TEST_URL, "prop1"); // get the base property PropertyDefinition prop1Def = service.getProperty(baseQName, prop1QName); assertNotNull(prop1Def); List<ConstraintDefinition> prop1Constraints = prop1Def.getConstraints(); assertEquals("Incorrect number of constraints", 3, prop1Constraints.size()); assertTrue("Constraint instance incorrect", prop1Constraints.get(0).getConstraint() instanceof RegexConstraint); assertTrue("Constraint instance incorrect", prop1Constraints.get(1).getConstraint() instanceof StringLengthConstraint); assertTrue("Constraint instance incorrect", prop1Constraints.get(2).getConstraint() instanceof RegisteredConstraint); // check the inherited property on folder (must be same as above) prop1Def = service.getProperty(folderQName, prop1QName); assertNotNull(prop1Def); prop1Constraints = prop1Def.getConstraints(); assertEquals("Incorrect number of constraints", 3, prop1Constraints.size()); assertTrue("Constraint instance incorrect", prop1Constraints.get(0).getConstraint() instanceof RegexConstraint); assertTrue("Constraint instance incorrect", prop1Constraints.get(1).getConstraint() instanceof StringLengthConstraint); assertTrue("Constraint instance incorrect", prop1Constraints.get(2).getConstraint() instanceof RegisteredConstraint); // check the overridden property on file (must be reverse of above) prop1Def = service.getProperty(fileQName, prop1QName); assertNotNull(prop1Def); prop1Constraints = prop1Def.getConstraints(); assertEquals("Incorrect number of constraints", 3, prop1Constraints.size()); assertTrue("Constraint instance incorrect", prop1Constraints.get(0).getConstraint() instanceof StringLengthConstraint); assertTrue("Constraint instance incorrect", prop1Constraints.get(1).getConstraint() instanceof RegexConstraint); assertTrue("Constraint instance incorrect", prop1Constraints.get(2).getConstraint() instanceof RegisteredConstraint); }
Example #22
Source File: CustomModelServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
@Override public ConstraintDefinition getCustomConstraint(QName name) { ParameterCheck.mandatory("name", name); CompiledModel compiledModel = getModelByUri(name.getNamespaceURI()); if (compiledModel != null) { return compiledModel.getConstraint(name); } return null; }
Example #23
Source File: ModelValidatorImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
private void validateDeleteConstraint(CompiledModel compiledModel, QName constraintName, boolean sharedModel) { String tenantDomain = TenantService.DEFAULT_DOMAIN; if (sharedModel) { tenantDomain = " for tenant [" + tenantService.getCurrentUserDomain() + "]"; } Set<QName> referencedBy = new HashSet<QName>(0); // check for references to constraint definition // note: could be anon prop constraint (if no referenceable constraint) Collection<QName> allModels = dictionaryDAO.getModels(); for (QName model : allModels) { Collection<PropertyDefinition> propDefs = null; if (compiledModel.getModelDefinition().getName().equals(model)) { // TODO deal with multiple pending model updates propDefs = compiledModel.getProperties(); } else { propDefs = dictionaryDAO.getProperties(model); } for (PropertyDefinition propDef : propDefs) { for (ConstraintDefinition conDef : propDef.getConstraints()) { if (constraintName.equals(conDef.getRef())) { referencedBy.add(conDef.getName()); } } } } if (referencedBy.size() == 1) { throw new AlfrescoRuntimeException("Failed to validate constraint delete" + tenantDomain + " - constraint definition '" + constraintName + "' is being referenced by '" + referencedBy.toArray()[0] + "' property constraint"); } else if (referencedBy.size() > 1) { throw new AlfrescoRuntimeException("Failed to validate constraint delete" + tenantDomain + " - constraint definition '" + constraintName + "' is being referenced by " + referencedBy.size() + " property constraints"); } }
Example #24
Source File: CustomModelsImpl.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
@Override public CustomModel createCustomModel(M2Model m2Model) { // Check the current user is authorised to import the custom model validateCurrentUser(); validateImportedM2Model(m2Model); CompiledModel compiledModel = null; try { compiledModel = customModelService.compileModel(m2Model); } catch (CustomModelConstraintException mce) { throw new ConstraintViolatedException(mce.getMessage()); } catch (InvalidCustomModelException iex) { throw new InvalidArgumentException(iex.getMessage()); } ModelDefinition modelDefinition = compiledModel.getModelDefinition(); CustomModel customModel = new CustomModel(); customModel.setName(modelDefinition.getName().getLocalName()); customModel.setAuthor(modelDefinition.getAuthor()); customModel.setDescription(modelDefinition.getDescription(dictionaryService)); customModel.setStatus(ModelStatus.DRAFT); NamespaceDefinition nsd = modelDefinition.getNamespaces().iterator().next(); customModel.setNamespaceUri(nsd.getUri()); customModel.setNamespacePrefix(nsd.getPrefix()); List<CustomType> customTypes = convertToCustomTypes(compiledModel.getTypes(), false); List<CustomAspect> customAspects = convertToCustomAspects(compiledModel.getAspects(), false); List<ConstraintDefinition> constraintDefinitions = CustomModelDefinitionImpl.removeInlineConstraints(compiledModel); List<CustomModelConstraint> customModelConstraints = convertToCustomModelConstraints(constraintDefinitions); customModel.setTypes(customTypes); customModel.setAspects(customAspects); customModel.setConstraints(customModelConstraints); return createCustomModelImpl(customModel, false); }
Example #25
Source File: AdminWebScriptTest.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
public List<ConstraintDefinition> getConstraints() { return null; }
Example #26
Source File: M2PropertyDefinition.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 4 votes |
public List<ConstraintDefinition> getConstraints() { return constraintDefs; }
Example #27
Source File: M2PropertyDefinition.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 4 votes |
/** * Create a property definition whose values are overridden * * @param propertyDef the property definition to override * @param override the overridden values * @return the property definition */ private M2Property createOverriddenProperty( PropertyDefinition propertyDef, M2PropertyOverride override, NamespacePrefixResolver prefixResolver, Map<QName, ConstraintDefinition> modelConstraints) { M2Property property = new M2Property(); property.setOverride(true); // Process Default Value String defaultValue = override.getDefaultValue(); property.setDefaultValue(defaultValue == null ? propertyDef.getDefaultValue() : defaultValue); // Process Mandatory Value Boolean isOverrideMandatory = override.isMandatory(); Boolean isOverrideMandatoryEnforced = override.isMandatoryEnforced(); if (isOverrideMandatory != null && propertyDef.isMandatory()) { // the override specified whether the property should be mandatory or not // check that the mandatory enforcement is not relaxed if (!isOverrideMandatory) { throw new DictionaryException( "d_dictionary.property.err.cannot_relax_mandatory", propertyDef.getName().toPrefixString()); } else if ((isOverrideMandatoryEnforced != null) && !isOverrideMandatoryEnforced && propertyDef.isMandatoryEnforced()) { throw new DictionaryException( "d_dictionary.property.err.cannot_relax_mandatory_enforcement", propertyDef.getName().toPrefixString()); } } property.setMandatory(isOverrideMandatory == null ? propertyDef.isMandatory() : isOverrideMandatory); property.setMandatoryEnforced(isOverrideMandatoryEnforced == null ? propertyDef.isMandatoryEnforced() : isOverrideMandatoryEnforced); // inherit or override constraints List<M2Constraint> overrideConstraints = override.getConstraints(); if (overrideConstraints != null) { constraintDefs = buildConstraints( overrideConstraints, this, prefixResolver, modelConstraints); } else { this.constraintDefs = propertyDef.getConstraints(); } // Copy all other properties as they are property.setDescription(propertyDef.getDescription(null)); property.setIndexed(propertyDef.isIndexed()); property.setIndexedAtomically(propertyDef.isIndexedAtomically()); property.setMultiValued(propertyDef.isMultiValued()); property.setProtected(propertyDef.isProtected()); property.setStoredInIndex(propertyDef.isStoredInIndex()); property.setTitle(propertyDef.getTitle(null)); property.setIndexTokenisationMode(propertyDef.getIndexTokenisationMode()); return property; }
Example #28
Source File: DataDictionaryBuilderImpl.java From alfresco-bulk-import with Apache License 2.0 | 4 votes |
/** * @see java.lang.Object#toString() */ @Override public String toString() { final StringBuilder result = new StringBuilder(1024); final Collection<Model> dataDictionary = getDataDictionary(); result.append("Models:"); if (dataDictionary != null) { for (Model model : dataDictionary) { ModelDefinition modelDefinition = model.model; result.append("\n\t"); result.append(modelDefinition.getName().toPrefixString()); result.append("\n\t\tNamespaces:"); Collection<NamespaceDefinition> namespaces = modelDefinition.getNamespaces(); if (namespaces != null && namespaces.size() > 0) { for (NamespaceDefinition namespace : namespaces) { result.append("\n\t\t\t"); result.append(namespace.getPrefix()); result.append(" = "); result.append(namespace.getUri()); } } else { result.append("\n\t\t\t<none>"); } result.append("\n\t\tConstraints:"); if (model.constraints != null && model.constraints.size() > 0) { for (ConstraintDefinition constraint : model.constraints) { result.append("\n\t\t\t"); result.append(constraint.getName().toPrefixString()); } } else { result.append("\n\t\t\t<none>"); } result.append("\n\t\tTypes:"); if (model.types != null && model.types.size() > 0) { for (TypeDefinition type : model.types) { result.append(classDefinitionToString(type)); } } else { result.append("\n\t\t\t<none>"); } result.append("\n\t\tAspects:"); if (model.aspects != null && model.aspects.size() > 0) { for (AspectDefinition aspect : model.aspects) { result.append(classDefinitionToString(aspect)); } } else { result.append("\n\t\t\t<none>"); } } } else { result.append("\n\t<none>"); } return(result.toString()); }
Example #29
Source File: M2PropertyDefinition.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 4 votes |
private static List<ConstraintDefinition> buildConstraints( List<M2Constraint> m2constraints, M2PropertyDefinition m2PropertyDef, NamespacePrefixResolver prefixResolver, Map<QName, ConstraintDefinition> modelConstraints) { List<ConstraintDefinition> constraints = new ArrayList<ConstraintDefinition>(5); Map<QName, ConstraintDefinition> constraintsByQName = new HashMap<QName, ConstraintDefinition>(7); for (M2Constraint constraint : m2constraints) { // Consistent naming scheme for anonymous property constraints if (constraint.getName() == null) { StringBuilder builder = new StringBuilder(); builder.append(m2PropertyDef.classDef.getModel().getName().getLocalName()).append("_"); builder.append(m2PropertyDef.classDef.getName().getLocalName()).append("_"); builder.append(m2PropertyDef.getName().getLocalName()).append("_"); builder.append("anon_"); builder.append(constraints.size()); QName newName = QName.createQName(m2PropertyDef.classDef.getModel().getName().getNamespaceURI(), builder.toString()); constraint.setName(newName.getPrefixedQName(prefixResolver).toPrefixString()); } ConstraintDefinition def = new M2ConstraintDefinition(m2PropertyDef, constraint, prefixResolver); QName qname = def.getName(); if (constraintsByQName.containsKey(qname)) { throw new DuplicateDefinitionException( "d_dictionary.property.err.duplicate_constraint_on_property", def.getName().toPrefixString(), m2PropertyDef.name.toPrefixString()); } else if (modelConstraints.containsKey(qname)) { throw new DuplicateDefinitionException( "d_dictionary.model.err.duplicate_constraint_on_model", def.getName().toPrefixString(), def.getModel().getName().toPrefixString()); } constraintsByQName.put(qname, def); constraints.add(def); modelConstraints.put(qname, def); } // done return constraints; }
Example #30
Source File: DataDictionaryBuilderImpl.java From alfresco-bulk-import with Apache License 2.0 | 4 votes |
private String classDefinitionToString(final ClassDefinition definition) { StringBuilder result = null; if (definition != null) { result = new StringBuilder(1024); result.append("\n\t\t\t"); result.append(definition.getName().toPrefixString()); result.append("\n\t\t\t\tParent: "); result.append(definition.getParentName() == null ? "<none>" : definition.getParentName().getPrefixString()); result.append("\n\t\t\t\tProperties:"); Map<QName,PropertyDefinition> properties = definition.getProperties(); if (properties != null && properties.size() > 0) { for (QName propertyName : properties.keySet()) { PropertyDefinition propertyDefinition = properties.get(propertyName); result.append("\n\t\t\t\t\t"); result.append(propertyName.toPrefixString()); result.append(" ("); result.append(propertyDefinition.getDataType().getName().getPrefixString()); result.append(")"); if (propertyDefinition.isMultiValued()) { result.append(" (multi-valued)"); } if (propertyDefinition.isMandatoryEnforced()) { result.append(" (mandatory)"); } List<ConstraintDefinition> propertyConstraints = propertyDefinition.getConstraints(); if (propertyConstraints != null && propertyConstraints.size() > 0) { result.append(" (constraints: "); for (ConstraintDefinition propertyConstraint : propertyConstraints) { result.append(propertyConstraint.getName().toPrefixString()); result.append(", "); } result.delete(result.length() - ", ".length(), result.length()); result.append(")"); } } } else { result.append("\n\t\t\t\t\t<none>"); } result.append("\n\t\t\t\tAssociations:"); Map<QName, AssociationDefinition> associations = definition.getAssociations(); if (associations != null && associations.size() > 0) { for (QName associationName : associations.keySet()) { AssociationDefinition associationDefinition = associations.get(associationName); result.append("\n\t\t\t\t\t"); result.append(associationName.toPrefixString()); result.append(associationDefinition.isChild() ? " (parent/child)" : " (peer)"); result.append(" (source: "); result.append(associationDefinition.getSourceClass().getName().toPrefixString()); result.append(")"); result.append(" (target: "); result.append(associationDefinition.getTargetClass().getName().toPrefixString()); result.append(")"); } } else { result.append("\n\t\t\t\t\t<none>"); } } return(result == null ? null : result.toString()); }