public void validateTransferEntities(EntityManager em, TransferEntities body) throws DispositionReportFaultMessage {
// No null input
if (body == null)
throw new FatalErrorException(new ErrorMessage("errors.NullInput"));
org.uddi.custody_v3.TransferToken apiTransferToken = body.getTransferToken();
if (apiTransferToken == null)
throw new FatalErrorException(new ErrorMessage("errors.transfertoken.NullInput"));
KeyBag keyBag = body.getKeyBag();
if (keyBag == null)
throw new FatalErrorException(new ErrorMessage("errors.keybag.NullInput"));
List<String> apiKeyList = keyBag.getKey();
if (apiKeyList == null || apiKeyList.size() == 0)
throw new ValueNotAllowedException(new ErrorMessage("errors.keybag.NoInput"));
String transferTokenId = new String(apiTransferToken.getOpaqueToken());
org.apache.juddi.model.TransferToken modelTransferToken = em.find(org.apache.juddi.model.TransferToken.class, transferTokenId);
if (modelTransferToken == null)
throw new TransferNotAllowedException(new ErrorMessage("errors.transferentities.TokenNotFound", transferTokenId));
Date now = new Date();
if (now.after(modelTransferToken.getExpirationDate()))
throw new TransferNotAllowedException(new ErrorMessage("errors.transferentities.TokenExpired", transferTokenId));
List<TransferTokenKey> transferKeyList = modelTransferToken.getTransferKeys();
List<String> modelKeyList = new ArrayList<String>(0);
if (transferKeyList != null && transferKeyList.size() > 0) {
for (TransferTokenKey ttk : transferKeyList)
modelKeyList.add(ttk.getEntityKey());
}
// The keys in the supplied key bag must match exactly the keys in the stored transfer and the entities must exist
Collections.sort(apiKeyList);
Collections.sort(modelKeyList);
int count = 0;
for (String key : apiKeyList) {
if (!key.equalsIgnoreCase(modelKeyList.get(count)))
throw new TransferNotAllowedException(new ErrorMessage("errors.transferentities.KeyMismatch", key + " & " + modelKeyList.get(count)));
UddiEntity uddiEntity = em.find(UddiEntity.class, key);
if (uddiEntity == null)
throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.EntityNotFound", key));
count++;
}
}