@GET @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @ApiOperation( value = "Returns a GEO label LML representation", notes = "Requires metadata/feedback documents as url") @ApiResponses({@ApiResponse(code = 400, message = "Error in feedback/metadata document")}) public Label getLabelByURL( @ApiParam("Url to metadata document") @QueryParam(Constants.PARAM_METADATA) URL metadataURL, @ApiParam("Url to feedback document") @QueryParam(Constants.PARAM_FEEDBACK) URL feedbackURL, @ApiParam("use cached labels") @QueryParam(Constants.PARAM_USECACHE) @DefaultValue(Constants.PARAM_USECACHE_DEFAULT) boolean useCache) throws IOException { if (metadataURL == null && feedbackURL == null) throw new WebApplicationException( Response.ok() .status(Status.BAD_REQUEST) .type(MediaType.TEXT_PLAIN) .entity("No metadata or feedback URL specified") .build()); MetadataTransformer metadataTransformer = this.transformer.get(); return metadataTransformer.getLabel(metadataURL, feedbackURL, useCache); }
@POST @Consumes(MediaType.MULTIPART_FORM_DATA) @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @ApiOperation( value = "Returns a GEO label LML representation", notes = "Requires metadata/feedback documents as data stream") @ApiResponses({@ApiResponse(code = 400, message = "Error in feedback/metadata document")}) public Label getLabelByStream( /* @ApiParam("Metadata document") */ @FormDataParam(Constants.PARAM_METADATA) InputStream metadataInputStream, /* @ApiParam("Feedback document") */ @FormDataParam(Constants.PARAM_FEEDBACK) InputStream feedbackInputStream) throws IOException { MetadataTransformer metadataTransformer = this.transformer.get(); Label label = new Label(); label.setMetadataUrl(new URL("http://not.available.for.direct.upload")); label.setFeedbackUrl(new URL("http://not.available.for.direct.upload")); PushbackInputStream tempStream; boolean hasData = false; if (metadataInputStream != null) { tempStream = new PushbackInputStream(metadataInputStream); int t = tempStream.read(); if (t != -1) { tempStream.unread(t); log.debug("Reading from metadata stream..."); metadataTransformer.updateGeoLabel(tempStream, label); hasData = true; } else tempStream.close(); } if (feedbackInputStream != null) { tempStream = new PushbackInputStream(feedbackInputStream); int t = tempStream.read(); if (t != -1) { tempStream.unread(t); log.debug("Reading from feedback stream..."); metadataTransformer.updateGeoLabel(tempStream, label); hasData = true; } else tempStream.close(); } if (!hasData) throw new WebApplicationException( Response.status(Response.Status.BAD_REQUEST) .type(MediaType.TEXT_PLAIN) .entity("No metadata or feedback file specified") .build()); return label; }