DataSetService extends BaseDataSetService { @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 public DataSet getMetadata(@PathVariable(value = "id") @ApiParam(name = "id", value = "Id of the data set metadata") String dataSetId) { if (dataSetId == null) { HttpResponseContext.status(HttpStatus.NO_CONTENT); return null; } LOG.debug("get dataset metadata for {}", dataSetId); DataSetMetadata metadata; securityProxy.asTechnicalUserForDataSet(); try { metadata = dataSetMetadataRepository.get(dataSetId); } finally { securityProxy.releaseIdentity(); } if (metadata == null) { throw new TDPException(DataSetErrorCodes.DATASET_DOES_NOT_EXIST, build().put("id", dataSetId)); } if (!metadata.getLifecycle().schemaAnalyzed()) { LOG.warn("Schema analyzed is not finished for #{}", dataSetId); } DataSet dataSet = new DataSet(); dataSet.setMetadata(conversionService.convert(metadata, UserDataSetMetadata.class)); LOG.debug("found dataset {} for #{}", dataSet.getMetadata().getName(), dataSetId); return dataSet; }  @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 getMetadata() throws Exception { DataSetMetadataBuilder builder = metadataBuilder.metadata().id("1234"); builder .row(ColumnMetadata.Builder .column() .id(1234) .name("id") .empty(0) .invalid(0) .valid(0) .type(Type.STRING)) .created(0) .name("name") .author("author") .footerSize(0) .headerSize(1) .qualityAnalyzed(true) .schemaAnalyzed(true) .formatFamilyId(new CSVFormatFamily().getBeanId()) .mediaType("text/csv"); DataSetMetadata metadata = builder.build(); metadata.getContent().addParameter(CSVFormatFamily.SEPARATOR_PARAMETER, ";"); dataSetMetadataRepository.save(metadata); String contentAsString = when().get("/datasets/{id}/metadata", "1234").asString(); InputStream expected = this.getClass().getResourceAsStream("../metadata1.json"); assertThat(contentAsString, sameJSONAsFile(expected)); Boolean isFavorites = from(contentAsString).get("metadata.favorite"); assertFalse(isFavorites); UserData userData = new UserData(security.getUserId(), versionService.version().getVersionId()); HashSet<String> favorites = new HashSet<>(); favorites.add("1234"); userData.setFavoritesDatasets(favorites); userDataRepository.save(userData); contentAsString = when().get("/datasets/{id}/metadata", "1234").asString(); isFavorites = from(contentAsString).get("metadata.favorite"); assertTrue(isFavorites); }