Skip to content
This repository has been archived by the owner on Jan 29, 2024. It is now read-only.

Commit

Permalink
Merge pull request #58 from jateeter/master
Browse files Browse the repository at this point in the history
Subscription/ThirdParty Integration
  • Loading branch information
jateeter committed Feb 4, 2014
2 parents 0e37045 + 961b43d commit 3e94ec3
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 8 deletions.
10 changes: 6 additions & 4 deletions src/main/java/org/energyos/espi/common/domain/Subscription.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Set;

/**
Expand Down Expand Up @@ -94,8 +96,8 @@ public class Subscription

@XmlTransient
@ManyToMany
@LazyCollection(LazyCollectionOption.FALSE)
private Set<UsagePoint> usagePoints;
@LazyCollection(LazyCollectionOption.TRUE)
private List<UsagePoint> usagePoints;

public Calendar lastUpdate;

Expand Down Expand Up @@ -131,11 +133,11 @@ public Calendar getLastUpdate() {
return lastUpdate;
}

public Set<UsagePoint> getUsagePoints() {
public List<UsagePoint> getUsagePoints() {
return usagePoints;
}

public void setUsagePoints(Set<UsagePoint> usagePoints) {
public void setUsagePoints(List<UsagePoint> usagePoints) {
this.usagePoints = usagePoints;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public Subscription findById(Long id) {
@Transactional
public void deleteById(Long id) {
Subscription subscription = findById(id);
Set<UsagePoint> ups = subscription.getUsagePoints();
List<UsagePoint> ups = subscription.getUsagePoints();
Iterator<UsagePoint> it = ups.iterator();
while (it.hasNext()) {
UsagePoint up = it.next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,7 @@ public ApplicationInformation findByDataCustodianClientId(
public void setApplicationInformation(ApplicationInformation applicationInformation);

public String getDataCustodianResourceEndpoint();

public String getThirdPartyNotifyURI();

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ List<IdentifiedObject> findByAllParentsHref(String relatedHref,
<T extends IdentifiedObject> Long findIdByXPath(Long id1, Long id2, Long id3, Long id4, Class<T> clazz);

<T extends IdentifiedObject> EntryTypeIterator findEntryTypeIterator(Class<T> clazz);

<T extends IdentifiedObject> EntryTypeIterator findEntryTypeIterator(List<Long> ids, Class<T> clazz);

<T extends IdentifiedObject> EntryType findEntryType(long id1, Class<T> clazz);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,7 @@ public interface SubscriptionService {
public Subscription findById(Long retailCustomerId, Long subscriptionId);

public Subscription findByUUID(UUID uuid);

public List<Long> findUsagePointIds(Long subscriptionId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,12 @@ public ApplicationInformation importResource(InputStream stream) {
return applicationInformation;
}

@Override
public String getThirdPartyNotifyURI() {
ApplicationInformation applicationInformation;
// TODO note the assumption on the first (seed) entry
applicationInformation = resourceService.findById(1L, ApplicationInformation.class);
return applicationInformation.getThirdPartyNotifyUri();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,9 @@ public void exportSubscription(String subscriptionHashedId, OutputStream stream,
@Override
public void exportBatchSubscription(long subscriptionId, OutputStream stream, ExportFilter exportFilter) throws IOException {
String hrefFragment = "/Batch/Subscription/" + subscriptionId;
exportEntriesFull(subscriptionService.findEntryTypeIterator(subscriptionId), stream, exportFilter, hrefFragment);
// first find all the usagePointIds this subscription is related to
List<Long> usagePointIdList = subscriptionService.findUsagePointIds(subscriptionId);
exportEntriesFull(resourceService.findEntryTypeIterator(usagePointIdList, UsagePoint.class), stream, exportFilter, hrefFragment);
}

@Override
Expand Down Expand Up @@ -574,9 +576,11 @@ private String adjustFragment(String fragment, EntryType entry ) {
// TODO here need the proper URI fragment for a subscription
result = "/RetailCustomer/" + rc.getId() + "/UsagePoint"; }
if (fragment.contains("Subscription")) {
// the entry contains a valid usagepoint at this stage
//
UsagePoint up = entry.getContent().getUsagePoint();
RetailCustomer rc = up.getRetailCustomer();
// TODO here need the proper URI fragment for a subscription

result = "/RetailCustomer/" + rc.getId() + "/UsagePoint";
}
if (fragment.contains("/Batch/RetailCustomer")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ public void setRepository(ResourceRepository repository) {
@Override
public <T extends IdentifiedObject> EntryTypeIterator findEntryTypeIterator(Class<T> clazz) {
List<Long> idList = repository.findAllIds(clazz);
return findEntryTypeIterator(idList, clazz);
}

@Override
public <T extends IdentifiedObject> EntryTypeIterator findEntryTypeIterator(List<Long> ids, Class<T> clazz) {
List<Long> idList = ids;
EntryTypeIterator result = null;
try {
result = (new EntryTypeIterator(this, idList, clazz));
Expand All @@ -149,7 +155,7 @@ public <T extends IdentifiedObject> EntryTypeIterator findEntryTypeIterator(Clas
}
return result;
}

@Override
public <T extends IdentifiedObject> EntryType findEntryType(long id1, Class<T> clazz) {
EntryType result = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.energyos.espi.common.utils.DateConverter;
import org.energyos.espi.common.utils.EntryTypeIterator;
import org.energyos.espi.common.utils.ExportFilter;
import org.hibernate.mapping.Set;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
Expand Down Expand Up @@ -75,6 +76,16 @@ public Subscription createSubscription(OAuth2Authentication authentication) {
subscription.setUUID(UUID.randomUUID());
subscription.setApplicationInformation(applicationInformationService.findByClientId(authentication.getOAuth2Request().getClientId()));
subscription.setRetailCustomer((RetailCustomer)authentication.getPrincipal());
subscription.setUsagePoints(new ArrayList<UsagePoint> ());
// set up the subscription's usagePoints list. Keep in mind that right
// now this is ALL usage points belonging to the RetailCustomer.
// TODO - scope this to only a selected (proper) subset of the usagePoints.
List <Long> upIds = resourceService.findAllIdsByXPath(subscription.getRetailCustomer().getId(), UsagePoint.class);
Iterator <Long> it = upIds.iterator();
while (it.hasNext()) {
UsagePoint usagePoint = resourceService.findById(it.next(), UsagePoint.class);
subscription.getUsagePoints().add(usagePoint);
}
subscription.setLastUpdate(new GregorianCalendar());
subscriptionRepository.persist(subscription);

Expand Down Expand Up @@ -214,4 +225,17 @@ public Subscription findById(Long retailCustomerId, Long subscriptionId) {
return subscriptionRepository.findById(subscriptionId);
}

@Override
public List<Long> findUsagePointIds(Long subscriptionId) {

List<Long> result = new ArrayList<Long>();
Subscription subscription = subscriptionRepository.findById(subscriptionId);
Iterator<UsagePoint> it = subscription.getUsagePoints().iterator();
while (it.hasNext()) {
result.add(it.next().getId());
}

return result;
}

}

0 comments on commit 3e94ec3

Please sign in to comment.