DataSetService extends BaseDataSetService { @RequestMapping(value = "/datasets", method = POST, produces = TEXT_PLAIN_VALUE) @ApiOperation(value = "Create a data set", produces = TEXT_PLAIN_VALUE, notes = "Create a new data set based on content provided in POST body. For documentation purposes, body is typed as 'text/plain' but operation accepts binary content too. Returns the id of the newly created data set.") @Timed @VolumeMetered public String create( @ApiParam(value = "User readable name of the data set (e.g. 'Finance Report 2015', 'Test Data Set').") @RequestParam(defaultValue = "") String name, @ApiParam(value = "An optional tag to be added in data set metadata once created.") @RequestParam(defaultValue = "") String tag, @ApiParam(value = "Size of the data set, in bytes.") @RequestParam(required = false) Long size, @RequestHeader(CONTENT_TYPE) String contentType, @ApiParam(value = "content") InputStream content) { checkDataSetName(name); final String id = UUID.randomUUID().toString(); final Marker marker = Markers.dataset(id); LOG.debug(marker, "Creating..."); if (size != null && size < 0) { LOG.warn("invalid size provided {}", size); throw new TDPException(UNEXPECTED_CONTENT, build().put("size", size)); } checkIfNameIsAvailable(name); final DataSetLocation location; try { location = datasetLocator.getDataSetLocation(contentType, content); } catch (IOException e) { throw new TDPException(DataSetErrorCodes.UNABLE_TO_READ_DATASET_LOCATION, e); } DataSetMetadata dataSetMetadata = null; final TDPException hypotheticalException; try { if (size != null && size > 0) { quotaService.checkIfAddingSizeExceedsAvailableStorage(size); } dataSetMetadata = metadataBuilder .metadata() .id(id) .name(name) .author(security.getUserId()) .location(location) .created(System.currentTimeMillis()) .tag(tag) .build(); dataSetMetadata.getLifecycle().setImporting(true); LOG.debug(marker, "Storing content..."); final long maxDataSetSizeAllowed = getMaxDataSetSizeAllowed(); final StrictlyBoundedInputStream sizeCalculator = new StrictlyBoundedInputStream(content, maxDataSetSizeAllowed); contentStore.storeAsRaw(dataSetMetadata, sizeCalculator); dataSetMetadata.setDataSetSize(sizeCalculator.getTotal()); LOG.debug(marker, "Content stored."); dataSetMetadataRepository.save(dataSetMetadata); LOG.debug(marker, "dataset metadata stored {}", dataSetMetadata); analyzeDataSet(id, emptyList()); LOG.debug(marker, "Created!"); asyncPublisher.multicastEvent(new DatasetImportedEvent(id)); return id; } catch (StrictlyBoundedInputStream.InputStreamTooLargeException e) { hypotheticalException = new TDPException(MAX_STORAGE_MAY_BE_EXCEEDED, e, build().put(STORAGE_LIMIT, e.getMaxSize())); } catch (TDPException e) { hypotheticalException = e; } catch (Exception e) { hypotheticalException = new TDPException(UNABLE_CREATE_DATASET, e); } finally { dataSetContentToNull(content); } dataSetMetadataRepository.remove(id); if (dataSetMetadata != null) { try { contentStore.delete(dataSetMetadata); } catch (Exception e) { LOG.error("Unable to delete uploaded data.", e); } } throw hypotheticalException; }  @RequestMapping(value = "/datasets", method = RequestMethod.GET) @ApiOperation(value = "List all data sets and filters on certified, or favorite or a limited number when asked", notes = "Returns the list of data sets (and filters) the current user is allowed to see. Creation date is a Epoch time value (in UTC time zone).") @Timed Stream<DatasetDTO> list(
            @ApiParam(value = "Sort key (by name, creation or modification date)") @RequestParam(
                    defaultValue = "creationDate") Sort sort,
            @ApiParam(value = "Order for sort key (desc or asc or modif)") @RequestParam(
                    defaultValue = "desc") Order order,
            @ApiParam(value = "Filter on name containing the specified name") @RequestParam(
                    required = false) String name,
            @ApiParam(value = "Filter on name containing the specified name strictness") @RequestParam(
                    defaultValue = "false") boolean nameStrict,
            @ApiParam(value = "Filter on certified data sets") @RequestParam(defaultValue = "false") boolean certified,
            @ApiParam(value = "Filter on favorite data sets") @RequestParam(defaultValue = "false") boolean favorite,
            @ApiParam(value = "Only return a limited number of data sets") @RequestParam(
                    defaultValue = "false") boolean limit); @RequestMapping(value = "/datasets/details", method = RequestMethod.GET) @ApiOperation(value = "List all data sets and filters on certified, or favorite or a limited number when asked", notes = "Returns the list of data sets (and filters) the current user is allowed to see. Creation date is a Epoch time value (in UTC time zone).") @Timed Stream<UserDataSetMetadata> listWithFullDetails(
            @ApiParam(value = "Sort key (by name, creation or modification date)") @RequestParam(
                    defaultValue = "creationDate") Sort sort,
            @ApiParam(value = "Order for sort key (desc or asc or modif)") @RequestParam(
                    defaultValue = "desc") Order order,
            @ApiParam(value = "Filter on name containing the specified name") @RequestParam(
                    required = false) String name,
            @ApiParam(value = "Filter on name containing the specified name strictness") @RequestParam(
                    defaultValue = "false") boolean nameStrict,
            @ApiParam(value = "Filter on certified data sets") @RequestParam(defaultValue = "false") boolean certified,
            @ApiParam(value = "Filter on favorite data sets") @RequestParam(defaultValue = "false") boolean favorite,
            @ApiParam(value = "Only return a limited number of data sets") @RequestParam(
                    defaultValue = "false") boolean limit); @RequestMapping(value = "/datasets/{id}/compatibledatasets", method = RequestMethod.GET) @ApiOperation(value = "List all compatible data sets", notes = "Returns the list of data sets the current user is allowed to see and which are compatible with the specified data set id.") @Timed Iterable<UserDataSetMetadata> listCompatibleDatasets(
            @PathVariable(value = "id") @ApiParam(name = "id", value = "Id of the data set metadata") String dataSetId,
            @ApiParam(value = "Sort key (by name or date).") @RequestParam(defaultValue = "creationDate") Sort sort,
            @ApiParam(value = "Order for sort key (desc or asc).") @RequestParam(defaultValue = "desc") Order order); @RequestMapping(value = "/datasets", method = POST, produces = TEXT_PLAIN_VALUE) @ApiOperation(value = "Create a data set", produces = TEXT_PLAIN_VALUE, notes = "Create a new data set based on content provided in POST body. For documentation purposes, body is typed as 'text/plain' but operation accepts binary content too. Returns the id of the newly created data set.") @Timed @VolumeMetered String create(
            @ApiParam(value = "User readable name of the data set (e.g. 'Finance Report 2015', 'Test Data Set').") @RequestParam(defaultValue = "") String name,
            @ApiParam(value = "An optional tag to be added in data set metadata once created.") @RequestParam(defaultValue = "") String tag,
            @ApiParam(value = "Size of the data set, in bytes.") @RequestParam(required = false) Long size,
            @RequestHeader(CONTENT_TYPE) String contentType,
            @ApiParam(value = "content") InputStream content); @RequestMapping(value = "/datasets/{id}/content", method = RequestMethod.GET) @ApiOperation(value = "Get a data set by id", notes = "Get a data set content based on provided id. Id should be a UUID returned by the list operation. Not valid or non existing data set id returns empty content.") @Timed @ResponseBody Callable<DataSet> get(
            @RequestParam(defaultValue = "true") @ApiParam(name = "metadata",
                    value = "Include metadata information in the response") boolean metadata, //
            @RequestParam(defaultValue = "false") @ApiParam(name = "includeInternalContent",
                    value = "Include internal content in the response") boolean includeInternalContent, //
            @RequestParam(defaultValue = "-1") @ApiParam(name = STORAGE_LIMIT, value = STORAGE_LIMIT) long limit, //
            @ApiParam(value = "Filter for retrieved content.") @RequestParam(value = "filter",
                    defaultValue = "") String filter,
            @PathVariable(value = "id") @ApiParam(name = "id",
                    value = "Id of the requested data set") String dataSetId); @RequestMapping(value = "/datasets/{id}/metadata", method = RequestMethod.GET) @ApiOperation(value = "Get metadata information of a data set by id", notes = "Get metadata information of a data set by id. Not valid or non existing data set id returns empty content.") @Timed @ResponseBody DataSet getMetadata(@PathVariable(value = "id") @ApiParam(name = "id",
            value = "Id of the data set metadata") String dataSetId); @RequestMapping(value = "/datasets/{id}", method = RequestMethod.DELETE) @ApiOperation(value = "Delete a data set by id", notes = "Delete a data set content based on provided id. Id should be a UUID returned by the list operation. Not valid or non existing data set id returns empty content.") @Timed void delete(@PathVariable(value = "id") @ApiParam(name = "id",
            value = "Id of the data set to delete") String dataSetId); @RequestMapping(value = "/datasets/{id}/copy", method = POST, produces = TEXT_PLAIN_VALUE) @ApiOperation(value = "Copy a data set", produces = TEXT_PLAIN_VALUE, notes = "Copy a new data set based on the given id. Returns the id of the newly created data set.") @Timed String copy(
            @PathVariable(value = "id") @ApiParam(name = "id", value = "Id of the data set to clone") String dataSetId,
            @ApiParam(value = "The name of the cloned dataset.") @RequestParam(required = false) String copyName); @RequestMapping(value = "/datasets/{id}/raw", method = PUT) @ApiOperation(value = "Update a data set by id", notes = "Update a data set content based on provided id and PUT body. Id should be a UUID returned by the list operation. Not valid or non existing data set id returns empty content. For documentation purposes, body is typed as 'text/plain' but operation accepts binary content too.") @Timed @VolumeMetered String updateRawDataSet(
            @PathVariable(value = "id") @ApiParam(name = "id", value = "Id of the data set to update") String dataSetId, //
            @RequestParam(value = "name", required = false) @ApiParam(name = "name",
                    value = "New value for the data set name") String name, //
            @RequestParam(value = "size", required = false) @ApiParam(name = "size",
                    value = "The size of the dataSet") Long size, //
            @ApiParam(value = "content") InputStream dataSetContent); @RequestMapping(value = "/datasets/errors", method = RequestMethod.GET) @ApiOperation(value = "Get all dataset related error codes.", notes = "Returns the list of all dataset related error codes.") @Timed Iterable<JsonErrorCodeDescription> listErrors(); @RequestMapping(value = "/datasets/{id}/preview", method = RequestMethod.GET) @ApiOperation(value = "Get a data preview set by id", notes = "Get a data set preview content based on provided id. Not valid or non existing data set id returns empty content. Data set not in drat status will return a redirect 301") @Timed @ResponseBody DataSet preview(@RequestParam(defaultValue = "true") @ApiParam(name = "metadata",
                    value = "Include metadata information in the response") boolean metadata, //
                    @RequestParam(defaultValue = "") @ApiParam(name = "sheetName",
                            value = "Sheet name to preview") String sheetName, //
                    @PathVariable(value = "id") @ApiParam(name = "id",
                            value = "Id of the requested data set") String dataSetId); @RequestMapping(value = "/datasets/{id}", method = PUT) @ApiOperation(value = "Update a data set metadata by id", notes = "Update a data set metadata according to the content of the PUT body. Id should be a UUID returned by the list operation. Not valid or non existing data set id return an error response.") @Timed void updateDataSet(
            @PathVariable(value = "id") @ApiParam(name = "id", value = "Id of the data set to update") String dataSetId,
            @RequestBody DataSetMetadata dataSetMetadata); @RequestMapping(value = "/datasets/favorites", method = RequestMethod.GET) @ApiOperation(value = "return all favorites datasets of the current user", notes = "Returns the list of favorites datasets.") @Timed Iterable<String> favorites(); @RequestMapping(value = "/datasets/{id}/favorite", method = PUT) @ApiOperation(value = "set or unset a dataset as favorite", notes = "Specify if a dataset is or is not a favorite for the current user.") @Timed void setFavorites(@RequestParam(defaultValue = "false") @ApiParam(name = "unset",
            value = "if true then unset the dataset as favorite, if false (default value) set the favorite flag") boolean unset, //
            @PathVariable(value = "id") @ApiParam(name = "id",
                    value = "Id of the favorite data set, do nothing is the id does not exist.") String dataSetId); @RequestMapping(value = "/datasets/{datasetId}/column/{columnId}", method = POST) @ApiOperation(value = "Update a column type and/or domain") @Timed void updateDatasetColumn(
            @PathVariable(value = "datasetId") @ApiParam(name = "datasetId",
                    value = "Id of the dataset") final String dataSetId,
            @PathVariable(value = "columnId") @ApiParam(name = "columnId",
                    value = "Id of the column") final String columnId,
            @RequestBody final UpdateColumnParameters parameters); @RequestMapping(value = "/datasets/search", method = GET) @ApiOperation(value = "Search the dataset metadata", notes = "Search the dataset metadata.") @Timed @Deprecated Stream<DatasetDTO> search( //
            @RequestParam @ApiParam(value = "What to search in data sets") final String name, //
            @RequestParam @ApiParam(value = "The searched name should be the full name") final boolean strict); @RequestMapping(value = "/datasets/imports/{import}/parameters", method = GET, produces = APPLICATION_JSON_VALUE) @ApiOperation(value = "Get the import parameters", notes = "This list can be used by user to change dataset encoding.") @Timed @PublicAPI // This method have to return Object because it can either return the legacy List<Parameter> or the new TComp // oriented // ComponentProperties Object getImportParameters(@PathVariable("import") final String importType); @RequestMapping(value = "/datasets/{id}/datastore/properties", method = GET) @ApiOperation(value = "Get the dataset import parameters", notes = "This list can be used by user to change dataset encoding.") @Timed // This method have to return Object because it can either return the legacy List<Parameter> or the new TComp // oriented // ComponentProperties Object getDataStoreParameters(@PathVariable("id") final String dataSetId); @RequestMapping(value = "/datasets/imports", method = GET) @ApiOperation(value = "list the supported encodings for dataset", notes = "This list can be used by user to change dataset encoding.") @Timed @PublicAPI Stream<Import> listSupportedImports(); @RequestMapping(value = "/datasets/{datasetId}/columns/{columnId}/types", method = GET) @ApiOperation(value = "list the types of the wanted column", notes = "This list can be used by user to change the column type.") @Timed @PublicAPI List<SemanticDomain> getDataSetColumnSemanticCategories(
            @ApiParam(value = "The dataset id") @PathVariable String datasetId,
            @ApiParam(value = "The column id") @PathVariable String columnId);  }
@Test public void create() throws Exception { int before = dataSetMetadataRepository.size(); String dataSetId = given() .body(IOUtils.toString(this.getClass().getResourceAsStream(TAGADA_CSV), UTF_8)) .queryParam("Content-Type", "text/csv") .when() .post("/datasets") .asString(); int after = dataSetMetadataRepository.size(); assertThat(after - before, is(1)); assertQueueMessages(dataSetId); }