private static String getClassificationFileModelCacheKey(ClassificationModel classificationModel, FileModel fileModel) { StringBuilder builder = new StringBuilder(); if (classificationModel != null) builder.append(classificationModel.getElement().id()); builder.append("_"); if (fileModel != null) builder.append(fileModel.getElement().id()); return builder.toString(); }
private static String getClassificationFileModelCacheKey(ClassificationModel classificationModel, FileModel fileModel) { StringBuilder builder = new StringBuilder(); if (classificationModel != null) builder.append(classificationModel.getElement().id()); builder.append("_"); if (fileModel != null) builder.append(fileModel.getElement().id()); return builder.toString(); }
/** * 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; }
private static List<Classification> getClassifications(GraphContext graphContext) { final List<Classification> classifications = new ArrayList<>(); ClassificationService classificationService = new ClassificationService(graphContext); for (ClassificationModel classificationModel : classificationService.findAll()) { for (FileModel fileModel : classificationModel.getFileModels()) { ClassificationImpl classification = new ClassificationImpl(classificationModel.getElement().id()); classification.setClassification(classificationModel.getClassification()); classification.setDescription(classificationModel.getDescription()); classification.setEffort(classificationModel.getEffort()); classification.setRuleID(classificationModel.getRuleID()); classification.setIssueCategory(new IssueCategoryImpl(classificationModel.getIssueCategory())); classification.setFile(fileModel.asFile()); classification.setLinks(asLinks(classificationModel.getLinks())); classifications.add(classification); classification.setQuickfixes(asQuickfixes(classificationModel.getQuickfixes())); } } return classifications; }
private static List<Classification> getClassifications(GraphContext graphContext) { final List<Classification> classifications = new ArrayList<>(); ClassificationService classificationService = new ClassificationService(graphContext); for (ClassificationModel classificationModel : classificationService.findAll()) { for (FileModel fileModel : classificationModel.getFileModels()) { ClassificationImpl classification = new ClassificationImpl(classificationModel.getElement().id()); classification.setClassification(classificationModel.getClassification()); classification.setDescription(classificationModel.getDescription()); classification.setEffort(classificationModel.getEffort()); classification.setRuleID(classificationModel.getRuleID()); classification.setIssueCategory(new IssueCategoryImpl(classificationModel.getIssueCategory())); classification.setFile(fileModel.asFile()); classification.setLinks(asLinks(classificationModel.getLinks())); classifications.add(classification); classification.setQuickfixes(asQuickfixes(classificationModel.getQuickfixes())); } } return classifications; }