@Test public void noGenesDeletesAllVariants() { when(this.xWikiDocument.getXObjects(Gene.GENE_CLASS)).thenReturn(null); when(this.xWikiDocument.getXObjects(VARIANT_CLASS_REFERENCE)) .thenReturn(Arrays.asList(this.variant1, this.variant2)); this.patientEmptyObjectsRemover.onEvent(null, this.xWikiDocument, null); verify(this.xWikiDocument).removeXObjects(VARIANT_CLASS_REFERENCE); }
@Override public void onEvent(Event event, Object source, Object data) { XWikiDocument doc = (XWikiDocument) source; List<BaseObject> geneXWikiObjects = doc.getXObjects(Gene.GENE_CLASS); List<BaseObject> variantXWikiObjects = doc.getXObjects(VARIANT_CLASS_REFERENCE); if (geneXWikiObjects == null || geneXWikiObjects.isEmpty()) { doc.removeXObjects(VARIANT_CLASS_REFERENCE); return; } geneXWikiObjects.stream().filter(Objects::nonNull) .filter(gene -> StringUtils.isBlank(gene.getStringValue(GENE_KEY))) .forEach(gene -> doc.removeXObject(gene)); if (variantXWikiObjects == null || variantXWikiObjects.isEmpty()) { return; } Set<String> genes = geneXWikiObjects.stream().filter(Objects::nonNull) .map(gene -> gene.getStringValue(GENE_KEY)).collect(Collectors.toSet()); variantXWikiObjects.stream().filter(Objects::nonNull) .filter(variant -> StringUtils.isBlank(variant.getStringValue(VARIANT_KEY)) || !genes.contains(variant.getStringValue(GENE_KEY))) .forEach(variant -> doc.removeXObject(variant)); }
EmptyGenotypeObjectsRemover extends AbstractEventListener { @Override public void onEvent(Event event, Object source, Object data) { XWikiDocument doc = (XWikiDocument) source; List<BaseObject> geneXWikiObjects = doc.getXObjects(Gene.GENE_CLASS); List<BaseObject> variantXWikiObjects = doc.getXObjects(VARIANT_CLASS_REFERENCE); if (geneXWikiObjects == null || geneXWikiObjects.isEmpty()) { doc.removeXObjects(VARIANT_CLASS_REFERENCE); return; } geneXWikiObjects.stream().filter(Objects::nonNull) .filter(gene -> StringUtils.isBlank(gene.getStringValue(GENE_KEY))) .forEach(gene -> doc.removeXObject(gene)); if (variantXWikiObjects == null || variantXWikiObjects.isEmpty()) { return; } Set<String> genes = geneXWikiObjects.stream().filter(Objects::nonNull) .map(gene -> gene.getStringValue(GENE_KEY)).collect(Collectors.toSet()); variantXWikiObjects.stream().filter(Objects::nonNull) .filter(variant -> StringUtils.isBlank(variant.getStringValue(VARIANT_KEY)) || !genes.contains(variant.getStringValue(GENE_KEY))) .forEach(variant -> doc.removeXObject(variant)); } }
EmptyGenotypeObjectsRemover extends AbstractEventListener { @Override public void onEvent(Event event, Object source, Object data) { XWikiDocument doc = (XWikiDocument) source; List<BaseObject> geneXWikiObjects = doc.getXObjects(Gene.GENE_CLASS); List<BaseObject> variantXWikiObjects = doc.getXObjects(VARIANT_CLASS_REFERENCE); if (geneXWikiObjects == null || geneXWikiObjects.isEmpty()) { doc.removeXObjects(VARIANT_CLASS_REFERENCE); return; } geneXWikiObjects.stream().filter(Objects::nonNull) .filter(gene -> StringUtils.isBlank(gene.getStringValue(GENE_KEY))) .forEach(gene -> doc.removeXObject(gene)); if (variantXWikiObjects == null || variantXWikiObjects.isEmpty()) { return; } Set<String> genes = geneXWikiObjects.stream().filter(Objects::nonNull) .map(gene -> gene.getStringValue(GENE_KEY)).collect(Collectors.toSet()); variantXWikiObjects.stream().filter(Objects::nonNull) .filter(variant -> StringUtils.isBlank(variant.getStringValue(VARIANT_KEY)) || !genes.contains(variant.getStringValue(GENE_KEY))) .forEach(variant -> doc.removeXObject(variant)); } EmptyGenotypeObjectsRemover(); }
EmptyGenotypeObjectsRemover extends AbstractEventListener { @Override public void onEvent(Event event, Object source, Object data) { XWikiDocument doc = (XWikiDocument) source; List<BaseObject> geneXWikiObjects = doc.getXObjects(Gene.GENE_CLASS); List<BaseObject> variantXWikiObjects = doc.getXObjects(VARIANT_CLASS_REFERENCE); if (geneXWikiObjects == null || geneXWikiObjects.isEmpty()) { doc.removeXObjects(VARIANT_CLASS_REFERENCE); return; } geneXWikiObjects.stream().filter(Objects::nonNull) .filter(gene -> StringUtils.isBlank(gene.getStringValue(GENE_KEY))) .forEach(gene -> doc.removeXObject(gene)); if (variantXWikiObjects == null || variantXWikiObjects.isEmpty()) { return; } Set<String> genes = geneXWikiObjects.stream().filter(Objects::nonNull) .map(gene -> gene.getStringValue(GENE_KEY)).collect(Collectors.toSet()); variantXWikiObjects.stream().filter(Objects::nonNull) .filter(variant -> StringUtils.isBlank(variant.getStringValue(VARIANT_KEY)) || !genes.contains(variant.getStringValue(GENE_KEY))) .forEach(variant -> doc.removeXObject(variant)); } EmptyGenotypeObjectsRemover(); @Override void onEvent(Event event, Object source, Object data); }
EmptyGenotypeObjectsRemover extends AbstractEventListener { @Override public void onEvent(Event event, Object source, Object data) { XWikiDocument doc = (XWikiDocument) source; List<BaseObject> geneXWikiObjects = doc.getXObjects(Gene.GENE_CLASS); List<BaseObject> variantXWikiObjects = doc.getXObjects(VARIANT_CLASS_REFERENCE); if (geneXWikiObjects == null || geneXWikiObjects.isEmpty()) { doc.removeXObjects(VARIANT_CLASS_REFERENCE); return; } geneXWikiObjects.stream().filter(Objects::nonNull) .filter(gene -> StringUtils.isBlank(gene.getStringValue(GENE_KEY))) .forEach(gene -> doc.removeXObject(gene)); if (variantXWikiObjects == null || variantXWikiObjects.isEmpty()) { return; } Set<String> genes = geneXWikiObjects.stream().filter(Objects::nonNull) .map(gene -> gene.getStringValue(GENE_KEY)).collect(Collectors.toSet()); variantXWikiObjects.stream().filter(Objects::nonNull) .filter(variant -> StringUtils.isBlank(variant.getStringValue(VARIANT_KEY)) || !genes.contains(variant.getStringValue(GENE_KEY))) .forEach(variant -> doc.removeXObject(variant)); } EmptyGenotypeObjectsRemover(); @Override void onEvent(Event event, Object source, Object data);  }