import React, {Component} from 'react'; import ListGroupItem from 'react-bootstrap/lib/ListGroupItem.js'; import ListGroup from 'react-bootstrap/lib/ListGroup.js'; import Panel from 'react-bootstrap/lib/Panel.js'; import i18n from 'nfvo-utils/i18n/i18n.js'; /** * parsing and showing the following Java Response object * * public class ValidationResponse { private boolean valid = true; private Collection vspErrors; private Collection licensingDataErrors; private Map> uploadDataErrors; private Map> compilationErrors; private QuestionnaireValidationResult questionnaireValidationResult; } * public class ErrorCode { private String id; private String message; private ErrorCategory category; } * public class ErrorMessage { private final ErrorLevel level; private final String message; } */ class SubmitErrorResponse extends Component { render() { let {validationResponse} = this.props; return (
{validationResponse.vspErrors && this.renderVspErrors(validationResponse.vspErrors)} {validationResponse.licensingDataErrors && this.renderVspErrors(validationResponse.licensingDataErrors)} {validationResponse.compilationErrors && this.renderCompilationErrors(validationResponse.compilationErrors)} {validationResponse.uploadDataErrors && this.renderUploadDataErrors(validationResponse.uploadDataErrors)} {validationResponse.questionnaireValidationResult && this.renderQuestionnaireValidationResult(validationResponse.questionnaireValidationResult)}
); } renderVspErrors(vspErrors) { return ( {this.parseErrorCodeCollection(vspErrors)} ); } renderLicensingDataErrors(licensingDataErrors) { return ( {this.parseErrorCodeCollection(licensingDataErrors)} ); } renderUploadDataErrors(uploadDataErrors) { return ( {this.parseMapOfErrorMessagesList(uploadDataErrors)} ); } renderCompilationErrors(compilationErrors) { return ( {this.parseMapOfErrorMessagesList(compilationErrors)} ); } parseErrorCodeCollection(errors) { return ( {errors.map(error =>
{i18n('Category: ')}{error.category}
{i18n('Message: ')}{error.message}
)}
); } parseMapOfErrorMessagesList(errorMap) { return ( {Object.keys(errorMap).map(errorStringKey => {errorMap[errorStringKey].map(error =>
{i18n('Level: ')}{error.level}
{i18n('Message: ')}{error.message}
)}
)}
); } renderQuestionnaireValidationResult(questionnaireValidationResult) { if (!questionnaireValidationResult.valid) { return this.parseAndRenderCompositionEntityValidationData(questionnaireValidationResult.validationData); } } parseAndRenderCompositionEntityValidationData(validationData) { let {entityType, entityId, errors = [], subEntitiesValidationData = []} = validationData; return ( {errors.map(error =>
{error}
)}
{subEntitiesValidationData.map(subValidationData => this.parseAndRenderCompositionEntityValidationData(subValidationData))}
); } } export default SubmitErrorResponse;