Roberto Sánchez
2013-12-17 9dee3b104cccba41cab0f4369bec444485da7014
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package net.curisit.securis.services;
import java.net.URI;
import java.text.MessageFormat;
import javax.inject.Inject;
import javax.inject.Named;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import net.curisit.integrity.beans.ServerConfigVersions;
import net.curisit.integrity.beans.ServiceResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
// The Java class will be hosted at the URI path "/myresource"
@Path("/license")
public class LicenseServices {
   // private LicenseHelper licenseHelper = InjectorFactory.getInjector().getInstance(LicenseHelper.class);
   private static final Logger log = LoggerFactory.getLogger(LicenseServices.class);
   private static final int DEFAULT_LICENSE_EXPIRATION = 3650; // 10 years;
   private static final String LICENSE_STRING = "CurisIntegrity Config Server v{0}.{1}";
   @Inject
   @Named("base-uri")
   private URI uri;
   @Inject
   public LicenseServices() {
   }
   /**
    * 
    * @return the server version in format majorVersion.minorVersion
    */
   @GET
   @Path("/")
   @Produces(
       { MediaType.TEXT_PLAIN })
   public Response currentVersion() {
       return Response.ok().entity(MessageFormat.format(LICENSE_STRING, 0, 1)).build();
   }
   @GET
   @Path("/dummy")
   @Produces(
       { MediaType.TEXT_PLAIN })
   public Response dummy() {
       return Response.ok().entity(uri.toString()).build();
   }
   /**
    * @return the version of the three entities that can be synchronized (Users, DataSet and Settings)
    */
   @GET
   @Path("/current/{license}")
   @Produces(
       { MediaType.APPLICATION_JSON })
   public ServiceResponse<ServerConfigVersions> status(@PathParam("license") String license, @DefaultValue("-1") @QueryParam("minorVersion") int minorVersion, @DefaultValue("-1") @QueryParam("majorVersion") int majorVersion) {
       log.info("Called 'current' service with license: {}", license);
       ServiceResponse<ServerConfigVersions> response = new ServiceResponse<ServerConfigVersions>();
       return response;
   }
   //
   // private <T> ServiceResponse<T> buildErrorResponse(ServiceResponse<T> response, String msgErrorCode) {
   // response.setSuccess(false);
   // response.setErrorMessage(localManager.getString(msgErrorCode));
   // response.setErrorMessageCode(msgErrorCode);
   // return response;
   // }
   //
   // private Date calculateCaducation() {
   // Integer licenseExpiration = systemParams.getParamAsInt(SystemParams.Keys.CONFIG_SERVER_LICENSE_EXPIRATION);
   // if (licenseExpiration == null)
   // licenseExpiration = DEFAULT_LICENSE_EXPIRATION;
   // return Utils.addDays(new Date(), licenseExpiration);
   // }
   //
   // private boolean validateLicense(String license) {
   // BasicApplication ba = basicApplicationDao.findByLicense(license);
   // return (ba != null);
   // }
   //
   // private boolean validateVersion(int minorVersion, int majorVersion) {
   // return (versionManager.getMajorVersion() == majorVersion);
   // }
   //
   // private BasicApplication findBasicApp(String license) {
   // BasicApplication ba = basicApplicationDao.findByLicense(license);
   // return ba;
   // }
   //
   // private License generateLicense() {
   // // TODO complete all field of the license
   // License license = new License();
   // license.setCustomerCode(systemParams.getParam(SystemParams.Keys.CONFIG_COMMON_CUSTOMER_CODE));
   // license.setCSCode(systemParams.getParam(SystemParams.Keys.CONFIG_COMMON_CS_CODE));
   // license.setCRCLogo("00000000");
   // license.setExpirationDate(calculateCaducation());
   // license.setInstallCode(codeGenerator.generateInstalationNumber());
   // return license;
   // }
}