}
public void validateTModel(EntityManager em, org.uddi.api_v3.TModel tModel, Configuration config) throws DispositionReportFaultMessage {
// A supplied tModel can't be null
if (tModel == null)
throw new ValueNotAllowedException(new ErrorMessage("errors.tmodel.NullInput"));
boolean entityExists = false;
String entityKey = tModel.getTModelKey();
if (entityKey == null || entityKey.length() == 0) {
KeyGenerator keyGen = KeyGeneratorFactory.getKeyGenerator();
entityKey = keyGen.generate();
tModel.setTModelKey(entityKey);
}
else {
// Per section 4.4: keys must be case-folded
entityKey = entityKey.toLowerCase();
tModel.setTModelKey(entityKey);
Object obj = em.find(org.apache.juddi.model.Tmodel.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
// First test to see if this is a Key Generator tModel. The keyGenerator suffix appearing in the key is the indicator, since this is not
// allowed *unless* it's a key generator.
if (entityKey.toUpperCase().contains(KeyGenerator.KEYGENERATOR_SUFFIX.toUpperCase())) {
ValidateUDDIKey.validateUDDIv3KeyGeneratorTModel(tModel);
// The root publisher is only allowed one key generator. This is published in the installation.
String rootPublisherStr = "root";
try {
rootPublisherStr = AppConfig.getConfiguration().getString(Property.JUDDI_ROOT_PUBLISHER);
} catch (ConfigurationException ce) {
log.error("Could not read the root publisher setting in the configuration.");
}
if (publisher.getAuthorizedName().equals(rootPublisherStr))
throw new FatalErrorException(new ErrorMessage("errors.tmodel.keygenerator.RootKeyGen"));
// It's a valid Key Generator, but is it available for this publisher?
if (!publisher.isKeyGeneratorAvailable(em, entityKey))
throw new KeyUnavailableException(new ErrorMessage("errors.keyunavailable.BadPartition", entityKey));
}
else {
// If not a key generator, then simply 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
if (tModel.getName() == null)
throw new ValueNotAllowedException(new ErrorMessage("errors.tmodel.NoName"));
validateCategoryBag(tModel.getCategoryBag(), config);
validateIdentifierBag(tModel.getIdentifierBag(), config);
List<org.uddi.api_v3.OverviewDoc> overviewDocList = tModel.getOverviewDoc();