예제 #1
0
 public static ValueSelector mockValueSelectorForEntity(
     GenuineVariableDescriptor variableDescriptor, ListMultimap<Object, Object> entityToValues) {
   ValueSelector valueSelector = mock(ValueSelector.class);
   when(valueSelector.getVariableDescriptor()).thenReturn(variableDescriptor);
   for (Map.Entry<Object, Collection<Object>> entry : entityToValues.asMap().entrySet()) {
     Object entity = entry.getKey();
     final List<Object> valueList = (List<Object>) entry.getValue();
     when(valueSelector.getSize(entity))
         .thenAnswer(
             new Answer<Long>() {
               @Override
               public Long answer(InvocationOnMock invocation) {
                 return (long) valueList.size();
               }
             });
     when(valueSelector.iterator(entity))
         .thenAnswer(
             new Answer<Iterator<Object>>() {
               @Override
               public Iterator<Object> answer(InvocationOnMock invocation) {
                 return valueList.iterator();
               }
             });
     when(valueSelector.getSize(entity)).thenReturn((long) valueList.size());
   }
   when(valueSelector.isCountable()).thenReturn(true);
   when(valueSelector.isNeverEnding()).thenReturn(false);
   return valueSelector;
 }
예제 #2
0
  /**
   * Validate domain service Ids are unique, and that the {@link PostConstruct} method, if present,
   * must either take no arguments or take a {@link Map} object), and that the {@link PreDestroy}
   * method, if present, must take no arguments.
   *
   * <p>TODO: there seems to be some duplication/overlap with {@link ServiceInitializer}.
   */
  private void validateServices(List<Object> serviceList) {
    for (Object service : serviceList) {
      final Method[] methods = service.getClass().getMethods();
      for (Method method : methods) {
        validatePostConstructMethods(service, method);
        validatePreDestroyMethods(service, method);
      }
    }

    ListMultimap<String, Object> servicesById = ArrayListMultimap.create();
    for (Object service : serviceList) {
      String id = ServiceUtil.id(service);
      servicesById.put(id, service);
    }
    for (Entry<String, Collection<Object>> servicesForId : servicesById.asMap().entrySet()) {
      String serviceId = servicesForId.getKey();
      Collection<Object> services = servicesForId.getValue();
      if (services.size() > 1) {
        throw new IllegalStateException(
            "Service ids must be unique; serviceId '"
                + serviceId
                + "' is declared by domain services "
                + classNamesFor(services));
      }
    }
  }
예제 #3
0
    @Override
    public PlanNode visitUnion(UnionNode node, RewriteContext<Set<Symbol>> context) {
      // Find out which output symbols we need to keep
      ImmutableListMultimap.Builder<Symbol, Symbol> rewrittenSymbolMappingBuilder =
          ImmutableListMultimap.builder();
      for (Symbol symbol : node.getOutputSymbols()) {
        if (context.get().contains(symbol)) {
          rewrittenSymbolMappingBuilder.putAll(symbol, node.getSymbolMapping().get(symbol));
        }
      }
      ListMultimap<Symbol, Symbol> rewrittenSymbolMapping = rewrittenSymbolMappingBuilder.build();

      // Find the corresponding input symbol to the remaining output symbols and prune the subplans
      ImmutableList.Builder<PlanNode> rewrittenSubPlans = ImmutableList.builder();
      for (int i = 0; i < node.getSources().size(); i++) {
        ImmutableSet.Builder<Symbol> expectedInputSymbols = ImmutableSet.builder();
        for (Collection<Symbol> symbols : rewrittenSymbolMapping.asMap().values()) {
          expectedInputSymbols.add(Iterables.get(symbols, i));
        }
        rewrittenSubPlans.add(
            context.rewrite(node.getSources().get(i), expectedInputSymbols.build()));
      }

      return new UnionNode(
          node.getId(),
          rewrittenSubPlans.build(),
          rewrittenSymbolMapping,
          ImmutableList.copyOf(rewrittenSymbolMapping.keySet()));
    }
예제 #4
0
  private void visitRule(
      Rule rule,
      AspectDefinition aspect,
      AspectParameters aspectParameters,
      ListMultimap<Attribute, LabelAndConfiguration> labelMap,
      ListMultimap<Attribute, Dependency> outgoingEdges) {
    Preconditions.checkNotNull(labelMap);
    for (Map.Entry<Attribute, Collection<LabelAndConfiguration>> entry :
        labelMap.asMap().entrySet()) {
      Attribute attribute = entry.getKey();
      for (LabelAndConfiguration dep : entry.getValue()) {
        Label label = dep.getLabel();
        BuildConfiguration config = dep.getConfiguration();

        Target toTarget;
        try {
          toTarget = getTarget(label);
        } catch (NoSuchThingException e) {
          throw new IllegalStateException(
              "not found: " + label + " from " + rule + " in " + attribute.getName());
        }
        if (toTarget == null) {
          continue;
        }
        BuildConfiguration.TransitionApplier transitionApplier = config.getTransitionApplier();
        if (config.useDynamicConfigurations()
            && config.isHostConfiguration()
            && !BuildConfiguration.usesNullConfiguration(toTarget)) {
          // This condition is needed because resolveLateBoundAttributes may switch config to
          // the host configuration, which is the only case DependencyResolver applies a
          // configuration transition outside of this method. We need to reflect that
          // transition in the results of this method, but config.evaluateTransition is hard-set
          // to return a NONE transition when the input is a host config. Since the outside
          // caller originally passed the *original* value of config (before the possible
          // switch), it can mistakenly interpret the result as a NONE transition from the
          // original value of config. This condition fixes that. Another fix would be to have
          // config.evaluateTransition return a HOST transition when the input config is a host,
          // but since this blemish is specific to DependencyResolver it seems best to keep the
          // fix here.
          // TODO(bazel-team): eliminate this special case by passing transitionApplier to
          // resolveLateBoundAttributes, so that method uses the same interface for transitions.
          transitionApplier.applyTransition(Attribute.ConfigurationTransition.HOST);
        } else {
          config.evaluateTransition(rule, attribute, toTarget, transitionApplier);
        }
        for (Dependency dependency :
            transitionApplier.getDependencies(
                label, requiredAspects(aspect, aspectParameters, attribute, toTarget, rule))) {
          outgoingEdges.put(entry.getKey(), dependency);
        }
      }
    }
  }
  /**
   * Returns a map of the data items.
   *
   * @return a map of items.
   * @see DataMap
   */
  @NonNull
  @Override
  public ListMultimap<String, I> getDataMap() {
    // put all the sets in a multimap. The result is that for each key,
    // there is a sorted list of items from all the layers, including removed ones.
    ListMultimap<String, I> fullItemMultimap = ArrayListMultimap.create();

    for (S resourceSet : mDataSets) {
      ListMultimap<String, I> map = resourceSet.getDataMap();
      for (Map.Entry<String, Collection<I>> entry : map.asMap().entrySet()) {
        fullItemMultimap.putAll(entry.getKey(), entry.getValue());
      }
    }

    return fullItemMultimap;
  }
  /**
   * Sets the post blob load state to TOUCHED.
   *
   * <p>After a load from the blob file, all items have their state set to nothing. If the load mode
   * is not set to incrementalState then we want the items that are in the current merge result to
   * have their state be TOUCHED.
   *
   * <p>This will allow the first use of {@link #mergeData(MergeConsumer, boolean)} to add these to
   * the consumer as if they were new items.
   *
   * @see #loadFromBlob(java.io.File, boolean)
   * @see DataItem#isTouched()
   */
  private void setPostBlobLoadStateToTouched() {
    ListMultimap<String, I> itemMap = ArrayListMultimap.create();

    // put all the sets into list per keys. The order is important as the lower sets are
    // overridden by the higher sets.
    for (S dataSet : mDataSets) {
      ListMultimap<String, I> map = dataSet.getDataMap();
      for (Map.Entry<String, Collection<I>> entry : map.asMap().entrySet()) {
        itemMap.putAll(entry.getKey(), entry.getValue());
      }
    }

    // the items that represent the current state is the last item in the list for each key.
    for (String key : itemMap.keySet()) {
      List<I> itemList = itemMap.get(key);
      itemList.get(itemList.size() - 1).resetStatusToTouched();
    }
  }
 @Override
 public Collection<List<V>> values() {
   Collection values = backingMap.asMap().values();
   return values;
 }
 @Override
 public Set<Entry<K, List<V>>> entrySet() {
   Set entries = backingMap.asMap().entrySet();
   return entries;
 }
예제 #9
0
    public SolrCell(
        CommandBuilder builder,
        Config config,
        Command parent,
        Command child,
        MorphlineContext context) {
      super(builder, config, parent, child, context);

      Config solrLocatorConfig = getConfigs().getConfig(config, "solrLocator");
      SolrLocator locator = new SolrLocator(solrLocatorConfig, context);
      LOG.debug("solrLocator: {}", locator);
      this.schema = locator.getIndexSchema();
      Preconditions.checkNotNull(schema);
      LOG.trace(
          "Solr schema: \n{}", Joiner.on("\n").join(new TreeMap(schema.getFields()).values()));

      ListMultimap<String, String> cellParams = ArrayListMultimap.create();
      String uprefix = getConfigs().getString(config, ExtractingParams.UNKNOWN_FIELD_PREFIX, null);
      if (uprefix != null) {
        cellParams.put(ExtractingParams.UNKNOWN_FIELD_PREFIX, uprefix);
      }
      for (String capture :
          getConfigs()
              .getStringList(
                  config, ExtractingParams.CAPTURE_ELEMENTS, Collections.<String>emptyList())) {
        cellParams.put(ExtractingParams.CAPTURE_ELEMENTS, capture);
      }
      Config fmapConfig = getConfigs().getConfig(config, "fmap", null);
      if (fmapConfig != null) {
        for (Map.Entry<String, Object> entry : new Configs().getEntrySet(fmapConfig)) {
          cellParams.put(ExtractingParams.MAP_PREFIX + entry.getKey(), entry.getValue().toString());
        }
      }
      String captureAttributes =
          getConfigs().getString(config, ExtractingParams.CAPTURE_ATTRIBUTES, null);
      if (captureAttributes != null) {
        cellParams.put(ExtractingParams.CAPTURE_ATTRIBUTES, captureAttributes);
      }
      String lowerNames = getConfigs().getString(config, ExtractingParams.LOWERNAMES, null);
      if (lowerNames != null) {
        cellParams.put(ExtractingParams.LOWERNAMES, lowerNames);
      }
      String defaultField = getConfigs().getString(config, ExtractingParams.DEFAULT_FIELD, null);
      if (defaultField != null) {
        cellParams.put(ExtractingParams.DEFAULT_FIELD, defaultField);
      }
      xpathExpr = getConfigs().getString(config, ExtractingParams.XPATH_EXPRESSION, null);
      if (xpathExpr != null) {
        cellParams.put(ExtractingParams.XPATH_EXPRESSION, xpathExpr);
      }

      this.dateFormats =
          getConfigs()
              .getStringList(config, "dateFormats", new ArrayList<>(DateUtil.DEFAULT_DATE_FORMATS));

      String handlerStr =
          getConfigs()
              .getString(
                  config,
                  "solrContentHandlerFactory",
                  TrimSolrContentHandlerFactory.class.getName());
      Class<? extends SolrContentHandlerFactory> factoryClass;
      try {
        factoryClass = (Class<? extends SolrContentHandlerFactory>) Class.forName(handlerStr);
      } catch (ClassNotFoundException cnfe) {
        throw new MorphlineCompilationException(
            "Could not find class " + handlerStr + " to use for " + "solrContentHandlerFactory",
            config,
            cnfe);
      }
      this.solrContentHandlerFactory =
          getSolrContentHandlerFactory(factoryClass, dateFormats, config);

      this.locale = getLocale(getConfigs().getString(config, "locale", ""));

      this.mediaTypeToParserMap = new HashMap<>();
      // MimeTypes mimeTypes = MimeTypes.getDefaultMimeTypes(); // FIXME
      // getMediaTypeRegistry.normalize()

      List<? extends Config> parserConfigs = getConfigs().getConfigList(config, "parsers");
      for (Config parserConfig : parserConfigs) {
        String parserClassName = getConfigs().getString(parserConfig, "parser");

        Object obj;
        try {
          obj = Class.forName(parserClassName).newInstance();
        } catch (Throwable e) {
          throw new MorphlineCompilationException(
              "Cannot instantiate Tika parser: " + parserClassName, config, e);
        }
        if (!(obj instanceof Parser)) {
          throw new MorphlineCompilationException(
              "Tika parser "
                  + obj.getClass().getName()
                  + " must be an instance of class "
                  + Parser.class.getName(),
              config);
        }
        Parser parser = (Parser) obj;
        this.parsers.add(parser);

        List<String> mediaTypes =
            getConfigs()
                .getStringList(parserConfig, SUPPORTED_MIME_TYPES, Collections.<String>emptyList());
        for (String mediaTypeStr : mediaTypes) {
          MediaType mediaType = parseMediaType(mediaTypeStr);
          addSupportedMimeType(mediaTypeStr);
          this.mediaTypeToParserMap.put(mediaType, parser);
        }

        if (!parserConfig.hasPath(SUPPORTED_MIME_TYPES)) {
          for (MediaType mediaType : parser.getSupportedTypes(new ParseContext())) {
            mediaType = mediaType.getBaseType();
            addSupportedMimeType(mediaType.toString());
            this.mediaTypeToParserMap.put(mediaType, parser);
          }
          List<String> extras =
              getConfigs()
                  .getStringList(
                      parserConfig,
                      ADDITIONAL_SUPPORTED_MIME_TYPES,
                      Collections.<String>emptyList());
          for (String mediaTypeStr : extras) {
            MediaType mediaType = parseMediaType(mediaTypeStr);
            addSupportedMimeType(mediaTypeStr);
            this.mediaTypeToParserMap.put(mediaType, parser);
          }
        }
      }
      // LOG.info("mediaTypeToParserMap="+mediaTypeToParserMap);

      Map<String, String[]> tmp = new HashMap();
      for (Map.Entry<String, Collection<String>> entry : cellParams.asMap().entrySet()) {
        tmp.put(entry.getKey(), entry.getValue().toArray(new String[entry.getValue().size()]));
      }
      this.solrParams = new MultiMapSolrParams(tmp);
      validateArguments();
    }
예제 #10
0
파일: FileQuery.java 프로젝트: velo/sonar
 public Map<String, Collection<String>> attributes() {
   return attributes.asMap();
 }