private BoundRequestBuilder getBuilderWithHeaderAndQuery(
      final String verb,
      final String url,
      @Nullable final String username,
      @Nullable final String password,
      final Multimap<String, String> options) {
    BoundRequestBuilder builder;

    if (verb.equals("GET")) {
      builder = httpClient.prepareGet(url);
    } else if (verb.equals("POST")) {
      builder = httpClient.preparePost(url);
    } else if (verb.equals("PUT")) {
      builder = httpClient.preparePut(url);
    } else if (verb.equals("DELETE")) {
      builder = httpClient.prepareDelete(url);
    } else if (verb.equals("HEAD")) {
      builder = httpClient.prepareHead(url);
    } else if (verb.equals("OPTIONS")) {
      builder = httpClient.prepareOptions(url);
    } else {
      throw new IllegalArgumentException("Unrecognized verb: " + verb);
    }

    if (username != null && password != null) {
      final Realm realm = new RealmBuilder().setPrincipal(username).setPassword(password).build();
      builder.setRealm(realm);
    }

    final Collection<String> acceptHeaders = options.removeAll(HTTP_HEADER_ACCEPT);
    final String acceptHeader;
    if (!acceptHeaders.isEmpty()) {
      acceptHeader = CSV_JOINER.join(acceptHeaders);
    } else {
      acceptHeader = ACCEPT_JSON;
    }
    builder.addHeader(HTTP_HEADER_ACCEPT, acceptHeader);

    String contentTypeHeader = getUniqueValue(options, HTTP_HEADER_CONTENT_TYPE);
    if (contentTypeHeader == null) {
      contentTypeHeader = CONTENT_TYPE_JSON;
    } else {
      options.removeAll(HTTP_HEADER_CONTENT_TYPE);
    }
    builder.addHeader(HTTP_HEADER_CONTENT_TYPE, contentTypeHeader);

    builder.setBodyEncoding("UTF-8");

    for (final String key : options.keySet()) {
      if (options.get(key) != null) {
        for (final String value : options.get(key)) {
          builder.addQueryParam(key, value);
        }
      }
    }

    return builder;
  }
 @Override
 public Multimap<String, String> process(Multimap<String, String> input) {
   String pname = matchRule.getPname();
   if (!input.containsKey(pname)) return input;
   String oldOvalue = input.get(pname).iterator().next();
   String newOvalue = oldOvalue.replaceAll(change.otrim, "");
   String[] split_triples = newOvalue.split(change.osplitTag);
   input.removeAll(pname);
   for (String split_triple : split_triples) {
     input.put(change.pnewName, "\"" + split_triple.trim() + "\"");
   }
   input.removeAll(pname);
   return input;
 }
  @SuppressWarnings("unchecked")
  private static void addRRset(
      Name name, final Message response, Record[] records, final int section) {
    Multimap<RequestType, Record> rrsets = ArrayListMultimap.create();
    for (Record r : records) {
      RequestType type = RequestType.typeOf(r.getType());
      rrsets.get(type).addAll(Collections2.filter(Arrays.asList(records), type));
    }
    Predicate<Record> checkNewRecord =
        new Predicate<Record>() {

          @Override
          public boolean apply(Record input) {
            for (int s = 1; s <= section; s++) {
              if (response.findRecord(input, s)) {
                return false;
              }
            }
            return true;
          }
        };
    if (rrsets.containsKey(RequestType.CNAME)) {
      for (Record cnames : Iterables.filter(rrsets.removeAll(RequestType.CNAME), checkNewRecord)) {
        response.addRecord(cnames, section);
      }
    }
    for (Record sectionRecord : Iterables.filter(rrsets.values(), checkNewRecord)) {
      response.addRecord(sectionRecord, section);
    }
  }
Beispiel #4
0
  /**
   * Clear the tracked visited folders & the cached {@link LocalPkgInfo} for the given filter types.
   *
   * @param filters A set of PkgType constants or {@link PkgType#PKG_ALL} to clear everything.
   */
  public void clearLocalPkg(@NonNull EnumSet<PkgType> filters) {
    mLegacyBuildTools = null;

    synchronized (mLocalPackages) {
      for (PkgType filter : filters) {
        mVisitedDirs.removeAll(filter);
        mLocalPackages.removeAll(filter);
      }

      // Clear the targets if the platforms or addons are being cleared
      if (filters.contains(PkgType.PKG_PLATFORM) || filters.contains(PkgType.PKG_ADDON)) {
        mCachedMissingTargets = null;
        mCachedTargets = null;
      }
    }
  }
Beispiel #5
0
  @Override
  public boolean remove(MetabolicReaction rxn) {

    // remove links to metabolites
    for (MetabolicParticipant p : rxn.getParticipants()) {
      Metabolite m = p.getMolecule();
      participantMap.get(m.getIdentifier()).remove(rxn);
      if (participantMap.get(m.getIdentifier()).isEmpty()) {
        participantMap.removeAll(m.getIdentifier());
      }
    }
    reactionMap.remove(rxn.getIdentifier(), rxn);
    return super.remove(rxn);
  }
  @Override
  public synchronized void onRemoveNetconfOperationServiceFactory(
      NetconfOperationServiceFactory service) {
    factories.remove(service);

    for (final AutoCloseable autoCloseable : registrations.get(service)) {
      try {
        autoCloseable.close();
      } catch (Exception e) {
        LOG.warn("Unable to close listener registration", e);
      }
    }

    registrations.removeAll(service);
  }
 public void after(EObject grammarElement) {
   EObject foundGrammarElement = grammarElements.remove(grammarElements.size() - 1);
   if (grammarElement != foundGrammarElement)
     throw new IllegalStateException(
         "expected element: '" + grammarElement + "', but was: '" + foundGrammarElement + "'");
   if (grammarElement instanceof UnorderedGroup && indexToHandledElements != null) {
     indexToHandledElements.removeAll(grammarElements.size());
   } else if (!grammarElements.isEmpty()) {
     int index = grammarElements.size() - 1;
     if (grammarElements.get(index) instanceof UnorderedGroup) {
       if (indexToHandledElements == null) {
         indexToHandledElements = LinkedHashMultimap.create();
       }
       indexToHandledElements.put(index, (AbstractElement) grammarElement);
     }
   }
 }
Beispiel #8
0
  /**
   * Prunes a multimap based on a predicate, returning the pruned values. The input map will be
   * modified.
   *
   * @param map The multimap to prune.
   * @param filterRule The pruning rule. When the predicate returns {@code false} for an entry, it
   *     will be pruned, otherwise it will be retained.
   * @param <K> The key type in the multimap.
   * @param <V> The value type in the multimap.
   * @return A new multimap, containing the pruned keys/values.
   */
  public static <K, V> Multimap<K, V> prune(
      Multimap<K, V> map, Predicate<Collection<V>> filterRule) {
    Preconditions.checkNotNull(map);
    Preconditions.checkNotNull(filterRule);
    Set<K> prunedKeys = Sets.newHashSet();
    for (K key : map.keySet()) {
      if (!filterRule.apply(map.get(key))) {
        prunedKeys.add(key);
      }
    }

    Multimap<K, V> pruned = ArrayListMultimap.create();
    for (K key : prunedKeys) {
      pruned.putAll(key, map.removeAll(key));
    }

    return pruned;
  }
Beispiel #9
0
 protected void applyValidation(de.jutzig.jabylon.properties.Property property) {
   Collection<Review> reviewList =
       reviewService.review(descriptor, currentItem.getSourceProperty(), property);
   reviews.removeAll(currentItem.getKey());
   if (reviewList.isEmpty()) {
     if (translated.getComponentError() != null) translated.setComponentError(null);
   } else {
     reviews.putAll((String) currentItem.getKey(), reviewList);
     List<ErrorMessage> errors = new ArrayList<ErrorMessage>(reviewList.size());
     for (Review review : reviewList) {
       UserError error =
           new UserError(review.getMessage(), UserError.CONTENT_TEXT, ErrorMessage.ERROR);
       errors.add(error);
     }
     CompositeErrorMessage message = new CompositeErrorMessage(errors);
     translated.setComponentError(message);
   }
 }
  @Override
  public boolean unregister(PDPObject element) {
    synchronized (this) {
      LOGGER.info("unregister {}", element);
      if (element instanceof Container) {
        containerCapacities.remove(element);
        containerContentsSize.remove(element);
        containerContents.removeAll(element);
      }

      if (element instanceof Parcel) {
        parcelState.removeValue((Parcel) element);
      }

      if (element instanceof Vehicle) {
        vehicleState.remove(element);
        pendingVehicleActions.remove(element);
      }
    }
    return true;
  }
Beispiel #11
0
 /**
  * Get SkyKeys for the FileValues for the given {@code pathFragments}. To do this, we look for a
  * package lookup node for each path fragment, since package lookup nodes contain the "root" of a
  * package. The returned SkyKeys correspond to FileValues that may not exist in the graph.
  */
 private Collection<SkyKey> getSkyKeysForFileFragments(Iterable<PathFragment> pathFragments) {
   Set<SkyKey> result = new HashSet<>();
   Multimap<PathFragment, PathFragment> currentToOriginal = ArrayListMultimap.create();
   for (PathFragment pathFragment : pathFragments) {
     currentToOriginal.put(pathFragment, pathFragment);
   }
   while (!currentToOriginal.isEmpty()) {
     Map<SkyKey, PathFragment> keys = new HashMap<>();
     for (PathFragment pathFragment : currentToOriginal.keySet()) {
       keys.put(
           PackageLookupValue.key(PackageIdentifier.createInDefaultRepo(pathFragment)),
           pathFragment);
     }
     Map<SkyKey, SkyValue> lookupValues = graph.getSuccessfulValues(keys.keySet());
     for (Map.Entry<SkyKey, SkyValue> entry : lookupValues.entrySet()) {
       PackageLookupValue packageLookupValue = (PackageLookupValue) entry.getValue();
       if (packageLookupValue.packageExists()) {
         PathFragment dir = keys.get(entry.getKey());
         Collection<PathFragment> originalFiles = currentToOriginal.get(dir);
         Preconditions.checkState(!originalFiles.isEmpty(), entry);
         for (PathFragment fileName : originalFiles) {
           result.add(
               FileValue.key(RootedPath.toRootedPath(packageLookupValue.getRoot(), fileName)));
         }
         currentToOriginal.removeAll(dir);
       }
     }
     Multimap<PathFragment, PathFragment> newCurrentToOriginal = ArrayListMultimap.create();
     for (PathFragment pathFragment : currentToOriginal.keySet()) {
       PathFragment parent = pathFragment.getParentDirectory();
       if (parent != null) {
         newCurrentToOriginal.putAll(parent, currentToOriginal.get(pathFragment));
       }
     }
     currentToOriginal = newCurrentToOriginal;
   }
   return result;
 }
Beispiel #12
0
 @Override
 public void entityDeleted(String podId, Pod entity) {
   containerServices.removeAll(podId);
 }
 public void setHeader(String name, String value) {
   headers.removeAll(name.toLowerCase());
   headers.put(name.toLowerCase(), value);
 }
  private <T> T doPrepareRequestAndMaybeFollowLocation(
      final String verb,
      final String uri,
      final Object body,
      final Multimap<String, String> optionsRo,
      final Multimap<String, String> optionsForFollow,
      final int timeoutSec,
      final Class<T> clazz,
      final boolean followLocation)
      throws KillBillClientException {
    final Multimap<String, String> options = HashMultimap.<String, String>create(optionsRo);

    final String createdBy = getUniqueValue(options, AUDIT_OPTION_CREATED_BY);
    final String reason = getUniqueValue(options, AUDIT_OPTION_REASON);
    final String comment = getUniqueValue(options, AUDIT_OPTION_COMMENT);
    String apiKey = getUniqueValue(options, TENANT_OPTION_API_KEY);
    if (apiKey == null) {
      apiKey = this.apiKey;
    }
    String apiSecret = getUniqueValue(options, TENANT_OPTION_API_SECRET);
    if (apiSecret == null) {
      apiSecret = this.apiSecret;
    }
    String username = getUniqueValue(options, RBAC_OPTION_USERNAME);
    if (username == null) {
      username = this.username;
    }
    String password = getUniqueValue(options, RBAC_OPTION_PASSWORD);
    if (password == null) {
      password = this.password;
    }

    options.removeAll(AUDIT_OPTION_CREATED_BY);
    options.removeAll(AUDIT_OPTION_REASON);
    options.removeAll(AUDIT_OPTION_COMMENT);
    options.removeAll(TENANT_OPTION_API_KEY);
    options.removeAll(TENANT_OPTION_API_SECRET);
    options.removeAll(RBAC_OPTION_USERNAME);
    options.removeAll(RBAC_OPTION_PASSWORD);

    final BoundRequestBuilder builder =
        getBuilderWithHeaderAndQuery(verb, getKBServerUrl(uri), username, password, options);

    // Multi-Tenancy headers
    if (apiKey != null) {
      builder.addHeader(JaxrsResource.HDR_API_KEY, apiKey);
    }
    if (apiSecret != null) {
      builder.addHeader(JaxrsResource.HDR_API_SECRET, apiSecret);
    }
    // Metadata Additional headers
    if (createdBy != null) {
      builder.addHeader(JaxrsResource.HDR_CREATED_BY, createdBy);
    }
    if (reason != null) {
      builder.addHeader(JaxrsResource.HDR_REASON, reason);
    }
    if (comment != null) {
      builder.addHeader(JaxrsResource.HDR_COMMENT, comment);
    }

    if (!"GET".equals(verb) && !"HEAD".equals(verb)) {
      if (body != null) {
        if (body instanceof String) {
          builder.setBody((String) body);
        } else {
          try {
            builder.setBody(mapper.writeValueAsString(body));
          } catch (JsonProcessingException e) {
            throw new KillBillClientException(e);
          }
        }
      } else {
        builder.setBody("{}");
      }
    }

    if (followLocation) {
      final Response response = executeAndWait(builder, timeoutSec, Response.class);
      if (response == null || response.getHeader("Location") == null) {
        // 404, bad request, ...
        return Response.class.isAssignableFrom(clazz) ? (T) response : null;
      } else {
        final String location = response.getHeader("Location");
        return doGetWithUrl(location, optionsForFollow, timeoutSec, clazz);
      }
    } else {
      return executeAndWait(builder, timeoutSec, clazz);
    }
  }