use of org.alfresco.opencmis.dictionary.TypeDefinitionWrapper in project alfresco-repository by Alfresco.
the class CMISConnector method removeSecondaryTypes.
public void removeSecondaryTypes(NodeRef nodeRef, List<String> secondaryTypes) {
if (secondaryTypes != null && secondaryTypes.size() > 0) {
for (String secondaryType : secondaryTypes) {
TypeDefinitionWrapper type = getType(secondaryType);
if (type == null) {
throw new CmisInvalidArgumentException("Invalid secondaryType: " + secondaryType);
}
nodeService.removeAspect(nodeRef, type.getAlfrescoName());
}
}
}
use of org.alfresco.opencmis.dictionary.TypeDefinitionWrapper in project alfresco-repository by Alfresco.
the class CMISConnector method processSecondaryTypes.
@SuppressWarnings("rawtypes")
private void processSecondaryTypes(NodeRef nodeRef, List secondaryTypes, Map<String, Pair<TypeDefinitionWrapper, Serializable>> propsToAdd) {
// diff existing aspects and secondaryTypes/aspects list
Set<QName> existingAspects = nodeService.getAspects(nodeRef);
Set<QName> secondaryTypeAspects = new HashSet<QName>();
for (Object o : secondaryTypes) {
String secondaryType = (String) o;
TypeDefinitionWrapper wrapper = getOpenCMISDictionaryService().findType(secondaryType);
if (wrapper != null) {
QName aspectQName = wrapper.getAlfrescoName();
secondaryTypeAspects.add(aspectQName);
} else {
throw new CmisInvalidArgumentException("Invalid secondary type id " + secondaryType);
}
}
Set<QName> aspectsToIgnore = new HashSet<>();
aspectsToIgnore.add(ContentModel.ASPECT_REFERENCEABLE);
aspectsToIgnore.add(ContentModel.ASPECT_LOCALIZED);
aspectsToIgnore.add(ContentModel.ASPECT_WORKING_COPY);
Set<String> namespacesToIgnore = new HashSet<>(singletonList(NamespaceService.SYSTEM_MODEL_1_0_URI));
// aspects to add == the list of secondary types - existing aspects - ignored aspects
Set<QName> toAdd = new HashSet<QName>(secondaryTypeAspects);
toAdd.removeAll(existingAspects);
toAdd.removeAll(aspectsToIgnore);
toAdd.removeIf(a -> namespacesToIgnore.contains(a.getNamespaceURI()));
// aspects to remove == existing aspects - secondary types
Set<QName> aspectsToRemove = new HashSet<QName>();
aspectsToRemove.addAll(existingAspects);
aspectsToRemove.removeAll(aspectsToIgnore);
Iterator<QName> it = aspectsToRemove.iterator();
while (it.hasNext()) {
QName aspectQName = it.next();
TypeDefinitionWrapper w = getOpenCMISDictionaryService().findNodeType(aspectQName);
if (w == null || secondaryTypeAspects.contains(aspectQName) || namespacesToIgnore.contains(aspectQName.getNamespaceURI())) {
// the type is not exposed,
// or is in the secondary types to set,
// or is in the set of namespaces to ignore,
// so remove it from the "to remove" set
it.remove();
}
}
// first, remove aspects
for (QName aspectQName : aspectsToRemove) {
nodeService.removeAspect(nodeRef, aspectQName);
}
// add aspects and properties
for (QName aspectQName : toAdd) {
nodeService.addAspect(nodeRef, aspectQName, null);
}
}
use of org.alfresco.opencmis.dictionary.TypeDefinitionWrapper in project alfresco-repository by Alfresco.
the class CMISConnector method setAspectProperties.
private void setAspectProperties(NodeRef nodeRef, boolean isNameChanging, CmisExtensionElement aspectExtension) {
if (aspectExtension.getChildren() == null) {
return;
}
List<String> aspectsToAdd = new ArrayList<String>();
List<String> aspectsToRemove = new ArrayList<String>();
Map<QName, List<Serializable>> aspectProperties = new HashMap<QName, List<Serializable>>();
for (CmisExtensionElement extension : aspectExtension.getChildren()) {
if (!ALFRESCO_EXTENSION_NAMESPACE.equals(extension.getNamespace())) {
continue;
}
if (ASPECTS_TO_ADD.equals(extension.getName()) && (extension.getValue() != null)) {
aspectsToAdd.add(extension.getValue());
} else if (ASPECTS_TO_REMOVE.equals(extension.getName()) && (extension.getValue() != null)) {
aspectsToRemove.add(extension.getValue());
} else if (PROPERTIES.equals(extension.getName()) && (extension.getChildren() != null)) {
for (CmisExtensionElement property : extension.getChildren()) {
if (!property.getName().startsWith("property")) {
continue;
}
String propertyId = (property.getAttributes() == null ? null : property.getAttributes().get("propertyDefinitionId"));
if ((propertyId == null) || (property.getChildren() == null)) {
continue;
}
PropertyType propertyType = PropertyType.STRING;
DatatypeFactory df = null;
if (property.getName().equals("propertyBoolean")) {
propertyType = PropertyType.BOOLEAN;
} else if (property.getName().equals("propertyInteger")) {
propertyType = PropertyType.INTEGER;
} else if (property.getName().equals("propertyDateTime")) {
propertyType = PropertyType.DATETIME;
try {
df = DatatypeFactory.newInstance();
} catch (DatatypeConfigurationException e) {
throw new CmisRuntimeException("Aspect conversation exception: " + e.getMessage(), e);
}
} else if (property.getName().equals("propertyDecimal")) {
propertyType = PropertyType.DECIMAL;
}
ArrayList<Serializable> values = new ArrayList<Serializable>();
if (property.getChildren() != null) {
// {
for (CmisExtensionElement valueElement : property.getChildren()) {
if ("value".equals(valueElement.getName())) {
switch(propertyType) {
case BOOLEAN:
try {
values.add(Boolean.parseBoolean(valueElement.getValue()));
} catch (Exception e) {
throw new CmisInvalidArgumentException("Invalid property aspect value: " + propertyId, e);
}
break;
case DATETIME:
try {
values.add(df.newXMLGregorianCalendar(valueElement.getValue()).toGregorianCalendar());
} catch (Exception e) {
throw new CmisInvalidArgumentException("Invalid property aspect value: " + propertyId, e);
}
break;
case INTEGER:
BigInteger value = null;
try {
value = new BigInteger(valueElement.getValue());
} catch (Exception e) {
throw new CmisInvalidArgumentException("Invalid property aspect value: " + propertyId, e);
}
// overflow check
PropertyDefinitionWrapper propDef = getOpenCMISDictionaryService().findProperty(propertyId);
if (propDef == null) {
throw new CmisInvalidArgumentException("Property " + propertyId + " is unknown!");
}
QName propertyQName = propDef.getPropertyAccessor().getMappedProperty();
if (propertyQName == null) {
throw new CmisConstraintException("Unable to set property " + propertyId + "!");
}
org.alfresco.service.cmr.dictionary.PropertyDefinition def = dictionaryService.getProperty(propertyQName);
QName dataDef = def.getDataType().getName();
if (dataDef.equals(DataTypeDefinition.INT) && (value.compareTo(maxInt) > 0 || value.compareTo(minInt) < 0)) {
throw new CmisConstraintException("Value is out of range for property " + propertyId);
}
if (dataDef.equals(DataTypeDefinition.LONG) && (value.compareTo(maxLong) > 0 || value.compareTo(minLong) < 0)) {
throw new CmisConstraintException("Value is out of range for property " + propertyId);
}
values.add(value);
break;
case DECIMAL:
try {
values.add(new BigDecimal(valueElement.getValue()));
} catch (Exception e) {
throw new CmisInvalidArgumentException("Invalid property aspect value: " + propertyId, e);
}
break;
default:
values.add(valueElement.getValue());
}
}
}
}
aspectProperties.put(QName.createQName(propertyId, namespaceService), values);
}
}
}
// remove and add aspects
String aspectType = null;
try {
for (String aspect : aspectsToRemove) {
aspectType = aspect;
TypeDefinitionWrapper type = getType(aspect);
if (type == null) {
throw new CmisInvalidArgumentException("Invalid aspect: " + aspectType);
}
QName typeName = type.getAlfrescoName();
// if aspect is hidden aspect, remove only if hidden node is not client controlled
if (typeName.equals(ContentModel.ASPECT_HIDDEN)) {
if (hiddenAspect.isClientControlled(nodeRef) || aspectProperties.containsKey(ContentModel.PROP_CLIENT_CONTROLLED)) {
// manipulate hidden aspect only if client controlled
nodeService.removeAspect(nodeRef, typeName);
}
// if(!isNameChanging && !hiddenAspect.isClientControlled(nodeRef) && !aspectProperties.containsKey(ContentModel.PROP_CLIENT_CONTROLLED))
// {
// nodeService.removeAspect(nodeRef, typeName);
// }
} else {
nodeService.removeAspect(nodeRef, typeName);
}
}
for (String aspect : aspectsToAdd) {
aspectType = aspect;
TypeDefinitionWrapper type = getType(aspect);
if (type == null) {
throw new CmisInvalidArgumentException("Invalid aspect: " + aspectType);
}
QName typeName = type.getAlfrescoName();
// if aspect is hidden aspect, remove only if hidden node is not client controlled
if (typeName.equals(ContentModel.ASPECT_HIDDEN)) {
if (hiddenAspect.isClientControlled(nodeRef) || aspectProperties.containsKey(ContentModel.PROP_CLIENT_CONTROLLED)) {
// manipulate hidden aspect only if client controlled
nodeService.addAspect(nodeRef, type.getAlfrescoName(), Collections.<QName, Serializable>emptyMap());
}
// if(!isNameChanging && !hiddenAspect.isClientControlled(nodeRef) && !aspectProperties.containsKey(ContentModel.PROP_CLIENT_CONTROLLED))
// {
// nodeService.addAspect(nodeRef, type.getAlfrescoName(),
// Collections.<QName, Serializable> emptyMap());
// }
} else {
nodeService.addAspect(nodeRef, type.getAlfrescoName(), Collections.<QName, Serializable>emptyMap());
}
}
} catch (InvalidAspectException e) {
throw new CmisInvalidArgumentException("Invalid aspect: " + aspectType);
} catch (InvalidNodeRefException e) {
throw new CmisInvalidArgumentException("Invalid node: " + nodeRef);
}
// set property
for (Map.Entry<QName, List<Serializable>> property : aspectProperties.entrySet()) {
QName propertyQName = property.getKey();
if (property.getValue().isEmpty()) {
if (HiddenAspect.HIDDEN_PROPERTIES.contains(property.getKey())) {
if (hiddenAspect.isClientControlled(nodeRef) || aspectProperties.containsKey(ContentModel.PROP_CLIENT_CONTROLLED)) {
// manipulate hidden aspect property only if client controlled
nodeService.removeProperty(nodeRef, propertyQName);
}
} else {
nodeService.removeProperty(nodeRef, property.getKey());
}
} else {
if (HiddenAspect.HIDDEN_PROPERTIES.contains(property.getKey())) {
if (hiddenAspect.isClientControlled(nodeRef) || aspectProperties.containsKey(ContentModel.PROP_CLIENT_CONTROLLED)) {
// manipulate hidden aspect property only if client controlled
nodeService.setProperty(nodeRef, property.getKey(), property.getValue().size() == 1 ? property.getValue().get(0) : (Serializable) property.getValue());
}
} else {
Serializable value = (Serializable) property.getValue();
nodeService.setProperty(nodeRef, property.getKey(), property.getValue().size() == 1 ? property.getValue().get(0) : value);
}
}
}
}
use of org.alfresco.opencmis.dictionary.TypeDefinitionWrapper in project alfresco-repository by Alfresco.
the class CMISConnector method addAspectProperties.
private void addAspectProperties(CMISNodeInfo info, String filter, PropertiesImpl result) {
if (getRequestCmisVersion().equals(CmisVersion.CMIS_1_1)) {
Set<String> propertyIds = new HashSet<>();
Set<String> filterSet = splitFilter(filter);
Set<QName> aspects = info.getNodeAspects();
for (QName aspect : aspects) {
TypeDefinitionWrapper aspectType = getOpenCMISDictionaryService().findNodeType(aspect);
if (aspectType == null) {
continue;
}
for (PropertyDefinitionWrapper propDef : aspectType.getProperties()) {
if (propertyIds.contains(propDef.getPropertyId())) {
// skip properties that have already been added
continue;
}
if ((filterSet != null) && (!filterSet.contains(propDef.getPropertyDefinition().getQueryName()))) {
// skip properties that are not in the filter
continue;
}
Serializable value = propDef.getPropertyAccessor().getValue(info);
result.addProperty(getProperty(propDef.getPropertyDefinition().getPropertyType(), propDef, value));
// mark property as 'added'
propertyIds.add(propDef.getPropertyId());
}
}
}
}
use of org.alfresco.opencmis.dictionary.TypeDefinitionWrapper in project alfresco-repository by Alfresco.
the class CMISConnector method createObjectId.
public String createObjectId(NodeRef nodeRef, boolean dropStoreRef) {
QName typeQName = nodeService.getType(nodeRef);
TypeDefinitionWrapper type = getOpenCMISDictionaryService().findNodeType(typeQName);
if (type instanceof ItemTypeDefinitionWrapper) {
return constructObjectId(nodeRef, null);
}
if (type instanceof FolderTypeDefintionWrapper) {
return constructObjectId(nodeRef, null, dropStoreRef);
}
Serializable versionLabel = getNodeService().getProperty(nodeRef, ContentModel.PROP_VERSION_LABEL);
if (versionLabel == null) {
versionLabel = CMISConnector.UNVERSIONED_VERSION_LABEL;
}
return constructObjectId(nodeRef, (String) versionLabel, dropStoreRef);
}
Aggregations