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 org.nuxeo.common.xmap.annotation.XNode;
023import org.nuxeo.common.xmap.annotation.XObject;
024import org.nuxeo.ecm.core.api.NuxeoException;
025import org.nuxeo.runtime.model.Descriptor;
026
027/**
028 * @since 10.2
029 */
030@XObject("action")
031public class BulkActionDescriptor implements Descriptor {
032
033    public static final Integer DEFAULT_BUCKET_SIZE = 100;
034
035    public static final Integer DEFAULT_BATCH_SIZE = 25;
036
037    @XNode("@name")
038    public String name;
039
040    @XNode("@bucketSize")
041    public Integer bucketSize = DEFAULT_BUCKET_SIZE;
042
043    @XNode("@batchSize")
044    public Integer batchSize = DEFAULT_BATCH_SIZE;
045
046    @XNode("@httpEnabled")
047    public Boolean httpEnabled = Boolean.FALSE;
048
049    @XNode("@sequentialCommands")
050    public Boolean sequentialCommands = Boolean.FALSE;
051
052    @XNode("@validationClass")
053    public Class<? extends BulkActionValidation> validationClass;
054
055    @Override
056    public String getId() {
057        return name;
058    }
059
060    public Integer getBucketSize() {
061        return bucketSize;
062    }
063
064    public Integer getBatchSize() {
065        return batchSize;
066    }
067
068    /**
069     * @since 10.10
070     */
071    public BulkActionValidation newValidationInstance() {
072        try {
073            return validationClass.getDeclaredConstructor().newInstance();
074        } catch (ReflectiveOperationException e) {
075            throw new NuxeoException("Cannot create validation class of type " + validationClass.getName(), e);
076        }
077    }
078}