Search in sources :

Example 31 with ModelAttribute

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));
}
Also used : ModelAttribute(org.springframework.web.bind.annotation.ModelAttribute)

Example 32 with ModelAttribute

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);
}
Also used : Locale(java.util.Locale) PersonalSettingsCommand(org.libresonic.player.command.PersonalSettingsCommand) ModelAttribute(org.springframework.web.bind.annotation.ModelAttribute)

Example 33 with ModelAttribute

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);
}
Also used : MusicFolderSettingsCommand(org.libresonic.player.command.MusicFolderSettingsCommand) ModelAttribute(org.springframework.web.bind.annotation.ModelAttribute)

Example 34 with ModelAttribute

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);
}
Also used : YearFilterPagingRequest(org.devgateway.ocds.web.rest.controller.request.YearFilterPagingRequest) Aggregation.group(org.springframework.data.mongodb.core.aggregation.Aggregation.group) Aggregation.newAggregation(org.springframework.data.mongodb.core.aggregation.Aggregation.newAggregation) Cacheable(org.springframework.cache.annotation.Cacheable) Aggregation.sort(org.springframework.data.mongodb.core.aggregation.Aggregation.sort) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) Aggregation.match(org.springframework.data.mongodb.core.aggregation.Aggregation.match) Fields(org.springframework.data.mongodb.core.aggregation.Fields) MongoConstants(org.devgateway.ocds.persistence.mongo.constants.MongoConstants) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) Valid(javax.validation.Valid) ApiOperation(io.swagger.annotations.ApiOperation) BigDecimal(java.math.BigDecimal) ModelAttribute(org.springframework.web.bind.annotation.ModelAttribute) DBObject(com.mongodb.DBObject) Direction(org.springframework.data.domain.Sort.Direction) LinkedHashSet(java.util.LinkedHashSet) Criteria.where(org.springframework.data.mongodb.core.query.Criteria.where) Collection(java.util.Collection) BasicDBObject(com.mongodb.BasicDBObject) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) Set(java.util.Set) BidSelectionMethodSearchController(org.devgateway.ocds.web.rest.controller.selector.BidSelectionMethodSearchController) AggregationResults(org.springframework.data.mongodb.core.aggregation.AggregationResults) Aggregation(org.springframework.data.mongodb.core.aggregation.Aggregation) RestController(org.springframework.web.bind.annotation.RestController) Collectors(java.util.stream.Collectors) List(java.util.List) Aggregation.project(org.springframework.data.mongodb.core.aggregation.Aggregation.project) CacheConfig(org.springframework.cache.annotation.CacheConfig) CustomProjectionOperation(org.devgateway.toolkit.persistence.mongo.aggregate.CustomProjectionOperation) BasicDBObject(com.mongodb.BasicDBObject) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ModelAttribute (org.springframework.web.bind.annotation.ModelAttribute)34 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)14 LinkedHashMap (java.util.LinkedHashMap)3 Locale (java.util.Locale)3 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 AuditLogDto (org.mifos.dto.domain.AuditLogDto)2 LoanProductRequest (org.mifos.dto.domain.LoanProductRequest)2 ReportCategoryDto (org.mifos.dto.domain.ReportCategoryDto)2 AuditLogScreenDto (org.mifos.dto.screen.AuditLogScreenDto)2 LoanProductFormDto (org.mifos.dto.screen.LoanProductFormDto)2 InvocableHandlerMethod (org.springframework.web.method.support.InvocableHandlerMethod)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 BasicDBObject (com.mongodb.BasicDBObject)1 DBObject (com.mongodb.DBObject)1 UserAccount (com.springone.myrestaurants.domain.UserAccount)1 IncludePage (freemarker.ext.servlet.IncludePage)1 ApiOperation (io.swagger.annotations.ApiOperation)1 IOException (java.io.IOException)1 BigDecimal (java.math.BigDecimal)1