add indicator access global filters and reset indicator event

This commit is contained in:
CITE\amentis 2024-09-13 17:46:58 +03:00
parent 0e983f04e5
commit b30f26588d
30 changed files with 546 additions and 79 deletions

View File

@ -172,8 +172,9 @@ public class AuditableAction {
public static final EventId Maintenance_SendReferenceTypeAccountingEntriesEvents = new EventId(230011, "Maintenance_SendReferenceTypeAccountingEntriesEvents");
public static final EventId Maintenance_SendUserAccountingEntriesEvents = new EventId(230012, "Maintenance_SendUserAccountingEntriesEvents");
public static final EventId Maintenance_SendIndicatorCreateEntryEvents = new EventId(230013, "Maintenance_SendIndicatorCreateEntryEvents");
public static final EventId Maintenance_SendIndicatorAccessEntryEvents = new EventId(230014, "Maintenance_SendIndicatorAccessEntryEvents");
public static final EventId Maintenance_SendIndicatorPointEntryEvents = new EventId(230015, "Maintenance_SendIndicatorPointEntryEvents");
public static final EventId Maintenance_SendIndicatorResetEntryEvents = new EventId(230014, "Maintenance_SendIndicatorResetEntryEvents");
public static final EventId Maintenance_SendIndicatorAccessEntryEvents = new EventId(230015, "Maintenance_SendIndicatorAccessEntryEvents");
public static final EventId Maintenance_SendIndicatorPointEntryEvents = new EventId(230016, "Maintenance_SendIndicatorPointEntryEvents");
public static final EventId Principal_Lookup = new EventId(240000, "Principal_Lookup");

View File

@ -40,6 +40,8 @@ public class OutboxIntegrationEvent extends IntegrationEvent {
public static final String INDICATOR_ENTRY = "INDICATOR_ENTRY";
public static final String INDICATOR_RESET_ENTRY = "INDICATOR_RESET_ENTRY";
private TrackedEvent event;
public TrackedEvent getEvent() {

View File

@ -40,6 +40,8 @@ public class OutboxProperties {
private final String indicatorTopic;
private final String indicatorResetTopic;
private final String indicatorAccessTopic;
private final String generateFileTopic;
@ -58,7 +60,7 @@ public class OutboxProperties {
String notifyTopic,
String forgetMeCompletedTopic,
String whatYouKnowAboutMeCompletedTopic,
String accountingEntryCreatedTopic, String indicatorPointTopic, String indicatorTopic, String indicatorAccessTopic, String generateFileTopic
String accountingEntryCreatedTopic, String indicatorPointTopic, String indicatorTopic, String indicatorResetTopic, String indicatorAccessTopic, String generateFileTopic
) {
this.exchange = exchange;
this.handleAckRetries = handleAckRetries;
@ -81,6 +83,7 @@ public class OutboxProperties {
this.accountingEntryCreatedTopic = accountingEntryCreatedTopic;
this.indicatorPointTopic = indicatorPointTopic;
this.indicatorTopic = indicatorTopic;
this.indicatorResetTopic = indicatorResetTopic;
this.indicatorAccessTopic = indicatorAccessTopic;
this.generateFileTopic = generateFileTopic;
}
@ -173,6 +176,10 @@ public class OutboxProperties {
return indicatorTopic;
}
public String getIndicatorResetTopic() {
return indicatorResetTopic;
}
public String getIndicatorAccessTopic() {
return indicatorAccessTopic;
}

View File

@ -454,6 +454,10 @@ public class OutboxRepositoryImpl implements OutboxRepository {
routingKey = this.outboxProperties.getIndicatorTopic();
break;
}
case OutboxIntegrationEvent.INDICATOR_RESET_ENTRY: {
routingKey = this.outboxProperties.getIndicatorResetTopic();
break;
}
case OutboxIntegrationEvent.INDICATOR_ACCESS_ENTRY: {
routingKey = this.outboxProperties.getIndicatorAccessTopic();
break;

View File

@ -0,0 +1,67 @@
package org.opencdmp.integrationevent.outbox.indicatoraccess;
import gr.cite.tools.validation.specification.Specification;
import org.opencdmp.commons.validation.BaseValidator;
import org.opencdmp.convention.ConventionService;
import org.opencdmp.errorcode.ErrorThesaurusProperties;
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 FilterColumnConfig {
private String column;
public static final String _column = "column";
private List<String> values;
public String getColumn() {
return column;
}
public void setColumn(String column) {
this.column = column;
}
public List<String> getValues() {
return values;
}
public void setValues(List<String> values) {
this.values = values;
}
@Component(FilterColumnConfigValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class FilterColumnConfigValidator extends BaseValidator<FilterColumnConfig> {
public static final String ValidatorName = "Indicatoraccess.FilterColumnConfigValidator";
private final MessageSource messageSource;
protected FilterColumnConfigValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors);
this.messageSource = messageSource;
}
@Override
protected Class<FilterColumnConfig> modelClass() {
return FilterColumnConfig.class;
}
@Override
protected List<Specification> specifications(FilterColumnConfig item) {
return Arrays.asList(
this.spec()
.must(() -> !this.isEmpty(item.getColumn()))
.failOn(FilterColumnConfig._column).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{FilterColumnConfig._column}, LocaleContextHolder.getLocale()))
);
}
}
}

View File

@ -0,0 +1,77 @@
package org.opencdmp.integrationevent.outbox.indicatoraccess;
import gr.cite.tools.validation.ValidatorFactory;
import gr.cite.tools.validation.specification.Specification;
import org.opencdmp.commons.validation.BaseValidator;
import org.opencdmp.convention.ConventionService;
import org.opencdmp.errorcode.ErrorThesaurusProperties;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.UUID;
public class IndicatorAccessConfig {
private List<FilterColumnConfig> globalFilterColumns;
public static final String _globalFilterColumns = "globalFilterColumns";
private Map<UUID, List<FilterColumnConfig>> groupFilterColumns;
public static final String _groupFilterColumns = "groupFilterColumns";
public List<FilterColumnConfig> getGlobalFilterColumns() {
return globalFilterColumns;
}
public void setGlobalFilterColumns(List<FilterColumnConfig> globalFilterColumns) {
this.globalFilterColumns = globalFilterColumns;
}
public Map<UUID, List<FilterColumnConfig>> getGroupFilterColumns() {
return groupFilterColumns;
}
public void setGroupFilterColumns(Map<UUID, List<FilterColumnConfig>> groupFilterColumns) {
this.groupFilterColumns = groupFilterColumns;
}
@Component(IndicatorAccessConfigValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class IndicatorAccessConfigValidator extends BaseValidator<IndicatorAccessConfig> {
public static final String ValidatorName = "IndicatorAccessConfigValidator";
private final MessageSource messageSource;
private final ValidatorFactory validatorFactory;
protected IndicatorAccessConfigValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) {
super(conventionService, errors);
this.messageSource = messageSource;
this.validatorFactory = validatorFactory;
}
@Override
protected Class<IndicatorAccessConfig> modelClass() {
return IndicatorAccessConfig.class;
}
@Override
protected List<Specification> specifications(IndicatorAccessConfig item) {
return Arrays.asList(
this.navSpec()
.iff(() -> !this.isListNullOrEmpty(item.getGlobalFilterColumns()))
.on(IndicatorAccessConfig._globalFilterColumns)
.over(item.getGlobalFilterColumns())
.using((itm) -> this.validatorFactory.validator(FilterColumnConfig.FilterColumnConfigValidator.class))
);
}
}
}

View File

@ -1,15 +1,29 @@
package org.opencdmp.integrationevent.outbox.indicatoraccess;
import gr.cite.tools.validation.ValidatorFactory;
import gr.cite.tools.validation.specification.Specification;
import org.opencdmp.commons.validation.BaseValidator;
import org.opencdmp.convention.ConventionService;
import org.opencdmp.errorcode.ErrorThesaurusProperties;
import org.opencdmp.integrationevent.TrackedEvent;
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 IndicatorAccessEvent extends TrackedEvent {
private UUID userId;
public static final String _indicatorId= "indicatorId";
public static final String _userId= "userId";
private UUID indicatorId;
public static final String _indicatorId= "indicatorId";
private IndicatorAccessConfig config;
public static final String _config = "config";
public UUID getUserId() {
return userId;
@ -26,4 +40,48 @@ public class IndicatorAccessEvent extends TrackedEvent {
public void setIndicatorId(UUID indicatorId) {
this.indicatorId = indicatorId;
}
public IndicatorAccessConfig getConfig() {
return config;
}
public void setConfig(IndicatorAccessConfig config) {
this.config = config;
}
@Component(IndicatorAccessEventValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class IndicatorAccessEventValidator extends BaseValidator<IndicatorAccessEvent> {
public static final String ValidatorName = "IndicatorAccessEventValidator";
private final MessageSource messageSource;
private final ValidatorFactory validatorFactory;
protected IndicatorAccessEventValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) {
super(conventionService, errors);
this.messageSource = messageSource;
this.validatorFactory = validatorFactory;
}
@Override
protected Class<IndicatorAccessEvent> modelClass() {
return IndicatorAccessEvent.class;
}
@Override
protected List<Specification> specifications(IndicatorAccessEvent item) {
return Arrays.asList(
this.spec()
.must(() -> this.isValidGuid(item.getIndicatorId()))
.failOn(IndicatorAccessEvent._indicatorId).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{IndicatorAccessEvent._indicatorId}, LocaleContextHolder.getLocale())),
this.refSpec()
.iff(() -> !this.isNull(item.getConfig()))
.on(IndicatorAccessEvent._config)
.over(item.getConfig())
.using(() -> this.validatorFactory.validator(IndicatorAccessConfig.IndicatorAccessConfigValidator.class))
);
}
}
}

View File

@ -0,0 +1,85 @@
package org.opencdmp.integrationevent.outbox.indicatorreset;
import gr.cite.tools.validation.ValidatorFactory;
import gr.cite.tools.validation.specification.Specification;
import org.opencdmp.commons.validation.BaseValidator;
import org.opencdmp.convention.ConventionService;
import org.opencdmp.errorcode.ErrorThesaurusProperties;
import org.opencdmp.integrationevent.TrackedEvent;
import org.opencdmp.integrationevent.outbox.indicator.IndicatorMetadata;
import org.opencdmp.integrationevent.outbox.indicator.IndicatorSchema;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
public class IndicatorResetEvent extends TrackedEvent {
private UUID id;
private IndicatorMetadata metadata;
private IndicatorSchema schema;
public static final String _schema = "schema";
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public IndicatorMetadata getMetadata() {
return metadata;
}
public void setMetadata(IndicatorMetadata metadata) {
this.metadata = metadata;
}
public IndicatorSchema getSchema() {
return schema;
}
public void setSchema(IndicatorSchema schema) {
this.schema = schema;
}
@Component(IndicatorResetEventValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class IndicatorResetEventValidator extends BaseValidator<IndicatorResetEvent> {
public static final String ValidatorName = "IndicatorResetEventValidator";
private final MessageSource messageSource;
private final ValidatorFactory validatorFactory;
protected IndicatorResetEventValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) {
super(conventionService, errors);
this.messageSource = messageSource;
this.validatorFactory = validatorFactory;
}
@Override
protected Class<IndicatorResetEvent> modelClass() {
return IndicatorResetEvent.class;
}
@Override
protected List<Specification> specifications(IndicatorResetEvent item) {
return Arrays.asList(
this.refSpec()
.iff(() -> !this.isNull(item.getSchema()))
.on(IndicatorResetEvent._schema)
.over(item.getSchema())
.using(() -> this.validatorFactory.validator(IndicatorSchema.IndicatorSchemaValidator.class))
);
}
}
}

View File

@ -0,0 +1,9 @@
package org.opencdmp.integrationevent.outbox.indicatorreset;
public interface IndicatorResetEventHandler {
void handle(IndicatorResetEvent event);
}

View File

@ -0,0 +1,42 @@
package org.opencdmp.integrationevent.outbox.indicatorreset;
import gr.cite.tools.logging.LoggerService;
import org.opencdmp.integrationevent.outbox.OutboxIntegrationEvent;
import org.opencdmp.integrationevent.outbox.OutboxService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.UUID;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class IndicatorResetEventHandlerImpl implements IndicatorResetEventHandler {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(IndicatorResetEventHandlerImpl.class));
private final OutboxService outboxService;
private final ApplicationContext applicationContext;
@Autowired
public IndicatorResetEventHandlerImpl(OutboxService outboxService, ApplicationContext applicationContext) {
this.outboxService = outboxService;
this.applicationContext = applicationContext;
}
@Override
public void handle(IndicatorResetEvent event) {
OutboxIntegrationEvent message = new OutboxIntegrationEvent();
message.setMessageId(UUID.randomUUID());
message.setType(OutboxIntegrationEvent.INDICATOR_RESET_ENTRY);
message.setEvent(event);
message.setTenantId(null);
this.outboxService.publish(message);
}
}

View File

@ -2,13 +2,14 @@ package org.opencdmp.service.maintenance;
import org.springframework.boot.context.properties.ConfigurationProperties;
import java.util.List;
import java.util.UUID;
@ConfigurationProperties(prefix = "kpi.user-indicator")
public class KpiProperties {
private UUID id;
private UUID user;
private List<UUID> userIds;
private String label;
@ -26,12 +27,12 @@ public class KpiProperties {
this.id = id;
}
public UUID getUser() {
return user;
public List<UUID> getUserIds() {
return userIds;
}
public void setUser(UUID user) {
this.user = user;
public void setUserIds(List<UUID> userIds) {
this.userIds = userIds;
}
public String getLabel() {

View File

@ -31,6 +31,8 @@ public interface MaintenanceService {
void sendIndicatorCreateEntryEvents() throws InvalidApplicationException;
void sendIndicatorResetEntryEvents() throws InvalidApplicationException;
void sendIndicatorAccessEntryEvents() throws InvalidApplicationException;
void sendIndicatorPointEntryEvents() throws InvalidApplicationException;

View File

@ -16,10 +16,14 @@ import org.opencdmp.integrationevent.outbox.accountingentrycreated.AccountingEnt
import org.opencdmp.integrationevent.outbox.annotationentityremoval.AnnotationEntityRemovalIntegrationEventHandler;
import org.opencdmp.integrationevent.outbox.annotationentitytouch.AnnotationEntityTouchedIntegrationEventHandler;
import org.opencdmp.integrationevent.outbox.indicator.*;
import org.opencdmp.integrationevent.outbox.indicatoraccess.FilterColumnConfig;
import org.opencdmp.integrationevent.outbox.indicatoraccess.IndicatorAccessConfig;
import org.opencdmp.integrationevent.outbox.indicatoraccess.IndicatorAccessEvent;
import org.opencdmp.integrationevent.outbox.indicatoraccess.IndicatorAccessEventHandler;
import org.opencdmp.integrationevent.outbox.indicatorpoint.IndicatorPointEvent;
import org.opencdmp.integrationevent.outbox.indicatorpoint.IndicatorPointEventHandler;
import org.opencdmp.integrationevent.outbox.indicatorreset.IndicatorResetEvent;
import org.opencdmp.integrationevent.outbox.indicatorreset.IndicatorResetEventHandler;
import org.opencdmp.integrationevent.outbox.tenantremoval.TenantRemovalIntegrationEventHandler;
import org.opencdmp.integrationevent.outbox.tenanttouched.TenantTouchedIntegrationEvent;
import org.opencdmp.integrationevent.outbox.tenanttouched.TenantTouchedIntegrationEventHandler;
@ -69,13 +73,14 @@ public class MaintenanceServiceImpl implements MaintenanceService {
private final AccountingService accountingService;
private final KpiProperties kpiProperties;
private final IndicatorElasticEventHandler indicatorElasticEventHandler;
private final IndicatorResetEventHandler indicatorResetEventHandler;
private final IndicatorAccessEventHandler indicatorAccessEventHandler;
private final IndicatorPointEventHandler indicatorPointEventHandler;
private final ValidatorFactory validatorFactory;
public MaintenanceServiceImpl(
TenantEntityManager entityManager, AuthorizationService authorizationService,
QueryFactory queryFactory, UserTouchedIntegrationEventHandler userTouchedIntegrationEventHandler, UserRemovalIntegrationEventHandler userRemovalIntegrationEventHandler, TenantTouchedIntegrationEventHandler tenantTouchedIntegrationEventHandler, TenantRemovalIntegrationEventHandler tenantRemovalIntegrationEventHandler, AnnotationEntityRemovalIntegrationEventHandler annotationEntityRemovalIntegrationEventHandler, AnnotationEntityTouchedIntegrationEventHandler annotationEntityTouchedIntegrationEventHandler, AccountingEntryCreatedIntegrationEventHandler accountingEntryCreatedIntegrationEventHandler, TenantScope tenantScope, TenantEntityManager tenantEntityManager, AccountingProperties accountingProperties, AccountingService accountingService, KpiProperties kpiProperties, IndicatorElasticEventHandler indicatorElasticEventHandler, IndicatorAccessEventHandler indicatorAccessEventHandler, IndicatorPointEventHandler indicatorPointEventHandler, ValidatorFactory validatorFactory) {
QueryFactory queryFactory, UserTouchedIntegrationEventHandler userTouchedIntegrationEventHandler, UserRemovalIntegrationEventHandler userRemovalIntegrationEventHandler, TenantTouchedIntegrationEventHandler tenantTouchedIntegrationEventHandler, TenantRemovalIntegrationEventHandler tenantRemovalIntegrationEventHandler, AnnotationEntityRemovalIntegrationEventHandler annotationEntityRemovalIntegrationEventHandler, AnnotationEntityTouchedIntegrationEventHandler annotationEntityTouchedIntegrationEventHandler, AccountingEntryCreatedIntegrationEventHandler accountingEntryCreatedIntegrationEventHandler, TenantScope tenantScope, TenantEntityManager tenantEntityManager, AccountingProperties accountingProperties, AccountingService accountingService, KpiProperties kpiProperties, IndicatorElasticEventHandler indicatorElasticEventHandler, IndicatorResetEventHandler indicatorResetEventHandler, IndicatorAccessEventHandler indicatorAccessEventHandler, IndicatorPointEventHandler indicatorPointEventHandler, ValidatorFactory validatorFactory) {
this.entityManager = entityManager;
this.authorizationService = authorizationService;
this.queryFactory = queryFactory;
@ -92,6 +97,7 @@ public class MaintenanceServiceImpl implements MaintenanceService {
this.accountingService = accountingService;
this.kpiProperties = kpiProperties;
this.indicatorElasticEventHandler = indicatorElasticEventHandler;
this.indicatorResetEventHandler = indicatorResetEventHandler;
this.indicatorAccessEventHandler = indicatorAccessEventHandler;
this.indicatorPointEventHandler = indicatorPointEventHandler;
this.validatorFactory = validatorFactory;
@ -415,6 +421,23 @@ public class MaintenanceServiceImpl implements MaintenanceService {
public void sendIndicatorCreateEntryEvents() throws InvalidApplicationException {
IndicatorElasticEvent event = new IndicatorElasticEvent();
event.setId(this.kpiProperties.getId());
event.setMetadata(this.defineMetadata());
event.setSchema(this.defineSchema());
this.validatorFactory.validator(IndicatorElasticEvent.IndicatorElasticEventValidator.class).validateForce(event);
this.indicatorElasticEventHandler.handle(event);
}
@Override
public void sendIndicatorResetEntryEvents() throws InvalidApplicationException {
IndicatorResetEvent event = new IndicatorResetEvent();
event.setId(this.kpiProperties.getId());
event.setMetadata(this.defineMetadata());
event.setSchema(this.defineSchema());
this.validatorFactory.validator(IndicatorResetEvent.IndicatorResetEventValidator.class).validateForce(event);
this.indicatorResetEventHandler.handle(event);
}
private IndicatorMetadata defineMetadata() {
IndicatorMetadata metadata = new IndicatorMetadata();
metadata.setCode(this.kpiProperties.getCode());
metadata.setLabel(this.kpiProperties.getLabel());
@ -422,72 +445,67 @@ public class MaintenanceServiceImpl implements MaintenanceService {
metadata.setUrl(this.kpiProperties.getUrl());
metadata.setDate(Instant.now());
event.setMetadata(metadata);
return metadata;
}
try {
this.tenantEntityManager.disableTenantFilters();
List<TenantUserEntity> tenantUserEntities = this.queryFactory.query(TenantUserQuery.class).disableTracking().userIds(this.kpiProperties.getUser()).collectAs(new BaseFieldSet().ensure(TenantUser._tenant));
List<IndicatorField> fields = new ArrayList<>();
private IndicatorSchema defineSchema() {
IndicatorSchema schema = new IndicatorSchema();
schema.setId(this.kpiProperties.getId());
IndicatorField field = new IndicatorField();
field.setCode("tenant_code");
field.setName("Tenant Code");
field.setBasetype(IndicatorFieldBaseType.Keyword);
fields.add(field);
List<IndicatorField> fields = new ArrayList<>();
IndicatorField field1 = new IndicatorField();
field1.setCode("user_id");
field1.setName("User Id");
field1.setBasetype(IndicatorFieldBaseType.Keyword);
fields.add(field1);
IndicatorField field = new IndicatorField();
field.setCode("tenant_code");
field.setName("Tenant Code");
field.setBasetype(IndicatorFieldBaseType.Keyword);
fields.add(field);
IndicatorField field2 = new IndicatorField();
field2.setCode("created_at");
field2.setName("Created at");
field2.setBasetype(IndicatorFieldBaseType.Date);
fields.add(field2);
IndicatorField field1 = new IndicatorField();
field1.setCode("user_id");
field1.setName("User Id");
field1.setBasetype(IndicatorFieldBaseType.Keyword);
fields.add(field1);
UserEntity user = this.queryFactory.query(UserQuery.class).disableTracking().ids(this.kpiProperties.getUser()).firstAs(new BaseFieldSet().ensure(User._name));
if (user == null) {
throw new MyApplicationException("user not found");
}
IndicatorField field3 = new IndicatorField();
field3.setCode("user_name");
field3.setName("User Name");
field3.setBasetype(IndicatorFieldBaseType.String);
fields.add(field3);
IndicatorField field2 = new IndicatorField();
field2.setCode("created_at");
field2.setName("Created at");
field2.setBasetype(IndicatorFieldBaseType.Date);
fields.add(field2);
IndicatorField field4 = new IndicatorField();
field4.setCode("value");
field4.setName("Value");
field4.setBasetype(IndicatorFieldBaseType.Integer);
fields.add(field4);
IndicatorField field3 = new IndicatorField();
field3.setCode("user_name");
field3.setName("User Name");
field3.setBasetype(IndicatorFieldBaseType.String);
fields.add(field3);
IndicatorSchema schema = new IndicatorSchema();
schema.setId(this.kpiProperties.getId());
schema.setFields(fields);
IndicatorField field4 = new IndicatorField();
field4.setCode("value");
field4.setName("Value");
field4.setBasetype(IndicatorFieldBaseType.Integer);
fields.add(field4);
event.setSchema(schema);
schema.setFields(fields);
this.validatorFactory.validator(IndicatorElasticEvent.IndicatorElasticEventValidator.class).validateForce(event);
this.indicatorElasticEventHandler.handle(event);
} finally {
this.tenantEntityManager.reloadTenantFilters();
}
return schema;
}
@Override
public void sendIndicatorAccessEntryEvents() throws InvalidApplicationException {
IndicatorAccessEvent event = new IndicatorAccessEvent();
event.setIndicatorId(this.kpiProperties.getId());
event.setUserId(this.kpiProperties.getUser());
try {
for (UUID userId: this.kpiProperties.getUserIds()) {
this.indicatorAccessEventHandler.handle(this.createIndicatorAccessEvent(userId, this.tenantScope.getDefaultTenantCode()), null);
}
this.tenantEntityManager.disableTenantFilters();
List<TenantUserEntity> tenantUserEntities = this.queryFactory.query(TenantUserQuery.class).disableTracking().userIds(this.kpiProperties.getUser()).collectAs(new BaseFieldSet().ensure(TenantUser._tenant));
if (tenantUserEntities != null) {
List<TenantUserEntity> tenantUserEntities = this.queryFactory.query(TenantUserQuery.class).disableTracking().userIds(this.kpiProperties.getUserIds()).collect();
if (tenantUserEntities == null || tenantUserEntities.isEmpty()) throw new MyApplicationException("tenant users not found");
List<TenantEntity> tenantEntities = this.queryFactory.query(TenantQuery.class).disableTracking().ids(tenantUserEntities.stream().map(TenantUserEntity::getTenantId).distinct().toList()).collectAs(new BaseFieldSet().ensure(Tenant._id).ensure(Tenant._code));
if (tenantEntities != null && !tenantEntities.isEmpty()) {
for (TenantUserEntity user: tenantUserEntities) {
this.indicatorAccessEventHandler.handle(event, user.getTenantId());
TenantEntity tenant = tenantEntities.stream().filter(x -> x.getId().equals(user.getTenantId())).findFirst().orElse(null);
if (tenant != null){
this.indicatorAccessEventHandler.handle(this.createIndicatorAccessEvent(user.getUserId(), tenant.getCode()), tenant.getId());
}
}
}
} finally {
@ -495,32 +513,49 @@ public class MaintenanceServiceImpl implements MaintenanceService {
}
}
private IndicatorAccessEvent createIndicatorAccessEvent(UUID userId, String tenantCode) {
IndicatorAccessEvent event = new IndicatorAccessEvent();
event.setIndicatorId(this.kpiProperties.getId());
event.setUserId(userId);
List<FilterColumnConfig> globalFilterColumns = new ArrayList<>();
FilterColumnConfig filterColumn = new FilterColumnConfig();
filterColumn.setColumn("tenant_code");
filterColumn.setValues(List.of(tenantCode));
globalFilterColumns.add(filterColumn);
IndicatorAccessConfig config = new IndicatorAccessConfig();
config.setGlobalFilterColumns(globalFilterColumns);
event.setConfig(config);
this.validatorFactory.validator(IndicatorAccessEvent.IndicatorAccessEventValidator.class).validateForce(event);
return event;
}
@Override
public void sendIndicatorPointEntryEvents() throws InvalidApplicationException {
IndicatorPointEvent event = new IndicatorPointEvent();
event.setIndicatorId(this.kpiProperties.getId());
event.add("user_id", this.kpiProperties.getUser());
event.add("created_at", Instant.now());
event.add("value", 1);
UserEntity user = this.queryFactory.query(UserQuery.class).disableTracking().ids(this.kpiProperties.getUser()).firstAs(new BaseFieldSet().ensure(User._name));
if (user == null) {
throw new MyApplicationException("user not found");
}
event.add("user_name", user.getName());
try {
this.tenantEntityManager.disableTenantFilters();
List<TenantUserEntity> tenantUserEntities = this.queryFactory.query(TenantUserQuery.class).disableTracking().userIds(this.kpiProperties.getUser()).collectAs(new BaseFieldSet().ensure(TenantUser._tenant));
if (tenantUserEntities != null) {
List<UserEntity> users = this.queryFactory.query(UserQuery.class).disableTracking().isActive(IsActive.Active).collectAs(new BaseFieldSet().ensure(User._id).ensure(User._name).ensure(User._createdAt));
if (users == null || users.isEmpty()) {
throw new MyApplicationException("users not found");
}
for (UserEntity user: users) {
this.indicatorPointEventHandler.handle(this.createIndicatorPointEvent(user, user.getCreatedAt(), this.tenantScope.getDefaultTenantCode()));
}
List<TenantUserEntity> tenantUserEntities = this.queryFactory.query(TenantUserQuery.class).disableTracking().collect();
if (tenantUserEntities != null && !tenantUserEntities.isEmpty()) {
List<TenantEntity> tenantEntities = this.queryFactory.query(TenantQuery.class).disableTracking().ids(tenantUserEntities.stream().map(TenantUserEntity::getTenantId).distinct().toList()).collect();
if (tenantEntities != null) {
for (TenantEntity tenant: tenantEntities) {
event.add("tenant_code", tenant.getCode());
this.validatorFactory.validator(IndicatorPointEvent.IndicatorPointEventValidator.class).validateForce(event);
this.indicatorPointEventHandler.handle(event);
for (TenantUserEntity tenantUser: tenantUserEntities) {
TenantEntity tenantEntity = tenantEntities.stream().filter(x -> x.getId().equals(tenantUser.getTenantId())).findFirst().orElse(null);
UserEntity userToAdd = users.stream().filter(x -> tenantUser.getUserId().equals(x.getId())).findFirst().orElse(null);
if (userToAdd != null && tenantEntity != null) {
this.indicatorPointEventHandler.handle(this.createIndicatorPointEvent(userToAdd, tenantUser.getCreatedAt(), tenantEntity.getCode()));
}
}
}
@ -529,4 +564,18 @@ public class MaintenanceServiceImpl implements MaintenanceService {
this.tenantEntityManager.reloadTenantFilters();
}
}
private IndicatorPointEvent createIndicatorPointEvent(UserEntity user, Instant createAt, String tenantCode) {
IndicatorPointEvent event = new IndicatorPointEvent();
event.setIndicatorId(this.kpiProperties.getId());
event.add("user_id", user.getId());
event.add("created_at", createAt);
event.add("user_name", user.getName());
event.add("value", 1);
event.add("tenant_code", tenantCode);
this.validatorFactory.validator(IndicatorPointEvent.IndicatorPointEventValidator.class).validateForce(event);
return event;
}
}

View File

@ -192,6 +192,16 @@ public class MaintenanceController {
this.auditService.track(AuditableAction.Maintenance_SendIndicatorCreateEntryEvents);
}
@RequestMapping(method = RequestMethod.POST, value = "/events/indicator-reset-entry")
public void sendIndicatorResetEvents() throws InvalidApplicationException {
logger.debug("send indicator reset entry queue events");
this.authorizationService.authorizeForce(Permission.ManageQueueEvents);
this.maintenanceService.sendIndicatorResetEntryEvents();
this.auditService.track(AuditableAction.Maintenance_SendIndicatorResetEntryEvents);
}
@RequestMapping(method = RequestMethod.POST, value = "/events/indicator-access-entry")
public void sendIndicatorAccessEvents() throws InvalidApplicationException {
logger.debug("send indicator create entry queue events");

View File

@ -1,7 +1,9 @@
kpi:
user-indicator:
id: 97c2d685-d7d2-4bd1-a287-ba329ad45d74
user: 8552f758-f196-4a51-a3fd-154c088d85c4
userIds:
- 8552f758-f196-4a51-a3fd-154c088d85c4
- e60876ed-87f8-4a8e-8081-e5620ec839cf
label: test
description: test
url: url test

View File

@ -44,6 +44,7 @@ queue:
what-you-know-about-me-completed-topic: whatyouknowaboutme.completed
accounting-entry-created-topic: accountingentry.create
indicator-topic: indicator.entry
indicator-reset-topic: indicator_reset.entry
indicator-point-topic: indicator_point.entry
indicator-access-topic: indicator_access.entry
generate-file-topic: generate.file

View File

@ -121,6 +121,13 @@ export class MaintenanceService extends BaseService {
catchError((error: any) => throwError(error)));
}
sendIndicatorResetEvents(): Observable<any> {
const url = `${this.apiBase}/events/indicator-reset-entry`;
return this.http
.post<any>(url, null).pipe(
catchError((error: any) => throwError(error)));
}
sendIndicatorAccessEvents(): Observable<any> {
const url = `${this.apiBase}/events/indicator-access-entry`;
return this.http

View File

@ -51,6 +51,7 @@
<div class="mt-2">
<h3>{{language.instant('MAINTENANCE-TASKS.SECTIONS.EVENTS.INDICATOR-TITLE')}}</h3>
<button mat-button (click)="sendIndicatorCreateEvents($event)" class="mb-1 mr-1 rounded-btn primary">{{language.instant('MAINTENANCE-TASKS.SECTIONS.EVENTS.ACTIONS.SEND-INDICATOR-CREATE-ENTRY')}}</button>
<button mat-button (click)="sendIndicatorResetEvents($event)" class="mb-1 mr-1 rounded-btn primary">{{language.instant('MAINTENANCE-TASKS.SECTIONS.EVENTS.ACTIONS.SEND-INDICATOR-RESET-ENTRY')}}</button>
<button mat-button (click)="sendIndicatorAccessEvents($event)" class="mb-1 mr-1 rounded-btn primary">{{language.instant('MAINTENANCE-TASKS.SECTIONS.EVENTS.ACTIONS.SEND-INDICATOR-ACCESS-ENTRY')}}</button>
<button mat-button (click)="sendIndicatorPointEvents($event)" class="mb-1 mr-1 rounded-btn primary">{{language.instant('MAINTENANCE-TASKS.SECTIONS.EVENTS.ACTIONS.SEND-INDICATOR-POINT-ENTRY')}}</button>
</div>

View File

@ -496,6 +496,37 @@ export class MaintenanceTasksComponent extends BaseComponent implements OnInit {
);
}
sendIndicatorResetEvents(ev: Event) {
this.dialog.open(ConfirmationDialogComponent, {
data: {
message: this.language.instant('MAINTENANCE-TASKS.CONFIRMATION.MESSAGE'),
confirmButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CONFIRM'),
cancelButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CANCEL')
},
maxWidth: '30em'
})
.afterClosed()
.subscribe(confirm => {
if (confirm) {
this.doSendIndicatorResetEvents(ev);
}
});
}
private doSendIndicatorResetEvents(ev: Event) {
(ev.target as HTMLButtonElement).disabled = true;
this.maintenanceService.sendIndicatorResetEvents().pipe(takeUntil(this._destroyed)).subscribe(
_ => {
(ev.target as HTMLButtonElement).disabled = false;
this.onCallbackSuccess();
},
error => {
(ev.target as HTMLButtonElement).disabled = false;
this.onCallbackError(error);
}
);
}
sendIndicatorAccessEvents(ev: Event) {
this.dialog.open(ConfirmationDialogComponent, {
data: {

View File

@ -424,6 +424,7 @@
"SEND-REFERENCE-TYPE-ACCOUNTING-ENTRIES": "Send reference type accounting entries events",
"SEND-USER-ACCOUNTING-ENTRIES": "Send user accounting entries events",
"SEND-INDICATOR-CREATE-ENTRY": "Send indicator create entry events",
"SEND-INDICATOR-RESET-ENTRY": "Send indicator reset entry events",
"SEND-INDICATOR-ACCESS-ENTRY": "Send indicator access entry events",
"SEND-INDICATOR-POINT-ENTRY": "Send indicator point entry events"
}

View File

@ -424,6 +424,7 @@
"SEND-REFERENCE-TYPE-ACCOUNTING-ENTRIES": "Send reference type accounting entries events",
"SEND-USER-ACCOUNTING-ENTRIES": "Send user accounting entries events",
"SEND-INDICATOR-CREATE-ENTRY": "Send indicator create entry events",
"SEND-INDICATOR-RESET-ENTRY": "Send indicator reset entry events",
"SEND-INDICATOR-ACCESS-ENTRY": "Send indicator access entry events",
"SEND-INDICATOR-POINT-ENTRY": "Send indicator point entry events"
}

View File

@ -422,6 +422,7 @@
"SEND-REFERENCE-TYPE-ACCOUNTING-ENTRIES": "Send reference type accounting entries events",
"SEND-USER-ACCOUNTING-ENTRIES": "Send user accounting entries events",
"SEND-INDICATOR-CREATE-ENTRY": "Send indicator create entry events",
"SEND-INDICATOR-RESET-ENTRY": "Send indicator reset entry events",
"SEND-INDICATOR-ACCESS-ENTRY": "Send indicator access entry events",
"SEND-INDICATOR-POINT-ENTRY": "Send indicator point entry events"
}

View File

@ -424,6 +424,7 @@
"SEND-REFERENCE-TYPE-ACCOUNTING-ENTRIES": "Send reference type accounting entries events",
"SEND-USER-ACCOUNTING-ENTRIES": "Send user accounting entries events",
"SEND-INDICATOR-CREATE-ENTRY": "Send indicator create entry events",
"SEND-INDICATOR-RESET-ENTRY": "Send indicator reset entry events",
"SEND-INDICATOR-ACCESS-ENTRY": "Send indicator access entry events",
"SEND-INDICATOR-POINT-ENTRY": "Send indicator point entry events"
}

View File

@ -424,6 +424,7 @@
"SEND-REFERENCE-TYPE-ACCOUNTING-ENTRIES": "Send reference type accounting entries events",
"SEND-USER-ACCOUNTING-ENTRIES": "Send user accounting entries events",
"SEND-INDICATOR-CREATE-ENTRY": "Send indicator create entry events",
"SEND-INDICATOR-RESET-ENTRY": "Send indicator reset entry events",
"SEND-INDICATOR-ACCESS-ENTRY": "Send indicator access entry events",
"SEND-INDICATOR-POINT-ENTRY": "Send indicator point entry events"
}

View File

@ -424,6 +424,7 @@
"SEND-REFERENCE-TYPE-ACCOUNTING-ENTRIES": "Send reference type accounting entries events",
"SEND-USER-ACCOUNTING-ENTRIES": "Send user accounting entries events",
"SEND-INDICATOR-CREATE-ENTRY": "Send indicator create entry events",
"SEND-INDICATOR-RESET-ENTRY": "Send indicator reset entry events",
"SEND-INDICATOR-ACCESS-ENTRY": "Send indicator access entry events",
"SEND-INDICATOR-POINT-ENTRY": "Send indicator point entry events"
}

View File

@ -424,6 +424,7 @@
"SEND-REFERENCE-TYPE-ACCOUNTING-ENTRIES": "Send reference type accounting entries events",
"SEND-USER-ACCOUNTING-ENTRIES": "Send user accounting entries events",
"SEND-INDICATOR-CREATE-ENTRY": "Send indicator create entry events",
"SEND-INDICATOR-RESET-ENTRY": "Send indicator reset entry events",
"SEND-INDICATOR-ACCESS-ENTRY": "Send indicator access entry events",
"SEND-INDICATOR-POINT-ENTRY": "Send indicator point entry events"
}

View File

@ -424,6 +424,7 @@
"SEND-REFERENCE-TYPE-ACCOUNTING-ENTRIES": "Send reference type accounting entries events",
"SEND-USER-ACCOUNTING-ENTRIES": "Send user accounting entries events",
"SEND-INDICATOR-CREATE-ENTRY": "Send indicator create entry events",
"SEND-INDICATOR-RESET-ENTRY": "Send indicator reset entry events",
"SEND-INDICATOR-ACCESS-ENTRY": "Send indicator access entry events",
"SEND-INDICATOR-POINT-ENTRY": "Send indicator point entry events"
}

View File

@ -424,6 +424,7 @@
"SEND-REFERENCE-TYPE-ACCOUNTING-ENTRIES": "Send reference type accounting entries events",
"SEND-USER-ACCOUNTING-ENTRIES": "Send user accounting entries events",
"SEND-INDICATOR-CREATE-ENTRY": "Send indicator create entry events",
"SEND-INDICATOR-RESET-ENTRY": "Send indicator reset entry events",
"SEND-INDICATOR-ACCESS-ENTRY": "Send indicator access entry events",
"SEND-INDICATOR-POINT-ENTRY": "Send indicator point entry events"
}

View File

@ -424,6 +424,7 @@
"SEND-REFERENCE-TYPE-ACCOUNTING-ENTRIES": "Send reference type accounting entries events",
"SEND-USER-ACCOUNTING-ENTRIES": "Send user accounting entries events",
"SEND-INDICATOR-CREATE-ENTRY": "Send indicator create entry events",
"SEND-INDICATOR-RESET-ENTRY": "Send indicator reset entry events",
"SEND-INDICATOR-ACCESS-ENTRY": "Send indicator access entry events",
"SEND-INDICATOR-POINT-ENTRY": "Send indicator point entry events"
}

View File

@ -424,6 +424,7 @@
"SEND-REFERENCE-TYPE-ACCOUNTING-ENTRIES": "Send reference type accounting entries events",
"SEND-USER-ACCOUNTING-ENTRIES": "Send user accounting entries events",
"SEND-INDICATOR-CREATE-ENTRY": "Send indicator create entry events",
"SEND-INDICATOR-RESET-ENTRY": "Send indicator reset entry events",
"SEND-INDICATOR-ACCESS-ENTRY": "Send indicator access entry events",
"SEND-INDICATOR-POINT-ENTRY": "Send indicator point entry events"
}