Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
trismegisto-services
Overview
Overview
Details
Activity
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
Mauro Paolo Josue Zuñiga Mallqui
trismegisto-services
Commits
f5ffd3fc
Commit
f5ffd3fc
authored
Jan 20, 2025
by
Mauro Paolo Josue Zuñiga Mallqui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[ADÐ] NUEVO CORREO TRISMEGISTO.LOGISTICA AGREGADO
parent
b21c5c8b
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
41 additions
and
18 deletions
+41
-18
DriveApi.java
.../java/web/multitask/trismegistoservices/api/DriveApi.java
+1
-1
EmailApi.java
.../java/web/multitask/trismegistoservices/api/EmailApi.java
+1
-1
GoogleConfig.java
...eb/multitask/trismegistoservices/config/GoogleConfig.java
+35
-14
GmailService.java
...ask/trismegistoservices/services/google/GmailService.java
+4
-2
oAuth2_logistica.json
src/main/resources/tokens/oAuth2_logistica.json
+0
-0
No files found.
src/main/java/web/multitask/trismegistoservices/api/DriveApi.java
View file @
f5ffd3fc
...
...
@@ -33,7 +33,7 @@ public class DriveApi {
response
.
put
(
"status"
,
false
);
response
.
put
(
"message"
,
"No se pudo subir el archivo,"
+
" existe multiples razones por las cuales esto puede ocurrir,"
+
" por favor verifique que el archivo no sea muy grande
o que el formato sea correcto
"
);
" por favor verifique que el archivo no sea muy grande
, que el formato sea correcto o se tenga permiso en la carpeta
"
);
return
ResponseEntity
.
badRequest
().
body
(
response
.
toMap
());
}
else
{
response
.
put
(
"status"
,
true
);
...
...
src/main/java/web/multitask/trismegistoservices/api/EmailApi.java
View file @
f5ffd3fc
...
...
@@ -25,7 +25,7 @@
public
ResponseEntity
<?>
full
(
@ModelAttribute
GmailRequest
request
)
{
try
{
MimeMessage
message
=
emailService
.
htmlMessage
(
request
);
JSONObject
response
=
emailService
.
send
(
message
);
JSONObject
response
=
emailService
.
send
(
message
,
request
.
getFrom
()
);
return
ResponseEntity
.
ok
(
response
.
toMap
());
}
catch
(
Exception
e
)
{
return
ResponseEntity
.
internalServerError
().
body
(
new
JSONObject
().
put
(
"message"
,
e
.
getMessage
()).
put
(
"status"
,
false
).
toMap
());
...
...
src/main/java/web/multitask/trismegistoservices/config/GoogleConfig.java
View file @
f5ffd3fc
...
...
@@ -25,12 +25,13 @@ import com.google.auth.http.HttpCredentialsAdapter;
import
com.google.auth.oauth2.GoogleCredentials
;
import
javax.annotation.PostConstruct
;
import
javax.mail.Address
;
@Configuration
public
class
GoogleConfig
{
private
static
final
JsonFactory
JSON_FACTORY
=
GsonFactory
.
getDefaultInstance
();
private
static
final
String
OAUTH2
=
"/oAuth2
.json"
;
// private static final String OAUTH2 = "/oAuth2_planilla
.json";
private
static
final
String
CREDENTIALS_FOLDER_PATH
=
"/tokens"
;
private
final
String
APPLICATION_NAME
=
"FullService Application"
;
private
String
refresh_token_gmail
=
null
;
...
...
@@ -40,22 +41,11 @@ public class GoogleConfig {
@PostConstruct
public
void
getGoogleCredentials
()
{
try
{
InputStream
in
=
GoogleConfig
.
class
.
getResourceAsStream
(
CREDENTIALS_FOLDER_PATH
+
OAUTH2
);
if
(
in
==
null
)
throw
new
FileNotFoundException
(
"Resource not found: "
+
CREDENTIALS_FOLDER_PATH
+
OAUTH2
);
GoogleClientSecrets
clientSecrets
=
GoogleClientSecrets
.
load
(
JSON_FACTORY
,
new
InputStreamReader
(
in
));
client_id
=
clientSecrets
.
getDetails
().
getClientId
();
client_secret
=
clientSecrets
.
getDetails
().
getClientSecret
();
refresh_token_gmail
=
clientSecrets
.
getDetails
().
get
(
"gmail_refresh_token"
).
toString
();
refresh_token_drive
=
clientSecrets
.
getDetails
().
get
(
"drive_refresh_token"
).
toString
();
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
"Error: "
+
e
);
}
}
public
Drive
getDrive
()
{
try
{
getCredentials
(
"/oAuth2_planilla.json"
);
NetHttpTransport
HTTP_TRANSPORT
=
GoogleNetHttpTransport
.
newTrustedTransport
();
Credential
authorize
=
new
GoogleCredential
.
Builder
().
setTransport
(
GoogleNetHttpTransport
.
newTrustedTransport
())
.
setJsonFactory
(
JSON_FACTORY
)
...
...
@@ -71,8 +61,18 @@ public class GoogleConfig {
}
}
public
Gmail
getGmail
()
{
public
Gmail
getGmail
(
String
from
)
{
try
{
switch
(
from
)
{
case
"trismegisto.planilla@sacooliveros.edu.pe"
:
getCredentials
(
"/oAuth2_planilla.json"
);
break
;
case
"trismegisto.logistica@sacooliveros.edu.pe"
:
getCredentials
(
"/oAuth2_logistica.json"
);
break
;
}
NetHttpTransport
HTTP_TRANSPORT
=
GoogleNetHttpTransport
.
newTrustedTransport
();
Credential
authorize
=
new
GoogleCredential
.
Builder
().
setTransport
(
GoogleNetHttpTransport
.
newTrustedTransport
())
.
setJsonFactory
(
JSON_FACTORY
)
...
...
@@ -88,6 +88,27 @@ public class GoogleConfig {
}
}
private
void
getCredentials
(
String
Path
)
{
try
{
InputStream
in
=
GoogleConfig
.
class
.
getResourceAsStream
(
CREDENTIALS_FOLDER_PATH
+
Path
);
if
(
in
==
null
)
throw
new
FileNotFoundException
(
"Resource not found: "
+
CREDENTIALS_FOLDER_PATH
+
Path
);
GoogleClientSecrets
clientSecrets
=
GoogleClientSecrets
.
load
(
JSON_FACTORY
,
new
InputStreamReader
(
in
));
client_id
=
clientSecrets
.
getDetails
().
getClientId
();
client_secret
=
clientSecrets
.
getDetails
().
getClientSecret
();
if
(
clientSecrets
.
getDetails
().
get
(
"gmail_refresh_token"
)
!=
null
){
refresh_token_gmail
=
clientSecrets
.
getDetails
().
get
(
"gmail_refresh_token"
).
toString
();
}
if
(
clientSecrets
.
getDetails
().
get
(
"drive_refresh_token"
)
!=
null
){
refresh_token_drive
=
clientSecrets
.
getDetails
().
get
(
"drive_refresh_token"
).
toString
();
}
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
"Error: "
+
e
);
}
}
public
String
getAccessToken
(
String
refresh_token
)
{
try
{
...
...
src/main/java/web/multitask/trismegistoservices/services/google/GmailService.java
View file @
f5ffd3fc
...
...
@@ -4,6 +4,8 @@ package web.multitask.trismegistoservices.services.google;
import
java.io.FileOutputStream
;
import
java.io.UnsupportedEncodingException
;
import
com.google.api.client.util.Base64
;
import
java.util.Arrays
;
import
java.util.Objects
;
import
java.util.Properties
;
import
java.util.stream.Collectors
;
...
...
@@ -93,14 +95,14 @@ package web.multitask.trismegistoservices.services.google;
}
}
public
JSONObject
send
(
MimeMessage
email
)
{
public
JSONObject
send
(
MimeMessage
email
,
String
from
)
{
try
{
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
();
email
.
writeTo
(
baos
);
String
encodedEmail
=
Base64
.
encodeBase64URLSafeString
(
baos
.
toByteArray
());
Message
message
=
new
Message
();
message
.
setRaw
(
encodedEmail
);
System
.
out
.
println
(
googleConfig
.
getGmail
().
users
().
messages
().
send
(
"me"
,
message
).
execute
());
System
.
out
.
println
(
googleConfig
.
getGmail
(
from
).
users
().
messages
().
send
(
"me"
,
message
).
execute
());
return
new
JSONObject
().
put
(
"message"
,
"Email enviado correctamente"
).
put
(
"status"
,
true
);
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
...
...
src/main/resources/tokens/oAuth2_logistica.json
0 → 100644
View file @
f5ffd3fc
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