001package org.kuali.ole.deliver.drools.rules;
002
003import org.apache.commons.io.FileUtils;
004import org.apache.commons.lang3.StringUtils;
005import org.kuali.ole.deliver.bo.drools.DroolsRuleBo;
006import org.kuali.ole.deliver.drools.DroolsConstants;
007
008import java.io.File;
009import java.io.IOException;
010import java.net.URISyntaxException;
011import java.net.URL;
012import java.util.HashMap;
013import java.util.Map;
014
015/**
016 * Created by pvsubrah on 7/9/15.
017 */
018public class IsAddressVerifiedRuleFormulator implements RuleFormulator {
019    @Override
020    public Map formulateRule(DroolsRuleBo droolsRuleBo) {
021
022        Map ruleMap = new HashMap();
023
024        Map map = new HashMap();
025        Object isAddressVerifiedRuleName = droolsRuleBo.getRuleName();
026        StringBuilder stringBuilder = new StringBuilder();
027        stringBuilder.append("\"").append(isAddressVerifiedRuleName).append("\"");
028        map.put("ruleName", stringBuilder.toString());
029        stringBuilder = new StringBuilder();
030        Object isAddressVerifiedErrorMessage = droolsRuleBo.getErrorMessage();
031        stringBuilder.append("\"").append(isAddressVerifiedErrorMessage).append("\"");
032        map.put("errorMessage", stringBuilder.toString());
033        stringBuilder = new StringBuilder();
034        String isAddressVerifiedOverridePermission = droolsRuleBo.getOverridePermission();
035        if(StringUtils.isNotBlank(isAddressVerifiedOverridePermission)){
036            stringBuilder.append("\"").append(isAddressVerifiedOverridePermission).append("\"");
037            map.put("overridePermissions", stringBuilder.toString());
038        }
039
040        String templateStringForAddressVerified = "";
041        URL activeIndicator = getClass().getResource("general-checks/address-verified.txt");
042        try {
043            File activeIndicatorFile = new File(activeIndicator.toURI());
044            templateStringForAddressVerified = FileUtils.readFileToString(activeIndicatorFile);
045        } catch (URISyntaxException e) {
046            e.printStackTrace();
047        } catch (IOException e) {
048            e.printStackTrace();
049        }
050        ruleMap.put(templateStringForAddressVerified, map);
051
052        return ruleMap;
053    }
054
055    @Override
056    public boolean isInterested(String value) {
057        return value.equals(DroolsConstants.GENERAL_CHECK_RULE_TYPE.ADDRESS_VERIFIED);
058    }
059
060    @Override
061    public boolean isInterestedForParameters(String value) {
062        return false;
063    }
064}