use of org.motechproject.mds.domain.ClassData in project motech by motech.
the class MDSConstructorImpl method buildClasses.
private Map<String, ClassData> buildClasses(List<EntityDto> entities, SchemaHolder schemaHolder) {
Map<String, ClassData> classDataMap = new LinkedHashMap<>();
// We build classes for all entities
for (EntityDto entity : entities) {
List<FieldDto> fields = schemaHolder.getFields(entity);
ClassData classData = buildClass(entity, fields);
ClassData historyClassData = null;
if (entity.isRecordHistory()) {
historyClassData = entityBuilder.buildHistory(entity, fields);
}
ClassData trashClassData = entityBuilder.buildTrash(entity, fields);
String className = entity.getClassName();
classDataMap.put(className, classData);
if (historyClassData != null) {
classDataMap.put(ClassName.getHistoryClassName(className), historyClassData);
}
classDataMap.put(ClassName.getTrashClassName(className), trashClassData);
}
return classDataMap;
}
use of org.motechproject.mds.domain.ClassData in project motech by motech.
the class MDSConstructorImpl method buildInfrastructure.
private void buildInfrastructure(EntityDto entity, SchemaHolder schemaHolder) {
String className = entity.getClassName();
List<ClassData> infrastructure = infrastructureBuilder.buildInfrastructure(entity, schemaHolder);
for (ClassData classData : infrastructure) {
// coming from the UI
if (classData.isInterfaceClass() && MotechClassPool.isServiceInterfaceRegistered(className)) {
MotechClassPool.registerEnhancedClassData(classData);
}
}
}
use of org.motechproject.mds.domain.ClassData in project motech by motech.
the class MDSConstructorImpl method buildEnum.
private void buildEnum(JavassistLoader loader, MdsJDOEnhancer enhancer, ComboboxHolder holder) {
ClassData data = enumBuilder.build(holder);
ByteArrayClassPath classPath = new ByteArrayClassPath(data.getClassName(), data.getBytecode());
MotechClassPool.getDefault().appendClassPath(classPath);
MotechClassPool.registerEnhancedClassData(data);
// register with the classloader so that we avoid issues with the persistence manager
MDSClassLoader.getInstance().safeDefineClass(data.getClassName(), data.getBytecode());
addClassData(loader, enhancer, data);
}
use of org.motechproject.mds.domain.ClassData in project motech by motech.
the class MDSConstructorImpl method buildClass.
private ClassData buildClass(EntityDto entity, List<FieldDto> fields) {
ClassData classData;
if (entity.isDDE()) {
// for DDE we load the class coming from the bundle
Bundle declaringBundle = MdsBundleHelper.searchForBundle(bundleContext, entity);
if (declaringBundle == null) {
throw new EntityCreationException("Declaring bundle unavailable for entity " + entity.getClassName());
}
classData = entityBuilder.buildDDE(entity, fields, declaringBundle);
} else {
classData = entityBuilder.build(entity, fields);
}
return classData;
}
use of org.motechproject.mds.domain.ClassData in project motech by motech.
the class EntityInfrastructureBuilderTest method shouldCreateCodeIfClassNotExistsInClassPath.
@Test
public void shouldCreateCodeIfClassNotExistsInClassPath() throws Exception {
doReturn(null).when(classLoader).loadClass(SAMPLE_SERVICE);
EntityDto entity = new EntityDto(Sample.class.getName());
List<ClassData> data = entityInfrastructureBuilder.buildInfrastructure(entity, schemaHolder);
assertNotNull(data);
assertFalse(data.isEmpty());
assertThat(data, hasItem(Matchers.<ClassData>hasProperty("className", equalTo(SAMPLE_REPOSITORY))));
assertThat(data, hasItem(Matchers.<ClassData>hasProperty("className", equalTo(SAMPLE_INTERFACE))));
assertThat(data, hasItem(Matchers.<ClassData>hasProperty("className", equalTo(SAMPLE_SERVICE))));
assertThat(data, hasItem(Matchers.<ClassData>hasProperty("interfaceClass", equalTo(true))));
}
Aggregations