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