Commit 9e86c915 authored by descamps's avatar descamps
Browse files

KDE - Add control identifier create notice PA / Modification Controller...

KDE - Add control identifier create notice PA / Modification Controller Service to put standalone mode / set tenant create profile linked to the context
parent 9a8a808c
......@@ -82,6 +82,8 @@ public class PuaPastisValidator {
private static final String CONTENT = "Content";
private static final String COMPLEX = "Complex";
private static final String REQUIRED = "required";
private static final String ID = "id";
private static final String SCHEMA = "$schema";
private JSONObject getProfileJsonExpected() {
if (profileJsonExpected == null) {
......@@ -124,28 +126,30 @@ 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());
if(!actualFieldList.contains("name") && !actualFieldList.contains("controlSchema")){
throw new AssertionError("Notice not contains the expected keys 'name' and 'controlSchema'");
}
}
// Next tests are controlling the ControlSchema
String controlSchemaString = pua.getString(CONTROLSCHEMA);
JSONObject controlSchemaActual = new JSONObject(controlSchemaString);
controlSchemaString = profileJson.getString(CONTROLSCHEMA);
JSONObject controlSchemaExpected = new JSONObject(controlSchemaString);
// Checking that the whole structure is respected. Doesn't care that the pua contains extended fields.
JSONAssert.assertEquals(controlSchemaExpected, controlSchemaActual, JSONCompareMode.LENIENT);
// Next tests are controlling the ControlSchema
String controlSchemaString = pua.getString(CONTROLSCHEMA);
JSONObject controlSchemaActual = new JSONObject(controlSchemaString);
controlSchemaString = profileJson.getString(CONTROLSCHEMA);
JSONObject controlSchemaExpected = new JSONObject(controlSchemaString);
if(standalone) {
// Checking that the whole structure is respected. Doesn't care that the pua contains extended fields.
JSONAssert.assertEquals(controlSchemaExpected, controlSchemaActual, JSONCompareMode.LENIENT);
// Checking that the definitions list is exactly the same as expected
JSONAssert.assertEquals(controlSchemaExpected.getJSONObject(DEFINITIONS),
controlSchemaActual.getJSONObject(DEFINITIONS), JSONCompareMode.STRICT);
// Checking that the definitions list is exactly the same as expected
JSONAssert.assertEquals(controlSchemaExpected.getJSONObject(DEFINITIONS),
controlSchemaActual.getJSONObject(DEFINITIONS), JSONCompareMode.STRICT);
// Checking that #management object is present and at the correct position
if (controlSchemaActual.has("patternProperties")) {
......@@ -167,6 +171,15 @@ public class PuaPastisValidator {
}
// #HAVEFUN
}
}
else{
if (!controlSchemaActual.has(ID)) {
throw new AssertionError("Missing 'id' key in 'controlSchema' object");
}
if (!controlSchemaActual.has(SCHEMA)) {
throw new AssertionError("Missing '$schema' key in controlSchema' object");
}
}
}
public JSONObject getDefinitionsFromExpectedProfile() {
......
......@@ -12,5 +12,6 @@
"tenant": 8,
"version": 1,
"fields": [
]
],
"type":"PUA"
}
......@@ -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);
}
}
......@@ -87,7 +87,7 @@ class PastisController {
@Secured(ServicesData.ROLE_GET_ARCHIVE_PROFILES)
@PostMapping(value = RestApi.PASTIS_DOWNLOAD_PUA, consumes = APPLICATION_JSON_UTF8, produces = MediaType.APPLICATION_JSON_VALUE)
ResponseEntity<String> getArchiveUnitProfile(@RequestBody final ProfileNotice json) throws TechnicalException {
String archiveUnitProfile = profileService.getArchiveUnitProfile(json);
String archiveUnitProfile = profileService.getArchiveUnitProfile(json, false);
if (archiveUnitProfile != null) {
return ResponseEntity.ok(archiveUnitProfile);
} else {
......@@ -112,8 +112,8 @@ class PastisController {
@Secured({ServicesData.ROLE_CREATE_ARCHIVE_PROFILES, ServicesData.ROLE_CREATE_PROFILES})
@PostMapping(value = RestApi.PASTIS_UPLOAD_PROFILE,
consumes = "multipart/form-data", produces = "application/json")
ResponseEntity<ProfileResponse> loadProfileFromFile(@RequestParam("file") MultipartFile file, @RequestParam("fileName") String fileName) throws NoSuchAlgorithmException, TechnicalException {
ProfileResponse profileResponse = profileService.loadProfileFromFile(file, fileName);
ResponseEntity<ProfileResponse> loadProfileFromFile(@RequestParam MultipartFile file, @RequestParam("fileName") String fileName) throws NoSuchAlgorithmException, TechnicalException {
ProfileResponse profileResponse = profileService.loadProfileFromFile(file,fileName, false);
if (profileResponse != null) {
return ResponseEntity.ok(profileResponse);
} else {
......
......@@ -146,9 +146,9 @@ public class PastisService {
}
public String getArchiveUnitProfile(final ProfileNotice json) throws TechnicalException {
public String getArchiveUnitProfile(final ProfileNotice json, final boolean standalone) throws TechnicalException {
Notice notice = new Notice();
if (json.getNotice() != null) {
if (!standalone && json.getNotice() != null) {
notice = json.getNotice();
}
......@@ -215,7 +215,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));
......@@ -269,7 +269,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());
......@@ -285,7 +285,7 @@ public class PastisService {
return profileResponse;
}
public ProfileResponse loadProfileFromFile(MultipartFile file, String fileName) throws NoSuchAlgorithmException, TechnicalException {
public ProfileResponse loadProfileFromFile(MultipartFile file, String fileName, boolean standalone) throws NoSuchAlgorithmException, TechnicalException {
PastisSAX2Handler handler = new PastisSAX2Handler();
PastisGetXmlJsonTree getJson = new PastisGetXmlJsonTree();
......@@ -313,7 +313,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());
......
......@@ -12,5 +12,6 @@
"tenant": 8,
"version": 1,
"fields": [
]
],
"type": "PUA"
}
......@@ -159,7 +159,7 @@ public class ProfileInternalController {
public ProfileDto create(@Valid @RequestBody ProfileDto archivalProfile, @RequestHeader(value = CommonConstants.X_TENANT_ID_HEADER) Integer tenant) {
LOGGER.debug("create profile={}", archivalProfile);
final VitamContext vitamContext = securityService.buildVitamContext(securityService.getTenantIdentifier());
archivalProfile.setTenant(0);
archivalProfile.setTenant(vitamContext.getTenantId());
return profileInternalService.create(vitamContext, archivalProfile);
}
......
......@@ -259,6 +259,10 @@ export class ProfileService implements OnDestroy {
return this.puaService.getOne(id, headers);
}
getPaProfile(id: string, headers?: HttpHeaders): Observable<Profile> {
return this.paService.getOne(id, headers);
}
createProfile(path: string, type: string): Observable<ProfileResponse> {
const params = new HttpParams().set('type', type);
return this.apiService.get<ProfileResponse>(path, {params});
......
......@@ -166,6 +166,7 @@ export class PastisPopupOptionComponent implements OnInit, OnDestroy {
let retour;
if (result.success) {
retour = result.data;
console.log(retour.identifier + "identifier")
if (result.mode === 'PUA') {
console.log('je suis sur un enregistrement d\'un PUA');
......
......@@ -9,7 +9,7 @@
<div class="row">
<div class="col-10 form-control">
<vitamui-common-input *ngIf="modePUA" [disabled]="editNotice" (change)="checkIdentifier()" [(ngModel)]="notice.identifier" class="col-9 px-0"
<vitamui-common-input [disabled]="editNotice" (change)="checkIdentifier(modePUA)" [(ngModel)]="notice.identifier" class="col-9 px-0"
placeholder="identifier" formControlName="identifier">
</vitamui-common-input>
</div>
......
......@@ -99,7 +99,7 @@ export class CreateNoticeComponent implements OnInit {
this.modePUA = true;
}
this.information = 'texte d\'information';
const identifierForm = this.modePUA ? [null, Validators.required] : [null];
const identifierForm = [null, Validators.required];
this.form = this.formBuilder.group({
identifier: identifierForm,
intitule: [null, Validators.required],
......@@ -155,18 +155,31 @@ export class CreateNoticeComponent implements OnInit {
}
checkIdentifier() {
checkIdentifier(modePUA: boolean) {
if (this.notice.identifier.length !== 0) {
this.profileService.getPuaProfile(this.notice.identifier).subscribe(
() => {
alert('Identifier already exists use another identifier');
this.validate = false;
}, () => {
this.validate = true;
this.checkIntitule();
}
);
if(modePUA) {
this.profileService.getPuaProfile(this.notice.identifier).subscribe(
() => {
alert('Identifier already exists use another identifier');
this.validate = false;
}, () => {
this.validate = true;
this.checkIntitule();
}
);
}
else{
this.profileService.getPaProfile(this.notice.identifier).subscribe(
() => {
alert('Identifier already exists use another identifier');
this.validate = false;
}, () => {
this.validate = true;
this.checkIntitule();
}
);
}
} else {
this.validate = false;
}
......
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