use of org.openremote.model.attribute.AttributeRef in project openremote by openremote.
the class WebsocketAgentProtocol method doUnlinkAttribute.
@Override
protected void doUnlinkAttribute(String assetId, Attribute<?> attribute, WebsocketAgentLink agentLink) {
AttributeRef attributeRef = new AttributeRef(assetId, attribute.getName());
protocolMessageConsumers.removeIf((attrRefConsumer) -> attrRefConsumer.key.equals(attributeRef));
attributeConnectedTasks.remove(attributeRef);
}
use of org.openremote.model.attribute.AttributeRef in project openremote by openremote.
the class ZWaveProtocol method doUnlinkAttribute.
@Override
protected synchronized void doUnlinkAttribute(String assetId, Attribute<?> attribute, ZWaveAgentLink agentLink) {
if (network == null) {
return;
}
AttributeRef attributeRef = new AttributeRef(assetId, attribute.getName());
Consumer<Value> sensorValueConsumer = sensorValueConsumerMap.remove(attributeRef);
network.removeSensorValueConsumer(sensorValueConsumer);
}
use of org.openremote.model.attribute.AttributeRef in project openremote by openremote.
the class ZWaveProtocol method doLinkAttribute.
@Override
protected synchronized void doLinkAttribute(String assetId, Attribute<?> attribute, ZWaveAgentLink agentLink) {
if (network == null) {
return;
}
int nodeId = agentLink.getDeviceNodeId().orElse(0);
int endpoint = agentLink.getDeviceEndpoint().orElse(0);
String linkName = agentLink.getDeviceValue().orElse("");
AttributeRef attributeRef = new AttributeRef(assetId, attribute.getName());
Class<?> clazz = (attribute == null ? null : attribute.getType().getType());
Consumer<Value> sensorValueConsumer = value -> updateLinkedAttribute(new AttributeState(attributeRef, toAttributeValue(value, clazz)));
sensorValueConsumerMap.put(attributeRef, sensorValueConsumer);
network.addSensorValueConsumer(nodeId, endpoint, linkName, sensorValueConsumer);
}
use of org.openremote.model.attribute.AttributeRef in project openremote by openremote.
the class AssetDatapointResourceImpl method getDatapointExport.
@Override
public void getDatapointExport(AsyncResponse asyncResponse, String attributeRefsString, long fromTimestamp, long toTimestamp) {
try {
AttributeRef[] attributeRefs = JSON.readValue(attributeRefsString, AttributeRef[].class);
for (AttributeRef attributeRef : attributeRefs) {
if (isRestrictedUser() && !assetStorageService.isUserAsset(getUserId(), attributeRef.getId())) {
throw new WebApplicationException(Response.Status.FORBIDDEN);
}
Asset<?> asset = assetStorageService.find(attributeRef.getId(), true);
if (asset == null) {
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
if (!isTenantActiveAndAccessible(asset.getRealm())) {
DATA_EXPORT_LOG.info("Forbidden access for user '" + getUsername() + "': " + asset);
throw new WebApplicationException(Response.Status.FORBIDDEN);
}
asset.getAttribute(attributeRef.getName()).orElseThrow(() -> new WebApplicationException(Response.Status.NOT_FOUND));
}
DATA_EXPORT_LOG.info("User '" + getUsername() + "' started data export for " + attributeRefsString + " from " + fromTimestamp + " to " + toTimestamp);
ScheduledFuture<File> exportFuture = assetDatapointService.exportDatapoints(attributeRefs, fromTimestamp, toTimestamp);
asyncResponse.register((ConnectionCallback) disconnected -> {
exportFuture.cancel(true);
});
File exportFile = null;
try {
exportFile = exportFuture.get();
ZipOutputStream zipOut = new ZipOutputStream(response.getOutputStream());
FileInputStream fin = new FileInputStream(exportFile);
ZipEntry zipEntry = new ZipEntry(exportFile.getName());
zipOut.putNextEntry(zipEntry);
IOUtils.copy(fin, zipOut);
zipOut.closeEntry();
zipOut.close();
fin.close();
response.setContentType("application/zip");
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"dataexport.zip\"");
asyncResponse.resume(response);
} catch (Exception ex) {
exportFuture.cancel(true);
asyncResponse.resume(new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR));
DATA_EXPORT_LOG.log(Level.SEVERE, "Exception in ScheduledFuture: ", ex);
} finally {
if (exportFile != null && exportFile.exists()) {
try {
exportFile.delete();
} catch (Exception e) {
DATA_EXPORT_LOG.log(Level.SEVERE, "Failed to delete temporary export file: " + exportFile.getPath(), e);
}
}
}
} catch (JsonProcessingException ex) {
asyncResponse.resume(new BadRequestException(ex));
}
}
use of org.openremote.model.attribute.AttributeRef in project openremote by openremote.
the class UDPProtocol method doLinkAttribute.
@Override
protected void doLinkAttribute(String assetId, Attribute<?> attribute, DefaultAgentLink agentLink) {
AttributeRef attributeRef = new AttributeRef(assetId, attribute.getName());
Consumer<String> messageConsumer = ProtocolUtil.createGenericAttributeMessageConsumer(assetId, attribute, agentLink, timerService::getCurrentTimeMillis, this::updateLinkedAttribute);
if (messageConsumer != null) {
protocolMessageConsumers.add(new Pair<>(attributeRef, messageConsumer));
}
}
Aggregations