List of usage examples for org.joda.time DateTime now
public static DateTime now()
ISOChronology
in the default time zone. From source file:com.alliander.osgp.acceptancetests.basicfunctions.VerifyAuthorizeDeviceFunctionSteps.java
License:Open Source License
private void getPowerUsageHistory() throws OsgpException { final GetPowerUsageHistoryRequest request = new GetPowerUsageHistoryRequest(); request.setDeviceIdentification(this.device.getDeviceIdentification()); request.setHistoryTermType(HistoryTermType.SHORT); final TimePeriod timePeriod = new TimePeriod(); try {/*from w w w . jav a 2s . c o m*/ timePeriod.setStartTime(DatatypeFactory.newInstance() .newXMLGregorianCalendar(DateTime.now().minusDays(1).toGregorianCalendar())); timePeriod.setEndTime( DatatypeFactory.newInstance().newXMLGregorianCalendar(DateTime.now().toGregorianCalendar())); } catch (final DatatypeConfigurationException e) { throw new TechnicalException(ComponentType.DOMAIN_PUBLIC_LIGHTING, e); } request.setTimePeriod(timePeriod); // device always responds ok final com.alliander.osgp.oslp.Oslp.GetPowerUsageHistoryResponse oslpResponse = com.alliander.osgp.oslp.Oslp.GetPowerUsageHistoryResponse .newBuilder() .addPowerUsageData( PowerUsageData.newBuilder().setMeterType(MeterType.P1).setRecordTime("20130101120000") .setActualConsumedPower(2).setTotalConsumedEnergy(2).build()) .setStatus(Status.OK).build(); this.oslpEnvelope = OslpTestUtils.createOslpEnvelopeBuilder().withDeviceId(Base64.decodeBase64(DEVICE_UID)) .withPayloadMessage(Message.newBuilder().setGetPowerUsageHistoryResponse(oslpResponse).build()) .build(); this.oslpChannelHandler = OslpTestUtils.createOslpChannelHandlerWithResponse(this.oslpEnvelope, this.channelMock, this.device.getNetworkAddress()); this.deviceService.setOslpChannelHandler(this.oslpChannelHandler); this.response = this.lightDeviceMonitoringEndpoint .getPowerUsageHistory(this.organisation.getOrganisationIdentification(), request); }
From source file:com.alliander.osgp.adapter.protocol.iec61850.infra.networking.reporting.Iec61850ClientSSLDEventListener.java
License:Open Source License
private DateTime determineDateTime(final FcModelNode evnRpn, final DateTime timeOfEntry) { final BdaTimestamp trgTimeNode = (BdaTimestamp) evnRpn.getChild(EVENT_NODE_TRIGGER_TIME); if (trgTimeNode != null && trgTimeNode.getDate() != null) { return new DateTime(trgTimeNode.getDate()); }//w w w . j av a2s .c om if (timeOfEntry != null) { /* * Use the reports time of entry for the event. The trigger time * will appear in the description with the event notification. * * See: determineDescription(FcModelNode) */ return timeOfEntry; } /* * No time of entry or trigger time available for the report. As a * fallback use the time the report is processed here as event time. */ return DateTime.now(); }
From source file:com.alliander.osgp.adapter.protocol.iec61850.infra.networking.services.Iec61850DeviceConnectionService.java
License:Open Source License
public synchronized void connect(final String ipAddress, final String deviceIdentification, final IED ied, final LogicalDevice logicalDevice) throws ConnectionFailureException { LOGGER.info("Trying to find connection in cache for deviceIdentification: {}", deviceIdentification); if (this.testIfConnectionIsCachedAndAlive(deviceIdentification, ied, logicalDevice)) { return;/*w w w . j av a2 s . c o m*/ } final InetAddress inetAddress = this.convertIpAddress(ipAddress); if (inetAddress == null) { return; } // Connect to obtain ClientAssociation and ServerModel. LOGGER.info("Trying to connect to deviceIdentification: {} at IP address {} using response time-out: {}", deviceIdentification, ipAddress, this.responseTimeout); final DateTime startTime = DateTime.now(); // Create instance of appropriate event listener. Iec61850ClientBaseEventListener eventListener = null; try { eventListener = Iec61850ClientEventListenerFactory.getInstance().getEventListener(ied, deviceIdentification, this.deviceManagementService); } catch (final ProtocolAdapterException e) { LOGGER.error( "ProtocolAdapterException: no Iec61850ClientBaseEventListener instance could be contructed, continue without event listener for deviceIdentification: " + deviceIdentification, e); } // For now, the port numbers are defined in the property file. If in // the future a database is added to this component, the port // numbers for particular devices should be saved using the // database. int port = 102; if (IED.FLEX_OVL.equals(ied)) { port = this.iec61850SsldPortServer; } else if (IED.ZOWN_RTU.equals(ied)) { port = this.iec61850RtuPortServer; } // Try to connect and receive the ClientAssociation. final Iec61850ClientAssociation iec61850ClientAssociation = this.iec61850Client .connect(deviceIdentification, inetAddress, eventListener, port); final ClientAssociation clientAssociation = iec61850ClientAssociation.getClientAssociation(); // Set response time-out. clientAssociation.setResponseTimeout(this.responseTimeout); // Read the ServerModel, either from the device or from a SCL file. ServerModel serverModel; try { serverModel = this.readServerModel(clientAssociation, deviceIdentification); } catch (final ProtocolAdapterException e) { LOGGER.error("ProtocolAdapterException: unable to read ServerModel for deviceIdentification " + deviceIdentification, e); throw new ConnectionFailureException(e.getMessage(), e); } // Cache the connection. this.cacheIec61850Connection(deviceIdentification, new Iec61850Connection(iec61850ClientAssociation, serverModel)); final DateTime endTime = DateTime.now(); LOGGER.info( "Connected to device: {}, fetched server model. Start time: {}, end time: {}, total time in milliseconds: {}", deviceIdentification, startTime, endTime, endTime.minus(startTime.getMillis()).getMillis()); }
From source file:com.alliander.osgp.adapter.protocol.oslp.elster.application.mapping.OslpGetConfigurationResponseToConfigurationConverter.java
License:Open Source License
private DateTime convertSummerTimeWinterTimeDetails(final String timeDetails) { final int month = Integer.parseInt(timeDetails.substring(0, 2)); final int day = Integer.parseInt(timeDetails.substring(2, 3)); final int hour = Integer.parseInt(timeDetails.substring(3, 5)); final int minutes = Integer.parseInt(timeDetails.substring(5, 7)); LOGGER.info("month: {}, day: {}, hour: {}, minutes: {}", month, day, hour, minutes); final int year = DateTime.now().getYear(); final int dayOfMonth = this.getLastDayOfMonth(month, day); final DateTime dateTime = new DateTime(year, month, dayOfMonth, hour, minutes); LOGGER.info("dateTime: {}", dateTime.toString()); return dateTime; }
From source file:com.alliander.osgp.adapter.protocol.oslp.elster.application.mapping.OslpGetConfigurationResponseToConfigurationConverter.java
License:Open Source License
/** * For a given Month of this year, find the date for the weekday {@link day} * .//from www . j av a 2 s .c om */ private int getLastDayOfMonth(final int month, final int day) { final DateTime dateTime = DateTime.now(); MutableDateTime x = dateTime.toMutableDateTime(); x.set(DateTimeFieldType.monthOfYear(), month); x.set(DateTimeFieldType.dayOfMonth(), 31); x = this.findLastDayOfOfMonth(day, x); return x.getDayOfMonth(); }
From source file:com.alliander.osgp.core.application.services.EventNotificationMessageService.java
License:Open Source License
private void updateRelayStatus(final int index, final Device device, final EventType eventType) { final boolean isRelayOn = EventType.LIGHT_EVENTS_LIGHT_ON.equals(eventType) || EventType.TARIFF_EVENTS_TARIFF_ON.equals(eventType); // Only handle the event if the relay doesn't have a status yet, or // if the state changed final Ssld ssld = this.ssldRepository.findOne(device.getId()); if ((ssld.getRelayStatusByIndex(index) == null) || (ssld.getRelayStatusByIndex(index).isLastKnownState() != isRelayOn)) { LOGGER.info("Handling new event {} for device {} to update the relay status for index {}.", eventType.name(), device.getDeviceIdentification(), index); ssld.updateRelayStatusByIndex(index, new RelayStatus(device, index, isRelayOn, DateTime.now().toDate())); }//from w ww . java2 s.com }
From source file:com.alliander.osgp.domain.core.valueobjects.smartmetering.CosemDateTime.java
License:Open Source License
public CosemDateTime() { this(DateTime.now()); }
From source file:com.alliander.osgp.dto.valueobjects.EventNotificationDto.java
License:Open Source License
/** * Earlier constructor without the DateTime the event occurred. For lack of * a better default this will use {@code DateTime.now()} as the moment * registered with the event./*from ww w . j a va 2 s. co m*/ * * @deprecated Use * {@link #EventNotificationDto(String, DateTime, EventTypeDto, String, Integer)} * if the time the event occurred is known. */ @Deprecated public EventNotificationDto(final String deviceUid, final EventTypeDto eventType, final String description, final Integer index) { this(deviceUid, DateTime.now(), eventType, description, index); }
From source file:com.alliander.osgp.dto.valueobjects.smartmetering.CosemDateTimeDto.java
License:Open Source License
public CosemDateTimeDto() { this(DateTime.now()); }
From source file:com.alliander.osgp.webdevicesimulator.service.OslpChannelHandler.java
License:Open Source License
private Oslp.Message handleRequest(final OslpEnvelope message, final int sequenceNumber) throws DeviceSimulatorException, IOException, ParseException { final Oslp.Message request = message.getPayloadMessage(); // Create response message Oslp.Message response = null;/*from w ww . j ava2 s .c o m*/ final String deviceIdString = Base64.encodeBase64String(message.getDeviceId()); LOGGER.info("request received, sequenceNumber: {}", sequenceNumber); LOGGER.info("manufacturerId byte[0]: {} byte[1]: {}", message.getDeviceId()[0], message.getDeviceId()[1]); LOGGER.info("deviceId as BASE 64 STRING: {}", deviceIdString); // lookup correct device. final Device device = this.deviceManagementService.findDevice(deviceIdString); if (device == null) { throw new DeviceSimulatorException("device with id: " + deviceIdString + " is unknown"); } // Calculate expected sequence number final Integer expectedSequenceNumber = device.doGetNextSequence(); // Check sequence number if (Math.abs(expectedSequenceNumber - sequenceNumber) > this.sequenceNumberWindow) { this.outOfSequenceList.add( new OutOfSequenceEvent(device.getId(), message.getPayloadMessage().toString(), DateTime.now())); throw new DeviceSimulatorException("SequenceNumber incorrect for device: " + device.getDeviceIdentification() + " Expected: " + (expectedSequenceNumber == 0 ? this.sequenceNumberMaximum : expectedSequenceNumber - 1) + " Actual: " + (sequenceNumber == 0 ? this.sequenceNumberMaximum : sequenceNumber - 1) + " SequenceNumberWindow: " + this.sequenceNumberWindow + " Request: " + message.getPayloadMessage().toString()); } // If responseDelayTime (and optional responseDelayRandomRange) are set, // sleep for a little while if (this.responseDelayTime != null && this.reponseDelayRandomRange == null) { this.sleep(this.responseDelayTime); } else if (this.responseDelayTime != null && this.reponseDelayRandomRange != null) { final Long randomDelay = (long) (this.reponseDelayRandomRange * this.random.nextDouble()); this.sleep(this.responseDelayTime + randomDelay); } // Handle only expected messages if (request.hasStartSelfTestRequest()) { device.setLightOn(true); device.setSelftestActive(true); response = createStartSelfTestResponse(); } else if (request.hasStopSelfTestRequest()) { device.setLightOn(false); device.setSelftestActive(false); response = createStopSelfTestResponse(); } else if (request.hasSetLightRequest()) { handleSetLightRequest(device, request.getSetLightRequest()); response = createSetLightResponse(); } else if (request.hasSetEventNotificationsRequest()) { this.handleSetEventNotificationsRequest(device, request.getSetEventNotificationsRequest()); response = createSetEventNotificationsResponse(); } else if (request.hasUpdateFirmwareRequest()) { this.handleUpdateFirmwareRequest(device, request.getUpdateFirmwareRequest()); response = createUpdateFirmwareResponse(); } else if (request.hasGetFirmwareVersionRequest()) { response = createGetFirmwareVersionResponse(); } else if (request.hasSwitchFirmwareRequest()) { response = createSwitchFirmwareResponse(); } else if (request.hasUpdateDeviceSslCertificationRequest()) { response = createUpdateDeviceSslCertificationResponse(); } else if (request.hasSetDeviceVerificationKeyRequest()) { response = createSetDeviceVerificationKeyResponse(); } else if (request.hasSetScheduleRequest()) { this.handleSetScheduleRequest(device, request.getSetScheduleRequest()); response = createSetScheduleResponse(); } else if (request.hasSetConfigurationRequest()) { this.handleSetConfigurationRequest(device, request.getSetConfigurationRequest()); response = this.createSetConfigurationResponse(); } else if (request.hasGetConfigurationRequest()) { this.handleGetConfigurationRequest(device, request.getGetConfigurationRequest()); response = this.createGetConfigurationResponse(device); } else if (request.hasSwitchConfigurationRequest()) { response = createSwitchConfigurationResponse(); } else if (request.hasGetActualPowerUsageRequest()) { this.handleGetActualPowerUsageRequest(device, request.getGetActualPowerUsageRequest()); response = createGetActualPowerUsageResponse(); } else if (request.hasGetPowerUsageHistoryRequest()) { this.handleGetPowerUsageHistoryRequest(device, request.getGetPowerUsageHistoryRequest()); response = createGetPowerUsageHistoryWithDatesResponse(request.getGetPowerUsageHistoryRequest()); } else if (request.hasGetStatusRequest()) { response = createGetStatusResponse(device); } else if (request.hasResumeScheduleRequest()) { response = createResumeScheduleResponse(); } else if (request.hasSetRebootRequest()) { response = createSetRebootResponse(); } else if (request.hasSetTransitionRequest()) { this.handleSetTransitionRequest(device); response = createSetTransitionResponse(); } else if (request.hasConfirmRegisterDeviceRequest()) { response = createConfirmRegisterDeviceResponse( request.getConfirmRegisterDeviceRequest().getRandomDevice(), request.getConfirmRegisterDeviceRequest().getRandomPlatform()); } else { // Handle errors by logging LOGGER.error("Did not expect request, ignoring: " + request.toString()); } // Update device device.setSequenceNumber(expectedSequenceNumber); this.deviceManagementService.updateDevice(device); // Write log entry for response LOGGER.debug("Responding: " + response); return response; }