public void validateBusinessEntity(EntityManager em, org.uddi.api_v3.BusinessEntity businessEntity) throws DispositionReportFaultMessage {
// A supplied businessEntity can't be null
if (businessEntity == null)
throw new ValueNotAllowedException(new ErrorMessage("errors.businessentity.NullInput"));
boolean entityExists = false;
String entityKey = businessEntity.getBusinessKey();
if (entityKey == null || entityKey.length() == 0) {
KeyGenerator keyGen = KeyGeneratorFactory.getKeyGenerator();
entityKey = keyGen.generate();
businessEntity.setBusinessKey(entityKey);
}
else {
// Per section 4.4: keys must be case-folded
entityKey = entityKey.toLowerCase();
businessEntity.setBusinessKey(entityKey);
Object obj = em.find(org.apache.juddi.model.BusinessEntity.class, entityKey);
if (obj != null) {
entityExists = true;
// Make sure publisher owns this entity.
if (!publisher.isOwner((UddiEntity)obj))
throw new UserMismatchException(new ErrorMessage("errors.usermismatch.InvalidOwner", entityKey));
}
else {
// Inside this block, we have a key proposed by the publisher on a new entity
// Validate key and then check to see that the proposed key is valid for this publisher
ValidateUDDIKey.validateUDDIv3Key(entityKey);
if (!publisher.isValidPublisherKey(em, entityKey))
throw new KeyUnavailableException(new ErrorMessage("errors.keyunavailable.BadPartition", entityKey));
}
}
if (!entityExists) {
// Check to make sure key isn't used by another entity.
if (!isUniqueKey(em, entityKey))
throw new KeyUnavailableException(new ErrorMessage("errors.keyunavailable.KeyExists", entityKey));
}
// TODO: validate "checked" categories or category groups (see section 5.2.3 of spec)? optional to support
validateNames(businessEntity.getName());