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;
}
Aggregations