blob: f2ec1582f31624f723c5bc0e18780b92cdb99acf [file] [log] [blame]
Michael Landoefa037d2017-02-19 12:57:33 +02001import React, {Component} from 'react';
2import ListGroupItem from 'react-bootstrap/lib/ListGroupItem.js';
3import ListGroup from 'react-bootstrap/lib/ListGroup.js';
4import Panel from 'react-bootstrap/lib/Panel.js';
5import i18n from 'nfvo-utils/i18n/i18n.js';
6
7/**
8 * parsing and showing the following Java Response object
9 *
10 * public class ValidationResponse {
11 private boolean valid = true;
12 private Collection<ErrorCode> vspErrors;
13 private Collection<ErrorCode> licensingDataErrors;
14 private Map<String, List<ErrorMessage>> uploadDataErrors;
15 private Map<String, List<ErrorMessage>> compilationErrors;
16 private QuestionnaireValidationResult questionnaireValidationResult;
17 }
18
19 * public class ErrorCode {
20 private String id;
21 private String message;
22 private ErrorCategory category;
23 }
24
25 * public class ErrorMessage {
26 private final ErrorLevel level;
27 private final String message;
28 }
29 */
30class SubmitErrorResponse extends Component {
31
32
33 render() {
34 let {validationResponse} = this.props;
35 return (
36 <div className='submit-error-response-view'>
37 {validationResponse.vspErrors && this.renderVspErrors(validationResponse.vspErrors)}
38 {validationResponse.licensingDataErrors && this.renderVspErrors(validationResponse.licensingDataErrors)}
39 {validationResponse.compilationErrors && this.renderCompilationErrors(validationResponse.compilationErrors)}
40 {validationResponse.uploadDataErrors && this.renderUploadDataErrors(validationResponse.uploadDataErrors)}
41 {validationResponse.questionnaireValidationResult && this.renderQuestionnaireValidationResult(validationResponse.questionnaireValidationResult)}
42 </div>
43 );
44 }
45
46 renderVspErrors(vspErrors) {
47 return (
48 <Panel header={i18n('VSP Errors')} collapsible>{this.parseErrorCodeCollection(vspErrors)}</Panel>
49 );
50 }
51
52 renderLicensingDataErrors(licensingDataErrors) {
53 return (
54 <Panel
55 header={i18n('Licensing Data Errors')}
56 collapsible>{this.parseErrorCodeCollection(licensingDataErrors)}
57 </Panel>
58 );
59 }
60
61 renderUploadDataErrors(uploadDataErrors) {
62 return (
63 <Panel
64 header={i18n('Upload Data Errors')}
65 collapsible>{this.parseMapOfErrorMessagesList(uploadDataErrors)}
66 </Panel>
67 );
68 }
69
70 renderCompilationErrors(compilationErrors) {
71 return (
72 <Panel
73 header={i18n('Compilation Errors')}
74 collapsible>{this.parseMapOfErrorMessagesList(compilationErrors)}
75 </Panel>
76 );
77 }
78
79 parseErrorCodeCollection(errors) {
80 return (
81 <ListGroup>{errors.map(error =>
82 <ListGroupItem className='error-code-list-item'>
83 <div><span>{i18n('Category: ')}</span>{error.category}</div>
84 <div><span>{i18n('Message: ')}</span>{error.message}</div>
85 </ListGroupItem>
86 )}</ListGroup>
87 );
88 }
89
90 parseMapOfErrorMessagesList(errorMap) {
91 return (
92 <ListGroup>
93 {Object.keys(errorMap).map(errorStringKey =>
94 <Panel header={errorStringKey} collapsible>
95 <ListGroup>{errorMap[errorStringKey].map(error =>
96 <ListGroupItem className='error-code-list-item'>
97 <div><span>{i18n('Level: ')}</span>{error.level}</div>
98 <div><span>{i18n('Message: ')}</span>{error.message}</div>
99 </ListGroupItem>
100 )}</ListGroup>
101 </Panel>
102 )}
103 </ListGroup>
104 );
105 }
106
107
108 renderQuestionnaireValidationResult(questionnaireValidationResult) {
109 if (!questionnaireValidationResult.valid) {
110 return this.parseAndRenderCompositionEntityValidationData(questionnaireValidationResult.validationData);
111 }
112 }
113
114 parseAndRenderCompositionEntityValidationData(validationData) {
115 let {entityType, entityId, errors = [], subEntitiesValidationData = []} = validationData;
116 return (
117 <ListGroup>
118 <Panel header={`${entityType}: ${entityId}`} collapsible>
119 <ListGroup>{errors.map(error =>
120 <ListGroupItem className='error-code-list-item'>
121 <div>{error}</div>
122 </ListGroupItem>
123 )}</ListGroup>
124 {subEntitiesValidationData.map(subValidationData => this.parseAndRenderCompositionEntityValidationData(subValidationData))}
125 </Panel>
126 </ListGroup>
127 );
128 }
129
130
131}
132
133export default SubmitErrorResponse;