Skip to content

Commit

Permalink
[3614] Add the ability to contribute additional payloads to represent…
Browse files Browse the repository at this point in the history
…ation subscriptions

Bug: #3614
Signed-off-by: Michaël Charfadi <[email protected]>
  • Loading branch information
mcharfadi authored and sbegaudeau committed Jun 17, 2024
1 parent 2132ea8 commit 71a180b
Show file tree
Hide file tree
Showing 15 changed files with 968 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ More existing APIs will be migrated to this new common pattern.
- https://github.com/eclipse-sirius/sirius-web/issues/3344[#3344] [core] Add support for reloading representations from the database
- https://github.com/eclipse-sirius/sirius-web/issues/3553[#3553] [core] Add RepresentationFactory extension point
- https://github.com/eclipse-sirius/sirius-web/issues/3587[#3587] [sirius-web] Add an extension point to contribute new project cards

- https://github.com/eclipse-sirius/sirius-web/issues/3614[#3614] [core] Add the ability to contribute additional payloads to representation subscriptions

=== Improvements

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*******************************************************************************
* Copyright (c) 2024 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.components.collaborative.api;

import org.eclipse.sirius.components.core.api.IInput;
import org.eclipse.sirius.components.core.api.IPayload;

import reactor.core.publisher.Flux;

/**
* Can be used to customize outputEvents of IRepresentationEventProcessor.
*
* @author mcharfadi
*/
public interface IRepresentationEventProcessorFluxCustomizer {

boolean canHandle(String editingContextId, IRepresentationConfiguration configuration, IInput input, IRepresentationEventProcessor representationEventProcessor);

Flux<IPayload> customize(String editingContextId, IRepresentationConfiguration configuration, IInput input, IRepresentationEventProcessor representationEventProcessor, Flux<IPayload> outputEvents);

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*******************************************************************************/
package org.eclipse.sirius.components.forms.tests.assertions;

import static org.assertj.core.api.Assertions.assertThat;

import org.assertj.core.api.AbstractAssert;
import org.eclipse.sirius.components.forms.Checkbox;

Expand All @@ -25,4 +27,39 @@ public class CheckboxAssert extends AbstractAssert<CheckboxAssert, Checkbox> {
public CheckboxAssert(Checkbox checkbox) {
super(checkbox, CheckboxAssert.class);
}

public CheckboxAssert hasLabel(String label) {
assertThat(this.actual.getLabel()).isEqualTo(label);

return this;
}

public CheckboxAssert hasValue(boolean value) {
assertThat(this.actual.isValue()).isEqualTo(value);

return this;
}

public CheckboxAssert hasHelp(String help) {
assertThat(this.actual.getHelpTextProvider().get()).isEqualTo(help);

return this;
}

public CheckboxAssert isReadOnly() {
assertThat(this.actual.isReadOnly())
.withFailMessage("Expecting the checkbox to be read only but was not read only instead")
.isTrue();

return this;
}

public CheckboxAssert isNotReadOnly() {
assertThat(this.actual.isReadOnly())
.withFailMessage("Expecting the checkbox not to be read only but was read only instead")
.isFalse();

return this;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.eclipse.sirius.components.forms.DateTime;
import org.eclipse.sirius.components.forms.Form;
import org.eclipse.sirius.components.forms.Group;
import org.eclipse.sirius.components.forms.Link;
import org.eclipse.sirius.components.forms.MultiSelect;
import org.eclipse.sirius.components.forms.Page;
import org.eclipse.sirius.components.forms.RichText;
Expand Down Expand Up @@ -49,6 +50,10 @@ public static CheckboxAssert assertThat(Checkbox checkbox) {
return new CheckboxAssert(checkbox);
}

public static LinkAssert assertThat(Link link) {
return new LinkAssert(link);
}

public static MultiSelectAssert assertThat(MultiSelect multiSelect) {
return new MultiSelectAssert(multiSelect);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*******************************************************************************
* Copyright (c) 2024 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.components.forms.tests.assertions;

import static org.assertj.core.api.Assertions.assertThat;

import org.assertj.core.api.AbstractAssert;
import org.eclipse.sirius.components.forms.Link;

/**
* Custom assertion class used to perform some tests on a link widget.
*
* @author sbegaudeau
*/
public class LinkAssert extends AbstractAssert<LinkAssert, Link> {

public LinkAssert(Link link) {
super(link, LinkAssert.class);
}

public LinkAssert hasLabel(String label) {
assertThat(this.actual.getLabel()).isEqualTo(label);

return this;
}

public LinkAssert hasUrl(String url) {
assertThat(this.actual.getUrl()).isEqualTo(url);

return this;
}

public LinkAssert hasHelp(String help) {
assertThat(this.actual.getHelpTextProvider().get()).isEqualTo(help);

return this;
}

public LinkAssert isReadOnly() {
assertThat(this.actual.isReadOnly())
.withFailMessage("Expecting the link to be read only but was not read only instead")
.isTrue();

return this;
}

public LinkAssert isNotReadOnly() {
assertThat(this.actual.isReadOnly())
.withFailMessage("Expecting the link not to be read only but was read only instead")
.isFalse();

return this;
}

public LinkAssert isBold() {
assertThat(this.actual.getStyle().isBold())
.withFailMessage("Expecting the link to be bold but was not bold instead")
.isTrue();

return this;
}

public LinkAssert isNotBold() {
assertThat(this.actual.getStyle().isBold())
.withFailMessage("Expecting the link not to be bold but was bold instead")
.isFalse();

return this;
}

public LinkAssert isItalic() {
assertThat(this.actual.getStyle().isItalic())
.withFailMessage("Expecting the link to be italic but was not italic instead")
.isTrue();

return this;
}

public LinkAssert isNotItalic() {
assertThat(this.actual.getStyle().isItalic())
.withFailMessage("Expecting the link not to be italic but was italic instead")
.isFalse();

return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*******************************************************************************
* Copyright (c) 2024 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.components.forms.tests.graphql;

import java.util.Objects;

import org.eclipse.sirius.components.collaborative.forms.dto.EditCheckboxInput;
import org.eclipse.sirius.components.graphql.tests.api.IGraphQLRequestor;
import org.eclipse.sirius.components.graphql.tests.api.IMutationRunner;
import org.springframework.stereotype.Service;

/**
* Used to edit a checkbox with the GraphQL API.
*
* @author sbegaudeau
*/
@Service
public class EditCheckboxMutationRunner implements IMutationRunner<EditCheckboxInput> {

private static final String EDIT_CHECKBOX_MUTATION = """
mutation editCheckbox($input: EditCheckboxInput!) {
editCheckbox(input: $input) {
__typename
}
}
""";

private final IGraphQLRequestor graphQLRequestor;

public EditCheckboxMutationRunner(IGraphQLRequestor graphQLRequestor) {
this.graphQLRequestor = Objects.requireNonNull(graphQLRequestor);
}

@Override
public String run(EditCheckboxInput input) {
return this.graphQLRequestor.execute(EDIT_CHECKBOX_MUTATION, input);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@
*******************************************************************************/
package org.eclipse.sirius.web.starter;

import java.util.List;
import java.util.Objects;
import java.util.concurrent.Executors;

import org.eclipse.sirius.components.collaborative.api.IEditingContextEventProcessorRegistry;
import org.eclipse.sirius.components.collaborative.api.IRepresentationConfiguration;
import org.eclipse.sirius.components.collaborative.api.IRepresentationEventProcessor;
import org.eclipse.sirius.components.collaborative.api.IRepresentationEventProcessorFluxCustomizer;
import org.eclipse.sirius.components.collaborative.api.ISubscriptionManagerFactory;
import org.eclipse.sirius.components.collaborative.editingcontext.api.IEditingContextEventProcessorExecutorServiceProvider;
import org.eclipse.sirius.components.collaborative.representations.SubscriptionManager;
Expand Down Expand Up @@ -68,6 +72,12 @@
})
public class SiriusWebStarterConfiguration {

private final List<IRepresentationEventProcessorFluxCustomizer> representationEventProcessorFluxCustomizers;

public SiriusWebStarterConfiguration(List<IRepresentationEventProcessorFluxCustomizer> representationEventProcessorFluxCustomizers) {
this.representationEventProcessorFluxCustomizers = Objects.requireNonNull(representationEventProcessorFluxCustomizers);
}

@Bean
@ConditionalOnMissingBean(IEditingContextEventProcessorExecutorServiceProvider.class)
public IEditingContextEventProcessorExecutorServiceProvider editingContextEventProcessorExecutorServiceProvider() {
Expand Down Expand Up @@ -123,12 +133,22 @@ public IEventProcessorSubscriptionProvider eventProcessorSubscriptionProvider(IE
public Flux<IPayload> getSubscription(String editingContextId, IRepresentationConfiguration representationConfiguration, IInput input) {
return editingContextEventProcessorRegistry.getOrCreateEditingContextEventProcessor(editingContextId)
.flatMap(processor -> processor.acquireRepresentationEventProcessor(representationConfiguration, input))
.map(representationEventProcessor -> representationEventProcessor.getOutputEvents(input))
.map(representationEventProcessor -> customizeFlux(editingContextId, representationConfiguration, input, representationEventProcessor))
.orElse(Flux.empty());
}
};
}

private Flux<IPayload> customizeFlux(String editingContextId, IRepresentationConfiguration representationConfiguration, IInput input, IRepresentationEventProcessor representationEventProcessor) {
Flux<IPayload> flux = representationEventProcessor.getOutputEvents(input);
for (IRepresentationEventProcessorFluxCustomizer representationEventProcessorFluxCustomizer : this.representationEventProcessorFluxCustomizers) {
if (representationEventProcessorFluxCustomizer.canHandle(editingContextId, representationConfiguration, input, representationEventProcessor)) {
flux = representationEventProcessorFluxCustomizer.customize(editingContextId, representationConfiguration, input, representationEventProcessor, flux);
}
}
return flux;
}

@Bean
@ConditionalOnMissingBean
public IEditingContextDispatcher editingContextDispatcher(IEditingContextEventProcessorRegistry editingContextEventProcessorRegistry, IMessageService messageService) {
Expand Down
Loading

0 comments on commit 71a180b

Please sign in to comment.