While using alfresco versionservice in your java class, you might face certain issues (especially while copying multiple files and creating/overwriting their versions):
Here are some issues and the working solution for it.
Error:
org.springframework.dao.ConcurrencyFailureException: Unexpected: current version does not appear to be 1st version in the list [workspace://version2Store/0a5e7701-2112-43b3-80f4-5dfb75ddd7ad, workspace://SpacesStore/3c5d0493-562c-455d-91b8-33bc717b39c4]at org.alfresco.repo.version.Version2ServiceImpl.getCurrentVersionImpl(Version2ServiceImpl.java:859)at org.alfresco.repo.version.Version2ServiceImpl.getCurrentVersion(Version2ServiceImpl.java:400)
This error can come up when the file you are creating/copying is not copied/written on it's immediate parent (ex: v1.0 is already there in alfresco repository, and the file you are copying on top of it should make the version 1.1. But the noderef which you are referring to while writing the file might not be the noderef of 1.0, but something else.
Alternatives I tried:
1)
getVersionService().createVersion(currentVersion.getFrozenStateNodeRef(), versionProperties);
Result:
ERROR: java.lang.UnsupportedOperationException: This operation is not supported by a version store implementation of the node service.at org.alfresco.repo.version.NodeServiceImpl.setProperty(NodeServiceImpl.java:468)
2)
VersionHistory vh = versionService.getVersionHistory(fileNodeRef);
Version version = vh.getRootVersion();
NodeRef node = version.getFrozenStateNodeRef();
Version currentVersion = versionService.getCurrentVersion(node);
Result:
ERROR: java.lang.UnsupportedOperationException: This operation is not supported by a version store implementation of the node service.at org.alfresco.repo.version.NodeServiceImpl.setProperty(NodeServiceImpl.java:468)
3)
If I keep getVersionedNodeRef() in both places:
VersionHistory vh = versionService.getVersionHistory(fileNodeRef);
Version version = vh.getHeadVersion();
Version newVersion = getVersionService().createVersion(version.getVersionedNodeRef(), versionProperties);
Result:
org.springframework.dao.ConcurrencyFailureException: Unexpected: current version does not appear to be 1st version in the list [workspace://version2Store/0fa61697-64d4-4107-a793-4b0330db6e4e, workspace://SpacesStore/bda8e3ea-dc65-4aca-842e-e3945f19182b]
4)
If I keep getFrozenStateNodeRef() :
VersionHistory vh = versionService.getVersionHistory(fileNodeRef);
Version version = vh.getHeadVersion();
Version newVersion = getVersionService().createVersion(version.getFrozenStateNodeRef(), versionProperties);
Result:
ERROR [PROJECT.webscripts.CopyFilesWebscript] [http-bio-8080-exec-20] java.lang.UnsupportedOperationException: This operation is not supported by a version store implementation of the node service.
java.lang.UnsupportedOperationException: This operation is not supported by a version store implementation of the node service.at org.alfresco.repo.version.NodeServiceImpl.setProperty(NodeServiceImpl.java:468)at sun.reflect.GeneratedMethodAccessor747.invoke(Unknown Source)
Head version Label=1.0
Head version Type=MAJOR
Head version versionedNodeRef=workspace://SpacesStore/d3755ca5-d430-4eb7-9c6b-2cd6a4bb913d
Head version fronzedStateNodeRef=versionStore://version2Store/2eb9b528-c4e9-4478-92a0-68bcd5c67fe2
Sometimes, this error is also faced:
2018-03-22 12:31:46,640 ERROR [PROJECT.webscripts.CopyFilesWebscript] [http-bio-8080-exec-38] org.alfresco.service.cmr.version.VersionServiceException: 02220005 The current version label of the node does not exist in the version history. org.alfresco.service.cmr.version.VersionServiceException: 02220005 The current version label of the node does not exist in the version history.at org.alfresco.repo.version.Version2ServiceImpl.createVersion(Version2ServiceImpl.java:243)at org.alfresco.repo.version.Version2ServiceImpl.createVersion(Version2ServiceImpl.java:118)
Working Solution/Code:
The class should use the following code for copying files (here in this case, it's multiple files, so we iterate over the files and copy.
for (NodeRef fileNode : list) {
String docName = nodeService.getProperty(fileNode, ContentModel.PROP_NAME).toString();
QName documentName = QName.createQName(CustomModel.CUSTOM_NAMESPACE_URI,docName);
NodeRef existingDocumentNodeRef = nodeService.getChildByName(newDestinationNode, ContentModel.ASSOC_CONTAINS, docName);
if(existingDocumentNodeRef!=null && getNodeService().exists(existingDocumentNodeRef)){
copySourceContent(fileNode,existingDocumentNodeRef);
/*Adding below method call not working - giving the error:
* org.springframework.dao.ConcurrencyFailureException: Unexpected: current version does not appear to be 1st version in the list*/
//copyProperties(fileNode,existingDocumentNodeRef);
Map versionProps = new HashMap();
versionProps.put(ContentModel.PROP_AUTO_VERSION, true);
versionProps.put(ContentModel.PROP_AUTO_VERSION_PROPS, true);
versionService.ensureVersioningEnabled(existingDocumentNodeRef, versionProps);
Map versionProperties = new HashMap(); versionProperties.put(VersionModel.PROP_VERSION_TYPE, VersionType.MINOR);
versionService.createVersion(existingDocumentNodeRef, versionProperties);
map.put(existingDocumentNodeRef.getId(), docName);
}
else
{
FileInfo fInfo = getFileFolderService().copy(fileNode, newDestinationNode, docName);
map.put(fInfo.getNodeRef().getId(), docName);
}
}
private void copySourceContent(NodeRef sourceNodeRef, NodeRef destNodeRef){
byte[] binaryData = null;
try {
ContentReader reader = getContentService().getReader(sourceNodeRef, ContentModel.PROP_CONTENT);
InputStream originalInputStream = reader.getContentInputStream();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
final int BUF_SIZE = 1 << 8;
//1KiB buffer
byte[] buffer = new byte[BUF_SIZE];
int bytesRead = -1;
while((bytesRead = originalInputStream.read(buffer)) > -1) {
outputStream.write(buffer, 0, bytesRead);
}
originalInputStream.close();
binaryData = outputStream.toByteArray();
ContentWriter writer = getContentService().getWriter(destNodeRef, ContentModel.PROP_CONTENT, true);
writer.putContent(new ByteArrayInputStream(binaryData));
} catch (Exception e) {
LOGGER.error("Exception while writing content :"+e);
}
}
Here are some issues and the working solution for it.
Error:
org.springframework.dao.ConcurrencyFailureException: Unexpected: current version does not appear to be 1st version in the list [workspace://version2Store/0a5e7701-2112-43b3-80f4-5dfb75ddd7ad, workspace://SpacesStore/3c5d0493-562c-455d-91b8-33bc717b39c4]at org.alfresco.repo.version.Version2ServiceImpl.getCurrentVersionImpl(Version2ServiceImpl.java:859)at org.alfresco.repo.version.Version2ServiceImpl.getCurrentVersion(Version2ServiceImpl.java:400)
This error can come up when the file you are creating/copying is not copied/written on it's immediate parent (ex: v1.0 is already there in alfresco repository, and the file you are copying on top of it should make the version 1.1. But the noderef which you are referring to while writing the file might not be the noderef of 1.0, but something else.
Alternatives I tried:
1)
getVersionService().createVersion(currentVersion.getFrozenStateNodeRef(), versionProperties);
Result:
ERROR: java.lang.UnsupportedOperationException: This operation is not supported by a version store implementation of the node service.at org.alfresco.repo.version.NodeServiceImpl.setProperty(NodeServiceImpl.java:468)
2)
VersionHistory vh = versionService.getVersionHistory(fileNodeRef);
Version version = vh.getRootVersion();
NodeRef node = version.getFrozenStateNodeRef();
Version currentVersion = versionService.getCurrentVersion(node);
Result:
ERROR: java.lang.UnsupportedOperationException: This operation is not supported by a version store implementation of the node service.at org.alfresco.repo.version.NodeServiceImpl.setProperty(NodeServiceImpl.java:468)
3)
If I keep getVersionedNodeRef() in both places:
VersionHistory vh = versionService.getVersionHistory(fileNodeRef);
Version version = vh.getHeadVersion();
Version newVersion = getVersionService().createVersion(version.getVersionedNodeRef(), versionProperties);
Result:
org.springframework.dao.ConcurrencyFailureException: Unexpected: current version does not appear to be 1st version in the list [workspace://version2Store/0fa61697-64d4-4107-a793-4b0330db6e4e, workspace://SpacesStore/bda8e3ea-dc65-4aca-842e-e3945f19182b]
4)
If I keep getFrozenStateNodeRef() :
VersionHistory vh = versionService.getVersionHistory(fileNodeRef);
Version version = vh.getHeadVersion();
Version newVersion = getVersionService().createVersion(version.getFrozenStateNodeRef(), versionProperties);
Result:
ERROR [PROJECT.webscripts.CopyFilesWebscript] [http-bio-8080-exec-20] java.lang.UnsupportedOperationException: This operation is not supported by a version store implementation of the node service.
java.lang.UnsupportedOperationException: This operation is not supported by a version store implementation of the node service.at org.alfresco.repo.version.NodeServiceImpl.setProperty(NodeServiceImpl.java:468)at sun.reflect.GeneratedMethodAccessor747.invoke(Unknown Source)
Head version Label=1.0
Head version Type=MAJOR
Head version versionedNodeRef=workspace://SpacesStore/d3755ca5-d430-4eb7-9c6b-2cd6a4bb913d
Head version fronzedStateNodeRef=versionStore://version2Store/2eb9b528-c4e9-4478-92a0-68bcd5c67fe2
Sometimes, this error is also faced:
2018-03-22 12:31:46,640 ERROR [PROJECT.webscripts.CopyFilesWebscript] [http-bio-8080-exec-38] org.alfresco.service.cmr.version.VersionServiceException: 02220005 The current version label of the node does not exist in the version history. org.alfresco.service.cmr.version.VersionServiceException: 02220005 The current version label of the node does not exist in the version history.at org.alfresco.repo.version.Version2ServiceImpl.createVersion(Version2ServiceImpl.java:243)at org.alfresco.repo.version.Version2ServiceImpl.createVersion(Version2ServiceImpl.java:118)
Working Solution/Code:
The class should use the following code for copying files (here in this case, it's multiple files, so we iterate over the files and copy.
for (NodeRef fileNode : list) {
String docName = nodeService.getProperty(fileNode, ContentModel.PROP_NAME).toString();
QName documentName = QName.createQName(CustomModel.CUSTOM_NAMESPACE_URI,docName);
NodeRef existingDocumentNodeRef = nodeService.getChildByName(newDestinationNode, ContentModel.ASSOC_CONTAINS, docName);
if(existingDocumentNodeRef!=null && getNodeService().exists(existingDocumentNodeRef)){
copySourceContent(fileNode,existingDocumentNodeRef);
/*Adding below method call not working - giving the error:
* org.springframework.dao.ConcurrencyFailureException: Unexpected: current version does not appear to be 1st version in the list*/
//copyProperties(fileNode,existingDocumentNodeRef);
Map versionProps = new HashMap();
versionProps.put(ContentModel.PROP_AUTO_VERSION, true);
versionProps.put(ContentModel.PROP_AUTO_VERSION_PROPS, true);
versionService.ensureVersioningEnabled(existingDocumentNodeRef, versionProps);
Map versionProperties = new HashMap(); versionProperties.put(VersionModel.PROP_VERSION_TYPE, VersionType.MINOR);
versionService.createVersion(existingDocumentNodeRef, versionProperties);
map.put(existingDocumentNodeRef.getId(), docName);
}
else
{
FileInfo fInfo = getFileFolderService().copy(fileNode, newDestinationNode, docName);
map.put(fInfo.getNodeRef().getId(), docName);
}
}
private void copySourceContent(NodeRef sourceNodeRef, NodeRef destNodeRef){
byte[] binaryData = null;
try {
ContentReader reader = getContentService().getReader(sourceNodeRef, ContentModel.PROP_CONTENT);
InputStream originalInputStream = reader.getContentInputStream();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
final int BUF_SIZE = 1 << 8;
//1KiB buffer
byte[] buffer = new byte[BUF_SIZE];
int bytesRead = -1;
while((bytesRead = originalInputStream.read(buffer)) > -1) {
outputStream.write(buffer, 0, bytesRead);
}
originalInputStream.close();
binaryData = outputStream.toByteArray();
ContentWriter writer = getContentService().getWriter(destNodeRef, ContentModel.PROP_CONTENT, true);
writer.putContent(new ByteArrayInputStream(binaryData));
} catch (Exception e) {
LOGGER.error("Exception while writing content :"+e);
}
}
Passionatesanket: Versioning And Versionservice Related Issues In Alfresco >>>>> Download Now
ReplyDelete>>>>> Download Full
Passionatesanket: Versioning And Versionservice Related Issues In Alfresco >>>>> Download LINK
>>>>> Download Now
Passionatesanket: Versioning And Versionservice Related Issues In Alfresco >>>>> Download Full
>>>>> Download LINK hx