use of org.motechproject.commons.api.MotechException in project motech by motech.
the class RestTestUtil method jsonMatcher.
/**
* Returns a JSON matcher that will match the given response against the expected one.
* The json files will be compared without respecting the order in which the variables appear in.
* This matcher was written with Spring MVC Testing in mind, but can be potentially used in other cases.
* @param expected the expected JSON output, as string
* @return an instance of a matcher that will perform the match
* @throws MotechException if we failed to parse the expected or actual string values into JSON
*/
public static Matcher<String> jsonMatcher(final String expected) {
return new BaseMatcher<String>() {
@Override
public boolean matches(Object argument) {
try {
ObjectMapper objectMapper = new ObjectMapper();
String actual = (String) argument;
JsonNode expectedTree = objectMapper.readTree(expected);
JsonNode actualTree = objectMapper.readTree(actual);
return expectedTree.equals(actualTree);
} catch (IOException e) {
throw new MotechException("Json parsing failure", e);
}
}
@Override
public void describeTo(Description description) {
description.appendText(expected);
}
};
}
use of org.motechproject.commons.api.MotechException in project motech by motech.
the class ConfigurationServiceImpl method savePlatformSettings.
@Override
@Transactional
public void savePlatformSettings(Properties settings) {
SettingsRecord dbSettings = getSettings();
dbSettings.setPlatformInitialized(true);
dbSettings.setLastRun(DateTime.now());
dbSettings.updateFromProperties(settings);
dbSettings.removeDefaults(defaultConfig);
try {
MessageDigest digest = MessageDigest.getInstance("MD5");
dbSettings.setConfigFileChecksum(new String(digest.digest(MapUtils.toProperties(dbSettings.asProperties()).toString().getBytes())));
} catch (NoSuchAlgorithmException e) {
throw new MotechException("MD5 algorithm not available", e);
}
addOrUpdateSettings(dbSettings);
}
use of org.motechproject.commons.api.MotechException in project motech by motech.
the class SettingsFacade method registerAllRawConfig.
/**
* Registers all raw configurations to the configuration service.
*/
protected void registerAllRawConfig() {
if (configurationService != null) {
for (Map.Entry<String, Resource> entry : rawConfig.entrySet()) {
String filename = entry.getKey();
Resource resource = entry.getValue();
if (!configurationService.rawConfigExists(getBundleSymbolicName(), filename)) {
// register new config with the platform
try {
InputStream is = resource.getInputStream();
configurationService.saveRawConfig(getBundleSymbolicName(), getBundleVersion(), filename, is);
} catch (IOException e) {
throw new MotechException("Can't save raw config " + filename, e);
}
}
}
rawConfigRegistered = true;
}
}
use of org.motechproject.commons.api.MotechException in project motech by motech.
the class SettingsFacade method setConfigFiles.
public void setConfigFiles(List<Resource> resources) {
for (Resource configFile : resources) {
try (InputStream inputStream = configFile.getInputStream()) {
Properties props = new Properties();
props.load(inputStream);
config.put(getResourceFileName(configFile), props);
defaultConfig.put(getResourceFileName(configFile), props);
} catch (IOException e) {
throw new MotechException("Cant load config file " + configFile.getFilename(), e);
}
}
registerAllProperties();
}
use of org.motechproject.commons.api.MotechException in project motech by motech.
the class ModuleAdminServiceImpl method installWithDependenciesFromFile.
private BundleInformation installWithDependenciesFromFile(File bundleFile, boolean startBundle) throws IOException {
JarInformation jarInformation = getJarInformations(bundleFile);
List<Bundle> bundlesInstalled = new ArrayList<>();
BundleInformation bundleInformation = null;
if (jarInformation == null) {
throw new IOException("Unable to read bundleFile " + bundleFile.getAbsolutePath());
}
try {
List<ArtifactResult> artifactResults = new LinkedList<>();
bundleWatcherSuspensionService.suspendBundleProcessing();
for (Dependency dependency : jarInformation.getPomInformation().getDependencies()) {
artifactResults.addAll(resolveDependencies(dependency, jarInformation.getPomInformation()));
}
artifactResults = removeDuplicatedArtifacts(artifactResults);
bundlesInstalled = installBundlesFromArtifacts(artifactResults);
final Bundle requestedModule = installBundleFromFile(bundleFile, true, false);
if (requestedModule != null) {
if (!isFragmentBundle(requestedModule) && startBundle) {
requestedModule.start();
}
bundlesInstalled.add(requestedModule);
bundleInformation = null;
} else {
bundleInformation = new BundleInformation(null);
}
} catch (BundleException | RepositoryException e) {
throw new MotechException("Error while installing bundle and dependencies.", e);
} finally {
bundleWatcherSuspensionService.restoreBundleProcessing();
}
// start bundles after all bundles installed to avoid any dependency resolution problems.
startBundles(bundlesInstalled, startBundle);
return bundleInformation;
}
Aggregations