tenant configuration changes

This commit is contained in:
Efstratios Giannopoulos 2024-04-25 14:53:07 +03:00
parent 7bcf66900d
commit 4ae62076f8
73 changed files with 1309 additions and 1724 deletions

View File

@ -166,6 +166,8 @@ public class AuditableAction {
public static final EventId TenantConfiguration_Lookup = new EventId(270001, "TenantConfiguration_Lookup"); public static final EventId TenantConfiguration_Lookup = new EventId(270001, "TenantConfiguration_Lookup");
public static final EventId TenantConfiguration_Persist = new EventId(270002, "TenantConfiguration_Persist"); public static final EventId TenantConfiguration_Persist = new EventId(270002, "TenantConfiguration_Persist");
public static final EventId TenantConfiguration_Delete = new EventId(270003, "TenantConfiguration_Delete"); public static final EventId TenantConfiguration_Delete = new EventId(270003, "TenantConfiguration_Delete");
public static final EventId TenantConfiguration_LookupByType = new EventId(270004, "TenantConfiguration_LookupByType");
} }

View File

@ -124,7 +124,7 @@ public class TenantConfigurationController {
TenantConfiguration model = this.builderFactory.builder(TenantConfigurationBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(fieldSet, query.firstAs(fieldSet)); TenantConfiguration model = this.builderFactory.builder(TenantConfigurationBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(fieldSet, query.firstAs(fieldSet));
this.auditService.track(AuditableAction.TenantConfiguration_Lookup, Map.ofEntries( this.auditService.track(AuditableAction.TenantConfiguration_LookupByType, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("type", type), new AbstractMap.SimpleEntry<String, Object>("type", type),
new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet) new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet)
)); ));
@ -136,7 +136,7 @@ public class TenantConfigurationController {
@Transactional @Transactional
@ValidationFilterAnnotation(validator = TenantConfigurationPersist.TenantConfigurationPersistValidator.ValidatorName, argumentName = "model") @ValidationFilterAnnotation(validator = TenantConfigurationPersist.TenantConfigurationPersistValidator.ValidatorName, argumentName = "model")
public TenantConfiguration persist(@RequestBody TenantConfigurationPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, JsonProcessingException, InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException { public TenantConfiguration persist(@RequestBody TenantConfigurationPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, JsonProcessingException, InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException {
logger.debug(new MapLogEntry("persisting" + DescriptionTemplateType.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet)); logger.debug(new MapLogEntry("persisting" + TenantConfiguration.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet));
TenantConfiguration persisted = this.tenantConfigurationService.persist(model, fieldSet); TenantConfiguration persisted = this.tenantConfigurationService.persist(model, fieldSet);
this.auditService.track(AuditableAction.TenantConfiguration_Persist, Map.ofEntries( this.auditService.track(AuditableAction.TenantConfiguration_Persist, Map.ofEntries(

View File

@ -1,16 +1,18 @@
package gr.cite.notification.web.controllers; package gr.cite.notification.web.controllers;
import com.fasterxml.jackson.core.JsonProcessingException;
import gr.cite.notification.audit.AuditableAction; import gr.cite.notification.audit.AuditableAction;
import gr.cite.notification.authorization.AuthorizationFlags; import gr.cite.notification.authorization.AuthorizationFlags;
import gr.cite.notification.common.enums.IsActive;
import gr.cite.notification.common.enums.TenantConfigurationType; import gr.cite.notification.common.enums.TenantConfigurationType;
import gr.cite.notification.common.types.tenantconfiguration.NotifierListConfigurationDataContainer; import gr.cite.notification.common.scope.tenant.TenantScope;
import gr.cite.notification.common.types.tenantconfiguration.NotifierListTenantConfigurationEntity;
import gr.cite.notification.data.TenantConfigurationEntity; import gr.cite.notification.data.TenantConfigurationEntity;
import gr.cite.notification.model.TenantConfiguration; import gr.cite.notification.model.builder.tenantconfiguration.TenantConfigurationBuilder;
import gr.cite.notification.model.builder.TenantConfigurationBuilder; import gr.cite.notification.model.censorship.tenantconfiguration.TenantConfigurationCensor;
import gr.cite.notification.model.censorship.TenantConfigurationCensor; import gr.cite.notification.model.persist.tenantconfiguration.TenantConfigurationPersist;
import gr.cite.notification.model.persist.NotificationTemplatePersist; import gr.cite.notification.model.tenantconfiguration.TenantConfiguration;
import gr.cite.notification.model.persist.tenantconfiguration.TenantConfigurationEmailClientPersist; import gr.cite.notification.model.persist.tenantconfiguration.NotifierListTenantConfigurationPersist;
import gr.cite.notification.model.persist.tenantconfiguration.TenantConfigurationNotifierListPersist;
import gr.cite.notification.query.TenantConfigurationQuery; import gr.cite.notification.query.TenantConfigurationQuery;
import gr.cite.notification.query.lookup.NotifierListLookup; import gr.cite.notification.query.lookup.NotifierListLookup;
import gr.cite.notification.query.lookup.TenantConfigurationLookup; import gr.cite.notification.query.lookup.TenantConfigurationLookup;
@ -31,46 +33,61 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource; import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.management.InvalidApplicationException; import javax.management.InvalidApplicationException;
import jakarta.transaction.Transactional;
import jakarta.validation.Valid; import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.*; import java.util.*;
@RestController @RestController
@RequestMapping(path = "api/notification/tenant-configuration") @RequestMapping(path = "api/notification/tenant-configuration")
public class TenantConfigurationController { public class TenantConfigurationController {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(TenantConfigurationController.class)); private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(TenantConfigurationController.class));
private final BuilderFactory builderFactory; private final BuilderFactory builderFactory;
private final AuditService auditService;
private final TenantConfigurationService tenantConfigurationService;
private final CensorFactory censorFactory;
private final QueryFactory queryFactory;
private final MessageSource messageSource;
@Autowired private final AuditService auditService;
public TenantConfigurationController(BuilderFactory builderFactory,
private final TenantConfigurationService tenantConfigurationService;
private final CensorFactory censorFactory;
private final QueryFactory queryFactory;
private final MessageSource messageSource;
private final TenantScope tenantScope;
public TenantConfigurationController(
BuilderFactory builderFactory,
AuditService auditService, AuditService auditService,
TenantConfigurationService tenantConfigurationService, CensorFactory censorFactory, TenantConfigurationService tenantConfigurationService, CensorFactory censorFactory,
QueryFactory queryFactory, QueryFactory queryFactory,
MessageSource messageSource) { MessageSource messageSource, TenantScope tenantScope) {
this.builderFactory = builderFactory; this.builderFactory = builderFactory;
this.auditService = auditService; this.auditService = auditService;
this.tenantConfigurationService = tenantConfigurationService; this.tenantConfigurationService = tenantConfigurationService;
this.censorFactory = censorFactory; this.censorFactory = censorFactory;
this.queryFactory = queryFactory; this.queryFactory = queryFactory;
this.messageSource = messageSource; this.messageSource = messageSource;
this.tenantScope = tenantScope;
} }
@PostMapping("query") @PostMapping("query")
public QueryResult<TenantConfiguration> query(@RequestBody TenantConfigurationLookup lookup) throws MyApplicationException, MyForbiddenException { public QueryResult<TenantConfiguration> query(@RequestBody TenantConfigurationLookup lookup) throws MyApplicationException, MyForbiddenException {
logger.debug("querying {}", TenantConfiguration.class.getSimpleName()); logger.debug("querying {}", TenantConfiguration.class.getSimpleName());
this.censorFactory.censor(TenantConfigurationCensor.class).censor(lookup.getProject()); this.censorFactory.censor(TenantConfigurationCensor.class).censor(lookup.getProject(), null);
TenantConfigurationQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrPermission);
TenantConfigurationQuery query = lookup.enrich(this.queryFactory);
List<TenantConfigurationEntity> data = query.collectAs(lookup.getProject()); List<TenantConfigurationEntity> data = query.collectAs(lookup.getProject());
List<TenantConfiguration> models = this.builderFactory.builder(TenantConfigurationBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(lookup.getProject(), data); List<TenantConfiguration> models = this.builderFactory.builder(TenantConfigurationBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(lookup.getProject(), data);
long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size(); long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size();
@ -81,13 +98,12 @@ public class TenantConfigurationController {
} }
@GetMapping("{id}") @GetMapping("{id}")
@Transactional public TenantConfiguration get(@PathVariable("id") UUID id, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException {
public TenantConfiguration get(@PathVariable UUID id, FieldSet fieldSet, Locale locale) throws MyApplicationException, MyForbiddenException, MyNotFoundException {
logger.debug(new MapLogEntry("retrieving" + TenantConfiguration.class.getSimpleName()).And("id", id).And("fields", fieldSet)); logger.debug(new MapLogEntry("retrieving" + TenantConfiguration.class.getSimpleName()).And("id", id).And("fields", fieldSet));
this.censorFactory.censor(TenantConfigurationCensor.class).censor(fieldSet); this.censorFactory.censor(TenantConfigurationCensor.class).censor(fieldSet, null);
TenantConfigurationQuery query = this.queryFactory.query(TenantConfigurationQuery.class).ids(id); TenantConfigurationQuery query = this.queryFactory.query(TenantConfigurationQuery.class).authorize(AuthorizationFlags.OwnerOrPermission).ids(id);
TenantConfiguration model = this.builderFactory.builder(TenantConfigurationBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(fieldSet, query.firstAs(fieldSet)); TenantConfiguration model = this.builderFactory.builder(TenantConfigurationBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(fieldSet, query.firstAs(fieldSet));
if (model == null) if (model == null)
throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, TenantConfiguration.class.getSimpleName()}, LocaleContextHolder.getLocale())); throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, TenantConfiguration.class.getSimpleName()}, LocaleContextHolder.getLocale()));
@ -96,60 +112,41 @@ public class TenantConfigurationController {
new AbstractMap.SimpleEntry<String, Object>("id", id), new AbstractMap.SimpleEntry<String, Object>("id", id),
new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet) new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet)
)); ));
//this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
return model; return model;
} }
@PostMapping("persist/email-client") @GetMapping("current-tenant/{type}")
@Transactional public TenantConfiguration getCurrentTenantType(@PathVariable("type") Short type, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException {
@ValidationFilterAnnotation(validator = TenantConfigurationEmailClientPersist.TenantConfigurationEmailClientPersistValidator.ValidatorName, argumentName = "model") logger.debug(new MapLogEntry("retrieving" + TenantConfiguration.class.getSimpleName()).And("type", type).And("fields", fieldSet));
public TenantConfiguration persist(@RequestBody TenantConfigurationEmailClientPersist model, FieldSet fieldSet)
{
logger.debug(new MapLogEntry("persisting").And("type", TenantConfigurationType.EMAIL_CLIENT_CONFIGURATION).And("model", model).And("fields", fieldSet));
TenantConfiguration persisted = this.tenantConfigurationService.persist(model, fieldSet); this.censorFactory.censor(TenantConfigurationCensor.class).censor(fieldSet, null);
this.auditService.track(AuditableAction.Tenant_Configuration_Persist, Map.of( TenantConfigurationQuery query = this.queryFactory.query(TenantConfigurationQuery.class).authorize(AuthorizationFlags.OwnerOrPermission).isActive(IsActive.Active).types(TenantConfigurationType.of(type));
"type", TenantConfigurationType.EMAIL_CLIENT_CONFIGURATION, if (this.tenantScope.isDefaultTenant()) query.tenantIsSet(false);
"model", model, else query.tenantIsSet(true).tenantIds(this.tenantScope.getTenant());
"fields", fieldSet
TenantConfiguration model = this.builderFactory.builder(TenantConfigurationBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(fieldSet, query.firstAs(fieldSet));
this.auditService.track(AuditableAction.TenantConfiguration_LookupByType, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("type", type),
new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet)
)); ));
//this._auditService.TrackIdentity(AuditableAction.IdentityTracking_Action);
return persisted; return model;
} }
@PostMapping("notifier-list/available") @PostMapping("persist")
public NotifierListConfigurationDataContainer getAvailableNotifiers(@RequestBody NotifierListLookup tenantNotifierListLookup) @org.springframework.transaction.annotation.Transactional
{ @ValidationFilterAnnotation(validator = TenantConfigurationPersist.TenantConfigurationPersistValidator.ValidatorName, argumentName = "model")
logger.debug("querying available notifiers"); public TenantConfiguration persist(@RequestBody TenantConfigurationPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, JsonProcessingException, InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException {
logger.debug(new MapLogEntry("persisting" + TenantConfiguration.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet));
NotifierListConfigurationDataContainer notifierListData = this.tenantConfigurationService.collectTenantAvailableNotifierList(tenantNotifierListLookup.getNotificationTypes());
this.auditService.track(AuditableAction.Tenant_Available_Notifiers_Query, Map.of(
"lookup", tenantNotifierListLookup
));
//this._auditService.TrackIdentity(AuditableAction.IdentityTracking_Action);
return notifierListData;
}
@PostMapping("persist/notifier-list")
@Transactional
@ValidationFilterAnnotation(validator = TenantConfigurationNotifierListPersist.TenantConfigurationNotifierListPersistValidator.ValidatorName, argumentName = "model")
public TenantConfiguration persist(@RequestBody TenantConfigurationNotifierListPersist model, FieldSet fieldSet)
{
logger.debug(new MapLogEntry("persisting").And("type", TenantConfigurationType.NOTIFIER_LIST).And("model", model).And("fields", fieldSet));
TenantConfiguration persisted = this.tenantConfigurationService.persist(model, fieldSet); TenantConfiguration persisted = this.tenantConfigurationService.persist(model, fieldSet);
this.auditService.track(AuditableAction.Tenant_Configuration_Persist, Map.of( this.auditService.track(AuditableAction.Tenant_Configuration_Persist, Map.ofEntries(
"type", TenantConfigurationType.NOTIFIER_LIST, new AbstractMap.SimpleEntry<String, Object>("model", model),
"model", model, new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet)
"fields", fieldSet
)); ));
//this._auditService.TrackIdentity(AuditableAction.IdentityTracking_Action);
return persisted; return persisted;
} }
@ -157,12 +154,11 @@ public class TenantConfigurationController {
@DeleteMapping("{id}") @DeleteMapping("{id}")
@Transactional @Transactional
public void delete(@PathVariable("id") UUID id) throws MyForbiddenException, InvalidApplicationException { public void delete(@PathVariable("id") UUID id) throws MyForbiddenException, InvalidApplicationException {
logger.debug(new MapLogEntry("deleting" + TenantConfiguration.class.getSimpleName()).And("id", id)); logger.debug(new MapLogEntry("retrieving" + TenantConfiguration.class.getSimpleName()).And("id", id));
this.tenantConfigurationService.deleteAndSave(id); this.tenantConfigurationService.deleteAndSave(id);
this.auditService.track(AuditableAction.Tenant_Configuration_Delete, "id", id); this.auditService.track(AuditableAction.Tenant_Configuration_Delete, "id", id);
//this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
} }
} }

View File

@ -4,9 +4,8 @@ import gr.cite.notification.audit.AuditableAction;
import gr.cite.notification.authorization.AuthorizationFlags; import gr.cite.notification.authorization.AuthorizationFlags;
import gr.cite.notification.common.enums.IsActive; import gr.cite.notification.common.enums.IsActive;
import gr.cite.notification.common.enums.TenantConfigurationType; import gr.cite.notification.common.enums.TenantConfigurationType;
import gr.cite.notification.common.types.tenantconfiguration.NotifierListConfigurationDataContainer; import gr.cite.notification.common.types.tenantconfiguration.NotifierListTenantConfigurationEntity;
import gr.cite.notification.data.UserNotificationPreferenceEntity; import gr.cite.notification.data.UserNotificationPreferenceEntity;
import gr.cite.notification.model.TenantConfiguration;
import gr.cite.notification.model.UserNotificationPreference; import gr.cite.notification.model.UserNotificationPreference;
import gr.cite.notification.model.builder.UserNotificationPreferenceBuilder; import gr.cite.notification.model.builder.UserNotificationPreferenceBuilder;
import gr.cite.notification.model.censorship.UserNotificationPreferenceCensor; import gr.cite.notification.model.censorship.UserNotificationPreferenceCensor;
@ -31,7 +30,6 @@ import gr.cite.tools.validation.ValidationFilterAnnotation;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource; import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import jakarta.transaction.Transactional; import jakarta.transaction.Transactional;
@ -103,11 +101,11 @@ public class UserNotificationPreferenceController {
} }
@PostMapping("notifier-list/available") @PostMapping("notifier-list/available")
public NotifierListConfigurationDataContainer getAvailableNotifiers(@RequestBody NotifierListLookup tenantNotifierListLookup) public NotifierListTenantConfigurationEntity getAvailableNotifiers(@RequestBody NotifierListLookup tenantNotifierListLookup)
{ {
logger.debug("querying available notifiers"); logger.debug("querying available notifiers");
NotifierListConfigurationDataContainer notifierListData = this.userNotificationPreferenceService.collectUserAvailableNotifierList(tenantNotifierListLookup.getNotificationTypes()); NotifierListTenantConfigurationEntity notifierListData = this.userNotificationPreferenceService.collectUserAvailableNotifierList(tenantNotifierListLookup.getNotificationTypes());
this.auditService.track(AuditableAction.User_Available_Notifiers_Query, Map.of( this.auditService.track(AuditableAction.User_Available_Notifiers_Query, Map.of(
"lookup", tenantNotifierListLookup "lookup", tenantNotifierListLookup
@ -122,12 +120,12 @@ public class UserNotificationPreferenceController {
@ValidationFilterAnnotation(validator = UserNotificationPreferencePersist.UserNotificationPreferencePersistValidator.ValidatorName, argumentName = "model") @ValidationFilterAnnotation(validator = UserNotificationPreferencePersist.UserNotificationPreferencePersistValidator.ValidatorName, argumentName = "model")
public List<UserNotificationPreference> persist(@RequestBody UserNotificationPreferencePersist model, FieldSet fieldSet) public List<UserNotificationPreference> persist(@RequestBody UserNotificationPreferencePersist model, FieldSet fieldSet)
{ {
logger.debug(new MapLogEntry("persisting").And("type", TenantConfigurationType.NOTIFIER_LIST).And("model", model).And("fields", fieldSet)); logger.debug(new MapLogEntry("persisting").And("type", TenantConfigurationType.NotifierList).And("model", model).And("fields", fieldSet));
List<UserNotificationPreference> persisted = this.userNotificationPreferenceService.persist(model, fieldSet); List<UserNotificationPreference> persisted = this.userNotificationPreferenceService.persist(model, fieldSet);
this.auditService.track(AuditableAction.User_Notification_Preference_Persist, Map.of( this.auditService.track(AuditableAction.User_Notification_Preference_Persist, Map.of(
"type", TenantConfigurationType.NOTIFIER_LIST, "type", TenantConfigurationType.NotifierList,
"model", model, "model", model,
"fields", fieldSet "fields", fieldSet
)); ));

View File

@ -35,6 +35,7 @@ public class AuditableAction {
public static final EventId Tenant_Configuration_Lookup = new EventId(21001, "Tenant_Configuration_Lookup"); public static final EventId Tenant_Configuration_Lookup = new EventId(21001, "Tenant_Configuration_Lookup");
public static final EventId Tenant_Configuration_Persist = new EventId(21002, "Tenant_Configuration_Persist"); public static final EventId Tenant_Configuration_Persist = new EventId(21002, "Tenant_Configuration_Persist");
public static final EventId Tenant_Configuration_Delete = new EventId(21003, "Tenant_Configuration_Delete"); public static final EventId Tenant_Configuration_Delete = new EventId(21003, "Tenant_Configuration_Delete");
public static final EventId TenantConfiguration_LookupByType = new EventId(210004, "TenantConfiguration_LookupByType");
public static final EventId User_Notification_Preference_Query = new EventId(22000, "User_Notification_Preference_Query"); public static final EventId User_Notification_Preference_Query = new EventId(22000, "User_Notification_Preference_Query");
public static final EventId User_Notification_Preference_Lookup = new EventId(22001, "User_Notification_Preference_Lookup"); public static final EventId User_Notification_Preference_Lookup = new EventId(22001, "User_Notification_Preference_Lookup");

View File

@ -24,6 +24,7 @@ public final class Permission {
public static final String BrowseTenantConfiguration = "BrowseTenantConfiguration"; public static final String BrowseTenantConfiguration = "BrowseTenantConfiguration";
public static final String EditTenantConfiguration = "EditTenantConfiguration"; public static final String EditTenantConfiguration = "EditTenantConfiguration";
public static final String DeleteTenantConfiguration = "DeleteTenantConfiguration";
//Notification Preference //Notification Preference
public static final String BrowseUserNotificationPreference = "BrowseUserNotificationPreference"; public static final String BrowseUserNotificationPreference = "BrowseUserNotificationPreference";

View File

@ -6,9 +6,9 @@ import gr.cite.notification.data.conventers.DatabaseEnum;
import java.util.Map; import java.util.Map;
public enum TenantConfigurationType implements DatabaseEnum<Short> { public enum TenantConfigurationType implements DatabaseEnum<Short> {
EMAIL_CLIENT_CONFIGURATION((short)1), NotifierList((short)0),
DEFAULT_USER_LOCALE((short)3), DefaultUserLocale((short) 1),
NOTIFIER_LIST((short)4); ;
private final Short value; private final Short value;

View File

@ -1,35 +0,0 @@
package gr.cite.notification.common.types.tenant;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "config")
@XmlAccessorType(XmlAccessType.FIELD)
public class TenantConfigEntity {
@XmlElement(name = "deposit-configuration")
private TenantDepositConfigEntity deposit;
@XmlElement(name = "file-transformers-configuration")
private TenantFileTransformersConfigEntity fileTransformers;
public TenantDepositConfigEntity getDeposit() {
return deposit;
}
public void setDeposit(TenantDepositConfigEntity deposit) {
this.deposit = deposit;
}
public TenantFileTransformersConfigEntity getFileTransformers() {
return fileTransformers;
}
public void setFileTransformers(TenantFileTransformersConfigEntity fileTransformers) {
this.fileTransformers = fileTransformers;
}
}

View File

@ -1,22 +0,0 @@
package gr.cite.notification.common.types.tenant;
import jakarta.xml.bind.annotation.*;
import java.util.List;
@XmlAccessorType(XmlAccessType.FIELD)
public class TenantDepositConfigEntity {
@XmlElementWrapper(name = "sources")
@XmlElement(name = "source")
private List<TenantSourceEntity> sources;
public List<TenantSourceEntity> getSources() {
return sources;
}
public void setSources(List<TenantSourceEntity> sources) {
this.sources = sources;
}
}

View File

@ -1,21 +0,0 @@
package gr.cite.notification.common.types.tenant;
import jakarta.xml.bind.annotation.*;
import java.util.List;
@XmlAccessorType(XmlAccessType.FIELD)
public class TenantFileTransformersConfigEntity {
@XmlElementWrapper(name = "sources")
@XmlElement(name = "source")
private List<TenantSourceEntity> sources;
public List<TenantSourceEntity> getSources() {
return sources;
}
public void setSources(List<TenantSourceEntity> sources) {
this.sources = sources;
}
}

View File

@ -1,76 +0,0 @@
package gr.cite.notification.common.types.tenant;
import jakarta.xml.bind.annotation.*;
import java.util.List;
@XmlAccessorType(XmlAccessType.FIELD)
public class TenantSourceEntity {
@XmlElement(name = "url")
private String url;
@XmlElementWrapper(name = "codes")
@XmlElement(name = "code")
private List<String> codes;
@XmlElement(name = "issuer-url")
private String issuerUrl;
@XmlElement(name = "client-id")
private String clientId;
@XmlElement(name = "client-secret")
private String clientSecret;
@XmlElement(name = "scope")
private String scope;
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public List<String> getCodes() {
return codes;
}
public void setCodes(List<String> codes) {
this.codes = codes;
}
public String getIssuerUrl() {
return issuerUrl;
}
public void setIssuerUrl(String issuerUrl) {
this.issuerUrl = issuerUrl;
}
public String getClientId() {
return clientId;
}
public void setClientId(String clientId) {
this.clientId = clientId;
}
public String getClientSecret() {
return clientSecret;
}
public void setClientSecret(String clientSecret) {
this.clientSecret = clientSecret;
}
public String getScope() {
return scope;
}
public void setScope(String scope) {
this.scope = scope;
}
}

View File

@ -1,37 +0,0 @@
package gr.cite.notification.common.types.tenantconfiguration;
public class DefaultUserLocaleConfigurationDataContainer {
public static class Field {
public static final String LANGUAGE = "language";
public static final String TIME_ZONE = "timeZone";
public static final String CULTURE = "culture";
}
private String language;
private String timeZone;
private String culture;
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
}
public String getTimeZone() {
return timeZone;
}
public void setTimeZone(String timeZone) {
this.timeZone = timeZone;
}
public String getCulture() {
return culture;
}
public void setCulture(String culture) {
this.culture = culture;
}
}

View File

@ -0,0 +1,32 @@
package gr.cite.notification.common.types.tenantconfiguration;
public class DefaultUserLocaleTenantConfigurationEntity {
private String timezone;
private String language;
private String culture;
public String getTimezone() {
return timezone;
}
public void setTimezone(String timezone) {
this.timezone = timezone;
}
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
}
public String getCulture() {
return culture;
}
public void setCulture(String culture) {
this.culture = culture;
}
}

View File

@ -1,87 +0,0 @@
package gr.cite.notification.common.types.tenantconfiguration;
public class EmailClientConfigurationDataContainer {
public static class Field {
public static final String REQUIRE_CREDENTIALS = "requireCredentials";
public static final String ENABLE_SSL = "enableSSL";
public static final String CERTIFICATE_PATH = "certificatePath";
public static final String HOST_SERVER = "hostServer";
public static final String HOST_PORT_NO = "hostPortNo";
public static final String EMAIL_ADDRESS = "emailAddress";
public static final String EMAIL_USER_NAME = "emailUserName";
public static final String EMAIL_PASSWORD = "emailPassword";
}
private Boolean requireCredentials;
private Boolean enableSSL;
private String certificatePath;
private String hostServer;
private Integer hostPortNo;
private String emailAddress;
private String emailUserName;
private String emailPassword;
public Boolean getRequireCredentials() {
return requireCredentials;
}
public void setRequireCredentials(Boolean requireCredentials) {
this.requireCredentials = requireCredentials;
}
public Boolean getEnableSSL() {
return enableSSL;
}
public void setEnableSSL(Boolean enableSSL) {
this.enableSSL = enableSSL;
}
public String getCertificatePath() {
return certificatePath;
}
public void setCertificatePath(String certificatePath) {
this.certificatePath = certificatePath;
}
public String getHostServer() {
return hostServer;
}
public void setHostServer(String hostServer) {
this.hostServer = hostServer;
}
public Integer getHostPortNo() {
return hostPortNo;
}
public void setHostPortNo(Integer hostPortNo) {
this.hostPortNo = hostPortNo;
}
public String getEmailAddress() {
return emailAddress;
}
public void setEmailAddress(String emailAddress) {
this.emailAddress = emailAddress;
}
public String getEmailUserName() {
return emailUserName;
}
public void setEmailUserName(String emailUserName) {
this.emailUserName = emailUserName;
}
public String getEmailPassword() {
return emailPassword;
}
public void setEmailPassword(String emailPassword) {
this.emailPassword = emailPassword;
}
}

View File

@ -6,17 +6,14 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
public class NotifierListConfigurationDataContainer { public class NotifierListTenantConfigurationEntity {
public static class Field {
public static final String NOTIFIERS = "notifiers";
}
private Map<UUID, List<NotificationContactType>> notifiers; private Map<UUID, List<NotificationContactType>> notifiers;
public NotifierListConfigurationDataContainer() { public NotifierListTenantConfigurationEntity() {
} }
public NotifierListConfigurationDataContainer(Map<UUID, List<NotificationContactType>> notifiers) { public NotifierListTenantConfigurationEntity(Map<UUID, List<NotificationContactType>> notifiers) {
this.notifiers = notifiers; this.notifiers = notifiers;
} }

View File

@ -3,20 +3,9 @@ package gr.cite.notification.common.types.user;
import java.util.UUID; import java.util.UUID;
public class AdditionalInfoEntity { public class AdditionalInfoEntity {
private String avatarUrl;
private String timezone; private String timezone;
private String culture; private String culture;
private String language; private String language;
private String roleOrganization;
private UUID organizationId;
public String getAvatarUrl() {
return avatarUrl;
}
public void setAvatarUrl(String avatarUrl) {
this.avatarUrl = avatarUrl;
}
public String getTimezone() { public String getTimezone() {
return timezone; return timezone;
@ -42,19 +31,4 @@ public class AdditionalInfoEntity {
this.language = language; this.language = language;
} }
public UUID getOrganizationId() {
return organizationId;
}
public void setOrganizationId(UUID organizationId) {
this.organizationId = organizationId;
}
public String getRoleOrganization() {
return roleOrganization;
}
public void setRoleOrganization(String roleOrganization) {
this.roleOrganization = roleOrganization;
}
} }

View File

@ -33,13 +33,11 @@ public class NotificationConfig {
} }
private final ApplicationContext applicationContext; private final ApplicationContext applicationContext;
private final NotificationProperties properties; private final NotificationProperties properties;
private final QueueListenerProperties queueListenerProperties;
@Autowired @Autowired
public NotificationConfig(ApplicationContext applicationContext, NotificationProperties properties, QueueListenerProperties queueListenerProperties) { public NotificationConfig(ApplicationContext applicationContext, NotificationProperties properties) {
this.applicationContext = applicationContext; this.applicationContext = applicationContext;
this.properties = properties; this.properties = properties;
this.queueListenerProperties = queueListenerProperties;
} }
@Bean(BeanQualifier.GLOBAL_POLICIES_MAP) @Bean(BeanQualifier.GLOBAL_POLICIES_MAP)

View File

@ -17,40 +17,29 @@ public class TenantConfigurationEntity extends TenantScopedBaseEntity {
@Id @Id
@Column(name = "id", columnDefinition = "uuid", updatable = false, nullable = false) @Column(name = "id", columnDefinition = "uuid", updatable = false, nullable = false)
private UUID id; private UUID id;
public final static String _id = "id";
public static final String _id = "id";
@Column(name = "type", nullable = false) @Column(name = "type", nullable = false)
@Convert(converter = TenantConfigurationTypeConverter.class) @Convert(converter = TenantConfigurationTypeConverter.class)
private TenantConfigurationType type; private TenantConfigurationType type;
public final static String _type = "type";
public static final String _type = "type";
@Column(name = "value", nullable = false) @Column(name = "value", nullable = false)
private String value; private String value;
public final static String _value = "value";
public static final String _value = "value";
@Column(name = "\"tenant\"", columnDefinition = "uuid")
private UUID tenantId;
public static final String _tenantId = "tenantId";
@Column(name = "created_at", nullable = false) @Column(name = "created_at", nullable = false)
private Instant createdAt; private Instant createdAt;
public final static String _createdAt = "createdAt";
public static final String _createdAt = "createdAt";
@Column(name = "updated_at", nullable = false) @Column(name = "updated_at", nullable = false)
private Instant updatedAt; private Instant updatedAt;
public final static String _updatedAt = "updatedAt";
public static final String _updatedAt = "updatedAt";
@Column(name = "is_active", nullable = false) @Column(name = "is_active", nullable = false)
@Convert(converter = IsActiveConverter.class) @Convert(converter = IsActiveConverter.class)
private IsActive isActive; private IsActive isActive;
public final static String _isActive = "isActive";
public static final String _isActive = "isActive";
public UUID getId() { public UUID getId() {
return id; return id;
@ -60,14 +49,6 @@ public class TenantConfigurationEntity extends TenantScopedBaseEntity {
this.id = id; this.id = id;
} }
public TenantConfigurationType getType() {
return type;
}
public void setType(TenantConfigurationType type) {
this.type = type;
}
public String getValue() { public String getValue() {
return value; return value;
} }
@ -76,14 +57,20 @@ public class TenantConfigurationEntity extends TenantScopedBaseEntity {
this.value = value; this.value = value;
} }
@Override public TenantConfigurationType getType() {
public UUID getTenantId() { return type;
return tenantId;
} }
@Override public void setType(TenantConfigurationType type) {
public void setTenantId(UUID tenantId) { this.type = type;
this.tenantId = tenantId; }
public IsActive getIsActive() {
return isActive;
}
public void setIsActive(IsActive isActive) {
this.isActive = isActive;
} }
public Instant getCreatedAt() { public Instant getCreatedAt() {
@ -101,13 +88,4 @@ public class TenantConfigurationEntity extends TenantScopedBaseEntity {
public void setUpdatedAt(Instant updatedAt) { public void setUpdatedAt(Instant updatedAt) {
this.updatedAt = updatedAt; this.updatedAt = updatedAt;
} }
public IsActive getIsActive() {
return isActive;
}
public void setIsActive(IsActive isActive) {
this.isActive = isActive;
}
} }

View File

@ -1,4 +1,4 @@
package gr.cite.notification.config.db; package gr.cite.notification.data.namingstrategy;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.bind.ConstructorBinding; import org.springframework.boot.context.properties.bind.ConstructorBinding;

View File

@ -1,4 +1,4 @@
package gr.cite.notification.config.db; package gr.cite.notification.data.namingstrategy;
import gr.cite.notification.common.StringUtils; import gr.cite.notification.common.StringUtils;
import org.hibernate.boot.model.naming.Identifier; import org.hibernate.boot.model.naming.Identifier;

View File

@ -18,6 +18,10 @@ public class ErrorThesaurusProperties {
private ErrorDescription tenantNotAllowed; private ErrorDescription tenantNotAllowed;
private ErrorDescription tenantTampering; private ErrorDescription tenantTampering;
private ErrorDescription tenantConfigurationTypeCanNotChange;
private ErrorDescription multipleTenantConfigurationTypeNotAllowed;
public ErrorDescription getHashConflict() { public ErrorDescription getHashConflict() {
return hashConflict; return hashConflict;
} }
@ -106,4 +110,20 @@ public class ErrorThesaurusProperties {
public void setTenantTampering(ErrorDescription tenantTampering) { public void setTenantTampering(ErrorDescription tenantTampering) {
this.tenantTampering = tenantTampering; this.tenantTampering = tenantTampering;
} }
public ErrorDescription getTenantConfigurationTypeCanNotChange() {
return tenantConfigurationTypeCanNotChange;
}
public void setTenantConfigurationTypeCanNotChange(ErrorDescription tenantConfigurationTypeCanNotChange) {
this.tenantConfigurationTypeCanNotChange = tenantConfigurationTypeCanNotChange;
}
public ErrorDescription getMultipleTenantConfigurationTypeNotAllowed() {
return multipleTenantConfigurationTypeNotAllowed;
}
public void setMultipleTenantConfigurationTypeNotAllowed(ErrorDescription multipleTenantConfigurationTypeNotAllowed) {
this.multipleTenantConfigurationTypeNotAllowed = multipleTenantConfigurationTypeNotAllowed;
}
} }

View File

@ -33,5 +33,8 @@ public class EventBroker {
public void emit(UserRemovedFromTenantEvent event) { public void emit(UserRemovedFromTenantEvent event) {
this.applicationEventPublisher.publishEvent(event); this.applicationEventPublisher.publishEvent(event);
} }
public void emit(TenantConfigurationTouchedEvent event) {
this.applicationEventPublisher.publishEvent(event);
}
} }

View File

@ -0,0 +1,45 @@
package gr.cite.notification.event;
import gr.cite.notification.common.enums.TenantConfigurationType;
import java.util.UUID;
public class TenantConfigurationTouchedEvent {
public TenantConfigurationTouchedEvent() {
}
public TenantConfigurationTouchedEvent(UUID tenantId, String tenantCode, TenantConfigurationType type) {
this.tenantId = tenantId;
this.tenantCode = tenantCode;
this.type = type;
}
private UUID tenantId;
private String tenantCode;
private TenantConfigurationType type;
public UUID getTenantId() {
return tenantId;
}
public void setTenantId(UUID tenantId) {
this.tenantId = tenantId;
}
public TenantConfigurationType getType() {
return type;
}
public void setType(TenantConfigurationType type) {
this.type = type;
}
public String getTenantCode() {
return tenantCode;
}
public void setTenantCode(String tenantCode) {
this.tenantCode = tenantCode;
}
}

View File

@ -1,145 +0,0 @@
package gr.cite.notification.model;
import gr.cite.notification.common.enums.IsActive;
import gr.cite.notification.common.enums.TenantConfigurationType;
import gr.cite.notification.common.types.tenantconfiguration.DefaultUserLocaleConfigurationDataContainer;
import gr.cite.notification.common.types.tenantconfiguration.EmailClientConfigurationDataContainer;
import gr.cite.notification.common.types.tenantconfiguration.NotifierListConfigurationDataContainer;
import java.time.Instant;
import java.util.UUID;
public class TenantConfiguration {
private UUID id;
public static final String _id = "id";
private UUID tenantId;
public static final String _tenantId = "tenantId";
private TenantConfigurationType type;
public static final String _type = "type";
private String value;
public static final String _value = "value";
private EmailClientConfigurationDataContainer emailClientData;
public static final String _emailClientData = "emailClientData";
private DefaultUserLocaleConfigurationDataContainer defaultUserLocaleData;
public static final String _defaultUserLocaleData = "defaultUserLocaleData";
private NotifierListConfigurationDataContainer notifierListData;
public static final String _notifierListData = "notifierListData";
private IsActive isActive;
public static final String _isActive = "isActive";
private Instant createdAt;
public static final String _createdAt = "createdAt";
private Instant updatedAt;
public static final String _updatedAt = "updatedAt";
private String hash;
public static final String _hash = "hash";
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public UUID getTenantId() {
return tenantId;
}
public void setTenantId(UUID tenantId) {
this.tenantId = tenantId;
}
public TenantConfigurationType getType() {
return type;
}
public void setType(TenantConfigurationType type) {
this.type = type;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public EmailClientConfigurationDataContainer getEmailClientData() {
return emailClientData;
}
public void setEmailClientData(EmailClientConfigurationDataContainer emailClientData) {
this.emailClientData = emailClientData;
}
public DefaultUserLocaleConfigurationDataContainer getDefaultUserLocaleData() {
return defaultUserLocaleData;
}
public void setDefaultUserLocaleData(DefaultUserLocaleConfigurationDataContainer defaultUserLocaleData) {
this.defaultUserLocaleData = defaultUserLocaleData;
}
public NotifierListConfigurationDataContainer getNotifierListData() {
return notifierListData;
}
public void setNotifierListData(NotifierListConfigurationDataContainer notifierListData) {
this.notifierListData = notifierListData;
}
public IsActive getIsActive() {
return isActive;
}
public void setIsActive(IsActive isActive) {
this.isActive = isActive;
}
public Instant getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Instant createdAt) {
this.createdAt = createdAt;
}
public Instant getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(Instant updatedAt) {
this.updatedAt = updatedAt;
}
public String getHash() {
return hash;
}
public void setHash(String hash) {
this.hash = hash;
}
}

View File

@ -1,12 +1,15 @@
package gr.cite.notification.model.builder; package gr.cite.notification.model.builder;
import gr.cite.notification.common.scope.tenant.TenantScope;
import gr.cite.notification.convention.ConventionService; import gr.cite.notification.convention.ConventionService;
import gr.cite.notification.data.tenant.TenantScopedBaseEntity;
import gr.cite.tools.data.builder.Builder; import gr.cite.tools.data.builder.Builder;
import gr.cite.tools.data.query.QueryBase; import gr.cite.tools.data.query.QueryBase;
import gr.cite.tools.exception.MyApplicationException; import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.FieldSet; import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.LoggerService;
import javax.management.InvalidApplicationException;
import java.time.Instant; import java.time.Instant;
import java.util.*; import java.util.*;
import java.util.function.Function; import java.util.function.Function;
@ -92,4 +95,15 @@ public abstract class BaseBuilder<M, D> implements Builder {
return this.conventionService.asIndexer(names); return this.conventionService.asIndexer(names);
} }
protected boolean getBelongsToCurrentTenant(TenantScopedBaseEntity entity, TenantScope tenantScope){
if (!tenantScope.isSet()) return true;
try {
if (entity.getTenantId() == null && tenantScope.getTenant() == null) return true;
if (entity.getTenantId() == null || tenantScope.getTenant() == null) return false;
return entity.getTenantId().equals(tenantScope.getTenant());
} catch (InvalidApplicationException e) {
return false;
}
}
} }

View File

@ -1,137 +0,0 @@
package gr.cite.notification.model.builder;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import gr.cite.notification.authorization.AuthorizationFlags;
import gr.cite.notification.common.types.tenantconfiguration.DefaultUserLocaleConfigurationDataContainer;
import gr.cite.notification.common.types.tenantconfiguration.EmailClientConfigurationDataContainer;
import gr.cite.notification.common.types.tenantconfiguration.NotifierListConfigurationDataContainer;
import gr.cite.notification.convention.ConventionService;
import gr.cite.notification.data.TenantConfigurationEntity;
import gr.cite.notification.model.TenantConfiguration;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.annotation.RequestScope;
import java.util.*;
@Component
@RequestScope
public class TenantConfigurationBuilder extends BaseBuilder<TenantConfiguration, TenantConfigurationEntity> {
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
private final ObjectMapper mapper;
@Autowired
public TenantConfigurationBuilder(ConventionService conventionService) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(TenantConfigurationBuilder.class)));
this.mapper = new ObjectMapper();
}
public TenantConfigurationBuilder authorize(EnumSet<AuthorizationFlags> values){
this.authorize = values;
return this;
}
@Override
public List<TenantConfiguration> build(FieldSet fields, List<TenantConfigurationEntity> data) throws MyApplicationException {
this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0),Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size) .orElse(0));
this.logger.trace(new DataLogEntry("requested fields",fields));
if(fields == null || data == null || fields.isEmpty()) return new ArrayList<>();
List<TenantConfiguration> models = new ArrayList<>();
for(TenantConfigurationEntity d : data){
TenantConfiguration m = new TenantConfiguration();
if(fields.hasField(this.asIndexer(TenantConfiguration._id))) m.setId(d.getId());
if(fields.hasField(this.asIndexer(TenantConfiguration._tenantId))) m.setTenantId(d.getTenantId());
if(fields.hasField(this.asIndexer(TenantConfiguration._type))) m.setType(d.getType());
if(fields.hasField(this.asIndexer(TenantConfiguration._value))) m.setValue(d.getValue());
if(fields.hasField(this.asIndexer(TenantConfiguration._defaultUserLocaleData))) {
try {
m.setDefaultUserLocaleData(mapper.readValue(d.getValue(), DefaultUserLocaleConfigurationDataContainer.class));
} catch (JsonProcessingException e) {
logger.error(e.getMessage(), e);
}
}
if (!fields.extractPrefixed(this.asIndexer(TenantConfiguration._defaultUserLocaleData)).isEmpty()) {
try {
DefaultUserLocaleConfigurationDataContainer container = mapper.readValue(d.getValue(), DefaultUserLocaleConfigurationDataContainer.class);
if (container != null) {
m.setDefaultUserLocaleData(new DefaultUserLocaleConfigurationDataContainer());
if (fields.hasField(this.asIndexer(TenantConfiguration._defaultUserLocaleData, DefaultUserLocaleConfigurationDataContainer.Field.LANGUAGE)))
m.getDefaultUserLocaleData().setLanguage(container.getLanguage());
if (fields.hasField(this.asIndexer(TenantConfiguration._defaultUserLocaleData, DefaultUserLocaleConfigurationDataContainer.Field.TIME_ZONE)))
m.getDefaultUserLocaleData().setTimeZone(container.getTimeZone());
if (fields.hasField(this.asIndexer(TenantConfiguration._defaultUserLocaleData, DefaultUserLocaleConfigurationDataContainer.Field.CULTURE)))
m.getDefaultUserLocaleData().setCulture(container.getCulture());
}
} catch (JsonProcessingException e) {
logger.error(e.getMessage(), e);
}
}
if(fields.hasField(this.asIndexer(TenantConfiguration._emailClientData))) {
try {
m.setEmailClientData(mapper.readValue(d.getValue(), EmailClientConfigurationDataContainer.class));
} catch (JsonProcessingException e) {
logger.error(e.getMessage(), e);
}
}
if (!fields.extractPrefixed(this.asIndexer(TenantConfiguration._emailClientData)).isEmpty()) {
try {
EmailClientConfigurationDataContainer container = mapper.readValue(d.getValue(), EmailClientConfigurationDataContainer.class);
if (container != null) {
m.setEmailClientData(new EmailClientConfigurationDataContainer());
if (fields.hasField(this.asIndexer(TenantConfiguration._emailClientData, EmailClientConfigurationDataContainer.Field.ENABLE_SSL)))
m.getEmailClientData().setEnableSSL(container.getEnableSSL());
if (fields.hasField(this.asIndexer(TenantConfiguration._emailClientData, EmailClientConfigurationDataContainer.Field.REQUIRE_CREDENTIALS)))
m.getEmailClientData().setRequireCredentials(container.getRequireCredentials());
if (fields.hasField(this.asIndexer(TenantConfiguration._emailClientData, EmailClientConfigurationDataContainer.Field.HOST_SERVER)))
m.getEmailClientData().setHostServer(container.getHostServer());
if (fields.hasField(this.asIndexer(TenantConfiguration._emailClientData, EmailClientConfigurationDataContainer.Field.HOST_PORT_NO)))
m.getEmailClientData().setHostPortNo(container.getHostPortNo());
if (fields.hasField(this.asIndexer(TenantConfiguration._emailClientData, EmailClientConfigurationDataContainer.Field.CERTIFICATE_PATH)))
m.getEmailClientData().setCertificatePath(container.getCertificatePath());
if (fields.hasField(this.asIndexer(TenantConfiguration._emailClientData, EmailClientConfigurationDataContainer.Field.EMAIL_ADDRESS)))
m.getEmailClientData().setEmailAddress(container.getEmailAddress());
if (fields.hasField(this.asIndexer(TenantConfiguration._emailClientData, EmailClientConfigurationDataContainer.Field.EMAIL_USER_NAME)))
m.getEmailClientData().setEmailUserName(container.getEmailUserName());
if (fields.hasField(this.asIndexer(TenantConfiguration._emailClientData, EmailClientConfigurationDataContainer.Field.EMAIL_PASSWORD)))
m.getEmailClientData().setEmailPassword(container.getEmailPassword());
}
} catch (JsonProcessingException e) {
logger.error(e.getMessage(), e);
}
}
if(fields.hasField(this.asIndexer(TenantConfiguration._notifierListData))) {
try {
m.setNotifierListData(mapper.readValue(d.getValue(), NotifierListConfigurationDataContainer.class));
} catch (JsonProcessingException e) {
logger.error(e.getMessage(), e);
}
}
if (!fields.extractPrefixed(this.asIndexer(TenantConfiguration._notifierListData)).isEmpty()) {
try {
NotifierListConfigurationDataContainer container = mapper.readValue(d.getValue(), NotifierListConfigurationDataContainer.class);
if (container != null) {
m.setNotifierListData(new NotifierListConfigurationDataContainer());
if (fields.hasField(this.asIndexer(TenantConfiguration._notifierListData, NotifierListConfigurationDataContainer.Field.NOTIFIERS)))
m.getNotifierListData().setNotifiers(container.getNotifiers());
}
} catch (JsonProcessingException e) {
logger.error(e.getMessage(), e);
}
}
if(fields.hasField(this.asIndexer(TenantConfiguration._isActive))) m.setIsActive(d.getIsActive());
if(fields.hasField(this.asIndexer(TenantConfiguration._createdAt))) m.setCreatedAt(d.getCreatedAt());
if(fields.hasField(this.asIndexer(TenantConfiguration._updatedAt))) m.setUpdatedAt(d.getUpdatedAt());
if(fields.hasField(this.asIndexer(TenantConfiguration._hash))) m.setHash(this.hashValue(d.getUpdatedAt()));
models.add(m);
}
this.logger.debug("build {} items",Optional.of(models).map(List::size).orElse(0));
return models;
}
}

View File

@ -4,7 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import gr.cite.notification.authorization.AuthorizationFlags; import gr.cite.notification.authorization.AuthorizationFlags;
import gr.cite.notification.convention.ConventionService; import gr.cite.notification.convention.ConventionService;
import gr.cite.notification.data.UserNotificationPreferenceEntity; import gr.cite.notification.data.UserNotificationPreferenceEntity;
import gr.cite.notification.model.TenantConfiguration; import gr.cite.notification.model.tenantconfiguration.TenantConfiguration;
import gr.cite.notification.model.UserNotificationPreference; import gr.cite.notification.model.UserNotificationPreference;
import gr.cite.tools.exception.MyApplicationException; import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.FieldSet; import gr.cite.tools.fieldset.FieldSet;

View File

@ -1,60 +0,0 @@
package gr.cite.notification.model.builder.tenantconfig;
import gr.cite.notification.authorization.AuthorizationFlags;
import gr.cite.notification.common.types.tenant.TenantConfigEntity;
import gr.cite.notification.convention.ConventionService;
import gr.cite.notification.model.builder.BaseBuilder;
import gr.cite.notification.model.tenantconfig.TenantConfig;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.*;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class TenantConfigBuilder extends BaseBuilder<TenantConfig, TenantConfigEntity> {
private final BuilderFactory builderFactory;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
public TenantConfigBuilder(
ConventionService conventionService, BuilderFactory builderFactory) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(TenantConfigBuilder.class)));
this.builderFactory = builderFactory;
}
public TenantConfigBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
public List<TenantConfig> build(FieldSet fields, List<TenantConfigEntity> data) throws MyApplicationException {
this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0));
this.logger.trace(new DataLogEntry("requested fields", fields));
if (fields == null || data == null || fields.isEmpty())
return new ArrayList<>();
FieldSet depositFields = fields.extractPrefixed(this.asPrefix(TenantConfig._deposit));
FieldSet fileFields = fields.extractPrefixed(this.asPrefix(TenantConfig._fileTransformers));
List<TenantConfig> models = new ArrayList<>();
for (TenantConfigEntity d : data) {
TenantConfig m = new TenantConfig();
if (!depositFields.isEmpty() && d.getDeposit() != null) m.setDeposit(this.builderFactory.builder(TenantDepositConfigBuilder.class).authorize(this.authorize).build(depositFields, d.getDeposit()));
if (!fileFields.isEmpty() && d.getFileTransformers() != null) m.setFileTransformers(this.builderFactory.builder(TenantFileTransformersBuilder.class).authorize(this.authorize).build(fileFields, d.getFileTransformers()));
models.add(m);
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models;
}
}

View File

@ -1,62 +0,0 @@
package gr.cite.notification.model.builder.tenantconfig;
import gr.cite.notification.authorization.AuthorizationFlags;
import gr.cite.notification.common.types.tenant.TenantSourceEntity;
import gr.cite.notification.convention.ConventionService;
import gr.cite.notification.model.builder.BaseBuilder;
import gr.cite.notification.model.tenantconfig.TenantSource;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.*;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class TenantSourceBuilder extends BaseBuilder<TenantSource, TenantSourceEntity> {
private final BuilderFactory builderFactory;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
public TenantSourceBuilder(
ConventionService conventionService, BuilderFactory builderFactory) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(TenantSourceBuilder.class)));
this.builderFactory = builderFactory;
}
public TenantSourceBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
public List<TenantSource> build(FieldSet fields, List<TenantSourceEntity> data) throws MyApplicationException {
this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0));
this.logger.trace(new DataLogEntry("requested fields", fields));
if (fields == null || data == null || fields.isEmpty())
return new ArrayList<>();
List<TenantSource> models = new ArrayList<>();
for (TenantSourceEntity d : data) {
TenantSource m = new TenantSource();
if (fields.hasField(this.asIndexer(TenantSource._url))) m.setUrl(d.getUrl());
if (fields.hasField(this.asIndexer(TenantSource._codes))) m.setCodes(d.getCodes());
if (fields.hasField(this.asIndexer(TenantSource._issuerUrl))) m.setIssuerUrl(d.getIssuerUrl());
if (fields.hasField(this.asIndexer(TenantSource._clientId))) m.setClientId(d.getClientId());
if (fields.hasField(this.asIndexer(TenantSource._clientSecret))) m.setClientSecret(d.getClientSecret());
if (fields.hasField(this.asIndexer(TenantSource._scope))) m.setScope(d.getScope());
models.add(m);
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models;
}
}

View File

@ -1,11 +1,10 @@
package gr.cite.notification.model.builder.tenantconfig; package gr.cite.notification.model.builder.tenantconfiguration;
import gr.cite.notification.authorization.AuthorizationFlags; import gr.cite.notification.authorization.AuthorizationFlags;
import gr.cite.notification.common.types.tenant.TenantFileTransformersConfigEntity; import gr.cite.notification.common.types.tenantconfiguration.DefaultUserLocaleTenantConfigurationEntity;
import gr.cite.notification.convention.ConventionService; import gr.cite.notification.convention.ConventionService;
import gr.cite.notification.model.builder.BaseBuilder; import gr.cite.notification.model.builder.BaseBuilder;
import gr.cite.notification.model.tenantconfig.TenantFileTransformersConfig; import gr.cite.notification.model.tenantconfiguration.DefaultUserLocaleTenantConfiguration;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.exception.MyApplicationException; import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.FieldSet; import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry; import gr.cite.tools.logging.DataLogEntry;
@ -20,39 +19,33 @@ import java.util.*;
@Component @Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class TenantFileTransformersBuilder extends BaseBuilder<TenantFileTransformersConfig, TenantFileTransformersConfigEntity> { public class DefaultUserLocaleTenantConfigurationBuilder extends BaseBuilder<DefaultUserLocaleTenantConfiguration, DefaultUserLocaleTenantConfigurationEntity> {
private final BuilderFactory builderFactory;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None); private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired @Autowired
public TenantFileTransformersBuilder( public DefaultUserLocaleTenantConfigurationBuilder(
ConventionService conventionService, BuilderFactory builderFactory) { ConventionService conventionService) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(TenantFileTransformersBuilder.class))); super(conventionService, new LoggerService(LoggerFactory.getLogger(DefaultUserLocaleTenantConfigurationBuilder.class)));
this.builderFactory = builderFactory;
} }
public TenantFileTransformersBuilder authorize(EnumSet<AuthorizationFlags> values) { public DefaultUserLocaleTenantConfigurationBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values; this.authorize = values;
return this; return this;
} }
@Override @Override
public List<TenantFileTransformersConfig> build(FieldSet fields, List<TenantFileTransformersConfigEntity> data) throws MyApplicationException { public List<DefaultUserLocaleTenantConfiguration> build(FieldSet fields, List<DefaultUserLocaleTenantConfigurationEntity> data) throws MyApplicationException {
this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0)); this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0));
this.logger.trace(new DataLogEntry("requested fields", fields)); this.logger.trace(new DataLogEntry("requested fields", fields));
if (fields == null || data == null || fields.isEmpty()) if (fields == null || data == null || fields.isEmpty())
return new ArrayList<>(); return new ArrayList<>();
FieldSet sourcesFields = fields.extractPrefixed(this.asPrefix(TenantFileTransformersConfig._sources)); List<DefaultUserLocaleTenantConfiguration> models = new ArrayList<>();
for (DefaultUserLocaleTenantConfigurationEntity d : data) {
List<TenantFileTransformersConfig> models = new ArrayList<>(); DefaultUserLocaleTenantConfiguration m = new DefaultUserLocaleTenantConfiguration();
for (TenantFileTransformersConfigEntity d : data) { if (fields.hasField(this.asIndexer(DefaultUserLocaleTenantConfiguration._culture))) m.setCulture(d.getCulture());
TenantFileTransformersConfig m = new TenantFileTransformersConfig(); if (fields.hasField(this.asIndexer(DefaultUserLocaleTenantConfiguration._timezone))) m.setTimezone(d.getTimezone());
if (!sourcesFields.isEmpty() && d.getSources() != null) { if (fields.hasField(this.asIndexer(DefaultUserLocaleTenantConfiguration._language))) m.setLanguage(d.getLanguage());
m.setSources(this.builderFactory.builder(TenantSourceBuilder.class).authorize(this.authorize).build(sourcesFields, d.getSources()));
}
models.add(m); models.add(m);
} }
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));

View File

@ -1,11 +1,10 @@
package gr.cite.notification.model.builder.tenantconfig; package gr.cite.notification.model.builder.tenantconfiguration;
import gr.cite.notification.authorization.AuthorizationFlags; import gr.cite.notification.authorization.AuthorizationFlags;
import gr.cite.notification.common.types.tenant.TenantDepositConfigEntity; import gr.cite.notification.common.types.tenantconfiguration.NotifierListTenantConfigurationEntity;
import gr.cite.notification.convention.ConventionService; import gr.cite.notification.convention.ConventionService;
import gr.cite.notification.model.builder.BaseBuilder; import gr.cite.notification.model.builder.BaseBuilder;
import gr.cite.notification.model.tenantconfig.TenantDepositConfig; import gr.cite.notification.model.tenantconfiguration.NotifierListTenantConfiguration;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.exception.MyApplicationException; import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.FieldSet; import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry; import gr.cite.tools.logging.DataLogEntry;
@ -20,39 +19,31 @@ import java.util.*;
@Component @Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class TenantDepositConfigBuilder extends BaseBuilder<TenantDepositConfig, TenantDepositConfigEntity> { public class NotifierListTenantConfigurationBuilder extends BaseBuilder<NotifierListTenantConfiguration, NotifierListTenantConfigurationEntity> {
private final BuilderFactory builderFactory;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None); private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired @Autowired
public TenantDepositConfigBuilder( public NotifierListTenantConfigurationBuilder(
ConventionService conventionService, BuilderFactory builderFactory) { ConventionService conventionService) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(TenantDepositConfigBuilder.class))); super(conventionService, new LoggerService(LoggerFactory.getLogger(NotifierListTenantConfigurationBuilder.class)));
this.builderFactory = builderFactory;
} }
public TenantDepositConfigBuilder authorize(EnumSet<AuthorizationFlags> values) { public NotifierListTenantConfigurationBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values; this.authorize = values;
return this; return this;
} }
@Override @Override
public List<TenantDepositConfig> build(FieldSet fields, List<TenantDepositConfigEntity> data) throws MyApplicationException { public List<NotifierListTenantConfiguration> build(FieldSet fields, List<NotifierListTenantConfigurationEntity> data) throws MyApplicationException {
this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0)); this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0));
this.logger.trace(new DataLogEntry("requested fields", fields)); this.logger.trace(new DataLogEntry("requested fields", fields));
if (fields == null || data == null || fields.isEmpty()) if (fields == null || data == null || fields.isEmpty())
return new ArrayList<>(); return new ArrayList<>();
FieldSet sourcesFields = fields.extractPrefixed(this.asPrefix(TenantDepositConfig._sources)); List<NotifierListTenantConfiguration> models = new ArrayList<>();
for (NotifierListTenantConfigurationEntity d : data) {
List<TenantDepositConfig> models = new ArrayList<>(); NotifierListTenantConfiguration m = new NotifierListTenantConfiguration();
for (TenantDepositConfigEntity d : data) { if (fields.hasField(this.asIndexer(NotifierListTenantConfiguration._notifiers))) m.setNotifiers(d.getNotifiers());
TenantDepositConfig m = new TenantDepositConfig();
if (!sourcesFields.isEmpty() && d.getSources() != null) {
m.setSources(this.builderFactory.builder(TenantSourceBuilder.class).authorize(this.authorize).build(sourcesFields, d.getSources()));
}
models.add(m); models.add(m);
} }
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));

View File

@ -0,0 +1,84 @@
package gr.cite.notification.model.builder.tenantconfiguration;
import gr.cite.notification.authorization.AuthorizationFlags;
import gr.cite.notification.common.JsonHandlingService;
import gr.cite.notification.common.enums.TenantConfigurationType;
import gr.cite.notification.common.scope.tenant.TenantScope;
import gr.cite.notification.common.types.tenantconfiguration.DefaultUserLocaleTenantConfigurationEntity;
import gr.cite.notification.common.types.tenantconfiguration.NotifierListTenantConfigurationEntity;
import gr.cite.notification.convention.ConventionService;
import gr.cite.notification.data.TenantConfigurationEntity;
import gr.cite.notification.model.builder.BaseBuilder;
import gr.cite.notification.model.tenantconfiguration.TenantConfiguration;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.*;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class TenantConfigurationBuilder extends BaseBuilder<TenantConfiguration, TenantConfigurationEntity> {
private final TenantScope tenantScope;
private final JsonHandlingService jsonHandlingService;
private final BuilderFactory builderFactory;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
public TenantConfigurationBuilder(
ConventionService conventionService,
TenantScope tenantScope, JsonHandlingService jsonHandlingService, BuilderFactory builderFactory1) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(TenantConfigurationBuilder.class)));
this.tenantScope = tenantScope;
this.jsonHandlingService = jsonHandlingService;
this.builderFactory = builderFactory1;
}
public TenantConfigurationBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
public List<TenantConfiguration> build(FieldSet fields, List<TenantConfigurationEntity> data) throws MyApplicationException {
this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0));
this.logger.trace(new DataLogEntry("requested fields", fields));
if (fields == null || data == null || fields.isEmpty())
return new ArrayList<>();
FieldSet notifierListFields = fields.extractPrefixed(this.asPrefix(TenantConfiguration._notifierList));
FieldSet defaultUserLocaleFields = fields.extractPrefixed(this.asPrefix(TenantConfiguration._defaultUserLocale));
List<TenantConfiguration> models = new ArrayList<>();
for (TenantConfigurationEntity d : data) {
TenantConfiguration m = new TenantConfiguration();
if (fields.hasField(this.asIndexer(TenantConfiguration._id))) m.setId(d.getId());
if (fields.hasField(this.asIndexer(TenantConfiguration._type))) m.setType(d.getType());
if (!notifierListFields.isEmpty() && !this.conventionService.isNullOrEmpty(d.getValue()) && TenantConfigurationType.NotifierList.equals(d.getType())){
NotifierListTenantConfigurationEntity valueTyped = this.jsonHandlingService.fromJsonSafe(NotifierListTenantConfigurationEntity.class, d.getValue());
m.setNotifierList(this.builderFactory.builder(NotifierListTenantConfigurationBuilder.class).authorize(this.authorize).build(notifierListFields, valueTyped));
}
if (!defaultUserLocaleFields.isEmpty() && !this.conventionService.isNullOrEmpty(d.getValue()) && TenantConfigurationType.DefaultUserLocale.equals(d.getType())){
DefaultUserLocaleTenantConfigurationEntity valueTyped = this.jsonHandlingService.fromJsonSafe(DefaultUserLocaleTenantConfigurationEntity.class, d.getValue());
m.setDefaultUserLocale(this.builderFactory.builder(DefaultUserLocaleTenantConfigurationBuilder.class).authorize(this.authorize).build(defaultUserLocaleFields, valueTyped));
}
if (fields.hasField(this.asIndexer(TenantConfiguration._createdAt))) m.setCreatedAt(d.getCreatedAt());
if (fields.hasField(this.asIndexer(TenantConfiguration._updatedAt))) m.setUpdatedAt(d.getUpdatedAt());
if (fields.hasField(this.asIndexer(TenantConfiguration._isActive))) m.setIsActive(d.getIsActive());
if (fields.hasField(this.asIndexer(TenantConfiguration._hash))) m.setHash(this.hashValue(d.getUpdatedAt()));
if (fields.hasField(this.asIndexer(TenantConfiguration._belongsToCurrentTenant))) m.setBelongsToCurrentTenant(this.getBelongsToCurrentTenant(d, this.tenantScope));
models.add(m);
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models;
}
}

View File

@ -1,32 +0,0 @@
package gr.cite.notification.model.censorship;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.notification.authorization.Permission;
import gr.cite.notification.convention.ConventionService;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class TenantConfigurationCensor extends BaseCensor {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(TenantConfigurationCensor.class));
private final AuthorizationService authService;
@Autowired
public TenantConfigurationCensor(ConventionService conventionService, AuthorizationService authService) {
super(conventionService);
this.authService = authService;
}
public void censor(FieldSet fields) {
logger.debug(new DataLogEntry("censoring fields", fields));
if (this.isEmpty(fields)) return;
this.authService.authorizeForce(Permission.BrowseTenantConfiguration);
}
}

View File

@ -0,0 +1,38 @@
package gr.cite.notification.model.censorship.tenantconfiguration;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.notification.authorization.Permission;
import gr.cite.notification.convention.ConventionService;
import gr.cite.notification.model.censorship.BaseCensor;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.UUID;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class DefaultUserLocaleTenantConfigurationCensor extends BaseCensor {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DefaultUserLocaleTenantConfigurationCensor.class));
protected final AuthorizationService authService;
public DefaultUserLocaleTenantConfigurationCensor(ConventionService conventionService, AuthorizationService authService) {
super(conventionService);
this.authService = authService;
}
public void censor(FieldSet fields, UUID userId) {
logger.debug(new DataLogEntry("censoring fields", fields));
if (fields == null || fields.isEmpty())
return;
this.authService.authorize(Permission.BrowseTenantConfiguration);
}
}

View File

@ -0,0 +1,38 @@
package gr.cite.notification.model.censorship.tenantconfiguration;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.notification.authorization.Permission;
import gr.cite.notification.convention.ConventionService;
import gr.cite.notification.model.censorship.BaseCensor;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.UUID;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class NotifierListTenantConfigurationCensor extends BaseCensor {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(NotifierListTenantConfigurationCensor.class));
protected final AuthorizationService authService;
public NotifierListTenantConfigurationCensor(ConventionService conventionService, AuthorizationService authService) {
super(conventionService);
this.authService = authService;
}
public void censor(FieldSet fields, UUID userId) {
logger.debug(new DataLogEntry("censoring fields", fields));
if (fields == null || fields.isEmpty())
return;
this.authService.authorize(Permission.BrowseTenantConfiguration);
}
}

View File

@ -0,0 +1,49 @@
package gr.cite.notification.model.censorship.tenantconfiguration;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.notification.authorization.Permission;
import gr.cite.notification.convention.ConventionService;
import gr.cite.notification.model.censorship.BaseCensor;
import gr.cite.tools.data.censor.CensorFactory;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import gr.cite.notification.model.tenantconfiguration.TenantConfiguration;
import java.util.UUID;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class TenantConfigurationCensor extends BaseCensor {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(TenantConfigurationCensor.class));
protected final AuthorizationService authService;
protected final CensorFactory censorFactory;
public TenantConfigurationCensor(ConventionService conventionService, AuthorizationService authService, CensorFactory censorFactory) {
super(conventionService);
this.authService = authService;
this.censorFactory = censorFactory;
}
public void censor(FieldSet fields, UUID userId) {
logger.debug(new DataLogEntry("censoring fields", fields));
if (fields == null || fields.isEmpty())
return;
this.authService.authorize(Permission.BrowseTenantConfiguration);
FieldSet cssColorsFields = fields.extractPrefixed(this.asIndexerPrefix(TenantConfiguration._notifierList));
this.censorFactory.censor(NotifierListTenantConfigurationCensor.class).censor(cssColorsFields, userId);
FieldSet defaultUserLocaleFields = fields.extractPrefixed(this.asIndexerPrefix(TenantConfiguration._defaultUserLocale));
this.censorFactory.censor(DefaultUserLocaleTenantConfigurationCensor.class).censor(defaultUserLocaleFields, userId);
}
}

View File

@ -29,17 +29,14 @@ public class TenantConfigurationDeleter implements Deleter {
private final TenantEntityManager entityManager; private final TenantEntityManager entityManager;
protected final QueryFactory queryFactory; protected final QueryFactory queryFactory;
private final DeleterFactory deleterFactory;
@Autowired @Autowired
public TenantConfigurationDeleter( public TenantConfigurationDeleter(
TenantEntityManager entityManager, TenantEntityManager entityManager,
QueryFactory queryFactory, QueryFactory queryFactory
DeleterFactory deleterFactory
) { ) {
this.entityManager = entityManager; this.entityManager = entityManager;
this.queryFactory = queryFactory; this.queryFactory = queryFactory;
this.deleterFactory = deleterFactory;
} }
public void deleteAndSaveByIds(List<UUID> ids) throws InvalidApplicationException { public void deleteAndSaveByIds(List<UUID> ids) throws InvalidApplicationException {
@ -61,7 +58,7 @@ public class TenantConfigurationDeleter implements Deleter {
logger.debug("will delete {} items", Optional.ofNullable(datas).map(List::size).orElse(0)); logger.debug("will delete {} items", Optional.ofNullable(datas).map(List::size).orElse(0));
if (datas == null || datas.isEmpty()) return; if (datas == null || datas.isEmpty()) return;
List<UUID> ids = datas.stream().map(TenantConfigurationEntity::getId).distinct().collect(Collectors.toList()); List<UUID> ids = datas.stream().map(TenantConfigurationEntity::getId).distinct().toList();
Instant now = Instant.now(); Instant now = Instant.now();

View File

@ -0,0 +1,82 @@
package gr.cite.notification.model.persist.tenantconfiguration;
import gr.cite.notification.common.validation.BaseValidator;
import gr.cite.notification.convention.ConventionService;
import gr.cite.notification.errorcode.ErrorThesaurusProperties;
import gr.cite.tools.validation.specification.Specification;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
public class DefaultUserLocaleTenantConfigurationPersist {
private String timezone;
public static final String _timezone = "timezone";
private String language;
public static final String _language = "language";
private String culture;
public static final String _culture = "culture";
public String getTimezone() {
return timezone;
}
public void setTimezone(String timezone) {
this.timezone = timezone;
}
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
}
public String getCulture() {
return culture;
}
public void setCulture(String culture) {
this.culture = culture;
}
@Component(DefaultUserLocaleTenantConfigurationPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class DefaultUserLocaleTenantConfigurationPersistValidator extends BaseValidator<DefaultUserLocaleTenantConfigurationPersist> {
public static final String ValidatorName = "DefaultUserLocaleTenantConfigurationPersistValidator";
private final MessageSource messageSource;
protected DefaultUserLocaleTenantConfigurationPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors);
this.messageSource = messageSource;
}
@Override
protected Class<DefaultUserLocaleTenantConfigurationPersist> modelClass() {
return DefaultUserLocaleTenantConfigurationPersist.class;
}
@Override
protected List<Specification> specifications(DefaultUserLocaleTenantConfigurationPersist item) {
return Arrays.asList(
this.spec()
.must(() -> !this.isEmpty(item.getTimezone()))
.failOn(DefaultUserLocaleTenantConfigurationPersist._timezone).failWith(messageSource.getMessage("Validation_Required", new Object[]{DefaultUserLocaleTenantConfigurationPersist._timezone}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getLanguage()))
.failOn(DefaultUserLocaleTenantConfigurationPersist._language).failWith(messageSource.getMessage("Validation_Required", new Object[]{DefaultUserLocaleTenantConfigurationPersist._language}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getCulture()))
.failOn(DefaultUserLocaleTenantConfigurationPersist._culture).failWith(messageSource.getMessage("Validation_Required", new Object[]{DefaultUserLocaleTenantConfigurationPersist._culture}, LocaleContextHolder.getLocale()))
);
}
}
}

View File

@ -0,0 +1,54 @@
package gr.cite.notification.model.persist.tenantconfiguration;
import gr.cite.notification.common.enums.NotificationContactType;
import gr.cite.notification.common.validation.BaseValidator;
import gr.cite.notification.convention.ConventionService;
import gr.cite.notification.errorcode.ErrorThesaurusProperties;
import gr.cite.tools.validation.specification.Specification;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import java.util.*;
public class NotifierListTenantConfigurationPersist {
private Map<UUID, List<NotificationContactType>> notifiers;
public static final String _notifiers = "notifiers";
public Map<UUID, List<NotificationContactType>> getNotifiers() {
return notifiers;
}
public void setNotifiers(Map<UUID, List<NotificationContactType>> notifiers) {
this.notifiers = notifiers;
}
@Component(NotifierListTenantConfigurationPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class NotifierListTenantConfigurationPersistValidator extends BaseValidator<NotifierListTenantConfigurationPersist> {
public static final String ValidatorName = "NotifierListTenantConfigurationPersistValidator";
private final MessageSource messageSource;
protected NotifierListTenantConfigurationPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors);
this.messageSource = messageSource;
}
@Override
protected Class<NotifierListTenantConfigurationPersist> modelClass() {
return NotifierListTenantConfigurationPersist.class;
}
@Override
protected List<Specification> specifications(NotifierListTenantConfigurationPersist item) {
return Collections.singletonList(
this.spec()
.must(() -> !this.isNull(item.getNotifiers()))
.failOn(NotifierListTenantConfigurationPersist._notifiers).failWith(messageSource.getMessage("Validation_Required", new Object[]{NotifierListTenantConfigurationPersist._notifiers}, LocaleContextHolder.getLocale()))
);
}
}
}

View File

@ -1,177 +0,0 @@
package gr.cite.notification.model.persist.tenantconfiguration;
import gr.cite.notification.common.validation.BaseValidator;
import gr.cite.notification.convention.ConventionService;
import gr.cite.notification.errorcode.ErrorThesaurusProperties;
import gr.cite.tools.validation.specification.Specification;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
public class TenantConfigurationEmailClientPersist {
private UUID id;
public static final String _id = "id";
private Boolean requireCredentials;
public static final String _requireCredentials = "requireCredentials";
private Boolean enableSSL;
public static final String _enableSSL = "enableSSL";
private String certificatePath;
public static final String _certificatePath = "certificatePath";
private String hostServer;
public static final String _hostServer = "hostServer";
private Integer hostPortNo;
public static final String _hostPortNo = "hostPortNo";
private String emailAddress;
public static final String _emailAddress = "emailAddress";
private String emailUserName;
public static final String _emailUserName = "emailUserName";
private String emailPassword;
public static final String _emailPassword = "emailPassword";
private String hash;
public static final String _hash = "hash";
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public Boolean getRequireCredentials() {
return requireCredentials;
}
public void setRequireCredentials(Boolean requireCredentials) {
this.requireCredentials = requireCredentials;
}
public Boolean getEnableSSL() {
return enableSSL;
}
public void setEnableSSL(Boolean enableSSL) {
this.enableSSL = enableSSL;
}
public String getCertificatePath() {
return certificatePath;
}
public void setCertificatePath(String certificatePath) {
this.certificatePath = certificatePath;
}
public String getHostServer() {
return hostServer;
}
public void setHostServer(String hostServer) {
this.hostServer = hostServer;
}
public Integer getHostPortNo() {
return hostPortNo;
}
public void setHostPortNo(Integer hostPortNo) {
this.hostPortNo = hostPortNo;
}
public String getEmailAddress() {
return emailAddress;
}
public void setEmailAddress(String emailAddress) {
this.emailAddress = emailAddress;
}
public String getEmailUserName() {
return emailUserName;
}
public void setEmailUserName(String emailUserName) {
this.emailUserName = emailUserName;
}
public String getEmailPassword() {
return emailPassword;
}
public void setEmailPassword(String emailPassword) {
this.emailPassword = emailPassword;
}
public String getHash() {
return hash;
}
public void setHash(String hash) {
this.hash = hash;
}
@Component(TenantConfigurationEmailClientPersist.TenantConfigurationEmailClientPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class TenantConfigurationEmailClientPersistValidator extends BaseValidator<TenantConfigurationEmailClientPersist> {
public static final String ValidatorName = "TenantConfigurationEmailClientPersistValidator";
private final MessageSource messageSource;
protected TenantConfigurationEmailClientPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors);
this.messageSource = messageSource;
}
@Override
protected Class<TenantConfigurationEmailClientPersist> modelClass() {
return TenantConfigurationEmailClientPersist.class;
}
@Override
protected List<Specification> specifications(TenantConfigurationEmailClientPersist item) {
return Arrays.asList(
this.spec()
.iff(() -> this.isValidGuid(item.getId()))
.must(() -> this.isValidHash(item.getHash()))
.failOn(TenantConfigurationEmailClientPersist._hash).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationEmailClientPersist._hash}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isValidGuid(item.getId()))
.must(() -> !this.isValidHash(item.getHash()))
.failOn(TenantConfigurationEmailClientPersist._hash).failWith(messageSource.getMessage("Validation_OverPosting", new Object[]{}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getRequireCredentials()))
.failOn(TenantConfigurationEmailClientPersist._requireCredentials).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationEmailClientPersist._requireCredentials}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getEnableSSL()))
.failOn(TenantConfigurationEmailClientPersist._enableSSL).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationEmailClientPersist._enableSSL}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getCertificatePath()))
.failOn(TenantConfigurationEmailClientPersist._certificatePath).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationEmailClientPersist._certificatePath}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getHostServer()))
.failOn(TenantConfigurationEmailClientPersist._hostServer).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationEmailClientPersist._hostServer}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getHostPortNo()))
.failOn(TenantConfigurationEmailClientPersist._hostPortNo).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationEmailClientPersist._hostPortNo}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getEmailAddress()))
.failOn(TenantConfigurationEmailClientPersist._emailAddress).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationEmailClientPersist._emailAddress}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getEmailUserName()))
.failOn(TenantConfigurationEmailClientPersist._emailUserName).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationEmailClientPersist._emailUserName}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getEmailPassword()))
.failOn(TenantConfigurationEmailClientPersist._emailPassword).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationEmailClientPersist._emailPassword}, LocaleContextHolder.getLocale()))
);
}
}
}

View File

@ -1,86 +0,0 @@
package gr.cite.notification.model.persist.tenantconfiguration;
import gr.cite.notification.common.enums.NotificationContactType;
import gr.cite.notification.common.validation.BaseValidator;
import gr.cite.notification.convention.ConventionService;
import gr.cite.notification.errorcode.ErrorThesaurusProperties;
import gr.cite.tools.validation.specification.Specification;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.UUID;
public class TenantConfigurationNotifierListPersist {
private UUID id;
public static final String _id = "id";
private Map<UUID, List<NotificationContactType>> notifiers;
public static final String _notifiers = "notifiers";
private String hash;
public static final String _hash = "hash";
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public Map<UUID, List<NotificationContactType>> getNotifiers() {
return notifiers;
}
public void setNotifiers(Map<UUID, List<NotificationContactType>> notifiers) {
this.notifiers = notifiers;
}
public String getHash() {
return hash;
}
public void setHash(String hash) {
this.hash = hash;
}
@Component(TenantConfigurationNotifierListPersist.TenantConfigurationNotifierListPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class TenantConfigurationNotifierListPersistValidator extends BaseValidator<TenantConfigurationNotifierListPersist> {
public static final String ValidatorName = "TenantConfigurationNotifierListPersistValidator";
private final MessageSource messageSource;
protected TenantConfigurationNotifierListPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors);
this.messageSource = messageSource;
}
@Override
protected Class<TenantConfigurationNotifierListPersist> modelClass() {
return TenantConfigurationNotifierListPersist.class;
}
@Override
protected List<Specification> specifications(TenantConfigurationNotifierListPersist item) {
return Arrays.asList(
this.spec()
.iff(() -> this.isValidGuid(item.getId()))
.must(() -> this.isValidHash(item.getHash()))
.failOn(TenantConfigurationNotifierListPersist._hash).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationNotifierListPersist._hash}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isValidGuid(item.getId()))
.must(() -> !this.isValidHash(item.getHash()))
.failOn(TenantConfigurationNotifierListPersist._hash).failWith(messageSource.getMessage("Validation_OverPosting", new Object[]{}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getNotifiers()))
.failOn(TenantConfigurationNotifierListPersist._notifiers).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationNotifierListPersist._notifiers}, LocaleContextHolder.getLocale()))
);
}
}
}

View File

@ -0,0 +1,142 @@
package gr.cite.notification.model.persist.tenantconfiguration;
import gr.cite.notification.common.enums.TenantConfigurationType;
import gr.cite.notification.common.validation.BaseValidator;
import gr.cite.notification.convention.ConventionService;
import gr.cite.notification.errorcode.ErrorThesaurusProperties;
import gr.cite.tools.validation.ValidatorFactory;
import gr.cite.tools.validation.specification.Specification;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
public class TenantConfigurationPersist {
private UUID id;
public static final String _id = "id";
private TenantConfigurationType type;
public static final String _type = "type";
private NotifierListTenantConfigurationPersist notifierList;
public static final String _notifierList = "notifierList";
private DefaultUserLocaleTenantConfigurationPersist defaultUserLocale;
public static final String _defaultUserLocale = "defaultUserLocale";
private String hash;
public static final String _hash = "hash";
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public NotifierListTenantConfigurationPersist getNotifierList() {
return notifierList;
}
public void setNotifierList(NotifierListTenantConfigurationPersist notifierList) {
this.notifierList = notifierList;
}
public DefaultUserLocaleTenantConfigurationPersist getDefaultUserLocale() {
return defaultUserLocale;
}
public void setDefaultUserLocale(DefaultUserLocaleTenantConfigurationPersist defaultUserLocale) {
this.defaultUserLocale = defaultUserLocale;
}
public String getHash() {
return hash;
}
public void setHash(String hash) {
this.hash = hash;
}
public TenantConfigurationType getType() {
return type;
}
public void setType(TenantConfigurationType type) {
this.type = type;
}
@Component(TenantConfigurationPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class TenantConfigurationPersistValidator extends BaseValidator<TenantConfigurationPersist> {
public static final String ValidatorName = "TenantConfigurationPersistValidator";
private final MessageSource messageSource;
private final ValidatorFactory validatorFactory;
protected TenantConfigurationPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) {
super(conventionService, errors);
this.messageSource = messageSource;
this.validatorFactory = validatorFactory;
}
@Override
protected Class<TenantConfigurationPersist> modelClass() {
return TenantConfigurationPersist.class;
}
@Override
protected List<Specification> specifications(TenantConfigurationPersist item) {
return Arrays.asList(
this.spec()
.iff(() -> this.isValidGuid(item.getId()))
.must(() -> this.isValidHash(item.getHash()))
.failOn(TenantConfigurationPersist._hash).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationPersist._hash}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isValidGuid(item.getId()))
.must(() -> !this.isValidHash(item.getHash()))
.failOn(TenantConfigurationPersist._hash).failWith(messageSource.getMessage("Validation_OverPosting", new Object[]{}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getType()))
.failOn(TenantConfigurationPersist._type).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationPersist._type}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isNull(item.getType()) && TenantConfigurationType.DefaultUserLocale.equals(item.getType()))
.must(() -> !this.isNull(item.getDefaultUserLocale()))
.failOn(TenantConfigurationPersist._defaultUserLocale).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationPersist._defaultUserLocale}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isNull(item.getType()) && TenantConfigurationType.NotifierList.equals(item.getType()))
.must(() -> !this.isNull(item.getNotifierList()))
.failOn(TenantConfigurationPersist._notifierList).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationPersist._notifierList}, LocaleContextHolder.getLocale())),
this.refSpec()
.iff(() -> !this.isNull(item.getDefaultUserLocale()) && TenantConfigurationType.DefaultUserLocale.equals(item.getType()))
.on(TenantConfigurationPersist._defaultUserLocale)
.over(item.getDefaultUserLocale())
.using(() -> this.validatorFactory.validator(DefaultUserLocaleTenantConfigurationPersist.DefaultUserLocaleTenantConfigurationPersistValidator.class)),
this.refSpec()
.iff(() -> !this.isNull(item.getNotifierList()) && TenantConfigurationType.NotifierList.equals(item.getType()))
.on(TenantConfigurationPersist._notifierList)
.over(item.getNotifierList())
.using(() -> this.validatorFactory.validator(NotifierListTenantConfigurationPersist.NotifierListTenantConfigurationPersistValidator.class))
);
}
}
}

View File

@ -1,92 +0,0 @@
package gr.cite.notification.model.persist.tenantconfiguration;
import gr.cite.notification.common.validation.BaseValidator;
import gr.cite.notification.convention.ConventionService;
import gr.cite.notification.errorcode.ErrorThesaurusProperties;
import gr.cite.tools.validation.specification.Specification;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
public class TenantConfigurationUserLocaleIntegrationPersist {
private String language;
public static final String _language = "language";
private String timeZone;
public static final String _timeZone = "timeZone";
private String culture;
public static final String _culture = "culture";
private String hash;
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
}
public String getTimeZone() {
return timeZone;
}
public void setTimeZone(String timeZone) {
this.timeZone = timeZone;
}
public String getCulture() {
return culture;
}
public void setCulture(String culture) {
this.culture = culture;
}
public String getHash() {
return hash;
}
public void setHash(String hash) {
this.hash = hash;
}
@Component(TenantConfigurationUserLocaleIntegrationPersist.TenantConfigurationUserLocaleIntegrationPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class TenantConfigurationUserLocaleIntegrationPersistValidator extends BaseValidator<TenantConfigurationUserLocaleIntegrationPersist> {
public static final String ValidatorName = "TenantConfigurationUserLocaleIntegrationPersistValidator";
private final MessageSource messageSource;
protected TenantConfigurationUserLocaleIntegrationPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors);
this.messageSource = messageSource;
}
@Override
protected Class<TenantConfigurationUserLocaleIntegrationPersist> modelClass() {
return TenantConfigurationUserLocaleIntegrationPersist.class;
}
@Override
protected List<Specification> specifications(TenantConfigurationUserLocaleIntegrationPersist item) {
return Arrays.asList(
this.spec()
.must(() -> !this.isNull(item.getLanguage()))
.failOn(TenantConfigurationUserLocaleIntegrationPersist._language).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationUserLocaleIntegrationPersist._language}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getTimeZone()))
.failOn(TenantConfigurationUserLocaleIntegrationPersist._timeZone).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationUserLocaleIntegrationPersist._timeZone}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getCulture()))
.failOn(TenantConfigurationUserLocaleIntegrationPersist._culture).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationUserLocaleIntegrationPersist._culture}, LocaleContextHolder.getLocale()))
);
}
}
}

View File

@ -1,28 +0,0 @@
package gr.cite.notification.model.tenantconfig;
public class TenantConfig {
public static final String _deposit = "deposit";
private TenantDepositConfig deposit;
public static final String _fileTransformers = "fileTransformers";
private TenantFileTransformersConfig fileTransformers;
public TenantDepositConfig getDeposit() {
return deposit;
}
public void setDeposit(TenantDepositConfig deposit) {
this.deposit = deposit;
}
public TenantFileTransformersConfig getFileTransformers() {
return fileTransformers;
}
public void setFileTransformers(TenantFileTransformersConfig fileTransformers) {
this.fileTransformers = fileTransformers;
}
}

View File

@ -1,17 +0,0 @@
package gr.cite.notification.model.tenantconfig;
import java.util.List;
public class TenantDepositConfig {
public static final String _sources = "sources";
private List<TenantSource> sources;
public List<TenantSource> getSources() {
return sources;
}
public void setSources(List<TenantSource> sources) {
this.sources = sources;
}
}

View File

@ -1,17 +0,0 @@
package gr.cite.notification.model.tenantconfig;
import java.util.List;
public class TenantFileTransformersConfig {
public static final String _sources = "sources";
private List<TenantSource> sources;
public List<TenantSource> getSources() {
return sources;
}
public void setSources(List<TenantSource> sources) {
this.sources = sources;
}
}

View File

@ -1,73 +0,0 @@
package gr.cite.notification.model.tenantconfig;
import java.util.List;
public class TenantSource {
public static final String _url = "url";
private String url;
public static final String _codes = "codes";
private List<String> codes;
public static final String _issuerUrl = "issuerUrl";
private String issuerUrl;
public static final String _clientId = "clientId";
private String clientId;
public static final String _clientSecret = "clientSecret";
private String clientSecret;
public static final String _scope = "scope";
private String scope;
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public List<String> getCodes() {
return codes;
}
public void setCodes(List<String> codes) {
this.codes = codes;
}
public String getIssuerUrl() {
return issuerUrl;
}
public void setIssuerUrl(String issuerUrl) {
this.issuerUrl = issuerUrl;
}
public String getClientId() {
return clientId;
}
public void setClientId(String clientId) {
this.clientId = clientId;
}
public String getClientSecret() {
return clientSecret;
}
public void setClientSecret(String clientSecret) {
this.clientSecret = clientSecret;
}
public String getScope() {
return scope;
}
public void setScope(String scope) {
this.scope = scope;
}
}

View File

@ -0,0 +1,35 @@
package gr.cite.notification.model.tenantconfiguration;
public class DefaultUserLocaleTenantConfiguration {
private String timezone;
public static final String _timezone = "timezone";
private String language;
public static final String _language = "language";
private String culture;
public static final String _culture = "culture";
public String getTimezone() {
return timezone;
}
public void setTimezone(String timezone) {
this.timezone = timezone;
}
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
}
public String getCulture() {
return culture;
}
public void setCulture(String culture) {
this.culture = culture;
}
}

View File

@ -0,0 +1,21 @@
package gr.cite.notification.model.tenantconfiguration;
import gr.cite.notification.common.enums.NotificationContactType;
import java.util.List;
import java.util.Map;
import java.util.UUID;
public class NotifierListTenantConfiguration {
private Map<UUID, List<NotificationContactType>> notifiers;
public static final String _notifiers = "notifiers";
public Map<UUID, List<NotificationContactType>> getNotifiers() {
return notifiers;
}
public void setNotifiers(Map<UUID, List<NotificationContactType>> notifiers) {
this.notifiers = notifiers;
}
}

View File

@ -0,0 +1,118 @@
package gr.cite.notification.model.tenantconfiguration;
import gr.cite.notification.common.enums.IsActive;
import gr.cite.notification.common.enums.TenantConfigurationType;
import gr.cite.notification.common.types.tenantconfiguration.NotifierListTenantConfigurationEntity;
import java.time.Instant;
import java.util.UUID;
public class TenantConfiguration {
private UUID id;
public static final String _id = "id";
private TenantConfigurationType type;
public static final String _type = "type";
private Instant createdAt;
public static final String _createdAt = "createdAt";
private NotifierListTenantConfiguration notifierList;
public static final String _notifierList = "notifierList";
private DefaultUserLocaleTenantConfiguration defaultUserLocale;
public static final String _defaultUserLocale = "defaultUserLocale";
private Instant updatedAt;
public static final String _updatedAt = "updatedAt";
private IsActive isActive;
public static final String _isActive = "isActive";
private String hash;
public static final String _hash = "hash";
private Boolean belongsToCurrentTenant;
public static final String _belongsToCurrentTenant = "belongsToCurrentTenant";
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public Instant getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Instant createdAt) {
this.createdAt = createdAt;
}
public NotifierListTenantConfiguration getNotifierList() {
return notifierList;
}
public void setNotifierList(NotifierListTenantConfiguration notifierList) {
this.notifierList = notifierList;
}
public DefaultUserLocaleTenantConfiguration getDefaultUserLocale() {
return defaultUserLocale;
}
public void setDefaultUserLocale(DefaultUserLocaleTenantConfiguration defaultUserLocale) {
this.defaultUserLocale = defaultUserLocale;
}
public Instant getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(Instant updatedAt) {
this.updatedAt = updatedAt;
}
public IsActive getIsActive() {
return isActive;
}
public void setIsActive(IsActive isActive) {
this.isActive = isActive;
}
public String getHash() {
return hash;
}
public void setHash(String hash) {
this.hash = hash;
}
public Boolean getBelongsToCurrentTenant() {
return belongsToCurrentTenant;
}
public void setBelongsToCurrentTenant(Boolean belongsToCurrentTenant) {
this.belongsToCurrentTenant = belongsToCurrentTenant;
}
public TenantConfigurationType getType() {
return type;
}
public void setType(TenantConfigurationType type) {
this.type = type;
}
}

View File

@ -1,13 +1,15 @@
package gr.cite.notification.query; package gr.cite.notification.query;
import gr.cite.notification.authorization.AuthorizationFlags;
import gr.cite.notification.common.enums.IsActive; import gr.cite.notification.common.enums.IsActive;
import gr.cite.notification.common.enums.TenantConfigurationType; import gr.cite.notification.common.enums.TenantConfigurationType;
import gr.cite.notification.data.TenantConfigurationEntity; import gr.cite.notification.data.TenantConfigurationEntity;
import gr.cite.notification.model.TenantConfiguration; import gr.cite.notification.model.tenantconfiguration.TenantConfiguration;
import gr.cite.tools.data.query.FieldResolver; import gr.cite.tools.data.query.FieldResolver;
import gr.cite.tools.data.query.QueryBase; import gr.cite.tools.data.query.QueryBase;
import gr.cite.tools.data.query.QueryContext; import gr.cite.tools.data.query.QueryContext;
import jakarta.persistence.Tuple; import jakarta.persistence.Tuple;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.Predicate; import jakarta.persistence.criteria.Predicate;
import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
@ -20,45 +22,106 @@ import java.util.*;
@Scope(BeanDefinition.SCOPE_PROTOTYPE) @Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class TenantConfigurationQuery extends QueryBase<TenantConfigurationEntity> { public class TenantConfigurationQuery extends QueryBase<TenantConfigurationEntity> {
private List<UUID> ids; private Collection<UUID> ids;
private Collection<UUID> tenantIds;
private Boolean tenantIsSet;
private Collection<IsActive> isActives;
private Collection<TenantConfigurationType> types;
private Collection<UUID> excludedIds;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
private List<IsActive> isActives;
private List<TenantConfigurationType> type; public TenantConfigurationQuery() {
}
public TenantConfigurationQuery ids(UUID... ids) { public TenantConfigurationQuery ids(UUID value) {
this.ids = Arrays.asList(ids); this.ids = List.of(value);
return this; return this;
} }
public TenantConfigurationQuery ids(List<UUID> ids) { public TenantConfigurationQuery ids(UUID... value) {
this.ids = ids; this.ids = Arrays.asList(value);
return this; return this;
} }
public TenantConfigurationQuery isActive(IsActive... isActives) { public TenantConfigurationQuery ids(Collection<UUID> values) {
this.isActives = Arrays.asList(isActives); this.ids = values;
return this; return this;
} }
public TenantConfigurationQuery isActive(List<IsActive> isActive) { public TenantConfigurationQuery tenantIds(UUID value) {
this.isActives = isActive; this.tenantIds = List.of(value);
return this; return this;
} }
public TenantConfigurationQuery type(TenantConfigurationType... type) { public TenantConfigurationQuery tenantIds(UUID... value) {
this.type = Arrays.asList(type); this.tenantIds = Arrays.asList(value);
return this; return this;
} }
public TenantConfigurationQuery type(List<TenantConfigurationType> type) { public TenantConfigurationQuery tenantIds(Collection<UUID> values) {
this.type = type; this.tenantIds = values;
return this;
}
public TenantConfigurationQuery tenantIsSet(Boolean values) {
this.tenantIsSet = values;
return this;
}
public TenantConfigurationQuery isActive(IsActive value) {
this.isActives = List.of(value);
return this;
}
public TenantConfigurationQuery isActive(IsActive... value) {
this.isActives = Arrays.asList(value);
return this;
}
public TenantConfigurationQuery isActive(Collection<IsActive> values) {
this.isActives = values;
return this;
}
public TenantConfigurationQuery types(TenantConfigurationType value) {
this.types = List.of(value);
return this;
}
public TenantConfigurationQuery types(TenantConfigurationType... value) {
this.types = Arrays.asList(value);
return this;
}
public TenantConfigurationQuery types(Collection<TenantConfigurationType> values) {
this.types = values;
return this;
}
public TenantConfigurationQuery excludedIds(Collection<UUID> values) {
this.excludedIds = values;
return this;
}
public TenantConfigurationQuery excludedIds(UUID value) {
this.excludedIds = List.of(value);
return this;
}
public TenantConfigurationQuery excludedIds(UUID... value) {
this.excludedIds = Arrays.asList(value);
return this;
}
public TenantConfigurationQuery authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this; return this;
} }
@Override @Override
protected Boolean isFalseQuery() { protected Boolean isFalseQuery() {
return this.isEmpty(this.ids) || this.isEmpty(this.isActives); return this.isEmpty(this.ids) ||this.isEmpty(this.isActives) ||this.isEmpty(this.types) || this.isEmpty(this.tenantIds);
} }
@Override @Override
@ -70,15 +133,41 @@ public class TenantConfigurationQuery extends QueryBase<TenantConfigurationEntit
protected <X, Y> Predicate applyFilters(QueryContext<X, Y> queryContext) { protected <X, Y> Predicate applyFilters(QueryContext<X, Y> queryContext) {
List<Predicate> predicates = new ArrayList<>(); List<Predicate> predicates = new ArrayList<>();
if (this.ids != null) { if (this.ids != null) {
predicates.add(queryContext.Root.get(TenantConfigurationEntity._id).in(ids)); CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(TenantConfigurationEntity._id));
for (UUID item : this.ids) inClause.value(item);
predicates.add(inClause);
}
if (this.tenantIds != null) {
CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(TenantConfigurationEntity._tenantId));
for (UUID item : this.tenantIds) inClause.value(item);
predicates.add(inClause);
} }
if (this.isActives != null) { if (this.isActives != null) {
predicates.add(queryContext.Root.get(TenantConfigurationEntity._isActive).in(isActives)); CriteriaBuilder.In<IsActive> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(TenantConfigurationEntity._isActive));
for (IsActive item : this.isActives) inClause.value(item);
predicates.add(inClause);
} }
if (type != null) { if (this.tenantIsSet != null) {
predicates.add(queryContext.Root.get(TenantConfigurationEntity._type).in(type)); if (this.tenantIsSet) predicates.add(queryContext.CriteriaBuilder.isNotNull(queryContext.Root.get(TenantConfigurationEntity._tenantId)));
else predicates.add(queryContext.CriteriaBuilder.isNull(queryContext.Root.get(TenantConfigurationEntity._tenantId)));
}
if (this.types != null) {
CriteriaBuilder.In<TenantConfigurationType> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(TenantConfigurationEntity._type));
for (TenantConfigurationType item : this.types) inClause.value(item);
predicates.add(inClause);
}
if (this.excludedIds != null) {
CriteriaBuilder.In<UUID> notInClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(TenantConfigurationEntity._id));
for (UUID item : this.excludedIds)
notInClause.value(item);
predicates.add(notInClause.not());
} }
if (!predicates.isEmpty()) { if (!predicates.isEmpty()) {
@ -90,42 +179,31 @@ public class TenantConfigurationQuery extends QueryBase<TenantConfigurationEntit
} }
@Override
protected String fieldNameOf(FieldResolver item) {
if (item.match(TenantConfiguration._id))
return TenantConfigurationEntity._id;
else if (item.match(TenantConfiguration._tenantId))
return TenantConfigurationEntity._tenantId;
else if (item.match(TenantConfiguration._defaultUserLocaleData))
return TenantConfiguration._defaultUserLocaleData;
else if (item.match(TenantConfiguration._emailClientData))
return TenantConfiguration._emailClientData;
else if (item.match(TenantConfiguration._notifierListData))
return TenantConfiguration._notifierListData;
else if (item.match(TenantConfiguration._type))
return TenantConfigurationEntity._type;
else if (item.match(TenantConfiguration._value))
return TenantConfigurationEntity._value;
else if (item.match(TenantConfiguration._createdAt))
return TenantConfigurationEntity._createdAt;
else if (item.match(TenantConfiguration._updatedAt))
return TenantConfigurationEntity._updatedAt;
else if (item.match(TenantConfiguration._isActive))
return TenantConfigurationEntity._isActive;
else
return null;
}
@Override @Override
protected TenantConfigurationEntity convert(Tuple tuple, Set<String> columns) { protected TenantConfigurationEntity convert(Tuple tuple, Set<String> columns) {
TenantConfigurationEntity item = new TenantConfigurationEntity(); TenantConfigurationEntity item = new TenantConfigurationEntity();
item.setId(QueryBase.convertSafe(tuple, columns, TenantConfigurationEntity._id, UUID.class)); item.setId(QueryBase.convertSafe(tuple, columns, TenantConfigurationEntity._id, UUID.class));
item.setValue(QueryBase.convertSafe(tuple, columns, TenantConfigurationEntity._value, String.class)); item.setValue(QueryBase.convertSafe(tuple, columns, TenantConfigurationEntity._value, String.class));
item.setType(QueryBase.convertSafe(tuple, columns, TenantConfigurationEntity._type, TenantConfigurationType.class));
item.setTenantId(QueryBase.convertSafe(tuple, columns, TenantConfigurationEntity._tenantId, UUID.class)); item.setTenantId(QueryBase.convertSafe(tuple, columns, TenantConfigurationEntity._tenantId, UUID.class));
item.setType(QueryBase.convertSafe(tuple, columns, TenantConfigurationEntity._type, TenantConfigurationType.class));
item.setCreatedAt(QueryBase.convertSafe(tuple, columns, TenantConfigurationEntity._createdAt, Instant.class)); item.setCreatedAt(QueryBase.convertSafe(tuple, columns, TenantConfigurationEntity._createdAt, Instant.class));
item.setUpdatedAt(QueryBase.convertSafe(tuple, columns, TenantConfigurationEntity._updatedAt, Instant.class)); item.setUpdatedAt(QueryBase.convertSafe(tuple, columns, TenantConfigurationEntity._updatedAt, Instant.class));
item.setIsActive(QueryBase.convertSafe(tuple, columns, TenantConfigurationEntity._isActive, IsActive.class)); item.setIsActive(QueryBase.convertSafe(tuple, columns, TenantConfigurationEntity._isActive, IsActive.class));
return item; return item;
} }
@Override
protected String fieldNameOf(FieldResolver item) {
if (item.match(TenantConfiguration._id)) return TenantConfigurationEntity._id;
else if (item.match(TenantConfiguration._type)) return TenantConfigurationEntity._type;
else if (item.prefix(TenantConfiguration._notifierList)) return TenantConfigurationEntity._value;
else if (item.match(TenantConfiguration._notifierList)) return TenantConfigurationEntity._value;
else if (item.match(TenantConfiguration._createdAt)) return TenantConfigurationEntity._createdAt;
else if (item.match(TenantConfiguration._updatedAt)) return TenantConfigurationEntity._updatedAt;
else if (item.match(TenantConfiguration._isActive)) return TenantConfigurationEntity._isActive;
else if (item.match(TenantConfiguration._belongsToCurrentTenant)) return TenantConfigurationEntity._tenantId;
else if (item.match(TenantConfigurationEntity._tenantId)) return TenantConfigurationEntity._tenantId;
else return null;
}
} }

View File

@ -11,16 +11,21 @@ import java.util.List;
import java.util.UUID; import java.util.UUID;
public class TenantConfigurationLookup extends Lookup { public class TenantConfigurationLookup extends Lookup {
private List<UUID> ids;
private List<IsActive> isActives;
private List<TenantConfigurationType> type;
public List<IsActive> getIsActives() { private List<IsActive> isActive;
return isActives; private List<TenantConfigurationType> types;
private List<UUID> ids;
private List<UUID> tenantIds;
private List<UUID> excludedIds;
private Boolean tenantIsSet;
public List<IsActive> getIsActive() {
return isActive;
} }
public void setIsActives(List<IsActive> isActive) { public void setIsActive(List<IsActive> isActive) {
this.isActives = isActive; this.isActive = isActive;
} }
public List<UUID> getIds() { public List<UUID> getIds() {
@ -31,23 +36,49 @@ public class TenantConfigurationLookup extends Lookup {
this.ids = ids; this.ids = ids;
} }
public List<TenantConfigurationType> getType() { public List<UUID> getExcludedIds() {
return type; return excludedIds;
} }
public void setType(List<TenantConfigurationType> type) { public void setExcludedIds(List<UUID> excludeIds) {
this.type = type; this.excludedIds = excludeIds;
}
public List<TenantConfigurationType> getTypes() {
return types;
}
public void setTypes(List<TenantConfigurationType> types) {
this.types = types;
}
public List<UUID> getTenantIds() {
return tenantIds;
}
public void setTenantIds(List<UUID> tenantIds) {
this.tenantIds = tenantIds;
}
public Boolean getTenantIsSet() {
return tenantIsSet;
}
public void setTenantIsSet(Boolean tenantIsSet) {
this.tenantIsSet = tenantIsSet;
} }
public TenantConfigurationQuery enrich(QueryFactory queryFactory) { public TenantConfigurationQuery enrich(QueryFactory queryFactory) {
TenantConfigurationQuery query = queryFactory.query(TenantConfigurationQuery.class); TenantConfigurationQuery query = queryFactory.query(TenantConfigurationQuery.class);
if (this.isActives != null) query.isActive(this.isActives); if (this.types != null) query.types(this.types);
if (this.isActive != null) query.isActive(this.isActive);
if (this.ids != null) query.ids(this.ids); if (this.ids != null) query.ids(this.ids);
if (this.type != null) query.type(this.type); if (this.excludedIds != null) query.excludedIds(this.excludedIds);
if (this.tenantIds != null) query.tenantIds(this.tenantIds);
if (this.tenantIsSet != null) query.tenantIsSet(this.tenantIsSet);
this.enrichCommon(query); this.enrichCommon(query);
return query; return query;
} }
} }

View File

@ -1,7 +1,7 @@
package gr.cite.notification.service.channelResolution; package gr.cite.notification.service.channelResolution;
import gr.cite.notification.common.enums.NotificationContactType; import gr.cite.notification.common.enums.NotificationContactType;
import gr.cite.notification.common.types.tenantconfiguration.NotifierListConfigurationDataContainer; import gr.cite.notification.common.types.tenantconfiguration.NotifierListTenantConfigurationEntity;
import gr.cite.notification.config.notification.NotificationConfig; import gr.cite.notification.config.notification.NotificationConfig;
import gr.cite.notification.errorcode.ErrorThesaurusProperties; import gr.cite.notification.errorcode.ErrorThesaurusProperties;
import gr.cite.notification.model.UserNotificationPreference; import gr.cite.notification.model.UserNotificationPreference;
@ -97,7 +97,7 @@ public class ChannelResolutionServiceImpl implements ChannelResolutionService{
} }
private List<NotificationContactType> lookupOrCollectTenantPolicies(UUID type) { private List<NotificationContactType> lookupOrCollectTenantPolicies(UUID type) {
NotifierListConfigurationDataContainer container = this.tenantConfigurationService.collectTenantNotifierList(); NotifierListTenantConfigurationEntity container = this.tenantConfigurationService.collectTenantNotifierList();
if (container == null || container.getNotifiers() == null) return null; if (container == null || container.getNotifiers() == null) return null;
return container.getNotifiers().get(type); return container.getNotifiers().get(type);
} }

View File

@ -1,4 +1,4 @@
package gr.cite.notification.config.formatting; package gr.cite.notification.service.formatting;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;

View File

@ -1,14 +1,8 @@
package gr.cite.notification.service.formatting; package gr.cite.notification.service.formatting;
import gr.cite.notification.cache.FormattingUserprofileCacheCacheService;
import gr.cite.notification.config.formatting.FormattingServiceProperties;
import gr.cite.notification.convention.ConventionService; import gr.cite.notification.convention.ConventionService;
import gr.cite.notification.data.UserEntity;
import gr.cite.notification.locale.LocaleService; import gr.cite.notification.locale.LocaleService;
import gr.cite.notification.model.User;
import gr.cite.notification.query.UserQuery;
import gr.cite.tools.data.query.QueryFactory; import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.fieldset.BaseFieldSet;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.context.annotation.RequestScope; import org.springframework.web.context.annotation.RequestScope;

View File

@ -1,4 +1,4 @@
package gr.cite.notification.config.formatting; package gr.cite.notification.service.formatting;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;

View File

@ -1,7 +1,6 @@
package gr.cite.notification.cache; package gr.cite.notification.service.formatting;
import gr.cite.notification.event.UserTouchedEvent; import gr.cite.notification.event.UserTouchedEvent;
import gr.cite.notification.config.formatting.FormattingUserprofileCacheOptions;
import gr.cite.tools.cache.CacheService; import gr.cite.tools.cache.CacheService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener; import org.springframework.context.event.EventListener;

View File

@ -1,4 +1,4 @@
package gr.cite.notification.config.formatting; package gr.cite.notification.service.formatting;
import gr.cite.tools.cache.CacheOptions; import gr.cite.tools.cache.CacheOptions;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;

View File

@ -1,6 +1,6 @@
package gr.cite.notification.service.message.builder; package gr.cite.notification.service.message.builder;
import gr.cite.notification.cache.NotificationTemplateCache; import gr.cite.notification.service.message.cache.NotificationTemplateCache;
import gr.cite.notification.common.StringUtils; import gr.cite.notification.common.StringUtils;
import gr.cite.notification.common.enums.NotificationContactType; import gr.cite.notification.common.enums.NotificationContactType;
import gr.cite.notification.common.enums.NotificationTemplateChannel; import gr.cite.notification.common.enums.NotificationTemplateChannel;
@ -19,7 +19,6 @@ import gr.cite.notification.service.message.model.MessageInfo;
import gr.cite.notification.service.notificationtemplate.NotificationTemplateService; import gr.cite.notification.service.notificationtemplate.NotificationTemplateService;
import gr.cite.tools.cipher.CipherService; import gr.cite.tools.cipher.CipherService;
import gr.cite.tools.cipher.config.CipherProfileProperties; import gr.cite.tools.cipher.config.CipherProfileProperties;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -27,7 +26,6 @@ import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.context.annotation.RequestScope; import org.springframework.web.context.annotation.RequestScope;
import java.util.ArrayList;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;

View File

@ -1,9 +1,8 @@
package gr.cite.notification.service.message.builder; package gr.cite.notification.service.message.builder;
import gr.cite.notification.cache.NotificationTemplateCache; import gr.cite.notification.service.message.cache.NotificationTemplateCache;
import gr.cite.notification.common.StringUtils; import gr.cite.notification.common.StringUtils;
import gr.cite.notification.common.enums.InAppNotificationPriority; import gr.cite.notification.common.enums.InAppNotificationPriority;
import gr.cite.notification.common.enums.IsActive;
import gr.cite.notification.common.enums.NotificationContactType; import gr.cite.notification.common.enums.NotificationContactType;
import gr.cite.notification.common.enums.NotificationTemplateChannel; import gr.cite.notification.common.enums.NotificationTemplateChannel;
import gr.cite.notification.common.types.notification.FieldInfo; import gr.cite.notification.common.types.notification.FieldInfo;

View File

@ -1,13 +1,9 @@
package gr.cite.notification.cache; package gr.cite.notification.service.message.cache;
import gr.cite.notification.config.notification.NotificationTemplateCacheOptions;
import gr.cite.tools.cache.CacheOptions;
import gr.cite.tools.cache.CacheService; import gr.cite.tools.cache.CacheService;
import org.springframework.cache.Cache; import org.springframework.cache.Cache;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.UUID;
@Component @Component
public class NotificationTemplateCache extends CacheService<NotificationTemplateCache.NotificationTemplateCacheValue> { public class NotificationTemplateCache extends CacheService<NotificationTemplateCache.NotificationTemplateCacheValue> {

View File

@ -1,4 +1,4 @@
package gr.cite.notification.config.notification; package gr.cite.notification.service.message.cache;
import gr.cite.tools.cache.CacheOptions; import gr.cite.tools.cache.CacheOptions;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;

View File

@ -1,6 +1,6 @@
package gr.cite.notification.service.message.common; package gr.cite.notification.service.message.common;
import gr.cite.notification.cache.NotificationTemplateCache; import gr.cite.notification.service.message.cache.NotificationTemplateCache;
import gr.cite.notification.common.StringUtils; import gr.cite.notification.common.StringUtils;
import gr.cite.notification.common.types.notification.FieldInfo; import gr.cite.notification.common.types.notification.FieldInfo;
import gr.cite.notification.config.notification.NotificationProperties; import gr.cite.notification.config.notification.NotificationProperties;

View File

@ -7,7 +7,8 @@ import gr.cite.notification.common.scope.tenant.TenantScope;
import gr.cite.notification.common.enums.NotificationDataType; import gr.cite.notification.common.enums.NotificationDataType;
import gr.cite.notification.common.types.notification.FieldInfo; import gr.cite.notification.common.types.notification.FieldInfo;
import gr.cite.notification.common.types.notification.NotificationFieldData; import gr.cite.notification.common.types.notification.NotificationFieldData;
import gr.cite.notification.common.types.tenantconfiguration.DefaultUserLocaleConfigurationDataContainer; import gr.cite.notification.common.types.tenantconfiguration.DefaultUserLocaleTenantConfigurationEntity;
import gr.cite.notification.common.types.user.AdditionalInfoEntity;
import gr.cite.notification.config.notification.NotificationConfig; import gr.cite.notification.config.notification.NotificationConfig;
import gr.cite.notification.config.notification.NotificationProperties; import gr.cite.notification.config.notification.NotificationProperties;
import gr.cite.notification.data.NotificationEntity; import gr.cite.notification.data.NotificationEntity;
@ -87,16 +88,18 @@ public class MessageBuilderServiceImpl implements MessageInfoBuilderService {
.isActive(IsActive.Active).first(); .isActive(IsActive.Active).first();
} }
if (userProfile != null) { AdditionalInfoEntity additionalInfoEntity = userProfile == null ? null : this.jsonHandlingService.fromJsonSafe(AdditionalInfoEntity.class, userProfile.getAdditionalInfo());
// messageInfo.setLanguage(userProfile.getLanguage());
// messageInfo.setCulture(userProfile.getCulture()); if (additionalInfoEntity != null) {
// messageInfo.setTimeZone(userProfile.getTimezone()); messageInfo.setLanguage(additionalInfoEntity.getLanguage());
messageInfo.setCulture(additionalInfoEntity.getCulture());
messageInfo.setTimeZone(additionalInfoEntity.getTimezone());
} else { } else {
DefaultUserLocaleConfigurationDataContainer defaultUserLocaleConfiguration = this.tenantConfigurationService.collectTenantUserLocale(); DefaultUserLocaleTenantConfigurationEntity defaultUserLocaleConfiguration = this.tenantConfigurationService.collectTenantUserLocale();
if (defaultUserLocaleConfiguration != null) { if (defaultUserLocaleConfiguration != null) {
messageInfo.setLanguage(defaultUserLocaleConfiguration.getLanguage()); messageInfo.setLanguage(defaultUserLocaleConfiguration.getLanguage());
messageInfo.setCulture(defaultUserLocaleConfiguration.getCulture()); messageInfo.setCulture(defaultUserLocaleConfiguration.getCulture());
messageInfo.setTimeZone(defaultUserLocaleConfiguration.getTimeZone()); messageInfo.setTimeZone(defaultUserLocaleConfiguration.getTimezone());
} }
} }

View File

@ -62,7 +62,6 @@ public class NotificationServiceImpl implements NotificationService {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(NotificationServiceImpl.class)); private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(NotificationServiceImpl.class));
private final TenantEntityManager entityManager; private final TenantEntityManager entityManager;
private final AuthorizationService authService; private final AuthorizationService authService;
private final AuthorizationService authorizationService;
private final DeleterFactory deleterFactory; private final DeleterFactory deleterFactory;
private final BuilderFactory builderFactory; private final BuilderFactory builderFactory;
private final ConventionService conventionService; private final ConventionService conventionService;
@ -78,7 +77,7 @@ public class NotificationServiceImpl implements NotificationService {
@Autowired @Autowired
public NotificationServiceImpl( public NotificationServiceImpl(
TenantEntityManager entityManager, TenantEntityManager entityManager,
AuthorizationService authService, AuthorizationService authorizationService, AuthorizationService authService,
DeleterFactory deleterFactory, DeleterFactory deleterFactory,
BuilderFactory builderFactory, BuilderFactory builderFactory,
ConventionService conventionService, ConventionService conventionService,
@ -87,7 +86,6 @@ public class NotificationServiceImpl implements NotificationService {
ChannelResolutionService channelResolutionService, MessageBuilderFactory messageBuilderFactory, ContactExtractorFactory contactExtractorFactory, NotifierFactory notifierFactory, ApplicationContext applicationContext, QueryFactory queryFactory) { ChannelResolutionService channelResolutionService, MessageBuilderFactory messageBuilderFactory, ContactExtractorFactory contactExtractorFactory, NotifierFactory notifierFactory, ApplicationContext applicationContext, QueryFactory queryFactory) {
this.entityManager = entityManager; this.entityManager = entityManager;
this.authService = authService; this.authService = authService;
this.authorizationService = authorizationService;
this.deleterFactory = deleterFactory; this.deleterFactory = deleterFactory;
this.builderFactory = builderFactory; this.builderFactory = builderFactory;
this.conventionService = conventionService; this.conventionService = conventionService;

View File

@ -1,4 +1,4 @@
package gr.cite.notification.config.email; package gr.cite.notification.service.notify;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;

View File

@ -2,7 +2,6 @@ package gr.cite.notification.service.notify;
import gr.cite.notification.common.StringUtils; import gr.cite.notification.common.StringUtils;
import gr.cite.notification.common.enums.NotificationContactType; import gr.cite.notification.common.enums.NotificationContactType;
import gr.cite.notification.config.email.EmailProperties;
import gr.cite.notification.service.contact.model.Contact; import gr.cite.notification.service.contact.model.Contact;
import gr.cite.notification.service.contact.model.EmailContact; import gr.cite.notification.service.contact.model.EmailContact;
import gr.cite.notification.service.message.model.EmailMessage; import gr.cite.notification.service.message.model.EmailMessage;

View File

@ -1,4 +1,4 @@
package gr.cite.notification.config.email; package gr.cite.notification.service.notify;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;

View File

@ -1,26 +1,31 @@
package gr.cite.notification.service.tenantconfiguration; package gr.cite.notification.service.tenantconfiguration;
import gr.cite.notification.common.types.tenantconfiguration.DefaultUserLocaleConfigurationDataContainer; import com.fasterxml.jackson.core.JsonProcessingException;
import gr.cite.notification.common.types.tenantconfiguration.EmailClientConfigurationDataContainer; import gr.cite.notification.common.types.tenantconfiguration.DefaultUserLocaleTenantConfigurationEntity;
import gr.cite.notification.common.types.tenantconfiguration.NotifierListConfigurationDataContainer; import gr.cite.notification.common.types.tenantconfiguration.NotifierListTenantConfigurationEntity;
import gr.cite.notification.model.TenantConfiguration; import gr.cite.notification.model.persist.tenantconfiguration.TenantConfigurationPersist;
import gr.cite.notification.model.persist.tenantconfiguration.TenantConfigurationEmailClientPersist; import gr.cite.notification.model.tenantconfiguration.TenantConfiguration;
import gr.cite.notification.model.persist.tenantconfiguration.TenantConfigurationNotifierListPersist; import gr.cite.tools.exception.MyApplicationException;
import gr.cite.notification.model.persist.tenantconfiguration.TenantConfigurationUserLocaleIntegrationPersist; import gr.cite.tools.exception.MyForbiddenException;
import gr.cite.tools.exception.MyNotFoundException;
import gr.cite.tools.exception.MyValidationException;
import gr.cite.tools.fieldset.FieldSet; import gr.cite.tools.fieldset.FieldSet;
import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.management.InvalidApplicationException; import javax.management.InvalidApplicationException;
import java.util.Set; import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.UUID; import java.util.UUID;
public interface TenantConfigurationService { public interface TenantConfigurationService {
EmailClientConfigurationDataContainer collectTenantEmailClient();
DefaultUserLocaleConfigurationDataContainer collectTenantUserLocale();
NotifierListConfigurationDataContainer collectTenantNotifierList();
NotifierListConfigurationDataContainer collectTenantAvailableNotifierList(Set<UUID> notificationTypes);
TenantConfiguration persist(TenantConfigurationEmailClientPersist emailClientPersist, FieldSet fieldSet);
TenantConfiguration persist(TenantConfigurationUserLocaleIntegrationPersist userLocaleIntegrationPersist, FieldSet fieldSet);
TenantConfiguration persist(TenantConfigurationNotifierListPersist notifierListPersist, FieldSet fieldSet);
void deleteAndSave(UUID id) throws InvalidApplicationException;
TenantConfiguration persist(TenantConfigurationPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JsonProcessingException, InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException;
void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException;
NotifierListTenantConfigurationEntity collectTenantNotifierList();
DefaultUserLocaleTenantConfigurationEntity collectTenantUserLocale();
} }

View File

@ -6,239 +6,217 @@ import gr.cite.notification.authorization.Permission;
import gr.cite.notification.common.JsonHandlingService; import gr.cite.notification.common.JsonHandlingService;
import gr.cite.notification.common.enums.IsActive; import gr.cite.notification.common.enums.IsActive;
import gr.cite.notification.common.enums.TenantConfigurationType; import gr.cite.notification.common.enums.TenantConfigurationType;
import gr.cite.notification.common.types.tenantconfiguration.DefaultUserLocaleConfigurationDataContainer; import gr.cite.notification.common.scope.tenant.TenantScope;
import gr.cite.notification.common.types.tenantconfiguration.EmailClientConfigurationDataContainer; import gr.cite.notification.common.types.tenantconfiguration.DefaultUserLocaleTenantConfigurationEntity;
import gr.cite.notification.common.types.tenantconfiguration.NotifierListConfigurationDataContainer; import gr.cite.notification.common.types.tenantconfiguration.NotifierListTenantConfigurationEntity;
import gr.cite.notification.convention.ConventionService; import gr.cite.notification.convention.ConventionService;
import gr.cite.notification.data.TenantConfigurationEntity; import gr.cite.notification.data.TenantConfigurationEntity;
import gr.cite.notification.data.TenantEntity;
import gr.cite.notification.data.TenantEntityManager; import gr.cite.notification.data.TenantEntityManager;
import gr.cite.notification.errorcode.ErrorThesaurusProperties; import gr.cite.notification.errorcode.ErrorThesaurusProperties;
import gr.cite.notification.model.TenantConfiguration; import gr.cite.notification.event.EventBroker;
import gr.cite.notification.model.builder.TenantConfigurationBuilder; import gr.cite.notification.event.TenantConfigurationTouchedEvent;
import gr.cite.notification.model.builder.tenantconfiguration.TenantConfigurationBuilder;
import gr.cite.notification.model.deleter.TenantConfigurationDeleter; import gr.cite.notification.model.deleter.TenantConfigurationDeleter;
import gr.cite.notification.model.persist.tenantconfiguration.TenantConfigurationEmailClientPersist; import gr.cite.notification.model.persist.tenantconfiguration.DefaultUserLocaleTenantConfigurationPersist;
import gr.cite.notification.model.persist.tenantconfiguration.TenantConfigurationNotifierListPersist; import gr.cite.notification.model.persist.tenantconfiguration.NotifierListTenantConfigurationPersist;
import gr.cite.notification.model.persist.tenantconfiguration.TenantConfigurationUserLocaleIntegrationPersist; import gr.cite.notification.model.persist.tenantconfiguration.TenantConfigurationPersist;
import gr.cite.notification.model.tenantconfiguration.TenantConfiguration;
import gr.cite.notification.query.TenantConfigurationQuery; import gr.cite.notification.query.TenantConfigurationQuery;
import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.deleter.DeleterFactory; import gr.cite.tools.data.deleter.DeleterFactory;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.exception.MyForbiddenException;
import gr.cite.tools.exception.MyNotFoundException; import gr.cite.tools.exception.MyNotFoundException;
import gr.cite.tools.exception.MyValidationException; import gr.cite.tools.exception.MyValidationException;
import gr.cite.tools.fieldset.BaseFieldSet; import gr.cite.tools.fieldset.BaseFieldSet;
import gr.cite.tools.fieldset.FieldSet; import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry;
import org.jetbrains.annotations.NotNull;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.MessageSource; import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Service;
import org.springframework.web.context.annotation.RequestScope; import gr.cite.notification.authorization.AuthorizationFlags;
import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.management.InvalidApplicationException; import javax.management.InvalidApplicationException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.time.Instant; import java.time.Instant;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
@Component @Service
@RequestScope
public class TenantConfigurationServiceImpl implements TenantConfigurationService { public class TenantConfigurationServiceImpl implements TenantConfigurationService {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(TenantConfigurationServiceImpl.class)); private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(TenantConfigurationServiceImpl.class));
private final ApplicationContext applicationContext; private final TenantEntityManager entityManager;
private final JsonHandlingService jsonHandlingService;
private final AuthorizationService authorizationService; private final AuthorizationService authorizationService;
private final ConventionService conventionService;
private final ErrorThesaurusProperties errors;
private final MessageSource messageSource;
private final BuilderFactory builderFactory;
private final TenantEntityManager dbContext;
private final DeleterFactory deleterFactory; private final DeleterFactory deleterFactory;
private final BuilderFactory builderFactory;
private final ConventionService conventionService;
private final ErrorThesaurusProperties errors;
private final MessageSource messageSource;
private final JsonHandlingService jsonHandlingService;
private final QueryFactory queryFactory;
private final EventBroker eventBroker;
private final TenantScope tenantScope;
@Autowired @Autowired
public TenantConfigurationServiceImpl(ApplicationContext applicationContext, JsonHandlingService jsonHandlingService, AuthorizationService authorizationService, ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, BuilderFactory builderFactory, TenantEntityManager dbContext, DeleterFactory deleterFactory) { public TenantConfigurationServiceImpl(
this.applicationContext = applicationContext; TenantEntityManager entityManager,
this.jsonHandlingService = jsonHandlingService; AuthorizationService authorizationService,
DeleterFactory deleterFactory,
BuilderFactory builderFactory,
ConventionService conventionService,
ErrorThesaurusProperties errors,
MessageSource messageSource, JsonHandlingService jsonHandlingService, QueryFactory queryFactory, EventBroker eventBroker, TenantScope tenantScope) {
this.entityManager = entityManager;
this.authorizationService = authorizationService; this.authorizationService = authorizationService;
this.deleterFactory = deleterFactory;
this.builderFactory = builderFactory;
this.conventionService = conventionService; this.conventionService = conventionService;
this.errors = errors; this.errors = errors;
this.messageSource = messageSource; this.messageSource = messageSource;
this.builderFactory = builderFactory; this.jsonHandlingService = jsonHandlingService;
this.dbContext = dbContext; this.queryFactory = queryFactory;
this.deleterFactory = deleterFactory; this.eventBroker = eventBroker;
this.tenantScope = tenantScope;
} }
@Override public TenantConfiguration persist(TenantConfigurationPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JsonProcessingException, InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException {
public EmailClientConfigurationDataContainer collectTenantEmailClient() { logger.debug(new MapLogEntry("persisting data TenantConfiguration").And("model", model).And("fields", fields));
TenantConfigurationQuery query = applicationContext.getBean(TenantConfigurationQuery.class);
String data = query.isActive(IsActive.Active).type(TenantConfigurationType.EMAIL_CLIENT_CONFIGURATION).first().getValue();
if (data == null) return null;
try {
EmailClientConfigurationDataContainer emailClientData = this.jsonHandlingService.fromJson(EmailClientConfigurationDataContainer.class, data);
return emailClientData;
} catch (JsonProcessingException e) {
logger.error(e.getMessage(), e);
}
return null;
}
@Override
public DefaultUserLocaleConfigurationDataContainer collectTenantUserLocale() {
TenantConfigurationQuery query = applicationContext.getBean(TenantConfigurationQuery.class);
TenantConfigurationEntity entity = query.isActive(IsActive.Active).type(TenantConfigurationType.DEFAULT_USER_LOCALE).first();
if(entity == null){
return null;
}
String data = entity.getValue();
if (data == null) return null;
try {
DefaultUserLocaleConfigurationDataContainer userLocaleData = this.jsonHandlingService.fromJson(DefaultUserLocaleConfigurationDataContainer.class, data);
return userLocaleData;
} catch (JsonProcessingException e) {
logger.error(e.getMessage(), e);
}
return null;
}
@Override
public NotifierListConfigurationDataContainer collectTenantNotifierList() {
TenantConfigurationQuery query = applicationContext.getBean(TenantConfigurationQuery.class);
TenantConfigurationEntity configurationEntity = query.isActive(IsActive.Active).type(TenantConfigurationType.NOTIFIER_LIST).first();
String data = configurationEntity != null ? configurationEntity.getValue() : null;
if (data == null) return null;
try {
NotifierListConfigurationDataContainer notifierListData = this.jsonHandlingService.fromJson(NotifierListConfigurationDataContainer.class, data);
return notifierListData;
} catch (JsonProcessingException e) {
logger.error(e.getMessage(), e);
}
return null;
}
@Override
public NotifierListConfigurationDataContainer collectTenantAvailableNotifierList(Set<UUID> notificationTypes) {
return null;
}
@Override
public TenantConfiguration persist(TenantConfigurationEmailClientPersist emailClientPersist, FieldSet fieldSet) {
EmailClientConfigurationDataContainer container = new EmailClientConfigurationDataContainer();
container.setEnableSSL(emailClientPersist.getEnableSSL());
container.setRequireCredentials(emailClientPersist.getRequireCredentials());
container.setHostServer(emailClientPersist.getHostServer());
container.setHostPortNo(emailClientPersist.getHostPortNo());
container.setCertificatePath(emailClientPersist.getCertificatePath());
container.setEmailAddress(emailClientPersist.getEmailAddress());
container.setEmailUserName(emailClientPersist.getEmailUserName());
container.setEmailPassword(emailClientPersist.getEmailPassword());
try {
String value = jsonHandlingService.toJson(container);
return this.persist(emailClientPersist.getId(), emailClientPersist.getHash(), TenantConfigurationType.EMAIL_CLIENT_CONFIGURATION, value, fieldSet);
} catch (JsonProcessingException e) {
logger.error(e.getMessage(), e);
}
return null;
}
@Override
public TenantConfiguration persist(TenantConfigurationUserLocaleIntegrationPersist userLocaleIntegrationPersist, FieldSet fieldSet) {
this.authorizationService.authorizeForce(Permission.EditTenantConfiguration); this.authorizationService.authorizeForce(Permission.EditTenantConfiguration);
TenantConfigurationQuery tenantConfigurationQuery = applicationContext.getBean(TenantConfigurationQuery.class); Boolean isUpdate = this.conventionService.isValidGuid(model.getId());
TenantConfigurationEntity data = tenantConfigurationQuery.isActive(IsActive.Active).type(TenantConfigurationType.DEFAULT_USER_LOCALE).first();
Boolean isUpdate = data != null;
if (!isUpdate) {
data = new TenantConfigurationEntity(); TenantConfigurationEntity data;
data.setCreatedAt(Instant.now());
data.setIsActive(IsActive.Active);
data.setType(TenantConfigurationType.DEFAULT_USER_LOCALE);
}
try {
DefaultUserLocaleConfigurationDataContainer container = new DefaultUserLocaleConfigurationDataContainer();
container.setCulture(userLocaleIntegrationPersist.getCulture());
container.setTimeZone(userLocaleIntegrationPersist.getTimeZone());
container.setLanguage(userLocaleIntegrationPersist.getLanguage());
String value = jsonHandlingService.toJson(container);
data.setValue(value);
data.setUpdatedAt(Instant.now());
this.dbContext.merge(data);
} catch (InvalidApplicationException | JsonProcessingException e) {
logger.error(e.getMessage(), e);
}
//this._eventBroker.EmitTenantConfigurationTouched(this._scope.Tenant, type);
TenantConfiguration persisted = this.builderFactory.builder(TenantConfigurationBuilder.class).build(fieldSet.merge(new BaseFieldSet(TenantConfiguration._id, TenantConfiguration._hash)), data);
return persisted;
}
@Override
public TenantConfiguration persist(TenantConfigurationNotifierListPersist notifierListPersist, FieldSet fieldSet) {
NotifierListConfigurationDataContainer container = new NotifierListConfigurationDataContainer();
container.setNotifiers(notifierListPersist.getNotifiers());
try {
String value = jsonHandlingService.toJson(container);
return this.persist(notifierListPersist.getId(), notifierListPersist.getHash(), TenantConfigurationType.NOTIFIER_LIST, value, fieldSet);
} catch (JsonProcessingException e) {
logger.error(e.getMessage(), e);
}
return null;
}
@Override
public void deleteAndSave(UUID id) throws InvalidApplicationException {
logger.debug("deleting tenant Configuration: {}", id);
this.authorizationService.authorizeForce(Permission.DeleteNotification);
this.deleterFactory.deleter(TenantConfigurationDeleter.class).deleteAndSaveByIds(List.of(id));
}
private TenantConfiguration persist(UUID modelId, String modelHash, TenantConfigurationType type, String value, FieldSet fieldSet) {
this.authorizationService.authorizeForce(Permission.EditTenantConfiguration);
Boolean isUpdate = this.conventionService.isValidGuid(modelId);
TenantConfigurationQuery tenantConfigurationQuery = applicationContext.getBean(TenantConfigurationQuery.class);
List<UUID> existingConfigIds = tenantConfigurationQuery.isActive(IsActive.Active).type(type).collectAs(new BaseFieldSet(TenantConfigurationEntity._id)).stream().map(TenantConfigurationEntity::getId).toList();
TenantConfigurationEntity data = null;
if (isUpdate) { if (isUpdate) {
if (!existingConfigIds.contains(modelId)) throw new MyValidationException(this.errors.getSingleTenantConfigurationPerTypeSupported().getCode(), this.errors.getSingleTenantConfigurationPerTypeSupported().getMessage()); data = this.entityManager.find(TenantConfigurationEntity.class, model.getId());
if (existingConfigIds.size() > 1) throw new MyValidationException(this.errors.getSingleTenantConfigurationPerTypeSupported().getCode(), this.errors.getSingleTenantConfigurationPerTypeSupported().getMessage()); if (data == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), TenantConfiguration.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (!this.conventionService.hashValue(data.getUpdatedAt()).equals(model.getHash())) throw new MyValidationException(this.errors.getHashConflict().getCode(), this.errors.getHashConflict().getMessage());
if (!data.getType().equals(model.getType())) throw new MyValidationException(this.errors.getTenantConfigurationTypeCanNotChange().getCode(), this.errors.getTenantConfigurationTypeCanNotChange().getMessage());
data = tenantConfigurationQuery.ids(modelId).first();
if (data == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{modelId, TenantConfigurationEntity.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (!modelHash.equals(this.conventionService.hashValue(data.getUpdatedAt()))) throw new MyValidationException(this.errors.getHashConflict().getCode(), this.errors.getHashConflict().getMessage());
if (!data.getType().equals(type)) throw new MyValidationException(this.errors.getIncompatibleTenantConfigurationTypes().getCode(), this.errors.getIncompatibleTenantConfigurationTypes().getMessage());
} else { } else {
if (!existingConfigIds.isEmpty()) throw new MyValidationException(this.errors.getSingleTenantConfigurationPerTypeSupported().getCode(), this.errors.getSingleTenantConfigurationPerTypeSupported().getMessage());
data = new TenantConfigurationEntity(); data = new TenantConfigurationEntity();
data.setCreatedAt(Instant.now()); data.setId(UUID.randomUUID());
data.setIsActive(IsActive.Active); data.setIsActive(IsActive.Active);
data.setType(type); data.setCreatedAt(Instant.now());
data.setType(model.getType());
} }
data.setValue(value); TenantConfigurationQuery tenantConfigurationQuery = this.queryFactory.query(TenantConfigurationQuery.class).excludedIds(data.getId()).isActive(IsActive.Active).types(data.getType());
if (data.getTenantId() == null) tenantConfigurationQuery.tenantIsSet(false);
else tenantConfigurationQuery.tenantIsSet(true).tenantIds(data.getTenantId());
if (tenantConfigurationQuery.count() > 0)throw new MyValidationException(this.errors.getMultipleTenantConfigurationTypeNotAllowed().getCode(), this.errors.getMultipleTenantConfigurationTypeNotAllowed().getMessage());
switch (data.getType()){
case NotifierList -> data.setValue(this.jsonHandlingService.toJson(this.buildNotifierListTenantConfigurationEntity(model.getNotifierList())));
case DefaultUserLocale -> data.setValue(this.jsonHandlingService.toJson(this.buildDefaultUserLocaleTenantConfigurationEntity(model.getDefaultUserLocale())));
default -> throw new InternalError("unknown type: " + data.getType());
}
data.setUpdatedAt(Instant.now()); data.setUpdatedAt(Instant.now());
if (isUpdate)
this.entityManager.merge(data);
else
this.entityManager.persist(data);
this.entityManager.flush();
if (data.getTenantId() != null) {
TenantEntity tenant = this.entityManager.find(TenantEntity.class, data.getTenantId());
if (tenant == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{data.getTenantId(), TenantEntity.class.getSimpleName()}, LocaleContextHolder.getLocale()));
this.eventBroker.emit(new TenantConfigurationTouchedEvent(tenant.getId(), tenant.getCode(), data.getType()));
} else {
this.eventBroker.emit(new TenantConfigurationTouchedEvent(data.getId(), this.tenantScope.getDefaultTenantCode(), data.getType()));
}
return this.builderFactory.builder(TenantConfigurationBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(BaseFieldSet.build(fields, TenantConfiguration._id), data);
}
private @NotNull DefaultUserLocaleTenantConfigurationEntity buildDefaultUserLocaleTenantConfigurationEntity(DefaultUserLocaleTenantConfigurationPersist persist){
DefaultUserLocaleTenantConfigurationEntity data = new DefaultUserLocaleTenantConfigurationEntity();
if (persist == null) return data;
data.setCulture(persist.getCulture());
data.setLanguage(persist.getLanguage());
data.setTimezone(persist.getTimezone());
return data;
}
private @NotNull NotifierListTenantConfigurationEntity buildNotifierListTenantConfigurationEntity(NotifierListTenantConfigurationPersist persist){
NotifierListTenantConfigurationEntity data = new NotifierListTenantConfigurationEntity();
if (persist == null) return data;
data.setNotifiers(persist.getNotifiers());
return data;
}
public void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException {
logger.debug("deleting dataset: {}", id);
this.authorizationService.authorizeForce(Permission.DeleteTenantConfiguration);
TenantConfigurationEntity data = this.entityManager.find(TenantConfigurationEntity.class, id);
if (data == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, TenantConfiguration.class.getSimpleName()}, LocaleContextHolder.getLocale()));
this.deleterFactory.deleter(TenantConfigurationDeleter.class).deleteAndSaveByIds(List.of(id));
if (data.getTenantId() != null) {
TenantEntity tenant = this.entityManager.find(TenantEntity.class, data.getTenantId());
if (tenant == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{data.getTenantId(), TenantEntity.class.getSimpleName()}, LocaleContextHolder.getLocale()));
this.eventBroker.emit(new TenantConfigurationTouchedEvent(tenant.getId(), tenant.getCode(), data.getType()));
} else {
this.eventBroker.emit(new TenantConfigurationTouchedEvent(data.getId(), this.tenantScope.getDefaultTenantCode(), data.getType()));
}
}
@Override
public NotifierListTenantConfigurationEntity collectTenantNotifierList() {
TenantConfigurationQuery query = this.queryFactory.query(TenantConfigurationQuery.class).authorize(AuthorizationFlags.OwnerOrPermission).isActive(IsActive.Active).types(TenantConfigurationType.NotifierList);
if (this.tenantScope.isDefaultTenant()) query.tenantIsSet(false);
else {
try { try {
this.dbContext.merge(data); query.tenantIsSet(true).tenantIds(this.tenantScope.getTenant());
} catch (InvalidApplicationException e) { } catch (InvalidApplicationException e) {
logger.error(e.getMessage(), e); throw new RuntimeException(e);
}
} }
//this._eventBroker.EmitTenantConfigurationTouched(this._scope.Tenant, type); TenantConfigurationEntity data = query.first();
if (data == null || this.conventionService.isNullOrEmpty(data.getValue())) return null;
TenantConfiguration persisted = this.builderFactory.builder(TenantConfigurationBuilder.class).build(fieldSet.merge(new BaseFieldSet(TenantConfiguration._id, TenantConfiguration._hash)), data); return this.jsonHandlingService.fromJsonSafe(NotifierListTenantConfigurationEntity.class, data.getValue());
return persisted;
//return null;
} }
@Override
public DefaultUserLocaleTenantConfigurationEntity collectTenantUserLocale() {
TenantConfigurationQuery query = this.queryFactory.query(TenantConfigurationQuery.class).authorize(AuthorizationFlags.OwnerOrPermission).isActive(IsActive.Active).types(TenantConfigurationType.DefaultUserLocale);
if (this.tenantScope.isDefaultTenant()) query.tenantIsSet(false);
else {
try {
query.tenantIsSet(true).tenantIds(this.tenantScope.getTenant());
} catch (InvalidApplicationException e) {
throw new RuntimeException(e);
}
}
TenantConfigurationEntity data = query.first();
if (data == null || this.conventionService.isNullOrEmpty(data.getValue())) return null;
return this.jsonHandlingService.fromJsonSafe(DefaultUserLocaleTenantConfigurationEntity.class, data.getValue());
}
} }

View File

@ -7,6 +7,7 @@ import gr.cite.notification.authorization.Permission;
import gr.cite.notification.common.JsonHandlingService; import gr.cite.notification.common.JsonHandlingService;
import gr.cite.notification.common.enums.IsActive; import gr.cite.notification.common.enums.IsActive;
import gr.cite.notification.common.scope.tenant.TenantScope; import gr.cite.notification.common.scope.tenant.TenantScope;
import gr.cite.notification.common.types.user.AdditionalInfoEntity;
import gr.cite.notification.convention.ConventionService; import gr.cite.notification.convention.ConventionService;
import gr.cite.notification.data.*; import gr.cite.notification.data.*;
import gr.cite.notification.integrationevent.inbox.usertouched.UserTouchedIntegrationEvent; import gr.cite.notification.integrationevent.inbox.usertouched.UserTouchedIntegrationEvent;
@ -34,6 +35,7 @@ import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry; import gr.cite.tools.logging.MapLogEntry;
import jakarta.persistence.EntityManager; import jakarta.persistence.EntityManager;
import jakarta.transaction.Transactional; import jakarta.transaction.Transactional;
import org.jetbrains.annotations.NotNull;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.context.MessageSource; import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.context.i18n.LocaleContextHolder;
@ -100,7 +102,7 @@ public class UserServiceImpl implements UserService {
data = new UserEntity(); data = new UserEntity();
data.setId(model.getId()); data.setId(model.getId());
data.setName(model.getName()); data.setName(model.getName());
data.setAdditionalInfo(this.jsonHandlingService.toJson(model.getProfile())); data.setAdditionalInfo(this.jsonHandlingService.toJson(this.buildAdditionalInfoEntity(model.getProfile())));
data.setCreatedAt(Instant.now()); data.setCreatedAt(Instant.now());
data.setUpdatedAt(Instant.now()); data.setUpdatedAt(Instant.now());
data.setIsActive(IsActive.Active); data.setIsActive(IsActive.Active);
@ -109,7 +111,7 @@ public class UserServiceImpl implements UserService {
} else { } else {
data.setName(model.getName()); data.setName(model.getName());
data.setAdditionalInfo(this.jsonHandlingService.toJson(model.getProfile())); data.setAdditionalInfo(this.jsonHandlingService.toJson(this.buildAdditionalInfoEntity(model.getProfile())));
data.setUpdatedAt(Instant.now()); data.setUpdatedAt(Instant.now());
data.setIsActive(IsActive.Active); data.setIsActive(IsActive.Active);
@ -131,6 +133,15 @@ public class UserServiceImpl implements UserService {
return this.builderFactory.builder(UserBuilder.class).authorize(EnumSet.of(AuthorizationFlags.None)).build(BaseFieldSet.build(fields, User._id), data); return this.builderFactory.builder(UserBuilder.class).authorize(EnumSet.of(AuthorizationFlags.None)).build(BaseFieldSet.build(fields, User._id), data);
} }
private @NotNull AdditionalInfoEntity buildAdditionalInfoEntity(UserTouchedIntegrationEvent.UserProfile persist){
AdditionalInfoEntity data = new AdditionalInfoEntity();
if (persist == null) return data;
data.setCulture(persist.getCulture());
data.setTimezone(persist.getTimezone());
data.setLanguage(persist.getLanguage());
return data;
}
@Override @Override
public void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException { public void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException {
logger.debug("deleting User: {}", id); logger.debug("deleting User: {}", id);

View File

@ -1,7 +1,6 @@
package gr.cite.notification.service.userNotificationPreference; package gr.cite.notification.service.userNotificationPreference;
import gr.cite.notification.common.enums.NotificationContactType; import gr.cite.notification.common.types.tenantconfiguration.NotifierListTenantConfigurationEntity;
import gr.cite.notification.common.types.tenantconfiguration.NotifierListConfigurationDataContainer;
import gr.cite.notification.model.UserNotificationPreference; import gr.cite.notification.model.UserNotificationPreference;
import gr.cite.notification.model.persist.UserNotificationPreferencePersist; import gr.cite.notification.model.persist.UserNotificationPreferencePersist;
import gr.cite.tools.fieldset.FieldSet; import gr.cite.tools.fieldset.FieldSet;
@ -14,7 +13,7 @@ import java.util.UUID;
public interface UserNotificationPreferenceService { public interface UserNotificationPreferenceService {
List<UserNotificationPreference> persist(UserNotificationPreferencePersist model, FieldSet fieldSet); List<UserNotificationPreference> persist(UserNotificationPreferencePersist model, FieldSet fieldSet);
NotifierListConfigurationDataContainer collectUserAvailableNotifierList(Set<UUID> notificationTypes); NotifierListTenantConfigurationEntity collectUserAvailableNotifierList(Set<UUID> notificationTypes);
List<UserNotificationPreference> collectUserNotificationPreferences(UUID id); List<UserNotificationPreference> collectUserNotificationPreferences(UUID id);
Map<UUID, List<UserNotificationPreference>> collectUserNotificationPreferences(List<UUID> ids); Map<UUID, List<UserNotificationPreference>> collectUserNotificationPreferences(List<UUID> ids);
} }

View File

@ -5,7 +5,7 @@ import gr.cite.notification.authorization.OwnedResource;
import gr.cite.notification.authorization.Permission; import gr.cite.notification.authorization.Permission;
import gr.cite.notification.common.enums.IsActive; import gr.cite.notification.common.enums.IsActive;
import gr.cite.notification.common.enums.NotificationContactType; import gr.cite.notification.common.enums.NotificationContactType;
import gr.cite.notification.common.types.tenantconfiguration.NotifierListConfigurationDataContainer; import gr.cite.notification.common.types.tenantconfiguration.NotifierListTenantConfigurationEntity;
import gr.cite.notification.config.notification.NotificationConfig; import gr.cite.notification.config.notification.NotificationConfig;
import gr.cite.notification.data.TenantEntityManager; import gr.cite.notification.data.TenantEntityManager;
import gr.cite.notification.data.UserNotificationPreferenceEntity; import gr.cite.notification.data.UserNotificationPreferenceEntity;
@ -71,7 +71,7 @@ public class UserNotificationPreferenceServiceImpl implements UserNotificationPr
this.authService.authorizeAtLeastOneForce(model.getUserId() != null ? List.of(new OwnedResource(model.getUserId())) : null, Permission.EditUserNotificationPreference); this.authService.authorizeAtLeastOneForce(model.getUserId() != null ? List.of(new OwnedResource(model.getUserId())) : null, Permission.EditUserNotificationPreference);
Map<UUID, List<NotificationContactType>> currentNotificationListPolicies; Map<UUID, List<NotificationContactType>> currentNotificationListPolicies;
NotifierListConfigurationDataContainer tenantNotifierListPolicies = this.tenantConfigurationService.collectTenantNotifierList(); NotifierListTenantConfigurationEntity tenantNotifierListPolicies = this.tenantConfigurationService.collectTenantNotifierList();
if (tenantNotifierListPolicies != null) if (tenantNotifierListPolicies != null)
{ {
currentNotificationListPolicies = mergeNotifierPolicies(tenantNotifierListPolicies.getNotifiers(), this.globalPoliciesMap); currentNotificationListPolicies = mergeNotifierPolicies(tenantNotifierListPolicies.getNotifiers(), this.globalPoliciesMap);
@ -91,9 +91,9 @@ public class UserNotificationPreferenceServiceImpl implements UserNotificationPr
} }
@Override @Override
public NotifierListConfigurationDataContainer collectUserAvailableNotifierList(Set<UUID> notificationTypes) { public NotifierListTenantConfigurationEntity collectUserAvailableNotifierList(Set<UUID> notificationTypes) {
Map<UUID, List<NotificationContactType>> currentNotificationListPolicies; Map<UUID, List<NotificationContactType>> currentNotificationListPolicies;
NotifierListConfigurationDataContainer tenantNotifierListPolicies = this.tenantConfigurationService.collectTenantNotifierList(); NotifierListTenantConfigurationEntity tenantNotifierListPolicies = this.tenantConfigurationService.collectTenantNotifierList();
if (tenantNotifierListPolicies != null) if (tenantNotifierListPolicies != null)
{ {
currentNotificationListPolicies = mergeNotifierPolicies(tenantNotifierListPolicies.getNotifiers(), this.globalPoliciesMap); currentNotificationListPolicies = mergeNotifierPolicies(tenantNotifierListPolicies.getNotifiers(), this.globalPoliciesMap);
@ -105,12 +105,12 @@ public class UserNotificationPreferenceServiceImpl implements UserNotificationPr
if (notificationTypes != null && !notificationTypes.isEmpty()) if (notificationTypes != null && !notificationTypes.isEmpty())
{ {
return new NotifierListConfigurationDataContainer(currentNotificationListPolicies return new NotifierListTenantConfigurationEntity(currentNotificationListPolicies
.entrySet().stream() .entrySet().stream()
.filter(x -> notificationTypes.contains(x.getKey())) .filter(x -> notificationTypes.contains(x.getKey()))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
} }
else return new NotifierListConfigurationDataContainer(currentNotificationListPolicies); else return new NotifierListTenantConfigurationEntity(currentNotificationListPolicies);
} }
@Override @Override