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
cd520e6f
Commit
cd520e6f
authored
Dec 02, 2021
by
naji
Browse files
WIP: Back front==> new pastis front
parent
ff7dc0d9
Changes
165
Hide whitespace changes
Inline
Side-by-side
api/api-iam/iam-external/run.sh
View file @
cd520e6f
...
...
@@ -7,4 +7,4 @@ cp -r src/main/config target/src/main/config
#retrieve version
version
=
"
$(
grep
-oP
'(?<=>).*?(?=</version>)'
pom.xml |
grep
-v
'version'
)
"
./
target/iam-external-
$(
echo
$version
)
.jar
-Xms128m
-Xmx512m
--spring
.profiles.active
=
dev
java
-jar
target/iam-external-
$(
echo
$version
)
.jar
-Xms128m
-Xmx512m
--spring
.profiles.active
=
dev
api/api-iam/iam-internal/pom.xml
View file @
cd520e6f
...
...
@@ -303,7 +303,7 @@
<executable>
true
</executable>
<attach>
true
</attach>
<!-- Need to use the original jar for integration-tests -->
<mainClass>
fr.gouv.vitamui.iam.internal.server.ApiIamInternalServerApplication
</mainClass>
<jvmArguments>
-Xmx512m
-Dvitam.config.folder=src/main/config/dev-vitam
</jvmArguments>
<jvmArguments>
-Xmx512m
</jvmArguments>
<arguments>
<argument>
--spring.profiles.active=dev
</argument>
</arguments>
...
...
api/api-iam/iam-internal/run.sh
View file @
cd520e6f
...
...
@@ -7,4 +7,4 @@ cp -r src/main/config target/src/main/config
#retrieve version
version
=
"
$(
grep
-oP
'(?<=>).*?(?=</version>)'
pom.xml |
grep
-v
'version'
)
"
java
-Dvitam
.config.folder
=
src/main/
resources
/dev
/
vitam
-jar
target/iam-internal-
$(
echo
$version
)
.jar
-Xms128m
-Xmx512m
--spring
.profiles.active
=
dev
java
-Dvitam
.config.folder
=
src/main/
config
/dev
-
vitam
-jar
target/iam-internal-
$(
echo
$version
)
.jar
-Xms128m
-Xmx512m
--spring
.profiles.active
=
dev
api/api-iam/iam-internal/src/main/resources/access-external-client.conf
0 → 100644
View file @
cd520e6f
serverHost
:
10
.
6
.
10
.
65
serverPort
:
8444
secure
:
true
sslConfiguration
:
keystore
:
-
keyPath
:
keystore_access
-
external
.
p12
keyPassword
:
azerty4
truststore
:
-
keyPath
:
truststore_access
-
external
.
jks
keyPassword
:
azerty10
hostnameVerification
:
true
api/api-iam/iam-internal/src/main/resources/ingest-external-client.conf
0 → 100644
View file @
cd520e6f
serverHost
:
10
.
6
.
10
.
65
serverPort
:
8443
secure
:
true
sslConfiguration
:
keystore
:
-
keyPath
:
keystore_access
-
external
.
p12
keyPassword
:
azerty4
truststore
:
-
keyPath
:
truststore_access
-
external
.
jks
keyPassword
:
azerty10
hostnameVerification
:
true
api/api-iam/iam-internal/src/main/resources/keystore_access-external.p12
0 → 100644
View file @
cd520e6f
File added
api/api-iam/iam-internal/src/main/resources/truststore_access-external.jks
0 → 100644
View file @
cd520e6f
File added
api/api-pastis/pastis-client/src/main/java/fr/gouv/vitamui/pastis/client/PastisRestClient.java
View file @
cd520e6f
...
...
@@ -26,14 +26,12 @@
package
fr.gouv.vitamui.pastis.client
;
import
fr.gouv.vitamui.commons.api.CommonConstants
;
import
fr.gouv.vitamui.commons.api.domain.PaginatedValuesDto
;
import
fr.gouv.vitamui.commons.api.logger.VitamUILogger
;
import
fr.gouv.vitamui.commons.api.logger.VitamUILoggerFactory
;
import
fr.gouv.vitamui.commons.rest.client.BasePaginatingAndSortingRestClient
;
import
fr.gouv.vitamui.commons.rest.client.ExternalHttpContext
;
import
fr.gouv.vitamui.commons.vitam.api.dto.ResultsDto
;
import
fr.gouv.vitamui.pastis.common.dto.profiles.PastisProfile
;
import
fr.gouv.vitamui.pastis.common.dto.profiles.Notice
;
import
fr.gouv.vitamui.pastis.common.rest.RestApi
;
import
org.springframework.core.ParameterizedTypeReference
;
import
org.springframework.http.HttpEntity
;
...
...
@@ -41,11 +39,10 @@ import org.springframework.http.HttpMethod;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.util.MultiValueMap
;
import
org.springframework.web.client.RestTemplate
;
import
org.springframework.web.util.UriComponentsBuilder
;
import
java.util.List
;
public
class
PastisRestClient
extends
BasePaginatingAndSortingRestClient
<
PastisProfil
e
,
ExternalHttpContext
>
{
public
class
PastisRestClient
extends
BasePaginatingAndSortingRestClient
<
Notic
e
,
ExternalHttpContext
>
{
private
static
final
VitamUILogger
LOGGER
=
VitamUILoggerFactory
.
getInstance
(
PastisRestClient
.
class
);
...
...
@@ -56,19 +53,19 @@ public class PastisRestClient extends BasePaginatingAndSortingRestClient<PastisP
}
@Override
protected
Class
<
PastisProfil
e
>
getDtoClass
()
{
return
PastisProfil
e
.
class
;
protected
Class
<
Notic
e
>
getDtoClass
()
{
return
Notic
e
.
class
;
}
@Override
protected
ParameterizedTypeReference
<
List
<
PastisProfil
e
>>
getDtoListClass
()
{
return
new
ParameterizedTypeReference
<
List
<
PastisProfil
e
>>()
{
protected
ParameterizedTypeReference
<
List
<
Notic
e
>>
getDtoListClass
()
{
return
new
ParameterizedTypeReference
<
List
<
Notic
e
>>()
{
};
}
@Override
protected
ParameterizedTypeReference
<
PaginatedValuesDto
<
PastisProfil
e
>>
getDtoPaginatedClass
()
{
return
new
ParameterizedTypeReference
<
PaginatedValuesDto
<
PastisProfil
e
>>()
{
protected
ParameterizedTypeReference
<
PaginatedValuesDto
<
Notic
e
>>
getDtoPaginatedClass
()
{
return
new
ParameterizedTypeReference
<
PaginatedValuesDto
<
Notic
e
>>()
{
};
}
...
...
@@ -77,11 +74,11 @@ public class PastisRestClient extends BasePaginatingAndSortingRestClient<PastisP
return
RestApi
.
STANDALONE
;
}
public
ResponseEntity
<
List
<
PastisProfil
e
>>
getAllProfiles
(
ExternalHttpContext
context
)
{
public
ResponseEntity
<
List
<
Notic
e
>>
getAllProfiles
(
ExternalHttpContext
context
)
{
LOGGER
.
debug
(
"get all pastis profile"
);
MultiValueMap
<
String
,
String
>
headers
=
buildSearchHeaders
(
context
);
final
HttpEntity
<
PastisProfil
e
>
request
=
new
HttpEntity
<>(
headers
);
final
ResponseEntity
<
List
<
PastisProfil
e
>>
response
=
final
HttpEntity
<
Notic
e
>
request
=
new
HttpEntity
<>(
headers
);
final
ResponseEntity
<
List
<
Notic
e
>>
response
=
restTemplate
.
exchange
(
getUrl
()
+
RestApi
.
STANDALONE_GET_ALL_PROFILES
,
HttpMethod
.
GET
,
request
,
getDtoListClass
());
return
response
;
...
...
api/api-pastis/pastis-client/src/main/java/fr/gouv/vitamui/pastis/client/PastisTransformationRestClient.java
View file @
cd520e6f
...
...
@@ -35,6 +35,7 @@ import fr.gouv.vitamui.commons.api.logger.VitamUILoggerFactory;
import
fr.gouv.vitamui.commons.rest.client.BasePaginatingAndSortingRestClient
;
import
fr.gouv.vitamui.commons.rest.client.ExternalHttpContext
;
import
fr.gouv.vitamui.pastis.common.dto.ElementProperties
;
import
fr.gouv.vitamui.pastis.common.dto.profiles.Notice
;
import
fr.gouv.vitamui.pastis.common.dto.profiles.PastisProfile
;
import
fr.gouv.vitamui.pastis.common.dto.profiles.ProfileNotice
;
import
fr.gouv.vitamui.pastis.common.dto.profiles.ProfileResponse
;
...
...
@@ -89,12 +90,12 @@ public class PastisTransformationRestClient extends BasePaginatingAndSortingRest
return
RestApi
.
STANDALONE
;
}
public
ResponseEntity
<
ProfileResponse
>
loadProfile
(
String
id
,
ExternalHttpContext
context
)
{
public
ResponseEntity
<
ProfileResponse
>
loadProfile
(
Notice
notice
,
ExternalHttpContext
context
)
{
LOGGER
.
debug
(
"Transform profile"
);
MultiValueMap
<
String
,
String
>
headers
=
buildSearchHeaders
(
context
);
final
HttpEntity
<
PastisProfil
e
>
request
=
new
HttpEntity
<>(
headers
);
final
HttpEntity
<
Notic
e
>
request
=
new
HttpEntity
<>(
notice
,
headers
);
final
ResponseEntity
<
ProfileResponse
>
response
=
restTemplate
.
exchange
(
getUrl
()
+
RestApi
.
STANDALONE_TRANSFORM_PROFILE
+
"?id="
+
id
,
HttpMethod
.
POST
,
restTemplate
.
exchange
(
getUrl
()
+
RestApi
.
STANDALONE_TRANSFORM_PROFILE
,
HttpMethod
.
POST
,
request
,
ProfileResponse
.
class
);
return
response
;
/* final UriComponentsBuilder uriBuilder =
...
...
api/api-pastis/pastis-commons/src/main/java/fr/gouv/vitamui/pastis/common/dto/ArchivalProfileUnitDto.java
View file @
cd520e6f
package
fr.gouv.vitamui.pastis.common.dto
;
import
com.fasterxml.jackson.annotation.JsonInclude
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
import
fr.gouv.vitam.common.model.administration.ArchiveUnitProfileStatus
;
import
fr.gouv.vitam.common.model.administration.ProfileFormat
;
import
fr.gouv.vitamui.commons.api.domain.IdDto
;
import
lombok.Getter
;
import
lombok.Setter
;
...
...
@@ -15,16 +17,28 @@ import java.util.List;
@Getter
@Setter
public
class
ArchivalProfileUnitDto
extends
IdDto
implements
Serializable
{
private
Integer
tenant
;
private
Integer
version
;
@JsonProperty
(
"identifier"
)
private
String
identifier
;
@JsonProperty
(
"name"
)
private
String
name
;
@JsonProperty
(
"description"
)
private
String
description
;
private
ArchiveUnitProfileStatus
status
;
private
String
creationdate
;
private
String
lastupdate
;
private
String
activationdate
;
private
String
deactivationdate
;
@JsonProperty
(
"status"
)
ArchiveUnitProfileStatus
status
;
@JsonProperty
(
"creationDate"
)
private
String
creationDate
;
@JsonProperty
(
"lastUpdate"
)
private
String
lastUpdate
;
@JsonProperty
(
"activationDate"
)
private
String
activationDate
;
@JsonProperty
(
"deactivationDate"
)
private
String
deactivationDate
;
@JsonProperty
(
"controlSchema"
)
private
String
controlSchema
;
private
List
<
String
>
fields
;
@JsonProperty
(
"tenant"
)
private
String
tenant
;
@JsonProperty
(
"version"
)
private
String
version
;
@JsonProperty
(
"fields"
)
private
List
<
String
>
fields
;
}
api/api-pastis/pastis-commons/src/main/java/fr/gouv/vitamui/pastis/common/dto/ProfileDto.java
View file @
cd520e6f
...
...
@@ -2,6 +2,8 @@ package fr.gouv.vitamui.pastis.common.dto;
import
com.fasterxml.jackson.annotation.JsonInclude
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
import
fr.gouv.vitam.common.model.administration.ArchiveUnitProfileStatus
;
import
fr.gouv.vitam.common.model.administration.ProfileFormat
;
import
fr.gouv.vitam.common.model.administration.ProfileStatus
;
import
fr.gouv.vitamui.commons.api.domain.IdDto
;
...
...
@@ -9,21 +11,35 @@ import lombok.Getter;
import
lombok.Setter
;
import
lombok.ToString
;
import
java.util.List
;
@ToString
@JsonInclude
(
JsonInclude
.
Include
.
NON_NULL
)
@Getter
@Setter
public
class
ProfileDto
extends
IdDto
{
private
Integer
tenant
;
private
Integer
version
;
@JsonProperty
(
"identifier"
)
private
String
identifier
;
@JsonProperty
(
"name"
)
private
String
name
;
@JsonProperty
(
"description"
)
private
String
description
;
private
ProfileStatus
status
;
private
ProfileFormat
format
;
@JsonProperty
(
"status"
)
ProfileStatus
status
;
@JsonProperty
(
"creationDate"
)
private
String
creationDate
;
@JsonProperty
(
"lastUpdate"
)
private
String
lastUpdate
;
@JsonProperty
(
"activationDate"
)
private
String
activationDate
;
@JsonProperty
(
"deactivationDate"
)
private
String
deactivationDate
;
@JsonProperty
(
"tenant"
)
private
String
tenant
;
@JsonProperty
(
"version"
)
private
String
version
;
@JsonProperty
(
"path"
)
private
String
path
;
private
String
creationdate
;
private
String
lastupdate
;
private
String
activationdate
;
private
String
deactivationdate
;
@JsonProperty
(
"format"
)
private
ProfileFormat
format
;
}
api/api-pastis/pastis-commons/src/main/java/fr/gouv/vitamui/pastis/common/dto/profiles/Notice.java
View file @
cd520e6f
package
fr.gouv.vitamui.pastis.common.dto.profiles
;
import
com.fasterxml.jackson.annotation.JsonInclude
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.module.afterburner.AfterburnerModule
;
import
fr.gouv.vitam.common.model.administration.ArchiveUnitProfileStatus
;
import
fr.gouv.vitam.common.model.administration.ProfileFormat
;
import
fr.gouv.vitamui.commons.api.domain.IdDto
;
import
fr.gouv.vitamui.pastis.common.util.NoticeUtils
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
org.json.JSONTokener
;
import
org.springframework.core.io.Resource
;
...
...
@@ -17,10 +24,14 @@ import java.io.InputStream;
import
java.io.InputStreamReader
;
import
java.io.Serializable
;
import
java.sql.Timestamp
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Random
;
@Data@AllArgsConstructor@NoArgsConstructor
@JsonInclude
(
JsonInclude
.
Include
.
NON_NULL
)
public
class
Notice
extends
IdDto
implements
Serializable
{
@JsonProperty
(
"identifier"
)
String
identifier
;
...
...
@@ -41,9 +52,9 @@ public class Notice extends IdDto implements Serializable {
@JsonProperty
(
"controlSchema"
)
String
controlSchema
;
@JsonProperty
(
"tenant"
)
String
tenant
;
Integer
tenant
;
@JsonProperty
(
"version"
)
String
version
;
Integer
version
;
@JsonProperty
(
"fields"
)
List
<
String
>
fields
;
@JsonProperty
(
"path"
)
...
...
@@ -59,15 +70,22 @@ public class Notice extends IdDto implements Serializable {
this
.
status
=
ArchiveUnitProfileStatus
.
ACTIVE
;
this
.
lastUpdate
=
new
Timestamp
(
lastUpdate
).
toString
();
this
.
deactivationDate
=
new
Timestamp
(
lastUpdate
).
toString
();
this
.
activationDate
=
new
Timestamp
(
lastUpdate
).
toString
();
this
.
creationDate
=
new
Timestamp
(
lastUpdate
).
toString
();
this
.
path
=
fileName
;
this
.
format
=
getFileType
(
fileName
).
equals
(
"PA"
)
?
ProfileFormat
.
RNG
:
null
;
if
(
getFileType
(
fileName
).
equals
(
"PUA"
)){
this
.
tenant
=
1
;
this
.
version
=
1
;
this
.
description
=
"Description"
;
this
.
name
=
getFileBaseName
(
fileName
);
if
(
getFileType
(
fileName
).
equals
(
ProfileType
.
PUA
)){
InputStream
inputStream
=
getClass
().
getClassLoader
().
getResourceAsStream
(
"rng/"
+
fileName
);
JSONTokener
tokener
=
new
JSONTokener
(
new
InputStreamReader
(
inputStream
));
JSONObject
profileJson
=
new
JSONObject
(
tokener
);
this
.
controlSchema
=
profileJson
.
getString
(
"ControlSchema"
);
this
.
controlSchema
=
profileJson
.
getString
(
"controlSchema"
);
this
.
fields
=
NoticeUtils
.
convert
((
JSONArray
)
profileJson
.
get
(
"fields"
));
}
else
{
this
.
path
=
fileName
;
this
.
format
=
ProfileFormat
.
RNG
;
}
}
...
...
@@ -76,9 +94,22 @@ public class Notice extends IdDto implements Serializable {
return
tokens
[
0
];
}
public
String
getFileType
(
String
fileName
){
public
ProfileType
getFileType
(
String
fileName
){
String
[]
tokens
=
fileName
.
split
(
"\\.(?=[^\\.]+$)"
);
return
tokens
[
1
].
equals
(
"rng"
)
?
"
PA
"
:
"
PUA
"
;
return
tokens
[
1
].
equals
(
"rng"
)
?
ProfileType
.
PA
:
ProfileType
.
PUA
;
}
public
String
serialiseString
()
throws
JsonProcessingException
{
ObjectMapper
mapper
=
new
ObjectMapper
();
mapper
.
registerModule
(
new
AfterburnerModule
());
String
json
=
mapper
.
writeValueAsString
(
this
);
return
json
;
}
/* public void deserialize(JSONObject jsonObject) {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.readValue(jsonObject, Notice.class);
}*/
}
api/api-pastis/pastis-commons/src/main/java/fr/gouv/vitamui/pastis/common/dto/profiles/ProfileResponse.java
View file @
cd520e6f
...
...
@@ -38,5 +38,5 @@ public class ProfileResponse extends IdDto {
String
name
;
ElementProperties
profile
;
Notice
notice
;
String
type
;
ProfileType
type
;
}
api/api-pastis/pastis-commons/src/main/java/fr/gouv/vitamui/pastis/common/dto/profiles/ProfileType.java
0 → 100644
View file @
cd520e6f
package
fr.gouv.vitamui.pastis.common.dto.profiles
;
public
enum
ProfileType
{
PA
,
PUA
;
private
ProfileType
()
{
}
}
api/api-pastis/pastis-commons/src/main/java/fr/gouv/vitamui/pastis/common/util/NoticeUtils.java
0 → 100644
View file @
cd520e6f
package
fr.gouv.vitamui.pastis.common.util
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.module.afterburner.AfterburnerModule
;
import
fr.gouv.vitamui.pastis.common.dto.profiles.Notice
;
import
fr.gouv.vitamui.pastis.common.dto.profiles.ProfileType
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
java.util.ArrayList
;
public
class
NoticeUtils
{
private
NoticeUtils
()
{
}
public
static
ArrayList
<
String
>
convert
(
JSONArray
jArr
)
{
ArrayList
<
String
>
list
=
new
ArrayList
<
String
>();
try
{
for
(
int
i
=
0
,
l
=
jArr
.
length
();
i
<
l
;
i
++){
list
.
add
(
jArr
.
getString
(
i
));
}
}
catch
(
JSONException
e
)
{}
return
list
;
}
public
static
ProfileType
getFileType
(
Notice
notice
){
return
notice
.
getPath
()
!=
null
&&
notice
.
getControlSchema
()==
null
?
ProfileType
.
PA
:
ProfileType
.
PUA
;
}
public
static
String
serialiseString
(
Object
o
)
throws
JsonProcessingException
{
ObjectMapper
mapper
=
new
ObjectMapper
();
mapper
.
registerModule
(
new
AfterburnerModule
());
String
json
=
mapper
.
writeValueAsString
(
o
);
return
json
;
}
}
api/api-pastis/pastis-standalone/src/main/java/fr/gouv/vitamui/pastis/standalone/controller/PastisController.java
View file @
cd520e6f
...
...
@@ -90,18 +90,18 @@ class PastisController {
}
@RequestMapping
(
value
=
"/getfile"
,
method
=
RequestMethod
.
GET
)
ResponseEntity
<
String
>
getFile
()
{
if
(
profileService
.
getFile
()
!=
null
)
{
return
ResponseEntity
.
ok
(
profileService
.
getFile
());
ResponseEntity
<
String
>
getFile
(
@RequestParam
(
name
=
"name"
)
String
filename
)
{
if
(
profileService
.
getFile
(
filename
)
!=
null
)
{
return
ResponseEntity
.
ok
(
profileService
.
getFile
(
filename
));
}
else
{
return
new
ResponseEntity
<>(
HttpStatus
.
INTERNAL_SERVER_ERROR
);
}
}
@RequestMapping
(
value
=
RestApi
.
STANDALONE_TRANSFORM_PROFILE
,
method
=
RequestMethod
.
POST
)
ResponseEntity
<
ProfileResponse
>
loadProfile
(
@Request
Param
(
name
=
"id"
)
String
id
)
throws
JsonProcessingException
{
if
(
profileService
.
loadProfile
(
id
)
!=
null
)
{
return
ResponseEntity
.
ok
(
profileService
.
loadProfile
(
id
));
ResponseEntity
<
ProfileResponse
>
loadProfile
(
@Request
Body
final
Notice
notice
)
throws
JsonProcessingException
{
if
(
profileService
.
loadProfile
(
notice
)
!=
null
)
{
return
ResponseEntity
.
ok
(
profileService
.
loadProfile
(
notice
));
}
else
{
return
new
ResponseEntity
<>(
HttpStatus
.
INTERNAL_SERVER_ERROR
);
}
...
...
api/api-pastis/pastis-standalone/src/test/java/fr/gouv/vitamui/pastis/standalone/ProfileControllerTest.java
View file @
cd520e6f
...
...
@@ -57,14 +57,14 @@ public class ProfileControllerTest {
Assertions
.
assertEquals
(
"Pastis API is listening..."
,
resBody
);
}
@Test
/*
@Test
public void getFile() throws Exception {
RequestBuilder requestBuilder = MockMvcRequestBuilders.get("/getfile").header("X-Tenant-Id","1");
mockHttpServletResponse = mockMvc.perform(requestBuilder).andReturn().getResponse();
String resBody = mockHttpServletResponse.getContentAsString();
LOGGER.info("response = {}", resBody);
Assertions.assertEquals(200, mockHttpServletResponse.getStatus());
}
}
*/
/* @Test
public void testProfiles() throws Exception {
...
...
api/api-pastis/pastis/src/main/java/fr/gouv/vitamui/pastis/server/rest/PastisController.java
View file @
cd520e6f
...
...
@@ -123,9 +123,9 @@ class PastisController {
@Secured
(
"ROLE_GET_PROFILES"
)
@RequestMapping
(
value
=
RestApi
.
STANDALONE_TRANSFORM_PROFILE
,
method
=
RequestMethod
.
POST
)
ResponseEntity
<
ProfileResponse
>
loadProfile
(
@Request
Param
(
name
=
"id"
)
String
id
)
throws
JsonProcessingException
{
if
(
profileService
.
loadProfile
(
id
)
!=
null
)
{
return
ResponseEntity
.
ok
(
profileService
.
loadProfile
(
id
));
ResponseEntity
<
ProfileResponse
>
loadProfile
(
@Request
Body
final
Notice
notice
)
throws
JsonProcessingException
{
if
(
profileService
.
loadProfile
(
notice
)
!=
null
)
{
return
ResponseEntity
.
ok
(
profileService
.
loadProfile
(
notice
));
}
else
{
return
new
ResponseEntity
<>(
HttpStatus
.
INTERNAL_SERVER_ERROR
);
}
...
...
@@ -144,9 +144,9 @@ class PastisController {
@Secured
(
"ROLE_UPDATE_PROFILES"
)
@RequestMapping
(
value
=
"/getfile"
,
method
=
RequestMethod
.
GET
)
ResponseEntity
<
String
>
getFile
()
{
if
(
profileService
.
getFile
()
!=
null
)
{
return
ResponseEntity
.
ok
(
profileService
.
getFile
());
ResponseEntity
<
String
>
getFile
(
@RequestParam
(
name
=
"name"
)
String
filename
)
{
if
(
profileService
.
getFile
(
filename
)
!=
null
)
{
return
ResponseEntity
.
ok
(
profileService
.
getFile
(
filename
));
}
else
{
return
new
ResponseEntity
<>(
HttpStatus
.
INTERNAL_SERVER_ERROR
);
}
...
...
api/api-pastis/pastis/src/main/java/fr/gouv/vitamui/pastis/server/service/JsonFromPUA.java
View file @
cd520e6f
...
...
@@ -34,7 +34,7 @@ public class JsonFromPUA {
* @return
*/
public
ElementProperties
getProfileFromPUA
(
JSONObject
jsonPUA
)
throws
IOException
{
String
controlSchemaString
=
(
String
)
jsonPUA
.
get
(
"
C
ontrolSchema"
);
String
controlSchemaString
=
(
String
)
jsonPUA
.
get
(
"
c
ontrolSchema"
);
JSONObject
controlSchema
=
new
JSONObject
(
controlSchemaString
);
idCounter
=
0L
;
...
...
api/api-pastis/pastis/src/main/java/fr/gouv/vitamui/pastis/server/service/PastisService.java
View file @
cd520e6f
...
...
@@ -47,6 +47,8 @@ import fr.gouv.vitamui.pastis.common.dto.profiles.Notice;
import
fr.gouv.vitamui.pastis.common.dto.profiles.PastisProfile
;
import
fr.gouv.vitamui.pastis.common.dto.profiles.ProfileNotice
;
import
fr.gouv.vitamui.pastis.common.dto.profiles.ProfileResponse
;
import
fr.gouv.vitamui.pastis.common.dto.profiles.ProfileType
;
import
fr.gouv.vitamui.pastis.common.util.NoticeUtils
;
import
fr.gouv.vitamui.pastis.common.util.PastisCustomCharacterEscapeHandler
;
import
fr.gouv.vitamui.pastis.common.util.PastisGetXmlJsonTree
;
import
fr.gouv.vitamui.pastis.common.util.PastisSAX2Handler
;
...
...
@@ -181,9 +183,9 @@ public class PastisService {
}
public
String
getFile
()
{
public
String
getFile
(
String
filename
)
{
InputStream
rngFile
=
getClass
().
getClassLoader
().
getResourceAsStream
(
"rng/
AUP_default_PASTIS.json"
);
InputStream
rngFile
=
getClass
().
getClassLoader
().
getResourceAsStream
(
"rng/
"
+
filename
);
if
(
rngFile
!=
null
)
{
return
rngFile
.
toString
();
}
else
{
...
...
@@ -213,46 +215,37 @@ public class PastisService {
return
getJson
.
getJsonParsedTree
(
handler
.
elementRNGRoot
);
}
public
ProfileResponse
loadProfile
(
String
id
)
throws
JsonProcessingException
{
public
ProfileResponse
loadProfile
(
Notice
notice
)
throws
JsonProcessingException
{
PastisSAX2Handler
handler
=
new
PastisSAX2Handler
();
PastisGetXmlJsonTree
getJson
=
new
PastisGetXmlJsonTree
();
/* PastisProfile profileToEdit;
ProfileResponse profileResponse = new ProfileResponse();*/
Notice
profileToEdit
;
ProfileResponse
profileResponse
=
new
ProfileResponse
();
try
{
profileToEdit
=
notices
.
stream
()
.
filter
(
p
->
p
.
getId
().
equals
(
id
))
.
collect
(
Collectors
.
toList
()).
get
(
0
);
InputStream
inputStream
=
getClass
().
getClassLoader
().
getResourceAsStream
(
"rng/"
+
profileToEdit
.
getPath
());
InputSource
inputSource
=
new
InputSource
(
inputStream
);
profileResponse
.
setId
(
profileToEdit
.
getId
());
profileResponse
.
setType
(
profileToEdit
.
getFileType
(
profileToEdit
.
getPath
()));
profileResponse
.
setName
(
profileToEdit
.
getIdentifier
());
if
(
profileResponse
.
getType
().
equals
(
"PA"
))
{
profileResponse
.
setId
(
notice
.
getId
());
profileResponse
.
setType
(
NoticeUtils
.
getFileType
(
notice
));
profileResponse
.
setName
(
notice
.
getIdentifier
());
String
s
=
notice
.
serialiseString
();
JSONObject
profileJson
=
new
JSONObject
(
s
);
if
(
NoticeUtils
.
getFileType
(
notice
).
equals
(
ProfileType
.
PA
))
{
InputStream
inputStream
=
getClass
().
getClassLoader
().
getResourceAsStream
(
"rng/"
+
notice
.
getPath
());
InputSource
inputSource
=
new
InputSource
(
inputStream
);
XMLReader
xmlReader
=
XMLReaderFactory
.
createXMLReader
();
xmlReader
.
setContentHandler
(
handler
);
xmlReader
.
parse
(
inputSource
);
profileResponse
.
setProfile
(
getJson
.
getJsonParsedTree
(
handler
.
elementRNGRoot
));
LOGGER
.
info
(
"Starting editing Archive Profile with id : {}"
,
id
);
}
else
if
(
profileToEdit
.
getPath
().
equals
(
"PUA"
))
{
JSONTokener
tokener
=
new
JSONTokener
(
new
InputStreamReader
(
inputStream
));
JSONObject
profileJson
=
new
JSONObject
(
tokener
);
LOGGER
.
info
(
"Starting editing Archive Profile with id : {}"
,
notice
.
getId
());
}
else
if
(
NoticeUtils
.
getFileType
(
notice
).
equals
(
ProfileType
.
PUA
))
{
puaPastisValidator
.
validatePUA
(
profileJson
);
profileResponse
.
setProfile
(
jsonFromPUA
.
getProfileFromPUA
(
profileJson
));