package com.github.dockerjava.jaxrs;

import java.util.List;

import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.MediaType;

import com.google.common.net.UrlEscapers;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.github.dockerjava.api.command.ListImagesCmd;
import com.github.dockerjava.api.model.Image;

import static com.google.common.net.UrlEscapers.urlPathSegmentEscaper;

public class ListImagesCmdExec extends AbstrDockerCmdExec<ListImagesCmd, List<Image>> implements ListImagesCmd.Exec {

	private static final Logger LOGGER = LoggerFactory.getLogger(ListImagesCmdExec.class);

	public ListImagesCmdExec(WebTarget baseResource) {
		super(baseResource);
	}

	@Override
	protected List<Image> execute(ListImagesCmd command) {
		WebTarget webResource = getBaseResource()
                .path("/images/json")
                .queryParam("filters", urlPathSegmentEscaper().escape(command.getFilters()))
                .queryParam("all", command.hasShowAllEnabled() ? "1" : "0");

		LOGGER.trace("GET: {}", webResource);

		List<Image> images = webResource.request()
				.accept(MediaType.APPLICATION_JSON)
				.get(new GenericType<List<Image>>() {
				});
		LOGGER.trace("Response: {}", images);

		return images;
	}

}

@@ -478,17 +478,19 @@
  extends
- 
+%0A%09%09
 AbstrDoc
@@ -538,17 +538,19 @@
 plements
- 
+%0A%09%09
 ListImag
@@ -614,16 +614,20 @@
 rFactory
+%0A%09%09%09
 .getLogg
@@ -845,33 +845,16 @@
 source()
-%0A                
 .path(%22/
@@ -867,32 +867,146 @@
 /json%22)%0A
-                
+%09%09%09%09.queryParam(%22all%22, command.hasShowAllEnabled() ? %221%22 : %220%22);%0A%0A%09%09if (command.getFilters() != null)%0A%09%09%09webResource = webResource
 .queryPa
@@ -1019,17 +1019,22 @@
 ilters%22,
- 
+%0A%09%09%09%09%09
 urlPathS
@@ -1082,84 +1082,8 @@
 ()))
-%0A                .queryParam(%22all%22, command.hasShowAllEnabled() ? %221%22 : %220%22)
 ;%0A%0A%09

send 'filters' parameter only if needed