-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[3897] Improve the search for projects
Bug: #3897 Signed-off-by: Stéphane Bégaudeau <[email protected]>
- Loading branch information
1 parent
06250d0
commit 6a89542
Showing
13 changed files
with
311 additions
and
26 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
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
33 changes: 33 additions & 0 deletions
33
...lipse/sirius/web/domain/boundedcontexts/project/repositories/ProjectSearchRepository.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,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); | ||
} |
60 changes: 60 additions & 0 deletions
60
...rius/web/domain/boundedcontexts/project/repositories/ProjectSearchRepositoryDelegate.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,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); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...e/sirius/web/domain/boundedcontexts/project/repositories/ProjectSearchRepositoryImpl.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,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); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...web/domain/boundedcontexts/project/repositories/api/IProjectSearchRepositoryDelegate.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,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> { | ||
} |
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
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
62 changes: 62 additions & 0 deletions
62
...pse/sirius/web/application/controllers/projects/ProjectSearchControllerConfiguration.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,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()); | ||
} | ||
}; | ||
} | ||
} |
Oops, something went wrong.