CcmApplicationsApi finished
parent
14f084eef7
commit
bebe653cce
|
|
@ -20,9 +20,13 @@ package org.libreccm.api.admin.web;
|
||||||
|
|
||||||
import org.libreccm.api.Identifier;
|
import org.libreccm.api.Identifier;
|
||||||
import org.libreccm.api.IdentifierParser;
|
import org.libreccm.api.IdentifierParser;
|
||||||
|
import org.libreccm.api.admin.categorization.DomainsApi;
|
||||||
import org.libreccm.api.admin.categorization.dto.DomainOwnershipData;
|
import org.libreccm.api.admin.categorization.dto.DomainOwnershipData;
|
||||||
import org.libreccm.api.admin.web.dto.CcmApplicationDto;
|
import org.libreccm.api.admin.web.dto.CcmApplicationDto;
|
||||||
import org.libreccm.api.dto.ListView;
|
import org.libreccm.api.dto.ListView;
|
||||||
|
import org.libreccm.categorization.Domain;
|
||||||
|
import org.libreccm.categorization.DomainManager;
|
||||||
|
import org.libreccm.categorization.DomainRepository;
|
||||||
import org.libreccm.core.CoreConstants;
|
import org.libreccm.core.CoreConstants;
|
||||||
import org.libreccm.l10n.LocalizedString;
|
import org.libreccm.l10n.LocalizedString;
|
||||||
import org.libreccm.security.AuthorizationRequired;
|
import org.libreccm.security.AuthorizationRequired;
|
||||||
|
|
@ -72,6 +76,12 @@ public class CcmApplicationsApi {
|
||||||
@Inject
|
@Inject
|
||||||
private ApplicationManager applicationManager;
|
private ApplicationManager applicationManager;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private DomainsApi domainsApi;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private DomainRepository domainRepository;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private ApplicationRepository applicationRepository;
|
private ApplicationRepository applicationRepository;
|
||||||
|
|
||||||
|
|
@ -224,7 +234,19 @@ public class CcmApplicationsApi {
|
||||||
@PathParam("appIdentifier") final String appIdentifier,
|
@PathParam("appIdentifier") final String appIdentifier,
|
||||||
final CcmApplicationDto applicationData
|
final CcmApplicationDto applicationData
|
||||||
) {
|
) {
|
||||||
throw new UnsupportedOperationException();
|
final CcmApplication application = findApplication(appIdentifier);
|
||||||
|
|
||||||
|
application.setTitle(applicationData.getTitle());
|
||||||
|
application.setDescription(applicationData.getDescription());
|
||||||
|
|
||||||
|
applicationRepository.save(application);
|
||||||
|
|
||||||
|
return Response
|
||||||
|
.ok(
|
||||||
|
String.format(
|
||||||
|
"Application %s successfully updated.", appIdentifier
|
||||||
|
)
|
||||||
|
).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@DELETE
|
@DELETE
|
||||||
|
|
@ -235,7 +257,15 @@ public class CcmApplicationsApi {
|
||||||
public Response deleteApplication(
|
public Response deleteApplication(
|
||||||
@PathParam("appIdentifier") final String appIdentifier
|
@PathParam("appIdentifier") final String appIdentifier
|
||||||
) {
|
) {
|
||||||
throw new UnsupportedOperationException();
|
final CcmApplication application = findApplication(appIdentifier);
|
||||||
|
|
||||||
|
applicationManager.deleteInstance(application);
|
||||||
|
|
||||||
|
return Response.ok(
|
||||||
|
String.format(
|
||||||
|
"Application instance %s deleted sucessfully.", appIdentifier
|
||||||
|
)
|
||||||
|
).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
|
|
@ -249,7 +279,18 @@ public class CcmApplicationsApi {
|
||||||
@QueryParam("limit") @DefaultValue("20") final int limit,
|
@QueryParam("limit") @DefaultValue("20") final int limit,
|
||||||
@QueryParam("offset") @DefaultValue("0") final int offset
|
@QueryParam("offset") @DefaultValue("0") final int offset
|
||||||
) {
|
) {
|
||||||
throw new UnsupportedOperationException();
|
final CcmApplication application = findApplication(appIdentifier);
|
||||||
|
return new ListView<>(
|
||||||
|
domainRepository
|
||||||
|
.findDomainsOfOwnerAsStream(application, limit, offset)
|
||||||
|
.map(DomainOwnershipData::new)
|
||||||
|
.collect(Collectors.toList()),
|
||||||
|
domainRepository
|
||||||
|
.countDomainsOfOwner(
|
||||||
|
application),
|
||||||
|
limit,
|
||||||
|
offset
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PUT
|
@PUT
|
||||||
|
|
@ -262,7 +303,7 @@ public class CcmApplicationsApi {
|
||||||
@PathParam("ownerIdentifier") final String appIdentifier,
|
@PathParam("ownerIdentifier") final String appIdentifier,
|
||||||
@PathParam("domainIdentifier") final String domainIdentifier
|
@PathParam("domainIdentifier") final String domainIdentifier
|
||||||
) {
|
) {
|
||||||
throw new UnsupportedOperationException();
|
return domainsApi.addOwner(domainIdentifier, appIdentifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
@DELETE
|
@DELETE
|
||||||
|
|
@ -271,10 +312,12 @@ public class CcmApplicationsApi {
|
||||||
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
|
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
public Response removeOwner(
|
public Response removeOwner(
|
||||||
@PathParam("appIdentifier") final String ownerIdentifierParam,
|
@PathParam("appIdentifier") final String appIdentifier,
|
||||||
@PathParam("domainIdentifier") final String domainIdentifierParam
|
@PathParam("domainIdentifier") final String domainIdentifier
|
||||||
) {
|
) {
|
||||||
throw new UnsupportedOperationException();
|
return domainsApi.removeOwner(
|
||||||
|
domainIdentifier, appIdentifier
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private CcmApplication findApplication(final String applicationIdentifier) {
|
private CcmApplication findApplication(final String applicationIdentifier) {
|
||||||
|
|
|
||||||
|
|
@ -72,8 +72,18 @@ import javax.xml.bind.annotation.XmlElement;
|
||||||
@NamedQuery(
|
@NamedQuery(
|
||||||
name = "DomainOwnershop.countForDomain",
|
name = "DomainOwnershop.countForDomain",
|
||||||
query = "SELECT COUNT(o) "
|
query = "SELECT COUNT(o) "
|
||||||
+ "FROM DomainOwnership o "
|
+ "FROM DomainOwnership o "
|
||||||
+ "WHERE o.domain = :domain"
|
+ "WHERE o.domain = :domain"
|
||||||
|
),
|
||||||
|
@NamedQuery(
|
||||||
|
name = "DomainOwnership.findByOwner",
|
||||||
|
query = "SELECT o FROM DomainOwnership o "
|
||||||
|
+ "WHERE o.owner = :owner "
|
||||||
|
+ "ORDER BY o.domainOrder"
|
||||||
|
),
|
||||||
|
@NamedQuery(
|
||||||
|
name = "DomainOwnership.countForOwner",
|
||||||
|
query = "SELECT COUNT(o) FROM DomainOwnership o WHERE o.owner = :owner"
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class,
|
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class,
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ package org.libreccm.categorization;
|
||||||
import org.libreccm.core.AbstractEntityRepository;
|
import org.libreccm.core.AbstractEntityRepository;
|
||||||
import org.libreccm.security.AuthorizationRequired;
|
import org.libreccm.security.AuthorizationRequired;
|
||||||
import org.libreccm.security.RequiresPrivilege;
|
import org.libreccm.security.RequiresPrivilege;
|
||||||
|
import org.libreccm.web.CcmApplication;
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
import javax.persistence.EntityGraph;
|
import javax.persistence.EntityGraph;
|
||||||
|
|
@ -141,6 +142,59 @@ public class DomainRepository extends AbstractEntityRepository<Long, Domain> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<DomainOwnership> findDomainsOfOwner(
|
||||||
|
final CcmApplication owner, final int limit, final int offset
|
||||||
|
) {
|
||||||
|
return getEntityManager()
|
||||||
|
.createNamedQuery(
|
||||||
|
"DomainOwnership.findByOwner",
|
||||||
|
DomainOwnership.class
|
||||||
|
)
|
||||||
|
.setParameter(
|
||||||
|
"owner",
|
||||||
|
Objects.requireNonNull(
|
||||||
|
owner,
|
||||||
|
"Can't find owners for domain null."
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setMaxResults(limit)
|
||||||
|
.setFirstResult(offset)
|
||||||
|
.getResultList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Stream<DomainOwnership> findDomainsOfOwnerAsStream(
|
||||||
|
final CcmApplication owner, final int limit, final int offset
|
||||||
|
) {
|
||||||
|
return getEntityManager()
|
||||||
|
.createNamedQuery(
|
||||||
|
"DomainOwnership.findByOwner",
|
||||||
|
DomainOwnership.class
|
||||||
|
)
|
||||||
|
.setParameter(
|
||||||
|
"owner",
|
||||||
|
Objects.requireNonNull(
|
||||||
|
owner,
|
||||||
|
"Can't find owners for domain null."
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setMaxResults(limit)
|
||||||
|
.setFirstResult(offset)
|
||||||
|
.getResultStream();
|
||||||
|
}
|
||||||
|
|
||||||
|
public long countDomainsOfOwner(final CcmApplication owner) {
|
||||||
|
return getEntityManager()
|
||||||
|
.createNamedQuery("DomainOwnership.countForOwner", Long.class)
|
||||||
|
.setParameter(
|
||||||
|
"owner",
|
||||||
|
Objects.requireNonNull(
|
||||||
|
owner,
|
||||||
|
"Can't find owners for domain null."
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.getSingleResult();
|
||||||
|
}
|
||||||
|
|
||||||
public List<DomainOwnership> findOwnersOfDomain(
|
public List<DomainOwnership> findOwnersOfDomain(
|
||||||
final Domain domain, final int limit, final int offset
|
final Domain domain, final int limit, final int offset
|
||||||
) {
|
) {
|
||||||
|
|
@ -149,7 +203,7 @@ public class DomainRepository extends AbstractEntityRepository<Long, Domain> {
|
||||||
"DomainOwnership.findForDomain", DomainOwnership.class
|
"DomainOwnership.findForDomain", DomainOwnership.class
|
||||||
)
|
)
|
||||||
.setParameter(
|
.setParameter(
|
||||||
"domain",
|
"domain",
|
||||||
Objects.requireNonNull(
|
Objects.requireNonNull(
|
||||||
domain, "Can't find owners for domain null."
|
domain, "Can't find owners for domain null."
|
||||||
)
|
)
|
||||||
|
|
@ -158,7 +212,7 @@ public class DomainRepository extends AbstractEntityRepository<Long, Domain> {
|
||||||
.setFirstResult(offset)
|
.setFirstResult(offset)
|
||||||
.getResultList();
|
.getResultList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Stream<DomainOwnership> findOwnersOfDomainAsStream(
|
public Stream<DomainOwnership> findOwnersOfDomainAsStream(
|
||||||
final Domain domain, final int limit, final int offset
|
final Domain domain, final int limit, final int offset
|
||||||
) {
|
) {
|
||||||
|
|
@ -167,7 +221,7 @@ public class DomainRepository extends AbstractEntityRepository<Long, Domain> {
|
||||||
"DomainOwnership.findForDomain", DomainOwnership.class
|
"DomainOwnership.findForDomain", DomainOwnership.class
|
||||||
)
|
)
|
||||||
.setParameter(
|
.setParameter(
|
||||||
"domain",
|
"domain",
|
||||||
Objects.requireNonNull(
|
Objects.requireNonNull(
|
||||||
domain, "Can't find owners for domain null."
|
domain, "Can't find owners for domain null."
|
||||||
)
|
)
|
||||||
|
|
@ -176,12 +230,12 @@ public class DomainRepository extends AbstractEntityRepository<Long, Domain> {
|
||||||
.setFirstResult(offset)
|
.setFirstResult(offset)
|
||||||
.getResultStream();
|
.getResultStream();
|
||||||
}
|
}
|
||||||
|
|
||||||
public long countOwnersOfDomain(final Domain domain) {
|
public long countOwnersOfDomain(final Domain domain) {
|
||||||
return getEntityManager()
|
return getEntityManager()
|
||||||
.createNamedQuery("DomainOwnershop.countForDomain", Long.class)
|
.createNamedQuery("DomainOwnershop.countForDomain", Long.class)
|
||||||
.setParameter(
|
.setParameter(
|
||||||
"domain",
|
"domain",
|
||||||
Objects.requireNonNull(
|
Objects.requireNonNull(
|
||||||
domain, "Can't find owners for domain null."
|
domain, "Can't find owners for domain null."
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue