Search in sources :

Example 1 with ImportReader

use of org.motechproject.mds.json.ImportReader in project motech by motech.

the class ImportExportServiceImpl method importSchema.

private void importSchema(final ImportContext importContext, final JsonReader jsonReader) {
    LOGGER.debug("Importing schema...");
    doInTransaction(new TransactionCallbackWithoutResult() {

        @Override
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            try {
                ImportReader importReader = new ImportReader(jsonReader, importContext);
                importReader.importSchema();
            } catch (IOException e) {
                throw new ImportExportException("An error occurred during importing schema", e);
            }
        }
    });
    if (importContext.hasUnresolvedEntities()) {
        LOGGER.warn("Unresolved relationships found. Skipping. ({})", importContext.getUnresolvedEntities());
    }
    LOGGER.debug("Schema imported.");
    LOGGER.debug("Regenerating MDS bundle and refreshing affected bundles: {}", importContext.getAffectedModules());
    mdsBundleRegenerationService.regenerateMdsDataBundleAfterDdeEnhancement(importContext.getAffectedModulesArray());
    LOGGER.debug("Bundles regenerated/refreshed");
}
Also used : ImportReader(org.motechproject.mds.json.ImportReader) ImportExportException(org.motechproject.mds.exception.importexport.ImportExportException) TransactionStatus(org.springframework.transaction.TransactionStatus) IOException(java.io.IOException) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult)

Example 2 with ImportReader

use of org.motechproject.mds.json.ImportReader in project motech by motech.

the class ImportExportServiceImpl method importInstances.

private void importInstances(final ImportContext importContext, final JsonReader jsonReader) {
    LOGGER.debug("Importing instances...");
    doInTransaction(new TransactionCallbackWithoutResult() {

        @Override
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            try {
                importContext.removeExistingInstances();
                ImportReader importReader = new ImportReader(jsonReader, importContext);
                importReader.importInstances();
            } catch (IOException e) {
                throw new ImportExportException("An error occurred during importing schema", e);
            }
        }
    });
    LOGGER.debug("Instances imported.");
}
Also used : ImportReader(org.motechproject.mds.json.ImportReader) ImportExportException(org.motechproject.mds.exception.importexport.ImportExportException) TransactionStatus(org.springframework.transaction.TransactionStatus) IOException(java.io.IOException) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult)

Aggregations

IOException (java.io.IOException)2 ImportExportException (org.motechproject.mds.exception.importexport.ImportExportException)2 ImportReader (org.motechproject.mds.json.ImportReader)2 TransactionStatus (org.springframework.transaction.TransactionStatus)2 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)2