use of org.apache.chemistry.opencmis.commons.data.CmisExtensionElement in project alfresco-repository by Alfresco.
the class CMISTest method testGetRepositoryInfos.
/**
* ALF-20389 Test Alfresco cmis stream interceptor that checks content stream for mimetype. Only ContentStreamImpl extensions should take palace.
*/
@Test
public void testGetRepositoryInfos() {
boolean cmisEx = false;
List<RepositoryInfo> infoDataList = null;
try {
infoDataList = withCmisService(new CmisServiceCallback<List<RepositoryInfo>>() {
@Override
public List<RepositoryInfo> execute(CmisService cmisService) {
ExtensionDataImpl result = new ExtensionDataImpl();
List<CmisExtensionElement> extensions = new ArrayList<CmisExtensionElement>();
result.setExtensions(extensions);
return cmisService.getRepositoryInfos(result);
}
});
} catch (CmisRuntimeException e) {
cmisEx = true;
}
assertNotNull(cmisEx ? "CmisRuntimeException was thrown. Please, take a look on ALF-20389" : "No CMIS repository information was retrieved", infoDataList);
}
use of org.apache.chemistry.opencmis.commons.data.CmisExtensionElement 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.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-repository by Alfresco.
the class CMISTest method testLastVersionOfVersionSeries.
/**
* Test to ensure that set of aspect returned by cmisService#getAllVersions for latest version is the same
* as for the object returned by cmisService#getObjectByPath.
*
* See <a href="https://issues.alfresco.com/jira/browse/MNT-9557">MNT-9557</a>
*/
@Test
public void testLastVersionOfVersionSeries() {
CallContext context = new SimpleCallContext("admin", "admin", CmisVersion.CMIS_1_0);
AuthenticationUtil.pushAuthentication();
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
final String FOLDER = "testUpdatePropertiesSetDeleteContentVersioning-" + GUID.generate(), DOC = "documentProperties-" + GUID.generate();
try {
final NodeRef nodeRef = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<NodeRef>() {
@Override
public NodeRef 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 documents
FileInfo document = fileFolderService.create(folderInfo.getNodeRef(), DOC, ContentModel.TYPE_CONTENT);
nodeService.setProperty(document.getNodeRef(), ContentModel.PROP_NAME, DOC);
nodeService.setProperty(document.getNodeRef(), ContentModel.PROP_DESCRIPTION, "Initial doc");
return document.getNodeRef();
}
});
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
// make sure that there is no version history yet
assertNull(versionService.getVersionHistory(nodeRef));
// create a version
// turn off auto-versioning
Map<QName, Serializable> props = new HashMap<QName, Serializable>();
props.put(ContentModel.PROP_INITIAL_VERSION, false);
props.put(ContentModel.PROP_AUTO_VERSION, false);
props.put(ContentModel.PROP_AUTO_VERSION_PROPS, false);
versionService.ensureVersioningEnabled(nodeRef, props);
return null;
}
});
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
assertNotNull(versionService.getVersionHistory(nodeRef));
// create another one version
versionService.createVersion(nodeRef, null);
return null;
}
});
final String NEW_DOC_NAME = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<String>() {
@Override
public String execute() throws Throwable {
// add aspect to the node
String newDocName = DOC + GUID.generate();
nodeService.addAspect(nodeRef, ContentModel.ASPECT_AUTHOR, null);
nodeService.setProperty(nodeRef, ContentModel.PROP_NAME, newDocName);
return newDocName;
}
});
CmisService cmisService = factory.getService(context);
String repositoryId = cmisService.getRepositoryInfos(null).get(0).getId();
List<ObjectData> versions = cmisService.getAllVersions(repositoryId, nodeRef.toString(), null, null, null, null);
assertNotNull(versions);
// get the latest version
ObjectData latestVersion = versions.get(0);
// get the object
ObjectData object = // cmisService.getObjectOfLatestVersion(repositoryId, nodeRef.toString(), null, false, null, null, null, null, false, false, null);
cmisService.getObjectByPath(repositoryId, "/" + FOLDER + "/" + NEW_DOC_NAME, null, null, null, null, false, false, null);
assertNotNull(latestVersion);
assertNotNull(object);
Object objectDescriptionString = object.getProperties().getProperties().get("cmis:name").getValues().get(0);
Object latestVersionDescriptionString = latestVersion.getProperties().getProperties().get("cmis:name").getValues().get(0);
// ensure that node and latest version both have same description
assertEquals(objectDescriptionString, latestVersionDescriptionString);
Set<String> documentAspects = new HashSet<String>();
for (CmisExtensionElement cmisEE : object.getProperties().getExtensions().get(0).getChildren()) {
documentAspects.add(cmisEE.getValue());
}
Set<String> latestVersionAspects = new HashSet<String>();
for (CmisExtensionElement cmisEE : latestVersion.getProperties().getExtensions().get(0).getChildren()) {
latestVersionAspects.add(cmisEE.getValue());
}
// ensure that node and latest version both have the same set of aspects
assertEquals(latestVersionAspects, documentAspects);
} finally {
AuthenticationUtil.popAuthentication();
}
}
Aggregations