@Override public Iterable<String> list(String path) { throw new VisalloException("Unsupported operation"); } }
@Test public void testMalformedDateValue() throws Exception { DatePropertyMapping propertyMapping = new DatePropertyMapping(null, null, buildJsonPropertyMapping()); try { propertyMapping.decodeValue("boston"); fail("Should have thrown an error for the malformed date"); } catch (VisalloException ve) { assertEquals("Unrecognized date value: boston", ve.getMessage()); } }
@Test public void testUnknownValue() throws Exception { BooleanPropertyMapping propertyMapping = new BooleanPropertyMapping(null, null, buildJsonPropertyMapping()); Map<String, Object> row = createIndexedMap("maybe"); try { propertyMapping.decodeValue(row); fail("An exception should have been raised"); } catch (VisalloException ve) { assertEquals("Unrecognized boolean value: maybe", ve.getMessage()); } }
@Override public <T> T run(Callable<T> callable) { try { synchronized (synchronizationObject) { return callable.call(); } } catch (Exception ex) { throw new VisalloException("Failed to run in lock", ex); } } };
public static <T> T inject(T o) { if (injector == null) { throw new VisalloException("Could not find injector"); } injector.injectMembers(o); return o; }
@Override public JSONObject convert(Class parameterType, String parameterName, String[] value) { try { return new JSONObject(value[0]); } catch (Exception ex) { throw new VisalloException("Could not parse JSONObject: " + value[0]); } } }
public OutputStream getOutputStream() { try { return response.getOutputStream(); } catch (IOException e) { throw new VisalloException("Could not get response output stream", e); } }
public void flushBuffer() { try { response.flushBuffer(); } catch (IOException e) { throw new VisalloException("Could not flush response buffer"); } }
public static Class getConfigurationLoaderByName(String configLoaderName) { Class configLoader; try { configLoader = Class.forName(configLoaderName); } catch (ClassNotFoundException e) { throw new VisalloException("Could not load class " + configLoaderName, e); } return configLoader; }
@Override public InputStream getInputStream(String path) { String fullPath = prefix + path; InputStream in = getClass().getResourceAsStream(fullPath); if (in == null) { throw new VisalloException("Could not find classpath file: " + fullPath); } return in; }
private int getCalendarField(String calendarField) { try { Field field = Calendar.class.getDeclaredField(calendarField); return field.getInt(null); } catch (NoSuchFieldException | IllegalAccessException ex) { throw new VisalloException("Invalid calendar field: " + calendarField, ex); } }
@Inject public UserUpdatePrivileges(UserRepository userRepository, PrivilegeRepository privilegeRepository) { if (!(privilegeRepository instanceof UserPropertyPrivilegeRepository)) { throw new VisalloException(UserPropertyPrivilegeRepository.class.getName() + " required"); } this.userRepository = userRepository; this.privilegeRepository = (UserPropertyPrivilegeRepository) privilegeRepository; }
protected void validateDataHas(JSONObject actionData, String propertyName) { if (!actionData.has(propertyName)) { throw new VisalloException("Could not find " + propertyName + " in data: " + actionData.toString()); } }
private static Properties parseStringToProperties(String propertiesString) { Properties properties = new Properties(); Reader reader = new StringReader(propertiesString); try { properties.load(reader); } catch (IOException ex) { throw new VisalloException("Could not load properties string", ex); } return properties; } }
public String generateETag(byte[] data) { try { MessageDigest digest = MessageDigest.getInstance("MD5"); byte[] md5 = digest.digest(data); return Hex.encodeHexString(md5); } catch (NoSuchAlgorithmException e) { throw new VisalloException("Could not find MD5", e); } }
private void write(HttpServletResponse response, String contentType, String output) throws IOException { if (output != null) { try (PrintWriter outWriter = response.getWriter()) { response.setContentType(contentType); outWriter.println(output); } } else { throw new VisalloException("Errors during minify: " + jsResourceName); } }
private void validateCreateUserArguments(CreateUserArgs args) { int s = args.authorizationRepositoryArguments.size(); if (s == 0) { return; } String authsString = args.authorizationRepositoryArguments.get(CLI_PARAMETER_AUTHORIZATIONS); if ((s == 1 && authsString == null) || s != 1) { throw new VisalloException(this.getClass().getName() + " expects no parameters or '" + CLI_PARAMETER_AUTHORIZATIONS + "'"); } }
protected byte[] getResourceAsByteArray(Class sourceClass, String resourceName) { try { InputStream in = sourceClass.getResourceAsStream(resourceName); if (in == null) { throw new IOException("Could not find resource: " + resourceName); } return IOUtils.toByteArray(in); } catch (IOException e) { throw new VisalloException("Could not load resource. " + sourceClass.getName() + " at " + resourceName, e); } }
private long getLastModified() { URL url = this.getClass().getResource(path); try { return url.openConnection().getLastModified(); } catch (IOException e) { throw new VisalloException("Unable to find template file: " + path, e); } }
protected byte[] getResourceAsByteArray(Class sourceClass, String resourceName) { try { InputStream in = sourceClass.getResourceAsStream(resourceName); if (in == null) { throw new IOException("Could not find resource: " + resourceName); } return IOUtils.toByteArray(in); } catch (IOException e) { throw new VisalloException("Could not load resource. " + sourceClass.getName() + " at " + resourceName, e); } }