Search in sources :

Example 1 with DmContentItemComparator

use of org.craftercms.studio.api.v1.util.DmContentItemComparator in project studio by craftercms.

the class WorkflowServiceImpl method getInProgressItems.

protected List<ContentItemTO> getInProgressItems(final String site, final DmContentItemComparator comparator, final boolean inProgressOnly) throws ServiceLayerException {
    final List<ContentItemTO> categoryItems = new ArrayList<>();
    List<ContentItemTO> categoryItems1 = getCategoryItems(site);
    categoryItems.addAll(categoryItems1);
    long st = System.currentTimeMillis();
    List<ItemState> changeSet = objectStateService.getChangeSet(site);
    logger.debug("Time taken listChangedAll()  " + (System.currentTimeMillis() - st));
    // the category item to add all other items that do not belong to
    // regular categories specified in the configuration
    st = System.currentTimeMillis();
    if (changeSet != null) {
        List<String> displayPatterns = servicesConfig.getDisplayInWidgetPathPatterns(site);
        // List<String> inProgressItems = new FastList<String>();
        for (ItemState state : changeSet) {
            if (contentService.contentExists(state.getSite(), state.getPath())) {
                if (ContentUtils.matchesPatterns(state.getPath(), displayPatterns)) {
                    ContentItemTO item = contentService.getContentItem(state.getSite(), state.getPath(), 0);
                    addInProgressItems(site, item, categoryItems, comparator, inProgressOnly);
                }
            }
        }
    }
    logger.debug("Time taken after listChangedAll() : " + (System.currentTimeMillis() - st));
    return categoryItems;
}
Also used : ContentItemTO(org.craftercms.studio.api.v1.to.ContentItemTO) ItemState(org.craftercms.studio.api.v1.dal.ItemState) ArrayList(java.util.ArrayList)

Example 2 with DmContentItemComparator

use of org.craftercms.studio.api.v1.util.DmContentItemComparator in project studio by craftercms.

the class DeploymentServiceImpl method addToScheduledDateList.

/**
 * add the given node to the scheduled items list
 *
 * @param site
 * @param launchDate
 * @param format
 * @param scheduledItems
 * @param comparator
 * @param subComparator
 * @param displayPatterns
 * @throws ServiceLayerException
 */
protected void addToScheduledDateList(String site, String environment, ZonedDateTime launchDate, String path, String packageId, List<ContentItemTO> scheduledItems, DmContentItemComparator comparator, DmContentItemComparator subComparator, List<String> displayPatterns) throws ServiceLayerException {
    String timeZone = servicesConfig.getDefaultTimezone(site);
    String dateLabel = launchDate.withZoneSameInstant(ZoneId.of(timeZone)).format(ISO_OFFSET_DATE_TIME);
    // display only if the path matches one of display patterns
    if (ContentUtils.matchesPatterns(path, displayPatterns)) {
        ContentItemTO itemToAdd = contentService.getContentItem(site, path, 0);
        itemToAdd.scheduledDate = launchDate;
        itemToAdd.environment = environment;
        itemToAdd.packageId = packageId;
        boolean found = false;
        for (int index = 0; index < scheduledItems.size(); index++) {
            ContentItemTO currDateItem = scheduledItems.get(index);
            // it non-recursively
            if (currDateItem.name.equals(dateLabel)) {
                currDateItem.addChild(itemToAdd, subComparator, false);
                found = true;
                break;
            // if the date is after the current date, add a new
            // date item before it
            // and add the content item to the new date item
            } else if (itemToAdd.scheduledDate.compareTo(currDateItem.scheduledDate) < 0) {
                ContentItemTO dateItem = createDateItem(dateLabel, itemToAdd, comparator, timeZone);
                scheduledItems.add(index, dateItem);
                found = true;
                break;
            }
        }
        // if not found, add to the end of list
        if (!found) {
            ContentItemTO dateItem = createDateItem(dateLabel, itemToAdd, comparator, timeZone);
            scheduledItems.add(dateItem);
        }
    }
}
Also used : ContentItemTO(org.craftercms.studio.api.v1.to.ContentItemTO)

Example 3 with DmContentItemComparator

use of org.craftercms.studio.api.v1.util.DmContentItemComparator 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 4 with DmContentItemComparator

use of org.craftercms.studio.api.v1.util.DmContentItemComparator 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 5 with DmContentItemComparator

use of org.craftercms.studio.api.v1.util.DmContentItemComparator in project studio by craftercms.

the class WorkflowServiceImpl method addInProgressItems.

protected void addInProgressItems(String site, ContentItemTO item, List<ContentItemTO> categoryItems, DmContentItemComparator comparator, boolean inProgressOnly) {
    if (addToQueue(false, inProgressOnly, true)) {
        if (!(item.isSubmitted() || item.isInProgress())) {
            return;
        }
        item.setDeleted(false);
        ContentItemTO found = null;
        String uri = item.getUri();
        for (ContentItemTO categoryItem : categoryItems) {
            String categoryPath = categoryItem.getPath() + FILE_SEPARATOR;
            if (uri.startsWith(categoryPath)) {
                found = categoryItem;
                break;
            }
        }
        if (found != null && !found.getUri().equals(item.getUri())) {
            found.addChild(item, comparator, true);
        }
    }
}
Also used : ContentItemTO(org.craftercms.studio.api.v1.to.ContentItemTO)

Aggregations

ContentItemTO (org.craftercms.studio.api.v1.to.ContentItemTO)9 ValidateParams (org.craftercms.commons.validation.annotations.param.ValidateParams)3 DmContentItemComparator (org.craftercms.studio.api.v1.util.DmContentItemComparator)3 HashMap (java.util.HashMap)2 JSONObject (net.sf.json.JSONObject)2 ArrayList (java.util.ArrayList)1 ItemState (org.craftercms.studio.api.v1.dal.ItemState)1 GoLiveQueue (org.craftercms.studio.api.v1.to.GoLiveQueue)1 GoLiveQueueChildFilter (org.craftercms.studio.api.v1.to.GoLiveQueueChildFilter)1 GoLiveQueueOrganizer (org.craftercms.studio.impl.v1.util.GoLiveQueueOrganizer)1