/** * 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; }
/** * 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; }
/** * 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; }
((SourceFileModel) fileModel).setGenerateSourceReport(true); ClassificationServiceCache.cacheClassificationFileModel(event, classification, fileModel, true); return classification;
((SourceFileModel) fileModel).setGenerateSourceReport(true); ClassificationServiceCache.cacheClassificationFileModel(event, classification, fileModel, true); return classification;