Added methods with limit and offset parameter to page models repo

Former-commit-id: 1c34927e92
restapi
Jens Pelzetter 2020-08-05 17:46:24 +02:00
parent 8b0e00dca8
commit 35b86a224a
1 changed files with 82 additions and 15 deletions

View File

@ -58,7 +58,7 @@ public class PageModelRepository extends AbstractEntityRepository<Long, PageMode
public Long getIdOfEntity(final PageModel entity) {
return entity.getPageModelId();
}
@Override
public boolean isNew(final PageModel pageModel) {
@ -91,7 +91,6 @@ public class PageModelRepository extends AbstractEntityRepository<Long, PageMode
@Transactional(Transactional.TxType.REQUIRED)
@Override
public void save(final PageModel pageModel) {
pageModel.setLastModified(new Date());
super.save(pageModel);
@ -106,11 +105,30 @@ public class PageModelRepository extends AbstractEntityRepository<Long, PageMode
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
@Transactional(Transactional.TxType.REQUIRED)
public List<PageModel> findAllDraftModels() {
return getEntityManager()
.createNamedQuery("PageModel.findAllDraftModels", PageModel.class)
.getResultList();
}
final TypedQuery<PageModel> query = getEntityManager()
.createNamedQuery("PageModel.findAllDraftModels", PageModel.class);
return query.getResultList();
/**
* Find all draft versions of {@link PageModel}s.
*
* @param limit
* @param offset
*
* @return A list with all draft versions of {@link PageModel}s.
*/
@AuthorizationRequired
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
@Transactional(Transactional.TxType.REQUIRED)
public List<PageModel> findAllDraftModels(
final int limit, final int offset
) {
return getEntityManager()
.createNamedQuery("PageModel.findAllDraftModels", PageModel.class)
.setMaxResults(limit)
.setFirstResult(offset)
.getResultList();
}
/**
@ -120,11 +138,27 @@ public class PageModelRepository extends AbstractEntityRepository<Long, PageMode
*/
@Transactional(Transactional.TxType.REQUIRED)
public List<PageModel> findAllLiveModels() {
return getEntityManager()
.createNamedQuery("PageModel.findAllLiveModels", PageModel.class)
.getResultList();
}
final TypedQuery<PageModel> query = getEntityManager()
.createNamedQuery("PageModel.findAllLiveModels", PageModel.class);
return query.getResultList();
/**
* Find all live versions of {@link PageModel}s.
*
* @param limit
* @param offset
* @return A list with all draft versions of {@link PageModel}s.
*/
@Transactional(Transactional.TxType.REQUIRED)
public List<PageModel> findAllLiveModels(
final int limit, final int offset
) {
return getEntityManager()
.createNamedQuery("PageModel.findAllLiveModels", PageModel.class)
.setMaxResults(limit)
.setFirstResult(offset)
.getResultList();
}
/**
@ -141,17 +175,50 @@ public class PageModelRepository extends AbstractEntityRepository<Long, PageMode
@AuthorizationRequired
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
public List<PageModel> findDraftByApplication(
final CcmApplication application) {
final CcmApplication application
) {
Objects.requireNonNull(application,
"Can't find page models for application null");
final TypedQuery<PageModel> query = getEntityManager()
return getEntityManager()
.createNamedQuery("PageModel.findDraftByApplication",
PageModel.class);
query.setParameter("application", application);
PageModel.class)
.setParameter("application", application)
.getResultList();
}
/**
* Finds the draft versions of all {@link PageModel}s for the provided
* application.
*
* @param application The application for which the {@link PageModel}s are
* retrieved.
* @param limit
* @param offset
*
* @return A list of the {@link PageModel}s defined for the provided
* {@code application}.
*/
@Transactional(Transactional.TxType.REQUIRED)
@AuthorizationRequired
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
public List<PageModel> findDraftByApplication(
final CcmApplication application,
final int limit,
final int offset
) {
return query.getResultList();
Objects.requireNonNull(application,
"Can't find page models for application null");
return getEntityManager()
.createNamedQuery("PageModel.findDraftByApplication",
PageModel.class)
.setParameter("application", application)
.setMaxResults(limit)
.setFirstResult(offset)
.getResultList();
}
/**