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 PolicyUnit createFromDiscoveryUnit(
     ExternalSchedulerDiscoveryUnit discoveryUnit, PolicyUnitType type) {
   PolicyUnit policy = new PolicyUnit();
   policy.setInternal(false);
   policy.setName(discoveryUnit.getName());
   policy.setPolicyUnitType(type);
   policy.setDescription(discoveryUnit.getDescription());
   if (!StringUtils.isEmpty(discoveryUnit.getRegex())) {
     policy.setParameterRegExMap(
         SimpleCustomPropertiesUtil.getInstance().convertProperties(discoveryUnit.getRegex()));
   } else {
     policy.setParameterRegExMap(new LinkedHashMap<String, String>());
   }
   return policy;
 }