RED-9394 - Add CONFIGURABLE_SMTP_SERVER license feature flag

This commit is contained in:
Andrei Isvoran 2024-09-13 12:30:02 +02:00
parent 256a50775d
commit 80cbda22bf
3 changed files with 71 additions and 0 deletions

View File

@ -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();
}
}
}

View File

@ -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();
}

View File

@ -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<String> ALL_FILE_FORMATS = List.of("pdf", "docx", "doc", "xls", "xlsx", "ppt", "pptx");
public static final List<String> 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);