Search in sources :

Example 26 with ContentItemTO

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

the class DeploymentServiceImpl method createDeploymentTask.

/**
 * create WcmDeploymentTask
 *
 * @param deployedLabel
 * @param item
 * @return deployment task
 */
protected DmDeploymentTaskTO createDeploymentTask(String deployedLabel, ContentItemTO item) {
    // otherwise just add as the last task
    DmDeploymentTaskTO task = new DmDeploymentTaskTO();
    task.setInternalName(deployedLabel);
    List<ContentItemTO> taskItems = task.getChildren();
    if (taskItems == null) {
        taskItems = new ArrayList<ContentItemTO>();
        task.setChildren(taskItems);
    }
    taskItems.add(item);
    task.setNumOfChildren(taskItems.size());
    return task;
}
Also used : DmDeploymentTaskTO(org.craftercms.studio.api.v1.to.DmDeploymentTaskTO) ContentItemTO(org.craftercms.studio.api.v1.to.ContentItemTO)

Example 27 with ContentItemTO

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

the class DeploymentServiceImpl method getScheduledItems.

@Override
@ValidateParams
public List<ContentItemTO> getScheduledItems(@ValidateStringParam(name = "site") String site, @ValidateStringParam(name = "sort") String sort, boolean ascending, @ValidateStringParam(name = "subSort") String subSort, boolean subAscending, @ValidateStringParam(name = "filterType") String filterType) throws ServiceLayerException {
    if (StringUtils.isEmpty(sort)) {
        sort = DmContentItemComparator.SORT_EVENT_DATE;
    }
    DmContentItemComparator comparator = new DmContentItemComparator(sort, ascending, true, true);
    DmContentItemComparator subComparator = new DmContentItemComparator(subSort, subAscending, true, true);
    List<ContentItemTO> items = null;
    items = getScheduledItems(site, comparator, subComparator, filterType);
    return items;
}
Also used : ContentItemTO(org.craftercms.studio.api.v1.to.ContentItemTO) DmContentItemComparator(org.craftercms.studio.api.v1.util.DmContentItemComparator) ValidateParams(org.craftercms.commons.validation.annotations.param.ValidateParams)

Example 28 with ContentItemTO

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

the class DeploymentServiceImpl method createDateItem.

protected ContentItemTO createDateItem(String name, ContentItemTO itemToAdd, DmContentItemComparator comparator, String timeZone) {
    ContentItemTO dateItem = new ContentItemTO();
    dateItem.name = name;
    dateItem.internalName = name;
    dateItem.eventDate = itemToAdd.scheduledDate;
    dateItem.scheduledDate = itemToAdd.scheduledDate;
    dateItem.timezone = timeZone;
    dateItem.addChild(itemToAdd, comparator, false);
    return dateItem;
}
Also used : ContentItemTO(org.craftercms.studio.api.v1.to.ContentItemTO)

Example 29 with ContentItemTO

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

the class DeploymentServiceImpl method getDeploymentHistory.

@Override
@ValidateParams
public List<DmDeploymentTaskTO> getDeploymentHistory(@ValidateStringParam(name = "site") String site, @ValidateIntegerParam(name = "daysFromToday") int daysFromToday, @ValidateIntegerParam(name = "numberOfItems") int numberOfItems, @ValidateStringParam(name = "sort") String sort, boolean ascending, @ValidateStringParam(name = "filterType") String filterType) throws SiteNotFoundException {
    // get the filtered list of attempts in a specific date range
    ZonedDateTime toDate = ZonedDateTime.now(ZoneOffset.UTC);
    ZonedDateTime fromDate = toDate.minusDays(daysFromToday);
    List<DeploymentSyncHistory> deployReports = deploymentHistoryProvider.getDeploymentHistory(site, getEnvironmentNames(site), fromDate, toDate, dmFilterWrapper, filterType, numberOfItems);
    List<DmDeploymentTaskTO> tasks = new ArrayList<DmDeploymentTaskTO>();
    if (deployReports != null) {
        int count = 0;
        String timezone = servicesConfig.getDefaultTimezone(site);
        Map<String, Set<String>> processedItems = new HashMap<String, Set<String>>();
        for (int index = 0; index < deployReports.size() && count < numberOfItems; index++) {
            DeploymentSyncHistory entry = deployReports.get(index);
            String env = entry.getEnvironment();
            if (!processedItems.containsKey(env)) {
                processedItems.put(env, new HashSet<String>());
            }
            if (!processedItems.get(env).contains(entry.getPath())) {
                ContentItemTO deployedItem = getDeployedItem(entry.getSite(), entry.getPath());
                if (deployedItem != null) {
                    deployedItem.eventDate = entry.getSyncDate();
                    deployedItem.endpoint = entry.getTarget();
                    deployedItem.setUser(entry.getUser());
                    deployedItem.setEndpoint(entry.getEnvironment());
                    String deployedLabel = entry.getSyncDate().withZoneSameInstant(ZoneId.of(timezone)).format(ISO_OFFSET_DATE);
                    if (tasks.size() > 0) {
                        DmDeploymentTaskTO lastTask = tasks.get(tasks.size() - 1);
                        String lastDeployedLabel = lastTask.getInternalName();
                        if (lastDeployedLabel.equals(deployedLabel)) {
                            // add to the last task if it is deployed on the same day
                            lastTask.setNumOfChildren(lastTask.getNumOfChildren() + 1);
                            lastTask.getChildren().add(deployedItem);
                        } else {
                            tasks.add(createDeploymentTask(deployedLabel, deployedItem));
                        }
                    } else {
                        tasks.add(createDeploymentTask(deployedLabel, deployedItem));
                    }
                    processedItems.get(env).add(entry.getPath());
                }
            }
        }
    }
    return tasks;
}
Also used : DmDeploymentTaskTO(org.craftercms.studio.api.v1.to.DmDeploymentTaskTO) Set(java.util.Set) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) HashMap(java.util.HashMap) DeploymentSyncHistory(org.craftercms.studio.api.v1.dal.DeploymentSyncHistory) ArrayList(java.util.ArrayList) FastArrayList(org.apache.commons.collections.FastArrayList) ContentItemTO(org.craftercms.studio.api.v1.to.ContentItemTO) ZonedDateTime(java.time.ZonedDateTime) ValidateParams(org.craftercms.commons.validation.annotations.param.ValidateParams)

Example 30 with ContentItemTO

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

Aggregations

ContentItemTO (org.craftercms.studio.api.v1.to.ContentItemTO)60 ValidateParams (org.craftercms.commons.validation.annotations.param.ValidateParams)19 HashMap (java.util.HashMap)16 ServiceLayerException (org.craftercms.studio.api.v1.exception.ServiceLayerException)15 ArrayList (java.util.ArrayList)10 ItemState (org.craftercms.studio.api.v1.dal.ItemState)10 ContentNotFoundException (org.craftercms.studio.api.v1.exception.ContentNotFoundException)10 JSONObject (net.sf.json.JSONObject)6 SiteNotFoundException (org.craftercms.studio.api.v1.exception.SiteNotFoundException)6 HashSet (java.util.HashSet)5 JSONException (net.sf.json.JSONException)5 ItemMetadata (org.craftercms.studio.api.v1.dal.ItemMetadata)5 ZonedDateTime (java.time.ZonedDateTime)4 CryptoException (org.craftercms.commons.crypto.CryptoException)4 EntitlementException (org.craftercms.commons.entitlements.exception.EntitlementException)4 DeploymentException (org.craftercms.studio.api.v1.service.deployment.DeploymentException)4 DocumentException (org.dom4j.DocumentException)4 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 MimetypesFileTypeMap (javax.activation.MimetypesFileTypeMap)3