| .. | .. |
|---|
| 1 | 1 | package net.curisit.securis.db; |
|---|
| 2 | 2 | |
|---|
| 3 | 3 | import java.io.Serializable; |
|---|
| 4 | +import java.util.Arrays; |
|---|
| 4 | 5 | import java.util.Date; |
|---|
| 5 | 6 | import java.util.List; |
|---|
| 7 | +import java.util.Map; |
|---|
| 6 | 8 | |
|---|
| 7 | 9 | import javax.persistence.Column; |
|---|
| 8 | 10 | import javax.persistence.Entity; |
|---|
| .. | .. |
|---|
| 15 | 17 | import javax.persistence.NamedQuery; |
|---|
| 16 | 18 | import javax.persistence.OneToMany; |
|---|
| 17 | 19 | import javax.persistence.Table; |
|---|
| 20 | + |
|---|
| 21 | +import net.curisit.integrity.commons.Utils; |
|---|
| 18 | 22 | |
|---|
| 19 | 23 | import org.codehaus.jackson.annotate.JsonAutoDetect; |
|---|
| 20 | 24 | import org.codehaus.jackson.annotate.JsonIgnore; |
|---|
| .. | .. |
|---|
| 269 | 273 | this.expirationDate = expirationDate; |
|---|
| 270 | 274 | } |
|---|
| 271 | 275 | |
|---|
| 276 | + public static class Action { |
|---|
| 277 | + public static final int CREATE = 1; |
|---|
| 278 | + public static final int REQUEST = 2; |
|---|
| 279 | + public static final int ACTIVATION = 3; |
|---|
| 280 | + public static final int SEND = 4; |
|---|
| 281 | + public static final int DOWNLOAD = 5; |
|---|
| 282 | + public static final int CANCEL = 6; |
|---|
| 283 | + public static final int DELETE = 7; |
|---|
| 284 | + } |
|---|
| 285 | + |
|---|
| 272 | 286 | public static class Status { |
|---|
| 273 | | - public static final int CREATED = 0; |
|---|
| 274 | | - public static final int SENT = 1; |
|---|
| 275 | | - public static final int ACTIVE = 2; |
|---|
| 276 | | - public static final int CANCELED = 3; |
|---|
| 287 | + public static final int CREATED = 1; |
|---|
| 288 | + public static final int REQUESTED = 2; |
|---|
| 289 | + public static final int PREACTIVE = 3; |
|---|
| 290 | + public static final int ACTIVE = 4; |
|---|
| 291 | + public static final int EXPIRED = 5; |
|---|
| 292 | + public static final int CANCELED = 6; |
|---|
| 293 | + public static final int DELETED = 7; |
|---|
| 294 | + |
|---|
| 295 | + private static final Map<Integer, List<Integer>> transitions = Utils.createMap( // |
|---|
| 296 | + Action.REQUEST, Arrays.asList(CREATED, REQUESTED), // |
|---|
| 297 | + Action.ACTIVATION, Arrays.asList(REQUESTED, PREACTIVE, EXPIRED), // |
|---|
| 298 | + Action.SEND, Arrays.asList(ACTIVE, PREACTIVE), // |
|---|
| 299 | + Action.DOWNLOAD, Arrays.asList(ACTIVE, PREACTIVE), // |
|---|
| 300 | + Action.CANCEL, Arrays.asList(ACTIVE, PREACTIVE, REQUESTED, EXPIRED), // |
|---|
| 301 | + Action.DELETE, Arrays.asList(CANCELED, CREATED) // |
|---|
| 302 | + |
|---|
| 303 | + ); |
|---|
| 304 | + |
|---|
| 305 | + /** |
|---|
| 306 | + * It checks if a given action is valid for the License, passing the action and the current license status |
|---|
| 307 | + * |
|---|
| 308 | + * @param oldStatus |
|---|
| 309 | + * @param newStatus |
|---|
| 310 | + * @return |
|---|
| 311 | + */ |
|---|
| 312 | + public static boolean isActionValid(Integer action, Integer currentStatus) { |
|---|
| 313 | + List<Integer> validStatuses = transitions.get(currentStatus); |
|---|
| 314 | + |
|---|
| 315 | + return validStatuses != null && validStatuses.contains(currentStatus); |
|---|
| 316 | + } |
|---|
| 277 | 317 | } |
|---|
| 278 | 318 | } |
|---|