Convert tabs to space in ONAP PAP REST1
[policy/engine.git] / ONAP-PAP-REST / src / main / java / org / onap / policy / pap / xacml / rest / components / CreateBrmsParamPolicy.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP-PAP-REST
4  * ================================================================================
5  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.pap.xacml.rest.components;
22
23 import java.io.File;
24 import java.io.IOException;
25 import java.io.PrintWriter;
26 import java.net.URI;
27 import java.net.URISyntaxException;
28 import java.nio.charset.Charset;
29 import java.nio.file.Files;
30 import java.nio.file.Path;
31 import java.nio.file.Paths;
32 import java.util.ArrayList;
33 import java.util.HashMap;
34 import java.util.Iterator;
35 import java.util.List;
36 import java.util.Map;
37 import java.util.Map.Entry;
38 import java.util.UUID;
39 import java.util.regex.Matcher;
40 import java.util.regex.Pattern;
41
42 import javax.script.SimpleBindings;
43
44 import org.apache.commons.io.FilenameUtils;
45 import org.onap.policy.common.logging.eelf.MessageCodes;
46 import org.onap.policy.common.logging.eelf.PolicyLogger;
47 import org.onap.policy.common.logging.flexlogger.FlexLogger;
48 import org.onap.policy.common.logging.flexlogger.Logger;
49 import org.onap.policy.pap.xacml.rest.controller.BRMSDictionaryController;
50 import org.onap.policy.pap.xacml.rest.daoimpl.CommonClassDaoImpl;
51 import org.onap.policy.rest.adapter.PolicyRestAdapter;
52 import org.onap.policy.rest.jpa.BRMSParamTemplate;
53
54 import com.att.research.xacml.api.pap.PAPException;
55 import com.att.research.xacml.std.IdentifierImpl;
56
57 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionType;
58 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionsType;
59 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType;
60 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType;
61 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeAssignmentExpressionType;
62 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType;
63 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType;
64 import oasis.names.tc.xacml._3_0.core.schema.wd_17.EffectType;
65 import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType;
66 import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObjectFactory;
67 import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
68 import oasis.names.tc.xacml._3_0.core.schema.wd_17.RuleType;
69 import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType; 
70
71 public class CreateBrmsParamPolicy extends Policy {
72
73     private static final Logger LOGGER = FlexLogger.getLogger(CreateBrmsParamPolicy.class);
74
75     public CreateBrmsParamPolicy() {
76         super();
77     }
78
79     public CreateBrmsParamPolicy(PolicyRestAdapter policyAdapter) {
80         this.policyAdapter = policyAdapter;
81         this.policyAdapter.setConfigType(policyAdapter.getConfigType());
82
83     }
84
85     public String expandConfigBody(String ruleContents, Map<String, String> brmsParamBody) {
86
87         Map<String,String> copyMap=new HashMap<>();
88         copyMap.putAll(brmsParamBody);
89         copyMap.put("policyName", policyName.substring(0, policyName.replace(".xml", "").lastIndexOf('.')));
90         copyMap.put("policyScope", policyAdapter.getDomainDir());
91         copyMap.put("policyVersion",policyAdapter.getHighestVersion().toString());
92         copyMap.put("unique", ("p"+policyName+UUID.randomUUID().toString()).replaceAll("[^A-Za-z0-9]", ""));
93
94         //Finding all the keys in the Map data-structure.
95         Iterator<String> iterator = copyMap.keySet().iterator();
96         Pattern p;
97         Matcher m;
98         while(iterator.hasNext()) {
99             //Converting the first character of the key into a lower case.
100             String input= iterator.next();
101             String output  = Character.toLowerCase(input.charAt(0)) +
102                     (input.length() > 1 ? input.substring(1) : "");
103             //Searching for a pattern in the String using the key.
104             p=Pattern.compile("\\$\\{"+output+"\\}");
105             m=p.matcher(ruleContents);
106             //Replacing the value with the inputs provided by the user in the editor.
107             String finalInput = copyMap.get(input);
108             if(finalInput.contains("$")){
109                 finalInput = finalInput.replace("$", "\\$");
110             }
111             ruleContents=m.replaceAll(finalInput);
112         }
113         return ruleContents;
114     }
115
116
117     
118     // Utility to read json data from the existing file to a string
119     static String readFile(String path, Charset encoding) throws IOException {
120         byte[] encoded = Files.readAllBytes(Paths.get(path));
121         return new String(encoded, encoding);
122     }
123
124     // Saving the Configurations file at server location for config policy.
125     protected void saveConfigurations(String policyName, String ruleBody) {
126         if (policyName.endsWith(".xml")) {
127             policyName = policyName.substring(0, policyName.lastIndexOf(".xml"));
128         }
129         try (PrintWriter out = new PrintWriter(CONFIG_HOME + File.separator + policyName + ".txt")) {
130             String expandedBody=expandConfigBody(ruleBody,policyAdapter.getBrmsParamBody());
131             out.println(expandedBody);
132             policyAdapter.setJsonBody(expandedBody);
133             policyAdapter.setConfigBodyData(expandedBody);
134             out.close();
135         } catch (Exception e) {
136             PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "CreateBrmsParamPolicy", "Exception saving configuration file");
137         }
138     }
139
140
141     // Here we are adding the extension for the configurations file based on the
142     // config type selection for saving.
143     private String getConfigFile(String filename) {
144         filename = FilenameUtils.removeExtension(filename);
145         if (filename.endsWith(".txt")) {
146             filename = filename.substring(0, filename.length() - 3);
147         }
148
149         filename = filename + ".txt";
150         return filename;
151     }
152
153     // Validations for Config form
154     public boolean validateConfigForm() {
155
156         // Validating mandatory Fields.
157         isValidForm = true;
158         return isValidForm;
159
160     }
161
162     @Override
163     public Map<String, String> savePolicies() throws PAPException {
164
165         Map<String, String> successMap = new HashMap<>();
166         if(isPolicyExists()){
167             successMap.put("EXISTS", "This Policy already exist on the PAP");
168             return successMap;
169         }
170
171         if (!isPreparedToSave()) {
172             prepareToSave();
173         }
174         // Until here we prepared the data and here calling the method to create
175         // xml.
176         Path newPolicyPath = null;
177         newPolicyPath = Paths.get(policyAdapter.getNewFileName());
178         successMap = createPolicy(newPolicyPath,getCorrectPolicyDataObject());
179         if(successMap == null){
180             successMap = new HashMap<>();
181             PolicyLogger.error("Failed to Update the Database Dictionary Tables.");
182             successMap.put("error", "DB UPDATE");
183         }
184         return successMap;
185     }
186
187     private String getValueFromDictionary(String templateName){
188         String ruleTemplate = null;
189         CommonClassDaoImpl dbConnection = new CommonClassDaoImpl();
190         String queryString="from BRMSParamTemplate where param_template_name= :templateName";
191         SimpleBindings params = new SimpleBindings();
192         params.put("templateName", templateName);
193         List<Object> result = dbConnection.getDataByQuery(queryString, params);
194         if(!result.isEmpty()){
195             BRMSParamTemplate template = (BRMSParamTemplate) result.get(0);
196             ruleTemplate = template.getRule();
197         }
198         return ruleTemplate;
199     }
200
201     protected Map<String, String> findType(String rule) {
202         Map<String, String> mapFieldType= new HashMap<>();
203         if(rule!=null){
204             try {
205                 StringBuilder params = new StringBuilder();
206                 Boolean flag = false;
207                 Boolean comment = false;
208                 String lines[] = rule.split("\n");
209                 for(String line : lines){
210                     if (line.isEmpty() || line.startsWith("//")) {
211                         continue;
212                     }
213                     if (line.startsWith("/*")) {
214                         comment = true;
215                         continue;
216                     }
217                     if (line.contains("//") && !(line.contains("http://") || line.contains("https://"))){
218                             line = line.split("\\/\\/")[0];
219                     }
220                     if (line.contains("/*")) {
221                         comment = true;
222                         if (line.contains("*/")) {
223                             try {
224                                 comment = false;
225                                 line = line.split("\\/\\*")[0]
226                                         + line.split("\\*\\/")[1].replace("*/", "");
227                             } catch (Exception e) {
228                                 LOGGER.debug(e);
229                                 line = line.split("\\/\\*")[0];
230                             }
231                         } else {
232                             line = line.split("\\/\\*")[0];
233                         }
234                     }
235                     if (line.contains("*/")) {
236                         comment = false;
237                         try {
238                             line = line.split("\\*\\/")[1].replace("*/", "");
239                         } catch (Exception e) {
240                             LOGGER.debug(e);
241                             line = "";
242                         }
243                     }
244                     if (comment) {
245                         continue;
246                     }
247                     if (flag) {
248                         params.append(line);
249                     }
250                     if (line.contains("declare Params")) {
251                         params.append(line);
252                         flag = true;
253                     }
254                     if (line.contains("end") && flag) {
255                         break;
256                     }
257                 }
258                 String param = params.toString().replace("declare Params", "").replace("end", "")
259                         .replaceAll("\\s+", "");
260                 String[] components = param.split(":");
261                 String caption = "";
262                 for (int i = 0; i < components.length; i++) {
263                     String type = "";
264                     if (i == 0) {
265                         caption = components[i];
266                     }
267                     if(caption.equals("")){
268                         break;
269                     }
270                     String nextComponent = "";
271                     try {
272                         nextComponent = components[i + 1];
273                     } catch (Exception e) {
274                         LOGGER.debug(e);
275                         nextComponent = components[i];
276                     }
277                     //If the type is of type String then we add the UI Item and type to the map.
278                     if (nextComponent.startsWith("String")) {
279                         type = "String";
280                         mapFieldType.put(caption, type);
281                         caption = nextComponent.replace("String", "");
282                     } else if (nextComponent.startsWith("int")) {
283                         type = "int";
284                         mapFieldType.put(caption, type);
285                         caption = nextComponent.replace("int", "");
286                     }
287                 }
288             } catch (Exception e) {
289                 PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "CreateBrmsParamPolicy", "Exception parsing file in findType");
290             }
291         }
292         return mapFieldType;
293     }
294
295     // This is the method for preparing the policy for saving. We have broken it
296     // out
297     // separately because the fully configured policy is used for multiple
298     // things
299     @Override
300     public boolean prepareToSave() throws PAPException {
301
302         if (isPreparedToSave()) {
303             // we have already done this
304             return true;
305         }
306
307         int version = 0;
308         String policyID = policyAdapter.getPolicyID();
309         version = policyAdapter.getHighestVersion();
310
311         // Create the Instance for pojo, PolicyType object is used in
312         // marshalling.
313         if (policyAdapter.getPolicyType().equals("Config")) {
314             PolicyType policyConfig = new PolicyType();
315
316             policyConfig.setVersion(Integer.toString(version));
317             policyConfig.setPolicyId(policyID);
318             policyConfig.setTarget(new TargetType());
319             policyAdapter.setData(policyConfig);
320         }
321
322         policyName = policyAdapter.getNewFileName();
323
324         if (policyAdapter.getData() != null) {
325             Map<String,String> ruleAndUIValue= policyAdapter.getBrmsParamBody();
326             String templateValue= ruleAndUIValue.get("templateName");
327             String valueFromDictionary= getValueFromDictionary(templateValue);
328
329             StringBuilder body = new StringBuilder();
330
331             try {
332                 body.append("/* Autogenerated Code Please Don't change/remove this comment section. This is for the UI purpose. \n\t " +
333                         "<$%BRMSParamTemplate=" + templateValue + "%$> \n");
334                 body.append("<%$Values=");
335                 for (Map.Entry<String, String> entry : ruleAndUIValue.entrySet()) {
336                     String uiKey = entry.getKey();
337                     if(!"templateName".equals(uiKey)) {
338                         body.append(uiKey+":-:"+entry.getValue()+":|:");
339                     }
340                 }
341                 body.append("$%> \n*/ \n");
342                 body.append(valueFromDictionary + "\n");
343             }
344             catch (Exception e) {
345                 PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "CreateBrmsParamPolicy", "Exception saving policy");
346             }
347
348             saveConfigurations(policyName,body.toString());
349
350             // Make sure the filename ends with an extension
351             if (!policyName.endsWith(".xml")) {
352                 policyName = policyName + ".xml";
353             }
354
355             PolicyType configPolicy = (PolicyType) policyAdapter.getData();
356
357             configPolicy.setDescription(policyAdapter.getPolicyDescription());
358
359             configPolicy.setRuleCombiningAlgId(policyAdapter.getRuleCombiningAlgId());
360
361             AllOfType allOfOne = new AllOfType();
362
363             String fileName = policyAdapter.getNewFileName();
364             String name = fileName.substring(fileName.lastIndexOf("\\") + 1, fileName.length());
365             if ((name == null) || (name.equals(""))) {
366                 name = fileName.substring(fileName.lastIndexOf("/") + 1,
367                         fileName.length());
368             }
369             allOfOne.getMatch().add(createMatch("PolicyName", name));
370
371
372             AllOfType allOf = new AllOfType();
373
374             // Match for ONAPName
375             allOf.getMatch().add(createMatch("ONAPName", policyAdapter.getOnapName()));
376             allOf.getMatch().add(createMatch("ConfigName", policyAdapter.getConfigName()));
377             // Match for riskType
378             allOf.getMatch().add(createDynamicMatch("RiskType", policyAdapter.getRiskType()));
379             // Match for riskLevel
380             allOf.getMatch().add(createDynamicMatch("RiskLevel", String.valueOf(policyAdapter.getRiskLevel())));
381             // Match for riskguard
382             allOf.getMatch().add(createDynamicMatch("guard", policyAdapter.getGuard()));
383             // Match for ttlDate
384             allOf.getMatch().add(createDynamicMatch("TTLDate", policyAdapter.getTtlDate()));
385             AnyOfType anyOf = new AnyOfType();
386             anyOf.getAllOf().add(allOfOne);
387             anyOf.getAllOf().add(allOf);
388
389             TargetType target = new TargetType();
390             target.getAnyOf().add(anyOf);
391
392             // Adding the target to the policy element
393             configPolicy.setTarget((TargetType) target);
394
395             RuleType rule = new RuleType();
396             rule.setRuleId(policyAdapter.getRuleID());
397
398             rule.setEffect(EffectType.PERMIT);
399
400             // Create Target in Rule
401             AllOfType allOfInRule = new AllOfType();
402
403             // Creating match for ACCESS in rule target
404             MatchType accessMatch = new MatchType();
405             AttributeValueType accessAttributeValue = new AttributeValueType();
406             accessAttributeValue.setDataType(STRING_DATATYPE);
407             accessAttributeValue.getContent().add("ACCESS");
408             accessMatch.setAttributeValue(accessAttributeValue);
409             AttributeDesignatorType accessAttributeDesignator = new AttributeDesignatorType();
410             URI accessURI = null;
411             try {
412                 accessURI = new URI(ACTION_ID);
413             } catch (URISyntaxException e) {
414                 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "CreateBrmsParamPolicy", "Exception creating ACCESS URI");
415             }
416             accessAttributeDesignator.setCategory(CATEGORY_ACTION);
417             accessAttributeDesignator.setDataType(STRING_DATATYPE);
418             accessAttributeDesignator.setAttributeId(new IdentifierImpl(
419                     accessURI).stringValue());
420             accessMatch.setAttributeDesignator(accessAttributeDesignator);
421             accessMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE);
422
423             // Creating Config Match in rule Target
424             MatchType configMatch = new MatchType();
425             AttributeValueType configAttributeValue = new AttributeValueType();
426             configAttributeValue.setDataType(STRING_DATATYPE);
427
428             configAttributeValue.getContent().add("Config");
429
430             configMatch.setAttributeValue(configAttributeValue);
431             AttributeDesignatorType configAttributeDesignator = new AttributeDesignatorType();
432             URI configURI = null;
433             try {
434                 configURI = new URI(RESOURCE_ID);
435             } catch (URISyntaxException e) {
436                 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "CreateBrmsParamPolicy", "Exception creating Config URI");
437             }
438
439             configAttributeDesignator.setCategory(CATEGORY_RESOURCE);
440             configAttributeDesignator.setDataType(STRING_DATATYPE);
441             configAttributeDesignator.setAttributeId(new IdentifierImpl(configURI).stringValue());
442             configMatch.setAttributeDesignator(configAttributeDesignator);
443             configMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE);
444
445             allOfInRule.getMatch().add(accessMatch);
446             allOfInRule.getMatch().add(configMatch);
447
448             AnyOfType anyOfInRule = new AnyOfType();
449             anyOfInRule.getAllOf().add(allOfInRule);
450
451             TargetType targetInRule = new TargetType();
452             targetInRule.getAnyOf().add(anyOfInRule);
453
454             rule.setTarget(targetInRule);
455             rule.setAdviceExpressions(getAdviceExpressions(version, policyName));
456
457             configPolicy
458                     .getCombinerParametersOrRuleCombinerParametersOrVariableDefinition()
459                     .add(rule);
460             policyAdapter.setPolicyData(configPolicy);
461
462         } else {
463             PolicyLogger.error("Unsupported data object."
464                     + policyAdapter.getData().getClass().getCanonicalName());
465         }
466         setPreparedToSave(true);
467         return true;
468     }
469
470     // Data required for Advice part is setting here.
471     private AdviceExpressionsType getAdviceExpressions(int version,
472             String fileName) {
473
474         //Policy Config ID Assignment
475         AdviceExpressionsType advices = new AdviceExpressionsType();
476         AdviceExpressionType advice = new AdviceExpressionType();
477         advice.setAdviceId("BRMSPARAMID");
478         advice.setAppliesTo(EffectType.PERMIT);
479         // For Configuration
480         AttributeAssignmentExpressionType assignment1 = new AttributeAssignmentExpressionType();
481         assignment1.setAttributeId("type");
482         assignment1.setCategory(CATEGORY_RESOURCE);
483         assignment1.setIssuer("");
484         AttributeValueType configNameAttributeValue = new AttributeValueType();
485         configNameAttributeValue.setDataType(STRING_DATATYPE);
486         configNameAttributeValue.getContent().add("Configuration");
487         assignment1.setExpression(new ObjectFactory()
488                 .createAttributeValue(configNameAttributeValue));
489         advice.getAttributeAssignmentExpression().add(assignment1);
490
491         // For Config file Url if configurations are provided.
492         // URL ID Assignment
493         AttributeAssignmentExpressionType assignment2 = new AttributeAssignmentExpressionType();
494         assignment2.setAttributeId("URLID");
495         assignment2.setCategory(CATEGORY_RESOURCE);
496         assignment2.setIssuer("");
497         AttributeValueType attributeValue = new AttributeValueType();
498         attributeValue.setDataType(URI_DATATYPE);
499
500         String content = CONFIG_URL + "/Config/"+ getConfigFile(policyName);
501
502         attributeValue.getContent().add(content);
503         assignment2.setExpression(new ObjectFactory()
504                 .createAttributeValue(attributeValue));
505         advice.getAttributeAssignmentExpression().add(assignment2);
506
507         // Policy Name Assignment
508         AttributeAssignmentExpressionType assignment3 = new AttributeAssignmentExpressionType();
509         assignment3.setAttributeId("PolicyName");
510         assignment3.setCategory(CATEGORY_RESOURCE);
511         assignment3.setIssuer("");
512         AttributeValueType attributeValue3 = new AttributeValueType();
513         attributeValue3.setDataType(STRING_DATATYPE);
514         fileName = FilenameUtils.removeExtension(fileName);
515         fileName = fileName + ".xml";
516         String name = fileName.substring(fileName.lastIndexOf("\\") + 1,
517                 fileName.length());
518         if ((name == null) || (name.equals(""))) {
519             name = fileName.substring(fileName.lastIndexOf("/") + 1,
520                     fileName.length());
521         }
522         attributeValue3.getContent().add(name);
523         assignment3.setExpression(new ObjectFactory()
524                 .createAttributeValue(attributeValue3));
525         advice.getAttributeAssignmentExpression().add(assignment3);
526
527         // Version Number Assignment
528         AttributeAssignmentExpressionType assignment4 = new AttributeAssignmentExpressionType();
529         assignment4.setAttributeId("VersionNumber");
530         assignment4.setCategory(CATEGORY_RESOURCE);
531         assignment4.setIssuer("");
532         AttributeValueType configNameAttributeValue4 = new AttributeValueType();
533         configNameAttributeValue4.setDataType(STRING_DATATYPE);
534         configNameAttributeValue4.getContent().add(Integer.toString(version));
535         assignment4.setExpression(new ObjectFactory()
536                 .createAttributeValue(configNameAttributeValue4));
537         advice.getAttributeAssignmentExpression().add(assignment4);
538
539         // Onap Name Assignment
540         AttributeAssignmentExpressionType assignment5 = new AttributeAssignmentExpressionType();
541         assignment5.setAttributeId("matching:" + ONAPID);
542         assignment5.setCategory(CATEGORY_RESOURCE);
543         assignment5.setIssuer("");
544         AttributeValueType configNameAttributeValue5 = new AttributeValueType();
545         configNameAttributeValue5.setDataType(STRING_DATATYPE);
546         configNameAttributeValue5.getContent().add(policyAdapter.getOnapName());
547         assignment5.setExpression(new ObjectFactory()
548                 .createAttributeValue(configNameAttributeValue5));
549         advice.getAttributeAssignmentExpression().add(assignment5);
550
551
552         //Config Name Assignment
553         AttributeAssignmentExpressionType assignment6 = new AttributeAssignmentExpressionType();
554         assignment6.setAttributeId("matching:" +CONFIGID);
555         assignment6.setCategory(CATEGORY_RESOURCE);
556         assignment6.setIssuer("");
557         AttributeValueType configNameAttributeValue6 = new AttributeValueType();
558         configNameAttributeValue6.setDataType(STRING_DATATYPE);
559         configNameAttributeValue6.getContent().add(policyAdapter.getConfigName());
560         assignment6.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue6));
561         advice.getAttributeAssignmentExpression().add(assignment6);
562         // Adding Controller Information. 
563         if(policyAdapter.getBrmsController()!=null){
564             BRMSDictionaryController brmsDicitonaryController = new BRMSDictionaryController();
565             advice.getAttributeAssignmentExpression().add(
566                         createResponseAttributes("controller:"+ policyAdapter.getBrmsController(), 
567                                 brmsDicitonaryController.getControllerDataByID(policyAdapter.getBrmsController()).getController()));
568         }
569         
570         // Adding Dependencies. 
571         if(policyAdapter.getBrmsDependency()!=null){
572             BRMSDictionaryController brmsDicitonaryController = new BRMSDictionaryController();
573             ArrayList<String> dependencies = new ArrayList<>();
574             StringBuilder key = new StringBuilder();
575             for(String dependencyName: policyAdapter.getBrmsDependency()){
576                 dependencies.add(brmsDicitonaryController.getDependencyDataByID(dependencyName).getDependency());
577                 key.append(dependencyName + ",");
578             }
579             advice.getAttributeAssignmentExpression().add(
580                         createResponseAttributes("dependencies:"+key.toString(), dependencies.toString()));
581         }
582         
583         // Dynamic Field Config Attributes. 
584         Map<String, String> dynamicFieldConfigAttributes = policyAdapter.getDynamicFieldConfigAttributes();
585         for (Entry<String, String> map : dynamicFieldConfigAttributes.entrySet()) {
586             advice.getAttributeAssignmentExpression().add(createResponseAttributes("key:"+map.getKey(), map.getValue()));
587         }
588
589         //Risk Attributes
590         AttributeAssignmentExpressionType assignment8 = new AttributeAssignmentExpressionType();
591         assignment8.setAttributeId("RiskType");
592         assignment8.setCategory(CATEGORY_RESOURCE);
593         assignment8.setIssuer("");
594
595         AttributeValueType configNameAttributeValue8 = new AttributeValueType();
596         configNameAttributeValue8.setDataType(STRING_DATATYPE);
597         configNameAttributeValue8.getContent().add(policyAdapter.getRiskType());
598         assignment8.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue8));
599
600         advice.getAttributeAssignmentExpression().add(assignment8);
601
602         AttributeAssignmentExpressionType assignment9 = new AttributeAssignmentExpressionType();
603         assignment9.setAttributeId("RiskLevel");
604         assignment9.setCategory(CATEGORY_RESOURCE);
605         assignment9.setIssuer("");
606
607         AttributeValueType configNameAttributeValue9 = new AttributeValueType();
608         configNameAttributeValue9.setDataType(STRING_DATATYPE);
609         configNameAttributeValue9.getContent().add(policyAdapter.getRiskLevel());
610         assignment9.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue9));
611
612         advice.getAttributeAssignmentExpression().add(assignment9);
613
614         AttributeAssignmentExpressionType assignment10 = new AttributeAssignmentExpressionType();
615         assignment10.setAttributeId("guard");
616         assignment10.setCategory(CATEGORY_RESOURCE);
617         assignment10.setIssuer("");
618
619         AttributeValueType configNameAttributeValue10 = new AttributeValueType();
620         configNameAttributeValue10.setDataType(STRING_DATATYPE);
621         configNameAttributeValue10.getContent().add(policyAdapter.getGuard());
622         assignment10.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue10));
623
624         advice.getAttributeAssignmentExpression().add(assignment10);
625
626         AttributeAssignmentExpressionType assignment11 = new AttributeAssignmentExpressionType();
627         assignment11.setAttributeId("TTLDate");
628         assignment11.setCategory(CATEGORY_RESOURCE);
629         assignment11.setIssuer("");
630
631         AttributeValueType configNameAttributeValue11 = new AttributeValueType();
632         configNameAttributeValue11.setDataType(STRING_DATATYPE);
633         configNameAttributeValue11.getContent().add(policyAdapter.getTtlDate());
634         assignment11.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue11));
635
636         advice.getAttributeAssignmentExpression().add(assignment11);
637
638         advices.getAdviceExpression().add(advice);
639         return advices;
640     }
641
642     @Override
643     public Object getCorrectPolicyDataObject() {
644         return policyAdapter.getData();
645     }
646
647     private AttributeAssignmentExpressionType  createResponseAttributes(String key, String value){
648         AttributeAssignmentExpressionType assignment7 = new AttributeAssignmentExpressionType();
649         assignment7.setAttributeId(key);
650         assignment7.setCategory(CATEGORY_RESOURCE);
651         assignment7.setIssuer("");
652         AttributeValueType configNameAttributeValue7 = new AttributeValueType();
653         configNameAttributeValue7.setDataType(STRING_DATATYPE);
654         configNameAttributeValue7.getContent().add(value);
655         assignment7.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue7));
656         return assignment7;
657     }
658 }