parent
40d1c34e86
commit
8dd3a112f7
|
|
@ -22,6 +22,7 @@ import org.libreccm.api.Identifier;
|
|||
import org.libreccm.api.IdentifierParser;
|
||||
import org.libreccm.api.admin.sites.dto.SiteDto;
|
||||
import org.libreccm.api.admin.web.dto.CcmApplicationId;
|
||||
import org.libreccm.api.dto.ListView;
|
||||
import org.libreccm.core.CoreConstants;
|
||||
import org.libreccm.security.AuthorizationRequired;
|
||||
import org.libreccm.security.RequiresPrivilege;
|
||||
|
|
@ -41,6 +42,7 @@ import javax.transaction.Transactional;
|
|||
import javax.ws.rs.BadRequestException;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.DefaultValue;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.NotFoundException;
|
||||
import javax.ws.rs.POST;
|
||||
|
|
@ -48,6 +50,7 @@ import javax.ws.rs.PUT;
|
|||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
|
@ -82,12 +85,20 @@ public class SitesApi {
|
|||
@AuthorizationRequired
|
||||
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public List<SiteDto> getSites() {
|
||||
return siteRepository
|
||||
.findAll()
|
||||
.stream()
|
||||
.map(SiteDto::new)
|
||||
.collect(Collectors.toList());
|
||||
public ListView<SiteDto> getSites(
|
||||
@QueryParam("limit") @DefaultValue("20") final int limit,
|
||||
@QueryParam("offset") @DefaultValue("0") final int offset
|
||||
) {
|
||||
return new ListView<>(
|
||||
siteRepository
|
||||
.findAll(limit, offset)
|
||||
.stream()
|
||||
.map(SiteDto::new)
|
||||
.collect(Collectors.toList()),
|
||||
siteRepository.countAll(),
|
||||
limit,
|
||||
offset
|
||||
);
|
||||
}
|
||||
|
||||
@GET
|
||||
|
|
@ -175,15 +186,21 @@ public class SitesApi {
|
|||
@AuthorizationRequired
|
||||
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public List<CcmApplicationId> getApplications(
|
||||
@PathParam("siteIdentifier") final String siteIdentifier
|
||||
public ListView<CcmApplicationId> getApplications(
|
||||
@PathParam("siteIdentifier") final String siteIdentifier,
|
||||
@QueryParam("limit") @DefaultValue("20") final int limit,
|
||||
@QueryParam("offset") @DefaultValue("0") final int offset
|
||||
) {
|
||||
final Site site = findSite(siteIdentifier);
|
||||
return site
|
||||
.getApplications()
|
||||
.stream()
|
||||
.map(CcmApplicationId::new)
|
||||
.collect(Collectors.toList());
|
||||
return new ListView<>(
|
||||
siteRepository
|
||||
.findApplicationsAsStream(site, limit, offset)
|
||||
.map(CcmApplicationId::new)
|
||||
.collect(Collectors.toList()),
|
||||
siteRepository.countApplications(site),
|
||||
limit,
|
||||
offset
|
||||
);
|
||||
}
|
||||
|
||||
@PUT
|
||||
|
|
|
|||
|
|
@ -28,6 +28,8 @@ import javax.persistence.CascadeType;
|
|||
import javax.persistence.Entity;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.NamedQueries;
|
||||
import javax.persistence.NamedQuery;
|
||||
import javax.persistence.Table;
|
||||
|
||||
/**
|
||||
|
|
@ -38,14 +40,26 @@ import javax.persistence.Table;
|
|||
* For example for the Admin application or the Content Center application
|
||||
* provided by the ccm-cms module it makes no sense to make them site aware.
|
||||
* These applications are used to manage objects which are shared by all sites.
|
||||
* Other applications like the Pages application provided by the ccm-cms module are
|
||||
* of course site aware. The Pages application for example manages the page tree
|
||||
* of one specific site.
|
||||
* Other applications like the Pages application provided by the ccm-cms module
|
||||
* are of course site aware. The Pages application for example manages the page
|
||||
* tree of one specific site.
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "SITE_AWARE_APPLICATIONS", schema = DB_SCHEMA)
|
||||
@NamedQueries({
|
||||
@NamedQuery(
|
||||
name = "SiteAwareApplication.findForSite",
|
||||
query = "SELECT a FROM SiteAwareApplication a WHERE a.site = :site"
|
||||
),
|
||||
@NamedQuery(
|
||||
name = "SiteAwareApplication.countForSite",
|
||||
query = "SELECT COUNT(a) "
|
||||
+ "FROM SiteAwareApplication a "
|
||||
+ "WHERE a.site = :site"
|
||||
)
|
||||
})
|
||||
public class SiteAwareApplication extends CcmApplication {
|
||||
|
||||
private static final long serialVersionUID = -8892544588904174406L;
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import org.libreccm.security.RequiresPrivilege;
|
|||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.persistence.NoResultException;
|
||||
|
|
@ -119,6 +120,44 @@ public class SiteRepository extends AbstractEntityRepository<Long, Site> {
|
|||
return query.getSingleResult();
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public List<SiteAwareApplication> findApplications(
|
||||
final Site forSite, final int limit, final int offset
|
||||
) {
|
||||
return getEntityManager()
|
||||
.createNamedQuery(
|
||||
"SiteAwareApplication.findForSite", SiteAwareApplication.class
|
||||
)
|
||||
.setParameter("site", forSite)
|
||||
.setMaxResults(limit)
|
||||
.setFirstResult(offset)
|
||||
.getResultList();
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public Stream<SiteAwareApplication> findApplicationsAsStream(
|
||||
final Site forSite, final int limit, final int offset
|
||||
) {
|
||||
return getEntityManager()
|
||||
.createNamedQuery(
|
||||
"SiteAwareApplication.findForSite", SiteAwareApplication.class
|
||||
)
|
||||
.setParameter("site", forSite)
|
||||
.setMaxResults(limit)
|
||||
.setFirstResult(offset)
|
||||
.getResultStream();
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public int countApplications(final Site forSite) {
|
||||
return getEntityManager()
|
||||
.createNamedQuery(
|
||||
"SiteAwareApplication.countForSite", Integer.class
|
||||
)
|
||||
.setParameter("site", forSite)
|
||||
.getSingleResult();
|
||||
}
|
||||
|
||||
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Reference in New Issue