Commit includes ControlLoopPolicy API and bugfixes
[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<>();
80     private static Map<String, String> matchMap = new HashMap<>();
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<>();
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<>();
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){
376                    con.close();
377                }
378                if (rs!=null){
379                    rs.close();
380                }
381                if (st!=null){
382                    st.close();
383                }
384            } catch (Exception ex){
385                    LOGGER.error("Exception Occured While Closing the Database Connection"+ex);
386            }
387        }
388        return ruleTemplate;
389        
390    }
391         // Data required for Advice part is setting here.
392         private AdviceExpressionsType getAdviceExpressions(int version, String fileName) {
393                 AdviceExpressionsType advices = new AdviceExpressionsType();
394                 AdviceExpressionType advice = new AdviceExpressionType();
395                 advice.setAdviceId("MSID");
396                 advice.setAppliesTo(EffectType.PERMIT);
397                 // For Configuration
398                 AttributeAssignmentExpressionType assignment1 = new AttributeAssignmentExpressionType();
399                 assignment1.setAttributeId("type");
400                 assignment1.setCategory(CATEGORY_RESOURCE);
401                 assignment1.setIssuer("");
402
403                 AttributeValueType configNameAttributeValue = new AttributeValueType();
404                 configNameAttributeValue.setDataType(STRING_DATATYPE);
405                 configNameAttributeValue.getContent().add("Configuration");
406                 assignment1.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue));
407
408                 advice.getAttributeAssignmentExpression().add(assignment1);
409                 // For Config file Url if configurations are provided.
410                 AttributeAssignmentExpressionType assignment2 = new AttributeAssignmentExpressionType();
411                 assignment2.setAttributeId("URLID");
412                 assignment2.setCategory(CATEGORY_RESOURCE);
413                 assignment2.setIssuer("");
414
415                 AttributeValueType AttributeValue = new AttributeValueType();
416                 AttributeValue.setDataType(URI_DATATYPE);
417                 String configName;
418                 if(policyName.endsWith(".xml")){
419                         configName = policyName.replace(".xml", "");
420                 }else{
421                         configName = policyName;
422                 }
423                 String content = CONFIG_URL +"/Config/" + configName + ".json";
424                 AttributeValue.getContent().add(content);
425                 assignment2.setExpression(new ObjectFactory().createAttributeValue(AttributeValue));
426
427                 advice.getAttributeAssignmentExpression().add(assignment2);
428                 AttributeAssignmentExpressionType assignment3 = new AttributeAssignmentExpressionType();
429                 assignment3.setAttributeId("PolicyName");
430                 assignment3.setCategory(CATEGORY_RESOURCE);
431                 assignment3.setIssuer("");
432
433                 AttributeValueType attributeValue3 = new AttributeValueType();
434                 attributeValue3.setDataType(STRING_DATATYPE);
435                 fileName = FilenameUtils.removeExtension(fileName);
436                 fileName = fileName + ".xml";
437                 String name = fileName.substring(fileName.lastIndexOf("\\") + 1, fileName.length());
438                 if ((name == null) || (name.equals(""))) {
439                         name = fileName.substring(fileName.lastIndexOf("/") + 1, fileName.length());
440                 }
441                 attributeValue3.getContent().add(name);
442                 assignment3.setExpression(new ObjectFactory().createAttributeValue(attributeValue3));
443                 advice.getAttributeAssignmentExpression().add(assignment3);
444
445                 AttributeAssignmentExpressionType assignment4 = new AttributeAssignmentExpressionType();
446                 assignment4.setAttributeId("VersionNumber");
447                 assignment4.setCategory(CATEGORY_RESOURCE);
448                 assignment4.setIssuer("");
449
450                 AttributeValueType configNameAttributeValue4 = new AttributeValueType();
451                 configNameAttributeValue4.setDataType(STRING_DATATYPE);
452                 configNameAttributeValue4.getContent().add(Integer.toString(version));
453                 assignment4.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue4));
454
455                 advice.getAttributeAssignmentExpression().add(assignment4);
456
457                 AttributeAssignmentExpressionType assignment5 = new AttributeAssignmentExpressionType();
458                 assignment5.setAttributeId("matching:" + ECOMPID);
459                 assignment5.setCategory(CATEGORY_RESOURCE);
460                 assignment5.setIssuer("");
461
462                 AttributeValueType configNameAttributeValue5 = new AttributeValueType();
463                 configNameAttributeValue5.setDataType(STRING_DATATYPE);
464                 configNameAttributeValue5.getContent().add(policyAdapter.getEcompName());
465                 assignment5.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue5));
466
467                 advice.getAttributeAssignmentExpression().add(assignment5);
468
469         AttributeAssignmentExpressionType assignment7 = new AttributeAssignmentExpressionType();
470         assignment7.setAttributeId("matching:service");
471         assignment7.setCategory(CATEGORY_RESOURCE);
472         assignment7.setIssuer("");
473  
474         AttributeValueType configNameAttributeValue7 = new AttributeValueType();
475         configNameAttributeValue7.setDataType(STRING_DATATYPE);
476         configNameAttributeValue7.getContent().add(policyAdapter.getServiceType());
477         assignment7.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue7));
478  
479         advice.getAttributeAssignmentExpression().add(assignment7);
480         
481         if (matchMap==null || matchMap.isEmpty()){
482                 AttributeAssignmentExpressionType assignment6 = new AttributeAssignmentExpressionType();
483                 assignment6.setAttributeId("matching:" + CONFIGID);
484                 assignment6.setCategory(CATEGORY_RESOURCE);
485                 assignment6.setIssuer("");
486
487                 AttributeValueType configNameAttributeValue6 = new AttributeValueType();
488                 configNameAttributeValue6.setDataType(STRING_DATATYPE);
489                 configNameAttributeValue6.getContent().add(policyAdapter.getConfigName());
490                 assignment6.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue6));
491
492                 advice.getAttributeAssignmentExpression().add(assignment6);
493
494
495                 AttributeAssignmentExpressionType assignment8 = new AttributeAssignmentExpressionType();
496                 assignment8.setAttributeId("matching:uuid");
497                 assignment8.setCategory(CATEGORY_RESOURCE);
498                 assignment8.setIssuer("");
499
500                 AttributeValueType configNameAttributeValue8 = new AttributeValueType();
501                 configNameAttributeValue8.setDataType(STRING_DATATYPE);
502                 configNameAttributeValue8.getContent().add(policyAdapter.getUuid());
503                 assignment8.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue8));
504
505                 advice.getAttributeAssignmentExpression().add(assignment8);
506
507                 AttributeAssignmentExpressionType assignment9 = new AttributeAssignmentExpressionType();
508                 assignment9.setAttributeId("matching:Location");
509                 assignment9.setCategory(CATEGORY_RESOURCE);
510                 assignment9.setIssuer("");
511
512                 AttributeValueType configNameAttributeValue9 = new AttributeValueType();
513                 configNameAttributeValue9.setDataType(STRING_DATATYPE);
514                 configNameAttributeValue9.getContent().add(policyAdapter.getLocation());
515                 assignment9.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue9));
516
517                 advice.getAttributeAssignmentExpression().add(assignment9);
518         } else {
519             for (Entry<String, String> matchValue : matchMap.entrySet()){
520                 String value = matchValue.getValue();
521                 String key = matchValue.getKey().trim();
522                 if (value.contains("matching-true")){
523                     if (mapAttribute.containsKey(key)){
524                         AttributeAssignmentExpressionType assignment9 = new AttributeAssignmentExpressionType();
525                         assignment9.setAttributeId("matching:" + key);
526                         assignment9.setCategory(CATEGORY_RESOURCE);
527                         assignment9.setIssuer("");
528                 
529                         AttributeValueType configNameAttributeValue9 = new AttributeValueType();
530                         configNameAttributeValue9.setDataType(STRING_DATATYPE);
531                         configNameAttributeValue9.getContent().add(mapAttribute.get(key));
532                         assignment9.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue9));
533                 
534                         advice.getAttributeAssignmentExpression().add(assignment9);
535  
536                     }
537                 }
538             }
539         }
540         
541                 AttributeAssignmentExpressionType assignment10 = new AttributeAssignmentExpressionType();
542                 assignment10.setAttributeId("Priority");
543                 assignment10.setCategory(CATEGORY_RESOURCE);
544                 assignment10.setIssuer("");
545
546                 AttributeValueType configNameAttributeValue10 = new AttributeValueType();
547                 configNameAttributeValue10.setDataType(STRING_DATATYPE);
548                 configNameAttributeValue10.getContent().add(policyAdapter.getPriority());
549                 assignment10.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue10));
550
551                 advice.getAttributeAssignmentExpression().add(assignment10);
552                 
553                 //Risk Attributes
554                 AttributeAssignmentExpressionType assignment11 = new AttributeAssignmentExpressionType();
555                 assignment11.setAttributeId("RiskType");
556                 assignment11.setCategory(CATEGORY_RESOURCE);
557                 assignment11.setIssuer("");
558
559                 AttributeValueType configNameAttributeValue11 = new AttributeValueType();
560                 configNameAttributeValue11.setDataType(STRING_DATATYPE);
561                 configNameAttributeValue11.getContent().add(policyAdapter.getRiskType());
562                 assignment11.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue11));
563
564                 advice.getAttributeAssignmentExpression().add(assignment11);
565                 
566                 AttributeAssignmentExpressionType assignment12 = new AttributeAssignmentExpressionType();
567                 assignment12.setAttributeId("RiskLevel");
568                 assignment12.setCategory(CATEGORY_RESOURCE);
569                 assignment12.setIssuer("");
570
571                 AttributeValueType configNameAttributeValue12 = new AttributeValueType();
572                 configNameAttributeValue12.setDataType(STRING_DATATYPE);
573                 configNameAttributeValue12.getContent().add(policyAdapter.getRiskLevel());
574                 assignment12.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue12));
575
576                 advice.getAttributeAssignmentExpression().add(assignment12);    
577
578                 AttributeAssignmentExpressionType assignment13 = new AttributeAssignmentExpressionType();
579                 assignment13.setAttributeId("guard");
580                 assignment13.setCategory(CATEGORY_RESOURCE);
581                 assignment13.setIssuer("");
582
583                 AttributeValueType configNameAttributeValue13 = new AttributeValueType();
584                 configNameAttributeValue13.setDataType(STRING_DATATYPE);
585                 configNameAttributeValue13.getContent().add(policyAdapter.getGuard());
586                 assignment13.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue13));
587
588                 advice.getAttributeAssignmentExpression().add(assignment13);
589                 
590                 AttributeAssignmentExpressionType assignment14 = new AttributeAssignmentExpressionType();
591                 assignment14.setAttributeId("TTLDate");
592                 assignment14.setCategory(CATEGORY_RESOURCE);
593                 assignment14.setIssuer("");
594
595                 AttributeValueType configNameAttributeValue14 = new AttributeValueType();
596                 configNameAttributeValue14.setDataType(STRING_DATATYPE);
597                 configNameAttributeValue14.getContent().add(policyAdapter.getTtlDate());
598                 assignment14.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue14));
599
600                 advice.getAttributeAssignmentExpression().add(assignment14);
601
602                 advices.getAdviceExpression().add(advice);
603                 return advices;
604         }
605
606         @Override
607         public Object getCorrectPolicyDataObject() {
608                 return policyAdapter.getPolicyData();
609         }       
610 }