Search in sources :

Example 16 with DmDependencyTO

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

the class WorkflowServiceImpl method getSubmittedItem_new.

protected DmDependencyTO getSubmittedItem_new(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 17 with DmDependencyTO

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

the class WorkflowServiceImpl method doDelete.

protected void doDelete(String site, List<DmDependencyTO> submittedItems, String approver) throws ServiceLayerException {
    long start = System.currentTimeMillis();
    String user = securityService.getCurrentUser();
    // get web project information
    // String assignee = getAssignee(site, sub);
    // Don't make go live an item if it is new and to be deleted
    final ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
    List<String> itemsToDelete = new ArrayList<>();
    List<DmDependencyTO> deleteItems = new ArrayList<>();
    List<DmDependencyTO> scheItems = new ArrayList<>();
    for (DmDependencyTO submittedItem : submittedItems) {
        String uri = submittedItem.getUri();
        ZonedDateTime schDate = submittedItem.getScheduledDate();
        boolean isItemForSchedule = false;
        if (schDate == null || schDate.isBefore(now)) {
            // Sending Notification
            if (StringUtils.isNotEmpty(approver)) {
                // immediate delete
                if (submittedItem.isSendEmail()) {
                    sendDeleteApprovalNotification(site, submittedItem, approver);
                // TODO move it after delete actually happens
                }
            }
            if (submittedItem.getUri().endsWith(DmConstants.INDEX_FILE)) {
                submittedItem.setUri(submittedItem.getUri().replace(FILE_SEPARATOR + DmConstants.INDEX_FILE, ""));
            }
            itemsToDelete.add(uri);
        } else {
            scheItems.add(submittedItem);
            isItemForSchedule = true;
        }
        submittedItem.setDeleted(true);
        // replace with the folder name
        boolean isNew = objectStateService.isNew(site, uri);
        if (!isNew || isItemForSchedule) {
            deleteItems.add(submittedItem);
        }
    }
    GoLiveContext context = new GoLiveContext(approver, site);
    final String pathPrefix = FILE_SEPARATOR + "wem-projects" + FILE_SEPARATOR + site + FILE_SEPARATOR + site + FILE_SEPARATOR + "work-area";
    Map<ZonedDateTime, List<DmDependencyTO>> groupedPackages = groupByDate(deleteItems, now);
    if (groupedPackages.isEmpty()) {
        groupedPackages.put(now, Collections.<DmDependencyTO>emptyList());
    }
    for (ZonedDateTime scheduledDate : groupedPackages.keySet()) {
        List<DmDependencyTO> deletePackage = groupedPackages.get(scheduledDate);
        SubmitPackage submitpackage = new SubmitPackage(pathPrefix);
        Set<String> rescheduledUris = new HashSet<String>();
        if (deletePackage != null) {
            ZonedDateTime launchDate = scheduledDate.equals(now) ? null : scheduledDate;
            Set<String> processedUris = new HashSet<String>();
            for (DmDependencyTO dmDependencyTO : deletePackage) {
                if (launchDate != null) {
                    handleReferences(site, submitpackage, dmDependencyTO, true, null, "", rescheduledUris, processedUris);
                } else {
                    applyDeleteDependencyRule(site, submitpackage, dmDependencyTO);
                }
            }
            String label = submitpackage.getLabel();
            SubmitLifeCycleOperation deleteOperation = null;
            Set<String> liveDependencyItems = new HashSet<String>();
            Set<String> allItems = new HashSet<String>();
            for (String uri : itemsToDelete) {
                // $ToDO $ remove this case and keep the item in go live queue
                GoLiveDeleteCandidates deleteCandidate = contentService.getDeleteCandidates(context.getSite(), uri);
                allItems.addAll(deleteCandidate.getAllItems());
                // get all dependencies that has to be removed as well
                liveDependencyItems.addAll(deleteCandidate.getLiveDependencyItems());
            }
            List<String> submitPackPaths = submitpackage.getPaths();
            if (launchDate != null) {
                deleteOperation = new PreScheduleDeleteOperation(this, submitpackage.getUris(), launchDate, context, rescheduledUris);
                label = DmConstants.DM_SCHEDULE_SUBMISSION_FLOW + ":" + label;
            } else {
                // add dependencies to submitPackage
                for (String liveDependency : liveDependencyItems) {
                    submitpackage.addToPackage(liveDependency);
                }
                submitPackPaths = submitpackage.getPaths();
                deleteOperation = new PreSubmitDeleteOperation(this, new HashSet<String>(allItems), context, rescheduledUris);
                removeChildFromSubmitPackForDelete(submitPackPaths);
            }
            Map<String, String> submittedBy = new HashMap<>();
            workflowProcessor.addToWorkflow(site, new ArrayList<String>(), launchDate, label, deleteOperation, approver, null);
        }
    }
    long end = System.currentTimeMillis();
    logger.debug("Submitted deleted items to queue time = " + (end - start));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) GoLiveContext(org.craftercms.studio.api.v1.service.workflow.context.GoLiveContext) DmDependencyTO(org.craftercms.studio.api.v1.to.DmDependencyTO) PreSubmitDeleteOperation(org.craftercms.studio.impl.v1.service.workflow.operation.PreSubmitDeleteOperation) PreScheduleDeleteOperation(org.craftercms.studio.impl.v1.service.workflow.operation.PreScheduleDeleteOperation) ZonedDateTime(java.time.ZonedDateTime) GoLiveDeleteCandidates(org.craftercms.studio.api.v1.to.GoLiveDeleteCandidates) SubmitLifeCycleOperation(org.craftercms.studio.impl.v1.service.workflow.operation.SubmitLifeCycleOperation) List(java.util.List) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 18 with DmDependencyTO

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

the class WorkflowServiceImpl method doSubmit.

protected void doSubmit(final String site, final DmDependencyTO dependencyTO, final ZonedDateTime scheduledDate, final boolean sendEmail, final boolean submitForDeletion, final String user, final boolean notifyAdmin, final String submissionComment, String environment) throws ServiceLayerException {
    // first remove from workflow
    removeFromWorkflow(site, dependencyTO.getUri(), true);
    ContentItemTO item = contentService.getContentItem(site, dependencyTO.getUri());
    Map<String, Object> properties = new HashMap<>();
    properties.put(ItemMetadata.PROP_SUBMITTED_BY, user);
    properties.put(ItemMetadata.PROP_SEND_EMAIL, sendEmail ? 1 : 0);
    properties.put(ItemMetadata.PROP_SUBMITTED_FOR_DELETION, submitForDeletion ? 1 : 0);
    properties.put(ItemMetadata.PROP_SUBMISSION_COMMENT, submissionComment);
    properties.put(ItemMetadata.PROP_SUBMITTED_TO_ENVIRONMENT, environment);
    if (null == scheduledDate) {
        properties.put(ItemMetadata.PROP_LAUNCH_DATE, null);
    } else {
        properties.put(ItemMetadata.PROP_LAUNCH_DATE, scheduledDate);
    }
    if (!objectMetadataManager.metadataExist(site, dependencyTO.getUri())) {
        objectMetadataManager.insertNewObjectMetadata(site, dependencyTO.getUri());
    }
    objectMetadataManager.setObjectMetadata(site, dependencyTO.getUri(), properties);
    if (scheduledDate != null) {
        objectStateService.transition(site, item, TransitionEvent.SUBMIT_WITH_WORKFLOW_SCHEDULED);
    } else {
        objectStateService.transition(site, item, TransitionEvent.SUBMIT_WITH_WORKFLOW_UNSCHEDULED);
    }
}
Also used : ContentItemTO(org.craftercms.studio.api.v1.to.ContentItemTO) HashMap(java.util.HashMap) JSONObject(net.sf.json.JSONObject)

Example 19 with DmDependencyTO

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

the class WorkflowServiceImpl method groupByDate.

@Override
public Map<ZonedDateTime, List<DmDependencyTO>> groupByDate(List<DmDependencyTO> submittedItems, ZonedDateTime now) {
    Map<ZonedDateTime, List<DmDependencyTO>> groupedPackages = new HashMap<>();
    for (DmDependencyTO submittedItem : submittedItems) {
        ZonedDateTime scheduledDate = (submittedItem.isNow()) ? null : submittedItem.getScheduledDate();
        if (scheduledDate == null || scheduledDate.isBefore(now)) {
            scheduledDate = now;
        }
        List<DmDependencyTO> goLivePackage = groupedPackages.get(scheduledDate);
        if (goLivePackage == null)
            goLivePackage = new ArrayList<>();
        goLivePackage.add(submittedItem);
        groupedPackages.put(scheduledDate, goLivePackage);
    }
    return groupedPackages;
}
Also used : ZonedDateTime(java.time.ZonedDateTime) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) DmDependencyTO(org.craftercms.studio.api.v1.to.DmDependencyTO)

Example 20 with DmDependencyTO

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