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
fc4d0496
Commit
fc4d0496
authored
Oct 21, 2020
by
Aaron Gutierrez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Se agregó un utilitario para convertir el archivo de excel a csv
parent
7dd9e1b1
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
129 additions
and
14 deletions
+129
-14
pom.xml
pom.xml
+3
-8
AgentService.java
src/main/java/com/bytesw/bytebot/service/AgentService.java
+7
-5
FileConverter.java
src/main/java/com/bytesw/bytebot/service/FileConverter.java
+6
-0
FileManagementService.java
...ava/com/bytesw/bytebot/service/FileManagementService.java
+0
-1
XlsToCsvFileConverter.java
...ava/com/bytesw/bytebot/service/XlsToCsvFileConverter.java
+113
-0
No files found.
pom.xml
View file @
fc4d0496
...
...
@@ -4,18 +4,18 @@
<parent>
<groupId>
com.bytesw.xdf
</groupId>
<artifactId>
byteXDF4Java-arq
</artifactId>
<version>
3.
1.0
</version>
<version>
3.
2.0-SNAPSHOT
</version>
</parent>
<groupId>
com.bytesw.bytebot
</groupId>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
bytebot-service
</artifactId>
<version>
0.0.1-SNAPSHOT
</version>
<version>
1.0.0
</version>
<packaging>
jar
</packaging>
<properties>
<xdf.version>
3.
1.0
</xdf.version>
<xdf.version>
3.
2.0-SNAPSHOT
</xdf.version>
<camel.version>
2.22.0
</camel.version>
<mainclass>
com.bytesw.bytebot.BytebotApplication
</mainclass>
<jacoco.version>
0.8.5
</jacoco.version>
...
...
@@ -422,11 +422,6 @@
<artifactId>
spring-boot-starter-undertow
</artifactId>
<scope>
provided
</scope>
</dependency>
<dependency>
<groupId>
javax.servlet
</groupId>
<artifactId>
javax.servlet-api
</artifactId>
<scope>
provided
</scope>
</dependency>
</dependencies>
<build>
<plugins>
...
...
src/main/java/com/bytesw/bytebot/service/AgentService.java
View file @
fc4d0496
...
...
@@ -4,10 +4,10 @@ import com.bytesw.bytebot.bean.*;
import
com.bytesw.bytebot.model.*
;
import
com.bytesw.bytebot.model.enums.*
;
import
com.bytesw.bytebot.repository.*
;
import
com.bytesw.xdf.config.AppContextManager
;
import
com.bytesw.xdf.sql.beans.Pagination
;
import
lombok.extern.log4j.Log4j2
;
import
org.apache.camel.ProducerTemplate
;
import
org.apache.commons.io.FileUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.PageRequest
;
...
...
@@ -18,8 +18,6 @@ import org.springframework.stereotype.Service;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.io.File
;
import
java.io.IOException
;
import
java.time.LocalDateTime
;
import
java.time.format.DateTimeFormatter
;
import
java.util.*
;
...
...
@@ -452,6 +450,10 @@ public class AgentService extends CustomPaginationService<Agent> {
@Transactional
(
propagation
=
Propagation
.
REQUIRED
)
public
void
synchronizeFiles
(
Long
id
,
String
user
)
{
if
(
AppContextManager
.
getAppContext
()
==
null
)
{
return
;
}
FileConverter
fileConverter
=
(
FileConverter
)
AppContextManager
.
getAppContext
().
getBean
(
"xlsToCsvFileConverter"
);
List
<
FrequentQuestion
>
frequentQuestions
=
frequentQuestionRepository
.
findAllByAgentIdAndStatus
(
id
,
FrequentQuestionStatusEnum
.
PENDING_SYNCHRONIZED
);
...
...
@@ -462,13 +464,13 @@ public class AgentService extends CustomPaginationService<Agent> {
Optional
<
QuestionFile
>
questionFileFound
=
questionFileRepository
.
findByUuid
(
frequentQuestion
.
getUuid
());
if
(
questionFileFound
.
isPresent
())
{
headers
.
put
(
"CamelFileName"
,
questionFileFound
.
get
().
getName
(
));
headers
.
put
(
"CamelFileName"
,
fileConverter
.
getFileName
(
questionFileFound
.
get
().
getName
()
));
// try {
// FileUtils.writeByteArrayToFile(new File("/home/schicoma/Escritorio/" + questionFileFound.get().getName()), questionFileFound.get().getData());
// } catch (IOException e) {
// e.printStackTrace();
// }
producerTemplate
.
sendBodyAndHeaders
(
"direct:transferFile"
,
questionFileFound
.
get
().
getData
(
),
headers
);
producerTemplate
.
sendBodyAndHeaders
(
"direct:transferFile"
,
fileConverter
.
convert
(
questionFileFound
.
get
().
getData
(),
questionFileFound
.
get
().
getName
()
),
headers
);
}
frequentQuestion
.
setStatus
(
FrequentQuestionStatusEnum
.
UPLOADED
);
...
...
src/main/java/com/bytesw/bytebot/service/FileConverter.java
0 → 100644
View file @
fc4d0496
package
com
.
bytesw
.
bytebot
.
service
;
public
interface
FileConverter
{
byte
[]
convert
(
byte
[]
inputFile
,
String
fileName
);
String
getFileName
(
String
fileName
);
}
src/main/java/com/bytesw/bytebot/service/FileManagementService.java
View file @
fc4d0496
...
...
@@ -14,7 +14,6 @@ import com.bytesw.bytebot.repository.QuestionFileRepository;
import
com.bytesw.bytebot.utils.Utilities
;
import
java.io.ByteArrayInputStream
;
import
java.io.IOException
;
import
java.text.SimpleDateFormat
;
import
java.time.LocalDateTime
;
import
java.time.format.DateTimeFormatter
;
import
java.util.ArrayList
;
...
...
src/main/java/com/bytesw/bytebot/service/XlsToCsvFileConverter.java
0 → 100644
View file @
fc4d0496
package
com
.
bytesw
.
bytebot
.
service
;
import
org.apache.commons.io.FilenameUtils
;
import
org.apache.poi.hssf.usermodel.HSSFWorkbook
;
import
org.apache.poi.ss.usermodel.*
;
import
org.apache.poi.xssf.usermodel.XSSFWorkbook
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
java.io.ByteArrayInputStream
;
import
java.io.InputStream
;
import
java.util.Iterator
;
@Component
(
"xlsToCsvFileConverter"
)
public
class
XlsToCsvFileConverter
implements
FileConverter
{
private
static
final
String
FILE_EXTENSION
=
".csv"
;
@Value
(
"${application.service.file-converter.xls-to-csv.separator:$$}"
)
private
String
separator
;
@Override
public
byte
[]
convert
(
byte
[]
inputFile
,
String
fileName
)
{
StringBuffer
data
=
new
StringBuffer
();
InputStream
fis
=
null
;
Workbook
workbook
=
null
;
try
{
//FileOutputStream fos = new FileOutputStream();
// Get the workbook object for XLSX file
fis
=
new
ByteArrayInputStream
(
inputFile
);
String
ext
=
FilenameUtils
.
getExtension
(
fileName
);
if
(
ext
.
equalsIgnoreCase
(
"xlsx"
))
{
workbook
=
new
XSSFWorkbook
(
fis
);
}
else
if
(
ext
.
equalsIgnoreCase
(
"xls"
))
{
workbook
=
new
HSSFWorkbook
(
fis
);
}
// Get first sheet from the workbook
int
numberOfSheets
=
workbook
.
getNumberOfSheets
();
Row
row
;
Cell
cell
;
// Iterate through each rows from first sheet
for
(
int
i
=
0
;
i
<
numberOfSheets
;
i
++)
{
Sheet
sheet
=
workbook
.
getSheetAt
(
0
);
Iterator
<
Row
>
rowIterator
=
sheet
.
iterator
();
while
(
rowIterator
.
hasNext
())
{
row
=
rowIterator
.
next
();
// For each row, iterate through each columns
Iterator
<
Cell
>
cellIterator
=
row
.
cellIterator
();
while
(
cellIterator
.
hasNext
())
{
cell
=
cellIterator
.
next
();
switch
(
cell
.
getCellType
())
{
case
BOOLEAN:
data
.
append
(
cell
.
getBooleanCellValue
()
+
separator
);
break
;
case
NUMERIC:
data
.
append
(
cell
.
getNumericCellValue
()
+
separator
);
break
;
case
STRING:
data
.
append
(
cell
.
getStringCellValue
()
+
separator
);
break
;
case
BLANK:
data
.
append
(
""
+
separator
);
break
;
default
:
data
.
append
(
cell
+
separator
);
}
}
data
.
setLength
(
data
.
length
()
-
separator
.
length
());
data
.
append
(
'\n'
);
// appending new line after each row
}
}
return
data
.
toString
().
getBytes
();
//fos.write(data.toString().getBytes());
//fos.close();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
if
(
workbook
!=
null
)
{
try
{
workbook
.
close
();
}
catch
(
Exception
e
)
{}
}
if
(
fis
!=
null
)
{
try
{
fis
.
close
();
}
catch
(
Exception
e
)
{}
}
}
return
new
byte
[]{};
}
@Override
public
String
getFileName
(
String
fileName
)
{
int
position
=
fileName
.
lastIndexOf
(
"."
);
String
fileNameWithoutExtension
=
fileName
.
substring
(
0
,
position
);
return
fileNameWithoutExtension
+
FILE_EXTENSION
;
}
}
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