use of org.apache.chemistry.opencmis.commons.server.CmisService in project alfresco-repository by Alfresco.
the class CMISTest method testDeleteFolder.
/**
* Test for ALF-18151.
*/
@Test
public void testDeleteFolder() {
AuthenticationUtil.pushAuthentication();
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
final Map<FileInfo, Boolean> testFolderMap = new HashMap<FileInfo, Boolean>(4);
try {
// create folder with file
String folderName = "testfolder" + GUID.generate();
String docName = "testdoc.txt" + GUID.generate();
FileInfo folder = createContent(folderName, docName, false);
testFolderMap.put(folder, Boolean.FALSE);
// create empty folder
String folderNameEmpty = "testfolder_empty1" + GUID.generate();
FileInfo folderEmpty = createContent(folderNameEmpty, null, false);
testFolderMap.put(folderEmpty, Boolean.TRUE);
// create folder with file
String folderNameRule = "testfolde_rule" + GUID.generate();
String docNameRule = "testdoc_rule.txt" + GUID.generate();
FileInfo folderWithRule = createContent(folderNameRule, docNameRule, true);
testFolderMap.put(folderWithRule, Boolean.FALSE);
// create empty folder
String folderNameEmptyRule = "testfolde_empty_rule1" + GUID.generate();
FileInfo folderEmptyWithRule = createContent(folderNameEmptyRule, null, true);
testFolderMap.put(folderEmptyWithRule, Boolean.TRUE);
withCmisService(new CmisServiceCallback<Void>() {
@Override
public Void execute(CmisService cmisService) {
List<RepositoryInfo> repositories = cmisService.getRepositoryInfos(null);
RepositoryInfo repo = repositories.get(0);
String repositoryId = repo.getId();
for (Map.Entry<FileInfo, Boolean> entry : testFolderMap.entrySet()) {
ObjectData objectData = cmisService.getObjectByPath(repositoryId, "/" + entry.getKey().getName(), null, true, IncludeRelationships.NONE, null, false, true, null);
Holder<String> objectId = new Holder<String>(objectData.getId());
try {
// delete folder
cmisService.deleteObjectOrCancelCheckOut(repositoryId, objectId.getValue(), Boolean.TRUE, null);
} catch (CmisConstraintException ex) {
assertTrue(!entry.getValue());
continue;
}
assertTrue(entry.getValue());
}
return null;
}
});
} finally {
for (Map.Entry<FileInfo, Boolean> entry : testFolderMap.entrySet()) {
if (fileFolderService.exists(entry.getKey().getNodeRef())) {
fileFolderService.delete(entry.getKey().getNodeRef());
}
}
AuthenticationUtil.popAuthentication();
}
}
use of org.apache.chemistry.opencmis.commons.server.CmisService 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.server.CmisService in project alfresco-repository by Alfresco.
the class CMISTest method withCmisService.
private <T extends Object> T withCmisService(CmisServiceCallback<T> callback, CmisVersion cmisVersion) {
CmisService cmisService = null;
try {
CallContext context = new SimpleCallContext("admin", "admin", cmisVersion);
cmisService = factory.getService(context);
T ret = callback.execute(cmisService);
return ret;
} finally {
if (cmisService != null) {
cmisService.close();
}
}
}
use of org.apache.chemistry.opencmis.commons.server.CmisService in project alfresco-repository by Alfresco.
the class CMISTest method testModelAvailability.
/**
* Test for MNT-10537.
*/
@Test
public void testModelAvailability() throws Exception {
final WorkflowDeployer testWorkflowDeployer = new WorkflowDeployer();
// setup dependencies
testWorkflowDeployer.setTransactionService(transactionService);
testWorkflowDeployer.setWorkflowService(workflowService);
testWorkflowDeployer.setWorkflowAdminService(workflowAdminService);
testWorkflowDeployer.setAuthenticationContext(authenticationContext);
testWorkflowDeployer.setDictionaryDAO(dictionaryDAO);
testWorkflowDeployer.setTenantAdminService(tenantAdminService);
testWorkflowDeployer.setTenantService(tenantService);
testWorkflowDeployer.setNodeService(nodeService);
testWorkflowDeployer.setNamespaceService(namespaceService);
testWorkflowDeployer.setSearchService(searchService);
// populate workflow parameters
java.util.Properties props = new java.util.Properties();
props.setProperty(WorkflowDeployer.ENGINE_ID, "activiti");
props.setProperty(WorkflowDeployer.LOCATION, "activiti/testCustomActiviti.bpmn20.xml");
props.setProperty(WorkflowDeployer.MIMETYPE, "text/xml");
props.setProperty(WorkflowDeployer.REDEPLOY, Boolean.FALSE.toString());
List<java.util.Properties> definitions = new ArrayList<java.util.Properties>(1);
definitions.add(props);
testWorkflowDeployer.setWorkflowDefinitions(definitions);
List<String> models = new ArrayList<String>(1);
models.add("activiti/testWorkflowModel.xml");
testWorkflowDeployer.setModels(models);
// deploy test workflow
RetryingTransactionHelper txnHelper = transactionService.getRetryingTransactionHelper();
txnHelper.setForceWritable(true);
txnHelper.doInTransaction(new RetryingTransactionCallback<Object>() {
@Override
public Object execute() throws Throwable {
return AuthenticationUtil.runAs(new RunAsWork<Object>() {
public Object doWork() {
testWorkflowDeployer.init();
return null;
}
}, AuthenticationUtil.getSystemUserName());
}
}, false, true);
org.alfresco.service.cmr.dictionary.TypeDefinition startTaskTypeDefinition = this.dictionaryService.getType(TEST_START_TASK);
org.alfresco.service.cmr.dictionary.TypeDefinition workflowTaskTypeDefinition = this.dictionaryService.getType(TEST_WORKFLOW_TASK);
// check that workflow types were correctly bootstrapped
assertNotNull(startTaskTypeDefinition);
assertNotNull(workflowTaskTypeDefinition);
// caches are refreshed asynchronously
Thread.sleep(5000);
// check that loaded model is available via CMIS API
CallContext context = new SimpleCallContext("admin", "admin", CmisVersion.CMIS_1_1);
CmisService service = factory.getService(context);
try {
List<RepositoryInfo> repositories = service.getRepositoryInfos(null);
assertTrue(repositories.size() > 0);
List<TypeDefinitionContainer> container = service.getTypeDescendants(repositories.get(0).getId(), null, new BigInteger("-1"), true, null);
assertTrue("Workflow model haven't been loaded", container.toString().contains("testwf:startTaskVarScriptAssign"));
} finally {
service.close();
}
}
use of org.apache.chemistry.opencmis.commons.server.CmisService 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();
}
}
Aggregations