Search in sources :

Example 1 with SchemaHolder

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

the class MdsRestBundleIT method setUp.

@Before
public void setUp() throws IOException {
    if (getDataService() == null || getDataServiceForFilteredEntity() == null) {
        clearEntities();
        prepareEntity();
        prepareFilteredEntity();
        SchemaHolder schemaHolder = entityService.getSchema();
        jarGeneratorService.regenerateMdsDataBundle(schemaHolder);
    }
    getDataService().deleteAll();
    getDataServiceForFilteredEntity().deleteAll();
    if (!userService.hasActiveMotechAdmin()) {
        userService.registerMotechAdmin("motech", "motech", "motech@motechsuite.org", Locale.ENGLISH);
    }
    getHttpClient().getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthPolicy.BASIC), new UsernamePasswordCredentials("motech", "motech"));
}
Also used : AuthScope(org.apache.http.auth.AuthScope) SchemaHolder(org.motechproject.mds.dto.SchemaHolder) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) Before(org.junit.Before)

Example 2 with SchemaHolder

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

the class MdsBundleWatcher method lockAndGetSchema.

private SchemaHolder lockAndGetSchema() {
    LOGGER.info("Retrieving MDS schema");
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    TransactionTemplate trxTemplate = new TransactionTemplate(transactionManager);
    final SchemaHolder schemaHolder = trxTemplate.execute(new TransactionCallback<SchemaHolder>() {

        @Override
        public SchemaHolder doInTransaction(TransactionStatus status) {
            schemaChangeLockManager.acquireLock(MdsBundleWatcher.class.getName() + " - start refreshing bundles");
            SchemaHolder result = entityService.getSchema();
            schemaChangeLockManager.releaseLock(MdsBundleWatcher.class.getName() + " - start refreshing bundles");
            return result;
        }
    });
    stopWatch.stop();
    LOGGER.info("Schema retrieved in {} ms", stopWatch.getTime());
    return schemaHolder;
}
Also used : TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) TransactionStatus(org.springframework.transaction.TransactionStatus) SchemaHolder(org.motechproject.mds.dto.SchemaHolder) StopWatch(org.apache.commons.lang.time.StopWatch)

Example 3 with SchemaHolder

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

the class MdsBundleWatcher method processSingleBundle.

private void processSingleBundle(final Bundle bundle) {
    SchemaHolder schemaHolder = lockAndGetSchema();
    final MDSProcessorOutput output = process(bundle, schemaHolder);
    if (hasNonEmptyOutput(output)) {
        TransactionTemplate tmpl = new TransactionTemplate(transactionManager);
        tmpl.execute(new TransactionCallbackWithoutResult() {

            @Override
            protected void doInTransactionWithoutResult(TransactionStatus status) {
                schemaChangeLockManager.acquireLock(MdsBundleWatcher.class.getName() + " - saving output of bundle processing");
                processAnnotationScanningResults(output);
                schemaChangeLockManager.releaseLock(MdsBundleWatcher.class.getName() + " - saving output of bundle processing");
            }
        });
        schemaHolder = lockAndGetSchema();
        // if we found annotations, we will refresh the bundle in order to start weaving the
        // classes it exposes
        refreshBundle(bundle, schemaHolder);
    }
}
Also used : MDSProcessorOutput(org.motechproject.mds.annotations.internal.MDSProcessorOutput) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) TransactionStatus(org.springframework.transaction.TransactionStatus) SchemaHolder(org.motechproject.mds.dto.SchemaHolder) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult)

Example 4 with SchemaHolder

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

the class MdsBundleWatcher method start.

// called by the initializer after the initial entities bundle was generated
public void start() {
    LOGGER.info("Scanning for MDS annotations");
    bundlesToRefresh = new ArrayList<>();
    StopWatch stopWatch = new StopWatch();
    SchemaHolder schemaHolder = lockAndGetSchema();
    final List<MDSProcessorOutput> mdsProcessorOutputs = processInstalledBundles(schemaHolder);
    stopWatch.start();
    new TransactionTemplate(transactionManager).execute(new TransactionCallbackWithoutResult() {

        @Override
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            schemaChangeLockManager.acquireLock(MdsBundleWatcher.class.getName() + " - start annotation processing");
            for (MDSProcessorOutput output : mdsProcessorOutputs) {
                processAnnotationScanningResults(output);
            }
            schemaChangeLockManager.releaseLock(MdsBundleWatcher.class.getName() + " - start annotation processing");
        }
    });
    stopWatch.stop();
    LOGGER.info("Annotation processing finished in {} ms", stopWatch.getTime());
    // classes it exposes
    if (!bundlesToRefresh.isEmpty()) {
        LOGGER.info("Starting bundle refresh process");
        schemaHolder = lockAndGetSchema();
        LOGGER.info("Refreshing bundles: {}", bundlesToRefresh);
        StopWatchHelper.restart(stopWatch);
        refreshBundles(bundlesToRefresh, schemaHolder);
        stopWatch.stop();
        LOGGER.info("Bundle refresh finished in {} ms", stopWatch.getTime());
    } else {
        LOGGER.info("No bundles to refresh, proceeding");
    }
    bundleContext.addBundleListener(this);
}
Also used : MDSProcessorOutput(org.motechproject.mds.annotations.internal.MDSProcessorOutput) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) TransactionStatus(org.springframework.transaction.TransactionStatus) SchemaHolder(org.motechproject.mds.dto.SchemaHolder) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) StopWatch(org.apache.commons.lang.time.StopWatch)

Example 5 with SchemaHolder

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

the class EntityServiceImpl method getSchema.

@Override
@Transactional
public SchemaHolder getSchema() {
    StopWatch stopWatch = new StopWatch();
    SchemaHolder entitiesHolder = new SchemaHolder();
    LOGGER.debug("Retrieving entities for processing");
    stopWatch.start();
    List<Entity> entities = allEntities.getActualEntities();
    stopWatch.stop();
    LOGGER.debug("{} entities retrieved in {} ms", entities.size(), stopWatch.getTime());
    StopWatchHelper.restart(stopWatch);
    for (Entity entity : entities) {
        LOGGER.debug("Preparing entity: {}", entity.getClassName());
        StopWatchHelper.restart(stopWatch);
        EntityDto entityDto = entity.toDto();
        stopWatch.stop();
        LOGGER.debug("Entity dto created in {} ms", stopWatch.getTime());
        StopWatchHelper.restart(stopWatch);
        AdvancedSettingsDto advSettingsDto = entity.advancedSettingsDto();
        stopWatch.stop();
        LOGGER.debug("Advanced settings dto created in {} ms", stopWatch.getTime());
        StopWatchHelper.restart(stopWatch);
        List<FieldDto> fieldDtos = entity.getFieldDtos();
        stopWatch.stop();
        LOGGER.debug("Field dtos created in {} ms", stopWatch.getTime());
        StopWatchHelper.restart(stopWatch);
        entitiesHolder.addEntity(entityDto, advSettingsDto, fieldDtos);
        stopWatch.stop();
        LOGGER.debug("Result stored in {} ms", stopWatch.getTime());
    }
    LOGGER.debug("Retrieving types for processing");
    List<Type> types = allTypes.retrieveAll();
    for (Type type : types) {
        TypeDto typeDto = type.toDto();
        entitiesHolder.addType(typeDto);
        entitiesHolder.addTypeValidation(typeDto, type.getTypeValidationDtos());
    }
    LOGGER.debug("Entities holder ready");
    return entitiesHolder;
}
Also used : MdsEntity(org.motechproject.mds.domain.MdsEntity) Entity(org.motechproject.mds.domain.Entity) MdsVersionedEntity(org.motechproject.mds.domain.MdsVersionedEntity) EntityDto(org.motechproject.mds.dto.EntityDto) Type(org.motechproject.mds.domain.Type) SchemaHolder(org.motechproject.mds.dto.SchemaHolder) TypeDto(org.motechproject.mds.dto.TypeDto) AdvancedSettingsDto(org.motechproject.mds.dto.AdvancedSettingsDto) StopWatch(org.apache.commons.lang.time.StopWatch) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) FieldDto(org.motechproject.mds.dto.FieldDto) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

SchemaHolder (org.motechproject.mds.dto.SchemaHolder)24 EntityDto (org.motechproject.mds.dto.EntityDto)7 FieldDto (org.motechproject.mds.dto.FieldDto)5 LookupFieldDto (org.motechproject.mds.dto.LookupFieldDto)5 Test (org.junit.Test)4 StopWatch (org.apache.commons.lang.time.StopWatch)3 FieldBasicDto (org.motechproject.mds.dto.FieldBasicDto)3 TransactionStatus (org.springframework.transaction.TransactionStatus)3 TransactionTemplate (org.springframework.transaction.support.TransactionTemplate)3 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 Before (org.junit.Before)2 MDSProcessorOutput (org.motechproject.mds.annotations.internal.MDSProcessorOutput)2 AdvancedSettingsDto (org.motechproject.mds.dto.AdvancedSettingsDto)2 DraftData (org.motechproject.mds.dto.DraftData)2 LookupDto (org.motechproject.mds.dto.LookupDto)2 SettingDto (org.motechproject.mds.dto.SettingDto)2