Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3649] [3630] Fix some remaining issues with the new architecture #3660

Merged
merged 3 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ More existing APIs will be migrated to this new common pattern.
- https://github.com/eclipse-sirius/sirius-web/issues/3624[#3624] [diagram] Fix an issue where the header separator does not fill the entire width of the node
- https://github.com/eclipse-sirius/sirius-web/issues/3531[#3531] [diagram] Fix unnecessary edges label re render
- https://github.com/eclipse-sirius/sirius-web/issues/3650[#3650] [diagram] Fix potential NPE in DiagramNavigator and Node toString method
- https://github.com/eclipse-sirius/sirius-web/issues/3649[#3649] [sirius-web] Restore support for Related elements view icons
- https://github.com/eclipse-sirius/sirius-web/issues/3630[#3630] [sirius-web] Restore support for the deletion of dangling representations

=== New Features

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021 Obeo.
* Copyright (c) 2021, 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
Expand Down Expand Up @@ -35,7 +35,7 @@ public interface IDanglingRepresentationDeletionService {
*/
boolean isDangling(IEditingContext editingContext, IRepresentation representation);

void deleteDanglingRepresentations(String editingContextId);
void deleteDanglingRepresentations(IEditingContext editingContext);

/**
* Implementation which does nothing, used for mocks in unit tests.
Expand All @@ -50,7 +50,7 @@ public boolean isDangling(IEditingContext editingContext, IRepresentation repres
}

@Override
public void deleteDanglingRepresentations(String editingContextId) {
public void deleteDanglingRepresentations(IEditingContext editingContext) {
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ private Disposable setupChangeDescriptionSinkConsumer() {
if (this.shouldPersistTheEditingContext(changeDescription)) {
this.editingContextPersistenceService.persist(this.editingContext);
}
this.danglingRepresentationDeletionService.deleteDanglingRepresentations(this.editingContext.getId());
this.danglingRepresentationDeletionService.deleteDanglingRepresentations(this.editingContext);

var timer = this.meterRegistry.timer(Monitoring.TIMER_REFRESH_REPRESENTATION, "changeDescription", changeDescription.getSourceId());
refreshRepresentationSample.stop(timer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,22 @@
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.web.application.images;
package org.eclipse.sirius.components.collaborative.gantt.service;

import java.util.List;

import org.eclipse.sirius.components.core.api.IImagePathService;
import org.springframework.stereotype.Service;

/**
* Utility class containing constants for the images of Sirius Web.
* Register the gantt images folder.
*
* @author sbegaudeau
*/
public final class ImageConstants {
public static final String IMAGES_ROOT_FOLDER = "/icons/svg";

public static final String RESOURCE_SVG = IMAGES_ROOT_FOLDER + "/Resource.svg";

private ImageConstants() {
// Prevent instantiation
@Service
public class GanttImagePathService implements IImagePathService {
@Override
public List<String> getPaths() {
return List.of("/gantt-images/");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class GanttImageProvider implements IRepresentationImageProvider {
@Override
public Optional<String> getImageURL(String kind) {
if (Gantt.KIND.equals(kind)) {
return Optional.of("/images/Gantt.svg");
return Optional.of("/gantt-images/gantt.svg");
}
return Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@
import org.eclipse.sirius.components.core.api.IEditingContext;
import org.eclipse.sirius.components.core.api.IObjectSearchService;
import org.eclipse.sirius.components.representations.IRepresentation;
import org.eclipse.sirius.web.application.UUIDParser;
import org.eclipse.sirius.web.domain.boundedcontexts.representationdata.services.api.IRepresentationDataDeletionService;
import org.eclipse.sirius.web.domain.boundedcontexts.representationdata.services.api.IRepresentationDataSearchService;
import org.eclipse.sirius.web.domain.boundedcontexts.representationdata.projections.RepresentationDataMetadataOnly;
import org.springframework.data.jdbc.core.mapping.AggregateReference;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
* Used to delete dangling representations.
Expand All @@ -31,8 +37,14 @@ public class DanglingRepresentationDeletionService implements IDanglingRepresent

private final IObjectSearchService objectSearchService;

public DanglingRepresentationDeletionService(IObjectSearchService objectSearchService) {
private final IRepresentationDataSearchService representationDataSearchService;

private final IRepresentationDataDeletionService representationDataDeletionService;

public DanglingRepresentationDeletionService(IObjectSearchService objectSearchService, IRepresentationDataSearchService representationDataSearchService, IRepresentationDataDeletionService representationDataDeletionService) {
this.objectSearchService = Objects.requireNonNull(objectSearchService);
this.representationDataSearchService = Objects.requireNonNull(representationDataSearchService);
this.representationDataDeletionService = Objects.requireNonNull(representationDataDeletionService);
}

@Override
Expand All @@ -43,7 +55,13 @@ public boolean isDangling(IEditingContext editingContext, IRepresentation repres
}

@Override
public void deleteDanglingRepresentations(String editingContextId) {
// Do nothing for now
@Transactional
public void deleteDanglingRepresentations(IEditingContext editingContext) {
new UUIDParser().parse(editingContext.getId()).ifPresent(projectId -> {
this.representationDataSearchService.findAllMetadataByProject(AggregateReference.to(projectId)).stream()
.filter(representationMetadata -> this.objectSearchService.getObject(editingContext, representationMetadata.targetObjectId()).isEmpty())
.map(RepresentationDataMetadataOnly::id)
.forEach(this.representationDataDeletionService::delete);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.eclipse.sirius.components.trees.TreeItem;
import org.eclipse.sirius.components.trees.description.TreeDescription;
import org.eclipse.sirius.components.trees.renderer.TreeRenderer;
import org.eclipse.sirius.web.application.images.ImageConstants;
import org.eclipse.sirius.web.application.views.explorer.services.api.IDeleteTreeItemHandler;
import org.eclipse.sirius.web.application.views.explorer.services.api.IExplorerChildrenProvider;
import org.eclipse.sirius.web.application.views.explorer.services.api.IExplorerElementsProvider;
Expand Down Expand Up @@ -222,7 +221,7 @@ private List<String> getImageURL(VariableManager variableManager) {
.flatMap(Optional::stream)
.toList();
} else if (self instanceof Resource) {
imageURL = List.of(ImageConstants.RESOURCE_SVG);
imageURL = List.of("/explorer/Resource.svg");
}
return imageURL;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2024 Obeo.
* Copyright (c) 2024, 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
Expand All @@ -10,7 +10,7 @@
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.web.application.images.services;
package org.eclipse.sirius.web.application.views.explorer.services;

import java.util.List;

Expand All @@ -26,6 +26,6 @@
public class ExplorerImagePathService implements IImagePathService {
@Override
public List<String> getPaths() {
return List.of("/icons/svg");
return List.of("/explorer");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ public class CurrentTreeDescriptionProvider implements ICurrentTreeDescriptionPr

private static final String TITLE = "Current";

private static final String WIDGET_ICON_URL = "/icons/svg/arrow_downward_black_24dp.svg";
private static final String WIDGET_ICON_URL = "/related-elements/arrow_downward_black_24dp.svg";

private static final String FOLDER_ICON_URL = "/icons/svg/folder_black_24dp.svg";
private static final String FOLDER_ICON_URL = "/related-elements/folder_black_24dp.svg";

private static final String CHILDREN_CATEGORY_ICON_URL = "/icons/svg/subdirectory_arrow_right_black_24dp.svg";
private static final String CHILDREN_CATEGORY_ICON_URL = "/related-elements/subdirectory_arrow_right_black_24dp.svg";

private static final String CATEGORY_KIND = "siriusWeb://category";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ public class IncomingTreeDescriptionProvider implements IIncomingTreeDescription

private static final String TITLE = "Incoming";

private static final String WIDGET_ICON_URL = "/images/west_black_24dp.svg";
private static final String WIDGET_ICON_URL = "/related-elements/west_black_24dp.svg";

private static final String INCOMING_REFERENCE_ICON_URL = "/images/west_black_24dp.svg";
private static final String INCOMING_REFERENCE_ICON_URL = "/related-elements/west_black_24dp.svg";

private static final String INCOMING_REFERENCES_KIND = "siriusWeb://category/incoming-references";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ public class OutgoingTreeDescriptionProvider implements IOutgoingTreeDescription

private static final String TITLE = "Outgoing";

private static final String WIDGET_ICON_URL = "/icons/svg/east_black_24dp.svg";
private static final String WIDGET_ICON_URL = "/related-elements/east_black_24dp.svg";

private static final String OUTGOING_REFERENCE_ICON_URL = "/icons/svg/east_black_24dp.svg";
private static final String OUTGOING_REFERENCE_ICON_URL = "/related-elements/east_black_24dp.svg";

private static final String OUTGOING_REFERENCE_KIND = "siriusWeb://category/outgoing-references";

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.web.application.views.relatedelements.services;

import java.util.List;

import org.eclipse.sirius.components.core.api.IImagePathService;
import org.springframework.stereotype.Service;

/**
* Used to allow access to the images of the related elements view.
*
* @author sbegaudeau
*/
@Service
public class RelatedElementsImagePathService implements IImagePathService {
@Override
public List<String> getPaths() {
return List.of("/related-elements");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*******************************************************************************
* Copyright (c) 2024, 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.domain.boundedcontexts.representationdata.projections;

import java.util.UUID;

/**
* Projection used to retrieve only the representation metadata of the representation data.
*
* @author sbegaudeau
*/
public record RepresentationDataMetadataOnly(
UUID id,
String label,
String kind,
String targetObjectId,
String descriptionId) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.UUID;

import org.eclipse.sirius.web.domain.boundedcontexts.representationdata.RepresentationData;
import org.eclipse.sirius.web.domain.boundedcontexts.representationdata.projections.RepresentationDataMetadataOnly;
import org.springframework.data.jdbc.repository.query.Query;
import org.springframework.data.repository.ListCrudRepository;
import org.springframework.data.repository.ListPagingAndSortingRepository;
Expand All @@ -36,6 +37,13 @@ public interface IRepresentationDataRepository extends ListPagingAndSortingRepos
""")
List<RepresentationData> findAllByProjectId(UUID projectId);

@Query("""
SELECT id, label, kind, target_object_id, description_id
FROM representation_data representationData
WHERE representationData.project_id = :projectId
""")
List<RepresentationDataMetadataOnly> findAllMetadataByProjectId(UUID projectId);

@Query("""
SELECT representationData.project_id
FROM representation_data representationData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.eclipse.sirius.web.domain.boundedcontexts.project.Project;
import org.eclipse.sirius.web.domain.boundedcontexts.representationdata.RepresentationData;
import org.eclipse.sirius.web.domain.boundedcontexts.representationdata.projections.RepresentationDataMetadataOnly;
import org.eclipse.sirius.web.domain.boundedcontexts.representationdata.repositories.IRepresentationDataRepository;
import org.eclipse.sirius.web.domain.boundedcontexts.representationdata.services.api.IRepresentationDataSearchService;
import org.springframework.data.jdbc.core.mapping.AggregateReference;
Expand Down Expand Up @@ -53,6 +54,11 @@ public List<RepresentationData> findAllByProject(AggregateReference<Project, UUI
return this.representationDataRepository.findAllByProjectId(project.getId());
}

@Override
public List<RepresentationDataMetadataOnly> findAllMetadataByProject(AggregateReference<Project, UUID> project) {
return this.representationDataRepository.findAllMetadataByProjectId(project.getId());
}

@Override
public boolean existAnyRepresentationForTargetObjectId(String targetObjectId) {
return this.representationDataRepository.existAnyRepresentationForTargetObjectId(targetObjectId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import org.eclipse.sirius.web.domain.boundedcontexts.project.Project;
import org.eclipse.sirius.web.domain.boundedcontexts.representationdata.RepresentationData;
import org.eclipse.sirius.web.domain.boundedcontexts.representationdata.projections.RepresentationDataMetadataOnly;
import org.springframework.data.jdbc.core.mapping.AggregateReference;

/**
Expand All @@ -33,6 +34,8 @@ public interface IRepresentationDataSearchService {

List<RepresentationData> findAllByProject(AggregateReference<Project, UUID> project);

List<RepresentationDataMetadataOnly> findAllMetadataByProject(AggregateReference<Project, UUID> project);

boolean existAnyRepresentationForTargetObjectId(String targetObjectId);

List<RepresentationData> findAllByTargetObjectId(String targetObjectId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ public boolean isDangling(IEditingContext editingContext, IRepresentation repres
}

@Override
public void deleteDanglingRepresentations(String editingContextId) {
new IDParser().parse(editingContextId).ifPresent(this.representationRepository::deleteDanglingRepresentations);
public void deleteDanglingRepresentations(IEditingContext editingContext) {
new IDParser().parse(editingContext.getId()).ifPresent(this.representationRepository::deleteDanglingRepresentations);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void givenProjectWhenItsImagesAreRequestedThenTheImagesAreReturned() {
public void givenTheURLOfAnImageWhichExistsWhenItsContentIsRequestedThenTheImageIsReturned() {
this.givenCommittedTransaction.commit();

var uri = "http://localhost:" + port + "/api/images/icons/svg/Resource.svg";
var uri = "http://localhost:" + port + "/api/images/explorer/Resource.svg";

HttpEntity<String> entity = new HttpEntity<>(null, new HttpHeaders());
var response = new TestRestTemplate().exchange(uri, HttpMethod.GET, entity, Resource.class);
Expand Down
Loading
Loading