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
a7b24dfd
Commit
a7b24dfd
authored
Feb 12, 2024
by
Mauro Paolo Josue Zuñiga Mallqui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[EDIT] SE MODIFICO OPTIMIZARON LAS FUNCIONES DE GENERACION DE EXCEL, AHORA USAN HILOS Y ASYNCRONIA
parent
a251c77e
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
116 additions
and
55 deletions
+116
-55
pom.xml
pom.xml
+5
-0
jboss-deployment-structure.xml
src/main/WEB-INF/ jboss-deployment-structure.xml
+16
-0
AppApplication.java
...ava/web/multitask/trismegistoservices/AppApplication.java
+2
-0
DriveApi.java
.../java/web/multitask/trismegistoservices/api/DriveApi.java
+1
-4
ExecutorConfig.java
.../multitask/trismegistoservices/config/ExecutorConfig.java
+20
-0
GoogleConfig.java
...eb/multitask/trismegistoservices/config/GoogleConfig.java
+4
-5
ExcelService.java
.../multitask/trismegistoservices/services/ExcelService.java
+68
-46
No files found.
pom.xml
View file @
a7b24dfd
...
...
@@ -185,6 +185,11 @@
<artifactId>
google-auth-library-oauth2-http
</artifactId>
<version>
1.3.0
</version>
</dependency>
<dependency>
<groupId>
org.apache.logging.log4j
</groupId>
<artifactId>
log4j-to-slf4j
</artifactId>
<version>
2.20.0
</version>
</dependency>
</dependencies>
<build>
<finalName>
trismegisto-services
</finalName>
...
...
src/main/WEB-INF/ jboss-deployment-structure.xml
0 → 100644
View file @
a7b24dfd
<?xml version="1.0"?>
<jboss-deployment-structure
xmlns=
"urn:jboss:deployment-structure:1.2"
>
<deployment>
<exclusions>
<module
name=
"org.apache.commons.logging"
/>
<module
name=
"org.apache.log4j"
/>
<module
name=
"org.jboss.logging"
/>
<module
name=
"org.jboss.logging.jul-to-slf4j-stub"
/>
<module
name=
"org.jboss.logmanager"
/>
<module
name=
"org.jboss.logmanager.log4j"
/>
<module
name=
"org.slf4j"
/>
<module
name=
"org.slf4j.impl"
/>
</exclusions>
</deployment>
</jboss-deployment-structure>
\ No newline at end of file
src/main/java/web/multitask/trismegistoservices/AppApplication.java
View file @
a7b24dfd
...
...
@@ -2,8 +2,10 @@ package web.multitask.trismegistoservices;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.scheduling.annotation.EnableAsync
;
@SpringBootApplication
@EnableAsync
public
class
AppApplication
{
public
static
void
main
(
String
[]
args
)
{
...
...
src/main/java/web/multitask/trismegistoservices/api/DriveApi.java
View file @
a7b24dfd
package
web
.
multitask
.
trismegistoservices
.
api
;
import
kotlin.ParameterName
;
import
lombok.AllArgsConstructor
;
import
org.json.JSONObject
;
import
org.springframework.http.MediaType
;
...
...
@@ -9,10 +9,7 @@ import org.springframework.web.bind.annotation.*;
import
org.springframework.web.multipart.MultipartFile
;
import
web.multitask.trismegistoservices.model.DriveRequest
;
import
web.multitask.trismegistoservices.services.DriveService
;
import
javax.annotation.Nullable
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
@RestController
@CrossOrigin
(
origins
=
"*"
)
...
...
src/main/java/web/multitask/trismegistoservices/config/ExecutorConfig.java
0 → 100644
View file @
a7b24dfd
package
web
.
multitask
.
trismegistoservices
.
config
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
;
@Configuration
public
class
ExecutorConfig
{
@Bean
public
ThreadPoolTaskExecutor
threadPoolTaskExecutor
()
{
ThreadPoolTaskExecutor
executor
=
new
ThreadPoolTaskExecutor
();
executor
.
setCorePoolSize
(
100
);
executor
.
setMaxPoolSize
(
100
);
executor
.
setQueueCapacity
(
1000
);
executor
.
setThreadNamePrefix
(
"ts-executor-"
);
executor
.
initialize
();
return
executor
;
}
}
\ No newline at end of file
src/main/java/web/multitask/trismegistoservices/config/GoogleConfig.java
View file @
a7b24dfd
...
...
@@ -30,11 +30,10 @@ public class GoogleConfig {
String
APPLICATION_NAME
=
"FullService Application"
;
JsonFactory
JSON_FACTORY
=
GsonFactory
.
getDefaultInstance
();
final
NetHttpTransport
HTTP_TRANSPORT
=
GoogleNetHttpTransport
.
newTrustedTransport
();
Drive
service
=
new
Drive
.
Builder
(
HTTP_TRANSPORT
,
JSON_FACTORY
,
return
new
Drive
.
Builder
(
HTTP_TRANSPORT
,
JSON_FACTORY
,
new
HttpCredentialsAdapter
(
getCredentials
(
HTTP_TRANSPORT
)))
.
setApplicationName
(
APPLICATION_NAME
)
.
build
();
return
service
;
}
catch
(
GeneralSecurityException
|
IOException
e
)
{
System
.
out
.
println
(
"Error: "
+
e
);
return
null
;
...
...
@@ -45,7 +44,6 @@ public class GoogleConfig {
throws
IOException
{
InputStream
in
=
GoogleConfig
.
class
.
getResourceAsStream
(
CREDENTIALS_FOLDER_PATH
+
CREDENTIALS_FILE_PATH
);
if
(
in
==
null
)
throw
new
FileNotFoundException
(
"Resource not found: "
+
CREDENTIALS_FOLDER_PATH
+
CREDENTIALS_FILE_PATH
);
GoogleCredentials
clientSecrets
=
GoogleCredentials
.
fromStream
(
in
).
createScoped
(
SCOPES
);
return
clientSecrets
;
return
GoogleCredentials
.
fromStream
(
in
).
createScoped
(
SCOPES
);
}
}
}
\ No newline at end of file
src/main/java/web/multitask/trismegistoservices/services/ExcelService.java
View file @
a7b24dfd
...
...
@@ -2,11 +2,11 @@ package web.multitask.trismegistoservices.services;
import
java.awt.Color
;
import
java.io.ByteArrayOutputStream
;
import
org.apache.poi.ss.usermodel.BorderStyle
;
import
org.apache.poi.ss.usermodel.FillPatternType
;
import
org.apache.poi.ss.usermodel.Fon
t
;
import
org.apache.poi.ss.usermodel.HorizontalAlignment
;
import
org.apache.poi.ss.usermodel.
VerticalAlignment
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.Lis
t
;
import
java.util.concurrent.CompletableFuture
;
import
org.apache.poi.ss.usermodel.
*
;
import
org.apache.poi.xssf.usermodel.XSSFCell
;
import
org.apache.poi.xssf.usermodel.XSSFCellStyle
;
import
org.apache.poi.xssf.usermodel.XSSFColor
;
...
...
@@ -18,10 +18,14 @@ import org.json.JSONArray;
import
org.json.JSONObject
;
import
org.springframework.core.io.ByteArrayResource
;
import
org.springframework.core.io.Resource
;
import
org.springframework.scheduling.annotation.Async
;
import
org.springframework.stereotype.Service
;
@Service
public
class
ExcelService
{
public
class
ExcelService
{
List
<
String
>
stylesSaved
=
new
ArrayList
<>();
List
<
XSSFCellStyle
>
styleObjectsSaved
=
new
ArrayList
<>();
public
byte
[]
generateExcel
(
JSONObject
json
)
{
ByteArrayOutputStream
outByteStream
=
new
ByteArrayOutputStream
();
...
...
@@ -37,62 +41,69 @@ public class ExcelService {
}
}
private
void
createSheet
(
XSSFWorkbook
workbook
,
JSONObject
json
)
{
@Async
public
void
createSheet
(
XSSFWorkbook
workbook
,
JSONObject
json
)
{
styleObjectsSaved
.
clear
();
stylesSaved
.
clear
();
List
<
CompletableFuture
<
Boolean
>>
results
=
new
ArrayList
<>();
if
(
json
.
optJSONArray
(
"sheetArray"
,
new
JSONArray
()).
isEmpty
())
{
XSSFSheet
sheet
=
workbook
.
createSheet
(
json
.
optString
(
"sheet_name"
,
"no_name"
));
buildSheet
(
workbook
,
sheet
,
json
);
}
else
{
JSONArray
sheetArray
=
json
.
optJSONArray
(
"sheetArray"
,
new
JSONArray
());
for
(
int
i
=
0
;
i
<
sheetArray
.
length
();
i
++){
JSONObject
sheetObject
=
sheetArray
.
optJSONObject
(
i
);
XSSFSheet
sheet
=
workbook
.
createSheet
(
sheetObject
.
optString
(
"sheet_name"
,
"no_name"
));
buildSheet
(
workbook
,
sheet
,
sheetObject
);
}
sheetArray
.
toList
().
stream
().
parallel
().
forEach
(
sheetObject
->
{
HashMap
<
String
,
Object
>
sheetMap
=
(
HashMap
<
String
,
Object
>)
sheetObject
;
JSONObject
jsonObject
=
new
JSONObject
(
sheetMap
);
XSSFSheet
sheet
=
workbook
.
createSheet
(
jsonObject
.
optString
(
"sheet_name"
,
"no_name"
));
JSONArray
identifiers
=
jsonObject
.
getJSONArray
(
"identifiers"
);
for
(
int
j
=
0
;
j
<
identifiers
.
length
();
j
++)
{
sheet
.
setColumnWidth
(
j
,
16
*
512
);
}
CompletableFuture
<
Boolean
>
result
=
buildSheet
(
workbook
,
sheet
,
jsonObject
);
results
.
add
(
result
);
});
}
}
private
void
buildSheet
(
XSSFWorkbook
workbook
,
XSSFSheet
sheet
,
JSONObject
json
)
{
@Async
public
CompletableFuture
<
Boolean
>
buildSheet
(
XSSFWorkbook
workbook
,
XSSFSheet
sheet
,
JSONObject
json
)
{
final
XSSFCellStyle
defaultStyle
=
createCellStyle
(
workbook
,
new
JSONObject
());
XSSFRow
row
;
XSSFCell
cell
;
XSSFCellStyle
cellStyle
;
JSONArray
identifiers
=
json
.
optJSONArray
(
"identifiers"
,
new
JSONArray
());
JSONArray
data
=
json
.
optJSONArray
(
"data"
,
new
JSONArray
());
JSONArray
styles
=
json
.
optJSONArray
(
"styles"
,
new
JSONArray
());
fillStylesArray
(
styles
,
workbook
,
stylesSaved
,
styleObjectsSaved
);
for
(
int
i
=
0
;
i
<
data
.
length
();
i
++)
{
XSSFRow
row
=
sheet
.
createRow
(
i
);
row
=
sheet
.
createRow
(
i
);
JSONObject
row_data
=
data
.
optJSONObject
(
i
);
for
(
int
j
=
0
;
j
<
identifiers
.
length
();
j
++)
{
XSSFCell
cell
=
row
.
createCell
(
j
);
cell
=
row
.
createCell
(
j
);
JSONArray
styleArray
=
styles
.
optJSONArray
(
i
,
new
JSONArray
());
JSONObject
style
=
styleArray
.
optJSONObject
(
j
,
new
JSONObject
());
if
(
style
.
isEmpty
()){
cell
.
setCellStyle
(
defaultStyle
);
}
else
{
XSSFCellStyle
cellStyle
=
createCellStyle
(
workbook
,
style
);
cell
.
setCellStyle
(
cellStyle
);
}
if
(
row_data
.
get
(
identifiers
.
optString
(
j
,
""
))
instanceof
String
){
cell
.
setCellValue
(
row_data
.
optString
(
identifiers
.
optString
(
j
,
""
),
""
));
cell
.
setCellType
(
org
.
apache
.
poi
.
ss
.
usermodel
.
CellType
.
STRING
);
}
else
if
(
row_data
.
get
(
identifiers
.
optString
(
j
,
""
))
instanceof
Integer
){
cell
.
setCellValue
(
row_data
.
optInt
(
identifiers
.
optString
(
j
,
""
),
0
));
cell
.
setCellType
(
org
.
apache
.
poi
.
ss
.
usermodel
.
CellType
.
NUMERIC
);
}
else
if
(
row_data
.
get
(
identifiers
.
optString
(
j
,
""
))
instanceof
Double
){
cell
.
setCellValue
(
row_data
.
optDouble
(
identifiers
.
optString
(
j
,
""
),
0.0
));
cell
.
setCellType
(
org
.
apache
.
poi
.
ss
.
usermodel
.
CellType
.
NUMERIC
);
}
else
if
(
row_data
.
get
(
identifiers
.
optString
(
j
,
""
))
instanceof
Boolean
){
cell
.
setCellValue
(
row_data
.
optBoolean
(
identifiers
.
optString
(
j
,
""
),
false
));
cell
.
setCellType
(
org
.
apache
.
poi
.
ss
.
usermodel
.
CellType
.
BOOLEAN
);
}
else
{
cell
.
setCellValue
(
row_data
.
optString
(
identifiers
.
optString
(
j
,
""
),
""
));
cell
.
setCellType
(
org
.
apache
.
poi
.
ss
.
usermodel
.
CellType
.
STRING
);
if
(!
stylesSaved
.
contains
(
style
.
toString
())){
stylesSaved
.
add
(
style
.
toString
());
cellStyle
=
createCellStyle
(
workbook
,
style
);
cell
.
setCellStyle
(
cellStyle
);
styleObjectsSaved
.
add
(
cellStyle
);
}
else
{
cell
.
setCellStyle
(
styleObjectsSaved
.
get
(
stylesSaved
.
indexOf
(
style
.
toString
())));
}
}
cell
.
setCellValue
(
row_data
.
optString
(
identifiers
.
optString
(
j
,
""
)));
}
}
for
(
int
i
=
0
;
i
<
identifiers
.
length
();
i
++)
{
sheet
.
autoSizeColumn
(
i
,
true
);
}
return
CompletableFuture
.
completedFuture
(
true
);
}
private
XSSFCellStyle
createCellStyle
(
XSSFWorkbook
workbook
,
JSONObject
styleJson
)
{
...
...
@@ -105,24 +116,20 @@ public class ExcelService {
XSSFCellStyle
style
=
workbook
.
createCellStyle
();
Font
font
=
workbook
.
createFont
();
style
.
setAlignment
(
align
.
equals
(
"center"
)
?
HorizontalAlignment
.
CENTER
:
align
.
equals
(
"left"
)
?
HorizontalAlignment
.
LEFT
:
HorizontalAlignment
.
RIGHT
);
style
.
setWrapText
(
tru
e
);
style
.
setWrapText
(
fals
e
);
style
.
setVerticalAlignment
(
VerticalAlignment
.
CENTER
);
style
.
setFillPattern
(
FillPatternType
.
SOLID_FOREGROUND
);
style
.
setBorderBottom
(
BorderStyle
.
THIN
);
style
.
setBorderTop
(
BorderStyle
.
THIN
);
style
.
setBorderLeft
(
BorderStyle
.
THIN
);
style
.
setBorderRight
(
BorderStyle
.
THIN
);
if
(
border
)
{
style
.
setBorderBottom
(
BorderStyle
.
THIN
);
style
.
setBorderTop
(
BorderStyle
.
THIN
);
style
.
setBorderLeft
(
BorderStyle
.
THIN
);
style
.
setBorderRight
(
BorderStyle
.
THIN
);
style
.
setBorderColor
(
BorderSide
.
BOTTOM
,
getXSSFColor
(
"#333333"
));
style
.
setBorderColor
(
BorderSide
.
TOP
,
getXSSFColor
(
"#333333"
));
style
.
setBorderColor
(
BorderSide
.
LEFT
,
getXSSFColor
(
"#333333"
));
style
.
setBorderColor
(
BorderSide
.
RIGHT
,
getXSSFColor
(
"#333333"
));
}
else
{
style
.
setBorderBottom
(
BorderStyle
.
THIN
);
style
.
setBorderTop
(
BorderStyle
.
THIN
);
style
.
setBorderLeft
(
BorderStyle
.
THIN
);
style
.
setBorderRight
(
BorderStyle
.
THIN
);
style
.
setBorderColor
(
BorderSide
.
BOTTOM
,
getXSSFColor
(
"#aaaaaa"
));
style
.
setBorderColor
(
BorderSide
.
TOP
,
getXSSFColor
(
"#aaaaaa"
));
style
.
setBorderColor
(
BorderSide
.
LEFT
,
getXSSFColor
(
"#aaaaaa"
));
...
...
@@ -162,4 +169,18 @@ public class ExcelService {
}
};
}
public
void
fillStylesArray
(
JSONArray
styles
,
XSSFWorkbook
workbook
,
List
<
String
>
stylesSaved
,
List
<
XSSFCellStyle
>
styleObjectsSaved
)
{
for
(
int
i
=
0
;
i
<
styles
.
length
();
i
++)
{
JSONArray
styleArray
=
styles
.
optJSONArray
(
i
,
new
JSONArray
());
for
(
int
j
=
0
;
j
<
styleArray
.
length
();
j
++)
{
JSONObject
style
=
styleArray
.
optJSONObject
(
j
,
new
JSONObject
());
if
(!
stylesSaved
.
contains
(
style
.
toString
())){
stylesSaved
.
add
(
style
.
toString
());
XSSFCellStyle
cellStyle
=
createCellStyle
(
workbook
,
style
);
styleObjectsSaved
.
add
(
cellStyle
);
}
}
}
}
}
\ No newline at end of file
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