05-22-2012 11:23 AM
private AlfrescoDocument addDocument(SourceObject sourceObject, Folder parentFolder, Map<String, Object> properties) {
properties.put(PropertyIds.OBJECT_TYPE_ID, properties.get(PropertyIds.OBJECT_TYPE_ID));
properties.put(PropertyIds.NAME, "myDocument");
ContentStream contentStream = createContenStream(sourceObject);
return (AlfrescoDocument) parentFolder.createDocument(properties, contentStream, VersioningState.MAJOR);
}The update method uses checkin and checkout to add a new version when the document already exists:private void updateDocument(SourceObject sourceObject, AlfrescoDocument doc) {
ContentStream contentStream = createContenStream(sourceObject);
ObjectId pwcId = doc.checkOut();
Document pwcDocument = (Document) session.getObject(pwcId);
boolean majorVersion = true;
pwcDocument.checkIn(majorVersion, null, contentStream, null);
}And the update is called only if the following query return something:public static AlfrescoDocument searchAlfrescoDocument(Session session, String name, String basePath) {
AlfrescoDocument alfrescoDocument = null;
String query = "SELECT * FROM cmis:document WHERE cmis:name = '" + name + "'";
ItemIterable<QueryResult> queryResult = session.query(query, true);
for (QueryResult item : queryResult) {
String itemObjectId = item.getPropertyByQueryName("cmis:objectId").getFirstValue().toString();
Document resultDocument = (Document) session.getObject(session.createObjectId(itemObjectId));
if (resultDocument.getPaths().get(0).startsWith(basePath)) {
if (alfrescoDocument == null) {
alfrescoDocument = (AlfrescoDocument)resultDocument;
}
}
}
return alfrescoDocument;
}It works fine but sometimes the search doesn't find a recently added document and throws a "CmisConstraintException: Conflict" because it tries to add a document that is already there. If I debug the code, stop right before the search and wait for a few seconds, the search finds the document and the update method is called. Is there a way to flush or commit the session or do something to avoid this kind of error?05-22-2012 02:45 PM
05-22-2012 03:16 PM
05-24-2012 03:08 PM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.