001/* 002 * (C) Copyright 2006-2016 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Dragos Mihalache 018 * Florent Guillaume 019 */ 020package org.nuxeo.ecm.platform.versioning.service; 021 022import org.nuxeo.ecm.core.api.DocumentModel; 023import org.nuxeo.ecm.core.api.VersioningOption; 024import org.nuxeo.ecm.core.api.versioning.VersioningService; 025import org.nuxeo.ecm.platform.versioning.api.VersionIncEditOptions; 026import org.nuxeo.ecm.platform.versioning.api.VersioningActions; 027import org.nuxeo.ecm.platform.versioning.api.VersioningManager; 028import org.nuxeo.runtime.api.Framework; 029import org.nuxeo.runtime.model.DefaultComponent; 030 031/** 032 * Versions management component implementation. 033 */ 034public class VersioningManagerImpl extends DefaultComponent implements VersioningManager { 035 036 /** 037 * @deprecated since 10.10, seems unused 038 */ 039 @Deprecated 040 public static final String COMPONENT_ID = "org.nuxeo.ecm.platform.versioning.VersioningManager"; 041 042 @Override 043 public VersionIncEditOptions getVersionIncEditOptions(DocumentModel doc) { 044 VersionIncEditOptions options = new VersionIncEditOptions(); 045 VersioningService service = Framework.getService(VersioningService.class); 046 for (VersioningOption option : service.getSaveOptions(doc)) { 047 VersioningActions action; 048 switch (option) { 049 case MINOR: 050 action = VersioningActions.ACTION_INCREMENT_MINOR; 051 break; 052 case MAJOR: 053 action = VersioningActions.ACTION_INCREMENT_MAJOR; 054 break; 055 default: 056 action = VersioningActions.ACTION_NO_INCREMENT; 057 } 058 if (option == service.getSaveOptions(doc).get(0)) { 059 options.setDefaultVersioningAction(action); 060 } 061 options.addOption(action); 062 } 063 064 return options; 065 } 066 067 @Override 068 public String getVersionLabel(DocumentModel doc) { 069 return doc.getVersionLabel(); 070 } 071 072}