69b9a9934ef4c12d046147ad687e17cdc76b1d7d
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk features
4  * ================================================================================
5  * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
6  * All rights reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  *
21  */
22 package org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.elalto;
23
24 import org.json.JSONObject;
25 import org.onap.ccsdk.features.sdnr.wt.common.database.SearchHit;
26 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.BaseSearchHitConverter;
27 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.ComponentName;
28
29 /**
30  * convert maintenance object from el alto version to frankfurt
31  * 
32  * @author jack
33  *
34  *         { "node": "ddd", "filter": [ { "definition": { "object-id-ref": "", "problem": "" }, "description": "",
35  *         "start": "2019-11-26T15:37+00:00", "end": "2019-11-26T23:37+00:00" }], "active": false } => { "id": "sim1"
36  *         "node-id": "sim1", "description": "", "start": "2020-01-28T12:00:17.6Z", "end": "2020-01-28T12:00:17.6Z",
37  *         "active": false, "object-id-ref": "", "problem": ""
38  *
39  */
40 public class FrankfurtMaintenanceConverter extends BaseSearchHitConverter {
41
42     public FrankfurtMaintenanceConverter() {
43         super(ComponentName.MAINTENANCE);
44     }
45
46     @Override
47     public SearchHit convert(SearchHit source) {
48
49         JSONObject src = source.getSource();
50         JSONObject data = new JSONObject();
51         data.put("id", src.getString("node"));
52         data.put("node-id", src.getString("node"));
53         data.put("active", src.getBoolean("active"));
54         JSONObject filter = null;
55         if (src.has("filter")) {
56             filter = src.getJSONArray("filter").length() > 0 ? src.getJSONArray("filter").getJSONObject(0) : null;
57         }
58         data.put("start", filter != null ? filter.getString("start") : "");
59         data.put("end", filter != null ? filter.getString("end") : "");
60         data.put("description", filter != null ? filter.getString("description") : "");
61         JSONObject definition =
62                 filter != null ? filter.has("definition") ? filter.getJSONObject("definition") : null : null;
63         data.put("problem", definition != null ? definition.getString("problem") : "");
64         data.put("object-id-ref", definition != null ? definition.getString("object-id-ref") : "");
65         return this.getSearchHit(source.getIndex(), source.getType(), source.getId(), data);
66     }
67 }