use of org.apache.chemistry.opencmis.commons.server.CmisService 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.server.CmisService in project alfresco-repository by Alfresco.
the class CMISTest method testCMISGetObjectParents.
/**
* MNT-14951: Test that the list of parents can be retrieved for a folder.
*/
@Test
public void testCMISGetObjectParents() throws Exception {
// setUp audit subsystem
setupAudit();
AuthenticationUtil.pushAuthentication();
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
try {
final NodeRef folderWithTwoParents = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<NodeRef>() {
@Override
public NodeRef execute() throws Throwable {
NodeRef companyHomeNodeRef = repositoryHelper.getCompanyHome();
String folder1 = GUID.generate();
FileInfo folderInfo1 = fileFolderService.create(companyHomeNodeRef, folder1, ContentModel.TYPE_FOLDER);
assertNotNull(folderInfo1);
String folder2 = GUID.generate();
FileInfo folderInfo2 = fileFolderService.create(companyHomeNodeRef, folder2, ContentModel.TYPE_FOLDER);
assertNotNull(folderInfo2);
// Create folder11 as a subfolder of folder1
String folder11 = GUID.generate();
FileInfo folderInfo11 = fileFolderService.create(folderInfo1.getNodeRef(), folder11, ContentModel.TYPE_FOLDER);
assertNotNull(folderInfo11);
// Add folder2 as second parent for folder11
nodeService.addChild(folderInfo2.getNodeRef(), folderInfo11.getNodeRef(), ContentModel.ASSOC_CONTAINS, ContentModel.ASSOC_CONTAINS);
return folderInfo11.getNodeRef();
}
});
withCmisService(new CmisServiceCallback<Void>() {
@Override
public Void execute(CmisService cmisService) {
List<RepositoryInfo> repositories = cmisService.getRepositoryInfos(null);
assertNotNull(repositories);
assertTrue(repositories.size() > 0);
String repositoryId = repositories.iterator().next().getId();
List<ObjectParentData> parents = cmisService.getObjectParents(repositoryId, folderWithTwoParents.getId(), null, Boolean.FALSE, IncludeRelationships.NONE, "cmis:none", Boolean.FALSE, null);
// Check if the second parent was also returned.
assertEquals(2, parents.size());
return null;
}
}, CmisVersion.CMIS_1_1);
} finally {
auditSubsystem.destroy();
AuthenticationUtil.popAuthentication();
}
}
use of org.apache.chemistry.opencmis.commons.server.CmisService in project alfresco-repository by Alfresco.
the class CMISTest method mnt10548test.
@Category(RedundantTests.class)
@Test
public void mnt10548test() throws Exception {
AuthenticationUtil.pushAuthentication();
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
final Pair<FileInfo, FileInfo> folderAndDocument = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Pair<FileInfo, FileInfo>>() {
private static final String TEST_NAME = "mnt10548test-";
@Override
public Pair<FileInfo, FileInfo> execute() throws Throwable {
NodeRef companyHomeNodeRef = repositoryHelper.getCompanyHome();
/* Create folder within companyHome */
String folderName = TEST_NAME + GUID.generate();
FileInfo folderInfo = fileFolderService.create(companyHomeNodeRef, folderName, ContentModel.TYPE_FOLDER);
nodeService.setProperty(folderInfo.getNodeRef(), ContentModel.PROP_NAME, folderName);
assertNotNull(folderInfo);
/* Create content */
String docName = TEST_NAME + GUID.generate();
FileInfo document = fileFolderService.create(folderInfo.getNodeRef(), docName, ContentModel.TYPE_CONTENT);
assertNotNull(document);
nodeService.setProperty(document.getNodeRef(), ContentModel.PROP_NAME, docName);
/* Add some tags */
NodeRef nodeRef = document.getNodeRef();
taggingService.addTag(nodeRef, "tag1");
taggingService.addTag(nodeRef, "tag2");
taggingService.addTag(nodeRef, "tag3");
return new Pair<FileInfo, FileInfo>(folderInfo, document);
}
});
ObjectData objData = withCmisService(new CmisServiceCallback<ObjectData>() {
private static final String FILE_FOLDER_SEPARATOR = "/";
@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();
String path = FILE_FOLDER_SEPARATOR + folderAndDocument.getFirst().getName() + FILE_FOLDER_SEPARATOR + folderAndDocument.getSecond().getName();
/* get CMIS object of document */
ObjectData objData = cmisService.getObjectByPath(repositoryId, path, null, false, null, null, false, false, null);
return objData;
}
}, CmisVersion.CMIS_1_1);
Map<String, PropertyData<?>> cmisProps = objData.getProperties().getProperties();
String taggable = ContentModel.ASPECT_TAGGABLE.getPrefixedQName(namespaceService).toPrefixString();
PropertyData<?> propData = cmisProps.get(taggable);
assertNotNull(propData);
List<?> props = propData.getValues();
assertTrue(props.size() == 3);
/* MNT-10548 fix : CMIS should return List of String, not List of NodeRef */
for (Object o : props) {
assertTrue(o.getClass() + " found but String expected", o instanceof String);
}
}
use of org.apache.chemistry.opencmis.commons.server.CmisService in project alfresco-repository by Alfresco.
the class CMISTest method testItemRelations.
/**
* MNT-11339 related test :
* Unable to create relationship between cmis:document and cmis:item
*/
@Test
public void testItemRelations() {
AuthenticationUtil.pushAuthentication();
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
final String TEST_NAME = "testItemRelations-";
final String FOLDER_NAME = TEST_NAME + "FOLDER" + GUID.generate();
final String DOCUMENT_NAME = TEST_NAME + "DOCUMENT" + GUID.generate();
final String CLIENT_NAME = "Some Test Client " + GUID.generate();
try {
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
NodeRef companyHomeNodeRef = repositoryHelper.getCompanyHome();
/* Create folder within companyHome */
FileInfo folderInfo = fileFolderService.create(companyHomeNodeRef, FOLDER_NAME, ContentModel.TYPE_FOLDER);
nodeService.setProperty(folderInfo.getNodeRef(), ContentModel.PROP_NAME, FOLDER_NAME);
assertNotNull(folderInfo);
// and document
FileInfo document = fileFolderService.create(folderInfo.getNodeRef(), DOCUMENT_NAME, ContentModel.TYPE_CONTENT);
assertNotNull(document);
nodeService.setProperty(document.getNodeRef(), ContentModel.PROP_NAME, DOCUMENT_NAME);
return null;
}
});
withCmisService(new CmisServiceCallback<String>() {
@SuppressWarnings("unchecked")
@Override
public String execute(CmisService cmisService) {
List<RepositoryInfo> repositories = cmisService.getRepositoryInfos(null);
assertTrue(repositories.size() > 0);
RepositoryInfo repo = repositories.get(0);
String repositoryId = repo.getId();
// ensure there are custom type, aspect and association defined
TypeDefinition tpdfn = cmisService.getTypeDefinition(repositoryId, "I:sctst:client", null);
assertNotNull("the I:sctst:client type is not defined", tpdfn);
TypeDefinition aspectDfn = cmisService.getTypeDefinition(repositoryId, "P:sctst:clientRelated", null);
assertNotNull("the P:sctst:clientRelated aspect is not defined", aspectDfn);
TypeDefinition relDfn = cmisService.getTypeDefinition(repositoryId, "R:sctst:relatedClients", null);
assertNotNull("the R:sctst:relatedClients association is not defined", relDfn);
// create cmis:item within test folder
PropertiesImpl properties = new PropertiesImpl();
properties.addProperty(new PropertyIdImpl(PropertyIds.OBJECT_TYPE_ID, tpdfn.getId()));
properties.addProperty(new PropertyStringImpl(PropertyIds.NAME, CLIENT_NAME));
properties.addProperty(new PropertyStringImpl("sctst:clientId", "id" + GUID.generate()));
properties.addProperty(new PropertyStringImpl("sctst:clientName", CLIENT_NAME));
ObjectData folderData = cmisService.getObjectByPath(repositoryId, "/" + FOLDER_NAME, null, null, null, null, null, null, null);
cmisService.createItem(repositoryId, properties, folderData.getId(), null, null, null, null);
ObjectData contentData = cmisService.getObjectByPath(repositoryId, "/" + FOLDER_NAME + "/" + DOCUMENT_NAME, null, null, null, null, null, null, null);
// add test aspect sctst:clientRelated to document
Properties props = cmisService.getProperties(repositoryId, contentData.getId(), null, null);
PropertyData<?> propAspects = props.getProperties().get(PropertyIds.SECONDARY_OBJECT_TYPE_IDS);
@SuppressWarnings("rawtypes") List aspects = propAspects.getValues();
aspects.add("P:sctst:clientRelated");
properties = new PropertiesImpl();
properties.addProperty(new PropertyStringImpl(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, aspects));
cmisService.updateProperties(repositoryId, new Holder<String>(contentData.getId()), null, properties, null);
// ensure document has sctst:clientRelated aspect applied
aspects = cmisService.getProperties(repositoryId, contentData.getId(), null, null).getProperties().get(PropertyIds.SECONDARY_OBJECT_TYPE_IDS).getValues();
assertTrue("P:sctst:clientRelated excpected", aspects.contains("P:sctst:clientRelated"));
ObjectData itemData = cmisService.getObjectByPath(repositoryId, "/" + FOLDER_NAME + "/" + CLIENT_NAME, null, null, null, null, null, null, null);
// create relationship between cmis:document and cmis:item
properties = new PropertiesImpl();
properties.addProperty(new PropertyIdImpl(PropertyIds.OBJECT_TYPE_ID, "R:sctst:relatedClients"));
properties.addProperty(new PropertyIdImpl(PropertyIds.SOURCE_ID, contentData.getId()));
properties.addProperty(new PropertyIdImpl(PropertyIds.TARGET_ID, itemData.getId()));
cmisService.createRelationship(repositoryId, properties, null, null, null, null);
return "";
}
}, CmisVersion.CMIS_1_1);
} finally {
AuthenticationUtil.popAuthentication();
}
}
use of org.apache.chemistry.opencmis.commons.server.CmisService in project alfresco-repository by Alfresco.
the class CMISTest method aPrivateCopyMustContainTheWorkingCopyAspect_CMIS_1_1_Version.
/**
* Related to REPO-4613.
* This test makes sure that once a copy is checked out, the private copy contains the aspect P:cm:workingcopy
*/
@Test
public void aPrivateCopyMustContainTheWorkingCopyAspect_CMIS_1_1_Version() {
// get repository id
final String repositoryId = withCmisService(new CmisServiceCallback<String>() {
@Override
public String execute(CmisService cmisService) {
List<RepositoryInfo> repositories = cmisService.getRepositoryInfos(null);
RepositoryInfo repo = repositories.get(0);
final String repositoryId = repo.getId();
return repositoryId;
}
}, CmisVersion.CMIS_1_1);
final Properties currentProperties = withCmisService(new CmisServiceCallback<Properties>() {
@Override
public Properties execute(CmisService cmisService) {
PropertiesImpl properties = new PropertiesImpl();
String objectTypeId = "cmis:document";
properties.addProperty(new PropertyIdImpl(PropertyIds.OBJECT_TYPE_ID, objectTypeId));
String fileName = "textFile" + GUID.generate();
properties.addProperty(new PropertyStringImpl(PropertyIds.NAME, fileName));
final ContentStreamImpl contentStream = new ContentStreamImpl(fileName, MimetypeMap.MIMETYPE_TEXT_PLAIN, "Simple text plain document");
String objectId = cmisService.create(repositoryId, properties, repositoryHelper.getCompanyHome().getId(), contentStream, VersioningState.MAJOR, null, null);
final Holder<String> objectIdHolder = new Holder<String>(objectId);
cmisService.checkOut(repositoryId, objectIdHolder, null, null);
ObjectData pwc = cmisService.getObject(repositoryId, objectIdHolder.getValue(), null, null, null, null, null, null, null);
pwc.getProperties();
Properties propertiesValues = pwc.getProperties();
return propertiesValues;
}
}, CmisVersion.CMIS_1_1);
List<String> secondaryTypeIds = (List<String>) currentProperties.getProperties().get(PropertyIds.SECONDARY_OBJECT_TYPE_IDS).getValues();
assertTrue(secondaryTypeIds.contains("P:cm:workingcopy"));
}
Aggregations