Search in sources :

Example 1 with DependencyRules

use of org.craftercms.studio.api.v1.service.dependency.DependencyRules in project studio by craftercms.

the class WorkflowServiceImpl method submitThisAndReferredComponents.

protected void submitThisAndReferredComponents(DmDependencyTO submittedItem, String site, ZonedDateTime scheduledDate, boolean sendEmail, boolean submitForDeletion, String submittedBy, DependencyRules rule, String submissionComment, String environment) throws ServiceLayerException {
    doSubmit(site, submittedItem, scheduledDate, sendEmail, submitForDeletion, submittedBy, true, submissionComment, environment);
    Set<DmDependencyTO> stringSet;
    if (submitForDeletion) {
        stringSet = rule.applyDeleteDependencyRule(submittedItem);
    } else {
        stringSet = rule.applySubmitRule(submittedItem);
    }
    for (DmDependencyTO s : stringSet) {
        ContentItemTO contentItem = contentService.getContentItem(site, s.getUri());
        boolean lsendEmail = true;
        boolean lnotifyAdmin = true;
        lsendEmail = sendEmail && ((!contentItem.isDocument() && !contentItem.isComponent() && !contentItem.isAsset()));
        lnotifyAdmin = (!contentItem.isDocument() && !contentItem.isComponent() && !contentItem.isAsset());
        // notify admin will always be true, unless for dependent document/banner/other-files
        doSubmit(site, s, scheduledDate, lsendEmail, submitForDeletion, submittedBy, lnotifyAdmin, submissionComment, environment);
    }
}
Also used : ContentItemTO(org.craftercms.studio.api.v1.to.ContentItemTO) DmDependencyTO(org.craftercms.studio.api.v1.to.DmDependencyTO)

Example 2 with DependencyRules

use of org.craftercms.studio.api.v1.service.dependency.DependencyRules in project studio by craftercms.

the class WorkflowServiceImpl method submitForApproval.

@SuppressWarnings("unchecked")
protected ResultTO submitForApproval(final String site, String submittedBy, final String request, final boolean delete) throws ServiceLayerException {
    RequestContext requestContext = RequestContextBuilder.buildSubmitContext(site, submittedBy);
    ResultTO result = new ResultTO();
    try {
        SimpleDateFormat format = new SimpleDateFormat(StudioConstants.DATE_PATTERN_WORKFLOW_WITH_TZ);
        JSONObject requestObject = JSONObject.fromObject(request);
        JSONArray items = requestObject.getJSONArray(JSON_KEY_ITEMS);
        int length = items.size();
        if (length > 0) {
            for (int index = 0; index < length; index++) {
                objectStateService.setSystemProcessing(site, items.optString(index), true);
            }
        }
        boolean isNow = (requestObject.containsKey(JSON_KEY_SCHEDULE)) ? StringUtils.equalsIgnoreCase(requestObject.getString(JSON_KEY_SCHEDULE), JSON_KEY_IS_NOW) : false;
        ZonedDateTime scheduledDate = null;
        if (!isNow) {
            scheduledDate = (requestObject.containsKey(JSON_KEY_SCHEDULED_DATE)) ? getScheduledDate(site, format, requestObject.getString(JSON_KEY_SCHEDULED_DATE)) : null;
        }
        boolean sendEmail = (requestObject.containsKey(JSON_KEY_SEND_EMAIL)) ? requestObject.getBoolean(JSON_KEY_SEND_EMAIL) : false;
        String environment = (requestObject != null && requestObject.containsKey(JSON_KEY_ENVIRONMENT)) ? requestObject.getString(JSON_KEY_ENVIRONMENT) : null;
        String submissionComment = (requestObject != null && requestObject.containsKey(JSON_KEY_SUBMISSION_COMMENT)) ? requestObject.getString(JSON_KEY_SUBMISSION_COMMENT) : null;
        // TODO: check scheduled date to make sure it is not null when isNow
        // = true and also it is not past
        String schDate = null;
        if (requestObject.containsKey(JSON_KEY_SCHEDULED_DATE)) {
            schDate = requestObject.getString(JSON_KEY_SCHEDULED_DATE);
        }
        if (length > 0) {
            List<DmDependencyTO> submittedItems = new ArrayList<DmDependencyTO>();
            for (int index = 0; index < length; index++) {
                String stringItem = items.optString(index);
                DmDependencyTO submittedItem = getSubmittedItem(site, stringItem, format, schDate, null);
                String user = submittedBy;
                submittedItems.add(submittedItem);
                if (delete) {
                    submittedItem.setSubmittedForDeletion(true);
                }
            }
            submittedItems.addAll(addDependenciesForSubmitForApproval(site, submittedItems, format, schDate));
            List<String> submittedPaths = new ArrayList<String>();
            for (DmDependencyTO goLiveItem : submittedItems) {
                submittedPaths.add(goLiveItem.getUri());
                objectStateService.setSystemProcessing(site, goLiveItem.getUri(), true);
                DependencyRules rule = new DependencyRules(site);
                rule.setObjectStateService(objectStateService);
                rule.setContentService(contentService);
                Set<DmDependencyTO> depSet = rule.applySubmitRule(goLiveItem);
                for (DmDependencyTO dep : depSet) {
                    submittedPaths.add(dep.getUri());
                    objectStateService.setSystemProcessing(site, dep.getUri(), true);
                }
            }
            List<DmError> errors = submitToGoLive(submittedItems, scheduledDate, sendEmail, delete, requestContext, submissionComment, environment);
            SiteFeed siteFeed = siteService.getSite(site);
            AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
            auditLog.setOperation(OPERATION_REQUEST_PUBLISH);
            auditLog.setActorId(submittedBy);
            auditLog.setSiteId(siteFeed.getId());
            auditLog.setPrimaryTargetId(site);
            auditLog.setPrimaryTargetType(TARGET_TYPE_CONTENT_ITEM);
            auditLog.setPrimaryTargetValue(site);
            auditServiceInternal.insertAuditLog(auditLog);
            result.setSuccess(true);
            result.setStatus(200);
            result.setMessage(notificationService.getNotificationMessage(site, NotificationMessageType.CompleteMessages, COMPLETE_SUBMIT_TO_GO_LIVE_MSG, Locale.ENGLISH));
            for (String relativePath : submittedPaths) {
                objectStateService.setSystemProcessing(site, relativePath, false);
            }
        }
    } catch (Exception e) {
        result.setSuccess(false);
        result.setMessage(e.getMessage());
        logger.error("Error while submitting content for approval.", e);
    }
    return result;
}
Also used : JSONArray(net.sf.json.JSONArray) ArrayList(java.util.ArrayList) DependencyRules(org.craftercms.studio.api.v1.service.dependency.DependencyRules) DmDependencyTO(org.craftercms.studio.api.v1.to.DmDependencyTO) ResultTO(org.craftercms.studio.api.v1.to.ResultTO) AuditLog(org.craftercms.studio.api.v2.dal.AuditLog) 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) JSONObject(net.sf.json.JSONObject) ZonedDateTime(java.time.ZonedDateTime) DmError(org.craftercms.studio.api.v1.to.DmError) SiteFeed(org.craftercms.studio.api.v1.dal.SiteFeed) RequestContext(org.craftercms.studio.api.v1.service.workflow.context.RequestContext) SimpleDateFormat(java.text.SimpleDateFormat)

Example 3 with DependencyRules

use of org.craftercms.studio.api.v1.service.dependency.DependencyRules in project studio by craftercms.

the class WorkflowServiceImpl method applyDeleteDependencyRule.

protected void applyDeleteDependencyRule(String site, SubmitPackage pack, DmDependencyTO dmDependencyTO) {
    pack.addToPackage(dmDependencyTO);
    DependencyRules rule = new DependencyRules(site);
    rule.setObjectStateService(objectStateService);
    rule.setContentService(contentService);
    Set<DmDependencyTO> dependencyTOSet = rule.applyDeleteDependencyRule(dmDependencyTO);
    for (DmDependencyTO dependencyTO : dependencyTOSet) {
        pack.addToPackage(dependencyTO);
    }
}
Also used : DependencyRules(org.craftercms.studio.api.v1.service.dependency.DependencyRules) DmDependencyTO(org.craftercms.studio.api.v1.to.DmDependencyTO)

Example 4 with DependencyRules

use of org.craftercms.studio.api.v1.service.dependency.DependencyRules in project studio by craftercms.

the class WorkflowServiceImpl method rejectThisAndReferences.

protected void rejectThisAndReferences(String site, DmDependencyTO dmDependencyTO, DependencyRules rule, String approver, String reason) {
    _reject(site, dmDependencyTO, approver, true, reason);
    Set<DmDependencyTO> dependencyTOSet = rule.applyRejectRule(dmDependencyTO);
    for (DmDependencyTO dependencyTO : dependencyTOSet) {
        boolean lsendEmail = true;
        try {
            ContentItemTO contentItem = contentService.getContentItem(site, dependencyTO.getUri());
            lsendEmail = !contentItem.isDocument() && !contentItem.isComponent() && !contentItem.isAsset();
        } catch (Exception e) {
            logger.error("during rejection, content retrieve failed");
            lsendEmail = false;
        }
        _reject(site, dependencyTO, approver, lsendEmail, reason);
    }
}
Also used : ContentItemTO(org.craftercms.studio.api.v1.to.ContentItemTO) DmDependencyTO(org.craftercms.studio.api.v1.to.DmDependencyTO) 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 5 with DependencyRules

use of org.craftercms.studio.api.v1.service.dependency.DependencyRules in project studio by craftercms.

the class WorkflowServiceImpl method submitToGoLive.

protected List<DmError> submitToGoLive(List<DmDependencyTO> submittedItems, ZonedDateTime scheduledDate, boolean sendEmail, boolean submitForDeletion, RequestContext requestContext, String submissionComment, String environment) throws ServiceLayerException {
    List<DmError> errors = new ArrayList<DmError>();
    String site = requestContext.getSite();
    String submittedBy = requestContext.getUser();
    for (DmDependencyTO submittedItem : submittedItems) {
        try {
            DependencyRules rule = new DependencyRules(site);
            rule.setContentService(contentService);
            rule.setObjectStateService(objectStateService);
            submitThisAndReferredComponents(submittedItem, site, scheduledDate, sendEmail, submitForDeletion, submittedBy, rule, submissionComment, environment);
            List<DmDependencyTO> children = submittedItem.getChildren();
            if (children != null && !submitForDeletion) {
                for (DmDependencyTO child : children) {
                    if (!child.isReference()) {
                        submitThisAndReferredComponents(child, site, scheduledDate, sendEmail, submitForDeletion, submittedBy, rule, submissionComment, environment);
                    }
                }
            }
        } catch (ContentNotFoundException e) {
            errors.add(new DmError(site, submittedItem.getUri(), e));
        }
    }
    notificationService.notifyApprovesContentSubmission(site, null, getDeploymentPaths(submittedItems), submittedBy, scheduledDate, submitForDeletion, submissionComment, Locale.ENGLISH);
    return errors;
}
Also used : ContentNotFoundException(org.craftercms.studio.api.v1.exception.ContentNotFoundException) DmError(org.craftercms.studio.api.v1.to.DmError) ArrayList(java.util.ArrayList) DependencyRules(org.craftercms.studio.api.v1.service.dependency.DependencyRules) DmDependencyTO(org.craftercms.studio.api.v1.to.DmDependencyTO)

Aggregations

DmDependencyTO (org.craftercms.studio.api.v1.to.DmDependencyTO)6 DependencyRules (org.craftercms.studio.api.v1.service.dependency.DependencyRules)4 ContentNotFoundException (org.craftercms.studio.api.v1.exception.ContentNotFoundException)3 ArrayList (java.util.ArrayList)2 JSONException (net.sf.json.JSONException)2 ServiceLayerException (org.craftercms.studio.api.v1.exception.ServiceLayerException)2 DeploymentException (org.craftercms.studio.api.v1.service.deployment.DeploymentException)2 ContentItemTO (org.craftercms.studio.api.v1.to.ContentItemTO)2 DmError (org.craftercms.studio.api.v1.to.DmError)2 SimpleDateFormat (java.text.SimpleDateFormat)1 ZonedDateTime (java.time.ZonedDateTime)1 JSONArray (net.sf.json.JSONArray)1 JSONObject (net.sf.json.JSONObject)1 ItemMetadata (org.craftercms.studio.api.v1.dal.ItemMetadata)1 SiteFeed (org.craftercms.studio.api.v1.dal.SiteFeed)1 RequestContext (org.craftercms.studio.api.v1.service.workflow.context.RequestContext)1 ResultTO (org.craftercms.studio.api.v1.to.ResultTO)1 AuditLog (org.craftercms.studio.api.v2.dal.AuditLog)1