Skip to content

Commit

Permalink
Merge pull request #39 from 52North/develop
Browse files Browse the repository at this point in the history
Merge develop
  • Loading branch information
bpross-52n authored Jul 16, 2019
2 parents 2fee920 + 8fe443e commit 07b99f9
Showing 1 changed file with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,18 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

import javax.inject.Inject;

import org.n52.janmayen.http.MediaType;
import org.n52.shetland.ogc.wps.response.ExecuteResponse;
import org.n52.shetland.ogc.wps.response.GetResultResponse;
import org.n52.shetland.ogc.ows.service.OwsServiceResponse;
import org.n52.shetland.ogc.wps.ResponseMode;
import org.n52.shetland.ogc.wps.Result;
import org.n52.shetland.ogc.wps.data.ProcessData;
Expand All @@ -45,9 +49,11 @@
*
* @author Christian Autermann
*/
public class StreamingRawWriter implements StreamWriter<ExecuteResponse> {
public class StreamingRawWriter implements StreamWriter<OwsServiceResponse> {

private static final StreamWriterKey KEY = new StreamWriterKey(ExecuteResponse.class, new MediaType());
private static final Set<StreamWriterKey> KEYS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
new StreamWriterKey(ExecuteResponse.class, new MediaType()), new StreamWriterKey(GetResultResponse.class,
new MediaType()))));

private final StreamWriterRepository streamWriterRepository;

Expand All @@ -57,10 +63,19 @@ public StreamingRawWriter(StreamWriterRepository streamWriterRepository) {
}

@Override
public void write(ExecuteResponse object,
public void write(OwsServiceResponse object,
OutputStream outputStream) throws EncodingException {
Result result = object.getResult().filter(r -> r.getResponseMode() == ResponseMode.RAW).orElseThrow(
() -> new UnsupportedStreamWriterInputException(object));

Result result = null;

if (object instanceof GetResultResponse) {
result = ((GetResultResponse) object).getResult();
} else if (object instanceof ExecuteResponse) {
result = ((ExecuteResponse) object).getResult().filter(r -> r.getResponseMode() == ResponseMode.RAW)
.orElseThrow(() -> new UnsupportedStreamWriterInputException(object));
} else {
throw new UnsupportedStreamWriterInputException(object);
}

ProcessData data = result.getOutputs().iterator().next();
if (data.isValue()) {
Expand All @@ -83,6 +98,6 @@ private <T> StreamWriter<? super T> getStreamWriter(T data) {

@Override
public Set<StreamWriterKey> getKeys() {
return Collections.singleton(KEY);
return KEYS;
}
}

0 comments on commit 07b99f9

Please sign in to comment.