private Collection getFilterGroup(Activity activity) {
   Object obj =
       (FilteredActivity)
           activity
               .getClass()
               .getAnnotation(com / google / android / apps / wallet / filter / FilteredActivity);
   if (obj == null) {
     throw new IllegalArgumentException(
         String.valueOf(activity.getClass().getName())
             .concat(" missing FilteredActivity annotation"));
   }
   if (((FilteredActivity) (obj)).group().equals("NONE")) {
     return new ArrayList();
   }
   if (!activityFilters.containsKey(((FilteredActivity) (obj)).group())) {
     activity = String.valueOf(activity.getClass().getName());
     obj = ((FilteredActivity) (obj)).group();
     String s = String.valueOf(activityFilters.keySet());
     throw new IllegalArgumentException(
         (new StringBuilder(
                 String.valueOf(activity).length()
                     + 49
                     + String.valueOf(obj).length()
                     + String.valueOf(s).length()))
             .append(activity)
             .append(" has invalid group attribute: ")
             .append(((String) (obj)))
             .append(" valid groups are: ")
             .append(s)
             .toString());
   } else {
     return activityFilters.get(((FilteredActivity) (obj)).group());
   }
 }
 /**
  * Using the criteria in {@code parentIdMap}, recursively adds all children under the partition ID
  * of {@code parentNode} to {@code parentNode}.
  *
  * @param parentNode required
  * @param parentIdMap the multimap from parent partition ID to list of child criteria
  */
 private static void addChildNodes(
     ProductPartitionNode parentNode, ListMultimap<Long, AdGroupCriterion> parentIdMap) {
   if (parentIdMap.containsKey(parentNode.getProductPartitionId())) {
     parentNode = parentNode.asSubdivision();
   }
   for (AdGroupCriterion adGroupCriterion : parentIdMap.get(parentNode.getProductPartitionId())) {
     ProductPartition partition = (ProductPartition) adGroupCriterion.getCriterion();
     ProductPartitionNode childNode = parentNode.addChild(partition.getCaseValue());
     childNode = childNode.setProductPartitionId(partition.getId());
     if (ProductPartitionType.SUBDIVISION.equals(partition.getPartitionType())) {
       childNode = childNode.asSubdivision();
     } else {
       if (adGroupCriterion instanceof BiddableAdGroupCriterion) {
         childNode = childNode.asBiddableUnit();
         Money cpcBidAmount = getBid((BiddableAdGroupCriterion) adGroupCriterion);
         if (cpcBidAmount != null) {
           childNode = childNode.setBid(cpcBidAmount.getMicroAmount());
         }
       } else {
         childNode = childNode.asExcludedUnit();
       }
     }
     addChildNodes(childNode, parentIdMap);
   }
 }
Example #3
0
 public void addCell(String parent, String child, String label, Multiplicity m, Sort contents) {
   if (parent != null) {
     if (!children.containsKey(Sort(parent))) {
       // create a fragment label for the parent cell.
       cellFragmentLabels.put(
           Sort(parent), KLabel(cellLabels.get(Sort(parent)).name() + "-fragment"));
     }
     if (m != Multiplicity.STAR) {
       cellAbsentLabels.put(Sort(child), KLabel("no" + child));
     }
     if (m == Multiplicity.STAR) {
       cellCollectionSorts.put(Sort(child + "Bag"), Sort(child));
     }
     parents.put(Sort(child), Sort(parent));
     children.put(Sort(parent), Sort(child));
     levels.put(Sort(child), 1 + levels.get(Sort(parent)));
   } else {
     levels.put(Sort(child), 0);
   }
   if (contents != null) {
     leafCellTypes.put(Sort(child), contents);
   }
   multiplicities.put(Sort(child), m);
   cellLabels.put(Sort(child), KLabel(label));
 }
Example #4
0
 /**
  * Add the element object to a list associated with the key. Any preexisting elements are removed.
  *
  * @param key the key to which the element object will be linked
  * @param element the single object to stored
  * @return true if the element was successfully added
  */
 public boolean addSingleton(Object key, Object element) {
   if (lookupMultimap.containsKey(key)) {
     // Remove all elements associated with this key
     while (!lookupMultimap.get(key).isEmpty()) {
       lookupMultimap.get(key).remove(0);
     }
   }
   lookupMultimap.put(key, element);
   return true;
 }
  /**
   * Returns a new instance of this class by retrieving the product partitions of the specified ad
   * group. All parameters are required.
   */
  public static ProductPartitionTree createAdGroupTree(
      AdWordsServices services, AdWordsSession session, Long adGroupId)
      throws ApiException, RemoteException {
    // Get the AdGroupCriterionService.
    AdGroupCriterionServiceInterface criterionService =
        services.get(session, AdGroupCriterionServiceInterface.class);

    SelectorBuilder selectorBuilder =
        new SelectorBuilder()
            .fields(
                REQUIRED_SELECTOR_FIELD_ENUMS.toArray(
                    new AdGroupCriterionField[REQUIRED_SELECTOR_FIELD_ENUMS.size()]))
            .equals(AdGroupCriterionField.AdGroupId, adGroupId.toString())
            .equals(AdGroupCriterionField.CriteriaType, "PRODUCT_PARTITION")
            .in(
                AdGroupCriterionField.Status,
                UserStatus.ENABLED.getValue(),
                UserStatus.PAUSED.getValue())
            .limit(PAGE_SIZE);

    AdGroupCriterionPage adGroupCriterionPage;

    // A multimap from each product partition ID to its direct children.
    ListMultimap<Long, AdGroupCriterion> parentIdMap = LinkedListMultimap.create();
    int offset = 0;
    do {
      // Get the next page of results.
      adGroupCriterionPage = criterionService.get(selectorBuilder.build());

      if (adGroupCriterionPage != null && adGroupCriterionPage.getEntries() != null) {
        for (AdGroupCriterion adGroupCriterion : adGroupCriterionPage.getEntries()) {
          ProductPartition partition = (ProductPartition) adGroupCriterion.getCriterion();
          parentIdMap.put(partition.getParentCriterionId(), adGroupCriterion);
        }
        offset += adGroupCriterionPage.getEntries().length;
        selectorBuilder.increaseOffsetBy(PAGE_SIZE);
      }
    } while (offset < adGroupCriterionPage.getTotalNumEntries());

    // Construct the ProductPartitionTree from the parentIdMap.
    if (!parentIdMap.containsKey(null)) {
      Preconditions.checkState(
          parentIdMap.isEmpty(), "No root criterion found in the tree but the tree is not empty");
      return createEmptyAdGroupTree(
          adGroupId, getAdGroupBiddingStrategyConfiguration(services, session, adGroupId));
    }

    return createNonEmptyAdGroupTree(adGroupId, parentIdMap);
  }
  /**
   * Returns a new tree based on a non-empty collection of ad group criteria. All parameters
   * required.
   *
   * @param adGroupId the ID of the ad group
   * @param parentIdMap the multimap from parent product partition ID to child criteria
   * @return a new ProductPartitionTree
   */
  private static ProductPartitionTree createNonEmptyAdGroupTree(
      Long adGroupId, ListMultimap<Long, AdGroupCriterion> parentIdMap) {
    Preconditions.checkNotNull(adGroupId, "Null ad group ID");
    Preconditions.checkArgument(
        !parentIdMap.isEmpty(), "parentIdMap passed for ad group ID %s is empty", adGroupId);
    Preconditions.checkArgument(
        parentIdMap.containsKey(null),
        "No root criterion found in the list of ad group criteria for ad group ID %s",
        adGroupId);

    AdGroupCriterion rootCriterion = Iterables.getOnlyElement(parentIdMap.get(null));

    Preconditions.checkState(
        rootCriterion instanceof BiddableAdGroupCriterion,
        "Root criterion for ad group ID %s is not a BiddableAdGroupCriterion",
        adGroupId);
    BiddableAdGroupCriterion biddableRootCriterion = (BiddableAdGroupCriterion) rootCriterion;

    BiddingStrategyConfiguration biddingStrategyConfig =
        biddableRootCriterion.getBiddingStrategyConfiguration();
    Preconditions.checkState(
        biddingStrategyConfig != null,
        "Null bidding strategy config on the root node of ad group ID %s",
        adGroupId);
    ProductPartitionNode rootNode =
        new ProductPartitionNode(
            null,
            (ProductDimension) null,
            rootCriterion.getCriterion().getId(),
            new ProductDimensionComparator());

    // Set the root's bid if a bid exists on the BiddableAdGroupCriterion.
    Money rootNodeBid = getBid(biddableRootCriterion);
    if (rootNodeBid != null) {
      rootNode = rootNode.asBiddableUnit().setBid(rootNodeBid.getMicroAmount());
    }

    addChildNodes(rootNode, parentIdMap);

    return new ProductPartitionTree(adGroupId, biddingStrategyConfig, rootNode);
  }
Example #7
0
  @Test
  public void testAclTableEntries() throws Exception {
    String userTestNamespace = "userTestNsp";
    Table acl = UTIL.getConnection().getTable(AccessControlLists.ACL_TABLE_NAME);
    try {
      ListMultimap<String, TablePermission> perms =
          AccessControlLists.getNamespacePermissions(conf, TEST_NAMESPACE);

      perms = AccessControlLists.getNamespacePermissions(conf, TEST_NAMESPACE);
      for (Map.Entry<String, TablePermission> entry : perms.entries()) {
        LOG.debug(entry);
      }
      assertEquals(6, perms.size());

      // Grant and check state in ACL table
      grantOnNamespace(UTIL, userTestNamespace, TEST_NAMESPACE, Permission.Action.WRITE);

      Result result = acl.get(new Get(Bytes.toBytes(userTestNamespace)));
      assertTrue(result != null);
      perms = AccessControlLists.getNamespacePermissions(conf, TEST_NAMESPACE);
      assertEquals(7, perms.size());
      List<TablePermission> namespacePerms = perms.get(userTestNamespace);
      assertTrue(perms.containsKey(userTestNamespace));
      assertEquals(1, namespacePerms.size());
      assertEquals(TEST_NAMESPACE, namespacePerms.get(0).getNamespace());
      assertEquals(null, namespacePerms.get(0).getFamily());
      assertEquals(null, namespacePerms.get(0).getQualifier());
      assertEquals(1, namespacePerms.get(0).getActions().length);
      assertEquals(Permission.Action.WRITE, namespacePerms.get(0).getActions()[0]);

      // Revoke and check state in ACL table
      revokeFromNamespace(UTIL, userTestNamespace, TEST_NAMESPACE, Permission.Action.WRITE);

      perms = AccessControlLists.getNamespacePermissions(conf, TEST_NAMESPACE);
      assertEquals(6, perms.size());
    } finally {
      acl.close();
    }
  }
Example #8
0
 public boolean containsLabel(CellLabel label) {
   return cells.containsKey(label);
 }
 @Override
 public boolean containsKey(final Object key) {
   return backingMap.containsKey(key);
 }
 @Test()
 public void testHandleIdCollision() throws Exception {
   ListMultimap<String, String> errors = instance.handleIdCollision(scopes, bundle);
   assertTrue(errors.containsKey(Ontology.IDENTIFIER_KEY));
 }
Example #11
0
 @Override
 public boolean isParentCell(Sort k) {
   return children.containsKey(k);
 }
Example #12
0
 @Override
 public boolean isLeafCell(Sort k) {
   return !children.containsKey(k) && isCell(k);
 }
Example #13
0
 /**
  * Determines whether the supplied key is present in the lookup.
  *
  * @param key the key to search for
  * @return true if the key does exist
  */
 public boolean containsKey(Object key) {
   return lookupMultimap.containsKey(key);
 }