Search in sources :

Example 11 with DmDependencyTO

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

the class WorkflowServiceImpl method getSubmittedItems.

/**
 * get submitted items from JSON request
 *
 * @param site
 * @param items
 * @param format
 * @return submitted items
 * @throws JSONException
 */
protected List<DmDependencyTO> getSubmittedItems(String site, JSONArray items, SimpleDateFormat format, String schDate) throws JSONException, ServiceLayerException {
    if (items != null) {
        int length = items.size();
        if (length > 0) {
            List<DmDependencyTO> submittedItems = new ArrayList<>();
            for (int index = 0; index < length; index++) {
                JSONObject item = items.getJSONObject(index);
                DmDependencyTO submittedItem = getSubmittedItem(site, item, format, schDate);
                submittedItems.add(submittedItem);
            }
            return submittedItems;
        }
    }
    return null;
}
Also used : JSONObject(net.sf.json.JSONObject) ArrayList(java.util.ArrayList) DmDependencyTO(org.craftercms.studio.api.v1.to.DmDependencyTO)

Example 12 with DmDependencyTO

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

the class WorkflowServiceImpl method sendDeleteApprovalNotification.

protected void sendDeleteApprovalNotification(String site, DmDependencyTO submittedItem, String approver) {
    try {
        if (submittedItem.isSendEmail()) {
            String uri = submittedItem.getUri();
            ContentItemTO contentItem = contentService.getContentItem(site, uri);
            if (contentItem != null) {
            // Prepare to send notification
            }
        }
    } catch (Exception e) {
        logger.error("Could not send delete approval notification for newly created item", e);
    }
}
Also used : ContentItemTO(org.craftercms.studio.api.v1.to.ContentItemTO) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException) ContentNotFoundException(org.craftercms.studio.api.v1.exception.ContentNotFoundException) JSONException(net.sf.json.JSONException) DeploymentException(org.craftercms.studio.api.v1.service.deployment.DeploymentException)

Example 13 with DmDependencyTO

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

the class WorkflowServiceImpl method getSubmittedItemApproveWithoutDependencies.

protected DmDependencyTO getSubmittedItemApproveWithoutDependencies(String site, String itemPath, SimpleDateFormat format, String globalSchDate) throws JSONException {
    DmDependencyTO submittedItem = new DmDependencyTO();
    submittedItem.setUri(itemPath);
    // TODO: check scheduled date to make sure it is not null when isNow =
    // true and also it is not past
    ZonedDateTime scheduledDate = null;
    if (globalSchDate != null && !StringUtils.isEmpty(globalSchDate)) {
        scheduledDate = getScheduledDate(site, format, globalSchDate);
    } else {
        if (submittedItem.getScheduledDate() != null) {
            scheduledDate = getScheduledDate(site, format, submittedItem.getScheduledDate().format(DateTimeFormatter.ofPattern(format.toPattern())));
        }
    }
    if (scheduledDate == null) {
        submittedItem.setNow(true);
    }
    submittedItem.setScheduledDate(scheduledDate);
    return submittedItem;
}
Also used : ZonedDateTime(java.time.ZonedDateTime) DmDependencyTO(org.craftercms.studio.api.v1.to.DmDependencyTO)

Example 14 with DmDependencyTO

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

the class WorkflowServiceImpl method getSubmittedItem.

protected DmDependencyTO getSubmittedItem(String site, String itemPath, SimpleDateFormat format, String globalSchDate, Set<String> processedDependencies) throws JSONException {
    DmDependencyTO submittedItem = new DmDependencyTO();
    submittedItem.setUri(itemPath);
    // true and also it is not past
    ZonedDateTime scheduledDate = null;
    if (globalSchDate != null && !StringUtils.isEmpty(globalSchDate)) {
        scheduledDate = getScheduledDate(site, format, globalSchDate);
    } else {
        if (submittedItem.getScheduledDate() != null) {
            scheduledDate = getScheduledDate(site, format, submittedItem.getScheduledDate().format(DateTimeFormatter.ofPattern(format.toPattern())));
        }
    }
    if (scheduledDate == null) {
        submittedItem.setNow(true);
    }
    submittedItem.setScheduledDate(scheduledDate);
    if (processedDependencies == null) {
        processedDependencies = new HashSet<String>();
    }
    if (CollectionUtils.isNotEmpty(submittedItem.getComponents())) {
        for (DmDependencyTO component : submittedItem.getComponents()) {
            if (!processedDependencies.contains(component.getUri())) {
                component = getSubmittedItem(site, component.getUri(), format, globalSchDate, processedDependencies);
            }
        }
    }
    if (CollectionUtils.isNotEmpty(submittedItem.getDocuments())) {
        for (DmDependencyTO document : submittedItem.getDocuments()) {
            if (!processedDependencies.contains(document.getUri())) {
                document = getSubmittedItem(site, document.getUri(), format, globalSchDate, processedDependencies);
            }
        }
    }
    if (CollectionUtils.isNotEmpty(submittedItem.getAssets())) {
        for (DmDependencyTO asset : submittedItem.getAssets()) {
            if (!processedDependencies.contains(asset.getUri())) {
                asset = getSubmittedItem(site, asset.getUri(), format, globalSchDate, processedDependencies);
            }
        }
    }
    if (CollectionUtils.isNotEmpty(submittedItem.getRenderingTemplates())) {
        for (DmDependencyTO template : submittedItem.getRenderingTemplates()) {
            if (!processedDependencies.contains(template.getUri())) {
                template = getSubmittedItem(site, template.getUri(), format, globalSchDate, processedDependencies);
            }
        }
    }
    if (CollectionUtils.isNotEmpty(submittedItem.getDeletedItems())) {
        for (DmDependencyTO deletedItem : submittedItem.getDeletedItems()) {
            if (!processedDependencies.contains(deletedItem.getUri())) {
                deletedItem = getSubmittedItem(site, deletedItem.getUri(), format, globalSchDate, processedDependencies);
            }
        }
    }
    if (CollectionUtils.isNotEmpty(submittedItem.getChildren())) {
        for (DmDependencyTO child : submittedItem.getChildren()) {
            if (!processedDependencies.contains(child.getUri())) {
                child = getSubmittedItem(site, child.getUri(), format, globalSchDate, processedDependencies);
            }
        }
    }
    return submittedItem;
}
Also used : ZonedDateTime(java.time.ZonedDateTime) DmDependencyTO(org.craftercms.studio.api.v1.to.DmDependencyTO)

Example 15 with DmDependencyTO

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

the class WorkflowServiceImpl method getSubmittedItem.

/**
 * get a submitted item from a JSON item
 *
 * @param site
 * @param item
 * @param format
 * @return submitted item
 * @throws net.sf.json.JSONException
 */
protected DmDependencyTO getSubmittedItem(String site, JSONObject item, SimpleDateFormat format, String globalSchDate) throws JSONException, ServiceLayerException {
    DmDependencyTO submittedItem = new DmDependencyTO();
    String uri = item.getString(JSON_KEY_URI);
    submittedItem.setUri(uri);
    boolean deleted = (item.containsKey(JSON_KEY_DELETED)) ? item.getBoolean(JSON_KEY_DELETED) : false;
    submittedItem.setDeleted(deleted);
    boolean isNow = (item.containsKey(JSON_KEY_IS_NOW)) ? item.getBoolean(JSON_KEY_IS_NOW) : false;
    submittedItem.setNow(isNow);
    boolean submittedForDeletion = (item.containsKey(JSON_KEY_SUBMITTED_FOR_DELETION)) ? item.getBoolean(JSON_KEY_SUBMITTED_FOR_DELETION) : false;
    boolean submitted = (item.containsKey(JSON_KEY_SUBMITTED)) ? item.getBoolean(JSON_KEY_SUBMITTED) : false;
    boolean inProgress = (item.containsKey(JSON_KEY_IN_PROGRESS)) ? item.getBoolean(JSON_KEY_IN_PROGRESS) : false;
    boolean isReference = (item.containsKey(JSON_KEY_IN_REFERENCE)) ? item.getBoolean(JSON_KEY_IN_REFERENCE) : false;
    submittedItem.setReference(isReference);
    // boolean submittedForDeletion =
    // (item.containsKey(JSON_KEY_SUBMITTED_FOR_DELETION)) ?
    // item.getBoolean(JSON_KEY_SUBMITTED_FOR_DELETION) : false;
    submittedItem.setSubmittedForDeletion(submittedForDeletion);
    submittedItem.setSubmitted(submitted);
    submittedItem.setInProgress(inProgress);
    // TODO: check scheduled date to make sure it is not null when isNow =
    // true and also it is not past
    ZonedDateTime scheduledDate = null;
    if (globalSchDate != null && !StringUtils.isEmpty(globalSchDate)) {
        scheduledDate = getScheduledDate(site, format, globalSchDate);
    } else {
        if (item.containsKey(JSON_KEY_SCHEDULED_DATE)) {
            String dateStr = item.getString(JSON_KEY_SCHEDULED_DATE);
            if (!StringUtils.isEmpty(dateStr)) {
                scheduledDate = getScheduledDate(site, format, dateStr);
            }
        }
    }
    if (scheduledDate == null && isNow == false) {
        submittedItem.setNow(true);
    }
    submittedItem.setScheduledDate(scheduledDate);
    JSONArray components = (item.containsKey(JSON_KEY_COMPONENTS) && !item.getJSONObject(JSON_KEY_COMPONENTS).isNullObject()) ? item.getJSONArray(JSON_KEY_COMPONENTS) : null;
    List<DmDependencyTO> submittedComponents = getSubmittedItems(site, components, format, globalSchDate);
    submittedItem.setComponents(submittedComponents);
    JSONArray documents = (item.containsKey(JSON_KEY_DOCUMENTS) && !item.getJSONObject(JSON_KEY_DOCUMENTS).isNullObject()) ? item.getJSONArray(JSON_KEY_DOCUMENTS) : null;
    List<DmDependencyTO> submittedDocuments = getSubmittedItems(site, documents, format, globalSchDate);
    submittedItem.setDocuments(submittedDocuments);
    JSONArray assets = (item.containsKey(JSON_KEY_ASSETS) && !item.getJSONObject(JSON_KEY_ASSETS).isNullObject()) ? item.getJSONArray(JSON_KEY_ASSETS) : null;
    List<DmDependencyTO> submittedAssets = getSubmittedItems(site, assets, format, globalSchDate);
    submittedItem.setAssets(submittedAssets);
    JSONArray templates = (item.containsKey(JSON_KEY_RENDERING_TEMPLATES) && !item.getJSONObject(JSON_KEY_RENDERING_TEMPLATES).isNullObject()) ? item.getJSONArray(JSON_KEY_RENDERING_TEMPLATES) : null;
    List<DmDependencyTO> submittedTemplates = getSubmittedItems(site, templates, format, globalSchDate);
    submittedItem.setRenderingTemplates(submittedTemplates);
    JSONArray deletedItems = (item.containsKey(JSON_KEY_DELETED_ITEMS) && !item.getJSONObject(JSON_KEY_DELETED_ITEMS).isNullObject()) ? item.getJSONArray(JSON_KEY_DELETED_ITEMS) : null;
    List<DmDependencyTO> deletes = getSubmittedItems(site, deletedItems, format, globalSchDate);
    submittedItem.setDeletedItems(deletes);
    JSONArray children = (item.containsKey(JSON_KEY_CHILDREN)) ? item.getJSONArray(JSON_KEY_CHILDREN) : null;
    List<DmDependencyTO> submittedChidren = getSubmittedItems(site, children, format, globalSchDate);
    submittedItem.setChildren(submittedChidren);
    if (uri.endsWith(DmConstants.XML_PATTERN)) {
        /**
         * Get dependent pages
         */
        Set<String> deps = dependencyService.getItemDependencies(site, uri, 1);
        List<String> pagePatterns = servicesConfig.getPagePatterns(site);
        List<String> documentPatterns = servicesConfig.getDocumentPatterns(site);
        List<DmDependencyTO> dependentPages = new ArrayList<>();
        List<DmDependencyTO> dependentDocuments = new ArrayList<>();
        for (String dep : deps) {
            if (ContentUtils.matchesPatterns(dep, pagePatterns)) {
                DmDependencyTO dmDependencyTO = new DmDependencyTO();
                dmDependencyTO.setUri(dep);
                dependentPages.add(dmDependencyTO);
            } else if (ContentUtils.matchesPatterns(dep, documentPatterns)) {
                DmDependencyTO dmDependencyTO = new DmDependencyTO();
                dmDependencyTO.setUri(dep);
                dependentDocuments.add(dmDependencyTO);
            }
        }
        submittedItem.setPages(dependentPages);
        submittedItem.setDocuments(dependentDocuments);
    }
    return submittedItem;
}
Also used : ZonedDateTime(java.time.ZonedDateTime) JSONArray(net.sf.json.JSONArray) 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