package no.dusken.aranea.web.control;
import no.dusken.aranea.model.Person;
import no.dusken.aranea.model.Role;
import no.dusken.aranea.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* @author Benjamin Bjørnseth <benjamin@underdusken.no>
*/
@Controller
public class ContactPageController {
private RoleService roleService;
private final String contactPageViewLocation = "no/dusken/aranea/base/common/contact";
private final String[] roles = {
"Ansvarlig redakt\u00f8r",
"Gjengsjef",
"Nyhetsredakt\u00f8r",
"Kulturredakt\u00f8r",
"Reportasjeredakt\u00f8r",
"Nettredakt\u00f8r",
"Fotoredakt\u00f8r",
"Grafisk ansvarlig",
"Annonseansvarlig",
"Debatt- og kronikkansvarlig",
"Maskinist"
};
@RequestMapping("/contact.do")
public String getContactPageView(Model model) {
Map<String, Person> persons = new LinkedHashMap<String, Person>();
for (String roleAsStr: roles) {
Role role = roleService.getRolesByName(roleAsStr);
if (role != null && role.getPersons() != null && role.getPersons().size() > 0) {
for (Person p : role.getPersons()) {
if (p.getActive()) {
persons.put(roleAsStr, p);
break;
}
}
}
}
model.addAttribute("persons", persons);
return contactPageViewLocation;
}
@Autowired
public void setRoleService(RoleService roleService) {
this.roleService = roleService;
}
public String[] getRoles() {
return roles;
}
}