Java Code Examples for org.alfresco.service.cmr.dictionary.ClassDefinition#getProperties()
The following examples show how to use
org.alfresco.service.cmr.dictionary.ClassDefinition#getProperties() .
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: WorkflowInterpreter.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
private void setupStartTaskParameters(TypeDefinition typeDef, Map<QName, Serializable> params) { // build a complete anonymous type for the start task List<AspectDefinition> aspects = typeDef.getDefaultAspects(); List<QName> aspectNames = new ArrayList<QName>(aspects.size()); getMandatoryAspects(typeDef, aspectNames); ClassDefinition startTaskDef = dictionaryService.getAnonymousType(typeDef.getName(), aspectNames); // apply default values Map<QName, PropertyDefinition> propertyDefs = startTaskDef.getProperties(); for (Map.Entry<QName, PropertyDefinition> entry : propertyDefs.entrySet()) { String defaultValue = entry.getValue().getDefaultValue(); if (params.get(entry.getKey()) == null) { if (defaultValue != null) { params.put(entry.getKey(), (Serializable)DefaultTypeConverter.INSTANCE.convert(entry.getValue().getDataType(), defaultValue)); } } else { params.put(entry.getKey(), (Serializable)DefaultTypeConverter.INSTANCE.convert(entry.getValue().getDataType(), params.get(entry.getKey()))); } } if (params.containsKey(WorkflowModel.ASSOC_ASSIGNEE)) { String value = (String)params.get(WorkflowModel.ASSOC_ASSIGNEE); ArrayList<NodeRef> assignees = new ArrayList<NodeRef>(); assignees.add(personService.getPerson(value)); params.put(WorkflowModel.ASSOC_ASSIGNEE, assignees); } params.put(WorkflowModel.ASSOC_PACKAGE, workflowService.createPackage(null)); }
Example 2
Source File: RepoDictionaryDAOTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public void testMandatoryEnforced() { // get the properties for the test type QName testEnforcedQName = QName.createQName(TEST_URL, "enforced"); ClassDefinition testEnforcedClassDef = service.getClass(testEnforcedQName); Map<QName, PropertyDefinition> testEnforcedPropertyDefs = testEnforcedClassDef.getProperties(); PropertyDefinition propertyDef = null; QName testMandatoryEnforcedQName = QName.createQName(TEST_URL, "mandatory-enforced"); propertyDef = testEnforcedPropertyDefs.get(testMandatoryEnforcedQName); assertNotNull("Property not found: " + testMandatoryEnforcedQName, propertyDef); assertTrue("Expected property to be mandatory: " + testMandatoryEnforcedQName, propertyDef.isMandatory()); assertTrue("Expected property to be mandatory-enforced: " + testMandatoryEnforcedQName, propertyDef.isMandatoryEnforced()); QName testMandatoryNotEnforcedQName = QName.createQName(TEST_URL, "mandatory-not-enforced"); propertyDef = testEnforcedPropertyDefs.get(testMandatoryNotEnforcedQName); assertNotNull("Property not found: " + testMandatoryNotEnforcedQName, propertyDef); assertTrue("Expected property to be mandatory: " + testMandatoryNotEnforcedQName, propertyDef.isMandatory()); assertFalse("Expected property to be mandatory-not-enforced: " + testMandatoryNotEnforcedQName, propertyDef.isMandatoryEnforced()); QName testMandatoryDefaultEnforcedQName = QName.createQName(TEST_URL, "mandatory-default-enforced"); propertyDef = testEnforcedPropertyDefs.get(testMandatoryDefaultEnforcedQName); assertNotNull("Property not found: " + testMandatoryDefaultEnforcedQName, propertyDef); assertTrue("Expected property to be mandatory: " + testMandatoryDefaultEnforcedQName, propertyDef.isMandatory()); assertFalse("Expected property to be mandatory-not-enforced: " + testMandatoryDefaultEnforcedQName, propertyDef.isMandatoryEnforced()); }
Example 3
Source File: DictionaryComponent.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 5 votes |
public PropertyDefinition getProperty(QName className, QName propertyName) { PropertyDefinition propDef = null; ClassDefinition classDef = dictionaryDAO.getClass(className); if (classDef != null) { Map<QName,PropertyDefinition> propDefs = classDef.getProperties(); propDef = propDefs.get(propertyName); } return propDef; }
Example 4
Source File: DictionaryComponent.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 5 votes |
public Map<QName,PropertyDefinition> getPropertyDefs(QName className) { ClassDefinition classDef = dictionaryDAO.getClass(className); if (classDef != null) { return classDef.getProperties(); } return null; }
Example 5
Source File: DictionaryDAOTest.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void testMandatoryEnforced() { // get the properties for the test type QName testEnforcedQName = QName.createQName(TEST_URL, "enforced"); ClassDefinition testEnforcedClassDef = service.getClass(testEnforcedQName); Map<QName, PropertyDefinition> testEnforcedPropertyDefs = testEnforcedClassDef.getProperties(); PropertyDefinition propertyDef = null; QName testMandatoryEnforcedQName = QName.createQName(TEST_URL, "mandatory-enforced"); propertyDef = testEnforcedPropertyDefs.get(testMandatoryEnforcedQName); assertNotNull("Property not found: " + testMandatoryEnforcedQName, propertyDef); assertTrue("Expected property to be mandatory: " + testMandatoryEnforcedQName, propertyDef.isMandatory()); assertTrue("Expected property to be mandatory-enforced: " + testMandatoryEnforcedQName, propertyDef.isMandatoryEnforced()); QName testMandatoryNotEnforcedQName = QName.createQName(TEST_URL, "mandatory-not-enforced"); propertyDef = testEnforcedPropertyDefs.get(testMandatoryNotEnforcedQName); assertNotNull("Property not found: " + testMandatoryNotEnforcedQName, propertyDef); assertTrue("Expected property to be mandatory: " + testMandatoryNotEnforcedQName, propertyDef.isMandatory()); assertFalse("Expected property to be mandatory-not-enforced: " + testMandatoryNotEnforcedQName, propertyDef.isMandatoryEnforced()); QName testMandatoryDefaultEnforcedQName = QName.createQName(TEST_URL, "mandatory-default-enforced"); propertyDef = testEnforcedPropertyDefs.get(testMandatoryDefaultEnforcedQName); assertNotNull("Property not found: " + testMandatoryDefaultEnforcedQName, propertyDef); assertTrue("Expected property to be mandatory: " + testMandatoryDefaultEnforcedQName, propertyDef.isMandatory()); assertFalse("Expected property to be mandatory-not-enforced: " + testMandatoryDefaultEnforcedQName, propertyDef.isMandatoryEnforced()); }
Example 6
Source File: VersionServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
@Override protected void defaultOnCreateVersion( QName classRef, NodeRef nodeRef, Map<String, Serializable> versionProperties, PolicyScope nodeDetails) { ClassDefinition classDefinition = this.dictionaryService.getClass(classRef); if (classDefinition != null) { boolean wasMLAware = MLPropertyInterceptor.setMLAware(true); try { // Copy the properties (along with their aspect) Map<QName,PropertyDefinition> propertyDefinitions = classDefinition.getProperties(); for (QName propertyName : propertyDefinitions.keySet()) { Serializable propValue = this.nodeService.getProperty(nodeRef, propertyName); nodeDetails.addProperty(classRef, propertyName, propValue); } // Also copy the aspect with no properties in its definition if (classDefinition.isAspect() && !nodeDetails.getAspects().contains(classRef)) { nodeDetails.addAspect(classRef); } } finally { MLPropertyInterceptor.setMLAware(wasMLAware); } // Version the associations (child and target) Map<QName, AssociationDefinition> assocDefs = classDefinition.getAssociations(); // TODO: Need way of getting child assocs of a given type if (classDefinition.isContainer()) { List<ChildAssociationRef> childAssocRefs = this.nodeService.getChildAssocs(nodeRef); for (ChildAssociationRef childAssocRef : childAssocRefs) { if (assocDefs.containsKey(childAssocRef.getTypeQName())) { nodeDetails.addChildAssociation(classDefinition.getName(), childAssocRef); } } } // TODO: Need way of getting assocs of a given type List<AssociationRef> nodeAssocRefs = this.nodeService.getTargetAssocs(nodeRef, RegexQNamePattern.MATCH_ALL); for (AssociationRef nodeAssocRef : nodeAssocRefs) { if (assocDefs.containsKey(nodeAssocRef.getTypeQName())) { nodeDetails.addAssociation(classDefinition.getName(), nodeAssocRef); } } } }
Example 7
Source File: CopyServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * Constructs the properties to copy that apply to the type and default aspects */ private Map<QName, Serializable> buildCopyProperties( CopyDetails copyDetails, Set<QName> classQNames, Map<QName, CopyBehaviourCallback> callbacks) { Map<QName, Serializable> sourceNodeProperties = copyDetails.getSourceNodeProperties(); Map<QName, Serializable> copyProperties = new HashMap<QName, Serializable>(sourceNodeProperties.size(), 1.0F); Map<QName, Serializable> scratchProperties = new HashMap<QName, Serializable>(11); // Each defined callback gets a chance to say which properties get copied // Only model-defined properties are considered for (QName classQName : classQNames) { CopyBehaviourCallback callback = callbacks.get(classQName); if (callback == null) { throw new IllegalStateException("Source node class has no callback: " + classQName); } // Ignore if not present or if not scheduled for a copy if (!callback.getMustCopy(classQName, copyDetails)) { continue; } // Get the dictionary definition ClassDefinition classDef = dictionaryService.getClass(classQName); if (classDef == null) { continue; } // Get the defined properties Map<QName, PropertyDefinition> propertyDefs = classDef.getProperties(); // Extract these from the source nodes properties and store in a safe (modifiable) map scratchProperties.clear(); for (QName propertyQName : propertyDefs.keySet()) { if (sourceNodeProperties.containsKey(propertyQName)) { Serializable value = sourceNodeProperties.get(propertyQName); scratchProperties.put(propertyQName, value); } } // What does the behaviour do with properties? Map<QName, Serializable> propsToCopy = callback.getCopyProperties(classQName, copyDetails, scratchProperties); // Add to the final properties copyProperties.putAll(propsToCopy); } // Done return copyProperties; }
Example 8
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()); }