示例#1
0
    /**
     * Parse the mapping definition for the ontology type.
     *
     * @param name the field name
     * @param node the JSON node holding the mapping definitions.
     * @param parserContext the parser context object.
     * @return a Builder for an OntologyMapper.
     */
    @SuppressWarnings("unchecked")
    @Override
    public Builder parse(String name, Map<String, Object> node, ParserContext parserContext)
        throws MapperParsingException {
      OntologySettings ontologySettings = null;

      Builder builder = new Builder(name, threadPool);

      for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator();
          iterator.hasNext(); ) {
        Entry<String, Object> entry = iterator.next();
        if (entry.getKey().equals(OntologySettings.ONTOLOGY_SETTINGS_KEY)) {
          ontologySettings =
              new OntologySettingsBuilder()
                  .settingsNode((Map<String, Object>) entry.getValue())
                  .build();
          iterator.remove();
        } else if (entry.getKey().equals(ONTOLOGY_PROPERTIES)) {
          Map<String, StringFieldMapper.Builder> builders =
              parseProperties((Map<String, Object>) entry.getValue(), parserContext);
          builder.propertyBuilders(builders);
          iterator.remove();
        }
      }

      if (ontologySettings == null) {
        throw new MapperParsingException("No ontology settings supplied");
      } else if (StringUtils.isBlank(ontologySettings.getOntologyUri())
          && StringUtils.isBlank(ontologySettings.getOlsBaseUrl())) {
        throw new MapperParsingException("No ontology URI or OLS details supplied");
      } else {
        builder = builder.ontologySettings(ontologySettings);
      }

      return builder;
    }