Search in sources :

Example 6 with ItemMetadata

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

the class DeploymentServiceImpl method createDeleteItems.

private List<PublishRequest> createDeleteItems(String site, String environment, List<String> paths, String approver, ZonedDateTime scheduledDate, String submissionComment) throws SiteNotFoundException {
    List<PublishRequest> newItems = new ArrayList<PublishRequest>(paths.size());
    String packageId = UUID.randomUUID().toString();
    for (String path : paths) {
        if (contentService.contentExists(site, path)) {
            ContentItemTO contentItem = contentService.getContentItem(site, path, 0);
            if (!contentItem.isFolder()) {
                PublishRequest item = new PublishRequest();
                ItemMetadata metadata = objectMetadataManager.getProperties(site, path);
                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(PublishRequest.Action.DELETE);
                if (metadata != null) {
                    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.setPackageId(packageId);
                item.setSubmissionComment(submissionComment);
                newItems.add(item);
                if (contentService.contentExists(site, path)) {
                    contentService.deleteContent(site, path, approver);
                    if (path.endsWith(FILE_SEPARATOR + DmConstants.INDEX_FILE)) {
                        deleteFolder(site, path.replace(FILE_SEPARATOR + DmConstants.INDEX_FILE, ""), approver);
                    }
                }
                String lastRepoCommitId = contentRepository.getRepoLastCommitId(site);
                if (StringUtils.isNotEmpty(lastRepoCommitId)) {
                    item.setCommitId(lastRepoCommitId);
                }
            } else {
                RepositoryItem[] children = contentRepository.getContentChildren(site, path);
                List<String> childPaths = new ArrayList<String>();
                for (RepositoryItem child : children) {
                    childPaths.add(child.path + FILE_SEPARATOR + child.name);
                }
                newItems.addAll(createDeleteItems(site, environment, childPaths, approver, scheduledDate, submissionComment));
                deleteFolder(site, path, approver);
            }
        }
    }
    return newItems;
}
Also used : RepositoryItem(org.craftercms.studio.api.v1.repository.RepositoryItem) ContentItemTO(org.craftercms.studio.api.v1.to.ContentItemTO) 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 ItemMetadata

use of org.craftercms.studio.api.v1.dal.ItemMetadata 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 8 with ItemMetadata

use of org.craftercms.studio.api.v1.dal.ItemMetadata 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 ItemMetadata

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

the class WorkflowServiceImpl method handleReferences.

protected void handleReferences(String site, SubmitPackage submitpackage, DmDependencyTO dmDependencyTO, boolean isNotScheduled, SubmitPackage dependencyPackage, String approver, Set<String> rescheduledUris, Set<String> processedUris) {
    if (!processedUris.contains(dmDependencyTO.getUri())) {
        ItemMetadata properties = objectMetadataManager.getProperties(site, dmDependencyTO.getUri());
        ZonedDateTime scheduledDate = null;
        if (properties != null) {
            scheduledDate = properties.getLaunchDate();
        }
        ItemState state = objectStateService.getObjectState(site, dmDependencyTO.getUri());
        if (state != null) {
            if (!State.isSubmitted(State.valueOf(state.getState())) && scheduledDate != null && scheduledDate.equals(dmDependencyTO.getScheduledDate())) {
                if (objectStateService.isScheduled(site, dmDependencyTO.getUri())) {
                    return;
                } else {
                    submitpackage.addToPackage(dmDependencyTO);
                }
            }
        }
        if (!dmDependencyTO.isReference()) {
            submitpackage.addToPackage(dmDependencyTO);
        }
        if (isRescheduleRequest(dmDependencyTO, site)) {
            rescheduledUris.add(dmDependencyTO.getUri());
        }
        processedUris.add(dmDependencyTO.getUri());
    }
}
Also used : ZonedDateTime(java.time.ZonedDateTime) ItemState(org.craftercms.studio.api.v1.dal.ItemState) ItemMetadata(org.craftercms.studio.api.v1.dal.ItemMetadata)

Example 10 with ItemMetadata

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

the class WorkflowServiceImpl method _cancelWorkflow.

protected void _cancelWorkflow(String site, String path) throws ServiceLayerException {
    List<String> allItemsToCancel = getWorkflowAffectedPathsInternal(site, path);
    List<String> paths = new ArrayList<String>();
    for (String affectedItem : allItemsToCancel) {
        try {
            deploymentService.cancelWorkflow(site, affectedItem);
            ItemMetadata itemMetadata = objectMetadataManager.getProperties(site, affectedItem);
            if (itemMetadata != null) {
                itemMetadata.setSubmittedBy(StringUtils.EMPTY);
                itemMetadata.setSendEmail(0);
                itemMetadata.setSubmittedForDeletion(0);
                itemMetadata.setSubmissionComment(StringUtils.EMPTY);
                itemMetadata.setLaunchDate(null);
                itemMetadata.setSubmittedToEnvironment(StringUtils.EMPTY);
                objectMetadataManager.updateObjectMetadata(itemMetadata);
            }
            paths.add(affectedItem);
        } catch (DeploymentException e) {
            logger.error("Error occurred while trying to cancel workflow for path [" + affectedItem + "], site " + site, e);
        }
    }
    objectStateService.transitionBulk(site, paths, org.craftercms.studio.api.v1.service.objectstate.TransitionEvent.REJECT, State.NEW_UNPUBLISHED_UNLOCKED);
}
Also used : ArrayList(java.util.ArrayList) DeploymentException(org.craftercms.studio.api.v1.service.deployment.DeploymentException) ItemMetadata(org.craftercms.studio.api.v1.dal.ItemMetadata)

Aggregations

ItemMetadata (org.craftercms.studio.api.v1.dal.ItemMetadata)14 ArrayList (java.util.ArrayList)7 ContentItemTO (org.craftercms.studio.api.v1.to.ContentItemTO)4 HashMap (java.util.HashMap)3 PublishRequest (org.craftercms.studio.api.v1.dal.PublishRequest)3 FastArrayList (org.apache.commons.collections.FastArrayList)2 SiteFeed (org.craftercms.studio.api.v1.dal.SiteFeed)2 RepositoryItem (org.craftercms.studio.api.v1.repository.RepositoryItem)2 DeploymentException (org.craftercms.studio.api.v1.service.deployment.DeploymentException)2 AuditLog (org.craftercms.studio.api.v2.dal.AuditLog)2 PublishingHistoryItem (org.craftercms.studio.api.v2.dal.PublishingHistoryItem)2 PublishingDashboardItem (org.craftercms.studio.model.rest.dashboard.PublishingDashboardItem)2 ZonedDateTime (java.time.ZonedDateTime)1 HasPermission (org.craftercms.commons.security.permissions.annotations.HasPermission)1 ItemState (org.craftercms.studio.api.v1.dal.ItemState)1 SiteNotFoundException (org.craftercms.studio.api.v1.exception.SiteNotFoundException)1 DependencyRules (org.craftercms.studio.api.v1.service.dependency.DependencyRules)1 DeploymentItemTO (org.craftercms.studio.api.v1.to.DeploymentItemTO)1 DmDependencyTO (org.craftercms.studio.api.v1.to.DmDependencyTO)1 AuditLogParameter (org.craftercms.studio.api.v2.dal.AuditLogParameter)1