Package org.swisspush.gateleen.core.util
Class ExpansionDeltaUtil
- java.lang.Object
-
- org.swisspush.gateleen.core.util.ExpansionDeltaUtil
-
public final class ExpansionDeltaUtil extends Object
Utility class providing methods used in ExpansionHandler and DeltaHandler.
- Author:
- https://github.com/mcweba [Marc-Andre Weber]
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classExpansionDeltaUtil.CollectionResourceContainerSimple container holding a collectionName and a list of resourceNamesstatic classExpansionDeltaUtil.SlashHandling
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringconstructRequestUri(String path, io.vertx.core.MultiMap params, List<String> paramsToRemove, String subResource, ExpansionDeltaUtil.SlashHandling slashHandling)Constructs a Request based on the given path and the given params without the paramsToRemovestatic io.vertx.core.Handler<Throwable>createRequestExceptionHandler(io.vertx.core.http.HttpServerRequest request, String uri, Class<?> caller)Utility method to create a Exception for aHttpServerRequeststatic io.vertx.core.Handler<Throwable>createResponseExceptionHandler(io.vertx.core.http.HttpServerRequest request, String uri, Class<?> caller)Utility method to create aExceptionfor aHttpServerRequeststatic StringextractCollectionFromPath(String path)Extracts the collection name from the given path.static List<String>extractCollectionResourceNames(io.vertx.core.json.JsonArray collectionArray)Extracts the collection resource names from the givenJsonArraystatic StringmapToDelimetedString(io.vertx.core.MultiMap map, String delim)Converts the given map to a delimited string based on the given delimiter.static StringremoveFromEndOfString(String source, String stringToRemove)Remove the stringToRemove from source when existingstatic ExpansionDeltaUtil.CollectionResourceContainerverifyCollectionResponse(io.vertx.core.http.HttpServerRequest request, io.vertx.core.buffer.Buffer data, Set<String> originalParams)Verifies the result of the collection request.static ExpansionDeltaUtil.CollectionResourceContainerverifyCollectionResponse(String targetPath, io.vertx.core.buffer.Buffer data, Set<String> originalParams)Verifies the result of the collection request.
-
-
-
Method Detail
-
mapToDelimetedString
public static String mapToDelimetedString(io.vertx.core.MultiMap map, String delim)
Converts the given map to a delimited string based on the given delimiter.Example Input Map: {k1=v1, k2=v2, k3=v3} Input delim: Result: k1=v1&k2=v2&k3=v3- Parameters:
map- The map to convert.delim- The delimiter to use between key-value pairs.- Returns:
- The delimited string.
-
removeFromEndOfString
public static String removeFromEndOfString(String source, String stringToRemove)
Remove the stringToRemove from source when existing- Parameters:
source- the source to remove the stringToRemove fromstringToRemove- the token to remove from source- Returns:
- String
-
extractCollectionFromPath
public static String extractCollectionFromPath(String path)
Extracts the collection name from the given path. The collection name is known to be the last segment of the path- Parameters:
path- path- Returns:
- String
-
extractCollectionResourceNames
public static List<String> extractCollectionResourceNames(io.vertx.core.json.JsonArray collectionArray) throws ResourceCollectionException
Extracts the collection resource names from the givenJsonArray- Parameters:
collectionArray- collectionArray- Returns:
- the list of collection names
- Throws:
ResourceCollectionException- ResourceCollectionException
-
constructRequestUri
public static String constructRequestUri(String path, io.vertx.core.MultiMap params, List<String> paramsToRemove, String subResource, ExpansionDeltaUtil.SlashHandling slashHandling)
Constructs a Request based on the given path and the given params without the paramsToRemove- Parameters:
path- the original path to modifyparams- the params of the original requestparamsToRemove- the params which should be removed in the new requestsubResource- additional segment for the new requestslashHandling- when set to true, the new request will have a / at the end- Returns:
- String
-
createRequestExceptionHandler
public static io.vertx.core.Handler<Throwable> createRequestExceptionHandler(io.vertx.core.http.HttpServerRequest request, String uri, Class<?> caller)
Utility method to create a Exception for aHttpServerRequest- Parameters:
request- the requesturi- an uricaller- the caller- Returns:
- Handler
-
createResponseExceptionHandler
public static io.vertx.core.Handler<Throwable> createResponseExceptionHandler(io.vertx.core.http.HttpServerRequest request, String uri, Class<?> caller)
Utility method to create aExceptionfor aHttpServerRequest- Parameters:
request- the requesturi- an uricaller- the caller- Returns:
- Handler
-
verifyCollectionResponse
public static ExpansionDeltaUtil.CollectionResourceContainer verifyCollectionResponse(io.vertx.core.http.HttpServerRequest request, io.vertx.core.buffer.Buffer data, Set<String> originalParams) throws ResourceCollectionException
Verifies the result of the collection request. Throws aResourceCollectionExceptionwhen no collection or more than one collection was found Returns aExpansionDeltaUtil.CollectionResourceContainercontaining the name of the collection and a list of the resourceNames.- Parameters:
request- the requestdata- the dataoriginalParams- originalParams- Returns:
- CollectionResourceContainer
- Throws:
ResourceCollectionException- ResourceCollectionException
-
verifyCollectionResponse
public static ExpansionDeltaUtil.CollectionResourceContainer verifyCollectionResponse(String targetPath, io.vertx.core.buffer.Buffer data, Set<String> originalParams) throws ResourceCollectionException
Verifies the result of the collection request. Throws aResourceCollectionExceptionwhen no collection or more than one collection was found Returns aExpansionDeltaUtil.CollectionResourceContainercontaining the name of the collection and a list of the resourceNames.- Parameters:
targetPath- target pathdata- the dataoriginalParams- originalParams- Returns:
- CollectionResourceContainer
- Throws:
ResourceCollectionException- ResourceCollectionException
-
-