use of org.motechproject.commons.api.MotechException in project motech by motech.
the class ModuleAdminServiceImpl method uninstallBundle.
@Override
public void uninstallBundle(long bundleId, boolean removeConfig) throws BundleException {
Bundle bundle = getBundle(bundleId);
bundle.uninstall();
if (removeConfig) {
// this is important that config is removed after bundle uninstall!
configurationService.removeAllBundleProperties(bundle.getSymbolicName());
}
try {
boolean deleted = bundleDirectoryManager.removeBundle(bundle);
importExportResolver.refreshPackage(bundle);
if (!deleted) {
LOGGER.warn("Failed to delete bundle file: " + bundle.getLocation());
}
} catch (IOException e) {
throw new MotechException("Error while removing bundle file", e);
}
}
use of org.motechproject.commons.api.MotechException in project motech by motech.
the class ModuleAdminServiceImpl method startBundles.
private void startBundles(List<Bundle> bundlesInstalled, boolean startBundles) {
try {
if (startBundles) {
LOGGER.info("Starting installed bundles.");
for (Bundle bundle : bundlesInstalled) {
if (bundle.getState() != Bundle.ACTIVE && !isFragmentBundle(bundle)) {
LOGGER.trace("Starting bundle: {}", bundle.getSymbolicName());
bundle.start();
}
}
}
} catch (Exception e) {
throw new MotechException("Error while starting bundle.", e);
}
}
use of org.motechproject.commons.api.MotechException in project motech by motech.
the class MotechProxyManager method loadDefaultSecurityConfiguration.
/**
* Loads {@link org.motechproject.security.domain.MotechSecurityConfiguration}
* from {@link MotechProxyManager#DEFAULT_SECURITY_CONFIG_FILE}
*
* @return loaded security configuration
*/
private MotechSecurityConfiguration loadDefaultSecurityConfiguration() {
try (InputStream in = this.getClass().getClassLoader().getResourceAsStream(DEFAULT_SECURITY_CONFIG_FILE)) {
LOGGER.debug("Load default security rules from: {}", DEFAULT_SECURITY_CONFIG_FILE);
MotechSecurityConfiguration config = (MotechSecurityConfiguration) motechJsonReader.readFromStream(in, MotechSecurityConfiguration.class);
loadedDefaultSecurityConfiguration = true;
return config;
} catch (IOException e) {
throw new MotechException("Error while loading json file", e);
}
}
use of org.motechproject.commons.api.MotechException in project motech by motech.
the class SettingsDto method getProperties.
public SettingsDto getProperties(SettingsDto dto, SettingsFacade settingsFacade) {
dto.setTaskPossibleErrors(settingsFacade.getProperty(TASK_POSSIBLE_ERRORS));
try (InputStream retries = settingsFacade.getRawConfig(TASK_PROPERTIES_FILE_NAME)) {
if (retries != null) {
Properties props = new Properties();
props.load(retries);
for (Map.Entry<Object, Object> entry : props.entrySet()) {
dto.taskRetries.put((String) entry.getKey(), (String) entry.getValue());
}
} else {
dto.taskRetries = new HashMap<String, String>();
}
} catch (IOException e) {
throw new MotechException("Error loading raw file config to properties", e);
}
return dto;
}
use of org.motechproject.commons.api.MotechException in project motech by motech.
the class KeyEvaluator method manipulate.
String manipulate(String manipulation, String value) {
String lowerCase = manipulation.toLowerCase();
String result = value;
if (lowerCase.contains("getvalue")) {
result = getValueFromMap(value, manipulation);
} else if (lowerCase.contains("join")) {
result = joinManipulation(value, manipulation);
} else if (lowerCase.contains("datetime")) {
try {
result = datetimeManipulation(value, manipulation);
} catch (IllegalArgumentException e) {
throw new MotechException("error.date.format", e);
}
} else if (lowerCase.contains("substring")) {
result = substringManipulation(value, manipulation);
} else if (lowerCase.contains("split")) {
result = splitManipulation(value, manipulation);
} else {
result = dateOrSimpleManipulation(value, manipulation);
}
return result;
}
Aggregations