mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-09-24 14:38:45 +00:00
Merge branch 'bug5510' into bug5666
This commit is contained in:
+2
-2
@@ -26,13 +26,13 @@ public interface SubscriptionService<C, P> extends RemoteService {
|
||||
/**
|
||||
* Fetch user current subscription data from database
|
||||
*/
|
||||
public SubscriptionListDTO getSubscriptions();
|
||||
public SubscriptionListDTO getSubscriptions(Boolean activeOnly);
|
||||
|
||||
public ArrayList<SubscriptionPlanDTO> getAllSubscriptionPlans();
|
||||
|
||||
public ArrayList<String> getUnlockingSubscriptionplans(WildcardPermission permission) throws UserManagementException;
|
||||
|
||||
SubscriptionPlanDTO getSubscriptionPlanById(String planId);
|
||||
SubscriptionPlanDTO getSubscriptionPlanDTOById(String planId);
|
||||
|
||||
boolean isUserInPossessionOfRoles(String planId) throws UserManagementException;
|
||||
|
||||
|
||||
+2
-2
@@ -10,7 +10,7 @@ import com.sap.sse.security.ui.shared.subscription.SubscriptionPlanDTO;
|
||||
public interface SubscriptionServiceAsync<C, P> {
|
||||
public void prepareCheckout(String planId, AsyncCallback<P> data);
|
||||
|
||||
public void getSubscriptions(AsyncCallback<SubscriptionListDTO> subscription);
|
||||
public void getSubscriptions(Boolean activeOnly, AsyncCallback<SubscriptionListDTO> subscription);
|
||||
|
||||
public void getConfiguration(AsyncCallback<C> callback);
|
||||
|
||||
@@ -18,7 +18,7 @@ public interface SubscriptionServiceAsync<C, P> {
|
||||
|
||||
public void getUnlockingSubscriptionplans(WildcardPermission permission, AsyncCallback<ArrayList<String>> callback);
|
||||
|
||||
public void getSubscriptionPlanById(String planId, AsyncCallback<SubscriptionPlanDTO> callback);
|
||||
public void getSubscriptionPlanDTOById(String planId, AsyncCallback<SubscriptionPlanDTO> callback);
|
||||
|
||||
void isUserInPossessionOfRoles(String planId, AsyncCallback<Boolean> callback);
|
||||
}
|
||||
|
||||
+4
-1
@@ -84,7 +84,10 @@ public class ChargebeeSubscriptionViewPresenter implements SubscriptionViewPrese
|
||||
private int counter = 0;
|
||||
@Override
|
||||
public void run() {
|
||||
if (counter == 10 || updateProcessed.get()) {
|
||||
if (counter == 10) {
|
||||
view.onUnfinishedPayment(StringMessages.INSTANCE.errorPollingCheckoutResults());
|
||||
this.cancel();
|
||||
}else if (updateProcessed.get()){
|
||||
this.cancel();
|
||||
}
|
||||
service.isUserInPossessionOfRoles(planId, new AsyncCallback<Boolean>() {
|
||||
|
||||
+10
-6
@@ -131,11 +131,15 @@ public abstract class SubscriptionServiceImpl<C, P> extends RemoteServiceServlet
|
||||
getSecurityService().updateUserSubscription(user.getName(), subscription);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if user already subscribed to plan
|
||||
*/
|
||||
protected boolean isUserSubscribedToPlan(User user, String planId) {
|
||||
return isValidSubscription(user.getSubscriptionByPlan(planId));
|
||||
protected boolean isSubscribedToMutuallyExclusivePlan(User user, SubscriptionPlan newPlan) {
|
||||
for (Subscription sub : user.getSubscriptions()) {
|
||||
SubscriptionPlan subscribedPlan = getSecurityService().getSubscriptionPlanById(sub.getPlanId());
|
||||
if (isValidSubscription(sub) && !isSubscriptionCancelled(sub)
|
||||
&& Util.containsAny(subscribedPlan.getPlanCategories(), newPlan.getPlanCategories())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -222,5 +226,5 @@ public abstract class SubscriptionServiceImpl<C, P> extends RemoteServiceServlet
|
||||
|
||||
protected abstract String getProviderName();
|
||||
|
||||
|
||||
protected abstract boolean isSubscriptionCancelled(Subscription subscription);
|
||||
}
|
||||
|
||||
+10
-11
@@ -66,9 +66,11 @@ public class ChargebeeSubscriptionServiceImpl extends
|
||||
final SubscriptionPlan planForPrice = getSecurityService().getSubscriptionPlanByItemPriceId(priceId);
|
||||
if(planForPrice == null) {
|
||||
throw new IllegalArgumentException("No matching subscription plan found for given price id");
|
||||
}
|
||||
if (!isUserSubscribedToPlan(user, planForPrice.getId())
|
||||
|| isSubscriptionCancelled(user.getSubscriptionByPlan(planForPrice.getId()))) {
|
||||
}else if(planForPrice.getIsOneTimePlan() && user.hasAnySubscription(planForPrice.getId())) {
|
||||
throw new IllegalArgumentException("Plan can only be subscribed once");
|
||||
}else if(isSubscribedToMutuallyExclusivePlan(user, planForPrice)) {
|
||||
throw new IllegalArgumentException("User has already subscribed to mutually exclusive plan");
|
||||
}else {
|
||||
final Pair<String, String> usernames = getUserFirstAndLastName(user);
|
||||
final String locale = user.getLocaleOrDefault().getLanguage();
|
||||
final Result result = HostedPage.checkoutNewForItems()
|
||||
@@ -79,9 +81,6 @@ public class ChargebeeSubscriptionServiceImpl extends
|
||||
.customerLocale(locale).billingAddressFirstName(usernames.getA())
|
||||
.billingAddressLastName(usernames.getB()).billingAddressCountry("US").request();
|
||||
response.setHostedPageJSONString(result.hostedPage().toJson());
|
||||
} else {
|
||||
response.setError(
|
||||
"User has already subscribed to " + planForPrice.getId() + " plan");
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
logger.log(Level.SEVERE, "Error in generating Chargebee hosted page data ", e);
|
||||
@@ -91,7 +90,7 @@ public class ChargebeeSubscriptionServiceImpl extends
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubscriptionListDTO getSubscriptions() {
|
||||
public SubscriptionListDTO getSubscriptions(Boolean activeOnly) {
|
||||
SubscriptionListDTO subscriptionDto = null;
|
||||
try {
|
||||
final User user = getCurrentUser();
|
||||
@@ -99,7 +98,7 @@ public class ChargebeeSubscriptionServiceImpl extends
|
||||
if (subscriptions != null) {
|
||||
final List<SubscriptionDTO> itemList = new ArrayList<>();
|
||||
for (final Subscription subscription : subscriptions) {
|
||||
if (subscription.hasSubscriptionId() && !isSubscriptionCancelled(subscription)) {
|
||||
if (subscription.hasSubscriptionId() && (!activeOnly || !isSubscriptionCancelled(subscription))) {
|
||||
itemList.add(
|
||||
new ChargebeeSubscriptionDTO(subscription.getPlanId(), subscription.getSubscriptionId(),
|
||||
subscription.getSubscriptionStatus(), subscription.getPaymentStatus(),
|
||||
@@ -117,7 +116,6 @@ public class ChargebeeSubscriptionServiceImpl extends
|
||||
logger.log(Level.SEVERE, "Error in getting subscription ", e);
|
||||
subscriptionDto = new SubscriptionListDTO(null, e.getMessage());
|
||||
}
|
||||
|
||||
return subscriptionDto;
|
||||
}
|
||||
|
||||
@@ -125,14 +123,15 @@ public class ChargebeeSubscriptionServiceImpl extends
|
||||
protected String getProviderName() {
|
||||
return ChargebeeSubscriptionProvider.PROVIDER_NAME;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected boolean isSubscriptionCancelled(final Subscription subscription) {
|
||||
return subscription != null
|
||||
&& subscription.getSubscriptionStatus().equalsIgnoreCase(ChargebeeSubscription.SUBSCRIPTION_STATUS_CANCELLED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubscriptionPlanDTO getSubscriptionPlanById(final String planId) {
|
||||
public SubscriptionPlanDTO getSubscriptionPlanDTOById(final String planId) {
|
||||
final SubscriptionPlan subscriptionPlanById = getSecurityService().getSubscriptionPlanById(planId);
|
||||
return subscriptionPlanById == null ? null : convertToDto(subscriptionPlanById);
|
||||
}
|
||||
|
||||
+1
-1
@@ -89,7 +89,7 @@ public class ChargebeeSubscriptionWriteServiceImpl extends ChargebeeSubscription
|
||||
getTime(contentSubscription.nextBillingAt()), getTime(contentSubscription.currentTermEnd()),
|
||||
getTime(contentSubscription.cancelledAt()), Subscription.emptyTime(), Subscription.emptyTime());
|
||||
updateUserSubscription(user, subscription);
|
||||
subscriptionDto = getSubscriptions();
|
||||
subscriptionDto = getSubscriptions(true);
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.SEVERE, "Error in saving subscription", e);
|
||||
subscriptionDto = new SubscriptionListDTO(null, e.getMessage());
|
||||
|
||||
Reference in New Issue
Block a user