diff --git a/src/main/api/studio-api.yaml b/src/main/api/studio-api.yaml index 462dc9f55e..8605618e48 100644 --- a/src/main/api/studio-api.yaml +++ b/src/main/api/studio-api.yaml @@ -6552,7 +6552,7 @@ paths: required: false schema: type: string - - name: systemType + - name: systemTypes in: query description: system types to filter package items by required: false @@ -6578,6 +6578,20 @@ paths: required: false schema: type: string + - name: offset + in: query + description: Offset for pagination + required: false + schema: + type: integer + format: int32 + - name: limit + in: query + description: Limit for pagination + required: false + schema: + type: integer + format: int32 responses: '200': description: OK @@ -8258,13 +8272,13 @@ paths: '500': $ref: '#/components/responses/InternalServerError' - /api/2/workflow/{site}/package/{package}/cancel: + /api/2/workflow/{site}/cancel: post: tags: - workflow - summary: Cancel publish package + summary: Cancel publish packages description: 'Required permission "cancel_publish"' - operationId: cancelPublishPackage + operationId: cancelPublishPackages parameters: - name: site in: path @@ -8273,14 +8287,6 @@ paths: schema: type: string example: "site123" - - name: package - in: path - description: package ID - required: true - schema: - type: integer - format: int64 - example: "12345" requestBody: description: parameters for publish package cancellation required: true @@ -8289,6 +8295,12 @@ paths: schema: type: object properties: + packageIds: + type: array + description: list of package IDs to cancel + items: + type: integer + format: int64 comment: type: string description: Reviewer's comment diff --git a/src/main/java/org/craftercms/studio/api/v2/dal/publish/PublishDAO.java b/src/main/java/org/craftercms/studio/api/v2/dal/publish/PublishDAO.java index ce9f348543..24e6066cbe 100644 --- a/src/main/java/org/craftercms/studio/api/v2/dal/publish/PublishDAO.java +++ b/src/main/java/org/craftercms/studio/api/v2/dal/publish/PublishDAO.java @@ -342,29 +342,36 @@ default Collection getPublishItems(final String siteId, final long Collection getPublishItems(@Param(SITE_ID) String siteId, @Param(PACKAGE_ID) long packageId, @Param(OFFSET) Integer offset, @Param(LIMIT) Integer limit); - /** - * Get the publish items (with metadata) for the given package - * - * @param siteId the site id - * @param packageId the package id - * @return PublishItemWithMetadata records for the package - */ - default Collection getPublishItemsWithMetadata(@Param(SITE_ID) String siteId, @Param(PACKAGE_ID) long packageId) { - return getPublishItemsWithMetadata(siteId, packageId, null, null); - } - /** * Get the paginated list of publish items (with metadata) for the given package * - * @param siteId the site id - * @param packageId the package id - * @param offset the offset to start from - * @param limit the max number of items to return + * @param siteId the site id + * @param packageId the package id + * @param path the path to filter by + * @param systemTypes the system types to filter by + * @param label the label to filter by + * @param offset the offset to start from + * @param limit the max number of items to return * @return PublishItemWithMetadata paginated records for the package */ Collection getPublishItemsWithMetadata(@Param(SITE_ID) String siteId, @Param(PACKAGE_ID) long packageId, + @Param(PATH) String path, @Param(SYSTEM_TYPES) Collection systemTypes, + @Param(LABEL) String label, @Param(OFFSET) Integer offset, @Param(LIMIT) Integer limit); + /** + * Get the number of publish items matching the given filters + * + * @param siteId the site id + * @param packageId the package id + * @param path the path to filter by + * @param systemTypes the system types to filter by + * @param label the label to filter by + */ + int getMatchingPublishItemCount(@Param(SITE_ID) String siteId, @Param(PACKAGE_ID) long packageId, + @Param(PATH) String path, @Param(SYSTEM_TYPES) Collection systemTypes, + @Param(LABEL) String label); + /** * Update the state for all publish items in the package * diff --git a/src/main/java/org/craftercms/studio/api/v2/service/publish/PublishService.java b/src/main/java/org/craftercms/studio/api/v2/service/publish/PublishService.java index d967b3b502..3996d00ab3 100644 --- a/src/main/java/org/craftercms/studio/api/v2/service/publish/PublishService.java +++ b/src/main/java/org/craftercms/studio/api/v2/service/publish/PublishService.java @@ -22,6 +22,7 @@ import org.craftercms.studio.api.v1.exception.SiteNotFoundException; import org.craftercms.studio.api.v1.exception.security.AuthenticationException; import org.craftercms.studio.api.v2.dal.publish.PublishItem; +import org.craftercms.studio.api.v2.dal.publish.PublishItemWithMetadata; import org.craftercms.studio.api.v2.dal.publish.PublishPackage; import org.craftercms.studio.api.v2.dal.publish.PublishPackage.ApprovalState; import org.craftercms.studio.api.v2.exception.publish.PublishPackageNotFoundException; @@ -85,14 +86,32 @@ Collection getPublishPackages(String siteId, String target, Long int offset, int limit) throws SiteNotFoundException; /** - * Get publish package details + * Get publish package items * - * @param siteId site identifier - * @param packageId package identifier - * @return publish package details - * @throws SiteNotFoundException site not found + * @param siteId site identifier + * @param packageId package identifier + * @param path regex to filter package items by + * @param systemTypes system types to filter package items by + * @param internalName internal name to filter package items by + * @param offset offset for pagination + * @param limit limit for pagination + * @return publish package item list + */ + Collection getPublishPackageItems(String siteId, long packageId, + String path, Collection systemTypes, String internalName, + int offset, int limit); + + /** + * Get publish package number of items matching the given filters + * + * @param siteId site identifier + * @param packageId package identifier + * @param path regex to filter package items by + * @param systemType system type to filter package items by + * @param internalName internal name to filter package items by + * @return publish package item list */ - PublishPackageDetails getPublishPackageDetails(String siteId, long packageId) throws SiteNotFoundException, PublishPackageNotFoundException; + int getPublishPackageItemCount(String siteId, long packageId, String path, List systemType, String internalName); /** * Get available publishing targets for given site diff --git a/src/main/java/org/craftercms/studio/api/v2/service/workflow/WorkflowService.java b/src/main/java/org/craftercms/studio/api/v2/service/workflow/WorkflowService.java index 1322c72e7a..44268e82fd 100644 --- a/src/main/java/org/craftercms/studio/api/v2/service/workflow/WorkflowService.java +++ b/src/main/java/org/craftercms/studio/api/v2/service/workflow/WorkflowService.java @@ -22,6 +22,7 @@ import org.craftercms.studio.model.rest.content.SandboxItem; import java.time.Instant; +import java.util.Collection; import java.util.List; public interface WorkflowService { @@ -87,14 +88,14 @@ void approvePackage(String siteId, long packageId, Instant schedule, boolean upd throws ServiceLayerException, AuthenticationException; /** - * Cancel publish package + * Cancel publish packages * - * @param siteId site identifier - * @param packageId the package identifier - * @param comment the user comment + * @param siteId site identifier + * @param packageIds the package identifiers + * @param comment the user comment * @throws SiteNotFoundException site not found */ - void cancelPackage(String siteId, long packageId, String comment) + void cancelPackages(String siteId, Collection packageIds, String comment) throws ServiceLayerException, AuthenticationException; /** diff --git a/src/main/java/org/craftercms/studio/controller/rest/v2/PublishController.java b/src/main/java/org/craftercms/studio/controller/rest/v2/PublishController.java index 731047db4f..ffeec78336 100644 --- a/src/main/java/org/craftercms/studio/controller/rest/v2/PublishController.java +++ b/src/main/java/org/craftercms/studio/controller/rest/v2/PublishController.java @@ -31,6 +31,7 @@ import org.craftercms.studio.api.v1.exception.security.AuthenticationException; import org.craftercms.studio.api.v1.exception.security.UserNotFoundException; import org.craftercms.studio.api.v2.dal.PublishStatus; +import org.craftercms.studio.api.v2.dal.publish.PublishItemWithMetadata; import org.craftercms.studio.api.v2.dal.publish.PublishPackage; import org.craftercms.studio.api.v2.exception.publish.PublishPackageNotFoundException; import org.craftercms.studio.api.v2.service.publish.PublishService; @@ -47,8 +48,10 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.List; +import static java.util.Collections.emptyList; import static org.apache.commons.collections.CollectionUtils.isEmpty; import static org.craftercms.commons.validation.annotations.param.EsapiValidationType.ALPHANUMERIC; import static org.craftercms.commons.validation.annotations.param.EsapiValidationType.USERNAME; @@ -75,24 +78,24 @@ public PublishController(final PublishService publishService, final SitesService @GetMapping(PATH_PARAM_SITE + PACKAGES) public PaginatedResultList getPublishPackages(@ValidSiteId @PathVariable String site, - @EsapiValidatedParam(type = ALPHANUMERIC) @Size(max = 20) - @RequestParam(name = REQUEST_PARAM_TARGET, required = false) - String target, - @RequestParam(name = REQUEST_PARAM_STATES, required = false) Long states, - @RequestParam(name = REQUEST_PARAM_APPROVAL_STATES, required = false) - List approvalStates, - @RequestParam(name = REQUEST_PARAM_SUBMITTER, required = false) - @EsapiValidatedParam(type = USERNAME) String submitter, - @RequestParam(name = REQUEST_PARAM_REVIEWER, required = false) - @EsapiValidatedParam(type = USERNAME) String reviewer, - @RequestParam(name = REQUEST_PARAM_IS_SCHEDULED, required = false) - Boolean isScheduled, - @RequestParam(name = REQUEST_PARAM_SORT, required = false) - List<@SqlSort(columns = PUBLISH_PACKAGES_SORT_FIELDS) SortField> sort, - @RequestParam(name = REQUEST_PARAM_OFFSET, required = false, - defaultValue = "0") @PositiveOrZero int offset, - @RequestParam(name = REQUEST_PARAM_LIMIT, required = false, - defaultValue = "10") @PositiveOrZero int limit) + @EsapiValidatedParam(type = ALPHANUMERIC) @Size(max = 20) + @RequestParam(name = REQUEST_PARAM_TARGET, required = false) + String target, + @RequestParam(name = REQUEST_PARAM_STATES, required = false) Long states, + @RequestParam(name = REQUEST_PARAM_APPROVAL_STATES, required = false) + List approvalStates, + @RequestParam(name = REQUEST_PARAM_SUBMITTER, required = false) + @EsapiValidatedParam(type = USERNAME) String submitter, + @RequestParam(name = REQUEST_PARAM_REVIEWER, required = false) + @EsapiValidatedParam(type = USERNAME) String reviewer, + @RequestParam(name = REQUEST_PARAM_IS_SCHEDULED, required = false) + Boolean isScheduled, + @RequestParam(name = REQUEST_PARAM_SORT, required = false) + List<@SqlSort(columns = PUBLISH_PACKAGES_SORT_FIELDS) SortField> sort, + @RequestParam(name = REQUEST_PARAM_OFFSET, required = false, + defaultValue = "0") @PositiveOrZero int offset, + @RequestParam(name = REQUEST_PARAM_LIMIT, required = false, + defaultValue = "10") @PositiveOrZero int limit) throws SiteNotFoundException { long total = publishService.getPublishPackagesCount(site, target, states, approvalStates, submitter, reviewer, isScheduled); Collection packages = new ArrayList<>(); @@ -110,13 +113,26 @@ public PaginatedResultList getPublishPackages(@ValidSiteId @Path } @GetMapping(PATH_PARAM_SITE + PACKAGE + PATH_PARAM_PACKAGE) - public ResultOne getPublishPackage(@PathVariable @ValidSiteId String site, - @PathVariable @Positive long packageId) + public PublishPackageDetails getPublishPackage(@PathVariable @ValidSiteId String site, + @PathVariable @Positive long packageId, + @RequestParam(name = REQUEST_PARAM_PATH, required = false) String path, + @RequestParam(name = REQUEST_PARAM_SYSTEM_TYPE, required = false) List systemTypes, + @RequestParam(name = REQUEST_PARAM_INTERNAL_NAME, required = false) String internalName, + @RequestParam(name = REQUEST_PARAM_OFFSET, required = false, + defaultValue = "0") @PositiveOrZero int offset, + @RequestParam(name = REQUEST_PARAM_LIMIT, required = false, + defaultValue = "10") @PositiveOrZero int limit) throws SiteNotFoundException, PublishPackageNotFoundException { - PublishPackageDetails publishPackageDetails = - publishService.getPublishPackageDetails(site, packageId); - ResultOne result = new ResultOne<>(); - result.setEntity(RESULT_KEY_PACKAGE, publishPackageDetails); + PublishPackage publishPackage = publishService.getPackage(site, packageId); + Collection items = emptyList(); + int totalItemCount = publishService.getPublishPackageItemCount(site, packageId, path, systemTypes, internalName); + if (totalItemCount > 0) { + items = publishService.getPublishPackageItems(site, packageId, path, systemTypes, internalName, offset, limit); + } + PublishPackageDetails result = new PublishPackageDetails(publishPackage, items); + result.setTotal(totalItemCount); + result.setOffset(offset); + result.setLimit(limit); result.setResponse(OK); return result; } diff --git a/src/main/java/org/craftercms/studio/controller/rest/v2/RequestConstants.java b/src/main/java/org/craftercms/studio/controller/rest/v2/RequestConstants.java index e3bdd29273..3c5e06150d 100644 --- a/src/main/java/org/craftercms/studio/controller/rest/v2/RequestConstants.java +++ b/src/main/java/org/craftercms/studio/controller/rest/v2/RequestConstants.java @@ -39,8 +39,10 @@ public final class RequestConstants { public static final String REQUEST_PARAM_ORDER = "order"; public static final String REQUEST_PARAM_PATH = "path"; public static final String REQUEST_PARAM_NAME = "name"; + public static final String REQUEST_PARAM_INTERNAL_NAME = "internalName"; public static final String REQUEST_PARAM_PROFILE_ID = "profileId"; public static final String REQUEST_PARAM_TYPE = "type"; + public static final String REQUEST_PARAM_SYSTEM_TYPE = "systemType"; public static final String REQUEST_PARAM_ENVIRONMENT = "environment"; public static final String REQUEST_PARAM_STATES = "states"; public static final String REQUEST_PARAM_APPROVAL_STATES = "approvalStates"; diff --git a/src/main/java/org/craftercms/studio/controller/rest/v2/RequestMappingConstants.java b/src/main/java/org/craftercms/studio/controller/rest/v2/RequestMappingConstants.java index 8a9ce42e4c..d5daf987ff 100644 --- a/src/main/java/org/craftercms/studio/controller/rest/v2/RequestMappingConstants.java +++ b/src/main/java/org/craftercms/studio/controller/rest/v2/RequestMappingConstants.java @@ -120,9 +120,7 @@ public final class RequestMappingConstants { public static final String WORKFLOW = "/workflow"; public static final String ITEM_STATES = "/item_states"; public static final String UPDATE_ITEM_STATES_BY_QUERY = "/update_item_states_by_query"; - public static final String AFFECTED_PATHS = "/affected_paths"; public static final String AFFECTED_PACKAGES = "/affected_packages"; - public static final String REQUEST_PUBLISH = "/request_publish"; public static final String REJECT = "/reject"; public static final String APPROVE = "/approve"; diff --git a/src/main/java/org/craftercms/studio/controller/rest/v2/WorkflowController.java b/src/main/java/org/craftercms/studio/controller/rest/v2/WorkflowController.java index 832622a156..5860e2425b 100644 --- a/src/main/java/org/craftercms/studio/controller/rest/v2/WorkflowController.java +++ b/src/main/java/org/craftercms/studio/controller/rest/v2/WorkflowController.java @@ -134,17 +134,6 @@ public Result updateItemStatesByQuery(@Valid @RequestBody UpdateItemStatesByQuer return result; } - @Deprecated - @GetMapping(value = AFFECTED_PATHS, produces = APPLICATION_JSON_VALUE) - public ResultList getWorkflowAffectedPaths(@ValidSiteId @RequestParam(REQUEST_PARAM_SITEID) String siteId, - @ValidExistingContentPath @RequestParam(REQUEST_PARAM_PATH) String path) { - // TODO: remove this once the UI switches to the new endpoint getWorkflowAffectedPackages - ResultList result = new ResultList<>(); - result.setEntities(RESULT_KEY_ITEMS, emptyList()); - result.setResponse(OK); - return result; - } - @GetMapping(value = PATH_PARAM_SITE + AFFECTED_PACKAGES, produces = APPLICATION_JSON_VALUE) public ResultList getWorkflowAffectedPackages(@ValidSiteId @PathVariable String site, @ValidExistingContentPath @RequestParam(REQUEST_PARAM_PATH) String path, @@ -179,11 +168,11 @@ public Result reject(@Valid @PathVariable @NotEmpty @ValidSiteId String site, @V return result; } - @PostMapping(PATH_PARAM_SITE + PACKAGE + PATH_PARAM_PACKAGE + CANCEL) - public Result cancel(@Valid @PathVariable @NotEmpty @ValidSiteId String site, @Valid @PathVariable @Positive long packageId, + @PostMapping(PATH_PARAM_SITE + CANCEL) + public Result cancel(@Valid @PathVariable @NotEmpty @ValidSiteId String site, @Valid @RequestBody ReviewPackageRequestBody cancelPackageRequest) throws ServiceLayerException, AuthenticationException { - workflowService.cancelPackage(site, packageId, cancelPackageRequest.getComment()); + workflowService.cancelPackages(site, cancelPackageRequest.getPackageIds(), cancelPackageRequest.getComment()); Result result = new Result(); result.setResponse(OK); return result; diff --git a/src/main/java/org/craftercms/studio/impl/v2/service/publish/PublishServiceImpl.java b/src/main/java/org/craftercms/studio/impl/v2/service/publish/PublishServiceImpl.java index 129bcebb53..41f33a4547 100644 --- a/src/main/java/org/craftercms/studio/impl/v2/service/publish/PublishServiceImpl.java +++ b/src/main/java/org/craftercms/studio/impl/v2/service/publish/PublishServiceImpl.java @@ -26,12 +26,12 @@ import org.craftercms.studio.api.v2.annotation.RequireSiteReady; import org.craftercms.studio.api.v2.annotation.SiteId; import org.craftercms.studio.api.v2.dal.publish.PublishItem; +import org.craftercms.studio.api.v2.dal.publish.PublishItemWithMetadata; import org.craftercms.studio.api.v2.dal.publish.PublishPackage; import org.craftercms.studio.api.v2.exception.publish.PublishPackageNotFoundException; import org.craftercms.studio.api.v2.security.HasAnyPermissions; import org.craftercms.studio.api.v2.service.publish.PublishService; import org.craftercms.studio.model.publish.PublishingTarget; -import org.craftercms.studio.model.rest.publish.PublishPackageDetails; import org.craftercms.studio.permissions.CompositePermission; import java.io.IOException; @@ -40,7 +40,6 @@ import java.util.List; import static org.craftercms.studio.permissions.StudioPermissionsConstants.*; -import static org.springframework.util.CollectionUtils.isEmpty; @RequireSiteReady public class PublishServiceImpl implements PublishService { @@ -73,14 +72,16 @@ public Collection getPublishPackages(@SiteId final String siteId @Override @RequireSiteExists @HasPermission(type = DefaultPermission.class, action = PERMISSION_GET_PUBLISHING_QUEUE) - public PublishPackageDetails getPublishPackageDetails(@SiteId String siteId, - long packageId) throws SiteNotFoundException, PublishPackageNotFoundException { - PublishPackageDetails packageDetails = publishServiceInternal.getPublishPackageDetails(siteId, packageId); - if (packageDetails == null) { - throw new PublishPackageNotFoundException(siteId, packageId); - } - - return packageDetails; + public Collection getPublishPackageItems(@SiteId String siteId, long packageId, + String path, Collection systemTypes, String internalName, + int offset, int limit) { + return publishServiceInternal.getPublishPackageItems(siteId, packageId, path, + systemTypes, internalName, offset, limit); + } + + @Override + public int getPublishPackageItemCount(String siteId, long packageId, String path, List systemType, String internalName) { + return publishServiceInternal.getPublishPackageItemCount(siteId, packageId, path, systemType, internalName); } @Override diff --git a/src/main/java/org/craftercms/studio/impl/v2/service/publish/internal/PublishServiceInternalImpl.java b/src/main/java/org/craftercms/studio/impl/v2/service/publish/internal/PublishServiceInternalImpl.java index 7e5f53c02b..3235d8d59b 100644 --- a/src/main/java/org/craftercms/studio/impl/v2/service/publish/internal/PublishServiceInternalImpl.java +++ b/src/main/java/org/craftercms/studio/impl/v2/service/publish/internal/PublishServiceInternalImpl.java @@ -44,7 +44,6 @@ import org.craftercms.studio.api.v2.service.security.internal.UserServiceInternal; import org.craftercms.studio.api.v2.service.site.SitesService; import org.craftercms.studio.model.publish.PublishingTarget; -import org.craftercms.studio.model.rest.publish.PublishPackageDetails; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -121,11 +120,15 @@ public Collection getPublishPackages(final String siteId, final } @Override - public PublishPackageDetails getPublishPackageDetails(String siteId, long packageId) - throws PublishPackageNotFoundException, SiteNotFoundException { - PublishPackage publishPackage = getPackage(siteId, packageId); - Collection publishItems = publishDao.getPublishItemsWithMetadata(siteId, packageId); - return new PublishPackageDetails(publishPackage, publishItems); + public Collection getPublishPackageItems(String siteId, long packageId, + String path, Collection systemTypes, String internalName, + int offset, int limit) { + return publishDao.getPublishItemsWithMetadata(siteId, packageId, path, systemTypes, internalName, offset, limit); + } + + @Override + public int getPublishPackageItemCount(String siteId, long packageId, String path, List systemType, String internalName) { + return publishDao.getMatchingPublishItemCount(siteId, packageId, path, systemType, internalName); } @Override @@ -692,6 +695,9 @@ protected Collection getPublishAllItems(final Site site) Collection unpublishedPaths = itemServiceInternal.getUnpublishedPaths(site.getId()).stream() .filter(path -> !contentRepository.isFolder(site.getSiteId(), path)) .toList(); + if (isEmpty(unpublishedPaths)) { + throw new InvalidParametersException("Failed to submit publish package: No items to publish"); + } Map statesByPath = itemServiceInternal.getItemStates(site.getSiteId(), unpublishedPaths); List publishItems = unpublishedPaths.stream() .map(path -> { @@ -699,9 +705,6 @@ protected Collection getPublishAllItems(final Site site) return createPublishItem(path, isNew(itemState) ? ADD : UPDATE, true); }) .toList(); - if (publishItems.isEmpty()) { - throw new InvalidParametersException("Failed to submit publish package: No items to publish"); - } return publishItems; } diff --git a/src/main/java/org/craftercms/studio/impl/v2/service/workflow/WorkflowServiceImpl.java b/src/main/java/org/craftercms/studio/impl/v2/service/workflow/WorkflowServiceImpl.java index 70b0027a7d..ec9cafdcde 100644 --- a/src/main/java/org/craftercms/studio/impl/v2/service/workflow/WorkflowServiceImpl.java +++ b/src/main/java/org/craftercms/studio/impl/v2/service/workflow/WorkflowServiceImpl.java @@ -30,6 +30,7 @@ import org.craftercms.studio.permissions.CompositePermission; import java.time.Instant; +import java.util.Collection; import java.util.List; import static org.craftercms.studio.permissions.CompositePermissionResolverImpl.PATH_LIST_RESOURCE_ID; @@ -98,7 +99,7 @@ public void rejectPackage(@SiteId String siteId, long packageId, String comment) @Override @RequireSiteExists @HasPermission(type = DefaultPermission.class, action = PERMISSION_CANCEL_PUBLISH) - public void cancelPackage(@SiteId String siteId, long packageId, String comment) throws ServiceLayerException, AuthenticationException { - workflowServiceInternal.cancelPackage(siteId, packageId, comment); + public void cancelPackages(@SiteId String siteId, Collection packageIds, String comment) throws ServiceLayerException, AuthenticationException { + workflowServiceInternal.cancelPackages(siteId, packageIds, comment); } } diff --git a/src/main/java/org/craftercms/studio/impl/v2/service/workflow/internal/WorkflowServiceInternalImpl.java b/src/main/java/org/craftercms/studio/impl/v2/service/workflow/internal/WorkflowServiceInternalImpl.java index 674e6dd494..2bfa28ccbc 100644 --- a/src/main/java/org/craftercms/studio/impl/v2/service/workflow/internal/WorkflowServiceInternalImpl.java +++ b/src/main/java/org/craftercms/studio/impl/v2/service/workflow/internal/WorkflowServiceInternalImpl.java @@ -46,6 +46,7 @@ import org.springframework.context.ApplicationEventPublisherAware; import java.time.Instant; +import java.util.Collection; import java.util.List; import static java.time.Instant.now; @@ -111,12 +112,14 @@ public void approvePackage(final String siteId, final long packageId, } @Override - public void cancelPackage(final String siteId, final long packageId, String comment) + public void cancelPackages(final String siteId, Collection packageIds, String comment) throws ServiceLayerException, AuthenticationException { - doReviewPackage(siteId, packageId, p -> { - p.setPackageState(CANCELLED.value); - p.setReviewerComment(comment); - }, OPERATION_CANCEL_PUBLISH_PACKAGE, WorkflowEvent.WorkFlowEventType.CANCEL); + for (Long packageId : packageIds) { + doReviewPackage(siteId, packageId, p -> { + p.setPackageState(CANCELLED.value); + p.setReviewerComment(comment); + }, OPERATION_CANCEL_PUBLISH_PACKAGE, WorkflowEvent.WorkFlowEventType.CANCEL); + } } @Override diff --git a/src/main/java/org/craftercms/studio/model/rest/publish/PublishPackageDetails.java b/src/main/java/org/craftercms/studio/model/rest/publish/PublishPackageDetails.java index 40abcb033d..12c9992910 100644 --- a/src/main/java/org/craftercms/studio/model/rest/publish/PublishPackageDetails.java +++ b/src/main/java/org/craftercms/studio/model/rest/publish/PublishPackageDetails.java @@ -16,30 +16,28 @@ package org.craftercms.studio.model.rest.publish; -import com.fasterxml.jackson.annotation.JsonUnwrapped; +import com.fasterxml.jackson.annotation.JsonProperty; import org.craftercms.studio.api.v2.dal.publish.PublishItemWithMetadata; import org.craftercms.studio.api.v2.dal.publish.PublishPackage; +import org.craftercms.studio.model.rest.PaginatedResultList; import java.util.Collection; +import static org.craftercms.studio.controller.rest.v2.ResultConstants.RESULT_KEY_ITEMS; + /** * Contains a {@link PublishPackage} general information and also its {@link PublishItemWithMetadata}s */ -public class PublishPackageDetails { +public class PublishPackageDetails extends PaginatedResultList { - private final Collection items; private final PublishPackage publishPackage; public PublishPackageDetails(final PublishPackage publishPackage, final Collection items) { this.publishPackage = publishPackage; - this.items = items; - } - - public Collection getItems() { - return items; + setEntities(RESULT_KEY_ITEMS, items); } - @JsonUnwrapped + @JsonProperty("package") public PublishPackage getPublishPackage() { return publishPackage; } diff --git a/src/main/java/org/craftercms/studio/model/rest/workflow/ReviewPackageRequestBody.java b/src/main/java/org/craftercms/studio/model/rest/workflow/ReviewPackageRequestBody.java index e1d9da7153..ed25c35a29 100644 --- a/src/main/java/org/craftercms/studio/model/rest/workflow/ReviewPackageRequestBody.java +++ b/src/main/java/org/craftercms/studio/model/rest/workflow/ReviewPackageRequestBody.java @@ -17,6 +17,9 @@ package org.craftercms.studio.model.rest.workflow; import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotEmpty; + +import java.util.List; /** * Request body for reviewing a package (reject, cancel, approve) @@ -25,6 +28,8 @@ public class ReviewPackageRequestBody { @NotBlank private String comment; + @NotEmpty + private List packageIds; public @NotBlank String getComment() { return comment; @@ -33,4 +38,12 @@ public class ReviewPackageRequestBody { public void setComment(@NotBlank String comment) { this.comment = comment; } + + public List getPackageIds() { + return packageIds; + } + + public void setPackageIds(List packageIds) { + this.packageIds = packageIds; + } } diff --git a/src/main/resources/org/craftercms/studio/api/v2/dal/DAOUtils.xml b/src/main/resources/org/craftercms/studio/api/v2/dal/DAOUtils.xml index ca1be95bc9..a4f2d50e57 100644 --- a/src/main/resources/org/craftercms/studio/api/v2/dal/DAOUtils.xml +++ b/src/main/resources/org/craftercms/studio/api/v2/dal/DAOUtils.xml @@ -27,4 +27,10 @@ + + + + LIMIT #{offset},#{limit} + + diff --git a/src/main/resources/org/craftercms/studio/api/v2/dal/publish/PublishDAO.xml b/src/main/resources/org/craftercms/studio/api/v2/dal/publish/PublishDAO.xml index 46634bf023..7384dfa183 100644 --- a/src/main/resources/org/craftercms/studio/api/v2/dal/publish/PublishDAO.xml +++ b/src/main/resources/org/craftercms/studio/api/v2/dal/publish/PublishDAO.xml @@ -38,19 +38,21 @@ select="org.craftercms.studio.api.v2.dal.publish.ItemTargetDAO.getByItemId"/> - + + + + + + + + + - + - - @@ -227,23 +229,48 @@ + + SELECT pi.*, ipi.item_id + , i.label as meta_label, i.system_type as meta_system_type, i.mime_type as meta_mime_type FROM publish_item pi INNER JOIN publish_package pp ON pi.package_id = pp.id INNER JOIN site s ON pp.site_id = s.id LEFT OUTER JOIN item_publish_item ipi ON pi.id = ipi.publish_item_id + + INNER JOIN item i ON ipi.item_id = i.id + WHERE pi.package_id = #{packageId} AND s.site_id = #{siteId} - - LIMIT #{offset},#{limit} + + + + AND i.path RLIKE #{path} + + + AND i.system_type IN #{systemType} + + + AND i.label RLIKE #{label} + @@ -328,9 +355,7 @@