View Javadoc
1   package com.srv4pos.server.api.softwareVendor;
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.http.HttpHelper;
7   import com.srv4pos.server.api.infrastructure.http.Transport;
8   import com.srv4pos.server.api.infrastructure.request.StringResponse;
9   
10  import java.net.URL;
11  import java.util.List;
12  
13  import static com.srv4pos.server.api.infrastructure.request.RequestHelper.requestString;
14  import static java.lang.String.format;
15  
16  /**
17   * This service is responsible for infos of software vendors.
18   * <p>User: Kirill, Date: 01.10.13 11:21</p>.
19   */
20  public class SoftwareVendorService {
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 SoftwareVendorService(URL url, Credentials credentials, Transport transport) {
33          this.url = url;
34          this.credentials = credentials;
35          this.transport = transport;
36      }
37  
38      /**
39       * Returns an entity.
40       *
41       * @param id identifies entity
42       * @return the entity
43       * @throws com.srv4pos.server.api.exceptions.ReferenceNotFoundJsonException if entity is not found
44       */
45      public SoftwareVendorInfo get(long id) {
46          return SoftwareVendorInfo.fromJsonToSoftwareVendorInfo(requestString(
47                  format("software-vendors/%s", id),
48                  HttpMethod.GET,
49                  url,
50                  credentials.toAuthentication(),
51                  null,
52                  null,
53                  EmptyConnectionWriter.EMPTY_CONNECTION_WRITER,
54                  HttpHelper.CONTENT_TYPE_APPLICATION_JSON,
55                  transport).getContent());
56      }
57  
58      /**
59       * Returns list of entities.
60       *
61       * @return list of entities
62       */
63      public List<SoftwareVendorInfo> list() {
64  
65          StringResponse response = requestString(
66                  "software-vendors",
67                  HttpMethod.GET,
68                  url,
69                  credentials.toAuthentication(),
70                  null,
71                  null,
72                  EmptyConnectionWriter.EMPTY_CONNECTION_WRITER,
73                  HttpHelper.CONTENT_TYPE_APPLICATION_JSON,
74                  transport);
75  
76          return (List<SoftwareVendorInfo>) SoftwareVendorInfo.fromJsonArrayToSoftwareVendorInfoes(response.getContent());
77      }
78  }