| .. | .. |
|---|
| 8 | 8 | |
|---|
| 9 | 9 | import javax.persistence.Column; |
|---|
| 10 | 10 | import javax.persistence.Entity; |
|---|
| 11 | +import javax.persistence.EntityManager; |
|---|
| 11 | 12 | import javax.persistence.FetchType; |
|---|
| 12 | 13 | import javax.persistence.GeneratedValue; |
|---|
| 13 | 14 | import javax.persistence.Id; |
|---|
| .. | .. |
|---|
| 17 | 18 | import javax.persistence.NamedQuery; |
|---|
| 18 | 19 | import javax.persistence.OneToMany; |
|---|
| 19 | 20 | import javax.persistence.Table; |
|---|
| 21 | +import javax.persistence.TypedQuery; |
|---|
| 20 | 22 | |
|---|
| 21 | 23 | import net.curisit.integrity.commons.Utils; |
|---|
| 22 | 24 | |
|---|
| 23 | | -import org.codehaus.jackson.annotate.JsonAutoDetect; |
|---|
| 24 | | -import org.codehaus.jackson.annotate.JsonIgnore; |
|---|
| 25 | | -import org.codehaus.jackson.annotate.JsonIgnoreProperties; |
|---|
| 26 | | -import org.codehaus.jackson.annotate.JsonProperty; |
|---|
| 27 | | -import org.codehaus.jackson.map.annotate.JsonSerialize; |
|---|
| 25 | +import com.fasterxml.jackson.annotation.JsonAutoDetect; |
|---|
| 26 | +import com.fasterxml.jackson.annotation.JsonIgnore; |
|---|
| 27 | +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
|---|
| 28 | +import com.fasterxml.jackson.annotation.JsonProperty; |
|---|
| 29 | +import com.fasterxml.jackson.databind.annotation.JsonSerialize; |
|---|
| 28 | 30 | |
|---|
| 29 | 31 | /** |
|---|
| 30 | 32 | * Entity implementation class for Entity: license |
|---|
| .. | .. |
|---|
| 36 | 38 | @Table(name = "license") |
|---|
| 37 | 39 | @JsonIgnoreProperties(ignoreUnknown = true) |
|---|
| 38 | 40 | @NamedQueries({ |
|---|
| 39 | | - @NamedQuery(name = "list-licenses-by-pack", query = "SELECT l FROM License l where l.pack.id = :packId") |
|---|
| 41 | + @NamedQuery(name = "list-licenses-by-pack", query = "SELECT l FROM License l where l.pack.id = :packId"), |
|---|
| 42 | + @NamedQuery(name = "list-active-licenses-by-req-data", query = "SELECT l FROM License l where l.reqDataHash = :hash and l.status in ('AC', 'PA')") |
|---|
| 40 | 43 | }) |
|---|
| 41 | 44 | public class License implements Serializable { |
|---|
| 42 | 45 | |
|---|
| .. | .. |
|---|
| 74 | 77 | @Column(name = "request_data") |
|---|
| 75 | 78 | @JsonProperty("request_data") |
|---|
| 76 | 79 | private String requestData; |
|---|
| 80 | + |
|---|
| 81 | + @Column(name = "request_data_hash") |
|---|
| 82 | + @JsonIgnore |
|---|
| 83 | + private String reqDataHash; |
|---|
| 77 | 84 | |
|---|
| 78 | 85 | @Column(name = "license_data") |
|---|
| 79 | 86 | @JsonProperty("license_data") |
|---|
| .. | .. |
|---|
| 286 | 293 | public static final int DOWNLOAD = 5; |
|---|
| 287 | 294 | public static final int CANCEL = 6; |
|---|
| 288 | 295 | public static final int DELETE = 7; |
|---|
| 296 | + public static final int BLOCK = 8; |
|---|
| 289 | 297 | } |
|---|
| 290 | 298 | |
|---|
| 291 | 299 | public static class Status { |
|---|
| .. | .. |
|---|
| 296 | 304 | Action.SEND, Arrays.asList(LicenseStatus.ACTIVE, LicenseStatus.PRE_ACTIVE), // |
|---|
| 297 | 305 | Action.DOWNLOAD, Arrays.asList(LicenseStatus.ACTIVE, LicenseStatus.PRE_ACTIVE), // |
|---|
| 298 | 306 | Action.CANCEL, Arrays.asList(LicenseStatus.ACTIVE, LicenseStatus.PRE_ACTIVE, LicenseStatus.REQUESTED, LicenseStatus.EXPIRED), // |
|---|
| 299 | | - Action.DELETE, Arrays.asList(LicenseStatus.CANCELLED, LicenseStatus.CREATED) // |
|---|
| 300 | | - |
|---|
| 307 | + Action.DELETE, Arrays.asList(LicenseStatus.CANCELLED, LicenseStatus.CREATED), // |
|---|
| 308 | + Action.BLOCK, Arrays.asList(LicenseStatus.CANCELLED) // |
|---|
| 301 | 309 | ); |
|---|
| 302 | 310 | |
|---|
| 303 | 311 | /** |
|---|
| .. | .. |
|---|
| 314 | 322 | return validStatuses != null && validStatuses.contains(currentStatus); |
|---|
| 315 | 323 | } |
|---|
| 316 | 324 | } |
|---|
| 325 | + |
|---|
| 326 | + public License findLicenseByRequestData(String requestData, EntityManager em) { |
|---|
| 327 | + TypedQuery<License> query = em.createNamedQuery("list-active-licenses-by-req-data", License.class); |
|---|
| 328 | + query.setParameter("hash", BlockedRequest.generateHash(requestData)); |
|---|
| 329 | + return null; |
|---|
| 330 | + } |
|---|
| 331 | + |
|---|
| 332 | + public String getReqDataHash() { |
|---|
| 333 | + return reqDataHash; |
|---|
| 334 | + } |
|---|
| 335 | + |
|---|
| 336 | + public void setReqDataHash(String reqDataHash) { |
|---|
| 337 | + this.reqDataHash = reqDataHash; |
|---|
| 338 | + } |
|---|
| 317 | 339 | } |
|---|