Commit f8749f30 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!25
parents 32751635 836b9b9c
......@@ -9,13 +9,12 @@ RUN apk add --update curl && \
RUN export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:/bin/java::")
RUN export PATH=$JAVA_HOME/bin:$PATH
VOLUME /tmp
ARG JAR_FILE
RUN echo ${JAR_FILE}
COPY ${JAR_FILE} app.jar
ENV JAVA_OPTS="-Xms512m -Xmx1024m"
# VOLUME /tmp
RUN echo 'target/bytebot-service-1.0.1-SNAPSHOT.jar'
COPY 'target/bytebot-service-1.0.1-SNAPSHOT.jar' app.jar
# ENV JAVA_OPTS="-Xms512m -Xmx1024m"
EXPOSE 8080
EXPOSE 8443
EXPOSE 22
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ]
ENTRYPOINT [ "sh", "-c", "java -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ]
FROM python:3.8-slim
USER root
COPY . .
RUN apt update && \
apt install -y nano curl awscli
RUN chmod +x entrypoint.sh
RUN mkdir /data
VOLUME [ "/data" ]
CMD ["sh","entrypoint.sh"]
\ No newline at end of file
#!/bin/bash
aws s3 sync s3://$bucket$path /data/$directory/
while :
do
echo "Container is still running"
sleep 5
done
\ No newline at end of file
package com.bytesw.bytebot.etl.batch.listener;
import lombok.extern.log4j.Log4j2;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.listener.JobExecutionListenerSupport;
@Log4j2
public class JobCompletionListener extends JobExecutionListenerSupport {
@Override
public void afterJob(JobExecution jobExecution) {
if (jobExecution.getStatus() == BatchStatus.COMPLETED) {
System.out.println("BATCH JOB COMPLETED SUCCESSFULLY");
log.debug("BATCH JOB COMPLETED SUCCESSFULLY");
}
}
......
......@@ -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;
}
......@@ -285,7 +292,6 @@ public class ScheduleService implements SchedulingConfigurer {
.getListAgentChannel(AgentStatusEnum.DEPLOYED.getName(), AgentParameterEnum.ACCESS_TWILIO.getName());
String keyDataSens = "";
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.getAgenId());
if (!futureMap.containsKey(keyDataSens)) {
......@@ -321,7 +327,7 @@ public class ScheduleService implements SchedulingConfigurer {
result = false;
}
} else if (exception.getFrequencyType().equals(FrequencyType.UNIQUE.getName())) {
if (now.toLocalDate() == exception.getDate()) {
if (now.toLocalDate().equals(exception.getDate())) {
result = false;
}
} else if (exception.getFrequencyType().equals(FrequencyType.UniqueWeekly.getName())) {
......@@ -347,8 +353,8 @@ public class ScheduleService implements SchedulingConfigurer {
@Scheduled(cron = "${application.byte-bot.batch.cron}")
@SchedulerLock(name = "Dashboard-ETL", lockAtLeastFor = "PT40S", lockAtMostFor = "PT50S")
protected void createJob() {
List<Agent> agentDeployed = agentRepository.findByStatus(AgentStatusEnum.DEPLOYED);
log.info("INICIADO");
if (!agentDeployed.isEmpty()) {
ThreadLocalStorage.setTenantName(tenant);
Job job = jobBuilderFactory.get("processJob")
......@@ -389,7 +395,9 @@ public class ScheduleService implements SchedulingConfigurer {
/* Métodos ETL de data sensible */
private Job createJobDataSens(DeleteDataSensBean data) {
System.out.println("ETL de eliminacion");
log.info("ETL de eliminacion");
data = deleteDataSensJDBCRepository.getAgentChannelByAgentID(AgentStatusEnum.DEPLOYED.getName(),
AgentParameterEnum.ACCESS_TWILIO.getName(), data.getAgenId());
ThreadLocalStorage.setTenantName(tenant);
return jobBuilderFactory.get( String.format("processDataSensible-%d",data.getAgenId()))
.incrementer(new RunIdIncrementer()).listener(listener)
......@@ -426,13 +434,13 @@ public class ScheduleService implements SchedulingConfigurer {
DeleteDataSensControlBean control = deleteDataSensJDBCRepository.getControl(data.getAgenId());
OffsetDateTime endDate = OffsetDateTime.now();
Long id = 0L;
int differenceTime = 0;
Long differenceTime = 0L;
if (control != null) {
OffsetDateTime lastSessionDate = OffsetDateTime.ofInstant(control.getDateDelete().toInstant(), ZoneId.systemDefault());
Duration difference = Duration.between(lastSessionDate, endDate);
differenceTime = (int) (difference.getSeconds() / 60);
differenceTime = (difference.getSeconds() / 60);
if (differenceTime < data.getDeletePeriod()) {
log.info("Agente " + data.getValue() + " aun no cumple con el periodo de espera.");
......
......@@ -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());
......
......@@ -31,6 +31,19 @@ public class DeleteDataSensJDBCRepository {
}
}
public DeleteDataSensBean getAgentChannelByAgentID(String status, String channel, Long id){
SqlSession session = sqlSessionFactory.openSession();
try {
Map<String, Object> params = new HashMap<>();
params.put("status", status);
params.put("channel", channel);
params.put("agentId", id);
return session.selectOne("com.bytesw.bytebot.dao.jdbc.ETLDataSensibleMapper.getAgentChannelByAgentId", params);
} finally {
session.close();
}
}
public DeleteDataSensControlBean getControl(Long id){
SqlSession session = sqlSessionFactory.openSession();
try {
......
package com.bytesw.bytebot.repository;
import com.bytesw.bytebot.model.Country;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import java.util.List;
/**
* @author Sebastián Chicoma Sandmann.
* @version 9-sep-2020
......@@ -15,4 +18,7 @@ import org.springframework.data.repository.CrudRepository;
* licencia de uso que firmó con Byte.
*/
public interface CountryRepository extends CrudRepository<Country, Long> {
@Query("select c from Country c order by c.name")
List<Country> findAllOrder();
}
......@@ -451,7 +451,7 @@ public class AgentService extends CustomPaginationService<Agent> {
public List<CountryBean> getCountries() {
List<CountryBean> countriesBean = new ArrayList<>();
List<Country> countries = (List<Country>) countryRepository.findAll();
List<Country> countries = countryRepository.findAllOrder();
for (Country country : countries) {
countriesBean.add(CountryBean.clone(country));
......
......@@ -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);
......@@ -136,13 +120,4 @@ public class BucketService {
}
}
public void list() {
AmazonS3 s3 = getS3Client();
List<Bucket> buckets = s3.listBuckets();
System.out.println("Your {S3} buckets are:");
for (Bucket b : buckets) {
System.out.println("* " + b.getName());
}
}
}
......@@ -283,7 +283,6 @@ public class BusinessParameterService extends XDFService<BusinessParameter, Busi
public boolean validateKey(BusinessParameterBean bean) {
Optional<BusinessParameter> businessParameterOptional = this.businessParameterRepository.findByKey(bean.getKey());
System.out.println(businessParameterOptional);
if (businessParameterOptional.isPresent()) {
BusinessParameterBean businessParameterBeanOptional = toBean(businessParameterOptional.get());
if (!businessParameterBeanOptional.getId().equals(bean.getId())) {
......@@ -305,4 +304,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()) && config.getTo().isAfter(nowTime)) {
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);
}
......
......@@ -8,14 +8,12 @@
SELECT COUNT(MESSA_ID)
FROM AVB_MESSAGE
WHERE MESSA_DATE &lt;= #{endDate} AND MESSA_DATE &gt;= #{startDate}
and INTEN_ID IS NOT NULL
</select>
<select id="countMessagesInRangeForHour" resultType="int" flushCache="true">
SELECT COUNT(MESSA_ID)
FROM AVB_MESSAGE
WHERE MESSA_DATE &lt;= #{endDate} AND MESSA_DATE &gt;= #{startDate}
and INTEN_ID IS NOT NULL
</select>
<!-- @TODO Pendiente agregar la fecha -->
......
......@@ -14,8 +14,8 @@
<select id="countSessionsInRange" resultType="int" flushCache="true">
select count(session_id) from avb_session
WHERE SESSION_LEDAT &lt;= #{endDate}
AND SESSION_LEDAT &gt;= #{startDate}
WHERE SESSION_DATE &lt;= #{endDate}
AND SESSION_DATE &gt;= #{startDate}
</select>
<select id="avgSessionsByCustomerInRange" resultType="Double" flushCache="true">
......@@ -23,7 +23,7 @@
(
select count(USER_ID) as SESSION_CANT
from AVB_SESSION bas
WHERE SESSION_LEDAT &lt;= #{endDate} AND SESSION_LEDAT &gt;= #{startDate} GROUP BY USER_ID
WHERE SESSION_DATE &lt;= #{endDate} AND SESSION_DATE &gt;= #{startDate} GROUP BY USER_ID
) AVB_SESSION_COUNT
</select>
......
......@@ -8,14 +8,12 @@
SELECT COUNT(MESSA_ID)
FROM AVB_MESSAGE
WHERE MESSA_DATE &lt;= #{endDate} AND MESSA_DATE &gt;= #{startDate}
and INTEN_ID IS NOT NULL
</select>
<select id="countMessagesInRangeForHour" resultType="int" flushCache="true">
SELECT COUNT(MESSA_ID)
FROM AVB_MESSAGE
WHERE MESSA_DATE &lt;= #{endDate} AND MESSA_DATE &gt;= #{startDate}
and INTEN_ID IS NOT NULL
</select>
<!-- @TODO Pendiente agregar la fecha -->
......
......@@ -14,8 +14,8 @@
<select id="countSessionsInRange" resultType="int" flushCache="true">
select count(session_id) from avb_session
WHERE SESSION_LEDAT &lt;= #{endDate}
AND SESSION_LEDAT &gt;= #{startDate}
WHERE SESSION_DATE &lt;= #{endDate}
AND SESSION_DATE &gt;= #{startDate}
</select>
<select id="avgSessionsByCustomerInRange" resultType="Double" flushCache="true">
......@@ -23,7 +23,7 @@
(
select count(USER_ID) as SESSION_CANT
from AVB_SESSION bas
WHERE SESSION_LEDAT &lt;= #{endDate} AND SESSION_LEDAT &gt;= #{startDate} GROUP BY USER_ID
WHERE SESSION_DATE &lt;= #{endDate} AND SESSION_DATE &gt;= #{startDate} GROUP BY USER_ID
) AVB_SESSION_COUNT
</select>
......
......@@ -17,6 +17,19 @@
WHERE agen_state=#{status} AND chpa_label=#{channel}
</select>
<select id="getAgentChannelByAgentId" resultType="ChannelByAgent" flushCache="true">
SELECT chpv_id as id,
chpv_value as channelValue,
AG.agen_iden as value,
AG.agen_id as agenId,
AG.agen_delete_sensible_period as deletePeriod
FROM AVB_DEPLOYMENT_CHANNEL_PARAM_VALUE ADCP
JOIN AVB_CHANNEL_PARAM ACP ON ACP.chpa_id=ADCP.chpa_id
JOIN avb_deployment_channel AD on AD.dcha_id=ADCP.dcha_id
JOIN avb_agent AG on AG.agen_id=AD.agen_id
WHERE agen_state=#{status} AND chpa_label=#{channel} and AG.agen_id = #{agentId}
</select>
<select id="getControl" resultType="DeleteControl" flushCache="true">
SELECT dsmc_id as id,
agent_id as agentId,
......
......@@ -17,6 +17,19 @@
WHERE agen_state=#{status} AND chpa_label=#{channel}
</select>
<select id="getAgentChannelByAgentId" resultType="ChannelByAgent" flushCache="true">
SELECT chpv_id as id,
chpv_value as channelValue,
AG.agen_iden as value,
AG.agen_id as agenId,
AG.agen_delete_sensible_period as deletePeriod
FROM AVB_DEPLOYMENT_CHANNEL_PARAM_VALUE ADCP
JOIN AVB_CHANNEL_PARAM ACP ON ACP.chpa_id=ADCP.chpa_id
JOIN avb_deployment_channel AD on AD.dcha_id=ADCP.dcha_id
JOIN avb_agent AG on AG.agen_id=AD.agen_id
WHERE agen_state=#{status} AND chpa_label=#{channel} and AG.agen_id = #{agentId}
</select>
<select id="getControl" resultType="DeleteControl" flushCache="true">
SELECT dsmc_id as id,
agent_id as agentId,
......
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