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"));
}
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;
}
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);
}
}
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);
}
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;
}
Aggregations