Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
BackEnd-V2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Joel Andres Molina Velez
BackEnd-V2
Commits
40bc6c1f
Commit
40bc6c1f
authored
Jul 14, 2023
by
Joel Andres Molina Velez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Se modifica los servicios de guardar de ServiceUzyTavAnexoSPR y ServiceUzyTavConvoca
parent
83fb7e0c
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
69 additions
and
8 deletions
+69
-8
persistence-units.xml
.jpb/persistence-units.xml
+13
-0
FileStorageService.java
...d/MovilidadWS/Service/FileStorage/FileStorageService.java
+48
-4
IFileStorageService.java
.../MovilidadWS/Service/FileStorage/IFileStorageService.java
+4
-0
ServiceUzyTavAnexoSPR.java
...lidadWS/Service/UzyTavAnexoSPR/ServiceUzyTavAnexoSPR.java
+3
-3
ServiceUzyTavConvoca.java
...vilidadWS/Service/UzyTavConvoca/ServiceUzyTavConvoca.java
+1
-1
16_espe.jpeg
uploadsIMG/16_espe.jpeg
+0
-0
38_MuestraPDF (1).pdf
uploadsPDF/38_MuestraPDF (1).pdf
+0
-0
No files found.
.jpb/persistence-units.xml
0 → 100644
View file @
40bc6c1f
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<component
name=
"PersistenceUnitSettings"
>
<persistence-units>
<persistence-unit
name=
"Default"
>
<packages>
<package
value=
"ec.edu.espe.movilidad.MovilidadWS"
/>
</packages>
</persistence-unit>
</persistence-units>
</component>
</project>
\ No newline at end of file
src/main/java/ec/edu/espe/movilidad/MovilidadWS/Service/FileStorage/FileStorageService.java
View file @
40bc6c1f
package
ec
.
edu
.
espe
.
movilidad
.
MovilidadWS
.
Service
.
FileStorage
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.multipart.MultipartFile
;
...
...
@@ -11,7 +10,7 @@ import java.nio.file.*;
@Service
public
class
FileStorageService
implements
IFileStorageService
{
private
final
Path
rootFolder
=
Paths
.
get
(
"uploads"
);
private
final
Path
rootFolder
=
Paths
.
get
(
"uploads
PDF
"
);
private
final
Path
rootFolderIMG
=
Paths
.
get
(
"uploadsIMG"
);
...
...
@@ -47,7 +46,7 @@ public class FileStorageService implements IFileStorageService {
}
}
@Override
public
String
moveFile
(
String
sourceFilePath
,
String
targetFileName
,
boolean
overwrite
)
throws
IOException
{
Path
sourcePath
=
Paths
.
get
(
sourceFilePath
);
Path
targetPath
=
rootFolder
.
resolve
(
targetFileName
);
...
...
@@ -67,13 +66,57 @@ public class FileStorageService implements IFileStorageService {
return
targetPath
.
toString
();
}
@Override
public
String
saveFileIMG
(
MultipartFile
file
,
String
fileName
,
boolean
overwrite
)
{
try
{
Path
filePath
=
rootFolderIMG
.
resolve
(
fileName
);
// Verificar si el archivo ya existe y si se permite la sobrescritura
if
(
Files
.
exists
(
filePath
)
&&
!
overwrite
)
{
throw
new
FileAlreadyExistsException
(
"File already exists: "
+
fileName
);
}
// Eliminar el archivo anterior si existe
if
(
Files
.
exists
(
filePath
))
{
Files
.
delete
(
filePath
);
}
/////////////
// Guardar el archivo, reemplazando si es necesario
try
(
InputStream
inputStream
=
file
.
getInputStream
())
{
Files
.
copy
(
inputStream
,
filePath
,
StandardCopyOption
.
REPLACE_EXISTING
);
}
return
filePath
.
toString
();
}
catch
(
FileAlreadyExistsException
e
)
{
// Manejar la excepción de archivo existente
// ... Realizar acciones adecuadas (por ejemplo, generar un nombre único)
throw
new
RuntimeException
(
"File already exists: "
+
fileName
,
e
);
}
catch
(
IOException
e
)
{
// Manejar la excepción de E/S
// ... Realizar acciones adecuadas (por ejemplo, registrar el error)
throw
new
RuntimeException
(
"Failed to save file: "
+
fileName
,
e
);
}
}
@Override
public
String
moveFileIMG
(
String
sourceFilePath
,
String
targetFileName
,
boolean
overwrite
)
throws
IOException
{
Path
sourcePath
=
Paths
.
get
(
sourceFilePath
);
Path
targetPath
=
rootFolderIMG
.
resolve
(
targetFileName
);
if
(
Files
.
exists
(
targetPath
)
&&
!
overwrite
)
{
throw
new
FileAlreadyExistsException
(
"File already exists: "
+
targetFileName
);
}
// Eliminar el archivo objetivo si existe y se permite la sobrescritura
if
(
Files
.
exists
(
targetPath
))
{
Files
.
delete
(
targetPath
);
}
// Mover el archivo de la ubicación de origen a la ubicación de destino
Files
.
move
(
sourcePath
,
targetPath
,
StandardCopyOption
.
REPLACE_EXISTING
);
return
targetPath
.
toString
();
}
}
\ No newline at end of file
src/main/java/ec/edu/espe/movilidad/MovilidadWS/Service/FileStorage/IFileStorageService.java
View file @
40bc6c1f
...
...
@@ -11,4 +11,8 @@ public interface IFileStorageService {
String
moveFile
(
String
sourceFilePath
,
String
targetFileName
,
boolean
overwrite
)
throws
IOException
;
String
saveFileIMG
(
MultipartFile
file
,
String
fileName
,
boolean
overwrite
);
String
moveFileIMG
(
String
sourceFilePath
,
String
targetFileName
,
boolean
overwrite
)
throws
IOException
;
}
src/main/java/ec/edu/espe/movilidad/MovilidadWS/Service/UzyTavAnexoSPR/ServiceUzyTavAnexoSPR.java
View file @
40bc6c1f
...
...
@@ -22,7 +22,7 @@ public class ServiceUzyTavAnexoSPR implements IServiceUzyTavAnexoSPR{
private
final
UzyTavAnexoSPRMapper
mapper
;
private
final
Path
rootFolder
=
Paths
.
get
(
"uploads"
);
private
final
Path
rootFolder
=
Paths
.
get
(
"uploads
IMG
"
);
private
final
IFileStorageService
fileStorageService
;
...
...
@@ -54,7 +54,7 @@ public class ServiceUzyTavAnexoSPR implements IServiceUzyTavAnexoSPR{
if
(
file
!=
null
&&
!
file
.
isEmpty
())
{
// Guardar el archivo en una ubicación temporal
String
tempFileName
=
"temp_"
+
file
.
getOriginalFilename
();
String
tempFilePath
=
fileStorageService
.
saveFile
(
file
,
tempFileName
,
true
);
String
tempFilePath
=
fileStorageService
.
saveFile
IMG
(
file
,
tempFileName
,
true
);
// Guardar el registro en la base de datos para generar el ID
ModelUzyTavAnexoSPR
uzyTavAnexoSPR
=
mapper
.
dtoToEntity
(
dtoUzyTavAnexoSPR
);
...
...
@@ -65,7 +65,7 @@ public class ServiceUzyTavAnexoSPR implements IServiceUzyTavAnexoSPR{
String
fileName
=
uzytavanexospr_id
+
"_"
+
file
.
getOriginalFilename
();
// Mueve el archivo de la ubicación temporal a la ubicación final
String
fileUrl
=
fileStorageService
.
moveFile
(
tempFilePath
,
fileName
,
true
);
String
fileUrl
=
fileStorageService
.
moveFile
IMG
(
tempFilePath
,
fileName
,
true
);
uzyTavAnexoSPR
.
setUzytavanexospr_nombre
(
fileName
);
uzyTavAnexoSPR
.
setUzytavanexospr_url
(
fileUrl
);
...
...
src/main/java/ec/edu/espe/movilidad/MovilidadWS/Service/UzyTavConvoca/ServiceUzyTavConvoca.java
View file @
40bc6c1f
...
...
@@ -16,7 +16,7 @@ import java.util.*;
@Service
public
class
ServiceUzyTavConvoca
implements
IServiceUzyTavConvoca
{
private
final
Path
rootFolder
=
Paths
.
get
(
"uploads"
);
private
final
Path
rootFolder
=
Paths
.
get
(
"uploads
PDF
"
);
private
final
DaoUzyTavConvoca
daoUzyTavConvoca
;
private
final
UzyTavConvocaMapper
modelMapper
;
private
final
IFileStorageService
fileStorageService
;
...
...
uploadsIMG/16_espe.jpeg
0 → 100644
View file @
40bc6c1f
15.6 KB
uploadsPDF/38_MuestraPDF (1).pdf
0 → 100644
View file @
40bc6c1f
File added
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