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 * Kevin Leturc <kleturc@nuxeo.com> 018 */ 019package org.nuxeo.ecm.core.bulk; 020 021import java.io.Serializable; 022import java.util.Collections; 023import java.util.HashMap; 024import java.util.Map; 025 026import org.apache.commons.lang3.builder.ToStringBuilder; 027 028/** 029 * A command to execute by {@link BulkService}. 030 * 031 * @since 10.2 032 */ 033public class BulkCommand implements Serializable { 034 035 private static final long serialVersionUID = 1L; 036 037 /** The username which run the bulk command. */ 038 protected String username; 039 040 protected String repository; 041 042 protected String query; 043 044 /** The bulk action to execute. */ 045 protected String action; 046 047 protected Map<String, String> params; 048 049 public BulkCommand() { 050 params = new HashMap<>(); 051 } 052 053 public BulkCommand withUsername(String username) { 054 this.username = username; 055 return this; 056 } 057 058 public String getUsername() { 059 return username; 060 } 061 062 public BulkCommand withRepository(String repository) { 063 this.repository = repository; 064 return this; 065 } 066 067 public String getRepository() { 068 return repository; 069 } 070 071 /** 072 * @param query the query used to get the document set concerned by the action 073 */ 074 public BulkCommand withQuery(String query) { 075 this.query = query; 076 return this; 077 } 078 079 public String getQuery() { 080 return query; 081 } 082 083 public BulkCommand withAction(String action) { 084 this.action = action; 085 return this; 086 } 087 088 public String getAction() { 089 return action; 090 } 091 092 public BulkCommand withParams(Map<String, String> params) { 093 this.params.putAll(params); 094 return this; 095 } 096 097 public Map<String, String> getParams() { 098 return Collections.unmodifiableMap(params); 099 } 100 101 public BulkCommand withParam(String key, String value) { 102 params.put(key, value); 103 return this; 104 } 105 106 public String getParam(String key) { 107 return params.get(key); 108 } 109 110 @Override 111 public String toString() { 112 return ToStringBuilder.reflectionToString(this); 113 } 114}