/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
- * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import java.util.List;
import javax.ws.rs.core.Response;
import lombok.NonNull;
+import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfKey;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.base.PfModelRuntimeException;
import org.onap.policy.models.base.PfReferenceKey;
-import org.onap.policy.models.base.PfValidationResult;
import org.onap.policy.models.dao.PfDao;
import org.onap.policy.models.pdp.concepts.Pdp;
import org.onap.policy.models.pdp.concepts.PdpGroup;
import org.onap.policy.models.pdp.persistence.concepts.JpaPdp;
import org.onap.policy.models.pdp.persistence.concepts.JpaPdpGroup;
import org.onap.policy.models.pdp.persistence.concepts.JpaPdpSubGroup;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* This class provides the provision of information on PAP concepts in the database to callers.
* @author Liam Fallon (liam.fallon@est.tech)
*/
public class PdpProvider {
- private static final Logger LOGGER = LoggerFactory.getLogger(PdpProvider.class);
-
- // Recurring string constants
- private static final String NOT_VALID = "\" is not valid \n";
/**
* Get PDP groups.
JpaPdpGroup jpaPdpGroup = new JpaPdpGroup();
jpaPdpGroup.fromAuthorative(pdpGroup);
- PfValidationResult validationResult = jpaPdpGroup.validate(new PfValidationResult());
- if (!validationResult.isOk()) {
- String errorMessage = "pdp group \"" + jpaPdpGroup.getId() + NOT_VALID + validationResult;
- LOGGER.warn(errorMessage);
- throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
+ BeanValidationResult validationResult = jpaPdpGroup.validate("PDP group");
+ if (!validationResult.isValid()) {
+ throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, validationResult.getResult());
}
dao.create(jpaPdpGroup);
JpaPdpGroup jpaPdpGroup = new JpaPdpGroup();
jpaPdpGroup.fromAuthorative(pdpGroup);
- PfValidationResult validationResult = jpaPdpGroup.validate(new PfValidationResult());
- if (!validationResult.isOk()) {
- String errorMessage = "pdp group \"" + jpaPdpGroup.getId() + NOT_VALID + validationResult;
- LOGGER.warn(errorMessage);
- throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
+ BeanValidationResult validationResult = jpaPdpGroup.validate("PDP group");
+ if (!validationResult.isValid()) {
+ throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, validationResult.getResult());
}
dao.update(jpaPdpGroup);
final JpaPdpSubGroup jpaPdpSubgroup = new JpaPdpSubGroup(subGroupKey);
jpaPdpSubgroup.fromAuthorative(pdpSubGroup);
- PfValidationResult validationResult = jpaPdpSubgroup.validate(new PfValidationResult());
- if (!validationResult.isOk()) {
- String errorMessage = "PDP subgroup \"" + jpaPdpSubgroup.getId() + NOT_VALID + validationResult;
- LOGGER.warn(errorMessage);
- throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
+ BeanValidationResult validationResult = jpaPdpSubgroup.validate("PDP sub group");
+ if (!validationResult.isValid()) {
+ throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, validationResult.getResult());
}
dao.update(jpaPdpSubgroup);
final JpaPdp jpaPdp = new JpaPdp(pdpKey);
jpaPdp.fromAuthorative(pdp);
- PfValidationResult validationResult = jpaPdp.validate(new PfValidationResult());
- if (!validationResult.isOk()) {
- String errorMessage = "PDP \"" + jpaPdp.getId() + NOT_VALID + validationResult;
- LOGGER.warn(errorMessage);
- throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
+ BeanValidationResult validationResult = jpaPdp.validate("PDP");
+ if (!validationResult.isValid()) {
+ throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, validationResult.getResult());
}
dao.update(jpaPdp);