16be5d97badc8a36412d7d30bd8a01a780cba802
[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  *{
35  *    "node": "ddd",
36  *    "filter": [
37  *    {
38  *        "definition": {
39  *            "object-id-ref": "",
40  *            "problem": ""
41  *        },
42  *        "description": "",
43  *        "start": "2019-11-26T15:37+00:00",
44  *        "end": "2019-11-26T23:37+00:00"
45  *    }],
46  *    "active": false
47  *}
48  *  =>
49  *{
50  *    "id": "sim1"
51  *    "node-id": "sim1",
52  *    "description": "",
53  *    "start": "2020-01-28T12:00:17.6Z",
54  *    "end": "2020-01-28T12:00:17.6Z",
55  *    "active": false,
56  *    "object-id-ref": "",
57  *    "problem": ""
58  *
59  */
60 public class FrankfurtMaintenanceConverter extends BaseSearchHitConverter {
61
62         public FrankfurtMaintenanceConverter() {
63                 super(ComponentName.MAINTENANCE);
64         }
65
66         @Override
67         public SearchHit convert(SearchHit source) {
68
69                 JSONObject src = source.getSource();
70                 JSONObject data = new JSONObject();
71                 data.put("id", src.getString("node"));
72                 data.put("node-id", src.getString("node"));
73                 data.put("active", src.getBoolean("active"));
74                 JSONObject filter = null;
75                 if (src.has("filter")) {
76                         filter = src.getJSONArray("filter").length() > 0 ? src.getJSONArray("filter").getJSONObject(0) : null;
77                 }
78                 data.put("start", filter != null ? filter.getString("start") : "");
79                 data.put("end", filter != null ? filter.getString("end") : "");
80                 data.put("description", filter != null ? filter.getString("description") : "");
81                 JSONObject definition = filter!=null?filter.has("definition")?filter.getJSONObject("definition"):null:null;
82                 data.put("problem", definition!=null?definition.getString("problem"):"");
83                 data.put("object-id-ref", definition!=null?definition.getString("object-id-ref"):"");
84                 return this.getSearchHit(source.getIndex(), source.getType(), source.getId(), data);
85         }
86 }