use of org.alfresco.service.cmr.version.Version in project acs-community-packaging by Alfresco.
the class VersionedDocumentDetailsDialog method getBrowsingVersionForMLContainer.
/**
* Util method which return the last (most recent) version of a translation of a given edition of a mlContainer according its language
*/
@SuppressWarnings("unchecked")
private Version getBrowsingVersionForMLContainer(NodeRef document, String editionLabel, String lang) {
// get the list of translations of the given edition of the mlContainer
List<VersionHistory> translations = getEditionService().getVersionedTranslations(this.documentEdition);
// if translation size == 0, the edition is the current edition and the translations are not yet attached.
if (translations.size() == 0) {
// the selection edition is the current.
return getBrowsingCurrentVersionForMLContainer(document, lang);
} else {
Version versionToReturn = null;
// get the last (most recent) version of the translation in the given lang of the edition
for (VersionHistory history : translations) {
// get the list of versions (in descending order - ie. most recent first)
List<Version> orderedVersions = new ArrayList<Version>(history.getAllVersions());
// the last version (ie. most recent) is the first version of the list
Version lastVersion = orderedVersions.get(0);
if (lastVersion != null) {
Map<QName, Serializable> properties = getEditionService().getVersionedMetadatas(lastVersion);
Locale locale = (Locale) properties.get(ContentModel.PROP_LOCALE);
if (locale.getLanguage().equalsIgnoreCase(lang)) {
versionToReturn = lastVersion;
this.versionHistory = history;
break;
}
}
}
return versionToReturn;
}
}
use of org.alfresco.service.cmr.version.Version in project alfresco-remote-api by Alfresco.
the class NodeVersionsRelation method delete.
@Override
@WebApiDescription(title = "Delete version")
public void delete(String nodeId, String versionId, Parameters parameters) {
Version v = findVersion(nodeId, versionId);
// live (aka versioned) nodeRef
NodeRef nodeRef = v.getVersionedNodeRef();
if (sr.getPermissionService().hasPermission(nodeRef, PermissionService.DELETE) != AccessStatus.ALLOWED) {
throw new PermissionDeniedException("Cannot delete version");
}
versionService.deleteVersion(nodeRef, v);
Map<QName, Serializable> props = sr.getNodeService().getProperties(nodeRef);
if (props.get(ContentModel.PROP_VERSION_LABEL) == null) {
// note: alternatively, the client can remove the "cm:versionable" aspect (if permissions allow) to clear the version history and disable versioning
throw new IntegrityException("Cannot delete last version (did you mean to disable versioning instead ?) [" + nodeId + "," + versionId + "]", null);
/*
if (props.get(ContentModel.PROP_VERSION_TYPE) != null)
{
// minor fix up to versionable aspect - ie. remove versionType
behaviourFilter.disableBehaviour(nodeRef, ContentModel.ASPECT_VERSIONABLE);
behaviourFilter.disableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);
try
{
sr.getNodeService().removeProperty(nodeRef, ContentModel.PROP_VERSION_TYPE);
}
finally
{
behaviourFilter.enableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);
behaviourFilter.enableBehaviour(nodeRef, ContentModel.ASPECT_VERSIONABLE);
}
}
*/
}
}
use of org.alfresco.service.cmr.version.Version 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());
}
use of org.alfresco.service.cmr.version.Version in project records-management by Alfresco.
the class RecordableVersionServiceImpl method getLatestVersionRecord.
/**
* Helper to get the latest version record for a given document (ie non-record)
*
* @param nodeRef node reference
* @return NodeRef latest version record, null otherwise
*/
private NodeRef getLatestVersionRecord(NodeRef nodeRef) {
NodeRef versionRecord = null;
// wire record up to previous record
VersionHistory versionHistory = getVersionHistory(nodeRef);
if (versionHistory != null) {
Collection<Version> previousVersions = versionHistory.getAllVersions();
for (Version previousVersion : previousVersions) {
// look for the associated record
final NodeRef previousRecord = (NodeRef) previousVersion.getVersionProperties().get(PROP_VERSION_RECORD);
if (previousRecord != null && nodeService.exists(previousRecord)) {
versionRecord = previousRecord;
break;
}
}
}
return versionRecord;
}
use of org.alfresco.service.cmr.version.Version in project records-management by Alfresco.
the class RecordableVersionServiceImpl method getVersion.
/**
* @see org.alfresco.repo.version.Version2ServiceImpl#getVersion(org.alfresco.service.cmr.repository.NodeRef)
*/
@Override
protected Version getVersion(NodeRef versionRef) {
Version version = super.getVersion(versionRef);
// place the version record reference in the version properties
NodeRef record = (NodeRef) dbNodeService.getProperty(versionRef, PROP_RECORD_NODE_REF);
if (record != null) {
version.getVersionProperties().put(PROP_VERSION_RECORD, record);
}
// place information about the destruction of the version record in the properties
Boolean destroyed = (Boolean) dbNodeService.getProperty(versionRef, PROP_DESTROYED);
if (destroyed == null) {
destroyed = Boolean.FALSE;
}
version.getVersionProperties().put(PROP_RECORDED_VERSION_DESTROYED, destroyed);
return version;
}
Aggregations