Skip to content

Commit

Permalink
[3897] Improve the search for projects
Browse files Browse the repository at this point in the history
Bug: #3897
Signed-off-by: Stéphane Bégaudeau <[email protected]>
  • Loading branch information
sbegaudeau committed Aug 28, 2024
1 parent 06250d0 commit 6a89542
Show file tree
Hide file tree
Showing 13 changed files with 311 additions and 26 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ A migration participant has been added to automatically keep compatible all diag
- https://github.com/eclipse-sirius/sirius-web/issues/3793[#3793] [sirius-web] Add mechanism to retrieve the parent object of an element in the tree representation
- https://github.com/eclipse-sirius/sirius-web/issues/3880[#3880] [sirius-web] Make some tests methods more generic
- https://github.com/eclipse-sirius/sirius-web/issues/3834[#3834] [deck] Add more variables for DeckDescription
- https://github.com/eclipse-sirius/sirius-web/issues/3897[#3897] [sirius-web] Improve the search for projects

== v2024.7.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.util.Optional;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.stream.StreamSupport;

Expand Down Expand Up @@ -89,8 +88,7 @@ public EditingContextSearchService(IProjectSearchService projectSearchService, I
@Transactional(readOnly = true)
public boolean existsById(String editingContextId) {
return new UUIDParser().parse(editingContextId)
.map(AggregateReference::<Project, UUID>to)
.map(this.semanticDataSearchService::existsByProject)
.map(this.projectSearchService::existsById)
.orElse(false);
}

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 @@ -25,5 +25,5 @@
* @author sbegaudeau
*/
@Repository
public interface IProjectRepository extends ListPagingAndSortingRepository<Project, UUID>, ListCrudRepository<Project, UUID> {
public interface IProjectRepository extends ListPagingAndSortingRepository<Project, UUID>, ListCrudRepository<Project, UUID>, ProjectSearchRepository<Project, UUID> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*******************************************************************************
* 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.project.repositories;

import java.util.Optional;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

/**
* Fragment interface used to search projects.
*
* @author sbegaudeau
*
* @param <T> The type of entity
* @param <ID> The type of the identifier
*/
public interface ProjectSearchRepository<T, ID> {
boolean existsById(ID id);

Optional<T> findById(ID id);

Page<T> findAll(Pageable pageable);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*******************************************************************************
* 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.domain.boundedcontexts.project.repositories;

import static org.springframework.data.relational.core.query.Criteria.where;
import static org.springframework.data.relational.core.query.Query.query;

import java.util.Objects;
import java.util.Optional;
import java.util.UUID;

import org.eclipse.sirius.web.domain.boundedcontexts.project.Project;
import org.eclipse.sirius.web.domain.boundedcontexts.project.repositories.api.IProjectSearchRepositoryDelegate;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jdbc.core.JdbcAggregateOperations;
import org.springframework.data.relational.core.query.Query;
import org.springframework.stereotype.Service;

/**
* Used to execute the queries for the project search repository.
*
* @author sbegaudeau
*/
@Service
public class ProjectSearchRepositoryDelegate implements IProjectSearchRepositoryDelegate {

private final JdbcAggregateOperations jdbcAggregateOperations;

public ProjectSearchRepositoryDelegate(JdbcAggregateOperations jdbcAggregateOperations) {
this.jdbcAggregateOperations = Objects.requireNonNull(jdbcAggregateOperations);
}

@Override
public boolean existsById(UUID projectId) {
Query query = query(where("id").is(projectId));
return this.jdbcAggregateOperations.exists(query, Project.class);
}

@Override
public Optional<Project> findById(UUID projectId) {
Query query = query(where("id").is(projectId));
return this.jdbcAggregateOperations.findOne(query, Project.class);
}

@Override
public Page<Project> findAll(Pageable pageable) {
return this.jdbcAggregateOperations.findAll(Project.class, pageable);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*******************************************************************************
* 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.project.repositories;

import java.util.Objects;
import java.util.Optional;
import java.util.UUID;

import org.eclipse.sirius.web.domain.boundedcontexts.project.Project;
import org.eclipse.sirius.web.domain.boundedcontexts.project.repositories.api.IProjectSearchRepositoryDelegate;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

/**
* Fragment repository used to customize the search of projects.
*
* @author sbegaudeau
*/
@Repository
public class ProjectSearchRepositoryImpl implements ProjectSearchRepository<Project, UUID> {

private final IProjectSearchRepositoryDelegate projectSearchRepositoryDelegate;

public ProjectSearchRepositoryImpl(IProjectSearchRepositoryDelegate projectSearchRepositoryDelegate) {
this.projectSearchRepositoryDelegate = Objects.requireNonNull(projectSearchRepositoryDelegate);
}

@Override
public boolean existsById(UUID projectId) {
return this.projectSearchRepositoryDelegate.existsById(projectId);
}

@Override
public Optional<Project> findById(UUID projectId) {
return this.projectSearchRepositoryDelegate.findById(projectId);
}

@Override
public Page<Project> findAll(Pageable pageable) {
return this.projectSearchRepositoryDelegate.findAll(pageable);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*******************************************************************************
* 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.project.repositories.api;

import java.util.UUID;

import org.eclipse.sirius.web.domain.boundedcontexts.project.Project;
import org.eclipse.sirius.web.domain.boundedcontexts.project.repositories.ProjectSearchRepository;

/**
* Used to delegate the behavior of the project search repository.
*
* @author sbegaudeau
*/
public interface IProjectSearchRepositoryDelegate extends ProjectSearchRepository<Project, UUID> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@
*/
@Repository
public interface ISemanticDataRepository extends ListPagingAndSortingRepository<SemanticData, UUID>, ListCrudRepository<SemanticData, UUID> {
@Query("""
SELECT
CASE WHEN count(*)> 0 THEN true ELSE false END
FROM semantic_data semanticData
WHERE semanticData.project_id = :projectId
""")
boolean existsByProjectId(UUID projectId);

@Query("""
SELECT *
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ public SemanticDataSearchService(ISemanticDataRepository semanticDataRepository)
this.semanticDataRepository = Objects.requireNonNull(semanticDataRepository);
}

@Override
public boolean existsByProject(AggregateReference<Project, UUID> project) {
return this.semanticDataRepository.existsByProjectId(project.getId());
}

@Override
public Optional<SemanticData> findByProject(AggregateReference<Project, UUID> project) {
return this.semanticDataRepository.findByProjectId(project.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
*/
public interface ISemanticDataSearchService {

boolean existsByProject(AggregateReference<Project, UUID> project);

Optional<SemanticData> findByProject(AggregateReference<Project, UUID> project);

List<SemanticData> findAllByDomains(List<String> domainUris);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.eclipse.sirius.web.domain.boundedcontexts.project.events.ProjectCreatedEvent;
import org.eclipse.sirius.web.domain.boundedcontexts.project.events.ProjectDeletedEvent;
import org.eclipse.sirius.web.domain.boundedcontexts.project.services.api.IProjectSearchService;
import org.eclipse.sirius.web.domain.boundedcontexts.semanticdata.services.api.ISemanticDataSearchService;
import org.eclipse.sirius.web.services.api.IDomainEventCollector;
import org.eclipse.sirius.web.tests.graphql.CreateProjectMutationRunner;
import org.eclipse.sirius.web.tests.graphql.DeleteProjectMutationRunner;
Expand All @@ -51,7 +50,6 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jdbc.core.mapping.AggregateReference;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.context.jdbc.SqlConfig;
import org.springframework.test.context.transaction.TestTransaction;
Expand Down Expand Up @@ -90,9 +88,6 @@ public class ProjectControllerIntegrationTests extends AbstractIntegrationTests
@Autowired
private IProjectSearchService projectSearchService;

@Autowired
private ISemanticDataSearchService semanticDataSearchService;

@Autowired
private IDomainEventCollector domainEventCollector;

Expand Down Expand Up @@ -207,8 +202,8 @@ public void givenValidProjectToCreateWhenMutationIsPerformedThenTheSemanticDataA

String projectId = JsonPath.read(result, "$.data.createProject.project.id");

var existsByProject = this.semanticDataSearchService.existsByProject(AggregateReference.to(UUID.fromString(projectId)));
assertThat(existsByProject).isTrue();
var exists = this.projectSearchService.existsById(UUID.fromString(projectId));
assertThat(exists).isTrue();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*******************************************************************************
* 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.controllers.projects;

import java.util.Optional;
import java.util.UUID;

import org.eclipse.sirius.web.domain.boundedcontexts.project.Project;
import org.eclipse.sirius.web.domain.boundedcontexts.project.repositories.api.IProjectSearchRepositoryDelegate;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.jdbc.core.simple.JdbcClient;

/**
* Configuration used to change the project search strategy.
*
* @author sbegaudeau
*/
public class ProjectSearchControllerConfiguration {

@Bean
@Primary
public IProjectSearchRepositoryDelegate testProjectSearchRepositoryDelegate(JdbcClient jdbcClient) {
return new IProjectSearchRepositoryDelegate() {
@Override
public boolean existsById(UUID projectId) {
return false;
}

@Override
public Optional<Project> findById(UUID projectId) {
return Optional.empty();
}

@Override
public Page<Project> findAll(Pageable pageable) {
var query = """
SELECT project.* FROM project
JOIN nature ON project.id = nature.project_id
WHERE nature.name = 'ecore'
""";
var projects = jdbcClient.sql(query)
.query(Project.class)
.list();
return new PageImpl<>(projects, pageable, projects.size());
}
};
}
}
Loading

0 comments on commit 6a89542

Please sign in to comment.