Search in sources :

Example 66 with ContentItemTO

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

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