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