All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.global.api.builders.RecurringBuilder Maven / Gradle / Ivy

There is a newer version: 14.2.3
Show newest version
package com.global.api.builders;

import com.global.api.ServicesContainer;
import com.global.api.entities.IRecurringEntity;
import com.global.api.entities.enums.TransactionType;
import com.global.api.entities.exceptions.ApiException;
import com.global.api.gateways.IRecurringGateway;

import java.util.EnumSet;
import java.util.HashMap;

public class RecurringBuilder extends TransactionBuilder {
    private String key;
    private String orderId;
    private IRecurringEntity entity;
    private HashMap searchCriteria = new HashMap();
    private Class clazz;
    private boolean forceDelete = false;

    public String getKey() {
        return key;
    }
    public String getOrderId() {
        return orderId;
    }
    public IRecurringEntity getEntity() {
        return entity;
    }
    public void setEntity(IRecurringEntity value) {
        this.entity = value;
    }
    public HashMap getSearchCriteria() {
        return searchCriteria;
    }
    public boolean isForceDelete() {
        return forceDelete;
    }

    public RecurringBuilder addSearchCriteria(String key, String value) {
        searchCriteria.put(key, value);
        return this;
    }
    public RecurringBuilder withKey(String value) {
        this.key = value;
        return this;
    }
    public RecurringBuilder withForceDelete(boolean value) {
        this.forceDelete = value;
        return this;
    }

    public RecurringBuilder(TransactionType type) {
        super(type);
    }
    public RecurringBuilder(TransactionType type, Class clazz) {
        super(type);
        this.clazz = clazz;
    }
    public RecurringBuilder(TransactionType type, IRecurringEntity entity, Class clazz) {
        super(type);

        if(entity != null) {
            this.entity = entity;
            this.key = entity.getKey();
            this.clazz = clazz;
        }
    }

    public TResult execute(String configName) throws ApiException {
        super.execute(configName);

        IRecurringGateway client = ServicesContainer.getInstance().getRecurring(configName);
        return client.processRecurring(this, clazz);
    }

    public void setupValidations() {
        this.validations.of(EnumSet.of(TransactionType.Edit, TransactionType.Delete, TransactionType.Fetch))
                .check("key").isNotNull();
        this.validations.of(TransactionType.Search).check("searchCriteria").isNotNull();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy