use of org.estatio.module.base.dom.UdoDomainObject2 in project estatio by estatio.
the class UdoDomainObjectContract_jdoAnnotations_Test method searchAndTest.
@SuppressWarnings("rawtypes")
@Test
public void searchAndTest() {
Reflections reflections = new Reflections("org.estatio.dom");
Set<Class<? extends UdoDomainObject>> subtypes = reflections.getSubTypesOf(UdoDomainObject.class);
for (Class<? extends UdoDomainObject> subtype : subtypes) {
if (subtype.isAnonymousClass() || subtype.isLocalClass() || subtype.isMemberClass() || subtype.getName().endsWith("ForTesting")) {
// skip (probably a testing class)
continue;
}
if (UdoDomainObject.class == subtype || UdoDomainObject2.class == subtype) {
// skip
continue;
}
System.out.println(">>> " + subtype.getName());
// must have a @PersistenceCapable(identityType=...) annotation
final PersistenceCapable persistenceCapable = subtype.getAnnotation(PersistenceCapable.class);
Assertions.assertThat(persistenceCapable).isNotNull();
IdentityType identityType = persistenceCapable.identityType();
Assertions.assertThat(identityType).isNotNull();
if (identityType == IdentityType.DATASTORE) {
// NOT mandatory to have a @DatastoreIdentity, but if does, then @DatastoreIdentity(..., column="id")
final DatastoreIdentity datastoreIdentity = subtype.getAnnotation(DatastoreIdentity.class);
if (datastoreIdentity != null) {
Assertions.assertThat(datastoreIdentity.column()).isEqualTo("id");
}
}
Inheritance inheritance = subtype.getAnnotation(Inheritance.class);
if (inheritance != null && inheritance.strategy() == InheritanceStrategy.SUPERCLASS_TABLE) {
// must NOT have a @Discriminator(..., column="discriminator")
final Annotation[] declaredAnnotations = subtype.getDeclaredAnnotations();
for (Annotation declaredAnnotation : declaredAnnotations) {
if (declaredAnnotation.annotationType() == Discriminator.class) {
Assert.fail("Class " + subtype.getName() + " inherits from " + subtype.getSuperclass().getName() + "and has (incorrectly) been annotated with @Discriminator");
}
}
// check if supertype has discriminator
// must have a @Discriminator(..., column="discriminator") on one of its supertypes
final Discriminator superDiscriminator = subtype.getSuperclass().getAnnotation(Discriminator.class);
Assertions.assertThat(superDiscriminator).isNotNull();
Assertions.assertThat(superDiscriminator.column()).isEqualTo("discriminator");
}
if (subtype.getSuperclass().equals(UdoDomainObject.class)) {
// must have a @Version(..., column="version")
final Version version = getAnnotationOfTypeOfItsSupertypes(subtype, Version.class);
Assertions.assertThat(version).isNotNull();
Assertions.assertThat(version.column()).isEqualTo("version");
}
}
}
use of org.estatio.module.base.dom.UdoDomainObject2 in project estatio by estatio.
the class ApplicationTenancyInvariantsService method on.
private void on(final ApplicationTenancyEventChanged ev, final Class<? extends ApplicationTenancyEventChanged> eventClass) {
final UdoDomainObject2 source = ev.getSource();
final List<ApplicationTenancySubscriberAlgorithm> algorithms = algorithmRegistry.lookup(source, eventClass);
for (final ApplicationTenancySubscriberAlgorithm algorithm : algorithms) {
getContainer().injectServicesInto(algorithm);
switch(ev.getEventPhase()) {
case HIDE:
algorithm.hide(ev, source);
break;
case DISABLE:
algorithm.disable(ev, source);
break;
case VALIDATE:
algorithm.validate(ev, source);
break;
case EXECUTING:
algorithm.executing(ev, source);
break;
case EXECUTED:
algorithm.executed(ev, source);
break;
}
}
}
Aggregations