-
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.
feat: add message-header entity read-only rest api
- Loading branch information
Showing
36 changed files
with
1,950 additions
and
46 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
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
43 changes: 43 additions & 0 deletions
43
...arter/src/main/java/org/citrusframework/simulator/repository/MessageHeaderRepository.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,43 @@ | ||
package org.citrusframework.simulator.repository; | ||
|
||
import org.citrusframework.simulator.model.MessageHeader; | ||
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 MessageHeader entity. | ||
*/ | ||
@Repository | ||
public interface MessageHeaderRepository extends JpaRepository<MessageHeader, Long>, JpaSpecificationExecutor<MessageHeader> { | ||
default Optional<MessageHeader> findOneWithEagerRelationships(Long id) { | ||
return this.findOneWithToOneRelationships(id); | ||
} | ||
|
||
default List<MessageHeader> findAllWithEagerRelationships() { | ||
return this.findAllWithToOneRelationships(); | ||
} | ||
|
||
default Page<MessageHeader> findAllWithEagerRelationships(Pageable pageable) { | ||
return this.findAllWithToOneRelationships(pageable); | ||
} | ||
|
||
@Query( | ||
value = "select messageHeader from MessageHeader messageHeader left join fetch messageHeader.message", | ||
countQuery = "select count(messageHeader) from MessageHeader messageHeader" | ||
) | ||
Page<MessageHeader> findAllWithToOneRelationships(Pageable pageable); | ||
|
||
@Query("select messageHeader from MessageHeader messageHeader left join fetch messageHeader.message") | ||
List<MessageHeader> findAllWithToOneRelationships(); | ||
|
||
@Query("select messageHeader from MessageHeader messageHeader left join fetch messageHeader.message where messageHeader.id =:id") | ||
Optional<MessageHeader> findOneWithToOneRelationships(@Param("id") Long id); | ||
} |
107 changes: 107 additions & 0 deletions
107
...tarter/src/main/java/org/citrusframework/simulator/service/MessageHeaderQueryService.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,107 @@ | ||
package org.citrusframework.simulator.service; | ||
|
||
import jakarta.persistence.criteria.JoinType; | ||
import org.citrusframework.simulator.model.MessageHeader; | ||
import org.citrusframework.simulator.model.MessageHeader_; | ||
import org.citrusframework.simulator.model.Message_; | ||
import org.citrusframework.simulator.repository.MessageHeaderRepository; | ||
import org.citrusframework.simulator.service.criteria.MessageHeaderCriteria; | ||
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 MessageHeader} entities in the database. | ||
* The main input is a {@link MessageHeaderCriteria} which gets converted to {@link Specification}, | ||
* in a way that all the filters must apply. | ||
* It returns a {@link List} of {@link MessageHeader} or a {@link Page} of {@link MessageHeader} which fulfills the criteria. | ||
*/ | ||
@Service | ||
@Transactional(readOnly = true) | ||
public class MessageHeaderQueryService extends QueryService<MessageHeader> { | ||
|
||
private final Logger log = LoggerFactory.getLogger(MessageHeaderQueryService.class); | ||
|
||
private final MessageHeaderRepository messageHeaderRepository; | ||
|
||
public MessageHeaderQueryService(MessageHeaderRepository messageHeaderRepository) { | ||
this.messageHeaderRepository = messageHeaderRepository; | ||
} | ||
|
||
/** | ||
* Return a {@link List} of {@link MessageHeader} 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<MessageHeader> findByCriteria(MessageHeaderCriteria criteria) { | ||
log.debug("find by criteria : {}", criteria); | ||
final Specification<MessageHeader> specification = createSpecification(criteria); | ||
return messageHeaderRepository.findAll(specification); | ||
} | ||
|
||
/** | ||
* Return a {@link Page} of {@link MessageHeader} 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<MessageHeader> findByCriteria(MessageHeaderCriteria criteria, Pageable page) { | ||
log.debug("find by criteria : {}, page: {}", criteria, page); | ||
final Specification<MessageHeader> specification = createSpecification(criteria); | ||
return messageHeaderRepository.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(MessageHeaderCriteria criteria) { | ||
log.debug("count by criteria : {}", criteria); | ||
final Specification<MessageHeader> specification = createSpecification(criteria); | ||
return messageHeaderRepository.count(specification); | ||
} | ||
|
||
/** | ||
* Function to convert {@link MessageHeaderCriteria} 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<MessageHeader> createSpecification(MessageHeaderCriteria criteria) { | ||
Specification<MessageHeader> 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.getHeaderId() != null) { | ||
specification = specification.and(buildRangeSpecification(criteria.getHeaderId(), MessageHeader_.headerId)); | ||
} | ||
if (criteria.getName() != null) { | ||
specification = specification.and(buildStringSpecification(criteria.getName(), MessageHeader_.name)); | ||
} | ||
if (criteria.getValue() != null) { | ||
specification = specification.and(buildStringSpecification(criteria.getValue(), MessageHeader_.value)); | ||
} | ||
if (criteria.getMessageId() != null) { | ||
specification = | ||
specification.and( | ||
buildSpecification( | ||
criteria.getMessageId(), | ||
root -> root.join(MessageHeader_.message, JoinType.LEFT).get(Message_.messageId) | ||
) | ||
); | ||
} | ||
} | ||
return specification; | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
...tor-starter/src/main/java/org/citrusframework/simulator/service/MessageHeaderService.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,59 @@ | ||
package org.citrusframework.simulator.service; | ||
|
||
import org.citrusframework.simulator.model.MessageHeader; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
|
||
import java.util.Optional; | ||
|
||
/** | ||
* Service Interface for managing {@link MessageHeader}. | ||
*/ | ||
public interface MessageHeaderService { | ||
/** | ||
* Save a messageHeader. | ||
* | ||
* @param messageHeader the entity to save. | ||
* @return the persisted entity. | ||
*/ | ||
MessageHeader save(MessageHeader messageHeader); | ||
|
||
/** | ||
* Updates a messageHeader. | ||
* | ||
* @param messageHeader the entity to update. | ||
* @return the persisted entity. | ||
*/ | ||
MessageHeader update(MessageHeader messageHeader); | ||
|
||
/** | ||
* Get all the messageHeaders. | ||
* | ||
* @param pageable the pagination information. | ||
* @return the list of entities. | ||
*/ | ||
Page<MessageHeader> findAll(Pageable pageable); | ||
|
||
/** | ||
* Get all the messageHeaders with eager load of many-to-many relationships. | ||
* | ||
* @param pageable the pagination information. | ||
* @return the list of entities. | ||
*/ | ||
Page<MessageHeader> findAllWithEagerRelationships(Pageable pageable); | ||
|
||
/** | ||
* Get the "id" messageHeader. | ||
* | ||
* @param id the id of the entity. | ||
* @return the entity. | ||
*/ | ||
Optional<MessageHeader> findOne(Long id); | ||
|
||
/** | ||
* Delete the "id" messageHeader. | ||
* | ||
* @param id the id of the entity. | ||
*/ | ||
void delete(Long id); | ||
} |
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.