Search in sources :

Example 21 with DmDependencyTO

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

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

the class WorkflowServiceImpl method getRefAndChildOfDiffDateFromParent_new.

protected List<DmDependencyTO> getRefAndChildOfDiffDateFromParent_new(String site, List<DmDependencyTO> submittedItems, boolean removeInPages) {
    List<DmDependencyTO> childAndReferences = new ArrayList<>();
    for (DmDependencyTO submittedItem : submittedItems) {
        List<DmDependencyTO> children = submittedItem.getChildren();
        ZonedDateTime date = submittedItem.getScheduledDate();
        if (children != null) {
            Iterator<DmDependencyTO> childItr = children.iterator();
            while (childItr.hasNext()) {
                DmDependencyTO child = childItr.next();
                ZonedDateTime pageDate = child.getScheduledDate();
                if ((date == null && pageDate != null) || (date != null && !date.equals(pageDate))) {
                    if (!submittedItem.isNow()) {
                        child.setNow(false);
                        if (date != null && (pageDate != null && pageDate.isBefore(date))) {
                            child.setScheduledDate(date);
                        }
                    }
                    childAndReferences.add(child);
                    List<DmDependencyTO> childDeps = child.flattenChildren();
                    for (DmDependencyTO childDep : childDeps) {
                        if (objectStateService.isUpdatedOrNew(site, childDep.getUri())) {
                            childAndReferences.add(childDep);
                        }
                    }
                    child.setReference(false);
                    childItr.remove();
                    if (removeInPages) {
                        String uri = child.getUri();
                        List<DmDependencyTO> pages = submittedItem.getPages();
                        if (pages != null) {
                            Iterator<DmDependencyTO> pagesIter = pages.iterator();
                            while (pagesIter.hasNext()) {
                                DmDependencyTO page = pagesIter.next();
                                if (page.getUri().equals(uri)) {
                                    pagesIter.remove();
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return childAndReferences;
}
Also used : ZonedDateTime(java.time.ZonedDateTime) ArrayList(java.util.ArrayList) DmDependencyTO(org.craftercms.studio.api.v1.to.DmDependencyTO)

Example 23 with DmDependencyTO

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

the class WorkflowServiceImpl method addDependenciesForSubmittedItems.

protected List<DmDependencyTO> addDependenciesForSubmittedItems(String site, List<DmDependencyTO> submittedItems, SimpleDateFormat format, String globalScheduledDate) throws ServiceLayerException {
    List<DmDependencyTO> dependencies = new ArrayList<DmDependencyTO>();
    Set<String> dependenciesPaths = new HashSet<String>();
    for (DmDependencyTO submittedItem : submittedItems) {
        if (!dependenciesPaths.contains(submittedItem.getUri())) {
            dependenciesPaths.addAll(dependencyService.getPublishingDependencies(site, submittedItem.getUri()));
        }
    }
    for (String depPath : dependenciesPaths) {
        dependencies.add(getSubmittedItem_new(site, depPath, format, globalScheduledDate));
    }
    return dependencies;
}
Also used : ArrayList(java.util.ArrayList) DmDependencyTO(org.craftercms.studio.api.v1.to.DmDependencyTO) HashSet(java.util.HashSet)

Example 24 with DmDependencyTO

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

the class WorkflowServiceImpl method resolveSubmittedPaths.

protected void resolveSubmittedPaths(String site, DmDependencyTO item, List<String> submittedPaths, Set<String> processedPaths) throws ServiceLayerException {
    if (!processedPaths.contains(item.getUri())) {
        if (!submittedPaths.contains(item.getUri())) {
            submittedPaths.add(item.getUri());
        }
        List<DmDependencyTO> children = item.getChildren();
        if (children != null) {
            for (DmDependencyTO child : children) {
                if (objectStateService.isUpdatedOrNew(site, child.getUri())) {
                    if (!submittedPaths.contains(child.getUri())) {
                        submittedPaths.add(child.getUri());
                    }
                    resolveSubmittedPaths(site, child, submittedPaths, processedPaths);
                }
            }
        }
        List<String> dependencyPaths = dependencyService.getPublishingDependencies(site, item.getUri());
        submittedPaths.addAll(dependencyPaths);
        processedPaths.addAll(dependencyPaths);
        processedPaths.add(item.getUri());
    }
}
Also used : DmDependencyTO(org.craftercms.studio.api.v1.to.DmDependencyTO)

Example 25 with DmDependencyTO

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

the class WorkflowServiceImpl method getChildrenForRenamedItem.

protected List<DmDependencyTO> getChildrenForRenamedItem(String site, DmDependencyTO renameItem) {
    List<DmDependencyTO> toRet = new ArrayList<>();
    List<DmDependencyTO> children = renameItem.getChildren();
    ZonedDateTime date = renameItem.getScheduledDate();
    if (children != null) {
        Iterator<DmDependencyTO> childItr = children.iterator();
        while (childItr.hasNext()) {
            DmDependencyTO child = childItr.next();
            ZonedDateTime pageDate = child.getScheduledDate();
            if ((date == null && pageDate != null) || (date != null && !date.equals(pageDate))) {
                if (!renameItem.isNow()) {
                    child.setNow(false);
                    if (date != null && (pageDate != null && pageDate.isBefore(date))) {
                        child.setScheduledDate(date);
                    }
                }
                toRet.add(child);
                List<DmDependencyTO> childDeps = child.flattenChildren();
                for (DmDependencyTO childDep : childDeps) {
                    if (objectStateService.isUpdatedOrNew(site, childDep.getUri())) {
                        toRet.add(childDep);
                    }
                }
                child.setReference(false);
                childItr.remove();
            }
        }
    }
    return toRet;
}
Also used : ZonedDateTime(java.time.ZonedDateTime) ArrayList(java.util.ArrayList) DmDependencyTO(org.craftercms.studio.api.v1.to.DmDependencyTO)

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