001/* 002 * (C) Copyright 2020 Nuxeo (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 * Thierry Casanova 018 */ 019 020package org.nuxeo.ecm.automation.core.operations.services.directory; 021 022import org.nuxeo.ecm.automation.OperationContext; 023import org.nuxeo.ecm.automation.core.Constants; 024import org.nuxeo.ecm.automation.core.annotations.Context; 025import org.nuxeo.ecm.automation.core.annotations.Operation; 026import org.nuxeo.ecm.automation.core.annotations.OperationMethod; 027import org.nuxeo.ecm.automation.core.annotations.Param; 028import org.nuxeo.ecm.core.api.Blob; 029import org.nuxeo.ecm.directory.api.DirectoryService; 030 031/** 032 * Load entries into a {@link org.nuxeo.ecm.directory.Directory} from a CSV File. Depending on 033 * {@code dataLoadingPolicy}, duplicate entries could: 034 * <ul> 035 * <li>be ignored</li> 036 * <li>be updated</li> 037 * <li>trigger an error</li> 038 * </ul> 039 * 040 * @since 11.1 041 */ 042@Operation(id = LoadFromCSV.ID, category = Constants.CAT_SERVICES, label = "Load directory entries from CSV file", description = "Load directory entries from a CSV file. Depending on the data loading policy, duplicate entries are ignored, updated or trigger an error.") 043public class LoadFromCSV extends AbstractDirectoryOperation { 044 045 public static final String ID = "Directory.LoadFromCSV"; 046 047 @Context 048 protected OperationContext ctx; 049 050 @Context 051 protected DirectoryService directoryService; 052 053 @Param(name = "directoryName") 054 protected String directoryName; 055 056 @Param(name = "dataLoadingPolicy") 057 protected String dataLoadingPolicy; 058 059 @OperationMethod 060 public void run(Blob dataBlob) { 061 validateCanManageDirectories(ctx); 062 directoryService.loadFromCSV(directoryName, dataBlob, dataLoadingPolicy); 063 } 064}