use of org.springframework.web.bind.annotation.ModelAttribute in project spring-framework by spring-projects.
the class ModelFactory method getNameForParameter.
/**
* Derive the model attribute name for a method parameter based on:
* <ol>
* <li>the parameter {@code @ModelAttribute} annotation value
* <li>the parameter type
* </ol>
* @param parameter a descriptor for the method parameter
* @return the derived name (never {@code null} or empty String)
*/
public static String getNameForParameter(MethodParameter parameter) {
ModelAttribute ann = parameter.getParameterAnnotation(ModelAttribute.class);
String name = (ann != null ? ann.value() : null);
return (StringUtils.hasText(name) ? name : Conventions.getVariableNameForParameter(parameter));
}
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);
}
Aggregations