com.mx.path.model.mdx.web.DateVersionedResponse Maven / Gradle / Ivy
The newest version!
package com.mx.path.model.mdx.web;
import static com.mx.path.model.mdx.web.controller.BaseController.MDX_MEDIA;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
import lombok.Builder;
import lombok.Data;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.mx.path.core.common.accessor.PathResponseStatus;
import com.mx.path.core.common.accessor.RequestValidationException;
import com.mx.path.core.common.configuration.ConfigurationException;
import com.mx.path.core.common.lang.Strings;
import com.mx.path.core.common.serialization.PathRequestSerializableException;
import com.mx.path.model.mdx.model.Resources;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
/**
* Use in Controller to provide multiple code paths, based on provided version header.
*
* The Version header is expected to be present in the Accept or Content-Type header as a parameter.
*
* Example:
*
{@code
* Accept: application/json;version=20240101
* }
*
* Usage:
*
{@code
* return new DateVersionedResponse(request)
* .defaultVersion(Account, Account, { o ->
* // Insert normal controller code for default version
* return ResponseEntity.ok().build()
* })
* .version(20240323, com.mx.path.model.mdx.model.account.v20240323.Account, com.mx.path.model.mdx.model.account.v20240323.Account, { o ->
* // Insert normal controller code for version 20240323
* return ResponseEntity.ok().build()
* })
* .execute()
* }
*/
public class DateVersionedResponse {
private static final int MINIMUM_VERSION = 19700101;
private static final Pattern VERSION_PATTERN = Pattern.compile(";\\s*version=([^;]+)");
/**
* Executed when no matching version found or no version provided
*/
private DateVersionedResponder defaultVersion;
/**
* Incoming request from Controller
*/
private final HttpServletRequest request;
/**
* Responders for each version
*/
private final Map responders = new HashMap<>();
@Data
@Builder
static class DateVersionedResponder {
private Class> requestType;
private Class> responseType;
private Function
© 2015 - 2024 Weber Informatics LLC | Privacy Policy