
org.n52.youngs.harvest.KvpCswSource Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of main Show documentation
Show all versions of main Show documentation
A mapping platform to load CSW records into Elasticsearch
The newest version!
/*
* Copyright 2015-2019 52°North Initiative for Geospatial Open Source
* Software GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.n52.youngs.harvest;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigInteger;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Supplier;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.namespace.NamespaceContext;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.stream.StreamSource;
import net.opengis.csw.v_2_0_2.AbstractRecordType;
import net.opengis.csw.v_2_0_2.GetRecordsResponseType;
import org.apache.http.client.fluent.Request;
import org.n52.youngs.api.Report;
import org.n52.youngs.api.Report.Level;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Node;
/**
*
* @author Daniel Nüst
*/
public class KvpCswSource extends CswSource {
private static final Logger log = LoggerFactory.getLogger(KvpCswSource.class);
private static final Joiner.MapJoiner urlParameterJoiner = Joiner.on("&").withKeyValueSeparator("=");
public KvpCswSource(String url, NamespaceContext nsContext) throws MalformedURLException, JAXBException {
super(url, nsContext);
}
public KvpCswSource(String url, Collection namespaces, NamespaceContext nsContext, String typeName, String outputSchema) throws MalformedURLException, JAXBException {
super(url, namespaces, nsContext, typeName, outputSchema);
}
public KvpCswSource(URL url, String namespacesParameter, String typeName, String outputSchema) throws JAXBException {
super(url, namespacesParameter, typeName, outputSchema);
}
public KvpCswSource(URL url, Collection namespaces, NamespaceContext nsContext, String typeName, String outputSchema) throws JAXBException {
super(url, namespaces, nsContext, typeName, outputSchema);
}
@Override
public Collection getRecords(long startPosition, long maxRecords, Report report) {
log.debug("Requesting {} records from catalog starting at {}", maxRecords, startPosition);
Collection records = Lists.newArrayList();
String recordsRequest = createRequest(startPosition, maxRecords);
log.trace("GetRecords request: {}", recordsRequest);
try {
InputStream response = Request.Get(recordsRequest).execute().returnContent().asStream();
JAXBElement jaxb_response = unmarshaller.unmarshal(new StreamSource(response),
GetRecordsResponseType.class);
BigInteger numberOfRecordsReturned = jaxb_response.getValue().getSearchResults().getNumberOfRecordsReturned();
log.debug("Got response with {} records", numberOfRecordsReturned);
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy