001/* 002 * (C) Copyright 2018 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 * pierre 018 */ 019package org.nuxeo.ecm.platform.csv.export.action; 020 021import static org.nuxeo.ecm.core.bulk.BulkServiceImpl.PRODUCE_IMMEDIATE_OPTION; 022import static org.nuxeo.ecm.core.bulk.BulkServiceImpl.STATUS_STREAM; 023import static org.nuxeo.lib.stream.computation.AbstractComputation.INPUT_1; 024import static org.nuxeo.lib.stream.computation.AbstractComputation.OUTPUT_1; 025import static org.nuxeo.lib.stream.computation.AbstractComputation.OUTPUT_2; 026import static org.nuxeo.lib.stream.computation.AbstractComputation.OUTPUT_3; 027 028import java.util.Arrays; 029import java.util.Map; 030 031import org.nuxeo.ecm.core.bulk.action.computation.ExposeBlob; 032import org.nuxeo.ecm.core.bulk.action.computation.MakeBlob; 033import org.nuxeo.ecm.core.bulk.action.computation.SortBlob; 034import org.nuxeo.ecm.core.bulk.action.computation.ZipBlob; 035import org.nuxeo.ecm.platform.csv.export.computation.CSVProjectionComputation; 036import org.nuxeo.lib.stream.computation.Topology; 037import org.nuxeo.runtime.stream.StreamProcessorTopology; 038 039/** 040 * @since 10.3 041 */ 042public class CSVExportAction implements StreamProcessorTopology { 043 044 public static final String ACTION_NAME = "csvExport"; 045 046 @Override 047 public Topology getTopology(Map<String, String> options) { 048 boolean produceImmediate = getOptionAsBoolean(options, PRODUCE_IMMEDIATE_OPTION, false); 049 return Topology.builder() 050 .addComputation(CSVProjectionComputation::new, // 051 Arrays.asList(INPUT_1 + ":" + ACTION_NAME, // 052 OUTPUT_1 + ":" + MakeBlob.NAME)) 053 .addComputation(() -> new MakeBlob(produceImmediate), // 054 Arrays.asList(INPUT_1 + ":" + MakeBlob.NAME, // 055 OUTPUT_1 + ":" + SortBlob.NAME, // 056 OUTPUT_2 + ":" + ZipBlob.NAME, // 057 OUTPUT_3 + ":" + ExposeBlob.NAME)) 058 .addComputation(SortBlob::new, // 059 Arrays.asList(INPUT_1 + ":" + SortBlob.NAME, // 060 OUTPUT_1 + ":" + ZipBlob.NAME, // 061 OUTPUT_2 + ":" + ExposeBlob.NAME)) 062 .addComputation(ZipBlob::new, // 063 Arrays.asList(INPUT_1 + ":" + ZipBlob.NAME, // 064 OUTPUT_1 + ":" + ExposeBlob.NAME)) 065 .addComputation(ExposeBlob::new, // 066 Arrays.asList(INPUT_1 + ":" + ExposeBlob.NAME, // 067 OUTPUT_1 + ":" + STATUS_STREAM)) 068 .build(); 069 } 070 071 public static boolean getOptionAsBoolean(Map<String, String> options, String option, boolean defaultValue) { 072 String value = options.get(option); 073 return value == null ? defaultValue : Boolean.valueOf(value); 074 } 075 076}