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

com.braintreegateway.SearchRequest Maven / Gradle / Ivy

There is a newer version: 3.32.0_1
Show newest version
package com.braintreegateway;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SearchRequest extends Request {
    private Map> criteria;
    private Map> rangeCriteria;
    private Map multiValueCriteria;
    private Map keyValueCriteria;
    
    public SearchRequest() {
        this.criteria = new HashMap>();
        this.rangeCriteria = new HashMap>();
        this.multiValueCriteria = new HashMap();
        this.keyValueCriteria = new HashMap();
    }
    
    public void addCriteria(String nodeName, SearchCriteria searchCriteria) {
        if (!criteria.containsKey(nodeName)) {
            criteria.put(nodeName, new ArrayList());
        }
        criteria.get(nodeName).add(searchCriteria);
    }
    
    public void addRangeCriteria(String nodeName, SearchCriteria searchCriteria) {
        if (!rangeCriteria.containsKey(nodeName)) {
            rangeCriteria.put(nodeName, new ArrayList());
        }
        rangeCriteria.get(nodeName).add(searchCriteria);
    }
    
    public void addMultipleValueCriteria(String nodeName, SearchCriteria searchCriteria) {
        multiValueCriteria.put(nodeName, searchCriteria);
    }
    
    public void addKeyValueCriteria(String nodeName, String value) {
        keyValueCriteria.put(nodeName, value);
    }
    
    @Override
    public String toQueryString(String parent) {
        return null;
    }
    
    @Override
    public String toQueryString() {
        return null;
    }
    
    @Override
    public String toXML() {
        StringBuilder builder = new StringBuilder();
        builder.append("");

        for (String key : criteria.keySet()) {
            builder.append(String.format("<%s>", RequestBuilder.xmlEscape(key)));
            for (SearchCriteria criterium : criteria.get(key)) {
                builder.append(criterium.toXML());
            }
            builder.append(String.format("", RequestBuilder.xmlEscape(key)));
        }
        for (String key : rangeCriteria.keySet()) {
            builder.append(String.format("<%s>", RequestBuilder.xmlEscape(key)));
            for (SearchCriteria criterium : rangeCriteria.get(key)) {
                builder.append(criterium.toXML());
            }
            builder.append(String.format("", RequestBuilder.xmlEscape(key)));
        }
        for (String key : multiValueCriteria.keySet()) {
            builder.append(RequestBuilder.wrapInXMLTag(key, multiValueCriteria.get(key).toXML(), "array"));
        }
        for (String key : keyValueCriteria.keySet()) {
            builder.append(RequestBuilder.wrapInXMLTag(key, keyValueCriteria.get(key)));
        }
        builder.append("");
        return builder.toString();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy