View Javadoc
1   package com.srv4pos.server.api.posplus;
2   
3   import com.srv4pos.server.api.infrastructure.HttpMethod;
4   import com.srv4pos.server.api.infrastructure.StringConnectionWriter;
5   import com.srv4pos.server.api.infrastructure.exceptions.enums.InconsistentDataErrorType;
6   import com.srv4pos.server.api.infrastructure.credentials.Credentials;
7   import com.srv4pos.server.api.infrastructure.http.HttpHelper;
8   import com.srv4pos.server.api.infrastructure.http.Transport;
9   
10  import java.net.URL;
11  
12  import static com.srv4pos.server.api.infrastructure.request.RequestHelper.requestString;
13  import static com.srv4pos.server.api.infrastructure.request.RequestHelper.requestVoid;
14  import static java.lang.String.format;
15  
16  /**
17   * For sending data to remote control unit.
18   * <p>User: Kirill, Date: 08.03.14 17:12</p>
19   */
20  public class PosPlusService {
21      private URL url;
22      private Credentials credentials;
23      private Transport transport;
24  
25      /**
26       * Constructs the service.
27       *
28       * @param url         of the server
29       * @param credentials to work with the server
30       * @param transport   to know the method to reach the server
31       */
32      public PosPlusService(URL url, Credentials credentials, Transport transport) {
33          this.url = url;
34          this.credentials = credentials;
35          this.transport = transport;
36      }
37  
38  /*
39      public Collection<PosPlusInfo> posPluses() {
40          return PosPlusInfo.fromJsonArrayToPosPlusInfoes(
41                  request(
42                          "pospluses",
43                          HttpMethod.GET,
44                          url,
45                          credentials,
46                          null,
47                          null,
48                          EmptyConnectionWriter.EMPTY_CONNECTION_WRITER,
49                          ServiceHelper.CONTENT_TYPE_APPLICATION_JSON,
50                          transport).toText());
51      }
52  
53      public PosPlusInfo updateAndGetPosPlusInfo(String id) {
54          return PosPlusInfo.fromJsonToPosPlusInfo(
55                  request(
56                          String.format("posplus/%s", id),
57                          HttpMethod.GET,
58                          url,
59                          credentials,
60                          null,
61                          null,
62                          EmptyConnectionWriter.EMPTY_CONNECTION_WRITER,
63                          ServiceHelper.CONTENT_TYPE_APPLICATION_JSON,
64                          transport).toText());
65      }
66  */
67  
68      /**
69       * Creates new entity.
70       *
71       * @param controlUnitEndpointInfo contains information about new control unit endpoint
72       */
73      public void create(ControlUnitEndpointInfo controlUnitEndpointInfo) {
74          requestVoid("control-unit-endpoints",
75                  HttpMethod.POST,
76                  url,
77                  credentials.toAuthentication(),
78                  null,
79                  null,
80                  new StringConnectionWriter(controlUnitEndpointInfo.toJson()),
81                  HttpHelper.CONTENT_TYPE_APPLICATION_JSON,
82                  transport);
83      }
84  }