Search in sources :

Example 1 with NavigationOrderSequence

use of org.craftercms.studio.api.v1.dal.NavigationOrderSequence in project studio by craftercms.

the class DmPageNavigationOrderServiceImpl method getNewNavOrder.

@RetryingOperation
@Override
@ValidateParams
public double getNewNavOrder(@ValidateStringParam(name = "site") String site, @ValidateSecurePathParam(name = "path") String path, @ValidateDoubleParam(name = "currentMaxNavOrder") double currentMaxNavOrder) {
    double lastNavOrder = 1000D;
    try {
        Map<String, String> params = new HashMap<String, String>();
        params.put("site", site);
        params.put("path", path);
        NavigationOrderSequence navigationOrderSequence = navigationOrderSequenceMapper.getPageNavigationOrderForSiteAndPath(params);
        if (navigationOrderSequence == null) {
            navigationOrderSequence = new NavigationOrderSequence();
            navigationOrderSequence.setSite(site);
            navigationOrderSequence.setPath(path);
            ContentItemTO itemTreeTO = contentService.getContentItemTree(site, path, 1);
            if (itemTreeTO == null) {
                navigationOrderSequence.setMaxCount(0F);
            } else {
                if (StringUtils.isEmpty(itemTreeTO.getNodeRef())) {
                    navigationOrderSequence.setFolderId(UUID.randomUUID().toString());
                } else {
                    navigationOrderSequence.setFolderId(itemTreeTO.getNodeRef());
                }
                if (currentMaxNavOrder < 0) {
                    navigationOrderSequence.setMaxCount(1000F * itemTreeTO.getNumOfChildren());
                } else {
                    double newMaxCount = currentMaxNavOrder + getPageNavigationOrderIncrement();
                    navigationOrderSequence.setMaxCount(newMaxCount);
                }
            }
            navigationOrderSequenceMapper.insert(navigationOrderSequence);
        } else {
            double newMaxCount = navigationOrderSequence.getMaxCount() + getPageNavigationOrderIncrement();
            navigationOrderSequence.setMaxCount(newMaxCount);
            navigationOrderSequenceMapper.update(navigationOrderSequence);
        }
        lastNavOrder = navigationOrderSequence.getMaxCount();
    } catch (Exception e) {
        logger.error("Unexpected error: ", e);
    }
    return lastNavOrder;
}
Also used : NavigationOrderSequence(org.craftercms.studio.api.v1.dal.NavigationOrderSequence) ContentItemTO(org.craftercms.studio.api.v1.to.ContentItemTO) HashMap(java.util.HashMap) RetryingOperation(org.craftercms.studio.api.v2.annotation.RetryingOperation) ValidateParams(org.craftercms.commons.validation.annotations.param.ValidateParams)

Aggregations

HashMap (java.util.HashMap)1 ValidateParams (org.craftercms.commons.validation.annotations.param.ValidateParams)1 NavigationOrderSequence (org.craftercms.studio.api.v1.dal.NavigationOrderSequence)1 ContentItemTO (org.craftercms.studio.api.v1.to.ContentItemTO)1 RetryingOperation (org.craftercms.studio.api.v2.annotation.RetryingOperation)1