return getDatabase().findById(uuid);
}
@Override
public ExpirationType renew(UUID uuid, ExpirationType requestedExpiration) {
SubscriptionTicket ticket = getDatabase().findById(uuid);
if (ticket == null) {
throw new UnknownSubscription();
}
LOG.info("[subscription=" + ticket.getUuid() + "] Requested renew expiration: "
+ requestedExpiration.getValue());
LOG.fine("[subscription=" + ticket.getUuid() + "] Current expiration: " + ticket.getExpires().toXMLFormat());
ExpirationType response = new ExpirationType();
XMLGregorianCalendar grantedExpires;
if (DurationAndDateUtil.isDuration(requestedExpiration.getValue())) {
// duration was requested
javax.xml.datatype.Duration requestedDuration = DurationAndDateUtil
.parseDuration(requestedExpiration.getValue());
javax.xml.datatype.Duration grantedDuration = requestedDuration;
LOG.info("[subscription=" + ticket.getUuid() + "] Granted renewal duration: " + grantedDuration.toString());
grantedExpires = getDatabase().findById(uuid)
.getExpires(); // NOW() or current Expires() ????
grantedExpires.add(grantedDuration);
response.setValue(grantedDuration.toString());
} else {
// end-date was requested
grantedExpires = DurationAndDateUtil.parseXMLGregorianCalendar(requestedExpiration.getValue());
LOG.info("[subscription=" + ticket.getUuid() + "] Granted expiration: " + grantedExpires.toXMLFormat());
response.setValue(grantedExpires.toXMLFormat());
}
getDatabase().findById(uuid).setExpires(grantedExpires);
return response;
}