use of org.apache.chemistry.opencmis.commons.impl.dataobjects.CmisExtensionElementImpl in project alfresco-repository by Alfresco.
the class CMISConnector method createCMISObjectImpl.
@SuppressWarnings("unchecked")
private ObjectData createCMISObjectImpl(final CMISNodeInfo info, Properties nodeProps, String filter, boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter, boolean includePolicyIds, boolean includeAcl) {
final ObjectDataImpl result = new ObjectDataImpl();
// set allowable actions
if (includeAllowableActions) {
result.setAllowableActions(getAllowableActions(info));
}
// set policy ids
if (includePolicyIds) {
result.setPolicyIds(new PolicyIdListImpl());
}
if (info.isRelationship()) {
// set properties
result.setProperties(getAssocProperties(info, filter));
// set ACL
if (includeAcl) {
// association have no ACL - return an empty list of ACEs
result.setAcl(new AccessControlListImpl((List<Ace>) Collections.EMPTY_LIST));
result.setIsExactAcl(Boolean.FALSE);
}
} else {
// set properties
result.setProperties(nodeProps);
// set relationships
if (includeRelationships != IncludeRelationships.NONE) {
result.setRelationships(getRelationships(info.getNodeRef(), includeRelationships));
}
// set renditions
if (!RENDITION_NONE.equals(renditionFilter)) {
List<RenditionData> renditions = getRenditions(info.getNodeRef(), renditionFilter, null, null);
if ((renditions != null) && (!renditions.isEmpty())) {
result.setRenditions(renditions);
} else {
result.setRenditions(Collections.EMPTY_LIST);
}
}
// set ACL
if (includeAcl) {
AuthenticationUtil.runAsSystem(new RunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
Acl acl = getACL(info.getCurrentNodeNodeRef(), false);
if (acl != null) {
result.setAcl(acl);
result.setIsExactAcl(acl.isExact());
}
return null;
}
});
}
// add aspects
List<CmisExtensionElement> extensions = getAspectExtensions(info, filter, result.getProperties().getProperties().keySet());
if (!extensions.isEmpty()) {
result.getProperties().setExtensions(Collections.singletonList((CmisExtensionElement) new CmisExtensionElementImpl(ALFRESCO_EXTENSION_NAMESPACE, ASPECTS, null, extensions)));
}
}
return result;
}
use of org.apache.chemistry.opencmis.commons.impl.dataobjects.CmisExtensionElementImpl in project alfresco-repository by Alfresco.
the class CMISTest method testMNT9090.
@Test
public void testMNT9090() throws Exception {
AuthenticationUtil.pushAuthentication();
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
try {
final FileInfo fileInfo = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<FileInfo>() {
@Override
public FileInfo execute() throws Throwable {
NodeRef companyHomeNodeRef = repositoryHelper.getCompanyHome();
String folderName = GUID.generate();
FileInfo folderInfo = fileFolderService.create(companyHomeNodeRef, folderName, ContentModel.TYPE_FOLDER);
nodeService.setProperty(folderInfo.getNodeRef(), ContentModel.PROP_NAME, folderName);
assertNotNull(folderInfo);
String docName = GUID.generate();
FileInfo fileInfo = fileFolderService.create(folderInfo.getNodeRef(), docName, ContentModel.TYPE_CONTENT);
assertNotNull(fileInfo);
nodeService.setProperty(fileInfo.getNodeRef(), ContentModel.PROP_NAME, docName);
QName ASPECT_AUDIO = QName.createQName(NamespaceService.AUDIO_MODEL_1_0_URI, "audio");
Map<QName, Serializable> aspectProperties = new HashMap<QName, Serializable>();
nodeService.addAspect(fileInfo.getNodeRef(), ASPECT_AUDIO, aspectProperties);
return fileInfo;
}
});
withCmisService(new CmisServiceCallback<Void>() {
@Override
public Void execute(CmisService cmisService) {
// get repository id
List<RepositoryInfo> repositories = cmisService.getRepositoryInfos(null);
assertTrue(repositories.size() > 0);
RepositoryInfo repo = repositories.get(0);
String repositoryId = repo.getId();
String objectIdStr = fileInfo.getNodeRef().toString();
Holder<String> objectId = new Holder<String>(objectIdStr);
// try to overflow the value
Object value = BigInteger.valueOf(Integer.MAX_VALUE + 1l);
Properties properties = new PropertiesImpl();
List<CmisExtensionElement> extensions = new ArrayList<CmisExtensionElement>();
CmisExtensionElement valueElem = new CmisExtensionElementImpl(CMISConnector.ALFRESCO_EXTENSION_NAMESPACE, "value", null, value.toString());
List<CmisExtensionElement> valueElems = new ArrayList<CmisExtensionElement>();
valueElems.add(valueElem);
List<CmisExtensionElement> children = new ArrayList<CmisExtensionElement>();
Map<String, String> attributes = new HashMap<String, String>();
attributes.put("propertyDefinitionId", "audio:trackNumber");
children.add(new CmisExtensionElementImpl(CMISConnector.ALFRESCO_EXTENSION_NAMESPACE, "propertyInteger", attributes, valueElems));
List<CmisExtensionElement> propertyValuesExtension = new ArrayList<CmisExtensionElement>();
propertyValuesExtension.add(new CmisExtensionElementImpl(CMISConnector.ALFRESCO_EXTENSION_NAMESPACE, CMISConnector.PROPERTIES, null, children));
CmisExtensionElement setAspectsExtension = new CmisExtensionElementImpl(CMISConnector.ALFRESCO_EXTENSION_NAMESPACE, CMISConnector.SET_ASPECTS, null, propertyValuesExtension);
extensions.add(setAspectsExtension);
properties.setExtensions(extensions);
// should throw a CMISConstraintException
cmisService.updateProperties(repositoryId, objectId, null, properties, null);
fail();
return null;
}
}, CmisVersion.CMIS_1_0);
} catch (CmisConstraintException e) {
assertTrue(e.getMessage().startsWith("Value is out of range for property"));
// ok
} finally {
AuthenticationUtil.popAuthentication();
}
}
use of org.apache.chemistry.opencmis.commons.impl.dataobjects.CmisExtensionElementImpl in project alfresco-repository by Alfresco.
the class CMISConnector method getAspectExtensions.
/**
* Builds aspect extension.
*/
public List<CmisExtensionElement> getAspectExtensions(CMISNodeInfo info, String filter, Set<String> alreadySetProperties) {
List<CmisExtensionElement> extensions = new ArrayList<CmisExtensionElement>();
Set<String> propertyIds = new HashSet<String>(alreadySetProperties);
List<CmisExtensionElement> propertyExtensionList = new ArrayList<CmisExtensionElement>();
Set<String> filterSet = splitFilter(filter);
Set<QName> aspects = info.getNodeAspects();
for (QName aspect : aspects) {
TypeDefinitionWrapper aspectType = getOpenCMISDictionaryService().findNodeType(aspect);
if (aspectType == null) {
continue;
}
AspectDefinition aspectDefinition = dictionaryService.getAspect(aspect);
Map<QName, org.alfresco.service.cmr.dictionary.PropertyDefinition> aspectProperties = aspectDefinition.getProperties();
extensions.add(new CmisExtensionElementImpl(ALFRESCO_EXTENSION_NAMESPACE, APPLIED_ASPECTS, null, aspectType.getTypeId()));
for (PropertyDefinitionWrapper propDef : aspectType.getProperties()) {
boolean addPropertyToExtensionList = getRequestCmisVersion().equals(CmisVersion.CMIS_1_1) && aspectProperties.keySet().contains(propDef.getAlfrescoName());
// MNT-11876 : add property to extension even if it has been returned (CMIS 1.1)
if (propertyIds.contains(propDef.getPropertyId()) && !addPropertyToExtensionList) {
// 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);
propertyExtensionList.add(createAspectPropertyExtension(propDef.getPropertyDefinition(), value));
// mark property as 'added'
propertyIds.add(propDef.getPropertyId());
}
}
if (!propertyExtensionList.isEmpty()) {
CmisExtensionElementImpl propertiesExtension = new CmisExtensionElementImpl(ALFRESCO_EXTENSION_NAMESPACE, "properties", null, propertyExtensionList);
extensions.addAll(Collections.singletonList(propertiesExtension));
}
return extensions;
}
use of org.apache.chemistry.opencmis.commons.impl.dataobjects.CmisExtensionElementImpl in project alfresco-repository by Alfresco.
the class CMISConnector method createAspectPropertyExtension.
/**
* Creates a property extension element.
*/
@SuppressWarnings("rawtypes")
private CmisExtensionElement createAspectPropertyExtension(PropertyDefinition<?> propertyDefinition, Object value) {
String name;
switch(propertyDefinition.getPropertyType()) {
case BOOLEAN:
name = "propertyBoolean";
break;
case DATETIME:
name = "propertyDateTime";
break;
case DECIMAL:
name = "propertyDecimal";
break;
case INTEGER:
name = "propertyInteger";
break;
case ID:
name = "propertyId";
break;
default:
name = "propertyString";
}
Map<String, String> attributes = new HashMap<String, String>();
attributes.put("propertyDefinitionId", propertyDefinition.getId());
attributes.put("queryName", propertyDefinition.getQueryName());
// optional value
if (propertyDefinition.getDisplayName() != null && propertyDefinition.getDisplayName().trim().length() > 0) {
attributes.put("displayName", propertyDefinition.getDisplayName());
}
// optional value
if (propertyDefinition.getLocalName() != null && propertyDefinition.getLocalName().trim().length() > 0) {
attributes.put("localName", propertyDefinition.getLocalName());
}
List<CmisExtensionElement> propertyValues = new ArrayList<CmisExtensionElement>();
if (value != null) {
if (value instanceof List) {
for (Object o : ((List) value)) {
if (o != null) {
propertyValues.add(new CmisExtensionElementImpl(CMIS_NAMESPACE, "value", null, convertAspectPropertyValue(o)));
} else {
logger.warn("Unexpected null entry in list value for property " + propertyDefinition.getDisplayName() + ", value = " + value);
}
}
} else {
propertyValues.add(new CmisExtensionElementImpl(CMIS_NAMESPACE, "value", null, convertAspectPropertyValue(value)));
}
}
return new CmisExtensionElementImpl(CMIS_NAMESPACE, name, attributes, propertyValues);
}
Aggregations