Integer chunkData = null;
if (body.getChunkToken() != null && body.getChunkToken().length() > 0) {
SubscriptionChunkToken chunkToken = em.find(SubscriptionChunkToken.class, body.getChunkToken());
if (chunkToken == null)
throw new InvalidValueException(new ErrorMessage("errors.getsubscriptionresult.InvalidChunkToken", body.getChunkToken()));
if (!chunkToken.getSubscriptionKey().equals(chunkToken.getSubscriptionKey()))
throw new InvalidValueException(new ErrorMessage("errors.getsubscriptionresult.NonMatchingChunkToken", body.getChunkToken()));
if (chunkToken.getStartPoint() != null && chunkToken.getStartPoint().getTime() != startPointDate.getTime())
throw new InvalidValueException(new ErrorMessage("errors.getsubscriptionresult.NonMatchingChunkToken", body.getChunkToken()));
if (chunkToken.getEndPoint() != null && chunkToken.getEndPoint().getTime() != endPointDate.getTime())
throw new InvalidValueException(new ErrorMessage("errors.getsubscriptionresult.NonMatchingChunkToken", body.getChunkToken()));
if (chunkToken.getExpiresAfter().before(new Date()))
throw new InvalidValueException(new ErrorMessage("errors.getsubscriptionresult.ExpiredChunkToken", body.getChunkToken()));
chunkData = chunkToken.getData();
// We've got the data from the chunk token, now it is no longer needed (once it's called, it's used up)
em.remove(chunkToken);
}