Commit 5fa0438d authored by toulemonde's avatar toulemonde
Browse files

Merge branch 'feat/211#321' into 'fix/sprint4_150322'

Ajout des fonctionnalités manquante

See merge request !72
parents a8c33e66 e33ca2bc
......@@ -51,7 +51,7 @@ import java.util.stream.Stream;
@NoArgsConstructor
public class ElementProperties {
private String additionalProperties;
private boolean additionalProperties;
private String name;
private String type;
private String cardinality;
......@@ -60,6 +60,7 @@ public class ElementProperties {
private String dataType;
private String value;
private String documentation;
private String editName;
@JsonIgnore
private Object sedaData;
......
......@@ -39,7 +39,6 @@ package fr.gouv.vitamui.pastis.common.dto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.gouv.vitamui.pastis.common.dto.factory.RngTagFactory;
import fr.gouv.vitamui.pastis.common.util.RNGConstants;
import lombok.Data;
import lombok.Getter;
......@@ -91,7 +90,19 @@ public class ElementRNG {
public static void setDocumentationForParentElement(ElementProperties parentNode, ElementRNG node) {
if (null != parentNode.getType() &&
RNGConstants.MetadaDataType.ELEMENT.getLabel().equals(parentNode.getType())) {
parentNode.setDocumentation(node.getValue());
if(parentNode.getName() != null && parentNode.getName().equals("ArchiveUnit")
&& node.getValue().contains("Commentaire : ")){
parentNode.setDocumentation(node.getValue().replace("Commentaire : ", ""));
if(parentNode.getDocumentation() != null ){
parentNode.setEditName(parentNode.getDocumentation());
}
}else{
if(parentNode.getDocumentation() != null ){
parentNode.setEditName(node.getValue());
}else{
parentNode.setDocumentation(node.getValue());
}
}
} else {
setDocumentationForParentElement(parentNode.getParent(), node);
}
......
......@@ -77,6 +77,8 @@ public class BaliseXML {
private static BaliseXML elementOrAttributeRNG;
private static AnnotationXML annotationXML;
private static DocumentationXML documentationXML;
private static AnnotationXML annotationCommentXML;
private static DocumentationXML documentationCommentXML;
public static BaliseXML getBaliseXMLStatic() {
return baliseXMLStatic;
......@@ -96,6 +98,8 @@ public class BaliseXML {
elementOrAttributeRNG = null;
annotationXML = null;
documentationXML = null;
annotationCommentXML = null;
documentationCommentXML = null;
setValueAndDataRNG(node);
// Set annotation and documentation tags (if exists)
......@@ -161,13 +165,9 @@ public class BaliseXML {
}
private static void setDocumentationAnnotationElementAttribute(ElementProperties node){
// Set annotation and documentation tags (if exists)
if (null != node.getDocumentation()) {
annotationXML = new AnnotationXML();
documentationXML = new DocumentationXML();
documentationXML.setDocumentation(node.getDocumentation());
annotationXML.setDocumentationXML(documentationXML);
}
setAnnotationDocumentationXML(node);
if (null != node.getType() && !node.getType().equals(UNDEFINED)) {
if (node.getType().equals("element")) {
elementOrAttributeRNG = new ElementXML();
......@@ -179,12 +179,38 @@ public class BaliseXML {
}
}
if (null != documentationXML && elementOrAttributeRNG != null) {
elementOrAttributeRNG.getChildren().add(annotationXML);
annotationXML.setParent(elementOrAttributeRNG);
if (elementOrAttributeRNG != null) {
if(null != documentationXML){
elementOrAttributeRNG.getChildren().add(annotationXML);
annotationXML.setParent(elementOrAttributeRNG);
}
if(annotationCommentXML != null){
elementOrAttributeRNG.getChildren().add(annotationCommentXML);
annotationCommentXML.setParent(elementOrAttributeRNG);
}
}
}
public static void setAnnotationDocumentationXML(ElementProperties node) {
// Set annotation and documentation tags (if exists)
if (null != node.getDocumentation()) {
annotationXML = new AnnotationXML();
documentationXML = new DocumentationXML();
documentationXML.setDocumentation(node.getDocumentation());
annotationXML.setDocumentationXML(documentationXML);
}
if(node.getName().equals("ArchiveUnit") && node.getEditName() != null){
annotationCommentXML = new AnnotationXML();
documentationCommentXML = new DocumentationXML();
documentationCommentXML.setDocumentation(node.getEditName());
annotationCommentXML.setDocumentationXML(documentationCommentXML);
if(node.getDocumentation() != null){
documentationXML.setDocumentation("Commentaire : " + node.getDocumentation());
annotationXML.setDocumentationXML(documentationXML);
}
}
}
/**
* Set Cardinality to element or attribute Rng
* @param node
......
......@@ -70,7 +70,7 @@ public class PuaFromJSON {
// 2. Add type
controlSchema.put("type", TYPE);
// 3. Add additionProperties
controlSchema.put("additionalProperties", elementProperties.getAdditionalProperties());
controlSchema.put("additionalProperties", elementProperties.isAdditionalProperties());
// 4. Check if tree contains Management metadata
addPatternProperties(elementProperties, controlSchema);
List<ElementProperties> elementsForTree = puaPastisValidator.ignoreMetadata(elementProperties);
......
......@@ -124,16 +124,19 @@ public class PuaPastisValidator {
* @param pua The string containing the JSON file to be validated
* @throws AssertionError
*/
public void validatePUA(JSONObject pua) throws AssertionError {
public void validatePUA(JSONObject pua, boolean standalone) throws AssertionError {
JSONObject profileJson = getProfileJsonExpected();
// Compare list of field at the root level
Set<String> actualFieldList = pua.keySet().stream().collect(toSet());
Set<String> expectedFieldList = profileJson.keySet().stream().collect(Collectors.toSet());
if (!actualFieldList.equals(expectedFieldList)) {
throw new AssertionError("PUA field list does not contains the expected values");
if (!standalone) {
Set<String> actualFieldList = pua.keySet().stream().collect(toSet());
Set<String> expectedFieldList = profileJson.keySet().stream().collect(Collectors.toSet());
if (!actualFieldList.equals(expectedFieldList)) {
throw new AssertionError("PUA field list does not contains the expected values");
}
}
// Next tests are controlling the ControlSchema
String controlSchemaString = pua.getString(CONTROLSCHEMA);
JSONObject controlSchemaActual = new JSONObject(controlSchemaString);
......@@ -147,6 +150,11 @@ public class PuaPastisValidator {
JSONAssert.assertEquals(controlSchemaExpected.getJSONObject(DEFINITIONS),
controlSchemaActual.getJSONObject(DEFINITIONS), JSONCompareMode.STRICT);
// Checking that additionalProperties is present and is boolean
if (controlSchemaActual.has("additionalProperties") &&
!(controlSchemaActual.get("additionalProperties") instanceof Boolean)) {
throw new AssertionError("PUA additionalProperties field does not contains a boolean value");
}
// Checking that #management object is present and at the correct position
if (controlSchemaActual.has("patternProperties")) {
JSONObject patternProperties = controlSchemaActual.getJSONObject("patternProperties");
......@@ -327,7 +335,8 @@ public class PuaPastisValidator {
* @param pua
* @throws IOException
*/
private void retrieveAccumalatedJsonManagaementProperties(ElementProperties element, List<String> rulesMetadata, List<String> childrenToEncapsulate, List<String> rulesFound, JSONObject pua) throws IOException {
private void retrieveAccumalatedJsonManagaementProperties(ElementProperties element, List<String> rulesMetadata,
List<String> childrenToEncapsulate, List<String> rulesFound, JSONObject pua) throws IOException {
for (ElementProperties childElement : element.getChildren()) {
JSONObject childrenOfRule = sortedJSON();
JSONObject grandChildrenOfRule = sortedJSON();
......@@ -338,7 +347,8 @@ public class PuaPastisValidator {
SedaNode sedaElement = getSedaMetadata(childElement.getName());
// 1. Check special cases
if (checkSpecialCases(rulesMetadata, rulesFound, childElement, sedaElement)) continue;
if (checkSpecialCases(rulesMetadata, rulesFound, childElement, sedaElement))
continue;
getMetaDataFromSeda(childElement, ruleTypeMetadataDetails, sedaElement);
Map<String, PuaMetadataDetails> ruleTypeMetadataMap = new HashMap<>();
Map<String, PuaMetadataDetails> nonSpecialChildOfRule = new HashMap<>();
......@@ -350,7 +360,8 @@ public class PuaPastisValidator {
for (ElementProperties grandChild : childElement.getChildren()) {
SedaNode node = getSedaMetadata(grandChild.getName());
if (childrenToEncapsulate.contains(grandChild.getName())) {
childrenContainsGrandChildName(grandChildrenOfRule, ruleTypeMetadataDetails, requiredChildren, grandChild, node);
childrenContainsGrandChildName(grandChildrenOfRule, ruleTypeMetadataDetails, requiredChildren,
grandChild, node);
} else {
getMetaDataFromSeda(grandChild, nonSpecialChildOfRuleDetails, node);
nonSpecialChildOfRule.put(grandChild.getName(), nonSpecialChildOfRuleDetails);
......@@ -388,7 +399,8 @@ public class PuaPastisValidator {
* @param sedaElement
* @return
*/
private boolean checkSpecialCases(List<String> rulesMetadata, List<String> rulesFound, ElementProperties childElement, SedaNode sedaElement) {
private boolean checkSpecialCases(List<String> rulesMetadata, List<String> rulesFound,
ElementProperties childElement, SedaNode sedaElement) {
if (!rulesMetadata.contains(childElement.getName()) || sedaElement == null) {
return true;
}
......@@ -398,25 +410,31 @@ public class PuaPastisValidator {
return false;
}
/** put Required Non Special Children
/**
* put Required Non Special Children
*
* @param childElement
* @param requiredNonSpecialChildren
* @param ruleTypeMetadata
*/
private void putRequiredNonSpecialChildren(ElementProperties childElement, List<String> requiredNonSpecialChildren, JSONObject ruleTypeMetadata) {
private void putRequiredNonSpecialChildren(ElementProperties childElement, List<String> requiredNonSpecialChildren,
JSONObject ruleTypeMetadata) {
if (!requiredNonSpecialChildren.isEmpty()) {
ruleTypeMetadata.getJSONObject(childElement.getName())
.put(REQUIRED, requiredNonSpecialChildren);
}
}
/** Put Children into rules
/**
* Put Children into rules
*
* @param childrenOfRule
* @param grandChildrenOfRule
* @param propertiesRules
* @param requiredChildren
*/
private void putChildrenIntoRules(JSONObject childrenOfRule, JSONObject grandChildrenOfRule, JSONObject propertiesRules, List<String> requiredChildren) {
private void putChildrenIntoRules(JSONObject childrenOfRule, JSONObject grandChildrenOfRule,
JSONObject propertiesRules, List<String> requiredChildren) {
if (!grandChildrenOfRule.isEmpty()) {
JSONObject propretyOfItems = new JSONObject().put(PROPERTIES, grandChildrenOfRule);
propretyOfItems.put(REQUIRED, requiredChildren);
......@@ -435,7 +453,9 @@ public class PuaPastisValidator {
* @param node
* @throws JsonProcessingException
*/
private void childrenContainsGrandChildName(JSONObject grandChildrenOfRule, PuaMetadataDetails ruleTypeMetadataDetails, List<String> requiredChildren, ElementProperties grandChild, SedaNode node) throws JsonProcessingException {
private void childrenContainsGrandChildName(JSONObject grandChildrenOfRule,
PuaMetadataDetails ruleTypeMetadataDetails, List<String> requiredChildren, ElementProperties grandChild,
SedaNode node) throws JsonProcessingException {
PuaMetadataDetails childOfRuleDetails = new PuaMetadataDetails();
getMetaDataFromSeda(grandChild, childOfRuleDetails, node);
if (grandChild.getCardinality().equals("0-1") ||
......@@ -619,12 +639,13 @@ public class PuaPastisValidator {
puaMetadataDetails.setMinItems(0);
puaMetadataDetails.setMaxItems(1);
}
if(!sedaElement.getElement().equals(COMPLEX) && el.getPuaData() != null && el.getPuaData().getPattern() != null){
if (!sedaElement.getElement().equals(COMPLEX) && el.getPuaData() != null &&
el.getPuaData().getPattern() != null) {
puaMetadataDetails.setPattern(el.getPuaData().getPattern());
}
if(el.getPuaData() != null && el.getPuaData().getEnum() != null){
if (el.getPuaData() != null && el.getPuaData().getEnum() != null) {
puaMetadataDetails.setEnums(el.getPuaData().getEnum());
}else{
} else {
if (!sedaElement.getEnumeration().isEmpty() && el.getValue() == null) {
puaMetadataDetails.setEnums(sedaElement.getEnumeration());
}
......
......@@ -8,7 +8,7 @@
"lastUpdate": "2020-11-26T14:08:20.987",
"activationDate": "2016-12-10T00:00:00.000",
"deactivationDate": "2016-12-10T00:00:00.000",
"controlSchema": "{\"$schema\":\"http://json-schema.org/draft-04/schema\",\"type\":\"object\",\"additionalProperties\":false,\"definitions\":{\"pattern-simple-date\":{\"type\":\"string\",\"pattern\":\"[0-9]{4}-[0-9]{2}-[0-9]{2}\"},\"pattern-date\":{\"type\":\"string\",\"pattern\":\"^([0-8][0-9]{3}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01]))$\"}},\"properties\":{}}",
"controlSchema": "{\"$schema\":\"http://json-schema.org/draft-04/schema\",\"type\":\"object\",\"definitions\":{\"pattern-simple-date\":{\"type\":\"string\",\"pattern\":\"[0-9]{4}-[0-9]{2}-[0-9]{2}\"},\"pattern-date\":{\"type\":\"string\",\"pattern\":\"^([0-8][0-9]{3}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01]))$\"}},\"properties\":{}}",
"tenant": 8,
"version": 1,
"fields": [
......
......@@ -52,6 +52,6 @@ public class PuaPastisValidatorTest {
InputStream inputStreamPua = getClass().getClassLoader().getResourceAsStream(pathFile);
JSONTokener tokener = new JSONTokener(new InputStreamReader(inputStreamPua));
JSONObject profileJson = new JSONObject(tokener);
puaPastisValidator.validatePUA(profileJson);
puaPastisValidator.validatePUA(profileJson, false);
}
}
......@@ -149,7 +149,7 @@ class PastisController {
@PostMapping(value = RestApi.PASTIS_UPLOAD_PROFILE,
consumes = "multipart/form-data", produces = "application/json")
ResponseEntity<ProfileResponse> loadProfileFromFile(@RequestParam MultipartFile file) throws NoSuchAlgorithmException, TechnicalException {
ProfileResponse profileResponse = profileService.loadProfileFromFile(file);
ProfileResponse profileResponse = profileService.loadProfileFromFile(file, true);
if (profileResponse != null) {
return ResponseEntity.ok(profileResponse);
} else {
......
......@@ -113,7 +113,7 @@ class PastisController {
@PostMapping(value = RestApi.PASTIS_UPLOAD_PROFILE,
consumes = "multipart/form-data", produces = "application/json")
ResponseEntity<ProfileResponse> loadProfileFromFile(@RequestParam MultipartFile file) throws NoSuchAlgorithmException, TechnicalException {
ProfileResponse profileResponse = profileService.loadProfileFromFile(file);
ProfileResponse profileResponse = profileService.loadProfileFromFile(file, false);
if (profileResponse != null) {
return ResponseEntity.ok(profileResponse);
} else {
......
......@@ -208,7 +208,7 @@ public class PastisService {
profileResponse.setProfile(getJson.getJsonParsedTree(handler.getElementRNGRoot()));
LOGGER.info("Starting editing Archive Profile with id : {}", notice.getId());
} else if (fileType.equals(ProfileType.PUA)) {
puaPastisValidator.validatePUA(profileJson);
puaPastisValidator.validatePUA(profileJson, false);
profileResponse.setProfile(jsonFromPUA.getProfileFromPUA(profileJson));
}
profileResponse.setNotice(NoticeUtils.getNoticeFromPUA(profileJson));
......@@ -262,7 +262,7 @@ public class PastisService {
} else {
JSONTokener tokener = new JSONTokener(new InputStreamReader(fileInputStream));
JSONObject profileJson = new JSONObject(tokener);
puaPastisValidator.validatePUA(profileJson);
puaPastisValidator.validatePUA(profileJson, false);
profileResponse.setProfile(jsonFromPUA.getProfileFromPUA(profileJson));
profileResponse.setNotice(NoticeUtils.getNoticeFromPUA(profileJson));
LOGGER.info("Starting editing Archive Unit Profile with name : {}", resource.getFilename());
......@@ -278,7 +278,7 @@ public class PastisService {
return profileResponse;
}
public ProfileResponse loadProfileFromFile(MultipartFile file) throws NoSuchAlgorithmException, TechnicalException {
public ProfileResponse loadProfileFromFile(MultipartFile file, boolean standalone) throws NoSuchAlgorithmException, TechnicalException {
PastisSAX2Handler handler = new PastisSAX2Handler();
PastisGetXmlJsonTree getJson = new PastisGetXmlJsonTree();
......@@ -306,7 +306,7 @@ public class PastisService {
} else {
JSONTokener tokener = new JSONTokener(new InputStreamReader(fileInputStream));
JSONObject profileJson = new JSONObject(tokener);
puaPastisValidator.validatePUA(profileJson);
puaPastisValidator.validatePUA(profileJson, standalone);
profileResponse.setProfile(jsonFromPUA.getProfileFromPUA(profileJson));
profileResponse.setNotice(NoticeUtils.getNoticeFromPUA(profileJson));
LOGGER.info("Starting editing Archive Unit Profile with name : {}", file.getOriginalFilename());
......
......@@ -8,7 +8,7 @@
"lastUpdate": "2020-11-26T14:08:20.987",
"activationDate": "2016-12-10T00:00:00.000",
"deactivationDate": "2016-12-10T00:00:00.000",
"controlSchema": "{\"$schema\":\"http://json-schema.org/draft-04/schema\",\"type\":\"object\",\"additionalProperties\":false,\"definitions\":{\"pattern-simple-date\":{\"type\":\"string\",\"pattern\":\"[0-9]{4}-[0-9]{2}-[0-9]{2}\"},\"pattern-date\":{\"type\":\"string\",\"pattern\":\"^([0-8][0-9]{3}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01]))$\"}},\"properties\":{}}",
"controlSchema": "{\"$schema\":\"http://json-schema.org/draft-04/schema\",\"type\":\"object\",\"definitions\":{\"pattern-simple-date\":{\"type\":\"string\",\"pattern\":\"[0-9]{4}-[0-9]{2}-[0-9]{2}\"},\"pattern-date\":{\"type\":\"string\",\"pattern\":\"^([0-8][0-9]{3}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01]))$\"}},\"properties\":{}}",
"tenant": 8,
"version": 1,
"fields": [
......
......@@ -55,6 +55,9 @@ export class AppComponent implements OnInit {
}
ngOnInit() {
if (this.isStandalone) {
document.title = 'PASTIS';
}
}
}
......@@ -131,7 +131,8 @@ export class FileService implements OnDestroy {
if (nodeName === 'ArchiveUnit' && this.sedaDataArchiveUnit != undefined) {
// Alors on utilise la définition SEDA de l'ArchiveUnit mère..
sedaDataMatch = this.sedaDataArchiveUnit;
} else {
}
else {
// Sinon on recherche la définition SEDA dans l'arbre
sedaDataMatch = sedaData.find(seda => seda.Name === nodeName);
// sedaDataMatch = this.sedaService.getSedaNodeRecursively(sedaData[0],nodeName)
......
......@@ -89,12 +89,7 @@ export class ProfileService implements OnDestroy {
getAllProfiles(): void {
if (environment.standalone) {
this.getStandaloneProfiles().subscribe((profiles: ProfileDescription[]) => {
if (profiles) {
this.retrievedProfiles.next(profiles);
console.log('Profiles: ', this.retrievedProfiles);
}
});
this.getAllProfilesStandalone();
} else {
this.getAllProfilesVitam();
// return this.getAllProfilesPaginated(pageRequest);
......@@ -126,6 +121,21 @@ export class ProfileService implements OnDestroy {
return allProfilesPUA;
}
getAllProfilesStandalone(): void {
this.getStandaloneProfiles().subscribe((profiles: ProfileDescription[]) => {
if (profiles) {
for (const profile of profiles) {
if (profile.controlSchema) {
profile.type = 'PUA';
} else {
profile.type = 'PA';
}
}
this.retrievedProfiles.next(profiles);
}
});
}
getAllProfilesVitam(): void {
const profiles: ProfileDescription[] = [];
this.subscription3$ = this.getAllProfilesPUA().subscribe((profileListPUA: ProfileDescription[] ) => {
......
......@@ -45,6 +45,7 @@ export class ToggleSidenavService {
constructor() { }
isOpened = new BehaviorSubject<boolean>(true);
isPending = new BehaviorSubject<boolean>(false);
show() {
this.isOpened.next(true);
......@@ -54,4 +55,12 @@ export class ToggleSidenavService {
this.isOpened.next(false);
console.log('SideNav is closed');
}
showPending(){
this.isPending.next(true);
}
hidePending(){
this.isPending.next(false);
}
}
<div *ngIf="pending then loadingSpinner"></div>
<ng-template #loadingSpinner>
<div class="steackhouse">
<mat-spinner color="primary" class="vitamui-spinner x-large my-3"></mat-spinner>
</div>
</ng-template>
<ngx-ui-loader></ngx-ui-loader>
<button (click)="openSideNav()"
......
......@@ -2,7 +2,17 @@
@import "../../assets/css/mixins";
@import "../../assets/css/layout";
::ng-deep .vitamui-spinner.mat-progress-spinner circle, .vitamui-spinner .mat-spinner circle{
stroke: var(--vitamui-primary) !important;
}
.steackhouse{
display: block;
position: absolute;
right: 50%;
top: 30%;
z-index: 1000;
}
.pastis-btn-show-profile{
position: absolute;
......
......@@ -63,6 +63,8 @@ export class MainComponent implements OnInit, OnDestroy {
editProfileComponent: EditProfileComponent;
opened: boolean;
pending: boolean;
pendingSub: Subscription;
events: string[] = [];
uploadedProfileResponse: ProfileResponse;
......@@ -78,7 +80,10 @@ export class MainComponent implements OnInit, OnDestroy {
this.sideNavService.isOpened.subscribe(status => {
this.opened = status;
});
})
this.pendingSub = this.sideNavService.isPending.subscribe(status=>{
this.pending = status;
})
}
ngOnInit() {
......@@ -140,6 +145,7 @@ export class MainComponent implements OnInit, OnDestroy {
if (this._routeParamsSubscription != null) {
this._routeParamsSubscription.unsubscribe();
}
if(this.pendingSub) this.pendingSub.unsubscribe();
}
}
......@@ -100,6 +100,7 @@ export enum DateFormatType {
}
export interface FileNode {
editName?: string;
additionalProperties:boolean;
id: number;
parentId: number;
......@@ -116,6 +117,7 @@ export interface FileNode {
children: FileNode[];
parent: FileNode;
sedaData: SedaData;
nonEditFileNode ?: boolean;
puaData?: PuaData;
}
......
......@@ -44,9 +44,10 @@ export interface MetadataHeaders {
id: number;
nomDuChamp: string;
nomDuChampFr: string;
nomDuChampEdit: string;
type: string;
valeurFixe: string;
cardinalite: string[];
commentaire: string;
enumeration: string[];
}
\ No newline at end of file
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment