Package com.linkedin.data

Examples of com.linkedin.data.DataMap


  @Test
  public void testErrorMessagesForArraysNotFastFail() throws JsonParseException,
      IOException,
      DataProcessingException
  {
    DataMap data = dataMapFromString("{ 'a': [1, 2, 3, 4, 5]}".replace('\'', '"'));
    DataMap filter = dataMapFromString("{ 'a': { '$*': { 'y': 1}}}".replace('\'', '"'));
    DataComplexProcessor processor = new DataComplexProcessor(new Filter(), filter, data);
    boolean thrown = false;
    try {
      processor.run(false);
    } catch (DataProcessingException e) {
View Full Code Here


  @Test
  public void testErrorMessagesForArraysFastFail() throws JsonParseException,
      IOException,
      DataProcessingException
  {
    DataMap data = dataMapFromString("{ 'a': [1, 2, 3, 4, 5]}".replace('\'', '"'));
    DataMap filter = dataMapFromString("{ 'a': { '$*': { 'y': 1}}}".replace('\'', '"'));
    DataComplexProcessor processor = new DataComplexProcessor(new Filter(), filter, data);
    boolean thrown = false;
    try {
      processor.run(true);
    } catch (DataProcessingException e) {
View Full Code Here

  @Test
  public void testIncorrectFilter() throws JsonParseException,
      IOException,
      DataProcessingException
  {
    DataMap data = dataMapFromString("{ 'a': [1, 2, 3, 4, 5]}".replace('\'', '"'));
    DataMap filter = dataMapFromString("{ 'a': { '$*': 'hola'}}".replace('\'', '"'));
    DataComplexProcessor processor = new DataComplexProcessor(new Filter(), filter, data);
    boolean thrown = false;
    try {
      processor.run(false);
    } catch (DataProcessingException e) {
View Full Code Here

  @Test
  public void testMaskCompositionDuringFilteringDoesNotOverwriteOriginalMask() throws JsonParseException,
      IOException,
      DataProcessingException
  {
    DataMap data = dataMapFromString("{ 'a': { 'b': 'b'}}".replace('\'', '"'));
    DataMap filter = dataMapFromString("{ '$*': { 'c': { 'd': 0}}, 'a': 1}".replace('\'', '"'));
    String originalFilter = filter.toString();
    DataComplexProcessor processor = new DataComplexProcessor(new Filter(), filter, data);
    processor.run(false);
    assertEquals(filter.toString(), originalFilter, "filter should not be modified");
  }
View Full Code Here

  @Test
  public void testInvalidArrayRangeInFilter() throws JsonParseException,
      IOException,
      DataProcessingException
  {
    DataMap data = dataMapFromString("{ 'a': [1, 2, 3, 4, 5]}".replace('\'', '"'));
    DataMap filter = dataMapFromString("{ 'a': { '$start': -2, '$count': -1}}".replace('\'', '"'));
    DataComplexProcessor processor = new DataComplexProcessor(new Filter(), filter, data);
    boolean thrown = false;
    try {
      processor.run(false);
    } catch (DataProcessingException e) {
View Full Code Here

    {
      // _defaultMode specifies if field should be filtered out by default
      final NodeMode defaultMode = _dafaultNodeModeCalculator.getDefaultNodeMode(opNode);

      // get complex wildcard if it exist e.g. $*: {...}
      final DataMap complexWildCard = getComplexWildCard(opNode);

      if (data.getClass() == DataList.class)
      {
        return filterDataList(opNode, ((DataList) data));
      }
View Full Code Here

   * Returns mask <code>{ "$*": v }</code>, where <code>v</code> is passed Integer.
   *
   */
  private static DataMap wildcard(Integer v)
  {
    final DataMap wildcardMap = new DataMap();
    wildcardMap.put(FilterConstants.WILDCARD, v);
    return wildcardMap;
  }
View Full Code Here

        // there is no need for further evaluation of mask, because this field
        // was explicitly masked with positive mask
        {
          if (childValue instanceof DataComplex)
          {
            final DataMap composed = compose(name, complexWildCard, wildcard(1));
            if (composed != null)
            {
              operation = composed;
            }
          }
          // else
          // data is of primitive type, and is selected with mask = 1, but there also
          // exist
          // a wildcard mask, in this case we don't report it as an error
        }
      }
      else
      {
        // field was not explicitly masked

        final Object opChild = opNode.get(Escaper.replaceAll(name, "$", "$$"));

        // if item was not explicitly excluded nor included

        if (opChild == null)
        {
          // 1. there was no filter for this item - in this case apply default filter
          // and $* if it was defined and field was not filtered out
          if (areFieldsExplicitlyRemoved(defaultMode)
              || areFieldsImplicitlyRemoved(defaultMode, complexWildCard))
          {
            operation = FilterConstants.NEGATIVE;
          }
          else if (complexWildCard != null)
          {
            if (childValue instanceof DataComplex)
            {
              operation = complexWildCard;
            }
            else if (needsRemoving(defaultMode, complexWildCard))
            {
              operation = FilterConstants.NEGATIVE;
            }
          }
        }
        else
        {
          // precondition:
          assert (opChild.getClass() == DataMap.class) : opChild;

          final Object rawWildcard = opNode.get(FilterConstants.WILDCARD);
          final DataMap effectiveComplexWildcard =
              ((rawWildcard != null && rawWildcard.equals(POSITIVE)) ? wildcard(POSITIVE)
                  : (DataMap) rawWildcard);
          // effectiveMask contains complex mask composed with wildcard if wildcard is
          // defined
          final DataMap effectiveMask =
              ((effectiveComplexWildcard == null) ? (DataMap) opChild
                  : compose(name, (DataMap) opChild, effectiveComplexWildcard));

          // 2. filter was complex
          if (needsRemoving(defaultMode, effectiveMask))
View Full Code Here

    assert mask2 != null;
    assert mask1 != null;

    try
    {
      final DataMap clone = mask1.copy();
      new DataComplexProcessor(new MaskComposition(), mask2, clone).run(true);
      return clone;
    }
    catch (CloneNotSupportedException e)
    {
View Full Code Here

    //at this nodes. The reason for it is that if field should not be used in more than
    //one operation e.g. $set and $delete, because such patch becomes ambiguous.
    //Each operation, upon being executed updates this variable.
    final Map<String, String> usedFields = new HashMap<String, String>();

    DataMap opNode = (DataMap) instruction.getOperation();
    DataMap dataNode = (DataMap) instruction.getData();

    /**
     * Apply all supported operations here. _usedFields is used to keep track of fields
     * that operations were applied to.
     */
 
View Full Code Here

TOP

Related Classes of com.linkedin.data.DataMap

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.