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