-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extension changing of subscription to invalid by 3 months
- Loading branch information
Showing
5 changed files
with
162 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
...repo-common/src/main/java/com/evolveum/midpoint/repo/common/util/SubscriptionWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package com.evolveum.midpoint.repo.common.util; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.Arrays; | ||
import java.util.Map; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Wrapper for subscription. Contains information about type and validity. | ||
*/ | ||
public class SubscriptionWrapper { | ||
|
||
private final SubscriptionType type; | ||
private final SubscriptionValidity validity; | ||
|
||
SubscriptionWrapper(SubscriptionType type, SubscriptionValidity validity) { | ||
this.type = type; | ||
this.validity = resolveValidity(type, validity); | ||
} | ||
|
||
private SubscriptionValidity resolveValidity(SubscriptionType type, SubscriptionValidity originalValidity) { | ||
if (type == SubscriptionType.DEMO_SUBSCRIPTION | ||
&& (originalValidity == SubscriptionValidity.INVALID_FIRST_MONTH | ||
|| originalValidity == SubscriptionValidity.INVALID_SECOND_MONTH | ||
|| originalValidity == SubscriptionValidity.INVALID_THIRD_MONTH)) { | ||
return SubscriptionValidity.INVALID; | ||
} | ||
return originalValidity; | ||
} | ||
|
||
SubscriptionWrapper(SubscriptionValidity subscriptionValidity) { | ||
this(null, subscriptionValidity); | ||
} | ||
|
||
public boolean isCorrect() { | ||
if (type != null && (validity == SubscriptionValidity.VALID | ||
|| validity == SubscriptionValidity.INVALID_FIRST_MONTH | ||
|| validity == SubscriptionValidity.INVALID_SECOND_MONTH | ||
|| validity == SubscriptionValidity.INVALID_THIRD_MONTH)) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
public SubscriptionType getType() { | ||
return type; | ||
} | ||
|
||
public SubscriptionValidity getValidity() { | ||
return validity; | ||
} | ||
|
||
/** | ||
* Enumeration for the type of subscription. | ||
*/ | ||
public enum SubscriptionType { | ||
|
||
ANNUAL_SUBSCRIPTION("01"), | ||
PLATFORM_SUBSCRIPTION("02"), | ||
DEPLOYMENT_SUBSCRIPTION("03"), | ||
DEVELOPMENT_SUBSCRIPTION("04"), | ||
DEMO_SUBSCRIPTION("05"); | ||
|
||
private final String subscriptionType; | ||
|
||
SubscriptionType(String subscriptionType) { | ||
this.subscriptionType = subscriptionType; | ||
} | ||
|
||
// public boolean isCorrect() { | ||
// return subscriptionType != null; | ||
// } | ||
|
||
private static final Map<String, SubscriptionType> CODE_TO_TYPE; | ||
|
||
static { | ||
CODE_TO_TYPE = Arrays.stream(values()) | ||
.filter(v -> v.subscriptionType != null) | ||
.collect(Collectors.toUnmodifiableMap(v -> v.subscriptionType, Function.identity())); | ||
} | ||
|
||
@Nullable | ||
public static SubscriptionType resolveType(String code) { | ||
return CODE_TO_TYPE.get(code); | ||
} | ||
} | ||
|
||
/** | ||
* Enumeration for the validity of subscription. | ||
*/ | ||
public enum SubscriptionValidity { | ||
NONE, | ||
INVALID, | ||
INVALID_FIRST_MONTH, | ||
INVALID_SECOND_MONTH, | ||
INVALID_THIRD_MONTH, | ||
VALID | ||
} | ||
} |