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

org.pipservices3.rpc.services.RestQueryParams Maven / Gradle / Ivy

The newest version!
package org.pipservices3.rpc.services;

import org.glassfish.jersey.internal.util.collection.MultivaluedStringMap;
import org.pipservices3.commons.convert.StringConverter;
import org.pipservices3.commons.data.FilterParams;
import org.pipservices3.commons.data.PagingParams;

import java.util.Map;

//import com.sun.jersey.core.util.*;

public class RestQueryParams extends MultivaluedStringMap {
	private static final long serialVersionUID = -903917330561942092L;

	public RestQueryParams() {
	}

	public RestQueryParams(String correlationId) {
		addCorrelationId(correlationId);
	}

	public RestQueryParams(String correlationId, FilterParams filter, PagingParams paging) {
		addCorrelationId(correlationId);
		addFilterParams(filter);
		addPagingParams(paging);
	}

	public void addCorrelationId(String correlationId) {
		if (correlationId == null)
			return;
		add("correlation_id", correlationId);
	}

	public void addFilterParams(FilterParams filter) {
		if (filter == null)
			return;

		for (Map.Entry entry : filter.entrySet()) {
			String value = entry.getValue();
			if (value != null)
				add(entry.getKey(), value);
		}
	}

	public void addPagingParams(PagingParams paging) {
		if (paging == null)
			return;

		if (paging.getSkip() != null)
			add("skip", StringConverter.toString(paging.getSkip()));
		if (paging.getTake() != null)
			add("take", StringConverter.toString(paging.getTake()));
		add("total", StringConverter.toString(paging.hasTotal()));
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy