Java Code Examples for org.apache.solr.common.util.NamedList#removeConfigArgs()

The following examples show how to use org.apache.solr.common.util.NamedList#removeConfigArgs() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ParseDateFieldUpdateProcessorFactory.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public void init(@SuppressWarnings({"rawtypes"})NamedList args) {
  
  Locale locale;
  String localeParam = (String)args.remove(LOCALE_PARAM);
  if (null != localeParam) {
    locale = LocaleUtils.toLocale(localeParam);
  } else {
    locale = Locale.US; // because well-known patterns assume this
  }

  Object defaultTimeZoneParam = args.remove(DEFAULT_TIME_ZONE_PARAM);
  ZoneId defaultTimeZone = ZoneOffset.UTC;
  if (null != defaultTimeZoneParam) {
    defaultTimeZone = ZoneId.of(defaultTimeZoneParam.toString());
  }

  @SuppressWarnings({"unchecked"})
  Collection<String> formatsParam = args.removeConfigArgs(FORMATS_PARAM);
  if (null != formatsParam) {
    for (String value : formatsParam) {
      DateTimeFormatter formatter = new DateTimeFormatterBuilder().parseLenient().parseCaseInsensitive()
          .appendPattern(value).toFormatter(locale)
          .withResolverStyle(ResolverStyle.LENIENT).withZone(defaultTimeZone);
      validateFormatter(formatter);
      formats.put(value, formatter);
    }
  }
  super.init(args);
}
 
Example 2
Source File: ParseBooleanFieldUpdateProcessorFactory.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public void init(@SuppressWarnings({"rawtypes"})NamedList args) {
  Object caseSensitiveParam = args.remove(CASE_SENSITIVE_PARAM);
  if (null != caseSensitiveParam) {
    if (caseSensitiveParam instanceof Boolean) {
      caseSensitive = (Boolean)caseSensitiveParam;
    } else {
      caseSensitive = Boolean.valueOf(caseSensitiveParam.toString());
    }
  }

  @SuppressWarnings({"unchecked"})
  Collection<String> trueValuesParam = args.removeConfigArgs(TRUE_VALUES_PARAM);
  if ( ! trueValuesParam.isEmpty()) {
    trueValues.clear();
    for (String trueVal : trueValuesParam) {
      trueValues.add(caseSensitive ? trueVal : trueVal.toLowerCase(Locale.ROOT));
    }
  }

  @SuppressWarnings({"unchecked"})
  Collection<String> falseValuesParam = args.removeConfigArgs(FALSE_VALUES_PARAM);
  if ( ! falseValuesParam.isEmpty()) {
    falseValues.clear();
    for (String val : falseValuesParam) {
      final String falseVal = caseSensitive ? val : val.toLowerCase(Locale.ROOT);
      if (trueValues.contains(falseVal)) {
        throw new SolrException(ErrorCode.SERVER_ERROR,
            "Param '" + FALSE_VALUES_PARAM + "' contains a value also in param '" + TRUE_VALUES_PARAM
                + "': '" + val + "'");
      }
      falseValues.add(falseVal);
    }
  }
  super.init(args);
}
 
Example 3
Source File: StatelessScriptUpdateProcessorFactory.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public void init(@SuppressWarnings({"rawtypes"})NamedList args) {
  @SuppressWarnings({"unchecked"})
  Collection<String> scripts =
    args.removeConfigArgs(SCRIPT_ARG);
  if (scripts.isEmpty()) {
    throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, 
                            "StatelessScriptUpdateProcessorFactory must be " +
                            "initialized with at least one " + SCRIPT_ARG);
  }
  scriptFiles = new ArrayList<>();
  for (String script : scripts) {
    scriptFiles.add(new ScriptFile(script));
  }

  params = args.remove(PARAMS_ARG);

  Object engine = args.remove(ENGINE_NAME_ARG);
  if (engine != null) {
    if (engine instanceof String) {
      engineName = (String)engine;
    } else {
      throw new SolrException
        (SolrException.ErrorCode.SERVER_ERROR, 
         "'" + ENGINE_NAME_ARG + "' init param must be a String (found: " + 
         engine.getClass() + ")");
    }
  }

  super.init(args);

}
 
Example 4
Source File: FieldMutatingUpdateProcessorFactory.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"unchecked"})
public static SelectorParams parseSelectorParams(@SuppressWarnings({"rawtypes"})NamedList args) {
  SelectorParams params = new SelectorParams();
  
  params.fieldName = new HashSet<>(args.removeConfigArgs("fieldName"));
  params.typeName = new HashSet<>(args.removeConfigArgs("typeName"));

  // we can compile the patterns now
  Collection<String> patterns = args.removeConfigArgs("fieldRegex");
  if (! patterns.isEmpty()) {
    params.fieldRegex = new ArrayList<>(patterns.size());
    for (String s : patterns) {
      try {
        params.fieldRegex.add(Pattern.compile(s));
      } catch (PatternSyntaxException e) {
        throw new SolrException
          (SolrException.ErrorCode.SERVER_ERROR,
              "Invalid 'fieldRegex' pattern: " + s, e);
      }
    }
  }
  
  // resolve this into actual Class objects later
  params.typeClass = args.removeConfigArgs("typeClass");

  // Returns null if the arg is not specified
  params.fieldNameMatchesSchemaField = args.removeBooleanArg("fieldNameMatchesSchemaField");
  
  return params;
}
 
Example 5
Source File: AddSchemaFieldsUpdateProcessorFactory.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
private static List<TypeMapping> parseTypeMappings(@SuppressWarnings({"rawtypes"})NamedList args) {
  List<TypeMapping> typeMappings = new ArrayList<>();
  @SuppressWarnings({"unchecked"})
  List<Object> typeMappingsParams = args.getAll(TYPE_MAPPING_PARAM);
  for (Object typeMappingObj : typeMappingsParams) {
    if (null == typeMappingObj) {
      throw new SolrException(SERVER_ERROR, "'" + TYPE_MAPPING_PARAM + "' init param cannot be null");
    }
    if ( ! (typeMappingObj instanceof NamedList) ) {
      throw new SolrException(SERVER_ERROR, "'" + TYPE_MAPPING_PARAM + "' init param must be a <lst>");
    }
    @SuppressWarnings({"rawtypes"})
    NamedList typeMappingNamedList = (NamedList)typeMappingObj;

    Object fieldTypeObj = typeMappingNamedList.remove(FIELD_TYPE_PARAM);
    if (null == fieldTypeObj) {
      throw new SolrException(SERVER_ERROR,
          "Each '" + TYPE_MAPPING_PARAM + "' <lst/> must contain a '" + FIELD_TYPE_PARAM + "' <str>");
    }
    if ( ! (fieldTypeObj instanceof CharSequence)) {
      throw new SolrException(SERVER_ERROR, "'" + FIELD_TYPE_PARAM + "' init param must be a <str>");
    }
    if (null != typeMappingNamedList.get(FIELD_TYPE_PARAM)) {
      throw new SolrException(SERVER_ERROR,
          "Each '" + TYPE_MAPPING_PARAM + "' <lst/> may contain only one '" + FIELD_TYPE_PARAM + "' <str>");
    }
    String fieldType = fieldTypeObj.toString();

    @SuppressWarnings({"unchecked"})
    Collection<String> valueClasses
        = typeMappingNamedList.removeConfigArgs(VALUE_CLASS_PARAM);
    if (valueClasses.isEmpty()) {
      throw new SolrException(SERVER_ERROR, 
          "Each '" + TYPE_MAPPING_PARAM + "' <lst/> must contain at least one '" + VALUE_CLASS_PARAM + "' <str>");
    }

    // isDefault (optional)
    Boolean isDefault = false;
    Object isDefaultObj = typeMappingNamedList.remove(IS_DEFAULT_PARAM);
    if (null != isDefaultObj) {
      if ( ! (isDefaultObj instanceof Boolean)) {
        throw new SolrException(SERVER_ERROR, "'" + IS_DEFAULT_PARAM + "' init param must be a <bool>");
      }
      if (null != typeMappingNamedList.get(IS_DEFAULT_PARAM)) {
        throw new SolrException(SERVER_ERROR,
            "Each '" + COPY_FIELD_PARAM + "' <lst/> may contain only one '" + IS_DEFAULT_PARAM + "' <bool>");
      }
      isDefault = Boolean.parseBoolean(isDefaultObj.toString());
    }
    
    Collection<CopyFieldDef> copyFieldDefs = new ArrayList<>(); 
    while (typeMappingNamedList.get(COPY_FIELD_PARAM) != null) {
      Object copyFieldObj = typeMappingNamedList.remove(COPY_FIELD_PARAM);
      if ( ! (copyFieldObj instanceof NamedList)) {
        throw new SolrException(SERVER_ERROR, "'" + COPY_FIELD_PARAM + "' init param must be a <lst>");
      }
      @SuppressWarnings({"rawtypes"})
      NamedList copyFieldNamedList = (NamedList)copyFieldObj;
      // dest
      Object destObj = copyFieldNamedList.remove(DEST_PARAM);
      if (null == destObj) {
        throw new SolrException(SERVER_ERROR,
            "Each '" + COPY_FIELD_PARAM + "' <lst/> must contain a '" + DEST_PARAM + "' <str>");
      }
      if ( ! (destObj instanceof CharSequence)) {
        throw new SolrException(SERVER_ERROR, "'" + COPY_FIELD_PARAM + "' init param must be a <str>");
      }
      if (null != copyFieldNamedList.get(COPY_FIELD_PARAM)) {
        throw new SolrException(SERVER_ERROR,
            "Each '" + COPY_FIELD_PARAM + "' <lst/> may contain only one '" + COPY_FIELD_PARAM + "' <str>");
      }
      String dest = destObj.toString();
      // maxChars (optional)
      Integer maxChars = 0;
      Object maxCharsObj = copyFieldNamedList.remove(MAX_CHARS_PARAM);
      if (null != maxCharsObj) {
        if ( ! (maxCharsObj instanceof Integer)) {
          throw new SolrException(SERVER_ERROR, "'" + MAX_CHARS_PARAM + "' init param must be a <int>");
        }
        if (null != copyFieldNamedList.get(MAX_CHARS_PARAM)) {
          throw new SolrException(SERVER_ERROR,
              "Each '" + COPY_FIELD_PARAM + "' <lst/> may contain only one '" + MAX_CHARS_PARAM + "' <str>");
        }
        maxChars = Integer.parseInt(maxCharsObj.toString());
      }
      copyFieldDefs.add(new CopyFieldDef(dest, maxChars));
    }
    typeMappings.add(new TypeMapping(fieldType, valueClasses, isDefault, copyFieldDefs));
    
    if (0 != typeMappingNamedList.size()) {
      throw new SolrException(SERVER_ERROR, 
          "Unexpected '" + TYPE_MAPPING_PARAM + "' init sub-param(s): '" + typeMappingNamedList.toString() + "'");
    }
    args.remove(TYPE_MAPPING_PARAM);
  }
  return typeMappings;
}