2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2019 Nordix Foundation.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.pap.xacml.rest.components;
24 import com.att.research.xacml.api.pap.PAPException;
26 import java.util.List;
28 import javax.persistence.PersistenceException;
30 import org.onap.policy.rest.dao.PolicyDbException;
31 import org.onap.policy.rest.jpa.GroupEntity;
32 import org.onap.policy.rest.jpa.PdpEntity;
33 import org.onap.policy.xacml.api.pap.OnapPDP;
34 import org.onap.policy.xacml.api.pap.OnapPDPGroup;
35 import org.onap.policy.xacml.std.pap.StdPDPGroup;
37 public interface PolicyDbDaoTransaction {
40 * Commits (makes permanent) the current transaction. Also, notifies other PolicyDBDao instances on other PAP
41 * servers of the update.
43 * @throws IllegalStateException if the PolicyDBDao transaction has not been used or has been committed already.
44 * @throws PersistenceException if the commit fails for some reason
46 public void commitTransaction();
49 * Create or update a policy.
51 * @param policy A Policy object representing the policy to store or update
52 * @param username A string of the username you want to be stored for doing this operation
53 * @throws IllegalStateException If a transaction is open that has not yet been committed
54 * @throws PersistenceException If a database error occurs
55 * @throws IllegalArgumentException If the Policy's PolicyRestAdapter contains incorrect data.
57 public void createPolicy(Policy policy, String username) throws PolicyDbException;
60 * Check if the PolicyDBDaoTransaction is currently open.
62 * @return False if the PolicyDBDao transaction has not been used or has been committed already, true if it is open.
64 public boolean isTransactionOpen();
67 * Rollback (undo) the current transaction.
69 public void rollbackTransaction();
72 * Close the PolicyDBDaoTransaction without rolling back or doing anything. Just used to close the Hibernate
78 * Create a new PDP group in the database.
80 * @param groupID The ID to name the new group (use PolicyDBDao.createNewPDPGroupId)
81 * @param groupName The name to use for the new group
82 * @param groupDescription Description of the new group (optional)
83 * @param username Username of the user performing the operation
84 * @throws IllegalArgumentException If non-optional parameters are null or empty strings
85 * @throws IllegalStateException If a transaction is already open
86 * @throws PersistenceException If a database error occurs
88 public void createGroup(String groupID, String groupName, String groupDescription, String username)
89 throws PolicyDbException;
92 * Updates a group in the database with a new name of description.
94 * @param group The group with updated information. The id must match an existing group, but the name and
95 * description can be changed.
96 * @param userId needed to store user information in policyAuditlog table during transaction.
97 * @throws IllegalArgumentException If non-optional parameters are null or empty strings
98 * @throws IllegalStateException If a transaction is already open
99 * @throws PersistenceException If a database error occurs or if the group can not be found
101 public void updateGroup(OnapPDPGroup group, String requestType, String userId) throws PolicyDbException;
104 * Updates a PDP in the database with new information.
106 * @param pdp The PDP to update
107 * @param username Username of the user performing the operation
108 * @throws IllegalArgumentException If non-optional parameters are null or empty strings
109 * @throws IllegalStateException If a transaction is already open
110 * @throws PersistenceException If a database error occurs or if the pdp can not be found
112 public void updatePdp(OnapPDP pdp, String username) throws PolicyDbException;
115 * Change the default group in the database to the group provided.
117 * @param group The new group which should be set as default in the database
118 * @param username Username of the user performing the operation
119 * @throws IllegalArgumentException If non-optional parameters are null or empty strings
120 * @throws IllegalStateException If a transaction is already open
121 * @throws PersistenceException If a database error occurs
123 public void changeDefaultGroup(OnapPDPGroup group, String username) throws PolicyDbException;
126 * Moves a PDP to a new group.
128 * @param pdp The PDP which is to be moved to a new group
129 * @param group The new group which the PDP should be added to
130 * @param username Username of the user performing the operation
131 * @throws IllegalArgumentException If non-optional parameters are null or empty strings
132 * @throws IllegalStateException If a transaction is already open
133 * @throws PersistenceException If a database error occurs
135 public void movePdp(OnapPDP pdp, OnapPDPGroup group, String username) throws PolicyDbException;
138 * Add a new PDP to an existing group.
140 * @param pdpID The ID to name the new PDP
141 * @param groupID The ID of the existing group to add the PDP to
142 * @param pdpName The name to use for the new PDP
143 * @param pdpDescription Description of the new PDP (optional)
144 * @param pdpJmxPort PDP JMX port
145 * @param username Username of the user performing the operation
146 * @throws IllegalArgumentException If non-optional parameters are null or empty strings
147 * @throws IllegalStateException If a transaction is already open
148 * @throws PersistenceException If a database error occurs
150 public void addPdpToGroup(String pdpID, String groupID, String pdpName, String pdpDescription, int pdpJmxPort,
151 String username) throws PolicyDbException;
154 * Add an existing policy to an existing group.
156 * @param group The ID of the existing group to add the policy to
157 * @param policyID The ID of an existing policy
158 * @return the PDP groups
159 * @throws PolicyDbException on DB exceptions
161 public StdPDPGroup addPolicyToGroup(String group, String policyID, String requestType, String username)
162 throws PolicyDbException;
165 * Delete an existing PDP groupPolicyDBException.
167 * @param group A PDPGroup object representing the group to delete
168 * @param moveToGroup A PDPGroup object representing another existing group which PDPs in the group being deleted
170 * @throws IllegalArgumentException If non-optional parameters are null or empty strings
171 * @throws IllegalStateException If a transaction is already open
172 * @throws PersistenceException If a database error occurs
173 * @throws PAPException If an error relating to how groups are handled occurs
175 public void deleteGroup(OnapPDPGroup group, OnapPDPGroup moveToGroup, String username) throws PolicyDbException;
178 * Removes an existing PDP from its group and deletes it.
180 * @param pdpID The ID of the existing PDP which should be deleted
181 * @throws IllegalArgumentException If non-optional parameters are null or empty strings
182 * @throws IllegalStateException If a transaction is already open
183 * @throws PersistenceException If a database error occurs
185 public void removePdpFromGroup(String pdpID, String username) throws PolicyDbException;
187 public GroupEntity getGroup(long groupKey);
189 public GroupEntity getGroup(String groupId);
191 public List<?> getPdpsInGroup(long groupKey);
193 public PdpEntity getPdp(long pdpKey);