@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); } } };
@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 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 + "'"); } }
private String getFileContents(String file) { String transformed = transformFilePath(file); try (InputStream is = RequireJsSupport.class.getResourceAsStream(transformed)) { if (is == null) { throw new VisalloException("File not found: " + transformed); } return IOUtils.toString(is, Charset.forName("UTF-8")); } catch (IOException ex) { throw new VisalloException("Could not read file contents: " + transformed, ex); } } }
protected void checkRoutePath(String entityType, String propertyName, HttpServletRequest request) { boolean isComment = isCommentProperty(propertyName); if (isComment && request.getPathInfo().equals(String.format("/%s/property", entityType))) { throw new VisalloException(String.format("Use /%s/comment to save comment properties", entityType)); } else if (!isComment && request.getPathInfo().equals(String.format("/%s/comment", entityType))) { throw new VisalloException(String.format("Use /%s/property to save non-comment properties", entityType)); } }
private static String readStreamingPropertyValueStringForHistory(StreamingPropertyValue spv) { try (InputStream in = spv.getInputStream()) { byte[] buffer = new byte[HISTORICAL_PROPERTY_MAX_SPV_SIZE]; int bytesRead = in.read(buffer, 0, HISTORICAL_PROPERTY_MAX_SPV_SIZE); if (bytesRead < 0) { return ""; } return new String(buffer, 0, bytesRead); } catch (IOException ex) { throw new VisalloException("Could not read StreamingPropertyValue", ex); } }
public static GraphPropertyMessage create(byte[] data) { try { GraphPropertyMessage message = mapper.readValue(data, GraphPropertyMessage.class); checkNotNull(message.getPriority(), "priority cannot be null"); return message; } catch (IOException e) { throw new VisalloException("Could not create " + GraphPropertyMessage.class.getName() + " from " + new String(data), e); } }
@Override public Relationship getRequiredRelationshipByIntent(String intent, String workspaceId) { Relationship relationship = getRelationshipByIntent(intent, workspaceId); if (relationship == null) { throw new VisalloException("Could not find relationship by intent: " + intent); } return relationship; }
protected void handleNextTupleException(VisalloLogger logger, Exception ex) throws InterruptedException { if (exitOnNextTupleFailure) { throw new VisalloException("Failed to get next tuple", ex); } else { logger.error("Failed to get next tuple", ex); Thread.sleep(10 * 1000); } }
private void validateCreateUserArguments(CreateUserArgs args) { int s = args.privilegeRepositoryArguments.size(); if (s == 0) { return; } String privsString = args.privilegeRepositoryArguments.get(CLI_PARAMETER_PRIVILEGES); if ((s == 1 && privsString == null) || s != 1) { throw new VisalloException(this.getClass().getName() + " expects no parameters or '" + CLI_PARAMETER_PRIVILEGES + "'"); } validatePrivileges(StringUtils.split(privsString, SEPARATOR_CHAR)); }
@Override public ClientApiObject[] convert(Class parameterType, String parameterName, String value) { try { return (ClientApiObject[]) ObjectMapperFactory.getInstance().readValue(value, parameterType); } catch (IOException ex) { throw new VisalloException("Could not convert \"" + value + "\" to object of type " + parameterType.getName(), ex); } } }
public void appendCssResource(String pathInfo) { try (InputStream in = this.getClass().getResourceAsStream(pathInfo)) { checkNotNull(in, "Could not find resource: " + pathInfo); appendCss(IOUtils.toString(in)); } catch (IOException ex) { throw new VisalloException("Could not append css resource: " + pathInfo, ex); } }
public static VisalloDate create(Object obj) { if (obj == null) { return null; } if (obj instanceof String) { return parse((String) obj); } if (obj instanceof Date) { return create((Date) obj); } throw new VisalloException("Invalid object type to convert to " + VisalloDate.class.getSimpleName() + ": " + obj.getClass().getName()); }
public String search(Graph graph, Authorizations authorizations) { Query query = graph.query(authorizations).limit(1); List<Vertex> vertices = Lists.newArrayList(query.vertices()); if (vertices.size() == 0) { throw new VisalloException("query returned no vertices"); } else if (vertices.size() > 1) { throw new VisalloException("query returned more than one vertex"); } return vertices.get(0).getId(); }
protected String getOntologyJson(String workspaceId) { ClientApiOntology result = ontologyRepository.getClientApiObject(workspaceId); try { return ObjectMapperFactory.getInstance().writeValueAsString(result); } catch (JsonProcessingException ex) { throw new VisalloException("Could not evaluate JSON: " + result, ex); } }
protected void clearWorkQueues() { WorkQueueRepository workQueueRepository = getWorkQueueRepository(); if (!(workQueueRepository instanceof TestWorkQueueRepository)) { throw new VisalloException("Can only clear work queue items from " + TestWorkQueueRepository.class.getName()); } ((TestWorkQueueRepository) workQueueRepository).clearQueue(); }
private void applyDirectoryEntityJsonObjectEqualityToQuery(Query graphQuery, String propertyName, JSONObject value0, User user) { String directoryEntityId = value0.optString("directoryEntityId", null); if (directoryEntityId != null) { graphQuery.has(propertyName, Compare.EQUAL, directoryEntityId); } else if (value0.optBoolean("currentUser", false)) { directoryEntityId = directoryRepository.getDirectoryEntityId(user); graphQuery.has(propertyName, Compare.EQUAL, directoryEntityId); } else { throw new VisalloException("Invalid directory entity JSONObject filter:\n" + value0.toString(2)); } }
protected void broadcastEntityImage(Element element, String propertyKey, String propertyName) { try { JSONObject json = getBroadcastEntityImageJson((Vertex) element); broadcastJson(json); } catch (Exception ex) { throw new VisalloException("Could not broadcast property change", ex); } }
private void validatePrivileges(String[] privileges) { for (String privilege : privileges) { if (privilegeRepository.findPrivilegeByName(privilege) == null) { throw new VisalloException( "Unexpected privilege \"" + privilege + "\". Expected one of [" + Privilege.toStringPrivileges(privilegeRepository.getAllPrivileges()) + "]"); } } }
protected void findOrAddEdge(Vertex fromVertex, final Vertex toVertex, String edgeLabel, User user, String workspaceId) { try (GraphUpdateContext ctx = graphRepository.beginGraphUpdate(Priority.LOW, user, getAuthorizations(workspaceId))) { ctx.setPushOnQueue(false); findOrAddEdge(ctx, fromVertex, toVertex, edgeLabel); } catch (Exception e) { throw new VisalloException("Could not findOrAddEdge", e); } }