Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
*
* Copyright (c) 2025 Green Button Alliance, Inc.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*
*/

package org.greenbuttonalliance.espi.common.dto.usage;

import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlRootElement;
import jakarta.xml.bind.annotation.XmlType;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
* DTO for ESPI ServiceStatus.
*
* <p>Java class for ServiceStatus complex type.
*/
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
@XmlRootElement(name = "ServiceStatus", namespace = "http://naesb.org/espi")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ServiceStatus", namespace = "http://naesb.org/espi", propOrder = {
"currentStatus"
})
public class ServiceStatusDto {

@XmlElement(required = true)
private String currentStatus;

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.greenbuttonalliance.espi.common.mapper.customer;

import org.greenbuttonalliance.espi.common.domain.customer.entity.CustomerEntity;
import org.greenbuttonalliance.espi.common.domain.usage.RetailCustomerEntity;
import org.greenbuttonalliance.espi.common.dto.customer.CustomerDto;
import org.greenbuttonalliance.espi.common.mapper.BaseMapperUtils;
import org.greenbuttonalliance.espi.common.mapper.DateTimeMapper;
Expand Down Expand Up @@ -59,6 +60,36 @@ public interface CustomerMapper {
@Mapping(target = "customerName", source = "customerName")
CustomerDto toDto(CustomerEntity entity);

/**
* Converts a RetailCustomerEntity to a CustomerDto.
* Maps essential identity fields to Customer representation.
*
* @param retailCustomer the retail customer entity
* @return the customer DTO
*/
default CustomerDto toDto(RetailCustomerEntity retailCustomer) {
if (retailCustomer == null) {
return null;
}
CustomerDto dto = new CustomerDto();
dto.setCustomerName(retailCustomer.getFirstName() + " " + retailCustomer.getLastName());

org.greenbuttonalliance.espi.common.dto.customer.OrganisationDto orgDto = new org.greenbuttonalliance.espi.common.dto.customer.OrganisationDto();
orgDto.setOrganisationName(retailCustomer.getFirstName() + " " + retailCustomer.getLastName());

org.greenbuttonalliance.espi.common.dto.customer.ElectronicAddressDto emailDto = new org.greenbuttonalliance.espi.common.dto.customer.ElectronicAddressDto();
emailDto.setEmail1(retailCustomer.getEmail());
orgDto.setElectronicAddress(emailDto);

org.greenbuttonalliance.espi.common.dto.customer.TelephoneNumberDto phoneDto = new org.greenbuttonalliance.espi.common.dto.customer.TelephoneNumberDto();
phoneDto.setLocalNumber(retailCustomer.getPhone());
orgDto.setPhone1(phoneDto);

dto.setOrganisation(orgDto);

return dto;
}

/**
* Converts a CustomerDto to a CustomerEntity.
* Maps customer information including embedded objects.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@

package org.greenbuttonalliance.espi.common.service;

import org.greenbuttonalliance.espi.common.dto.atom.AtomEntryDto;
import org.greenbuttonalliance.espi.common.dto.atom.LinkDto;
import org.greenbuttonalliance.espi.common.dto.atom.UsageAtomEntryDto;

import jakarta.annotation.PostConstruct;
import jakarta.xml.bind.JAXBContext;
import jakarta.xml.bind.JAXBException;
Expand Down Expand Up @@ -196,4 +200,40 @@ public void exportDtoWithHeader(Object dto, OutputStream stream) {
throw new RuntimeException("Failed to export DTO with header", e);
}
}

/**
* Creates an Atom entry for ServiceStatus.
*
* @param currentStatus the current service status
* @return AtomEntryDto wrapped around ServiceStatusDto
*/
public AtomEntryDto createServiceStatusEntry(String currentStatus) {
org.greenbuttonalliance.espi.common.dto.usage.ServiceStatusDto serviceStatus =
org.greenbuttonalliance.espi.common.dto.usage.ServiceStatusDto.builder()
.currentStatus(currentStatus)
.build();

AtomEntryDto entry = new UsageAtomEntryDto();
entry.setTitle("ServiceStatus");
entry.setId("urn:uuid:" + java.util.UUID.randomUUID());
entry.setPublished(java.time.OffsetDateTime.now());
entry.setUpdated(java.time.OffsetDateTime.now());

java.util.List<LinkDto> links = new java.util.ArrayList<>();

LinkDto selfLink = new LinkDto();
selfLink.setRel("self");
selfLink.setHref("ServiceStatus");
links.add(selfLink);

LinkDto upLink = new LinkDto();
upLink.setRel("up");
upLink.setHref("");
links.add(upLink);

entry.setLinks(links);
entry.setContent(serviceStatus);

return entry;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@

package org.greenbuttonalliance.espi.common.service;

import org.greenbuttonalliance.espi.common.domain.usage.ReadingTypeEntity;
import org.greenbuttonalliance.espi.common.domain.usage.RetailCustomerEntity;
import org.greenbuttonalliance.espi.common.domain.usage.TimeConfigurationEntity;
import org.greenbuttonalliance.espi.common.domain.usage.UsagePointEntity;
import org.greenbuttonalliance.espi.common.domain.usage.UsageSummaryEntity;
import org.greenbuttonalliance.espi.common.dto.atom.AtomFeedDto;
import org.greenbuttonalliance.espi.common.dto.atom.AtomEntryDto;

Expand Down Expand Up @@ -93,5 +97,43 @@ public interface DtoExportService {
*/
AtomEntryDto createAtomEntry(String title, Object resource);

AtomFeedDto createUsagePointsFeed(List<UsagePointEntity> usagePoints);

AtomFeedDto createUsagePointsFeedByIds(List<UUID> usagePointIds);

AtomEntryDto createUsagePointEntry(UsagePointEntity usagePoint);

AtomEntryDto createUsagePointEntry(UUID usagePointId);

AtomFeedDto createTimeConfigurationsFeed();

AtomFeedDto createTimeConfigurationsFeedByUsagePointId(UUID usagePointId);

AtomEntryDto createTimeConfigurationEntry(UUID timeConfigurationId);

AtomEntryDto createTimeConfigurationEntry(TimeConfigurationEntity timeConfiguration);

AtomFeedDto createRetailCustomersFeed();

AtomEntryDto createRetailCustomerEntry(Long retailCustomerId);

AtomEntryDto createRetailCustomerEntry(RetailCustomerEntity retailCustomer);

AtomFeedDto createUsageSummariesFeed();

AtomFeedDto createUsageSummariesFeedByUsagePointId(UUID usagePointId);

AtomEntryDto createUsageSummaryEntry(UUID usageSummaryId);

AtomEntryDto createUsageSummaryEntry(UsageSummaryEntity usageSummary);

AtomFeedDto createReadingTypesFeed();

AtomEntryDto createReadingTypeEntry(UUID readingTypeId);

AtomEntryDto createReadingTypeEntry(ReadingTypeEntity readingType);

AtomEntryDto createServiceStatusEntry(String currentStatus);

void exportAtomFeed(AtomFeedDto atomFeedDto, OutputStream stream);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.greenbuttonalliance.espi.common.domain.usage.ReadingTypeEntity;

import java.io.InputStream;
import java.util.List;
import java.util.UUID;

public interface ReadingTypeService {
Expand All @@ -41,6 +42,8 @@ public interface ReadingTypeService {

ReadingTypeEntity findById(UUID readingTypeId);

List<ReadingTypeEntity> findAll();

void add(ReadingTypeEntity readingType);

void delete(ReadingTypeEntity readingType);
Expand Down
Loading
Loading