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 AlfrescoCmisServiceImpl method bulkUpdateProperties.
@Override
public List<BulkUpdateObjectIdAndChangeToken> bulkUpdateProperties(final String repositoryId, List<BulkUpdateObjectIdAndChangeToken> objectIdAndChangeTokens, final Properties properties, final List<String> addSecondaryTypeIds, final List<String> removeSecondaryTypeIds, ExtensionsData extension) {
checkRepositoryId(repositoryId);
if (objectIdAndChangeTokens.size() > connector.getBulkMaxItems()) {
throw new CmisConstraintException("Bulk update not supported for more than " + connector.getBulkMaxItems() + " objects.");
}
// MNT-16376 We need the CMIS call context from this thread to set
// to the working threads below, in order to correctly identify
// the CMIS version protocol used for this CMIS call
final CallContext cmisCallContext = AlfrescoCmisServiceCall.get();
// WorkProvider
class WorkProvider implements BatchProcessWorkProvider<BulkEntry> {
private final Iterator<BulkUpdateObjectIdAndChangeToken> iterator;
private final int size;
private final int batchSize;
private BulkUpdateContext context;
public WorkProvider(List<BulkUpdateObjectIdAndChangeToken> objectIdAndChangeTokens, BulkUpdateContext context, int batchSize) {
this.iterator = objectIdAndChangeTokens.iterator();
this.size = objectIdAndChangeTokens.size();
this.context = context;
this.batchSize = batchSize;
}
@Override
public synchronized int getTotalEstimatedWorkSize() {
return size;
}
@Override
public synchronized Collection<BulkEntry> getNextWork() {
Collection<BulkEntry> results = new ArrayList<BulkEntry>(batchSize);
while (results.size() < batchSize && iterator.hasNext()) {
results.add(new BulkEntry(context, iterator.next(), properties, addSecondaryTypeIds, removeSecondaryTypeIds, getContext().isObjectInfoRequired()));
}
return results;
}
}
BulkUpdateContext context = new BulkUpdateContext(objectIdAndChangeTokens.size());
RetryingTransactionHelper helper = connector.getRetryingTransactionHelper();
final String runAsUser = AuthenticationUtil.getRunAsUser();
// Worker
BatchProcessWorker<BulkEntry> worker = new BatchProcessWorker<BulkEntry>() {
@Override
public void process(final BulkEntry entry) throws Throwable {
entry.update();
}
public String getIdentifier(BulkEntry entry) {
return entry.getObjectIdAndChangeToken().getId();
}
@Override
public void beforeProcess() throws Throwable {
// Authentication
AuthenticationUtil.pushAuthentication();
AuthenticationUtil.setFullyAuthenticatedUser(runAsUser);
AlfrescoCmisServiceCall.set(cmisCallContext);
}
@Override
public void afterProcess() throws Throwable {
// Clear authentication
AuthenticationUtil.popAuthentication();
}
};
// Processor
BatchProcessor<BulkEntry> processor = new BatchProcessor<BulkEntry>("CMISbulkUpdateProperties", helper, new WorkProvider(objectIdAndChangeTokens, context, connector.getBulkBatchSize()), connector.getBulkWorkerThreads(), connector.getBulkBatchSize(), null, logger, 100);
processor.process(worker, true);
for (CMISNodeInfo info : context.getSuccesses()) {
NodeRef nodeRef = info.getNodeRef();
connector.getActivityPoster().postFileFolderUpdated(info.isFolder(), nodeRef);
}
return context.getChanges();
}
use of org.apache.chemistry.opencmis.commons.server.CallContext in project alfresco-repository by Alfresco.
the class CMISConnector method isPublicApi.
private boolean isPublicApi() {
boolean isPublicApi = false;
CallContext callContext = AlfrescoCmisServiceCall.get();
if (callContext != null) {
String value = (String) callContext.get("isPublicApi");
isPublicApi = (value == null ? false : Boolean.parseBoolean(value));
}
return isPublicApi;
}
use of org.apache.chemistry.opencmis.commons.server.CallContext in project alfresco-repository by Alfresco.
the class CMISConnector method getRequestCmisVersion.
public CmisVersion getRequestCmisVersion() {
CallContext callContext = AlfrescoCmisServiceCall.get();
CmisVersion cmisVersion = (callContext != null ? callContext.getCmisVersion() : CmisVersion.CMIS_1_0);
return cmisVersion;
}
use of org.apache.chemistry.opencmis.commons.server.CallContext 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