@@ -467,11 +467,10 @@ public void setResources(List<IdentifiedObject> identifiedObjects) {
467467 }
468468
469469 public TimeConfiguration getTimeConfiguration () {
470- // TODO Auto-generated method stub
471- return null ;
470+ return localTimeParameters ;
472471 }
473472
474- public Long getContentId (Class resourceClass ) {
473+ public Long getContentId (Class < IdentifiedObject > resourceClass ) {
475474 // TODO its ugly right now, clean it up when templates are done
476475 Long result = 1L ;
477476 if (this .getApplicationInformation () != null ) {
@@ -534,114 +533,79 @@ public Long getContentId(Class resourceClass) {
534533 }
535534
536535 public String buildSelfHref (String hrefFragment ) {
537- // TODO its ugly right now (and getting uglier:( , clean it up when templates are done
538- // right now this is very specific to .../UsagePoint as seen in a download
539- String result = hrefFragment ;
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- }
536+ // strip the result down to the "..../resource"
537+ String result = hrefFragment .substring (0 , hrefFragment .indexOf ("/resource" ) + "/resource" .length ());
548538
549539 // now do the right thing for each resource (there will be only one non-null resource in the ContentType
550-
540+ //
551541 if (this .getApplicationInformation () != null ) {
552- result = result + this .getApplicationInformation ().getId ();
542+ result = result + "/ApplicationInformation/" + this .getApplicationInformation ().getId ();
553543 }
554544
555545 if (this .getAuthorization () != null ) {
556- result = result + this .getAuthorization ().getId ();
546+ result = result + "/Authorization/" + this .getAuthorization ().getId ();
557547 }
558548
559549 if (this .getElectricPowerQualitySummary () != null ) {
560- if ( usagePointId_P ) {
561-
562- UsagePoint usagePoint = this . getElectricPowerQualitySummary (). getUsagePoint ();
563- usagePointId = "/ " + usagePoint .getId ();
564- }
565- result = result + usagePointId + "/ElectricPowerQualitySummary/" + this .getElectricPowerQualitySummary ().getId ();
550+
551+ UsagePoint usagePoint = this . getElectricPowerQualitySummary (). getUsagePoint ();
552+ RetailCustomer retailCustomer = usagePoint . getRetailCustomer ();
553+ result = result + "/RetailCustomer/ " + retailCustomer .getId ()
554+ + "/UsagePoint/" + usagePoint . getId ()
555+ + "/ElectricPowerQualitySummary/" + this .getElectricPowerQualitySummary ().getId ();
566556 }
567557
568558 if (this .getElectricPowerUsageSummary () != null ) {
569- if (usagePointId_P ) {
570-
571- UsagePoint usagePoint = this .getElectricPowerUsageSummary ().getUsagePoint ();
572- usagePointId = "/" + usagePoint .getId ();
573- }
574-
575- result = result + usagePointId + "/ElectricPowerUsageSummary/" + this .getElectricPowerUsageSummary ().getId ();
559+ UsagePoint usagePoint = this .getElectricPowerUsageSummary ().getUsagePoint ();
560+ RetailCustomer retailCustomer = usagePoint .getRetailCustomer ();
561+ result = result + "/RetailCustomer/" + retailCustomer .getId ()
562+ + "/UsagePoint/" + usagePoint .getId ()
563+ + "/ElectricPowerUsageSummary/" + this .getElectricPowerUsageSummary ().getId ();
576564 }
577565
578566 if (this .getIntervalBlocks () != null ) {
579567 MeterReading meterReading = this .getIntervalBlocks ().get (0 ) .getMeterReading ();
580- if (usagePointId_P ) {
581-
582- UsagePoint usagePoint = meterReading .getUsagePoint ();
583- usagePointId = "/" + usagePoint .getId ();
584- }
585-
586- result = result + usagePointId + "/MeterReading/" + meterReading .getId () + "/IntervalBlock/" + this .getIntervalBlocks ().get (0 ).getId ();
568+ UsagePoint usagePoint = meterReading .getUsagePoint ();
569+ RetailCustomer retailCustomer = usagePoint .getRetailCustomer ();
570+ result = result + "/RetailCustomer/" + retailCustomer .getId ()
571+ + "/UsagePoint/" + usagePoint .getId ()
572+ + "/MeterReading/" + meterReading .getId ()
573+ + "/IntervalBlock/" + this .getIntervalBlocks ().get (0 ).getId ();
587574 }
588575
589576 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- */
577+
578+ result = result + "/LocalTimeParameters/" + this .getLocalTimeParameters ().getId ();
579+
603580 }
604581
605582 if (this .getMeterReading () != null ) {
606- if (usagePointId_P ) {
607-
608- UsagePoint usagePoint = meterReading .getUsagePoint ();
609- usagePointId = "/" + usagePoint .getId ();
610- }
611583
612- result = result + usagePointId + "/MeterReading/" + this .getMeterReading ().getId ();
584+ UsagePoint usagePoint = this .getMeterReading ().getUsagePoint ();
585+ RetailCustomer retailCustomer = usagePoint .getRetailCustomer ();
586+ result = result + "/RetailCustomer/" + retailCustomer .getId ()
587+ + "/UsagePoint/" + usagePoint .getId ()
588+ + "/MeterReading/" + meterReading .getId ();
613589 }
614590
615591 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- */
592+ result = result + "/ReadingType/" + this .getReadingType ().getId ();
631593 }
632594
633595 if (this .getRetailCustomer () != null ) {
634- result = result + "/" + this .getRetailCustomer ().getId ();
596+ result = result + "/RetailCustomer/ " + this .getRetailCustomer ().getId ();
635597 }
636598
637599 if (this .getSubscription () != null ) {
638- result = result + this .getSubscription ().getId ();
600+ result = result + "/Subscription/" + this .getSubscription ().getId ();
639601
640602 }
641603
642604 if (this .getUsagePoint () != null ) {
643- result = result + "/" + this .getUsagePoint ().getId ();
644- }
605+ RetailCustomer retailCustomer = this .getUsagePoint ().getRetailCustomer ();
606+ result = result + "/RetailCustomer/" + retailCustomer .getId ()
607+ + "/UsagePoint/" + this .getUsagePoint ().getId ();
608+ }
645609
646610 return result ;
647611
@@ -652,77 +616,63 @@ public String buildSelfHref(String hrefFragment) {
652616
653617
654618 public List <String > buildRelHref (String hrefFragment ) {
655- // TODO its ugly right now, clean it up when templates are done
656- // if the last element of the fragment is a UsagePoint, then we may be doing a full dump
657- // and the fragement generation logic is a bit different
619+ // only MeterReading and UsagePoint have "related" references
658620
659621 List <String > result = new ArrayList <String >();
660622
661623 if (this .getMeterReading () != null ) {
624+ // get the objects
662625 UsagePoint usagePoint = this .getMeterReading ().getUsagePoint ();
663626 RetailCustomer retailCustomer = usagePoint .getRetailCustomer ();
664627 ReadingType readingType = this .getMeterReading ().getReadingType ();
628+
665629 String temp = hrefFragment ;
666- String usagePointId = "" ;
667- if (hrefFragment .lastIndexOf ("UsagePoint" ) == (hrefFragment .length () - "UsagePoint" .length ())) {
668- usagePointId = "/" + usagePoint .getId ();
630+
631+ // check for ROOT form
632+ if (hrefFragment .contains ("/RetailCustomer" )) {
633+ // XPath form
634+ temp = temp .substring (0 , temp .indexOf ("/RetailCustomer" ));
635+ } else {
636+ // it is a ROOT form
637+ temp = temp .substring (0 , temp .indexOf ("/MeterReading" ));
669638 }
670639
671- temp = temp + usagePointId + "/MeterReading/" + this .getMeterReading ().getId ();
640+ // build the full path
641+ temp = temp + "/RetailCustomer/" + retailCustomer .getId () + "/UsagePoint/" + usagePoint .getId () + "/MeterReading/" + meterReading .getId ();
642+
672643 result .add (temp + "/IntervalBlock" );
673644
674- temp = temp . substring ( 0 , temp . indexOf ( "/RetailCustomer" ));
675- result .add (temp + "/ReadingType/" + readingType .getId ());
645+ // for ReadingType, make it ROOT access
646+ result .add (temp . substring ( 0 , temp . indexOf ( "/RetailCustomer" )) + "/ReadingType/" + readingType .getId ());
676647 }
677648
678649 if (this .getUsagePoint () != null ) {
650+ // get the objects
679651 RetailCustomer retailCustomer = this .getUsagePoint ().getRetailCustomer ();
680652 List <ElectricPowerQualitySummary > qualityList = this .getUsagePoint ().getElectricPowerQualitySummaries ();
681653 List <ElectricPowerUsageSummary > usageList = this .getUsagePoint ().getElectricPowerUsageSummaries ();
682654 TimeConfiguration timeConfiguration = this .getUsagePoint ().getLocalTimeParameters ();
683655 String temp = hrefFragment ;
684- String usagePointId = "" ;
685656
686- if (hrefFragment .lastIndexOf ("UsagePoint" ) == (hrefFragment .length () - "UsagePoint" .length ())) {
687- usagePointId = "/" + this .getUsagePoint ().getId ();
657+ // check for ROOT form
658+ if (hrefFragment .contains ("/RetailCustomer" )) {
659+ // XPath form
660+ temp = temp .substring (0 , temp .indexOf ("/RetailCustomer" ));
661+ } else {
662+ // ROOT form
663+ temp = temp .substring (0 , temp .indexOf ("/UsagePoint" ));
688664 }
689- temp = temp + usagePointId ;
690-
665+ // build the full path
666+ temp = temp + "/RetailCustomer/" + retailCustomer .getId () + "/UsagePoint/" + usagePoint .getId ();
667+
691668 result .add (temp + "/MeterReading" );
692669 if (!(qualityList .isEmpty ())) result .add (temp + "/ElectricPowerQualitySummary" );
693670 if (!(usageList .isEmpty ())) result .add (temp + "/ElectricPowerUsageSummary" );
694671 // for LocalTimeParameters - make it a ROOT access
695672 //
696- temp = temp .substring (0 , temp .indexOf ("/RetailCustomer" ));
697- result .add (temp + "/LocalTimeParameters/" + timeConfiguration .getId ());
673+ result .add (temp .substring (0 , temp .indexOf ("/RetailCustomer" )) + "/LocalTimeParameters/" + timeConfiguration .getId ());
698674 }
699- /*
700- if (this.getReadingType() != null) {
701- return result; }
702- if (this.getRetailCustomer() != null) {
703- return result; }
704- if (this.getSubscription() != null) {
705- return result;
706- }
707- if (this.getApplicationInformation() != null) {
708- return result;
709- }
710- if (this.getAuthorization() != null) {
711- return result;
712- }
713- if (this.getElectricPowerQualitySummary() != null) {
714- return result;
715- }
716- if (this.getElectricPowerUsageSummary() != null) {
717- return result;
718- }
719- if (this.getIntervalBlocks() != null) {
720- return result;
721- }
722- if (this.getLocalTimeParameters() != null) {
723- return result;
724- }
725- */
675+
726676 return result ;
727677 }
728678
0 commit comments