11-06-2010 01:30 PM
public UploadResponse updateDocument(Reference ref, String strContent, UploadRequest req)
throws AuthoringFault, RemoteException {
log.info("start call to VersionUtilImpl.updateDocument");
UploadResponse res = new UploadResponse();
ICleanupUtil axisStubCleanupUtil = new AxisStubCleanupUtil();
RepositoryServiceSoapBindingStub repositoryService = null;
AuthoringServiceSoapBindingStub authoringService = null;
try {
repositoryService = WebServiceFactory.getRepositoryService();
/*
* Use authoring service to checkout file, update content, then
* check back in with major revision
*/
authoringService = WebServiceFactory.getAuthoringService();
/*
* Checkout the document to update, placing the working document in
* the same folder
*/
Predicate itemToCheckOut = new Predicate(new Reference[] { ref }, null, null);
/*
* First confirm that the content reference does not have the
* versionable aspect applied
*/
Node node = repositoryService.get(itemToCheckOut)[0];
for (String aspect : node.getAspects()) {
log.info("aspect: " + aspect);
if (Constants.ASPECT_VERSIONABLE.equals(aspect) == false) {
/*
* Add the versionable aspect to the newly created content.
* This will allows the content to be versioned
*/
makeVersionable(itemToCheckOut);
}
}
CheckoutResult checkOutResult = authoringService.checkout(itemToCheckOut, null);
/* Get a reference to the working copy */
Reference workingCopyReference = checkOutResult.getWorkingCopies()[0];
IMetadataUpdates metadataUpdates = new MetadataUpdatesImpl();
NamedValue[] properties = metadataUpdates.organizeUpdates(req, strContent);
Predicate where = new Predicate(new Reference[] { workingCopyReference }, null, null);
CML cml = new CML();
CMLUpdate update = new CMLUpdate(properties, where, null);
cml.setUpdate(new CMLUpdate[] { update });
try {
repositoryService.update(cml);
} catch (RepositoryFault e) {
log.error("RepositoryFault!", e);
throw e;
} catch (RemoteException e) {
log.error("RemoteException!", e);
throw e;
}
/*
* Now check the working copy in with a description of the change
* made that will be recorded in the version history
*/
String versionDescription = "This is a default description. The content has been updated.";
String desc = req.getDmsRqstFld2();
if (desc != null && !desc.equalsIgnoreCase("")) {
versionDescription = desc;
}
log.info("Notes for this version got from dmsRqstFld2: " + versionDescription);
NamedValue[] revisionType = new NamedValue[] { Utils.createNamedValue("versionType", "MAJOR"),
Utils.createNamedValue("description", versionDescription) };
CheckinResult checkinResult = authoringService.checkin(where, revisionType, false);
Reference[] refs = checkinResult.getCheckedIn();
/*
* Make sure to get the uuid of the latest file version in the
* CheckinResult object
*/
String xpath = refs[0].getPath();
log.info("getPath(): " + xpath);
String strUuid = refs[0].getUuid();
log.info("getUuid(): " + strUuid);
String strDestStoreAddress = refs[0].getStore().getAddress();
log.info("getAddress(): " + strDestStoreAddress);
VersionHistory versionHistory = authoringService.getVersionHistory(refs[0]);
Version[] versions = versionHistory.getVersions();
Version version = versions[0];
String versionLabel = version.getLabel();
log.info("versionLabel: " + versionLabel);
String strAfrescoUrlPrefix = PropertyUtils.getInstance().getProps().getProperty(
"alfresco.url.prefix");
String alfrescoUrl = strAfrescoUrlPrefix + strDestStoreAddress + "/" + strUuid + "/"
+ req.getFileName();
log.info("Alfresco URL: " + alfrescoUrl);
String strCfoPortalUrlPrefix = PropertyUtils.getInstance().getProps().getProperty(
"cfoportal.url.prefix");
String dmsUrl = strCfoPortalUrlPrefix + strUuid + "/" + req.getFileName();
log.info("CFO Portal URL: " + dmsUrl);
res.setDmsFileUrl(dmsUrl);
res.setStatus("0");
res.setMessage("Successfully updated file and incremented version in DMS!");
res.setVersion(versionLabel);
res.setXpath(xpath);
res.setUuid(strUuid);
res.setStoreAddress(strDestStoreAddress);
} catch (RepositoryFault e) {
log.error("RepositoryFault!", e);
throw e;
} catch (RemoteException e) {
log.error("RemoteException!", e);
throw e;
} finally {
axisStubCleanupUtil.cleanup(repositoryService);
axisStubCleanupUtil.cleanup(authoringService);
}
log.info("done call to VersionUtilImpl.updateDocument");
return res;
}
public void makeVersionable(Predicate itemToCheckOut) throws RepositoryFault, RemoteException {
RepositoryServiceSoapBindingStub repositoryService = null;
ICleanupUtil cleanupUtil = new AxisStubCleanupUtil();
try {
/* Create the add aspect query object */
CMLAddAspect addAspect = new CMLAddAspect(Constants.ASPECT_VERSIONABLE, null, itemToCheckOut,
null);
/* Create the content management language query */
CML cml = new CML();
cml.setAddAspect(new CMLAddAspect[] { addAspect });
repositoryService = WebServiceFactory.getRepositoryService();
/*
* Execute the query, which will add the versionable aspect to the
* node in question
*/
repositoryService.update(cml);
} catch (RepositoryFault e) {
cleanupUtil.cleanup(repositoryService);
throw e;
} catch (RemoteException e) {
cleanupUtil.cleanup(repositoryService);
throw e;
}
}
public String[] getVersionDetails(Version version) {
String[] versionLabelAndDesc = new String[2];
String versionLabel = null;
String description = null;
for (NamedValue namedValue : version.getCommentaries()) {
if (namedValue.getName().equals("description") == true) {
description = namedValue.getValue();
}
}
versionLabel = version.getLabel();
versionLabelAndDesc[0] = versionLabel;
versionLabelAndDesc[1] = description;
return versionLabelAndDesc;
}
11-08-2010 01:45 PM
11-10-2010 08:33 AM
Just to be sure: You're saying that the there should be a version available from before 1.0?
11-11-2010 05:39 AM
11-13-2010 04:26 AM
You would have to programmatically register behaviour against the document type to control the version numbering: VersionServicePolicies.OnCreateVersionPolicy
11-15-2010 05:34 AM
11-17-2010 08:58 AM
What I mean is that you would have to add some code to the server to change the version number policy i.e. write some java code as an AMP.
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.