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 markExternalPoliciesAsDisabled(List<PolicyUnit> units) {
   for (PolicyUnit policyUnit : units) {
     if (!policyUnit.isInternal()) {
       policyUnit.setEnabled(false);
       getPolicyUnitDao().update(policyUnit);
     }
   }
 }