Skip to content
This repository was archived by the owner on Jul 1, 2025. It is now read-only.

Commit 2531472

Browse files
committed
Merge pull request #33 from jateeter/master
FInal step of <link> references conversions
2 parents 9349c43 + c43a3a4 commit 2531472

File tree

10 files changed

+350
-27
lines changed

10 files changed

+350
-27
lines changed

src/main/java/org/energyos/espi/common/domain/ObjectFactory.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public class ObjectFactory {
6565
public final static QName BatchItemInfo_QNAME = new QName("http://naesb.org/espi", "BatchItemInfo");
6666
public final static QName ElectricPowerUsageSummary_QNAME = new QName("http://naesb.org/espi", "ElectricPowerUsageSummary");
6767
public final static QName LineItem_QNAME = new QName("http://naesb.org/espi", "LineItem");
68-
68+
public final static QName RetailCustomer_QNAME = new QName("http://naesb.org/espi", "RetailCustomer");
6969
/**
7070
* Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: org.naesb.espi
7171
*/
@@ -198,6 +198,13 @@ public ReadingType createReadingType() {
198198
return new ReadingType();
199199
}
200200

201+
/**
202+
* Create an instance of {@link RetailCustomer }
203+
*/
204+
public RetailCustomer createRetailCustomer() {
205+
return new RetailCustomer();
206+
}
207+
201208
/**
202209
* Create an instance of {@link RationalNumber }
203210
*/
@@ -258,6 +265,14 @@ public JAXBElement<ReadingType> createReadingType(ReadingType value) {
258265
return new JAXBElement<ReadingType>(ReadingType_QNAME, ReadingType.class, null, value);
259266
}
260267

268+
/**
269+
* Create an instance of {@link JAXBElement }{@code <}{@link RetailCustomer }{@code >}}
270+
*/
271+
@XmlElementDecl(namespace = "http://naesb.org/espi", name = "RetailCustomer")
272+
public JAXBElement<RetailCustomer> createRetailCustomer(RetailCustomer value) {
273+
return new JAXBElement<RetailCustomer>(RetailCustomer_QNAME, RetailCustomer.class, null, value);
274+
}
275+
261276
/**
262277
* Create an instance of {@link JAXBElement }{@code <}{@link SummaryMeasurement }{@code >}}
263278
*/

src/main/java/org/energyos/espi/common/domain/ReadingType.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import javax.xml.bind.annotation.XmlAccessType;
3131
import javax.xml.bind.annotation.XmlAccessorType;
3232
import javax.xml.bind.annotation.XmlRootElement;
33+
import javax.xml.bind.annotation.XmlTransient;
3334
import javax.xml.bind.annotation.XmlType;
3435
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
3536

@@ -115,6 +116,11 @@ public class ReadingType
115116
public static final String QUERY_FIND_ALL_IDS_BY_USAGE_POINT_ID = "ReadingType.findAllIdsByUsagePointId";
116117
public static final String QUERY_FIND_ALL_IDS = "ReadingType.findAllIds";
117118

119+
@XmlTransient
120+
@OneToOne(cascade = CascadeType.PERSIST, fetch = FetchType.EAGER)
121+
@JoinColumn(name = "meter_reading_id")
122+
private MeterReading meterReading;
123+
118124
protected String accumulationBehaviour;
119125
protected String commodity;
120126
protected String consumptionTier;
@@ -137,6 +143,14 @@ public class ReadingType
137143
@Embedded
138144
protected ReadingInterharmonic interharmonic;
139145

146+
public void setMeterReading(MeterReading meterReading) {
147+
this.meterReading = meterReading;
148+
}
149+
150+
public MeterReading getMeterReading() {
151+
return this.meterReading;
152+
}
153+
140154
/**
141155
* Gets the value of the accumulationBehaviour property.
142156
*

src/main/java/org/energyos/espi/common/domain/RetailCustomer.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.energyos.espi.common.domain;
1818

19+
import org.energyos.espi.common.models.atom.adapters.RetailCustomerAdapter;
1920
import org.hibernate.annotations.Type;
2021
import org.hibernate.validator.constraints.NotEmpty;
2122
import org.springframework.security.core.GrantedAuthority;
@@ -25,22 +26,32 @@
2526
import javax.persistence.*;
2627
import javax.validation.constraints.NotNull;
2728
import javax.validation.constraints.Size;
29+
import javax.xml.bind.annotation.XmlAccessType;
30+
import javax.xml.bind.annotation.XmlAccessorType;
31+
import javax.xml.bind.annotation.XmlRootElement;
2832
import javax.xml.bind.annotation.XmlTransient;
33+
import javax.xml.bind.annotation.XmlType;
34+
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
2935

3036
import java.security.Principal;
3137
import java.util.ArrayList;
3238
import java.util.Collection;
3339

40+
@XmlRootElement(name="RetailCustomer")
41+
@XmlAccessorType(XmlAccessType.FIELD)
42+
@XmlType(name = "RetailCustomer")
3443
@Entity
3544
@Table(name = "retail_customers")
45+
@XmlJavaTypeAdapter(RetailCustomerAdapter.class)
3646
@NamedQueries(value = {
3747
@NamedQuery(name = RetailCustomer.QUERY_FIND_BY_ID, query = "SELECT customer FROM RetailCustomer customer WHERE customer.id = :id"),
3848
@NamedQuery(name = RetailCustomer.QUERY_FIND_ALL, query = "SELECT customer FROM RetailCustomer customer"),
3949
@NamedQuery(name = RetailCustomer.QUERY_FIND_BY_USERNAME, query = "SELECT customer FROM RetailCustomer customer WHERE customer.username = :username"),
4050
@NamedQuery(name = RetailCustomer.QUERY_FIND_ALL_IDS, query = "SELECT retailCustomer.id FROM RetailCustomer retailCustomer")
4151

4252
})
43-
public class RetailCustomer implements UserDetails, Principal {
53+
54+
public class RetailCustomer implements UserDetails, Principal{
4455

4556
public final static String QUERY_FIND_BY_ID = "RetailCustomer.findById";
4657
public final static String QUERY_FIND_ALL = "RetailCustomer.findAll";
@@ -50,7 +61,6 @@ public class RetailCustomer implements UserDetails, Principal {
5061
public final static String ROLE_USER = "ROLE_USER";
5162
public final static String ROLE_CUSTODIAN = "ROLE_CUSTODIAN";
5263

53-
5464
@Id
5565
@GeneratedValue(strategy = GenerationType.IDENTITY)
5666
@XmlTransient

src/main/java/org/energyos/espi/common/domain/TimeConfiguration.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,20 @@ public class TimeConfiguration extends IdentifiedObject {
9191
@XmlJavaTypeAdapter(HexBinaryAdapter.class)
9292
protected byte[] dstStartRule;
9393
protected long tzOffset;
94+
95+
@XmlTransient
96+
@OneToOne(cascade = CascadeType.PERSIST, fetch = FetchType.EAGER)
97+
@JoinColumn(name = "usage_point_id")
98+
private UsagePoint usagePoint;
9499

95-
100+
public void setUsagePoint(UsagePoint usagePoint) {
101+
this.usagePoint = usagePoint;
102+
}
103+
104+
public UsagePoint getUsagePoint() {
105+
return this.usagePoint;
106+
}
107+
96108
/**
97109
* Gets the value of the dstEndRule property.
98110
*

src/main/java/org/energyos/espi/common/models/atom/ContentType.java

Lines changed: 193 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
"applicationInformation",
7979
"authorization",
8080
"subscription",
81+
"retailCustomer",
8182
"content"
8283
})
8384
@XmlSeeAlso({
@@ -90,8 +91,13 @@
9091
Subscription.class,
9192
ElectricPowerQualitySummary.class,
9293
IntervalBlock.class,
93-
ReadingType.class
94+
ReadingType.class,
95+
ApplicationInformation.class,
96+
Authorization.class,
97+
Subscription.class,
98+
RetailCustomer.class
9499
})
100+
95101
public class ContentType {
96102

97103
@XmlElementRefs({
@@ -155,6 +161,13 @@ public class ContentType {
155161
@XmlAnyElement(lax = true)
156162
protected Subscription subscription;
157163

164+
// TODO note that the namespace here may be incorrect??
165+
@XmlElementRefs({
166+
@XmlElementRef(name = "RetailCustomer", namespace = "http://naesb.org/espi", type = JAXBElement.class, required = false),
167+
})
168+
@XmlAnyElement(lax = true)
169+
protected RetailCustomer retailCustomer;
170+
158171
@XmlMixed
159172
@XmlAnyElement(lax = true)
160173
protected List<Object> content;
@@ -217,12 +230,6 @@ public void setAuthorization(Authorization authorization){
217230
this.authorization = authorization;
218231
}
219232

220-
public Subscription getSubscription() {
221-
return this.subscription;
222-
}
223-
public void setSubscription(Subscription subscription){
224-
this.subscription = subscription;
225-
}
226233
/**
227234
* The Atom content construct is defined in section 4.1.3 of the format spec.
228235
* Gets the value of the content property.
@@ -341,6 +348,13 @@ public Map<QName, String> getOtherAttributes() {
341348
return otherAttributes;
342349
}
343350

351+
public RetailCustomer getRetailCustomer() {
352+
return this.retailCustomer;
353+
}
354+
public void setRetailCustomer(RetailCustomer retailCustomer){
355+
this.retailCustomer = retailCustomer;
356+
}
357+
344358
public void setReadingType(ReadingType readingType) {
345359
this.readingType = readingType;
346360
}
@@ -364,6 +378,14 @@ public ElectricPowerQualitySummary getElectricPowerQualitySummary() {
364378
public void setElectricPowerQualitySummary(ElectricPowerQualitySummary electricPowerQualitySummary) {
365379
this.electricPowerQualitySummary = electricPowerQualitySummary;
366380
}
381+
382+
public Subscription getSubscription() {
383+
return this.subscription;
384+
}
385+
public void setSubscription(Subscription subscription){
386+
this.subscription = subscription;
387+
}
388+
367389

368390
public TimeConfiguration getLocalTimeParameters() {
369391
return localTimeParameters;
@@ -448,5 +470,169 @@ public TimeConfiguration getTimeConfiguration() {
448470
// TODO Auto-generated method stub
449471
return null;
450472
}
473+
474+
public Long getContentId(Class resourceClass) {
475+
// TODO its ugly right now, clean it up when templates are done
476+
Long result = 1L;
477+
if (this.getApplicationInformation() != null) {
478+
if (ApplicationInformation.class.equals(resourceClass)) {
479+
return this.getApplicationInformation().getId();
480+
}
481+
}
482+
if (this.getAuthorization() != null) {
483+
if (Authorization.class.equals(resourceClass)) {
484+
return this.getAuthorization().getId();
485+
}
486+
}
487+
if (this.getElectricPowerQualitySummary() != null) {
488+
if (ElectricPowerQualitySummary.class.equals(resourceClass)) {
489+
return this.getElectricPowerQualitySummary().getId();
490+
}
491+
}
492+
if (this.getElectricPowerUsageSummary() != null) {
493+
if (ElectricPowerUsageSummary.class.equals(resourceClass)) {
494+
return this.getElectricPowerUsageSummary().getId();
495+
}
496+
}
497+
if (this.getIntervalBlocks() != null) {
498+
// TODO this one is not right, but may not be needed??
499+
if (IntervalBlock.class.equals(resourceClass)) {
500+
return this.getIntervalBlocks().get(0).getId();
501+
}
502+
}
503+
if (this.getLocalTimeParameters() != null) {
504+
if (TimeConfiguration.class.equals(resourceClass)) {
505+
return this.getLocalTimeParameters().getId();
506+
}
507+
}
508+
if (this.getMeterReading() != null) {
509+
if (MeterReading.class.equals(resourceClass)) {
510+
return this.getMeterReading().getId();
511+
}
512+
}
513+
if (this.getReadingType() != null) {
514+
if (ReadingType.class.equals(resourceClass)) {
515+
return this.getReadingType().getId();
516+
}
517+
}
518+
if (this.getRetailCustomer() != null) {
519+
if (RetailCustomer.class.equals(resourceClass)) {
520+
return this.getRetailCustomer().getId();
521+
}
522+
}
523+
if (this.getSubscription() != null) {
524+
if (Subscription.class.equals(resourceClass)) {
525+
return this.getSubscription().getId();
526+
}
527+
}
528+
if (this.getUsagePoint() != null) {
529+
if (UsagePoint.class.equals(resourceClass)) {
530+
return this.getUsagePoint().getId();
531+
}
532+
}
533+
return result;
534+
}
535+
536+
public String buildSelfHref(String hrefFragment) {
537+
// TODO its ugly right now, clean it up when templates are done
538+
String result = "";
539+
if (this.getApplicationInformation() != null) {
540+
return "/ApplicationInformation/" + this.getApplicationInformation().getId();
541+
}
542+
if (this.getAuthorization() != null) {
543+
return "/Authorization/" + this.getAuthorization().getId();
544+
}
545+
if (this.getElectricPowerQualitySummary() != null) {
546+
UsagePoint usagePoint = this.getElectricPowerQualitySummary().getUsagePoint();
547+
RetailCustomer retailCustomer = usagePoint.getRetailCustomer();
548+
return "/RetailCustomer/" + retailCustomer.getId() + "/UsagePoint/" + usagePoint.getId() + "/ElectricPowerQualitySummary/" + this.getElectricPowerQualitySummary().getId();
549+
}
550+
if (this.getElectricPowerUsageSummary() != null) {
551+
UsagePoint usagePoint = this.getElectricPowerUsageSummary().getUsagePoint();
552+
RetailCustomer retailCustomer = usagePoint.getRetailCustomer();
553+
return "/RetailCustomer/" + retailCustomer.getId() + "/UsagePoint/" + usagePoint.getId() + "/ElectricPowerUsageSummary/" + this.getElectricPowerUsageSummary().getId();
554+
}
555+
if (this.getIntervalBlocks() != null) {
556+
MeterReading meterReading = this.getIntervalBlocks().get(0).getMeterReading();
557+
UsagePoint usagePoint = meterReading.getUsagePoint();
558+
RetailCustomer retailCustomer = usagePoint.getRetailCustomer();
559+
return "/RetailCustomer/" + retailCustomer.getId() + "/UsagePoint/" + usagePoint.getId() + "/MeterReading/" + meterReading.getId() + "/IntervalBlock/" + this.getIntervalBlocks().get(0).getId();
560+
}
561+
if (this.getLocalTimeParameters() != null) {
562+
UsagePoint usagePoint = this.getLocalTimeParameters().getUsagePoint();
563+
RetailCustomer retailCustomer = usagePoint.getRetailCustomer();
564+
return "/RetailCustomer/" + retailCustomer.getId() + "/UsagePoint/" + usagePoint.getId() + "/LocalTimeParameters/" + this.getLocalTimeParameters().getId();
565+
}
566+
if (this.getMeterReading() != null) {
567+
UsagePoint usagePoint = this.getMeterReading().getUsagePoint();
568+
RetailCustomer retailCustomer = usagePoint.getRetailCustomer();
569+
return "/RetailCustomer/" + retailCustomer.getId() + "/UsagePoint/" + usagePoint.getId() + "/MeterReading/" + this.getMeterReading().getId();
570+
}
571+
if (this.getReadingType() != null) {
572+
MeterReading meterReading = this.getReadingType().getMeterReading();
573+
UsagePoint usagePoint = meterReading.getUsagePoint();
574+
RetailCustomer retailCustomer = usagePoint.getRetailCustomer();
575+
return "/RetailCustomer/" + retailCustomer.getId() + "/UsagePoint/" + usagePoint.getId() + "/MeterReading/" + meterReading.getId() + "/ReadingType/" + this.getReadingType().getId();
576+
}
577+
if (this.getRetailCustomer() != null) {
578+
return "/RetailCustomer/" + this.getRetailCustomer().getId();
579+
}
580+
if (this.getSubscription() != null) {
581+
return "/Subscription/" + this.getSubscription().getId();
582+
583+
}
584+
if (this.getUsagePoint() != null) {
585+
RetailCustomer retailCustomer = this.getUsagePoint().getRetailCustomer();
586+
return "/RetailCustomer/" + retailCustomer.getId() + "/UsagePoint/" + this.getUsagePoint().getId();
587+
}
588+
return result;
589+
}
590+
591+
public List<String> buildRelHref(String hrefFragment) {
592+
// TODO its ugly right now, clean it up when templates are done
593+
List<String> result = new ArrayList<String>();
594+
595+
if (this.getApplicationInformation() != null) {
596+
return result;
597+
}
598+
if (this.getAuthorization() != null) {
599+
return result;
600+
}
601+
if (this.getElectricPowerQualitySummary() != null) {
602+
return result;
603+
}
604+
if (this.getElectricPowerUsageSummary() != null) {
605+
return result;
606+
}
607+
if (this.getIntervalBlocks() != null) {
608+
return result;
609+
}
610+
if (this.getLocalTimeParameters() != null) {
611+
return result; }
612+
if (this.getMeterReading() != null) {
613+
UsagePoint usagePoint = this.getMeterReading().getUsagePoint();
614+
RetailCustomer retailCustomer = usagePoint.getRetailCustomer();
615+
ReadingType readingType = this.getMeterReading().getReadingType();
616+
result.add("/RetailCustomer/" + retailCustomer.getId() + "/UsagePoint/" + usagePoint.getId() + "/MeterReading/" + this.getMeterReading().getId() + "/IntervalBlock");
617+
result.add("/RetailCustomer/" + retailCustomer.getId() + "/UsagePoint/" + usagePoint.getId() + "/MeterReading/" + this.getMeterReading().getId() + "/ReadingType/" + readingType.getId());
618+
return result; }
619+
if (this.getReadingType() != null) {
620+
return result; }
621+
if (this.getRetailCustomer() != null) {
622+
return result; }
623+
if (this.getSubscription() != null) {
624+
return result;
625+
}
626+
if (this.getUsagePoint() != null) {
627+
RetailCustomer retailCustomer = this.getUsagePoint().getRetailCustomer();
628+
TimeConfiguration timeConfiguration = this.getUsagePoint().getLocalTimeParameters();
629+
result.add("/RetailCustomer/" + retailCustomer.getId() + "/UsagePoint/" + this.getUsagePoint().getId() + "/MeterReading");
630+
result.add("/RetailCustomer/" + retailCustomer.getId() + "/UsagePoint/" + this.getUsagePoint().getId() + "/ElectricPowerQualitySummary");
631+
result.add("/RetailCustomer/" + retailCustomer.getId() + "/UsagePoint/" + this.getUsagePoint().getId() + "/ElectricPowerUsageSummary");
632+
result.add("/RetailCustomer/" + retailCustomer.getId() + "/UsagePoint/" + this.getUsagePoint().getId() + "/LocalTimeParameters/" + timeConfiguration.getId());
633+
return result;
634+
}
635+
return result;
636+
}
451637

452638
}

0 commit comments

Comments
 (0)