Merge "Refactoring data-provider:provider generateDTOs"
[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.
27  * To be replaced by NetconfTimeStampImpl
28  */
29 @Deprecated
30 public class InternalDateAndTime {
31
32     private static final String TESTPATTERNSTRING = "2017-01-01T00:00:00.0Z";
33     private static final String INITIALPATTERN = "0000-00-00T00:00:00.0Z";
34
35     private static final InternalDateAndTime TESTPATTERN = new InternalDateAndTime(TESTPATTERNSTRING);
36     private static final DateAndTime TESTPATTERN2 = new DateAndTime(TESTPATTERNSTRING);
37
38     private static final NetconfTimeStamp NETCONFTIME_CONVERTER = NetconfTimeStampImpl.getConverter();
39
40     /** Internal variable to hold the value, that is converted **/
41     private final String internalDateAndTime;
42
43     /**
44      * Static builder ONF1.0
45      * @param time in ONF1.0 yang format
46      * @return  InternalDateAndTime
47      */
48
49     public static InternalDateAndTime valueOf(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime time) {
50         return new InternalDateAndTime(time);
51     }
52
53     /**
54      * @return     Getter with String representation
55      */
56     public String getValue() {
57         return internalDateAndTime;
58     }
59
60     /**
61      * Get a testpattern
62      * @return testpattern
63      */
64     public static InternalDateAndTime getTestpattern() {
65         return TESTPATTERN;
66     }
67
68     /**
69      * @return DateAndTime testpattern
70      */
71     public static @Nullable DateAndTime getTestpatternDateAndTime() {
72         return TESTPATTERN2;
73     }
74
75     /*----------------------------------------------------------------
76      * Private constructors
77      */
78
79     /**
80      * Convert ONF 1.2 DateAndTime to String
81      * @param time as input
82      */
83     private InternalDateAndTime(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime time) {
84         if (time != null) {
85             internalDateAndTime = NETCONFTIME_CONVERTER.getTimeStampFromNetconf(time.getValue());
86         } else {
87             internalDateAndTime = INITIALPATTERN;
88         }
89     }
90
91     /**
92      * Setup static TEST
93      * @param internalDateAndTime
94      */
95     private InternalDateAndTime(String internalDateAndTime) {
96         this.internalDateAndTime = internalDateAndTime;
97     }
98
99 }