use of org.alfresco.service.cmr.version.VersionType in project alfresco-remote-api by Alfresco.
the class NodesImpl method createNewFile.
private NodeRef createNewFile(NodeRef parentNodeRef, String fileName, QName nodeType, Content content, Map<QName, Serializable> props, QName assocTypeQName, Parameters params, Boolean versionMajor, String versionComment) {
NodeRef nodeRef = createNodeImpl(parentNodeRef, fileName, nodeType, props, assocTypeQName);
if (content == null) {
// Write "empty" content
writeContent(nodeRef, fileName, new ByteArrayInputStream("".getBytes()), false);
} else {
// Write content
writeContent(nodeRef, fileName, content.getInputStream(), true);
}
if ((versionMajor != null) || (versionComment != null)) {
behaviourFilter.disableBehaviour(nodeRef, ContentModel.ASPECT_VERSIONABLE);
try {
// by default, first version is major, unless specified otherwise
VersionType versionType = VersionType.MAJOR;
if ((versionMajor != null) && (!versionMajor)) {
versionType = VersionType.MINOR;
}
createVersion(nodeRef, false, versionType, versionComment);
extractMetadata(nodeRef);
} finally {
behaviourFilter.enableBehaviour(nodeRef, ContentModel.ASPECT_VERSIONABLE);
}
}
return nodeRef;
}
use of org.alfresco.service.cmr.version.VersionType in project alfresco-remote-api by Alfresco.
the class NodesImpl method updateExistingFile.
private Node updateExistingFile(NodeRef parentNodeRef, NodeRef nodeRef, String fileName, BasicContentInfo contentInfo, InputStream stream, Parameters parameters, Boolean versionMajor, String versionComment) {
boolean isVersioned = versionService.isVersioned(nodeRef);
behaviourFilter.disableBehaviour(nodeRef, ContentModel.ASPECT_VERSIONABLE);
try {
writeContent(nodeRef, fileName, stream, true);
if ((isVersioned) || (versionMajor != null) || (versionComment != null)) {
VersionType versionType = null;
if (versionMajor != null) {
versionType = (versionMajor ? VersionType.MAJOR : VersionType.MINOR);
} else {
// note: it is possible to have versionable aspect but no versions (=> no version label)
if ((!isVersioned) || (nodeService.getProperty(nodeRef, ContentModel.PROP_VERSION_LABEL) == null)) {
versionType = VersionType.MAJOR;
} else {
versionType = VersionType.MINOR;
}
}
createVersion(nodeRef, isVersioned, versionType, versionComment);
}
ActivityInfo activityInfo = getActivityInfo(parentNodeRef, nodeRef);
postActivity(Activity_Type.UPDATED, activityInfo, false);
extractMetadata(nodeRef);
} finally {
behaviourFilter.enableBehaviour(nodeRef, ContentModel.ASPECT_VERSIONABLE);
}
return getFolderOrDocumentFullInfo(nodeRef, null, null, parameters);
}
use of org.alfresco.service.cmr.version.VersionType in project alfresco-remote-api by Alfresco.
the class NodeVersionsRelation method revertById.
@Operation("revert")
@WebApiDescription(title = "Revert Version", description = "Reverts (ie. promotes) specified version to become a new, most recent, version", successStatus = HttpServletResponse.SC_OK)
public Node revertById(String nodeId, String versionId, VersionOptions versionOptions, Parameters parameters, WithResponse withResponse) {
Version v = findVersion(nodeId, versionId);
if (v != null) {
CheckOutCheckInService cociService = sr.getCheckOutCheckInService();
NodeRef nodeRef = v.getVersionedNodeRef();
String versionComment = versionOptions.getComment();
VersionType versionType = VersionType.MINOR;
Boolean versionMajor = versionOptions.getMajorVersion();
if ((versionMajor != null) && (versionMajor)) {
versionType = VersionType.MAJOR;
}
Map<String, Serializable> versionProperties = new HashMap<>(2);
versionProperties.put(VersionModel.PROP_VERSION_TYPE, versionType);
if (versionComment != null) {
versionProperties.put(VersionModel.PROP_DESCRIPTION, versionComment);
}
// cancel editing if we want to revert
if (sr.getNodeService().hasAspect(nodeRef, ContentModel.ASPECT_WORKING_COPY)) {
nodeRef = cociService.cancelCheckout(nodeRef);
}
// TODO review default for deep and/or whether we should make it an option
versionService.revert(nodeRef, v, false);
// Checkout/Checkin the node - to store the new version in version history
NodeRef wcNodeRef = cociService.checkout(nodeRef);
cociService.checkin(wcNodeRef, versionProperties);
// get latest version
v = versionService.getVersionHistory(nodeRef).getHeadVersion();
Node node = nodes.getFolderOrDocumentFullInfo(v.getFrozenStateNodeRef(), null, null, parameters, null);
mapVersionInfo(v, node);
return node;
}
throw new EntityNotFoundException(nodeId + "-" + versionId);
}
Aggregations