Commit 60f4a48c authored by Roberto Loayza Miljanovich's avatar Roberto Loayza Miljanovich

Merge branch 'dev_marcos' into 'developer'

Dev marcos

See merge request ByteBot/web/bytebot-service!22
parents d136e061 4e812b11
......@@ -9,7 +9,7 @@
<packaging>jar</packaging>
<properties>
<xdf.version>3.3.0</xdf.version>
<xdf.version>3.4.0</xdf.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
......
......@@ -11,6 +11,8 @@ import com.google.gson.GsonBuilder;
import io.swagger.annotations.ApiParam;
import java.security.Principal;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import lombok.extern.log4j.Log4j2;
......@@ -104,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);
}
......@@ -175,8 +176,8 @@ public class AgentController {
return new ResponseEntity<>(gson.toJson(response), HttpStatus.OK);
} catch (Exception e) {
e.printStackTrace();
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
@PutMapping("/file-upload/{uuid}")
......@@ -195,13 +196,14 @@ public class AgentController {
@DeleteMapping("/file-upload/{uuid}")
public ResponseEntity<String> deleteBdc(@ApiParam(value = "uuid", required = true) @PathVariable("uuid") String uuid) {
Gson gson = gsonBuilder.create();
Map<String, String> resp = new HashMap<>();
try {
orquestadorService.deleteBcd(uuid);
String response = "Todo Ok";
return new ResponseEntity<>(gson.toJson(response), HttpStatus.OK);
resp.put("message", "OK");
return new ResponseEntity<>(gson.toJson(resp), HttpStatus.OK);
} catch (Exception e) {
log.error("Error detectado: ", e);
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
resp.put("message", "ERROR");
return new ResponseEntity<>(gson.toJson(resp), HttpStatus.OK);
}
}
......
package com.bytesw.bytebot.controller;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HealthController {
@GetMapping("/health")
public ResponseEntity<Void> health() {
return new ResponseEntity<>(HttpStatus.OK);
}
}
......@@ -65,7 +65,7 @@ public class ScheduleService implements SchedulingConfigurer {
@Qualifier("schedulerLockTaskScheduler")
TaskScheduler poolScheduler;
@Value("${application.byte-bot.batch.cron: 0 0/1 * * * * }")
@Value("${application.byte-bot.batch.cron}")
private String cronExpression;
@Value("${application.byte-bot.batch.chunk:500}")
......@@ -135,10 +135,25 @@ public class ScheduleService implements SchedulingConfigurer {
@Autowired
private CalendarExceptionFullRepository calendarExceptionFullRepository;
@Autowired
private BusinessParameterRepository businessParameterRepository;
private boolean schedulerFlag = false;
private List<String> keys = new ArrayList<>();
private String tenant;
private ScheduledTaskRegistrar taskRegister;
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) {
......@@ -168,7 +183,16 @@ public class ScheduleService implements SchedulingConfigurer {
}
private void configureTask(String tenantIdentifier, String identifier, ScheduledTaskRegistrar taskRegistrar) {
Trigger trigger = new CronTrigger(cronExpression, TimeZone.getDefault());
tenant = tenantIdentifier;
taskRegister = taskRegistrar;
Optional<BusinessParameter> zone = businessParameterRepository.findByKey(parameter);
if (zone.isPresent()) {
timeZone = TimeZone.getTimeZone(zone.get().getDefaultValue());
} else {
timeZone = TimeZone.getTimeZone(zoneDefault);
}
Trigger trigger = new CronTrigger(cronExpression, timeZone);
/* ETL de Dashboard */
String key = String.format("%s-%s", tenantIdentifier, identifier);
futureMap.put(key, taskRegistrar.getScheduler().schedule(() -> scheduleCron(createJob(tenantIdentifier), tenantIdentifier), trigger));
......@@ -179,40 +203,85 @@ public class ScheduleService implements SchedulingConfigurer {
/* Busca las listas de SchedulerTask */
List<SchedulerTask> listSchedulerTask = schedulerTaskRepository.findByEtlId(processDelete.getId());
for (SchedulerTask schedulerTask : listSchedulerTask) {
Trigger triggerDelete = new CronTrigger(schedulerTask.getCronExpression(), TimeZone.getDefault());
String keyScheduler = String.format("%s-%s", tenantIdentifier, schedulerTask.getCalendarID());
Trigger triggerDelete = new CronTrigger(schedulerTask.getCronExpression(), timeZone);
String keyScheduler = String.format("%s-%s-%s", tenantIdentifier, schedulerTask.getCalendarID().trim(), schedulerTask.getId());
futureMap.put(keyScheduler, taskRegistrar.getScheduler()
.schedule(() -> processDeleteData(tenantIdentifier, taskRegistrar, schedulerTask.getCalendarID().trim()), triggerDelete));
}
}
public void restartTask(SchedulerTask model) {
String key = String.format("%s-%s-%s", tenant, model.getCalendarID().trim(), model.getId());
Trigger trigger = new CronTrigger(model.getCronExpression(), timeZone);
if (futureMap.containsKey(key)) {
cancelTask(model);
}
futureMap.put(key, taskRegister.getScheduler()
.schedule(() -> processDeleteData(tenant, taskRegister, model.getCalendarID().trim()), trigger));
}
public void cancelTaskDelete(Long id) {
String keyDataSens = String.format("deleteSensible-%s-%s", tenant, id);
if (futureMap.containsKey(keyDataSens)) {
ScheduledFuture future = futureMap.get(keyDataSens);
future.cancel(true);
futureMap.remove(keyDataSens);
if (keys.contains(keyDataSens)) {
keys.remove(keyDataSens);
}
}
}
public void cancelTask(SchedulerTask model) {
String key = String.format("%s-%s-%s", tenant, model.getCalendarID().trim(), model.getId());
if (futureMap.containsKey(key)){
ScheduledFuture future = futureMap.get(key);
future.cancel(true);
futureMap.remove(key);
}
if (!keys.isEmpty()) {
for (String keyTask: keys) {
if (futureMap.containsKey(keyTask)) {
ScheduledFuture future = futureMap.get(keyTask);
future.cancel(true);
futureMap.remove(keyTask);
}
}
}
}
/*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()) {
if (actual.isBefore(weekScheduler.getTo()) && actual.isAfter(weekScheduler.getFrom())) {
//schedulerFlag = true;
Optional<List<CalendarExceptionFull>> calendarException = calendarExceptionFullRepository.findByCalendarId(calendarId);
if (calendarException.isPresent()){
schedulerFlag = validateException(calendarException.get());
break;
} else {
schedulerFlag = true;
}
} else {
schedulerFlag = false;
}
}
if (schedulerFlag) {
Trigger trigger = new CronTrigger(cronExpression, TimeZone.getDefault());
List<DeleteDataSensBean> deleteDataSensBeans = deleteDataSensJDBCRepository
.getListAgentChannel(AgentStatusEnum.DEPLOYED.getName(), AgentParameterEnum.ACCESS_TWILIO.getName());
String keyDataSens = "";
for (DeleteDataSensBean data : deleteDataSensBeans) {
keyDataSens = String.format("deleteSensible-%s-%s", tenantIdentifier, data.getValue());
Agent agent = agentRepository.findById(data.getAgenId()).get();
Trigger trigger = new CronTrigger("0 0/1 * * * *", timeZone);
keyDataSens = String.format("deleteSensible-%s-%s", tenantIdentifier, data.getAgenId());
if (!futureMap.containsKey(keyDataSens)) {
keys.add(keyDataSens);
futureMap.put(keyDataSens, taskRegistrar.getScheduler()
......@@ -221,7 +290,11 @@ public class ScheduleService implements SchedulingConfigurer {
}
} else {
keys.forEach(x -> {
futureMap.remove(x);
if (futureMap.containsKey(x)) {
ScheduledFuture future = futureMap.get(x);
future.cancel(true);
futureMap.remove(x);
}
});
}
}
......@@ -303,8 +376,9 @@ public class ScheduleService implements SchedulingConfigurer {
/* Métodos ETL de data sensible */
private Job createJobDataSens(String tenantIdentifier, DeleteDataSensBean data) {
System.out.println("ETL de eliminacion");
ThreadLocalStorage.setTenantName(tenantIdentifier);
return jobBuilderFactory.get( String.format("processDataSensible%d",+data.getAgenId()))
return jobBuilderFactory.get( String.format("processDataSensible-%d",+data.getAgenId()))
.incrementer(new RunIdIncrementer()).listener(listener)
.flow(createStepDataSens(tenantIdentifier, data)).end().build();
}
......
......@@ -58,7 +58,7 @@ public class DataSensibleJPAWriter implements ItemWriter<DynaBean>, StepExecutio
@Override
@Transactional
public void write(List<? extends DynaBean> list) throws Exception {
Object numeros = JsonUtils.getFieldFromJson(agent.getChannelValue(), "$.telefonos_desplegados");
Object numeros = JsonUtils.getFieldFromJson(agent.getChannelValue(), "$.telefono_despliegue");
List<String> numerosAgentes = numbersAgent((List<Map>) numeros);
for (DynaBean dynaBean : list) {
Long id = Long.parseLong(dynaBean.get("id").toString());
......@@ -75,7 +75,7 @@ public class DataSensibleJPAWriter implements ItemWriter<DynaBean>, StepExecutio
if (toAgent == null) {
continue;
}
if (toAgent.isEmpty()) {
if (!toAgent.isEmpty()) {
agentNumber = toAgent.split(":")[1];
}
if (numerosAgentes.contains(agentNumber)) {
......@@ -142,7 +142,7 @@ public class DataSensibleJPAWriter implements ItemWriter<DynaBean>, StepExecutio
private List<String> numbersAgent(List<Map> listNumber){
List<String> result = new ArrayList<>();
for (Map map : listNumber){
String cod = (String) map.get("CodigoInternacional");
String cod = (String) map.get("codigoInternacional");
String number = (String) map.get("numero");
String agent = "+" + cod + number;
result.add(agent);
......
......@@ -6,7 +6,6 @@ import lombok.ToString;
import javax.persistence.*;
//AVB_INTENT
@Cacheable(false)
@Entity
@Getter @Setter @ToString
......
......@@ -164,7 +164,7 @@ public class UserMessageProcessed extends MessageProcessedSupport implements Mes
List<DeleteDataSensBean> deleteDataSensBeans = deleteDataSensJDBCRepository
.getListAgentChannel(AgentStatusEnum.DEPLOYED.getName(), AgentParameterEnum.ACCESS_TWILIO.getName());
for (DeleteDataSensBean deleteDataSensBean: deleteDataSensBeans) {
Object numeros = JsonUtils.getFieldFromJson(deleteDataSensBean.getChannelValue(), "$.telefonos_desplegados");
Object numeros = JsonUtils.getFieldFromJson(deleteDataSensBean.getChannelValue(), "$.telefono_despliegue");
List<String> numerosAgentes = numbersAgent((List<Map>) numeros);
if (numerosAgentes.contains(number)) {
agentId = deleteDataSensBean.getAgenId();
......@@ -178,7 +178,7 @@ public class UserMessageProcessed extends MessageProcessedSupport implements Mes
private List<String> numbersAgent(List<Map> listNumber){
List<String> result = new ArrayList<>();
for (Map map : listNumber){
String cod = (String) map.get("CodigoInternacional");
String cod = (String) map.get("codigoInternacional");
String number = (String) map.get("numero");
String agent = "+" + cod + number;
result.add(agent);
......
......@@ -17,6 +17,7 @@ public class FileValidationResponse {
private String status;
private String user;
private String uploadDate;
private String message;
private FileValidationResult fileValidationResult;
}
......@@ -12,6 +12,8 @@ import java.util.NoSuchElementException;
public enum ValidationStatusEnum {
OK("OK"),
ERROR("ERROR"),
DATA_INCOMPLETE ("DI"),
FORMAT_INCORRECT("FI"),
INCOMPATIBLE_EXTENSION("IE"),
HEADER_ERROR ("HE"),
CONTENT_ERROR("CE");
......
......@@ -8,11 +8,13 @@ import com.bytesw.bytebot.model.enums.AgentTypeEnum;
import com.bytesw.bytebot.model.enums.LanguageEnum;
import lombok.*;
import org.hibernate.annotations.Type;
import org.hibernate.envers.Audited;
import javax.persistence.*;
import java.io.Serializable;
import java.util.List;
@Audited
@Entity
@Getter @Setter @EqualsAndHashCode(of = "id")
@NoArgsConstructor
......
......@@ -11,7 +11,7 @@ import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.NamedQuery;
//@Audited
@Audited
@Entity
@DiscriminatorValue(value=AnnualCalendarException.DISCRIMINATOR_VALUE)
@NamedQuery(name = "AnnualCalendarException.findByPK", query = "Select u from AnnualCalendarException u where u.id = ?1")
......
......@@ -10,7 +10,7 @@ import javax.persistence.*;
import java.io.Serializable;
import java.util.List;
//@Audited
@Audited
@Entity
@Table(name = "AVB_CALENDAR")
@NamedQuery(name = "Calendar.findByPK", query = "Select u from Calendar u where u.id = ?1")
......
......@@ -13,7 +13,7 @@ import javax.persistence.*;
import java.io.Serializable;
import java.math.BigInteger;
//@Audited
@Audited
@Entity
@Inheritance(
strategy = InheritanceType.SINGLE_TABLE
......
......@@ -13,7 +13,6 @@ import java.math.BigInteger;
import java.time.LocalDate;
import java.time.OffsetDateTime;
//@Audited
@Entity
@Inheritance(
strategy = InheritanceType.SINGLE_TABLE
......@@ -50,10 +49,6 @@ public class CalendarExceptionFull implements Serializable {
@Column(name = "CALE_ID")
private String calendarID;
// @ManyToOne(optional = false)
// @JoinColumn(name = "CALE_ID", referencedColumnName = "CALE_ID", nullable = false)
// private Calendar calendar;
@Column(name = "CALE_EXC_MONTH")
private BigInteger month;
......
......@@ -4,6 +4,7 @@ import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.envers.Audited;
import javax.persistence.*;
import java.util.List;
......@@ -19,6 +20,7 @@ import java.util.List;
* Confidencial y debe usarla de acuerdo con los términos de aceptación de
* licencia de uso que firmó con Byte.
*/
@Audited
@Entity
@Table(name = "AVB_CHANNEL")
@Getter @Setter @ToString
......
......@@ -5,6 +5,7 @@ import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.envers.Audited;
import javax.persistence.*;
......@@ -19,6 +20,7 @@ import javax.persistence.*;
* Confidencial y debe usarla de acuerdo con los términos de aceptación de
* licencia de uso que firmó con Byte.
*/
@Audited
@Entity
@Table(name = "AVB_CHANNEL_PARAM")
@Getter
......
package com.bytesw.bytebot.model;
import lombok.*;
import org.hibernate.envers.Audited;
import javax.persistence.*;
import java.util.List;
@Audited
@Entity
@Getter
@Setter
......
......@@ -6,6 +6,7 @@ import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.envers.Audited;
import javax.persistence.*;
import java.util.List;
......@@ -21,6 +22,7 @@ import java.util.List;
* Confidencial y debe usarla de acuerdo con los términos de aceptación de
* licencia de uso que firmó con Byte.
*/
@Audited
@Entity
@Table(name = "AVB_DEPLOYMENT_CHANNEL")
@Getter
......
......@@ -4,6 +4,7 @@ import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.envers.Audited;
import javax.persistence.*;
......@@ -18,6 +19,7 @@ import javax.persistence.*;
* Confidencial y debe usarla de acuerdo con los términos de aceptación de
* licencia de uso que firmó con Byte.
*/
@Audited
@Entity
@Table(name = "AVB_DEPLOYMENT_CHANNEL_PARAM_VALUE")
@Getter
......
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;
import lombok.ToString;
import org.hibernate.envers.Audited;
import javax.persistence.*;
import java.time.LocalDateTime;
import java.time.OffsetDateTime;
/**
* @author Sebastian Chicoma Sandmann
......@@ -24,12 +22,14 @@ import java.time.OffsetDateTime;
* Confidencial y debe usarla de acuerdo con los términos de aceptación de
* licencia de uso que firmó con Byte.
*/
@Audited
@Entity
@Table(name = "AVB_FREQUENT_QUESTION")
@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")
......
......@@ -9,7 +9,7 @@ import org.hibernate.envers.Audited;
import javax.persistence.*;
import java.io.Serializable;
//@Audited
@Audited
@Entity
@Table(name = "avb_process_etl")
@NamedQuery(name = "ProcessETL.findByPK", query = "Select u from ProcessETL u where u.id = ?1")
......
......@@ -14,7 +14,9 @@ import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.annotations.Type;
import org.hibernate.envers.Audited;
@Audited
@Entity
@Getter
@Setter
......
......@@ -12,7 +12,7 @@ import javax.persistence.Entity;
import javax.persistence.NamedQuery;
import java.time.OffsetDateTime;
//@Audited
@Audited
@Entity
@DiscriminatorValue(value= RangeCalendarException.DISCRIMINATOR_VALUE)
@NamedQuery(name = "RangeCalendarException.findByPK", query = "Select u from RangeCalendarException u where u.id = ?1")
......
......@@ -13,7 +13,7 @@ import javax.persistence.*;
import java.io.Serializable;
import java.math.BigInteger;
//@Audited
@Audited
@Entity
@Table(name = "AVB_SCHEDULER_TASK")
@NamedQuery(name = "SchedulerTask.findByPK", query = "Select u from SchedulerTask u where u.id = ?1")
......
package com.bytesw.bytebot.model;
import lombok.*;
import org.hibernate.envers.Audited;
import javax.persistence.*;
......@@ -15,7 +16,7 @@ import javax.persistence.*;
* Confidencial y debe usarla de acuerdo con los términos de aceptación de
* licencia de uso que firmó con Byte.
*/
@Audited
@Entity
@Getter @Setter
@NoArgsConstructor
......
......@@ -12,7 +12,7 @@ import javax.persistence.Entity;
import javax.persistence.NamedQuery;
import java.time.LocalDate;
//@Audited
@Audited
@Entity
@DiscriminatorValue(value= UniqueCalendarException.DISCRIMINATOR_VALUE)
@NamedQuery(name = "UniqueCalendarException.findByPK", query = "Select u from UniqueCalendarException u where u.id = ?1")
......
......@@ -11,7 +11,7 @@ import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.NamedQuery;
//@Audited
@Audited
@Entity
@DiscriminatorValue(value= UniqueWeeklyCalendarException.DISCRIMINATOR_VALUE)
@NamedQuery(name = "UniqueWeeklyCalendarException.findByPK", query = "Select u from UniqueWeeklyCalendarException u where u.id = ?1")
......
......@@ -14,7 +14,7 @@ import java.math.BigInteger;
import java.time.OffsetDateTime;
import java.time.OffsetTime;
//@Audited
@Audited
@Entity
@Table(name = "AVB_WEEK_SCHEDULER")
@NamedQuery(name = "WeekScheduler.findByPK", query = "Select u from WeekScheduler u where u.id = ?1")
......
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();
}
......
......@@ -21,6 +21,9 @@ public class StatusConverter implements AttributeConverter<StatusEnum, String> {
@Override
public String convertToDatabaseColumn(StatusEnum value) {
if (value == null) {
return null;
}
return value.getName();
}
......
......@@ -8,19 +8,19 @@ import org.springframework.stereotype.Component;
@Component
public class SFTPRoute extends RouteBuilder {
@Value("${application.bytebot-integration.ftp.username}")
@Value("${application.AVB-integration.ftp.username}")
private String username;
@Value("${application.bytebot-integration.ftp.password}")
@Value("${application.AVB-integration.ftp.password}")
private String password;
@Value("${application.bytebot-integration.ftp.directory:}")
@Value("${application.AVB-integration.ftp.directory:}")
private String directory;
@Value("${application.bytebot-integration.ftp.host}")
@Value("${application.AVB-integration.ftp.host}")
private String host;
@Value("${application.bytebot-integration.ftp.passiveMode:true}")
@Value("${application.AVB-integration.ftp.passiveMode:true}")
private boolean passiveMode;
@Value("${application.services.multi-tenant:false}")
......
package com.bytesw.bytebot.service;
import com.bytesw.bytebot.bean.*;
import com.bytesw.bytebot.etl.batch.service.ScheduleService;
import com.bytesw.bytebot.model.*;
import com.bytesw.bytebot.jdbc.AgentJDBCRepository;
import com.bytesw.bytebot.model.enums.*;
......@@ -60,6 +61,9 @@ public class AgentService extends CustomPaginationService<Agent> {
@Autowired
private ProducerTemplate producerTemplate;
@Autowired
private ScheduleService scheduleService;
public List<DeploymentChannelParamValueBean> GetKeysFromAgents(AgentStatusEnum status){
List<DeploymentChannelParamValueBean> values = agentJDBCRepository.getCredentialsFromAgentStatus(status.getName());
......@@ -147,7 +151,6 @@ public class AgentService extends CustomPaginationService<Agent> {
if (agent.getCountryId() != null) {
Optional<Country> countryFound = countryRepository.findById(agent.getCountryId());
if (countryFound.isPresent()) {
agentBD.setCountry(countryFound.get());
}
......@@ -435,7 +438,7 @@ public class AgentService extends CustomPaginationService<Agent> {
if (agentFound.isPresent()) {
Agent agent = agentFound.get();
agent.setStatus(AgentStatusEnum.DELETED);
scheduleService.cancelTaskDelete(id);
agentRepository.save(agent);
}
}
......
......@@ -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;
......@@ -23,6 +25,7 @@ import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.time.OffsetDateTime;
import java.util.List;
import java.util.Optional;
......@@ -41,9 +44,19 @@ public class BucketService {
@Value("${application.bucket.modelBucket}")
private String modelDir;
@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;
......@@ -54,21 +67,34 @@ public class BucketService {
}
public boolean generate(byte[] file, FileValidationResponse response) {
Optional<BusinessParameter> businessParameter = businessParameterRepository.findByKey("Bucket");
boolean result = false;
if (!businessParameter.isPresent()) {
throw new NotFoundException("No existe el parametro de negocio del bucket.");
Optional<BusinessParameter> deployment = businessParameterRepository.findByKey(parameter);
String bucketName = new String();
if (!deployment.isPresent()) {
response.setMessage("NOT.FOUND.BUSINESS.PARAMETER");
throw new NotFoundException();
}
String bucketName = businessParameter.get().getDefaultValue();
List<BusinessParameterConfiguration> deploy = businessParameterConfigurationRepository
.findBusinessParameterConfigurationListByBusinessParameter(deployment.get().getId());
if (deploy.isEmpty()) {
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());
try {
FileOutputStream stream = new FileOutputStream(mainFile);
stream.write(file);
String newFile = String.format("%s/%s/1.0/%s/%s",tenant, response.getUuid(), fileDir, mainFile.getName());
String newFile = String.format("%s/%s/%s/%s/%s",tenant, response.getUuid(), version, fileDir, mainFile.getName());
PutObjectRequest request = new PutObjectRequest(bucketName, newFile, mainFile);
AmazonS3 amazonS3 = getS3Client();
amazonS3.putObject(request);
String modelFile = String.format("%s/%s/1.0/%s",tenant, response.getUuid(), modelDir);
String modelFile = String.format("%s/%s/%s/%s",tenant, response.getUuid(), version, modelDir);
createFolder(bucketName, modelFile, amazonS3);
mainFile.delete();
result = true;
......@@ -88,20 +114,20 @@ 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("No existe el parametro de negocio del bucket.");
throw new NotFoundException();
}
String bucketName = businessParameter.get().getDefaultValue();
try {
AmazonS3 s3Client = getS3Client();
Optional<QuestionFile> questionFile = questionFileRepository.findByUuid(uuid);
if (!questionFile.isPresent()) {
throw new NotFoundException("El uuid no se encuentra enlazado con un file");
throw new NotFoundException();
}
String keyName = String.format("%s/%s/1.0/%s/%s",tenant, uuid, fileDir, questionFile.get().getName());
String keyName = String.format("%s/%s/%s/%s/%s",tenant, uuid, version, fileDir, questionFile.get().getName());
s3Client.deleteObject(new DeleteObjectRequest(bucketName, keyName));
keyName = String.format("%s/%s/1.0/%s/",tenant, uuid, modelDir);
keyName = String.format("%s/%s/%s/%s/",tenant, uuid, version, modelDir);
s3Client.deleteObject(new DeleteObjectRequest(bucketName, keyName));
} catch (AmazonServiceException e) {
e.printStackTrace();
......
......@@ -2,12 +2,10 @@ package com.bytesw.bytebot.service;
import com.bytesw.bytebot.etl.utils.JsonUtils;
import com.bytesw.bytebot.http.FileValidationResponse;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.log4j.Log4j2;
import org.apache.http.HttpEntity;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
......@@ -18,8 +16,6 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@Service
@Log4j2
......@@ -31,10 +27,13 @@ public class KnowledgeService {
@Value("${application.knowledge.url}")
private String url;
@Value("${application.bucket.version}")
private String version;
public boolean generate(FileValidationResponse response) throws IOException {
boolean result = false;
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpPost httppost = new HttpPost(String.format("%s/clients/%s/versions/1.0", url, tenant));
HttpPost httppost = new HttpPost(String.format("%s/clients/%s/versions/%s", url, tenant, version));
String json = String.format("{\"filename_csv\": \"%s\", \"index_name\": \"%s\"}",response.getFileName(), response.getUuid());
StringEntity entity = new StringEntity(json);
try {
......@@ -52,10 +51,11 @@ public class KnowledgeService {
};
String res = httpclient.execute(httppost, responseHandler);
String status = (String) JsonUtils.getFieldFromJson(res, "$.message.status");
httpclient.close();
if (status.equals("success")){
result = true;
}
} catch (IOException e) {
} catch (Exception e) {
log.error(e.getMessage());
}
return result;
......@@ -64,8 +64,7 @@ public class KnowledgeService {
public boolean delete(String uuid) {
boolean result = false;
try {
HttpDelete httpDelete = new HttpDelete(String.format("%s/clients/%s/indexes/%s/versions/1.0", url, tenant, uuid));
System.out.println("Executing request " + httpDelete.getRequestLine());
HttpDelete httpDelete = new HttpDelete(String.format("%s/clients/%s/indexes/%s/versions/%s", url, tenant, uuid, version));
ResponseHandler<String> responseHandler = response -> {
int status = response.getStatusLine().getStatusCode();
if (status >= 200 && status < 300) {
......
......@@ -4,19 +4,25 @@ 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;
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.io.IOException;
import java.time.OffsetDateTime;
import java.util.List;
import java.util.Optional;
@Service
......@@ -39,18 +45,46 @@ public class OrquestadorService {
@Autowired
private KnowledgeService knowledgeService;
@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(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()) {
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.validateAndSaveFile(uuid,file);
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());
......@@ -58,46 +92,77 @@ public class OrquestadorService {
model.setStatus(StatusBcdEnum.CARGADO.getName());
model = bdcControlRepository.save(model);
//Carga archivo a bucket
step = bucketService.generate(file.getBytes(), response);
if (!step) {
throw new NotFoundException("Error a cargar archivo.");
if (modeDeployment.equalsIgnoreCase("onCloud")) {
//Carga archivo a bucket
step = bucketService.generate(file.getBytes(), response);
if (!step) {
response.setMessage("NOT.FOUND.BUCKET");
throw new NotFoundException();
}
step = false;
model.setStatus(StatusBcdEnum.INDEXANDO.getName());
model = bdcControlRepository.save(model);
}
step = false;
model.setStatus(StatusBcdEnum.INDEXANDO.getName());
model = bdcControlRepository.save(model);
//Generacion del modelo
step = knowledgeService.generate(response);
if (!step) {
throw new NotFoundException("Error a cargar archivo.");
response.setMessage("NOT.FOUND.KNOWLEDGE");
throw new NotFoundException();
}
response.setStatus(FrequentQuestionStatusEnum.CORRECTO.getName());
model.setStatus(StatusBcdEnum.INDEXADO.getName());
model = bdcControlRepository.save(model);
}catch (Exception e) {
if (response.getMessage() == null) {
response.setMessage("ERROR.UPLOAD");
}
response.setStatus(FrequentQuestionStatusEnum.ERROR.getName());
}
return response;
}
public FileValidationResponse retry(String uuid) {
Optional<BdcControl> modelBdc = bdcControlRepository.findByUuid(uuid);
if (!modelBdc.isPresent()) {
throw new NotFoundException("No se subio archivo a la BD");
throw new NotFoundException("NOT.FOUND.DATA.CONTROL");
}
boolean step = false;
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()) {
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);
if (!questionFile.isPresent()) {
throw new NotFoundException("No se encontro archivo en la BD");
response.setMessage("NOT.FOUND.DATA");
throw new NotFoundException();
}
step = bucketService.generate(questionFile.get().getData(), response);
if (!step) {
throw new NotFoundException("Error a cargar archivo.");
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);
......@@ -106,13 +171,17 @@ public class OrquestadorService {
if (model.getStatus().equals(StatusBcdEnum.INDEXANDO.getName())) {
step = knowledgeService.generate(response);
if (!step) {
throw new NotFoundException("Error a cargar knowledge.");
response.setMessage("NOT.FOUND.KNOWLEDGE");
throw new NotFoundException();
}
}
model.setStatus(StatusBcdEnum.INDEXADO.getName());
model = bdcControlRepository.save(model);
response.setStatus(FrequentQuestionStatusEnum.CORRECTO.getName());
} catch (IOException e) {
} catch (Exception e) {
if (response.getMessage() == null) {
response.setMessage("ERROR.UPLOAD");
}
response.setStatus(FrequentQuestionStatusEnum.ERROR.getName());
}
return response;
......@@ -121,13 +190,13 @@ 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());
model = bdcControlRepository.save(model);
......
......@@ -2,10 +2,12 @@ package com.bytesw.bytebot.service;
import com.bytesw.bytebot.bean.CalendarBean;
import com.bytesw.bytebot.bean.SchedulerTaskBean;
import com.bytesw.bytebot.etl.batch.service.ScheduleService;
import com.bytesw.bytebot.model.Calendar;
import com.bytesw.bytebot.model.SchedulerTask;
import com.bytesw.bytebot.repository.CalendarRepository;
import com.bytesw.bytebot.repository.SchedulerTaskRepository;
import com.bytesw.xdf.exception.AlreadyExistsException;
import com.bytesw.xdf.exception.NotFoundException;
import com.bytesw.xdf.service.XDFService;
import org.springframework.beans.BeanUtils;
......@@ -26,6 +28,12 @@ public class SchedulerTaskService extends XDFService<SchedulerTask, SchedulerTas
@Autowired
private CalendarRepository calendarRepository;
@Autowired
private SchedulerTaskRepository schedulerTaskRepository;
@Autowired
private ScheduleService scheduleService;
protected SchedulerTaskService(SchedulerTaskRepository repository) {
super(repository);
}
......@@ -73,4 +81,38 @@ public class SchedulerTaskService extends XDFService<SchedulerTask, SchedulerTas
initialData.put("calendarList", calendarBeanList);
return initialData;
}
@Override
public SchedulerTaskBean create(SchedulerTaskBean schedulerTaskBean) {
SchedulerTask schedulerTask = new SchedulerTask();
schedulerTask = toModel(schedulerTask, schedulerTaskBean);
schedulerTask = schedulerTaskRepository.save(schedulerTask);
scheduleService.restartTask(schedulerTask);
System.out.println(schedulerTask);
return toBean(schedulerTask);
}
@Override
public SchedulerTaskBean update(SchedulerTaskBean bean, BigInteger id) {
Optional<SchedulerTask> model = schedulerTaskRepository.findById(id);
if (!model.isPresent()) {
throw new NotFoundException();
}
SchedulerTask schedulerTask = new SchedulerTask();
schedulerTask = toModel(schedulerTask, bean);
schedulerTask = schedulerTaskRepository.save(schedulerTask);
scheduleService.restartTask(schedulerTask);
return toBean(schedulerTask);
}
@Override
public void delete (BigInteger id) {
Optional<SchedulerTask> model = schedulerTaskRepository.findById(id);
if (!model.isPresent()) {
throw new NotFoundException();
}
scheduleService.cancelTask(model.get());
schedulerTaskRepository.deleteById(id);
}
}
spring.autoconfigure.exclude: org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration, org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration, org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration
server:
servlet.context-path: ${APPLICATION_PATH:/bytebot}
servlet.context-path: ${APPLICATION_PATH:/AVB}
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/
#NOTA debe terminar con /
static-content-location: file:/home/mgutierrez/Descargas/dist/bytebot-html/
security:
......@@ -28,7 +27,7 @@ application:
byte-bot:
batch:
chunk: 10
cron: 0/50 * * * * *
cron: 0 0/1 * * * *
show-side-bar: false
test: ENC(OEchnTXpIZnCVdPNthgCZBfQjMt1AUS1)
name: xdf-example
......@@ -56,7 +55,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:
......@@ -72,7 +71,7 @@ application:
messaging:
queue-test: action_queue.fifo
topic-test: topic-test
bytebot-integration:
AVB-integration:
ftp:
host: localhost
username: ftp
......@@ -94,11 +93,17 @@ application:
host: localhost
port: 8161
queue-name: task_queue
timezone:
zone: TimeZone
default: America/Mexico_City
bucket:
deployment: DeployMode
parameter: KnowledgeBaseBucket
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 +117,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_hdi
driverClassName: 'org.postgresql.Driver'
username: postgres
password: postgres
......@@ -123,16 +128,16 @@ spring:
hikari.registerMbeans: true
security:
basepath: http://localhost:9077/bytebot
basepath: http://localhost:9077/AVB
provider: byte # oracle, amazon
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 +145,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_hdi
driverClassName: 'org.postgresql.Driver'
username: postgres
password: postgres
......@@ -150,16 +155,16 @@ spring:
testWhileIdle: true
hikari.registerMbeans: true
security:
basepath: http://localhost:9077/bytebot
basepath: http://localhost:9077/AVB
provider: byte # oracle, amazon
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 +187,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