| .. | .. |
|---|
| 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; |
|---|
| 6 | +import java.util.List; |
|---|
| 7 | +import java.util.Map; |
|---|
| 5 | 8 | import java.util.Set; |
|---|
| 6 | 9 | |
|---|
| 7 | 10 | import javax.persistence.CascadeType; |
|---|
| .. | .. |
|---|
| 16 | 19 | import javax.persistence.NamedQuery; |
|---|
| 17 | 20 | import javax.persistence.OneToMany; |
|---|
| 18 | 21 | import javax.persistence.Table; |
|---|
| 22 | + |
|---|
| 23 | +import net.curisit.integrity.commons.Utils; |
|---|
| 19 | 24 | |
|---|
| 20 | 25 | import com.fasterxml.jackson.annotation.JsonAutoDetect; |
|---|
| 21 | 26 | import com.fasterxml.jackson.annotation.JsonIgnore; |
|---|
| .. | .. |
|---|
| 321 | 326 | |
|---|
| 322 | 327 | return (id == null ? 0 : id.hashCode()); |
|---|
| 323 | 328 | } |
|---|
| 329 | + |
|---|
| 330 | + public static class Action { |
|---|
| 331 | + public static final int CREATE = 1; |
|---|
| 332 | + public static final int ACTIVATION = 2; |
|---|
| 333 | + public static final int PUT_ONHOLD = 3; |
|---|
| 334 | + public static final int CANCEL = 4; |
|---|
| 335 | + public static final int DELETE = 5; |
|---|
| 336 | + } |
|---|
| 337 | + |
|---|
| 338 | + public static class Status { |
|---|
| 339 | + |
|---|
| 340 | + private static final Map<Integer, List<Integer>> transitions = Utils.createMap( // |
|---|
| 341 | + Action.ACTIVATION, Arrays.asList(PackStatus.CREATED, PackStatus.ON_HOLD, PackStatus.EXPIRED), // |
|---|
| 342 | + Action.PUT_ONHOLD, Arrays.asList(PackStatus.ACTIVE), // |
|---|
| 343 | + Action.CANCEL, Arrays.asList(PackStatus.ACTIVE, PackStatus.ON_HOLD, PackStatus.EXPIRED), // |
|---|
| 344 | + Action.DELETE, Arrays.asList(PackStatus.CANCELLED, PackStatus.CREATED) // |
|---|
| 345 | + ); |
|---|
| 346 | + |
|---|
| 347 | + /** |
|---|
| 348 | + * It checks if a given action is valid for the License, passing the |
|---|
| 349 | + * action and the current license status |
|---|
| 350 | + * |
|---|
| 351 | + * @param oldStatus |
|---|
| 352 | + * @param newStatus |
|---|
| 353 | + * @return |
|---|
| 354 | + */ |
|---|
| 355 | + public static boolean isActionValid(Integer action, PackStatus currentStatus) { |
|---|
| 356 | + List<Integer> validStatuses = transitions.get(currentStatus); |
|---|
| 357 | + |
|---|
| 358 | + return validStatuses != null && validStatuses.contains(currentStatus); |
|---|
| 359 | + } |
|---|
| 360 | + } |
|---|
| 324 | 361 | } |
|---|