Skip to content

Commit

Permalink
[3679] Also split persistence service
Browse files Browse the repository at this point in the history
Bug: #3679
Signed-off-by: Guillaume Coutable <guillaume.coutable@obeo.fr>
  • Loading branch information
gcoutable committed Oct 24, 2024
1 parent 70b74f3 commit abf1b9c
Show file tree
Hide file tree
Showing 26 changed files with 279 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.eclipse.sirius.components.collaborative.api.ChangeDescription;
import org.eclipse.sirius.components.collaborative.api.ChangeKind;
import org.eclipse.sirius.components.collaborative.api.IEditingContextEventHandler;
import org.eclipse.sirius.components.collaborative.api.IRepresentationMetadataPersistenceService;
import org.eclipse.sirius.components.collaborative.api.IRepresentationPersistenceService;
import org.eclipse.sirius.components.collaborative.api.Monitoring;
import org.eclipse.sirius.components.collaborative.charts.messages.ICollaborativeChartsMessageService;
Expand Down Expand Up @@ -49,6 +50,8 @@ public class CreateHierarchyEventHandler implements IEditingContextEventHandler

private final IRepresentationDescriptionSearchService representationDescriptionSearchService;

private final IRepresentationMetadataPersistenceService representationMetadataPersistenceService;

private final IRepresentationPersistenceService representationPersistenceService;

private final IObjectService objectService;
Expand All @@ -59,10 +62,12 @@ public class CreateHierarchyEventHandler implements IEditingContextEventHandler

private final Counter counter;

public CreateHierarchyEventHandler(IRepresentationDescriptionSearchService representationDescriptionSearchService, IRepresentationPersistenceService representationPersistenceService,
IObjectService objectService, ICollaborativeChartsMessageService messageService, HierarchyCreationService hierarchyCreationService, MeterRegistry meterRegistry) {
public CreateHierarchyEventHandler(IRepresentationDescriptionSearchService representationDescriptionSearchService, IRepresentationMetadataPersistenceService representationMetadataPersistenceService,
IRepresentationPersistenceService representationPersistenceService, IObjectService objectService, ICollaborativeChartsMessageService messageService,
HierarchyCreationService hierarchyCreationService, MeterRegistry meterRegistry) {
this.representationDescriptionSearchService = Objects.requireNonNull(representationDescriptionSearchService);
this.representationPersistenceService = Objects.requireNonNull(representationPersistenceService);
this.representationMetadataPersistenceService = Objects.requireNonNull(representationMetadataPersistenceService);
this.objectService = Objects.requireNonNull(objectService);
this.messageService = Objects.requireNonNull(messageService);
this.hierarchyCreationService = Objects.requireNonNull(hierarchyCreationService);
Expand Down Expand Up @@ -102,9 +107,10 @@ public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDesc
HierarchyDescription representationDescription = optionalHierarchyDescription.get();

Hierarchy hierarchy = this.hierarchyCreationService.create(createRepresentationInput, createRepresentationInput.representationName(), object, representationDescription, editingContext);
var representationMetadata = new RepresentationMetadata(hierarchy.getId(), hierarchy.getKind(), hierarchy.getLabel(), hierarchy.getDescriptionId());
this.representationMetadataPersistenceService.save(createRepresentationInput, editingContext, representationMetadata, hierarchy.getTargetObjectId());
this.representationPersistenceService.save(createRepresentationInput, editingContext, hierarchy);

var representationMetadata = new RepresentationMetadata(hierarchy.getId(), hierarchy.getKind(), hierarchy.getLabel(), hierarchy.getDescriptionId());
payload = new CreateRepresentationSuccessPayload(input.id(), representationMetadata);
changeDescription = new ChangeDescription(ChangeKind.REPRESENTATION_CREATION, editingContext.getId(), input);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ private Hierarchy doRender(ICause cause, String label, Object targetObject, IEdi

Hierarchy newHierarchy = new HierarchyRenderer().render(element);

this.representationPersistenceService.save(null, editingContext, newHierarchy);

long end = System.currentTimeMillis();
this.timer.record(end - start, TimeUnit.MILLISECONDS);
return newHierarchy;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*******************************************************************************
* 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.RepresentationMetadata;
import org.eclipse.sirius.components.core.api.IEditingContext;
import org.eclipse.sirius.components.events.ICause;

/**
* Used to persist representation metadata.
*
* @author gcoutable
*/
public interface IRepresentationMetadataPersistenceService {

void save(ICause cause, IEditingContext editingContext, RepresentationMetadata representationMetadata, String targetObjectId);

/**
* Empty implementation, used for mocks in unit tests.
*
* @author pcdavid
*/
class NoOp implements IRepresentationMetadataPersistenceService {

@Override
public void save(ICause cause, IEditingContext editingContext, RepresentationMetadata representationMetadata, String targetObjectId) {
// Do nothing
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public Mono<IPayload> handle(IInput input) {
* The sink to publish payload
* @param input
* The input event
* @return The response computed by the event handler
*/
private void doHandle(One<IPayload> payloadSink, IInput input) {
this.logger.trace("Input received: {}", input);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.eclipse.sirius.components.collaborative.api.ChangeDescription;
import org.eclipse.sirius.components.collaborative.api.ChangeKind;
import org.eclipse.sirius.components.collaborative.api.IEditingContextEventHandler;
import org.eclipse.sirius.components.collaborative.api.IRepresentationMetadataPersistenceService;
import org.eclipse.sirius.components.collaborative.api.IRepresentationPersistenceService;
import org.eclipse.sirius.components.collaborative.api.Monitoring;
import org.eclipse.sirius.components.collaborative.deck.api.IDeckCreationService;
Expand Down Expand Up @@ -50,6 +51,8 @@ public class CreateDeckEventHandler implements IEditingContextEventHandler {

private final IRepresentationDescriptionSearchService representationDescriptionSearchService;

private final IRepresentationMetadataPersistenceService representationMetadataPersistenceService;

private final IRepresentationPersistenceService representationPersistenceService;

private final IDeckCreationService deckCreationService;
Expand All @@ -60,9 +63,10 @@ public class CreateDeckEventHandler implements IEditingContextEventHandler {

private final Counter counter;

public CreateDeckEventHandler(IRepresentationDescriptionSearchService representationDescriptionSearchService, IRepresentationPersistenceService representationPersistenceService,
public CreateDeckEventHandler(IRepresentationDescriptionSearchService representationDescriptionSearchService, IRepresentationMetadataPersistenceService representationMetadataPersistenceService, IRepresentationPersistenceService representationPersistenceService,
IDeckCreationService diagramCreationService, IObjectService objectService, ICollaborativeMessageService messageService, MeterRegistry meterRegistry) {
this.representationDescriptionSearchService = Objects.requireNonNull(representationDescriptionSearchService);
this.representationMetadataPersistenceService = Objects.requireNonNull(representationMetadataPersistenceService);
this.representationPersistenceService = Objects.requireNonNull(representationPersistenceService);
this.deckCreationService = Objects.requireNonNull(diagramCreationService);
this.objectService = Objects.requireNonNull(objectService);
Expand Down Expand Up @@ -102,10 +106,10 @@ public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDesc
Object object = optionalObject.get();

Deck deckDiagram = this.deckCreationService.create(createRepresentationInput.representationName(), object, deckDescription, editingContext);

var representationMetadata = new RepresentationMetadata(deckDiagram.id(), deckDiagram.getKind(), deckDiagram.getLabel(), deckDiagram.descriptionId());
this.representationMetadataPersistenceService.save(createRepresentationInput, editingContext, representationMetadata, deckDiagram.getTargetObjectId());
this.representationPersistenceService.save(createRepresentationInput, editingContext, deckDiagram);

var representationMetadata = new RepresentationMetadata(deckDiagram.id(), deckDiagram.getKind(), deckDiagram.label(), deckDiagram.descriptionId());
payload = new CreateRepresentationSuccessPayload(input.id(), representationMetadata);
changeDescription = new ChangeDescription(ChangeKind.REPRESENTATION_CREATION, editingContext.getId(), input);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.eclipse.sirius.components.collaborative.api.ChangeDescription;
import org.eclipse.sirius.components.collaborative.api.ChangeKind;
import org.eclipse.sirius.components.collaborative.api.IEditingContextEventHandler;
import org.eclipse.sirius.components.collaborative.api.IRepresentationMetadataPersistenceService;
import org.eclipse.sirius.components.collaborative.api.IRepresentationPersistenceService;
import org.eclipse.sirius.components.collaborative.api.Monitoring;
import org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramCreationService;
Expand Down Expand Up @@ -51,6 +52,8 @@ public class CreateDiagramEventHandler implements IEditingContextEventHandler {

private final IRepresentationDescriptionSearchService representationDescriptionSearchService;

private final IRepresentationMetadataPersistenceService representationMetadataPersistenceService;

private final IRepresentationPersistenceService representationPersistenceService;

private final IDiagramCreationService diagramCreationService;
Expand All @@ -61,9 +64,10 @@ public class CreateDiagramEventHandler implements IEditingContextEventHandler {

private final Counter counter;

public CreateDiagramEventHandler(IRepresentationDescriptionSearchService representationDescriptionSearchService, IRepresentationPersistenceService representationPersistenceService,
public CreateDiagramEventHandler(IRepresentationDescriptionSearchService representationDescriptionSearchService, IRepresentationMetadataPersistenceService representationMetadataPersistenceService, IRepresentationPersistenceService representationPersistenceService,
IDiagramCreationService diagramCreationService, IObjectService objectService, ICollaborativeDiagramMessageService messageService, MeterRegistry meterRegistry) {
this.representationDescriptionSearchService = Objects.requireNonNull(representationDescriptionSearchService);
this.representationMetadataPersistenceService = Objects.requireNonNull(representationMetadataPersistenceService);
this.representationPersistenceService = Objects.requireNonNull(representationPersistenceService);
this.diagramCreationService = Objects.requireNonNull(diagramCreationService);
this.objectService = Objects.requireNonNull(objectService);
Expand Down Expand Up @@ -93,22 +97,20 @@ public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDesc
ChangeDescription changeDescription = new ChangeDescription(ChangeKind.NOTHING, editingContext.getId(), input);

if (input instanceof CreateRepresentationInput createRepresentationInput) {
// @formatter:off
Optional<DiagramDescription> optionalDiagramDescription = this.representationDescriptionSearchService.findById(editingContext, createRepresentationInput.representationDescriptionId())
.filter(DiagramDescription.class::isInstance)
.map(DiagramDescription.class::cast);
// @formatter:on
Optional<Object> optionalObject = this.objectService.getObject(editingContext, createRepresentationInput.objectId());

if (optionalDiagramDescription.isPresent() && optionalObject.isPresent()) {
DiagramDescription diagramDescription = optionalDiagramDescription.get();
Object object = optionalObject.get();

Diagram diagram = this.diagramCreationService.create(createRepresentationInput.representationName(), object, diagramDescription, editingContext);

var representationMetadata = new RepresentationMetadata(diagram.getId(), diagram.getKind(), diagram.getLabel(), diagram.getDescriptionId());
this.representationMetadataPersistenceService.save(createRepresentationInput, editingContext, representationMetadata, diagram.getTargetObjectId());
this.representationPersistenceService.save(createRepresentationInput, editingContext, diagram);

var representationMetadata = new RepresentationMetadata(diagram.getId(), diagram.getKind(), diagram.getLabel(), diagram.getDescriptionId());
payload = new CreateRepresentationSuccessPayload(input.id(), representationMetadata);
changeDescription = new ChangeDescription(ChangeKind.REPRESENTATION_CREATION, editingContext.getId(), input);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import org.eclipse.sirius.components.collaborative.api.ChangeDescription;
import org.eclipse.sirius.components.collaborative.api.ChangeKind;
import org.eclipse.sirius.components.collaborative.api.IRepresentationMetadataPersistenceService;
import org.eclipse.sirius.components.collaborative.api.IRepresentationPersistenceService;
import org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramCreationService;
import org.eclipse.sirius.components.collaborative.diagrams.messages.ICollaborativeDiagramMessageService;
Expand Down Expand Up @@ -88,7 +89,7 @@ public Optional<Object> getObject(IEditingContext editingContext, String objectI
}
};

CreateDiagramEventHandler handler = new CreateDiagramEventHandler(representationDescriptionSearchService, new IRepresentationPersistenceService.NoOp(), diagramCreationService, objectService,
CreateDiagramEventHandler handler = new CreateDiagramEventHandler(representationDescriptionSearchService, new IRepresentationMetadataPersistenceService.NoOp(), new IRepresentationPersistenceService.NoOp(), diagramCreationService, objectService,
new ICollaborativeDiagramMessageService.NoOp(), new SimpleMeterRegistry());

var input = new CreateRepresentationInput(UUID.randomUUID(), UUID.randomUUID().toString(), UUID.randomUUID().toString(), "objectId", "representationName");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,12 @@ public FormDescriptionEditorCreationService(IRepresentationDescriptionSearchServ

@Override
public FormDescriptionEditor create(ICause cause, String label, Object targetObject, FormDescriptionEditorDescription formDescriptionEditorDescription, IEditingContext editingContext) {
FormDescriptionEditor newFormDescriptionEditor = FormDescriptionEditor.newFormDescriptionEditor(UUID.randomUUID().toString())
return FormDescriptionEditor.newFormDescriptionEditor(UUID.randomUUID().toString())
.label(label)
.targetObjectId(this.objectService.getId(targetObject))
.descriptionId(formDescriptionEditorDescription.getId())
.pages(List.of()) // We don't store form description editor pages, it will be re-render by the FormDescriptionEditorProcessor.
.build();

this.representationPersistenceService.save(cause, editingContext, newFormDescriptionEditor);

return newFormDescriptionEditor;
}

@Override
Expand Down
Loading

0 comments on commit abf1b9c

Please sign in to comment.