2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.opencomp.vid.model.mso;
23 import com.fasterxml.jackson.databind.ObjectMapper;
24 import com.google.common.base.MoreObjects;
26 import javax.ws.rs.core.Response;
27 import java.text.DateFormat;
28 import java.text.SimpleDateFormat;
31 * The Class RestObject.
33 * @param <T> the generic type
35 public class RestObject<T> {
37 final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
39 final static ObjectMapper objectMapper = new ObjectMapper();
42 * Generic version of the RestObject class.
45 // T stands for "Type"
48 // The string source of t, if available
51 /** The status code. */
52 private int statusCode= 0;
57 public RestObject(Response cres, Class<?> tClass) {
59 String rawEntity = null;
62 rawEntity = cres.readEntity(String.class);
63 T t = (T) objectMapper.readValue(rawEntity, tClass);
66 catch ( Exception e ) {
68 this.setRaw(rawEntity);
69 } catch (Exception e2) {
73 int status = cres.getStatus();
74 this.setStatusCode (status);
83 public void set(T t) { this.t = t; }
90 public T get() { return t; }
93 * Sets the status code.
95 * @param v the new status code
97 public void setStatusCode(int v) { this.statusCode = v; }
100 * Gets the status code.
102 * @return the status code
104 public int getStatusCode() { return this.statusCode; }
106 public String getRaw() {
110 public void setRaw(String rawT) {
115 public String toString() {
116 return MoreObjects.toStringHelper(this)
119 .add("statusCode", statusCode)