Search in sources :

Example 41 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 42 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 43 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)

Example 44 with ModelAttribute

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;
}
Also used : ContactRoleType(org.orcid.core.salesforce.model.ContactRoleType) LinkedHashMap(java.util.LinkedHashMap) ModelAttribute(org.springframework.web.bind.annotation.ModelAttribute)

Example 45 with ModelAttribute

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;
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) ClassPathResource(org.springframework.core.io.ClassPathResource) Cacheable(org.springframework.cache.annotation.Cacheable) ModelAttribute(org.springframework.web.bind.annotation.ModelAttribute)

Aggregations

ModelAttribute (org.springframework.web.bind.annotation.ModelAttribute)59 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)19 IOException (java.io.IOException)7 Valid (javax.validation.Valid)6 RequestMethod (org.springframework.web.bind.annotation.RequestMethod)6 SimpleDateFormat (java.text.SimpleDateFormat)5 LinkedHashMap (java.util.LinkedHashMap)5 HttpSession (javax.servlet.http.HttpSession)5 Autowired (org.springframework.beans.factory.annotation.Autowired)5 Sort (org.springframework.data.domain.Sort)5 FileNotFoundException (java.io.FileNotFoundException)4 DateFormat (java.text.DateFormat)4 java.util (java.util)4 Callable (java.util.concurrent.Callable)4 ExecutionException (java.util.concurrent.ExecutionException)4 ExecutorService (java.util.concurrent.ExecutorService)4 Executors (java.util.concurrent.Executors)4 Future (java.util.concurrent.Future)4 TimeUnit (java.util.concurrent.TimeUnit)4 PreDestroy (javax.annotation.PreDestroy)4