protected static RevisionSpec validateRevision(String revisioneventTypeName, ConfigurationRevisionEventType config, EventAdapterService eventAdapterService)
throws ConfigurationException
{
if ((config.getNameBaseEventTypes() == null) || (config.getNameBaseEventTypes().size() == 0))
{
throw new ConfigurationException("Required base event type name is not set in the configuration for revision event type '" + revisioneventTypeName + "'");
}
if (config.getNameBaseEventTypes().size() > 1)
{
throw new ConfigurationException("Only one base event type name may be added to revision event type '" + revisioneventTypeName + "', multiple base types are not yet supported");
}
// get base types
String baseeventTypeName = config.getNameBaseEventTypes().iterator().next();
EventType baseEventType = eventAdapterService.getExistsTypeByName(baseeventTypeName);
if (baseEventType == null)
{
throw new ConfigurationException("Could not locate event type for name '" + baseeventTypeName + "' in the configuration for revision event type '" + revisioneventTypeName + "'");
}
// get name types
EventType[] deltaTypes = new EventType[config.getNameDeltaEventTypes().size()];
String[] deltaNames = new String[config.getNameDeltaEventTypes().size()];
int count = 0;
for (String deltaName : config.getNameDeltaEventTypes())
{
EventType deltaEventType = eventAdapterService.getExistsTypeByName(deltaName);
if (deltaEventType == null)
{
throw new ConfigurationException("Could not locate event type for name '" + deltaName + "' in the configuration for revision event type '" + revisioneventTypeName + "'");
}
deltaTypes[count] = deltaEventType;
deltaNames[count] = deltaName;
count++;
}
// the key properties must be set
if ((config.getKeyPropertyNames() == null) || (config.getKeyPropertyNames().length == 0))
{
throw new ConfigurationException("Required key properties are not set in the configuration for revision event type '" + revisioneventTypeName + "'");
}
// make sure the key properties exist the base type and all delta types
checkKeysExist(baseEventType, baseeventTypeName, config.getKeyPropertyNames(), revisioneventTypeName);
for (int i = 0; i < deltaTypes.length; i++)
{
checkKeysExist(deltaTypes[i], deltaNames[i], config.getKeyPropertyNames(), revisioneventTypeName);
}
// key property names shared between base and delta must have the same type
String keyPropertyNames[] = PropertyUtility.copyAndSort(config.getKeyPropertyNames());
for (String key : keyPropertyNames)
{
Class typeProperty = baseEventType.getPropertyType(key);
for (EventType dtype : deltaTypes)
{
Class dtypeProperty = dtype.getPropertyType(key);
if ((dtypeProperty != null) && (typeProperty != dtypeProperty))
{
throw new ConfigurationException("Key property named '" + key + "' does not have the same type for base and delta types of revision event type '" + revisioneventTypeName + "'");
}
}
}
// In the "declared" type the change set properties consist of only :
// (base event type properties) minus (key properties) minus (properties only on base event type)
if (config.getPropertyRevision() == ConfigurationRevisionEventType.PropertyRevision.OVERLAY_DECLARED)
{
// determine non-key properties: those overridden by any delta, and those simply only present on the base event type
String nonkeyPropertyNames[] = PropertyUtility.uniqueExclusiveSort(baseEventType.getPropertyNames(), keyPropertyNames);
Set<String> baseEventOnlyProperties = new HashSet<String>();
Set<String> changesetPropertyNames = new HashSet<String>();
for (String nonKey : nonkeyPropertyNames)
{
boolean overriddenProperty = false;
for (EventType type : deltaTypes)
{
if (type.isProperty(nonKey))
{
changesetPropertyNames.add(nonKey);
overriddenProperty = true;
break;
}
}
if (!overriddenProperty)
{
baseEventOnlyProperties.add(nonKey);
}
}
String changesetProperties[] = changesetPropertyNames.toArray(new String[changesetPropertyNames.size()]);
String baseEventOnlyPropertyNames[] = baseEventOnlyProperties.toArray(new String[baseEventOnlyProperties.size()]);
// verify that all changeset properties match event type
for (String changesetProperty : changesetProperties)
{
Class typeProperty = baseEventType.getPropertyType(changesetProperty);
for (EventType dtype : deltaTypes)
{
Class dtypeProperty = dtype.getPropertyType(changesetProperty);
if ((dtypeProperty != null) && (typeProperty != dtypeProperty))
{
throw new ConfigurationException("Property named '" + changesetProperty + "' does not have the same type for base and delta types of revision event type '" + revisioneventTypeName + "'");
}
}
}
return new RevisionSpec(config.getPropertyRevision(), baseEventType, deltaTypes, deltaNames, keyPropertyNames, changesetProperties, baseEventOnlyPropertyNames, false, null);
}
else
{
// In the "exists" type the change set properties consist of all properties: base event properties plus delta types properties
Set<String> allProperties = new HashSet<String>();
allProperties.addAll(Arrays.asList(baseEventType.getPropertyNames()));
for (EventType deltaType : deltaTypes)
{
allProperties.addAll(Arrays.asList(deltaType.getPropertyNames()));
}
String[] allPropertiesArr = allProperties.toArray(new String[allProperties.size()]);
String[] changesetProperties = PropertyUtility.uniqueExclusiveSort(allPropertiesArr, keyPropertyNames);
// All properties must have the same type, if a property exists for any given type
boolean hasContributedByDelta = false;
boolean[] contributedByDelta = new boolean[changesetProperties.length];
count = 0;
for (String property : changesetProperties)
{
Class basePropertyType = baseEventType.getPropertyType(property);
Class typeTemp = null;
if (basePropertyType != null)
{
typeTemp = basePropertyType;
}
else
{
hasContributedByDelta = true;
contributedByDelta[count] = true;
}
for (EventType dtype : deltaTypes)
{
Class dtypeProperty = dtype.getPropertyType(property);
if (dtypeProperty != null)
{
if ((typeTemp != null) && (dtypeProperty != typeTemp))
{
throw new ConfigurationException("Property named '" + property + "' does not have the same type for base and delta types of revision event type '" + revisioneventTypeName + "'");
}
}
typeTemp = dtypeProperty;
}