Search in sources :

Example 1 with DmOrderTO

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

the class ContentServiceImpl method getItemOrders.

/**
 * get WCM content item order metadata
 *
 * @param nodes
 * @return item orders metadata
 */
protected List<DmOrderTO> getItemOrders(List<Node> nodes) {
    // TODO: SJ: Rewrite this and the whole order/sort system; 3.1+
    if (nodes != null) {
        List<DmOrderTO> orders = new ArrayList<DmOrderTO>(nodes.size());
        for (Node node : nodes) {
            String orderName = DmConstants.JSON_KEY_ORDER_DEFAULT;
            String orderStr = node.getText();
            addOrderValue(orders, orderName, orderStr);
        }
        return orders;
    } else {
        return null;
    }
}
Also used : DmOrderTO(org.craftercms.studio.api.v1.to.DmOrderTO) Node(org.dom4j.Node) ArrayList(java.util.ArrayList)

Example 2 with DmOrderTO

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

the class ContentServiceImpl method addOrderValue.

/**
 * add order value to the list of orders
 *
 * @param orders
 * @param orderName
 * @param orderStr
 */
protected void addOrderValue(List<DmOrderTO> orders, String orderName, String orderStr) {
    Double orderValue = null;
    try {
        orderValue = Double.parseDouble(orderStr);
    } catch (NumberFormatException e) {
        logger.debug(orderName + ", " + orderStr + " is not a valid order value pair.");
    }
    if (!StringUtils.isEmpty(orderName) && orderValue != null) {
        DmOrderTO order = new DmOrderTO();
        order.setId(orderName);
        order.setOrder(orderValue);
        orders.add(order);
    }
}
Also used : DmOrderTO(org.craftercms.studio.api.v1.to.DmOrderTO)

Example 3 with DmOrderTO

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

the class ContentServiceImpl method reorderItems.

@Override
@ValidateParams
public double reorderItems(@ValidateStringParam(name = "site") String site, @ValidateSecurePathParam(name = "relativePath") String relativePath, @ValidateSecurePathParam(name = "before") String before, @ValidateSecurePathParam(name = "after") String after, @ValidateStringParam(name = "orderName") String orderName) throws ServiceLayerException {
    Double beforeOrder = null;
    Double afterOrder = null;
    DmOrderTO beforeOrderTO = null;
    DmOrderTO afterOrderTO = null;
    // if the path is not provided, the order is 0
    if (!StringUtils.isEmpty(before)) {
        ContentItemTO beforeItem = getContentItem(site, before, 0);
        beforeOrder = beforeItem.getOrder(orderName);
        beforeOrderTO = new DmOrderTO();
        beforeOrderTO.setId(before);
        if (beforeOrder != null && beforeOrder > 0) {
            beforeOrderTO.setOrder(beforeOrder);
        }
    }
    // ORDER_INCREMENT
    if (!StringUtils.isEmpty(after)) {
        ContentItemTO afterItem = getContentItem(site, after, 0);
        afterOrder = afterItem.getOrder(orderName);
        afterOrderTO = new DmOrderTO();
        afterOrderTO.setId(after);
        if (afterOrder != null && afterOrder > 0) {
            afterOrderTO.setOrder(afterOrder);
        }
    }
    // if no after and before provided, the initial value is ORDER_INCREMENT
    if (afterOrder == null && beforeOrder == null) {
        return dmPageNavigationOrderService.getNewNavOrder(site, ContentUtils.getParentUrl(relativePath.replace(FILE_SEPARATOR + DmConstants.INDEX_FILE, "")));
    } else if (beforeOrder == null) {
        return (0 + afterOrder) / 2;
    } else if (afterOrder == null) {
        logger.info("afterOrder == null");
        return dmPageNavigationOrderService.getNewNavOrder(site, ContentUtils.getParentUrl(relativePath.replace(FILE_SEPARATOR + DmConstants.INDEX_FILE, "")), beforeOrder);
    } else {
        // return (beforeOrder + afterOrder) / 2;
        return computeReorder(site, relativePath, beforeOrderTO, afterOrderTO, orderName);
    }
}
Also used : ContentItemTO(org.craftercms.studio.api.v1.to.ContentItemTO) DmOrderTO(org.craftercms.studio.api.v1.to.DmOrderTO) ValidateParams(org.craftercms.commons.validation.annotations.param.ValidateParams)

Example 4 with DmOrderTO

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

the class ContentServiceImpl method getOrders.

private List<DmOrderTO> getOrders(String site, String relativePath, String orderName, boolean includeFloating) {
    // otherwise remove the file name only
    if (!StringUtils.isEmpty(relativePath)) {
        if (relativePath.endsWith(DmConstants.XML_PATTERN)) {
            int index = relativePath.lastIndexOf(FILE_SEPARATOR);
            if (index > 0) {
                String fileName = relativePath.substring(index + 1);
                String path = relativePath.substring(0, index);
                if (DmConstants.INDEX_FILE.equals(fileName)) {
                    int secondIndex = path.lastIndexOf(FILE_SEPARATOR);
                    if (secondIndex > 0) {
                        path = path.substring(0, secondIndex);
                    }
                }
                relativePath = path;
            }
        }
    }
    // get the root item and its children
    ContentItemTO item = getContentItem(site, relativePath);
    if (item.getChildren() != null) {
        List<DmOrderTO> orders = new ArrayList<DmOrderTO>(item.getChildren().size());
        String pathIndex = relativePath + FILE_SEPARATOR + DmConstants.INDEX_FILE;
        for (ContentItemTO child : item.getChildren()) {
            // exclude index.xml, the level descriptor and floating pages at the path
            if (!(pathIndex.equals(child.getUri()) || child.isLevelDescriptor() || child.isDeleted()) && (!child.isFloating() || includeFloating)) {
                DmOrderTO order = new DmOrderTO();
                order.setId(child.getUri());
                Double orderNumber = child.getOrder(orderName);
                // add only if the page contains order information
                if (orderNumber != null && orderNumber > 0) {
                    order.setOrder(child.getOrder(orderName));
                    order.setName(child.getInternalName());
                    if (child.isDisabled())
                        order.setDisabled("true");
                    else
                        order.setDisabled("false");
                    if (child.isNavigation())
                        order.setPlaceInNav("true");
                    else
                        order.setPlaceInNav("false");
                    orders.add(order);
                }
            }
        }
        return orders;
    }
    return null;
}
Also used : ContentItemTO(org.craftercms.studio.api.v1.to.ContentItemTO) DmOrderTO(org.craftercms.studio.api.v1.to.DmOrderTO) ArrayList(java.util.ArrayList)

Aggregations

DmOrderTO (org.craftercms.studio.api.v1.to.DmOrderTO)4 ArrayList (java.util.ArrayList)2 ContentItemTO (org.craftercms.studio.api.v1.to.ContentItemTO)2 ValidateParams (org.craftercms.commons.validation.annotations.param.ValidateParams)1 Node (org.dom4j.Node)1