2 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13 * or implied. See the License for the specific language governing
14 * permissions and limitations under the License.
16 import React, {Component} from 'react';
17 import ListGroupItem from 'react-bootstrap/lib/ListGroupItem.js';
18 import i18n from 'nfvo-utils/i18n/i18n.js';
19 import SVGIcon from 'sdc-ui/lib/react/SVGIcon.js';
20 import Icon from 'nfvo-components/icon/Icon.jsx';
21 import {Collapse} from 'react-bootstrap';
23 * parsing and showing the following Java Response object
25 * public class ValidationResponse {
26 private boolean valid = true;
27 private Collection<ErrorCode> vspErrors;
28 private Collection<ErrorCode> licensingDataErrors;
29 private Map<String, List<ErrorMessage>> uploadDataErrors;
30 private Map<String, List<ErrorMessage>> compilationErrors;
31 private QuestionnaireValidationResult questionnaireValidationResult;
34 * public class ErrorCode {
36 private String message;
37 private ErrorCategory category;
40 * public class ErrorMessage {
41 private final ErrorLevel level;
42 private final String message;
45 class SubmitErrorResponse extends Component {
49 let {validationResponse : {vspErrors, licensingDataErrors, questionnaireValidationResult, uploadDataErrors}} = this.props;
51 <div className='submit-error-response-view'>
52 {vspErrors && this.renderVspErrors(vspErrors)}
53 {licensingDataErrors && this.renderVspErrors(licensingDataErrors)}
54 {questionnaireValidationResult && this.renderComponentsErrors(questionnaireValidationResult)}
55 {uploadDataErrors && this.renderUploadDataErrors(uploadDataErrors)}
60 renderVspErrors(errors) {
62 <ErrorBlock errorType={i18n('VSP Errors')}>
64 {errors.length && errors.map(error=>{return (<ErrorMessage error={error.message}/>);})}
71 renderComponentsErrors(errors) {
73 <ErrorBlock errorType={i18n('Components Errors')}>
75 {errors.validationData.length && errors.validationData.map(item =>{ return (<ComponentError item={item}/>);})}
81 renderUploadDataErrors(uploadDataErrors) {
83 <ErrorBlock errorType={i18n('Upload Data Errors')}>
85 <UploadErrorList items={uploadDataErrors}/>
93 const ComponentError = ({item}) => {
97 <div className='component-name-header'>{item.entityName}</div>
98 {item.errors.map(error => {return(<ErrorMessage key={i++} error={error}/>);})}
103 function* entries(obj) {
104 for (let key of Object.keys(obj)) {
105 yield {header: key, list: obj[key]};
109 const UploadErrorList = ({items}) => {
110 let generator = entries(items);
114 for (let item of generator) {errors.push(
116 <div className='component-name-header'>{item.header}</div>
117 {item.list.map(error => <ErrorMessage key={i++} warning={error.level === 'WARNING'} error={error.message}/> )}
127 class ErrorBlock extends React.Component {
133 let {errorType, children} = this.props;
135 <div className='error-block'>
136 <ErrorHeader collapsed={this.state.collapsed} onClick={()=>{this.setState({collapsed: !this.state.collapsed});}} errorType={errorType}/>
137 <Collapse in={this.state.collapsed}>
145 const ErrorHeader = ({errorType, collapsed, onClick}) => {
147 <div onClick={onClick} className='error-block-header'>
148 <SVGIcon iconClassName={collapsed ? '' : 'right' } name='chevronDown'/>
154 const ErrorMessage = ({error, warning}) => {
156 <ListGroupItem className='error-code-list-item'>
157 <Icon image={warning ? 'warning' : 'error'} label={error}/>
162 export default SubmitErrorResponse;