parent
d6758f478f
commit
ebf9d0d520
|
|
@ -20,9 +20,13 @@ package org.libreccm.api.admin.web;
|
|||
|
||||
import org.libreccm.api.Identifier;
|
||||
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.web.dto.CcmApplicationDto;
|
||||
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.l10n.LocalizedString;
|
||||
import org.libreccm.security.AuthorizationRequired;
|
||||
|
|
@ -72,6 +76,12 @@ public class CcmApplicationsApi {
|
|||
@Inject
|
||||
private ApplicationManager applicationManager;
|
||||
|
||||
@Inject
|
||||
private DomainsApi domainsApi;
|
||||
|
||||
@Inject
|
||||
private DomainRepository domainRepository;
|
||||
|
||||
@Inject
|
||||
private ApplicationRepository applicationRepository;
|
||||
|
||||
|
|
@ -224,7 +234,19 @@ public class CcmApplicationsApi {
|
|||
@PathParam("appIdentifier") final String appIdentifier,
|
||||
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
|
||||
|
|
@ -235,7 +257,15 @@ public class CcmApplicationsApi {
|
|||
public Response deleteApplication(
|
||||
@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
|
||||
|
|
@ -249,7 +279,18 @@ public class CcmApplicationsApi {
|
|||
@QueryParam("limit") @DefaultValue("20") final int limit,
|
||||
@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
|
||||
|
|
@ -262,7 +303,7 @@ public class CcmApplicationsApi {
|
|||
@PathParam("ownerIdentifier") final String appIdentifier,
|
||||
@PathParam("domainIdentifier") final String domainIdentifier
|
||||
) {
|
||||
throw new UnsupportedOperationException();
|
||||
return domainsApi.addOwner(domainIdentifier, appIdentifier);
|
||||
}
|
||||
|
||||
@DELETE
|
||||
|
|
@ -271,10 +312,12 @@ public class CcmApplicationsApi {
|
|||
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public Response removeOwner(
|
||||
@PathParam("appIdentifier") final String ownerIdentifierParam,
|
||||
@PathParam("domainIdentifier") final String domainIdentifierParam
|
||||
@PathParam("appIdentifier") final String appIdentifier,
|
||||
@PathParam("domainIdentifier") final String domainIdentifier
|
||||
) {
|
||||
throw new UnsupportedOperationException();
|
||||
return domainsApi.removeOwner(
|
||||
domainIdentifier, appIdentifier
|
||||
);
|
||||
}
|
||||
|
||||
private CcmApplication findApplication(final String applicationIdentifier) {
|
||||
|
|
|
|||
|
|
@ -74,6 +74,16 @@ import javax.xml.bind.annotation.XmlElement;
|
|||
query = "SELECT COUNT(o) "
|
||||
+ "FROM DomainOwnership o "
|
||||
+ "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,
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ package org.libreccm.categorization;
|
|||
import org.libreccm.core.AbstractEntityRepository;
|
||||
import org.libreccm.security.AuthorizationRequired;
|
||||
import org.libreccm.security.RequiresPrivilege;
|
||||
import org.libreccm.web.CcmApplication;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
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(
|
||||
final Domain domain, final int limit, final int offset
|
||||
) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue