protected static boolean checkIdle(final Point p) throws NimbitsException { final Calendar c = Calendar.getInstance(); c.add(Calendar.SECOND, p.getIdleSeconds() * -1); boolean retVal = false; final List<Entity> result = EntityServiceFactory.getInstance() .getEntityByKey( UserServiceFactory.getServerInstance().getAdmin(), p.getOwner(), EntityType.user); if (!result.isEmpty()) { final User u = (User) result.get(0); final List<Value> v = ValueServiceFactory.getInstance().getCurrentValue(p); if (p.getIdleSeconds() > 0 && !v.isEmpty() && v.get(0).getTimestamp().getTime() <= c.getTimeInMillis() && !p.getIdleAlarmSent()) { p.setIdleAlarmSent(true); EntityServiceFactory.getInstance().addUpdateEntity(u, p); // PointServiceFactory.getInstance().updatePoint(u, p); final Value va = ValueFactory.createValueModel(v.get(0), AlertType.IdleAlert); SubscriptionServiceFactory.getInstance().processSubscriptions(u, p, va); retVal = true; } } return retVal; }
/** Gets given data into this object. */ public void merge(final ParseResult other) { if (this.calendars.size() == 0) { this.calendars.add((Calendar) other.getLocalTimestamp(0).clone()); } if (!other.getUTCTimestampCopy().equals(this.getUTCTimestampCopy())) { throw new IllegalArgumentException( "Cannot merge result data in " // System.out.println("Cannot merge result data in " + "different times (" + other.getUTCTimestampCopy() + " is not as expected " + this.getUTCTimestampCopy() + ")\n" + "Original result is related to " + this.symbols + " and " + "unexpected result is related to " + other.symbols); } for (Map.Entry<String, Map<Field, Double>> symbolVals : other.values.entrySet()) { boolean symbolFound = false; for (int i = 0; i < this.symbols.size(); i++) { if (this.symbols.get(i).equals(symbolVals.getKey())) { symbolFound = true; break; } } if (!symbolFound) { final String s = symbolVals.getKey(); this.addSymbol(s); for (int i = 0; i < this.symbols.size(); i++) { if (this.symbols.get(i).equals(s)) { final Calendar c = (Calendar) other.getLocalTimestamp(s).clone(); final long millis = c.getTimeInMillis(); c.setTimeZone(other.getLocalTimestamp(s).getTimeZone()); c.setTimeInMillis(millis); if (this.calendars.size() <= i) this.newTimestamp(i); this.calendars.set(i, c); break; } } } for (Map.Entry<Field, Double> fieldValue : symbolVals.getValue().entrySet()) { this.putValue(symbolVals.getKey(), fieldValue.getKey(), fieldValue.getValue()); } } }