use of org.apache.chemistry.opencmis.commons.data.CmisExtensionElement in project alfresco-repository by Alfresco.
the class CMISTest method testMNT10021.
/**
* CMIS 1.0 aspect properties should provide the following CMIS attributes:
* propertyDefinitionId, displayName, localName, queryName
*/
@Test
public void testMNT10021() throws Exception {
final String folderName = "testfolder." + GUID.generate();
final String docName = "testdoc.txt." + GUID.generate();
AuthenticationUtil.pushAuthentication();
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
try {
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
NodeRef companyHomeNodeRef = repositoryHelper.getCompanyHome();
FileInfo folderInfo = fileFolderService.create(companyHomeNodeRef, folderName, ContentModel.TYPE_FOLDER);
nodeService.setProperty(folderInfo.getNodeRef(), ContentModel.PROP_NAME, folderName);
assertNotNull(folderInfo);
FileInfo document = fileFolderService.create(folderInfo.getNodeRef(), docName, ContentModel.TYPE_CONTENT);
assertNotNull(document);
nodeService.setProperty(document.getNodeRef(), ContentModel.PROP_NAME, docName);
// lock adds aspects to the document with properties: lockIsDeep, lockOwner, lockType, expiryDate, lockLifetime
lockService.lock(document.getNodeRef(), LockType.READ_ONLY_LOCK, 0, true);
return null;
}
});
final ObjectData objectData = withCmisService(new CmisServiceCallback<ObjectData>() {
@Override
public ObjectData execute(CmisService cmisService) {
List<RepositoryInfo> repositories = cmisService.getRepositoryInfos(null);
assertTrue(repositories.size() > 0);
RepositoryInfo repo = repositories.get(0);
String repositoryId = repo.getId();
ObjectData objectData = cmisService.getObjectByPath(repositoryId, "/" + folderName + "/" + docName, null, true, IncludeRelationships.NONE, null, false, true, null);
return objectData;
}
}, CmisVersion.CMIS_1_0);
List<CmisExtensionElement> propertyExtensionList = objectData.getProperties().getExtensions();
assertEquals("propertyExtensionList should be singletonList", propertyExtensionList.size(), 1);
List<CmisExtensionElement> extensions = propertyExtensionList.iterator().next().getChildren();
for (CmisExtensionElement extension : extensions) {
if ("properties".equals(extension.getName())) {
// check properties extension
List<CmisExtensionElement> propExtensions = extension.getChildren();
assertTrue("cmisObject should contain aspect properties", propExtensions.size() > 0);
for (CmisExtensionElement prop : propExtensions) {
Map<String, String> cmisAspectProperty = prop.getAttributes();
Set<String> cmisAspectPropertyNames = cmisAspectProperty.keySet();
assertTrue("propertyDefinitionId attribute should be present", cmisAspectPropertyNames.contains("propertyDefinitionId"));
assertTrue("queryName attribute should be present", cmisAspectPropertyNames.contains("queryName"));
// optional values that are present for test document
assertTrue("displayName attribute should be present for property of test node", cmisAspectPropertyNames.contains("displayName"));
assertTrue("localName attribute should be present for property of test node", cmisAspectPropertyNames.contains("localName"));
assertEquals(cmisAspectPropertyNames.size(), 4);
// check values
for (String aspectPropertyName : cmisAspectPropertyNames) {
String value = cmisAspectProperty.get(aspectPropertyName);
assertTrue("value for " + aspectPropertyName + " should be present", value != null && value.length() > 0);
}
}
}
}
} catch (CmisConstraintException e) {
fail(e.toString());
} finally {
AuthenticationUtil.popAuthentication();
}
}
use of org.apache.chemistry.opencmis.commons.data.CmisExtensionElement in project alfresco-repository by Alfresco.
the class CMISTest method testExtensionDataIsReturnedViaCmis1_1.
/**
* MNT-11876 : Test that Alfresco CMIS 1.1 Implementation is returning aspect and aspect properties as extension data
* @throws Exception
*/
@Test
public void testExtensionDataIsReturnedViaCmis1_1() throws Exception {
AuthenticationUtil.pushAuthentication();
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
final String FOLDER = "testExtensionDataIsReturnedViaCmis1_1-" + GUID.generate();
final String CONTENT = FOLDER + "-file";
try {
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
// create folder
FileInfo folderInfo = fileFolderService.create(repositoryHelper.getCompanyHome(), FOLDER, ContentModel.TYPE_FOLDER);
nodeService.setProperty(folderInfo.getNodeRef(), ContentModel.PROP_NAME, FOLDER);
assertNotNull(folderInfo);
// create document
FileInfo document = fileFolderService.create(folderInfo.getNodeRef(), CONTENT, ContentModel.TYPE_CONTENT);
assertNotNull(document);
nodeService.setProperty(document.getNodeRef(), ContentModel.PROP_NAME, CONTENT);
// apply aspect with properties
Map<QName, Serializable> props = new HashMap<QName, Serializable>();
props.put(ContentModel.PROP_LATITUDE, Double.valueOf(1.0d));
props.put(ContentModel.PROP_LONGITUDE, Double.valueOf(1.0d));
nodeService.addAspect(document.getNodeRef(), ContentModel.ASPECT_GEOGRAPHIC, props);
return null;
}
});
final ObjectData objectData = withCmisService(new CmisServiceCallback<ObjectData>() {
@Override
public ObjectData execute(CmisService cmisService) {
List<RepositoryInfo> repositories = cmisService.getRepositoryInfos(null);
assertTrue(repositories.size() > 0);
RepositoryInfo repo = repositories.get(0);
String repositoryId = repo.getId();
// get object data
ObjectData objectData = cmisService.getObjectByPath(repositoryId, "/" + FOLDER + "/" + CONTENT, null, true, IncludeRelationships.NONE, null, false, true, null);
return objectData;
}
}, CmisVersion.CMIS_1_1);
// get extension data from object properties
List<CmisExtensionElement> extensions = objectData.getProperties().getExtensions().iterator().next().getChildren();
Set<String> appliedAspects = new HashSet<String>();
Set<String> aspectProperties = new HashSet<String>();
for (CmisExtensionElement extension : extensions) {
if (CMISConnector.PROPERTIES.equals(extension.getName())) {
// check properties extension
List<CmisExtensionElement> propExtensions = extension.getChildren();
assertTrue("cmisObject should contain aspect properties", propExtensions.size() > 0);
for (CmisExtensionElement prop : propExtensions) {
Map<String, String> cmisAspectProperty = prop.getAttributes();
Set<String> cmisAspectPropertyNames = cmisAspectProperty.keySet();
assertTrue("propertyDefinitionId attribute should be present", cmisAspectPropertyNames.contains("propertyDefinitionId"));
aspectProperties.add(cmisAspectProperty.get("propertyDefinitionId"));
}
} else if (CMISConnector.APPLIED_ASPECTS.equals(extension.getName())) {
appliedAspects.add(extension.getValue());
}
}
// extension data should contain applied aspects and aspect properties
assertTrue("Extensions should contain " + ContentModel.ASPECT_GEOGRAPHIC, appliedAspects.contains("P:cm:geographic"));
assertTrue("Extensions should contain " + ContentModel.PROP_LATITUDE, aspectProperties.contains("cm:latitude"));
assertTrue("Extensions should contain " + ContentModel.PROP_LONGITUDE, aspectProperties.contains("cm:longitude"));
} finally {
AuthenticationUtil.popAuthentication();
}
}
use of org.apache.chemistry.opencmis.commons.data.CmisExtensionElement in project alfresco-remote-api by Alfresco.
the class RepoService method getProperties.
/*
* Get (CMIS) node properties
*/
private Properties getProperties(NodeRef nodeRef) {
CMISNodeInfoImpl nodeInfo = cmisConnector.createNodeInfo(nodeRef);
final Properties properties = cmisConnector.getNodeProperties(nodeInfo, null);
// fake the title property, which CMIS doesn't give us
String title = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_TITLE);
final PropertyStringImpl titleProp = new PropertyStringImpl(ContentModel.PROP_TITLE.toString(), title);
Properties wrapProperties = new Properties() {
@Override
public List<CmisExtensionElement> getExtensions() {
return properties.getExtensions();
}
@Override
public void setExtensions(List<CmisExtensionElement> extensions) {
properties.setExtensions(extensions);
}
@Override
public Map<String, PropertyData<?>> getProperties() {
Map<String, PropertyData<?>> updatedProperties = new HashMap<String, PropertyData<?>>(properties.getProperties());
updatedProperties.put(titleProp.getId(), titleProp);
return updatedProperties;
}
@Override
public List<PropertyData<?>> getPropertyList() {
List<PropertyData<?>> propertyList = new ArrayList<PropertyData<?>>(properties.getPropertyList());
propertyList.add(titleProp);
return propertyList;
}
};
return wrapProperties;
}
use of org.apache.chemistry.opencmis.commons.data.CmisExtensionElement in project alfresco-repository by Alfresco.
the class CMISConnector method setProperties.
/**
* Sets property values.
*/
@SuppressWarnings({ "rawtypes" })
public void setProperties(NodeRef nodeRef, TypeDefinitionWrapper type, Properties properties, String... exclude) {
if (properties == null) {
return;
}
Map<String, PropertyData<?>> incomingPropsMap = properties.getProperties();
if (incomingPropsMap == null) {
return;
}
// extract property data into an easier to use form
Map<String, Pair<TypeDefinitionWrapper, Serializable>> propsMap = new HashMap<String, Pair<TypeDefinitionWrapper, Serializable>>();
for (String propertyId : incomingPropsMap.keySet()) {
PropertyData<?> property = incomingPropsMap.get(propertyId);
PropertyDefinitionWrapper propDef = type.getPropertyById(property.getId());
if (propDef == null) {
propDef = getOpenCMISDictionaryService().findProperty(propertyId);
if (propDef == null) {
throw new CmisInvalidArgumentException("Property " + property.getId() + " is unknown!");
}
}
Boolean isOnWorkingCopy = checkOutCheckInService.isWorkingCopy(nodeRef);
Updatability updatability = propDef.getPropertyDefinition().getUpdatability();
if (!isUpdatable(updatability, isOnWorkingCopy)) {
throw new CmisInvalidArgumentException("Property " + propertyId + " is read-only!");
}
TypeDefinitionWrapper propType = propDef.getOwningType();
Serializable value = getValue(property, propDef.getPropertyDefinition().getCardinality() == Cardinality.MULTI);
Pair<TypeDefinitionWrapper, Serializable> pair = new Pair<TypeDefinitionWrapper, Serializable>(propType, value);
propsMap.put(propertyId, pair);
}
// Need to do deal with secondary types first
Pair<TypeDefinitionWrapper, Serializable> pair = propsMap.get(PropertyIds.SECONDARY_OBJECT_TYPE_IDS);
Serializable secondaryTypesProperty = (pair != null ? pair.getSecond() : null);
if (secondaryTypesProperty != null) {
if (!(secondaryTypesProperty instanceof List)) {
throw new CmisInvalidArgumentException("Secondary types must be a list!");
}
List secondaryTypes = (List) secondaryTypesProperty;
if (secondaryTypes != null && secondaryTypes.size() > 0) {
// add/remove secondary types/aspects
processSecondaryTypes(nodeRef, secondaryTypes, propsMap);
}
}
for (String propertyId : propsMap.keySet()) {
if (propertyId.equals(PropertyIds.SECONDARY_OBJECT_TYPE_IDS)) {
// already handled above
continue;
}
pair = propsMap.get(propertyId);
TypeDefinitionWrapper propType = pair.getFirst();
Serializable value = pair.getSecond();
if (Arrays.binarySearch(exclude, propertyId) < 0) {
setProperty(nodeRef, propType, propertyId, value);
}
}
List<CmisExtensionElement> extensions = properties.getExtensions();
if (extensions != null) {
boolean isNameChanging = properties.getProperties().containsKey(PropertyIds.NAME);
for (CmisExtensionElement extension : extensions) {
if (ALFRESCO_EXTENSION_NAMESPACE.equals(extension.getNamespace()) && SET_ASPECTS.equals(extension.getName())) {
setAspectProperties(nodeRef, isNameChanging, extension);
break;
}
}
}
}
use of org.apache.chemistry.opencmis.commons.data.CmisExtensionElement 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;
}
Aggregations