Skip to content

Commit

Permalink
Update Feature and Subscription Plan according to backend changes
Browse files Browse the repository at this point in the history
  • Loading branch information
TudorOrban committed Aug 27, 2024
1 parent 6afeca6 commit b4f8a28
Show file tree
Hide file tree
Showing 22 changed files with 122 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.util.function.Consumer;
import static org.chainoptim.desktop.core.organization.model.Organization.SubscriptionPlanTier.PRO;

/**
* Root controller managing the currently displayed main content
Expand Down Expand Up @@ -103,7 +102,7 @@ private Result<User> handleUserResponse(Result<User> result) {

User user = result.getData();

user.getOrganization().setSubscriptionPlanTier(PRO);
user.getOrganization().setSubscriptionPlanTier(result.getData().getOrganization().getSubscriptionPlanTier());

// Set user to TenantContext for reuse throughout the app
TenantContext.setCurrentUser(user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.chainoptim.desktop.shared.httphandling.Result;
import org.chainoptim.desktop.shared.util.DataReceiver;
import org.chainoptim.desktop.shared.util.resourceloader.CommonViewsLoader;
import org.chainoptim.desktop.shared.util.resourceloader.FXMLLoaderService;

import com.google.inject.Inject;
import javafx.application.Platform;
Expand All @@ -29,9 +28,7 @@
import java.io.IOException;
import java.net.URL;
import java.util.List;
import java.util.Optional;
import java.util.ResourceBundle;
import static org.chainoptim.desktop.core.organization.model.Organization.SubscriptionPlanTier.PRO;

public class OrganizationController implements Initializable {

Expand Down Expand Up @@ -166,7 +163,7 @@ private Result<Organization> handleOrganizationResponse(Result<Organization> res
}
organizationViewData.setOrganization(result.getData());

organizationViewData.getOrganization().setSubscriptionPlanTier(PRO);
organizationViewData.getOrganization().setSubscriptionPlanTier(result.getData().getSubscriptionPlanTier());

initializeUI();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package org.chainoptim.desktop.core.organization.controller;

import org.chainoptim.desktop.core.context.SupplyChainSnapshotContext;
import org.chainoptim.desktop.core.organization.model.Organization;
import org.chainoptim.desktop.core.organization.model.OrganizationViewData;
import org.chainoptim.desktop.core.organization.model.PlanDetails;
import org.chainoptim.desktop.core.organization.model.SubscriptionPlans;
import org.chainoptim.desktop.core.organization.model.*;
import org.chainoptim.desktop.shared.util.DataReceiver;

import com.google.inject.Inject;
Expand All @@ -31,8 +28,8 @@ public class OrganizationSubscriptionPlanController implements DataReceiver<Orga
private OrganizationViewData organizationViewData;
private final SupplyChainSnapshotContext snapshotContext;
private PlanDetails planDetails;
private Organization.SubscriptionPlanTier currentPlan;
private Organization.SubscriptionPlanTier currentPreviewedPlan;
private SubscriptionPlanTier currentPlan;
private SubscriptionPlanTier currentPreviewedPlan;

// FXML
@FXML
Expand Down Expand Up @@ -194,7 +191,7 @@ private ContextMenu createPlanPopover() {
contextMenu.getItems().add(new SeparatorMenuItem());

// List of plans
for (Organization.SubscriptionPlanTier plan : Organization.SubscriptionPlanTier.values()) {
for (SubscriptionPlanTier plan : SubscriptionPlanTier.values()) {
MenuItem planItem = new MenuItem(plan.toString());
if (plan == currentPlan) {
planItem.getStyleClass().add("general-label");
Expand All @@ -206,7 +203,7 @@ private ContextMenu createPlanPopover() {
return contextMenu;
}

private void handlePreviewPlan(Organization.SubscriptionPlanTier plan) {
private void handlePreviewPlan(SubscriptionPlanTier plan) {
toggleButtonsVisibility(true);

previewPlan(plan);
Expand All @@ -220,10 +217,10 @@ private void handleCancelPreview(ContextMenu planPopover) {
previewPlan(currentPlan);
}

private void previewPlan(Organization.SubscriptionPlanTier plan) {
private void previewPlan(SubscriptionPlanTier plan) {
if (currentPreviewedPlan == plan) return;
currentPreviewedPlan = plan;
planDetails = SubscriptionPlans.getPlans().get(plan);
planDetails = BaseSubscriptionPlans.getPlans().get(plan);
// Rerender UI
tabTitle.setText("Subscription Plan: " + plan.toString());
renderGridPane();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package org.chainoptim.desktop.core.organization.model;

import org.chainoptim.desktop.core.organization.model.Organization;
import org.chainoptim.desktop.core.organization.model.PlanDetails;

import lombok.Getter;


import java.util.Map;

@Getter
public class SubscriptionPlans {
public class BaseSubscriptionPlans {

private SubscriptionPlans() {}
private BaseSubscriptionPlans() {}

private static final PlanDetails NONE_PLAN = PlanDetails.builder()
.pricePerMonthDollars(0)
Expand All @@ -22,12 +20,16 @@ private SubscriptionPlans() {}
.maxProducts(1)
.maxComponents(1)
.maxProductStages(3)
.maxTransportRoutes(3)
.maxPricings(1)
.maxFactories(1)
.maxFactoryStages(3)
.maxFactoryInventoryItems(5)
.factoryPerformanceOn(false)
.maxWarehouses(1)
.maxWarehouseInventoryItems(5)
.maxCompartments(2)
.maxCrates(3)
.maxSuppliers(1)
.maxSupplierOrders(5)
.maxSupplierShipments(3)
Expand All @@ -36,35 +38,72 @@ private SubscriptionPlans() {}
.maxClientOrders(5)
.maxClientShipments(3)
.clientPerformanceOn(false)
.maxLocations(2)
.build();

private static final PlanDetails BASIC_PLAN = PlanDetails.builder()
.pricePerMonthDollars(300)
.pricePerMonthDollars(30)
.maxMembers(10)
.maxRoles(5)
.realTimeNotificationsOn(false)
.emailNotificationsOn(false)
.customNotificationsOn(false)
.maxProducts(10)
.maxComponents(10)
.maxProductStages(25)
.maxTransportRoutes(50)
.maxPricings(10)
.maxFactories(10)
.maxFactoryStages(25)
.maxFactoryInventoryItems(50)
.factoryPerformanceOn(false)
.maxWarehouses(10)
.maxWarehouseInventoryItems(50)
.maxCompartments(2)
.maxCrates(3)
.maxSuppliers(10)
.maxSupplierOrders(50)
.maxSupplierShipments(50)
.supplierPerformanceOn(false)
.maxClients(10)
.maxClientOrders(50)
.maxClientShipments(50)
.clientPerformanceOn(false)
.maxLocations(20)
.build();

private static final PlanDetails PROFESSIONAL_PLAN = PlanDetails.builder()
.pricePerMonthDollars(300)
.maxMembers(25)
.maxRoles(10)
.realTimeNotificationsOn(true)
.emailNotificationsOn(false)
.customNotificationsOn(false)
.maxProducts(10)
.maxComponents(20)
.maxProducts(25)
.maxComponents(25)
.maxProductStages(50)
.maxFactories(10)
.maxTransportRoutes(100)
.maxPricings(10)
.maxFactories(25)
.maxFactoryStages(50)
.maxFactoryInventoryItems(250)
.factoryPerformanceOn(false)
.maxWarehouses(10)
.maxWarehouses(25)
.maxWarehouseInventoryItems(250)
.maxSuppliers(10)
.maxCompartments(50)
.maxCrates(50)
.maxSuppliers(25)
.maxSupplierOrders(250)
.maxSupplierShipments(500)
.supplierPerformanceOn(false)
.maxClients(10)
.maxClients(25)
.maxClientOrders(250)
.maxClientShipments(500)
.clientPerformanceOn(false)
.maxLocations(50)
.build();

private static final PlanDetails PRO_PLAN = PlanDetails.builder()
private static final PlanDetails ENTERPRISE_PLAN = PlanDetails.builder()
.pricePerMonthDollars(1200)
.maxMembers(-1) // Unlimited marker
.maxRoles(-1)
Expand All @@ -74,12 +113,16 @@ private SubscriptionPlans() {}
.maxProducts(-1)
.maxComponents(-1)
.maxProductStages(-1)
.maxTransportRoutes(-1)
.maxPricings(-1)
.maxFactories(-1)
.maxFactoryStages(-1)
.maxFactoryInventoryItems(-1)
.factoryPerformanceOn(true)
.maxWarehouses(-1)
.maxWarehouseInventoryItems(-1)
.maxCompartments(-1)
.maxCrates(-1)
.maxSuppliers(-1)
.maxSupplierOrders(-1)
.maxSupplierShipments(-1)
Expand All @@ -88,15 +131,21 @@ private SubscriptionPlans() {}
.maxClientOrders(-1)
.maxClientShipments(-1)
.clientPerformanceOn(true)
.maxLocations(-1)
.build();

private static final Map<Organization.SubscriptionPlanTier, PlanDetails> PLANS = Map.of(
Organization.SubscriptionPlanTier.NONE, NONE_PLAN,
Organization.SubscriptionPlanTier.BASIC, BASIC_PLAN,
Organization.SubscriptionPlanTier.PRO, PRO_PLAN
private static final Map<SubscriptionPlanTier, PlanDetails> PLANS = Map.of(
SubscriptionPlanTier.NONE, NONE_PLAN,
SubscriptionPlanTier.BASIC, BASIC_PLAN,
SubscriptionPlanTier.PROFESSIONAL, PROFESSIONAL_PLAN,
SubscriptionPlanTier.ENTERPRISE, ENTERPRISE_PLAN
);

public static Map<Organization.SubscriptionPlanTier, PlanDetails> getPlans() {
public static Map<SubscriptionPlanTier, PlanDetails> getPlans() {
return PLANS;
}

public static PlanDetails getPlan(SubscriptionPlanTier tier) {
return PLANS.get(tier);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,7 @@ public class Organization {

private Set<User> users;

public enum SubscriptionPlanTier {
NONE,
BASIC,
PRO;

@Override
public String toString() {
return name().charAt(0) + name().substring(1).toLowerCase();
}
}

public PlanDetails getSubscriptionPlan() {
return SubscriptionPlans.getPlans().get(subscriptionPlanTier);
return BaseSubscriptionPlans.getPlans().get(subscriptionPlanTier);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public class PlanDetails {
private int maxProducts;
private int maxComponents;
private int maxProductStages;
private int maxTransportRoutes;
private int maxPricings;

// Factories
private int maxFactories;
Expand All @@ -31,6 +33,8 @@ public class PlanDetails {
// Warehouses
private int maxWarehouses;
private int maxWarehouseInventoryItems;
private int maxCompartments;
private int maxCrates;

// Suppliers
private int maxSuppliers;
Expand All @@ -43,4 +47,7 @@ public class PlanDetails {
private int maxClientOrders;
private int maxClientShipments;
private boolean clientPerformanceOn;

// Locations
private int maxLocations;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.chainoptim.desktop.core.organization.model;

public enum SubscriptionPlanTier {
NONE,
BASIC,
PROFESSIONAL,
ENTERPRISE;

@Override
public String toString() {
return name().charAt(0) + name().substring(1).toLowerCase();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ private Result<List<UpcomingEvent>> handleEventsException(Throwable throwable) {
private void renderTimeline() {
titleLabel.setText("Upcoming Events (" + events.size() + ")");
eventsHBox.getChildren().clear();
if (events.isEmpty()) {
Label noEventsLabel = new Label("No upcoming events");
noEventsLabel.getStyleClass().add("general-label-large");
eventsHBox.getChildren().add(noEventsLabel);
return;
}

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMM dd, yyyy hh:mm a");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public CompletableFuture<Result<List<UpcomingEvent>>> getUpcomingEventsByOrganiz
String cacheKey = CacheKeyBuilder.buildAdvancedSearchKey(
"upcoming-events", "organization", organizationId.toString(), searchParams);
String routeAddress = rootAddress + cacheKey;
System.out.println("Route address: " + routeAddress);

HttpRequest request = requestBuilder.buildReadRequest(routeAddress, tokenManager.getToken());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,11 @@ private void updatePricing(float quantity) {
}

private float calculatePrice(float quantity) {
TreeMap<Float, Float> pricePerVolume = this.pricing.getProductPricing().getPricePerVolume();
if (pricePerVolume == null || pricePerVolume.isEmpty()) {
TreeMap<Float, Float> pricePerVolume = new TreeMap<>();
if (this.pricing.getProductPricing().getPricePerVolume() != null) {
pricePerVolume.putAll(this.pricing.getProductPricing().getPricePerVolume());
}
if (pricePerVolume.isEmpty()) {
return quantity * this.pricing.getProductPricing().getPricePerUnit();
}

Expand All @@ -121,6 +124,10 @@ private void renderPricing() {
float previousQuantity = 0;
int rowIndex = 0;

if (this.pricing.getProductPricing().getPricePerVolume() == null) {
return;
}

for (Map.Entry<Float, Float> entry : this.pricing.getProductPricing().getPricePerVolume().entrySet()) {
String rangeLabelContent;
if (previousQuantity == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private void loadFallbackManager() {
private void loadSelectProductView() {
// Initialize time selection input view
FXMLLoader selectProductLoader = fxmlLoaderService.setUpLoader(
"/org/chainoptim/desktop/shared/common/uielements/Select/SelectProductView.fxml",
"/org/chainoptim/desktop/shared/common/uielements/select/SelectProductView.fxml",
controllerFactory::createController
);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ private CreateSupplierOrderDTO getCreateSupplierOrderDTO(SupplierOrder order) {
}
createSupplierOrderDTO.setOrganizationId(supplier.getOrganizationId());
createSupplierOrderDTO.setSupplierId(supplier.getId());
createSupplierOrderDTO.setComponentId(order.getComponent().getId());
createSupplierOrderDTO.setComponentId(order.getComponent() != null ? order.getComponent().getId() : null);
createSupplierOrderDTO.setQuantity(order.getQuantity());
createSupplierOrderDTO.setDeliveredQuantity(order.getDeliveredQuantity());
createSupplierOrderDTO.setOrderDate(order.getOrderDate());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private void initializeUI() {

private void setUpKeyComboBox() {
keyComboBox.setPromptText("Filter by...");
keyComboBox.getStyleClass().setAll("custom-combo-box");
keyComboBox.getStyleClass().add("custom-combo-box");
keyComboBox.getItems().addAll(filterOptions.stream().map(FilterOption::getKey).toList());

keyComboBox.valueProperty().addListener((observable, oldValue, newValue) ->
Expand Down
Loading

0 comments on commit b4f8a28

Please sign in to comment.