Search in sources :

Example 6 with PublishRequest

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

the class DeploymentServiceImpl method createItems.

private List<PublishRequest> createItems(String site, String environment, Map<String, List<String>> paths, ZonedDateTime scheduledDate, String approver, String submissionComment) {
    List<PublishRequest> newItems = new ArrayList<PublishRequest>();
    String packageId = UUID.randomUUID().toString();
    Map<String, Object> params = null;
    for (String action : paths.keySet()) {
        for (String path : paths.get(action)) {
            PublishRequest item = new PublishRequest();
            ItemMetadata metadata = objectMetadataManager.getProperties(site, path);
            if (metadata != null) {
                params = new HashMap<String, Object>();
                params.put("site_id", site);
                params.put("environment", environment);
                params.put("state", PublishRequest.State.READY_FOR_LIVE);
                params.put("path", path);
                params.put("commitId", metadata.getCommitId());
                if (publishRequestMapper.checkItemQueued(params) > 0) {
                    logger.info("Path " + path + " with commit ID " + metadata.getCommitId() + " already has queued publishing request for environment " + environment + " of site " + site + ". Adding another publishing request is skipped.");
                } else {
                    item.setId(++CTED_AUTOINCREMENT);
                    item.setSite(site);
                    item.setEnvironment(environment);
                    item.setPath(path);
                    item.setScheduledDate(scheduledDate);
                    item.setState(PublishRequest.State.READY_FOR_LIVE);
                    item.setAction(action);
                    if (metadata.getRenamed() > 0) {
                        String oldPath = metadata.getOldUrl();
                        item.setOldPath(oldPath);
                    }
                    String commitId = metadata.getCommitId();
                    if (StringUtils.isNotEmpty(commitId) && contentRepositoryV2.commitIdExists(site, commitId)) {
                        item.setCommitId(commitId);
                    } else {
                        if (StringUtils.isNotEmpty(commitId)) {
                            logger.warn("Commit ID is NULL for content " + path + ". Was the git repo reset at some point?");
                        } else {
                            logger.warn("Commit ID " + commitId + " does not exist for content " + path + ". Was the git repo reset at some point?");
                        }
                        logger.info("Publishing content from HEAD for " + path);
                        item.setCommitId(contentRepository.getRepoLastCommitId(site));
                    }
                    String contentTypeClass = contentService.getContentTypeClass(site, path);
                    item.setContentTypeClass(contentTypeClass);
                    item.setUser(approver);
                    item.setSubmissionComment(submissionComment);
                    item.setPackageId(packageId);
                    newItems.add(item);
                }
                if (scheduledDate != null && scheduledDate.isAfter(ZonedDateTime.now(ZoneOffset.UTC))) {
                    Map<String, Object> properties = new HashMap<>();
                    properties.put(ItemMetadata.PROP_SUBMISSION_COMMENT, submissionComment);
                    properties.put(ItemMetadata.PROP_SUBMITTED_TO_ENVIRONMENT, environment);
                    properties.put(ItemMetadata.PROP_LAUNCH_DATE, scheduledDate);
                    objectMetadataManager.setObjectMetadata(site, path, properties);
                }
            }
        }
    }
    return newItems;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FastArrayList(org.apache.commons.collections.FastArrayList) PublishRequest(org.craftercms.studio.api.v1.dal.PublishRequest) ItemMetadata(org.craftercms.studio.api.v1.dal.ItemMetadata)

Example 7 with PublishRequest

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

the class PublishingManagerImpl method processMandatoryDependencies.

@Override
public List<DeploymentItemTO> processMandatoryDependencies(PublishRequest item, Set<String> pathsToDeploy, Set<String> missingDependenciesPaths) throws DeploymentException, ServiceLayerException {
    List<DeploymentItemTO> mandatoryDependencies = new ArrayList<DeploymentItemTO>();
    String site = item.getSite();
    String path = item.getPath();
    if (StringUtils.equals(item.getAction(), PublishRequest.Action.NEW) || StringUtils.equals(item.getAction(), PublishRequest.Action.MOVE)) {
        if (ContentUtils.matchesPatterns(path, servicesConfig.getPagePatterns(site))) {
            String helpPath = path.replace(FILE_SEPARATOR + getIndexFile(), "");
            int idx = helpPath.lastIndexOf(FILE_SEPARATOR);
            String parentPath = helpPath.substring(0, idx) + FILE_SEPARATOR + getIndexFile();
            if (objectStateService.isNew(site, parentPath) || objectMetadataManager.isRenamed(site, parentPath)) {
                if (!missingDependenciesPaths.contains(parentPath) && !pathsToDeploy.contains(parentPath)) {
                    deploymentService.cancelWorkflow(site, parentPath);
                    missingDependenciesPaths.add(parentPath);
                    PublishRequest parentItem = createMissingItem(site, parentPath, item);
                    DeploymentItemTO parentDeploymentItem = processItem(parentItem);
                    mandatoryDependencies.add(parentDeploymentItem);
                    mandatoryDependencies.addAll(processMandatoryDependencies(parentItem, pathsToDeploy, missingDependenciesPaths));
                }
            }
        }
        if (!isEnablePublishingWithoutDependencies()) {
            List<String> dependentPaths = dependencyService.getPublishingDependencies(site, path);
            for (String dependentPath : dependentPaths) {
                // TODO: SJ: This bypasses the Content Service, fix
                if (objectStateService.isNew(site, dependentPath) || objectMetadataManager.isRenamed(site, dependentPath)) {
                    if (!missingDependenciesPaths.contains(dependentPath) && !pathsToDeploy.contains(dependentPath)) {
                        deploymentService.cancelWorkflow(site, dependentPath);
                        missingDependenciesPaths.add(dependentPath);
                        PublishRequest dependentItem = createMissingItem(site, dependentPath, item);
                        DeploymentItemTO dependentDeploymentItem = processItem(dependentItem);
                        if (Objects.nonNull(dependentDeploymentItem)) {
                            mandatoryDependencies.add(dependentDeploymentItem);
                        }
                        mandatoryDependencies.addAll(processMandatoryDependencies(dependentItem, pathsToDeploy, missingDependenciesPaths));
                    }
                }
            }
        }
    }
    return mandatoryDependencies;
}
Also used : DeploymentItemTO(org.craftercms.studio.api.v1.to.DeploymentItemTO) ArrayList(java.util.ArrayList) PublishRequest(org.craftercms.studio.api.v1.dal.PublishRequest)

Example 8 with PublishRequest

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

the class PublishingManagerImpl method createMissingItem.

private PublishRequest createMissingItem(String site, String itemPath, PublishRequest item) {
    PublishRequest missingItem = new PublishRequest();
    missingItem.setSite(site);
    missingItem.setEnvironment(item.getEnvironment());
    missingItem.setPath(itemPath);
    missingItem.setScheduledDate(item.getScheduledDate());
    missingItem.setState(item.getState());
    if (objectStateService.isNew(site, itemPath)) {
        missingItem.setAction(PublishRequest.Action.NEW);
    }
    ItemMetadata metadata = objectMetadataManager.getProperties(site, itemPath);
    if (metadata != null) {
        if (metadata.getRenamed() != 0) {
            String oldPath = metadata.getOldUrl();
            missingItem.setOldPath(oldPath);
            missingItem.setAction(PublishRequest.Action.MOVE);
        }
        String commitId = metadata.getCommitId();
        if (StringUtils.isNotEmpty(commitId)) {
            missingItem.setCommitId(commitId);
        } else {
            missingItem.setCommitId(contentRepository.getRepoLastCommitId(site));
        }
    }
    String contentTypeClass = contentService.getContentTypeClass(site, itemPath);
    missingItem.setContentTypeClass(contentTypeClass);
    missingItem.setUser(item.getUser());
    missingItem.setSubmissionComment(item.getSubmissionComment());
    missingItem.setPackageId(item.getPackageId());
    return missingItem;
}
Also used : PublishRequest(org.craftercms.studio.api.v1.dal.PublishRequest) ItemMetadata(org.craftercms.studio.api.v1.dal.ItemMetadata)

Example 9 with PublishRequest

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

the class PublishingManagerImpl method getPublishingStatus.

@Override
@ValidateParams
public String getPublishingStatus(@ValidateStringParam(name = "site") String site) {
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("site", site);
    params.put("now", ZonedDateTime.now(ZoneOffset.UTC));
    List<String> states = new ArrayList<String>() {

        {
            add(READY_FOR_LIVE);
            add(PublishRequest.State.BLOCKED);
            add(PublishRequest.State.PROCESSING);
        }
    };
    params.put("states", states);
    PublishRequest result = publishRequestMapper.checkPublishingStatus(params);
    return result.getState();
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PublishRequest(org.craftercms.studio.api.v1.dal.PublishRequest) ValidateParams(org.craftercms.commons.validation.annotations.param.ValidateParams)

Example 10 with PublishRequest

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

the class PublishServiceInternalImpl method getDeploymentHistory.

@Override
public List<DeploymentHistoryItem> getDeploymentHistory(String siteId, List<String> environments, ZonedDateTime fromDate, ZonedDateTime toDate, String filterType, int numberOfItems) {
    int offset = 0;
    int counter = 0;
    List<DeploymentHistoryItem> toRet = new ArrayList<DeploymentHistoryItem>();
    String contentTypeClass = null;
    switch(filterType) {
        case CONTENT_TYPE_PAGE:
        case CONTENT_TYPE_COMPONENT:
        case CONTENT_TYPE_ASSET:
            contentTypeClass = filterType;
            break;
        default:
            contentTypeClass = null;
            break;
    }
    List<PublishRequest> deploymentHistory = publishRequestDao.getDeploymentHistory(siteId, environments, COMPLETED, contentTypeClass, fromDate, toDate, offset, numberOfItems);
    if (CollectionUtils.isNotEmpty(deploymentHistory)) {
        for (PublishRequest publishRequest : deploymentHistory) {
            DeploymentHistoryItem dhi = new DeploymentHistoryItem();
            dhi.setSite(siteId);
            dhi.setPath(publishRequest.getPath());
            dhi.setDeploymentDate(publishRequest.getCompletedDate());
            dhi.setUser(publishRequest.getUser());
            dhi.setEnvironment(publishRequest.getEnvironment());
            toRet.add(dhi);
            if (!(++counter < numberOfItems)) {
                break;
            }
        }
    }
    toRet.sort((o1, o2) -> o2.getDeploymentDate().compareTo(o1.getDeploymentDate()));
    return toRet;
}
Also used : DeploymentHistoryItem(org.craftercms.studio.api.v2.dal.DeploymentHistoryItem) ArrayList(java.util.ArrayList) PublishRequest(org.craftercms.studio.api.v2.dal.PublishRequest)

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