Policy 1707 commit to LF
[policy/engine.git] / ECOMP-PAP-REST / src / main / java / org / openecomp / policy / pap / xacml / rest / components / PolicyDBDaoTransaction.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ECOMP-PAP-REST
4  * ================================================================================
5  * Copyright (C) 2017 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.openecomp.policy.pap.xacml.rest.components;
22
23 import java.util.List;
24
25 import javax.persistence.PersistenceException;
26
27 import org.openecomp.policy.rest.jpa.GroupEntity;
28 import org.openecomp.policy.rest.jpa.PdpEntity;
29 import org.openecomp.policy.xacml.api.pap.EcompPDP;
30 import org.openecomp.policy.xacml.api.pap.EcompPDPGroup;
31
32 import com.att.research.xacml.api.pap.PAPException;
33
34 public interface PolicyDBDaoTransaction {
35
36         /**
37          * Commits (makes permanent) the current transaction. Also, notifies other PolicyDBDao instances on other PAP servers of the update.
38          * @throws IllegalStateException if the PolicyDBDao transaction has not been used or has been committed already.
39          * @throws PersistenceException if the commit fails for some reason
40          */
41         public void commitTransaction();
42         
43         /**
44          * Create or update a policy
45          * @param policy A Policy object representing the policy to store or update
46          * @param username A string of the username you want to be stored for doing this operation
47          * @throws IllegalStateException If a transaction is open that has not yet been committed
48          * @throws PersistenceException If a database error occurs
49          * @throws IllegalArgumentException If the Policy's PolicyRestAdapter contains incorrect data.
50          */
51         public void createPolicy(Policy policy, String username) throws IllegalStateException, PersistenceException, IllegalArgumentException;
52         
53         /**
54          * Create or update a policy
55          * @param filePath The file path of the policy xml file
56          * @param username A string of the username you want to be stored for doing this operation
57          * @throws IllegalStateException If a transaction is open that has not yet been committed
58          * @throws PersistenceException If a database error occurs
59          * @throws IllegalArgumentException If the file path is incorrect, or if it refers to a Config policy
60          */
61         public void createPolicy(String filePath, String username) throws IllegalStateException, PersistenceException, IllegalArgumentException;
62         
63         /**
64          * Check if the PolicyDBDaoTransaction is currently open
65          * @return False if the PolicyDBDao transaction has not been used or has been committed already, true if it is open.
66          */
67         public boolean isTransactionOpen();
68         
69         
70         
71         /**
72          * Delete an existing policy
73          * @param policyToDelete The file path of the policy to delete
74          * @throws IllegalArgumentException If the file path given can not be parsed
75          * @throws IllegalStateException If a transaction is open that has not yet been committed
76          * @throws PersistenceException If a database error occurs
77          */
78         public void deletePolicy(String policyToDelete) throws IllegalStateException, PersistenceException, IllegalArgumentException;
79         
80         /**
81          * Rollback (undo) the current transaction.
82          */
83         public void rollbackTransaction();
84         
85         /**
86          * Close the PolicyDBDaoTransaction without rolling back or doing anything. Just used to close the EntityManager
87          */
88         public void close();
89         
90         
91         /**
92          * Create a new PDP group in the database
93          * @param groupID The ID to name the new group (use PolicyDBDao.createNewPDPGroupId)
94          * @param groupName The name to use for the new group
95          * @param groupDescription Description of the new group (optional)
96          * @param username Username of the user performing the operation
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
100          */
101         public void createGroup(String groupID, String groupName, String groupDescription, String username) throws IllegalArgumentException, IllegalStateException, PersistenceException;
102         
103         /**
104          * Updates a group in the database with a new name of description
105          * @param group The group with updated information. The id must match an existing group, but the name and description can be changed.
106          * @param username Username of the user performing the operation
107          * @throws IllegalArgumentException If non-optional parameters are null or empty strings
108          * @throws IllegalStateException If a transaction is already open
109          * @throws PersistenceException If a database error occurs or if the group can not be found
110          */
111         public void updateGroup(EcompPDPGroup group, String username) throws IllegalArgumentException, IllegalStateException, PersistenceException;
112         
113         /**
114          * Updates a PDP in the database with new information
115          * @param pdp The PDP to update
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 or if the pdp can not be found
120          */
121         public void updatePdp(EcompPDP pdp, String username) throws IllegalArgumentException, IllegalStateException, PersistenceException;
122         
123         /**
124          * Change the default group in the database to the group provided.
125          * @param group The new group which should be set as default in the database
126          * @param username Username of the user performing the operation
127          * @throws IllegalArgumentException If non-optional parameters are null or empty strings
128          * @throws IllegalStateException If a transaction is already open
129          * @throws PersistenceException If a database error occurs
130          */
131         public void changeDefaultGroup(EcompPDPGroup group, String username) throws IllegalArgumentException, IllegalStateException, PersistenceException;
132         
133         /**
134          * Moves a PDP to a new group.
135          * @param pdp The PDP which is to be moved to a new group
136          * @param group The new group which the PDP should be added to
137          * @param username Username of the user performing the operation
138          * @throws IllegalArgumentException If non-optional parameters are null or empty strings
139          * @throws IllegalStateException If a transaction is already open
140          * @throws PersistenceException If a database error occurs
141          */
142         public void movePdp(EcompPDP pdp, EcompPDPGroup group, String username) throws IllegalArgumentException, IllegalStateException, PersistenceException;
143         
144         /**
145          * Add a new PDP to an existing group
146          * @param pdpID The ID to name the new PDP
147          * @param groupID The ID of the existing group to add the PDP to
148          * @param pdpName The name to use for the new PDP
149          * @param pdpDescription Description of the new PDP (optional)
150          * @param pdpJmxPort
151          * @param username Username of the user performing the operation
152          * @throws IllegalArgumentException If non-optional parameters are null or empty strings
153          * @throws IllegalStateException If a transaction is already open
154          * @throws PersistenceException If a database error occurs
155          */
156         public void addPdpToGroup(String pdpID, String groupID, String pdpName, String pdpDescription, int pdpJmxPort, String username) throws IllegalArgumentException, IllegalStateException, PersistenceException;
157         
158         /**
159          * Add an existing policy to an existing group
160          * @param group The ID of the existing group to add the policy to
161          * @param policyID The ID of an existing policy
162          * @throws IllegalArgumentException If non-optional parameters are null or empty strings
163          * @throws IllegalStateException If a transaction is already open
164          * @throws PersistenceException If a database error occurs
165          */
166         public void addPolicyToGroup(String group, String policyID, String username) throws IllegalArgumentException, IllegalStateException, PersistenceException;
167         
168         
169         /**
170          * Delete an existing PDP group
171          * @param group A PDPGroup object representing the group to delete
172          * @param moveToGroup A PDPGroup object representing another existing group which PDPs in the group being deleted 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(EcompPDPGroup group, EcompPDPGroup moveToGroup, String username)throws IllegalArgumentException, IllegalStateException, PersistenceException, PAPException;
179         
180         /**
181          * Removes an existing PDP from its group and deletes it.
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 IllegalArgumentException, IllegalStateException, PersistenceException;
188         
189         public GroupEntity getGroup(long groupKey);
190         public GroupEntity getGroup(String groupId);
191         public List<?> getPdpsInGroup(long groupKey);
192         public PdpEntity getPdp(long pdpKey);
193
194         void renamePolicy(String oldPath, String newPath,String username);
195
196         void clonePolicy(String oldPolicyPath, String newPolicyPath, String username);
197                 
198 }