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

Commit 3a1e800

Browse files
committed
Merge pull request #54 from jateeter/master
/Batch/.../UsagePoint & .../UsagePoint/1 as well as fixing <link> to
2 parents 1adb20c + bcd358c commit 3a1e800

2 files changed

Lines changed: 120 additions & 87 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public class Routes {
106106
public static final String RETAIL_CUSTOMER_MEMBER_UPLOAD_MY_DATA = "/espi/1_1/resource/RetailCustomer/{retailCustomerId}/UploadMyData";
107107

108108
// paterns for RESTful Batch services
109-
public static final String BATCH_DOWNLOAD_MY_DATA_COLLECTION = "/espi/1_1/resource/Batch/RetailCustomer/{retailCustomerId}";
109+
public static final String BATCH_DOWNLOAD_MY_DATA_COLLECTION = "/espi/1_1/resource/Batch/RetailCustomer/{retailCustomerId}/UsagePoint";
110110
public static final String BATCH_DOWNLOAD_MY_DATA_MEMBER = "/espi/1_1/resource/Batch/RetailCustomer/{retailCustomerId}/UsagePoint/{usagePointId}";
111111
public static final String BATCH_UPLOAD_MY_DATA = "/espi/1_1/resource/Batch/RetailCustomer/{retailCustomerId}";
112112
public static final String BATCH_BULK_MEMBER = "/espi/1_1/resource/Batch/Bulk/{bulkId}";

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

Lines changed: 119 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -534,101 +534,126 @@ public Long getContentId(Class resourceClass) {
534534
}
535535

536536
public String buildSelfHref(String hrefFragment) {
537-
// TODO its ugly right now, clean it up when templates are done
537+
// TODO its ugly right now (and getting uglier:( , clean it up when templates are done
538538
// right now this is very specific to .../UsagePoint as seen in a download
539539
String result = hrefFragment;
540-
// if the last element of the fragment is a UsagePoint, the we may be doing a full dump
541-
// and the fragment generation logic is a bit different
542-
if (hrefFragment.lastIndexOf("UsagePoint") == (hrefFragment.length() - "UsagePoint".length())) {
543-
if (this.getApplicationInformation() != null) {
544-
return result + this.getApplicationInformation().getId();
545-
}
546-
if (this.getAuthorization() != null) {
547-
return result + this.getAuthorization().getId();
548-
}
549-
if (this.getElectricPowerQualitySummary() != null) {
550-
UsagePoint usagePoint = this.getElectricPowerQualitySummary()
551-
.getUsagePoint();
552-
RetailCustomer retailCustomer = usagePoint.getRetailCustomer();
553-
return result + "/" + usagePoint.getId()
554-
+ "/ElectricPowerQualitySummary/"
555-
+ this.getElectricPowerQualitySummary().getId();
556-
}
557-
if (this.getElectricPowerUsageSummary() != null) {
558-
UsagePoint usagePoint = this.getElectricPowerUsageSummary()
559-
.getUsagePoint();
560-
RetailCustomer retailCustomer = usagePoint.getRetailCustomer();
561-
return result + "/" + usagePoint.getId()
562-
+ "/ElectricPowerUsageSummary/"
563-
+ this.getElectricPowerUsageSummary().getId();
564-
}
565-
if (this.getIntervalBlocks() != null) {
566-
MeterReading meterReading = this.getIntervalBlocks().get(0)
567-
.getMeterReading();
568-
UsagePoint usagePoint = meterReading.getUsagePoint();
569-
RetailCustomer retailCustomer = usagePoint.getRetailCustomer();
570-
return result + "/" + usagePoint.getId() + "/MeterReading/"
571-
+ meterReading.getId() + "/IntervalBlock/"
572-
+ this.getIntervalBlocks().get(0).getId();
573-
}
574-
if (this.getLocalTimeParameters() != null) {
575-
// here, we assume "result" has got the right mutated hrefFragment ...
576-
return result + "/LocalTimeParameters/" + this.getLocalTimeParameters().getId();
577-
/*
578-
* // if one had a normal structure, one would have ...
579-
UsagePoint usagePoint = this.getLocalTimeParameters()
580-
.getUsagePoint();
581-
RetailCustomer retailCustomer = usagePoint.getRetailCustomer();
582-
return result + "/" + usagePoint.getId()
583-
+ "/LocalTimeParameters/"
584-
+ this.getLocalTimeParameters().getId();
585-
*/
586-
}
587-
if (this.getMeterReading() != null) {
588-
UsagePoint usagePoint = this.getMeterReading().getUsagePoint();
589-
RetailCustomer retailCustomer = usagePoint.getRetailCustomer();
590-
return result + "/" + usagePoint.getId() + "/MeterReading/"
591-
+ this.getMeterReading().getId();
592-
}
593-
if (this.getReadingType() != null) {
594-
// here, we assume "result" has got the right mutated hrefFragment ...
595-
return result + "/ReadingType/" + this.getReadingType().getId();
596-
/*
597-
* // if one had a normal structure, one would have ...
598-
599-
MeterReading meterReading = this.getReadingType()
600-
.getMeterReading();
601-
UsagePoint usagePoint = meterReading.getUsagePoint();
602-
RetailCustomer retailCustomer = usagePoint.getRetailCustomer();
603-
return result + "/" + usagePoint.getId() + "/MeterReading/"
604-
+ meterReading.getId() + "/ReadingType/"
605-
+ this.getReadingType().getId();
606-
*/
540+
String usagePointId = "";
541+
Boolean usagePointId_P = false;
542+
543+
// if the last element of the fragment is a UsagePoint, we will need to add a usagePointId to the URI
544+
if (hrefFragment.lastIndexOf("UsagePoint") == (hrefFragment.length() - "UsagePoint".length()))
545+
{
546+
usagePointId_P = true;
547+
}
548+
549+
// now do the right thing for each resource (there will be only one non-null resource in the ContentType
550+
551+
if (this.getApplicationInformation() != null) {
552+
result = result + this.getApplicationInformation().getId();
553+
}
554+
555+
if (this.getAuthorization() != null) {
556+
result = result + this.getAuthorization().getId();
557+
}
558+
559+
if (this.getElectricPowerQualitySummary() != null) {
560+
if (usagePointId_P) {
561+
562+
UsagePoint usagePoint = this.getElectricPowerQualitySummary().getUsagePoint();
563+
usagePointId = "/" + usagePoint.getId();
607564
}
608-
if (this.getRetailCustomer() != null) {
609-
return result + "/" + this.getRetailCustomer().getId();
565+
result = result + usagePointId + "/ElectricPowerQualitySummary/" + this.getElectricPowerQualitySummary().getId();
566+
}
567+
568+
if (this.getElectricPowerUsageSummary() != null) {
569+
if (usagePointId_P) {
570+
571+
UsagePoint usagePoint = this.getElectricPowerUsageSummary().getUsagePoint();
572+
usagePointId = "/" + usagePoint.getId();
610573
}
611-
if (this.getSubscription() != null) {
612-
return result + this.getSubscription().getId();
574+
575+
result = result + usagePointId + "/ElectricPowerUsageSummary/" + this.getElectricPowerUsageSummary().getId();
576+
}
577+
578+
if (this.getIntervalBlocks() != null) {
579+
MeterReading meterReading = this.getIntervalBlocks().get(0) .getMeterReading();
580+
if (usagePointId_P) {
613581

582+
UsagePoint usagePoint = meterReading.getUsagePoint();
583+
usagePointId = "/" + usagePoint.getId();
614584
}
615-
if (this.getUsagePoint() != null) {
616-
RetailCustomer retailCustomer = this.getUsagePoint()
617-
.getRetailCustomer();
618-
return result + "/" + this.getUsagePoint().getId();
585+
586+
result = result + usagePointId + "/MeterReading/" + meterReading.getId() + "/IntervalBlock/" + this.getIntervalBlocks().get(0).getId();
587+
}
588+
589+
if (this.getLocalTimeParameters() != null) {
590+
// here, we assume "result" has got the right mutated hrefFragment ...
591+
String temp = result.substring(0, result.indexOf("/RetailCustomer"));
592+
// temp now has only the .../espi/1_1/resource in it.
593+
result = temp + "/LocalTimeParameters/" + this.getLocalTimeParameters().getId();
594+
/*
595+
// if one had a normal structure, one would have ...
596+
UsagePoint usagePoint = this.getLocalTimeParameters()
597+
.getUsagePoint();
598+
RetailCustomer retailCustomer = usagePoint.getRetailCustomer();
599+
result = result + "/" + usagePoint.getId()
600+
+ "/LocalTimeParameters/"
601+
+ this.getLocalTimeParameters().getId();
602+
*/
603+
}
604+
605+
if (this.getMeterReading() != null) {
606+
if (usagePointId_P) {
607+
608+
UsagePoint usagePoint = meterReading.getUsagePoint();
609+
usagePointId = "/" + usagePoint.getId();
619610
}
620-
} else {
621-
// we get here if we have a specific GET to a resource - in this
622-
// case, the hrefFragment should be correct as it stands
623-
result = hrefFragment;
611+
612+
result = result + usagePointId + "/MeterReading/" + this.getMeterReading().getId();
624613
}
614+
615+
if (this.getReadingType() != null) {
616+
// here, we assume "result" has got the right mutated hrefFragment ...
617+
String temp = result.substring(0, result.indexOf("/RetailCustomer"));
618+
// temp now has only the .../espi/1_1/resource in it.
619+
result = temp + "/ReadingType/" + this.getReadingType().getId();
620+
/*
621+
* // if one had a normal structure, one would have ...
622+
623+
MeterReading meterReading = this.getReadingType()
624+
.getMeterReading();
625+
UsagePoint usagePoint = meterReading.getUsagePoint();
626+
RetailCustomer retailCustomer = usagePoint.getRetailCustomer();
627+
result = result + "/" + usagePoint.getId() + "/MeterReading/"
628+
+ meterReading.getId() + "/ReadingType/"
629+
+ this.getReadingType().getId();
630+
*/
631+
}
632+
633+
if (this.getRetailCustomer() != null) {
634+
result = result + "/" + this.getRetailCustomer().getId();
635+
}
636+
637+
if (this.getSubscription() != null) {
638+
result = result + this.getSubscription().getId();
639+
640+
}
641+
642+
if (this.getUsagePoint() != null) {
643+
result = result + "/" + this.getUsagePoint().getId();
644+
}
645+
625646
return result;
626-
}
647+
648+
}
649+
650+
651+
627652

628653

629654
public List<String> buildRelHref(String hrefFragment) {
630655
// TODO its ugly right now, clean it up when templates are done
631-
// if the last element of the fragment is a UsagePoint, the we may be doing a full dump
656+
// if the last element of the fragment is a UsagePoint, then we may be doing a full dump
632657
// and the fragement generation logic is a bit different
633658

634659
List<String> result = new ArrayList<String>();
@@ -638,10 +663,14 @@ public List<String> buildRelHref(String hrefFragment) {
638663
RetailCustomer retailCustomer = usagePoint.getRetailCustomer();
639664
ReadingType readingType = this.getMeterReading().getReadingType();
640665
String temp = hrefFragment;
666+
String usagePointId = "";
641667
if (hrefFragment.lastIndexOf("UsagePoint") == (hrefFragment.length() - "UsagePoint".length())) {
642-
temp = temp + "/" + usagePoint.getId() + "/MeterReading/" + this.getMeterReading().getId();
643-
}
668+
usagePointId = "/" + usagePoint.getId();
669+
}
670+
671+
temp = temp + usagePointId + "/MeterReading/" + this.getMeterReading().getId();
644672
result.add(temp + "/IntervalBlock");
673+
645674
temp = temp.substring(0, temp.indexOf("/RetailCustomer"));
646675
result.add(temp + "/ReadingType/" + readingType.getId());
647676
}
@@ -652,13 +681,17 @@ public List<String> buildRelHref(String hrefFragment) {
652681
List <ElectricPowerUsageSummary> usageList = this.getUsagePoint().getElectricPowerUsageSummaries();
653682
TimeConfiguration timeConfiguration = this.getUsagePoint().getLocalTimeParameters();
654683
String temp = hrefFragment;
684+
String usagePointId = "";
685+
655686
if (hrefFragment.lastIndexOf("UsagePoint") == (hrefFragment.length() - "UsagePoint".length())) {
656-
temp = temp + "/" + this.getUsagePoint().getId();
687+
usagePointId = "/" + this.getUsagePoint().getId();
657688
}
689+
temp = temp + usagePointId;
690+
658691
result.add(temp + "/MeterReading");
659692
if (!(qualityList.isEmpty())) result.add(temp + "/ElectricPowerQualitySummary");
660693
if (!(usageList.isEmpty())) result.add(temp + "/ElectricPowerUsageSummary");
661-
// for LocalTimeParameters - maket it a ROOT access
694+
// for LocalTimeParameters - make it a ROOT access
662695
//
663696
temp = temp.substring(0, temp.indexOf("/RetailCustomer"));
664697
result.add(temp + "/LocalTimeParameters/" + timeConfiguration.getId());

0 commit comments

Comments
 (0)