class ViewConfigController extends BaseController {

    @RequestMapping(path = "/copy/{id}", method = RequestMethod.POST)
    @Transactional
    public String copyView(@PathVariable final Long id, final RedirectAttributes redirectAttributes) {
        // Retrieve it
        if (!viewRepository.existsById(id)) {
            // Set flash message & redirect
            redirectAttributes.addFlashAttribute("FlashMessage", FlashMessage.newWarning("Unable to find view!"));
        } else {
            // Retrieve view
            viewRepository.findById(id).ifPresent((view) -> {
                // Create Copy manager
                final ViewCopyManager copyManager = new ViewCopyManager(viewRepository);
                final String newName = "Copy of " + view.getName();
                copyManager.copy(view, newName);

                redirectAttributes.addFlashAttribute(
                    "FlashMessage",
                    FlashMessage.newSuccess("Copied view using name '" + newName + "'!")
                );
            });
        }

        // redirect to cluster index
        return "redirect:/configuration/view";
    }

}