Search in sources :

Example 31 with DmDependencyTO

use of org.craftercms.studio.api.v1.to.DmDependencyTO in project studio by craftercms.

the class WorkflowServiceImpl method goLivepackage.

protected void goLivepackage(String site, SubmitPackage submitpackage, DmDependencyTO dmDependencyTO, boolean isNotScheduled, SubmitPackage dependencyPackage, String approver, Set<String> rescheduledUris, Set<String> processedUris) {
    if (!processedUris.contains(dmDependencyTO.getUri())) {
        handleReferences(site, submitpackage, dmDependencyTO, isNotScheduled, dependencyPackage, approver, rescheduledUris, processedUris);
        List<DmDependencyTO> children = dmDependencyTO.getChildren();
        if (children != null) {
            for (DmDependencyTO child : children) {
                handleReferences(site, submitpackage, child, isNotScheduled, dependencyPackage, approver, rescheduledUris, processedUris);
                goLivepackage(site, submitpackage, child, isNotScheduled, dependencyPackage, approver, rescheduledUris, processedUris);
            }
        }
        processedUris.add(dmDependencyTO.getUri());
    }
}
Also used : DmDependencyTO(org.craftercms.studio.api.v1.to.DmDependencyTO)

Example 32 with DmDependencyTO

use of org.craftercms.studio.api.v1.to.DmDependencyTO 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 33 with DmDependencyTO

use of org.craftercms.studio.api.v1.to.DmDependencyTO in project studio by craftercms.

the class DependencyRules method applySubmitRule.

public Set<DmDependencyTO> applySubmitRule(DmDependencyTO submittedItem) {
    Set<DmDependencyTO> dependencies = new HashSet<DmDependencyTO>();
    if (submittedItem.getDocuments() != null) {
        for (DmDependencyTO document : submittedItem.getDocuments()) {
            if (objectStateService.isUpdatedOrNew(site, document.getUri())) {
                document.setNow(submittedItem.isNow());
                document.setScheduledDate(submittedItem.getScheduledDate());
                document.setSubmitted(true);
                dependencies.add(document);
            }
            Set<DmDependencyTO> dependencyTOSet = applySubmitRule(document);
            dependencies.addAll(dependencyTOSet);
        }
    }
    // get components
    if (submittedItem.getComponents() != null) {
        for (DmDependencyTO component : submittedItem.getComponents()) {
            if (objectStateService.isUpdatedOrNew(site, component.getUri())) {
                component.setNow(submittedItem.isNow());
                component.setScheduledDate(submittedItem.getScheduledDate());
                component.setSubmitted(true);
                dependencies.add(component);
            }
            Set<DmDependencyTO> dependencyTOSet = applySubmitRule(component);
            dependencies.addAll(dependencyTOSet);
        }
    }
    // get assets
    if (submittedItem.getAssets() != null) {
        for (DmDependencyTO asset : submittedItem.getAssets()) {
            if (objectStateService.isUpdatedOrNew(site, asset.getUri())) {
                dependencies.add(asset);
                asset.setNow(submittedItem.isNow());
                asset.setScheduledDate(submittedItem.getScheduledDate());
                asset.setSubmitted(true);
            }
            Set<DmDependencyTO> dependencyTOSet = applySubmitRule(asset);
            dependencies.addAll(dependencyTOSet);
        }
    }
    // get templates
    if (submittedItem.getRenderingTemplates() != null) {
        for (DmDependencyTO template : submittedItem.getRenderingTemplates()) {
            if (objectStateService.isUpdatedOrNew(site, template.getUri())) {
                dependencies.add(template);
                template.setNow(submittedItem.isNow());
                template.setScheduledDate(submittedItem.getScheduledDate());
                template.setSubmitted(true);
            }
            Set<DmDependencyTO> dependencyTOSet = applySubmitRule(template);
            dependencies.addAll(dependencyTOSet);
        }
    }
    // get level descriptors
    if (submittedItem.getLevelDescriptors() != null) {
        for (DmDependencyTO ld : submittedItem.getLevelDescriptors()) {
            if (objectStateService.isUpdatedOrNew(site, ld.getUri())) {
                dependencies.add(ld);
                ld.setNow(submittedItem.isNow());
                ld.setScheduledDate(submittedItem.getScheduledDate());
                ld.setSubmitted(true);
            }
            Set<DmDependencyTO> dependencyTOSet = applySubmitRule(ld);
            dependencies.addAll(dependencyTOSet);
        }
    }
    // get pages
    if (submittedItem.getPages() != null) {
        for (DmDependencyTO page : submittedItem.getPages()) {
            if (objectStateService.isNew(site, page.getUri())) {
                page.setNow(submittedItem.isNow());
                page.setScheduledDate(submittedItem.getScheduledDate());
                page.setSubmitted(true);
                dependencies.add(page);
            }
            Set<DmDependencyTO> childPages = applySubmitRule(page);
            dependencies.addAll(childPages);
        }
    }
    return dependencies;
}
Also used : DmDependencyTO(org.craftercms.studio.api.v1.to.DmDependencyTO) HashSet(java.util.HashSet)

Aggregations

DmDependencyTO (org.craftercms.studio.api.v1.to.DmDependencyTO)27 ArrayList (java.util.ArrayList)16 ZonedDateTime (java.time.ZonedDateTime)13 HashSet (java.util.HashSet)9 JSONObject (net.sf.json.JSONObject)8 ContentItemTO (org.craftercms.studio.api.v1.to.ContentItemTO)8 JSONException (net.sf.json.JSONException)7 ServiceLayerException (org.craftercms.studio.api.v1.exception.ServiceLayerException)7 JSONArray (net.sf.json.JSONArray)6 SimpleDateFormat (java.text.SimpleDateFormat)5 HashMap (java.util.HashMap)5 ResultTO (org.craftercms.studio.api.v1.to.ResultTO)5 ContentNotFoundException (org.craftercms.studio.api.v1.exception.ContentNotFoundException)4 DependencyRules (org.craftercms.studio.api.v1.service.dependency.DependencyRules)4 DeploymentException (org.craftercms.studio.api.v1.service.deployment.DeploymentException)4 List (java.util.List)3 SiteFeed (org.craftercms.studio.api.v1.dal.SiteFeed)3 MultiChannelPublishingContext (org.craftercms.studio.api.v1.service.workflow.context.MultiChannelPublishingContext)3 AuditLog (org.craftercms.studio.api.v2.dal.AuditLog)3 ValidateParams (org.craftercms.commons.validation.annotations.param.ValidateParams)2