Policy TestSuite Enabled
[policy/engine.git] / ECOMP-PAP-REST / src / main / java / org / openecomp / policy / pap / xacml / rest / components / MicroServiceConfigPolicy.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ECOMP-PAP-REST
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
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.openecomp.policy.pap.xacml.rest.components;
22
23 import java.io.File;
24 import java.io.PrintWriter;
25 import java.net.URI;
26 import java.net.URISyntaxException;
27 import java.nio.file.Path;
28 import java.nio.file.Paths;
29 import java.sql.Connection;
30 import java.sql.DriverManager;
31 import java.sql.ResultSet;
32 import java.sql.SQLException;
33 import java.sql.Statement;
34 import java.util.HashMap;
35 import java.util.Iterator;
36 import java.util.Map;
37 import java.util.Map.Entry;
38
39 import org.apache.commons.io.FilenameUtils;
40 import org.apache.commons.lang.StringUtils;
41 import org.openecomp.policy.common.logging.eelf.MessageCodes;
42 import org.openecomp.policy.common.logging.eelf.PolicyLogger;
43 import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
44 import org.openecomp.policy.common.logging.flexlogger.Logger;
45 import org.openecomp.policy.rest.XACMLRestProperties;
46 import org.openecomp.policy.rest.adapter.PolicyRestAdapter;
47
48 import com.att.research.xacml.std.IdentifierImpl;
49 import com.att.research.xacml.util.XACMLProperties;
50 import com.fasterxml.jackson.databind.JsonNode;
51 import com.fasterxml.jackson.databind.ObjectMapper;
52 import com.google.common.base.Splitter;
53
54 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionType;
55 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionsType;
56 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType;
57 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType;
58 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeAssignmentExpressionType;
59 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType;
60 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType;
61 import oasis.names.tc.xacml._3_0.core.schema.wd_17.EffectType;
62 import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType;
63 import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObjectFactory;
64 import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
65 import oasis.names.tc.xacml._3_0.core.schema.wd_17.RuleType;
66 import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType; 
67
68 public class MicroServiceConfigPolicy extends Policy {
69         
70         private static final Logger LOGGER = FlexLogger.getLogger(MicroServiceConfigPolicy.class);
71         
72     /*
73      * These are the parameters needed for DB access from the PAP
74      */
75     private static String papDbDriver = null;
76     private static String papDbUrl = null;
77     private static String papDbUser = null;
78     private static String papDbPassword = null;
79     private static Map<String, String> mapAttribute = new HashMap<String,String>();
80     private static Map<String, String> matchMap = new HashMap<String,String>();
81
82         public MicroServiceConfigPolicy() {
83                 super();
84         }
85         
86         public MicroServiceConfigPolicy(PolicyRestAdapter policyAdapter){
87                 this.policyAdapter = policyAdapter;
88         }
89
90         //save configuration of the policy based on the policyname
91         private void saveConfigurations(String policyName, String jsonBody) {
92                 try {
93                         if(policyName.endsWith(".xml")){
94                                 policyName = policyName.replace(".xml", "");
95                         }
96                         PrintWriter out = new PrintWriter(CONFIG_HOME + File.separator + policyName +".json");
97                         out.println(jsonBody);
98                         out.close();
99                 } catch (Exception e) {
100                         LOGGER.error("Exception Occured While writing Configuration data"+e);
101                 } 
102         }
103         
104         
105         @Override
106         public Map<String, String> savePolicies() throws Exception {
107
108                 Map<String, String> successMap = new HashMap<String,String>();
109                 if(isPolicyExists()){
110                         successMap.put("EXISTS", "This Policy already exist on the PAP");
111                         return successMap;
112                 }
113
114                 if(!isPreparedToSave()){
115                         //Prep and configure the policy for saving
116                         prepareToSave();
117                 }
118
119                 // Until here we prepared the data and here calling the method to create xml.
120                 Path newPolicyPath = null;
121                 newPolicyPath = Paths.get(policyAdapter.getNewFileName());
122
123                 successMap = createPolicy(newPolicyPath,getCorrectPolicyDataObject());  
124         
125                 return successMap;              
126         }
127         
128         //This is the method for preparing the policy for saving.  We have broken it out
129         //separately because the fully configured policy is used for multiple things
130         @Override
131         public boolean prepareToSave() throws Exception{
132
133                 if(isPreparedToSave()){
134                         //we have already done this
135                         return true;
136                 }
137                 
138                 int version = 0;
139                 String policyID = policyAdapter.getPolicyID();
140                 version = policyAdapter.getHighestVersion();
141                 
142                 // Create the Instance for pojo, PolicyType object is used in marshalling.
143                 if (policyAdapter.getPolicyType().equals("Config")) {
144                         PolicyType policyConfig = new PolicyType();
145
146                         policyConfig.setVersion(Integer.toString(version));
147                         policyConfig.setPolicyId(policyID);
148                         policyConfig.setTarget(new TargetType());
149                         policyAdapter.setData(policyConfig);
150                 }
151                 policyName = policyAdapter.getNewFileName();
152                 if (policyAdapter.getData() != null) {
153                         // Save the Configurations file with the policy name with extention based on selection.
154                         String jsonBody = policyAdapter.getJsonBody();
155                         saveConfigurations(policyName, jsonBody);
156                         
157                         // Make sure the filename ends with an extension
158                         if (policyName.endsWith(".xml") == false) {
159                                 policyName = policyName + ".xml";
160                         }
161                         
162         
163                         PolicyType configPolicy = (PolicyType) policyAdapter.getData();
164                         
165                         configPolicy.setDescription(policyAdapter.getPolicyDescription());
166
167                         configPolicy.setRuleCombiningAlgId(policyAdapter.getRuleCombiningAlgId());
168                         
169                         AllOfType allOfOne = new AllOfType();
170                         String fileName = policyAdapter.getNewFileName();
171                         String name = fileName.substring(fileName.lastIndexOf("\\") + 1, fileName.length());
172                         if ((name == null) || (name.equals(""))) {
173                                 name = fileName.substring(fileName.lastIndexOf("/") + 1, fileName.length());
174                         }
175                         
176             //setup values for pulling out matching attributes
177             ObjectMapper mapper = new ObjectMapper();
178             JsonNode rootNode = mapper.readTree(policyAdapter.getJsonBody());
179             String matching = null;
180             
181             if (policyAdapter.getTtlDate()==null){
182                 policyAdapter.setTtlDate("NA");
183             }
184             if (policyAdapter.getServiceType().contains("-v")){
185                 matching = getValueFromDictionary(policyAdapter.getServiceType());
186             } else {
187                 String jsonVersion  = StringUtils.replaceEach(rootNode.get("version").toString(), new String[]{"\""}, new String[]{""});
188                 matching = getValueFromDictionary(policyAdapter.getServiceType() + "-v" + jsonVersion);
189             }
190             
191             matchMap = new HashMap<String,String>();
192             if (matching != null && !matching.isEmpty()){
193                 matchMap = Splitter.on(",").withKeyValueSeparator("=").split(matching);
194                 if(policyAdapter.getJsonBody() != null){
195                     pullMatchValue(rootNode);           
196                 }
197             }
198             
199                         // Match for policyName
200                         allOfOne.getMatch().add(createMatch("PolicyName", name));
201                         
202                         AllOfType allOf = new AllOfType();
203                 
204                         // Adding the matches to AllOfType element Match for Ecomp
205                         allOf.getMatch().add(createMatch("ECOMPName", policyAdapter.getEcompName()));
206                         if (matchMap==null || matchMap.isEmpty()){
207                                 // Match for ConfigName
208                                 allOf.getMatch().add(createMatch("ConfigName", policyAdapter.getConfigName()));
209                                 // Match for Service
210                                 allOf.getMatch().add(createDynamicMatch("service", policyAdapter.getServiceType()));
211                                 // Match for uuid
212                                 allOf.getMatch().add(createDynamicMatch("uuid", policyAdapter.getUuid()));
213                                 // Match for location
214                                 allOf.getMatch().add(createDynamicMatch("location", policyAdapter.getLocation()));
215                         }else {
216                                 for (Entry<String, String> matchValue : matchMap.entrySet()){
217                                         String value = matchValue.getValue();
218                                         String key = matchValue.getKey().trim();
219                                         if (value.contains("matching-true")){
220                                                 if (mapAttribute.containsKey(key)){
221                                                         allOf.getMatch().add(createDynamicMatch(key, mapAttribute.get(key)));
222                                                 }
223                                         }
224                                 }
225                         }
226                         // Match for riskType
227                         allOf.getMatch().add(
228                                         createDynamicMatch("RiskType", policyAdapter.getRiskType()));
229                         // Match for riskLevel
230                         allOf.getMatch().add(
231                                         createDynamicMatch("RiskLevel", String.valueOf(policyAdapter.getRiskLevel())));
232                         // Match for riskguard
233                         allOf.getMatch().add(
234                                         createDynamicMatch("guard", policyAdapter.getGuard()));
235                         // Match for ttlDate
236                         allOf.getMatch().add(
237                                         createDynamicMatch("TTLDate", policyAdapter.getTtlDate()));
238
239                         AnyOfType anyOf = new AnyOfType();
240                         anyOf.getAllOf().add(allOfOne);
241                         anyOf.getAllOf().add(allOf);
242
243                         TargetType target = new TargetType();
244                         ((TargetType) target).getAnyOf().add(anyOf);
245                         
246                         // Adding the target to the policy element
247                         configPolicy.setTarget((TargetType) target);
248
249                         RuleType rule = new RuleType();
250                         rule.setRuleId(policyAdapter.getRuleID());
251                         
252                         rule.setEffect(EffectType.PERMIT);
253                         
254                         // Create Target in Rule
255                         AllOfType allOfInRule = new AllOfType();
256
257                         // Creating match for ACCESS in rule target
258                         MatchType accessMatch = new MatchType();
259                         AttributeValueType accessAttributeValue = new AttributeValueType();
260                         accessAttributeValue.setDataType(STRING_DATATYPE);
261                         accessAttributeValue.getContent().add("ACCESS");
262                         accessMatch.setAttributeValue(accessAttributeValue);
263                         AttributeDesignatorType accessAttributeDesignator = new AttributeDesignatorType();
264                         URI accessURI = null;
265                         try {
266                                 accessURI = new URI(ACTION_ID);
267                         } catch (URISyntaxException e) {
268                                 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "MicroServiceConfigPolicy", "Exception creating ACCESS URI");
269                         }
270                         accessAttributeDesignator.setCategory(CATEGORY_ACTION);
271                         accessAttributeDesignator.setDataType(STRING_DATATYPE);
272                         accessAttributeDesignator.setAttributeId(new IdentifierImpl(accessURI).stringValue());
273                         accessMatch.setAttributeDesignator(accessAttributeDesignator);
274                         accessMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE);
275
276                         // Creating Config Match in rule Target
277                         MatchType configMatch = new MatchType();
278                         AttributeValueType configAttributeValue = new AttributeValueType();
279                         configAttributeValue.setDataType(STRING_DATATYPE);
280                         configAttributeValue.getContent().add("Config");
281                         configMatch.setAttributeValue(configAttributeValue);
282                         AttributeDesignatorType configAttributeDesignator = new AttributeDesignatorType();
283                         URI configURI = null;
284                         try {
285                                 configURI = new URI(RESOURCE_ID);
286                         } catch (URISyntaxException e) {
287                                 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "MicroServiceConfigPolicy", "Exception creating Config URI");
288                         }
289                         configAttributeDesignator.setCategory(CATEGORY_RESOURCE);
290                         configAttributeDesignator.setDataType(STRING_DATATYPE);
291                         configAttributeDesignator.setAttributeId(new IdentifierImpl(configURI).stringValue());
292                         configMatch.setAttributeDesignator(configAttributeDesignator);
293                         configMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE);
294
295                         allOfInRule.getMatch().add(accessMatch);
296                         allOfInRule.getMatch().add(configMatch);
297
298                         AnyOfType anyOfInRule = new AnyOfType();
299                         anyOfInRule.getAllOf().add(allOfInRule);
300
301                         TargetType targetInRule = new TargetType();
302                         targetInRule.getAnyOf().add(anyOfInRule);
303
304                         rule.setTarget(targetInRule);
305                         rule.setAdviceExpressions(getAdviceExpressions(version, policyName));
306
307                         configPolicy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(rule);
308                         policyAdapter.setPolicyData(configPolicy);
309
310                 } else {
311                         PolicyLogger.error("Unsupported data object." + policyAdapter.getData().getClass().getCanonicalName());
312                 }
313                 setPreparedToSave(true);
314                 return true;
315         }
316         
317     private void pullMatchValue(JsonNode rootNode) {
318         Iterator<Map.Entry<String, JsonNode>> fieldsIterator = rootNode.fields();
319         String newValue = null;
320            while (fieldsIterator.hasNext()) {
321                Map.Entry<String, JsonNode> field = fieldsIterator.next();
322                final String key = field.getKey();
323                final JsonNode value = field.getValue();
324                if (value.isContainerNode() && !value.isArray()) {
325                    pullMatchValue(value); // RECURSIVE CALL
326                } else {
327                    newValue = StringUtils.replaceEach(value.toString(), new String[]{"[", "]", "\""}, new String[]{"", "", ""});
328                    mapAttribute.put(key, newValue);
329                }
330            }
331        
332    }
333
334    private String getValueFromDictionary(String service){
335        
336        Connection con = null;
337        Statement st = null;
338        ResultSet rs = null;
339        
340        String modelName = service.split("-v")[0];
341        String modelVersion = service.split("-v")[1];
342        
343        
344        /*
345         * Retrieve the property values for db access from the xacml.pap.properties
346         */
347        papDbDriver = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_DB_DRIVER);
348        papDbUrl = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_DB_URL);
349        papDbUser = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_DB_USER);
350        papDbPassword = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_DB_PASSWORD);
351        
352        String ruleTemplate=null;
353        
354        try {
355            //Get DB Connection
356            Class.forName(papDbDriver);
357            con = DriverManager.getConnection(papDbUrl,papDbUser,papDbPassword);
358            st = con.createStatement();
359    
360            String queryString = "Select * from MicroServiceModels where modelName=\""  + modelName
361                    + "\" AND version=\"" + modelVersion+"\"";
362
363            
364            rs = st.executeQuery(queryString);
365            if(rs.next()){
366                ruleTemplate=rs.getString("annotation");
367            }
368            rs.close();
369        }catch (ClassNotFoundException e) {
370            PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "MicroServiceModels", "Exception querying MicroServiceModels");
371        } catch (SQLException e) {
372            PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "MicroServiceModels", "Exception querying MicroServiceModels");
373        } finally {
374            try{
375                if (con!=null) con.close();
376                if (rs!=null) rs.close();
377                if (st!=null) st.close();
378            } catch (Exception ex){
379                    LOGGER.error("Exception Occured While Closing the Database Connection"+ex);
380            }
381        }
382        return ruleTemplate;
383        
384    }
385         // Data required for Advice part is setting here.
386         private AdviceExpressionsType getAdviceExpressions(int version, String fileName) {
387                 AdviceExpressionsType advices = new AdviceExpressionsType();
388                 AdviceExpressionType advice = new AdviceExpressionType();
389                 advice.setAdviceId("MSID");
390                 advice.setAppliesTo(EffectType.PERMIT);
391                 // For Configuration
392                 AttributeAssignmentExpressionType assignment1 = new AttributeAssignmentExpressionType();
393                 assignment1.setAttributeId("type");
394                 assignment1.setCategory(CATEGORY_RESOURCE);
395                 assignment1.setIssuer("");
396
397                 AttributeValueType configNameAttributeValue = new AttributeValueType();
398                 configNameAttributeValue.setDataType(STRING_DATATYPE);
399                 configNameAttributeValue.getContent().add("Configuration");
400                 assignment1.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue));
401
402                 advice.getAttributeAssignmentExpression().add(assignment1);
403                 // For Config file Url if configurations are provided.
404                 AttributeAssignmentExpressionType assignment2 = new AttributeAssignmentExpressionType();
405                 assignment2.setAttributeId("URLID");
406                 assignment2.setCategory(CATEGORY_RESOURCE);
407                 assignment2.setIssuer("");
408
409                 AttributeValueType AttributeValue = new AttributeValueType();
410                 AttributeValue.setDataType(URI_DATATYPE);
411                 String configName;
412                 if(policyName.endsWith(".xml")){
413                         configName = policyName.replace(".xml", "");
414                 }else{
415                         configName = policyName;
416                 }
417                 String content = CONFIG_URL +"/Config/" + configName + ".json";
418                 AttributeValue.getContent().add(content);
419                 assignment2.setExpression(new ObjectFactory().createAttributeValue(AttributeValue));
420
421                 advice.getAttributeAssignmentExpression().add(assignment2);
422                 AttributeAssignmentExpressionType assignment3 = new AttributeAssignmentExpressionType();
423                 assignment3.setAttributeId("PolicyName");
424                 assignment3.setCategory(CATEGORY_RESOURCE);
425                 assignment3.setIssuer("");
426
427                 AttributeValueType attributeValue3 = new AttributeValueType();
428                 attributeValue3.setDataType(STRING_DATATYPE);
429                 fileName = FilenameUtils.removeExtension(fileName);
430                 fileName = fileName + ".xml";
431                 String name = fileName.substring(fileName.lastIndexOf("\\") + 1, fileName.length());
432                 if ((name == null) || (name.equals(""))) {
433                         name = fileName.substring(fileName.lastIndexOf("/") + 1, fileName.length());
434                 }
435                 attributeValue3.getContent().add(name);
436                 assignment3.setExpression(new ObjectFactory().createAttributeValue(attributeValue3));
437                 advice.getAttributeAssignmentExpression().add(assignment3);
438
439                 AttributeAssignmentExpressionType assignment4 = new AttributeAssignmentExpressionType();
440                 assignment4.setAttributeId("VersionNumber");
441                 assignment4.setCategory(CATEGORY_RESOURCE);
442                 assignment4.setIssuer("");
443
444                 AttributeValueType configNameAttributeValue4 = new AttributeValueType();
445                 configNameAttributeValue4.setDataType(STRING_DATATYPE);
446                 configNameAttributeValue4.getContent().add(Integer.toString(version));
447                 assignment4.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue4));
448
449                 advice.getAttributeAssignmentExpression().add(assignment4);
450
451                 AttributeAssignmentExpressionType assignment5 = new AttributeAssignmentExpressionType();
452                 assignment5.setAttributeId("matching:" + ECOMPID);
453                 assignment5.setCategory(CATEGORY_RESOURCE);
454                 assignment5.setIssuer("");
455
456                 AttributeValueType configNameAttributeValue5 = new AttributeValueType();
457                 configNameAttributeValue5.setDataType(STRING_DATATYPE);
458                 configNameAttributeValue5.getContent().add(policyAdapter.getEcompName());
459                 assignment5.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue5));
460
461                 advice.getAttributeAssignmentExpression().add(assignment5);
462
463         AttributeAssignmentExpressionType assignment7 = new AttributeAssignmentExpressionType();
464         assignment7.setAttributeId("matching:service");
465         assignment7.setCategory(CATEGORY_RESOURCE);
466         assignment7.setIssuer("");
467  
468         AttributeValueType configNameAttributeValue7 = new AttributeValueType();
469         configNameAttributeValue7.setDataType(STRING_DATATYPE);
470         configNameAttributeValue7.getContent().add(policyAdapter.getServiceType());
471         assignment7.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue7));
472  
473         advice.getAttributeAssignmentExpression().add(assignment7);
474         
475         if (matchMap==null || matchMap.isEmpty()){
476                 AttributeAssignmentExpressionType assignment6 = new AttributeAssignmentExpressionType();
477                 assignment6.setAttributeId("matching:" + CONFIGID);
478                 assignment6.setCategory(CATEGORY_RESOURCE);
479                 assignment6.setIssuer("");
480
481                 AttributeValueType configNameAttributeValue6 = new AttributeValueType();
482                 configNameAttributeValue6.setDataType(STRING_DATATYPE);
483                 configNameAttributeValue6.getContent().add(policyAdapter.getConfigName());
484                 assignment6.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue6));
485
486                 advice.getAttributeAssignmentExpression().add(assignment6);
487
488
489                 AttributeAssignmentExpressionType assignment8 = new AttributeAssignmentExpressionType();
490                 assignment8.setAttributeId("matching:uuid");
491                 assignment8.setCategory(CATEGORY_RESOURCE);
492                 assignment8.setIssuer("");
493
494                 AttributeValueType configNameAttributeValue8 = new AttributeValueType();
495                 configNameAttributeValue8.setDataType(STRING_DATATYPE);
496                 configNameAttributeValue8.getContent().add(policyAdapter.getUuid());
497                 assignment8.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue8));
498
499                 advice.getAttributeAssignmentExpression().add(assignment8);
500
501                 AttributeAssignmentExpressionType assignment9 = new AttributeAssignmentExpressionType();
502                 assignment9.setAttributeId("matching:Location");
503                 assignment9.setCategory(CATEGORY_RESOURCE);
504                 assignment9.setIssuer("");
505
506                 AttributeValueType configNameAttributeValue9 = new AttributeValueType();
507                 configNameAttributeValue9.setDataType(STRING_DATATYPE);
508                 configNameAttributeValue9.getContent().add(policyAdapter.getLocation());
509                 assignment9.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue9));
510
511                 advice.getAttributeAssignmentExpression().add(assignment9);
512         } else {
513             for (Entry<String, String> matchValue : matchMap.entrySet()){
514                 String value = matchValue.getValue();
515                 String key = matchValue.getKey().trim();
516                 if (value.contains("matching-true")){
517                     if (mapAttribute.containsKey(key)){
518                         AttributeAssignmentExpressionType assignment9 = new AttributeAssignmentExpressionType();
519                         assignment9.setAttributeId("matching:" + key);
520                         assignment9.setCategory(CATEGORY_RESOURCE);
521                         assignment9.setIssuer("");
522                 
523                         AttributeValueType configNameAttributeValue9 = new AttributeValueType();
524                         configNameAttributeValue9.setDataType(STRING_DATATYPE);
525                         configNameAttributeValue9.getContent().add(mapAttribute.get(key));
526                         assignment9.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue9));
527                 
528                         advice.getAttributeAssignmentExpression().add(assignment9);
529  
530                     }
531                 }
532             }
533         }
534         
535                 AttributeAssignmentExpressionType assignment10 = new AttributeAssignmentExpressionType();
536                 assignment10.setAttributeId("Priority");
537                 assignment10.setCategory(CATEGORY_RESOURCE);
538                 assignment10.setIssuer("");
539
540                 AttributeValueType configNameAttributeValue10 = new AttributeValueType();
541                 configNameAttributeValue10.setDataType(STRING_DATATYPE);
542                 configNameAttributeValue10.getContent().add(policyAdapter.getPriority());
543                 assignment10.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue10));
544
545                 advice.getAttributeAssignmentExpression().add(assignment10);
546                 
547                 //Risk Attributes
548                 AttributeAssignmentExpressionType assignment11 = new AttributeAssignmentExpressionType();
549                 assignment11.setAttributeId("RiskType");
550                 assignment11.setCategory(CATEGORY_RESOURCE);
551                 assignment11.setIssuer("");
552
553                 AttributeValueType configNameAttributeValue11 = new AttributeValueType();
554                 configNameAttributeValue11.setDataType(STRING_DATATYPE);
555                 configNameAttributeValue11.getContent().add(policyAdapter.getRiskType());
556                 assignment11.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue11));
557
558                 advice.getAttributeAssignmentExpression().add(assignment11);
559                 
560                 AttributeAssignmentExpressionType assignment12 = new AttributeAssignmentExpressionType();
561                 assignment12.setAttributeId("RiskLevel");
562                 assignment12.setCategory(CATEGORY_RESOURCE);
563                 assignment12.setIssuer("");
564
565                 AttributeValueType configNameAttributeValue12 = new AttributeValueType();
566                 configNameAttributeValue12.setDataType(STRING_DATATYPE);
567                 configNameAttributeValue12.getContent().add(policyAdapter.getRiskLevel());
568                 assignment12.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue12));
569
570                 advice.getAttributeAssignmentExpression().add(assignment12);    
571
572                 AttributeAssignmentExpressionType assignment13 = new AttributeAssignmentExpressionType();
573                 assignment13.setAttributeId("guard");
574                 assignment13.setCategory(CATEGORY_RESOURCE);
575                 assignment13.setIssuer("");
576
577                 AttributeValueType configNameAttributeValue13 = new AttributeValueType();
578                 configNameAttributeValue13.setDataType(STRING_DATATYPE);
579                 configNameAttributeValue13.getContent().add(policyAdapter.getGuard());
580                 assignment13.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue13));
581
582                 advice.getAttributeAssignmentExpression().add(assignment13);
583                 
584                 AttributeAssignmentExpressionType assignment14 = new AttributeAssignmentExpressionType();
585                 assignment14.setAttributeId("TTLDate");
586                 assignment14.setCategory(CATEGORY_RESOURCE);
587                 assignment14.setIssuer("");
588
589                 AttributeValueType configNameAttributeValue14 = new AttributeValueType();
590                 configNameAttributeValue14.setDataType(STRING_DATATYPE);
591                 configNameAttributeValue14.getContent().add(policyAdapter.getTtlDate());
592                 assignment14.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue14));
593
594                 advice.getAttributeAssignmentExpression().add(assignment14);
595
596                 advices.getAdviceExpression().add(advice);
597                 return advices;
598         }
599
600         @Override
601         public Object getCorrectPolicyDataObject() {
602                 return policyAdapter.getPolicyData();
603         }       
604 }