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 #79 from jateeter/master
Browse files Browse the repository at this point in the history
completed AssociateUsagePoint bug fix
  • Loading branch information
jateeter committed Feb 27, 2014
2 parents c98c931 + 952b7ce commit 4fc61a0
Showing 1 changed file with 51 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,54 +147,59 @@ public RetailCustomer importResource(InputStream stream) {

@Transactional
@Override
public Subscription associateByUUID(Long retailCustomerId, UUID uuId) {
public Subscription associateByUUID(Long retailCustomerId, UUID uuid) {
Subscription subscription = null;
UsagePoint usagePoint = new UsagePoint();
usagePoint.setUUID(uuId);

RetailCustomer retailCustomer = findById(retailCustomerId);
usagePoint.setServiceCategory(new ServiceCategory(ServiceCategory.ELECTRICITY_SERVICE));
usagePoint.setRetailCustomer(retailCustomer);
usagePointService.createOrReplaceByUUID(usagePoint);

// now retrieve the result and use it for any pending subscriptions
usagePoint = usagePointService.findByUUID(uuId);

// now see if there are any authorizations for this information
//
try {

List<Authorization> authorizationList = authorizationService.findAllByRetailCustomerId(retailCustomer.getId());
Iterator<Authorization> authorizationIterator = authorizationList.iterator();

while (authorizationIterator.hasNext()) {

Authorization authorization = authorizationIterator.next();
subscription = subscriptionService.findByAuthorizationId(authorization.getId());
String resourceUri = authorization.getResourceURI();
if (resourceUri == null) {

// this is the first time this authorization has been in effect. We
// must set up the appropriate resource links
ApplicationInformation applicationInformation = authorization.getApplicationInformation();
resourceUri = applicationInformation.getDataCustodianResourceEndpoint();
resourceUri = resourceUri + "/Batch/Subscription/" + subscription.getId();
authorization.setResourceURI(resourceUri);
}

// make sure the UsagePoints we just imported are linked up with
// the subscription if any
subscription = subscriptionService.addUsagePoint(subscription, usagePoint);
resourceService.persist(subscription);
resourceService.persist(usagePoint);
}
} catch (Exception e){
// we don't expect any problems here, and if we do have an exception,
// it will rollback the transaction.
e.printStackTrace();
return null;
}
RetailCustomer retailCustomer = null;
UsagePoint usagePoint = null;

try {
retailCustomer = resourceService.findById(retailCustomerId, RetailCustomer.class);

usagePoint = resourceService.findByUUID(uuid, UsagePoint.class);

if (usagePoint == null) {

usagePoint = new UsagePoint();
usagePoint.setUUID(uuid);
usagePoint.setDescription("A Temporary UsagePoint Description");
resourceService.persist(usagePoint);

}
usagePoint.setRetailCustomer(retailCustomer);
resourceService.merge(usagePoint);


// now see if there are any authorizations for this information
//
try {

for (Authorization authorization : authorizationService.findAllByRetailCustomerId(retailCustomer.getId())) {


String resourceUri = authorization.getResourceURI();
if (resourceUri == null) {

authorization.setResourceURI(authorization.getApplicationInformation().getDataCustodianResourceEndpoint()
+ "/Batch/Subscription/" + subscription.getId());
resourceService.merge(authorization);

}

subscription = subscriptionService.findByAuthorizationId(authorization.getId());

subscription.getUsagePoints().add(usagePoint);
resourceService.merge(subscription);
}
} catch (Exception e){
// we get here if we don't have a subscription
return null;
}


} catch (Exception e) {
System.out.printf("****Error Associating UsagePoint: %s - %s\n", retailCustomer.toString(), usagePoint.toString());
}

return subscription;
}

Expand Down

0 comments on commit 4fc61a0

Please sign in to comment.