main/src/main/java/org/onap/policy/pap/main/rest/depundep/PdpGroupDeployProvider.java
/**
     * Performs additional validations of the policies within a subgroup.
     *
     * @param data session data
     * @param dbsub subgroup from the DB, or {@code null} if this is a new subgroup
     * @param subgrp the subgroup whose policies are to be validated, updated to fully
     *        qualified versions upon return
     * @param result the validation result
     * @throws PfModelException if an error occurred
     */
Performs additional validations of the policies within a subgroup.
Performs additional validations of the policies within a subgroup .
private ValidationResult validatePolicies(SessionData data, PdpSubGroup dbsub, PdpSubGroup subgrp)
                    throws PfModelException {
        Map<String, String> dbname2vers = new HashMap<>();
        if (dbsub != null) {
            dbsub.getPolicies().forEach(ident -> dbname2vers.put(ident.getName(), ident.getVersion()));
        }
        BeanValidationResult result = new BeanValidationResult(subgrp.getPdpType(), subgrp);
        for (ToscaPolicyIdentifier ident : subgrp.getPolicies()) {
            String expectedVersion = dbname2vers.get(ident.getName());
            if (expectedVersion != null) {
                validateVersion(expectedVersion, ident, result);
                ident.setVersion(expectedVersion);
                continue;
            }
            ToscaPolicy policy = data.getPolicy(new ToscaPolicyIdentifierOptVersion(ident));
            if (policy == null) {
                result.addResult(new ObjectValidationResult(POLICY_RESULT_NAME, ident, ValidationStatus.INVALID,
                                "unknown policy"));
            } else if (!subgrp.getSupportedPolicyTypes().contains(policy.getTypeIdentifier())) {
                result.addResult(new ObjectValidationResult(POLICY_RESULT_NAME, ident, ValidationStatus.INVALID,
                                "not a supported policy for the subgroup"));
            } else {
                ident.setVersion(policy.getVersion());
            }
        }
        return result;
    }
private ValidationResult validatePolicies ( SessionData data , PdpSubGroup dbsub , PdpSubGroup subgrp ) throws PfModelException { Map < String , String > dbname2vers = new HashMap < > ( ) ; if ( dbsub != null ) { dbsub . getPolicies ( ) . forEach ( ident -> dbname2vers . put ( ident . getName ( ) , ident . getVersion ( ) ) ) ; } BeanValidationResult result = new BeanValidationResult ( subgrp . getPdpType ( ) , subgrp ) ; for ( ToscaPolicyIdentifier ident : subgrp . getPolicies ( ) ) { String expectedVersion = dbname2vers . get ( ident . getName ( ) ) ; if ( expectedVersion != null ) { validateVersion ( expectedVersion , ident , result ) ; ident . setVersion ( expectedVersion ) ; continue ; } ToscaPolicy policy = data . getPolicy ( new ToscaPolicyIdentifierOptVersion ( ident ) ) ; if ( policy == null ) { result . addResult ( new ObjectValidationResult ( POLICY_RESULT_NAME , ident , ValidationStatus . INVALID , "unknown policy" ) ) ; } else if ( ! subgrp . getSupportedPolicyTypes ( ) . contains ( policy . getTypeIdentifier ( ) ) ) { result . addResult ( new ObjectValidationResult ( POLICY_RESULT_NAME , ident , ValidationStatus . INVALID , "not a supported policy for the subgroup" ) ) ; } else { ident . setVersion ( policy . getVersion ( ) ) ; } } return result ; }
Performs additional validations of the policies within a subgroup.
Performs additional validations of the policies within a subgroup .
// build a map of the DB data, from policy name to (fully qualified) policy version // note: "ident" may not have a fully qualified version // policy exists in the DB list - compare the versions // policy doesn't appear in the DB's policy list - look it up // replace version with the fully qualified version from the policy