2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.policy.pap.xacml.rest.components;
23 import java.util.List;
26 import javax.persistence.PersistenceException;
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;
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;
38 public interface PolicyDBDaoTransaction {
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
45 public void commitTransaction();
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.
55 public void createPolicy(Policy policy, String username) throws IllegalStateException, PersistenceException, IllegalArgumentException;
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
65 public void createPolicy(String filePath, String username) throws IllegalStateException, PersistenceException, IllegalArgumentException;
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.
71 public boolean isTransactionOpen();
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
82 public void deletePolicy(String policyToDelete) throws IllegalStateException, PersistenceException, IllegalArgumentException;
85 * Rollback (undo) the current transaction.
87 public void rollbackTransaction();
90 * Close the PolicyDBDaoTransaction without rolling back or doing anything. Just used to close the EntityManager
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
105 public void createGroup(String groupID, String groupName, String groupDescription, String username) throws IllegalArgumentException, IllegalStateException, PersistenceException;
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
115 public void updateGroup(EcompPDPGroup group, String username) throws IllegalArgumentException, IllegalStateException, PersistenceException;
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
125 public void updatePdp(EcompPDP pdp, String username) throws IllegalArgumentException, IllegalStateException, PersistenceException;
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
135 public void changeDefaultGroup(EcompPDPGroup group, String username) throws IllegalArgumentException, IllegalStateException, PersistenceException;
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
146 public void movePdp(EcompPDP pdp, EcompPDPGroup group, String username) throws IllegalArgumentException, IllegalStateException, PersistenceException;
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)
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
160 public void addPdpToGroup(String pdpID, String groupID, String pdpName, String pdpDescription, int pdpJmxPort, String username) throws IllegalArgumentException, IllegalStateException, PersistenceException;
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
170 public void addPolicyToGroup(String group, String policyID, String username) throws IllegalArgumentException, IllegalStateException, PersistenceException;
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
182 public void deleteGroup(EcompPDPGroup group, EcompPDPGroup moveToGroup, String username)throws IllegalArgumentException, IllegalStateException, PersistenceException, PAPException;
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
191 public void removePdpFromGroup(String pdpID, String username) throws IllegalArgumentException, IllegalStateException, PersistenceException;
193 public GroupEntity getGroup(long groupKey);
194 public GroupEntity getGroup(String groupId);
195 public List<?> getPdpsInGroup(long groupKey);
196 public PdpEntity getPdp(long pdpKey);
198 void renamePolicy(String oldPath, String newPath,String username);
200 void clonePolicy(String oldPolicyPath, String newPolicyPath, String username);