* ============LICENSE_START=======================================================
* ONAP PAP
* ================================================================================
- * Copyright (C) 2019-2021 Nordix Foundation.
+ * Copyright (C) 2019-2021, 2023 Nordix Foundation.
* Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property.
* Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
* ================================================================================
package org.onap.policy.pap.main.rest;
+import jakarta.ws.rs.core.Response.Status;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Consumer;
import java.util.stream.Collectors;
-import javax.ws.rs.core.Response.Status;
import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.common.parameters.ValidationResult;
import org.onap.policy.common.parameters.ValidationStatus;
List<PdpSubGroup> subGroupsWithPolicies =
groups.getGroups().parallelStream().flatMap(group -> group.getPdpSubgroups().parallelStream())
.filter(subGroup -> null != subGroup.getPolicies() && !subGroup.getPolicies().isEmpty())
- .collect(Collectors.toList());
+ .toList();
if (!subGroupsWithPolicies.isEmpty()) {
logger.warn(
"Policies cannot be deployed during PdpGroup Create/Update operation. Ignoring the list of policies");
/**
* Creates or updates PDP groups. This is the method that does the actual work.
*
- * @param data session data
+ * @param data session data
* @param groups PDP group configurations
* @throws PfModelException if an error occurred
*/
/**
* Adds a new group.
*
- * @param data session data
+ * @param data session data
* @param group the group to be added
* @return the validation result
* @throws PfModelException if an error occurred
/**
* Performs additional validations of a group, but does not examine the subgroups.
*
- * @param group the group to be validated
+ * @param group the group to be validated
* @param result the validation result
*/
private void validateGroupOnly(PdpGroup group, BeanValidationResult result) {
return;
}
- switch (group.getPdpGroupState()) {
- case ACTIVE:
- case PASSIVE:
- break;
-
- default:
- result.addResult("pdpGroupState", group.getPdpGroupState(),
- ValidationStatus.INVALID, "must be null, ACTIVE, or PASSIVE");
- break;
+ PdpState pdpGroupState = group.getPdpGroupState();
+ if (pdpGroupState != PdpState.ACTIVE && pdpGroupState != PdpState.PASSIVE) {
+ result.addResult("pdpGroupState", group.getPdpGroupState(),
+ ValidationStatus.INVALID, "must be null, ACTIVE, or PASSIVE");
}
}
/**
* Updates an existing group.
*
- * @param data session data
+ * @param data session data
* @param dbgroup the group, as it appears within the DB
- * @param group the group to be added
+ * @param group the group to be added
* @return the validation result
* @throws PfModelException if an error occurred
*/
}
/**
- * Updates a field, if the new value is different than the old value.
+ * Updates a field, if the new value is different from the old value.
*
* @param oldValue old value
* @param newValue new value
- * @param setter function to set the field to the new value
- * @return {@code true} if the field was updated, {@code false} if it already matched
- * the new value
+ * @param setter function to set the field to the new value
+ * @return {@code true} if the field was updated, {@code false} if it already matched the new value
*/
private <T> boolean updateField(T oldValue, T newValue, Consumer<T> setter) {
if (oldValue == newValue) {
/**
* Adds or updates subgroups within the group.
*
- * @param data session data
+ * @param data session data
* @param dbgroup the group, as it appears within the DB
- * @param group the group to be added
- * @param result the validation result
+ * @param group the group to be added
+ * @param result the validation result
* @return {@code true} if the DB group was modified, {@code false} otherwise
* @throws PfModelException if an error occurred
*/
private boolean addOrUpdateSubGroups(SessionData data, PdpGroup dbgroup, PdpGroup group,
- BeanValidationResult result) throws PfModelException {
+ BeanValidationResult result) throws PfModelException {
// create a map of existing subgroups
Map<String, PdpSubGroup> type2sub = new HashMap<>();
/**
* Notifies any PDPs whose subgroups are being removed.
*
- * @param data session data
+ * @param data session data
* @param dbgroup the group, as it appears within the DB
- * @param group the group being updated
+ * @param group the group being updated
* @return {@code true} if a subgroup was removed, {@code false} otherwise
* @throws PfModelException if an error occurred
*/
/**
* Notifies the PDPs that their subgroup is being removed.
*
- * @param data session data
+ * @param data session data
* @param subgrp subgroup that is being removed
*/
private void notifyPdpsDelSubGroup(SessionData data, PdpSubGroup subgrp) {
/**
* Tracks PDP responses when their subgroup is removed.
*
- * @param data session data
+ * @param data session data
* @param pdpGroup PdpGroup name
- * @param subgrp subgroup that is being removed
+ * @param subgrp subgroup that is being removed
* @throws PfModelException if an error occurred
*/
private void trackPdpsDelSubGroup(SessionData data, String pdpGroup, PdpSubGroup subgrp) throws PfModelException {
/**
* Adds a new subgroup.
*
- * @param data session data
+ * @param data session data
* @param subgrp the subgroup to be added, updated to fully qualified versions upon
- * return
+ * return
* @return the validation result
* @throws PfModelException if an error occurred
*/
/**
* Updates an existing subgroup.
*
- * @param dbsub the subgroup, from the DB
- * @param subgrp the subgroup to be updated, updated to fully qualified versions upon
- * return
+ * @param dbsub the subgroup, from the DB
+ * @param subgrp the subgroup to be updated, updated to fully qualified versions upon
+ * return
* @param container container for additional validation results
- * @return {@code true} if the subgroup content was changed, {@code false} if there
- * were no changes
+ * @return {@code true} if the subgroup content was changed, {@code false} if there were no changes
*/
private boolean updateSubGroup(PdpSubGroup dbsub, PdpSubGroup subgrp, BeanValidationResult container) {
/**
* Performs additional validations of a subgroup.
*
- * @param dbsub the subgroup, from the DB
- * @param subgrp the subgroup to be validated, updated to fully qualified versions
- * upon return
+ * @param dbsub the subgroup, from the DB
+ * @param subgrp the subgroup to be validated, updated to fully qualified versions
+ * upon return
* @param container container for additional validation results
* @return {@code true} if the subgroup is valid, {@code false} otherwise
*/
/**
* Performs validations of the supported policy types within a subgroup.
*
- * @param data session data
+ * @param data session data
* @param subgrp the subgroup to be validated
* @return the validation result
* @throws PfModelException if an error occurred
@Override
protected Updater makeUpdater(SessionData data, ToscaPolicy policy,
- ToscaConceptIdentifierOptVersion desiredPolicy) {
+ ToscaConceptIdentifierOptVersion desiredPolicy) {
throw new UnsupportedOperationException("makeUpdater should not be invoked");
}
}