Search in sources :

Example 1 with MotechException

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);
    }
}
Also used : MotechException(org.motechproject.commons.api.MotechException) Bundle(org.osgi.framework.Bundle) IOException(java.io.IOException)

Example 2 with MotechException

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);
    }
}
Also used : MotechException(org.motechproject.commons.api.MotechException) Bundle(org.osgi.framework.Bundle) AuthenticationException(org.apache.maven.wagon.authentication.AuthenticationException) BundleException(org.osgi.framework.BundleException) ConnectionException(org.apache.maven.wagon.ConnectionException) MotechException(org.motechproject.commons.api.MotechException) ArtifactResolutionException(org.sonatype.aether.resolution.ArtifactResolutionException) BundleNotFoundException(org.motechproject.admin.exception.BundleNotFoundException) DependencyResolutionException(org.sonatype.aether.resolution.DependencyResolutionException) RepositoryException(org.sonatype.aether.RepositoryException) IOException(java.io.IOException)

Example 3 with MotechException

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);
    }
}
Also used : MotechException(org.motechproject.commons.api.MotechException) MotechSecurityConfiguration(org.motechproject.security.domain.MotechSecurityConfiguration) InputStream(java.io.InputStream) IOException(java.io.IOException)

Example 4 with MotechException

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;
}
Also used : MotechException(org.motechproject.commons.api.MotechException) InputStream(java.io.InputStream) IOException(java.io.IOException) Properties(java.util.Properties) Map(java.util.Map) HashMap(java.util.HashMap)

Example 5 with MotechException

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;
}
Also used : MotechException(org.motechproject.commons.api.MotechException)

Aggregations

MotechException (org.motechproject.commons.api.MotechException)33 IOException (java.io.IOException)25 InputStream (java.io.InputStream)9 Properties (java.util.Properties)8 ArrayList (java.util.ArrayList)6 MessageDigest (java.security.MessageDigest)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)4 HashMap (java.util.HashMap)4 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 Map (java.util.Map)3 ObjectName (javax.management.ObjectName)3 SettingsRecord (org.motechproject.config.domain.SettingsRecord)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 OutputStream (java.io.OutputStream)2 DigestInputStream (java.security.DigestInputStream)2 QueueViewMBean (org.apache.activemq.broker.jmx.QueueViewMBean)2 TaskHandlerException (org.motechproject.tasks.exception.TaskHandlerException)2 Bundle (org.osgi.framework.Bundle)2 ClassPathResource (org.springframework.core.io.ClassPathResource)2 Resource (org.springframework.core.io.Resource)2