use of org.alfresco.service.cmr.dictionary.PropertyDefinition in project alfresco-remote-api by Alfresco.
the class RestVariableHelper method setVariableValueAndType.
/**
* Sets the variable value with possible conversion to the correct format to be used in the response and sets
* the type accordingly. If the variables is defined on the {@link TypeDefinition}, the data-type is used. If it's not
* defined, the type is deducted from the raw variable value.
*/
protected void setVariableValueAndType(Variable variable, Object value, TypeDefinitionContext context) {
PropertyDefinition propDef = context.getPropertyDefinition(variable.getName());
if (propDef != null) {
variable.setValue(getSafePropertyValue(value));
variable.setType(propDef.getDataType().getName().toPrefixString(namespaceService));
} else {
// Not defined as a property, check if it's an association
AssociationDefinition assocDef = context.getAssociationDefinition(variable.getName());
if (assocDef == null) {
// Try to get an association definition through dictionary
String[] prefixLocalName = variable.getName().split("_");
if (prefixLocalName.length == 2) {
QName qName = QName.createQName(prefixLocalName[0], prefixLocalName[1], namespaceService);
assocDef = dictionaryService.getAssociation(qName);
}
}
if (assocDef != null) {
// Type of variable is the target class-name
variable.setType(assocDef.getTargetClass().getName().toPrefixString(namespaceService));
variable.setValue(getAssociationRepresentation(value, assocDef));
} else {
// Variable is not declared as property or association type-def. Use actual raw value as base for conversion.
variable.setValue(getSafePropertyValue(value));
variable.setType(extractTypeStringFromValue(value));
}
}
}
use of org.alfresco.service.cmr.dictionary.PropertyDefinition in project alfresco-remote-api by Alfresco.
the class AdminWebScriptTest method testResidualProperties.
@Test
public // ALF-21950 We check now if the property belongs to the type of the node
void testResidualProperties() throws Exception {
NodeBrowserPost nodeBrowserPost = new NodeBrowserPost();
DictionaryService dictionaryService = mock(DictionaryService.class);
NodeService nodeService = mock(NodeService.class);
nodeBrowserPost.setDictionaryService(dictionaryService);
nodeBrowserPost.setNodeService(nodeService);
// make own class definition from origin type
ClassDefinition classDefinition = mock(ClassDefinition.class);
when(dictionaryService.getClass(any())).thenReturn(classDefinition);
QName qnameResidualFalse1 = QName.createQName("testResidualProperties", "residualFalse1");
QName qnameResidualFalse2 = QName.createQName("testResidualProperties", "residualFalse2");
QName qnameResidualTrue1 = QName.createQName("testResidualProperties", "residualTrue1");
QName qnameResidualTrue2 = QName.createQName("testResidualProperties", "residualTrue2");
// Define residual False properties inside of class definition
// That simulates the belonging of the properties to a given type of a node
Map<QName, PropertyDefinition> properties = new HashMap<>();
properties.put(qnameResidualFalse1, new SimplePropertyDefinition(false));
properties.put(qnameResidualFalse2, new SimplePropertyDefinition(true));
when(classDefinition.getProperties()).thenReturn(properties);
when(dictionaryService.getProperty(eq(qnameResidualFalse1))).thenReturn(new SimplePropertyDefinition(false));
when(dictionaryService.getProperty(eq(qnameResidualFalse2))).thenReturn(new SimplePropertyDefinition(true));
when(dictionaryService.getProperty(eq(qnameResidualTrue1))).thenReturn(new SimplePropertyDefinition(true));
when(dictionaryService.getProperty(eq(qnameResidualTrue2))).thenReturn(new SimplePropertyDefinition(false));
// property found in definition so it is not residual
String value = "abc";
NodeBrowserPost.Property property = nodeBrowserPost.new Property(qnameResidualFalse1, value, null);
assertFalse(property.getResidual());
// property belongs to an aspect so it is not residual
property = nodeBrowserPost.new Property(qnameResidualFalse2, value, null);
assertFalse(property.getResidual());
// property not found in definition but it is an aspect so it is not residual
property = nodeBrowserPost.new Property(qnameResidualTrue1, value, null);
assertFalse(property.getResidual());
// property not found in definition so it is residual
property = nodeBrowserPost.new Property(qnameResidualTrue2, value, null);
assertTrue(property.getResidual());
}
use of org.alfresco.service.cmr.dictionary.PropertyDefinition in project alfresco-remote-api by Alfresco.
the class NodesImpl method mapToNodeProperties.
public Map<QName, Serializable> mapToNodeProperties(Map<String, Object> props) {
Map<QName, Serializable> nodeProps = new HashMap<>(props.size());
for (Entry<String, Object> entry : props.entrySet()) {
String propName = entry.getKey();
QName propQName = createQName(propName);
PropertyDefinition pd = dictionaryService.getProperty(propQName);
if (pd != null) {
Serializable value = null;
if (entry.getValue() != null) {
if (pd.getDataType().getName().equals(DataTypeDefinition.NODE_REF)) {
String nodeRefString = (String) entry.getValue();
if (!NodeRef.isNodeRef(nodeRefString)) {
value = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, nodeRefString);
} else {
value = new NodeRef(nodeRefString);
}
} else {
value = (Serializable) entry.getValue();
}
}
nodeProps.put(propQName, value);
} else {
throw new InvalidArgumentException("Unknown property: " + propName);
}
}
return nodeProps;
}
use of org.alfresco.service.cmr.dictionary.PropertyDefinition in project alfresco-remote-api by Alfresco.
the class WorkflowModelBuilder method buildPropertyLabels.
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;
}
});
}
use of org.alfresco.service.cmr.dictionary.PropertyDefinition in project alfresco-remote-api by Alfresco.
the class PropPatchMethod method patchProperties.
protected void patchProperties(FileInfo nodeInfo, String path) throws WebDAVServerException {
failedProperty = null;
for (PropertyAction action : m_propertyActions) {
if (action.getProperty().isProtected()) {
failedProperty = action.getProperty();
break;
}
}
Map<QName, String> deadProperties = null;
for (PropertyAction propertyAction : m_propertyActions) {
int statusCode;
String statusCodeDescription;
WebDAVProperty property = propertyAction.getProperty();
if (failedProperty == null) {
PropertyDefinition propDef = getDAVHelper().getDictionaryService().getProperty(property.createQName());
boolean deadProperty = propDef == null || (!propDef.getContainerClass().isAspect() && !getDAVHelper().getDictionaryService().isSubClass(getNodeService().getType(nodeInfo.getNodeRef()), propDef.getContainerClass().getName()));
if (deadProperty && deadProperties == null) {
deadProperties = loadDeadProperties(nodeInfo.getNodeRef());
}
if (PropertyAction.SET == propertyAction.getAction()) {
if (deadProperty) {
deadProperties.put(property.createQName(), property.getValue());
} else {
getNodeService().setProperty(nodeInfo.getNodeRef(), property.createQName(), property.getValue());
}
} else if (PropertyAction.REMOVE == propertyAction.getAction()) {
if (deadProperty) {
deadProperties.remove(property.createQName());
} else {
getNodeService().removeProperty(nodeInfo.getNodeRef(), property.createQName());
}
} else {
throw new WebDAVServerException(HttpServletResponse.SC_BAD_REQUEST);
}
statusCode = HttpServletResponse.SC_OK;
statusCodeDescription = WebDAV.SC_OK_DESC;
} else if (failedProperty == property) {
statusCode = HttpServletResponse.SC_FORBIDDEN;
statusCodeDescription = WebDAV.SC_FORBIDDEN_DESC;
} else {
statusCode = WebDAV.WEBDAV_SC_FAILED_DEPENDENCY;
statusCodeDescription = WebDAV.WEBDAV_SC_FAILED_DEPENDENCY_DESC;
}
propertyAction.setResult(statusCode, statusCodeDescription);
}
if (deadProperties != null) {
persistDeadProperties(nodeInfo.getNodeRef(), deadProperties);
}
}
Aggregations