001/** 002 * Copyright 2018 Tampere University of Technology, Pori Department 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package service.tut.pori.apilta.shock.datatypes; 017 018import java.util.Date; 019 020import javax.xml.bind.annotation.XmlAccessType; 021import javax.xml.bind.annotation.XmlAccessorType; 022import javax.xml.bind.annotation.XmlElement; 023import javax.xml.bind.annotation.XmlRootElement; 024import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; 025 026import service.tut.pori.tasks.datatypes.Task.Visibility; 027import core.tut.pori.users.UserIdentity; 028import core.tut.pori.utils.ISODateAdapter; 029 030/** 031 * 032 * 033 */ 034@XmlRootElement(name=service.tut.pori.apilta.sensors.datatypes.Definitions.ELEMENT_MEASUREMENT) 035@XmlAccessorType(XmlAccessType.NONE) 036public class ShockMeasurement { 037 @XmlElement(name=Definitions.ELEMENT_LEVEL) 038 private Integer _level = null; 039 @XmlElement(name = service.tut.pori.apilta.sensors.datatypes.Definitions.ELEMENT_MEASUREMENT_ID) 040 private String _measurementId = null; 041 @XmlElement(name = service.tut.pori.tasks.Definitions.ELEMENT_DATA_VISIBILITY) 042 private Visibility _visibility = null; 043 @XmlElement(name=core.tut.pori.users.Definitions.ELEMENT_USER_IDENTITY) 044 private UserIdentity _userId = null; 045 @XmlElement(name=Definitions.ELEMENT_ACCELEROMETER_DATA) 046 private AccelerometerData _accelerometerData = null; 047 @XmlElement(name=Definitions.ELEMENT_LOCATION_DATA) 048 private LocationData _locationData = null; 049 @XmlJavaTypeAdapter(ISODateAdapter.class) 050 @XmlElement(name=Definitions.ELEMENT_TIMESTAMP) 051 private Date _timestamp = null; 052 053 /** 054 * for sub-classing, use the static 055 * 056 * @return true if valid 057 * @see #isValid(ShockMeasurement) 058 */ 059 protected boolean isValid() { 060 if(_timestamp == null){ 061 return false; 062 }else if(_accelerometerData != null && !AccelerometerData.isValid(_accelerometerData)){ 063 return false; 064 }else if(_locationData != null && !LocationData.isValid(_locationData)){ 065 return false; 066 }else{ 067 return true; 068 } 069 } 070 071 /** 072 * 073 * @param measurement 074 * @return true if valid and not null 075 */ 076 public static boolean isValid(ShockMeasurement measurement) { 077 return (measurement != null && measurement.isValid()); 078 } 079 080 /** 081 * @return the measurementId 082 */ 083 public String getMeasurementId() { 084 return _measurementId; 085 } 086 087 /** 088 * @param measurementId the measurementId to set 089 */ 090 public void setMeasurementId(String measurementId) { 091 _measurementId = measurementId; 092 } 093 094 /** 095 * @return the visibility 096 */ 097 public Visibility getVisibility() { 098 return _visibility; 099 } 100 101 /** 102 * @param visibility the visibility to set 103 */ 104 public void setVisibility(Visibility visibility) { 105 _visibility = visibility; 106 } 107 108 /** 109 * @return the userId 110 */ 111 public UserIdentity getUserId() { 112 return _userId; 113 } 114 115 /** 116 * @param userId the userId to set 117 */ 118 public void setUserId(UserIdentity userId) { 119 _userId = userId; 120 } 121 122 /** 123 * @return the accelerometerData 124 */ 125 public AccelerometerData getAccelerometerData() { 126 return _accelerometerData; 127 } 128 129 /** 130 * @param accelerometerData the accelerometerData to set 131 */ 132 public void setAccelerometerData(AccelerometerData accelerometerData) { 133 _accelerometerData = accelerometerData; 134 } 135 136 /** 137 * @return the locationData 138 */ 139 public LocationData getLocationData() { 140 return _locationData; 141 } 142 143 /** 144 * @param locationData the locationData to set 145 */ 146 public void setLocationData(LocationData locationData) { 147 _locationData = locationData; 148 } 149 150 /** 151 * @return the timestamp 152 */ 153 public Date getTimestamp() { 154 return _timestamp; 155 } 156 157 /** 158 * @param timestamp the timestamp to set 159 */ 160 public void setTimestamp(Date timestamp) { 161 _timestamp = timestamp; 162 } 163 164 /** 165 * @return the level 166 */ 167 public Integer getLevel() { 168 return _level; 169 } 170 171 /** 172 * @param level the level to set 173 */ 174 public void setLevel(Integer level) { 175 _level = level; 176 } 177}