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