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.onap.dmaap.dbcapi.model;
23 import io.swagger.annotations.ApiModelProperty;
24 import java.util.Calendar;
25 import java.util.Date;
26 import java.util.TimeZone;
27 import javax.xml.bind.annotation.XmlRootElement;
28 import org.onap.dmaap.dbcapi.logging.BaseLoggingClass;
31 public abstract class DmaapObject extends BaseLoggingClass {
32 @ApiModelProperty( value = "datestamp for last update to this object")
33 protected Date lastMod;
34 protected DmaapObject_Status status;
36 public Date getLastMod() {
40 public void setLastMod(Date lastMod) {
41 this.lastMod = lastMod;
44 public void setLastMod() {
45 this.lastMod = Calendar.getInstance(TimeZone.getTimeZone("UTC")).getTime();
48 public enum DmaapObject_Status {
56 public DmaapObject_Status getStatus() {
60 public void setStatus(DmaapObject_Status status) {
64 public void setStatus( String val ) {
65 if ( val == null || val.isEmpty() ) {
66 this.status = DmaapObject_Status.EMPTY;
67 } else if (val.compareToIgnoreCase("new") == 0 ) {
68 this.status = DmaapObject_Status.NEW;
69 } else if ( val.compareToIgnoreCase("staged" ) == 0) {
70 this.status = DmaapObject_Status.STAGED;
71 } else if ( val.compareToIgnoreCase("valid") == 0) {
72 this.status = DmaapObject_Status.VALID;
73 } else if ( val.compareToIgnoreCase("invalid") == 0) {
74 this.status = DmaapObject_Status.INVALID;
75 } else if ( val.compareToIgnoreCase("deleted") == 0) {
76 this.status = DmaapObject_Status.DELETED;
78 this.status = DmaapObject_Status.INVALID;
82 @ApiModelProperty( hidden=true )
83 public boolean isStatusValid() {
84 if ( this.status == DmaapObject_Status.VALID ) {
91 * TODO: get this working so arrays and sub-class within an Object can be logged
93 public String toString() {
94 return classToString( this );
97 private String classToString( Object obj ) {
98 Field[] fields = obj.getClass().getDeclaredFields();
99 StringBuilder res = new StringBuilder( "{");
100 boolean first = true;
101 for ( Field field: fields ) {
102 logger.info( field.getName() + " toString=" + field.toString() + " toGenericString=" + field.toGenericString());
110 field.setAccessible(true); // avoid IllegalAccessException
113 Class<?> t = field.getType();
115 if ( t == String.class ) {
116 res.append( "\"" ).append( field.getName() ).append( "\": \"");
119 res.append(field.get(this));
120 } catch ( IllegalAccessException iae) {
121 res.append( "UNK(iae)");
122 } catch (IllegalArgumentException iae2 ) {
123 res.append( "UNK(iae2)");
124 } catch ( NullPointerException npe ) {
125 res.append( "UNK(npe)");
126 } catch ( ExceptionInInitializerError eie ) {
127 res.append( "UNK(eie)");
130 } else if ( t == ArrayList.class ){
132 res.append( classToString( field ));
138 return( res.toString());