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
a5e47903
Commit
a5e47903
authored
Nov 26, 2021
by
Cristian Aguirre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update ETL Delete Sensible Data
parent
b0d4957a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
40 additions
and
43 deletions
+40
-43
ScheduleService.java
...com/bytesw/bytebot/etl/batch/service/ScheduleService.java
+3
-3
DataSensibleJPAWriter.java
...ytesw/bytebot/etl/batch/writer/DataSensibleJPAWriter.java
+29
-31
TwilioService.java
...va/com/bytesw/bytebot/service/provider/TwilioService.java
+5
-6
application.yml
src/main/resources/application.yml
+3
-3
No files found.
src/main/java/com/bytesw/bytebot/etl/batch/service/ScheduleService.java
View file @
a5e47903
...
...
@@ -21,6 +21,7 @@ import com.bytesw.bytebot.repository.AgentRepository;
import
com.bytesw.xdf.multitenant.core.ThreadLocalStorage
;
import
com.google.gson.Gson
;
import
lombok.extern.log4j.Log4j2
;
import
org.apache.commons.dbcp.BasicDataSource
;
import
org.springframework.batch.core.*
;
import
org.springframework.batch.core.configuration.annotation.JobBuilderFactory
;
import
org.springframework.batch.core.configuration.annotation.StepBuilderFactory
;
...
...
@@ -38,6 +39,7 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import
org.springframework.scheduling.support.CronTrigger
;
import
org.springframework.stereotype.Service
;
import
javax.sql.DataSource
;
import
java.time.Duration
;
import
java.time.OffsetDateTime
;
import
java.time.ZoneId
;
...
...
@@ -248,8 +250,7 @@ public class ScheduleService implements SchedulingConfigurer {
if
(
differenceTime
<
data
.
getDeletePeriod
())
{
log
.
info
(
"Agente "
+
data
.
getValue
()
+
" aun no cumple con el periodo de espera."
);
// throw new RuntimeException("Time is not yet fulfilled");
return
null
;
id
=
null
;
}
else
{
id
=
control
.
getEventId
();
}
...
...
@@ -258,7 +259,6 @@ public class ScheduleService implements SchedulingConfigurer {
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
);
}
...
...
src/main/java/com/bytesw/bytebot/etl/batch/writer/DataSensibleJPAWriter.java
View file @
a5e47903
...
...
@@ -13,6 +13,7 @@ import com.bytesw.bytebot.etl.model.Intent;
import
com.bytesw.bytebot.etl.utils.JsonUtils
;
import
com.bytesw.xdf.multitenant.core.ThreadLocalStorage
;
import
com.bytesw.bytebot.etl.services.DeleteSensMessageService
;
import
com.jayway.jsonpath.PathNotFoundException
;
import
lombok.Getter
;
import
lombok.Setter
;
import
lombok.extern.log4j.Log4j2
;
...
...
@@ -64,11 +65,15 @@ public class DataSensibleJPAWriter implements ItemWriter<DynaBean>, StepExecutio
Long
id
=
Long
.
parseLong
(
dynaBean
.
get
(
"id"
).
toString
());
String
json
=
(
String
)
dynaBean
.
get
(
"data"
);
String
event
=
(
String
)
JsonUtils
.
getFieldFromJson
(
json
,
"$.event"
);
String
sender_id
;
// Transform present Date
String
presentDate
=
OffsetDateTime
.
now
().
toString
().
replace
(
'T'
,
' '
);
String
timeZone
=
presentDate
.
substring
(
presentDate
.
length
()
-
6
);
presentDate
=
presentDate
.
replace
(
timeZone
,
""
);
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
.
contains
(
intent
))
{
String
SmSMessageSid
=
(
String
)
JsonUtils
.
getFieldFromJson
(
json
,
"$.metadata.SmsMessageSid"
);
...
...
@@ -76,19 +81,16 @@ public class DataSensibleJPAWriter implements ItemWriter<DynaBean>, StepExecutio
if
(!
intenId
.
isPresent
())
{
throw
new
Exception
(
"Intent no esta presente"
);
}
// Transform present Date
String
presentDate
=
OffsetDateTime
.
now
().
toString
().
replace
(
'T'
,
' '
);
String
timeZone
=
presentDate
.
substring
(
presentDate
.
length
()
-
6
);
presentDate
=
presentDate
.
replace
(
timeZone
,
""
);
String
senderId
=
(
String
)
JsonUtils
.
getFieldFromJson
(
json
,
"$.metadata.sender_id"
);
if
(
senderId
.
isEmpty
())
{
senderId
=
(
String
)
JsonUtils
.
getFieldFromJson
(
json
,
"$.sender_id"
);
try
{
sender_id
=
(
String
)
JsonUtils
.
getFieldFromJson
(
json
,
"$.sender_id"
);
log
.
info
(
sender_id
);
}
catch
(
Exception
e
){
log
.
info
(
e
.
getMessage
());
sender_id
=
(
String
)
JsonUtils
.
getFieldFromJson
(
json
,
"$.metadata.sender_id"
);
}
List
<
DeleteDataSensRegistryBean
>
deleteSensibleBean
=
service
.
deleteMessage
(
agent
.
getAgenId
()
,
SmSMessageSid
,
intenId
.
get
().
getId
(),
sender
I
d
);
,
SmSMessageSid
,
intenId
.
get
().
getId
(),
sender
_i
d
);
for
(
DeleteDataSensRegistryBean
registry
:
deleteSensibleBean
)
{
DeleteDataSensibleLog
reg
=
new
DeleteDataSensibleLog
();
...
...
@@ -99,30 +101,26 @@ public class DataSensibleJPAWriter implements ItemWriter<DynaBean>, StepExecutio
reg
.
setDate
(
Timestamp
.
valueOf
(
presentDate
));
deleteDataSensibleLogRepository
.
save
(
reg
);
}
DeleteDataSensibleControl
control
=
new
DeleteDataSensibleControl
();
Optional
<
DeleteDataSensibleControl
>
controlBd
=
deleteDataSensibleControlRepository
.
findEventIdByAgentId
(
agent
.
getAgenId
());
if
(
controlBd
.
isPresent
())
{
// Update
control
.
setId
(
controlBd
.
get
().
getId
());
control
.
setAgentId
(
agent
.
getAgenId
());
control
.
setEventId
(
id
);
control
.
setDate
(
Timestamp
.
valueOf
(
presentDate
));
deleteDataSensibleControlRepository
.
save
(
control
);
}
else
{
// Create
control
.
setAgentId
(
agent
.
getAgenId
());
control
.
setEventId
(
id
);
control
.
setDate
(
Timestamp
.
valueOf
(
presentDate
));
deleteDataSensibleControlRepository
.
save
(
control
);
}
}
}
}
DeleteDataSensibleControl
control
=
new
DeleteDataSensibleControl
();
Optional
<
DeleteDataSensibleControl
>
controlBd
=
deleteDataSensibleControlRepository
.
findEventIdByAgentId
(
agent
.
getAgenId
());
if
(
controlBd
.
isPresent
())
{
// Update
control
.
setId
(
controlBd
.
get
().
getId
());
control
.
setAgentId
(
agent
.
getAgenId
());
control
.
setEventId
(
id
);
control
.
setDate
(
Timestamp
.
valueOf
(
presentDate
));
deleteDataSensibleControlRepository
.
save
(
control
);
}
else
{
// Create
control
.
setAgentId
(
agent
.
getAgenId
());
control
.
setEventId
(
id
);
control
.
setDate
(
Timestamp
.
valueOf
(
presentDate
));
deleteDataSensibleControlRepository
.
save
(
control
);
}
}
//service.saveDataSensControl(eventBean.getId(), eventBean.getSenderId());
}
@Override
...
...
src/main/java/com/bytesw/bytebot/service/provider/TwilioService.java
View file @
a5e47903
...
...
@@ -63,14 +63,12 @@ public class TwilioService extends ProviderService{
exist_agent
=
true
;
}
}
log
.
debug
(
"EXISTE AGENT: "
+
exist_agent
);
if
(!
exist_agent
){
log
.
info
(
"No existe un agente con el ID especificado"
);
throw
new
Exception
(
"No se encontró un agente con canales deployados con dicho ID"
);
}
String
[]
images_droped
=
new
String
[
MAX_LIMIT
];
Twilio
.
init
(
sid
,
token
);
TwilioRestClient
twilio_client
=
Twilio
.
getRestClient
();
ResourceSet
<
Media
>
media
=
Media
.
reader
(
SmsId
).
limit
(
MAX_LIMIT
).
read
();
int
cont
=
0
;
for
(
Media
record
:
media
)
{
...
...
@@ -80,9 +78,8 @@ public class TwilioService extends ProviderService{
}
if
(
cont
==
0
)
{
log
.
info
(
"No hay imágenes para el mensaje indicado"
);
throw
new
NotFoundException
(
"No se encontraron imágenes para
dicho mensaje"
);
throw
new
NotFoundException
(
"No se encontraron imágenes para
el mensaje "
+
SmsId
);
}
else
{
// data.put("images_droped", Arrays.copyOfRange(images_droped, 0, cont));
for
(
String
image
:
Arrays
.
copyOfRange
(
images_droped
,
0
,
cont
)){
data
.
add
(
image
);
}
...
...
@@ -101,10 +98,12 @@ public class TwilioService extends ProviderService{
throw
new
InternalError
(
"Fallo en la conexión con Twilio API"
);
}
else
{
log
.
info
(
"El mensaje no existe para : "
+
SmsId
+
"\n"
+
e
.
getMessage
());
throw
new
NotFoundException
(
"No se encontr
o el mensaje en el Proveedor"
);
throw
new
NotFoundException
(
"No se encontr
aron imágenes para el mensaje "
+
SmsId
);
}
}
catch
(
NotFoundException
e
){
throw
new
NotFoundException
(
e
.
getMessage
());
}
catch
(
Exception
e
){
throw
new
Exception
(
e
);
throw
new
Exception
(
e
.
getMessage
()
);
}
}
}
src/main/resources/application.yml
View file @
a5e47903
...
...
@@ -26,8 +26,8 @@ management:
application
:
byte-bot
:
batch
:
chunk
:
1
cron
:
0/50
0
* * * * *
chunk
:
1
0
cron
:
0/50 * * * * *
show-side-bar
:
false
test
:
ENC(OEchnTXpIZnCVdPNthgCZBfQjMt1AUS1)
name
:
xdf-example
...
...
@@ -55,7 +55,7 @@ application:
multi-tenant-conf
:
exclude-service
:
/
authorization-service.url
:
http://localhost:17580
security
:
oauth2sso
# none, basic, oauth2sso
security
:
none
# 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
:
...
...
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