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 <[email protected]> 018 */ 019package org.nuxeo.drive.operations; 020 021import java.io.IOException; 022import java.util.Map; 023import java.util.Set; 024 025import org.nuxeo.drive.service.FileSystemChangeSummary; 026import org.nuxeo.drive.service.NuxeoDriveManager; 027import org.nuxeo.drive.service.impl.RootDefinitionsHelper; 028import org.nuxeo.ecm.automation.OperationContext; 029import org.nuxeo.ecm.automation.core.Constants; 030import org.nuxeo.ecm.automation.core.annotations.Context; 031import org.nuxeo.ecm.automation.core.annotations.Operation; 032import org.nuxeo.ecm.automation.core.annotations.OperationMethod; 033import org.nuxeo.ecm.automation.core.annotations.Param; 034import org.nuxeo.ecm.core.api.Blob; 035import org.nuxeo.ecm.core.api.Blobs; 036import org.nuxeo.ecm.core.api.IdRef; 037import org.nuxeo.runtime.api.Framework; 038 039/** 040 * Gets a summary of the document changes in the synchronization roots of the currently authenticated user for the 041 * interval starting with the given lower bound. 042 * 043 * @author Antoine Taillefer 044 */ 045@Operation(id = NuxeoDriveGetChangeSummary.ID, category = Constants.CAT_SERVICES, label = "Nuxeo Drive: Get change summary", description = "Get a summary of document changes in the synchronization roots of the currently authenticated user." // 046 + " Return the result as a JSON blob.") 047public class NuxeoDriveGetChangeSummary { 048 049 public static final String ID = "NuxeoDrive.GetChangeSummary"; 050 051 @Context 052 protected OperationContext ctx; 053 054 @Param(name = "lowerBound", required = false, description = "Optional lower bound of the interval for which to get the changes." // 055 + " If not provided, the list of document changes will be emtpy, yet the summary will contain the upper bound of the scanned interval." // 056 + " If set to 0, the interval will start from the repository's initialization.", values = "-1") 057 protected Long lowerBound = -1L; 058 059 /** 060 * Expect a String structure with form: repo-1:root-ref-1,repo-1:root-ref-2,repo-2:root-ref-3 061 * 062 * @deprecated since 10.3 063 */ 064 @Deprecated 065 @Param(name = "lastSyncActiveRootDefinitions", required = false) 066 protected String lastSyncActiveRootDefinitions; 067 068 @OperationMethod 069 public Blob run() throws IOException { 070 NuxeoDriveManager driveManager = Framework.getService(NuxeoDriveManager.class); 071 Map<String, Set<IdRef>> lastActiveRootRefs = RootDefinitionsHelper.parseRootDefinitions( 072 lastSyncActiveRootDefinitions); 073 FileSystemChangeSummary docChangeSummary; 074 docChangeSummary = driveManager.getChangeSummary(ctx.getPrincipal(), lastActiveRootRefs, lowerBound); 075 return Blobs.createJSONBlobFromValue(docChangeSummary); 076 } 077 078}