Search in sources :

Example 1 with TrackingDto

use of org.motechproject.mds.dto.TrackingDto 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 2 with TrackingDto

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

the class Entity method advancedSettingsDto.

@NotPersistent
public AdvancedSettingsDto advancedSettingsDto() {
    AdvancedSettingsDto advancedSettingsDto = new AdvancedSettingsDto();
    RestOptionsDto restDto;
    if (null == restOptions) {
        restDto = new RestOptions(this).toDto();
    } else {
        restDto = restOptions.toDto();
    }
    List<LookupDto> indexes = new ArrayList<>();
    for (Lookup lookup : getLookups()) {
        indexes.add(lookup.toDto());
    }
    Tracking trackingMapping = getTracking();
    TrackingDto trackingDto = (trackingMapping == null) ? new TrackingDto() : trackingMapping.toDto();
    advancedSettingsDto.setIndexes(indexes);
    advancedSettingsDto.setEntityId(getId());
    advancedSettingsDto.setBrowsing(getBrowsingSettings().toDto());
    advancedSettingsDto.setRestOptions(restDto);
    advancedSettingsDto.setTracking(trackingDto);
    return advancedSettingsDto;
}
Also used : LookupDto(org.motechproject.mds.dto.LookupDto) ArrayList(java.util.ArrayList) AdvancedSettingsDto(org.motechproject.mds.dto.AdvancedSettingsDto) RestOptionsDto(org.motechproject.mds.dto.RestOptionsDto) TrackingDto(org.motechproject.mds.dto.TrackingDto) NotPersistent(javax.jdo.annotations.NotPersistent)

Example 3 with TrackingDto

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

the class BaseInstanceIT method setUpEntity.

private void setUpEntity() throws Exception {
    String entityClass = getEntityClassName();
    entity = new EntityDto(entityClass);
    entity.setRecordHistory(true);
    entity = entityService.createEntity(entity);
    entityService.addFields(entity, getEntityFields());
    TrackingDto tracking = entityService.getAdvancedSettings(entity.getId(), true).getTracking();
    tracking.setAllowCreateEvent(false);
    tracking.setAllowUpdateEvent(false);
    tracking.setAllowDeleteEvent(false);
    entityService.updateTracking(entity.getId(), tracking);
    SchemaHolder schemaHolder = entityService.getSchema();
    mdsConstructor.constructEntities(schemaHolder);
    PersistenceManagerFactory factory = getDataPersistenceManagerFactory();
    if (null == factory.getMetadata(entityClass)) {
        factory.registerMetadata(metadataHolder.getJdoMetadata());
    }
    CtClass ctClass = MotechClassPool.getDefault().get(getRepositoryClass());
    MDSClassLoader.getInstance().safeDefineClass(getRepositoryClass(), ctClass.toBytecode());
    ctClass = MotechClassPool.getDefault().get(getInterfaceClass());
    MDSClassLoader.getInstance().safeDefineClass(getInterfaceClass(), ctClass.toBytecode());
    ctClass = MotechClassPool.getDefault().get(getServiceClass());
    MDSClassLoader.getInstance().safeDefineClass(getServiceClass(), ctClass.toBytecode());
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) CtClass(javassist.CtClass) SchemaHolder(org.motechproject.mds.dto.SchemaHolder) PersistenceManagerFactory(javax.jdo.PersistenceManagerFactory) TrackingDto(org.motechproject.mds.dto.TrackingDto)

Example 4 with TrackingDto

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

the class EntityProcessorTest method shouldSetRecordHistoryFlag.

@Test
public void shouldSetRecordHistoryFlag() {
    processor.process(AnotherSample.class);
    verify(crudEventsProcessor).setClazz(AnotherSample.class);
    verify(crudEventsProcessor).setTrackingDto(trackingDtoCaptor.capture());
    verify(crudEventsProcessor).execute(bundle, schemaHolder);
    TrackingDto trackingDto = trackingDtoCaptor.getValue();
    assertFalse(trackingDto.isRecordHistory());
    processor.process(Sample.class);
    verify(crudEventsProcessor).setClazz(Sample.class);
    verify(crudEventsProcessor, times(2)).setTrackingDto(trackingDtoCaptor.capture());
    verify(crudEventsProcessor, times(2)).execute(bundle, schemaHolder);
    trackingDto = trackingDtoCaptor.getValue();
    assertTrue(trackingDto.isRecordHistory());
}
Also used : TrackingDto(org.motechproject.mds.dto.TrackingDto) Test(org.junit.Test)

Example 5 with TrackingDto

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

the class EntityProcessorTest method shouldSetNonEditableFlag.

@Test
public void shouldSetNonEditableFlag() {
    processor.process(AnotherSample.class);
    verify(crudEventsProcessor).setClazz(AnotherSample.class);
    verify(crudEventsProcessor).setTrackingDto(trackingDtoCaptor.capture());
    verify(crudEventsProcessor).execute(bundle, schemaHolder);
    TrackingDto trackingDto = trackingDtoCaptor.getValue();
    assertTrue(trackingDto.isNonEditable());
    processor.process(Sample.class);
    verify(crudEventsProcessor).setClazz(Sample.class);
    verify(crudEventsProcessor, times(2)).setTrackingDto(trackingDtoCaptor.capture());
    verify(crudEventsProcessor, times(2)).execute(bundle, schemaHolder);
    trackingDto = trackingDtoCaptor.getValue();
    assertFalse(trackingDto.isNonEditable());
}
Also used : TrackingDto(org.motechproject.mds.dto.TrackingDto) Test(org.junit.Test)

Aggregations

TrackingDto (org.motechproject.mds.dto.TrackingDto)8 Test (org.junit.Test)3 AdvancedSettingsDto (org.motechproject.mds.dto.AdvancedSettingsDto)3 EntityDto (org.motechproject.mds.dto.EntityDto)3 RestOptionsDto (org.motechproject.mds.dto.RestOptionsDto)2 Annotation (java.lang.annotation.Annotation)1 ArrayList (java.util.ArrayList)1 CtClass (javassist.CtClass)1 PersistenceManagerFactory (javax.jdo.PersistenceManagerFactory)1 NotPersistent (javax.jdo.annotations.NotPersistent)1 Entity (org.motechproject.mds.annotations.Entity)1 AnotherInvalidSecuritySample (org.motechproject.mds.annotations.internal.samples.AnotherInvalidSecuritySample)1 AnotherSample (org.motechproject.mds.annotations.internal.samples.AnotherSample)1 InvalidSecuritySample (org.motechproject.mds.annotations.internal.samples.InvalidSecuritySample)1 ReadAccessSample (org.motechproject.mds.annotations.internal.samples.ReadAccessSample)1 RelatedSample (org.motechproject.mds.annotations.internal.samples.RelatedSample)1 Sample (org.motechproject.mds.annotations.internal.samples.Sample)1 MdsEntity (org.motechproject.mds.domain.MdsEntity)1 MdsVersionedEntity (org.motechproject.mds.domain.MdsVersionedEntity)1 FieldDto (org.motechproject.mds.dto.FieldDto)1