From 94704d9e4a7b511cf2b130b036d182090dee0d73 Mon Sep 17 00:00:00 2001 From: Jens Pelzetter Date: Thu, 4 Jun 2020 12:01:44 +0200 Subject: [PATCH] API for Category domains (only method definitions, no implementation yet) Former-commit-id: 8fe5c38cb9f283b7d941fbda688e3e564635d99d --- .../api/admin/categorization/DomainsApi.java | 127 ++++++++++++-- .../admin/categorization/dto/CategoryId.java | 78 +++++++++ .../admin/categorization/dto/DomainData.java | 160 ++++++++++++++++++ .../dto/DomainOwnershipData.java | 70 ++++++++ .../categorization/dto/SubCategoryId.java | 61 +++++++ .../api/admin/web/dto/CcmApplicationId.java | 59 +++++++ 6 files changed, 541 insertions(+), 14 deletions(-) create mode 100644 ccm-core/src/main/java/org/libreccm/api/admin/categorization/dto/CategoryId.java create mode 100644 ccm-core/src/main/java/org/libreccm/api/admin/categorization/dto/DomainData.java create mode 100644 ccm-core/src/main/java/org/libreccm/api/admin/categorization/dto/DomainOwnershipData.java create mode 100644 ccm-core/src/main/java/org/libreccm/api/admin/categorization/dto/SubCategoryId.java create mode 100644 ccm-core/src/main/java/org/libreccm/api/admin/web/dto/CcmApplicationId.java diff --git a/ccm-core/src/main/java/org/libreccm/api/admin/categorization/DomainsApi.java b/ccm-core/src/main/java/org/libreccm/api/admin/categorization/DomainsApi.java index 77651dc8c..39a041f95 100644 --- a/ccm-core/src/main/java/org/libreccm/api/admin/categorization/DomainsApi.java +++ b/ccm-core/src/main/java/org/libreccm/api/admin/categorization/DomainsApi.java @@ -18,8 +18,28 @@ */ package org.libreccm.api.admin.categorization; +import org.libreccm.api.admin.categorization.dto.DomainData; +import org.libreccm.api.admin.categorization.dto.DomainOwnershipData; +import org.libreccm.api.dto.ListView; +import org.libreccm.core.CoreConstants; +import org.libreccm.security.AuthorizationRequired; +import org.libreccm.security.RequiresPrivilege; + +import java.util.List; + import javax.enterprise.context.RequestScoped; +import javax.transaction.Transactional; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.DefaultValue; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +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.MediaType; /** * @@ -28,21 +48,100 @@ import javax.ws.rs.Path; @RequestScoped @Path("/domains") public class DomainsApi { + + @GET + @Path("/") + @Produces(MediaType.APPLICATION_JSON) + @AuthorizationRequired + @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN) + @Transactional(Transactional.TxType.REQUIRED) + public ListView getDomains( + @QueryParam("limit") @DefaultValue("20") final int limit, + @QueryParam("offset") @DefaultValue("0") final int offset + ) { + throw new UnsupportedOperationException(); + } + + @GET + @Path("/{domainIdentifier}") + @Produces(MediaType.APPLICATION_JSON) + @AuthorizationRequired + @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN) + @Transactional(Transactional.TxType.REQUIRED) + public DomainData getDomain( + @PathParam("domainIdentifier") final String domainIdentifierParam) { + throw new UnsupportedOperationException(); + } + + @POST + @Path("/") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @AuthorizationRequired + @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN) + @Transactional(Transactional.TxType.REQUIRED) + public ListView addDomain(final DomainData domainData) { + throw new UnsupportedOperationException(); + } + + @PUT + @Path("/{domainIdentifier}") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @AuthorizationRequired + @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN) + @Transactional(Transactional.TxType.REQUIRED) + public DomainData updateDomain( + @PathParam("domainIdentifier") final String domainIdentifierParam, + final DomainData domainData) { + throw new UnsupportedOperationException(); + } + + @DELETE + @Path("/{domainIdentifier}") + @AuthorizationRequired + @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN) + @Transactional(Transactional.TxType.REQUIRED) + public DomainData deleteDomain( + @PathParam("domainIdentifier") final String domainIdentifierParam) { + throw new UnsupportedOperationException(); + } - // GET Domains @Path("/") + @GET + @Path("/{domainIdentifier}/owners") + @Produces(MediaType.APPLICATION_JSON) + @AuthorizationRequired + @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN) + @Transactional(Transactional.TxType.REQUIRED) + public List getOwners( + @PathParam("domainIdentifier") final String domainIdentifierParam + ) { + throw new UnsupportedOperationException(); + } + + @GET + @Path("/{domainIdentifier}/owners/{ownerIdentifier}") + @Produces(MediaType.APPLICATION_JSON) + @AuthorizationRequired + @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN) + @Transactional(Transactional.TxType.REQUIRED) + public List addOwner( + @PathParam("domainIdentifier") final String domainIdentifierParam, + @PathParam("ownerIdentifier") final String ownerIdentifierParam + ) { + throw new UnsupportedOperationException(); + } - // GET Domain @Path("/domain-identifier") + @DELETE + @Path("/{domainIdentifier}/owners/{ownerIdentifier}") + @AuthorizationRequired + @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN) + @Transactional(Transactional.TxType.REQUIRED) + public List removeOwner( + @PathParam("domainIdentifier") final String domainIdentifierParam, + @PathParam("ownerIdentifier") final String ownerIdentifierParam + ) { + throw new UnsupportedOperationException(); + } - // POST @Path("/") create new - - // PUT Domain @Path("/domain-identifier") - - - // DELETE Domain @Path("/domain-identifier") - - // GET owners @Path("/domain-identifier/owners") - - // PUT Add owner @Path("/domain-identifier/owners/owner-identifier") - - // DELETE Remove owner @Path("/domain-identifier/owners/owner-identifier") } diff --git a/ccm-core/src/main/java/org/libreccm/api/admin/categorization/dto/CategoryId.java b/ccm-core/src/main/java/org/libreccm/api/admin/categorization/dto/CategoryId.java new file mode 100644 index 000000000..db8d263a2 --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/api/admin/categorization/dto/CategoryId.java @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2020 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.libreccm.api.admin.categorization.dto; + +import org.libreccm.categorization.Category; + +/** + * Provides the informations for identifing a {@link Category}. + * + * @author Jens Pelzetter + */ +public class CategoryId { + + private long categoryId; + + private String uuid; + + private String uniqueId; + + /** + * Constructor for creating empty instances. + */ + public CategoryId() { + // Nothing + } + + /** + * Creates an instance from the provided catgory. + * + * @param category The {@link Category} used as source. + */ + public CategoryId(final Category category) { + categoryId = category.getObjectId(); + uuid = category.getUuid(); + uniqueId = category.getUniqueId(); + } + + public long getCategoryId() { + return categoryId; + } + + public void setCategoryId(final long categoryId) { + this.categoryId = categoryId; + } + + public String getUuid() { + return uuid; + } + + public void setUuid(final String uuid) { + this.uuid = uuid; + } + + public String getUniqueId() { + return uniqueId; + } + + public void setUniqueId(final String uniqueId) { + this.uniqueId = uniqueId; + } + +} diff --git a/ccm-core/src/main/java/org/libreccm/api/admin/categorization/dto/DomainData.java b/ccm-core/src/main/java/org/libreccm/api/admin/categorization/dto/DomainData.java new file mode 100644 index 000000000..e60775ae8 --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/api/admin/categorization/dto/DomainData.java @@ -0,0 +1,160 @@ +/* + * Copyright (C) 2020 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.libreccm.api.admin.categorization.dto; + +import org.libreccm.categorization.Domain; +import org.libreccm.l10n.LocalizedString; + +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +/** + * + * @author Jens Pelzetter + */ +public class DomainData { + + private long domainId; + + private String uuid; + + private String domainKey; + + private String uri; + + private LocalizedString title; + + private LocalizedString description; + + private String version; + + private String released; + + private CategoryId root; + + private List owners; + + public DomainData() { + owners = new ArrayList<>(); + } + + public DomainData(final Domain domain) { + domainId = domain.getObjectId(); + uuid = domain.getUuid(); + domainKey = domain.getDomainKey(); + uri = domain.getUri(); + title = domain.getTitle(); + description = domain.getDescription(); + version = domain.getVersion(); + released = DateTimeFormatter + .ISO_DATE_TIME + .format(domain.getReleased().toInstant()); + root = new CategoryId(domain.getRoot()); + + owners = domain + .getOwners() + .stream() + .map(DomainOwnershipData::new) + .collect(Collectors.toList()); + } + + public long getDomainId() { + return domainId; + } + + public void setDomainId(final long domainId) { + this.domainId = domainId; + } + + public String getUuid() { + return uuid; + } + + public void setUuid(final String uuid) { + this.uuid = uuid; + } + + public String getDomainKey() { + return domainKey; + } + + public void setDomainKey(final String domainKey) { + this.domainKey = domainKey; + } + + public String getUri() { + return uri; + } + + public void setUri(final String uri) { + this.uri = uri; + } + + public LocalizedString getTitle() { + return title; + } + + public void setTitle(final LocalizedString title) { + this.title = title; + } + + public LocalizedString getDescription() { + return description; + } + + public void setDescription(final LocalizedString description) { + this.description = description; + } + + public String getVersion() { + return version; + } + + public void setVersion(final String version) { + this.version = version; + } + + public String getReleased() { + return released; + } + + public void setReleased(final String released) { + this.released = released; + } + + public CategoryId getRoot() { + return root; + } + + public void setRoot(final CategoryId root) { + this.root = root; + } + + public List getOwners() { + return new ArrayList<>(owners); + } + + public void setOwners(final List owners) { + this.owners = new ArrayList<>(owners); + } + + +} diff --git a/ccm-core/src/main/java/org/libreccm/api/admin/categorization/dto/DomainOwnershipData.java b/ccm-core/src/main/java/org/libreccm/api/admin/categorization/dto/DomainOwnershipData.java new file mode 100644 index 000000000..fde3571d9 --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/api/admin/categorization/dto/DomainOwnershipData.java @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2020 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.libreccm.api.admin.categorization.dto; + +import org.libreccm.api.admin.web.dto.CcmApplicationId; +import org.libreccm.categorization.DomainOwnership; + +/** + * + * @author Jens Pelzetter + */ +public class DomainOwnershipData { + + private long ownershipId; + + private String uuid; + + private CcmApplicationId owner; + + public DomainOwnershipData() { + // Nothing + } + + public DomainOwnershipData(final DomainOwnership ownership) { + ownershipId = ownership.getOwnershipId(); + uuid = ownership.getUuid(); + owner = new CcmApplicationId(ownership.getOwner()); + } + + public long getOwnershipId() { + return ownershipId; + } + + public void setOwnershipId(final long ownershipId) { + this.ownershipId = ownershipId; + } + + public String getUuid() { + return uuid; + } + + public void setUuid(final String uuid) { + this.uuid = uuid; + } + + public CcmApplicationId getOwner() { + return owner; + } + + public void setOwner(final CcmApplicationId owner) { + this.owner = owner; + } + +} diff --git a/ccm-core/src/main/java/org/libreccm/api/admin/categorization/dto/SubCategoryId.java b/ccm-core/src/main/java/org/libreccm/api/admin/categorization/dto/SubCategoryId.java new file mode 100644 index 000000000..5ebf3367d --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/api/admin/categorization/dto/SubCategoryId.java @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2020 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.libreccm.api.admin.categorization.dto; + +import org.libreccm.categorization.Category; +import org.libreccm.l10n.LocalizedString; + +/** + * + * @author Jens Pelzetter + */ +public class SubCategoryId extends CategoryId { + + private String name; + + private LocalizedString title; + + public SubCategoryId() { + super(); + } + + public SubCategoryId(final Category category) { + super(category); + name = category.getName(); + title = category.getTitle(); + } + + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + public LocalizedString getTitle() { + return title; + } + + public void setTitle(final LocalizedString title) { + this.title = title; + } + + +} diff --git a/ccm-core/src/main/java/org/libreccm/api/admin/web/dto/CcmApplicationId.java b/ccm-core/src/main/java/org/libreccm/api/admin/web/dto/CcmApplicationId.java new file mode 100644 index 000000000..1a085953f --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/api/admin/web/dto/CcmApplicationId.java @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2020 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.libreccm.api.admin.web.dto; + +import org.libreccm.api.core.dto.CcmObjectId; +import org.libreccm.web.CcmApplication; + +/** + * + * @author Jens Pelzetter + */ +public class CcmApplicationId extends CcmObjectId { + + private String applicationType; + + private String primaryUrl; + + public CcmApplicationId() { + super(); + } + + public CcmApplicationId(final CcmApplication application) { + applicationType = application.getApplicationType(); + primaryUrl = application.getPrimaryUrl(); + } + + public String getApplicationType() { + return applicationType; + } + + public void setApplicationType(final String applicationType) { + this.applicationType = applicationType; + } + + public String getPrimaryUrl() { + return primaryUrl; + } + + public void setPrimaryUrl(final String primaryUrl) { + this.primaryUrl = primaryUrl; + } + +}