Skip to content

Commit

Permalink
Publish API updates (#3675)
Browse files Browse the repository at this point in the history
* Bulk cancel publish package API

* Get package API to paginate and filter the items.

* Remove unused workflow affected_paths API
  • Loading branch information
jmendeza authored Dec 17, 2024
1 parent b8114fa commit 1425de2
Show file tree
Hide file tree
Showing 16 changed files with 222 additions and 130 deletions.
36 changes: 24 additions & 12 deletions src/main/api/studio-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,29 +342,36 @@ default Collection<PublishItem> getPublishItems(final String siteId, final long
Collection<PublishItem> 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<PublishItemWithMetadata> 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<PublishItemWithMetadata> getPublishItemsWithMetadata(@Param(SITE_ID) String siteId, @Param(PACKAGE_ID) long packageId,
@Param(PATH) String path, @Param(SYSTEM_TYPES) Collection<String> 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<String> systemTypes,
@Param(LABEL) String label);

/**
* Update the state for all publish items in the package
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -85,14 +86,32 @@ Collection<PublishPackage> 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<PublishItemWithMetadata> getPublishPackageItems(String siteId, long packageId,
String path, Collection<String> 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<String> systemType, String internalName);

/**
* Get available publishing targets for given site
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<Long> packageIds, String comment)
throws ServiceLayerException, AuthenticationException;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -75,24 +78,24 @@ public PublishController(final PublishService publishService, final SitesService

@GetMapping(PATH_PARAM_SITE + PACKAGES)
public PaginatedResultList<PublishPackage> 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<PublishPackage.ApprovalState> 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<PublishPackage.ApprovalState> 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<PublishPackage> packages = new ArrayList<>();
Expand All @@ -110,13 +113,26 @@ public PaginatedResultList<PublishPackage> getPublishPackages(@ValidSiteId @Path
}

@GetMapping(PATH_PARAM_SITE + PACKAGE + PATH_PARAM_PACKAGE)
public ResultOne<PublishPackageDetails> 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<String> 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<PublishPackageDetails> result = new ResultOne<>();
result.setEntity(RESULT_KEY_PACKAGE, publishPackageDetails);
PublishPackage publishPackage = publishService.getPackage(site, packageId);
Collection<PublishItemWithMetadata> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,6 @@ public Result updateItemStatesByQuery(@Valid @RequestBody UpdateItemStatesByQuer
return result;
}

@Deprecated
@GetMapping(value = AFFECTED_PATHS, produces = APPLICATION_JSON_VALUE)
public ResultList<SandboxItem> 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<SandboxItem> 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<PublishPackage> getWorkflowAffectedPackages(@ValidSiteId @PathVariable String site,
@ValidExistingContentPath @RequestParam(REQUEST_PARAM_PATH) String path,
Expand Down Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 1425de2

Please sign in to comment.