use of org.apache.chemistry.opencmis.commons.server.CallContext 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.CallContext in project alfresco-repository by Alfresco.
the class CMISTest method testIsLatestMajorVersionMNT10868.
/**
* MNT-10868 CMIS: Incorrect value of Latest Major version on Versions and Properties tabs.
*/
@Test
public void testIsLatestMajorVersionMNT10868() {
CallContext context = new SimpleCallContext("admin", "admin", CmisVersion.CMIS_1_0);
String repositoryId = null;
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
CmisService cmisService = factory.getService(context);
try {
// get repository id
List<RepositoryInfo> repositories = cmisService.getRepositoryInfos(null);
assertTrue(repositories.size() > 0);
RepositoryInfo repo = repositories.get(0);
repositoryId = repo.getId();
final String folderName = "testfolder" + GUID.generate();
final String docName = "testdoc.txt" + GUID.generate();
final FileInfo fileInfo = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<FileInfo>() {
@Override
public FileInfo execute() throws Throwable {
NodeRef companyHomeNodeRef = repositoryHelper.getCompanyHome();
FileInfo folderInfo = fileFolderService.create(companyHomeNodeRef, folderName, ContentModel.TYPE_FOLDER);
nodeService.setProperty(folderInfo.getNodeRef(), ContentModel.PROP_NAME, folderName);
FileInfo fileInfo = fileFolderService.create(folderInfo.getNodeRef(), docName, ContentModel.TYPE_CONTENT);
nodeService.setProperty(fileInfo.getNodeRef(), ContentModel.PROP_NAME, docName);
nodeService.addAspect(fileInfo.getNodeRef(), ContentModel.ASPECT_VERSIONABLE, null);
return fileInfo;
}
});
ObjectData objectData = cmisService.getObjectByPath(repositoryId, "/" + folderName + "/" + docName, null, true, IncludeRelationships.NONE, null, false, true, null);
PropertyData<?> pd = getPropIsLatestMajorVersion(objectData);
if (pd != null) {
assertTrue("The CMISDictionaryModel.PROP_IS_LATEST_MAJOR_VERSION should be true as major version was created", (Boolean) pd.getValues().get(0));
}
nodeService.setProperty(fileInfo.getNodeRef(), ContentModel.PROP_TITLE, docName);
// Create minor version
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Object>() {
public Object execute() throws Throwable {
// get an updating writer
ContentWriter writer = contentService.getWriter(fileInfo.getNodeRef(), ContentModel.PROP_CONTENT, true);
writer.setMimetype("text/plain");
writer.putContent("New Version");
return null;
}
});
objectData = cmisService.getObjectByPath(repositoryId, "/" + folderName + "/" + docName, null, true, IncludeRelationships.NONE, null, false, true, null);
pd = getPropIsLatestMajorVersion(objectData);
if (pd != null) {
assertFalse("The CMISDictionaryModel.PROP_IS_LATEST_MAJOR_VERSION should be false as minor version was created", (Boolean) pd.getValues().get(0));
}
} finally {
cmisService.close();
}
}
use of org.apache.chemistry.opencmis.commons.server.CallContext in project iaf by ibissource.
the class CmisUtils method populateCmisAttributes.
public static void populateCmisAttributes(PipeLineSession session) {
CallContext callContext = (CallContext) session.get(CMIS_CALLCONTEXT_KEY);
if (callContext != null) {
session.put(CMIS_VERSION_KEY, callContext.getCmisVersion());
session.put(CMIS_BINDING_KEY, callContext.getBinding());
if ("basic".equalsIgnoreCase(CMIS_SECURITYHANDLER)) {
HttpServletRequest request = (HttpServletRequest) callContext.get(CallContext.HTTP_SERVLET_REQUEST);
session.setSecurityHandler(new HttpSecurityHandler(request));
} else if ("wsse".equalsIgnoreCase(CMIS_SECURITYHANDLER)) {
session.setSecurityHandler(new CmisSecurityHandler(callContext));
}
}
}
use of org.apache.chemistry.opencmis.commons.server.CallContext in project alfresco-repository by Alfresco.
the class CMISTest method testCheckIn.
/**
* Test for MNT-9203.
*/
@Test
public void testCheckIn() {
String repositoryId = null;
ObjectData objectData = null;
Holder<String> objectId = null;
CallContext context = new SimpleCallContext("admin", "admin", CmisVersion.CMIS_1_0);
final String folderName = "testfolder." + GUID.generate();
final String docName = "testdoc.txt." + GUID.generate();
final String customModel = "cmistest.model";
final QName testCustomTypeQName = QName.createQName(customModel, "sop");
final QName authorisedByQname = QName.createQName(customModel, "authorisedBy");
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();
FileInfo folderInfo = fileFolderService.create(companyHomeNodeRef, folderName, ContentModel.TYPE_FOLDER);
nodeService.setProperty(folderInfo.getNodeRef(), ContentModel.PROP_NAME, folderName);
FileInfo fileInfo = fileFolderService.create(folderInfo.getNodeRef(), docName, testCustomTypeQName);
Map<QName, Serializable> customProperties = new HashMap<QName, Serializable>();
customProperties.put(authorisedByQname, "customPropertyString");
customProperties.put(ContentModel.PROP_NAME, docName);
nodeService.setProperties(fileInfo.getNodeRef(), customProperties);
return fileInfo;
}
});
CmisService service = factory.getService(context);
try {
List<RepositoryInfo> repositories = service.getRepositoryInfos(null);
assertTrue(repositories.size() > 0);
RepositoryInfo repo = repositories.get(0);
repositoryId = repo.getId();
objectData = service.getObjectByPath(repositoryId, "/" + folderName + "/" + docName, null, true, IncludeRelationships.NONE, null, false, true, null);
// checkout
objectId = new Holder<String>(objectData.getId());
service.checkOut(repositoryId, objectId, null, new Holder<Boolean>(true));
} finally {
service.close();
}
try {
service = factory.getService(context);
PropertyStringImpl prop = new PropertyStringImpl();
prop.setId("abc:" + authorisedByQname.toPrefixString());
prop.setValue(null);
Collection<PropertyData<?>> propsList = new ArrayList<PropertyData<?>>();
propsList.add(prop);
Properties properties = new PropertiesImpl(propsList);
// checkIn on pwc
service.checkIn(repositoryId, objectId, false, properties, null, null, null, null, null, null);
} finally {
service.close();
}
// check that value is null
assertTrue(nodeService.getProperty(fileInfo.getNodeRef(), authorisedByQname) == null);
} finally {
AuthenticationUtil.popAuthentication();
}
}
use of org.apache.chemistry.opencmis.commons.server.CallContext in project alfresco-repository by Alfresco.
the class AlfrescoCmisServiceImpl method beforeCall.
@Override
public void beforeCall() {
AuthenticationUtil.pushAuthentication();
if (authentication != null) {
// Use the previously-obtained authentication
AuthenticationUtil.setFullAuthentication(authentication);
} else {
CallContext context = getContext();
if (context == null) {
// Service not opened, yet
return;
}
// Sticky sessions?
if (connector.openHttpSession()) {
// create a session -> set a cookie
// if the CMIS client supports cookies that might help in clustered environments
((HttpServletRequest) context.get(CallContext.HTTP_SERVLET_REQUEST)).getSession();
}
// Authenticate
if (authentication != null) {
// We have already authenticated; just reuse the authentication
AuthenticationUtil.setFullAuthentication(authentication);
} else {
// First check if we already are authenticated
if (AuthenticationUtil.getFullyAuthenticatedUser() == null) {
// We have to go to the repo and authenticate
String user = context.getUsername();
String password = context.getPassword();
Authorization auth = new Authorization(user, password);
if (auth.isTicket()) {
connector.getAuthenticationService().validate(auth.getTicket());
} else {
connector.getAuthenticationService().authenticate(auth.getUserName(), auth.getPasswordCharArray());
}
}
this.authentication = AuthenticationUtil.getFullAuthentication();
}
// // TODO: How is the proxy user working.
// // Until we know what it is meant to do, it's not available
// String currentUser = connector.getAuthenticationService().getCurrentUserName();
// String user = getContext().getUsername();
// String password = getContext().getPassword();
// if (currentUser != null && currentUser.equals(connector.getProxyUser()))
// {
// if (user != null && user.length() > 0)
// {
// AuthenticationUtil.setFullyAuthenticatedUser(user);
// }
// }
}
}
Aggregations