public ConfigTypeNode enrich(final ConfigTypeNode node, final String lang) { return doEnrich(node.getConfigurationType(), lang, patch -> { final ConfigTypeNode copy = new ConfigTypeNode(node.getId(), node.getVersion(), node.getParentId(), node.getConfigurationType(), node.getName(), node.getDisplayName(), node.getEdges(), new ArrayList<>(), new ArrayList<>(node.getActions())); patch.doPatchProperties(copy.getProperties(), node.getProperties()); patch.appendBuiltInActions(copy.getActions()); return copy; }).orElse(node); }
private CompletionStage<UiNode> toUiNode(final String language, final ConfigTypeNode node, final ConfigTypeNodes nodes, final ComponentIndices componentIndices, final boolean noFamily, final Function<String, String> placeholderProvider) { final ConfigTypeNode family = noFamily ? defaultFamily : configurationService.getFamilyOf(node.getParentId(), nodes); final String icon = noFamily ? null : configurationService.findIcon(family.getId(), componentIndices); final Node configType = new Node(node.getId(), node.getDisplayName(), family.getId(), family.getDisplayName(), icon, node.getEdges(), node.getVersion(), node.getName()); return uiSpecService .convert(family.getName(), language, modelEnricherService.enrich(node, language), new UiSpecContext(language, placeholderProvider)) .thenApply(uiSpec -> new UiNode(uiSpec, configType)); }
private CompletionStage<LinkedHashMap<String, String>> findPotentialIdsAndNames(final ConfigTypeNode node, final UiSpecContext context) { return referenceService .findReferencesByTypeAndName(node.getConfigurationType(), node.getId(), context) .thenApply(values -> ofNullable(values.getItems()) .map(items -> items .stream() .collect(toMap(Values.Item::getId, Values.Item::getLabel, (a, b) -> { throw new IllegalArgumentException("Conflict is not possible here"); }, LinkedHashMap::new))) .orElseGet(LinkedHashMap::new)); }
final Stream<ConfigTypeNode> configNode; if (idFilter.test(c.getId())) { final ConfigTypeNode node = new ConfigTypeNode(); node.setId(c.getId()); node.setVersion(c.getVersion()); node.setConfigurationType(c.getKey().getConfigType()); node.setName(c.getKey().getConfigName()); node.setParentId(parentId); node .setDisplayName(resourcesBundle .configurationDisplayName(c.getKey().getConfigType(), c.getKey().getConfigName()) .orElse(c.getKey().getConfigName())); if (!lightPayload) { node.setActions(actionsService.findActions(family, container, locale, c, resourcesBundle)); final String forcedPrefix = c.getMeta().getName(); node .setProperties(propertiesService .buildProperties(singletonList(c.getMeta()), loader, locale, null) .map(p -> new SimplePropertyDefinition( node.setEdges(c.getChildConfigs().stream().map(Config::getId).collect(toSet()));
private CompletionStage<NewForm> createChildrenChooserForm(final UiSpecContext context, final List<ConfigTypeNode> childrenSpec, final ConfigTypeNode parentSpec, final String parentEntityId, final String selectedId, final ConfigTypeNodes nodes) { final ConfigTypeNode refChild = childrenSpec .stream() .filter(it -> it.getId().equals(selectedId)) .findFirst() .orElseGet(() -> childrenSpec.iterator().next()); final ConfigTypeNode family = configurationService.getFamilyOf(refChild.getId(), nodes); final ConfigTypeNode formModel = modelEnricherService.enrich(refChild, context.getLanguage()); formModel .getProperties() .add(createChildrenChooserProperty(childrenSpec, parentEntityId, context.getLanguage(), selectedId, modelEnricherService.findPropertyPrefixForEnrichingProperty(refChild.getConfigurationType()))); return componentClient .getAllComponents(context.getLanguage(), context.getPlaceholderProvider()) .thenCompose(components -> uiSpecService .convert(family.getName(), context.getLanguage(), formModel, context) .thenApply(ui -> new UiNode(ui, new Node(selectedId, refChild.getDisplayName(), family.getId(), family.getDisplayName(), ofNullable(family.getId()) .map(id -> configurationService.findIcon(id, components)) .orElse(null), emptyList(), null, refChild.getName())))) .thenApply(this::toNewFormResponse) .thenCompose( newForm -> handleReferences(configurationService.getFamilyOf(refChild.getId(), nodes).getName(), context, refChild, parentEntityId, parentSpec, newForm)); }
public Optional<SimplePropertyDefinition> findFormId(final ConfigTypeNode node) { return node .getProperties() .stream() .filter(p -> "true".equals(p.getMetadata().get("proxyserver::formId"))) .findFirst(); }
.thenCompose(detail -> configurations .getAllConfigurations(context.getLanguage(), context.getPlaceholderProvider()) .thenApply(nodes -> configurationService.getFamilyOf(detail.getId(), nodes)) .thenCompose(familyNode -> filterProperties(familyNode.getName(), detail.getProperties(), context) .thenCompose(props -> replaceReferences(context, props, form.getProperties()).thenApply(nestedProps -> { final String root = detail .getProperties() .stream() .map(SimplePropertyDefinition::getPath)
final ConfigTypeNode node = new ConfigTypeNode(); node.setId(family.getId()); node.setName(family.getMeta().getName()); node.setDisplayName(resourcesBundle.displayName().orElse(family.getMeta().getName())); node.setEdges(family.getConfigs().stream().map(Config::getId).collect(toSet())); familyNode = Stream.of(node); } else {
@Override public int compareTo(final ComparableConfigTypeNode o) { if (o == null) { return -1; } if (o == this || delegate == o.getDelegate()) { return 0; } if (isNested(this, o)) { return -1; } if (isNested(o, this)) { return 1; } // just to sort globally final int myPropCount = delegate.getProperties().size(); final int otherPropCount = o.getDelegate().getProperties().size(); if (myPropCount == otherPropCount) { return delegate.getId().compareTo(o.getDelegate().getId()); } return myPropCount - otherPropCount; }
.thenCompose(node -> { final JsonObject enrichment = modelEnricherService.extractEnrichment(node.getConfigurationType(), lang, payload); final JsonObject configuration = enrichment.isEmpty() ? payload : payload .collect(toJsonObject()); return onPersistEvent .fireAsync(new OnPersist(requestContext, jsonb, node.getId(), enrichment, node.getProperties(), configurationFormatter.flatten(configuration)), notificationOptions) .thenCompose(persist -> {
private CompletionStage<ConfigTypeNode> getEnrichedNode(final String id, final UiSpecContext context, final String family) { return getNode(id, context.getLanguage(), context.getPlaceholderProvider()) .thenApply(node -> modelEnricherService.enrich(node, context.getLanguage())) .thenCompose(node -> propertiesService .filterProperties(family, node.getProperties(), context) .thenApply(newProps -> { node.setProperties(newProps); return node; })); }
.stream() .filter(node -> configurationService .getFamilyOf(node.getId(), nodes) .getName() .equals(family) && type.equals(node.getConfigurationType()) && name.equals(node.getName())) .findFirst() .map(node -> findPotentialIdsAndNames(node, context))
case 0: throw new IllegalArgumentException( "No dataset available for connection " + parentSpec.getDisplayName()); case 1: return configurationClient .getDetails(context.getLanguage(), parentSpec.getId(), context.getPlaceholderProvider()) .thenCompose( parent -> configurationClient .getDetails(context.getLanguage(), childrenSpec.iterator().next().getId(), context.getPlaceholderProvider()) .thenCompose( child -> toNewForm( configurationService .getFamilyOf(child.getId(), nodes) .getName(), context, child, entityId, parent))); default: // add a dropdown to select the dataset
.thenCompose(config -> { final JsonObject enrichment = modelEnricherService.extractEnrichment(config.getConfigurationType(), lang, payload); final JsonObject configuration = enrichment.isEmpty() ? payload : payload .collect(toJsonObject()); return onEditEvent .fireAsync(new OnEdit(id, requestContext, jsonb, enrichment, config.getProperties(), configurationFormatter.flatten(configuration)), notificationOptions) .thenCompose(OnEdit::getCompletionListener)
private CompletionStage<ConfigTypeNode> getNode(final String id, final String lang, final Function<String, String> placeholderProvider) { return id.isEmpty() // todo: drop that hardcoded datastore string ? CompletableFuture .completedFuture(new ConfigTypeNode("datastore", 0, null, "datastore", "datastore", "datastore", emptySet(), new ArrayList<>(), new ArrayList<>())) : configurationClient.getDetails(lang, id, placeholderProvider); }
private CompletionStage<NewForm> toNewForm(final String family, final UiSpecContext context, final ConfigTypeNode node, final String refId, final ConfigTypeNode parentFormSpec) { return self .getNewForm(context, node.getId()) .thenCompose(newForm -> handleReferences(family, context, node, refId, parentFormSpec, newForm)); }
private CompletionStage<Ui> toUiSpec(final ConfigTypeNode detail, final ConfigTypeNode family, final UiSpecContext context) { return configurationService .filterNestedConfigurations(family.getName(), detail, context) .thenCompose(newDetail -> uiSpecService .convert(family.getName(), context.getLanguage(), newDetail, context)); }
private SimplePropertyDefinition createChildrenChooserProperty(final List<ConfigTypeNode> childrenTypes, final String parentEntityId, final String locale, final String selectedItem, final String propertyPrefix) { final Map<String, String> metadata = new HashMap<>(); metadata .put("action::reloadFromParentEntityIdAndType", "builtin::root::reloadFromParentEntityIdAndType(" + "parentId=" + parentEntityId + ",type=" + childrenTypes.iterator().next().getConfigurationType() + ")"); metadata.put("action::reloadFromParentEntityIdAndType::parameters", ".."); final String simpleName = "childrenType"; final String path = ofNullable(propertyPrefix).filter(it -> !it.isEmpty()).map(p -> p + '.').orElse("") + simpleName; final LinkedHashMap<String, String> values = createConfigTypesValues(childrenTypes); return new SimplePropertyDefinition(path, simpleName, i18n.actionServiceChildrenTypePropertyDisplayName(new Locale(ofNullable(locale).orElse(""))), "enum", selectedItem, new PropertyValidation(true, null, null, null, null, null, null, null, null, values.keySet()), metadata, null, values); }
private CompletionStage<UiNode> toUiNode(final UiSpecContext context, final ConfigTypeNode detail, final ComponentIndices iconComponents, final ConfigTypeNode family) { return toUiSpec(detail, family, context) .thenApply(ui -> new UiNode(ui, new Node(detail.getId(), detail.getDisplayName(), family.getId(), family.getDisplayName(), ofNullable(family.getId()) .map(id -> configurationService.findIcon(id, iconComponents)) .orElse(null), detail.getEdges(), detail.getVersion(), detail.getName()))); }
final Map<String, String> configInstance = new HashMap<>(); final SimplePropertyDefinition refProp = node .getProperties() .stream() .filter(it -> it .getMetadata() .getOrDefault("configurationtype::name", "") .equals(parentFormSpec.getName()) && it .getMetadata() .getOrDefault("configurationtype::type", "") .equals(parentFormSpec.getConfigurationType())) .findFirst() .orElseThrow(() -> new IllegalStateException( "No parent matched for form " + node.getId() + "(entity=" + refId + ")")); configInstance.put(refProp.getPath() + ".$selfReferenceType", node.getConfigurationType()); .filterProperties(family, node.getProperties(), context) .thenCompose(props -> propertiesService.replaceReferences(context, props, configInstance)) .thenApply(props -> { if (node.getProperties() != null && !node.getProperties().isEmpty()) { final Map<String, String> mergedWithDefaults = new HashMap<>(formatter.flatten(newForm.getProperties())); mergedWithDefaults.putAll(props); final JsonObject properties = formatter.unflatten(node.getProperties(), mergedWithDefaults); final JsonObject enrichedProperties = newForm .getProperties()