/** * Add a {@link WindupVertexFrame} type to the list of mappings for the given pattern and {@link GraphRewrite} * event. */ public static void addMapping(GraphRewrite event, String pattern, Class<? extends WindupVertexFrame> type) { getMappings(event, pattern).add(type); }
/** * Get the list of {@link WindupVertexFrame} type mappings for the given pattern and {@link GraphRewrite} event. */ public static List<Class<? extends WindupVertexFrame>> getMappings(GraphRewrite event, String pattern) { Map<String, List<Class<? extends WindupVertexFrame>>> mappings = getMappings(event); List<Class<? extends WindupVertexFrame>> result = mappings.get(pattern); if (result == null) { result = new ArrayList<>(); mappings.put(pattern, result); } return result; }
@Override public void vertexPropertyChanged(Vertex vertex, String key, Object oldValue, Object setValue) { if (FileModel.FILE_PATH.equals(key)) { FileService fileService = new FileService(event.getGraphContext()); FileModel model = fileService.frame(vertex); Map<String, List<Class<? extends WindupVertexFrame>>> mappings = FileMapping .getMappings(event); for (Entry<String, List<Class<? extends WindupVertexFrame>>> entry : mappings.entrySet()) { String pattern = entry.getKey(); List<Class<? extends WindupVertexFrame>> types = entry.getValue(); if (((String) setValue).matches(pattern)) { if (!model.isDirectory()) { for (Class<? extends WindupVertexFrame> type : types) { GraphService.addTypeToModel(event.getGraphContext(), model, type); } LOG.fine("Mapped file [" + model.getFilePath() + "] matching pattern [" + pattern + "] to the following [" + types.size() + "] types: " + types); } } } } }
.getMappings(event);
@Override public void vertexPropertyChanged(Vertex element, Property oldValue, Object setValue, Object... vertexPropertyKeyValues) { String key = oldValue.key(); if (!FileModel.FILE_PATH.equals(key)) return; FileService fileService = new FileService(event.getGraphContext()); // Reload it to make sure that we have one that is attached to the graph element = event.getGraphContext().getGraph().vertices(element.id()).next(); FileModel model = fileService.frame(element); if (model.isDirectory()) return; Map<String, List<Class<? extends WindupVertexFrame>>> mappings = FileMapping.getMappings(event); // Compare the value being set to "fileType" against file mapping patterns. // If it matches, add the vertex types to this vertex. for (Entry<String, List<Class<? extends WindupVertexFrame>>> entry : mappings.entrySet()) { String pattern = entry.getKey(); List<Class<? extends WindupVertexFrame>> types = entry.getValue(); if (((String) setValue).matches(pattern)) { for (Class<? extends WindupVertexFrame> type : types) { GraphService.addTypeToModel(event.getGraphContext(), model, type); } LOG.fine("Mapped file [" + model.getFilePath() + "] matching pattern [" + pattern + "] " + "to the following [" + types.size() + "] types: " + types); } } }
@Override public void vertexPropertyChanged(Vertex element, Property oldValue, Object setValue, Object... vertexPropertyKeyValues) { String key = oldValue.key(); if (!FileModel.FILE_PATH.equals(key)) return; FileService fileService = new FileService(event.getGraphContext()); // Reload it to make sure that we have one that is attached to the graph element = event.getGraphContext().getGraph().vertices(element.id()).next(); FileModel model = fileService.frame(element); if (model.isDirectory()) return; Map<String, List<Class<? extends WindupVertexFrame>>> mappings = FileMapping.getMappings(event); // Compare the value being set to "fileType" against file mapping patterns. // If it matches, add the vertex types to this vertex. for (Entry<String, List<Class<? extends WindupVertexFrame>>> entry : mappings.entrySet()) { String pattern = entry.getKey(); List<Class<? extends WindupVertexFrame>> types = entry.getValue(); if (((String) setValue).matches(pattern)) { for (Class<? extends WindupVertexFrame> type : types) { GraphService.addTypeToModel(event.getGraphContext(), model, type); } LOG.fine("Mapped file [" + model.getFilePath() + "] matching pattern [" + pattern + "] " + "to the following [" + types.size() + "] types: " + types); } } }