Commit 97cfff9b authored by Roberto Loayza's avatar Roberto Loayza

Update auditoria

parent e4061f0b
......@@ -106,7 +106,6 @@ public class AgentController {
}
} catch (Exception e) {
log.error("Error detectado: ", e);
hs = HttpStatus.INTERNAL_SERVER_ERROR;
return new ResponseEntity<>(gsonBuilder.create().toJson(ExceptionUtils.getFullStackTrace(e)), hs);
}
......
......@@ -148,6 +148,12 @@ public class ScheduleService implements SchedulingConfigurer {
private TimeZone timeZone;
@Value("${application.timezone.zone}")
private String parameter;
@Value("${application.timezone.default}")
private String zoneDefault;
@Override
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
if (scheduledTaskRegistrar == null) {
......@@ -179,11 +185,11 @@ public class ScheduleService implements SchedulingConfigurer {
private void configureTask(String tenantIdentifier, String identifier, ScheduledTaskRegistrar taskRegistrar) {
tenant = tenantIdentifier;
taskRegister = taskRegistrar;
Optional<BusinessParameter> zone = businessParameterRepository.findByKey("TimeZone");
Optional<BusinessParameter> zone = businessParameterRepository.findByKey(parameter);
if (zone.isPresent()) {
timeZone = TimeZone.getTimeZone(zone.get().getDefaultValue());
} else {
timeZone = TimeZone.getDefault();
timeZone = TimeZone.getTimeZone(zoneDefault);
}
Trigger trigger = new CronTrigger(cronExpression, timeZone);
......@@ -234,6 +240,12 @@ 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());
} else {
timeZone = TimeZone.getTimeZone(zoneDefault);
}
Optional<List<WeekScheduler>> dates = weekSchedulerRepository.findByCalendarId(calendarId);
OffsetTime actual = OffsetTime.now();
for(WeekScheduler weekScheduler: dates.get()) {
......
package com.bytesw.bytebot.model;
import com.bytesw.bytebot.model.converters.FrequentQuestionStatusConverter;
import com.bytesw.bytebot.model.converters.StatusConverter;
import com.bytesw.bytebot.model.enums.FrequentQuestionStatusEnum;
import com.bytesw.bytebot.model.enums.StatusEnum;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
......@@ -12,7 +10,6 @@ import org.hibernate.envers.Audited;
import javax.persistence.*;
import java.time.LocalDateTime;
import java.time.OffsetDateTime;
/**
* @author Sebastian Chicoma Sandmann
......@@ -31,7 +28,8 @@ import java.time.OffsetDateTime;
@Getter
@Setter
@ToString
@EqualsAndHashCode(of = {"id"}, callSuper = false)
@EqualsAndHashCode(of = "id")
@NamedQuery(name = "FrequentQuestion.findByPK", query = "Select u from FrequentQuestion u where u.id = ?1")
public class FrequentQuestion {
@Id
@Column(name = "FQUE_ID")
......
package com.bytesw.bytebot.model.converters;
import com.bytesw.bytebot.model.enums.AgentStatusEnum;
import com.bytesw.bytebot.model.enums.FrequentQuestionStatusEnum;
import org.apache.camel.Converter;
......@@ -22,6 +21,9 @@ public class FrequentQuestionStatusConverter implements AttributeConverter<Frequ
@Override
public String convertToDatabaseColumn(FrequentQuestionStatusEnum value) {
if (value == null) {
return null;
}
return value.getName();
}
......
......@@ -7,7 +7,9 @@ import com.amazonaws.services.s3.model.DeleteObjectRequest;
import com.amazonaws.services.s3.model.ObjectMetadata;
import com.bytesw.bytebot.http.FileValidationResponse;
import com.bytesw.bytebot.model.BusinessParameter;
import com.bytesw.bytebot.model.BusinessParameterConfiguration;
import com.bytesw.bytebot.model.QuestionFile;
import com.bytesw.bytebot.repository.BusinessParameterConfigurationRepository;
import com.bytesw.bytebot.repository.BusinessParameterRepository;
import com.bytesw.bytebot.repository.QuestionFileRepository;
import com.bytesw.xdf.exception.NotFoundException;
......@@ -45,9 +47,15 @@ public class BucketService {
@Value("${application.bucket.version}")
private String version;
@Value("${application.bucket.parameter}")
private String parameter;
@Autowired
private QuestionFileRepository questionFileRepository;
@Autowired
private BusinessParameterConfigurationRepository businessParameterConfigurationRepository;
@Autowired
private BusinessParameterRepository businessParameterRepository;
......@@ -58,12 +66,25 @@ public class BucketService {
}
public boolean generate(byte[] file, FileValidationResponse response) {
Optional<BusinessParameter> businessParameter = businessParameterRepository.findByKey("Bucket");
if (!businessParameter.isPresent()) {
Optional<BusinessParameter> deployment = businessParameterRepository.findByKey(parameter);
String bucketName = new String();
if (!deployment.isPresent()) {
response.setMessage("NOT.FOUND.BUSINESS.PARAMETER");
throw new NotFoundException();
}
if (deployment.get().getDefaultValue() != null) {
bucketName = deployment.get().getDefaultValue();
} else {
List<BusinessParameterConfiguration> deploy = businessParameterConfigurationRepository
.findBusinessParameterConfigurationListByBusinessParameter(deployment.get().getId());
if (deploy.isEmpty()) {
response.setMessage("NOT.FOUND.BUSINESS.PARAMETER");
throw new NotFoundException();
}
bucketName = deploy.get(0).getValue();
}
boolean result = false;
String bucketName = businessParameter.get().getDefaultValue();
File mainFile = new File(response.getFileName());
try {
FileOutputStream stream = new FileOutputStream(mainFile);
......@@ -92,7 +113,7 @@ public class BucketService {
}
public void delete(String uuid) {
Optional<BusinessParameter> businessParameter = businessParameterRepository.findByKey("Bucket");
Optional<BusinessParameter> businessParameter = businessParameterRepository.findByKey(parameter);
if (!businessParameter.isPresent()) {
throw new NotFoundException();
}
......
......@@ -65,7 +65,6 @@ public class KnowledgeService {
boolean result = false;
try {
HttpDelete httpDelete = new HttpDelete(String.format("%s/clients/%s/indexes/%s/versions/%s", url, tenant, uuid, version));
System.out.println("Executing request " + httpDelete.getRequestLine());
ResponseHandler<String> responseHandler = response -> {
int status = response.getStatusLine().getStatusCode();
if (status >= 200 && status < 300) {
......
......@@ -5,19 +5,23 @@ 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;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
import java.util.Optional;
@Service
......@@ -43,23 +47,43 @@ public class OrquestadorService {
@Autowired
private BusinessParameterRepository businessParameterRepository;
@Autowired
private BusinessParameterConfigurationRepository businessParameterConfigurationRepository;
@Value("${application.bucket.deployment}")
private String parameter;
public FileValidationResponse executeGenerateBCD(String uuid, MultipartFile file) {
BdcControl model = new BdcControl();
FileValidationResponse response = new FileValidationResponse();
boolean step = false;
try{
//Modo de despliegue
Optional<BusinessParameter> deployment = businessParameterRepository.findByKey("Despliegue");
Optional<BusinessParameter> deployment = businessParameterRepository.findByKey(parameter);
String modeDeployment = new String();
if (!deployment.isPresent()) {
response.setMessage("NOT.FOUND.BUSINESS.PARAMETER");
throw new NotFoundException();
}
if (deployment.get().getDefaultValue() != null) {
modeDeployment = deployment.get().getDefaultValue();
} else {
List<BusinessParameterConfiguration> deploy = businessParameterConfigurationRepository
.findBusinessParameterConfigurationListByBusinessParameter(deployment.get().getId());
if (deploy.isEmpty()) {
response.setMessage("NOT.FOUND.BUSINESS.PARAMETER");
throw new NotFoundException();
}
modeDeployment = deploy.get(0).getValue();
}
//Valida y guarda en base de datos
response = fileManagementService.saveFile(uuid, file);
if(response.getFileValidationResult().getStatus().getName() != ValidationStatusEnum.OK.getName()) {
response.setStatus(FrequentQuestionStatusEnum.ERROR.getName());
return response;
}
model.setUuid(response.getUuid());
model.setFileId(response.getId());
model.setFileName(response.getFileName());
......@@ -67,7 +91,7 @@ public class OrquestadorService {
model.setStatus(StatusBcdEnum.CARGADO.getName());
model = bdcControlRepository.save(model);
if (deployment.get().getDefaultValue().equalsIgnoreCase("onCloud")) {
if (modeDeployment.equalsIgnoreCase("onCloud")) {
//Carga archivo a bucket
step = bucketService.generate(file.getBytes(), response);
if (!step) {
......@@ -108,21 +132,36 @@ public class OrquestadorService {
BdcControl model = modelBdc.get();
FileValidationResponse response = modelToFileValidation(model);
try {
Optional<BusinessParameter> deployment = businessParameterRepository.findByKey("Despliegue");
Optional<BusinessParameter> deployment = businessParameterRepository.findByKey(parameter);
String modeDeployment = new String();
if (!deployment.isPresent()) {
response.setMessage("NOT.FOUND.BUSINESS.PARAMETER");
throw new NotFoundException();
}
if (deployment.get().getDefaultValue() != null) {
modeDeployment = deployment.get().getDefaultValue();
} else {
List<BusinessParameterConfiguration> deploy = businessParameterConfigurationRepository
.findBusinessParameterConfigurationListByBusinessParameter(deployment.get().getId());
if (deploy.isEmpty()) {
response.setMessage("NOT.FOUND.BUSINESS.PARAMETER");
throw new NotFoundException();
}
modeDeployment = deploy.get(0).getValue();
}
if (model.getStatus().equals(StatusBcdEnum.CARGADO.getName())) {
Optional<QuestionFile> questionFile = questionFileRepository.findByUuid(uuid);
if (!questionFile.isPresent()) {
response.setMessage("NOT.FOUND.DATA");
throw new NotFoundException();
}
step = bucketService.generate(questionFile.get().getData(), response);
if (!step) {
response.setMessage("NOT.FOUND.BUCKET");
throw new NotFoundException();
if (modeDeployment.equalsIgnoreCase("onCloud")) {
step = bucketService.generate(questionFile.get().getData(), response);
if (!step) {
response.setMessage("NOT.FOUND.BUCKET");
throw new NotFoundException();
}
}
model.setStatus(StatusBcdEnum.INDEXANDO.getName());
model = bdcControlRepository.save(model);
......@@ -150,14 +189,12 @@ public class OrquestadorService {
public void deleteBcd(String uuid) {
Optional<BdcControl> bdcControl = bdcControlRepository.findByUuid(uuid);
if (!bdcControl.isPresent()) {
//throw new NotFoundException("Control no encontrado.");
throw new NotFoundException();
}
BdcControl model = bdcControl.get();
if (model.getStatus().equals(StatusBcdEnum.INDEXADO.getName())) {
boolean step = knowledgeService.delete(uuid);
if (!step) {
//throw new NotFoundException("Error a eliminar modelo del bucket");
throw new NotFoundException();
}
model.setStatus(StatusBcdEnum.INDEXANDO.getName());
......
......@@ -5,7 +5,7 @@ server:
port: ${APPLICATION_PORT:9077}
web:
#static-content-location: file:/home/mgutierrez/Documentos/Bytesw/bytebot-workspace/dist/bytebot-html/
static-content-location: file:/home/mgutierrez/Descargas/dist-1/dist/bytebot-html/
static-content-location: file:/home/mgutierrez/Descargas/dist/bytebot-html/
#NOTA debe terminar con /
security:
......@@ -56,7 +56,7 @@ application:
multi-tenant-conf:
exclude-service: /
authorization-service.url: http://localhost:17580
security: none #oauth2sso # none, basic, oauth2sso
security: oauth2sso #none, basic, oauth2sso
security.method: true
security-exclude: /service/oauth/userinfo, /actuator/**, /mylogout, /login, /logout, /goodbye, /error, /anon, /cache.manifest, /favicon.ico, /service/file, /goodbye /byteboot
messaging:
......@@ -94,11 +94,17 @@ application:
host: localhost
port: 8161
queue-name: task_queue
timezone:
zone: TimeZone
default: America/Mexico_City
bucket:
deployment: Despliegue
parameter: Bucket
tenant: T186A1
region: us-east-1
fileBucket: KB_Files
modelBucket: KB_Model
version: "1.0"
knowledge:
url: "http://127.0.0.1:3000/byteknowledgebaseApi"
......@@ -112,7 +118,7 @@ spring:
datasource:
database-type: postgres
schemaName: avb
url: jdbc:postgresql://192.168.0.115:5432/bytebot?useSSL=false&currentSchema=avb
url: jdbc:postgresql://192.168.0.119:5432/bytebot?useSSL=false&currentSchema=avb
driverClassName: 'org.postgresql.Driver'
username: postgres
password: postgres
......@@ -128,11 +134,11 @@ spring:
oauth2-client:
clientId: xdf-client
clientSecret: xdf-secret
accessTokenUri: http://192.168.0.115:18080/oauth/token
userAuthorizationUri: http://192.168.0.115:18080/oauth/authorize
accessTokenUri: http://192.168.0.119:18080/oauth/token
userAuthorizationUri: http://192.168.0.119:18080/oauth/authorize
oauth2-resource:
userInfoUri: http://192.168.0.115:18080/oauth/userinfo
logoutUri: http://192.168.0.115:18080/oauth/userlogout
userInfoUri: http://192.168.0.119:18080/oauth/userinfo
logoutUri: http://192.168.0.119:18080/oauth/userlogout
tenants:
-
id: T186A1
......@@ -140,7 +146,7 @@ spring:
datasource:
database-type: postgres
schemaName: avb
url: jdbc:postgresql://192.168.0.115:5432/bytebot?useSSL=false&currentSchema=avb
url: jdbc:postgresql://192.168.0.119:5432/bytebot?useSSL=false&currentSchema=avb
driverClassName: 'org.postgresql.Driver'
username: postgres
password: postgres
......@@ -155,11 +161,11 @@ spring:
oauth2-client:
clientId: xdf-client
clientSecret: xdf-secret
accessTokenUri: http://192.168.0.115:18080/oauth/token
userAuthorizationUri: http://192.168.0.115:18080/oauth/authorize
accessTokenUri: http://192.168.0.119:18080/oauth/token
userAuthorizationUri: http://192.168.0.119:18080/oauth/authorize
oauth2-resource:
userInfoUri: http://192.168.0.115:18080/oauth/userinfo
logoutUri: http://192.168.0.115:18080/oauth/userlogout
userInfoUri: http://192.168.0.119:18080/oauth/userinfo
logoutUri: http://192.168.0.119:18080/oauth/userlogout
jpa:
......@@ -182,8 +188,8 @@ batch:
datasource:
jdbc-driver: 'org.postgresql.Driver'
username: postgres
password: postgres
jdbc-url: jdbc:postgresql://localhost:5432/bytebot?useSSL=false&currentSchema=avb
password:
jdbc-url: jdbc:postgresql://192.168.21.74:5432/avb?useSSL=false&currentSchema=avb
query: 'select * from events WHERE id > %d order by id asc'
logging.level.root: INFO
......
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