001/*
002 * (C) Copyright 2012 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 *     Antoine Taillefer <ataillefer@nuxeo.com>
018 */
019package org.nuxeo.drive.operations.test;
020
021import org.nuxeo.drive.service.FileSystemItemAdapterService;
022import org.nuxeo.drive.service.VersioningFileSystemItemFactory;
023import org.nuxeo.drive.service.impl.DefaultFileSystemItemFactory;
024import org.nuxeo.drive.service.impl.FileSystemItemAdapterServiceImpl;
025import org.nuxeo.ecm.automation.core.Constants;
026import org.nuxeo.ecm.automation.core.annotations.Operation;
027import org.nuxeo.ecm.automation.core.annotations.OperationMethod;
028import org.nuxeo.ecm.automation.core.annotations.Param;
029import org.nuxeo.ecm.core.api.VersioningOption;
030import org.nuxeo.runtime.api.Framework;
031
032/**
033 * Sets versioning options on the {@link DefaultFileSystemItemFactory}:
034 * <ul>
035 * <li>delay (default: 1 hour)</li>
036 * <li>option (default: MINOR)</li>
037 * </ul>
038 *
039 * @author Antoine Taillefer
040 * @deprecated since 9.1 as the automatic versioning is handled by versioning system, versioning mechanism has been
041 *             removed from drive, setting options is not supported anymore
042 */
043@Deprecated
044@Operation(id = NuxeoDriveSetVersioningOptions.ID, category = Constants.CAT_SERVICES, label = "Nuxeo Drive: Set versioning options", deprecatedSince = "9.1")
045public class NuxeoDriveSetVersioningOptions {
046
047    public static final String ID = "NuxeoDrive.SetVersioningOptions";
048
049    @Param(name = "delay", required = false)
050    protected String delay;
051
052    @Param(name = "option", required = false)
053    protected String option;
054
055    @OperationMethod
056    public void run() {
057        NuxeoDriveIntegrationTestsHelper.checkOperationAllowed();
058        FileSystemItemAdapterService fileSystemItemAdapterService = Framework.getService(
059                FileSystemItemAdapterService.class);
060        VersioningFileSystemItemFactory defaultFileSystemItemFactory = (VersioningFileSystemItemFactory) ((FileSystemItemAdapterServiceImpl) fileSystemItemAdapterService).getFileSystemItemFactory(
061                "defaultFileSystemItemFactory");
062        if (delay != null) {
063            defaultFileSystemItemFactory.setVersioningDelay(Double.parseDouble(delay));
064        }
065        if (option != null) {
066            defaultFileSystemItemFactory.setVersioningOption(VersioningOption.valueOf(option));
067        }
068    }
069}