AdvancedFilterValidator implements GenericMetaInfDataValidator, FilterValidator, DocumentViewXmlValidator, JcrPathValidator { @Override public Collection<ValidationMessage> validate(@NotNull WorkspaceFilter filter) { if (isSubPackage) { return null; } Collection<ValidationMessage> messages = new LinkedList<>(); messages.addAll(validatePathFilterSets(filter.getFilterSets(), true)); messages.addAll(validatePathFilterSets(filter.getPropertyFilterSets(), false)); Set<String> ancestors = new LinkedHashSet<>(); for (PathFilterSet set : filter.getFilterSets()) { if ("cleanup".equals(set.getType())) { continue; } String root = StringUtils.substringBeforeLast(set.getRoot(), "/"); if (validRoots.contains(root)) { continue; } if (filter.contains(root)) { continue; } ancestors.add(root); } for (String root : ancestors) { String coveringPackageId = null; boolean isContained = false; for (PackageInfo dependencyInfo : dependenciesMetaInfo) { WorkspaceFilter dependencyFilter = dependencyInfo.getFilter(); if (dependencyFilter.contains(root)) { isContained = true; } if (dependencyFilter.covers(root)) { coveringPackageId = dependencyInfo.getId().toString(); } } if (!isContained) { String msg; if (coveringPackageId == null) { msg = String.format(MESSAGE_FILTER_ROOT_ANCESTOR_UNCOVERED, root); } else { msg = String.format(MESSAGE_FILTER_ROOT_ANCESTOR_COVERED_BUT_EXCLUDED, root, coveringPackageId); } messages.add(new ValidationMessage(severityForUncoveredFilterRootAncestors, msg)); } } return messages; } AdvancedFilterValidator(@NotNull DocumentBuilderFactory factory, @NotNull ValidationMessageSeverity defaultSeverity, @NotNull ValidationMessageSeverity severityForUncoveredAncestorNodes, @NotNull ValidationMessageSeverity severityForUncoveredFilterRootAncestors, @NotNull ValidationMessageSeverity severityForOrphanedFilterEntries, boolean isSubPackage, @NotNull Collection<PackageInfo> dependenciesMetaInfo, @NotNull WorkspaceFilter filter, @NotNull Collection<String> validRoots); void setFilterValidators(Map<String, FilterValidator> filterValidators); @Override Collection<ValidationMessage> done(); @Override Collection<ValidationMessage> validate(@NotNull WorkspaceFilter filter); @Override @Nullable Collection<ValidationMessage> validateJcrPath(@NotNull NodeContext nodeContext,
            boolean isFolder); @Override @Nullable Collection<ValidationMessage> validate(@NotNull DocViewNode node, @NotNull NodeContext nodeContext,
            boolean isRoot); @Override Collection<ValidationMessage> validateMetaInfData(@NotNull InputStream input, @NotNull Path filePath, @NotNull Path basePath); @Override boolean shouldValidateMetaInfData(@NotNull Path filePath);  }
@Test public void testRootNodesInFilterPartlyContainedInDependencies() throws IOException, ConfigurationException { DefaultWorkspaceFilter dependencyFilter = new DefaultWorkspaceFilter(); try (InputStream input = this.getClass().getResourceAsStream("/dependency1-filter.xml")) { dependencyFilter.load(input); } DefaultWorkspaceFilter filter = new DefaultWorkspaceFilter(); try (InputStream input = this.getClass().getResourceAsStream("/filter-with-uncovered-roots.xml")) { filter.load(input); } validRoots.add("/customroot"); dependenciesMetaInfo.add(new DefaultPackageInfo(PackageId.fromString("group:dependency1"), dependencyFilter, PackageType.APPLICATION)); validator = new AdvancedFilterValidator( factory, ValidationMessageSeverity.ERROR, ValidationMessageSeverity.ERROR, ValidationMessageSeverity.ERROR, ValidationMessageSeverity.ERROR, false, dependenciesMetaInfo, filter, validRoots); Collection<ValidationMessage> messages = validator.validate(filter); ValidationExecutorTest.assertViolation(messages, ValidationMessageSeverity.INFO, new ValidationMessage(ValidationMessageSeverity.ERROR, String.format(AdvancedFilterValidator.MESSAGE_FILTER_ROOT_ANCESTOR_UNCOVERED, "/apps/uncovered")), new ValidationMessage(ValidationMessageSeverity.ERROR, String.format(AdvancedFilterValidator.MESSAGE_FILTER_ROOT_ANCESTOR_COVERED_BUT_EXCLUDED, "/apps/covered2/excluded", "group:dependency1")), new ValidationMessage(ValidationMessageSeverity.ERROR, String.format(AdvancedFilterValidator.MESSAGE_FILTER_ROOT_ANCESTOR_UNCOVERED, "/invalidroot"))); }
@Test public void testUncoveredRootNodesInFilter() throws IOException, ConfigurationException { DefaultWorkspaceFilter filter = new DefaultWorkspaceFilter(); try (InputStream input = this.getClass().getResourceAsStream("/filter.xml")) { filter.load(input); } validator = new AdvancedFilterValidator( factory, ValidationMessageSeverity.INFO, AdvancedFilterValidatorFactory.DEFAULT_SEVERITY_FOR_UNCOVERED_ANCESTOR_NODES, ValidationMessageSeverity.INFO, ValidationMessageSeverity.ERROR, false, dependenciesMetaInfo, filter, validRoots); Collection<ValidationMessage> messages = validator.validate(filter); ValidationExecutorTest.assertViolation(messages, ValidationMessageSeverity.INFO, new ValidationMessage(ValidationMessageSeverity.INFO, String.format(AdvancedFilterValidator.MESSAGE_FILTER_ROOT_ANCESTOR_UNCOVERED, "/apps/test4"))); }