250029a89f35070a2fd71d5c4ad73319a161fe80
[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
25 import java.util.List;
26
27 import javax.persistence.PersistenceException;
28
29 import org.onap.policy.rest.dao.PolicyDBException;
30 import org.onap.policy.rest.jpa.GroupEntity;
31 import org.onap.policy.rest.jpa.PdpEntity;
32 import org.onap.policy.xacml.api.pap.OnapPDP;
33 import org.onap.policy.xacml.api.pap.OnapPDPGroup;
34 import org.onap.policy.xacml.std.pap.StdPDPGroup;
35
36 public interface PolicyDBDaoTransaction {
37
38     /**
39      * Commits (makes permanent) the current transaction. Also, notifies other PolicyDBDao instances on other PAP
40      * servers of the update.
41      *
42      * @throws IllegalStateException if the PolicyDBDao transaction has not been used or has been committed already.
43      * @throws PersistenceException if the commit fails for some reason
44      */
45     public void commitTransaction();
46
47     /**
48      * Create or update a policy
49      *
50      * @param policy A Policy object representing the policy to store or update
51      * @param username A string of the username you want to be stored for doing this operation
52      * @throws IllegalStateException If a transaction is open that has not yet been committed
53      * @throws PersistenceException If a database error occurs
54      * @throws IllegalArgumentException If the Policy's PolicyRestAdapter contains incorrect data.
55      */
56     public void createPolicy(Policy policy, String username) throws PolicyDBException;
57
58     /**
59      * Check if the PolicyDBDaoTransaction is currently open
60      *
61      * @return False if the PolicyDBDao transaction has not been used or has been committed already, true if it is open.
62      */
63     public boolean isTransactionOpen();
64
65     /**
66      * Rollback (undo) the current transaction.
67      */
68     public void rollbackTransaction();
69
70     /**
71      * Close the PolicyDBDaoTransaction without rolling back or doing anything. Just used to close the Hibernate
72      * session.
73      */
74     public void close();
75
76     /**
77      * Create a new PDP group in the database
78      *
79      * @param groupID The ID to name the new group (use PolicyDBDao.createNewPDPGroupId)
80      * @param groupName The name to use for the new group
81      * @param groupDescription Description of the new group (optional)
82      * @param username Username of the user performing the operation
83      * @throws IllegalArgumentException If non-optional parameters are null or empty strings
84      * @throws IllegalStateException If a transaction is already open
85      * @throws PersistenceException If a database error occurs
86      */
87     public void createGroup(String groupID, String groupName, String groupDescription, String username)
88             throws PolicyDBException;
89
90     /**
91      * Updates a group in the database with a new name of description
92      *
93      * @param group The group with updated information. The id must match an existing group, but the name and
94      *        description can be changed.
95      * @param username Username of the user performing the operation
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
100      */
101     public void updateGroup(OnapPDPGroup group, String requestType, String userId) throws PolicyDBException;
102
103     /**
104      * Updates a PDP in the database with new information
105      *
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
111      */
112     public void updatePdp(OnapPDP pdp, String username) throws PolicyDBException;
113
114     /**
115      * Change the default group in the database to the group provided.
116      *
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
122      */
123     public void changeDefaultGroup(OnapPDPGroup group, String username) throws PolicyDBException;
124
125     /**
126      * Moves a PDP to a new group.
127      *
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
134      */
135     public void movePdp(OnapPDP pdp, OnapPDPGroup group, String username) throws PolicyDBException;
136
137     /**
138      * Add a new PDP to an existing group
139      *
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
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
149      */
150     public void addPdpToGroup(String pdpID, String groupID, String pdpName, String pdpDescription, int pdpJmxPort,
151             String username) throws PolicyDBException;
152
153     /**
154      * Add an existing policy to an existing group
155      *
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
159      * @throws IllegalArgumentException If non-optional parameters are null or empty strings
160      * @throws IllegalStateException If a transaction is already open
161      * @throws PersistenceException If a database error occurs
162      * @throws PolicyDBException
163      */
164     public StdPDPGroup addPolicyToGroup(String group, String policyID, String requestType, String username)
165             throws PolicyDBException;
166
167     /**
168      * Delete an existing PDP groupPolicyDBException
169      *
170      * @param group A PDPGroup object representing the group to delete
171      * @param moveToGroup A PDPGroup object representing another existing group which PDPs in the group being deleted
172      *        should be moved to
173      * @throws IllegalArgumentException If non-optional parameters are null or empty strings
174      * @throws IllegalStateException If a transaction is already open
175      * @throws PersistenceException If a database error occurs
176      * @throws PAPException If an error relating to how groups are handled occurs
177      */
178     public void deleteGroup(OnapPDPGroup group, OnapPDPGroup moveToGroup, String username) throws PolicyDBException;
179
180     /**
181      * Removes an existing PDP from its group and deletes it.
182      *
183      * @param pdpID The ID of the existing PDP which should be deleted
184      * @throws IllegalArgumentException If non-optional parameters are null or empty strings
185      * @throws IllegalStateException If a transaction is already open
186      * @throws PersistenceException If a database error occurs
187      */
188     public void removePdpFromGroup(String pdpID, String username) throws PolicyDBException;
189
190     public GroupEntity getGroup(long groupKey);
191
192     public GroupEntity getGroup(String groupId);
193
194     public List<?> getPdpsInGroup(long groupKey);
195
196     public PdpEntity getPdp(long pdpKey);
197 }