<commit_before>package org.commonjava.aprox.promote.rules

import org.commonjava.aprox.model.core.StoreKey
import org.commonjava.aprox.promote.validate.model.ValidationRequest
import org.commonjava.aprox.promote.validate.model.ValidationRule
import org.commonjava.cartographer.graph.discover.DiscoveryConfig
import org.commonjava.maven.atlas.ident.ref.ArtifactRef
import org.commonjava.maven.atlas.ident.ref.SimpleTypeAndClassifier
import org.slf4j.LoggerFactory

class ArtifactRefAvailability implements ValidationRule {

    String validate(ValidationRequest request) {
        def verifyStore = request.getValidationParameter("availableInStoreKey")
        StoreKey verifyStoreKey = null
        if (verifyStore == null) {
            def logger = LoggerFactory.getLogger(getClass())
            logger.warn("No external store (availableInStoreKey parameter) specified for validating path availability in rule-set: {}. Using target: {} instead.", request.getRuleSet().getName(), request.getTarget())
            verifyStoreKey = request.getTarget()
        } else {
            verifyStoreKey = StoreKey.fromString(verifyStore)
            if (verifyStoreKey == null) {
                return "Invalid target: ${verifyStore} is not a StoreKey"
            }
        }

        def builder = new StringBuilder()
        def tools = request.getTools()
        def dc = DiscoveryConfig.getDisabledConfig();

        dc.setIncludeBuildSection(false)
        dc.setIncludeManagedDependencies(false)

        def logger = LoggerFactory.getLogger(ValidationRule.class)

        def pomTC = new SimpleTypeAndClassifier("pom")
        request.getSourcePaths().each { it ->
            if (it.endsWith(".pom")) {
                def relationships = tools.getRelationshipsForPom(it, dc, request.getPromoteRequest(), verifyStoreKey)
                if (relationships != null) {
                    relationships.each { rel ->
                        def target = rel.getTarget()
                        def path = tools.toArtifactPath(target)
                        def txfr = tools.getTransfer(verifyStoreKey, path)
                        logger.info("{} in {}: {}. Exists? {}", target, verifyStoreKey, txfr, txfr.exists())
                        if (!txfr.exists()) {
                            if (builder.length() > 0) {
                                builder.append("\n")
                            }
                            builder.append(it).append(" is invalid: ").append(path).append(" is not available via: ").append(verifyStoreKey)
                        }

                        if ((target instanceof ArtifactRef) && !pomTC.equals(((ArtifactRef) target).getTypeAndClassifier())) {
                            path = tools.toArtifactPath(target.asPomArtifact())
                            txfr = tools.getTransfer(verifyStoreKey, path)
                            logger.info("POM {} in {}: {}. Exists? {}", target.asPomArtifact(), verifyStoreKey, txfr, txfr.exists())
                            if (!txfr.exists()) {
                                if (builder.length() > 0) {
                                    builder.append("\n")
                                }
                                builder.append(it).append(" is invalid: ").append(path).append(" is not available via: ").append(verifyStoreKey)
                            }
                        }
                    }
                }
            }
        }

        builder.length() > 0 ? builder.toString() : null
    }
}<commit_msg>Update artifact-refs-via to check also promoted repository, not only verifyStoreKey<commit_after>package org.commonjava.aprox.promote.rules

import org.commonjava.aprox.model.core.StoreKey
import org.commonjava.aprox.promote.validate.model.ValidationRequest
import org.commonjava.aprox.promote.validate.model.ValidationRule
import org.commonjava.cartographer.graph.discover.DiscoveryConfig
import org.commonjava.maven.atlas.ident.ref.ArtifactRef
import org.commonjava.maven.atlas.ident.ref.SimpleTypeAndClassifier
import org.slf4j.LoggerFactory

class ArtifactRefAvailability implements ValidationRule {

    String validate(ValidationRequest request) {
        def verifyStore = request.getValidationParameter("availableInStoreKey")
        StoreKey verifyStoreKey = null
        if (verifyStore == null) {
            def logger = LoggerFactory.getLogger(getClass())
            logger.warn("No external store (availableInStoreKey parameter) specified for validating path availability in rule-set: {}. Using target: {} instead.", request.getRuleSet().getName(), request.getTarget())
            verifyStoreKey = request.getTarget()
        } else {
            verifyStoreKey = StoreKey.fromString(verifyStore)
            if (verifyStoreKey == null) {
                return "Invalid target: ${verifyStore} is not a StoreKey"
            }
        }

        def builder = new StringBuilder()
        def tools = request.getTools()
        def dc = DiscoveryConfig.getDisabledConfig();

        dc.setIncludeBuildSection(false)
        dc.setIncludeManagedDependencies(false)

        def logger = LoggerFactory.getLogger(ValidationRule.class)

        def pomTC = new SimpleTypeAndClassifier("pom")
        request.getSourcePaths().each { it ->
            if (it.endsWith(".pom")) {
                def relationships = tools.getRelationshipsForPom(it, dc, request.getPromoteRequest(), verifyStoreKey)
                if (relationships != null) {
                    relationships.each { rel ->
                        def target = rel.getTarget()
                        def path = tools.toArtifactPath(target)
                        def txfr = tools.getTransfer(verifyStoreKey, path)
                        logger.info("{} in {}: {}. Exists? {}", target, verifyStoreKey, txfr, txfr.exists())
                        if (!txfr.exists()) {
                            txfr = tools.getTransfer(request.getSource(), path)
                            logger.info("{} in {}: {}. Exists? {}", target, request.getSource(), txfr, txfr.exists())
                            if (!txfr.exists()) {
                                if (builder.length() > 0) {
                                    builder.append("\n")
                                }
                                builder.append(it).append(" is invalid: ").append(path).append(" is not available via: ").append(verifyStoreKey)
                            }
                        }

                        if ((target instanceof ArtifactRef) && !pomTC.equals(((ArtifactRef) target).getTypeAndClassifier())) {
                            path = tools.toArtifactPath(target.asPomArtifact())
                            txfr = tools.getTransfer(verifyStoreKey, path)
                            logger.info("POM {} in {}: {}. Exists? {}", target.asPomArtifact(), verifyStoreKey, txfr, txfr.exists())
                            if (!txfr.exists()) {
                                txfr = tools.getTransfer(request.getSource(), path)
                                logger.info("{} in {}: {}. Exists? {}", target, request.getSource(), txfr, txfr.exists())
                                if (!txfr.exists()) {
                                    if (builder.length() > 0) {
                                        builder.append("\n")
                                    }
                                    builder.append(it).append(" is invalid: ").append(path).append(" is not available via: ").append(verifyStoreKey)
                                }
                            }
                        }
                    }
                }
            }
        }

        builder.length() > 0 ? builder.toString() : null
    }
}
{'fraction_non_alphanumeric': 0.10747542679772375, 'fraction_numerical': 0.0010346611484738748, 'mean_word_length': 1.7248062015503876, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2563509', 'n_tokens_mistral': 1927, 'n_tokens_neox': 1847, 'n_words': 375}