Skip to content

Commit

Permalink
subscription id improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Mar 17, 2017
1 parent e29c891 commit e289cf3
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 21 deletions.
Expand Up @@ -132,7 +132,8 @@
<div class="pull-right hidden-xs" wicket:id="version">
<b><wicket:message key="PageTemplate.version"/></b> <wicket:message key="pageBase.midPointVersion"/>
</div>
<div wicket:id="subscriptionMessage"/>
<div wicket:id="subscriptionMessage" class="pull-left"/>
<wicket:message key="PageTemplate.copy" class="pull-right"/>
</footer>
</div>

Expand Down
Expand Up @@ -25,6 +25,7 @@

import com.evolveum.midpoint.audit.api.AuditService;
import com.evolveum.midpoint.common.SystemConfigurationHolder;
import com.evolveum.midpoint.gui.api.SubscriptionType;
import com.evolveum.midpoint.model.api.*;
import com.evolveum.midpoint.web.component.menu.*;
import com.evolveum.midpoint.web.page.admin.configuration.*;
Expand Down Expand Up @@ -713,7 +714,22 @@ public boolean isVisible() {
});
add(version);

Label subscriptionMessage = new Label(ID_SUBSCRIPTION_MESSAGE, createStringResource("PageBase.subscriptionMessage"));
Label subscriptionMessage = new Label(ID_SUBSCRIPTION_MESSAGE,
new AbstractReadOnlyModel<String>() {
private static final long serialVersionUID = 1L;

@Override
public String getObject() {
String subscriptionId = getSubscriptionId();
if (!WebComponentUtil.isSubscriptionIdCorrect(subscriptionId)){
return createStringResource("PageBase.nonActiveSubscriptionMessage").getString() + " ";
}
if (SubscriptionType.DEMO_SUBSRIPTION.getSubscriptionType().equals(subscriptionId.substring(0, 2))){
return createStringResource("PageBase.demoSubscriptionMessage").getString() + " ";
}
return "";
}
});
subscriptionMessage.setOutputMarkupId(true);
subscriptionMessage.add(new VisibleEnableBehaviour() {
private static final long serialVersionUID = 1L;
Expand All @@ -724,7 +740,9 @@ public boolean isVisible() {
if (StringUtils.isEmpty(subscriptionId)){
return true;
}
return !WebComponentUtil.checkSubscriptionId(subscriptionId);
return !WebComponentUtil.isSubscriptionIdCorrect(subscriptionId) ||
(SubscriptionType.DEMO_SUBSRIPTION.getSubscriptionType().equals(subscriptionId.substring(0, 2))
&& WebComponentUtil.isSubscriptionIdCorrect(subscriptionId));
}
});
add(subscriptionMessage);
Expand Down
Expand Up @@ -25,15 +25,7 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;

import javax.xml.datatype.DatatypeConfigurationException;
Expand Down Expand Up @@ -1853,14 +1845,14 @@ public static Integer getIntegerParameter(PageParameters params, String key) {
return value.toInteger();
}

public static boolean checkSubscriptionId(String subscriptionId){
public static boolean isSubscriptionIdCorrect(String subscriptionId){
if (StringUtils.isEmpty(subscriptionId)) {
return false;
}
if (!NumberUtils.isDigits(subscriptionId)){
return false;
}
if (subscriptionId.length() < 15){
if (subscriptionId.length() < 11){
return false;
}
String subscriptionType = subscriptionId.substring(0, 2);
Expand All @@ -1874,15 +1866,27 @@ public static boolean checkSubscriptionId(String subscriptionId){
if (!isTypeCorrect){
return false;
}
String expDateStr = subscriptionId.substring(2, 6);
SimpleDateFormat dateFormat = new SimpleDateFormat("MMyy");
String substring1 = subscriptionId.substring(2, 4);
String substring2 = subscriptionId.substring(4, 6);
try {
Date expDate = dateFormat.parse(expDateStr);
Date currentDate = new Date(System.currentTimeMillis());;
if (expDate.before(currentDate)){
if (Integer.parseInt(substring1) < 1 || Integer.parseInt(substring1) > 12) {
return false;
}
} catch (Exception ex){

SimpleDateFormat dateFormat = new SimpleDateFormat("yy");
String currentYear = dateFormat.format(Calendar.getInstance().getTime());
if (Integer.parseInt(substring2) < Integer.parseInt(currentYear)){
return false;
}

String expDateStr = subscriptionId.substring(2, 6);
dateFormat = new SimpleDateFormat("MMyy");
Date expDate = dateFormat.parse(expDateStr);
Date currentDate = new Date(System.currentTimeMillis());
if (expDate.before(currentDate)) {
return false;
}
} catch (Exception ex) {
return false;
}
VerhoeffCheckDigit checkDigit = new VerhoeffCheckDigit();
Expand Down
Expand Up @@ -1149,6 +1149,8 @@ PageBase.clearCssCache=Clear less/js cache
pageBase.midPointVersion=${pom.version}, ${git.describe}
pageBase.unknownBuildNumber=unknown
PageBase.subscriptionMessage=Non-subscription.
PageBase.nonActiveSubscriptionMessage=Powered by a free midPoint community subscription. Please consider purchasing subscription today.
PageBase.demoSubscriptionMessage=Powered by Evolveum demo subscription.
PageBulkAction.async=Asynchronous
PageBulkAction.button.start=Start
PageBulkAction.message.emptyString=Inserted bulk action is empty. Please provide non-empty script.
Expand Down Expand Up @@ -2970,7 +2972,7 @@ PageAdmin.menu.assignments=Assignments
PageAdmin.menu.credentials=Credentials
PageAdmin.menu.request=Request a role
PageTemplate.version=Version\:
PageTemplate.copy=<strong>Copyright &copy; 2010-2016 <a href\="https\://www.evolveum.com/" target\="_blank">Evolveum</a> and partners.</strong> Thank you for using <a href\="http\://midpoint.evolveum.com" target\="_blank">midPoint</a>
PageTemplate.copy=<strong>Copyright &copy; 2010-2017 <a href\="https\://www.evolveum.com/" target\="_blank">Evolveum</a> and partners.</strong> Thank you for using <a href\="http\://midpoint.evolveum.com" target\="_blank">midPoint</a>
PageTemplate.toggleNavigation=Toggle navigation
PageTemplate.user=user
PageTemplate.couldntNavigateBreadcrumb=Couldn't navigate breadcrumb, reason\: {0}
Expand Down

0 comments on commit e289cf3

Please sign in to comment.