use of org.alfresco.traitextender.Extend in project alfresco-repository by Alfresco.
the class Version2ServiceImpl method getVersionHistory.
@Override
@Extend(extensionAPI = VersionServiceExtension.class, traitAPI = VersionServiceTrait.class)
public VersionHistory getVersionHistory(NodeRef nodeRef) {
if (logger.isDebugEnabled()) {
logger.debug("Run as user " + AuthenticationUtil.getRunAsUser());
logger.debug("Fully authenticated " + AuthenticationUtil.getFullyAuthenticatedUser());
}
VersionHistory versionHistory = null;
// Get the version history regardless of whether the node is still 'live' or not
NodeRef versionHistoryRef = getVersionHistoryNodeRef(nodeRef);
if (versionHistoryRef != null) {
versionHistory = buildVersionHistory(versionHistoryRef, nodeRef);
}
return versionHistory;
}
use of org.alfresco.traitextender.Extend in project alfresco-repository by Alfresco.
the class Version2ServiceImpl method restore.
@Override
@Extend(extensionAPI = VersionServiceExtension.class, traitAPI = VersionServiceTrait.class)
public NodeRef restore(NodeRef nodeRef, NodeRef parentNodeRef, QName assocTypeQName, QName assocQName, boolean deep) {
if (logger.isDebugEnabled()) {
logger.debug("Run as user " + AuthenticationUtil.getRunAsUser());
logger.debug("Fully authenticated " + AuthenticationUtil.getFullyAuthenticatedUser());
}
NodeRef restoredNodeRef = null;
// Check that the node does not exist
if (this.nodeService.exists(nodeRef) == true) {
// Error since you can not restore a node that already exists
throw new VersionServiceException(MSGID_ERR_RESTORE_EXISTS, new Object[] { nodeRef.toString() });
}
// Try and get the version details that we want to restore to
Version version = getHeadVersion(nodeRef);
if (version == null) {
// Error since there is no version information available to restore the node from
throw new VersionServiceException(MSGID_ERR_RESTORE_NO_VERSION, new Object[] { nodeRef.toString() });
}
// Set the uuid of the new node
Map<QName, Serializable> props = new HashMap<QName, Serializable>(1);
props.put(ContentModel.PROP_NODE_UUID, ((NodeRef) version.getVersionProperty(Version2Model.PROP_FROZEN_NODE_REF)).getId());
props.put(ContentModel.PROP_VERSION_LABEL, version.getVersionLabel());
// Get the type of the frozen node
QName type = (QName) dbNodeService.getType(VersionUtil.convertNodeRef(version.getFrozenStateNodeRef()));
// Disable auto-version behaviour
this.policyBehaviourFilter.disableBehaviour(ContentModel.ASPECT_VERSIONABLE);
try {
// Create the restored node
restoredNodeRef = this.nodeService.createNode(parentNodeRef, assocTypeQName, assocQName, type, props).getChildRef();
} finally {
// Enable auto-version behaviour
this.policyBehaviourFilter.enableBehaviour(ContentModel.ASPECT_VERSIONABLE);
}
// Now we need to revert the newly restored node
revert(restoredNodeRef, version, deep);
return restoredNodeRef;
}
use of org.alfresco.traitextender.Extend in project alfresco-repository by Alfresco.
the class Version2ServiceImpl method createVersion.
@Override
@Extend(extensionAPI = VersionServiceExtension.class, traitAPI = VersionServiceTrait.class)
public Collection<Version> createVersion(Collection<NodeRef> nodeRefs, Map<String, Serializable> versionProperties) throws ReservedVersionNameException, AspectMissingException {
if (logger.isDebugEnabled()) {
logger.debug("Run as user " + AuthenticationUtil.getRunAsUser());
logger.debug("Fully authenticated " + AuthenticationUtil.getFullyAuthenticatedUser());
}
/*
* Note: we can't control the order of the list, so if we have children and parents in the list and the
* parents get versioned before the children and the children are not already versioned then the parents
* child references will be pointing to the node ref, rather than the version history.
*/
long startTime = System.currentTimeMillis();
Collection<Version> result = new ArrayList<Version>(nodeRefs.size());
// deprecated (unused)
int versionNumber = 0;
// Version each node in the list
for (NodeRef nodeRef : nodeRefs) {
result.add(createVersion(nodeRef, versionProperties, versionNumber));
}
if (logger.isDebugEnabled()) {
logger.debug("created version list (" + getVersionStoreReference() + ") in " + (System.currentTimeMillis() - startTime) + " ms (with " + nodeRefs.size() + " nodes)");
}
return result;
}
use of org.alfresco.traitextender.Extend in project alfresco-repository by Alfresco.
the class Version2ServiceImpl method deleteVersion.
@Override
@Extend(extensionAPI = VersionServiceExtension.class, traitAPI = VersionServiceTrait.class)
public void deleteVersion(NodeRef nodeRef, Version version) {
if (logger.isDebugEnabled()) {
logger.debug("Run as user " + AuthenticationUtil.getRunAsUser());
logger.debug("Fully authenticated " + AuthenticationUtil.getFullyAuthenticatedUser());
}
// Check the mandatory parameters
ParameterCheck.mandatory("nodeRef", nodeRef);
ParameterCheck.mandatory("version", version);
Version currentVersion = getCurrentVersion(nodeRef);
// Delete the version node
this.dbNodeService.deleteNode(VersionUtil.convertNodeRef(version.getFrozenStateNodeRef()));
// If we try to delete the last version
if (currentVersion.getVersionLabel().equals(version.getVersionLabel())) {
Version headVersion = getHeadVersion(nodeRef);
if (headVersion != null) {
// Reset the version label property on the versionable node to new head version
// Disable the VersionableAspect for this change though, we don't want
// to have this create a new version for the property change!
policyBehaviourFilter.disableBehaviour(nodeRef, ContentModel.ASPECT_VERSIONABLE);
try {
this.nodeService.setProperty(nodeRef, ContentModel.PROP_VERSION_LABEL, headVersion.getVersionLabel());
// MNT-13097 Content will be reverted as well
revert(nodeRef, headVersion);
} finally {
policyBehaviourFilter.enableBehaviour(nodeRef, ContentModel.ASPECT_VERSIONABLE);
}
} else {
deleteVersionHistory(nodeRef);
}
}
}
use of org.alfresco.traitextender.Extend in project alfresco-repository by Alfresco.
the class Version2ServiceImpl method createVersion.
@Override
@Extend(extensionAPI = VersionServiceExtension.class, traitAPI = VersionServiceTrait.class)
public Version createVersion(NodeRef nodeRef, Map<String, Serializable> versionProperties) throws ReservedVersionNameException, AspectMissingException {
if (logger.isDebugEnabled()) {
logger.debug("Run as user " + AuthenticationUtil.getRunAsUser());
logger.debug("Fully authenticated " + AuthenticationUtil.getFullyAuthenticatedUser());
}
long startTime = System.currentTimeMillis();
// deprecated (unused)
int versionNumber = 0;
// Create the version
Version version = createVersion(nodeRef, versionProperties, versionNumber);
if (logger.isDebugEnabled()) {
logger.debug("created version (" + VersionUtil.convertNodeRef(version.getFrozenStateNodeRef()) + ") in " + (System.currentTimeMillis() - startTime) + " ms");
}
return version;
}
Aggregations