List of usage examples for org.joda.time DateTime DateTime
public DateTime(Object instant)
From source file:com.alliander.osgp.adapter.protocol.iec61850.infra.networking.services.commands.Iec61850UpdateFirmwareCommand.java
License:Open Source License
public void pushFirmwareToDevice(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection, final String fullUrl) throws ProtocolAdapterException { final Function<Void> function = new Function<Void>() { @Override/*from w w w.ja v a 2 s . com*/ public Void apply() throws Exception { // Getting the functional firmware version. LOGGER.info("Reading the functional firmware version"); final NodeContainer functionalFirmwareNode = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.FUNCTIONAL_FIRMWARE, Fc.CF); iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), functionalFirmwareNode.getFcmodelNode()); LOGGER.info("Updating the firmware download url"); functionalFirmwareNode.writeString(SubDataAttribute.URL, fullUrl); final NodeContainer clock = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.CLOCK, Fc.CF); iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), clock.getFcmodelNode()); final DateTime deviceTime = new DateTime(clock.getDate(SubDataAttribute.CURRENT_TIME)); // Creating a Date one minute from now. final Date oneMinuteFromNow = deviceTime.plusMinutes(1).toDate(); LOGGER.info("Updating the firmware download start time to: {}", oneMinuteFromNow); functionalFirmwareNode.writeDate(SubDataAttribute.START_TIME, oneMinuteFromNow); return null; } }; iec61850Client.sendCommandWithRetry(function); }
From source file:com.alliander.osgp.adapter.protocol.iec61850.infra.networking.services.commands.Iec61850UpdateSslCertificateCommand.java
License:Open Source License
public void pushSslCertificateToDevice(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection, final CertificationDto certification) throws ProtocolAdapterException { final Function<Void> function = new Function<Void>() { @Override//w w w . j a va2 s. c o m public Void apply() throws Exception { LOGGER.info("Reading the certificate authority url"); final NodeContainer sslConfiguration = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.CERTIFICATE_AUTHORITY_REPLACE, Fc.CF); iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), sslConfiguration.getFcmodelNode()); // Removing trailing and leading slashes (if present) from the // domain and the URL. String adjustedDomain = certification.getCertificateDomain(); if (adjustedDomain.endsWith("/")) { adjustedDomain = adjustedDomain.substring(0, adjustedDomain.length() - 1); } String adjustedUrl = certification.getCertificateUrl(); if (adjustedUrl.startsWith("/")) { adjustedUrl = adjustedUrl.substring(1, adjustedUrl.length()); } final String fullUrl = adjustedDomain.concat("/").concat(adjustedUrl); LOGGER.info("Updating the certificate download url to {}", fullUrl); sslConfiguration.writeString(SubDataAttribute.URL, fullUrl); final NodeContainer clock = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.CLOCK, Fc.CF); iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), clock.getFcmodelNode()); final DateTime deviceTime = new DateTime(clock.getDate(SubDataAttribute.CURRENT_TIME)); final Date oneMinuteFromNow = deviceTime.plusMinutes(1).toDate(); LOGGER.info("Updating the certificate download start time to: {}", oneMinuteFromNow); sslConfiguration.writeDate(SubDataAttribute.START_TIME, oneMinuteFromNow); return null; } }; iec61850Client.sendCommandWithRetry(function); }