/v3.2/nimbits-model/src/com/nimbits/client/model/point/PointModel.java

http://nimbits-server.googlecode.com/ · Java · 776 lines · 559 code · 198 blank · 19 comment · 2 complexity · 99bdb624594e781889c0f85830f92c04 MD5 · raw file

  1. /*
  2. * Copyright (c) 2010 Tonic Solutions LLC.
  3. *
  4. * http://www.nimbits.com
  5. *
  6. *
  7. * Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
  8. *
  9. * http://www.gnu.org/licenses/gpl.html
  10. *
  11. * Unless required by applicable law or agreed to in writing, software distributed under the license is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
  12. */
  13. package com.nimbits.client.model.point;
  14. import com.nimbits.client.model.ClientType;
  15. import com.nimbits.client.model.common.CommonFactoryLocator;
  16. import com.nimbits.client.model.value.AlertType;
  17. import com.nimbits.client.model.value.Value;
  18. import java.io.Serializable;
  19. import java.util.Date;
  20. import java.util.List;
  21. public class PointModel implements Serializable, Point {
  22. private long id;
  23. private static final long serialVersionUID = 1L;
  24. private AlertType alertState;
  25. private String uuid;
  26. private Date lastChecked;
  27. private String host;
  28. private long catID;
  29. private boolean isSystemPoint;
  30. private long userFK;
  31. private String name;
  32. private Date createDate;
  33. private long X;
  34. private long Y;
  35. private long Z;
  36. private long target;
  37. private String formula;
  38. private double highAlarm = 0.0;
  39. private int expire = 90;
  40. private String unit;
  41. private double compression = 0.1;
  42. private double lowAlarm = 0.0;
  43. private boolean highAlarmOn;
  44. private boolean lowAlarmOn;
  45. private int alarmDelay = 1;
  46. private long lastAlarmSent;
  47. private String description;
  48. private boolean isPublic;
  49. private boolean postToFacebook;
  50. private boolean alarmToFacebook;
  51. @Override
  52. public boolean isAlarmToEmail() {
  53. return alarmToEmail;
  54. }
  55. @Override
  56. public void setAlarmToEmail(boolean alarmToEmail) {
  57. this.alarmToEmail = alarmToEmail;
  58. }
  59. private boolean alarmToEmail;
  60. private boolean sendIM;
  61. private boolean sendAlarmIM;
  62. private boolean sendTweet;
  63. private boolean sendAlarmTweet;
  64. private String tag;
  65. private double lowestRecordedValue;
  66. private double highestRecordedValue;
  67. //
  68. // private double lastRecordedValue;
  69. private Date lastRecordedTimestamp;
  70. private String lastNote;
  71. private double lat;
  72. private double lng;
  73. private boolean idleAlarmOn;
  74. private Integer idleSeconds = 0;
  75. //reset on any data write
  76. private boolean idleAlarmSent;
  77. //reset on any data write
  78. private boolean ignoreIncomingCompressedValues;
  79. //reset on any data write
  80. private boolean readOnly;
  81. public void setClientType(ClientType clientType) {
  82. this.clientType = clientType;
  83. }
  84. private ClientType clientType;
  85. public PointModel(Point p) {
  86. this.id = p.getId();
  87. this.uuid = p.getUuid();
  88. this.lastChecked = p.getLastChecked();
  89. this.host = p.getHost();
  90. this.catID = p.getCatID();
  91. this.isSystemPoint = p.isSystemPoint();
  92. this.userFK = p.getUserFK();
  93. this.name = p.getName().getValue();
  94. this.createDate = p.getCreateDate();
  95. this.X = p.getX();
  96. this.Y = p.getY();
  97. this.Z = p.getZ();
  98. this.target = p.getTarget();
  99. this.formula = p.getFormula();
  100. this.highAlarm = p.getHighAlarm();
  101. this.expire = p.getExpire();
  102. this.unit = p.getUnit();
  103. this.compression = p.getCompression();
  104. this.lowAlarm = p.getLowAlarm();
  105. this.highAlarmOn = p.isHighAlarmOn();
  106. this.lowAlarmOn = p.isLowAlarmOn();
  107. this.alarmDelay = p.getAlarmDelay();
  108. this.lastAlarmSent = p.getLastAlarmSent();
  109. this.description = p.getDescription();
  110. this.isPublic = p.isPublic();
  111. this.postToFacebook = p.isPostToFacebook();
  112. this.alarmToFacebook = p.getAlarmToFacebook();
  113. this.sendIM = p.getSendIM();
  114. this.sendAlarmIM = p.getSendAlarmIM();
  115. this.sendTweet = p.getSendTweet();
  116. this.sendAlarmTweet = p.getSendAlarmTweet();
  117. this.tag = p.getTag();
  118. this.lowestRecordedValue = p.getLowestRecordedValue();
  119. this.highestRecordedValue = p.getHighestRecordedValue();
  120. this.lastRecordedTimestamp = p.getLastRecordedTimestamp();
  121. this.lastNote = p.getLastNote();
  122. this.lat = p.getLat();
  123. this.lng = p.getLng();
  124. this.idleAlarmOn = p.isIdleAlarmOn();
  125. this.idleSeconds = p.getIdleSeconds();
  126. this.idleAlarmSent = p.getIdleAlarmSent();
  127. this.ignoreIncomingCompressedValues = p.getIgnoreIncomingCompressedValues();
  128. this.readOnly = p.getReadOnly();
  129. this.targetValue = p.getTargetValue();
  130. this.jsonPointDataArray = p.getJsonPointDataArray();
  131. this.values = p.getValues();
  132. this.value = p.getValue();
  133. this.alarmToEmail = p.isAlarmToEmail();
  134. }
  135. @Override
  136. public boolean isIdleAlarmOn() {
  137. return idleAlarmOn;
  138. }
  139. @Override
  140. public AlertType getAlertState() {
  141. return this.alertState;
  142. }
  143. @Override
  144. public void setAlertState(final AlertType alertState) {
  145. this.alertState = alertState;
  146. }
  147. @Override
  148. public void setIdleAlarmOn(final boolean idleAlarmOn) {
  149. this.idleAlarmOn = idleAlarmOn;
  150. }
  151. @Override
  152. public int getIdleSeconds() {
  153. return idleSeconds;
  154. }
  155. @Override
  156. public void setIdleSeconds(final int idleSeconds) {
  157. this.idleSeconds = idleSeconds;
  158. }
  159. @Override
  160. public boolean getIdleAlarmSent() {
  161. return idleAlarmSent;
  162. }
  163. @Override
  164. public void setIdleAlarmSent(final boolean idleAlarmSent) {
  165. this.idleAlarmSent = idleAlarmSent;
  166. }
  167. // Constructors
  168. public PointModel() {
  169. }
  170. public PointModel(final long userFK, final PointName pointName, final long catID, final String uuid) {
  171. this();
  172. this.userFK = userFK;
  173. this.name = pointName.getValue();
  174. this.catID = catID;
  175. this.uuid = uuid;
  176. }
  177. public PointModel(final long userFK, final PointName pointName, final String uuid) {
  178. this();
  179. this.userFK = userFK;
  180. this.name = pointName.getValue();
  181. this.highestRecordedValue = 0.0;
  182. this.lowestRecordedValue = 0.0;
  183. this.lastRecordedTimestamp = new Date();
  184. this.uuid = uuid;
  185. }
  186. public PointModel(final PointName name, final String uuid) {
  187. this.name = name.getValue();
  188. this.highestRecordedValue = 0.0;
  189. this.lowestRecordedValue = 0.0;
  190. this.lastRecordedTimestamp = new Date();
  191. this.uuid = uuid;
  192. }
  193. public PointModel(final long id, final long userFk) {
  194. this.id = id;
  195. this.userFK = userFk;
  196. }
  197. // End Constructors
  198. private double targetValue;
  199. private String jsonPointDataArray;
  200. private List<Value> values;
  201. private Value value;
  202. @Override
  203. public int getAlarmDelay() {
  204. return alarmDelay;
  205. }
  206. @Override
  207. public boolean getAlarmToFacebook() {
  208. return alarmToFacebook;
  209. }
  210. @Override
  211. public long getCatID() {
  212. return catID;
  213. }
  214. @Override
  215. public double getCompression() {
  216. return this.compression;
  217. }
  218. @Override
  219. public Date getCreateDate() {
  220. return new Date(this.createDate.getTime());
  221. }
  222. @Override
  223. public String getDescription() {
  224. return this.description == null ? "" : this.description;
  225. }
  226. @Override
  227. public int getExpire() {
  228. return expire;
  229. }
  230. @Override
  231. public String getFormula() {
  232. return this.formula;
  233. }
  234. @Override
  235. public double getHighAlarm() {
  236. return highAlarm;
  237. }
  238. @Override
  239. public double getHighestRecordedValue() {
  240. return highestRecordedValue;
  241. }
  242. @Override
  243. public String getHost() {
  244. return host;
  245. }
  246. @Override
  247. public long getId() {
  248. return id;
  249. }
  250. @Override
  251. public String getJsonPointDataArray() {
  252. return jsonPointDataArray;
  253. }
  254. @Override
  255. public long getLastAlarmSent() {
  256. return lastAlarmSent;
  257. }
  258. @Override
  259. public Date getLastChecked() {
  260. return new Date(this.lastChecked.getTime());
  261. }
  262. @Override
  263. public double getLastLat() {
  264. return lat;
  265. }
  266. @Override
  267. public double getLastLng() {
  268. return lng;
  269. }
  270. @Override
  271. public String getLastNote() {
  272. return lastNote;
  273. }
  274. @Override
  275. public Date getLastRecordedTimestamp() {
  276. return lastRecordedTimestamp == null ? new Date() : new Date(this.lastRecordedTimestamp.getTime());
  277. }
  278. @Override
  279. public double getLat() {
  280. return getLastLat();
  281. }
  282. @Override
  283. public double getLng() {
  284. return getLastLng();
  285. }
  286. @Override
  287. public double getLowAlarm() {
  288. return lowAlarm;
  289. }
  290. @Override
  291. public double getLowestRecordedValue() {
  292. return lowestRecordedValue;
  293. }
  294. @Override
  295. public PointName getName() {
  296. return CommonFactoryLocator.getInstance().createPointName(this.name);
  297. }
  298. @Override
  299. public boolean getSendAlarmIM() {
  300. return sendAlarmIM;
  301. }
  302. @Override
  303. public boolean getSendAlarmTweet() {
  304. return sendAlarmTweet;
  305. }
  306. @Override
  307. public boolean getSendIM() {
  308. return sendIM;
  309. }
  310. @Override
  311. public boolean getSendTweet() {
  312. return sendTweet;
  313. }
  314. @Override
  315. public String getTag() {
  316. return tag;
  317. }
  318. @Override
  319. public long getTarget() {
  320. return target;
  321. }
  322. @Override
  323. public String getUnit() {
  324. return unit;
  325. }
  326. @Override
  327. public long getUserFK() {
  328. return userFK;
  329. }
  330. @Override
  331. public String getUuid() {
  332. return uuid;
  333. }
  334. @Override
  335. public Value getValue() {
  336. return value;
  337. }
  338. @Override
  339. public List<Value> getValues() {
  340. return values;
  341. }
  342. @Override
  343. public long getX() {
  344. return X;
  345. }
  346. @Override
  347. public long getY() {
  348. return Y;
  349. }
  350. @Override
  351. public long getZ() {
  352. return Z;
  353. }
  354. @Override
  355. public boolean isHighAlarmOn() {
  356. return highAlarmOn;
  357. }
  358. @Override
  359. public boolean isLowAlarmOn() {
  360. return lowAlarmOn;
  361. }
  362. @Override
  363. public boolean isPostToFacebook() {
  364. return postToFacebook;
  365. }
  366. @Override
  367. public boolean isPublic() {
  368. return isPublic;
  369. }
  370. @Override
  371. public boolean isSystemPoint() {
  372. return isSystemPoint;
  373. }
  374. @Override
  375. public void setAlarmDelay(final int alarmDelay) {
  376. this.alarmDelay = alarmDelay;
  377. }
  378. @Override
  379. public void setAlarmToFacebook(final boolean alarmToFacebook) {
  380. this.alarmToFacebook = alarmToFacebook;
  381. }
  382. @Override
  383. public void setCatID(final long catID) {
  384. this.catID = catID;
  385. }
  386. @Override
  387. public void setCompression(final double compression) {
  388. this.compression = compression;
  389. }
  390. @Override
  391. public void setCreateDate(final Date createDate) {
  392. this.createDate = new Date(createDate.getTime());
  393. }
  394. @Override
  395. public void setDescription(final String value) {
  396. this.description = value;
  397. }
  398. @Override
  399. public void setExpire(final int expire) {
  400. this.expire = expire;
  401. }
  402. @Override
  403. public void setFormula(final String formula) {
  404. this.formula = formula;
  405. }
  406. @Override
  407. public void setHighAlarm(double highAlarm) {
  408. this.highAlarm = highAlarm;
  409. }
  410. @Override
  411. public void setHighAlarmOn(final boolean highAlarmOn) {
  412. this.highAlarmOn = highAlarmOn;
  413. }
  414. @Override
  415. public void setHighestRecordedValue(final double highestRecordedValue) {
  416. this.highestRecordedValue = highestRecordedValue;
  417. }
  418. @Override
  419. public void setHost(final String host) {
  420. this.host = host;
  421. }
  422. @Override
  423. public void setId(final long id) {
  424. this.id = id;
  425. }
  426. @Override
  427. public void setJsonPointDataArray(final String jsonPointDataArray) {
  428. this.jsonPointDataArray = jsonPointDataArray;
  429. }
  430. @Override
  431. public void setLastAlarmSent(final long lastAlarmSent) {
  432. this.lastAlarmSent = lastAlarmSent;
  433. }
  434. @Override
  435. public void setLastChecked(final Date lastChecked) {
  436. this.lastChecked = new Date(lastChecked.getTime());
  437. }
  438. @Override
  439. public void setLastLat(final double lastLat) {
  440. this.lat = lastLat;
  441. }
  442. @Override
  443. public void setLastLng(final double lastLng) {
  444. this.lng = lastLng;
  445. }
  446. @Override
  447. public void setLastNote(final String lastNote) {
  448. this.lastNote = lastNote;
  449. }
  450. @Override
  451. public void setLastRecordedTimestamp(final Date lastRecordedTimestamp) {
  452. this.lastRecordedTimestamp = new Date(lastRecordedTimestamp.getTime());
  453. }
  454. @Override
  455. public void setLat(final double lat) {
  456. this.lat = lat;
  457. }
  458. @Override
  459. public void setLng(final double lng) {
  460. this.lng = lng;
  461. }
  462. @Override
  463. public void setLowAlarm(final double lowAlarm) {
  464. this.lowAlarm = lowAlarm;
  465. }
  466. @Override
  467. public void setLowAlarmOn(final boolean lowAlarmOn) {
  468. this.lowAlarmOn = lowAlarmOn;
  469. }
  470. @Override
  471. public void setLowestRecordedValue(final double lowestRecordedValue) {
  472. this.lowestRecordedValue = lowestRecordedValue;
  473. }
  474. @Override
  475. public void setName(final PointName name) {
  476. this.name = name.getValue();
  477. }
  478. @Override
  479. public void setPostToFacebook(final boolean postToFacebook) {
  480. this.postToFacebook = postToFacebook;
  481. }
  482. @Override
  483. public void setPublic(final boolean isPublic) {
  484. this.isPublic = isPublic;
  485. }
  486. @Override
  487. public void setSendAlarmIM(final boolean sendAlarmIM) {
  488. this.sendAlarmIM = sendAlarmIM;
  489. }
  490. @Override
  491. public void setSendAlarmTweet(final boolean sendAlarmTweet) {
  492. this.sendAlarmTweet = sendAlarmTweet;
  493. }
  494. @Override
  495. public void setSendIM(final boolean sendIM) {
  496. this.sendIM = sendIM;
  497. }
  498. @Override
  499. public void setSendTweet(final boolean sendTweet) {
  500. this.sendTweet = sendTweet;
  501. }
  502. @Override
  503. public void setSystemPoint(final boolean isSystemPoint) {
  504. this.isSystemPoint = isSystemPoint;
  505. }
  506. @Override
  507. public void setTag(final String tag) {
  508. this.tag = tag;
  509. }
  510. @Override
  511. public void setTarget(final long long1) {
  512. this.target = long1;
  513. }
  514. @Override
  515. public void setUnit(final String unit) {
  516. this.unit = unit;
  517. }
  518. @Override
  519. public void setUserFK(final long userFK) {
  520. this.userFK = userFK;
  521. }
  522. @Override
  523. public void setUuid(final String uuid) {
  524. this.uuid = uuid;
  525. }
  526. @Override
  527. public void setValue(final Value value) {
  528. this.value = value;
  529. }
  530. @Override
  531. public void setValues(final List<Value> values) {
  532. this.values = values;
  533. }
  534. @Override
  535. public void setX(final long x) {
  536. X = x;
  537. }
  538. @Override
  539. public void setY(final long y) {
  540. Y = y;
  541. }
  542. @Override
  543. public void setZ(final long z) {
  544. Z = z;
  545. }
  546. @Override
  547. public String toString() {
  548. return name;
  549. }
  550. @Override
  551. public void setTargetValue(final double targetValue) {
  552. this.targetValue = targetValue;
  553. }
  554. @Override
  555. public double getTargetValue() {
  556. return targetValue;
  557. }
  558. @Override
  559. public void setIgnoreIncomingCompressedValues(
  560. final boolean ignoreIncomingCompressedValues) {
  561. this.ignoreIncomingCompressedValues = ignoreIncomingCompressedValues;
  562. }
  563. @Override
  564. public boolean getIgnoreIncomingCompressedValues() {
  565. return ignoreIncomingCompressedValues;
  566. }
  567. @Override
  568. public void setReadOnly(final boolean readOnly) {
  569. this.readOnly = readOnly;
  570. }
  571. @Override
  572. public boolean getReadOnly() {
  573. return readOnly;
  574. }
  575. public ClientType getClientType() {
  576. return clientType;
  577. }
  578. }