Search in sources :

Example 16 with PublishRequest

use of org.craftercms.studio.api.v1.dal.PublishRequest in project studio by craftercms.

the class PublishingManagerImpl method markItemsCompleted.

@Override
@ValidateParams
public void markItemsCompleted(@ValidateStringParam(name = "site") String site, @ValidateStringParam(name = "environment") String environment, List<PublishRequest> processedItems) throws DeploymentException {
    ZonedDateTime completed = ZonedDateTime.now();
    for (PublishRequest item : processedItems) {
        item.setState(PublishRequest.State.COMPLETED);
        item.setCompletedDate(completed);
        retryingOperationFacade.markPublishRequestCompleted(item);
    }
}
Also used : ZonedDateTime(java.time.ZonedDateTime) PublishRequest(org.craftercms.studio.api.v1.dal.PublishRequest) ValidateParams(org.craftercms.commons.validation.annotations.param.ValidateParams)

Example 17 with PublishRequest

use of org.craftercms.studio.api.v1.dal.PublishRequest in project studio by craftercms.

the class PublishingManagerImpl method processItem.

@Override
public DeploymentItemTO processItem(PublishRequest item) throws DeploymentException, SiteNotFoundException {
    if (item == null) {
        throw new DeploymentException("Cannot process item, item is null.");
    }
    DeploymentItemTO deploymentItem = new DeploymentItemTO();
    deploymentItem.setSite(item.getSite());
    deploymentItem.setPath(item.getPath());
    deploymentItem.setCommitId(item.getCommitId());
    deploymentItem.setPackageId(item.getPackageId());
    String site = item.getSite();
    String path = item.getPath();
    String oldPath = item.getOldPath();
    String environment = item.getEnvironment();
    String action = item.getAction();
    String user = item.getUser();
    String liveEnvironment = LIVE_ENVIRONMENT;
    if (servicesConfig.isStagingEnvironmentEnabled(site)) {
        liveEnvironment = servicesConfig.getLiveEnvironment(site);
    }
    boolean isLive = false;
    if (StringUtils.isNotEmpty(liveEnvironment)) {
        if (liveEnvironment.equals(environment)) {
            isLive = true;
        }
    } else if (StringUtils.equalsIgnoreCase(LIVE_ENVIRONMENT, item.getEnvironment()) || StringUtils.equalsIgnoreCase(PRODUCTION_ENVIRONMENT, environment)) {
        isLive = true;
    }
    if (StringUtils.equals(action, PublishRequest.Action.DELETE)) {
        if (oldPath != null && oldPath.length() > 0) {
            contentService.deleteContent(site, oldPath, user);
            boolean hasRenamedChildren = false;
            if (oldPath.endsWith(FILE_SEPARATOR + DmConstants.INDEX_FILE)) {
                if (contentService.contentExists(site, oldPath.replace(FILE_SEPARATOR + DmConstants.INDEX_FILE, ""))) {
                    // TODO: SJ: This bypasses the Content Service, fix
                    RepositoryItem[] children = contentRepository.getContentChildren(site, oldPath.replace(FILE_SEPARATOR + DmConstants.INDEX_FILE, ""));
                    if (children.length > 1) {
                        hasRenamedChildren = true;
                    }
                }
                if (!hasRenamedChildren) {
                    deleteFolder(site, oldPath.replace(FILE_SEPARATOR + DmConstants.INDEX_FILE, ""), user);
                }
            }
            deploymentItem.setMove(true);
            deploymentItem.setOldPath(oldPath);
            objectMetadataManager.clearRenamed(site, path);
        }
        boolean haschildren = false;
        if (item.getPath().endsWith(FILE_SEPARATOR + DmConstants.INDEX_FILE)) {
            if (contentService.contentExists(site, path.replace(FILE_SEPARATOR + DmConstants.INDEX_FILE, ""))) {
                // TODO: SJ: This bypasses the Content Service, fix
                RepositoryItem[] children = contentRepository.getContentChildren(site, path.replace(FILE_SEPARATOR + DmConstants.INDEX_FILE, ""));
                if (children.length > 1) {
                    haschildren = true;
                }
            }
        }
        if (contentService.contentExists(site, path)) {
            contentService.deleteContent(site, path, user);
            if (!haschildren) {
                deleteFolder(site, path.replace(FILE_SEPARATOR + DmConstants.INDEX_FILE, ""), user);
            }
        }
        deploymentItem.setDelete(true);
    } else {
        if (StringUtils.equals(action, PublishRequest.Action.MOVE)) {
            deploymentItem.setMove(true);
            deploymentItem.setOldPath(oldPath);
            if (oldPath != null && oldPath.length() > 0) {
                if (isLive) {
                    objectMetadataManager.clearRenamed(site, path);
                }
            }
        }
        ItemMetadata itemMetadata = objectMetadataManager.getProperties(site, path);
        if (itemMetadata == null) {
            if (contentService.contentExists(site, path)) {
                LOGGER.warn("Content item: '" + site + "':'" + path + "' doesn't exists in " + "the database, but does exist in git. This may cause problems " + "in the environment: '" + environment + "'");
            } else {
                LOGGER.warn("Content item: '" + site + "':'" + path + "' cannot be published. " + "Content does not exist in git nor in the database. Skipping...");
                return null;
            }
        } else {
            ContentItemTO contentItem = contentService.getContentItem(site, path);
            if (isLive) {
                // should consider what should be done if this does not work.
                // Currently the method will bail and the item is stuck in processing.
                LOGGER.debug("Environment is live, transition item to LIVE state {0}:{1}", site, path);
                // check if commit id from workflow and from object state match
                if (Objects.isNull(itemMetadata.getCommitId()) || itemMetadata.getCommitId().equals(item.getCommitId())) {
                    objectStateService.transition(site, contentItem, TransitionEvent.DEPLOYMENT);
                }
            } else {
                objectStateService.transition(site, contentItem, TransitionEvent.SAVE);
            }
            itemMetadata.setSubmittedBy(StringUtils.EMPTY);
            itemMetadata.setSendEmail(0);
            itemMetadata.setSubmittedForDeletion(0);
            itemMetadata.setSubmissionComment(StringUtils.EMPTY);
            itemMetadata.setSubmittedToEnvironment(StringUtils.EMPTY);
            itemMetadata.setLaunchDate(null);
            objectMetadataManager.updateObjectMetadata(itemMetadata);
        }
        String blacklistConfig = studioConfiguration.getProperty(CONFIGURATION_PUBLISHING_BLACKLIST_REGEX);
        if (StringUtils.isNotEmpty(blacklistConfig) && ContentUtils.matchesPatterns(item.getPath(), Arrays.asList(StringUtils.split(blacklistConfig, ",")))) {
            LOGGER.debug("File " + item.getPath() + " of the site " + site + " will not be published because it " + "matches the configured publishing blacklist regex patterns.");
            markItemsCompleted(site, item.getEnvironment(), Arrays.asList(item));
            deploymentItem = null;
        }
    }
    return deploymentItem;
}
Also used : RepositoryItem(org.craftercms.studio.api.v1.repository.RepositoryItem) ContentItemTO(org.craftercms.studio.api.v1.to.ContentItemTO) DeploymentItemTO(org.craftercms.studio.api.v1.to.DeploymentItemTO) DeploymentException(org.craftercms.studio.api.v1.service.deployment.DeploymentException) ItemMetadata(org.craftercms.studio.api.v1.dal.ItemMetadata)

Example 18 with PublishRequest

use of org.craftercms.studio.api.v1.dal.PublishRequest in project studio by craftercms.

the class PublishingManagerImpl method markItemsBlocked.

@RetryingOperation
@Override
@ValidateParams
public void markItemsBlocked(@ValidateStringParam(name = "site") String site, @ValidateStringParam(name = "environment") String environment, List<PublishRequest> copyToEnvironmentItems) throws DeploymentException {
    for (PublishRequest item : copyToEnvironmentItems) {
        item.setState(PublishRequest.State.BLOCKED);
        publishRequestMapper.updateItemDeploymentState(item);
    }
}
Also used : PublishRequest(org.craftercms.studio.api.v1.dal.PublishRequest) RetryingOperation(org.craftercms.studio.api.v2.annotation.RetryingOperation) ValidateParams(org.craftercms.commons.validation.annotations.param.ValidateParams)

Aggregations

PublishRequest (org.craftercms.studio.api.v1.dal.PublishRequest)14 ArrayList (java.util.ArrayList)10 ValidateParams (org.craftercms.commons.validation.annotations.param.ValidateParams)8 SiteNotFoundException (org.craftercms.studio.api.v1.exception.SiteNotFoundException)5 FastArrayList (org.apache.commons.collections.FastArrayList)4 ItemMetadata (org.craftercms.studio.api.v1.dal.ItemMetadata)4 DeploymentException (org.craftercms.studio.api.v1.service.deployment.DeploymentException)4 DeploymentItemTO (org.craftercms.studio.api.v1.to.DeploymentItemTO)4 HashMap (java.util.HashMap)3 ServiceLayerException (org.craftercms.studio.api.v1.exception.ServiceLayerException)3 RetryingOperation (org.craftercms.studio.api.v2.annotation.RetryingOperation)3 HashSet (java.util.HashSet)2 CommitNotFoundException (org.craftercms.studio.api.v1.exception.CommitNotFoundException)2 EnvironmentNotFoundException (org.craftercms.studio.api.v1.exception.EnvironmentNotFoundException)2 RepositoryItem (org.craftercms.studio.api.v1.repository.RepositoryItem)2 ContentItemTO (org.craftercms.studio.api.v1.to.ContentItemTO)2 PublishRequest (org.craftercms.studio.api.v2.dal.PublishRequest)2 UncategorizedSQLException (org.springframework.jdbc.UncategorizedSQLException)2 SimpleDateFormat (java.text.SimpleDateFormat)1 ZonedDateTime (java.time.ZonedDateTime)1