Skip to content

Commit

Permalink
[357] Remove the use of SubscriptionDescription during subscription
Browse files Browse the repository at this point in the history
Bug: #357
Signed-off-by: Stéphane Bégaudeau <[email protected]>
  • Loading branch information
sbegaudeau committed Mar 4, 2021
1 parent 0302d75 commit 4e72acd
Show file tree
Hide file tree
Showing 12 changed files with 10 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
public interface IEditingContextEventProcessor {
UUID getEditingContextId();

<T extends IRepresentationEventProcessor> Optional<T> acquireRepresentationEventProcessor(Class<T> representationEventProcessorClass, IRepresentationConfiguration configuration,
SubscriptionDescription subscriptionDescription, IInput input);
<T extends IRepresentationEventProcessor> Optional<T> acquireRepresentationEventProcessor(Class<T> representationEventProcessorClass, IRepresentationConfiguration configuration, IInput input);

List<IRepresentationEventProcessor> getRepresentationEventProcessors();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ public interface ISubscriptionManager {

void remove(UUID correlationId, String username);

void add(IInput input, SubscriptionDescription subscriptionDescription);

void remove(UUID correlationId, SubscriptionDescription subscriptionDescription);

boolean isEmpty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class NoOpEditingContextEventProcessor implements IEditingContextEventPro

@Override
public <T extends IRepresentationEventProcessor> Optional<T> acquireRepresentationEventProcessor(Class<T> representationEventProcessorClass, IRepresentationConfiguration configuration,
SubscriptionDescription subscriptionDescription, IInput input) {
IInput input) {
return Optional.empty();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2020 Obeo.
* Copyright (c) 2019, 2021 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
Expand Down Expand Up @@ -60,12 +60,6 @@ public Optional<Principal> getPrincipal(DataFetchingEnvironment environment) {
// @formatter:on
}

@Override
public String getSubscriptionId(DataFetchingEnvironment environment) {
GraphQLContext graphQLContext = environment.getContext();
return graphQLContext.getOrDefault(GraphQLConstants.SUBSCRIPTION_ID, ""); //$NON-NLS-1$
}

@Override
public boolean canEdit(DataFetchingEnvironment environment, UUID projectId) {
// @formatter:off
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2020 Obeo.
* Copyright (c) 2019, 2021 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
Expand Down Expand Up @@ -28,8 +28,6 @@ public interface IDataFetchingEnvironmentService {

Optional<Principal> getPrincipal(DataFetchingEnvironment environment);

String getSubscriptionId(DataFetchingEnvironment environment);

boolean canEdit(DataFetchingEnvironment environment, UUID projectId);

boolean canAdmin(DataFetchingEnvironment environment, UUID projectId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@
*******************************************************************************/
package org.eclipse.sirius.web.graphql.datafetchers.subscriptions;

import java.security.Principal;
import java.util.Objects;

import org.eclipse.sirius.web.annotations.graphql.GraphQLSubscriptionTypes;
import org.eclipse.sirius.web.annotations.spring.graphql.SubscriptionDataFetcher;
import org.eclipse.sirius.web.collaborative.api.dto.SubscribersUpdatedEventPayload;
import org.eclipse.sirius.web.collaborative.api.services.IEditingContextEventProcessorRegistry;
import org.eclipse.sirius.web.collaborative.api.services.SubscriptionDescription;
import org.eclipse.sirius.web.collaborative.forms.api.FormConfiguration;
import org.eclipse.sirius.web.collaborative.forms.api.IFormEventProcessor;
import org.eclipse.sirius.web.collaborative.forms.api.dto.FormEventInput;
Expand Down Expand Up @@ -76,15 +74,11 @@ public SubscriptionFormEventDataFetcher(IDataFetchingEnvironmentService dataFetc
@Override
public Publisher<IPayload> get(DataFetchingEnvironment environment) throws Exception {
var input = this.dataFetchingEnvironmentService.getInput(environment, FormEventInput.class);

Principal principal = this.dataFetchingEnvironmentService.getPrincipal(environment).orElse(null);
String subscriptionId = this.dataFetchingEnvironmentService.getSubscriptionId(environment);

var formConfiguration = new FormConfiguration(input.getFormId());

// @formatter:off
return this.editingContextEventProcessorRegistry.getOrCreateEditingContextEventProcessor(input.getProjectId())
.flatMap(processor -> processor.acquireRepresentationEventProcessor(IFormEventProcessor.class, formConfiguration, new SubscriptionDescription(principal, subscriptionId), input))
.flatMap(processor -> processor.acquireRepresentationEventProcessor(IFormEventProcessor.class, formConfiguration, input))
.map(representationEventProcessor -> representationEventProcessor.getOutputEvents(input))
.orElse(Flux.empty());
// @formatter:on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@
*******************************************************************************/
package org.eclipse.sirius.web.graphql.datafetchers.subscriptions;

import java.security.Principal;
import java.util.Objects;

import org.eclipse.sirius.web.annotations.graphql.GraphQLSubscriptionTypes;
import org.eclipse.sirius.web.annotations.spring.graphql.SubscriptionDataFetcher;
import org.eclipse.sirius.web.collaborative.api.dto.SubscribersUpdatedEventPayload;
import org.eclipse.sirius.web.collaborative.api.services.IEditingContextEventProcessorRegistry;
import org.eclipse.sirius.web.collaborative.api.services.SubscriptionDescription;
import org.eclipse.sirius.web.collaborative.forms.api.IFormEventProcessor;
import org.eclipse.sirius.web.collaborative.forms.api.PropertiesConfiguration;
import org.eclipse.sirius.web.collaborative.forms.api.dto.FormRefreshedEventPayload;
Expand Down Expand Up @@ -75,15 +73,11 @@ public SubscriptionPropertiesEventDataFetcher(IDataFetchingEnvironmentService da
@Override
public Publisher<IPayload> get(DataFetchingEnvironment environment) throws Exception {
var input = this.dataFetchingEnvironmentService.getInput(environment, PropertiesEventInput.class);

Principal principal = this.dataFetchingEnvironmentService.getPrincipal(environment).orElse(null);
String subscriptionId = this.dataFetchingEnvironmentService.getSubscriptionId(environment);

var propertiesConfiguration = new PropertiesConfiguration(input.getObjectId());

// @formatter:off
return this.editingContextEventProcessorRegistry.getOrCreateEditingContextEventProcessor(input.getProjectId())
.flatMap(processor -> processor.acquireRepresentationEventProcessor(IFormEventProcessor.class, propertiesConfiguration, new SubscriptionDescription(principal, subscriptionId), input))
.flatMap(processor -> processor.acquireRepresentationEventProcessor(IFormEventProcessor.class, propertiesConfiguration, input))
.map(representationEventProcessor -> representationEventProcessor.getOutputEvents(input))
.orElse(Flux.empty());
// @formatter:on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@
*******************************************************************************/
package org.eclipse.sirius.web.graphql.datafetchers.subscriptions;

import java.security.Principal;
import java.util.Objects;

import org.eclipse.sirius.web.annotations.graphql.GraphQLSubscriptionTypes;
import org.eclipse.sirius.web.annotations.spring.graphql.SubscriptionDataFetcher;
import org.eclipse.sirius.web.collaborative.api.dto.SubscribersUpdatedEventPayload;
import org.eclipse.sirius.web.collaborative.api.services.IEditingContextEventProcessorRegistry;
import org.eclipse.sirius.web.collaborative.api.services.SubscriptionDescription;
import org.eclipse.sirius.web.collaborative.trees.api.ITreeEventProcessor;
import org.eclipse.sirius.web.collaborative.trees.api.TreeConfiguration;
import org.eclipse.sirius.web.collaborative.trees.api.TreeEventInput;
Expand Down Expand Up @@ -74,15 +72,11 @@ public SubscriptionTreeEventDataFetcher(IDataFetchingEnvironmentService dataFetc
@Override
public Publisher<IPayload> get(DataFetchingEnvironment environment) throws Exception {
var input = this.dataFetchingEnvironmentService.getInput(environment, TreeEventInput.class);

String subscriptionId = this.dataFetchingEnvironmentService.getSubscriptionId(environment);
Principal principal = this.dataFetchingEnvironmentService.getPrincipal(environment).orElse(null);

var treeConfiguration = new TreeConfiguration(input.getEditingContextId(), input.getExpanded());

// @formatter:off
return this.editingContextEventProcessorRegistry.getOrCreateEditingContextEventProcessor(input.getEditingContextId())
.flatMap(processor -> processor.acquireRepresentationEventProcessor(ITreeEventProcessor.class, treeConfiguration, new SubscriptionDescription(principal, subscriptionId), input))
.flatMap(processor -> processor.acquireRepresentationEventProcessor(ITreeEventProcessor.class, treeConfiguration, input))
.map(representationEventProcessor -> representationEventProcessor.getOutputEvents(input))
.orElse(Flux.empty());
// @formatter:on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@
*******************************************************************************/
package org.eclipse.sirius.web.spring.collaborative.diagrams.graphql;

import java.security.Principal;
import java.util.Objects;

import org.eclipse.sirius.web.annotations.graphql.GraphQLSubscriptionTypes;
import org.eclipse.sirius.web.annotations.spring.graphql.SubscriptionDataFetcher;
import org.eclipse.sirius.web.collaborative.api.dto.SubscribersUpdatedEventPayload;
import org.eclipse.sirius.web.collaborative.api.services.IEditingContextEventProcessorRegistry;
import org.eclipse.sirius.web.collaborative.api.services.SubscriptionDescription;
import org.eclipse.sirius.web.collaborative.diagrams.api.DiagramConfiguration;
import org.eclipse.sirius.web.collaborative.diagrams.api.IDiagramEventProcessor;
import org.eclipse.sirius.web.collaborative.diagrams.api.dto.DiagramEventInput;
Expand Down Expand Up @@ -74,15 +72,11 @@ public SubscriptionDiagramEventDataFetcher(IDataFetchingEnvironmentService dataF
@Override
public Publisher<IPayload> get(DataFetchingEnvironment environment) throws Exception {
var input = this.dataFetchingEnvironmentService.getInput(environment, DiagramEventInput.class);

String subscriptionId = this.dataFetchingEnvironmentService.getSubscriptionId(environment);
Principal principal = this.dataFetchingEnvironmentService.getPrincipal(environment).orElse(null);

var diagramConfiguration = new DiagramConfiguration(input.getDiagramId());

// @formatter:off
return this.editingContextEventProcessorRegistry.getOrCreateEditingContextEventProcessor(input.getProjectId())
.flatMap(processor -> processor.acquireRepresentationEventProcessor(IDiagramEventProcessor.class, diagramConfiguration, new SubscriptionDescription(principal, subscriptionId), input))
.flatMap(processor -> processor.acquireRepresentationEventProcessor(IDiagramEventProcessor.class, diagramConfiguration, input))
.map(representationEventProcessor -> representationEventProcessor.getOutputEvents(input))
.orElse(Flux.empty());
// @formatter:on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,25 +303,22 @@ private Optional<EventHandlerResponse> handleRepresentationInput(IRepresentation

@Override
public <T extends IRepresentationEventProcessor> Optional<T> acquireRepresentationEventProcessor(Class<T> representationEventProcessorClass, IRepresentationConfiguration configuration,
SubscriptionDescription subscriptionDescription, IInput input) {
IInput input) {
// @formatter:off
var optionalRepresentationEventProcessor = Optional.ofNullable(this.representationEventProcessors.get(configuration.getId()))
.filter(representationEventProcessorClass::isInstance)
.map(representationEventProcessorClass::cast);
// @formatter:on

if (!optionalRepresentationEventProcessor.isPresent()) {
optionalRepresentationEventProcessor = this.representationEventProcessorComposedFactory.createRepresentationEventProcessor(representationEventProcessorClass, configuration,
this.editingContext);
if (optionalRepresentationEventProcessor.isPresent()) {
var representationEventProcessor = optionalRepresentationEventProcessor.get();
this.representationEventProcessors.put(configuration.getId(), representationEventProcessor);
representationEventProcessor.getSubscriptionManager().add(input, subscriptionDescription);
} else {
this.logger.warn("The representation with the id {} does not exist", configuration.getId()); //$NON-NLS-1$
}
} else {
var representationEventProcessor = optionalRepresentationEventProcessor.get();
representationEventProcessor.getSubscriptionManager().add(input, subscriptionDescription);
}

return optionalRepresentationEventProcessor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ public void remove(UUID correlationId, String username) {
}
}

@Override
public void add(IInput input, SubscriptionDescription subscriptionDescription) {
}

@Override
public void remove(UUID correlationId, SubscriptionDescription subscriptionDescription) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ public class StartMessageHandler implements IWebSocketMessageHandler {

private static final String COUNTER_METRIC_NAME = "siriusweb_graphql_ws"; //$NON-NLS-1$

/** Used to separate the session id from the operation id in the creation of the subscription id. */
private static final String SEPARATOR = "#"; //$NON-NLS-1$

private Logger logger = LoggerFactory.getLogger(StartMessageHandler.class);

private final WebSocketSession session;
Expand Down Expand Up @@ -89,7 +86,6 @@ public void handle(StartMessage startMessage) {

// @formatter:off
GraphQLContext graphQLContext = GraphQLContext.newContext()
.of(GraphQLConstants.SUBSCRIPTION_ID, this.session.getId() + SEPARATOR + id)
.of(GraphQLConstants.PRINCIPAL, this.session.getPrincipal())
.build();

Expand Down

0 comments on commit 4e72acd

Please sign in to comment.