-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[4177] Add table representation support
Bug: #4177 Signed-off-by: Florian ROUËNÉ <[email protected]>
- Loading branch information
Showing
40 changed files
with
1,975 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...clipse/sirius/web/papaya/representations/table/PackageTableRepresentationDescription.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.web.papaya.representations.table; | ||
|
||
import java.util.List; | ||
|
||
import org.eclipse.sirius.components.collaborative.api.IRepresentationDescriptionsProvider; | ||
import org.eclipse.sirius.components.collaborative.api.RepresentationDescriptionMetadata; | ||
import org.eclipse.sirius.components.core.api.IEditingContext; | ||
import org.eclipse.sirius.components.representations.IRepresentationDescription; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* Used to provide the RepresentationDescriptionMetadata for papaya packages table. | ||
* | ||
* @author Jerome Gout | ||
*/ | ||
@Service | ||
public class PackageTableRepresentationDescription implements IRepresentationDescriptionsProvider { | ||
|
||
@Override | ||
public boolean canHandle(IRepresentationDescription representationDescription) { | ||
return representationDescription.getId().equals(PackageTableRepresentationDescriptionProvider.TABLE_DESCRIPTION_ID); | ||
} | ||
|
||
@Override | ||
public List<RepresentationDescriptionMetadata> handle(IEditingContext editingContext, Object object, IRepresentationDescription representationDescription) { | ||
return List.of(new RepresentationDescriptionMetadata(representationDescription.getId(), representationDescription.getLabel(), representationDescription.getLabel())); | ||
} | ||
|
||
} |
339 changes: 339 additions & 0 deletions
339
...irius/web/papaya/representations/table/PackageTableRepresentationDescriptionProvider.java
Large diffs are not rendered by default.
Oops, something went wrong.
27 changes: 27 additions & 0 deletions
27
...c/main/java/org/eclipse/sirius/web/tests/services/api/IGivenCreatedTableSubscription.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 CEA LIST. | ||
* 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.web.tests.services.api; | ||
|
||
import org.eclipse.sirius.components.collaborative.dto.CreateRepresentationInput; | ||
|
||
import reactor.core.publisher.Flux; | ||
|
||
/** | ||
* Used to create a table and subscribe to it. | ||
* | ||
* @author frouene | ||
*/ | ||
public interface IGivenCreatedTableSubscription { | ||
|
||
Flux<Object> createAndSubscribe(CreateRepresentationInput input); | ||
} |
68 changes: 68 additions & 0 deletions
68
...main/java/org/eclipse/sirius/web/tests/services/tables/GivenCreatedTableSubscription.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 CEA LIST. | ||
* 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.web.tests.services.tables; | ||
|
||
import java.util.Objects; | ||
import java.util.UUID; | ||
|
||
import org.eclipse.sirius.components.collaborative.dto.CreateRepresentationInput; | ||
import org.eclipse.sirius.components.collaborative.tables.TableEventInput; | ||
import org.eclipse.sirius.components.tables.tests.graphql.TableEventSubscriptionRunner; | ||
import org.eclipse.sirius.web.tests.services.api.IGivenCommittedTransaction; | ||
import org.eclipse.sirius.web.tests.services.api.IGivenCreatedRepresentation; | ||
import org.eclipse.sirius.web.tests.services.api.IGivenCreatedTableSubscription; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.test.context.transaction.TestTransaction; | ||
|
||
import graphql.execution.DataFetcherResult; | ||
import reactor.core.publisher.Flux; | ||
|
||
/** | ||
* Used to create a table and subscribe to it. | ||
* | ||
* @author frouene | ||
*/ | ||
@Service | ||
public class GivenCreatedTableSubscription implements IGivenCreatedTableSubscription { | ||
|
||
private final IGivenCommittedTransaction givenCommittedTransaction; | ||
|
||
private final IGivenCreatedRepresentation givenCreatedRepresentation; | ||
|
||
private final TableEventSubscriptionRunner tableEventSubscriptionRunner; | ||
|
||
public GivenCreatedTableSubscription(IGivenCommittedTransaction givenCommittedTransaction, IGivenCreatedRepresentation givenCreatedRepresentation, | ||
TableEventSubscriptionRunner tableEventSubscriptionRunner) { | ||
this.givenCommittedTransaction = Objects.requireNonNull(givenCommittedTransaction); | ||
this.givenCreatedRepresentation = Objects.requireNonNull(givenCreatedRepresentation); | ||
this.tableEventSubscriptionRunner = Objects.requireNonNull(tableEventSubscriptionRunner); | ||
} | ||
|
||
@Override | ||
public Flux<Object> createAndSubscribe(CreateRepresentationInput input) { | ||
this.givenCommittedTransaction.commit(); | ||
|
||
String representationId = this.givenCreatedRepresentation.createRepresentation(input); | ||
|
||
var tableEventInput = new TableEventInput(UUID.randomUUID(), input.editingContextId(), representationId); | ||
var flux = this.tableEventSubscriptionRunner.run(tableEventInput); | ||
|
||
TestTransaction.flagForCommit(); | ||
TestTransaction.end(); | ||
TestTransaction.start(); | ||
|
||
return flux.filter(DataFetcherResult.class::isInstance) | ||
.map(DataFetcherResult.class::cast) | ||
.map(DataFetcherResult::getData); | ||
} | ||
} |
98 changes: 98 additions & 0 deletions
98
...ipse/sirius/web/application/controllers/tables/PapayaTableControllerIntegrationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 CEA LIST. | ||
* 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.web.application.controllers.tables; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.fail; | ||
|
||
import java.time.Duration; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
import java.util.function.Consumer; | ||
|
||
import org.eclipse.sirius.components.collaborative.dto.CreateRepresentationInput; | ||
import org.eclipse.sirius.components.collaborative.tables.TableRefreshedEventPayload; | ||
import org.eclipse.sirius.web.AbstractIntegrationTests; | ||
import org.eclipse.sirius.web.data.PapayaIdentifiers; | ||
import org.eclipse.sirius.web.tests.services.api.IGivenCreatedTableSubscription; | ||
import org.eclipse.sirius.web.tests.services.api.IGivenInitialServerState; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.jdbc.Sql; | ||
import org.springframework.test.context.jdbc.SqlConfig; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import reactor.core.publisher.Flux; | ||
import reactor.test.StepVerifier; | ||
|
||
/** | ||
* Integration tests of the table representation with a papaya model. | ||
* | ||
* @author frouene | ||
*/ | ||
@Transactional | ||
@SuppressWarnings("checkstyle:MultipleStringLiterals") | ||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = {"sirius.web.test.enabled=studio"}) | ||
public class PapayaTableControllerIntegrationTests extends AbstractIntegrationTests { | ||
|
||
private static final String MISSING_TABLE = "Missing table"; | ||
|
||
@Autowired | ||
private IGivenInitialServerState givenInitialServerState; | ||
|
||
@Autowired | ||
private IGivenCreatedTableSubscription givenCreatedTableSubscription; | ||
|
||
@BeforeEach | ||
public void beforeEach() { | ||
this.givenInitialServerState.initialize(); | ||
} | ||
|
||
private Flux<Object> givenSubscriptionToTable() { | ||
var input = new CreateRepresentationInput( | ||
UUID.randomUUID(), | ||
PapayaIdentifiers.PAPAYA_PROJECT.toString(), | ||
"papaya_package_table_description", | ||
PapayaIdentifiers.SIRIUS_WEB_DOMAIN_PACKAGE.toString(), | ||
"Table" | ||
); | ||
return this.givenCreatedTableSubscription.createAndSubscribe(input); | ||
} | ||
|
||
@Test | ||
@DisplayName("Given a table representation, when we subscribe to its event, then the representation data are received") | ||
@Sql(scripts = {"/scripts/papaya.sql"}, executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) | ||
@Sql(scripts = {"/scripts/cleanup.sql"}, executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD, config = @SqlConfig(transactionMode = SqlConfig.TransactionMode.ISOLATED)) | ||
public void givenTableRepresentationWhenWeSubscribeToItsEventThenTheRepresentationDataAreReceived() { | ||
var flux = this.givenSubscriptionToTable(); | ||
|
||
Consumer<Object> initialTableContentConsumer = payload -> Optional.of(payload) | ||
.filter(TableRefreshedEventPayload.class::isInstance) | ||
.map(TableRefreshedEventPayload.class::cast) | ||
.map(TableRefreshedEventPayload::table) | ||
.ifPresentOrElse(table -> { | ||
assertThat(table).isNotNull(); | ||
assertThat(table.getColumns()).hasSize(4); | ||
assertThat(table.getLines()).hasSize(2); | ||
}, () -> fail(MISSING_TABLE)); | ||
|
||
StepVerifier.create(flux) | ||
.consumeNextWith(initialTableContentConsumer) | ||
.thenCancel() | ||
.verify(Duration.ofSeconds(10)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.