Search in sources :

Example 11 with ItemMetadata

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

the class WorkflowServiceImpl method reject.

protected void reject(String site, List<DmDependencyTO> submittedItems, String reason, String approver) {
    if (submittedItems != null) {
        // and only submit the top level items to workflow
        for (DmDependencyTO dmDependencyTO : submittedItems) {
            DependencyRules rule = new DependencyRules(site);
            rule.setContentService(contentService);
            rule.setObjectStateService(objectStateService);
            rejectThisAndReferences(site, dmDependencyTO, rule, approver, reason);
            List<DmDependencyTO> children = dmDependencyTO.getChildren();
            if (children != null) {
                for (DmDependencyTO child : children) {
                    rejectThisAndReferences(site, child, rule, approver, reason);
                }
            }
        }
        if (!submittedItems.isEmpty()) {
            // for some reason ,  submittedItems.get(0).getSubmittedBy() returns empty and
            // metadata for the same value is also empty , using last modify to blame the rejection.
            final ItemMetadata metaData = objectMetadataManager.getProperties(site, submittedItems.get(0).getUri());
            // worst case, we need someone to blame.
            String whoToBlame = "admin";
            if (metaData != null && StringUtils.isNotBlank(metaData.getModifier())) {
                whoToBlame = metaData.getModifier();
            }
            notificationService.notifyContentRejection(site, whoToBlame, getDeploymentPaths(submittedItems), reason, approver, Locale.ENGLISH);
        }
    }
// TODO: send the reason to the user
}
Also used : DependencyRules(org.craftercms.studio.api.v1.service.dependency.DependencyRules) DmDependencyTO(org.craftercms.studio.api.v1.to.DmDependencyTO) ItemMetadata(org.craftercms.studio.api.v1.dal.ItemMetadata)

Example 12 with ItemMetadata

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

the class PublishServiceImpl method cancelPublishingPackages.

@Override
@HasPermission(type = DefaultPermission.class, action = ACTION_CANCEL_PUBLISH)
public void cancelPublishingPackages(@ProtectedResourceId(SITE_ID_RESOURCE_ID) String siteId, List<String> packageIds) throws SiteNotFoundException {
    if (!siteService.exists(siteId)) {
        throw new SiteNotFoundException(siteId);
    }
    publishServiceInternal.cancelPublishingPackages(siteId, packageIds);
    List<AuditLogParameter> auditLogParameters = new ArrayList<AuditLogParameter>();
    for (String pId : packageIds) {
        PublishingPackageDetails packageDetails = publishServiceInternal.getPublishingPackageDetails(siteId, pId);
        List<String> paths = new ArrayList<String>();
        for (PublishingPackageDetails.PublishingPackageItem item : packageDetails.getItems()) {
            paths.add(item.getPath());
            ItemMetadata itemMetadata = objectMetadataManager.getProperties(siteId, item.getPath());
            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);
            }
            AuditLogParameter auditLogParameter = new AuditLogParameter();
            auditLogParameter.setTargetId(siteId + ":" + item.getPath());
            auditLogParameter.setTargetType(TARGET_TYPE_CONTENT_ITEM);
            auditLogParameter.setTargetValue(item.getPath());
            auditLogParameters.add(auditLogParameter);
        }
        objectStateService.transitionBulk(siteId, paths, REJECT, NEW_UNPUBLISHED_UNLOCKED);
        createAuditLogEntry(siteId, auditLogParameters);
    }
}
Also used : ArrayList(java.util.ArrayList) AuditLogParameter(org.craftercms.studio.api.v2.dal.AuditLogParameter) PublishingPackageDetails(org.craftercms.studio.api.v2.dal.PublishingPackageDetails) SiteNotFoundException(org.craftercms.studio.api.v1.exception.SiteNotFoundException) ItemMetadata(org.craftercms.studio.api.v1.dal.ItemMetadata) HasPermission(org.craftercms.commons.security.permissions.annotations.HasPermission)

Example 13 with ItemMetadata

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

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

the class ContentServiceImpl method generateDeleteActivity.

protected void generateDeleteActivity(String site, String path, String approver) throws SiteNotFoundException {
    // TODO: SJ: activities. Fix in 3.1+ by introducing the audit service and refactoring accordingly
    if (StringUtils.isEmpty(approver)) {
        approver = securityService.getCurrentUser();
    }
    boolean exists = contentExists(site, path);
    if (exists) {
        ContentItemTO item = getContentItem(site, path, 0);
        ItemMetadata properties = objectMetadataManager.getProperties(site, path);
        String user = (properties != null && !StringUtils.isEmpty(properties.getSubmittedBy()) ? properties.getSubmittedBy() : approver);
        Map<String, String> extraInfo = new HashMap<String, String>();
        if (item.isFolder()) {
            extraInfo.put(DmConstants.KEY_CONTENT_TYPE, CONTENT_TYPE_FOLDER);
        } else {
            extraInfo.put(DmConstants.KEY_CONTENT_TYPE, getContentTypeClass(site, path));
        }
        logger.debug("[DELETE] posting delete activity on " + path + " by " + user + " in " + site);
        SiteFeed siteFeed = siteService.getSite(site);
        AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
        auditLog.setOperation(OPERATION_DELETE);
        auditLog.setSiteId(siteFeed.getId());
        auditLog.setActorId(user);
        auditLog.setPrimaryTargetId(site + ":" + path);
        auditLog.setPrimaryTargetType(TARGET_TYPE_CONTENT_ITEM);
        auditLog.setPrimaryTargetValue(path);
        auditLog.setPrimaryTargetSubtype(getContentTypeClass(site, path));
        auditServiceInternal.insertAuditLog(auditLog);
        // process content life cycle
        if (path.endsWith(DmConstants.XML_PATTERN)) {
            String contentType = item.getContentType();
            dmContentLifeCycleService.process(site, user, path, contentType, DmContentLifeCycleService.ContentLifeCycleOperation.DELETE, null);
        }
    }
}
Also used : ContentItemTO(org.craftercms.studio.api.v1.to.ContentItemTO) HashMap(java.util.HashMap) SiteFeed(org.craftercms.studio.api.v1.dal.SiteFeed) AuditLog(org.craftercms.studio.api.v2.dal.AuditLog) 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