Commit 589cb33c authored by Roberto Loayza's avatar Roberto Loayza

Update BusinessParameterService,ScheduleService, DataSensibleMapper

parent 45c1fa81
......@@ -292,7 +292,6 @@ public class ScheduleService implements SchedulingConfigurer {
.getListAgentChannel(AgentStatusEnum.DEPLOYED.getName(), AgentParameterEnum.ACCESS_TWILIO.getName());
String keyDataSens = "";
for (DeleteDataSensBean data : deleteDataSensBeans) {
Agent agent = agentRepository.findById(data.getAgenId()).get();
Trigger trigger = new CronTrigger(cronExpression, timeZone);
keyDataSens = String.format("deleteSensible-%s-%s", tenantIdentifier, data.getAgenId());
if (!futureMap.containsKey(keyDataSens)) {
......@@ -354,8 +353,8 @@ public class ScheduleService implements SchedulingConfigurer {
@Scheduled(cron = "${application.byte-bot.batch.cron}")
@SchedulerLock(name = "Dashboard-ETL", lockAtLeastFor = "PT40S", lockAtMostFor = "PT50S")
protected void createJob() {
List<Agent> agentDeployed = agentRepository.findByStatus(AgentStatusEnum.DEPLOYED);
log.info("INICIADO");
if (!agentDeployed.isEmpty()) {
ThreadLocalStorage.setTenantName(tenant);
Job job = jobBuilderFactory.get("processJob")
......@@ -397,6 +396,8 @@ public class ScheduleService implements SchedulingConfigurer {
/* Métodos ETL de data sensible */
private Job createJobDataSens(DeleteDataSensBean data) {
log.info("ETL de eliminacion");
data = deleteDataSensJDBCRepository.getAgentChannelByAgentID(AgentStatusEnum.DEPLOYED.getName(),
AgentParameterEnum.ACCESS_TWILIO.getName(), data.getAgenId());
ThreadLocalStorage.setTenantName(tenant);
return jobBuilderFactory.get( String.format("processDataSensible-%d",data.getAgenId()))
.incrementer(new RunIdIncrementer()).listener(listener)
......@@ -430,24 +431,18 @@ public class ScheduleService implements SchedulingConfigurer {
throw new RuntimeException("Properties not found");
}
Optional<Agent> agent = agentRepository.findById(data.getAgenId());
if (!agent.isPresent()) {
throw new RuntimeException("Agent not found");
}
DeleteDataSensControlBean control = deleteDataSensJDBCRepository.getControl(data.getAgenId());
OffsetDateTime endDate = OffsetDateTime.now();
int periodAgent = agent.get().getPeriod();
Long id = 0L;
int differenceTime = 0;
Long differenceTime = 0L;
if (control != null) {
OffsetDateTime lastSessionDate = OffsetDateTime.ofInstant(control.getDateDelete().toInstant(), ZoneId.systemDefault());
Duration difference = Duration.between(lastSessionDate, endDate);
differenceTime = (int) (difference.getSeconds() / 60);
differenceTime = (difference.getSeconds() / 60);
if (differenceTime <= periodAgent) {
if (differenceTime < data.getDeletePeriod()) {
log.info("Agente " + data.getValue() + " aun no cumple con el periodo de espera.");
id = null;
} else {
......
......@@ -31,6 +31,19 @@ public class DeleteDataSensJDBCRepository {
}
}
public DeleteDataSensBean getAgentChannelByAgentID(String status, String channel, Long id){
SqlSession session = sqlSessionFactory.openSession();
try {
Map<String, Object> params = new HashMap<>();
params.put("status", status);
params.put("channel", channel);
params.put("agentId", id);
return session.selectOne("com.bytesw.bytebot.dao.jdbc.ETLDataSensibleMapper.getAgentChannelByAgentId", params);
} finally {
session.close();
}
}
public DeleteDataSensControlBean getControl(Long id){
SqlSession session = sqlSessionFactory.openSession();
try {
......
......@@ -120,13 +120,4 @@ public class BucketService {
}
}
public void list() {
AmazonS3 s3 = getS3Client();
List<Bucket> buckets = s3.listBuckets();
System.out.println("Your {S3} buckets are:");
for (Bucket b : buckets) {
System.out.println("* " + b.getName());
}
}
}
......@@ -283,7 +283,6 @@ public class BusinessParameterService extends XDFService<BusinessParameter, Busi
public boolean validateKey(BusinessParameterBean bean) {
Optional<BusinessParameter> businessParameterOptional = this.businessParameterRepository.findByKey(bean.getKey());
System.out.println(businessParameterOptional);
if (businessParameterOptional.isPresent()) {
BusinessParameterBean businessParameterBeanOptional = toBean(businessParameterOptional.get());
if (!businessParameterBeanOptional.getId().equals(bean.getId())) {
......@@ -337,7 +336,7 @@ public class BusinessParameterService extends XDFService<BusinessParameter, Busi
break;
}
}
if (config.getFrom().isBefore(config.getTo()) && nowTime.isAfter(config.getFrom())) {
if (config.getFrom().isBefore(config.getTo()) && nowTime.isAfter(config.getFrom()) && config.getTo().isAfter(nowTime)) {
parameterResult = config.getValue();
break;
}
......
......@@ -17,6 +17,19 @@
WHERE agen_state=#{status} AND chpa_label=#{channel}
</select>
<select id="getAgentChannelByAgentId" resultType="ChannelByAgent" flushCache="true">
SELECT chpv_id as id,
chpv_value as channelValue,
AG.agen_iden as value,
AG.agen_id as agenId,
AG.agen_delete_sensible_period as deletePeriod
FROM AVB_DEPLOYMENT_CHANNEL_PARAM_VALUE ADCP
JOIN AVB_CHANNEL_PARAM ACP ON ACP.chpa_id=ADCP.chpa_id
JOIN avb_deployment_channel AD on AD.dcha_id=ADCP.dcha_id
JOIN avb_agent AG on AG.agen_id=AD.agen_id
WHERE agen_state=#{status} AND chpa_label=#{channel} and AG.agen_id = #{agentId}
</select>
<select id="getControl" resultType="DeleteControl" flushCache="true">
SELECT dsmc_id as id,
agent_id as agentId,
......
......@@ -17,6 +17,19 @@
WHERE agen_state=#{status} AND chpa_label=#{channel}
</select>
<select id="getAgentChannelByAgentId" resultType="ChannelByAgent" flushCache="true">
SELECT chpv_id as id,
chpv_value as channelValue,
AG.agen_iden as value,
AG.agen_id as agenId,
AG.agen_delete_sensible_period as deletePeriod
FROM AVB_DEPLOYMENT_CHANNEL_PARAM_VALUE ADCP
JOIN AVB_CHANNEL_PARAM ACP ON ACP.chpa_id=ADCP.chpa_id
JOIN avb_deployment_channel AD on AD.dcha_id=ADCP.dcha_id
JOIN avb_agent AG on AG.agen_id=AD.agen_id
WHERE agen_state=#{status} AND chpa_label=#{channel} and AG.agen_id = #{agentId}
</select>
<select id="getControl" resultType="DeleteControl" flushCache="true">
SELECT dsmc_id as id,
agent_id as agentId,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment