use of org.motechproject.mds.entityinfo.EntityInfo in project motech by motech.
the class JarGeneratorServiceImpl method generate.
@Override
public File generate(SchemaHolder schemaHolder) throws IOException {
Path tempDir = Files.createTempDirectory("mds");
Path tempFile = Files.createTempFile(tempDir, "mds-entities", ".jar");
java.util.jar.Manifest manifest = createManifest();
StringBuilder entityNamesSb = new StringBuilder();
StringBuilder historyEntitySb = new StringBuilder();
try (FileOutputStream fileOutput = new FileOutputStream(tempFile.toFile());
JarOutputStream output = new JarOutputStream(fileOutput, manifest)) {
List<EntityInfo> information = new ArrayList<>();
for (ClassData classData : MotechClassPool.getEnhancedClasses(false)) {
String className = classData.getClassName();
// insert entity class, only for EUDE, note that this can also be a generated enum class
if (!classData.isDDE()) {
addEntry(output, JavassistUtil.toClassPath(className), classData.getBytecode());
}
// insert history and trash classes, these classes will not be present for enums
ClassData historyClassData = MotechClassPool.getHistoryClassData(className);
if (historyClassData != null) {
addEntry(output, JavassistUtil.toClassPath(historyClassData.getClassName()), historyClassData.getBytecode());
historyEntitySb.append(className).append('\n');
}
ClassData trashClassData = MotechClassPool.getTrashClassData(className);
if (trashClassData != null) {
addEntry(output, JavassistUtil.toClassPath(trashClassData.getClassName()), trashClassData.getBytecode());
}
if (!classData.isEnumClassData()) {
EntityDto entity = schemaHolder.getEntityByClassName(classData.getClassName());
List<FieldDto> fields = schemaHolder.getFields(entity);
AdvancedSettingsDto advancedSettings = schemaHolder.getAdvancedSettings(entity);
EntityInfo info = buildEntityInfo(entity, fields, advancedSettings);
// we keep the name to construct a file containing all entity names
// the file is required for schema generation
entityNamesSb.append(className).append('\n');
// insert repository
String repositoryName = MotechClassPool.getRepositoryName(className);
if (addClass(output, repositoryName)) {
info.setRepository(repositoryName);
}
// insert service implementation
String serviceClass = MotechClassPool.getServiceImplName(className);
if (addClass(output, serviceClass)) {
info.setServiceClass(serviceClass);
info.setServiceName(ClassName.getServiceName(className));
}
// insert the interface
String interfaceName = MotechClassPool.getInterfaceName(className);
if (MotechClassPool.isServiceInterfaceRegistered(className)) {
// we import the service interface
info.setInterfaceName(interfaceName);
} else {
// we generated the service interface from scratch and include it in the bundle
if (addClass(output, interfaceName)) {
info.setInterfaceName(interfaceName);
}
}
information.add(info);
}
}
String blueprint = mergeTemplate(information, BLUEPRINT_TEMPLATE);
String context = mergeTemplate(information, MDS_ENTITIES_CONTEXT_TEMPLATE);
String channel = mergeTemplate(information, MDS_CHANNEL_TEMPLATE);
jdoListenerRegistryService.updateEntityNames();
jdoListenerRegistryService.removeInactiveListeners(entityNamesSb.toString());
String entityWithListenersNames = jdoListenerRegistryService.getEntitiesListenerStr();
addEntries(output, blueprint, context, channel, entityNamesSb.toString(), historyEntitySb.toString(), entityWithListenersNames);
addEntityInfoFiles(output, information);
return tempFile.toFile();
}
}
use of org.motechproject.mds.entityinfo.EntityInfo in project motech by motech.
the class JarGeneratorServiceImpl method buildEntityInfo.
private EntityInfo buildEntityInfo(EntityDto entity, List<FieldDto> fields, AdvancedSettingsDto advancedSettings) {
EntityInfo info = new EntityInfo();
info.setEntity(entity);
info.setAdvancedSettings(advancedSettings);
info.setFieldsInfo(getFieldsInfo(entity, fields, advancedSettings));
return info;
}
use of org.motechproject.mds.entityinfo.EntityInfo in project motech by motech.
the class JarGeneratorServiceImpl method addEntityInfoFiles.
private void addEntityInfoFiles(JarOutputStream output, List<EntityInfo> entityInfos) throws IOException {
final ObjectMapper objectMapper = new ObjectMapper();
for (EntityInfo entityInfo : entityInfos) {
String asJson = objectMapper.writeValueAsString(entityInfo);
addEntry(output, ENTITY_INFO_DIR + entityInfo.getClassName() + ".json", asJson.getBytes(Charset.forName("UTF-8")));
}
}
use of org.motechproject.mds.entityinfo.EntityInfo in project motech by motech.
the class MdsRestFacadeImpl method init.
@PostConstruct
public void init() {
entityClass = dataService.getClassType();
EntityInfo entity = entityInfoReader.getEntityInfo(entityClass.getName());
moduleName = entity.getModule();
entityName = entity.getName();
namespace = entity.getNamespace();
readRestOptions(entity);
Map<String, FieldDto> fieldMap = DtoHelper.asFieldMapByName(entity.getFieldDtos());
readLookups(entity);
readFieldsExposedByRest(fieldMap);
readBlobFieldsExposedByRest(fieldMap);
}
Aggregations