blob: 3b0418dab1b680edd3f2414eb4c3ca917bc99ac2 [file] [log] [blame]
/*********************************************************************************
* Copyright (c) 2020 Robert Bosch GmbH and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Robert Bosch GmbH - initial API and implementation
********************************************************************************
*/
package org.eclipse.app4mc.cloud.manager;
import java.util.stream.Collectors;
import org.eclipse.app4mc.cloud.manager.storage.StorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder;
@Controller
public class WorkflowResultController {
@Autowired
private StorageService storageService;
@GetMapping("/workflowResults")
public String workflowResults(Model model) {
model.addAttribute("workflows", storageService.loadAll()
.map(path -> path.toString().substring(path.toString().lastIndexOf('_') + 1))
.collect(Collectors.toMap(
uuid -> {
WorkflowStatus status = WorkflowStatusHelper.loadWorkflowStatus(storageService.load(uuid, "workflowstatus.json").toFile());
return (status != null && status.getName() != null) ? status.getName() : uuid;
},
uuid -> MvcUriComponentsBuilder.fromMethodName(WorkflowController.class,
"workflow",
model,
uuid).build().toUri().toString()))
);
// render the form view
return "workflowResults";
}
@GetMapping("/deleteAllResults")
public String delete(Model model) {
storageService.deleteAll();
// remove possible status from model
model.addAttribute("workflowStatus", new WorkflowStatus());
return "redirect:/workflowResults";
}
}