diff --git a/src/main/java/org/craftercms/studio/api/v2/repository/GitContentRepository.java b/src/main/java/org/craftercms/studio/api/v2/repository/GitContentRepository.java index 33ec9b99f9..606eb605ab 100644 --- a/src/main/java/org/craftercms/studio/api/v2/repository/GitContentRepository.java +++ b/src/main/java/org/craftercms/studio/api/v2/repository/GitContentRepository.java @@ -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; @@ -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 validatePublishCommits(String siteId, Collection commitIds) throws IOException, ServiceLayerException; + SequencedCollection validatePublishCommits(String siteId, Collection commitIds) throws IOException, ServiceLayerException; /** * Update the target branch ref to point to the given commit id diff --git a/src/main/java/org/craftercms/studio/controller/rest/v2/ExceptionHandlers.java b/src/main/java/org/craftercms/studio/controller/rest/v2/ExceptionHandlers.java index a30301c2da..de5a60df6b 100644 --- a/src/main/java/org/craftercms/studio/controller/rest/v2/ExceptionHandlers.java +++ b/src/main/java/org/craftercms/studio/controller/rest/v2/ExceptionHandlers.java @@ -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; @@ -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; @@ -588,14 +588,13 @@ public Result handleException(HttpServletRequest request, ContentMoveInvalidLoca @ExceptionHandler(ContentInPublishQueueException.class) @ResponseStatus(HttpStatus.CONFLICT) - public ResultList handleException(HttpServletRequest request, ContentInPublishQueueException e) { + public ResultList handleException(HttpServletRequest request, ContentInPublishQueueException e) { ApiResponse response = new ApiResponse(ApiResponse.CONTENT_IN_PUBLISH_QUEUE); response.setMessage(e.getMessage()); handleExceptionInternal(request, e, response); - ResultList result = new ResultList<>(); + ResultList 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; } 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 db7bda5e22..832622a156 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 @@ -27,6 +27,7 @@ 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; @@ -34,7 +35,6 @@ 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.*; @@ -146,13 +146,11 @@ public ResultList getWorkflowAffectedPaths(@ValidSiteId @RequestPar } @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, - @RequestParam(value = REQUEST_PARAM_INCLUDE_CHILDREN, required = false) boolean includeChildren) { - Collection affectedPackages = emptyIfNull(publishService.getActivePackagesForItems(site, List.of(path), includeChildren)) - .stream() - .map(PublishPackageResponse::new).toList(); - ResultList result = new ResultList<>(); + public ResultList getWorkflowAffectedPackages(@ValidSiteId @PathVariable String site, + @ValidExistingContentPath @RequestParam(REQUEST_PARAM_PATH) String path, + @RequestParam(value = REQUEST_PARAM_INCLUDE_CHILDREN, required = false) boolean includeChildren) { + Collection affectedPackages = emptyIfNull(publishService.getActivePackagesForItems(site, List.of(path), includeChildren)); + ResultList result = new ResultList<>(); result.setEntities(RESULT_KEY_PACKAGES, affectedPackages); result.setResponse(OK); return result; diff --git a/src/main/java/org/craftercms/studio/impl/v2/repository/GitContentRepositoryImpl.java b/src/main/java/org/craftercms/studio/impl/v2/repository/GitContentRepositoryImpl.java index bfa5a303fa..2dc0dabd39 100644 --- a/src/main/java/org/craftercms/studio/impl/v2/repository/GitContentRepositoryImpl.java +++ b/src/main/java/org/craftercms/studio/impl/v2/repository/GitContentRepositoryImpl.java @@ -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; @@ -754,7 +753,11 @@ public boolean shallowContentExists(String site, String path) { } @Override - public List validatePublishCommits(final String siteId, final Collection commitIds) throws IOException, ServiceLayerException { + public SequencedCollection validatePublishCommits(final String siteId, final Collection commitIds) throws IOException, ServiceLayerException { + if (isEmpty(commitIds)) { + return emptyList(); + } + String repoLockKey = helper.getSandboxRepoLockKey(siteId); Repository repo = helper.getRepository(siteId, SANDBOX); generalLockService.lock(repoLockKey); diff --git a/src/main/java/org/craftercms/studio/impl/v2/repository/blob/BlobAwareContentRepository.java b/src/main/java/org/craftercms/studio/impl/v2/repository/blob/BlobAwareContentRepository.java index 4434433323..5e63131c2d 100644 --- a/src/main/java/org/craftercms/studio/impl/v2/repository/blob/BlobAwareContentRepository.java +++ b/src/main/java/org/craftercms/studio/impl/v2/repository/blob/BlobAwareContentRepository.java @@ -751,7 +751,7 @@ public List getIntroducedCommits(String site, String baseCommit, String } @Override - public List validatePublishCommits(final String siteId, final Collection commitIds) throws IOException, ServiceLayerException { + public SequencedCollection validatePublishCommits(final String siteId, final Collection commitIds) throws IOException, ServiceLayerException { return localRepositoryV2.validatePublishCommits(siteId, commitIds); } diff --git a/src/main/java/org/craftercms/studio/impl/v2/service/dependency/internal/DependencyServiceInternalImpl.java b/src/main/java/org/craftercms/studio/impl/v2/service/dependency/internal/DependencyServiceInternalImpl.java index 1195d1c109..1e722e1330 100644 --- a/src/main/java/org/craftercms/studio/impl/v2/service/dependency/internal/DependencyServiceInternalImpl.java +++ b/src/main/java/org/craftercms/studio/impl/v2/service/dependency/internal/DependencyServiceInternalImpl.java @@ -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; @@ -84,6 +86,9 @@ public Collection getSoftDependencies(String site, Set paths) { @LogExecutionTime public Collection getPublishingSoftDependencies(final String site, final Set paths) { logger.trace("Get all soft dependencies for site '{}' paths '{}'", site, paths); + if (isEmpty(paths)) { + return emptyList(); + } Set result = new HashSet<>(); List> deps = dependencyDao.getPublishingSoftDependenciesForList(site, paths, getItemSpecificDependenciesPatterns(), MODIFIED_MASK, NEW_MASK); @@ -109,6 +114,9 @@ protected List getItemSpecificDependenciesPatterns() { @Override @RequireSiteExists public Collection getHardDependencies(@SiteId String site, String publishingTarget, Collection paths) { + if (isEmpty(paths)) { + return emptyList(); + } boolean isLiveTarget = StringUtils.equals(servicesConfig.getLiveEnvironment(site), publishingTarget); return dependencyDao.getHardDependenciesForList(site, publishingTarget, paths, getItemSpecificDependenciesPatterns(), isLiveTarget); 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 252a6020b2..7e5f53c02b 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 @@ -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; @@ -158,7 +159,7 @@ public CalculatedPublishPackageResult calculatePublishPackage(final String siteI final Collection commitIds) throws ServiceLayerException, IOException { Site site = siteService.getSite(siteId); Set 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() ? @@ -345,7 +346,7 @@ private void createPublishItemsFromCommitIds(final Site site, final Collection sortedCommits = contentRepository.validatePublishCommits(site.getSiteId(), commitIds); + SequencedCollection sortedCommits = contentRepository.validatePublishCommits(site.getSiteId(), commitIds); publishItemsByPath.putAll( sortedCommits.stream() .map(commitId -> contentRepository.getOperationsFromFirstParentDiff(site.getSiteId(), commitId)) diff --git a/src/main/java/org/craftercms/studio/model/rest/dashboard/Activity.java b/src/main/java/org/craftercms/studio/model/rest/dashboard/Activity.java index f13dbab534..64959e61ca 100644 --- a/src/main/java/org/craftercms/studio/model/rest/dashboard/Activity.java +++ b/src/main/java/org/craftercms/studio/model/rest/dashboard/Activity.java @@ -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 @@ -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; @@ -34,7 +35,7 @@ public class Activity { protected Item item; @JsonProperty("package") - protected Package publishPackage; + protected PublishPackage publishPackage; public long getId() { return id; @@ -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; diff --git a/src/main/java/org/craftercms/studio/model/rest/publish/PublishPackageResponse.java b/src/main/java/org/craftercms/studio/model/rest/publish/PublishPackageResponse.java deleted file mode 100644 index af05193012..0000000000 --- a/src/main/java/org/craftercms/studio/model/rest/publish/PublishPackageResponse.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * 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 - * the Free Software Foundation. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package org.craftercms.studio.model.rest.publish; - -import org.craftercms.studio.api.v2.dal.publish.PublishPackage; -import org.craftercms.studio.model.rest.Person; - -import java.time.Instant; - -/** - * Contains {@link PublishPackage} general information to be returned by rest APIs - */ -public class PublishPackageResponse { - private final long id; - private final Instant submittedOn; - private final String submitterComment; - private final String target; - private final PublishPackage.ApprovalState approvalState; - private final long packageState; - private final Instant schedule; - private final Person submitter; - - public PublishPackageResponse(final PublishPackage publishPackage) { - this.approvalState = publishPackage.getApprovalState(); - this.id = publishPackage.getId(); - this.packageState = publishPackage.getPackageState(); - this.submittedOn = publishPackage.getSubmittedOn(); - this.submitterComment = publishPackage.getSubmitterComment(); - this.target = publishPackage.getTarget(); - this.schedule = publishPackage.getSchedule(); - this.submitter = publishPackage.getSubmitter(); - } - - @SuppressWarnings("unused") - public PublishPackage.ApprovalState getApprovalState() { - return approvalState; - } - - @SuppressWarnings("unused") - public long getId() { - return id; - } - - @SuppressWarnings("unused") - public long getPackageState() { - return packageState; - } - - @SuppressWarnings("unused") - public Instant getSubmittedOn() { - return submittedOn; - } - - @SuppressWarnings("unused") - public String getSubmitterComment() { - return submitterComment; - } - - @SuppressWarnings("unused") - public String getTarget() { - return target; - } - - @SuppressWarnings("unused") - public Instant getSchedule() { - return schedule; - } - - @SuppressWarnings("unused") - public Person getSubmitter() { - return submitter; - } -} diff --git a/src/main/resources/org/craftercms/studio/api/v2/dal/ActivityStreamDAO.xml b/src/main/resources/org/craftercms/studio/api/v2/dal/ActivityStreamDAO.xml index 1ffbef2d29..507d4b53ac 100644 --- a/src/main/resources/org/craftercms/studio/api/v2/dal/ActivityStreamDAO.xml +++ b/src/main/resources/org/craftercms/studio/api/v2/dal/ActivityStreamDAO.xml @@ -1,6 +1,6 @@