securis/src/main/java/net/curisit/securis/db/License.java
.. .. @@ -14,6 +14,8 @@ 14 14 import javax.persistence.Table; 15 15 16 16 import org.codehaus.jackson.annotate.JsonAutoDetect; 17 +import org.codehaus.jackson.annotate.JsonIgnore;18 +import org.codehaus.jackson.annotate.JsonProperty;17 19 import org.codehaus.jackson.map.annotate.JsonSerialize; 18 20 19 21 /** .. .. @@ -36,22 +38,45 @@ 36 38 37 39 private String code; 38 40 39 - @Column(name = "creation_timestamp")40 - private Date creationTimestamp;41 -42 - @ManyToOne43 - @JoinColumn(name = "organization_id")44 - private Organization organization;45 -41 + @JsonIgnore46 42 @ManyToOne 47 43 @JoinColumn(name = "pack_id") 48 44 private Pack pack; 49 45 46 + @JsonIgnore50 47 @ManyToOne 51 48 @JoinColumn(name = "created_by") 52 49 private User createdBy; 53 50 54 - private int numLicenses;51 + @JsonIgnore52 + @ManyToOne53 + @JoinColumn(name = "canceled_by")54 + private User canceledBy;55 +56 + private int status;57 +58 + @JoinColumn(name = "full_name")59 + private String fullName;60 +61 + private String email;62 +63 + @Column(name = "creation_timestamp")64 + private Date creationTimestamp;65 +66 + @Column(name = "modification_timestamp")67 + private Date modificationTimestamp;68 +69 + @Column(name = "activation_timestamp")70 + private Date activationTimestamp;71 +72 + @Column(name = "cancelation_timestamp")73 + private Date cancelationTimestamp;74 +75 + @Column(name = "send_timestamp")76 + private Date sendTimestamp;77 +78 + @Column(name = "last_access_timestamp")79 + private Date lastAccessTimestamp;55 80 56 81 public int getId() { 57 82 return id; .. .. @@ -73,28 +98,12 @@ 73 98 this.creationTimestamp = creationTimestamp; 74 99 } 75 100 76 - public Organization getOrganization() {77 - return organization;78 - }79 -80 - public void setOrganization(Organization organization) {81 - this.organization = organization;82 - }83 -84 101 public User getCreatedBy() { 85 102 return createdBy; 86 103 } 87 104 88 105 public void setCreatedBy(User createdBy) { 89 106 this.createdBy = createdBy; 90 - }91 -92 - public int getNumLicenses() {93 - return numLicenses;94 - }95 -96 - public void setNumLicenses(int numLicenses) {97 - this.numLicenses = numLicenses;98 107 } 99 108 100 109 public Pack getPack() { .. .. @@ -105,4 +114,136 @@ 105 114 this.pack = pack; 106 115 } 107 116 117 + @JsonProperty("created_by_id")118 + public String getCreatedById() {119 + return createdBy == null ? null : createdBy.getUsername();120 + }121 +122 + @JsonProperty("created_by_id")123 + public void setCreatedById(String username) {124 + if (username == null) {125 + createdBy = null;126 + } else {127 + createdBy = new User();128 + createdBy.setUsername(username);129 + }130 + }131 +132 + @JsonProperty("canceled_by_id")133 + public String getCanceledById() {134 + return canceledBy == null ? null : canceledBy.getUsername();135 + }136 +137 + @JsonProperty("canceled_by_id")138 + public void setCanceledById(String username) {139 + if (username == null) {140 + canceledBy = null;141 + } else {142 + canceledBy = new User();143 + canceledBy.setUsername(username);144 + }145 + }146 +147 + @JsonProperty("pack_code")148 + public String getLicenseTypcode() {149 + return pack == null ? null : pack.getCode();150 + }151 +152 + @JsonProperty("pack_id")153 + public Integer getOrgId() {154 + return pack == null ? null : pack.getId();155 + }156 +157 + @JsonProperty("pack_id")158 + public void setOrgId(Integer idPack) {159 + if (idPack == null) {160 + pack = null;161 + } else {162 + pack = new Pack();163 + pack.setId(idPack);164 + }165 + }166 +167 + public int getStatus() {168 + return status;169 + }170 +171 + public void setStatus(int status) {172 + this.status = status;173 + }174 +175 + public Date getModificationTimestamp() {176 + return modificationTimestamp;177 + }178 +179 + public void setModificationTimestamp(Date modificationTimestamp) {180 + this.modificationTimestamp = modificationTimestamp;181 + }182 +183 + public String getFullName() {184 + return fullName;185 + }186 +187 + public void setFullName(String fullName) {188 + this.fullName = fullName;189 + }190 +191 + public String getEmail() {192 + return email;193 + }194 +195 + public void setEmail(String email) {196 + this.email = email;197 + }198 +199 + public Date getActivationTimestamp() {200 + return activationTimestamp;201 + }202 +203 + public void setActivationTimestamp(Date activationTimestamp) {204 + this.activationTimestamp = activationTimestamp;205 + }206 +207 + public Date getSendTimestamp() {208 + return sendTimestamp;209 + }210 +211 + public void setSendTimestamp(Date sendTimestamp) {212 + this.sendTimestamp = sendTimestamp;213 + }214 +215 + public void setId(int id) {216 + this.id = id;217 + }218 +219 + public User getCanceledBy() {220 + return canceledBy;221 + }222 +223 + public void setCanceledBy(User canceledBy) {224 + this.canceledBy = canceledBy;225 + }226 +227 + public Date getCancelationTimestamp() {228 + return cancelationTimestamp;229 + }230 +231 + public void setCancelationTimestamp(Date cancelationTimestamp) {232 + this.cancelationTimestamp = cancelationTimestamp;233 + }234 +235 + public Date getLastAccessTimestamp() {236 + return lastAccessTimestamp;237 + }238 +239 + public void setLastAccessTimestamp(Date lastAccessTimestamp) {240 + this.lastAccessTimestamp = lastAccessTimestamp;241 + }242 +243 + public static class Status {244 + public static final int CREATED = 0;245 + public static final int SENT = 1;246 + public static final int ACTIVE = 2;247 + public static final int CANCELED = 3;248 + }108 249 } securis/src/main/java/net/curisit/securis/db/LicenseType.java
.. .. @@ -14,6 +14,7 @@ 14 14 import javax.persistence.Table; 15 15 16 16 import org.codehaus.jackson.annotate.JsonAutoDetect; 17 +import org.codehaus.jackson.annotate.JsonIgnore;17 18 import org.codehaus.jackson.annotate.JsonIgnoreProperties; 18 19 import org.codehaus.jackson.annotate.JsonProperty; 19 20 import org.codehaus.jackson.map.annotate.JsonSerialize; .. .. @@ -30,7 +31,7 @@ 30 31 @Entity 31 32 @Table(name = "license_type") 32 33 @NamedQueries( 33 - { @NamedQuery(name = "list-license_types", query = "SELECT new map(lt.id as id, lt.code as code, lt.name as name, lt.description as description, lt.creationTimestamp as creationTimestamp, ap.id as application_id, ap.name as application_name) FROM LicenseType lt inner join lt.application ap") })34 + { @NamedQuery(name = "list-license_types", query = "SELECT lt FROM LicenseType lt") })34 35 public class LicenseType implements Serializable { 35 36 36 37 private static final Logger log = LoggerFactory.getLogger(LicenseType.class); .. .. @@ -47,6 +48,7 @@ 47 48 @Column(name = "creation_timestamp") 48 49 private Date creationTimestamp; 49 50 51 + @JsonIgnore50 52 @ManyToOne 51 53 @JoinColumn(name = "application_id") 52 54 private Application application; .. .. @@ -83,6 +85,11 @@ 83 85 return application; 84 86 } 85 87 88 + @JsonProperty("application_name")89 + public String getParentOrgName() {90 + return application == null ? null : application.getName();91 + }92 +86 93 @JsonProperty("application_id") 87 94 public Integer getApplicationId() { 88 95 log.info("application " + application); securis/src/main/java/net/curisit/securis/db/Pack.java
.. .. @@ -17,6 +17,8 @@ 17 17 import javax.persistence.Table; 18 18 19 19 import org.codehaus.jackson.annotate.JsonAutoDetect; 20 +import org.codehaus.jackson.annotate.JsonIgnore;21 +import org.codehaus.jackson.annotate.JsonProperty;20 22 import org.codehaus.jackson.map.annotate.JsonSerialize; 21 23 22 24 /** .. .. @@ -42,25 +44,34 @@ 42 44 @Column(name = "creation_timestamp") 43 45 private Date creationTimestamp; 44 46 47 + @JsonIgnore45 48 @ManyToOne 46 49 @JoinColumn(name = "organization_id") 47 50 private Organization organization; 48 51 52 + @JsonIgnore49 53 @ManyToOne 50 54 @JoinColumn(name = "license_type_id") 51 55 private LicenseType licenseType; 52 56 57 + @JsonIgnore53 58 @ManyToOne 54 59 @JoinColumn(name = "created_by") 55 60 private User createdBy; 56 61 62 + @JsonIgnore57 63 @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "pack") 58 64 private Set<License> licenses; 59 65 66 + @JoinColumn(name = "num_licenses")60 67 private int numLicenses; 61 68 62 69 public int getId() { 63 70 return id; 71 + }72 +73 + public void setId(int id) {74 + this.id = id;64 75 } 65 76 66 77 public String getCode() { .. .. @@ -111,4 +122,92 @@ 111 122 this.numLicenses = numLicenses; 112 123 } 113 124 125 + @JsonProperty("num_activations")126 + public int getNumActivations() {127 + if (licenses == null)128 + return 0;129 + int num = 0;130 + for (License lic : licenses) {131 + if (lic.getStatus() == License.Status.ACTIVE)132 + num++;133 + }134 + return num;135 + }136 +137 + /**138 + * Counts all created licenses, It counts active licenses and licenses waiting for activation This number will be used to control the max number of licenses created. Ignore canceled licenses.139 + *140 + * @return141 + */142 + @JsonProperty("num_creations")143 + public int getNumCreations() {144 + if (licenses == null)145 + return 0;146 + int num = 0;147 + for (License lic : licenses) {148 + if (lic.getStatus() != License.Status.CANCELED)149 + num++;150 + }151 + return num;152 + }153 +154 + /**155 + * Number of available licenses in this pack156 + *157 + * @return158 + */159 + @JsonProperty("num_available")160 + public int getNumAvailables() {161 + return numLicenses - getNumCreations();162 + }163 +164 + @JsonProperty("organization_name")165 + public String getOrgName() {166 + return organization == null ? null : organization.getName();167 + }168 +169 + @JsonProperty("application_name")170 + public String getAppName() {171 + if (licenseType == null)172 + return null;173 + Application app = licenseType.getApplication();174 + return app == null ? null : app.getName();175 + }176 +177 + @JsonProperty("organization_id")178 + public Integer getOrgId() {179 + return organization == null ? null : organization.getId();180 + }181 +182 + @JsonProperty("organization_id")183 + public void setOrgId(Integer idOrg) {184 + if (idOrg == null) {185 + organization = null;186 + } else {187 + organization = new Organization();188 + organization.setId(idOrg);189 + }190 + }191 +192 + @JsonProperty("license_type_id")193 + public Integer getLicTypeId() {194 + return licenseType == null ? null : licenseType.getId();195 + }196 +197 + @JsonProperty("created_by_id")198 + public String getCreatedById() {199 + return createdBy == null ? null : createdBy.getUsername();200 + }201 +202 + @JsonProperty("created_by_id")203 + public void setCreatedById(String username) {204 + createdBy = new User();205 + createdBy.setUsername(username);206 + }207 +208 + @JsonProperty("licensetype_code")209 + public String getLicenseTypcode() {210 + return licenseType == null ? null : licenseType.getCode();211 + }212 +114 213 } securis/src/main/java/net/curisit/securis/services/LicenseTypeResource.java
.. .. @@ -6,7 +6,7 @@ 6 6 import javax.inject.Inject; 7 7 import javax.inject.Provider; 8 8 import javax.persistence.EntityManager; 9 -import javax.persistence.Query;9 +import javax.persistence.TypedQuery;10 10 import javax.servlet.http.HttpServletRequest; 11 11 import javax.ws.rs.Consumes; 12 12 import javax.ws.rs.DELETE; .. .. @@ -64,9 +64,8 @@ 64 64 log.info("Getting license types list "); 65 65 66 66 EntityManager em = emProvider.get(); 67 - Query q = em.createNamedQuery("list-license_types");68 - @SuppressWarnings("unchecked")69 - List<Object> list = q.getResultList();67 + TypedQuery<LicenseType> q = em.createNamedQuery("list-license_types", LicenseType.class);68 + List<LicenseType> list = q.getResultList();70 69 71 70 return Response.ok(list).build(); 72 71 } securis/src/main/java/net/curisit/securis/services/UserResource.java
.. .. @@ -208,7 +208,7 @@ 208 208 209 209 request.getSession().setAttribute("username", user); 210 210 if ("no".equals(password)) 211 - return Response.status(Status.FORBIDDEN).build();211 + return Response.status(Status.UNAUTHORIZED).build();212 212 String tokenAuth = tokenHelper.generateToken(user); 213 213 return Response.ok(Utils.createMap("success", true, "token", tokenAuth)).build(); 214 214 }