-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
42 changed files
with
2,309 additions
and
34 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
45 changes: 45 additions & 0 deletions
45
...rter/src/main/java/org/citrusframework/simulator/repository/ScenarioActionRepository.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,45 @@ | ||
package org.citrusframework.simulator.repository; | ||
|
||
import org.citrusframework.simulator.model.ScenarioAction; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Spring Data JPA repository for the ScenarioAction entity. | ||
*/ | ||
@Repository | ||
public interface ScenarioActionRepository extends JpaRepository<ScenarioAction, Long>, JpaSpecificationExecutor<ScenarioAction> { | ||
default Optional<ScenarioAction> findOneWithEagerRelationships(Long id) { | ||
return this.findOneWithToOneRelationships(id); | ||
} | ||
|
||
default List<ScenarioAction> findAllWithEagerRelationships() { | ||
return this.findAllWithToOneRelationships(); | ||
} | ||
|
||
default Page<ScenarioAction> findAllWithEagerRelationships(Pageable pageable) { | ||
return this.findAllWithToOneRelationships(pageable); | ||
} | ||
|
||
@Query( | ||
value = "select scenarioAction from ScenarioAction scenarioAction left join fetch scenarioAction.scenarioExecution", | ||
countQuery = "select count(scenarioAction) from ScenarioAction scenarioAction" | ||
) | ||
Page<ScenarioAction> findAllWithToOneRelationships(Pageable pageable); | ||
|
||
@Query("select scenarioAction from ScenarioAction scenarioAction left join fetch scenarioAction.scenarioExecution") | ||
List<ScenarioAction> findAllWithToOneRelationships(); | ||
|
||
@Query( | ||
"select scenarioAction from ScenarioAction scenarioAction left join fetch scenarioAction.scenarioExecution where scenarioAction.actionId =:actionId" | ||
) | ||
Optional<ScenarioAction> findOneWithToOneRelationships(@Param("actionId") Long actionId); | ||
} |
110 changes: 110 additions & 0 deletions
110
...arter/src/main/java/org/citrusframework/simulator/service/ScenarioActionQueryService.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,110 @@ | ||
package org.citrusframework.simulator.service; | ||
|
||
import jakarta.persistence.criteria.JoinType; | ||
import org.citrusframework.simulator.model.ScenarioAction; | ||
import org.citrusframework.simulator.model.ScenarioAction_; | ||
import org.citrusframework.simulator.model.ScenarioExecution_; | ||
import org.citrusframework.simulator.repository.ScenarioActionRepository; | ||
import org.citrusframework.simulator.service.criteria.ScenarioActionCriteria; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.jpa.domain.Specification; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Service for executing complex queries for {@link ScenarioAction} entities in the database. | ||
* The main input is a {@link ScenarioActionCriteria} which gets converted to {@link Specification}, | ||
* in a way that all the filters must apply. | ||
* It returns a {@link List} of {@link ScenarioAction} or a {@link Page} of {@link ScenarioAction} which fulfills the criteria. | ||
*/ | ||
@Service | ||
@Transactional(readOnly = true) | ||
public class ScenarioActionQueryService extends QueryService<ScenarioAction> { | ||
|
||
private final Logger log = LoggerFactory.getLogger(ScenarioActionQueryService.class); | ||
|
||
private final ScenarioActionRepository scenarioActionRepository; | ||
|
||
public ScenarioActionQueryService(ScenarioActionRepository scenarioActionRepository) { | ||
this.scenarioActionRepository = scenarioActionRepository; | ||
} | ||
|
||
/** | ||
* Return a {@link List} of {@link ScenarioAction} which matches the criteria from the database. | ||
* @param criteria The object which holds all the filters, which the entities should match. | ||
* @return the matching entities. | ||
*/ | ||
@Transactional(readOnly = true) | ||
public List<ScenarioAction> findByCriteria(ScenarioActionCriteria criteria) { | ||
log.debug("find by criteria : {}", criteria); | ||
final Specification<ScenarioAction> specification = createSpecification(criteria); | ||
return scenarioActionRepository.findAll(specification); | ||
} | ||
|
||
/** | ||
* Return a {@link Page} of {@link ScenarioAction} which matches the criteria from the database. | ||
* @param criteria The object which holds all the filters, which the entities should match. | ||
* @param page The page, which should be returned. | ||
* @return the matching entities. | ||
*/ | ||
@Transactional(readOnly = true) | ||
public Page<ScenarioAction> findByCriteria(ScenarioActionCriteria criteria, Pageable page) { | ||
log.debug("find by criteria : {}, page: {}", criteria, page); | ||
final Specification<ScenarioAction> specification = createSpecification(criteria); | ||
return scenarioActionRepository.findAll(specification, page); | ||
} | ||
|
||
/** | ||
* Return the number of matching entities in the database. | ||
* @param criteria The object which holds all the filters, which the entities should match. | ||
* @return the number of matching entities. | ||
*/ | ||
@Transactional(readOnly = true) | ||
public long countByCriteria(ScenarioActionCriteria criteria) { | ||
log.debug("count by criteria : {}", criteria); | ||
final Specification<ScenarioAction> specification = createSpecification(criteria); | ||
return scenarioActionRepository.count(specification); | ||
} | ||
|
||
/** | ||
* Function to convert {@link ScenarioActionCriteria} to a {@link Specification} | ||
* @param criteria The object which holds all the filters, which the entities should match. | ||
* @return the matching {@link Specification} of the entity. | ||
*/ | ||
protected Specification<ScenarioAction> createSpecification(ScenarioActionCriteria criteria) { | ||
Specification<ScenarioAction> specification = Specification.where(null); | ||
if (criteria != null) { | ||
// This has to be called first, because the distinct method returns null | ||
if (criteria.getDistinct() != null) { | ||
specification = specification.and(distinct(criteria.getDistinct())); | ||
} | ||
if (criteria.getActionId() != null) { | ||
specification = specification.and(buildRangeSpecification(criteria.getActionId(), ScenarioAction_.actionId)); | ||
} | ||
if (criteria.getName() != null) { | ||
specification = specification.and(buildStringSpecification(criteria.getName(), ScenarioAction_.name)); | ||
} | ||
if (criteria.getStartDate() != null) { | ||
specification = specification.and(buildRangeSpecification(criteria.getStartDate(), ScenarioAction_.startDate)); | ||
} | ||
if (criteria.getEndDate() != null) { | ||
specification = specification.and(buildRangeSpecification(criteria.getEndDate(), ScenarioAction_.endDate)); | ||
} | ||
if (criteria.getScenarioExecutionId() != null) { | ||
specification = | ||
specification.and( | ||
buildSpecification( | ||
criteria.getScenarioExecutionId(), | ||
root -> root.join(ScenarioAction_.scenarioExecution, JoinType.LEFT).get(ScenarioExecution_.executionId) | ||
) | ||
); | ||
} | ||
} | ||
return specification; | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...or-starter/src/main/java/org/citrusframework/simulator/service/ScenarioActionService.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,54 @@ | ||
package org.citrusframework.simulator.service; | ||
|
||
import org.citrusframework.simulator.model.ScenarioAction; | ||
import org.citrusframework.simulator.model.ScenarioExecution; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
|
||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Service Interface for managing {@link ScenarioAction}. | ||
*/ | ||
public interface ScenarioActionService { | ||
/** | ||
* Save a scenarioAction. | ||
* | ||
* @param scenarioAction the entity to save. | ||
* @return the persisted entity. | ||
*/ | ||
ScenarioAction save(ScenarioAction scenarioAction); | ||
|
||
/** | ||
* Get all the scenarioActions. | ||
* | ||
* @param pageable the pagination information. | ||
* @return the list of entities. | ||
*/ | ||
Page<ScenarioAction> findAll(Pageable pageable); | ||
|
||
/** | ||
* Get the "id" scenarioAction. | ||
* | ||
* @param id the id of the entity. | ||
* @return the entity. | ||
*/ | ||
Optional<ScenarioAction> findOne(Long id); | ||
|
||
/** | ||
* Function that converts the {@link ScenarioAction} to its "DTO-form": It may only contain the {@code scenarioName} | ||
* of the related {@link ScenarioExecution}, no further attributes. That is especially true for relationships, | ||
* because of a possible {@link org.hibernate.LazyInitializationException}). | ||
* | ||
* @param scenarioAction The entity, which should be returned | ||
* @return the entity with prepared {@link ScenarioExecution} | ||
*/ | ||
static ScenarioAction restrictToDtoProperties(ScenarioAction scenarioAction) { | ||
ScenarioExecution scenarioExecution = scenarioAction.getScenarioExecution(); | ||
if (!Objects.isNull(scenarioExecution)) { | ||
scenarioAction.setScenarioExecution(ScenarioExecution.builder().scenarioName(scenarioExecution.getScenarioName()).build()); | ||
} | ||
return scenarioAction; | ||
} | ||
} |
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.