Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • dad/cines-vitamui
1 result
Show changes
Showing
with 1122 additions and 964 deletions
......@@ -87,16 +87,12 @@ export class UserActionAddMetadataComponent implements OnInit {
}
);
this.fileService.nodeChange.subscribe(fileNode=>{this.fileNode = fileNode})
this.sedaData = this.sedaService.sedaRules[0];
this.sedaService.getSedaRules().subscribe((data: any) => {
this.sedaData = data[0];
this.sedaNodeFound = this.fileNode.sedaData;
this.allowedChildren = this.sedaService.findSelectableElementList(this.sedaNodeFound,this.fileNode)
.filter(e=>e.Element !== SedaElementConstants.attribute);
this.allowedChildrenNames = this.allowedChildren.map(e=>e.Name);
})
this.sedaNodeFound = this.fileNode.sedaData;
this.allowedChildren = this.sedaService.findSelectableElementList(this.sedaNodeFound,this.fileNode)
.filter(e=>e.Element !== SedaElementConstants.attribute);
this.allowedChildrenNames = this.allowedChildren.map(e=>e.Name);
// Subscribe observer to button status and
// set the inital state of the ok button to disabled
......@@ -133,6 +129,7 @@ export class UserActionAddMetadataComponent implements OnInit {
})
this.addedItems.length > 0 ? this.atLeastOneIsSelected = true : this.atLeastOneIsSelected = false
this.upateButtonStatusAndDataToSend();
this.allowedChildrenNames = new FilterByNamePipe().transform(this.allowedChildrenNames,this.filterName);
}
onAddSelectedElement(elementName: string){
......@@ -202,7 +199,6 @@ export class FilterByNamePipe implements PipeTransform {
transform(listOfNames: string[], nameToFilter: string): string[] {
if(!listOfNames) return null;
if(!nameToFilter) return listOfNames;
return listOfNames.filter(name => name.toLowerCase().indexOf(nameToFilter.toLowerCase()) >= 0);
}
}
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { DuplicateMetadataComponent } from './duplicate-metadata.component';
describe('DuplicateMetadataComponent', () => {
let component: DuplicateMetadataComponent;
let fixture: ComponentFixture<DuplicateMetadataComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ DuplicateMetadataComponent ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(DuplicateMetadataComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
import {Component, OnInit} from '@angular/core';
import {MatDialogRef} from "@angular/material/dialog";
import {PastisDialogConfirmComponent} from "../../shared/pastis-dialog/pastis-dialog-confirm/pastis-dialog-confirm.component";
import {PopupService} from "../../core/services/popup.service";
@Component({
selector: 'duplicate-metadata',
templateUrl: './duplicate-metadata.component.html',
styleUrls: ['./duplicate-metadata.component.css']
})
export class DuplicateMetadataComponent implements OnInit {
dataToSend: string;
constructor(public dialogRef: MatDialogRef<PastisDialogConfirmComponent>,
private popUpService: PopupService) {
}
ngOnInit(): void {
this.popUpService.setPopUpDataOnClose(this.dialogRef.componentInstance.dialogReceivedData.fileNode.name);
}
}
/*
Copyright © CINES - Centre Informatique National pour l'Enseignement Supérieur (2020)
Copyright © CINES - Centre Informatique National pour l'Enseignement Supérieur (2020)
[dad@cines.fr]
This software is a computer program whose purpose is to provide
a web application to create, edit, import and export archive
This software is a computer program whose purpose is to provide
a web application to create, edit, import and export archive
profiles based on the french SEDA standard
(https://redirect.francearchives.fr/seda/).
This software is governed by the CeCILL-C license under French law and
abiding by the rules of distribution of free software. You can use,
abiding by the rules of distribution of free software. You can use,
modify and/ or redistribute the software under the terms of the CeCILL-C
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
"http://www.cecill.info".
As a counterpart to the access to the source code and rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty and the software's author, the holder of the
economic rights, and the successive licensors have only limited
liability.
liability.
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
......@@ -28,9 +28,9 @@ that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL-C license and that you accept its terms.
......@@ -39,7 +39,6 @@ import { Component, OnInit } from '@angular/core';
import { ProfileService } from '../../core/services/profile.service';
import { FileService } from '../../core/services/file.service';
import { FileNode } from '../../profile/edit-profile/classes/file-node';
import { NoticeService } from '../../core/services/notice.service';
@Component({
selector: 'pastis-user-action-save-profile',
......@@ -50,38 +49,33 @@ export class UserActionSaveProfileComponent implements OnInit {
data: FileNode[] = [];
profileType:string;
constructor(private profileService: ProfileService, private fileService: FileService) { }
constructor(private profileService: ProfileService, private fileService: FileService, private noticeService: NoticeService) { }
ngOnInit() {}
ngOnInit() {
this.profileService.profileMode.subscribe(profileMode => {
this.profileType = profileMode});
}
saveProfileToFile() {
//Retrieve the current file tree data as a JSON
this.data = this.fileService.allData.getValue();
console.log("On export button saveProfileToFile with current data %o",this.fileService.nodeChange.getValue());
if (this.data) {
console.error("Profile type on: ", this.profileType )
console.debug("Profile type on: ", this.profileService.profileMode )
// Get Notice changement
let notice:any;
if(this.profileType === "PUA"){
this.noticeService.notice.subscribe(
if(this.profileService.profileMode === "PUA"){
this.fileService.notice.subscribe(
(value: any) => {
notice = value;
},
(error) => {
console.log(error)
}
}
)
}
// Send the retrieved JSON data to profile service
this.profileService.uploadFile(this.data,notice,this.profileType).subscribe(retrievedData => {
this.profileService.uploadFile(this.data,notice,this.profileService.profileMode).subscribe(retrievedData => {
console.log("Data profile service: " + retrievedData)
console.log('New updated data: ', this.data);
console.log('Data: ', retrievedData);
......@@ -93,8 +87,8 @@ export class UserActionSaveProfileComponent implements OnInit {
downloadFile(dataFile:any): void {
console.error("Profile mode : ", this.profileType)
let typeFile = this.profileType === "PA" ? 'application/xml' : 'application/json';
console.debug("Profile mode : ", this.profileService.profileMode)
let typeFile = this.profileService.profileMode === "PA" ? 'application/xml' : 'application/json';
const newBlob = new Blob([dataFile], { type: typeFile });
if (window.navigator && window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveOrOpenBlob(newBlob);
......@@ -103,7 +97,7 @@ export class UserActionSaveProfileComponent implements OnInit {
const data = window.URL.createObjectURL(newBlob);
const link = document.createElement('a');
link.href = data;
link.download = this.profileType === "PA" ? 'pastis_profile.rng' : 'pastis.json';
link.download = this.profileService.profileMode === "PA" ? 'pastis_profile.rng' : 'pastis.json';
// this is necessary as link.click() does not work on the latest firefox
link.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true, view: window }));
setTimeout( () => {
......
......@@ -54,9 +54,6 @@ export class UserActionUploadProfileComponent implements OnInit {
uploader: FileUploader = new FileUploader({url: URL});
fileToUpload: File = null;
//@Output()
//updatedData: EventEmitter<any> = new EventEmitter();
constructor(private profileService: ProfileService,private fileService: FileService) { }
ngOnInit() {
......@@ -75,7 +72,7 @@ export class UserActionUploadProfileComponent implements OnInit {
this.profileService.uploadProfile(formData).subscribe( fileData => {
if (fileData) {
console.log('File submited! : ', fileData);
this.fileService.updateFileTree(fileData);
this.fileService.updateTreeWithProfile(fileData);
}
});
}
......
......@@ -44,10 +44,11 @@ import { FilterByNamePipe } from './add-metadata/add-metadata.component';
import { UserActionSaveProfileComponent } from './save-profile/save-profile.component';
import { PastisMaterialModule } from '../material.module';
import { UserActionsDownloadDocComponent } from './download-doc/download-doc.component';
import { DuplicateMetadataComponent } from './duplicate-metadata/duplicate-metadata.component';
@NgModule({
declarations: [UserActionUploadProfileComponent,FilterByNamePipe, UserActionSaveProfileComponent, UserActionsDownloadDocComponent],
declarations: [UserActionUploadProfileComponent,FilterByNamePipe, UserActionSaveProfileComponent, UserActionsDownloadDocComponent, DuplicateMetadataComponent],
imports: [
CommonModule,
PastisMaterialModule,
......
......@@ -64,16 +64,6 @@
width: 100%;
}
.pastis-table-container {
position: absolute;
width: 80%;
left: 120px;
top: 359px;
margin-right: 120px;
/*Material*/
height: 100%;
}
.pastis-table {
width: 80%;
height: 612px;
......
/*
Copyright © CINES - Centre Informatique National pour l'Enseignement Supérieur (2020)
Copyright © CINES - Centre Informatique National pour l'Enseignement Supérieur (2020)
[dad@cines.fr]
This software is a computer program whose purpose is to provide
a web application to create, edit, import and export archive
This software is a computer program whose purpose is to provide
a web application to create, edit, import and export archive
profiles based on the french SEDA standard
(https://redirect.francearchives.fr/seda/).
This software is governed by the CeCILL-C license under French law and
abiding by the rules of distribution of free software. You can use,
abiding by the rules of distribution of free software. You can use,
modify and/ or redistribute the software under the terms of the CeCILL-C
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
"http://www.cecill.info".
As a counterpart to the access to the source code and rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty and the software's author, the holder of the
economic rights, and the successive licensors have only limited
liability.
liability.
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
......@@ -28,9 +28,9 @@ that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL-C license and that you accept its terms.
......@@ -38,4 +38,5 @@ knowledge of the CeCILL-C license and that you accept its terms.
export interface IEnvironment {
production: boolean;
apiServerUrl?: string;
standalone?: boolean;
}
/*
Copyright © CINES - Centre Informatique National pour l'Enseignement Supérieur (2020)
Copyright © CINES - Centre Informatique National pour l'Enseignement Supérieur (2020)
[dad@cines.fr]
This software is a computer program whose purpose is to provide
a web application to create, edit, import and export archive
This software is a computer program whose purpose is to provide
a web application to create, edit, import and export archive
profiles based on the french SEDA standard
(https://redirect.francearchives.fr/seda/).
This software is governed by the CeCILL-C license under French law and
abiding by the rules of distribution of free software. You can use,
abiding by the rules of distribution of free software. You can use,
modify and/ or redistribute the software under the terms of the CeCILL-C
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
"http://www.cecill.info".
As a counterpart to the access to the source code and rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty and the software's author, the holder of the
economic rights, and the successive licensors have only limited
liability.
liability.
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
......@@ -28,38 +28,30 @@ that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL-C license and that you accept its terms.
*/
// This file can be replaced during build by using the `fileReplacements` array.
// `ng build --prod` replaces `environment.ts` with `environment.prod.ts`.
// The list of file replacements can be found in `angular.json`.
import { Injectable } from '@angular/core';
import { BehaviorSubject, Observable } from 'rxjs';
import { NoticeProfile } from 'projects/pastis/src/app/profile/edit-profile/classes/profile-response';
import { FileService } from './file.service';
import{IEnvironment} from './IEnvironment'
@Injectable({
providedIn: 'root'
})
export class NoticeService {
export const environment: IEnvironment= {
production: false,
apiServerUrl: "http://localhost:80",
standalone: true,
};
notice = new BehaviorSubject<NoticeProfile>(null);
constructor(private fileService: FileService) {
}
getNotice(): Observable<NoticeProfile>{
this.fileService.notice.subscribe(
(value: any) => {
this.notice.next(value);
},
(error) => {
console.log(error)
}
);
return this.notice;
}
}
\ No newline at end of file
/*
* For easier debugging in development mode, you can import the following file
* to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`.
*
* This import should be commented out in production mode because it will have a negative impact
* on performance if an error is thrown.
*/
// import 'zone.js/dist/zone-error'; // Included with Angular CLI.
......@@ -43,7 +43,8 @@ import{IEnvironment} from './IEnvironment'
export const environment: IEnvironment= {
production: false,
apiServerUrl: "https://sandbox78.cines.fr:8051"
apiServerUrl: "https://dev.vitamui.com:8051",
standalone: false
};
/*
......
{
"compileOnSave": false,
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"resolveJsonModule": true,
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
......
......@@ -270,5 +270,82 @@
</profile>
<!-- End of Dev profile -->
<!-- Start of standalone profile -->
<profile>
<id>standalone</id>
<build>
<!-- Start of dev profile plugins -->
<plugins>
<!-- maven plugin resources-->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${build.directory}/classes/static/</outputDirectory>
<resources>
<resource>
<directory>../ui-frontend/target/www</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<!-- SpringBoot maven plugin-->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>build-info</id>
<goals>
<goal>build-info</goal>
</goals>
</execution>
<execution>
<id>spring-boot-repackage</id>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>true</executable>
<attach>false</attach> <!-- Need to use the original jar for integration-tests -->
<mainClass>fr.gouv.vitamui.pastis.PastisRestApplication</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>${project.basedir}/src/main/resources/application.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<!-- End of Dev profile -->
</profiles>
</project>
server:
host: localhost
port: 8080
scheme: http
management.endpoints.web.exposure.include: "*"
# Uncomment if you want to use you specific logback config.
#logging:
config: src/main/config/logback.xml
cors.allowed-origins: http://localhost:80
/*
Copyright © CINES - Centre Informatique National pour l'Enseignement Supérieur (2020)
Copyright © CINES - Centre Informatique National pour l'Enseignement Supérieur (2020)
[dad@cines.fr]
This software is a computer program whose purpose is to provide
a web application to create, edit, import and export archive
This software is a computer program whose purpose is to provide
a web application to create, edit, import and export archive
profiles based on the french SEDA standard
(https://redirect.francearchives.fr/seda/).
This software is governed by the CeCILL-C license under French law and
abiding by the rules of distribution of free software. You can use,
abiding by the rules of distribution of free software. You can use,
modify and/ or redistribute the software under the terms of the CeCILL-C
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
"http://www.cecill.info".
As a counterpart to the access to the source code and rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty and the software's author, the holder of the
economic rights, and the successive licensors have only limited
liability.
liability.
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
......@@ -28,9 +28,9 @@ that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL-C license and that you accept its terms.
......@@ -39,12 +39,15 @@ package fr.gouv.vitamui.pastis.configuration;
import fr.gouv.vitamui.pastis.model.profiles.PastisProfile;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.web.servlet.error.ErrorViewResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@Configuration
......@@ -64,4 +67,10 @@ public class PastisConfiguration {
}
};
}
@Bean
public ErrorViewResolver customErrorViewResolver() {
final ModelAndView redirectToIndexHtml = new ModelAndView("forward:/index.html", Collections.emptyMap(), HttpStatus.OK);
return (request, status, model) -> status == HttpStatus.NOT_FOUND ? redirectToIndexHtml : null;
}
}
/*
Copyright © CINES - Centre Informatique National pour l'Enseignement Supérieur (2020)
Copyright © CINES - Centre Informatique National pour l'Enseignement Supérieur (2020)
[dad@cines.fr]
This software is a computer program whose purpose is to provide
a web application to create, edit, import and export archive
This software is a computer program whose purpose is to provide
a web application to create, edit, import and export archive
profiles based on the french SEDA standard
(https://redirect.francearchives.fr/seda/).
This software is governed by the CeCILL-C license under French law and
abiding by the rules of distribution of free software. You can use,
abiding by the rules of distribution of free software. You can use,
modify and/ or redistribute the software under the terms of the CeCILL-C
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
"http://www.cecill.info".
As a counterpart to the access to the source code and rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty and the software's author, the holder of the
economic rights, and the successive licensors have only limited
liability.
liability.
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
......@@ -28,9 +28,9 @@ that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL-C license and that you accept its terms.
......@@ -45,6 +45,7 @@ import fr.gouv.vitamui.pastis.model.jaxb.*;
import fr.gouv.vitamui.pastis.model.profiles.PastisProfile;
import fr.gouv.vitamui.pastis.model.profiles.Notice;
import fr.gouv.vitamui.pastis.model.profiles.ProfileNotice;
import fr.gouv.vitamui.pastis.model.profiles.ProfileResponse;
import fr.gouv.vitamui.pastis.util.pua.JsonFromPUA;
import fr.gouv.vitamui.pastis.util.PastisCustomCharacterEscapeHandler;
import fr.gouv.vitamui.pastis.util.PastisGetXmlJsonTree;
......@@ -144,7 +145,7 @@ class ProfileController {
writer = new OutputStreamWriter(os, "UTF-8");
marshallerObj.marshal(eparentRng, writer);
response = new String (os.toByteArray(), "UTF-8");
response = os.toString("UTF-8");
} catch (IOException e1) {
e1.printStackTrace();
......@@ -189,7 +190,7 @@ class ProfileController {
}
@RequestMapping (value = "/createprofile", method = RequestMethod.GET)
ResponseEntity<String> createprofile() throws URISyntaxException {
ResponseEntity<ElementProperties> createprofile() throws URISyntaxException {
PastisSAX2Handler handler = new PastisSAX2Handler();
PastisGetXmlJsonTree getJson = new PastisGetXmlJsonTree();
......@@ -212,13 +213,12 @@ class ProfileController {
}
@RequestMapping (value = "/edit", method = RequestMethod.POST)
ResponseEntity<String> loadProfile(@RequestParam(name = "id") String id) throws JsonProcessingException {
ResponseEntity<ProfileResponse> loadProfile(@RequestParam(name = "id") String id) throws JsonProcessingException {
PastisSAX2Handler handler = new PastisSAX2Handler();
PastisGetXmlJsonTree getJson = new PastisGetXmlJsonTree();
PastisProfile profileToEdit;
String notice = null;
String parsedProfile = null;
ObjectMapper mapper = new ObjectMapper();
ProfileResponse profileResponse = new ProfileResponse();
try {
profileToEdit = pastisProfiles.stream()
.filter(p -> Long.toString(p.getId()).equals(id))
......@@ -228,21 +228,21 @@ class ProfileController {
profileToEdit.getFileName());
InputSource inputSource = new InputSource(inputStream);
if (profileToEdit.getType().equals("PA")) {
profileResponse.setId(profileToEdit.getId());
profileResponse.setType(profileToEdit.getType());
if (profileResponse.getType().equals("PA")) {
XMLReader xmlReader = XMLReaderFactory.createXMLReader();
xmlReader.setContentHandler(handler);
xmlReader.parse(inputSource);
parsedProfile = getJson.getJsonParsedTree(handler.elementRNGRoot);
profileResponse.setProfile(getJson.getJsonParsedTree(handler.elementRNGRoot));
LOGGER.info("Starting editing Archive Profile with id : {}", id);
} else if (profileToEdit.getType().equals("PUA")) {
JSONTokener tokener = new JSONTokener(new InputStreamReader(inputStream));
JSONObject profileJson = new JSONObject(tokener);
puaPastisValidator.validatePUA(profileJson);
ElementProperties profile = jsonFromPUA.getProfileFromPUA(profileJson);
parsedProfile = "[" + mapper.writeValueAsString(profile) + "]";
Notice noticeObject = noticeFromPUA.getNoticeFromPUA(profileJson);
notice = mapper.writeValueAsString(noticeObject);
LOGGER.info("Starting editing Archive Unit Profile with id : {}", id);
profileResponse.setProfile(jsonFromPUA.getProfileFromPUA(profileJson));
profileResponse.setNotice(noticeFromPUA.getNoticeFromPUA(profileJson));
}
} catch (SAXException | IOException e ) {
LOGGER.error("Failed to load profile with id : {}", id);
......@@ -251,45 +251,36 @@ class ProfileController {
LOGGER.error("Failed to load pua with id {} and error message {}", id, ae.getMessage());
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
JSONObject response = new JSONObject();
response.put("id", profileToEdit.getId());
response.put("profile", parsedProfile);
response.put("notice", notice);
return ResponseEntity.ok(response.toString());
return ResponseEntity.ok(profileResponse);
}
@RequestMapping (value = "/new", method = RequestMethod.POST,
consumes = "multipart/form-data", produces = "application/json")
ResponseEntity<String> loadProfileFromFile(@RequestParam MultipartFile file) {
ResponseEntity<ProfileResponse> loadProfileFromFile(@RequestParam MultipartFile file) {
PastisSAX2Handler handler = new PastisSAX2Handler();
PastisGetXmlJsonTree getJson = new PastisGetXmlJsonTree();
PastisProfile profileToEdit;
String notice = null;
String parsedProfile = null;
ObjectMapper mapper = new ObjectMapper();
ProfileResponse profileResponse = new ProfileResponse();
try {
String fileExtension = file.getOriginalFilename().split("\\.")[1];
profileResponse.setType(fileExtension.equals("rng") ? "PA":"PUA");
InputStream fileInputStream = file.getInputStream();
InputSource inputSource = new InputSource(file.getInputStream());
if (fileExtension.equals("rng")) {
if (profileResponse.getType().equals("PA")) {
XMLReader xmlReader = XMLReaderFactory.createXMLReader();
xmlReader.setContentHandler(handler);
xmlReader.parse(inputSource);
parsedProfile = getJson.getJsonParsedTree(handler.elementRNGRoot);
profileResponse.setProfile(getJson.getJsonParsedTree(handler.elementRNGRoot));
LOGGER.info("Starting editing Archive Profile from file : {}",file.getOriginalFilename());
} else if (fileExtension.equals("json")) {
} else {
JSONTokener tokener = new JSONTokener(new InputStreamReader(fileInputStream));
JSONObject profileJson = new JSONObject(tokener);
puaPastisValidator.validatePUA(profileJson);
ElementProperties profile = jsonFromPUA.getProfileFromPUA(profileJson);
parsedProfile = "[" + mapper.writeValueAsString(profile) + "]";
Notice noticeObject = noticeFromPUA.getNoticeFromPUA(profileJson);
notice = mapper.writeValueAsString(noticeObject);
profileResponse.setProfile(jsonFromPUA.getProfileFromPUA(profileJson));
profileResponse.setNotice(noticeFromPUA.getNoticeFromPUA(profileJson));
LOGGER.info("Starting editing Archive Unit Profile with name : {}", file.getOriginalFilename());
}
......@@ -301,19 +292,16 @@ class ProfileController {
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
JSONObject response = new JSONObject();
response.put("id", Math.abs(new Random().nextLong()) / 1000);
response.put("profile", parsedProfile);
response.put("notice", notice);
profileResponse.setId((Math.abs(new Random().nextLong()) / 1000));
return ResponseEntity.ok(response.toString());
return ResponseEntity.ok(profileResponse);
}
@RequestMapping (value = "/createprofilefromfile",
method = RequestMethod.POST,consumes = "multipart/form-data",
produces = "application/json")
ResponseEntity<String> createprofilefromfile(@RequestParam MultipartFile file ) {
ResponseEntity<?> createprofilefromfile(@RequestParam MultipartFile file ) {
PastisSAX2Handler handler = new PastisSAX2Handler();
PastisGetXmlJsonTree getJson = new PastisGetXmlJsonTree();
......@@ -326,9 +314,9 @@ class ProfileController {
return new ResponseEntity<>("Error while processing file : ", HttpStatus.INTERNAL_SERVER_ERROR);
} catch (SAXException e) {
if (e instanceof SAXParseException) {
return new ResponseEntity<>("Erreur lors du chargement du profil, ligne " + ((SAXParseException) e).getLineNumber() + " colonne " + ((SAXParseException) e).getColumnNumber() + ": " + e.getMessage() , HttpStatus.INTERNAL_SERVER_ERROR);
return ResponseEntity.badRequest().body("Erreur lors du chargement du profil, ligne " + ((SAXParseException) e).getLineNumber() + " colonne " + ((SAXParseException) e).getColumnNumber() + ": " + e.getMessage());
} else {
return new ResponseEntity<>("Error while processing file : ", HttpStatus.INTERNAL_SERVER_ERROR);
return ResponseEntity.badRequest().body("Error while processing file : ");
}
}
......
/*
* Copyright French Prime minister Office/SGMAP/DINSIC/Vitam Program (2019-2021)
*
* contact@programmevitam.fr
*
* This software is a computer program whose purpose is to implement a digital archiving back-office system managing
* high volumetry securely and efficiently.
*
* This software is governed by the CeCILL 2.1 license under French law and abiding by the rules of distribution of free
* software. You can use, modify and/ or redistribute the software under the terms of the CeCILL 2.1 license as
* circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license,
* users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the
* successive licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or
* developing or reproducing the software by the user in light of its specific status of free software, that may mean
* that it is complicated to manipulate, and that also therefore means that it is reserved for developers and
* experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the
* software's suitability as regards their requirements in conditions enabling the security of their systems and/or data
* to be ensured and, more generally, to use and operate it in the same conditions as regards security.
*
* The fact that you are presently reading this means that you have had knowledge of the CeCILL 2.1 license and that you
* accept its terms.
*/
package fr.gouv.vitamui.pastis.model.profiles;
import fr.gouv.vitamui.pastis.model.ElementProperties;
public class ProfileResponse {
Long id;
ElementProperties profile;
Notice notice;
String type;
public ElementProperties getProfile() {
return profile;
}
public void setProfile(ElementProperties profile) {
this.profile = profile;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Notice getNotice() {
return notice;
}
public void setNotice(Notice notice) {
this.notice = notice;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
/*
Copyright © CINES - Centre Informatique National pour l'Enseignement Supérieur (2020)
Copyright © CINES - Centre Informatique National pour l'Enseignement Supérieur (2020)
[dad@cines.fr]
This software is a computer program whose purpose is to provide
a web application to create, edit, import and export archive
This software is a computer program whose purpose is to provide
a web application to create, edit, import and export archive
profiles based on the french SEDA standard
(https://redirect.francearchives.fr/seda/).
This software is governed by the CeCILL-C license under French law and
abiding by the rules of distribution of free software. You can use,
abiding by the rules of distribution of free software. You can use,
modify and/ or redistribute the software under the terms of the CeCILL-C
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
"http://www.cecill.info".
As a counterpart to the access to the source code and rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty and the software's author, the holder of the
economic rights, and the successive licensors have only limited
liability.
liability.
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
......@@ -28,9 +28,9 @@ that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL-C license and that you accept its terms.
......@@ -61,24 +61,9 @@ public class PastisGetXmlJsonTree {
private static Logger LOGGER = LoggerFactory.getLogger(PastisGetXmlJsonTree.class);
public String getJsonParsedTree(ElementRNG elementRNGRoot) {
public ElementProperties getJsonParsedTree(ElementRNG elementRNGRoot) {
ElementRNG.buildElementPropertiesTree(elementRNGRoot,0, null);
ElementProperties eparent = ElementRNG.elementStaticRoot;
ObjectMapper mapper = new ObjectMapper();
String jsonString = "";
try {
jsonString = mapper.writeValueAsString(eparent);
} catch (JsonGenerationException e1) {
e1.printStackTrace();
} catch (JsonMappingException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
LOGGER.info("JSON file successfully generated");
return "["+jsonString+"]";
return ElementRNG.elementStaticRoot;
}
// Test an xml to json and a json to xml.
......