use of org.motechproject.mds.dto.AdvancedSettingsDto in project motech by motech.
the class EntityProcessorTest method setUp.
@Before
public void setUp() throws Exception {
processor = new EntityProcessor();
processor.setFieldProcessor(fieldProcessor);
processor.setUIFilterableProcessor(uiFilterableProcessor);
processor.setUIDisplayableProcessor(uiDisplayableProcessor);
processor.setRestOperationsProcessor(restOperationsProcessor);
processor.setRestIgnoreProcessor(restIgnoreProcessor);
processor.setCrudEventsProcessor(crudEventsProcessor);
processor.setNonEditableProcessor(nonEditableProcessor);
processor.setBundle(bundle);
processor.setSchemaHolder(schemaHolder);
processor.beforeExecution();
when(schemaHolder.getType(Long.class)).thenReturn(TypeDto.LONG);
when(schemaHolder.getType(String.class)).thenReturn(TypeDto.STRING);
when(schemaHolder.getType(DateTime.class)).thenReturn(TypeDto.DATETIME);
when(schemaHolder.getEntityByClassName(AnotherSample.class.getName())).thenReturn(entity);
when(schemaHolder.getEntityByClassName(ReadAccessSample.class.getName())).thenReturn(readOnlyEntity);
when(schemaHolder.getAdvancedSettings(anyString())).thenReturn(new AdvancedSettingsDto());
setUpMockBundle();
}
use of org.motechproject.mds.dto.AdvancedSettingsDto in project motech by motech.
the class ExampleData method getAdvanced.
public AdvancedSettingsDto getAdvanced(Long entityId) {
AdvancedSettingsDto found = clone(AdvancedSettingsDto.class, getPurgeAdvanced(entityId));
if (advancedHistory.containsKey(entityId)) {
AdvancedSettingsDto temporary = advancedHistory.get(entityId);
found.setId(temporary.getId());
found.setEntityId(temporary.getEntityId());
found.setTracking(temporary.getTracking());
found.setIndexes(temporary.getIndexes());
found.setRestOptions(temporary.getRestOptions());
found.setBrowsing(temporary.getBrowsing());
}
return found;
}
use of org.motechproject.mds.dto.AdvancedSettingsDto in project motech by motech.
the class FieldHelperTest method shouldEditLookups.
@Test
public void shouldEditLookups() {
AdvancedSettingsDto advancedSettingsDto = advancedSettingsDto();
FieldHelper.setField(advancedSettingsDto, "indexes.0.lookupName", asList("newVal"));
assertEquals("newVal", advancedSettingsDto.getIndexes().get(0).getLookupName());
FieldHelper.setField(advancedSettingsDto, "indexes.1.singleObjectReturn", asList(true));
assertTrue(advancedSettingsDto.getIndexes().get(1).isSingleObjectReturn());
}
use of org.motechproject.mds.dto.AdvancedSettingsDto in project motech by motech.
the class BaseInstanceIT method createService.
private MotechDataService createService() throws Exception {
Object repository = MDSClassLoader.getInstance().loadClass(getRepositoryClass()).newInstance();
Object service = MDSClassLoader.getInstance().loadClass(getServiceClass()).newInstance();
EntityInfoReader entityInfoReader = new EntityInfoReader() {
@Override
public EntityInfo getEntityInfo(String entityClassName) {
return buildEntityInfo();
}
@Override
public EntityInfo getEntityInfo(Long entityId) {
return buildEntityInfo();
}
@Override
public Collection<String> getEntitiesClassNames() {
List<String> classNames = new ArrayList<>();
classNames.add(entity.getClassName());
return classNames;
}
private EntityInfo buildEntityInfo() {
EntityInfo info = new EntityInfo();
info.setEntity(entity);
info.setAdvancedSettings(new AdvancedSettingsDto());
List<FieldInfo> fieldInfos = new ArrayList<>();
for (FieldDto fieldDto : getEntityFields()) {
FieldInfo fieldInfo = new FieldInfo();
fieldInfo.setField(fieldDto);
fieldInfos.add(fieldInfo);
}
info.setFieldsInfo(fieldInfos);
return info;
}
};
PropertyUtil.safeSetProperty(repository, "persistenceManagerFactory", getDataPersistenceManagerFactory());
PropertyUtil.safeSetProperty(service, "transactionManager", getDataTransactionManager());
PropertyUtil.safeSetProperty(service, "repository", repository);
PropertyUtil.safeSetProperty(service, "entityInfoReader", entityInfoReader);
PropertyUtil.safeSetProperty(service, "historyService", getHistoryService());
PropertyUtil.safeSetProperty(service, "trashService", getTrashService());
PropertyUtil.safeSetProperty(service, "osgiEventProxy", getOsgiEventProxy());
MotechDataService mds = (MotechDataService) service;
((DefaultMotechDataService) mds).init();
return mds;
}
use of org.motechproject.mds.dto.AdvancedSettingsDto 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();
}
}
Aggregations