private PolicyUnit compareToDB(
      List<PolicyUnit> dbEnteries,
      ExternalSchedulerDiscoveryUnit discoveryUnit,
      PolicyUnitType type) {
    for (PolicyUnit policyUnit : dbEnteries) {
      if (policyUnit.isInternal()) {
        continue;
      }

      if (policyUnit.getPolicyUnitType() != type) {
        continue;
      }

      if (!policyUnit.getName().equals(discoveryUnit.getName())) {
        continue;
      }

      Map<String, String> discoveryPropMap =
          StringUtils.isEmpty(discoveryUnit.getRegex())
              ? new LinkedHashMap<String, String>()
              : SimpleCustomPropertiesUtil.getInstance()
                  .convertProperties(discoveryUnit.getRegex());
      if (!discoveryPropMap.equals(policyUnit.getParameterRegExMap())
          || !discoveryUnit.getDescription().equals(policyUnit.getDescription())
          || !policyUnit.isEnabled()) {
        sendToDb(discoveryUnit, policyUnit.getId(), type);
      }

      return policyUnit;
    }
    sendToDb(discoveryUnit, null, type);
    return null;
  }
 private void fillClusterPolicy(
     Map<Guid, ClusterPolicy> map, List<ClusterPolicyUnit> clusterPolicyUnits) {
   Map<Guid, PolicyUnit> policyUnitMap = new HashMap<Guid, PolicyUnit>();
   for (PolicyUnit policyUnit : policyUnitDao.getAll()) {
     policyUnitMap.put(policyUnit.getId(), policyUnit);
   }
   for (ClusterPolicyUnit clusterPolicyUnit : clusterPolicyUnits) {
     ClusterPolicy clusterPolicy = map.get(clusterPolicyUnit.getClusterPolicyId());
     if (policyUnitMap.get(clusterPolicyUnit.getPolicyUnitId()).getPolicyUnitType()
         == PolicyUnitType.FILTER) {
       if (clusterPolicy.getFilters() == null) {
         clusterPolicy.setFilters(new ArrayList<Guid>());
       }
       clusterPolicy.getFilters().add(clusterPolicyUnit.getPolicyUnitId());
       if (clusterPolicyUnit.getFilterSequence() != 0) {
         if (clusterPolicy.getFilterPositionMap() == null) {
           clusterPolicy.setFilterPositionMap(new HashMap<Guid, Integer>());
         }
         clusterPolicy
             .getFilterPositionMap()
             .put(clusterPolicyUnit.getPolicyUnitId(), clusterPolicyUnit.getFilterSequence());
       }
     }
     if (policyUnitMap.get(clusterPolicyUnit.getPolicyUnitId()).getPolicyUnitType()
         == PolicyUnitType.WEIGHT) {
       if (clusterPolicy.getFunctions() == null) {
         clusterPolicy.setFunctions(new ArrayList<Pair<Guid, Integer>>());
       }
       clusterPolicy
           .getFunctions()
           .add(
               new Pair<Guid, Integer>(
                   clusterPolicyUnit.getPolicyUnitId(), clusterPolicyUnit.getFactor()));
     }
     if (policyUnitMap.get(clusterPolicyUnit.getPolicyUnitId()).getPolicyUnitType()
         == PolicyUnitType.LOAD_BALANCING) {
       clusterPolicy.setBalance(clusterPolicyUnit.getPolicyUnitId());
     }
   }
 }