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