Commit 45c1fa81 authored by Roberto Loayza's avatar Roberto Loayza

Update BusinessParameterService, ScheduleService, OrquestadorService

parent 6e1e5140
...@@ -24,6 +24,7 @@ import com.bytesw.bytebot.model.enums.AgentStatusEnum; ...@@ -24,6 +24,7 @@ import com.bytesw.bytebot.model.enums.AgentStatusEnum;
import com.bytesw.bytebot.model.enums.FrequencyType; import com.bytesw.bytebot.model.enums.FrequencyType;
import com.bytesw.bytebot.model.enums.ProcessETLEnum; import com.bytesw.bytebot.model.enums.ProcessETLEnum;
import com.bytesw.bytebot.repository.*; import com.bytesw.bytebot.repository.*;
import com.bytesw.bytebot.service.BusinessParameterService;
import com.bytesw.xdf.multitenant.core.ThreadLocalStorage; import com.bytesw.xdf.multitenant.core.ThreadLocalStorage;
import com.google.gson.Gson; import com.google.gson.Gson;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
...@@ -147,7 +148,7 @@ public class ScheduleService implements SchedulingConfigurer { ...@@ -147,7 +148,7 @@ public class ScheduleService implements SchedulingConfigurer {
private CalendarExceptionFullRepository calendarExceptionFullRepository; private CalendarExceptionFullRepository calendarExceptionFullRepository;
@Autowired @Autowired
private BusinessParameterRepository businessParameterRepository; private BusinessParameterService businessParameterService;
private boolean schedulerFlag = false; private boolean schedulerFlag = false;
...@@ -196,9 +197,9 @@ public class ScheduleService implements SchedulingConfigurer { ...@@ -196,9 +197,9 @@ public class ScheduleService implements SchedulingConfigurer {
private void configureTask(String tenantIdentifier, String identifier, ScheduledTaskRegistrar taskRegistrar) { private void configureTask(String tenantIdentifier, String identifier, ScheduledTaskRegistrar taskRegistrar) {
tenant = tenantIdentifier; tenant = tenantIdentifier;
taskRegister = taskRegistrar; taskRegister = taskRegistrar;
Optional<BusinessParameter> zone = businessParameterRepository.findByKey(parameter); String zone = businessParameterService.getBusinessParameterForKey(parameter);
if (zone.isPresent()) { if (zone != null) {
timeZone = TimeZone.getTimeZone(zone.get().getDefaultValue()); timeZone = TimeZone.getTimeZone(zone);
} else { } else {
timeZone = TimeZone.getTimeZone(zoneDefault); timeZone = TimeZone.getTimeZone(zoneDefault);
} }
...@@ -258,23 +259,29 @@ public class ScheduleService implements SchedulingConfigurer { ...@@ -258,23 +259,29 @@ public class ScheduleService implements SchedulingConfigurer {
/*ETL eliminacion de data sensible*/ /*ETL eliminacion de data sensible*/
public void processDeleteData(String tenantIdentifier, ScheduledTaskRegistrar taskRegistrar, String calendarId) { public void processDeleteData(String tenantIdentifier, ScheduledTaskRegistrar taskRegistrar, String calendarId) {
Optional<BusinessParameter> zone = businessParameterRepository.findByKey(parameter); String zone = businessParameterService.getBusinessParameterForKey(parameter);
if (zone.isPresent()) { if (zone != null) {
timeZone = TimeZone.getTimeZone(zone.get().getDefaultValue()); timeZone = TimeZone.getTimeZone(zone);
} else { } else {
timeZone = TimeZone.getTimeZone(zoneDefault); timeZone = TimeZone.getTimeZone(zoneDefault);
} }
Optional<List<WeekScheduler>> dates = weekSchedulerRepository.findByCalendarId(calendarId); Optional<List<WeekScheduler>> dates = weekSchedulerRepository.findByCalendarId(calendarId);
OffsetTime actual = OffsetTime.now(); OffsetTime actual = OffsetTime.now();
OffsetDateTime now = OffsetDateTime.now();
for(WeekScheduler weekScheduler: dates.get()) { for(WeekScheduler weekScheduler: dates.get()) {
int day = now.getDayOfWeek().getValue() == 7? 1: (now.getDayOfWeek().getValue() + 1);
if(day != weekScheduler.getDayOfWeek()){
schedulerFlag = false;
continue;
}
if (actual.isBefore(weekScheduler.getTo()) && actual.isAfter(weekScheduler.getFrom())) { if (actual.isBefore(weekScheduler.getTo()) && actual.isAfter(weekScheduler.getFrom())) {
Optional<List<CalendarExceptionFull>> calendarException = calendarExceptionFullRepository.findByCalendarId(calendarId); Optional<List<CalendarExceptionFull>> calendarException = calendarExceptionFullRepository.findByCalendarId(calendarId);
if (calendarException.isPresent()){ if (calendarException.isPresent()){
schedulerFlag = validateException(calendarException.get()); schedulerFlag = validateException(calendarException.get());
break;
} else { } else {
schedulerFlag = true; schedulerFlag = true;
} }
break;
} else { } else {
schedulerFlag = false; schedulerFlag = false;
} }
...@@ -423,8 +430,14 @@ public class ScheduleService implements SchedulingConfigurer { ...@@ -423,8 +430,14 @@ public class ScheduleService implements SchedulingConfigurer {
throw new RuntimeException("Properties not found"); 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()); DeleteDataSensControlBean control = deleteDataSensJDBCRepository.getControl(data.getAgenId());
OffsetDateTime endDate = OffsetDateTime.now(); OffsetDateTime endDate = OffsetDateTime.now();
int periodAgent = agent.get().getPeriod();
Long id = 0L; Long id = 0L;
int differenceTime = 0; int differenceTime = 0;
...@@ -434,7 +447,7 @@ public class ScheduleService implements SchedulingConfigurer { ...@@ -434,7 +447,7 @@ public class ScheduleService implements SchedulingConfigurer {
differenceTime = (int) (difference.getSeconds() / 60); differenceTime = (int) (difference.getSeconds() / 60);
if (differenceTime < data.getDeletePeriod()) { if (differenceTime <= periodAgent) {
log.info("Agente " + data.getValue() + " aun no cumple con el periodo de espera."); log.info("Agente " + data.getValue() + " aun no cumple con el periodo de espera.");
id = null; id = null;
} else { } else {
......
...@@ -117,6 +117,8 @@ public class DataSensibleJPAWriter implements ItemWriter<DynaBean>, StepExecutio ...@@ -117,6 +117,8 @@ public class DataSensibleJPAWriter implements ItemWriter<DynaBean>, StepExecutio
} }
} }
} }
} else {
update_control = true;
} }
DeleteDataSensibleControl control = new DeleteDataSensibleControl(); DeleteDataSensibleControl control = new DeleteDataSensibleControl();
Optional<DeleteDataSensibleControl> controlBd = deleteDataSensibleControlRepository.findEventIdByAgentId(agent.getAgenId()); Optional<DeleteDataSensibleControl> controlBd = deleteDataSensibleControlRepository.findEventIdByAgentId(agent.getAgenId());
......
...@@ -55,10 +55,7 @@ public class BucketService { ...@@ -55,10 +55,7 @@ public class BucketService {
private QuestionFileRepository questionFileRepository; private QuestionFileRepository questionFileRepository;
@Autowired @Autowired
private BusinessParameterConfigurationRepository businessParameterConfigurationRepository; private BusinessParameterService businessParameterService;
@Autowired
private BusinessParameterRepository businessParameterRepository;
private AmazonS3 getS3Client() { private AmazonS3 getS3Client() {
return AmazonS3ClientBuilder.standard() return AmazonS3ClientBuilder.standard()
...@@ -67,23 +64,11 @@ public class BucketService { ...@@ -67,23 +64,11 @@ public class BucketService {
} }
public boolean generate(byte[] file, FileValidationResponse response) { public boolean generate(byte[] file, FileValidationResponse response) {
Optional<BusinessParameter> deployment = businessParameterRepository.findByKey(parameter); String bucketName = businessParameterService.getBusinessParameterForKey(parameter);
String bucketName = new String(); if (bucketName == null) {
if (!deployment.isPresent()) {
response.setMessage("NOT.FOUND.BUSINESS.PARAMETER");
throw new NotFoundException();
}
List<BusinessParameterConfiguration> deploy = businessParameterConfigurationRepository
.findBusinessParameterConfigurationListByBusinessParameter(deployment.get().getId());
if (deploy.isEmpty()) {
response.setMessage("NOT.FOUND.BUSINESS.PARAMETER"); response.setMessage("NOT.FOUND.BUSINESS.PARAMETER");
throw new NotFoundException(); throw new NotFoundException();
} }
if (deploy.get(0).getFrom().isAfter(OffsetDateTime.now())) {
bucketName = deploy.get(0).getValue();
} else if (deployment.get().getDefaultValue() != null) {
bucketName = deployment.get().getDefaultValue();
}
boolean result = false; boolean result = false;
File mainFile = new File(response.getFileName()); File mainFile = new File(response.getFileName());
...@@ -114,11 +99,10 @@ public class BucketService { ...@@ -114,11 +99,10 @@ public class BucketService {
} }
public void delete(String uuid) { public void delete(String uuid) {
Optional<BusinessParameter> businessParameter = businessParameterRepository.findByKey(parameter); String bucketName = businessParameterService.getBusinessParameterForKey(parameter);
if (!businessParameter.isPresent()) { if (bucketName == null) {
throw new NotFoundException(); throw new NotFoundException();
} }
String bucketName = businessParameter.get().getDefaultValue();
try { try {
AmazonS3 s3Client = getS3Client(); AmazonS3 s3Client = getS3Client();
Optional<QuestionFile> questionFile = questionFileRepository.findByUuid(uuid); Optional<QuestionFile> questionFile = questionFileRepository.findByUuid(uuid);
......
...@@ -305,4 +305,45 @@ public class BusinessParameterService extends XDFService<BusinessParameter, Busi ...@@ -305,4 +305,45 @@ public class BusinessParameterService extends XDFService<BusinessParameter, Busi
} }
return beanList; return beanList;
} }
public String getBusinessParameterForKey(String parameter) {
Optional<BusinessParameter> businessParameter = businessParameterRepository.findByKey(parameter);
if(!businessParameter.isPresent()) {
return null;
}
String parameterResult = null;
if (businessParameter.get().getRequired()) {
parameterResult = businessParameter.get().getDefaultValue();
}
List<BusinessParameterConfiguration> parameterConfig = businessParameterConfigurationRepository
.findBusinessParameterConfigurationListByBusinessParameter(businessParameter.get().getId());
if (parameterConfig.isEmpty()) {
return parameterResult;
}
OffsetDateTime nowTime = OffsetDateTime.now();
for (BusinessParameterConfiguration config: parameterConfig) {
if (config.getTo() == null) {
if (nowTime.isAfter(config.getFrom())) {
parameterResult = config.getValue();
break;
}
} else {
if (config.getFrom().equals(config.getTo())) {
if (config.getFrom().isBefore(nowTime)) {
parameterResult = config.getValue();
break;
}
}
if (config.getFrom().isBefore(config.getTo()) && nowTime.isAfter(config.getFrom())) {
parameterResult = config.getValue();
break;
}
}
}
return parameterResult;
}
} }
...@@ -4,14 +4,10 @@ import com.bytesw.bytebot.http.FileValidationResponse; ...@@ -4,14 +4,10 @@ import com.bytesw.bytebot.http.FileValidationResponse;
import com.bytesw.bytebot.http.FileValidationResult; import com.bytesw.bytebot.http.FileValidationResult;
import com.bytesw.bytebot.http.enums.ValidationStatusEnum; import com.bytesw.bytebot.http.enums.ValidationStatusEnum;
import com.bytesw.bytebot.model.BdcControl; import com.bytesw.bytebot.model.BdcControl;
import com.bytesw.bytebot.model.BusinessParameter;
import com.bytesw.bytebot.model.BusinessParameterConfiguration;
import com.bytesw.bytebot.model.QuestionFile; import com.bytesw.bytebot.model.QuestionFile;
import com.bytesw.bytebot.model.enums.FrequentQuestionStatusEnum; import com.bytesw.bytebot.model.enums.FrequentQuestionStatusEnum;
import com.bytesw.bytebot.model.enums.StatusBcdEnum; import com.bytesw.bytebot.model.enums.StatusBcdEnum;
import com.bytesw.bytebot.repository.BdcControlRepository; import com.bytesw.bytebot.repository.BdcControlRepository;
import com.bytesw.bytebot.repository.BusinessParameterConfigurationRepository;
import com.bytesw.bytebot.repository.BusinessParameterRepository;
import com.bytesw.bytebot.repository.QuestionFileRepository; import com.bytesw.bytebot.repository.QuestionFileRepository;
import com.bytesw.xdf.exception.NotFoundException; import com.bytesw.xdf.exception.NotFoundException;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
...@@ -21,8 +17,6 @@ import org.springframework.stereotype.Service; ...@@ -21,8 +17,6 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.time.OffsetDateTime;
import java.util.List;
import java.util.Optional; import java.util.Optional;
@Service @Service
...@@ -46,10 +40,7 @@ public class OrquestadorService { ...@@ -46,10 +40,7 @@ public class OrquestadorService {
private KnowledgeService knowledgeService; private KnowledgeService knowledgeService;
@Autowired @Autowired
private BusinessParameterRepository businessParameterRepository; private BusinessParameterService businessParameterService;
@Autowired
private BusinessParameterConfigurationRepository businessParameterConfigurationRepository;
@Value("${application.bucket.deployment}") @Value("${application.bucket.deployment}")
private String parameter; private String parameter;
...@@ -60,23 +51,12 @@ public class OrquestadorService { ...@@ -60,23 +51,12 @@ public class OrquestadorService {
boolean step = false; boolean step = false;
try{ try{
//Modo de despliegue //Modo de despliegue
Optional<BusinessParameter> deployment = businessParameterRepository.findByKey(parameter); String modeDeployment = businessParameterService.getBusinessParameterForKey(parameter);
String modeDeployment = new String(); if (modeDeployment == null) {
if (!deployment.isPresent()) {
response.setMessage("NOT.FOUND.BUSINESS.PARAMETER");
throw new NotFoundException();
}
List<BusinessParameterConfiguration> deploy = businessParameterConfigurationRepository
.findBusinessParameterConfigurationListByBusinessParameter(deployment.get().getId());
if (deploy.isEmpty()) {
response.setMessage("NOT.FOUND.BUSINESS.PARAMETER"); response.setMessage("NOT.FOUND.BUSINESS.PARAMETER");
throw new NotFoundException(); throw new NotFoundException();
} }
if (deploy.get(0).getFrom().isAfter(OffsetDateTime.now())) {
modeDeployment = deploy.get(0).getValue();
} else if (deployment.get().getDefaultValue() != null) {
modeDeployment = deployment.get().getDefaultValue();
}
//Valida y guarda en base de datos //Valida y guarda en base de datos
response = fileManagementService.saveFile(uuid, file); response = fileManagementService.saveFile(uuid, file);
if(response.getFileValidationResult().getStatus().getName() != ValidationStatusEnum.OK.getName()) { if(response.getFileValidationResult().getStatus().getName() != ValidationStatusEnum.OK.getName()) {
...@@ -84,7 +64,6 @@ public class OrquestadorService { ...@@ -84,7 +64,6 @@ public class OrquestadorService {
return response; return response;
} }
model.setUuid(response.getUuid()); model.setUuid(response.getUuid());
model.setFileId(response.getId()); model.setFileId(response.getId());
model.setFileName(response.getFileName()); model.setFileName(response.getFileName());
...@@ -133,23 +112,11 @@ public class OrquestadorService { ...@@ -133,23 +112,11 @@ public class OrquestadorService {
BdcControl model = modelBdc.get(); BdcControl model = modelBdc.get();
FileValidationResponse response = modelToFileValidation(model); FileValidationResponse response = modelToFileValidation(model);
try { try {
Optional<BusinessParameter> deployment = businessParameterRepository.findByKey(parameter); String modeDeployment = businessParameterService.getBusinessParameterForKey(parameter);
String modeDeployment = new String(); if (modeDeployment == null) {
if (!deployment.isPresent()) {
response.setMessage("NOT.FOUND.BUSINESS.PARAMETER");
throw new NotFoundException();
}
List<BusinessParameterConfiguration> deploy = businessParameterConfigurationRepository
.findBusinessParameterConfigurationListByBusinessParameter(deployment.get().getId());
if (deploy.isEmpty()) {
response.setMessage("NOT.FOUND.BUSINESS.PARAMETER"); response.setMessage("NOT.FOUND.BUSINESS.PARAMETER");
throw new NotFoundException(); throw new NotFoundException();
} }
if (deploy.get(0).getFrom().isAfter(OffsetDateTime.now())) {
modeDeployment = deploy.get(0).getValue();
} else if (deployment.get().getDefaultValue() != null) {
modeDeployment = deployment.get().getDefaultValue();
}
if (model.getStatus().equals(StatusBcdEnum.CARGADO.getName())) { if (model.getStatus().equals(StatusBcdEnum.CARGADO.getName())) {
Optional<QuestionFile> questionFile = questionFileRepository.findByUuid(uuid); Optional<QuestionFile> questionFile = questionFileRepository.findByUuid(uuid);
......
...@@ -88,7 +88,6 @@ public class SchedulerTaskService extends XDFService<SchedulerTask, SchedulerTas ...@@ -88,7 +88,6 @@ public class SchedulerTaskService extends XDFService<SchedulerTask, SchedulerTas
schedulerTask = toModel(schedulerTask, schedulerTaskBean); schedulerTask = toModel(schedulerTask, schedulerTaskBean);
schedulerTask = schedulerTaskRepository.save(schedulerTask); schedulerTask = schedulerTaskRepository.save(schedulerTask);
scheduleService.restartTask(schedulerTask); scheduleService.restartTask(schedulerTask);
System.out.println(schedulerTask);
return toBean(schedulerTask); return toBean(schedulerTask);
} }
......
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