use of org.motechproject.mds.exception.MdsException in project motech by motech.
the class EntitiesBundleMonitor method start.
/**
* Starts or updates the entities bundle from the given {@code File}.
*
* @param src file that points to an entities bundle jar
* @param startBundle {@code true} if the generated bundle should start;
* otherwise {@code false}.
* @see org.motechproject.mds.service.JarGeneratorService
*/
public void start(File src, boolean startBundle) {
LOGGER.debug("Starting bundle from: {}", src);
try (InputStream stream = new FileInputStream(src)) {
Bundle entitiesBundle = getEntitiesBundle();
if (entitiesBundle == null) {
LOGGER.info("Entities bundle does not exist");
install(stream);
} else if (Bundle.INSTALLED == entitiesBundle.getState()) {
LOGGER.info("Entities bundle exists and it is installed");
update(stream);
} else {
LOGGER.info("Entities bundle exists and it is resolved");
stopEntitiesBundle();
update(stream);
}
if (startBundle) {
start();
}
} catch (IOException e) {
throw new MdsException("Unable to read temporary entities bundle", e);
}
}
use of org.motechproject.mds.exception.MdsException in project motech by motech.
the class EntitiesBundleMonitor method install.
private void install(InputStream stream) {
LOGGER.info("Installing the entities bundle");
try {
bundleContext.installBundle(bundleLocation(), stream);
} catch (BundleException e) {
throw new MdsException("Unable to install the entities bundle", e);
}
waitUntil(new Condition() {
@Override
public boolean await() {
return !bundleInstalled;
}
}, "installed");
LOGGER.info("Installed the entities bundle");
}
use of org.motechproject.mds.exception.MdsException in project motech by motech.
the class StateManagerUtil method setTransactionVersion.
/**
* Sets the given transaction version to the instance state manager.
*
* @param instance the instance from which state manager will be retrieved
* @param version the transaction version
* @param versionFieldName the name of the version field
*/
public static void setTransactionVersion(Object instance, Object version, String versionFieldName) {
try {
StateManagerImpl stateManager = getStateManager(instance);
stateManager.setVersion(version);
AbstractClassMetaData cmd = stateManager.getClassMetaData();
int fieldPosition = cmd.getAbsolutePositionOfMember(versionFieldName);
boolean[] dirtyFields = getDirtyFields(stateManager);
// we must mark version field as non dirty
dirtyFields[fieldPosition] = false;
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new MdsException("Cannot set proper transaction version", e);
}
}
use of org.motechproject.mds.exception.MdsException in project motech by motech.
the class MdsBundleWatcher method processAnnotationScanningResults.
private void processAnnotationScanningResults(MDSProcessorOutput output) {
Map<String, Long> entityIdMappings = new HashMap<>();
Set<String> newEntities = new HashSet<>();
Bundle bundle = output.getBundle();
try {
migrationService.processBundle(bundle);
} catch (IOException e) {
LOGGER.error("An error occurred while copying the migrations from bundle: {}", bundle.getSymbolicName(), e);
}
try {
editableLookupsLoader.addEditableLookups(output, bundle);
} catch (MdsException e) {
LOGGER.error("Unable to read JSON defined lookups from bundle: {}", bundle, e);
}
for (EntityProcessorOutput result : output.getEntityProcessorOutputs()) {
EntityDto processedEntity = result.getEntityProcessingResult();
EntityDto entity = entityService.getEntityByClassName(processedEntity.getClassName());
if (entity == null) {
entity = entityService.createEntity(processedEntity);
newEntities.add(entity.getClassName());
}
entityIdMappings.put(entity.getClassName(), entity.getId());
entityService.updateRestOptions(entity.getId(), result.getRestProcessingResult());
entityService.updateTracking(entity.getId(), result.getTrackingProcessingResult());
entityService.addFields(entity, result.getFieldProcessingResult());
entityService.addFilterableFields(entity, result.getUiFilterableProcessingResult());
entityService.addDisplayedFields(entity, result.getUiDisplayableProcessingResult());
entityService.updateSecurityOptions(entity.getId(), processedEntity.getSecurityMode(), processedEntity.getSecurityMembers(), processedEntity.getReadOnlySecurityMode(), processedEntity.getReadOnlySecurityMembers());
entityService.updateMaxFetchDepth(entity.getId(), processedEntity.getMaxFetchDepth());
entityService.addNonEditableFields(entity, result.getNonEditableProcessingResult());
}
for (Map.Entry<String, List<LookupDto>> entry : output.getLookupProcessorOutputs().entrySet()) {
String entityClassName = entry.getKey();
Long entityId = entityIdMappings.get(entityClassName);
if (schemaComparator.lookupsDiffer(entityId, entry.getValue())) {
entityService.addLookups(entityId, entry.getValue());
if (!newEntities.contains(entityClassName)) {
entityService.incrementVersion(entityId);
}
}
}
}
use of org.motechproject.mds.exception.MdsException in project motech by motech.
the class EntitiesBundleMonitor method start.
/**
* Starts the entities bundle and waits until it will be started and its context will be
* initialized.
*/
public void start() {
LOGGER.info("Starting the entities bundle");
try {
Bundle entitiesBundle = getEntitiesBundle();
if (entitiesBundle != null && entitiesBundle.getState() != Bundle.STARTING && entitiesBundle.getState() != Bundle.ACTIVE) {
entitiesBundle.start();
} else {
LOGGER.warn("No entities bundle to start");
return;
}
} catch (BundleException e) {
if (e.getType() == BundleException.RESOLVE_ERROR) {
throw new MdsEntityWireException(e);
} else {
throw new MdsException("Unable to start the entities bundle", e);
}
}
waitUntil(new Condition() {
@Override
public boolean await() {
return !bundleStarted;
}
}, "started");
LOGGER.info("Started the entities bundle");
waitForEntitiesContext();
}
Aggregations