-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: scheduler to delete expired ini audit
- Loading branch information
1 parent
5f22707
commit 35a7392
Showing
9 changed files
with
206 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/main/java/it/finanze/sanita/fse2/ms/gtw/garbage/enums/IniEventType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package it.finanze.sanita.fse2.ms.gtw.garbage.enums; | ||
|
||
public enum IniEventType { | ||
INI_CREATE_SOAP, | ||
INI_REPLACE_SOAP, | ||
INI_UPDATE_SOAP, | ||
INI_DELETE_SOAP, | ||
INI_RIFERIMENTO_SOAP, | ||
INI_GET_METADATI_SOAP | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/main/java/it/finanze/sanita/fse2/ms/gtw/garbage/repository/IAuditIniRetentionRepo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package it.finanze.sanita.fse2.ms.gtw.garbage.repository; | ||
|
||
import java.util.Date; | ||
|
||
public interface IAuditIniRetentionRepo { | ||
|
||
void deleteExpiredAudit(Date date); | ||
} |
55 changes: 55 additions & 0 deletions
55
src/main/java/it/finanze/sanita/fse2/ms/gtw/garbage/repository/entity/AuditIniETY.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package it.finanze.sanita.fse2.ms.gtw.garbage.repository.entity; | ||
|
||
import it.finanze.sanita.fse2.ms.gtw.garbage.enums.IniEventType; | ||
import lombok.Data; | ||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.mongodb.core.mapping.Document; | ||
import org.springframework.data.mongodb.core.mapping.Field; | ||
|
||
import java.util.Date; | ||
|
||
@Document(collection = "#{@auditIni}") | ||
@Data | ||
public class AuditIniETY { | ||
|
||
public static final String WORKFLOW_INSTANCE_ID = "workflow_instance_id"; | ||
public static final String EVENT_TYPE = "eventType"; | ||
public static final String EVENT_DATE = "eventDate"; | ||
public static final String MICROSERVICE_NAME = "microserviceName"; | ||
public static final String SOAP_REQUEST = "soapRequest"; | ||
public static final String SOAP_RESPONSE = "soapResponse"; | ||
public static final String EXPIRING_DATE = "expiring_date"; | ||
|
||
@Id | ||
private String id; | ||
|
||
@Field(name = WORKFLOW_INSTANCE_ID) | ||
private final String workflowInstanceId; | ||
|
||
@Field(name = EVENT_TYPE) | ||
private final IniEventType eventType; | ||
|
||
@Field(name = EVENT_DATE) | ||
private final Date eventDate; | ||
|
||
@Field(name = SOAP_REQUEST) | ||
private String soapRequest; | ||
|
||
@Field(name = SOAP_RESPONSE) | ||
private String soapResponse; | ||
|
||
@Field(name = MICROSERVICE_NAME) | ||
private String microserviceName; | ||
|
||
@Field(name = EXPIRING_DATE) | ||
private Date expiringDate; | ||
|
||
public AuditIniETY(String workflowInstanceId, IniEventType eventType, Date eventDate, String soapRequest, String soapResponse){ | ||
this.workflowInstanceId = workflowInstanceId; | ||
this.eventType = eventType; | ||
this.eventDate = eventDate; | ||
this.soapRequest = soapRequest; | ||
this.soapResponse = soapResponse; | ||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
...ain/java/it/finanze/sanita/fse2/ms/gtw/garbage/repository/impl/AuditIniRetentionRepo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package it.finanze.sanita.fse2.ms.gtw.garbage.repository.impl; | ||
|
||
import it.finanze.sanita.fse2.ms.gtw.garbage.repository.IAuditIniRetentionRepo; | ||
import it.finanze.sanita.fse2.ms.gtw.garbage.repository.entity.AuditIniETY; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.mongodb.core.MongoTemplate; | ||
import org.springframework.data.mongodb.core.query.Criteria; | ||
import org.springframework.data.mongodb.core.query.Query; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.Date; | ||
import java.util.List; | ||
|
||
@Repository | ||
@Slf4j | ||
public class AuditIniRetentionRepo implements IAuditIniRetentionRepo { | ||
|
||
@Autowired | ||
private MongoTemplate mongoTemplate; | ||
|
||
@Override | ||
public void deleteExpiredAudit(Date date) { | ||
Pageable pageable = PageRequest.of(0, 100); | ||
Query query = new Query(Criteria.where(AuditIniETY.EXPIRING_DATE).lte(date)).with(pageable); | ||
|
||
List<AuditIniETY> audits; | ||
int totalDeleted=0; | ||
|
||
do { | ||
audits = mongoTemplate.find(query, AuditIniETY.class); | ||
|
||
int deletedInBatch=audits.size(); | ||
totalDeleted += deletedInBatch; | ||
|
||
if (!audits.isEmpty()) { | ||
mongoTemplate.remove(query, AuditIniETY.class); | ||
} | ||
|
||
pageable = pageable.next(); | ||
query.with(pageable); | ||
|
||
log.debug("{} records has been deleted in the current batch", deletedInBatch); | ||
|
||
} while (!audits.isEmpty()); | ||
|
||
log.debug("Total records deleted: {}", totalDeleted); | ||
} | ||
|
||
|
||
} |
42 changes: 42 additions & 0 deletions
42
...main/java/it/finanze/sanita/fse2/ms/gtw/garbage/scheduler/AuditIniRetentionScheduler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package it.finanze.sanita.fse2.ms.gtw.garbage.scheduler; | ||
|
||
import it.finanze.sanita.fse2.ms.gtw.garbage.service.IAuditIniRetentionSRV; | ||
import it.finanze.sanita.fse2.ms.gtw.garbage.service.IConfigSRV; | ||
import it.finanze.sanita.fse2.ms.gtw.garbage.utility.DateUtility; | ||
import lombok.extern.slf4j.Slf4j; | ||
import net.javacrumbs.shedlock.spring.annotation.SchedulerLock; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.time.LocalDateTime; | ||
import java.time.ZoneId; | ||
import java.util.Date; | ||
|
||
@Slf4j | ||
@Component | ||
public class AuditIniRetentionScheduler { | ||
|
||
@Autowired | ||
private IAuditIniRetentionSRV auditIniRetentionSRV; | ||
|
||
@Autowired | ||
private IConfigSRV configSRV; | ||
|
||
@Scheduled(cron = "${scheduler.audit.ini-retention}") | ||
@SchedulerLock(name = "invokeRulesRetentionScheduler", lockAtMostFor = "60m") | ||
public void action() { | ||
run(); | ||
} | ||
|
||
public void run() { | ||
log.debug("Audit-ini Retention Scheduler - Retention Scheduler starting"); | ||
try { | ||
log.debug("Checking for expired ini audit..."); | ||
auditIniRetentionSRV.deleteAudit(new Date()); | ||
} catch (Exception e) { | ||
log.warn("Audit-ini Scheduler - Error while executing audit-ini data retention", e); | ||
} | ||
log.debug("Audit-ini Retention Scheduler - Retention Scheduler finished"); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/it/finanze/sanita/fse2/ms/gtw/garbage/service/IAuditIniRetentionSRV.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package it.finanze.sanita.fse2.ms.gtw.garbage.service; | ||
|
||
import java.util.Date; | ||
|
||
public interface IAuditIniRetentionSRV { | ||
|
||
void deleteAudit(Date date); | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/it/finanze/sanita/fse2/ms/gtw/garbage/service/impl/AuditIniRetentionSRV.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package it.finanze.sanita.fse2.ms.gtw.garbage.service.impl; | ||
|
||
import it.finanze.sanita.fse2.ms.gtw.garbage.repository.IAuditIniRetentionRepo; | ||
import it.finanze.sanita.fse2.ms.gtw.garbage.service.IAuditIniRetentionSRV; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.Date; | ||
|
||
@Service | ||
public class AuditIniRetentionSRV implements IAuditIniRetentionSRV{ | ||
|
||
@Autowired | ||
IAuditIniRetentionRepo repo; | ||
|
||
@Override | ||
public void deleteAudit(Date date) { | ||
repo.deleteExpiredAudit(date); | ||
} | ||
} |