From 80cbda22bfe2bbb36336d8cd7b0e7d42b87cffda Mon Sep 17 00:00:00 2001 From: Andrei Isvoran Date: Fri, 13 Sep 2024 12:30:02 +0200 Subject: [PATCH] RED-9394 - Add CONFIGURABLE_SMTP_SERVER license feature flag --- .../controller/LicenseInternalController.java | 40 +++++++++++++++++++ .../internal/resources/LicenseResource.java | 25 ++++++++++++ .../service/LicenseUtilityService.java | 6 +++ 3 files changed, 71 insertions(+) create mode 100644 persistence-service-v1/persistence-service-internal-api-impl-v1/src/main/java/com/iqser/red/service/persistence/v1/internal/api/controller/LicenseInternalController.java create mode 100644 persistence-service-v1/persistence-service-internal-api-v1/src/main/java/com/iqser/red/service/persistence/service/v1/api/internal/resources/LicenseResource.java diff --git a/persistence-service-v1/persistence-service-internal-api-impl-v1/src/main/java/com/iqser/red/service/persistence/v1/internal/api/controller/LicenseInternalController.java b/persistence-service-v1/persistence-service-internal-api-impl-v1/src/main/java/com/iqser/red/service/persistence/v1/internal/api/controller/LicenseInternalController.java new file mode 100644 index 000000000..381a60021 --- /dev/null +++ b/persistence-service-v1/persistence-service-internal-api-impl-v1/src/main/java/com/iqser/red/service/persistence/v1/internal/api/controller/LicenseInternalController.java @@ -0,0 +1,40 @@ +package com.iqser.red.service.persistence.v1.internal.api.controller; + +import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.READ_LICENSE; +import static com.iqser.red.service.persistence.management.v1.processor.service.LicenseUtilityService.LICENSE_OBJECT_ID; + +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.RestController; + +import com.iqser.red.service.persistence.management.v1.processor.service.LicenseUtilityService; +import com.iqser.red.service.persistence.service.v1.api.internal.resources.LicenseResource; +import com.iqser.red.service.persistence.service.v1.api.shared.model.license.RedactionLicenseModel; +import com.iqser.red.storage.commons.service.StorageService; +import com.knecon.fforesight.tenantcommons.TenantContext; + +import lombok.RequiredArgsConstructor; + +@RestController +@RequiredArgsConstructor +public class LicenseInternalController implements LicenseResource { + + private final StorageService storageService; + private final LicenseUtilityService licenseUtilityService; + + + @Override + public RedactionLicenseModel getLicense() { + + String tenantId = TenantContext.getTenantId(); + if (storageService.objectExists(tenantId, LICENSE_OBJECT_ID)) { + try { + return storageService.readJSONObject(tenantId, LICENSE_OBJECT_ID, RedactionLicenseModel.class); + } catch (Exception e) { + return licenseUtilityService.generateDemoLicense(); + } + } else { + return licenseUtilityService.generateDemoLicense(); + } + } + +} diff --git a/persistence-service-v1/persistence-service-internal-api-v1/src/main/java/com/iqser/red/service/persistence/service/v1/api/internal/resources/LicenseResource.java b/persistence-service-v1/persistence-service-internal-api-v1/src/main/java/com/iqser/red/service/persistence/service/v1/api/internal/resources/LicenseResource.java new file mode 100644 index 000000000..b1d096599 --- /dev/null +++ b/persistence-service-v1/persistence-service-internal-api-v1/src/main/java/com/iqser/red/service/persistence/service/v1/api/internal/resources/LicenseResource.java @@ -0,0 +1,25 @@ +package com.iqser.red.service.persistence.service.v1.api.internal.resources; + +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.ResponseStatus; + +import com.iqser.red.service.persistence.service.v1.api.shared.model.license.RedactionLicenseModel; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; + +public interface LicenseResource { + + String LICENSE_REST_PATH = InternalApi.BASE_PATH + "/license"; + + @ResponseBody + @ResponseStatus(value = HttpStatus.OK) + @GetMapping(value = LICENSE_REST_PATH, produces = MediaType.APPLICATION_JSON_VALUE) + @Operation(summary = "Returns the current license (or a demo license in case none is configured") + @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "License returned successfully.")}) + RedactionLicenseModel getLicense(); +} diff --git a/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/service/LicenseUtilityService.java b/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/service/LicenseUtilityService.java index db510480f..da972dbb5 100644 --- a/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/service/LicenseUtilityService.java +++ b/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/service/LicenseUtilityService.java @@ -29,11 +29,14 @@ public class LicenseUtilityService { public static final String LICENSE_PAGE_COUNT = "LICENSE_PAGE_COUNT"; public static final String LICENSE_MS_OFFICE_FORMATS = "LICENSE_SUPPORT_MS_OFFICE_FORMATS"; public static final String PDFTRON_FRONTEND_LICENSE = "PDFTRON_FRONTEND_LICENSE"; + public static final String CONFIGURABLE_SMTP_SERVER = "CONFIGURABLE_SMTP_SERVER"; public static final String PDFTRON_FEATURE = "pdftron"; public static final String PROCESSING_PAGES_FEATURE = "processingPages"; public static final String DEFAULT_PROCESSING_PAGES = "200000"; public static final String SUPPORT_MS_OFFICE_FORMATS_FEATURE = "supportMSOfficeFormats"; public static final String DEFAULT_SUPPORT_MS_OFFICE_FORMATS = "false"; + public static final String CONFIGURABLE_SMTP_SERVER_FEATURE = "configurableSMTPServer"; + public static final String DEFAULT_CONFIGURABLE_SMTP_SERVER = "false"; public static final List ALL_FILE_FORMATS = List.of("pdf", "docx", "doc", "xls", "xlsx", "ppt", "pptx"); public static final List FILE_FORMATS_EXCLUDING_MS_OFFICE = List.of("pdf"); @@ -74,6 +77,9 @@ public class LicenseUtilityService { boolean supportMSOfficeFormats = Boolean.parseBoolean(environment.getProperty(LICENSE_MS_OFFICE_FORMATS, DEFAULT_SUPPORT_MS_OFFICE_FORMATS)); demo.getFeatures().add(Feature.builder().name(SUPPORT_MS_OFFICE_FORMATS_FEATURE).type(FeatureType.BOOLEAN).value(supportMSOfficeFormats).build()); + boolean configurableSMTPServer = Boolean.parseBoolean(environment.getProperty(CONFIGURABLE_SMTP_SERVER, DEFAULT_CONFIGURABLE_SMTP_SERVER)); + demo.getFeatures().add(Feature.builder().name(CONFIGURABLE_SMTP_SERVER_FEATURE).type(FeatureType.BOOLEAN).value(configurableSMTPServer).build()); + var demoLicense = new RedactionLicenseModel(); demoLicense.setActiveLicense("RedactManager"); demoLicense.getLicenses().add(demo);