Refresh option in validation result page
[sdc.git] / openecomp-ui / src / sdc-app / onboarding / softwareProduct / validationResults / SoftwareProductValidationResultsViewActionHelper.js
1 /**
2  * Copyright (c) 2019 Vodafone Group
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 import RestAPIUtil from 'nfvo-utils/RestAPIUtil.js';
17 import Configuration from 'sdc-app/config/Configuration.js';
18 import { actionTypes } from './SoftwareProductValidationResultsViewConstants.js';
19
20 function encodeResultQueryData(requestId, endPoints) {
21     const query = [];
22     query.push('requestId=' + requestId);
23     endPoints.forEach(endPoint => {
24         query.push('endPoint=' + encodeURIComponent(endPoint));
25     });
26
27     return query.join('&');
28 }
29 function fetchVspValidationResults(requestId, endPoints) {
30     const restPrefix = Configuration.get('restPrefix');
31     const requestQuery = encodeResultQueryData(requestId, endPoints);
32     return RestAPIUtil.fetch(
33         `${restPrefix}/v1.0/externaltesting/executions?${requestQuery}`
34     );
35 }
36 function fetchVspChecks() {
37     const restPrefix = Configuration.get('restPrefix');
38     return RestAPIUtil.fetch(`${restPrefix}/v1.0/externaltesting/testcasetree`);
39 }
40 const SoftwareProductValidationResultsViewActionHelper = {
41     refreshValidationResults(dispatch, { requestId, endPoints }) {
42         return new Promise((resolve, reject) => {
43             fetchVspValidationResults(requestId, endPoints)
44                 .then(response => {
45                     dispatch({
46                         type: actionTypes.FETCH_VSP_RESULT,
47                         vspTestResults: response
48                     });
49                     resolve(response);
50                 })
51                 .catch(error => {
52                     reject(error);
53                 });
54         });
55     },
56     fetchVspChecks(dispatch) {
57         return new Promise((resolve, reject) => {
58             fetchVspChecks()
59                 .then(response => {
60                     dispatch({
61                         type: actionTypes.FETCH_VSP_CHECKS,
62                         vspChecks: response
63                     });
64                     resolve(response);
65                 })
66                 .catch(error => {
67                     reject(error);
68                 });
69         });
70     },
71     updateDisplayTestResultData(dispatch, { testResultToDisplay }) {
72         dispatch({
73             type: actionTypes.UPDATE_DISPLAY_TEST_RESULT_DATA,
74             testResultToDisplay: testResultToDisplay
75         });
76     }
77 };
78
79 export default SoftwareProductValidationResultsViewActionHelper;