Catalog alignment
[sdc.git] / catalog-model / src / main / java / org / openecomp / sdc / be / model / CatalogUpdateTimestamp.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.be.model;
22
23 import java.io.IOException;
24
25 import com.fasterxml.jackson.annotation.JsonProperty;
26 import com.fasterxml.jackson.core.type.TypeReference;
27 import com.fasterxml.jackson.databind.ObjectMapper;
28 import com.fasterxml.jackson.databind.SerializationFeature;
29
30
31 public class CatalogUpdateTimestamp  {
32
33   
34
35     @JsonProperty("previousUpdateTime")
36     private long previousUpdateTime;
37     @JsonProperty("currentUpdateTime")
38     private long currentUpdateTime;
39
40     public CatalogUpdateTimestamp() {
41     }
42     public CatalogUpdateTimestamp(long previousUpdateTime, long currentUpdateTime) {
43         this.previousUpdateTime = previousUpdateTime;
44         this.currentUpdateTime = currentUpdateTime;
45     }
46
47     public CatalogUpdateTimestamp(CatalogUpdateTimestamp catalogUpdateTimestamp) {
48         this.previousUpdateTime = catalogUpdateTimestamp.getPreviousUpdateTime();
49         this.currentUpdateTime = catalogUpdateTimestamp.getCurrentUpdateTime();
50     }
51
52     @Override
53     public boolean equals(Object obj) {
54         if (obj instanceof CatalogUpdateTimestamp){
55             return (this.getCurrentUpdateTime() == ((CatalogUpdateTimestamp) obj).getCurrentUpdateTime()
56                     && this.getPreviousUpdateTime() == ((CatalogUpdateTimestamp) obj).getPreviousUpdateTime())
57                     || super.equals(obj);
58         }
59         return false;
60     }
61     
62    
63     public long getCurrentUpdateTime() {
64         return currentUpdateTime;
65     }
66
67     
68     public long getPreviousUpdateTime() {
69         return previousUpdateTime;
70     }
71     
72     
73     public void setPreviousUpdateTime(long previousUpdateTime) {
74         this.previousUpdateTime = previousUpdateTime;
75     }
76
77     public void setCurrentUpdateTime(long currentUpdateTime) {
78         this.currentUpdateTime = currentUpdateTime;
79     }
80
81     @Override
82     public int hashCode() {
83         return super.hashCode();
84     }
85
86     @Override
87     public String toString() {
88         return "CatalogUpdateTimestamp [currentUpdateTime = " + currentUpdateTime + ", previousUpdateTime = " + previousUpdateTime + "]";
89     }
90     
91     public    static CatalogUpdateTimestamp buildFromHttpResponse(String responseBody) throws IOException {
92         ObjectMapper objectMapper = new ObjectMapper();
93         objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
94         TypeReference<CatalogUpdateTimestamp> typeRef = new TypeReference<CatalogUpdateTimestamp>() {};
95         return objectMapper.readValue(responseBody, typeRef);
96     }
97         public static CatalogUpdateTimestamp buildDummyCatalogUpdateTimestamp() {
98                 long currentTimeMillis = System.currentTimeMillis();
99                 return new CatalogUpdateTimestamp(0L, currentTimeMillis);
100         }
101
102 }