Search in sources :

Example 1 with AttributeAssignment

use of org.wso2.balana.ctx.AttributeAssignment in project carbon-identity-framework by wso2.

the class JSONResponseWriter method attributeAssignmentToJsonObject.

/**
 * Private method to convert a given Balana <code>{@link AttributeAssignment}</code> to <code>{@link JsonObject}</code>
 *
 * @param attributeAssignment <code>{@link AttributeAssignment}</code>
 * @return <code>{@link JsonObject}</code>
 */
private static JsonObject attributeAssignmentToJsonObject(AttributeAssignment attributeAssignment) {
    JsonObject jsonObjectAttribute = new JsonObject();
    jsonObjectAttribute.addProperty(EntitlementEndpointConstants.ATTRIBUTE_ID, attributeAssignment.getAttributeId().toString());
    /*As per the xacml 3.0 core spec(section 5.41), Category and Issuer are optional categories for
        Element <AttributeAssignmentExpression>*/
    if (attributeAssignment.getIssuer() != null) {
        jsonObjectAttribute.addProperty(EntitlementEndpointConstants.ATTRIBUTE_ISSUER, attributeAssignment.getIssuer().toString());
    }
    if (attributeAssignment.getCategory() != null) {
        jsonObjectAttribute.addProperty(EntitlementEndpointConstants.CATEGORY_DEFAULT, attributeAssignment.getCategory().toString());
    }
    // try to get the attribute value and type by using json
    try {
        JsonObject attributeValue = gson.fromJson(gson.toJson(attributeAssignment), JsonObject.class);
        /*As per the xacml 3.0 core spec(section 7.3.1), data-type is a required attribute and content is optional
            for Element <AttributeValue>*/
        if (attributeValue.get("content") != null) {
            jsonObjectAttribute.addProperty(EntitlementEndpointConstants.ATTRIBUTE_VALUE, attributeValue.get("content").getAsString());
        }
        if (xacmlJSONProfileShortFormEnable) {
            jsonObjectAttribute.addProperty(EntitlementEndpointConstants.ATTRIBUTE_DATA_TYPE, uriToShortenForm(attributeValue.get("type").getAsString()));
        } else {
            jsonObjectAttribute.addProperty(EntitlementEndpointConstants.ATTRIBUTE_DATA_TYPE, attributeValue.get("type").getAsString());
        }
    } catch (Exception e) {
        return null;
    }
    return jsonObjectAttribute;
}
Also used : JsonObject(com.google.gson.JsonObject) ResponseWriteException(org.wso2.carbon.identity.entitlement.endpoint.exception.ResponseWriteException)

Example 2 with AttributeAssignment

use of org.wso2.balana.ctx.AttributeAssignment in project carbon-identity-framework by wso2.

the class TestJSONResponseWriter method testWriteWithObligations.

@Test
public void testWriteWithObligations() throws URISyntaxException {
    List<AttributeAssignment> assignments = new ArrayList<>();
    String content = "Error: Channel request is not WEB.";
    URI type = new URI("http://www.w3.org/2001/XMLSchema#string");
    URI attributeId = new URI("urn:oasis:names:tc:xacml:3.0:example:attribute:text");
    AttributeAssignment attributeAssignment = new AttributeAssignment(attributeId, type, null, content, null);
    assignments.add(attributeAssignment);
    List<ObligationResult> obligationResults = new ArrayList<>();
    ObligationResult obligationResult = new Obligation(assignments, new URI("channel_ko"));
    obligationResults.add(obligationResult);
    List<String> codes = new ArrayList<>();
    codes.add("urn:oasis:names:tc:xacml:1.0:status:ok");
    AbstractResult abstractResult = new Result(1, new Status(codes), obligationResults, null, null);
    ResponseCtx responseCtx = new ResponseCtx(abstractResult);
    JSONResponseWriter jsonResponseWriter = new JSONResponseWriter();
    try {
        JsonObject jsonObject = jsonResponseWriter.write(responseCtx);
        assertNotNull("Failed to build the XACML json response", jsonObject.toString());
        assertFalse("Failed to build the XACML json response", jsonObject.entrySet().isEmpty());
        for (Map.Entry<String, JsonElement> jsonElementEntry : jsonObject.entrySet()) {
            if (jsonElementEntry.getKey().equals("Response")) {
                JsonArray jsonArray = (JsonArray) jsonElementEntry.getValue();
                assertEquals("Failed to build the XACML json response with correct evaluation", jsonArray.get(0).getAsJsonObject().get("Decision").getAsString(), "Deny");
            }
        }
    } catch (ResponseWriteException e) {
        assertNull("Failed to build the XACML response", e);
    }
}
Also used : AttributeAssignment(org.wso2.balana.ctx.AttributeAssignment) Status(org.wso2.balana.ctx.Status) Obligation(org.wso2.balana.xacml3.Obligation) ResponseWriteException(org.wso2.carbon.identity.entitlement.endpoint.exception.ResponseWriteException) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) URI(java.net.URI) ResponseCtx(org.wso2.balana.ctx.ResponseCtx) AbstractResult(org.wso2.balana.ctx.AbstractResult) ObligationResult(org.wso2.balana.ObligationResult) Result(org.wso2.balana.ctx.xacml3.Result) JsonArray(com.google.gson.JsonArray) ObligationResult(org.wso2.balana.ObligationResult) JsonElement(com.google.gson.JsonElement) AbstractResult(org.wso2.balana.ctx.AbstractResult) Map(java.util.Map) Test(org.testng.annotations.Test)

Example 3 with AttributeAssignment

use of org.wso2.balana.ctx.AttributeAssignment in project carbon-identity-framework by wso2.

the class JSONResponseWriter method obligationToJsonObject.

/**
 * Private method to convert Balana <code>{@link Obligation}</code> to <code>{@link JsonObject}</code>
 *
 * @param obligation <code>{@link Obligation}</code>
 * @return <code>{@link JsonObject}</code>
 */
private static JsonObject obligationToJsonObject(Obligation obligation) {
    JsonObject jsonObligation = new JsonObject();
    jsonObligation.addProperty(EntitlementEndpointConstants.OBLIGATION_OR_ADVICE_ID, obligation.getObligationId().toString());
    JsonArray attributeAssignments = new JsonArray();
    for (AttributeAssignment aa : obligation.getAssignments()) {
        attributeAssignments.add(attributeAssignmentToJsonObject(aa));
    }
    jsonObligation.add(EntitlementEndpointConstants.ATTRIBUTE_ASSIGNMENTS, attributeAssignments);
    return jsonObligation;
}
Also used : JsonArray(com.google.gson.JsonArray) AttributeAssignment(org.wso2.balana.ctx.AttributeAssignment) JsonObject(com.google.gson.JsonObject)

Example 4 with AttributeAssignment

use of org.wso2.balana.ctx.AttributeAssignment in project carbon-identity-framework by wso2.

the class JSONResponseWriter method adviceToJsonObject.

/**
 * Private method to convert Balana <code>{@link Advice}</code> to <code>{@link JsonObject}</code>
 *
 * @param advice <code>{@link Advice}</code>
 * @return <code>{@link JsonObject}</code>
 */
private static JsonObject adviceToJsonObject(Advice advice) {
    JsonObject jsonAdvice = new JsonObject();
    jsonAdvice.addProperty(EntitlementEndpointConstants.OBLIGATION_OR_ADVICE_ID, advice.getAdviceId().toString());
    JsonArray attributeAssignments = new JsonArray();
    for (AttributeAssignment aa : advice.getAssignments()) {
        attributeAssignments.add(attributeAssignmentToJsonObject(aa));
    }
    jsonAdvice.add(EntitlementEndpointConstants.ATTRIBUTE_ASSIGNMENTS, attributeAssignments);
    return jsonAdvice;
}
Also used : JsonArray(com.google.gson.JsonArray) AttributeAssignment(org.wso2.balana.ctx.AttributeAssignment) JsonObject(com.google.gson.JsonObject)

Example 5 with AttributeAssignment

use of org.wso2.balana.ctx.AttributeAssignment in project carbon-identity-framework by wso2.

the class PolicyCreatorUtil method createRequestElementDTO.

// 
// /**
// * This method creates a policy element of the XACML policy
// * @param policyElementDTO  policy element data object
// * @param doc XML document
// * @return policyElement
// */
// 
// public static Element createPolicyElement(PolicyElementDTO policyElementDTO, Document doc)  {
// 
// Element policyElement = doc.createElement(EntitlementPolicyConstants.POLICY_ELEMENT);
// 
// policyElement.setAttribute("xmlns", EntitlementPolicyConstants.XACML3_POLICY_NAMESPACE);
// 
// if(policyElementDTO.getPolicyName() != null && policyElementDTO.getPolicyName().trim().length() > 0) {
// policyElement.setAttribute(EntitlementPolicyConstants.POLICY_ID, policyElementDTO.
// getPolicyName());
// } else {
// return null;
// }
// 
// if(policyElementDTO.getRuleCombiningAlgorithms() != null && policyElementDTO.
// getRuleCombiningAlgorithms().trim().length() > 0) {
// if(PolicyEditorConstants.CombiningAlog.FIRST_APPLICABLE_ID.equals(policyElementDTO.
// getRuleCombiningAlgorithms().trim())){
// policyElement.setAttribute(EntitlementPolicyConstants.RULE_ALGORITHM,
// PolicyEditorConstants.RULE_ALGORITHM_IDENTIFIER_1 + policyElementDTO.
// getRuleCombiningAlgorithms());
// } else {
// policyElement.setAttribute(EntitlementPolicyConstants.RULE_ALGORITHM,
// PolicyEditorConstants.RULE_ALGORITHM_IDENTIFIER_3 + policyElementDTO.
// getRuleCombiningAlgorithms());
// }
// } else {
// return null;
// }
// 
// if(policyElementDTO.getVersion() != null && policyElementDTO.getVersion().trim().length() > 0){
// policyElement.setAttribute(EntitlementPolicyConstants.POLICY_VERSION,
// policyElementDTO.getVersion());
// } else {
// // policy version is handled by wso2 registry.  therefore we can ignore it, although it
// // is a required attribute
// policyElement.setAttribute(EntitlementPolicyConstants.POLICY_VERSION, "1.0");
// }
// 
// if(policyElementDTO.getPolicyDescription() != null && policyElementDTO.
// getPolicyDescription().trim().length() > 0) {
// 
// Element descriptionElement = doc.createElement(EntitlementPolicyConstants.
// DESCRIPTION_ELEMENT);
// descriptionElement.setTextContent(policyElementDTO.getPolicyDescription());
// policyElement.appendChild(descriptionElement);
// }
// 
// return policyElement;
// }
// 
// ////XACML3
// 
// /**
// * This method creates a match element (subject,action,resource or environment) of the XACML policy
// * @param matchElementDTO match element data object
// * @param doc XML document
// * @return match Element
// */
// public static Element createMatchElement(MatchElementDTO matchElementDTO, Document doc)  {
// 
// Element matchElement = null;
// if(matchElementDTO.getMatchId() != null && matchElementDTO.getMatchId().trim().length() > 0) {
// 
// matchElement = doc.createElement(EntitlementPolicyConstants.MATCH_ELEMENT);
// 
// matchElement.setAttribute(EntitlementPolicyConstants.MATCH_ID,
// matchElementDTO.getMatchId());
// 
// if(matchElementDTO.getAttributeValueElementDTO() != null) {
// Element attributeValueElement = createAttributeValueElement(matchElementDTO.
// getAttributeValueElementDTO(), doc);
// matchElement.appendChild(attributeValueElement);
// }
// 
// if(matchElementDTO.getAttributeDesignatorDTO() != null ) {
// Element attributeDesignatorElement = createAttributeDesignatorElement(matchElementDTO.
// getAttributeDesignatorDTO(), doc);
// matchElement.appendChild(attributeDesignatorElement);
// }
// 
// if(matchElementDTO.getAttributeSelectorDTO() != null ) {
// Element attributeSelectorElement = createAttributeSelectorElement(matchElementDTO.
// getAttributeSelectorDTO(), doc);
// matchElement.appendChild(attributeSelectorElement);
// }
// }
// return matchElement;
// }
// 
// /**
// * This method creates the attribute value element
// * @param attributeValueElementDTO attribute value element data object
// * @param doc XML document
// * @return attribute value element
// */
// public static Element createAttributeValueElement(AttributeValueElementDTO
// attributeValueElementDTO, Document doc) {
// 
// Element attributeValueElement = doc.createElement(EntitlementPolicyConstants.ATTRIBUTE_VALUE);
// 
// if(attributeValueElementDTO.getAttributeValue() != null && attributeValueElementDTO.
// getAttributeValue().trim().length() > 0) {
// 
// attributeValueElement.setTextContent(attributeValueElementDTO.getAttributeValue().trim());
// 
// if(attributeValueElementDTO.getAttributeDataType()!= null && attributeValueElementDTO.
// getAttributeDataType().trim().length() > 0){
// attributeValueElement.setAttribute(EntitlementPolicyConstants.DATA_TYPE,
// attributeValueElementDTO.getAttributeDataType());
// } else {
// attributeValueElement.setAttribute(EntitlementPolicyConstants.DATA_TYPE,
// EntitlementPolicyConstants.STRING_DATA_TYPE);
// }
// 
// }
// 
// return attributeValueElement;
// 
// }
// 
// /**
// * This creates XML representation of Attributes Element using AttributesElementDTO object
// *
// * @param elementDTO  AttributesElementDTO
// * @param doc Document
// * @return DOM element
// */
// public static Element createAttributesElement(AttributesElementDTO elementDTO, Document doc){
// 
// Element attributesElement = doc.createElement(EntitlementPolicyConstants.ATTRIBUTES);
// 
// attributesElement.setAttribute(EntitlementPolicyConstants.CATEGORY, elementDTO.getCategory());
// 
// List<AttributeElementDTO> attributeElementDTOs = elementDTO.getAttributeElementDTOs();
// if(attributeElementDTOs != null && attributeElementDTOs.size() > 0){
// for(AttributeElementDTO attributeElementDTO : attributeElementDTOs){
// Element attributeElement = doc.createElement(EntitlementPolicyConstants.ATTRIBUTE);
// attributeElement.setAttribute(EntitlementPolicyConstants.ATTRIBUTE_ID,
// attributeElementDTO.getAttributeId());
// attributeElement.setAttribute(EntitlementPolicyConstants.INCLUDE_RESULT,
// Boolean.toString(attributeElementDTO.isIncludeInResult()));
// 
// if(attributeElementDTO.getIssuer() != null &&
// attributeElementDTO.getIssuer().trim().length() > 0){
// attributeElement.setAttribute(EntitlementPolicyConstants.ISSUER,
// attributeElementDTO.getIssuer());
// }
// 
// List<String> values = attributeElementDTO.getAttributeValues();
// for(String value : values){
// Element attributeValueElement = doc.createElement(EntitlementPolicyConstants.
// ATTRIBUTE_VALUE);
// attributeValueElement.setAttribute(EntitlementPolicyConstants.DATA_TYPE,
// attributeElementDTO.getDataType());
// attributeValueElement.setTextContent(value.trim());
// attributeElement.appendChild(attributeValueElement);
// }
// attributesElement.appendChild(attributeElement);
// }
// }
// return attributesElement;
// }
// 
// 
// public static Element createFunctionElement(FunctionDTO functionDTO, Document doc) {
// 
// Element functionElement = doc.createElement(EntitlementPolicyConstants.FUNCTION);
// 
// if(functionDTO.getFunctionId() != null && functionDTO.getFunctionId().trim().length() > 0) {
// functionElement.setAttribute(EntitlementPolicyConstants.FUNCTION_ID,
// functionDTO.getFunctionId());
// }
// 
// return functionElement;
// }
// 
// //    public static Element createAttributeDesignatorElement(AttributeDesignatorDTO
// //            attributeDesignatorDTO, Document doc) {
// //
// //        String attributeDesignatorElementName =  attributeDesignatorDTO.getElementName() +
// //                EntitlementPolicyConstants.ATTRIBUTE_DESIGNATOR;
// //
// //        Element attributeDesignatorElement = doc.createElement(attributeDesignatorElementName);
// //
// //        if(attributeDesignatorDTO.getAttributeId() != null && attributeDesignatorDTO.
// //                getAttributeId().trim().length() > 0 ){
// //
// //            attributeDesignatorElement.setAttribute(EntitlementPolicyConstants.ATTRIBUTE_ID,
// //                    attributeDesignatorDTO.getAttributeId());
// //
// //            if(attributeDesignatorDTO.getDataType() != null && attributeDesignatorDTO.
// //                    getDataType().trim().length() > 0) {
// //                attributeDesignatorElement.setAttribute(EntitlementPolicyConstants.DATA_TYPE,
// //                        attributeDesignatorDTO.getDataType());
// //            } else {
// //                attributeDesignatorElement.setAttribute(EntitlementPolicyConstants.DATA_TYPE,
// //                        EntitlementPolicyConstants.STRING_DATA_TYPE);
// //            }
// //
// //            if(attributeDesignatorDTO.getIssuer() != null && attributeDesignatorDTO.getIssuer().
// //                    trim().length() > 0) {
// //                attributeDesignatorElement.setAttribute(EntitlementPolicyConstants.ISSUER,
// //                        attributeDesignatorDTO.getIssuer());
// //            }
// //
// //            if(attributeDesignatorDTO.getMustBePresent() != null && attributeDesignatorDTO.
// //                    getMustBePresent().trim().length() > 0){
// //                attributeDesignatorElement.setAttribute(EntitlementPolicyConstants.MUST_BE_PRESENT,
// //                        attributeDesignatorDTO.getMustBePresent());
// //            }
// //
// //            if(attributeDesignatorDTO.getSubjectCategory() != null){
// //                attributeDesignatorElement.setAttribute(EntitlementPolicyConstants.MUST_BE_PRESENT,
// //                        attributeDesignatorDTO.getSubjectCategory());
// //            }
// //
// //        }
// //
// //        return attributeDesignatorElement;
// //    }
// 
// 
// public static Element createAttributeDesignatorElement(AttributeDesignatorDTO
// attributeDesignatorDTO, Document doc) {
// 
// String attributeDesignatorElementName =
// EntitlementPolicyConstants.ATTRIBUTE_DESIGNATOR;
// 
// Element attributeDesignatorElement = doc.createElement(attributeDesignatorElementName);
// 
// String attributeId = attributeDesignatorDTO.getAttributeId();
// String category = attributeDesignatorDTO.getCategory();
// 
// if(attributeId != null && attributeId.trim().length() > 0 && category != null &&
// category.trim().length() > 0){
// 
// attributeDesignatorElement.setAttribute(EntitlementPolicyConstants.ATTRIBUTE_ID,
// attributeDesignatorDTO.getAttributeId());
// 
// attributeDesignatorElement.setAttribute(EntitlementPolicyConstants.CATEGORY,
// attributeDesignatorDTO.getCategory());
// 
// if(attributeDesignatorDTO.getDataType() != null && attributeDesignatorDTO.
// getDataType().trim().length() > 0) {
// attributeDesignatorElement.setAttribute(EntitlementPolicyConstants.DATA_TYPE,
// attributeDesignatorDTO.getDataType());
// } else {
// attributeDesignatorElement.setAttribute(EntitlementPolicyConstants.DATA_TYPE,
// EntitlementPolicyConstants.STRING_DATA_TYPE);
// }
// 
// if(attributeDesignatorDTO.getIssuer() != null && attributeDesignatorDTO.getIssuer().
// trim().length() > 0) {
// attributeDesignatorElement.setAttribute(EntitlementPolicyConstants.ISSUER,
// attributeDesignatorDTO.getIssuer());
// }
// 
// if(attributeDesignatorDTO.getMustBePresent() != null && attributeDesignatorDTO.
// getMustBePresent().trim().length() > 0){
// attributeDesignatorElement.setAttribute(EntitlementPolicyConstants.MUST_BE_PRESENT,
// attributeDesignatorDTO.getMustBePresent());
// } else {
// attributeDesignatorElement.setAttribute(EntitlementPolicyConstants.MUST_BE_PRESENT,
// "true");
// }
// 
// }
// 
// return attributeDesignatorElement;
// }
// 
// 
// public static Element createAttributeSelectorElement(AttributeSelectorDTO attributeSelectorDTO,
// Document doc)  {
// 
// Element attributeSelectorElement = doc.createElement(EntitlementPolicyConstants.
// ATTRIBUTE_SELECTOR);
// 
// if(attributeSelectorDTO.getAttributeSelectorRequestContextPath() != null &&
// attributeSelectorDTO.getAttributeSelectorRequestContextPath().trim().length() > 0) {
// 
// attributeSelectorElement.setAttribute(EntitlementPolicyConstants.REQUEST_CONTEXT_PATH,
// EntitlementPolicyConstants.ATTRIBUTE_NAMESPACE + attributeSelectorDTO.
// getAttributeSelectorRequestContextPath());
// 
// if(attributeSelectorDTO.getAttributeSelectorDataType() != null &&
// attributeSelectorDTO.getAttributeSelectorDataType().trim().length() > 0) {
// attributeSelectorElement.setAttribute(EntitlementPolicyConstants.DATA_TYPE,
// attributeSelectorDTO.getAttributeSelectorDataType());
// } else {
// attributeSelectorElement.setAttribute(EntitlementPolicyConstants.DATA_TYPE,
// EntitlementPolicyConstants.STRING_DATA_TYPE);
// }
// 
// if(attributeSelectorDTO.getAttributeSelectorMustBePresent() != null &&
// attributeSelectorDTO.getAttributeSelectorMustBePresent().trim().length() > 0) {
// attributeSelectorElement.setAttribute(EntitlementPolicyConstants.MUST_BE_PRESENT,
// attributeSelectorDTO.getAttributeSelectorMustBePresent());
// }
// 
// }
// 
// return attributeSelectorElement;
// }
// 
// public static Element createObligationsElement(List<ObligationElementDTO> obligationElementDTOs,
// Document doc){
// 
// 
// Element obligationExpressions = null;
// Element adviceExpressions = null;
// 
// if(obligationElementDTOs != null && obligationElementDTOs.size() > 0){
// 
// for(ObligationElementDTO dto : obligationElementDTOs){
// String id = dto.getId();
// String effect = dto.getEffect();
// 
// if(id != null && id.trim().length() > 0 && effect != null){
// if(dto.getType() == ObligationElementDTO.ADVICE){
// if(adviceExpressions == null){
// adviceExpressions = doc.
// createElement(EntitlementPolicyConstants.ADVICE_EXPRESSIONS);
// }
// 
// Element adviceExpression = doc.
// createElement(EntitlementPolicyConstants.ADVICE_EXPRESSION);
// adviceExpression.setAttribute(EntitlementPolicyConstants.ADVICE_ID, id);
// adviceExpression.setAttribute(EntitlementPolicyConstants.ADVICE_EFFECT, effect);
// List<AttributeAssignmentElementDTO> elementDTOs = dto.getAssignmentElementDTOs();
// if(elementDTOs != null){
// for(AttributeAssignmentElementDTO elementDTO : elementDTOs){
// Element element = createAttributeAssignmentElement(elementDTO, doc);
// if(element != null){
// adviceExpression.appendChild(element);
// }
// }
// }
// adviceExpressions.appendChild(adviceExpression);
// } else {
// 
// if(obligationExpressions == null){
// obligationExpressions = doc.
// createElement(EntitlementPolicyConstants.OBLIGATION_EXPRESSIONS);
// }
// 
// Element obligationExpression = doc.
// createElement(EntitlementPolicyConstants.OBLIGATION_EXPRESSION);
// obligationExpression.setAttribute(EntitlementPolicyConstants.OBLIGATION_ID, id);
// obligationExpression.setAttribute(EntitlementPolicyConstants.OBLIGATION_EFFECT,
// effect);
// List<AttributeAssignmentElementDTO> elementDTOs = dto.getAssignmentElementDTOs();
// if(elementDTOs != null){
// for(AttributeAssignmentElementDTO elementDTO : elementDTOs){
// Element element = createAttributeAssignmentElement(elementDTO, doc);
// if(element != null){
// obligationExpression.appendChild(element);
// }
// }
// }
// obligationExpressions.appendChild(obligationExpression);
// }
// }
// }
// }
// 
// if(adviceExpressions != null){
// return adviceExpressions;
// }
// 
// return obligationExpressions;
// }
// 
// public static Element createAttributeAssignmentElement(AttributeAssignmentElementDTO assignmentElementDTO,
// Document doc){
// 
// String attributeId = assignmentElementDTO.getAttributeId();
// 
// if(attributeId != null && attributeId.trim().length() > 0){
// 
// String category = assignmentElementDTO.getCategory();
// String issuer = assignmentElementDTO.getIssuer();
// ApplyElementDTO applyElementDTO = assignmentElementDTO.getApplyElementDTO();
// AttributeDesignatorDTO designatorDTO = assignmentElementDTO.getDesignatorDTO();
// AttributeValueElementDTO valueElementDTO = assignmentElementDTO.getValueElementDTO();
// 
// Element attributeAssignment = doc.
// createElement(EntitlementPolicyConstants.ATTRIBUTE_ASSIGNMENT);
// attributeAssignment.setAttribute(EntitlementPolicyConstants.ATTRIBUTE_ID,
// attributeId);
// if(category != null && category.trim().length() > 0){
// attributeAssignment.setAttribute(EntitlementPolicyConstants.CATEGORY, category);
// }
// 
// if(issuer != null && issuer.trim().length() > 0){
// attributeAssignment.setAttribute(EntitlementPolicyConstants.ISSUER, issuer);
// }
// 
// if(applyElementDTO != null){
// attributeAssignment.appendChild(createApplyElement(applyElementDTO, doc));
// }
// 
// if(designatorDTO != null){
// attributeAssignment.appendChild(createAttributeDesignatorElement(designatorDTO, doc));
// }
// 
// if(valueElementDTO != null){
// attributeAssignment.appendChild(createAttributeValueElement(valueElementDTO, doc));
// }
// 
// return attributeAssignment;
// }
// 
// return null;
// }
// 
// public static Element createSubElement(SubElementDTO subElementDTO, Document doc) {
// 
// String subElementName = subElementDTO.getElementName();
// 
// Element subElement = doc.createElement(subElementName);
// 
// for( MatchElementDTO matchElementDTO : subElementDTO.getMatchElementDTOs()) {
// Element matchElement = createMatchElement(matchElementDTO, doc);
// if(matchElement != null) {
// subElement.appendChild(matchElement);
// }
// }
// 
// return subElement;
// }
// 
// public static Element createTargetElement(List<SubElementDTO> subElementDTOs, Document doc) {
// 
// Element targetElement = doc.createElement(EntitlementPolicyConstants.TARGET_ELEMENT);
// String subjectElementName = EntitlementPolicyConstants.SUBJECT_ELEMENT + "s";
// String actionElementName = EntitlementPolicyConstants.ACTION_ELEMENT + "s";
// String resourceElementName = EntitlementPolicyConstants.RESOURCE_ELEMENT + "s";
// String enviornementElementName = EntitlementPolicyConstants.ENVIRONMENT_ELEMENT + "s";
// 
// Element subjectElement = doc.createElement(subjectElementName);
// Element actionElement = doc.createElement(actionElementName);
// Element resourceElement = doc.createElement(resourceElementName);
// Element enviornementElement = doc.createElement(enviornementElementName);
// 
// 
// for(SubElementDTO subElementDTO : subElementDTOs) {
// 
// if(subElementDTO.getElementName().equals(EntitlementPolicyConstants.SUBJECT_ELEMENT)) {
// Element subParentElement = createSubElement(subElementDTO, doc);
// subjectElement.appendChild(subParentElement);
// }
// 
// if(subElementDTO.getElementName().equals(EntitlementPolicyConstants.ACTION_ELEMENT)) {
// Element subParentElement = createSubElement(subElementDTO, doc);
// actionElement.appendChild(subParentElement);
// }
// 
// if(subElementDTO.getElementName().equals(EntitlementPolicyConstants.RESOURCE_ELEMENT)) {
// Element subParentElement = createSubElement(subElementDTO, doc);
// resourceElement.appendChild(subParentElement);
// }
// 
// if(subElementDTO.getElementName().equals(EntitlementPolicyConstants.ENVIRONMENT_ELEMENT)) {
// Element subParentElement = createSubElement(subElementDTO, doc);
// enviornementElement.appendChild(subParentElement);
// }
// }
// 
// targetElement.appendChild(subjectElement);
// targetElement.appendChild(actionElement);
// targetElement.appendChild(resourceElement);
// targetElement.appendChild(enviornementElement);
// 
// return targetElement;
// }
// 
// 
// public static Element createRuleElement(RuleElementDTO ruleElementDTO, Document doc) {
// 
// TargetElementDTO targetElementDTO = ruleElementDTO.getTargetElementDTO();
// ConditionElementDT0 conditionElementDT0 = ruleElementDTO.getConditionElementDT0();
// List<ObligationElementDTO> obligationElementDTOs = ruleElementDTO.getObligationElementDTOs();
// 
// Element ruleElement = doc.createElement(EntitlementPolicyConstants.RULE_ELEMENT);
// 
// if(ruleElementDTO.getRuleId() != null && ruleElementDTO.getRuleId().trim().length() > 0){
// ruleElement.setAttribute(EntitlementPolicyConstants.RULE_ID, ruleElementDTO.getRuleId());
// }
// 
// if(ruleElementDTO.getRuleEffect() != null && ruleElementDTO.getRuleEffect().trim().length() > 0){
// ruleElement.setAttribute(EntitlementPolicyConstants.RULE_EFFECT,
// ruleElementDTO.getRuleEffect());
// }
// 
// if(ruleElementDTO.getRuleDescription() != null && ruleElementDTO.getRuleDescription().
// trim().length() > 0){
// Element descriptionElement = doc.createElement(EntitlementPolicyConstants.
// DESCRIPTION_ELEMENT);
// descriptionElement.setTextContent(ruleElementDTO.getRuleDescription());
// ruleElement.appendChild(descriptionElement);
// }
// 
// if(targetElementDTO != null ){
// Element targetElement = PolicyEditorUtil.createTargetElement(targetElementDTO, doc);
// ruleElement.appendChild(targetElement);
// }
// 
// if(conditionElementDT0 != null){
// ruleElement.appendChild(createConditionElement(conditionElementDT0, doc));
// }
// 
// 
// if(obligationElementDTOs != null && obligationElementDTOs.size() > 0){
// List<ObligationElementDTO> obligations = new ArrayList<ObligationElementDTO>();
// List<ObligationElementDTO> advices = new ArrayList<ObligationElementDTO>();
// for(ObligationElementDTO obligationElementDTO : obligationElementDTOs){
// if(obligationElementDTO.getType() == ObligationElementDTO.ADVICE){
// advices.add(obligationElementDTO);
// } else {
// obligations.add(obligationElementDTO);
// }
// }
// Element obligation = createObligationsElement(obligations, doc);
// Element advice = createObligationsElement(advices, doc);
// if(obligation != null){
// ruleElement.appendChild(obligation);
// }
// if(advice != null){
// ruleElement.appendChild(advice);
// }
// }
// 
// return ruleElement;
// }
// 
// 
// public static Element createConditionElement(ConditionElementDT0 conditionElementDT0, Document doc) {
// 
// Element conditionElement = doc.createElement(EntitlementPolicyConstants.CONDITION_ELEMENT);
// 
// if(conditionElementDT0.getApplyElement() != null){
// conditionElement.appendChild(createApplyElement(conditionElementDT0.getApplyElement(), doc));
// 
// } else if(conditionElementDT0.getAttributeValueElementDTO() != null) {
// Element attributeValueElement = createAttributeValueElement(conditionElementDT0.
// getAttributeValueElementDTO(), doc);
// conditionElement.appendChild(attributeValueElement);
// 
// } else if(conditionElementDT0.getAttributeDesignator() != null) {
// AttributeDesignatorDTO attributeDesignatorDTO = conditionElementDT0.getAttributeDesignator();
// conditionElement.appendChild(createAttributeDesignatorElement(attributeDesignatorDTO, doc));
// 
// } else if(conditionElementDT0.getFunctionFunctionId() != null) {
// Element functionElement = doc.createElement(EntitlementPolicyConstants.FUNCTION_ELEMENT);
// functionElement.setAttribute(EntitlementPolicyConstants.FUNCTION_ID,
// conditionElementDT0.getFunctionFunctionId());
// conditionElement.appendChild(functionElement);
// } else if(conditionElementDT0.getVariableId() != null){
// Element variableReferenceElement = doc.createElement(EntitlementPolicyConstants.
// VARIABLE_REFERENCE);
// variableReferenceElement.setAttribute(EntitlementPolicyConstants.VARIABLE_ID,
// conditionElementDT0.getVariableId());
// conditionElement.appendChild(variableReferenceElement);
// }
// 
// return conditionElement;
// 
// }
// 
// public static Element createApplyElement(ApplyElementDTO applyElementDTO, Document doc) {
// 
// Element applyElement = doc.createElement(EntitlementPolicyConstants.APPLY_ELEMENT);
// 
// if(applyElementDTO.getFunctionId() != null && applyElementDTO.getFunctionId().trim().length() > 0){
// applyElement.setAttribute(EntitlementPolicyConstants.FUNCTION_ID,
// applyElementDTO.getFunctionId());
// }
// 
// if(applyElementDTO.getFunctionFunctionId() != null && applyElementDTO.
// getFunctionFunctionId().trim().length() > 0){
// FunctionDTO functionDTO = new FunctionDTO();
// functionDTO.setFunctionId(applyElementDTO.getFunctionFunctionId());
// Element functionElement = createFunctionElement(functionDTO, doc);
// applyElement.appendChild(functionElement);
// }
// 
// List<ApplyElementDTO> applyElementDTOs = applyElementDTO.getApplyElements();
// 
// if(applyElementDTOs != null && applyElementDTOs.size() > 0) {
// 
// for(ApplyElementDTO elementDTO : applyElementDTOs) {
// Element subApplyElement = createApplyElement(elementDTO, doc);
// applyElement.appendChild(subApplyElement);
// }
// }
// 
// List<AttributeValueElementDTO> attributeValueElementDTOs = applyElementDTO.
// getAttributeValueElementDTOs();
// if(attributeValueElementDTOs != null && attributeValueElementDTOs.size() > 0) {
// 
// for(AttributeValueElementDTO attributeValueElementDTO : attributeValueElementDTOs) {
// Element attributeValueElement = createAttributeValueElement(attributeValueElementDTO,
// doc);
// 
// applyElement.appendChild(attributeValueElement);
// }
// }
// 
// List<AttributeDesignatorDTO> attributeDesignatorDTOs = applyElementDTO.getAttributeDesignators();
// if(attributeDesignatorDTOs != null && attributeDesignatorDTOs.size() > 0) {
// 
// for(AttributeDesignatorDTO attributeDesignatorDTO : attributeDesignatorDTOs) {
// Element attributeDesignatorElement =
// createAttributeDesignatorElement(attributeDesignatorDTO, doc);
// applyElement.appendChild(attributeDesignatorElement);
// }
// }
// 
// List<AttributeSelectorDTO> attributeSelectorDTOs = applyElementDTO.getAttributeSelectors();
// if(attributeSelectorDTOs != null && attributeSelectorDTOs.size() > 0) {
// 
// for(AttributeSelectorDTO attributeSelectorDTO : attributeSelectorDTOs) {
// Element attributeSelectorElement = createAttributeSelectorElement(attributeSelectorDTO,
// doc);
// applyElement.appendChild(attributeSelectorElement);
// }
// }
// return applyElement;
// }
// 
// ///////
// public static ApplyElementDTO createApplyElementForBagFunctions(String functionId,
// String category,
// String attributeId,
// String[] attributeValues,
// String dataType){
// 
// ApplyElementDTO applyElementDTO = new ApplyElementDTO();
// 
// if(attributeValues != null && functionId != null && functionId.trim().length() > 0 &&
// category != null && category.trim().length() > 0 &&
// attributeId != null && attributeId.trim().length() > 0){
// 
// ApplyElementDTO applyElementDTOBag = new ApplyElementDTO();
// for(String attributeValue :attributeValues){
// attributeValue = attributeValue.trim();
// AttributeValueElementDTO attributeValueElementDTO = new AttributeValueElementDTO();
// if(dataType != null && dataType.trim().length() > 0){
// attributeValueElementDTO.setAttributeDataType(dataType);
// } else {
// attributeValueElementDTO.setAttributeDataType(EntitlementPolicyConstants.STRING_DATA_TYPE);
// }
// attributeValueElementDTO.setAttributeValue(attributeValue.trim());
// applyElementDTOBag.setAttributeValueElementDTO(attributeValueElementDTO);
// }
// 
// applyElementDTOBag.setFunctionId(EntitlementPolicyConstants.FUNCTION_BAG);
// 
// AttributeDesignatorDTO attributeDesignatorDTO = new AttributeDesignatorDTO();
// if(dataType != null && dataType.trim().length() > 0){
// attributeDesignatorDTO.setDataType(dataType);
// } else {
// attributeDesignatorDTO.setDataType(EntitlementPolicyConstants.STRING_DATA_TYPE);
// }
// attributeDesignatorDTO.setAttributeId(attributeId);
// attributeDesignatorDTO.setCategory(category);
// 
// applyElementDTO.setApplyElement(applyElementDTOBag);
// applyElementDTO.setAttributeDesignators(attributeDesignatorDTO);
// applyElementDTO.setFunctionId(functionId);
// 
// }
// 
// return applyElementDTO;
// }
// 
// public static ApplyElementDTO createApplyElementForNonBagFunctions(String functionId,
// String category,
// String attributeId,
// String attributeValue,
// String dataType){
// 
// ApplyElementDTO applyElementDTO = new ApplyElementDTO();
// 
// if(attributeValue != null && attributeValue.trim().length() > 0 && functionId != null &&
// functionId.trim().length() > 0 && category != null &&
// category.trim().length() > 0 && attributeId != null &&
// attributeId.trim().length() > 0) {
// 
// AttributeValueElementDTO attributeValueElementDTO = new AttributeValueElementDTO();
// if(dataType != null && dataType.trim().length() > 0){
// attributeValueElementDTO.setAttributeDataType(dataType);
// } else {
// attributeValueElementDTO.setAttributeDataType(EntitlementPolicyConstants.STRING_DATA_TYPE);
// }
// attributeValueElementDTO.setAttributeValue(attributeValue.trim());
// 
// AttributeDesignatorDTO attributeDesignatorDTO = new AttributeDesignatorDTO();
// if(dataType != null && dataType.trim().length() > 0){
// attributeDesignatorDTO.setDataType(dataType);
// } else {
// attributeDesignatorDTO.setDataType(EntitlementPolicyConstants.STRING_DATA_TYPE);
// }
// attributeDesignatorDTO.setAttributeId(attributeId);
// attributeDesignatorDTO.setCategory(category);
// 
// applyElementDTO.setAttributeValueElementDTO(attributeValueElementDTO);
// applyElementDTO.setAttributeDesignators(attributeDesignatorDTO);
// applyElementDTO.setFunctionId(functionId);
// 
// }
// 
// return applyElementDTO;
// }
// 
// public static ApplyElementDTO createApplyElementForNonBagFunctionsWithAnyOf(String functionId,
// String attributeDesignatorType,
// String attributeDesignatorId,
// String attributeValue){
// 
// ApplyElementDTO applyElementDTO = new ApplyElementDTO();
// 
// if(attributeValue != null && attributeValue.trim().length() > 0 && functionId != null &&
// functionId.trim().length() > 0 && attributeDesignatorType != null &&
// attributeDesignatorType.trim().length() > 0 && attributeDesignatorId != null &&
// attributeDesignatorId.trim().length() > 0) {
// 
// AttributeValueElementDTO attributeValueElementDTO = new AttributeValueElementDTO();
// attributeValueElementDTO.setAttributeDataType(EntitlementPolicyConstants.STRING_DATA_TYPE);
// attributeValueElementDTO.setAttributeValue(attributeValue.trim());
// 
// AttributeDesignatorDTO attributeDesignatorDTO = new AttributeDesignatorDTO();
// attributeDesignatorDTO.setDataType(EntitlementPolicyConstants.STRING_DATA_TYPE);
// attributeDesignatorDTO.setAttributeId(attributeDesignatorId);
// attributeDesignatorDTO.setCategory(attributeDesignatorType);
// 
// applyElementDTO.setFunctionFunctionId(functionId);
// applyElementDTO.setAttributeValueElementDTO(attributeValueElementDTO);
// applyElementDTO.setAttributeDesignators(attributeDesignatorDTO);
// applyElementDTO.setFunctionId(EntitlementPolicyConstants.FUNCTION_ANY_OF);
// 
// }
// 
// return applyElementDTO;
// }
// 
// 
// public static MatchElementDTO createMatchElementForNonBagFunctions(String functionId,
// String attributeValue,
// String category,
// String attributeId,
// String dataType) {
// MatchElementDTO matchElementDTO = new MatchElementDTO();
// 
// if(functionId != null && functionId.trim().length() > 0 && attributeValue != null &&
// attributeValue.trim().length() > 0&& category != null &&
// category.trim().length() > 0 && attributeId != null &&
// attributeId.trim().length() > 0) {
// AttributeValueElementDTO attributeValueElementDTO = new AttributeValueElementDTO();
// if(dataType != null && dataType.trim().length() > 0){
// attributeValueElementDTO.setAttributeDataType(dataType);
// } else {
// attributeValueElementDTO.setAttributeDataType(EntitlementPolicyConstants.STRING_DATA_TYPE);
// }
// attributeValueElementDTO.setAttributeValue(attributeValue.trim());
// 
// AttributeDesignatorDTO attributeDesignatorDTO = new AttributeDesignatorDTO();
// if(dataType != null && dataType.trim().length() > 0){
// attributeValueElementDTO.setAttributeDataType(dataType);
// } else {
// attributeValueElementDTO.setAttributeDataType(EntitlementPolicyConstants.STRING_DATA_TYPE);
// }
// attributeDesignatorDTO.setAttributeId(attributeId);
// attributeDesignatorDTO.setCategory(category);
// 
// matchElementDTO.setMatchId(functionId);
// matchElementDTO.setAttributeValueElementDTO(attributeValueElementDTO);
// matchElementDTO.setAttributeDesignatorDTO(attributeDesignatorDTO);
// }
// 
// return matchElementDTO;
// }
// 
// public static Element createBasicRuleElementDTO(BasicRuleDTO basicRuleDTO,
// Document doc) {
// 
// String functionOnResources =  basicRuleDTO.getFunctionOnResources();
// String functionOnSubjects = basicRuleDTO.getFunctionOnSubjects();
// String functionOnActions = basicRuleDTO.getFunctionOnActions();
// String functionOnEnvironment = basicRuleDTO.getFunctionOnEnvironment();
// String resourceNames = basicRuleDTO.getResourceList();
// String actionNames = basicRuleDTO.getActionList();
// String subjectNames = basicRuleDTO.getSubjectList();
// String environmentNames = basicRuleDTO.getEnvironmentList();
// String resourceId = basicRuleDTO.getResourceId();
// String subjectId = basicRuleDTO.getSubjectId();
// String actionId = basicRuleDTO.getActionId();
// String environmentId = basicRuleDTO.getEnvironmentId();
// String resourceDataType = basicRuleDTO.getResourceDataType();
// String subjectDataType = basicRuleDTO.getSubjectDataType();
// String actionDataType = basicRuleDTO.getActionDataType();
// String environmentDataType = basicRuleDTO.getEnvironmentDataType();
// 
// 
// Element resourcesElement = null;
// Element actionsElement = null;
// Element subjectsElement = null;
// Element environmentsElement = null;
// Element targetElement = null;
// Element applyElement = null;
// Element conditionElement = null;
// Element ruleElement =  null ;
// 
// ApplyElementDTO applyElementDTO = new ApplyElementDTO();
// 
// if(resourceNames != null  && resourceNames.trim().length() > 0) {
// String[] resources = resourceNames.split(EntitlementPolicyConstants.ATTRIBUTE_SEPARATOR);
// if(resourceId == null || resourceId.trim().length() < 1){
// resourceId = EntitlementPolicyConstants.RESOURCE_ID;
// }
// if(functionOnResources.equals(EntitlementPolicyConstants.EQUAL_TO) ||
// functionOnResources.equals(EntitlementPolicyConstants.REGEXP_MATCH) ) {
// resourcesElement = doc.createElement(PolicyEditorConstants.ANY_OF_ELEMENT);
// Element resourceElement = doc.createElement(PolicyEditorConstants.ALL_OF_ELEMENT);
// MatchElementDTO matchElementDTO = createMatchElementForNonBagFunctions(
// getFunctionId(functionOnResources),
// resources[0].trim(), PolicyEditorConstants.RESOURCE_CATEGORY_URI, resourceId, resourceDataType);
// Element matchElement= createMatchElement(matchElementDTO, doc);
// if(matchElement != null){
// resourceElement.appendChild(matchElement);
// }
// resourcesElement.appendChild(resourceElement);
// 
// } else if(functionOnResources.contains("less") || functionOnResources.contains("greater")){
// 
// AttributeDesignatorDTO designatorDTO = new AttributeDesignatorDTO();
// designatorDTO.setCategory(PolicyEditorConstants.RESOURCE_CATEGORY_URI);
// designatorDTO.setAttributeId(resourceId);
// designatorDTO.setDataType(resourceDataType);
// designatorDTO.setMustBePresent("true");
// try {
// ApplyElementDTO elementDTO = PolicyEditorUtil.
// processGreaterLessThanFunctions(functionOnResources, resourceDataType,
// resourceNames, designatorDTO);
// applyElementDTO.setApplyElement(elementDTO);
// } catch (PolicyEditorException e) {
// //ignore TODO
// }
// } else if(functionOnResources.equals(EntitlementPolicyConstants.IS_IN)) {
// ApplyElementDTO elementDTO = createApplyElementForNonBagFunctions(
// getFunctionId(functionOnResources),
// PolicyEditorConstants.RESOURCE_CATEGORY_URI, resourceId, resources[0].trim(), resourceDataType);
// applyElementDTO.setApplyElement(elementDTO);
// } else {
// ApplyElementDTO elementDTO = createApplyElementForBagFunctions(
// getFunctionId(functionOnResources),
// PolicyEditorConstants.RESOURCE_CATEGORY_URI, resourceId, resources, resourceDataType);
// applyElementDTO.setApplyElement(elementDTO);
// }
// }
// 
// if(actionNames != null  && actionNames.trim().length() > 0) {
// String[] actions = actionNames.split(EntitlementPolicyConstants.ATTRIBUTE_SEPARATOR);
// if(actionId == null || actionId.trim().length() < 1){
// actionId = EntitlementPolicyConstants.ACTION_ID;
// }
// if(functionOnActions.equals(EntitlementPolicyConstants.EQUAL_TO) ||
// functionOnActions.equals(EntitlementPolicyConstants.REGEXP_MATCH)) {
// actionsElement = doc.createElement(PolicyEditorConstants.ANY_OF_ELEMENT);
// Element actionElement = doc.createElement(PolicyEditorConstants.ALL_OF_ELEMENT);
// MatchElementDTO matchElementDTO = createMatchElementForNonBagFunctions(
// getFunctionId(functionOnActions),
// actions[0].trim(), PolicyEditorConstants.ACTION_CATEGORY_URI, actionId, actionDataType);
// Element matchElement= createMatchElement(matchElementDTO, doc);
// if(matchElement != null){
// actionElement.appendChild(matchElement);
// }
// actionsElement.appendChild(actionElement);
// } else if(functionOnActions.contains("less") || functionOnActions.contains("greater")){
// 
// AttributeDesignatorDTO designatorDTO = new AttributeDesignatorDTO();
// designatorDTO.setCategory(PolicyEditorConstants.ACTION_CATEGORY_URI);
// designatorDTO.setAttributeId(actionId);
// designatorDTO.setDataType(actionDataType);
// designatorDTO.setMustBePresent("true");
// try {
// ApplyElementDTO elementDTO = PolicyEditorUtil.
// processGreaterLessThanFunctions(functionOnActions, actionDataType,
// actionNames, designatorDTO);
// applyElementDTO.setApplyElement(elementDTO);
// } catch (PolicyEditorException e) {
// //ignore TODO
// }
// } else if(functionOnActions.equals(EntitlementPolicyConstants.IS_IN)) {
// ApplyElementDTO elementDTO = createApplyElementForNonBagFunctions(
// getFunctionId(functionOnActions),
// PolicyEditorConstants.ACTION_CATEGORY_URI, actionId, actions[0].trim(), actionDataType);
// applyElementDTO.setApplyElement(elementDTO);
// } else {
// ApplyElementDTO elementDTO = createApplyElementForBagFunctions(
// getFunctionId(functionOnActions),
// EntitlementPolicyConstants.ACTION_ELEMENT, actionId, actions, actionDataType);
// applyElementDTO.setApplyElement(elementDTO);
// }
// }
// 
// if(environmentNames != null  && environmentNames.trim().length() > 0) {
// String[] environments = environmentNames.split(EntitlementPolicyConstants.ATTRIBUTE_SEPARATOR);
// if(environmentId == null || environmentId.trim().length() < 1){
// environmentId = EntitlementPolicyConstants.ENVIRONMENT_ID;
// }
// if(functionOnEnvironment.equals(EntitlementPolicyConstants.EQUAL_TO) ||
// functionOnEnvironment.equals(EntitlementPolicyConstants.REGEXP_MATCH)) {
// environmentsElement = doc.createElement(PolicyEditorConstants.ANY_OF_ELEMENT);
// Element environmentElement = doc.createElement(PolicyEditorConstants.ALL_OF_ELEMENT);
// MatchElementDTO matchElementDTO = createMatchElementForNonBagFunctions(
// getFunctionId(functionOnEnvironment),
// environments[0].trim(), PolicyEditorConstants.ENVIRONMENT_CATEGORY_URI, environmentId, environmentDataType);
// Element matchElement= createMatchElement(matchElementDTO, doc);
// if(matchElement != null){
// environmentElement.appendChild(matchElement);
// }
// environmentsElement.appendChild(environmentElement);
// } else if(functionOnEnvironment.contains("less") || functionOnEnvironment.contains("greater")){
// 
// AttributeDesignatorDTO designatorDTO = new AttributeDesignatorDTO();
// designatorDTO.setCategory(PolicyEditorConstants.ENVIRONMENT_CATEGORY_URI);
// designatorDTO.setAttributeId(environmentId);
// designatorDTO.setDataType(environmentDataType);
// designatorDTO.setMustBePresent("true");
// try {
// ApplyElementDTO elementDTO = PolicyEditorUtil.
// processGreaterLessThanFunctions(functionOnEnvironment, environmentDataType,
// environmentNames, designatorDTO);
// applyElementDTO.setApplyElement(elementDTO);
// } catch (PolicyEditorException e) {
// //ignore TODO
// }
// } else if(functionOnEnvironment.equals(EntitlementPolicyConstants.IS_IN)) {
// ApplyElementDTO elementDTO = createApplyElementForNonBagFunctions(
// getFunctionId(functionOnEnvironment),
// PolicyEditorConstants.ENVIRONMENT_CATEGORY_URI, environmentId, environments[0].trim(), environmentDataType);
// applyElementDTO.setApplyElement(elementDTO);
// } else {
// ApplyElementDTO elementDTO = createApplyElementForBagFunctions(
// getFunctionId(functionOnEnvironment),
// PolicyEditorConstants.ENVIRONMENT_CATEGORY_URI, environmentId, environments, environmentDataType);
// applyElementDTO.setApplyElement(elementDTO);
// }
// }
// 
// if(subjectNames != null  && subjectNames.trim().length() > 0) {
// String[] subjects = subjectNames.split(EntitlementPolicyConstants.ATTRIBUTE_SEPARATOR);
// if(subjectId == null || subjectId.trim().length() < 1){
// subjectId = EntitlementPolicyConstants.SUBJECT_ID_DEFAULT;
// }
// 
// ApplyElementDTO elementDTO = null;
// if(functionOnSubjects.equals(EntitlementPolicyConstants.EQUAL_TO) ||
// functionOnSubjects.equals(EntitlementPolicyConstants.REGEXP_MATCH)) {
// elementDTO = createApplyElementForNonBagFunctionsWithAnyOf(
// getFunctionId(functionOnSubjects),
// PolicyEditorConstants.SUBJECT_CATEGORY_URI,subjectId, subjects[0].trim());
// 
// } else if(functionOnSubjects.contains("less") || functionOnSubjects.contains("greater")){
// 
// AttributeDesignatorDTO designatorDTO = new AttributeDesignatorDTO();
// designatorDTO.setCategory(PolicyEditorConstants.ACTION_CATEGORY_URI);
// designatorDTO.setAttributeId(subjectId);
// designatorDTO.setDataType(subjectDataType);
// designatorDTO.setMustBePresent("true");
// try {
// elementDTO = PolicyEditorUtil.
// processGreaterLessThanFunctions(functionOnSubjects, subjectDataType,
// subjectNames, designatorDTO);
// applyElementDTO.setApplyElement(elementDTO);
// } catch (PolicyEditorException e) {
// //ignore TODO
// }
// } else if(functionOnSubjects.equals(EntitlementPolicyConstants.IS_IN)) {
// elementDTO = createApplyElementForNonBagFunctions(
// getFunctionId(functionOnSubjects),
// PolicyEditorConstants.SUBJECT_CATEGORY_URI, subjectId, subjects[0].trim(), subjectDataType);
// } else {
// elementDTO = createApplyElementForBagFunctions(
// getFunctionId(functionOnSubjects),
// PolicyEditorConstants.SUBJECT_CATEGORY_URI, subjectId, subjects, subjectDataType);
// }
// 
// if(elementDTO != null){
// applyElementDTO.setApplyElement(elementDTO);
// }
// }
// 
// List<ApplyElementDTO> applyElementDTOs = applyElementDTO.getApplyElements();
// 
// if(applyElementDTOs.size() > 1) {
// applyElementDTO.setFunctionId(EntitlementPolicyConstants.FUNCTION_AND);
// applyElement = createApplyElement(applyElementDTO, doc);
// } else if(applyElementDTOs.size() == 1){
// applyElement = createApplyElement(applyElementDTOs.get(0), doc);
// }
// 
// if(resourcesElement != null || actionsElement != null || subjectsElement != null ||
// environmentsElement != null) {
// targetElement = doc.createElement(EntitlementPolicyConstants.TARGET_ELEMENT);
// if(resourcesElement != null) {
// targetElement.appendChild(resourcesElement);
// }
// if(actionsElement != null) {
// targetElement.appendChild(actionsElement);
// }
// if(subjectsElement != null) {
// targetElement.appendChild(subjectsElement);
// }
// 
// if(environmentsElement != null){
// targetElement.appendChild(environmentsElement);
// }
// }
// 
// if(applyElement != null) {
// conditionElement = doc.createElement(EntitlementPolicyConstants.CONDITION_ELEMENT);
// conditionElement.appendChild(applyElement);
// }
// 
// if(basicRuleDTO.getRuleId() != null && basicRuleDTO.getRuleId().trim().length() > 0 &&
// basicRuleDTO.getRuleEffect() != null && basicRuleDTO.getRuleEffect().
// trim().length() > 0){
// 
// ruleElement = doc.createElement(EntitlementPolicyConstants.RULE_ELEMENT);
// ruleElement.setAttribute(EntitlementPolicyConstants.RULE_ID, basicRuleDTO.
// getRuleId());
// ruleElement.setAttribute(EntitlementPolicyConstants.RULE_EFFECT,
// basicRuleDTO.getRuleEffect());
// 
// if(basicRuleDTO.getRuleDescription() != null && basicRuleDTO.
// getRuleDescription().trim().length() > 0){
// ruleElement.setAttribute(EntitlementPolicyConstants.RULE_DESCRIPTION,
// basicRuleDTO.getRuleDescription());
// }
// 
// if(targetElement != null) {
// ruleElement.appendChild(targetElement);
// }
// if(conditionElement != null) {
// ruleElement.appendChild(conditionElement);
// }
// }
// 
// return ruleElement;
// 
// }
// 
// 
// 
// public static Element createBasicTargetElementDTO(BasicTargetDTO basicTargetDTO,
// Document doc) {
// 
// //TODO
// String functionOnResources =  basicTargetDTO.getFunctionOnResources();
// String functionOnSubjects = basicTargetDTO.getFunctionOnSubjects();
// String functionOnActions = basicTargetDTO.getFunctionOnActions();
// String functionOnEnvironment = basicTargetDTO.getFunctionOnEnvironment();
// String resourceNames = basicTargetDTO.getResourceList();
// String actionNames = basicTargetDTO.getActionList();
// String subjectNames = basicTargetDTO.getSubjectList();
// String environmentNames = basicTargetDTO.getEnvironmentList();
// String resourceId = basicTargetDTO.getResourceId();
// String subjectId = basicTargetDTO.getSubjectId();
// String actionId = basicTargetDTO.getActionId();
// String environmentId = basicTargetDTO.getEnvironmentId();
// String resourceDataType = basicTargetDTO.getResourceDataType();
// String subjectDataType = basicTargetDTO.getSubjectDataType();
// String actionDataType = basicTargetDTO.getActionDataType();
// String environmentDataType = basicTargetDTO.getResourceDataType();
// 
// Element resourcesElement = null;
// Element actionsElement = null;
// Element subjectsElement = null;
// Element environmentsElement = null;
// Element targetElement = doc.createElement(EntitlementPolicyConstants.TARGET_ELEMENT);
// 
// if(resourceNames != null  && resourceNames.trim().length() > 0) {
// resourcesElement = doc.createElement(PolicyEditorConstants.ANY_OF_ELEMENT);
// Element resourceElement = doc.createElement(PolicyEditorConstants.ALL_OF_ELEMENT);
// String[] resources = resourceNames.split(EntitlementPolicyConstants.ATTRIBUTE_SEPARATOR);
// if(resourceId == null || resourceId.trim().length() < 1) {
// resourceId = EntitlementPolicyConstants.RESOURCE_ID;
// }
// if(functionOnResources.equals(EntitlementPolicyConstants.EQUAL_TO) ||
// functionOnResources.equals(EntitlementPolicyConstants.REGEXP_MATCH) ) {
// MatchElementDTO matchElementDTO = createMatchElementForNonBagFunctions(
// getFunctionId(functionOnResources),
// resources[0].trim(), PolicyEditorConstants.RESOURCE_CATEGORY_URI, resourceId, resourceDataType);
// Element matchElement= createMatchElement(matchElementDTO, doc);
// if(matchElement != null){
// resourceElement.appendChild(matchElement);
// }
// resourcesElement.appendChild(resourceElement);
// } else if(functionOnResources.equals(EntitlementPolicyConstants.AT_LEAST_ONE_MATCH)) {
// for(String resource : resources){
// resource = resource.trim();
// Element resourceEle = doc.createElement(PolicyEditorConstants.ALL_OF_ELEMENT);
// MatchElementDTO matchElementDTO = createMatchElementForNonBagFunctions(
// getFunctionId(EntitlementPolicyConstants.EQUAL_TO),
// resource, PolicyEditorConstants.RESOURCE_CATEGORY_URI, resourceId, resourceDataType);
// Element matchElement= createMatchElement(matchElementDTO, doc);
// if(matchElement != null){
// resourceEle.appendChild(matchElement);
// }
// resourcesElement.appendChild(resourceEle);
// }
// } else if(functionOnResources.equals(EntitlementPolicyConstants.AT_LEAST_ONE_MATCH_REGEXP)) {
// for(String resource : resources){
// resource = resource.trim();
// Element resourceEle = doc.createElement(PolicyEditorConstants.ALL_OF_ELEMENT);
// MatchElementDTO matchElementDTO = createMatchElementForNonBagFunctions(
// getFunctionId(EntitlementPolicyConstants.REGEXP_MATCH),
// resource, PolicyEditorConstants.RESOURCE_CATEGORY_URI, resourceId, resourceDataType);
// Element matchElement= createMatchElement(matchElementDTO, doc);
// if(matchElement != null){
// resourceEle.appendChild(matchElement);
// }
// resourcesElement.appendChild(resourceEle);
// }
// } else if(functionOnResources.equals(EntitlementPolicyConstants.MATCH_REGEXP_SET_OF)) {
// for(String resource : resources){
// resource = resource.trim();
// MatchElementDTO matchElementDTO = createMatchElementForNonBagFunctions(
// getFunctionId(EntitlementPolicyConstants.REGEXP_MATCH),
// resource, PolicyEditorConstants.RESOURCE_CATEGORY_URI, resourceId, resourceDataType);
// Element matchElement= createMatchElement(matchElementDTO, doc);
// if(matchElement != null){
// resourceElement.appendChild(matchElement);
// }
// }
// resourcesElement.appendChild(resourceElement);
// }else if(functionOnResources.equals(EntitlementPolicyConstants.SET_OF)) {
// for(String resource : resources){
// resource = resource.trim();
// MatchElementDTO matchElementDTO = createMatchElementForNonBagFunctions(
// getFunctionId(EntitlementPolicyConstants.EQUAL_TO),
// resource, PolicyEditorConstants.RESOURCE_CATEGORY_URI, resourceId, resourceDataType);
// Element matchElement= createMatchElement(matchElementDTO, doc);
// if(matchElement != null){
// resourceElement.appendChild(matchElement);
// }
// }
// resourcesElement.appendChild(resourceElement);
// }
// }
// 
// if(actionNames != null  && actionNames.trim().length() > 0) {
// actionsElement = doc.createElement(PolicyEditorConstants.ANY_OF_ELEMENT);
// Element actionElement = doc.createElement(PolicyEditorConstants.ALL_OF_ELEMENT);
// String[] actions = actionNames.split(",");
// if(actionId == null || actionId.trim().length() < 1) {
// actionId = EntitlementPolicyConstants.ACTION_ID;
// }
// if(functionOnActions.equals(EntitlementPolicyConstants.EQUAL_TO) ||
// functionOnActions.equals(EntitlementPolicyConstants. REGEXP_MATCH)) {
// MatchElementDTO matchElementDTO = createMatchElementForNonBagFunctions(
// getFunctionId(functionOnActions),
// actions[0].trim(), PolicyEditorConstants.ACTION_CATEGORY_URI, actionId, actionDataType);
// Element matchElement= createMatchElement(matchElementDTO, doc);
// if(matchElement != null){
// actionElement.appendChild(matchElement);
// }
// actionsElement.appendChild(actionElement);
// } else if(functionOnActions.equals(EntitlementPolicyConstants.AT_LEAST_ONE_MATCH)) {
// for(String action : actions){
// action = action.trim();
// Element actionEle = doc.createElement(PolicyEditorConstants.ALL_OF_ELEMENT);
// MatchElementDTO matchElementDTO = createMatchElementForNonBagFunctions(
// getFunctionId(EntitlementPolicyConstants.EQUAL_TO),
// action, PolicyEditorConstants.ACTION_CATEGORY_URI, actionId, actionDataType);
// Element matchElement= createMatchElement(matchElementDTO, doc);
// if(matchElement != null){
// actionEle.appendChild(matchElement);
// }
// actionsElement.appendChild(actionEle);
// }
// } else if(functionOnActions.equals(EntitlementPolicyConstants.AT_LEAST_ONE_MATCH_REGEXP)) {
// for(String action : actions){
// action = action.trim();
// Element actionEle = doc.createElement(PolicyEditorConstants.ALL_OF_ELEMENT);
// MatchElementDTO matchElementDTO = createMatchElementForNonBagFunctions(
// getFunctionId(EntitlementPolicyConstants.REGEXP_MATCH),
// action, PolicyEditorConstants.ACTION_CATEGORY_URI, actionId, actionDataType);
// Element matchElement= createMatchElement(matchElementDTO, doc);
// if(matchElement != null){
// actionEle.appendChild(matchElement);
// }
// actionsElement.appendChild(actionEle);
// }
// } else if(functionOnActions.equals(EntitlementPolicyConstants.MATCH_REGEXP_SET_OF)) {
// for(String action : actions){
// action = action.trim();
// MatchElementDTO matchElementDTO = createMatchElementForNonBagFunctions(
// getFunctionId(EntitlementPolicyConstants.REGEXP_MATCH),
// action, PolicyEditorConstants.ACTION_CATEGORY_URI, actionId, actionDataType);
// Element matchElement= createMatchElement(matchElementDTO, doc);
// if(matchElement != null){
// actionElement.appendChild(matchElement);
// }
// }
// actionsElement.appendChild(actionElement);
// } else if(functionOnActions.equals(EntitlementPolicyConstants.SET_OF)) {
// for(String action : actions){
// action = action.trim();
// MatchElementDTO matchElementDTO = createMatchElementForNonBagFunctions(
// getFunctionId(EntitlementPolicyConstants.EQUAL_TO),
// action, PolicyEditorConstants.ACTION_CATEGORY_URI, actionId, actionDataType);
// Element matchElement= createMatchElement(matchElementDTO, doc);
// if(matchElement != null){
// actionElement.appendChild(matchElement);
// }
// }
// actionsElement.appendChild(actionElement);
// }
// 
// }
// 
// if(environmentNames != null  && environmentNames.trim().length() > 0) {
// environmentsElement = doc.createElement(PolicyEditorConstants.ANY_OF_ELEMENT);
// Element environmentElement = doc.createElement(PolicyEditorConstants.ALL_OF_ELEMENT);
// String[] environments = environmentNames.split(",");
// if(environmentId == null || environmentId.trim().length() < 1) {
// environmentId = EntitlementPolicyConstants.ENVIRONMENT_ID;
// }
// if(functionOnEnvironment.equals(EntitlementPolicyConstants.EQUAL_TO) ||
// functionOnEnvironment.equals(EntitlementPolicyConstants.REGEXP_MATCH)) {
// MatchElementDTO matchElementDTO = createMatchElementForNonBagFunctions(
// getFunctionId(functionOnEnvironment),
// environments[0].trim(), PolicyEditorConstants.ENVIRONMENT_CATEGORY_URI, environmentId, environmentDataType);
// Element matchElement= createMatchElement(matchElementDTO, doc);
// if(matchElement != null){
// environmentElement.appendChild(matchElement);
// }
// environmentsElement.appendChild(environmentElement);
// } else if(functionOnEnvironment.equals(EntitlementPolicyConstants.AT_LEAST_ONE_MATCH)) {
// for(String environment : environments){
// environment = environment.trim();
// Element environmentEle = doc.createElement(PolicyEditorConstants.ALL_OF_ELEMENT);
// MatchElementDTO matchElementDTO = createMatchElementForNonBagFunctions(
// getFunctionId(EntitlementPolicyConstants.EQUAL_TO),
// environment, PolicyEditorConstants.ENVIRONMENT_CATEGORY_URI, environmentId, environmentDataType);
// Element matchElement= createMatchElement(matchElementDTO, doc);
// if(matchElement != null){
// environmentEle.appendChild(matchElement);
// }
// environmentsElement.appendChild(environmentEle);
// }
// } else if(functionOnEnvironment.equals(EntitlementPolicyConstants.AT_LEAST_ONE_MATCH_REGEXP)) {
// for(String environment : environments){
// environment = environment.trim();
// Element environmentEle = doc.createElement(PolicyEditorConstants.ALL_OF_ELEMENT);
// MatchElementDTO matchElementDTO = createMatchElementForNonBagFunctions(
// getFunctionId(EntitlementPolicyConstants.REGEXP_MATCH),
// environment, PolicyEditorConstants.ENVIRONMENT_CATEGORY_URI, environmentId, environmentDataType);
// Element matchElement= createMatchElement(matchElementDTO, doc);
// if(matchElement != null){
// environmentEle.appendChild(matchElement);
// }
// environmentsElement.appendChild(environmentEle);
// }
// }else if(functionOnEnvironment.equals(EntitlementPolicyConstants.MATCH_REGEXP_SET_OF)) {
// for(String environment : environments){
// environment = environment.trim();
// MatchElementDTO matchElementDTO = createMatchElementForNonBagFunctions(
// getFunctionId(EntitlementPolicyConstants.REGEXP_MATCH),
// environment, PolicyEditorConstants.ENVIRONMENT_CATEGORY_URI, environmentId, environmentDataType);
// Element matchElement= createMatchElement(matchElementDTO, doc);
// if(matchElement != null){
// environmentElement.appendChild(matchElement);
// }
// }
// environmentsElement.appendChild(environmentElement);
// }else if(functionOnEnvironment.equals(EntitlementPolicyConstants.SET_OF)) {
// for(String environment : environments){
// environment = environment.trim();
// MatchElementDTO matchElementDTO = createMatchElementForNonBagFunctions(
// getFunctionId(EntitlementPolicyConstants.EQUAL_TO),
// environment, PolicyEditorConstants.ENVIRONMENT_CATEGORY_URI, environmentId, environmentDataType);
// Element matchElement= createMatchElement(matchElementDTO, doc);
// if(matchElement != null){
// environmentElement.appendChild(matchElement);
// }
// }
// environmentsElement.appendChild(environmentElement);
// }
// }
// 
// if(subjectNames != null  && subjectNames.trim().length() > 0) {
// subjectsElement = doc.createElement(PolicyEditorConstants.ANY_OF_ELEMENT);
// Element subjectElement = doc.createElement(PolicyEditorConstants.ALL_OF_ELEMENT);
// String[] subjects = subjectNames.split(",");
// if(subjectId == null || subjectId.trim().length() < 1){
// subjectId = EntitlementPolicyConstants.SUBJECT_ID_DEFAULT;
// }
// 
// if(EntitlementPolicyConstants.EQUAL_TO.equals(functionOnSubjects) ||
// EntitlementPolicyConstants.REGEXP_MATCH.equals(functionOnSubjects)) {
// MatchElementDTO matchElementDTO = createMatchElementForNonBagFunctions(
// getFunctionId(functionOnSubjects),
// subjects[0].trim(), PolicyEditorConstants.SUBJECT_CATEGORY_URI, subjectId, subjectDataType);
// Element matchElement= createMatchElement(matchElementDTO, doc);
// if(matchElement != null){
// subjectElement.appendChild(matchElement);
// }
// subjectsElement.appendChild(subjectElement);
// } else if(EntitlementPolicyConstants.AT_LEAST_ONE_MATCH.equals(functionOnSubjects)){
// for(String subject : subjects){
// subject = subject.trim();
// Element subjectEle = doc.createElement(PolicyEditorConstants.ALL_OF_ELEMENT);
// MatchElementDTO matchElementDTO = createMatchElementForNonBagFunctions(
// getFunctionId(EntitlementPolicyConstants.EQUAL_TO),
// subject, PolicyEditorConstants.SUBJECT_CATEGORY_URI, subjectId, subjectDataType);
// Element matchElement= createMatchElement(matchElementDTO, doc);
// if(matchElement != null){
// subjectEle.appendChild(matchElement);
// }
// subjectsElement.appendChild(subjectEle);
// }
// } else if(EntitlementPolicyConstants.AT_LEAST_ONE_MATCH_REGEXP.equals(functionOnSubjects)){
// for(String subject : subjects){
// subject = subject.trim();
// Element subjectEle = doc.createElement(PolicyEditorConstants.ALL_OF_ELEMENT);
// MatchElementDTO matchElementDTO = createMatchElementForNonBagFunctions(
// getFunctionId(EntitlementPolicyConstants.REGEXP_MATCH),
// subject, PolicyEditorConstants.SUBJECT_CATEGORY_URI, subjectId, subjectDataType);
// Element matchElement= createMatchElement(matchElementDTO, doc);
// if(matchElement != null){
// subjectEle.appendChild(matchElement);
// }
// subjectsElement.appendChild(subjectEle);
// }
// } else if(EntitlementPolicyConstants.SET_OF.equals(functionOnSubjects)){
// for(String subject : subjects){
// subject = subject.trim();
// MatchElementDTO matchElementDTO = createMatchElementForNonBagFunctions(
// getFunctionId(EntitlementPolicyConstants.EQUAL_TO),
// subject, PolicyEditorConstants.SUBJECT_CATEGORY_URI, subjectId, subjectDataType);
// Element matchElement= createMatchElement(matchElementDTO, doc);
// if(matchElement != null){
// subjectElement.appendChild(matchElement);
// }
// }
// subjectsElement.appendChild(subjectElement);
// } else if(EntitlementPolicyConstants.MATCH_REGEXP_SET_OF.equals(functionOnSubjects)){
// for(String subject : subjects){
// subject = subject.trim();
// MatchElementDTO matchElementDTO = createMatchElementForNonBagFunctions(
// getFunctionId(EntitlementPolicyConstants.REGEXP_MATCH),
// subject, PolicyEditorConstants.SUBJECT_CATEGORY_URI, subjectId, subjectDataType);
// Element matchElement= createMatchElement(matchElementDTO, doc);
// if(matchElement != null){
// subjectElement.appendChild(matchElement);
// }
// }
// subjectsElement.appendChild(subjectElement);
// }
// }
// 
// if(resourcesElement != null) {
// targetElement.appendChild(resourcesElement);
// }
// if(actionsElement != null) {
// targetElement.appendChild(actionsElement);
// }
// if(subjectsElement != null) {
// targetElement.appendChild(subjectsElement);
// }
// 
// if(environmentsElement != null){
// targetElement.appendChild(environmentsElement);
// }
// 
// return targetElement;
// }
// 
/**
 * Creates XML request from  RequestDTO object
 *
 * @param requestDTO
 * @return
 */
public static RequestElementDTO createRequestElementDTO(RequestDTO requestDTO) {
    RequestElementDTO requestElement = new RequestElementDTO();
    List<RowDTO> rowDTOs = requestDTO.getRowDTOs();
    if (rowDTOs == null || rowDTOs.size() < 1) {
        return requestElement;
    }
    Map<String, AttributesElementDTO> dtoMap = new HashMap<String, AttributesElementDTO>();
    List<AttributesElementDTO> dtoList = new ArrayList<AttributesElementDTO>();
    for (RowDTO rowDTO : rowDTOs) {
        String category = rowDTO.getCategory();
        String value = rowDTO.getAttributeValue();
        String attributeId = rowDTO.getAttributeId();
        if (category != null && category.trim().length() > 0 && value != null && value.trim().length() > 0 && attributeId != null && attributeId.trim().length() > 0) {
            if (requestDTO.isMultipleRequest()) {
                String[] values = value.split(EntitlementPolicyConstants.ATTRIBUTE_SEPARATOR);
                for (String attributeValue : values) {
                    AttributesElementDTO attributesElementDTO = new AttributesElementDTO();
                    attributesElementDTO.setCategory(category);
                    AttributeElementDTO attributeElementDTO = new AttributeElementDTO();
                    attributeElementDTO.addAttributeValue(attributeValue);
                    attributeElementDTO.setAttributeId(attributeId);
                    attributeElementDTO.setIncludeInResult(rowDTO.isNotCompleted());
                    attributesElementDTO.addAttributeElementDTO(attributeElementDTO);
                    if (rowDTO.getAttributeDataType() != null && rowDTO.getAttributeDataType().trim().length() > 0) {
                        attributeElementDTO.setDataType(rowDTO.getAttributeDataType());
                    } else {
                        attributeElementDTO.setDataType(EntitlementPolicyConstants.STRING_DATA_TYPE);
                    }
                    dtoList.add(attributesElementDTO);
                }
            } else {
                AttributesElementDTO attributesElementDTO = dtoMap.get(category);
                if (attributesElementDTO == null) {
                    attributesElementDTO = new AttributesElementDTO();
                    attributesElementDTO.setCategory(category);
                }
                String[] values = value.split(EntitlementPolicyConstants.ATTRIBUTE_SEPARATOR);
                AttributeElementDTO attributeElementDTO = new AttributeElementDTO();
                attributeElementDTO.setAttributeValues(Arrays.asList(values));
                attributeElementDTO.setAttributeId(attributeId);
                attributeElementDTO.setIncludeInResult(rowDTO.isNotCompleted());
                attributesElementDTO.addAttributeElementDTO(attributeElementDTO);
                if (rowDTO.getAttributeDataType() != null && rowDTO.getAttributeDataType().trim().length() > 0) {
                    attributeElementDTO.setDataType(rowDTO.getAttributeDataType());
                } else {
                    attributeElementDTO.setDataType(EntitlementPolicyConstants.STRING_DATA_TYPE);
                }
                dtoMap.put(category, attributesElementDTO);
            }
        }
    }
    requestElement.setMultipleRequest(requestDTO.isMultipleRequest());
    requestElement.setCombinedDecision(requestDTO.isCombinedDecision());
    requestElement.setReturnPolicyIdList(requestDTO.isReturnPolicyIdList());
    if (!requestDTO.isMultipleRequest()) {
        dtoList = new ArrayList<AttributesElementDTO>();
        for (Map.Entry<String, AttributesElementDTO> entry : dtoMap.entrySet()) {
            dtoList.add(entry.getValue());
        }
    }
    requestElement.setAttributesElementDTOs(dtoList);
    return requestElement;
}
Also used : RequestElementDTO(org.wso2.balana.utils.policy.dto.RequestElementDTO) RowDTO(org.wso2.carbon.identity.entitlement.ui.dto.RowDTO) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AttributesElementDTO(org.wso2.balana.utils.policy.dto.AttributesElementDTO) AttributeElementDTO(org.wso2.balana.utils.policy.dto.AttributeElementDTO) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

JsonObject (com.google.gson.JsonObject)5 JsonArray (com.google.gson.JsonArray)4 AttributeAssignment (org.wso2.balana.ctx.AttributeAssignment)4 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 ResponseWriteException (org.wso2.carbon.identity.entitlement.endpoint.exception.ResponseWriteException)3 JsonElement (com.google.gson.JsonElement)2 URI (java.net.URI)2 Test (org.testng.annotations.Test)2 ObligationResult (org.wso2.balana.ObligationResult)2 AbstractResult (org.wso2.balana.ctx.AbstractResult)2 ResponseCtx (org.wso2.balana.ctx.ResponseCtx)2 Status (org.wso2.balana.ctx.Status)2 Result (org.wso2.balana.ctx.xacml3.Result)2 HashMap (java.util.HashMap)1 AttributeElementDTO (org.wso2.balana.utils.policy.dto.AttributeElementDTO)1 AttributesElementDTO (org.wso2.balana.utils.policy.dto.AttributesElementDTO)1 RequestElementDTO (org.wso2.balana.utils.policy.dto.RequestElementDTO)1 Advice (org.wso2.balana.xacml3.Advice)1 Obligation (org.wso2.balana.xacml3.Obligation)1