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.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    public static final String COMPONENT_ID = "org.nuxeo.ecm.platform.versioning.VersioningManager";
037
038    @Override
039    public VersionIncEditOptions getVersionIncEditOptions(DocumentModel doc) {
040        VersionIncEditOptions options = new VersionIncEditOptions();
041        VersioningService service = Framework.getService(VersioningService.class);
042        for (VersioningOption option : service.getSaveOptions(doc)) {
043            VersioningActions action;
044            switch (option) {
045            case MINOR:
046                action = VersioningActions.ACTION_INCREMENT_MINOR;
047                break;
048            case MAJOR:
049                action = VersioningActions.ACTION_INCREMENT_MAJOR;
050                break;
051            default:
052                action = VersioningActions.ACTION_NO_INCREMENT;
053            }
054            if (option == service.getSaveOptions(doc).get(0)) {
055                options.setDefaultVersioningAction(action);
056            }
057            options.addOption(action);
058        }
059
060        return options;
061    }
062
063    @Override
064    public String getVersionLabel(DocumentModel doc) {
065        return doc.getVersionLabel();
066    }
067
068}