1 package com.srv4pos.server.api.kdfacet;
2
3 import com.srv4pos.server.api.infrastructure.EmptyConnectionWriter;
4 import com.srv4pos.server.api.infrastructure.HttpMethod;
5 import com.srv4pos.server.api.infrastructure.credentials.Credentials;
6 import com.srv4pos.server.api.infrastructure.exceptions.enums.InconsistentDataErrorType;
7 import com.srv4pos.server.api.infrastructure.http.HttpHelper;
8 import com.srv4pos.server.api.infrastructure.http.Transport;
9 import com.srv4pos.server.api.infrastructure.request.StringResponse;
10
11 import java.net.URL;
12 import java.util.HashMap;
13 import java.util.List;
14
15 import static com.srv4pos.server.api.infrastructure.request.RequestHelper.requestString;
16
17 public class KdFacetService {
18 private URL url;
19 private Credentials credentials;
20 private Transport transport;
21
22 public KdFacetService(URL url, Credentials credentials, Transport transport) {
23 this.url = url;
24 this.credentials = credentials;
25 this.transport = transport;
26 }
27
28 public List<KdFacetInfo> list(
29 Integer firstResult,
30 Integer maxResults,
31 String serial,
32 String sellerId,
33 String cashRegisterName,
34 Long softwareVendorId) {
35 return list(firstResult, maxResults, serial, sellerId, cashRegisterName, softwareVendorId, null, null);
36 }
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54 public List<KdFacetInfo> list(
55 Integer firstResult,
56 Integer maxResults,
57 String serial,
58 String sellerId,
59 String cashRegisterName,
60 Long softwareVendorId,
61 KdFacetInfo.Fields orderBy,
62 Boolean orderDesc) {
63 HashMap<String, String> params = new HashMap<String, String>();
64 if (firstResult != null) {
65 params.put("firstResult", Integer.toString(firstResult));
66 }
67 if (maxResults != null) {
68 params.put("maxResults", Integer.toString(maxResults));
69 }
70 if (serial != null) {
71 params.put("controlUnit", serial);
72 }
73 if (sellerId != null) {
74 params.put("seller", sellerId);
75 }
76 if (cashRegisterName != null) {
77 params.put("cashRegisterName", cashRegisterName);
78 }
79 if (softwareVendorId != null) {
80 params.put("softwareVendor", Long.toString(softwareVendorId));
81 }
82 if (orderBy != null) {
83 params.put("orderBy", orderBy.name());
84 }
85 if (orderDesc != null) {
86 params.put("orderDesc", orderDesc.toString());
87 }
88
89 StringResponse response = requestString(
90 "kd-facets",
91 HttpMethod.GET,
92 url,
93 credentials.toAuthentication(),
94 null,
95 params,
96 EmptyConnectionWriter.EMPTY_CONNECTION_WRITER,
97 HttpHelper.CONTENT_TYPE_APPLICATION_JSON,
98 transport
99 );
100 return response == null ? null : (List<KdFacetInfo>) KdFacetInfo.fromJsonArrayToKdFacetInfoes(response.getContent());
101 }
102 }