- public Map<Pair<String, String>, List<ToscaPolicy>> getDeployedPolicyList(@NonNull final PfDao dao,
- final String name) throws PfModelException {
- return new LinkedHashMap<>();
+ public void cudPolicyStatus(@NonNull final PfDao dao, Collection<PdpPolicyStatus> createObjs,
+ Collection<PdpPolicyStatus> updateObjs, Collection<PdpPolicyStatus> deleteObjs) {
+
+ synchronized (statusLock) {
+ dao.deleteCollection(fromAuthorativeStatus(deleteObjs, "deletePdpPolicyStatusList"));
+ dao.createCollection(fromAuthorativeStatus(createObjs, "createPdpPolicyStatusList"));
+ dao.createCollection(fromAuthorativeStatus(updateObjs, "updatePdpPolicyStatusList"));
+ }
+ }
+
+ /**
+ * Converts a collection of authorative policy status to a collection of JPA policy
+ * status. Validates the resulting list.
+ *
+ * @param objs authorative policy status to convert
+ * @param fieldName name of the field containing the collection
+ * @return a collection of JPA policy status
+ */
+ private Collection<JpaPdpPolicyStatus> fromAuthorativeStatus(Collection<PdpPolicyStatus> objs, String fieldName) {
+ if (objs == null) {
+ return Collections.emptyList();
+ }
+
+ List<JpaPdpPolicyStatus> jpas = objs.stream().map(JpaPdpPolicyStatus::new).collect(Collectors.toList());
+
+ // validate the objects
+ var result = new BeanValidationResult(fieldName, jpas);
+
+ var count = 0;
+ for (JpaPdpPolicyStatus jpa: jpas) {
+ result.addResult(jpa.validate(String.valueOf(count++)));
+ }
+
+ if (!result.isValid()) {
+ throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, result.getResult());
+ }
+
+ return jpas;