Created
July 17, 2013 14:20
-
-
Save ramrrr/6020969 to your computer and use it in GitHub Desktop.
AlertComposer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package heimdall.ui.send; | |
| import java.util.LinkedHashMap; | |
| import java.util.Map; | |
| import heimdall.auth.UserContext; | |
| import heimdall.channel.voice.VoiceModule; | |
| import heimdall.module.Module; | |
| import heimdall.module.ModuleRepository; | |
| import heimdall.module.AccessResourceImpl.ResourceType; | |
| import heimdall.risk.EventRepository; | |
| import heimdall.ui.core.menu.MenuEntry; | |
| import heimdall.utility.VoiceChannelConfigHelper; | |
| import org.springframework.beans.factory.annotation.Autowired; | |
| import org.springframework.security.access.annotation.Secured; | |
| import org.springframework.stereotype.Controller; | |
| import org.springframework.ui.Model; | |
| import org.springframework.web.bind.annotation.RequestMapping; | |
| /** | |
| * @author Ståle Undheim <su@ums.no> | |
| */ | |
| @Controller | |
| @RequestMapping("/sendDirect") | |
| @MenuEntry(value = "send.menu", rank = 20, secured = @Secured("MODULE:sendModule"), link = false) | |
| public class AlertComposer { | |
| private EventRepository eventRepository; | |
| private ModuleRepository moduleRepository; | |
| private UserContext userContext; | |
| @Autowired | |
| public void setEventRepository(final EventRepository eventRepository) { | |
| this.eventRepository = eventRepository; | |
| } | |
| @Autowired | |
| public void setModuleRepository(final ModuleRepository moduleRepository) { | |
| this.moduleRepository = moduleRepository; | |
| } | |
| @Autowired | |
| public void setUserContext(final UserContext userContext) { | |
| this.userContext = userContext; | |
| } | |
| /** | |
| * Return the view name for the composer view. | |
| * | |
| * @param model to populate. | |
| * @return the composer view. | |
| */ | |
| @RequestMapping("/composer") | |
| @MenuEntry(value = "composer.menu", rank = 1000) | |
| public String composer(final Model model) { | |
| model.addAttribute("eventName", eventRepository.nextEventName()); | |
| model.addAttribute("voiceNoOfTries", | |
| VoiceChannelConfigHelper.getNumberOfTries()); | |
| model.addAttribute("voiceHangupTimes", | |
| VoiceChannelConfigHelper.getNoOfCallTimes()); | |
| model.addAttribute("voiceIntervalOfTries", | |
| VoiceChannelConfigHelper.getIntervalTimes()); | |
| Map<String, String> priorities = new LinkedHashMap<>(); | |
| for (int i = getPriority(); i <= 8; i++) { | |
| priorities.put(String.valueOf(i), String.valueOf(i)); | |
| } | |
| model.addAttribute("voicePriorities", priorities); | |
| model.addAttribute("voiceMaxoutboundLines", getMaxOutboundLines()); | |
| return "/sendDirect/alertComposer"; | |
| } | |
| /** | |
| * Gets the priority for the voice message | |
| * @return | |
| */ | |
| private int getPriority() { | |
| int priority = 0; | |
| for (Module module : moduleRepository.getModules()) { | |
| if (module instanceof VoiceModule) { | |
| priority = userContext.getOrganization() | |
| .getAccessResourceValue(module, | |
| userContext.getOrganization(), | |
| ResourceType.PRIOROTY); | |
| } | |
| } | |
| return priority; | |
| } | |
| /** | |
| * gets the maximum number of outbound lines | |
| * @return | |
| */ | |
| private int getMaxOutboundLines() { | |
| int maxOutboundLines = 0; | |
| for (Module module : moduleRepository.getModules()) { | |
| if (module instanceof VoiceModule) { | |
| maxOutboundLines = userContext.getOrganization() | |
| .getAccessResourceValue(module, | |
| userContext.getOrganization(), | |
| ResourceType.OUTBOUND_LINES); | |
| } | |
| } | |
| return maxOutboundLines; | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment