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 * Funsho David 018 */ 019 020package org.nuxeo.ecm.core.bulk; 021 022import static org.apache.commons.lang3.StringUtils.defaultIfBlank; 023 024import org.nuxeo.common.xmap.annotation.XNode; 025import org.nuxeo.common.xmap.annotation.XObject; 026import org.nuxeo.ecm.core.api.NuxeoException; 027import org.nuxeo.runtime.model.Descriptor; 028 029/** 030 * @since 10.2 031 */ 032@XObject("action") 033public class BulkActionDescriptor implements Descriptor { 034 035 public static final Integer DEFAULT_BUCKET_SIZE = 100; 036 037 public static final Integer DEFAULT_BATCH_SIZE = 25; 038 039 // @since 11.1 040 @XNode("@enabled") 041 protected boolean isEnabled = true; 042 043 @XNode("@name") 044 public String name; 045 046 // @since 11.1 047 @XNode("@inputStream") 048 public String inputStream; 049 050 @XNode("@bucketSize") 051 public Integer bucketSize = DEFAULT_BUCKET_SIZE; 052 053 @XNode("@batchSize") 054 public Integer batchSize = DEFAULT_BATCH_SIZE; 055 056 @XNode("@httpEnabled") 057 public Boolean httpEnabled = Boolean.FALSE; 058 059 @XNode("@sequentialCommands") 060 public Boolean sequentialCommands = Boolean.FALSE; 061 062 @XNode("@validationClass") 063 public Class<? extends BulkActionValidation> validationClass; 064 065 // @since 11.1 066 @XNode("@defaultScroller") 067 public String defaultScroller; 068 069 // @since 11.4 the maximum number of items that the scroller can return 070 @XNode("@defaultQueryLimit") 071 public Long defaultQueryLimit; 072 073 @Override 074 public String getId() { 075 return name; 076 } 077 078 public Integer getBucketSize() { 079 return bucketSize; 080 } 081 082 public Integer getBatchSize() { 083 return batchSize; 084 } 085 086 // @since 11.4 087 public Long getDefaultQueryLimit() { 088 return defaultQueryLimit; 089 } 090 091 /** 092 * @since 10.10 093 */ 094 public BulkActionValidation newValidationInstance() { 095 try { 096 return validationClass.getDeclaredConstructor().newInstance(); 097 } catch (ReflectiveOperationException e) { 098 throw new NuxeoException("Cannot create validation class of type " + validationClass.getName(), e); 099 } 100 } 101 102 // @since 11.1 103 public boolean isEnabled() { 104 return isEnabled; 105 } 106 107 // @since 11.1 108 public void setEnabled(boolean isEnabled) { 109 this.isEnabled = isEnabled; 110 } 111 112 // @since 11.1 113 public String getDefaultScroller() { 114 return defaultScroller; 115 } 116 117 // @since 11.1 118 public String getInputStream() { 119 return defaultIfBlank(inputStream, name); 120 } 121 122}