@Override public Object convert(Class type, Object value) { try { return new DateTime(new SimpleDateFormat(DATE_PATTERN + " " + TIME_PATTERN_12_HOURS).parse((String) value)); } catch (ParseException e) { throw new MotechException("Encountered exception while parsing mobile form", e); } } }
private FieldValidator getValidationHandler(Annotation annotation) { Annotation validationMarker = annotation.annotationType().getAnnotation(ValidationMarker.class); if (validationMarker == null) { throw new MotechException("Field validator has not been annotated with ValidationMarker, " + annotation.annotationType().getName()); } try { Class<FieldValidator> fieldValidatorClass = (Class<FieldValidator>) validationMarker.annotationType().getMethod("handler").invoke(validationMarker); return fieldValidatorClass.newInstance(); } catch (Exception e) { throw new MotechException("Exception while instantiating validation handler, this should never happen", e); } }
@Override public void handle(MotechEvent event) { try { callHandler(event); } catch (Exception e) { LoggerFactory.getLogger(bean.getClass()).error("Failed to handle event", e); throw new MotechException("Failed to handle event", e); } }
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); } }
public String getFileContent(String fileName, String formGroupName) { String xformFilePath = join(asList(XFORMS_FOLDER, formGroupName, fileName), File.separator); try { return org.apache.commons.io.IOUtils.toString(getClass().getClassLoader().getResourceAsStream(xformFilePath)); } catch (Exception e) { throw new MotechException("Encountered error while loading openxdata forms", e); } } }
public StubServer start() { try { server.start(); } catch (Exception e) { throw new MotechException("Stub Sever Could not be started", e); } return this; }
public void stop() { try { server.stop(); } catch (Exception e) { throw new MotechException("Stub Server could not be stopped", e); } }
@Override public Object convert(Class type, Object value) { try { Date parsedDate = new SimpleDateFormat(TIME_PATTERN_12_HOURS).parse((String) value); return Time.parseTime(new SimpleDateFormat(TIME_PATTERN_24_HOURS).format(parsedDate), ":"); } catch (ParseException e) { throw new MotechException("Encountered exception while parsing mobile form", e); } } }
private void startAdmin() { Bundle adminBundle = getAdminBundle(); if (adminBundle == null) { LOGGER.warn("Admin bundle not installed"); } else if (adminBundle.getState() == Bundle.ACTIVE) { LOGGER.warn("Admin bundle already active"); } else { try { adminBundle.start(); } catch (BundleException e) { throw new MotechException("Cannot start admin bundle", e); } } }
@Override public void afterPropertiesSet() { if (getKey() == null || getKey().trim().isEmpty()) { throw new MotechException("Transition key is required"); } if (getNode() == null) { throw new MotechException("Transition node id is required"); } }
public void saveRawConfig(String filename, Resource resource) { rawConfig.put(filename, resource); String version = (bundle != null && bundle.getVersion() != null) ? bundle.getVersion().toString() : ""; String bundleSymbolicName = bundle != null ? bundle.getSymbolicName() : ""; try { InputStream is = resource.getInputStream(); if (configurationService != null) { configurationService.saveRawConfig(getSymbolicName(), version, bundleSymbolicName, filename, is); } } catch (IOException e) { throw new MotechException("Error saving file " + filename, e); } }
public void saveConfigProperties(String filename, Properties properties) { config.put(filename, properties); String version = (bundle != null && bundle.getVersion() != null) ? bundle.getVersion().toString() : ""; String bundleSymbolicName = bundle != null ? bundle.getSymbolicName() : ""; if (propsRegistered) { try { if (configurationService != null) { configurationService.addOrUpdateProperties(getSymbolicName(), version, bundleSymbolicName, filename, properties, defaultConfig.get(filename)); } } catch (IOException e) { throw new MotechException("Can't save settings " + filename, e); } } }
@Override public void afterPropertiesSet() { if (getMessage() == null || getMessage().trim().isEmpty()) { throw new MotechException("Message content is required"); } }
@Override public void afterPropertiesSet() { if (getName() == null || getName().trim().isEmpty()) { throw new MotechException("Tree name is required"); } if (getNodes() == null || getNodes().size() == 0) { throw new MotechException("Tree nodes is required"); } }
public void setProperty(String key, String value) { String filename = findFilename(key); if (filename == null) { throw new MotechException("No file containing key " + key); } setProperty(filename, key, value); }
@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); } }
private String executeGetMethod(GetMethod get) { LOGGER.debug("Making HTTP request to fetch OpenMRS Atom Feed: " + httpClient.getHostConfiguration().getHostURL() + get.getPath() + get.getQueryString()); try { int responseCode = httpClient.executeMethod(get); if (responseCode == HttpStatus.SC_OK) { LOGGER.debug("Successfully made HTTP request to OpenMRS"); return get.getResponseBodyAsString(); } else { LOGGER.warn("OpenMRS Atom Feed module returned non 200 status: " + get.getStatusCode()); return ""; } } catch (IOException e) { LOGGER.error("Motech OpenMRS Atom Feed module could not communicate with the OpenMRS"); throw new MotechException(e.getMessage(), e); } }
private void configurePolling(String pollingType, String pollingStartTime, String pollingInterval) { if (!ObjectUtils.equals("daily", pollingType) && !ObjectUtils.equals("interval", pollingType)) { throw new MotechException("Motech OpenMRS Atom Feed polling type can only be: interval or daily"); } parseRequiredConfigString(pollingStartTime); if ("interval".equals(pollingType)) { intervalPolling = true; parseIntervalConfigString(pollingInterval); } }
/** * Read json file and return VoxeoConfig. Typically server url and application tokens * @param filename json file to read * @return VoxeoConfig object with configuration from json file. */ public VoxeoConfig getConfig(String filename) { InputStream stream = settings.getRawConfig(filename); if (stream == null) { throw new MotechException("File not found in classpath: " + filename); } return (VoxeoConfig) new MotechJsonReader().readFromStream(stream, new TypeToken<VoxeoConfig>() { }.getType()); } }
@Override public void formProcessed(StudyData studyData, FormData formData, String formXml) { try { Map<String, String> data = parser.parse(formXml); Form form = allMobileForms.getFormByName(data.get(marker)); FormBean formBean = (FormBean) Class.forName(form.bean()).newInstance(); formBean.setValidator(form.validator()); formBean.setFormname(form.name()); formBean.setStudyName(form.studyName()); formBean.setXmlContent(formXml); formBean.setDepends(form.getDepends()); mapToBeanConvertor.convert(formBean, handleEmptyStrings(data)); studies.get(studies.size() - 1).addForm(formBean); } catch (Exception e) { throw new MotechException("Exception occurred while parsing form xml", e); } }