@Override public boolean equals(Object otherObj) { if (!(otherObj instanceof ModuleMultimap)) { return false; } ModuleMultimap other = (ModuleMultimap) otherObj; Consumer<Exception> noopExceptionHandler = e -> { }; return new EqualsBuilder() .append(moduleListSuppliers.keySet(), other.moduleListSuppliers.keySet()) .append(getValidModuleLists(noopExceptionHandler), other.getValidModuleLists(noopExceptionHandler)) .isEquals(); }
@Override public ModuleMultimap get() { return new ModuleMultimap(modules); } });
/** * Returns a map of module types to list of modules, excluding module types where retrieval failed, typically due * to validation errors. * * @param exceptionHandler the exception handler to invoke if an error occurred * @return the valid module lists */ public Map<String, List<ModuleBean>> getValidModuleLists(Consumer<Exception> exceptionHandler) { Optional<Consumer<Exception>> optionalExceptionHandler = Optional.of(exceptionHandler); for (String moduleType : moduleListSuppliers.keySet()) { loadExistingModuleList(moduleType, optionalExceptionHandler); } return Collections.unmodifiableMap(validModules); }
private static ImmutableMap<String, String> buildKeyMap(ConnectAddonBean addon) { ImmutableMap.Builder<String, String> keyMapBuilder = ImmutableMap.<String, String>builder(); Consumer<Exception> moduleValidationExceptionHandler = new ModuleValidationExceptionHandler(); { Optional<List<ModuleBean>> optionalWebItems = addon.getModules().getValidModuleListOfType("webItems", moduleValidationExceptionHandler); optionalWebItems.ifPresent( webItems -> keyMapBuilder.putAll(createKeyToQualifiedKeyMap(addon, webItems)) ); } { Optional<List<ModuleBean>> optionalWebSections = addon.getModules().getValidModuleListOfType("webSections", moduleValidationExceptionHandler); optionalWebSections.ifPresent( webSections -> keyMapBuilder.putAll(createKeyToQualifiedKeyMap(addon, webSections)) ); } return keyMapBuilder.build(); }
/** * Get a module bean, restricting which type it is allowed to be. * * @param moduleKey the module key * @param allowedBeanTypes allowed module bean types * @return Module bean */ public Optional<? extends ModuleBean> getValidModuleOfType(String moduleKey, Set<Class<? extends ModuleBean>> allowedBeanTypes, Consumer<Exception> exceptionHandler) { return allowedBeanTypes.stream() .flatMap(type -> getValidModuleListOfClass(type, exceptionHandler) .stream()) .filter(moduleBean -> (moduleBean instanceof RequiredKeyBean) && ((RequiredKeyBean) moduleBean).getRawKey().equals(moduleKey)) .findFirst(); }
private static ImmutableMap<String, String> buildKeyMap(ConnectAddonBean addon) { ImmutableMap.Builder<String, String> keyMapBuilder = ImmutableMap.<String, String>builder(); Consumer<Exception> moduleValidationExceptionHandler = new ModuleValidationExceptionHandler(); { Optional<List<ModuleBean>> optionalWebItems = addon.getModules().getValidModuleListOfType("webItems", moduleValidationExceptionHandler); optionalWebItems.ifPresent( webItems -> keyMapBuilder.putAll(createKeyToQualifiedKeyMap(addon, webItems)) ); } { Optional<List<ModuleBean>> optionalWebSections = addon.getModules().getValidModuleListOfType("webSections", moduleValidationExceptionHandler); optionalWebSections.ifPresent( webSections -> keyMapBuilder.putAll(createKeyToQualifiedKeyMap(addon, webSections)) ); } return keyMapBuilder.build(); }
/** * Get a module bean, restricting which type it is allowed to be. * * @param moduleKey the module key * @param allowedBeanTypes allowed module bean types * @return Module bean */ public Optional<? extends ModuleBean> getValidModuleOfType(String moduleKey, Set<Class<? extends ModuleBean>> allowedBeanTypes, Consumer<Exception> exceptionHandler) { return allowedBeanTypes.stream() .flatMap(type -> getValidModuleListOfClass(type, exceptionHandler) .stream()) .filter(moduleBean -> (moduleBean instanceof RequiredKeyBean) && ((RequiredKeyBean) moduleBean).getRawKey().equals(moduleKey)) .findFirst(); }
@Override public boolean equals(Object otherObj) { if (!(otherObj instanceof ModuleMultimap)) { return false; } ModuleMultimap other = (ModuleMultimap) otherObj; Consumer<Exception> noopExceptionHandler = e -> { }; return new EqualsBuilder() .append(moduleListSuppliers.keySet(), other.moduleListSuppliers.keySet()) .append(getValidModuleLists(noopExceptionHandler), other.getValidModuleLists(noopExceptionHandler)) .isEquals(); }
/** * Returns a list of modules of the given type, unless a validation error occurred when retrieving it. * * @param type the module type for which to return the list of modules * @param exceptionHandler the exception handler to invoke if an error occurred * @return a list of modules, or {@link Optional#empty()} if an error occurred */ public Optional<List<ModuleBean>> getValidModuleListOfType(String type, Consumer<Exception> exceptionHandler) { if (moduleListSuppliers.containsKey(type)) { return Optional.ofNullable(loadExistingModuleList(type, Optional.of(exceptionHandler))); } return Optional.empty(); }
private void addPluginInfoParameterForPageIfDeclared(PluginInformation pluginInfo, String parameterKey, ConnectAddonBean addon, String moduleType) { Optional<List<ModuleBean>> optionalPages = addon.getModules().getValidModuleListOfType( moduleType, moduleValidationExceptionHandler); optionalPages.ifPresent(moduleBeans -> { ConnectPageModuleBean page = (ConnectPageModuleBean) moduleBeans.get(0); if (null != page && !Strings.isNullOrEmpty(page.getUrl())) { pluginInfo.addParameter(parameterKey, ConnectIFrameServletPath.forModule(addon.getKey(), page.getRawKey())); } }); } }
@Override public ModuleMultimap get() { return new ModuleMultimap(modules); } });
/** * Returns a list of modules that are assignable to the given class, unless a validation error occurred when retrieving it. * * @param moduleBeanClass the module class for which to return the list of modules * @param exceptionHandler the exception handler to invoke if an error occurred * @return a list of modules, or {@link Optional#empty()} if an error occurred */ public <T extends ModuleBean> List<T> getValidModuleListOfClass(Class<T> moduleBeanClass, Consumer<Exception> exceptionHandler) { return getValidModuleLists(exceptionHandler).entrySet().stream() .flatMap(entry -> entry.getValue().stream() .filter(bean -> moduleBeanClass.isAssignableFrom(bean.getClass()))) .map(moduleBeanClass::cast) .collect(toList()); }
/** * Returns a list of modules of the given type, unless a validation error occurred when retrieving it. * * @param type the module type for which to return the list of modules * @param exceptionHandler the exception handler to invoke if an error occurred * @return a list of modules, or {@link Optional#empty()} if an error occurred */ public Optional<List<ModuleBean>> getValidModuleListOfType(String type, Consumer<Exception> exceptionHandler) { if (moduleListSuppliers.containsKey(type)) { return Optional.ofNullable(loadExistingModuleList(type, Optional.of(exceptionHandler))); } return Optional.empty(); }
/** * Returns a list of modules that are assignable to the given class, unless a validation error occurred when retrieving it. * * @param moduleBeanClass the module class for which to return the list of modules * @param exceptionHandler the exception handler to invoke if an error occurred * @return a list of modules, or {@link Optional#empty()} if an error occurred */ public <T extends ModuleBean> List<T> getValidModuleListOfClass(Class<T> moduleBeanClass, Consumer<Exception> exceptionHandler) { return getValidModuleLists(exceptionHandler).entrySet().stream() .flatMap(entry -> entry.getValue().stream() .filter(bean -> moduleBeanClass.isAssignableFrom(bean.getClass()))) .map(moduleBeanClass::cast) .collect(toList()); }
/** * Returns a map of module types to list of modules, excluding module types where retrieval failed, typically due * to validation errors. * * @param exceptionHandler the exception handler to invoke if an error occurred * @return the valid module lists */ public Map<String, List<ModuleBean>> getValidModuleLists(Consumer<Exception> exceptionHandler) { Optional<Consumer<Exception>> optionalExceptionHandler = Optional.of(exceptionHandler); for (String moduleType : moduleListSuppliers.keySet()) { loadExistingModuleList(moduleType, optionalExceptionHandler); } return Collections.unmodifiableMap(validModules); }
@Override public int hashCode() { return new HashCodeBuilder(41, 7) .append(moduleListSuppliers.keySet()) .append(getValidModuleLists(e -> { })) .build(); } }
@Override public int hashCode() { return new HashCodeBuilder(41, 7) .append(moduleListSuppliers.keySet()) .append(getValidModuleLists(e -> { })) .build(); } }
public Map<String, List<ModuleBean>> validateModules(ConnectAddonBean addon, ModuleValidationExceptionHandler exceptionHandler) throws InvalidDescriptorException { Map<String, List<ModuleBean>> validModuleLists = addon.getModules().getValidModuleLists(exceptionHandler); Map<String, ConnectModuleProvider<? extends ModuleBean>> moduleProviders = getModuleProviders(); for (Map.Entry<String, List<ModuleBean>> validModuleList : validModuleLists.entrySet()) { @SuppressWarnings("unchecked") ConnectModuleProvider<ModuleBean> moduleProvider = (ConnectModuleProvider<ModuleBean>) moduleProviders.get(validModuleList.getKey()); List<ModuleBean> modules = validModuleList.getValue(); try { moduleProvider.validateDescriptorModuleDependencies(modules, addon); } catch (ConnectModuleValidationException e) { exceptionHandler.acceptModuleValidationCause(e); } catch (Exception e) { exceptionHandler.accept(e); } } return validModuleLists; }
public Map<String, List<ModuleBean>> validateModules(ConnectAddonBean addon, ModuleValidationExceptionHandler exceptionHandler) throws InvalidDescriptorException { final Map<String, List<ModuleBean>> validModuleLists = addon.getModules().getValidModuleLists(exceptionHandler); for (ConnectAddonBeanModuleValidator validator : connectContainerUtil.getBeansOfType(ConnectAddonBeanModuleValidator.class)) { try { validator.validateModules(addon, validModuleLists); } catch (ConnectModuleValidationException e) { exceptionHandler.acceptModuleValidationCause(e); } catch (Exception e) { exceptionHandler.accept(e); } } return validModuleLists; }