Esempio n. 1
0
  /**
   * Retrieves the configured property values for the view bean definition associated with the given
   * id
   *
   * <p>Since constructing the View object can be expensive, when metadata only is needed this
   * method can be used to retrieve the configured property values. Note this looks at the merged
   * bean definition
   *
   * @param viewId - id for the view to retrieve
   * @return PropertyValues configured on the view bean definition, or null if view is not found
   */
  public PropertyValues getViewPropertiesById(String viewId) {
    String beanName = viewBeanEntriesById.get(viewId);
    if (StringUtils.isNotBlank(beanName)) {
      BeanDefinition beanDefinition = ddBeans.getMergedBeanDefinition(beanName);

      return beanDefinition.getPropertyValues();
    }

    return null;
  }
Esempio n. 2
0
  /**
   * Retrieves the configured property values for the view bean definition associated with the given
   * type and index
   *
   * <p>Since constructing the View object can be expensive, when metadata only is needed this
   * method can be used to retrieve the configured property values. Note this looks at the merged
   * bean definition
   *
   * @param viewTypeName - type name for the view
   * @param indexKey - Map of index key parameters, these are the parameters the indexer used to
   *     index the view initially and needs to identify an unique view instance
   * @return PropertyValues configured on the view bean definition, or null if view is not found
   */
  public PropertyValues getViewPropertiesByType(
      ViewType viewTypeName, Map<String, String> indexKey) {
    String index = buildTypeIndex(indexKey);

    ViewTypeDictionaryIndex typeIndex = getTypeIndex(viewTypeName);

    String beanName = typeIndex.get(index);
    if (StringUtils.isNotBlank(beanName)) {
      BeanDefinition beanDefinition = ddBeans.getMergedBeanDefinition(beanName);

      return beanDefinition.getPropertyValues();
    }

    return null;
  }
Esempio n. 3
0
  /**
   * Gets all {@code View} prototypes configured for the given view type name
   *
   * @param viewTypeName - view type name to retrieve
   * @return List<View> view prototypes with the given type name, or empty list
   */
  public List<View> getViewsForType(ViewType viewTypeName) {
    List<View> typeViews = new ArrayList<View>();

    // get view ids for the type
    if (viewEntriesByType.containsKey(viewTypeName.name())) {
      ViewTypeDictionaryIndex typeIndex = viewEntriesByType.get(viewTypeName.name());
      for (Entry<String, String> typeEntry : typeIndex.getViewIndex().entrySet()) {
        View typeView = ddBeans.getBean(typeEntry.getValue(), View.class);
        typeViews.add(typeView);
      }
    } else {
      throw new DataDictionaryException("Unable to find view index for type: " + viewTypeName);
    }

    return typeViews;
  }
Esempio n. 4
0
  /**
   * Retrieves the view singleton from spring that has the given id.
   *
   * @param viewId the unique id for the view
   * @return View instance with the given id
   */
  public View getImmutableViewById(String viewId) {
    String beanName = viewBeanEntriesById.get(viewId);
    if (StringUtils.isBlank(beanName)) {
      throw new DataDictionaryException("Unable to find View with id: " + viewId);
    }

    View view = ddBeans.getBean(beanName, View.class);

    if (UifConstants.ViewStatus.CREATED.equals(view.getViewStatus())) {
      try {
        ViewLifecycle.preProcess(view);
      } catch (IllegalStateException ex) {
        if (LOG.isDebugEnabled()) {
          LOG.debug(
              "preProcess not run due to an IllegalStateException. Exception message: "
                  + ex.getMessage());
        }
      }
    }

    return view;
  }
Esempio n. 5
0
  /**
   * Initializes the view index {@code Map} then iterates through all the beans in the factory that
   * implement {@code View}, adding them to the index
   */
  protected void buildViewIndicies() {
    LOG.info("Starting View Index Building");

    viewBeanEntriesById = new HashMap<String, String>();
    viewEntriesByType = new HashMap<String, ViewTypeDictionaryIndex>();
    viewPools = new HashMap<String, UifViewPool>();

    boolean inDevMode =
        Boolean.parseBoolean(
            ConfigContext.getCurrentContextConfig()
                .getProperty(KRADConstants.ConfigParameters.KRAD_DEV_MODE));

    ExecutorService executor = Executors.newFixedThreadPool(threadPoolSize);

    String[] beanNames = ddBeans.getBeanNamesForType(View.class);
    for (final String beanName : beanNames) {
      BeanDefinition beanDefinition = ddBeans.getMergedBeanDefinition(beanName);
      PropertyValues propertyValues = beanDefinition.getPropertyValues();

      String id = ViewModelUtils.getStringValFromPVs(propertyValues, "id");
      if (StringUtils.isBlank(id)) {
        id = beanName;
      }

      if (viewBeanEntriesById.containsKey(id)) {
        throw new DataDictionaryException(
            "Two views must not share the same id. Found duplicate id: " + id);
      }

      viewBeanEntriesById.put(id, beanName);

      indexViewForType(propertyValues, id);

      // pre-load views if necessary
      if (!inDevMode) {
        String poolSizeStr = ViewModelUtils.getStringValFromPVs(propertyValues, "preloadPoolSize");
        if (StringUtils.isNotBlank(poolSizeStr)) {
          int poolSize = Integer.parseInt(poolSizeStr);
          if (poolSize < 1) {
            continue;
          }

          final View view = (View) ddBeans.getBean(beanName);
          final UifViewPool viewPool = new UifViewPool();
          viewPool.setMaxSize(poolSize);
          for (int j = 0; j < poolSize; j++) {
            Runnable createView =
                new Runnable() {
                  @Override
                  public void run() {
                    viewPool.addViewInstance((View) CopyUtils.copy(view));
                  }
                };

            executor.execute(createView);
          }
          viewPools.put(id, viewPool);
        }
      }
    }

    executor.shutdown();

    LOG.info("Completed View Index Building");
  }