maintenance changes
This commit is contained in:
parent
1c5c699195
commit
5a6ab32768
|
@ -0,0 +1,29 @@
|
|||
package eu.eudat.service.maintenance;
|
||||
|
||||
import eu.eudat.model.Description;
|
||||
import eu.eudat.model.Prefilling;
|
||||
import eu.eudat.model.PrefillingSource;
|
||||
import eu.eudat.model.persist.DescriptionProfilingRequest;
|
||||
import eu.eudat.model.persist.PrefillingSearchRequest;
|
||||
import eu.eudat.model.persist.PrefillingSourcePersist;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
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 jakarta.xml.bind.JAXBException;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import javax.management.InvalidApplicationException;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public interface MaintenanceService {
|
||||
|
||||
|
||||
void sendUserTouchEvents() throws InvalidApplicationException;
|
||||
|
||||
void sendTenantTouchEvents() throws InvalidApplicationException;
|
||||
}
|
|
@ -0,0 +1,113 @@
|
|||
package eu.eudat.service.maintenance;
|
||||
|
||||
import eu.eudat.authorization.Permission;
|
||||
import eu.eudat.commons.enums.IsActive;
|
||||
import eu.eudat.data.TenantEntity;
|
||||
import eu.eudat.data.TenantEntityManager;
|
||||
import eu.eudat.data.UserEntity;
|
||||
import eu.eudat.integrationevent.outbox.tenantremoval.TenantRemovalIntegrationEventHandler;
|
||||
import eu.eudat.integrationevent.outbox.tenanttouched.TenantTouchedIntegrationEvent;
|
||||
import eu.eudat.integrationevent.outbox.tenanttouched.TenantTouchedIntegrationEventHandler;
|
||||
import eu.eudat.integrationevent.outbox.userremoval.UserRemovalIntegrationEventHandler;
|
||||
import eu.eudat.integrationevent.outbox.usertouched.UserTouchedIntegrationEventHandler;
|
||||
import eu.eudat.model.Tenant;
|
||||
import eu.eudat.model.User;
|
||||
import eu.eudat.query.TenantQuery;
|
||||
import eu.eudat.query.UserQuery;
|
||||
import gr.cite.commons.web.authz.service.AuthorizationService;
|
||||
import gr.cite.tools.data.query.QueryFactory;
|
||||
import gr.cite.tools.fieldset.BaseFieldSet;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.management.InvalidApplicationException;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class MaintenanceServiceImpl implements MaintenanceService {
|
||||
|
||||
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(MaintenanceServiceImpl.class));
|
||||
private final TenantEntityManager entityManager;
|
||||
private final AuthorizationService authorizationService;
|
||||
private final QueryFactory queryFactory;
|
||||
|
||||
private final UserTouchedIntegrationEventHandler userTouchedIntegrationEventHandler;
|
||||
|
||||
private final UserRemovalIntegrationEventHandler userRemovalIntegrationEventHandler;
|
||||
|
||||
private final TenantTouchedIntegrationEventHandler tenantTouchedIntegrationEventHandler;
|
||||
|
||||
private final TenantRemovalIntegrationEventHandler tenantRemovalIntegrationEventHandler;
|
||||
|
||||
|
||||
public MaintenanceServiceImpl(
|
||||
TenantEntityManager entityManager, AuthorizationService authorizationService,
|
||||
QueryFactory queryFactory, UserTouchedIntegrationEventHandler userTouchedIntegrationEventHandler, UserRemovalIntegrationEventHandler userRemovalIntegrationEventHandler, TenantTouchedIntegrationEventHandler tenantTouchedIntegrationEventHandler, TenantRemovalIntegrationEventHandler tenantRemovalIntegrationEventHandler) {
|
||||
this.entityManager = entityManager;
|
||||
this.authorizationService = authorizationService;
|
||||
this.queryFactory = queryFactory;
|
||||
this.userTouchedIntegrationEventHandler = userTouchedIntegrationEventHandler;
|
||||
this.userRemovalIntegrationEventHandler = userRemovalIntegrationEventHandler;
|
||||
this.tenantTouchedIntegrationEventHandler = tenantTouchedIntegrationEventHandler;
|
||||
this.tenantRemovalIntegrationEventHandler = tenantRemovalIntegrationEventHandler;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void sendUserTouchEvents() throws InvalidApplicationException {
|
||||
logger.debug("send user touch queue events");
|
||||
this.authorizationService.authorizeForce(Permission.ManageQueueEvents);
|
||||
|
||||
List<UserEntity> activeUsers;
|
||||
List<UserEntity> inactiveUsers;
|
||||
try {
|
||||
this.entityManager.disableTenantFilters();
|
||||
UserQuery userQuery = queryFactory.query(UserQuery.class);
|
||||
userQuery.isActive(IsActive.Active);
|
||||
activeUsers = userQuery.collectAs(new BaseFieldSet().ensure(User._id));
|
||||
userQuery.isActive(IsActive.Inactive);
|
||||
inactiveUsers = userQuery.collectAs(new BaseFieldSet().ensure(User._id));
|
||||
this.entityManager.enableTenantFilters();
|
||||
|
||||
} finally {
|
||||
this.entityManager.enableTenantFilters();
|
||||
}
|
||||
for(UserEntity user : activeUsers)
|
||||
this.userTouchedIntegrationEventHandler.handle(user.getId());
|
||||
|
||||
for(UserEntity user : inactiveUsers)
|
||||
this.userRemovalIntegrationEventHandler.handle(user.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendTenantTouchEvents() throws InvalidApplicationException {
|
||||
logger.debug("send tenant touch queue events");
|
||||
this.authorizationService.authorizeForce(Permission.ManageQueueEvents);
|
||||
|
||||
List<TenantEntity> activeTenants;
|
||||
List<TenantEntity> inactiveTenants;
|
||||
try {
|
||||
this.entityManager.disableTenantFilters();
|
||||
TenantQuery tenantQuery = queryFactory.query(TenantQuery.class);
|
||||
tenantQuery.isActive(IsActive.Active);
|
||||
activeTenants = tenantQuery.collectAs(new BaseFieldSet().ensure(Tenant._id).ensure(Tenant._code));
|
||||
tenantQuery.isActive(IsActive.Inactive);
|
||||
inactiveTenants = tenantQuery.collectAs(new BaseFieldSet().ensure(Tenant._id).ensure(Tenant._code));
|
||||
|
||||
} finally {
|
||||
this.entityManager.enableTenantFilters();
|
||||
}
|
||||
for (TenantEntity tenant : activeTenants) {
|
||||
TenantTouchedIntegrationEvent event = new TenantTouchedIntegrationEvent();
|
||||
event.setId(tenant.getId());
|
||||
event.setCode(tenant.getCode());
|
||||
this.tenantTouchedIntegrationEventHandler.handle(event);
|
||||
}
|
||||
|
||||
for (TenantEntity tenant : inactiveTenants) {
|
||||
this.tenantRemovalIntegrationEventHandler.handle(tenant.getId());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -14,6 +14,7 @@ import eu.eudat.integrationevent.outbox.usertouched.UserTouchedIntegrationEventH
|
|||
import eu.eudat.query.TenantQuery;
|
||||
import eu.eudat.query.UserQuery;
|
||||
import eu.eudat.service.elastic.ElasticService;
|
||||
import eu.eudat.service.maintenance.MaintenanceService;
|
||||
import gr.cite.commons.web.authz.service.AuthorizationService;
|
||||
import gr.cite.tools.auditing.AuditService;
|
||||
import gr.cite.tools.data.query.QueryFactory;
|
||||
|
@ -40,38 +41,17 @@ public class MaintenanceController {
|
|||
|
||||
private final AuditService auditService;
|
||||
|
||||
private final QueryFactory queryFactory;
|
||||
|
||||
private final TenantEntityManager entityManager;
|
||||
|
||||
private final UserTouchedIntegrationEventHandler userTouchedIntegrationEventHandler;
|
||||
|
||||
private final UserRemovalIntegrationEventHandler userRemovalIntegrationEventHandler;
|
||||
|
||||
private final TenantTouchedIntegrationEventHandler tenantTouchedIntegrationEventHandler;
|
||||
|
||||
private final TenantRemovalIntegrationEventHandler tenantRemovalIntegrationEventHandler;
|
||||
|
||||
private final MaintenanceService maintenanceService;
|
||||
@Autowired
|
||||
public MaintenanceController(
|
||||
AuthorizationService authorizationService,
|
||||
ElasticService elasticService,
|
||||
AuditService auditService,
|
||||
QueryFactory queryFactory,
|
||||
TenantEntityManager entityManager,
|
||||
UserTouchedIntegrationEventHandler userTouchedIntegrationEventHandler,
|
||||
UserRemovalIntegrationEventHandler userRemovalIntegrationEventHandler,
|
||||
TenantTouchedIntegrationEventHandler tenantTouchedIntegrationEventHandler,
|
||||
TenantRemovalIntegrationEventHandler tenantRemovalIntegrationEventHandler) {
|
||||
MaintenanceService maintenanceService) {
|
||||
this.authorizationService = authorizationService;
|
||||
this.elasticService = elasticService;
|
||||
this.auditService = auditService;
|
||||
this.queryFactory = queryFactory;
|
||||
this.entityManager = entityManager;
|
||||
this.userTouchedIntegrationEventHandler = userTouchedIntegrationEventHandler;
|
||||
this.userRemovalIntegrationEventHandler = userRemovalIntegrationEventHandler;
|
||||
this.tenantTouchedIntegrationEventHandler = tenantTouchedIntegrationEventHandler;
|
||||
this.tenantRemovalIntegrationEventHandler = tenantRemovalIntegrationEventHandler;
|
||||
this.maintenanceService = maintenanceService;
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST, value = {"/index/elastic"})
|
||||
|
@ -96,51 +76,22 @@ public class MaintenanceController {
|
|||
this.auditService.track(AuditableAction.Maintenance_ClearElastic);
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.DELETE, value = {"/events/users/touch"})
|
||||
@RequestMapping(method = RequestMethod.POST, value = {"/events/users/touch"})
|
||||
public void sendUserTouchEvents() throws InvalidApplicationException {
|
||||
logger.debug("send user touch queue events");
|
||||
this.authorizationService.authorizeForce(Permission.ManageQueueEvents);
|
||||
|
||||
this.entityManager.disableTenantFilters();
|
||||
UserQuery userQuery = queryFactory.query(UserQuery.class);
|
||||
userQuery.isActive(IsActive.Active);
|
||||
List<UserEntity> activeUsers = userQuery.collect();
|
||||
userQuery.isActive(IsActive.Inactive);
|
||||
List<UserEntity> inactiveUsers = userQuery.collect();
|
||||
this.entityManager.enableTenantFilters();
|
||||
|
||||
for(UserEntity user : activeUsers)
|
||||
this.userTouchedIntegrationEventHandler.handle(user.getId());
|
||||
|
||||
for(UserEntity user : inactiveUsers)
|
||||
this.userRemovalIntegrationEventHandler.handle(user.getId());
|
||||
this.maintenanceService.sendUserTouchEvents();
|
||||
|
||||
this.auditService.track(AuditableAction.Maintenance_SendUserTouchEvents);
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.DELETE, value = {"/events/tenants/touch"})
|
||||
@RequestMapping(method = RequestMethod.POST, value = {"/events/tenants/touch"})
|
||||
public void sendTenantTouchEvents() throws InvalidApplicationException {
|
||||
logger.debug("send tenant touch queue events");
|
||||
this.authorizationService.authorizeForce(Permission.ManageQueueEvents);
|
||||
|
||||
this.entityManager.disableTenantFilters();
|
||||
TenantQuery tenantQuery = queryFactory.query(TenantQuery.class);
|
||||
tenantQuery.isActive(IsActive.Active);
|
||||
List<TenantEntity> activeTenants = tenantQuery.collect();
|
||||
tenantQuery.isActive(IsActive.Inactive);
|
||||
List<TenantEntity> inactiveTenants = tenantQuery.collect();
|
||||
this.entityManager.enableTenantFilters();
|
||||
|
||||
for (TenantEntity tenant : activeTenants) {
|
||||
TenantTouchedIntegrationEvent event = new TenantTouchedIntegrationEvent();
|
||||
event.setId(tenant.getId());
|
||||
event.setCode(tenant.getCode());
|
||||
this.tenantTouchedIntegrationEventHandler.handle(event);
|
||||
}
|
||||
|
||||
for (TenantEntity tenant : inactiveTenants) {
|
||||
this.tenantRemovalIntegrationEventHandler.handle(tenant.getId());
|
||||
}
|
||||
this.maintenanceService.sendTenantTouchEvents();
|
||||
|
||||
this.auditService.track(AuditableAction.Maintenance_SendTenantTouchEvents);
|
||||
}
|
||||
|
|
|
@ -32,14 +32,14 @@ export class MaintenanceService extends BaseService {
|
|||
sendUserTouchEvents(): Observable<any> {
|
||||
const url = `${this.apiBase}/events/users/touch`;
|
||||
return this.http
|
||||
.delete<any>(url).pipe(
|
||||
.post<any>(url, null).pipe(
|
||||
catchError((error: any) => throwError(error)));
|
||||
}
|
||||
|
||||
sendTenantTouchEvents(): Observable<any> {
|
||||
const url = `${this.apiBase}/events/tenants/touch`;
|
||||
return this.http
|
||||
.delete<any>(url).pipe(
|
||||
.post<any>(url, null).pipe(
|
||||
catchError((error: any) => throwError(error)));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue