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

io.github11904212.java.stac.client.search.dto.QueryParamFields Maven / Gradle / Ivy

There is a newer version: 1.0.0-alpha.0.7
Show newest version
package io.github11904212.java.stac.client.search.dto;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * this class is a POJO containing the fields parameter of an STAC search.
 * see https://api.stacspec.org/v1.0.0-rc.1/item-search/#operation/getItemSearch
 * for detailed information.
 */
@JsonInclude(JsonInclude.Include.NON_NULL)
public class QueryParamFields {

    private List include = new ArrayList<>();
    private List exclude = new ArrayList<>();


    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    public List getInclude() {
        return include;
    }

    public void setInclude(List include) {
        this.include = include;
    }

    public void addFieldToInclude(String field) {
        this.include.add(field);
    }

    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    public List getExclude() {
        return exclude;
    }

    public void setExclude(List exclude) {
        this.exclude = exclude;
    }

    public void addFieldToExclude(String field) {
        this.exclude.add(field);
    }

    @JsonIgnore
    String toUrlQuery() {
        var excludeSigned = this.exclude.stream().map(
                entry -> entry.startsWith("-") ? entry : "-" + entry
        ).collect(Collectors.toList());
        return "fields=" + String.join(",", include) + "," + String.join(",", excludeSigned);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy