//------------------------------------------< private >---
private void setProperties(Node node, String typeId, Properties properties) {
if (properties == null || properties.getProperties() == null) {
throw new CmisConstraintException("No properties!");
}
Set<String> addedProps = new HashSet<String>();
// get the property definitions
TypeDefinition type = typeManager.getType(typeId);
if (type == null) {
throw new CmisObjectNotFoundException("Type '" + typeId + "' is unknown!");
}
try {
// check if all required properties are there
for (PropertyData<?> prop : properties.getProperties().values()) {
PropertyDefinition<?> propDef = type.getPropertyDefinitions().get(prop.getId());
// do we know that property?
if (propDef == null) {
throw new CmisConstraintException("Property '" + prop.getId() + "' is unknown!");
}
// skip type id
if (propDef.getId().equals(PropertyIds.OBJECT_TYPE_ID)) {
addedProps.add(prop.getId());
continue;
}
// can it be set?
if (propDef.getUpdatability() == Updatability.READONLY) {
throw new CmisConstraintException("Property '" + prop.getId() + "' is readonly!");
}
// empty properties are invalid
if (PropertyHelper.isPropertyEmpty(prop)) {
throw new CmisConstraintException("Property '" + prop.getId() + "' must not be empty!");
}
// add it
JcrConverter.setProperty(node, prop);
addedProps.add(prop.getId());
}
// check if required properties are missing and try to add default values if defined
for (PropertyDefinition<?> propDef : type.getPropertyDefinitions().values()) {
if (!addedProps.contains(propDef.getId()) && propDef.getUpdatability() != Updatability.READONLY) {
PropertyData<?> prop = PropertyHelper.getDefaultValue(propDef);
if (prop == null && propDef.isRequired()) {
throw new CmisConstraintException("Property '" + propDef.getId() + "' is required!");
}
else if (prop != null) {
JcrConverter.setProperty(node, prop);
}
}