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