Skip to content

Commit

Permalink
Publisher APIs updates (#3674)
Browse files Browse the repository at this point in the history
* Tolerate missing params in calculate publishing package API

* Remove PublishPackageResponse and just return the packages

* Get publishPackage metadata in user activity API
  • Loading branch information
jmendeza authored Dec 11, 2024
1 parent 3359948 commit cba0da2
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 138 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@
import org.springframework.util.function.ThrowingConsumer;

import java.io.IOException;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.*;

import static org.eclipse.jgit.lib.Constants.HEAD;

Expand Down Expand Up @@ -234,7 +231,7 @@ void forAllSitePaths(String siteId,
* @throws IOException if there is any error reading the git log
* @throws ServiceLayerException if there is any commit ID that is not valid for publishing
*/
List<String> validatePublishCommits(String siteId, Collection<String> commitIds) throws IOException, ServiceLayerException;
SequencedCollection<String> validatePublishCommits(String siteId, Collection<String> commitIds) throws IOException, ServiceLayerException;

/**
* Update the target branch ref to point to the given commit id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.craftercms.studio.api.v1.exception.*;
import org.craftercms.studio.api.v1.exception.repository.*;
import org.craftercms.studio.api.v1.exception.security.*;
import org.craftercms.studio.api.v2.dal.publish.PublishPackage;
import org.craftercms.studio.api.v2.exception.*;
import org.craftercms.studio.api.v2.exception.configuration.InvalidConfigurationException;
import org.craftercms.studio.api.v2.exception.content.ContentExistException;
Expand All @@ -53,7 +54,6 @@
import org.craftercms.studio.model.rest.Result;
import org.craftercms.studio.model.rest.ResultList;
import org.craftercms.studio.model.rest.ResultOne;
import org.craftercms.studio.model.rest.publish.PublishPackageResponse;
import org.owasp.esapi.ESAPI;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -588,14 +588,13 @@ public Result handleException(HttpServletRequest request, ContentMoveInvalidLoca

@ExceptionHandler(ContentInPublishQueueException.class)
@ResponseStatus(HttpStatus.CONFLICT)
public ResultList<PublishPackageResponse> handleException(HttpServletRequest request, ContentInPublishQueueException e) {
public ResultList<PublishPackage> handleException(HttpServletRequest request, ContentInPublishQueueException e) {
ApiResponse response = new ApiResponse(ApiResponse.CONTENT_IN_PUBLISH_QUEUE);
response.setMessage(e.getMessage());
handleExceptionInternal(request, e, response);
ResultList<PublishPackageResponse> result = new ResultList<>();
ResultList<PublishPackage> result = new ResultList<>();
result.setResponse(response);
result.setEntities(RESULT_KEY_PUBLISH_PACKAGES,
e.getPublishPackages().stream().map(PublishPackageResponse::new).toList());
result.setEntities(RESULT_KEY_PUBLISH_PACKAGES, e.getPublishPackages());

return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@
import org.craftercms.studio.api.v1.exception.SiteNotFoundException;
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.publish.PublishPackage;
import org.craftercms.studio.api.v2.exception.InvalidParametersException;
import org.craftercms.studio.api.v2.service.publish.PublishService;
import org.craftercms.studio.api.v2.service.workflow.WorkflowService;
import org.craftercms.studio.model.rest.PaginatedResultList;
import org.craftercms.studio.model.rest.Result;
import org.craftercms.studio.model.rest.ResultList;
import org.craftercms.studio.model.rest.content.SandboxItem;
import org.craftercms.studio.model.rest.publish.PublishPackageResponse;
import org.craftercms.studio.model.rest.workflow.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
Expand Down Expand Up @@ -146,13 +146,11 @@ public ResultList<SandboxItem> getWorkflowAffectedPaths(@ValidSiteId @RequestPar
}

@GetMapping(value = PATH_PARAM_SITE + AFFECTED_PACKAGES, produces = APPLICATION_JSON_VALUE)
public ResultList<PublishPackageResponse> getWorkflowAffectedPackages(@ValidSiteId @PathVariable String site,
@ValidExistingContentPath @RequestParam(REQUEST_PARAM_PATH) String path,
@RequestParam(value = REQUEST_PARAM_INCLUDE_CHILDREN, required = false) boolean includeChildren) {
Collection<PublishPackageResponse> affectedPackages = emptyIfNull(publishService.getActivePackagesForItems(site, List.of(path), includeChildren))
.stream()
.map(PublishPackageResponse::new).toList();
ResultList<PublishPackageResponse> result = new ResultList<>();
public ResultList<PublishPackage> getWorkflowAffectedPackages(@ValidSiteId @PathVariable String site,
@ValidExistingContentPath @RequestParam(REQUEST_PARAM_PATH) String path,
@RequestParam(value = REQUEST_PARAM_INCLUDE_CHILDREN, required = false) boolean includeChildren) {
Collection<PublishPackage> affectedPackages = emptyIfNull(publishService.getActivePackagesForItems(site, List.of(path), includeChildren));
ResultList<PublishPackage> result = new ResultList<>();
result.setEntities(RESULT_KEY_PACKAGES, affectedPackages);
result.setResponse(OK);
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package org.craftercms.studio.impl.v2.repository;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -754,7 +753,11 @@ public boolean shallowContentExists(String site, String path) {
}

@Override
public List<String> validatePublishCommits(final String siteId, final Collection<String> commitIds) throws IOException, ServiceLayerException {
public SequencedCollection<String> validatePublishCommits(final String siteId, final Collection<String> commitIds) throws IOException, ServiceLayerException {
if (isEmpty(commitIds)) {
return emptyList();
}

String repoLockKey = helper.getSandboxRepoLockKey(siteId);
Repository repo = helper.getRepository(siteId, SANDBOX);
generalLockService.lock(repoLockKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ public List<String> getIntroducedCommits(String site, String baseCommit, String
}

@Override
public List<String> validatePublishCommits(final String siteId, final Collection<String> commitIds) throws IOException, ServiceLayerException {
public SequencedCollection<String> validatePublishCommits(final String siteId, final Collection<String> commitIds) throws IOException, ServiceLayerException {
return localRepositoryV2.validatePublishCommits(siteId, commitIds);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
import java.util.stream.Collectors;

import static java.lang.String.format;
import static java.util.Collections.emptyList;
import static org.apache.commons.collections4.CollectionUtils.isEmpty;
import static org.apache.commons.collections4.CollectionUtils.isNotEmpty;
import static org.craftercms.studio.api.v2.dal.DependencyDAO.TARGET_PATH_COLUMN_NAME;
import static org.craftercms.studio.api.v2.dal.ItemState.MODIFIED_MASK;
Expand Down Expand Up @@ -84,6 +86,9 @@ public Collection<String> getSoftDependencies(String site, Set<String> paths) {
@LogExecutionTime
public Collection<String> getPublishingSoftDependencies(final String site, final Set<String> paths) {
logger.trace("Get all soft dependencies for site '{}' paths '{}'", site, paths);
if (isEmpty(paths)) {
return emptyList();
}
Set<String> result = new HashSet<>();
List<Map<String, String>> deps = dependencyDao.getPublishingSoftDependenciesForList(site, paths, getItemSpecificDependenciesPatterns(),
MODIFIED_MASK, NEW_MASK);
Expand All @@ -109,6 +114,9 @@ protected List<String> getItemSpecificDependenciesPatterns() {
@Override
@RequireSiteExists
public Collection<String> getHardDependencies(@SiteId String site, String publishingTarget, Collection<String> paths) {
if (isEmpty(paths)) {
return emptyList();
}
boolean isLiveTarget = StringUtils.equals(servicesConfig.getLiveEnvironment(site), publishingTarget);
return dependencyDao.getHardDependenciesForList(site, publishingTarget, paths,
getItemSpecificDependenciesPatterns(), isLiveTarget);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import static java.lang.String.format;
import static java.util.Collections.emptyList;
import static java.util.stream.Collectors.*;
import static org.apache.commons.collections4.CollectionUtils.emptyIfNull;
import static org.apache.commons.collections4.CollectionUtils.union;
import static org.apache.commons.lang3.ArrayUtils.contains;
import static org.apache.commons.lang3.StringUtils.defaultIfEmpty;
Expand Down Expand Up @@ -158,7 +159,7 @@ public CalculatedPublishPackageResult calculatePublishPackage(final String siteI
final Collection<String> commitIds) throws ServiceLayerException, IOException {
Site site = siteService.getSite(siteId);
Set<String> corePackagePaths = new HashSet<>();
corePackagePaths.addAll(publishRequestPaths.stream()
corePackagePaths.addAll(emptyIfNull(publishRequestPaths).stream()
.collect(teeing(
flatMapping(requestPath -> expandPublishRequestPath(site, requestPath).stream(), toSet()),
flatMapping(requestPath -> (requestPath.includeSoftDeps() ?
Expand Down Expand Up @@ -345,7 +346,7 @@ private void createPublishItemsFromCommitIds(final Site site, final Collection<S
return;
}
// Validate and sort commits
List<String> sortedCommits = contentRepository.validatePublishCommits(site.getSiteId(), commitIds);
SequencedCollection<String> sortedCommits = contentRepository.validatePublishCommits(site.getSiteId(), commitIds);
publishItemsByPath.putAll(
sortedCommits.stream()
.map(commitId -> contentRepository.getOperationsFromFirstParentDiff(site.getSiteId(), commitId))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2007-2022 Crafter Software Corporation. All Rights Reserved.
* Copyright (C) 2007-2024 Crafter Software Corporation. All Rights Reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as published by
Expand All @@ -18,6 +18,7 @@

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.craftercms.studio.api.v2.dal.publish.PublishPackage;
import org.craftercms.studio.model.rest.Person;

import java.time.ZonedDateTime;
Expand All @@ -34,7 +35,7 @@ public class Activity {
protected Item item;

@JsonProperty("package")
protected Package publishPackage;
protected PublishPackage publishPackage;

public long getId() {
return id;
Expand Down Expand Up @@ -76,29 +77,14 @@ public void setItem(Item item) {
this.item = item;
}

public Package getPublishPackage() {
public PublishPackage getPublishPackage() {
return publishPackage;
}

public void setPublishPackage(Package publishPackage) {
public void setPublishPackage(PublishPackage publishPackage) {
this.publishPackage = publishPackage;
}

//TODO: Populate with metadata once Publish Packages are fully implemented
public static class Package {

protected String id;

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

}

public static class Item {

protected long id;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (C) 2007-2022 Crafter Software Corporation. All Rights Reserved.
~ Copyright (C) 2007-2024 Crafter Software Corporation. All Rights Reserved.
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License version 3 as published by
Expand All @@ -26,8 +26,8 @@
<association property="person" resultMap="org.craftercms.studio.api.v2.dal.UserDAO.PersonMap"/>
<association property="item" columnPrefix="item_" notNullColumn="id" autoMapping="true"
javaType="org.craftercms.studio.model.rest.dashboard.Activity$Item"/>
<association property="publishPackage" columnPrefix="package_" notNullColumn="id" autoMapping="true"
javaType="org.craftercms.studio.model.rest.dashboard.Activity$Package"/>
<association property="publishPackage" column="{packageId=package_id,siteId=site_id}"
select="org.craftercms.studio.api.v2.dal.publish.PublishDAO.getById"/>
</resultMap>

<insert id="insertActivity">
Expand Down Expand Up @@ -73,10 +73,9 @@
<include refid="activitiesForUsersFilters"/>
</select>

<!-- TODO: Fix the join once we have a real publish package table -->
<select id="getActivitiesForUsers" resultMap="ActivityMap" >
SELECT
a.id AS asid, a.action, a.action_timestamp, a.item_id, a.package_id, a.item_path as item_recordedPath,
a.id AS asid, a.site_id, a.action, a.action_timestamp, a.item_id, a.package_id, a.item_path as item_recordedPath,
a.item_label as item_recordedLabel,
u.username, u.first_name, u.last_name, u.avatar,
i.path as item_path, i.label as item_label, i.preview_url as item_previewUrl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.apache.commons.lang3.StringUtils
import org.craftercms.core.util.ExceptionUtils
import org.craftercms.studio.api.v2.exception.content.ContentInPublishQueueException
import org.craftercms.studio.model.rest.publish.PublishPackageResponse
import scripts.api.ContentServices
import org.craftercms.studio.api.v1.exception.ContentNotFoundException
import org.craftercms.commons.validation.ValidationException
Expand Down Expand Up @@ -71,7 +70,6 @@ try {
response.setStatus(409)
result.message = inQueueException.message
result.publishPackages = inQueueException.getPublishPackages()
.collect { new PublishPackageResponse(it) }
}
}
return result
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import org.craftercms.engine.exception.HttpStatusCodeException
import org.craftercms.studio.api.v1.exception.ServiceLayerException
import org.craftercms.studio.api.v2.exception.content.ContentExistException
import org.craftercms.studio.api.v2.exception.content.ContentInPublishQueueException
import org.craftercms.studio.model.rest.publish.PublishPackageResponse
import scripts.api.ContentServices

def result = [:]
Expand Down Expand Up @@ -173,7 +172,6 @@ if (JakartaServletFileUpload.isMultipartContent(request)) {
response.setStatus(409)
result.message = inQueueException.message
result.publishPackages = inQueueException.getPublishPackages()
.collect { new PublishPackageResponse(it) }
}
}
return result

0 comments on commit cba0da2

Please sign in to comment.