Exemplo n.º 1
0
  private CswRecordCollection buildCollection(
      SourceResponse sourceResponse, Map<String, Serializable> arguments) {

    CswRecordCollection recordCollection = new CswRecordCollection();

    recordCollection.setNumberOfRecordsMatched(sourceResponse.getHits());
    recordCollection.setNumberOfRecordsReturned(sourceResponse.getResults().size());
    recordCollection.setStartPosition(sourceResponse.getRequest().getQuery().getStartIndex());

    Object elementSetTypeArg = arguments.get(CswConstants.ELEMENT_SET_TYPE);
    if (elementSetTypeArg instanceof ElementSetType) {
      ElementSetType elementSetType = (ElementSetType) elementSetTypeArg;
      recordCollection.setElementSetType(elementSetType);
    }

    Object elementNamesArg = arguments.get(CswConstants.ELEMENT_NAMES);
    if (elementNamesArg instanceof QName[]) {
      QName[] qnames = (QName[]) elementNamesArg;
      if (qnames.length > 0) {
        List<QName> elementNames = new ArrayList();
        for (QName entry : qnames) {
          elementNames.add(entry);
        }
        recordCollection.setElementName(elementNames);
      }
    }

    Object isByIdQuery = arguments.get(CswConstants.IS_BY_ID_QUERY);
    if (isByIdQuery != null) {
      recordCollection.setById((Boolean) isByIdQuery);
    }

    Object arg = arguments.get((CswConstants.GET_RECORDS));
    if (arg != null && arg instanceof GetRecordsType) {
      recordCollection.setRequest((GetRecordsType) arg);
    }

    Object resultType = arguments.get(CswConstants.RESULT_TYPE_PARAMETER);
    if (resultType instanceof ResultType) {
      recordCollection.setResultType((ResultType) resultType);
    }

    Object outputSchema = arguments.get(CswConstants.OUTPUT_SCHEMA_PARAMETER);
    if (outputSchema instanceof String) {
      recordCollection.setOutputSchema((String) outputSchema);
    } else {
      recordCollection.setOutputSchema(CswConstants.CSW_OUTPUT_SCHEMA);
    }

    Object doWriteNamespaces = arguments.get(CswConstants.WRITE_NAMESPACES);
    if (doWriteNamespaces instanceof Boolean) {
      recordCollection.setDoWriteNamespaces((Boolean) doWriteNamespaces);
    }

    return recordCollection;
  }
Exemplo n.º 2
0
  private void validateInput(SourceResponse sourceResponse, Map<String, Serializable> arguments) {

    if (null == sourceResponse) {
      throw new IllegalArgumentException("Null source response.");
    } else if (null == arguments) {
      throw new IllegalArgumentException("Null argument map.");
    } else if (null == sourceResponse.getResults()) {
      throw new IllegalArgumentException("Null results list.");
    } else if (!isByIdQuery(arguments)
        && null == arguments.get(CswConstants.RESULT_TYPE_PARAMETER)) {
      // An exception is thrown only if the query isn't by ID (i.e. it's not a GetRecordById
      // request) because GetRecordById does not use the ResultType attribute.
      throw new IllegalArgumentException("Null result type argument.");
    } else if (null == sourceResponse.getRequest()) {
      throw new IllegalArgumentException("Null source response query request.");
    } else if (null == sourceResponse.getRequest().getQuery()) {
      throw new IllegalArgumentException("Null source response query.");
    }
  }