use of org.springframework.web.bind.annotation.ModelAttribute in project libresonic by Libresonic.
the class PersonalSettingsController method formBackingObject.
@ModelAttribute
protected void formBackingObject(HttpServletRequest request, Model model) throws Exception {
PersonalSettingsCommand command = new PersonalSettingsCommand();
User user = securityService.getCurrentUser(request);
UserSettings userSettings = settingsService.getUserSettings(user.getUsername());
command.setUser(user);
command.setLocaleIndex("-1");
command.setThemeIndex("-1");
command.setAlbumLists(AlbumListType.values());
command.setAlbumListId(userSettings.getDefaultAlbumList().getId());
command.setAvatars(settingsService.getAllSystemAvatars());
command.setCustomAvatar(settingsService.getCustomAvatar(user.getUsername()));
command.setAvatarId(getAvatarId(userSettings));
command.setPartyModeEnabled(userSettings.isPartyModeEnabled());
command.setQueueFollowingSongs(userSettings.isQueueFollowingSongs());
command.setShowNowPlayingEnabled(userSettings.isShowNowPlayingEnabled());
command.setShowArtistInfoEnabled(userSettings.isShowArtistInfoEnabled());
command.setNowPlayingAllowed(userSettings.isNowPlayingAllowed());
command.setMainVisibility(userSettings.getMainVisibility());
command.setPlaylistVisibility(userSettings.getPlaylistVisibility());
command.setFinalVersionNotificationEnabled(userSettings.isFinalVersionNotificationEnabled());
command.setBetaVersionNotificationEnabled(userSettings.isBetaVersionNotificationEnabled());
command.setSongNotificationEnabled(userSettings.isSongNotificationEnabled());
command.setAutoHidePlayQueue(userSettings.isAutoHidePlayQueue());
command.setListReloadDelay(userSettings.getListReloadDelay());
command.setKeyboardShortcutsEnabled(userSettings.isKeyboardShortcutsEnabled());
command.setLastFmEnabled(userSettings.isLastFmEnabled());
command.setLastFmUsername(userSettings.getLastFmUsername());
command.setLastFmPassword(userSettings.getLastFmPassword());
command.setPaginationSize(userSettings.getPaginationSize());
Locale currentLocale = userSettings.getLocale();
Locale[] locales = settingsService.getAvailableLocales();
String[] localeStrings = new String[locales.length];
for (int i = 0; i < locales.length; i++) {
localeStrings[i] = locales[i].getDisplayName(locales[i]);
if (locales[i].equals(currentLocale)) {
command.setLocaleIndex(String.valueOf(i));
}
}
command.setLocales(localeStrings);
String currentThemeId = userSettings.getThemeId();
Theme[] themes = settingsService.getAvailableThemes();
command.setThemes(themes);
for (int i = 0; i < themes.length; i++) {
if (themes[i].getId().equals(currentThemeId)) {
command.setThemeIndex(String.valueOf(i));
break;
}
}
model.addAttribute("command", command);
}
use of org.springframework.web.bind.annotation.ModelAttribute in project libresonic by Libresonic.
the class MusicFolderSettingsController method formBackingObject.
@ModelAttribute
protected void formBackingObject(@RequestParam(value = "scanNow", required = false) String scanNow, @RequestParam(value = "expunge", required = false) String expunge, Model model) throws Exception {
MusicFolderSettingsCommand command = new MusicFolderSettingsCommand();
if (scanNow != null) {
settingsService.clearMusicFolderCache();
mediaScannerService.scanLibrary();
}
if (expunge != null) {
expunge();
}
command.setInterval(String.valueOf(settingsService.getIndexCreationInterval()));
command.setHour(String.valueOf(settingsService.getIndexCreationHour()));
command.setFastCache(settingsService.isFastCacheEnabled());
command.setOrganizeByFolderStructure(settingsService.isOrganizeByFolderStructure());
command.setScanning(mediaScannerService.isScanning());
command.setMusicFolders(wrap(settingsService.getAllMusicFolders(true, true)));
command.setNewMusicFolder(new MusicFolderSettingsCommand.MusicFolderInfo());
model.addAttribute("command", command);
}
use of org.springframework.web.bind.annotation.ModelAttribute in project ocvn by devgateway.
the class TenderPriceByTypeYearController method tenderPriceByAllBidSelectionMethods.
@ApiOperation(value = "Same as /api/tenderPriceByBidSelectionMethod, but it always returns " + "all bidSelectionMethods (it adds the missing bid selection methods with zero totals")
@RequestMapping(value = "/api/tenderPriceByAllBidSelectionMethods", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
public List<DBObject> tenderPriceByAllBidSelectionMethods(@ModelAttribute @Valid final YearFilterPagingRequest filter) {
List<DBObject> tenderPriceByBidSelectionMethod = tenderPriceByBidSelectionMethod(filter);
// create a treeset ordered by procurment method details key
Collection<DBObject> ret = new TreeSet<>((DBObject o1, DBObject o2) -> o1.get(Keys.PROCUREMENT_METHOD_DETAILS).toString().compareTo(o2.get(Keys.PROCUREMENT_METHOD_DETAILS).toString()));
// add them all to sorted set
for (DBObject o : tenderPriceByBidSelectionMethod) {
if (o.containsField(Keys.PROCUREMENT_METHOD_DETAILS) && o.get(Keys.PROCUREMENT_METHOD_DETAILS) != null) {
ret.add(o);
} else {
o.put(Keys.PROCUREMENT_METHOD_DETAILS, UNSPECIFIED);
ret.add(o);
}
}
// get all the non null bid selection methods
Set<Object> bidSelectionMethods = bidSelectionMethodSearchController.bidSelectionMethods().stream().filter(e -> e.get(Fields.UNDERSCORE_ID) != null).map(e -> e.get(Fields.UNDERSCORE_ID)).collect(Collectors.toCollection(LinkedHashSet::new));
bidSelectionMethods.add(UNSPECIFIED);
// remove elements that already are in the result
bidSelectionMethods.removeAll(ret.stream().map(e -> e.get(Keys.PROCUREMENT_METHOD_DETAILS)).collect(Collectors.toSet()));
// add the missing procurementmethoddetails with zero amounts
bidSelectionMethods.forEach(e -> {
DBObject obj = new BasicDBObject(Keys.PROCUREMENT_METHOD_DETAILS, e.toString());
obj.put(Keys.TOTAL_TENDER_AMOUNT, BigDecimal.ZERO);
ret.add(obj);
});
return new ArrayList<>(ret);
}
use of org.springframework.web.bind.annotation.ModelAttribute in project ORCID-Source by ORCID.
the class SelfServiceController method retrieveContactRoleTypesAsMap.
@ModelAttribute("contactRoleTypes")
public Map<String, String> retrieveContactRoleTypesAsMap() {
Map<String, String> map = new LinkedHashMap<>();
for (ContactRoleType type : ContactRoleType.values()) {
map.put(type.name(), getMessage(buildInternationalizationKey(ContactRoleType.class, type.name())));
}
Map<String, String> sorted = new LinkedHashMap<>();
// @formatter:off
map.entrySet().stream().sorted(Map.Entry.<String, String>comparingByValue()).forEachOrdered(x -> sorted.put(x.getKey(), x.getValue()));
// @formatter:on
return sorted;
}
use of org.springframework.web.bind.annotation.ModelAttribute in project ORCID-Source by ORCID.
the class BaseController method getStaticCdnPath.
/**
* Return the path where the static content will be. If there is a cdn path
* configured, it will return the cdn path; if it is not a cdn path it will
* return a reference to the static folder "/static"
*
* @return the path to the CDN or the path to the local static content
*/
@ModelAttribute("staticCdn")
@Cacheable("staticContent")
public String getStaticCdnPath(HttpServletRequest request) {
if (StringUtils.isEmpty(this.cdnConfigFile)) {
return getStaticContentPath(request);
}
ClassPathResource configFile = new ClassPathResource(this.cdnConfigFile);
if (configFile.exists()) {
try (InputStream is = configFile.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is))) {
String uri = br.readLine();
if (uri != null) {
String releaseVersion = ReleaseNameUtils.getReleaseName();
if (!uri.contains(releaseVersion)) {
if (!uri.endsWith("/")) {
uri += '/';
}
uri += releaseVersion;
}
this.staticCdnPath = uri;
}
} catch (IOException e) {
e.printStackTrace();
}
}
if (StringUtils.isBlank(this.staticCdnPath))
return getStaticContentPath(request);
return staticCdnPath;
}
Aggregations