Skip to content

Commit

Permalink
v.1.10.2 - Upload Zip
Browse files Browse the repository at this point in the history
Test
  • Loading branch information
damikael committed Oct 25, 2023
2 parents 8c9c10a + 8708bd3 commit 8483ce0
Show file tree
Hide file tree
Showing 18 changed files with 838 additions and 44 deletions.
4 changes: 2 additions & 2 deletions spid-validator/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
"file-loader": "1.1.6",
"html-loader": "0.5.4",
"html-webpack-plugin": "2.30.1",
"node-sass": "^4.13.1",
"sass": "1.35.2",
"rimraf": "2.6.2",
"sass-loader": "6.0.6",
"sass-loader": "^7.3.1",
"source-list-map": "2.0.0",
"style-loader": "0.19.1",
"uglify-js": "3.3.7",
Expand Down
25 changes: 22 additions & 3 deletions spid-validator/client/src/components/AceEditor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,32 @@ class AceEditor extends Component {

constructor(props) {
super(props);
this.state = {code: format((props.code!=null)? props.code:"")};
this.state = {
mode: 'xml',
code: ""
};
}

static getDerivedStateFromProps(props, state) {
Utility.log("State", props.code)

let mode = props.mode;
let code = props.code;

switch(props.mode) {
case 'json':
code = JSON.stringify(props.code, null, 4);
break;

case 'xml':
default:
mode = 'xml';
code = format((props.code!=null)? props.code : "");
break;
}

return {
code: format((props.code!=null)? props.code:"")
code: code,
mode: mode
}
}

Expand Down
4 changes: 3 additions & 1 deletion spid-validator/client/src/components/AceEditor/view.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import React from 'react';
import AceEditor from 'react-ace';
import 'brace/mode/xml';
import 'brace/mode/json';
import 'brace/theme/cobalt';
import "./style.css";

function view(me) {

return(
<AceEditor
mode="xml"
mode={me.state.mode}
theme="cobalt"
name="AceEditor"
className="AceEditor"
defaultValue={me.state.code}
value={me.state.code}
readOnly={true}
maxLines={10000}
showPrintMargin={false}
wrapEnabled={true}
editorProps={{$blockScrolling: true}}
/>
Expand Down
15 changes: 14 additions & 1 deletion spid-validator/client/src/components/Sidebar/_nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default {
sessionRequired: false,
children: [
{
name: 'Download',
name: 'Download from URL',
url: '/metadata-sp-download',
sessionRequired: false,
},
Expand Down Expand Up @@ -35,6 +35,19 @@ export default {
}
]
},
{
name: 'Pacchetto ZIP',
icon: 'icon-folder',
open: true,
sessionRequired: false,
children: [
{
name: 'Upload ZIP',
url: '/metadata-sp-upload-zip',
sessionRequired: false,
}
]
},
{
name: 'Request',
icon: 'icon-cursor',
Expand Down
4 changes: 3 additions & 1 deletion spid-validator/client/src/containers/Main/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Breadcrumb from '../../components/Breadcrumb/';
import Aside from '../../components/Aside/';
import Footer from '../../components/Footer/';
import MetadataSpDownload from '../../views/MetadataSpDownload/';
import MetadataSpUploadZip from '../../views/MetadataSpUploadZip/';
import MetadataSpCheck from '../../views/MetadataSpCheck/';
import Request from '../../views/Request/';
import RequestCheck from '../../views/RequestCheck/';
Expand Down Expand Up @@ -158,7 +159,8 @@ class Main extends Component {
<Breadcrumb />
<Container fluid>
<Switch>
<Route path="/metadata-sp-download" name="Metadata Service Provider / Download" component={MetadataSpDownload}/>
<Route path="/metadata-sp-download" name="Metadata Service Provider / Download from URL" component={MetadataSpDownload}/>
<Route path="/metadata-sp-upload-zip" name="Metadata Service Provider / Upload from ZIP" component={MetadataSpUploadZip}/>
<Route path="/metadata-sp-check-xsd" key="metadata-sp-check-xsd" render={()=><MetadataSpCheck test="xsd" />} />
<Route path="/metadata-sp-check-strict" key="metadata-sp-check-strict" render={()=><MetadataSpCheck test="strict" />} />
<Route path="/metadata-sp-check-certs" key="metadata-sp-check-certs" render={()=><MetadataSpCheck test="certs" />} />
Expand Down
1 change: 1 addition & 0 deletions spid-validator/client/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ ReactDOM.render((
<HashRouter>
<Switch>
<Route path="/metadata-sp-download" component={Main}/>
<Route path="/metadata-sp-upload-zip" component={Main}/>
<Route path="/metadata-sp-check-xsd" component={Main}/>
<Route path="/metadata-sp-check-strict" component={Main}/>
<Route path="/metadata-sp-check-certs" component={Main}/>
Expand Down
3 changes: 2 additions & 1 deletion spid-validator/client/src/routes.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const routes = {
'/': 'Home',
'/metadata-sp-download': 'Metadata Service Provider / Download',
'/metadata-sp-download': 'Metadata Service Provider / Download from URL',
'/metadata-sp-upload-zip': 'Metadata Service Provider / Upload ZIP',
'/metadata-sp-checl-xsd': 'Metadata Service Provider / Check XSD',
'/metadata-sp-check-strict': 'Metadata Service Provider / Check Strict',
'/metadata-sp-check-certs': 'Metadata Service Provider / Check Certificates',
Expand Down
33 changes: 33 additions & 0 deletions spid-validator/client/src/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,39 @@ class MainService {
});
}

uploadFile(file, check, profile, production, callback_progress_upload, callback_progress_download, callback_response, callback_error) {
Utility.log("POST: /api/metadata-sp/upload/zip");
const formData = new FormData();
formData.append('file', file);
formData.append('check', check);
formData.append('profile', profile);
formData.append('production', production);
axios.post(' /api/metadata-sp/upload/zip?apikey=' + Utility.getApikey(), formData, {
headers: { 'Content-Type': 'multipart/form-data' },
onUploadProgress: (progressEvent)=>callback_progress_upload(progressEvent),
onDownloadProgress: (progressEvent)=>callback_progress_download(progressEvent)
})
.then(function(response) {
callback_response(response.data);
})
.catch(function(error) {
callback_error((error.response!=null) ? error.response.data : "Service not available");
});
}

setSessionMetadata(metadata, callback_response, callback_error) {
Utility.log("PUT /api/metadata-sp");
axios.put('/api/metadata-sp?apikey=' + Utility.getApikey(), {metadata: metadata})
.then(function(response) {
Utility.log("setSessionMetadata Success", response.data);
callback_response(response.data);
})
.catch(function(error) {
Utility.log("setSessionMetadata Error", error.response.data);
callback_error((error.response!=null) ? error.response.data : "Service not available");
});
}

getLastCheckMetadataSp(test, callback_response, callback_error) {
Utility.log("GET /api/metadata-sp/lastcheck/" + test);
axios.get('/api/metadata-sp/lastcheck/' + test + '?apikey=' + Utility.getApikey(), {timeout: 900000})
Expand Down
2 changes: 1 addition & 1 deletion spid-validator/client/src/views/MetadataSpDownload/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function view(me) {
<div className="col-sm-12">
<b>Metadata URL</b>
</div>
<div className="col-sm-12">
<div className="col-sm-12 mt-3">
<input type="text"
ref="inputMetadata"
className="metadata"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
import React, { Component } from 'react';
import view from "./view.js";
import Utility from '../../utility';
import Services from '../../services';
import ReduxStore from "../../redux/store";
import Actions from "../../redux/main/actions";


class MetadataSpUploadZip extends Component {

constructor(props) {
super(props);

this.state = {
detailview: false,
file: null,
loading: false,
loaded: false,
fileName: null,
fileSize: null,
fileType: null,
check: "extra",
profile: "spid-sp-ag-public-full",
production: true,
report: null
};
}

componentDidMount() {
let service = Services.getMainService();
let store = ReduxStore.getMain();
let storeState = store.getState();
}

render() {
return view(this);
}

setDetailView(detailed) {
this.setState({
detailview: detailed
});
}

setCheck(check) {
this.setState({
check: check
});
}

setProfile(profile) {
this.setState({
profile: profile
});
}

setProduction(production) {
this.setState({
production: production
});
this.setState({
production: production
}, ()=> {
this.uploadMetadataZip(this.state.file);
});
}


uploadMetadataZip(metadata_zip) {

let service = Services.getMainService();

this.setState({
file: metadata_zip,
loading: true,
loaded: false,
fileName: metadata_zip.name,
fileSize: metadata_zip.size,
fileType: metadata_zip.type,
report: null
});

Utility.blockUI(true);
service.uploadFile(
metadata_zip,
this.state.check,
this.state.profile,
this.state.production? 'Y':'N',

(progress)=> {
let progress_percent = Math.round((parseInt(progress.loaded)*100)/parseInt(progress.total));
if(progress_percent<100) {
this.setState({
progress_message: "Uploading ZIP file...",
progress: progress_percent + "%"
});
} else {
this.setState({
progress_message: "Validating all metadata. Please wait...",
progress: ""
});
}
},
(progress)=> {
let progress_percent = Math.round((parseInt(progress.loaded)*100)/parseInt(progress.total));
this.setState({
progress_message: "Downloading report...",
progress: progress_percent + '%'
});
},
(report)=> {
this.setState({
file: metadata_zip,
loading: false,
loaded: true,
progress: 0,
check: report.check,
profile: report.profile,
production: report.production,
report: report
});

Utility.blockUI(false);
},
(error)=> {
Utility.showModal({
title: "Errore",
body: error,
isOpen: true
});
this.setState({
file: null,
loading: false,
loaded: false,
fileName: null,
fileSize: null,
fileType: null,
check: "extra",
profile: "spid-sp-ag-public-full",
production: true,
report: null
});

Utility.blockUI(false);
}
);
}

openMetadata(metadata) {
let service = Services.getMainService();
let store = ReduxStore.getMain();

Utility.blockUI(true);
service.setSessionMetadata(metadata,
(success)=> {
store.dispatch(Actions.setMetadataSpURL(metadata.url));
store.dispatch(Actions.setMetadataSpXML(metadata.xml));
this.props.history.push('/metadata-sp-download');
Utility.blockUI(false);
},
(error)=> {
Utility.showModal({
title: "Errore",
body: error,
isOpen: true
});
Utility.blockUI(false);
}
);
}

print() {
Utility.print(this.state.fileName);
}

}

export default MetadataSpUploadZip;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "MetadataSpUploadZip",
"version": "0.0.0",
"private": true,
"main": "./MetadataSpUploadZip.js"
}
Loading

0 comments on commit 8483ce0

Please sign in to comment.