Commit ba62812c authored by Roberto Loayza's avatar Roberto Loayza

Despliegue de base de conocimiento.

parent 53a752db
...@@ -185,7 +185,6 @@ public class ScheduleService implements SchedulingConfigurer { ...@@ -185,7 +185,6 @@ public class ScheduleService implements SchedulingConfigurer {
} else { } else {
timeZone = TimeZone.getDefault(); timeZone = TimeZone.getDefault();
} }
System.out.println(timeZone);
Trigger trigger = new CronTrigger(cronExpression, timeZone); Trigger trigger = new CronTrigger(cronExpression, timeZone);
/* ETL de Dashboard */ /* ETL de Dashboard */
...@@ -222,6 +221,13 @@ public class ScheduleService implements SchedulingConfigurer { ...@@ -222,6 +221,13 @@ public class ScheduleService implements SchedulingConfigurer {
future.cancel(true); future.cancel(true);
futureMap.remove(key); futureMap.remove(key);
} }
if (!keys.isEmpty()) {
for (String Key: keys) {
ScheduledFuture future = futureMap.get(Key);
future.cancel(true);
futureMap.remove(key);
}
}
} }
/*ETL eliminacion de data sensible*/ /*ETL eliminacion de data sensible*/
...@@ -230,7 +236,6 @@ public class ScheduleService implements SchedulingConfigurer { ...@@ -230,7 +236,6 @@ public class ScheduleService implements SchedulingConfigurer {
OffsetTime actual = OffsetTime.now(); OffsetTime actual = OffsetTime.now();
for(WeekScheduler weekScheduler: dates.get()) { for(WeekScheduler weekScheduler: dates.get()) {
if (actual.isBefore(weekScheduler.getTo()) && actual.isAfter(weekScheduler.getFrom())) { if (actual.isBefore(weekScheduler.getTo()) && actual.isAfter(weekScheduler.getFrom())) {
//schedulerFlag = true;
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());
...@@ -242,12 +247,12 @@ public class ScheduleService implements SchedulingConfigurer { ...@@ -242,12 +247,12 @@ public class ScheduleService implements SchedulingConfigurer {
} }
if (schedulerFlag) { if (schedulerFlag) {
Trigger trigger = new CronTrigger(cronExpression, timeZone);
List<DeleteDataSensBean> deleteDataSensBeans = deleteDataSensJDBCRepository List<DeleteDataSensBean> deleteDataSensBeans = deleteDataSensJDBCRepository
.getListAgentChannel(AgentStatusEnum.DEPLOYED.getName(), AgentParameterEnum.ACCESS_TWILIO.getName()); .getListAgentChannel(AgentStatusEnum.DEPLOYED.getName(), AgentParameterEnum.ACCESS_TWILIO.getName());
String keyDataSens = ""; String keyDataSens = "";
for (DeleteDataSensBean data : deleteDataSensBeans) { 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.getValue()); keyDataSens = String.format("deleteSensible-%s-%s", tenantIdentifier, data.getValue());
if (!futureMap.containsKey(keyDataSens)) { if (!futureMap.containsKey(keyDataSens)) {
keys.add(keyDataSens); keys.add(keyDataSens);
...@@ -324,7 +329,7 @@ public class ScheduleService implements SchedulingConfigurer { ...@@ -324,7 +329,7 @@ public class ScheduleService implements SchedulingConfigurer {
private ItemReader getReader(String tenantIdentifier) { private ItemReader getReader(String tenantIdentifier) {
if (properties == null) { if (properties == null) {
throw new RuntimeException("Prope rties not found"); throw new RuntimeException("Properties not found");
} }
Optional<TenantBatchBean> tenantFound = findTenant(tenantIdentifier); Optional<TenantBatchBean> tenantFound = findTenant(tenantIdentifier);
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
*/ */
package com.bytesw.bytebot.service; package com.bytesw.bytebot.service;
import com.amazonaws.services.dynamodbv2.xspec.S;
import com.bytesw.bytebot.http.FileValidationResponse; 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;
...@@ -129,8 +130,9 @@ public class FileManagementService { ...@@ -129,8 +130,9 @@ public class FileManagementService {
//@Validaciones: De Contenido(Todos deben tener valor) //@Validaciones: De Contenido(Todos deben tener valor)
int rowNumber = 0; int rowNumber = 0;
int rowError = 0;
Iterator<Row> rowIterator = sheet.iterator(); Iterator<Row> rowIterator = sheet.iterator();
Map<Integer, Object> recordsRowErrorMap = new HashMap<>();; Map<Integer, Object> recordsRowErrorMap = new HashMap<>();
while (rowIterator.hasNext()) { while (rowIterator.hasNext()) {
Row row = (Row) rowIterator.next(); Row row = (Row) rowIterator.next();
...@@ -193,12 +195,20 @@ public class FileManagementService { ...@@ -193,12 +195,20 @@ public class FileManagementService {
if (!recordsErrorMap.isEmpty()) { if (!recordsErrorMap.isEmpty()) {
if (recordsErrorMap.size() != fileHeaders.length){ if (recordsErrorMap.size() != fileHeaders.length){
recordsRowErrorMap.put(rowNumber + 1, recordsErrorMap); recordsRowErrorMap.put(rowNumber + 1, recordsErrorMap);
} else {
rowError++;
} }
} }
rowNumber++; rowNumber++;
} }
if (rowError > 0) {
Map<String, String> rowErrorResult = new HashMap<>();
rowErrorResult.put("ROW.NULL", "ROW.DATA.NULL");
recordsRowErrorMap.put(rowError, rowErrorResult);
}
if (!recordsRowErrorMap.isEmpty()) { if (!recordsRowErrorMap.isEmpty()) {
log.info("Hay errores en el contenido del archivo: " + recordsRowErrorMap); log.info("Hay errores en el contenido del archivo: " + recordsRowErrorMap);
result.setStatus(ValidationStatusEnum.CONTENT_ERROR); result.setStatus(ValidationStatusEnum.CONTENT_ERROR);
...@@ -246,44 +256,88 @@ public class FileManagementService { ...@@ -246,44 +256,88 @@ public class FileManagementService {
String line; String line;
InputStream is = file.getInputStream(); InputStream is = file.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is)); BufferedReader br = new BufferedReader(new InputStreamReader(is));
Map<String, String> headerErrorMap = new HashMap<>();
Map<Integer, Object> recordsRowErrorMap = new HashMap<>();
int rowData = 1;
while ((line = br.readLine()) != null) { while ((line = br.readLine()) != null) {
List<String> row = new ArrayList<>(); List<String> row = new ArrayList<>();
String[] data = line.split(";"); String[] data = line.split(";");
if (data.length != fileHeaders.length) {
Map<String, String> dataError = new HashMap<>(); if (data.length <= 1) {
dataError.put("DATA", "DATA.INCOMPLETE"); headerErrorMap.put("FORMAT.SEPARATION", "ERROR.SEPARATION.FORMAT");
result.setHeadersErrorMap(dataError); }
result.setStatus(ValidationStatusEnum.ERROR);
response.setFileValidationResult(result); if (data.length < fileHeaders.length) {
return response; Map<String, String> recordsErrorMap = new HashMap<>();
recordsErrorMap.put(ValidationStatusEnum.DATA_INCOMPLETE.getName(), "DATA.INCOMPLETE");
recordsRowErrorMap.put(rowData, recordsErrorMap);
} }
for (String dato : data) { for (String dato : data) {
if (validateData(dato)) { if (validateData(dato)) {
Map<String, String> errorFormat = new HashMap<>(); headerErrorMap.put("FORMAT.DATA", "WRONG.DATA.INCORRECT");
errorFormat.put("DATA", "FORMAT.INCORRECT");
result.setHeadersErrorMap(errorFormat);
result.setStatus(ValidationStatusEnum.ERROR);
response.setFileValidationResult(result);
return response;
} }
row.add(dato); row.add(dato);
} }
rowData++;
rows.add(row); rows.add(row);
} }
if(!headerErrorMap.isEmpty()) {
result.setHeadersErrorMap(headerErrorMap);
result.setStatus(ValidationStatusEnum.HEADER_ERROR);
response.setFileValidationResult(result);
return response;
}
if (!recordsRowErrorMap.isEmpty()) {
log.info("Hay errores en el contenido del archivo: " + recordsRowErrorMap);
result.setStatus(ValidationStatusEnum.CONTENT_ERROR);
result.setRecordsErrorMap(recordsRowErrorMap);
response.setFileValidationResult(result);
return response;
}
List<String> headersList = new ArrayList<>(); List<String> headersList = new ArrayList<>();
for (String header: rows.get(0)) { for (String header: rows.get(0)) {
headersList.add(header.replace('"', ' ')); headersList.add(header.replace('"', ' '));
} }
Map<String, String> headerErrorMap = validateHeaders(headersList);
headerErrorMap = validateHeaders(headersList);
if (!headerErrorMap.isEmpty()) { if (!headerErrorMap.isEmpty()) {
result.setHeadersErrorMap(headerErrorMap); result.setHeadersErrorMap(headerErrorMap);
result.setStatus(ValidationStatusEnum.ERROR); result.setStatus(ValidationStatusEnum.HEADER_ERROR);
response.setFileValidationResult(result); response.setFileValidationResult(result);
return response; return response;
} }
rows.remove(0);
} catch (IOException e) { } catch (IOException e) {
System.err.println(e.getMessage()); System.err.println(e.getMessage());
} }
int rowNumber = 0;
Map<Integer, Object> recordsRowErrorMap = new HashMap<>();
for (List<String> item: rows) {
Map<String, Object> recordsXRow = new HashMap<>();
Map<String, String> recordsErrorMap = validateRecordsXRow(recordsXRow);
if (!recordsErrorMap.isEmpty()) {
if (recordsErrorMap.size() != fileHeaders.length){
recordsRowErrorMap.put(rowNumber + 1, recordsErrorMap);
}
}
rowNumber++;
}
if (!recordsRowErrorMap.isEmpty()) {
log.info("Hay errores en el contenido del archivo: " + recordsRowErrorMap);
result.setStatus(ValidationStatusEnum.CONTENT_ERROR);
result.setRecordsErrorMap(recordsRowErrorMap);
response.setFileValidationResult(result);
return response;
}
result.setStatus(ValidationStatusEnum.OK); result.setStatus(ValidationStatusEnum.OK);
QuestionFile questionFileBD = new QuestionFile(); QuestionFile questionFileBD = new QuestionFile();
...@@ -326,7 +380,7 @@ public class FileManagementService { ...@@ -326,7 +380,7 @@ public class FileManagementService {
} }
for (String header : headersList) { for (String header : headersList) {
if (header.toUpperCase().trim().equalsIgnoreCase(keyHeader)) { if (header.toUpperCase().trim().equals(keyHeader)) {
int ocurrences = headerOcurrencesMap.get(keyHeader); int ocurrences = headerOcurrencesMap.get(keyHeader);
headerOcurrencesMap.put(keyHeader, ocurrences + 1); headerOcurrencesMap.put(keyHeader, ocurrences + 1);
headerOrganized.put(keyHeader, index); headerOrganized.put(keyHeader, index);
......
...@@ -48,6 +48,7 @@ public class KnowledgeService { ...@@ -48,6 +48,7 @@ public class KnowledgeService {
}; };
String res = httpclient.execute(httppost, responseHandler); String res = httpclient.execute(httppost, responseHandler);
String status = (String) JsonUtils.getFieldFromJson(res, "$.message.status"); String status = (String) JsonUtils.getFieldFromJson(res, "$.message.status");
httpclient.close();
if (status.equals("success")){ if (status.equals("success")){
result = true; result = true;
} }
......
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