Reformat sdnr devicemanager to ONAP code style
[ccsdk/features.git] / sdnr / wt / devicemanager / provider / src / main / java / org / onap / ccsdk / features / sdnr / wt / devicemanager / impl / util / InternalDateAndTime.java
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 package org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.util;
19
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.NetconfTimeStamp;
22 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.NetconfTimeStampImpl;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
24
25 /**
26  * Converts time stamps into internal format according to ONF1.2 and ISO 8601. To be replaced by NetconfTimeStampImpl
27  */
28 @Deprecated
29 public class InternalDateAndTime {
30
31     private static final String TESTPATTERNSTRING = "2017-01-01T00:00:00.0Z";
32     private static final String INITIALPATTERN = "0000-00-00T00:00:00.0Z";
33
34     private static final InternalDateAndTime TESTPATTERN = new InternalDateAndTime(TESTPATTERNSTRING);
35     private static final DateAndTime TESTPATTERN2 = new DateAndTime(TESTPATTERNSTRING);
36
37     private static final NetconfTimeStamp NETCONFTIME_CONVERTER = NetconfTimeStampImpl.getConverter();
38
39     /** Internal variable to hold the value, that is converted **/
40     private final String internalDateAndTime;
41
42     /**
43      * Static builder ONF1.0
44      * 
45      * @param time in ONF1.0 yang format
46      * @return InternalDateAndTime
47      */
48
49     public static InternalDateAndTime valueOf(
50             org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime time) {
51         return new InternalDateAndTime(time);
52     }
53
54     /**
55      * @return Getter with String representation
56      */
57     public String getValue() {
58         return internalDateAndTime;
59     }
60
61     /**
62      * Get a testpattern
63      * 
64      * @return testpattern
65      */
66     public static InternalDateAndTime getTestpattern() {
67         return TESTPATTERN;
68     }
69
70     /**
71      * @return DateAndTime testpattern
72      */
73     public static @Nullable DateAndTime getTestpatternDateAndTime() {
74         return TESTPATTERN2;
75     }
76
77     /*----------------------------------------------------------------
78      * Private constructors
79      */
80
81     /**
82      * Convert ONF 1.2 DateAndTime to String
83      * 
84      * @param time as input
85      */
86     private InternalDateAndTime(
87             org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime time) {
88         if (time != null) {
89             internalDateAndTime = NETCONFTIME_CONVERTER.getTimeStampFromNetconf(time.getValue());
90         } else {
91             internalDateAndTime = INITIALPATTERN;
92         }
93     }
94
95     /**
96      * Setup static TEST
97      * 
98      * @param internalDateAndTime
99      */
100     private InternalDateAndTime(String internalDateAndTime) {
101         this.internalDateAndTime = internalDateAndTime;
102     }
103
104 }