Skip to content

Commit

Permalink
fix up remaining errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jodygarnett committed Apr 7, 2017
1 parent a2c91fd commit a28fd93
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 28 deletions.

This file was deleted.

Expand Up @@ -75,7 +75,7 @@ public ImportTask taskGet(@PathVariable Long id, @PathVariable Integer taskId) {


@GetMapping(path = {"/{taskId}/progress"}, produces = { MediaType.APPLICATION_JSON_VALUE, @GetMapping(path = {"/{taskId}/progress"}, produces = { MediaType.APPLICATION_JSON_VALUE,
CatalogController.TEXT_JSON , MediaType.TEXT_HTML_VALUE}) CatalogController.TEXT_JSON , MediaType.TEXT_HTML_VALUE})
public ImportJSONWrapper progressGet(@PathVariable Long id, @PathVariable Integer taskId) { public ImportWrapper progressGet(@PathVariable Long id, @PathVariable Integer taskId) {


JSONObject progress = new JSONObject(); JSONObject progress = new JSONObject();
ImportTask inProgress = importer.getCurrentlyProcessingTask(id); ImportTask inProgress = importer.getCurrentlyProcessingTask(id);
Expand All @@ -96,7 +96,7 @@ public ImportJSONWrapper progressGet(@PathVariable Long id, @PathVariable Intege
} catch (JSONException jex) { } catch (JSONException jex) {
throw new RestException("Internal Error", HttpStatus.INTERNAL_SERVER_ERROR, jex); throw new RestException("Internal Error", HttpStatus.INTERNAL_SERVER_ERROR, jex);
} }
return new ImportJSONWrapper(progress); return (writer,builder,converter) -> writer.write(progress.toString());
} }


@GetMapping(path = {"/{taskId}/target"}, produces = { MediaType.APPLICATION_JSON_VALUE, @GetMapping(path = {"/{taskId}/target"}, produces = { MediaType.APPLICATION_JSON_VALUE,
Expand Down
@@ -0,0 +1,74 @@
/* (c) 2017 Open Source Geospatial Foundation - all rights reserved
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
*/
package org.geoserver.importer.rest.converters;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;

import org.geoserver.importer.ImportContext;
import org.geoserver.importer.ImportTask;
import org.geoserver.importer.Importer;
import org.geoserver.importer.rest.converters.ImportJSONWriter.FlushableJSONBuilder;
import org.geoserver.importer.transform.ImportTransform;
import org.geoserver.rest.catalog.CatalogController;
import org.geoserver.rest.converters.BaseMessageConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpInputMessage;
import org.springframework.http.HttpOutputMessage;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.http.converter.HttpMessageNotWritableException;
import org.springframework.stereotype.Component;

import net.sf.json.JSONObject;

/**
* Convert {@link ImportTask} to/from JSON.
*/
@Component
public class ImportTransformJSONMessageConverter extends BaseMessageConverter<ImportTransform> {

Importer importer;

@Autowired
public ImportTransformJSONMessageConverter(Importer importer) {
super(MediaType.APPLICATION_JSON, CatalogController.MEDIATYPE_TEXT_JSON);
this.importer = importer;
}

@Override
public int getPriority() {
return super.getPriority() - 5;
}

@Override
protected boolean supports(Class<?> clazz) {
return ImportTransform.class.isAssignableFrom(clazz);
}

//
// Reading
//
@Override
protected ImportTransform readInternal(Class<? extends ImportTransform> clazz,
HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
try (InputStream in = inputMessage.getBody()) {
ImportJSONReader reader = new ImportJSONReader(importer);
JSONObject json = reader.parse(in);
ImportTransform transform = reader.transform(json);

return transform;
}
}

//
// writing
//
@Override
protected boolean canWrite(MediaType mediaType) {
return false;
}
}
@@ -0,0 +1,69 @@
/* (c) 2017 Open Source Geospatial Foundation - all rights reserved
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
*/
package org.geoserver.importer.rest.converters;

import java.io.IOException;
import java.io.InputStream;

import org.geoserver.importer.ImportTask;
import org.geoserver.importer.Importer;
import org.geoserver.importer.transform.TransformChain;
import org.geoserver.rest.catalog.CatalogController;
import org.geoserver.rest.converters.BaseMessageConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpInputMessage;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.stereotype.Component;

import net.sf.json.JSONObject;

/**
* Convert {@link ImportTask} to/from JSON.
*/
@Component
public class TransformChainJSONMessageConverter extends BaseMessageConverter<TransformChain<?>> {

Importer importer;

@Autowired
public TransformChainJSONMessageConverter(Importer importer) {
super(MediaType.APPLICATION_JSON, CatalogController.MEDIATYPE_TEXT_JSON);
this.importer = importer;
}

@Override
public int getPriority() {
return super.getPriority() - 5;
}

@Override
protected boolean supports(Class<?> clazz) {
return TransformChain.class.isAssignableFrom(clazz);
}

//
// Reading
//
@Override
protected TransformChain<?> readInternal(Class<? extends TransformChain<?>> clazz,
HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
try (InputStream in = inputMessage.getBody()) {
ImportJSONReader reader = new ImportJSONReader(importer);
JSONObject json = reader.parse(in);
TransformChain<?> transform = (TransformChain<?>) reader.transform(json);

return transform;
}
}

//
// writing
//
@Override
protected boolean canWrite(MediaType mediaType) {
return false;
}
}
Expand Up @@ -192,7 +192,7 @@ public void testGetTask() throws Exception {


@Test @Test
public void testGetTaskProgress() throws Exception { public void testGetTaskProgress() throws Exception {
JSONObject json = (JSONObject) getAsJSON(RestBaseController.ROOT_PATH+"/imports/0/tasks/0/progress"); JSONObject json = (JSONObject) getAsJSON(RestBaseController.ROOT_PATH+"/imports/0/tasks/0/progress",200);
assertEquals("READY", json.get("state")); assertEquals("READY", json.get("state"));
//TODO: trigger import and check progress //TODO: trigger import and check progress
} }
Expand Down
Expand Up @@ -1277,6 +1277,16 @@ protected Document getAsDOM(final String path, String encoding) throws Exception
protected JSON getAsJSON(final String path, int statusCode) protected JSON getAsJSON(final String path, int statusCode)
throws Exception { throws Exception {
MockHttpServletResponse response = getAsServletResponse(path, statusCode); MockHttpServletResponse response = getAsServletResponse(path, statusCode);
int status = response.getStatus();
if( statusCode != status ){
String content = response.getContentAsString();
if( content == null || content.length() == 0 ){
throw new ServiceException("expected status <"+statusCode+"> but was <"+status+">");
}
else {
throw new ServiceException("expected status <"+statusCode+"> but was <"+status+">:"+content);
}
}
return json(response); return json(response);
} }


Expand Down

0 comments on commit a28fd93

Please sign in to comment.