aboutsummaryrefslogtreecommitdiffstats
path: root/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/model/PDPPolicyContainer.java
diff options
context:
space:
mode:
authorGuo Ruijing <ruijing.guo@intel.com>2017-07-31 08:47:35 +0000
committerPamela Dragosh <pdragosh@research.att.com>2017-07-31 15:51:10 -0400
commit073cc188efe9abb4c010cf674e34e2cf46ef1c52 (patch)
tree155c23fbdf3a838ecb5f4183fc3bb6b09aac41eb /ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/model/PDPPolicyContainer.java
parent4ca818fdfb9b807562166800a086b413593d6894 (diff)
[POLICY-73] replace openecomp for policy-engine
Change-Id: I54072f6bcd388c0e05562614ee89b4ae7ad67004 Signed-off-by: Guo Ruijing <ruijing.guo@intel.com> Signed-off-by: Pamela Dragosh <pdragosh@research.att.com>
Diffstat (limited to 'ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/model/PDPPolicyContainer.java')
-rw-r--r--ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/model/PDPPolicyContainer.java348
1 files changed, 0 insertions, 348 deletions
diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/model/PDPPolicyContainer.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/model/PDPPolicyContainer.java
deleted file mode 100644
index 13a1801bd..000000000
--- a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/model/PDPPolicyContainer.java
+++ /dev/null
@@ -1,348 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ECOMP-PAP-REST
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.policy.pap.xacml.rest.model;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Set;
-
-import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
-import org.openecomp.policy.common.logging.flexlogger.Logger;
-import org.openecomp.policy.pap.xacml.rest.util.PolicyContainer;
-import org.openecomp.policy.pap.xacml.rest.util.PolicyItemSetChangeNotifier;
-import org.openecomp.policy.xacml.api.XACMLErrorConstants;
-import org.openecomp.policy.xacml.std.pap.StdPDPPolicy;
-
-import com.att.research.xacml.api.pap.PDP;
-import com.att.research.xacml.api.pap.PDPGroup;
-import com.att.research.xacml.api.pap.PDPPolicy;
-import com.fasterxml.jackson.databind.DeserializationFeature;
-import com.fasterxml.jackson.databind.ObjectMapper;
-
-public class PDPPolicyContainer extends PolicyItemSetChangeNotifier implements PolicyContainer.Indexed {
- private static final long serialVersionUID = 1L;
- private static Logger logger = FlexLogger.getLogger(PDPPolicyContainer.class);
-
- /**
- * String identifier of a file's "Id" property.
- */
- public static String PROPERTY_ID = "Id";
-
- /**
- * String identifier of a file's "name" property.
- */
- public static String PROPERTY_NAME = "Name";
-
- /**
- * String identifier of a file's "name" property.
- */
- public static String PROPERTY_VERSION = "Version";
-
- /**
- * String identifier of a file's "Description" property.
- */
- public static String PROPERTY_DESCRIPTION = "Description";
-
- /**
- * String identifier of a file's "IsRoot" property.
- */
- public static String PROPERTY_ISROOT = "Root";
-
- /**
- * List of the string identifiers for the available properties.
- */
- public static Collection<String> PDPPOLICY_PROPERTIES;
-
- private final Object data;
- private List<PDPPolicy> policies;
-
- @SuppressWarnings("unchecked")
- public PDPPolicyContainer(Object data) {
- super();
- this.data = data;
- if (this.data instanceof PDPGroup) {
- policies = new ArrayList<PDPPolicy> (((PDPGroup) this.data).getPolicies());
- }
- if (this.data instanceof PDP) {
- policies = new ArrayList<PDPPolicy> (((PDP) this.data).getPolicies());
- }
- if (this.data instanceof Set) {
- policies = new ArrayList<PDPPolicy> ((Set<PDPPolicy>)data);
- }
- if (this.policies == null) {
- logger.info("NULL policies");
- throw new NullPointerException("PDPPolicyContainer created with unexpected Object type '" + data.getClass().getName() + "'");
- }
- this.setContainer(this);
- }
-
- @Override
- public Object nextItemId(Object itemId) {
- if (logger.isTraceEnabled()) {
- logger.trace("nextItemId: " + itemId);
- }
- int index = this.policies.indexOf(itemId);
- if (index == -1 || ((index + 1) >= this.policies.size())) {
- return null;
- }
- return new PDPPolicyItem(this.policies.get(index + 1));
- }
-
- @Override
- public Object prevItemId(Object itemId) {
- if (logger.isTraceEnabled()) {
- logger.trace("prevItemId: " + itemId);
- }
- int index = this.policies.indexOf(itemId);
- if (index <= 0) {
- return null;
- }
- return new PDPPolicyItem(this.policies.get(index - 1));
- }
-
- @Override
- public Object firstItemId() {
- if (logger.isTraceEnabled()) {
- logger.trace("firstItemId: ");
- }
- if (this.policies.isEmpty()) {
- return null;
- }
- return new PDPPolicyItem(this.policies.get(0));
- }
-
- @Override
- public Object lastItemId() {
- if (logger.isTraceEnabled()) {
- logger.trace("lastItemid: ");
- }
- if (this.policies.isEmpty()) {
- return null;
- }
- return new PDPPolicyItem(this.policies.get(this.policies.size() - 1));
- }
-
- @Override
- public boolean isFirstId(Object itemId) {
- if (logger.isTraceEnabled()) {
- logger.trace("isFirstId: " + itemId);
- }
- if (this.policies.isEmpty()) {
- return false;
- }
- return (itemId.equals(this.policies.get(0)));
- }
-
- @Override
- public boolean isLastId(Object itemId) {
- if (logger.isTraceEnabled()) {
- logger.trace("isLastId: " + itemId);
- }
- if (this.policies.isEmpty()) {
- return false;
- }
- return (itemId.equals(this.policies.get(this.policies.size() - 1)));
- }
-
- @Override
- public Object addItemAfter(Object previousItemId)
- throws UnsupportedOperationException {
- return null;
- }
-
- @Override
- public Collection<?> getContainerPropertyIds() {
- return PDPPOLICY_PROPERTIES;
- }
-
- @Override
- public Collection<?> getItemIds() {
- final Collection<Object> items = new ArrayList<>();
- items.addAll(this.policies);
- return Collections.unmodifiableCollection(items);
- }
-
-
- @Override
- public Class<?> getType(Object propertyId) {
- if (propertyId.equals(PROPERTY_ID)) {
- return String.class;
- }
- if (propertyId.equals(PROPERTY_NAME)) {
- return String.class;
- }
- if (propertyId.equals(PROPERTY_VERSION)) {
- return String.class;
- }
- if (propertyId.equals(PROPERTY_DESCRIPTION)) {
- return String.class;
- }
- if (propertyId.equals(PROPERTY_ISROOT)) {
- return Boolean.class;
- }
- return null;
- }
-
- @Override
- public int size() {
- if (logger.isTraceEnabled()) {
- logger.trace("size: " + this.policies.size());
- }
- return this.policies.size();
- }
-
- @Override
- public boolean containsId(Object itemId) {
- if (logger.isTraceEnabled()) {
- logger.trace("containsId: " + itemId);
- }
- return this.policies.contains(itemId);
- }
-
- @Override
- public Object addItem() throws UnsupportedOperationException {
- throw new UnsupportedOperationException("Cannot add an empty policy.");
- }
-
- @Override
- public boolean removeItem(Object itemId)
- throws UnsupportedOperationException {
- if (logger.isTraceEnabled()) {
- logger.trace("removeItem: " + itemId);
- }
- ObjectMapper mapper = new ObjectMapper();
- mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
- StdPDPPolicy pdpPolicy = null;
- try {
- pdpPolicy = mapper.readValue(itemId.toString() , StdPDPPolicy.class);
- for(int i = 0; i< policies.size(); i++){
- if(policies.get(i).getId().equalsIgnoreCase(pdpPolicy.getId())){
- return this.policies.remove(this.policies.get(i));
- }
- }
- } catch (Exception e) {
- logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Exception Occured While Mapping the Removing Policy from PDP Group to Std Policy"+e);
- }
- return this.policies.remove(itemId);
- }
-
- @Override
- public boolean addContainerProperty(Object propertyId, Class<?> type,
- Object defaultValue) throws UnsupportedOperationException {
- return false;
- }
-
- @Override
- public boolean removeContainerProperty(Object propertyId)
- throws UnsupportedOperationException {
- return false;
- }
-
- @Override
- public boolean removeAllItems() throws UnsupportedOperationException {
- return false;
- }
-
- @Override
- public int indexOfId(Object itemId) {
- if (logger.isTraceEnabled()) {
- logger.trace("indexOfId: " + itemId);
- }
- return this.policies.indexOf(itemId);
- }
-
- @Override
- public Object getIdByIndex(int index) {
- if (logger.isTraceEnabled()) {
- logger.trace("getIdByIndex: " + index);
- }
- return this.policies.get(index);
- }
-
- @Override
- public List<?> getItemIds(int startIndex, int numberOfItems) {
- if (logger.isTraceEnabled()) {
- logger.trace("getItemIds: " + startIndex + " " + numberOfItems);
- }
- if (numberOfItems < 0) {
- throw new IllegalArgumentException();
- }
- return this.policies.subList(startIndex, startIndex + numberOfItems);
- }
-
- @Override
- public Object addItemAt(int index) throws UnsupportedOperationException {
- if (logger.isTraceEnabled()) {
- logger.trace("addItemAt: " + index);
- }
- return null;
- }
-
- public class PDPPolicyItem {
- private final PDPPolicy policy;
-
- public PDPPolicyItem(PDPPolicy itemId) {
- this.policy = itemId;
- }
-
- public String getId() {
- if (logger.isTraceEnabled()) {
- logger.trace("getId: " + this.policy);
- }
- return this.policy.getId();
- }
-
- public String getName() {
- if (logger.isTraceEnabled()) {
- logger.trace("getName: " + this.policy);
- }
- return this.policy.getName();
- }
-
- public String getVersion() {
- if (logger.isTraceEnabled()) {
- logger.trace("getVersion: " + this.policy);
- }
- return this.policy.getVersion();
- }
-
- public String getDescription() {
- if (logger.isTraceEnabled()) {
- logger.trace("getDescription: " + this.policy);
- }
- return this.policy.getDescription();
- }
-
- public boolean getRoot() {
- if (logger.isTraceEnabled()) {
- logger.trace("isRoot: " + this.policy);
- }
- return this.policy.isRoot();
- }
-
- public void setRoot(Boolean root) {
- ((StdPDPPolicy)this.policy).setRoot(root);
- }
-
- }
-} \ No newline at end of file