Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
E
ejercicio2-framework-back
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Josue
ejercicio2-framework-back
Commits
8868b12a
Commit
8868b12a
authored
Nov 25, 2021
by
Cristian Aguirre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Sensible Data Elimination ETL Process
parent
5b30c81e
Changes
17
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
490 additions
and
6 deletions
+490
-6
DeleteDataSensBean.java
...om/bytesw/bytebot/etl/batch/beans/DeleteDataSensBean.java
+16
-0
DeleteDataSensControlBean.java
...sw/bytebot/etl/batch/beans/DeleteDataSensControlBean.java
+17
-0
DeleteDataSensRegistryBean.java
...w/bytebot/etl/batch/beans/DeleteDataSensRegistryBean.java
+18
-0
ConvertToBeanProcessor.java
...w/bytebot/etl/batch/processor/ConvertToBeanProcessor.java
+0
-1
ScheduleService.java
...com/bytesw/bytebot/etl/batch/service/ScheduleService.java
+96
-3
DataSensibleJPAWriter.java
...ytesw/bytebot/etl/batch/writer/DataSensibleJPAWriter.java
+70
-0
DeleteDataSensibleControlRepository.java
.../bytebot/etl/dao/DeleteDataSensibleControlRepository.java
+7
-0
IntentTypeEnum.java
...ain/java/com/bytesw/bytebot/etl/enums/IntentTypeEnum.java
+34
-0
DeleteDataSensibleControl.java
...m/bytesw/bytebot/etl/model/DeleteDataSensibleControl.java
+34
-0
DeleteSensMessageService.java
...bytesw/bytebot/etl/services/DeleteSensMessageService.java
+48
-0
ProcessMessageService.java
...om/bytesw/bytebot/etl/services/ProcessMessageService.java
+13
-1
DeleteDataSensJDBCRepository.java
...com/bytesw/bytebot/jdbc/DeleteDataSensJDBCRepository.java
+56
-0
Agent.java
src/main/java/com/bytesw/bytebot/model/Agent.java
+3
-0
AgentParameterEnum.java
...va/com/bytesw/bytebot/model/enums/AgentParameterEnum.java
+2
-1
DataSensibleMapper.xml
...resources/config/mappers/etl/mysql/DataSensibleMapper.xml
+36
-0
DataSensibleMapper.xml
...ources/config/mappers/etl/postgres/DataSensibleMapper.xml
+36
-0
mybatis-config.xml
src/main/resources/mybatis-config.xml
+4
-0
No files found.
src/main/java/com/bytesw/bytebot/etl/batch/beans/DeleteDataSensBean.java
0 → 100644
View file @
8868b12a
package
com
.
bytesw
.
bytebot
.
etl
.
batch
.
beans
;
import
lombok.Getter
;
import
lombok.Setter
;
@Getter
@Setter
public
class
DeleteDataSensBean
{
private
Long
id
;
private
String
channelValue
;
private
String
value
;
private
Long
agenId
;
private
Long
deletePeriod
;
}
src/main/java/com/bytesw/bytebot/etl/batch/beans/DeleteDataSensControlBean.java
0 → 100644
View file @
8868b12a
package
com
.
bytesw
.
bytebot
.
etl
.
batch
.
beans
;
import
lombok.Getter
;
import
lombok.Setter
;
import
java.sql.Timestamp
;
@Getter
@Setter
public
class
DeleteDataSensControlBean
{
private
Long
id
;
private
Long
agenId
;
private
Timestamp
dateDelete
;
private
Long
eventId
;
}
\ No newline at end of file
src/main/java/com/bytesw/bytebot/etl/batch/beans/DeleteDataSensRegistryBean.java
0 → 100644
View file @
8868b12a
package
com
.
bytesw
.
bytebot
.
etl
.
batch
.
beans
;
import
lombok.Getter
;
import
lombok.Setter
;
import
java.time.OffsetDateTime
;
@Getter
@Setter
public
class
DeleteDataSensRegistryBean
{
private
Long
id
;
private
Long
inten_id
;
private
Long
sender_id
;
private
String
message_sid
;
private
String
multimedia_sid
;
private
OffsetDateTime
update_time
;
}
src/main/java/com/bytesw/bytebot/etl/batch/processor/ConvertToBeanProcessor.java
View file @
8868b12a
...
@@ -3,7 +3,6 @@ package com.bytesw.bytebot.etl.batch.processor;
...
@@ -3,7 +3,6 @@ package com.bytesw.bytebot.etl.batch.processor;
import
com.bytesw.bytebot.etl.batch.beans.DynaBean
;
import
com.bytesw.bytebot.etl.batch.beans.DynaBean
;
import
com.bytesw.bytebot.etl.beans.EventBean
;
import
com.bytesw.bytebot.etl.beans.EventBean
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
lombok.extern.log4j.Log4j2
;
import
org.springframework.batch.item.ItemProcessor
;
import
org.springframework.batch.item.ItemProcessor
;
public
class
ConvertToBeanProcessor
implements
ItemProcessor
<
DynaBean
,
DynaBean
>
{
public
class
ConvertToBeanProcessor
implements
ItemProcessor
<
DynaBean
,
DynaBean
>
{
...
...
src/main/java/com/bytesw/bytebot/etl/batch/service/ScheduleService.java
View file @
8868b12a
package
com
.
bytesw
.
bytebot
.
etl
.
batch
.
service
;
package
com
.
bytesw
.
bytebot
.
etl
.
batch
.
service
;
import
com.bytesw.bytebot.etl.batch.beans.DynaBean
;
import
com.bytesw.bytebot.etl.batch.beans.*
;
import
com.bytesw.bytebot.etl.batch.beans.TenantBatchBean
;
import
com.bytesw.bytebot.etl.batch.factory.mapper.RowMapperFactory
;
import
com.bytesw.bytebot.etl.batch.factory.mapper.RowMapperFactory
;
import
com.bytesw.bytebot.etl.batch.factory.reader.DataBaseItemReaderFactory
;
import
com.bytesw.bytebot.etl.batch.factory.reader.DataBaseItemReaderFactory
;
import
com.bytesw.bytebot.etl.batch.processor.ConvertToBeanProcessor
;
import
com.bytesw.bytebot.etl.batch.processor.ConvertToBeanProcessor
;
import
com.bytesw.bytebot.etl.batch.writer.ByteBotJPAWriter
;
import
com.bytesw.bytebot.etl.batch.writer.ByteBotJPAWriter
;
import
com.bytesw.bytebot.etl.batch.writer.DataSensibleJPAWriter
;
import
com.bytesw.bytebot.etl.config.BatchProperties
;
import
com.bytesw.bytebot.etl.config.BatchProperties
;
import
com.bytesw.bytebot.etl.dao.EventHistoryRepository
;
import
com.bytesw.bytebot.etl.dao.EventHistoryRepository
;
import
com.bytesw.bytebot.etl.enums.IntentTypeEnum
;
import
com.bytesw.bytebot.etl.services.DeleteSensMessageService
;
import
com.bytesw.bytebot.etl.services.ProcessMessageService
;
import
com.bytesw.bytebot.etl.services.ProcessMessageService
;
import
com.bytesw.bytebot.jdbc.DeleteDataSensJDBCRepository
;
import
com.bytesw.bytebot.model.enums.AgentParameterEnum
;
import
com.bytesw.bytebot.model.enums.AgentStatusEnum
;
import
com.bytesw.bytebot.repository.AgentRepository
;
import
com.bytesw.xdf.multitenant.core.ThreadLocalStorage
;
import
com.bytesw.xdf.multitenant.core.ThreadLocalStorage
;
import
com.google.gson.Gson
;
import
com.google.gson.Gson
;
import
lombok.extern.log4j.Log4j2
;
import
lombok.extern.log4j.Log4j2
;
...
@@ -29,6 +35,9 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar;
...
@@ -29,6 +35,9 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import
org.springframework.scheduling.support.CronTrigger
;
import
org.springframework.scheduling.support.CronTrigger
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
java.time.Duration
;
import
java.time.OffsetDateTime
;
import
java.time.ZoneId
;
import
java.util.*
;
import
java.util.*
;
import
java.util.concurrent.ScheduledFuture
;
import
java.util.concurrent.ScheduledFuture
;
...
@@ -76,6 +85,9 @@ public class ScheduleService implements SchedulingConfigurer {
...
@@ -76,6 +85,9 @@ public class ScheduleService implements SchedulingConfigurer {
@Autowired
@Autowired
private
ProcessMessageService
service
;
private
ProcessMessageService
service
;
@Autowired
private
DeleteSensMessageService
deleteSensMessageService
;
@Autowired
@Autowired
private
Gson
gson
;
private
Gson
gson
;
...
@@ -85,6 +97,12 @@ public class ScheduleService implements SchedulingConfigurer {
...
@@ -85,6 +97,12 @@ public class ScheduleService implements SchedulingConfigurer {
@Autowired
@Autowired
private
EventHistoryRepository
eventHistoryRepository
;
private
EventHistoryRepository
eventHistoryRepository
;
@Autowired
private
AgentRepository
agentRepository
;
@Autowired
private
DeleteDataSensJDBCRepository
deleteDataSensJDBCRepository
;
@Override
@Override
public
void
configureTasks
(
ScheduledTaskRegistrar
taskRegistrar
)
{
public
void
configureTasks
(
ScheduledTaskRegistrar
taskRegistrar
)
{
if
(
scheduledTaskRegistrar
==
null
)
{
if
(
scheduledTaskRegistrar
==
null
)
{
...
@@ -110,15 +128,28 @@ public class ScheduleService implements SchedulingConfigurer {
...
@@ -110,15 +128,28 @@ public class ScheduleService implements SchedulingConfigurer {
configureTask
(
tenant
.
getId
(),
"prueba"
,
taskRegistrar
);
configureTask
(
tenant
.
getId
(),
"prueba"
,
taskRegistrar
);
});
});
//@TODO Falta añadir el modo multitenan
//@TODO Falta añadir el modo multitenan
t
}
}
private
void
configureTask
(
String
tenantIdentifier
,
String
identifier
,
ScheduledTaskRegistrar
taskRegistrar
)
{
private
void
configureTask
(
String
tenantIdentifier
,
String
identifier
,
ScheduledTaskRegistrar
taskRegistrar
)
{
Trigger
trigger
=
new
CronTrigger
(
cronExpression
,
TimeZone
.
getDefault
());
Trigger
trigger
=
new
CronTrigger
(
cronExpression
,
TimeZone
.
getDefault
());
/* ETL de Dashboard */
String
key
=
String
.
format
(
"%s-%s"
,
tenantIdentifier
,
identifier
);
String
key
=
String
.
format
(
"%s-%s"
,
tenantIdentifier
,
identifier
);
futureMap
.
put
(
key
,
taskRegistrar
.
getScheduler
().
schedule
(()
->
scheduleCron
(
createJob
(
tenantIdentifier
),
tenantIdentifier
),
trigger
));
futureMap
.
put
(
key
,
taskRegistrar
.
getScheduler
().
schedule
(()
->
scheduleCron
(
createJob
(
tenantIdentifier
),
tenantIdentifier
),
trigger
));
/*ETL eliminacion de data sensible*/
List
<
DeleteDataSensBean
>
deleteDataSensBeans
=
deleteDataSensJDBCRepository
.
getListAgentChannel
(
AgentStatusEnum
.
DEPLOYED
.
getName
(),
AgentParameterEnum
.
ACCESS_TWILIO
.
getName
());
String
keyDataSens
=
""
;
for
(
DeleteDataSensBean
data
:
deleteDataSensBeans
){
keyDataSens
=
String
.
format
(
"%s-%s"
,
tenantIdentifier
,
data
.
getValue
());
futureMap
.
put
(
keyDataSens
,
taskRegistrar
.
getScheduler
()
.
schedule
(()
->
scheduleCron
(
createJobDataSens
(
tenantIdentifier
,
data
),
tenantIdentifier
),
trigger
));
}
}
}
/* Métodos utilizados para ETL de dashboard */
private
Job
createJob
(
String
tenantIdentifier
)
{
private
Job
createJob
(
String
tenantIdentifier
)
{
ThreadLocalStorage
.
setTenantName
(
tenantIdentifier
);
ThreadLocalStorage
.
setTenantName
(
tenantIdentifier
);
return
jobBuilderFactory
.
get
(
"processJob"
)
return
jobBuilderFactory
.
get
(
"processJob"
)
...
@@ -156,6 +187,68 @@ public class ScheduleService implements SchedulingConfigurer {
...
@@ -156,6 +187,68 @@ public class ScheduleService implements SchedulingConfigurer {
return
dataBaseItemReaderFactory
.
createReader
(
rowMapperFactory
.
createMapper
(
new
HashMap
<>()),
params
);
return
dataBaseItemReaderFactory
.
createReader
(
rowMapperFactory
.
createMapper
(
new
HashMap
<>()),
params
);
}
}
/* Métodos ETL de data sensible */
private
Job
createJobDataSens
(
String
tenantIdentifier
,
DeleteDataSensBean
data
)
{
ThreadLocalStorage
.
setTenantName
(
tenantIdentifier
);
return
jobBuilderFactory
.
get
(
"processJobDataSensible"
)
.
incrementer
(
new
RunIdIncrementer
()).
listener
(
listener
)
.
flow
(
createStepDataSens
(
tenantIdentifier
,
data
)).
end
().
build
();
}
private
Step
createStepDataSens
(
String
tenantIdentifier
,
DeleteDataSensBean
data
)
{
DataSensibleJPAWriter
writer
=
new
DataSensibleJPAWriter
();
List
<
String
>
intentByAgent
=
deleteDataSensJDBCRepository
.
getIntentByAgent
(
IntentTypeEnum
.
SENSIBLE
.
getName
(),
data
.
getAgenId
());
writer
.
setIntentByAgent
(
intentByAgent
);
writer
.
setAgent
(
data
);
writer
.
setService
(
deleteSensMessageService
);
return
stepBuilderFactory
.
get
(
"processByteBotDatasSens"
)
.<
DynaBean
,
DynaBean
>
chunk
(
chunk
)
.
reader
(
getReaderDataSens
(
tenantIdentifier
,
data
))
.
processor
(
new
ConvertToBeanProcessor
())
.
writer
(
writer
).
build
();
}
private
ItemReader
getReaderDataSens
(
String
tenantIdentifier
,
DeleteDataSensBean
data
)
{
if
(
properties
==
null
)
{
throw
new
RuntimeException
(
"Properties not found"
);
}
Optional
<
TenantBatchBean
>
tenantFound
=
findTenant
(
tenantIdentifier
);
if
(!
tenantFound
.
isPresent
())
{
throw
new
RuntimeException
(
"Properties not found"
);
}
DeleteDataSensControlBean
control
=
deleteDataSensJDBCRepository
.
getControl
(
data
.
getAgenId
());
OffsetDateTime
endDate
=
OffsetDateTime
.
now
();
Long
id
=
8200L
;
// Prueba
int
differenceTime
=
0
;
if
(
control
!=
null
){
OffsetDateTime
lastSessionDate
=
OffsetDateTime
.
ofInstant
(
control
.
getDateDelete
().
toInstant
(),
ZoneId
.
systemDefault
());
Duration
difference
=
Duration
.
between
(
lastSessionDate
,
endDate
);
differenceTime
=
(
int
)
(
difference
.
getSeconds
()/
60
);
if
(
differenceTime
<
data
.
getDeletePeriod
())
{
log
.
debug
(
"Agente "
+
data
.
getValue
()
+
" aun no cumple con el periodo de espera."
);
throw
new
RuntimeException
(
"Time is not yet fulfilled"
);
}
else
{
id
=
control
.
getEventId
();
}
}
Map
<
String
,
Object
>
params
=
new
HashMap
<>();
params
.
putAll
(
tenantFound
.
get
().
getDatasource
());
params
.
put
(
"query"
,
String
.
format
((
String
)
params
.
get
(
"query"
),
id
));
log
.
debug
(
"PARAMS: "
+
params
);
return
dataBaseItemReaderFactory
.
createReader
(
rowMapperFactory
.
createMapper
(
new
HashMap
<>()),
params
);
}
/* Métodos generales */
private
Optional
<
TenantBatchBean
>
findTenant
(
String
tenantId
)
{
private
Optional
<
TenantBatchBean
>
findTenant
(
String
tenantId
)
{
return
properties
.
getTenants
().
stream
().
filter
(
x
->
x
.
getId
().
equals
(
tenantId
)).
findFirst
();
return
properties
.
getTenants
().
stream
().
filter
(
x
->
x
.
getId
().
equals
(
tenantId
)).
findFirst
();
}
}
...
...
src/main/java/com/bytesw/bytebot/etl/batch/writer/DataSensibleJPAWriter.java
0 → 100644
View file @
8868b12a
package
com
.
bytesw
.
bytebot
.
etl
.
batch
.
writer
;
import
com.bytesw.bytebot.etl.batch.beans.DeleteDataSensBean
;
import
com.bytesw.bytebot.etl.batch.beans.DynaBean
;
import
com.bytesw.bytebot.etl.enums.EventTypeEnum
;
import
com.bytesw.bytebot.etl.services.ProcessMessageService
;
import
com.bytesw.bytebot.etl.utils.JsonUtils
;
import
com.bytesw.xdf.exception.NotFoundException
;
import
com.bytesw.xdf.multitenant.core.ThreadLocalStorage
;
import
com.bytesw.bytebot.etl.services.DeleteSensMessageService
;
import
com.bytesw.bytebot.service.provider.TwilioService
;
import
lombok.Getter
;
import
lombok.Setter
;
import
lombok.extern.log4j.Log4j2
;
import
org.springframework.batch.core.ExitStatus
;
import
org.springframework.batch.core.StepExecution
;
import
org.springframework.batch.core.StepExecutionListener
;
import
org.springframework.batch.item.ItemWriter
;
import
com.bytesw.bytebot.etl.batch.beans.DeleteDataSensRegistryBean
;
import
javax.transaction.Transactional
;
import
java.util.List
;
@Log4j2
public
class
DataSensibleJPAWriter
implements
ItemWriter
<
DynaBean
>,
StepExecutionListener
{
@Getter
@Setter
private
DeleteSensMessageService
service
;
@Getter
@Setter
private
List
<
String
>
intentByAgent
;
@Getter
@Setter
private
DeleteDataSensBean
agent
;
@Override
@Transactional
public
void
write
(
List
<?
extends
DynaBean
>
list
)
throws
Exception
{
for
(
DynaBean
dynaBean
:
list
)
{
log
.
debug
(
"LLegue ACA"
);
String
json
=
(
String
)
dynaBean
.
get
(
"data"
);
String
event
=
(
String
)
JsonUtils
.
getFieldFromJson
(
json
,
"$.event"
);
if
(
EventTypeEnum
.
USER
.
getName
().
equals
(
event
))
{
String
toAgent
=
(
String
)
JsonUtils
.
getFieldFromJson
(
json
,
"$.metadata.To"
);
if
(
agent
.
getChannelValue
().
equals
(
toAgent
))
{
String
intent
=
(
String
)
JsonUtils
.
getFieldFromJson
(
json
,
"$.parse_data.intent.name"
);
if
(
intentByAgent
.
indexOf
(
intent
)
>=
0
)
{
log
.
debug
(
"Llegue aca"
);
String
SmSMessageSid
=
(
String
)
JsonUtils
.
getFieldFromJson
(
json
,
"$.metadata.SmsMessageSid"
);
List
<
DeleteDataSensRegistryBean
>
deleteSensibleBean
=
service
.
deleteMessage
(
agent
.
getAgenId
(),
SmSMessageSid
);
}
}
}
}
//service.saveDataSensControl(eventBean.getId(), eventBean.getSenderId());
}
@Override
public
void
beforeStep
(
StepExecution
stepExecution
)
{
String
tenantId
=
stepExecution
.
getJobParameters
().
getString
(
"tenantId"
);
ThreadLocalStorage
.
setTenantName
(
tenantId
);
}
@Override
public
ExitStatus
afterStep
(
StepExecution
stepExecution
)
{
return
stepExecution
.
getExitStatus
();
}
}
src/main/java/com/bytesw/bytebot/etl/dao/DeleteDataSensibleControlRepository.java
0 → 100644
View file @
8868b12a
package
com
.
bytesw
.
bytebot
.
etl
.
dao
;
import
com.bytesw.bytebot.etl.model.DeleteDataSensibleControl
;
import
org.springframework.data.repository.CrudRepository
;
public
interface
DeleteDataSensibleControlRepository
extends
CrudRepository
<
DeleteDataSensibleControl
,
Long
>
{
}
src/main/java/com/bytesw/bytebot/etl/enums/IntentTypeEnum.java
0 → 100644
View file @
8868b12a
package
com
.
bytesw
.
bytebot
.
etl
.
enums
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.NoSuchElementException
;
public
enum
IntentTypeEnum
{
SENSIBLE
(
"1"
),
NO_SENSIBLE
(
"0"
);
private
final
String
name
;
private
static
final
Map
<
String
,
IntentTypeEnum
>
map
=
new
HashMap
<>();
static
{
for
(
IntentTypeEnum
type
:
IntentTypeEnum
.
values
())
{
map
.
put
(
type
.
name
,
type
);
}
}
IntentTypeEnum
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getName
()
{
return
name
;
}
public
static
IntentTypeEnum
fromString
(
String
name
)
{
if
(
map
.
containsKey
(
name
))
{
return
map
.
get
(
name
);
}
throw
new
NoSuchElementException
(
name
+
" not found"
);
}
}
src/main/java/com/bytesw/bytebot/etl/model/DeleteDataSensibleControl.java
0 → 100644
View file @
8868b12a
package
com
.
bytesw
.
bytebot
.
etl
.
model
;
import
lombok.Getter
;
import
lombok.Setter
;
import
lombok.ToString
;
import
javax.persistence.*
;
import
java.sql.Timestamp
;
@Cacheable
(
false
)
@Entity
@Getter
@Setter
@ToString
@Table
(
name
=
"avb_delete_sens_msg_control"
)
public
class
DeleteDataSensibleControl
{
@Id
@Column
(
name
=
"dsmc_id"
)
@TableGenerator
(
name
=
"AVB_DELETE_MSG_SENS_CONTROL_GENERATOR"
,
table
=
"SEQUENCE_TABLE"
,
pkColumnName
=
"SEQ_NAME"
,
valueColumnName
=
"SEQ_COUNT"
,
pkColumnValue
=
"AVB_DELETE_MSG_SENS_CONTROL_SEQ"
,
allocationSize
=
1
)
@GeneratedValue
(
strategy
=
GenerationType
.
TABLE
,
generator
=
"AVB_DELETE_MSG_SENS_CONTROL_GENERATOR"
)
private
Long
id
;
@Column
(
name
=
"agent_id"
)
private
Long
agentId
;
@Column
(
name
=
"dsmc_date"
)
private
Timestamp
date
;
@Column
(
name
=
"evnt_id"
)
private
Long
eventId
;
}
src/main/java/com/bytesw/bytebot/etl/services/DeleteSensMessageService.java
0 → 100644
View file @
8868b12a
package
com
.
bytesw
.
bytebot
.
etl
.
services
;
import
com.bytesw.bytebot.etl.batch.beans.DeleteDataSensRegistryBean
;
import
com.bytesw.bytebot.etl.dao.DeleteDataSensibleControlRepository
;
import
com.bytesw.bytebot.service.provider.TwilioService
;
import
com.bytesw.xdf.exception.NotFoundException
;
import
lombok.extern.log4j.Log4j2
;
import
org.springframework.stereotype.Service
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
@Service
@Log4j2
public
class
DeleteSensMessageService
{
@Autowired
private
TwilioService
twilioService
;
@Autowired
DeleteDataSensibleControlRepository
deleteDataSensibleControlRepository
;
public
List
<
DeleteDataSensRegistryBean
>
deleteMessage
(
Long
agentId
,
String
SmsMessage
)
throws
Exception
{
List
<
DeleteDataSensRegistryBean
>
deleteMessages
=
new
ArrayList
<
DeleteDataSensRegistryBean
>();
Map
<
String
,
Object
>
data
=
new
HashMap
<>();
Map
<
String
,
Object
>
params
=
new
HashMap
<>();
params
.
put
(
"agent_id"
,
agentId
.
intValue
());
try
{
Map
<
String
,
Object
>
result
=
new
HashMap
<>();
data
=
twilioService
.
generateInfo
(
SmsMessage
,
params
);
log
.
debug
(
"RESPUESTA: "
+
data
);
DeleteDataSensRegistryBean
registry
=
new
DeleteDataSensRegistryBean
();
if
(
data
.
get
(
"status"
)
!=
null
){
}
}
catch
(
NotFoundException
e
){
log
.
debug
(
e
);
log
.
debug
(
"Imagen no encontrada"
);
}
catch
(
Exception
e
){
log
.
debug
(
e
);
log
.
debug
(
"Error consumiento servicio de Proveedor"
);
}
return
deleteMessages
;
}
}
src/main/java/com/bytesw/bytebot/etl/services/ProcessMessageService.java
View file @
8868b12a
...
@@ -2,6 +2,7 @@ package com.bytesw.bytebot.etl.services;
...
@@ -2,6 +2,7 @@ package com.bytesw.bytebot.etl.services;
import
com.bytesw.bytebot.etl.beans.ProcessMessageResult
;
import
com.bytesw.bytebot.etl.beans.ProcessMessageResult
;
import
com.bytesw.bytebot.etl.dao.EventHistoryRepository
;
import
com.bytesw.bytebot.etl.dao.EventHistoryRepository
;
import
com.bytesw.bytebot.etl.dao.DeleteDataSensibleControlRepository
;
import
com.bytesw.bytebot.etl.enums.EventTypeEnum
;
import
com.bytesw.bytebot.etl.enums.EventTypeEnum
;
import
com.bytesw.bytebot.etl.model.EventHistory
;
import
com.bytesw.bytebot.etl.model.EventHistory
;
import
com.bytesw.bytebot.etl.utils.JsonUtils
;
import
com.bytesw.bytebot.etl.utils.JsonUtils
;
...
@@ -19,15 +20,26 @@ public class ProcessMessageService {
...
@@ -19,15 +20,26 @@ public class ProcessMessageService {
@Autowired
@Autowired
private
EventHistoryRepository
eventHistoryRepository
;
private
EventHistoryRepository
eventHistoryRepository
;
@Autowired
private
DeleteDataSensibleControlRepository
deleteDataSensibleControlRepository
;
public
void
saveHistory
(
Long
id
,
String
senderId
)
{
public
void
saveHistory
(
Long
id
,
String
senderId
)
{
EventHistory
eventHistory
=
new
EventHistory
();
EventHistory
eventHistory
=
new
EventHistory
();
eventHistory
.
setDate
(
OffsetDateTime
.
now
());
eventHistory
.
setDate
(
OffsetDateTime
.
now
());
eventHistory
.
setEventId
(
id
);
eventHistory
.
setEventId
(
id
);
eventHistory
.
setSenderId
(
senderId
);
eventHistory
.
setSenderId
(
senderId
);
eventHistoryRepository
.
save
(
eventHistory
);
eventHistoryRepository
.
save
(
eventHistory
);
}
}
/*public void saveDataSensControl(Long agentId, Timestamp date, Long eventId){
DeleteDataSensibleControl deleteDataSensibleControl = new DeleteDataSensibleControl();
deleteDataSensibleControl.setAgentId(agentId);
deleteDataSensibleControl.setDate(date);
deleteDataSensibleControl.setEventId(eventId);
deleteDataSensibleControlRepository.save(deleteDataSensibleControl);
}*/
public
ProcessMessageResult
processMessage
(
String
json
,
String
senderId
)
throws
Exception
{
public
ProcessMessageResult
processMessage
(
String
json
,
String
senderId
)
throws
Exception
{
ProcessMessageResult
result
=
new
ProcessMessageResult
();
ProcessMessageResult
result
=
new
ProcessMessageResult
();
log
.
debug
(
json
);
log
.
debug
(
json
);
...
...
src/main/java/com/bytesw/bytebot/jdbc/DeleteDataSensJDBCRepository.java
0 → 100644
View file @
8868b12a
package
com
.
bytesw
.
bytebot
.
jdbc
;
import
com.bytesw.bytebot.etl.batch.beans.DeleteDataSensBean
;
import
com.bytesw.bytebot.etl.batch.beans.DeleteDataSensControlBean
;
import
org.apache.ibatis.session.SqlSession
;
import
org.apache.ibatis.session.SqlSessionFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.stereotype.Component
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
@Component
public
class
DeleteDataSensJDBCRepository
{
@Autowired
@Qualifier
(
"sqlSessionFactory"
)
private
SqlSessionFactory
sqlSessionFactory
;
public
List
<
DeleteDataSensBean
>
getListAgentChannel
(
String
status
,
String
channel
){
SqlSession
session
=
sqlSessionFactory
.
openSession
();
try
{
Map
<
String
,
Object
>
params
=
new
HashMap
<>();
params
.
put
(
"status"
,
status
);
params
.
put
(
"channel"
,
channel
);
return
session
.
selectList
(
"com.bytesw.bytebot.dao.jdbc.ETLDataSensibleMapper.getAgentChannel"
,
params
);
}
finally
{
session
.
close
();
}
}
public
DeleteDataSensControlBean
getControl
(
Long
id
){
SqlSession
session
=
sqlSessionFactory
.
openSession
();
try
{
Map
<
String
,
Object
>
params
=
new
HashMap
<>();
params
.
put
(
"agenId"
,
id
);
return
session
.
selectOne
(
"com.bytesw.bytebot.dao.jdbc.ETLDataSensibleMapper.getControl"
,
params
);
}
finally
{
session
.
close
();
}
}
public
List
<
String
>
getIntentByAgent
(
String
sensible
,
Long
id
){
SqlSession
session
=
sqlSessionFactory
.
openSession
();
try
{
Map
<
String
,
Object
>
params
=
new
HashMap
<>();
params
.
put
(
"sensible"
,
sensible
);
params
.
put
(
"agenId"
,
id
);
return
session
.
selectList
(
"com.bytesw.bytebot.dao.jdbc.ETLDataSensibleMapper.getIntentByAgent"
,
params
);
}
finally
{
session
.
close
();
}
}
}
src/main/java/com/bytesw/bytebot/model/Agent.java
View file @
8868b12a
...
@@ -45,6 +45,9 @@ public class Agent implements Serializable {
...
@@ -45,6 +45,9 @@ public class Agent implements Serializable {
@Column
(
name
=
"agen_tzone"
)
@Column
(
name
=
"agen_tzone"
)
private
String
timezone
;
private
String
timezone
;
@Column
(
name
=
"agen_delete_period"
)
private
String
period
;
@Lob
@Lob
@Type
(
type
=
"org.hibernate.type.TextType"
)
@Type
(
type
=
"org.hibernate.type.TextType"
)
@Basic
(
fetch
=
FetchType
.
LAZY
)
@Basic
(
fetch
=
FetchType
.
LAZY
)
...
...
src/main/java/com/bytesw/bytebot/model/enums/AgentParameterEnum.java
View file @
8868b12a
...
@@ -8,7 +8,8 @@ import java.util.Map;
...
@@ -8,7 +8,8 @@ import java.util.Map;
@Getter
@Getter
public
enum
AgentParameterEnum
{
public
enum
AgentParameterEnum
{
ACCESS_ID
(
"account-identifier"
),
ACCESS_ID
(
"account-identifier"
),
ACCESS_TOKEN
(
"authentication-token"
);
ACCESS_TOKEN
(
"authentication-token"
),
ACCESS_TWILIO
(
"twillio-number"
);
private
static
final
Map
<
String
,
AgentParameterEnum
>
map
=
new
HashMap
<>();
private
static
final
Map
<
String
,
AgentParameterEnum
>
map
=
new
HashMap
<>();
...
...
src/main/resources/config/mappers/etl/mysql/DataSensibleMapper.xml
0 → 100644
View file @
8868b12a
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper
namespace=
"com.bytesw.bytebot.dao.jdbc.ETLDataSensibleMapper"
>
<!-- In Config XML file -->
<cache
readOnly=
"true"
></cache>
<select
id=
"getAgentChannel"
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_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}
</select>
<select
id=
"getControl"
resultType=
"DeleteControl"
flushCache=
"true"
>
SELECT dsmc_id as id,
agent_id as agentId,
dsmc_date as dateDelete,
evnt_id as eventId
FROM avb_delete_sens_msg_control
WHERE agent_id=#{agenId}
</select>
<select
id=
"getIntentByAgent"
resultType=
"String"
flushCache=
"true"
>
SELECT
inten_ident as intent
FROM avb_intent
WHERE intent_is_sensible = #{sensible} AND agen_id = #{agenId}
</select>
</mapper>
src/main/resources/config/mappers/etl/postgres/DataSensibleMapper.xml
0 → 100644
View file @
8868b12a
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper
namespace=
"com.bytesw.bytebot.dao.jdbc.ETLDataSensibleMapper"
>
<!-- In Config XML file -->
<cache
readOnly=
"true"
></cache>
<select
id=
"getAgentChannel"
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_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}
</select>
<select
id=
"getControl"
resultType=
"DeleteControl"
flushCache=
"true"
>
SELECT dsmc_id as id,
agent_id as agentId,
dsmc_date as dateDelete,
evnt_id as eventId
FROM avb_delete_sens_msg_control
WHERE agent_id=#{agenId}
</select>
<select
id=
"getIntentByAgent"
resultType=
"String"
flushCache=
"true"
>
SELECT
inten_ident as intent
FROM avb_intent
WHERE intent_is_sensible = #{sensible} AND agen_id = #{agenId}
</select>
</mapper>
src/main/resources/mybatis-config.xml
View file @
8868b12a
...
@@ -13,6 +13,9 @@
...
@@ -13,6 +13,9 @@
<typeAlias
type=
"com.bytesw.bytebot.bean.DeploymentChannelParamValueBean"
alias=
"DeploymentChannelParamValue"
/>
<typeAlias
type=
"com.bytesw.bytebot.bean.DeploymentChannelParamValueBean"
alias=
"DeploymentChannelParamValue"
/>
<typeAlias
type=
"com.bytesw.bytebot.bean.SessionByClientBean"
alias=
"SessionByClient"
/>
<typeAlias
type=
"com.bytesw.bytebot.bean.SessionByClientBean"
alias=
"SessionByClient"
/>
<typeAlias
type=
"com.bytesw.bytebot.etl.beans.SessionBean"
alias=
"Session"
/>
<typeAlias
type=
"com.bytesw.bytebot.etl.beans.SessionBean"
alias=
"Session"
/>
<typeAlias
type=
"com.bytesw.bytebot.etl.batch.beans.DeleteDataSensBean"
alias=
"ChannelByAgent"
/>
<typeAlias
type=
"com.bytesw.bytebot.etl.batch.beans.DeleteDataSensControlBean"
alias=
"DeleteControl"
/>
</typeAliases>
</typeAliases>
<mappers>
<mappers>
...
@@ -26,6 +29,7 @@
...
@@ -26,6 +29,7 @@
<mapper
resource=
"config/mappers/etl/${database-type-xdf}/SessionMapper.xml"
/>
<mapper
resource=
"config/mappers/etl/${database-type-xdf}/SessionMapper.xml"
/>
<mapper
resource=
"config/mappers/etl/${database-type-xdf}/MessageMapper.xml"
/>
<mapper
resource=
"config/mappers/etl/${database-type-xdf}/MessageMapper.xml"
/>
<mapper
resource=
"config/mappers/etl/${database-type-xdf}/ResponseMapper.xml"
/>
<mapper
resource=
"config/mappers/etl/${database-type-xdf}/ResponseMapper.xml"
/>
<mapper
resource=
"config/mappers/etl/${database-type-xdf}/DataSensibleMapper.xml"
/>
</mappers>
</mappers>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment