Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
Pegasus is a framework for building robust, scalable service architectures using dynamic discovery and simple asychronous type-checked REST + JSON APIs.
/*
Copyright (c) 2012 LinkedIn Corp.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* $Id: $
*/
package com.linkedin.restli.internal.server.util;
import com.linkedin.restli.common.ComplexKeySpec;
import com.linkedin.restli.common.TypeSpec;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.linkedin.data.DataMap;
import com.linkedin.data.schema.DataSchema;
import com.linkedin.data.schema.DataSchemaUtil;
import com.linkedin.data.template.DataTemplateUtil;
import com.linkedin.data.template.RecordTemplate;
import com.linkedin.data.transform.filter.request.MaskTree;
import com.linkedin.jersey.api.uri.UriComponent;
import com.linkedin.r2.message.rest.RestRequest;
import com.linkedin.restli.common.BatchRequest;
import com.linkedin.restli.common.ComplexResourceKey;
import com.linkedin.restli.common.CompoundKey;
import com.linkedin.restli.common.HttpStatus;
import com.linkedin.restli.common.RestConstants;
import com.linkedin.restli.internal.common.IllegalMaskException;
import com.linkedin.restli.internal.common.PathSegment.PathSegmentSyntaxException;
import com.linkedin.restli.internal.common.URIMaskUtil;
import com.linkedin.restli.internal.common.ValueConverter;
import com.linkedin.restli.internal.server.RestLiInternalException;
import com.linkedin.restli.internal.server.RoutingResult;
import com.linkedin.restli.internal.server.model.ResourceModel;
import com.linkedin.restli.server.Key;
import com.linkedin.restli.server.RoutingException;
/**
* @author Josh Walker
* @version $Revision: $
*/
public class ArgumentUtils
{
private static final Logger _log = LoggerFactory.getLogger(ArgumentUtils.class);
private static final Pattern SIMPLE_KEY_DELIMETER_PATTERN =
Pattern.compile(Pattern.quote(String.valueOf(RestConstants.SIMPLE_KEY_DELIMITER)));
private static final Pattern LEGACY_SIMPLE_KEY_DELIMETER_PATTERN = Pattern.compile(Pattern.quote(";"));
private static final Pattern KEY_VALUE_DELIMETER_PATTERN =
Pattern.compile(Pattern.quote(String.valueOf(RestConstants.KEY_VALUE_DELIMITER)));
private static final Pattern LEGACY_KEY_VALUE_DELIMETER_PATTERN = Pattern.compile(Pattern.quote(":"));
/**
* @param routingResult {@link RoutingResult}
* @return key value of the resource addressed by this method
*/
public static Object getResourceKey(final RoutingResult routingResult)
{
return routingResult.getContext().getPathKeys().get(
routingResult.getResourceMethod().getResourceModel().getKeyName());
}
/**
* @param routingResult {@link RoutingResult}
* @return whether the resource addressed by this method has a key
*/
public static boolean hasResourceKey(final RoutingResult routingResult)
{
return routingResult.getResourceMethod().getResourceModel().getPrimaryKey() != null;
}
/**
* @param request {@link RestRequest}
* @param recordClass resource value class
* @param resource value type which is a subclass of {@link RecordTemplate}
* @return resource value
*/
public static V extractEntity(final RestRequest request,
final Class recordClass)
{
try
{
return DataMapUtils.read(request, recordClass);
}
catch (IOException e)
{
throw new RoutingException("Error parsing entity body: " + e.getMessage(),
HttpStatus.S_400_BAD_REQUEST.getCode());
}
}
/**
* @param routingResult {@link RoutingResult}
* @return value class of the resource addressed by this method
*/
public static Class extends RecordTemplate> getValueClass(final RoutingResult routingResult)
{
return routingResult.getResourceMethod().getResourceModel().getValueClass();
}
/**
* Convert a DataMap representation of a BatchRequest (string->record) into a Java Map
* appropriate for passing into application code. Note that compound/complex keys are
* represented as their string encoding in the DataMap. Since we have already parsed
* these keys, we simply try to match the string representations, rather than re-parsing.
*
*
* @param data - the input DataMap to be converted
* @param valueClass - the RecordTemplate type of the values
* @param ids - the parsed batch ids from the request URI
* @return a map using appropriate key and value classes
*/
public static Map