Example usage for org.springframework.http HttpStatus MOVED_PERMANENTLY

List of usage examples for org.springframework.http HttpStatus MOVED_PERMANENTLY

Introduction

In this page you can find the example usage for org.springframework.http HttpStatus MOVED_PERMANENTLY.

Prototype

HttpStatus MOVED_PERMANENTLY

To view the source code for org.springframework.http HttpStatus MOVED_PERMANENTLY.

Click Source Link

Document

301 Moved Permanently .

Usage

From source file:org.orcid.frontend.web.controllers.PublicProfileController.java

@RequestMapping(value = "/{orcid:(?:\\d{4}-){3,}\\d{3}[x]}")
public ModelAndView publicPreviewRedir(HttpServletRequest request,
        @RequestParam(value = "page", defaultValue = "1") int pageNo,
        @RequestParam(value = "maxResults", defaultValue = "15") int maxResults,
        @PathVariable("orcid") String orcid) {
    RedirectView rv = new RedirectView();
    rv.setStatusCode(HttpStatus.MOVED_PERMANENTLY);
    rv.setUrl(getBasePath() + orcid.toUpperCase());
    return new ModelAndView(rv);
}

From source file:org.springframework.test.web.servlet.htmlunit.MockWebResponseBuilder.java

private WebResponseData webResponseData() throws IOException {
    List<NameValuePair> responseHeaders = responseHeaders();
    int statusCode = (this.response.getRedirectedUrl() != null ? HttpStatus.MOVED_PERMANENTLY.value()
            : this.response.getStatus());
    String statusMessage = statusMessage(statusCode);
    return new WebResponseData(this.response.getContentAsByteArray(), statusCode, statusMessage,
            responseHeaders);/*from   ww w  .ja va  2 s  .c  o m*/
}

From source file:org.talend.dataprep.api.service.command.dataset.DataSetPreview.java

public DataSetPreview(String dataSetId, boolean metadata, String sheetName) {
    super(GenericCommand.TRANSFORM_GROUP);
    execute(() -> onExecute(dataSetId, metadata, sheetName));
    onError(e -> new TDPException(APIErrorCodes.UNABLE_TO_RETRIEVE_DATASET_CONTENT, e,
            ExceptionContext.build().put("id", dataSetId)));
    on(HttpStatus.ACCEPTED, HttpStatus.NO_CONTENT).then(emptyStream());
    on(HttpStatus.OK).then(pipeStream());
    // Move permanently/temporarily behaviors
    BiFunction<HttpRequestBase, HttpResponse, InputStream> move = (req, res) -> {
        Exception cause = new Exception(res.getStatusLine().getStatusCode() + ":" //
                + res.getStatusLine().getReasonPhrase());
        throw new TDPException(APIErrorCodes.DATASET_REDIRECT, cause,
                ExceptionContext.build().put("id", dataSetId));
    };//from  www . jav a2s  . co m
    on(HttpStatus.MOVED_PERMANENTLY, HttpStatus.FOUND).then(move);
}

From source file:org.talend.dataprep.dataset.service.DataSetService.java

/**
 * Returns preview of the the data set content for given id (first 100 rows). Service might return
 * {@link org.apache.commons.httpclient.HttpStatus#SC_ACCEPTED} if the data set exists but analysis is not yet fully
 * completed so content is not yet ready to be served.
 *
 * @param metadata If <code>true</code>, includes data set metadata information.
 * @param sheetName the sheet name to preview
 * @param dataSetId A data set id.//from  w  ww  . jav a2 s.  co  m
 */
@RequestMapping(value = "/datasets/{id}/preview", method = RequestMethod.GET, produces = APPLICATION_JSON_VALUE)
@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
public 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) {

    DataSetMetadata dataSetMetadata = dataSetMetadataRepository.get(dataSetId);

    if (dataSetMetadata == null) {
        HttpResponseContext.status(HttpStatus.NO_CONTENT);
        return DataSet.empty(); // No data set, returns empty content.
    }
    if (!dataSetMetadata.isDraft()) {
        // Moved to get data set content operation
        HttpResponseContext.status(HttpStatus.MOVED_PERMANENTLY);
        HttpResponseContext.header("Location", "/datasets/" + dataSetId + "/content");
        return DataSet.empty(); // dataset not anymore a draft so preview doesn't make sense.
    }
    if (StringUtils.isNotEmpty(sheetName)) {
        dataSetMetadata.setSheetName(sheetName);
    }
    // take care of previous data without schema parser result
    if (dataSetMetadata.getSchemaParserResult() != null) {
        // sheet not yet set correctly so use the first one
        if (StringUtils.isEmpty(dataSetMetadata.getSheetName())) {
            String theSheetName = dataSetMetadata.getSchemaParserResult().getSheetContents().get(0).getName();
            LOG.debug("preview for dataSetMetadata: {} with sheetName: {}", dataSetId, theSheetName);
            dataSetMetadata.setSheetName(theSheetName);
        }

        String theSheetName = dataSetMetadata.getSheetName();

        Optional<Schema.SheetContent> sheetContentFound = dataSetMetadata.getSchemaParserResult()
                .getSheetContents().stream().filter(sheetContent -> theSheetName.equals(sheetContent.getName()))
                .findFirst();

        if (!sheetContentFound.isPresent()) {
            HttpResponseContext.status(HttpStatus.NO_CONTENT);
            return DataSet.empty(); // No sheet found, returns empty content.
        }

        List<ColumnMetadata> columnMetadatas = sheetContentFound.get().getColumnMetadatas();

        if (dataSetMetadata.getRowMetadata() == null) {
            dataSetMetadata.setRowMetadata(new RowMetadata(emptyList()));
        }

        dataSetMetadata.getRowMetadata().setColumns(columnMetadatas);
    } else {
        LOG.warn("dataset#{} has draft status but any SchemaParserResult");
    }
    // Build the result
    DataSet dataSet = new DataSet();
    if (metadata) {
        dataSet.setMetadata(conversionService.convert(dataSetMetadata, UserDataSetMetadata.class));
    }
    dataSet.setRecords(contentStore.stream(dataSetMetadata).limit(100));
    return dataSet;
}

From source file:org.talend.dataprep.dataset.service.DataSetServiceTest.java

@Test
public void previewNonDraft() throws Exception {
    // Create a data set
    String dataSetId = given().body(IOUtils.toString(this.getClass().getResourceAsStream(TAGADA_CSV)))
            .queryParam("Content-Type", "text/csv").when().post("/datasets").asString();
    final DataSetMetadata dataSetMetadata = dataSetMetadataRepository.get(dataSetId);
    assertThat(dataSetMetadata, notNullValue());
    dataSetMetadata.setDraft(false); // Ensure it is no draft
    dataSetMetadataRepository.save(dataSetMetadata);
    // Should receive a 301 that redirects to the GET data set content operation
    given().redirects().follow(false).contentType(JSON).get("/datasets/{id}/preview", dataSetId) //
            .then() //
            .statusCode(HttpStatus.MOVED_PERMANENTLY.value());
    // Should receive a 200 if code follows redirection
    given().redirects().follow(true).contentType(JSON).get("/datasets/{id}/preview", dataSetId) //
            .then() //
            .statusCode(OK.value());/*from  w ww.  jav a2  s .  co  m*/
}