if (source.getLastInteractionDate() != null) { target.append(PROP_LAST_INTERACTION_DATE, source.getLastInteractionDate()); if (source.getPresenceMissingDate() != null) { target.append(PROP_PRESENCE_MISSING_DATE, source.getPresenceMissingDate()); if (source.getLastLocation() != null) { target.append(PROP_LAST_LOCATION, MongoDeviceLocation.toDocument(source.getLastLocation(), true)); if (!source.getLatestMeasurements().isEmpty()) { List<Document> measurements = new ArrayList<Document>(); for (IDeviceMeasurement sm : source.getLatestMeasurements()) { measurements.add(MongoDeviceMeasurement.toDocument(sm, true)); if (!source.getLatestAlerts().isEmpty()) { List<Document> alerts = new ArrayList<Document>(); for (IDeviceAlert sa : source.getLatestAlerts()) { alerts.add(MongoDeviceAlert.toDocument(sa, true));
@Override public boolean shouldGenerateEvent(IDeviceAssignment assignment, IDeviceStateChangeCreateRequest request) throws SiteWhereException { if (assignment.getState().getPresenceMissingDate() != null) { return false; } return true; } }
public static DeviceAssignmentState copy(IDeviceAssignmentState source) throws SiteWhereException { DeviceAssignmentState target = new DeviceAssignmentState(); target.setLastInteractionDate(source.getLastInteractionDate()); target.setPresenceMissingDate(source.getPresenceMissingDate()); if (source.getLastLocation() != null) { target.setLastLocation(DeviceLocation.copy(source.getLastLocation())); } List<DeviceMeasurement> measurements = new ArrayList<DeviceMeasurement>(); for (IDeviceMeasurement sm : source.getLatestMeasurements()) { measurements.add(DeviceMeasurement.copy(sm)); } target.setLatestMeasurements(measurements); List<DeviceAlert> alerts = new ArrayList<DeviceAlert>(); for (IDeviceAlert sa : source.getLatestAlerts()) { alerts.add(DeviceAlert.copy(sa)); } target.setLatestAlerts(alerts); return target; } }
@Override public byte[] encodeDeviceAssignmentState(IDeviceAssignmentState state) throws SiteWhereException { ProtobufMarshaler.DeviceAssignmentState.Builder builder = ProtobufMarshaler.DeviceAssignmentState.newBuilder(); if (state.getLastInteractionDate() != null) { builder.setLastInteractionDate(state.getLastInteractionDate().getTime()); if (state.getLastLocation() != null) { builder.setLastLocation(marshalDeviceLocation(state.getLastLocation())); if (state.getLatestMeasurements() != null) { for (IDeviceMeasurement mx : state.getLatestMeasurements()) { ProtobufMarshaler.DeviceMeasurement.Builder mbuilder = ProtobufMarshaler.DeviceMeasurement.newBuilder(); mbuilder.setName(mx.getName()); if (state.getLatestAlerts() != null) { for (IDeviceAlert alert : state.getLatestAlerts()) { builder.addLatestAlerts(marshalDeviceAlert(alert));