Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
dad
Cines Vitamui
Commits
ef704a59
Commit
ef704a59
authored
Nov 15, 2021
by
descamps
Browse files
KDE - 15/11/2021 - Importer un fichier xsd ou rng dans un profil Correctif
parent
4e201427
Changes
6
Hide whitespace changes
Inline
Side-by-side
api/api-referential/referential-external-client/src/main/java/fr/gouv/vitamui/referential/external/client/ProfileExternalRestClient.java
View file @
ef704a59
...
...
@@ -44,6 +44,7 @@ import fr.gouv.vitamui.commons.rest.client.ExternalHttpContext;
import
fr.gouv.vitamui.referential.common.dto.ProfileDto
;
import
fr.gouv.vitamui.referential.common.rest.RestApi
;
import
org.springframework.core.ParameterizedTypeReference
;
import
org.springframework.core.io.ByteArrayResource
;
import
org.springframework.core.io.FileSystemResource
;
import
org.springframework.core.io.Resource
;
import
org.springframework.http.HttpEntity
;
...
...
@@ -100,11 +101,11 @@ public class ProfileExternalRestClient extends BasePaginatingAndSortingRestClien
}
public
ResponseEntity
<
JsonNode
>
updateProfileFile
(
ExternalHttpContext
context
,
String
id
,
MultipartFile
profileFile
)
{
public
ResponseEntity
<
JsonNode
>
updateProfileFile
(
ExternalHttpContext
context
,
String
id
,
MultipartFile
profileFile
)
throws
IOException
{
final
UriComponentsBuilder
uriBuilder
=
UriComponentsBuilder
.
fromHttpUrl
(
getUrl
()
+
"/updateProfileFile"
+
CommonConstants
.
PATH_ID
);
MultiValueMap
<
String
,
Object
>
bodyMap
=
new
LinkedMultiValueMap
<>();
bodyMap
.
add
(
"file"
,
new
FileSystemResource
(
convert
(
profileFile
)));
bodyMap
.
add
(
"file"
,
new
FileSystemResource
(
profileFile
.
getBytes
(),
profileFile
.
getOriginalFilename
(
)));
final
HttpEntity
<
MultiValueMap
<
String
,
Object
>>
request
=
new
HttpEntity
<>(
bodyMap
,
buildHeaders
(
context
));
return
restTemplate
.
exchange
(
uriBuilder
.
build
(
id
),
HttpMethod
.
PUT
,
...
...
@@ -112,21 +113,18 @@ public class ProfileExternalRestClient extends BasePaginatingAndSortingRestClien
JsonNode
.
class
);
}
public
static
File
convert
(
MultipartFile
file
)
{
File
convFile
=
new
File
(
file
.
getOriginalFilename
());
try
{
convFile
.
createNewFile
();
FileOutputStream
fos
=
new
FileOutputStream
(
convFile
);
fos
.
write
(
file
.
getBytes
());
fos
.
close
();
}
catch
(
IOException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
public
static
class
FileSystemResource
extends
ByteArrayResource
{
private
String
fileName
;
public
FileSystemResource
(
byte
[]
byteArray
,
String
filename
)
{
super
(
byteArray
);
this
.
fileName
=
filename
;
}
return
convFile
;
}
public
String
getFilename
()
{
return
fileName
;
}
public
void
setFilename
(
String
fileName
)
{
this
.
fileName
=
fileName
;
}
}
}
api/api-referential/referential-external/src/main/java/fr/gouv/vitamui/referential/external/server/rest/ProfileExternalController.java
View file @
ef704a59
...
...
@@ -62,6 +62,7 @@ import org.springframework.web.bind.annotation.*;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.validation.Valid
;
import
java.io.IOException
;
import
java.util.Collection
;
import
java.util.Map
;
import
java.util.Optional
;
...
...
@@ -119,7 +120,7 @@ public class ProfileExternalController {
*/
@PutMapping
(
value
=
"/updateProfileFile"
+
CommonConstants
.
PATH_ID
)
public
ResponseEntity
<
JsonNode
>
importProfileFile
(
final
@PathVariable
(
"id"
)
String
id
,
@RequestParam
(
"file"
)
MultipartFile
file
)
{
@RequestParam
(
"file"
)
MultipartFile
file
)
throws
IOException
{
LOGGER
.
debug
(
"Update {} profile file with id :{}"
,
id
);
LOGGER
.
debug
(
"Import profile file {}"
,
file
);
ParameterChecker
.
checkParameter
(
"profileFile stream is a mandatory parameter: "
,
file
);
...
...
api/api-referential/referential-external/src/main/java/fr/gouv/vitamui/referential/external/server/service/ProfileExternalService.java
View file @
ef704a59
...
...
@@ -55,6 +55,7 @@ import org.springframework.http.ResponseEntity;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.IOException
;
import
java.util.*
;
import
java.util.stream.Collectors
;
...
...
@@ -145,7 +146,7 @@ public class ProfileExternalService extends AbstractResourceClientService<Profil
}
public
ResponseEntity
<
JsonNode
>
updateProfileFile
(
String
id
,
MultipartFile
profileFile
)
{
public
ResponseEntity
<
JsonNode
>
updateProfileFile
(
String
id
,
MultipartFile
profileFile
)
throws
IOException
{
return
profileInternalRestClient
.
updateProfileFile
(
getInternalHttpContext
(),
id
,
profileFile
);
}
}
api/api-referential/referential-internal-client/src/main/java/fr/gouv/vitamui/referential/internal/client/ProfileInternalRestClient.java
View file @
ef704a59
...
...
@@ -46,6 +46,7 @@ import fr.gouv.vitamui.commons.rest.client.InternalHttpContext;
import
fr.gouv.vitamui.referential.common.dto.ProfileDto
;
import
fr.gouv.vitamui.referential.common.rest.RestApi
;
import
org.springframework.core.ParameterizedTypeReference
;
import
org.springframework.core.io.ByteArrayResource
;
import
org.springframework.core.io.FileSystemResource
;
import
org.springframework.core.io.Resource
;
import
org.springframework.http.HttpEntity
;
...
...
@@ -104,10 +105,10 @@ public class ProfileInternalRestClient extends BasePaginatingAndSortingRestClien
public
ResponseEntity
<
JsonNode
>
updateProfileFile
(
InternalHttpContext
context
,
String
id
,
MultipartFile
profileFile
)
{
public
ResponseEntity
<
JsonNode
>
updateProfileFile
(
InternalHttpContext
context
,
String
id
,
MultipartFile
profileFile
)
throws
IOException
{
final
UriComponentsBuilder
uriBuilder
=
UriComponentsBuilder
.
fromHttpUrl
(
getUrl
()
+
"/updateProfileFile"
+
CommonConstants
.
PATH_ID
);
MultiValueMap
<
String
,
Object
>
bodyMap
=
new
LinkedMultiValueMap
<>();
bodyMap
.
add
(
"file"
,
new
FileSystemResource
(
convert
(
profileFile
)));
bodyMap
.
add
(
"file"
,
new
FileSystemResource
(
profileFile
.
getBytes
(),
profileFile
.
getOriginalFilename
(
)));
final
HttpEntity
<
MultiValueMap
<
String
,
Object
>>
request
=
new
HttpEntity
<>(
bodyMap
,
buildHeaders
(
context
));
return
restTemplate
.
exchange
(
uriBuilder
.
build
(
id
),
...
...
@@ -116,38 +117,17 @@ public class ProfileInternalRestClient extends BasePaginatingAndSortingRestClien
JsonNode
.
class
);
}
public
static
File
convert
(
MultipartFile
file
)
{
File
convFile
=
new
File
(
file
.
getOriginalFilename
());
try
{
convFile
.
createNewFile
();
FileOutputStream
fos
=
new
FileOutputStream
(
convFile
);
fos
.
write
(
file
.
getBytes
());
fos
.
close
();
}
catch
(
IOException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
return
convFile
;
}
/** Resource resouceFile = new FileSystemResource(file.getBytes(), file.getOriginalFilename());
body.add("files", resouceFile);
);
public
static
class
FileSystemResource
extends
ByteArrayResource
{
private
String
fileName
;
public static class FileSystemResource extends ByteArrayResource {
private String fileName;
public FileSystemResource(byte[] byteArray , String filename) {
super(byteArray);
this.fileName = filename;
}
public
FileSystemResource
(
byte
[]
byteArray
,
String
filename
)
{
super
(
byteArray
);
this
.
fileName
=
filename
;
}
public String getFilename() { return fileName; }
public void setFilename(String fileName) { this.fileName= fileName; }
public
String
getFilename
()
{
return
fileName
;
}
public
void
setFilename
(
String
fileName
)
{
this
.
fileName
=
fileName
;
}
}*/
}
}
ui/ui-referential/src/main/java/fr/gouv/vitamui/referential/rest/ProfileController.java
View file @
ef704a59
...
...
@@ -63,6 +63,7 @@ import javax.validation.Valid;
import
javax.ws.rs.Consumes
;
import
javax.ws.rs.Produces
;
import
javax.ws.rs.core.Context
;
import
java.io.IOException
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLEncoder
;
import
java.nio.charset.StandardCharsets
;
...
...
@@ -158,7 +159,7 @@ public class ProfileController extends AbstractUiRestController {
@ApiOperation
(
value
=
"Importer un fichier xsd ou rng dans un profil"
)
@PutMapping
(
value
=
"/updateProfileFile"
+
CommonConstants
.
PATH_ID
)
public
ResponseEntity
<
JsonNode
>
importProfileFile
(
final
@PathVariable
(
"id"
)
String
id
,
@RequestParam
(
"file"
)
MultipartFile
file
)
{
@RequestParam
(
"file"
)
MultipartFile
file
)
throws
IOException
{
LOGGER
.
debug
(
"Update profile file with id :{}"
,
id
);
ParameterChecker
.
checkParameter
(
"profileFile stream is a mandatory parameter: "
,
file
);
ParameterChecker
.
checkParameter
(
"The Identifier is a mandatory parameter: "
,
id
);
...
...
ui/ui-referential/src/main/java/fr/gouv/vitamui/referential/service/ProfileService.java
View file @
ef704a59
...
...
@@ -55,6 +55,7 @@ import org.springframework.http.ResponseEntity;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.IOException
;
import
java.util.Collection
;
import
java.util.Optional
;
...
...
@@ -121,7 +122,7 @@ public class ProfileService extends AbstractPaginateService<ProfileDto> {
return
webClient
.
importProfiles
(
context
,
file
);
}
public
ResponseEntity
<
JsonNode
>
updateProfileFile
(
ExternalHttpContext
context
,
String
id
,
MultipartFile
profileFile
)
{
public
ResponseEntity
<
JsonNode
>
updateProfileFile
(
ExternalHttpContext
context
,
String
id
,
MultipartFile
profileFile
)
throws
IOException
{
return
client
.
updateProfileFile
(
context
,
id
,
profileFile
);
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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