Search in sources :

Example 11 with EntityDto

use of org.motechproject.mds.dto.EntityDto in project motech by motech.

the class InstanceServiceTest method shouldUpdateGridSize.

@Test
public void shouldUpdateGridSize() {
    setUpSecurityContext();
    EntityDto entityDto = new EntityDto();
    entityDto.setReadOnlySecurityMode(null);
    entityDto.setSecurityMode(null);
    entityDto.setClassName(TestSample.class.getName());
    EntityRecord entityRecord = new EntityRecord(ENTITY_ID + 1, null, new ArrayList<>());
    when(entityService.getEntity(ENTITY_ID + 1)).thenReturn(entityDto);
    mockDataService();
    instanceService.getEntityRecords(entityRecord.getId(), new QueryParams(1, 100));
    verify(entityService).getEntityFieldsForUI(ENTITY_ID + 1);
    verify(userPreferencesService).updateGridSize(ENTITY_ID + 1, "motech", 100);
}
Also used : BasicEntityRecord(org.motechproject.mds.web.domain.BasicEntityRecord) EntityRecord(org.motechproject.mds.web.domain.EntityRecord) EntityDto(org.motechproject.mds.dto.EntityDto) QueryParams(org.motechproject.mds.query.QueryParams) Test(org.junit.Test)

Example 12 with EntityDto

use of org.motechproject.mds.dto.EntityDto in project motech by motech.

the class EntityProcessor method process.

@Override
protected void process(AnnotatedElement element) {
    BundleHeaders bundleHeaders = new BundleHeaders(getBundle());
    EntityProcessorOutput entityProcessorOutput = new EntityProcessorOutput();
    Class clazz = (Class) element;
    Class<Entity> ann = ReflectionsUtil.getAnnotationClass(clazz, Entity.class);
    Annotation annotation = AnnotationUtils.findAnnotation(clazz, ann);
    if (null != annotation) {
        String className = clazz.getName();
        String name = ReflectionsUtil.getAnnotationValue(annotation, NAME, ClassName.getSimpleName(className));
        String module = ReflectionsUtil.getAnnotationValue(annotation, MODULE, bundleHeaders.getName(), bundleHeaders.getSymbolicName());
        String bundleSymbolicName = getBundle().getSymbolicName();
        String namespace = ReflectionsUtil.getAnnotationValue(annotation, NAMESPACE);
        String tableName = ReflectionsUtil.getAnnotationValue(annotation, TABLE_NAME);
        boolean recordHistory = Boolean.parseBoolean(ReflectionsUtil.getAnnotationValue(annotation, HISTORY));
        boolean nonEditable = Boolean.parseBoolean(ReflectionsUtil.getAnnotationValue(annotation, NON_EDITABLE));
        EntityDto entity = getSchemaHolder().getEntityByClassName(className);
        RestOptionsDto restOptions = new RestOptionsDto();
        TrackingDto tracking = new TrackingDto();
        Collection<FieldDto> fields;
        if (entity == null) {
            LOGGER.debug("Creating DDE for {}", className);
            entity = new EntityDto(null, className, name, module, namespace, tableName, recordHistory, SecurityMode.EVERYONE, null, null, null, clazz.getSuperclass().getName(), Modifier.isAbstract(clazz.getModifiers()), false, bundleSymbolicName);
        } else {
            LOGGER.debug("DDE for {} already exists, updating if necessary", className);
            AdvancedSettingsDto advancedSettings = getSchemaHolder().getAdvancedSettings(className);
            restOptions = advancedSettings.getRestOptions();
            tracking = advancedSettings.getTracking();
            entity.setBundleSymbolicName(bundleSymbolicName);
            entity.setModule(module);
        }
        if (!tracking.isModifiedByUser()) {
            tracking.setRecordHistory(recordHistory);
            tracking.setNonEditable(nonEditable);
        }
        setSecurityOptions(element, entity);
        // per entity maxFetchDepth that will be passed to the Persistence Manager
        setMaxFetchDepth(entity, annotation);
        entityProcessorOutput.setEntityProcessingResult(entity);
        fields = findFields(clazz, entity);
        String versionField = getVersionFieldName(clazz);
        addVersionMetadata(fields, versionField);
        addDefaultFields(entity, fields);
        restOptions = processRestOperations(clazz, restOptions);
        restOptions = findRestFields(clazz, restOptions, fields);
        updateUiChangedFields(fields, className);
        updateResults(entityProcessorOutput, clazz, fields, restOptions, tracking, versionField);
        add(entity);
        processingResult.add(entityProcessorOutput);
        MotechClassPool.registerDDE(entity.getClassName());
    } else {
        LOGGER.debug("Did not find Entity annotation in class: {}", clazz.getName());
    }
}
Also used : MdsEntity(org.motechproject.mds.domain.MdsEntity) MdsVersionedEntity(org.motechproject.mds.domain.MdsVersionedEntity) Entity(org.motechproject.mds.annotations.Entity) BundleHeaders(org.motechproject.osgi.web.util.BundleHeaders) Annotation(java.lang.annotation.Annotation) TrackingDto(org.motechproject.mds.dto.TrackingDto) EntityDto(org.motechproject.mds.dto.EntityDto) AdvancedSettingsDto(org.motechproject.mds.dto.AdvancedSettingsDto) RestOptionsDto(org.motechproject.mds.dto.RestOptionsDto) FieldDto(org.motechproject.mds.dto.FieldDto)

Example 13 with EntityDto

use of org.motechproject.mds.dto.EntityDto in project motech by motech.

the class FieldProcessor method getFieldByName.

private FieldDto getFieldByName(String className, String fieldName) {
    if (!StringUtils.equals(cachedClassname, className)) {
        EntityDto entityDto = getSchemaHolder().getEntityByClassName(className);
        if (entityDto != null) {
            cachedFields = getSchemaHolder().getFields(entityDto);
        } else {
            cachedFields = new ArrayList<>();
        }
        cachedClassname = className;
    }
    for (FieldDto field : cachedFields) {
        if (StringUtils.equals(field.getBasic().getName(), fieldName)) {
            return field;
        }
    }
    return null;
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) FieldDto(org.motechproject.mds.dto.FieldDto)

Example 14 with EntityDto

use of org.motechproject.mds.dto.EntityDto in project motech by motech.

the class MdsStressIT method stressTestCreating.

private void stressTestCreating(MotechDataService service, Class clazz) throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException, ClassNotFoundException {
    EntityDto entityDto = entityService.getEntityByClassName(FOO_CLASS);
    for (int i = 0; i < TEST_INSTANCES; i++) {
        testInstances.add(generator.makeDummyInstance(entityDto.getId()));
    }
    Long startTime = System.nanoTime();
    for (Object instance : testInstances) {
        service.create(instance);
    }
    Long endTime = (System.nanoTime() - startTime) / 1000000;
    LOGGER.info("MDS Service: Creating " + TEST_INSTANCES + " instances took " + endTime + "ms.");
    logToFile((double) endTime);
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto)

Example 15 with EntityDto

use of org.motechproject.mds.dto.EntityDto in project motech by motech.

the class EntityServiceImplTest method shouldCreateValidClassNames.

@Test
public void shouldCreateValidClassNames() throws IOException {
    EntityDto entityDto1 = new EntityDto(null, null, "test name with spaces", null, null, null, null);
    EntityDto entityDto2 = new EntityDto(null, null, "    second test      with spaces", null, null, null, null);
    EntityDto entityDto3 = new EntityDto(null, null, "Sample name  ", null, null, null, null);
    when(entity.getField((String) any())).thenReturn(null);
    when(allEntities.create((EntityDto) any())).thenReturn(entity);
    EntityDto entityDto4 = new EntityDto(null, "org.motechproject.mds.entity.TestNameWithSpaces", "test name with spaces", null, null, null, null);
    entityService.createEntity(entityDto1);
    verify(allEntities, times(1)).create(entityDto4);
    entityDto4 = new EntityDto(null, "org.motechproject.mds.entity.SecondTestWithSpaces", "second test      with spaces", null, null, null, null);
    entityService.createEntity(entityDto2);
    verify(allEntities, times(1)).create(entityDto4);
    entityDto4 = new EntityDto(null, "org.motechproject.mds.entity.SampleName", "Sample name", null, null, null, null);
    entityService.createEntity(entityDto3);
    verify(allEntities, times(1)).create(entityDto4);
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) Test(org.junit.Test)

Aggregations

EntityDto (org.motechproject.mds.dto.EntityDto)136 Test (org.junit.Test)61 FieldDto (org.motechproject.mds.dto.FieldDto)53 ArrayList (java.util.ArrayList)34 LookupFieldDto (org.motechproject.mds.dto.LookupFieldDto)32 MotechDataService (org.motechproject.mds.service.MotechDataService)26 LookupDto (org.motechproject.mds.dto.LookupDto)24 List (java.util.List)19 BasicEntityRecord (org.motechproject.mds.web.domain.BasicEntityRecord)12 Method (java.lang.reflect.Method)11 FieldTestHelper.lookupFieldDto (org.motechproject.mds.testutil.FieldTestHelper.lookupFieldDto)11 Arrays.asList (java.util.Arrays.asList)9 FieldBasicDto (org.motechproject.mds.dto.FieldBasicDto)9 EntityRecord (org.motechproject.mds.web.domain.EntityRecord)9 AdvancedSettingsDto (org.motechproject.mds.dto.AdvancedSettingsDto)7 TypeDto (org.motechproject.mds.dto.TypeDto)7 HashMap (java.util.HashMap)6 SchemaHolder (org.motechproject.mds.dto.SchemaHolder)6 BasicFieldRecord (org.motechproject.mds.web.domain.BasicFieldRecord)6 FieldRecord (org.motechproject.mds.web.domain.FieldRecord)6