aboutsummaryrefslogtreecommitdiffstats
path: root/applications/common/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'applications/common/src/main')
-rw-r--r--applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/ToscaDictionary.java6
-rw-r--r--applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/ToscaPolicyTranslatorUtils.java69
-rw-r--r--applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/operationshistory/GetOperationOutcomePip.java14
3 files changed, 81 insertions, 8 deletions
diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/ToscaDictionary.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/ToscaDictionary.java
index c8dab3a8..921babb8 100644
--- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/ToscaDictionary.java
+++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/ToscaDictionary.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 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.
@@ -82,6 +82,10 @@ public final class ToscaDictionary {
new IdentifierImpl(ID_URN_ONAP, "guard:target:min");
public static final Identifier ID_RESOURCE_GUARD_MAX =
new IdentifierImpl(ID_URN_ONAP, "guard:target:max");
+ public static final Identifier ID_RESOURCE_GUARD_TIMESTART =
+ new IdentifierImpl(ID_URN_ONAP, "guard.target:timestart");
+ public static final Identifier ID_RESOURCE_GUARD_TIMEEND =
+ new IdentifierImpl(ID_URN_ONAP, "guard.target:timeend");
/*
* This id specifically for guard is provided by the
diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/ToscaPolicyTranslatorUtils.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/ToscaPolicyTranslatorUtils.java
index cdf5404b..f1d3d5e3 100644
--- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/ToscaPolicyTranslatorUtils.java
+++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/ToscaPolicyTranslatorUtils.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 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.
@@ -23,10 +23,14 @@
package org.onap.policy.pdp.xacml.application.common;
import com.att.research.xacml.api.Identifier;
+import com.att.research.xacml.api.XACML3;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType;
+import oasis.names.tc.xacml._3_0.core.schema.wd_17.ApplyType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType;
+import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObjectFactory;
+import org.apache.commons.lang3.StringUtils;
/**
* This class contains static methods of helper classes to convert TOSCA policies
@@ -36,6 +40,7 @@ import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType;
*
*/
public final class ToscaPolicyTranslatorUtils {
+ private static final ObjectFactory factory = new ObjectFactory();
private ToscaPolicyTranslatorUtils() {
super();
@@ -99,4 +104,66 @@ public final class ToscaPolicyTranslatorUtils {
}
return allOf;
}
+
+ /**
+ * Takes start and end time interval and generates an ApplyType for it.
+ *
+ * @param start ISO8601 timestamp
+ * @param end ISO8601 timestamp
+ * @return ApplyType
+ */
+ public static ApplyType generateTimeInRange(String start, String end) {
+ if (StringUtils.isBlank(start) || StringUtils.isBlank(end)) {
+ return null;
+ }
+
+ AttributeDesignatorType designator = new AttributeDesignatorType();
+ designator.setAttributeId(XACML3.ID_ENVIRONMENT_CURRENT_TIME.stringValue());
+ designator.setCategory(XACML3.ID_ATTRIBUTE_CATEGORY_ENVIRONMENT.stringValue());
+ designator.setDataType(XACML3.ID_DATATYPE_TIME.stringValue());
+
+ AttributeValueType valueStart = new AttributeValueType();
+ valueStart.setDataType(XACML3.ID_DATATYPE_TIME.stringValue());
+ valueStart.getContent().add(start);
+
+ AttributeValueType valueEnd = new AttributeValueType();
+ valueEnd.setDataType(XACML3.ID_DATATYPE_TIME.stringValue());
+ valueEnd.getContent().add(end);
+
+
+ ApplyType applyOneAndOnly = new ApplyType();
+ applyOneAndOnly.setDescription("Unbag the current time");
+ applyOneAndOnly.setFunctionId(XACML3.ID_FUNCTION_TIME_ONE_AND_ONLY.stringValue());
+ applyOneAndOnly.getExpression().add(factory.createAttributeDesignator(designator));
+
+ ApplyType applyTimeInRange = new ApplyType();
+ applyTimeInRange.setDescription("return true if current time is in range.");
+ applyTimeInRange.setFunctionId(XACML3.ID_FUNCTION_TIME_IN_RANGE.stringValue());
+ applyTimeInRange.getExpression().add(factory.createApply(applyOneAndOnly));
+ applyTimeInRange.getExpression().add(factory.createAttributeValue(valueStart));
+ applyTimeInRange.getExpression().add(factory.createAttributeValue(valueEnd));
+
+ return applyTimeInRange;
+ }
+
+ /**
+ * Parses an integer value from the string.
+ *
+ * @param strInteger String representation of integer
+ * @return Integer object
+ */
+ public static Integer parseInteger(String strInteger) {
+ Integer theInt = null;
+ try {
+ theInt = Integer.parseInt(strInteger);
+ } catch (NumberFormatException e) {
+ try {
+ Double dblLimit = Double.parseDouble(strInteger);
+ theInt = dblLimit.intValue();
+ } catch (NumberFormatException e1) {
+ return null;
+ }
+ }
+ return theInt;
+ }
}
diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/operationshistory/GetOperationOutcomePip.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/operationshistory/GetOperationOutcomePip.java
index f2339b11..56d68d55 100644
--- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/operationshistory/GetOperationOutcomePip.java
+++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/operationshistory/GetOperationOutcomePip.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 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.
@@ -32,7 +32,7 @@ import java.util.Arrays;
import java.util.Base64;
import java.util.Collection;
import java.util.Properties;
-
+import javax.persistence.NoResultException;
import javax.persistence.Persistence;
import org.onap.policy.pdp.xacml.application.common.ToscaDictionary;
@@ -101,14 +101,14 @@ public class GetOperationOutcomePip extends StdOnapPip {
// Determine if the issuer is correct
//
if (Strings.isNullOrEmpty(pipRequest.getIssuer())) {
- logger.debug("issuer is null - returning empty response");
+ logger.error("issuer is null - returning empty response");
//
// We only respond to ourself as the issuer
//
return StdPIPResponse.PIP_RESPONSE_EMPTY;
}
if (! pipRequest.getIssuer().startsWith(ToscaDictionary.GUARD_ISSUER_PREFIX)) {
- logger.debug("Issuer does not start with guard");
+ logger.error("Issuer does not start with guard");
//
// We only respond to ourself as the issuer
//
@@ -161,9 +161,11 @@ public class GetOperationOutcomePip extends StdOnapPip {
.setParameter(2, target)
.setMaxResults(1)
.getSingleResult();
+ } catch (NoResultException e) {
+ logger.trace("No results", e);
} catch (Exception e) {
- logger.error("Typed query failed ", e);
- return null;
+ logger.error("Typed query failed", e);
}
+ return null;
}
}