91fed715d734134743aae7f8d67dbb62aae1c2c8
[ccsdk/features.git] /
1 /*******************************************************************************
2  * ============LICENSE_START========================================================================
3  * ONAP : ccsdk feature sdnr wt
4  * =================================================================================================
5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6  * =================================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software distributed under the License
13  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14  * or implied. See the License for the specific language governing permissions and limitations under
15  * the License.
16  * ============LICENSE_END==========================================================================
17  ******************************************************************************/
18 /**
19  *
20  */
21 package org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.util;
22
23 import org.onap.ccsdk.features.sdnr.wt.base.netconf.util.NetconfTimeStamp;
24 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.DateAndTime;
25
26 /**
27  * Converts time stamps into internal format according to ONF1.2 and ISO 8601.
28  * @author herbert
29  *
30  */
31 public class InternalDateAndTime {
32
33     private static final NetconfTimeStamp NETCONFTIME_CONVERTER = NetconfTimeStamp.getConverter();
34
35     private static final InternalDateAndTime TESTPATTERN = new InternalDateAndTime("2017-01-01T00:00:00.0Z");
36     private static final String INITIALPATTERN = "0000-00-00T00:00:00.0Z";
37
38     String internalDateAndTime = INITIALPATTERN;
39
40     /**
41      * Static builder ONF1.2
42      * @param time in ONF1.2 yang format
43      * @return  InternalDateAndTime
44      */
45     public static InternalDateAndTime valueOf(DateAndTime time) {
46         return new InternalDateAndTime(time);
47     }
48
49     /**
50      * Static builder ONF1.0
51      * @param time in ONF1.0 yang format
52      * @return  InternalDateAndTime
53      */
54
55     public static InternalDateAndTime valueOf(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime time) {
56         return new InternalDateAndTime(time);
57     }
58
59     /**
60      * @return     Getter with String representation
61      */
62     public String getValue() {
63         return internalDateAndTime;
64     }
65
66     /*----------------------------------------------------------------
67      * Private constructors and functions
68      */
69
70     /**
71      * Convert ONF 1.2 DateAndTime to String
72      * @param time as input
73      */
74     private InternalDateAndTime(DateAndTime time) {
75         internalDateAndTime = NETCONFTIME_CONVERTER.getTimeStampFromNetconf(time.getValue());
76     }
77
78     /**
79      * Convert ONF 1.2 DateAndTime to String
80      * @param time as input
81      */
82     private InternalDateAndTime(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime time) {
83         if (time != null) {
84             internalDateAndTime = NETCONFTIME_CONVERTER.getTimeStampFromNetconf(time.getValue());
85         } else {
86             internalDateAndTime = INITIALPATTERN;
87         }
88     }
89
90     /**
91      * Setup static TEST
92      * @param internalDateAndTime
93      */
94     private InternalDateAndTime(String internalDateAndTime) {
95         this.internalDateAndTime = internalDateAndTime;
96     }
97
98     /**
99      * Get a testpattern
100      * @return testpattern
101      */
102     public static InternalDateAndTime getTestpattern() {
103         return TESTPATTERN;
104     }
105
106
107
108 }