use of org.alfresco.service.cmr.version.VersionHistory in project records-management by Alfresco.
the class RejectRecordTest method testRevertAfterReject.
/**
*/
public void testRevertAfterReject() throws Exception {
doBehaviourDrivenTest(new BehaviourDrivenTest() {
private NodeRef document;
public void given() {
NodeRef folder = fileFolderService.create(documentLibrary, GUID.generate(), TYPE_FOLDER).getNodeRef();
document = fileFolderService.create(folder, GUID.generate(), TYPE_CONTENT).getNodeRef();
assertFalse(recordService.isRecord(document));
ownableService.setOwner(document, userName);
versionService.ensureVersioningEnabled(document, null);
// document is declared as a record by user
AuthenticationUtil.runAs(new RunAsWork<Void>() {
public Void doWork() throws Exception {
// declare record
recordService.createRecord(filePlan, document);
return null;
}
}, userName);
assertTrue(nodeService.hasAspect(document, ASPECT_FILE_PLAN_COMPONENT));
}
public void when() {
// reject the record
recordService.rejectRecord(document, REASON);
assertFalse(nodeService.hasAspect(document, ASPECT_FILE_PLAN_COMPONENT));
// upload a new version of the document
AuthenticationUtil.runAs(new RunAsWork<Void>() {
public Void doWork() throws Exception {
ContentWriter writer = contentService.getWriter(document, ContentModel.PROP_CONTENT, true);
writer.putContent("This is a change to the content and should force a new version");
versionService.createVersion(document, null);
return null;
}
}, userName);
assertFalse(nodeService.hasAspect(document, ASPECT_FILE_PLAN_COMPONENT));
VersionHistory history = versionService.getVersionHistory(document);
assertEquals(2, history.getAllVersions().size());
final Version initial = history.getRootVersion();
assertFalse(nodeService.hasAspect(initial.getFrozenStateNodeRef(), ASPECT_FILE_PLAN_COMPONENT));
AuthenticationUtil.runAs(new RunAsWork<Void>() {
public Void doWork() throws Exception {
// revert the document to a previous version
versionService.revert(document, initial);
return null;
}
}, userName);
}
public void then() {
// document is no longer a record
assertFalse(recordService.isRecord(document));
// expected owner has be re-set
assertEquals(userName, ownableService.getOwner(document));
}
});
}
use of org.alfresco.service.cmr.version.VersionHistory in project records-management by Alfresco.
the class DeleteRecordVersionTest method testDeleteCurrentVersion.
/**
* Given a chain of version records (1.0, 1.1, 1.2) which are all related
* When I delete version record 1.2
* Then 1.1 is the most recent version
*/
public void testDeleteCurrentVersion() {
final NodeRef myDocument = createDocumentWithRecordVersions();
doBehaviourDrivenTest(new BehaviourDrivenTest() {
private VersionHistory versionHistory;
public void given() throws Exception {
// get version history
versionHistory = versionService.getVersionHistory(myDocument);
}
public void when() {
Version version12 = versionHistory.getVersion("1.2");
NodeRef recordVersion12 = recordableVersionService.getVersionRecord(version12);
// delete record version 1.2
nodeService.deleteNode(recordVersion12);
}
public void then() {
// check 1.2
Version version12 = versionHistory.getVersion("1.2");
assertNotNull(version12);
assertTrue(recordableVersionService.isRecordedVersionDestroyed(version12));
assertNull(recordableVersionService.getVersionRecord(version12));
// verify 1.1
Version version11 = versionHistory.getVersion("1.1");
assertNotNull(version11);
NodeRef recordVersion11 = recordableVersionService.getVersionRecord(version11);
assertNotNull(recordVersion11);
assertTrue(relationshipService.getRelationshipsTo(recordVersion11, RelationshipService.RELATIONSHIP_VERSIONS).isEmpty());
Set<Relationship> from11 = relationshipService.getRelationshipsFrom(recordVersion11, RelationshipService.RELATIONSHIP_VERSIONS);
assertEquals(1, from11.size());
// verify 1.0
Version version10 = versionHistory.getVersion("1.0");
assertNotNull(version10);
NodeRef recordVersion10 = recordableVersionService.getVersionRecord(version10);
assertNotNull(recordVersion10);
Set<Relationship> to10 = relationshipService.getRelationshipsTo(recordVersion10, RelationshipService.RELATIONSHIP_VERSIONS);
assertEquals(1, to10.size());
assertEquals(recordVersion11, to10.iterator().next().getSource());
assertTrue(relationshipService.getRelationshipsFrom(recordVersion10, RelationshipService.RELATIONSHIP_VERSIONS).isEmpty());
}
});
}
use of org.alfresco.service.cmr.version.VersionHistory in project records-management by Alfresco.
the class DeleteRecordVersionTest method testDeleteMiddleVersion.
/**
* Given a chain of version records (1.0, 1.1, 1.2) which are all related
* When I delete version record 1.1
* Then 1.2 now 'versions' 1.0
*/
public void testDeleteMiddleVersion() {
final NodeRef myDocument = createDocumentWithRecordVersions();
doBehaviourDrivenTest(new BehaviourDrivenTest() {
private VersionHistory versionHistory;
public void given() throws Exception {
// get version history
versionHistory = versionService.getVersionHistory(myDocument);
}
public void when() {
Version version11 = versionHistory.getVersion("1.1");
NodeRef recordVersion11 = recordableVersionService.getVersionRecord(version11);
// delete record version 1.1
nodeService.deleteNode(recordVersion11);
}
public void then() {
// check the deleted version
Version version11 = versionHistory.getVersion("1.1");
assertNotNull(version11);
assertTrue(recordableVersionService.isRecordedVersionDestroyed(version11));
NodeRef recordVersion11 = recordableVersionService.getVersionRecord(version11);
assertNull(recordVersion11);
// verify 1.2 setup as expected
Version version12 = versionHistory.getHeadVersion();
assertEquals("1.2", version12.getVersionLabel());
NodeRef recordVersion12 = recordableVersionService.getVersionRecord(version12);
assertNotNull(recordVersion12);
assertTrue(relationshipService.getRelationshipsTo(recordVersion12, RelationshipService.RELATIONSHIP_VERSIONS).isEmpty());
Set<Relationship> from12 = relationshipService.getRelationshipsFrom(recordVersion12, RelationshipService.RELATIONSHIP_VERSIONS);
assertEquals(1, from12.size());
// verify 1.0 setup as expected
Version version10 = versionHistory.getVersion("1.0");
assertEquals("1.0", version10.getVersionLabel());
NodeRef recordVersion10 = recordableVersionService.getVersionRecord(version10);
assertNotNull(recordVersion10);
Set<Relationship> to10 = relationshipService.getRelationshipsTo(recordVersion10, RelationshipService.RELATIONSHIP_VERSIONS);
assertEquals(1, to10.size());
assertEquals(recordVersion12, to10.iterator().next().getSource());
assertTrue(relationshipService.getRelationshipsFrom(recordVersion10, RelationshipService.RELATIONSHIP_VERSIONS).isEmpty());
}
});
}
use of org.alfresco.service.cmr.version.VersionHistory in project alfresco-remote-api by Alfresco.
the class RenditionsImpl method findVersionIfApplicable.
private NodeRef findVersionIfApplicable(NodeRef nodeRef, String versionLabelId) {
if (versionLabelId != null) {
nodeRef = nodes.validateOrLookupNode(nodeRef.getId(), null);
VersionHistory vh = versionService.getVersionHistory(nodeRef);
if (vh != null) {
try {
Version v = vh.getVersion(versionLabelId);
nodeRef = VersionUtil.convertNodeRef(v.getFrozenStateNodeRef());
} catch (VersionDoesNotExistException vdne) {
throw new NotFoundException("Couldn't find version: [" + nodeRef.getId() + ", " + versionLabelId + "]");
}
}
}
return nodeRef;
}
use of org.alfresco.service.cmr.version.VersionHistory in project alfresco-remote-api by Alfresco.
the class NodeVersionsRelation method readAll.
/**
* List version history
*
* @param nodeId String id of (live) node
*/
@Override
@WebApiDescription(title = "Return version history as a paged list of version node infos")
public CollectionWithPagingInfo<Node> readAll(String nodeId, Parameters parameters) {
NodeRef nodeRef = nodes.validateOrLookupNode(nodeId, null);
VersionHistory vh = versionService.getVersionHistory(nodeRef);
Map<String, UserInfo> mapUserInfo = new HashMap<>(10);
List<String> includeParam = parameters.getInclude();
List<Node> collection = null;
if (vh != null) {
collection = new ArrayList<>(vh.getAllVersions().size());
for (Version v : vh.getAllVersions()) {
Node node = nodes.getFolderOrDocument(v.getFrozenStateNodeRef(), null, null, includeParam, mapUserInfo);
mapVersionInfo(v, node);
collection.add(node);
}
}
return listPage(collection, parameters.getPaging());
}
Aggregations