Search in sources :

Example 11 with AdvancedSettingsDto

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();
}
Also used : ReadAccessSample(org.motechproject.mds.annotations.internal.samples.ReadAccessSample) AdvancedSettingsDto(org.motechproject.mds.dto.AdvancedSettingsDto) AnotherSample(org.motechproject.mds.annotations.internal.samples.AnotherSample) Before(org.junit.Before)

Example 12 with AdvancedSettingsDto

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;
}
Also used : AdvancedSettingsDto(org.motechproject.mds.dto.AdvancedSettingsDto)

Example 13 with AdvancedSettingsDto

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());
}
Also used : AdvancedSettingsDto(org.motechproject.mds.dto.AdvancedSettingsDto) Test(org.junit.Test)

Example 14 with AdvancedSettingsDto

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;
}
Also used : ArrayList(java.util.ArrayList) DefaultMotechDataService(org.motechproject.mds.service.DefaultMotechDataService) MotechDataService(org.motechproject.mds.service.MotechDataService) EntityInfoReader(org.motechproject.mds.entityinfo.EntityInfoReader) EntityInfo(org.motechproject.mds.entityinfo.EntityInfo) AdvancedSettingsDto(org.motechproject.mds.dto.AdvancedSettingsDto) DefaultMotechDataService(org.motechproject.mds.service.DefaultMotechDataService) FieldInfo(org.motechproject.mds.entityinfo.FieldInfo) FieldDto(org.motechproject.mds.dto.FieldDto)

Example 15 with AdvancedSettingsDto

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();
    }
}
Also used : Path(java.nio.file.Path) ArrayList(java.util.ArrayList) JarOutputStream(java.util.jar.JarOutputStream) EntityDto(org.motechproject.mds.dto.EntityDto) ClassData(org.motechproject.mds.domain.ClassData) EntityInfo(org.motechproject.mds.entityinfo.EntityInfo) FileOutputStream(java.io.FileOutputStream) AdvancedSettingsDto(org.motechproject.mds.dto.AdvancedSettingsDto) FieldDto(org.motechproject.mds.dto.FieldDto)

Aggregations

AdvancedSettingsDto (org.motechproject.mds.dto.AdvancedSettingsDto)17 Test (org.junit.Test)7 EntityDto (org.motechproject.mds.dto.EntityDto)7 FieldDto (org.motechproject.mds.dto.FieldDto)7 ArrayList (java.util.ArrayList)5 LookupDto (org.motechproject.mds.dto.LookupDto)5 RestOptionsDto (org.motechproject.mds.dto.RestOptionsDto)5 LookupFieldDto (org.motechproject.mds.dto.LookupFieldDto)4 TrackingDto (org.motechproject.mds.dto.TrackingDto)3 LinkedList (java.util.LinkedList)2 List (java.util.List)2 AnotherSample (org.motechproject.mds.annotations.internal.samples.AnotherSample)2 ReadAccessSample (org.motechproject.mds.annotations.internal.samples.ReadAccessSample)2 MdsEntity (org.motechproject.mds.domain.MdsEntity)2 MdsVersionedEntity (org.motechproject.mds.domain.MdsVersionedEntity)2 SchemaHolder (org.motechproject.mds.dto.SchemaHolder)2 EntityInfo (org.motechproject.mds.entityinfo.EntityInfo)2 FileOutputStream (java.io.FileOutputStream)1 Annotation (java.lang.annotation.Annotation)1 Method (java.lang.reflect.Method)1