/** * Cache the status of the link between the provided {@link ClassificationModel} and the given {@link FileModel}. */ static void cacheClassificationFileModel(GraphRewrite event, ClassificationModel classificationModel, FileModel fileModel, boolean linked) { String key = getClassificationFileModelCacheKey(classificationModel, fileModel); getCache(event).put(key, linked); }
private boolean isClassificationLinkedToFileModel(GraphRewrite event, ClassificationModel classificationModel, FileModel fileModel) { return ClassificationServiceCache.isClassificationLinkedToFileModel(event, classificationModel, fileModel); }
/** * Indicates whether or not the given {@link FileModel} is already attached to the {@link ClassificationModel}. * * Note that this assumes all {@link ClassificationModel} attachments are handled via the {@link ClassificationService}. * * Outside of tests, this should be a safe assumption to make. */ static boolean isClassificationLinkedToFileModel(GraphRewrite event, ClassificationModel classificationModel, FileModel fileModel) { String key = getClassificationFileModelCacheKey(classificationModel, fileModel); Boolean linked = getCache(event).get(key); if (linked == null) { GraphTraversal<Vertex, Vertex> existenceCheck = new GraphTraversalSource(event.getGraphContext().getGraph()).V(classificationModel.getElement()); existenceCheck.out(ClassificationModel.FILE_MODEL); existenceCheck.filter(vertexTraverser -> vertexTraverser.get().equals(fileModel.getElement())); linked = existenceCheck.hasNext(); cacheClassificationFileModel(event, classificationModel, fileModel, linked); } return linked; }
@Override public void afterExecution(GraphRewrite event) { getCache(event).clear(); } }
/** * This method just attaches the {@link ClassificationModel} to the {@link FileModel}. * It will only do so if this link is not already present. */ public ClassificationModel attachClassification(GraphRewrite event, ClassificationModel classificationModel, FileModel fileModel) { if (fileModel instanceof DuplicateArchiveModel) { fileModel = ((DuplicateArchiveModel) fileModel).getCanonicalArchive(); } if (!isClassificationLinkedToFileModel(event, classificationModel, fileModel)) { classificationModel.addFileModel(fileModel); if (fileModel instanceof SourceFileModel) ((SourceFileModel) fileModel).setGenerateSourceReport(true); } ClassificationServiceCache.cacheClassificationFileModel(event, classificationModel, fileModel, true); return classificationModel; }
/** * Indicates whether or not the given {@link FileModel} is already attached to the {@link ClassificationModel}. * * Note that this assumes all {@link ClassificationModel} attachments are handled via the {@link ClassificationService}. * * Outside of tests, this should be a safe assumption to make. */ static boolean isClassificationLinkedToFileModel(GraphRewrite event, ClassificationModel classificationModel, FileModel fileModel) { String key = getClassificationFileModelCacheKey(classificationModel, fileModel); Boolean linked = getCache(event).get(key); if (linked == null) { GraphTraversal<Vertex, Vertex> existenceCheck = new GraphTraversalSource(event.getGraphContext().getGraph()).V(classificationModel.getElement()); existenceCheck.out(ClassificationModel.FILE_MODEL); existenceCheck.filter(vertexTraverser -> vertexTraverser.get().equals(fileModel.getElement())); linked = existenceCheck.hasNext(); cacheClassificationFileModel(event, classificationModel, fileModel, linked); } return linked; }
@Override public void afterExecution(GraphRewrite event) { getCache(event).clear(); } }
/** * This method just attaches the {@link ClassificationModel} to the {@link FileModel}. * It will only do so if this link is not already present. */ public ClassificationModel attachClassification(GraphRewrite event, ClassificationModel classificationModel, FileModel fileModel) { if (fileModel instanceof DuplicateArchiveModel) { fileModel = ((DuplicateArchiveModel) fileModel).getCanonicalArchive(); } if (!isClassificationLinkedToFileModel(event, classificationModel, fileModel)) { classificationModel.addFileModel(fileModel); if (fileModel instanceof SourceFileModel) ((SourceFileModel) fileModel).setGenerateSourceReport(true); } ClassificationServiceCache.cacheClassificationFileModel(event, classificationModel, fileModel, true); return classificationModel; }
/** * Cache the status of the link between the provided {@link ClassificationModel} and the given {@link FileModel}. */ static void cacheClassificationFileModel(GraphRewrite event, ClassificationModel classificationModel, FileModel fileModel, boolean linked) { String key = getClassificationFileModelCacheKey(classificationModel, fileModel); getCache(event).put(key, linked); }
@Override public void beforeExecution(GraphRewrite event) { getCache(event).clear(); }
((SourceFileModel) fileModel).setGenerateSourceReport(true); ClassificationServiceCache.cacheClassificationFileModel(event, classification, fileModel, true); return classification;
private boolean isClassificationLinkedToFileModel(GraphRewrite event, ClassificationModel classificationModel, FileModel fileModel) { return ClassificationServiceCache.isClassificationLinkedToFileModel(event, classificationModel, fileModel); }
@Override public void beforeExecution(GraphRewrite event) { getCache(event).clear(); }
((SourceFileModel) fileModel).setGenerateSourceReport(true); ClassificationServiceCache.cacheClassificationFileModel(event, classification, fileModel, true); return classification;