Search in sources :

Example 16 with ModelAttribute

use of org.springframework.web.bind.annotation.ModelAttribute in project libresonic by Libresonic.

the class PlayerSettingsController method formBackingObject.

@ModelAttribute
protected void formBackingObject(HttpServletRequest request, Model model) throws Exception {
    handleRequestParameters(request);
    List<Player> players = getPlayers(request);
    User user = securityService.getCurrentUser(request);
    PlayerSettingsCommand command = new PlayerSettingsCommand();
    Player player = null;
    String playerId = request.getParameter("id");
    if (playerId != null) {
        player = playerService.getPlayerById(playerId);
    } else if (!players.isEmpty()) {
        player = players.get(0);
    }
    if (player != null) {
        command.setPlayerId(player.getId());
        command.setName(player.getName());
        command.setDescription(player.toString());
        command.setType(player.getType());
        command.setLastSeen(player.getLastSeen());
        command.setDynamicIp(player.isDynamicIp());
        command.setAutoControlEnabled(player.isAutoControlEnabled());
        command.setM3uBomEnabled(player.isM3uBomEnabled());
        command.setTranscodeSchemeName(player.getTranscodeScheme().name());
        command.setTechnologyName(player.getTechnology().name());
        command.setAllTranscodings(transcodingService.getAllTranscodings());
        List<Transcoding> activeTranscodings = transcodingService.getTranscodingsForPlayer(player);
        int[] activeTranscodingIds = new int[activeTranscodings.size()];
        for (int i = 0; i < activeTranscodings.size(); i++) {
            activeTranscodingIds[i] = activeTranscodings.get(i).getId();
        }
        command.setActiveTranscodingIds(activeTranscodingIds);
    }
    command.setTranscodingSupported(transcodingService.isDownsamplingSupported(null));
    command.setTranscodeDirectory(transcodingService.getTranscodeDirectory().getPath());
    command.setTranscodeSchemes(TranscodeScheme.values());
    command.setTechnologies(PlayerTechnology.values());
    command.setPlayers(players.toArray(new Player[players.size()]));
    command.setAdmin(user.isAdminRole());
    model.addAttribute("command", command);
}
Also used : PlayerSettingsCommand(org.libresonic.player.command.PlayerSettingsCommand) ModelAttribute(org.springframework.web.bind.annotation.ModelAttribute)

Example 17 with ModelAttribute

use of org.springframework.web.bind.annotation.ModelAttribute in project libresonic by Libresonic.

the class DatabaseSettingsController method formBackingObject.

@ModelAttribute
protected void formBackingObject(Model model) throws Exception {
    DatabaseSettingsCommand command = new DatabaseSettingsCommand();
    command.setConfigType(settingsService.getDatabaseConfigType());
    command.setEmbedDriver(settingsService.getDatabaseConfigEmbedDriver());
    command.setEmbedPassword(settingsService.getDatabaseConfigEmbedPassword());
    command.setEmbedUrl(settingsService.getDatabaseConfigEmbedUrl());
    command.setEmbedUsername(settingsService.getDatabaseConfigEmbedUsername());
    command.setJNDIName(settingsService.getDatabaseConfigJNDIName());
    command.setMysqlVarcharMaxlength(settingsService.getDatabaseMysqlVarcharMaxlength());
    command.setUsertableQuote(settingsService.getDatabaseUsertableQuote());
    model.addAttribute("command", command);
}
Also used : DatabaseSettingsCommand(org.libresonic.player.command.DatabaseSettingsCommand) ModelAttribute(org.springframework.web.bind.annotation.ModelAttribute)

Example 18 with ModelAttribute

use of org.springframework.web.bind.annotation.ModelAttribute in project libresonic by Libresonic.

the class GeneralSettingsController method formBackingObject.

@ModelAttribute
protected void formBackingObject(Model model) throws Exception {
    GeneralSettingsCommand command = new GeneralSettingsCommand();
    command.setCoverArtFileTypes(settingsService.getCoverArtFileTypes());
    command.setIgnoredArticles(settingsService.getIgnoredArticles());
    command.setShortcuts(settingsService.getShortcuts());
    command.setIndex(settingsService.getIndexString());
    command.setPlaylistFolder(settingsService.getPlaylistFolder());
    command.setMusicFileTypes(settingsService.getMusicFileTypes());
    command.setVideoFileTypes(settingsService.getVideoFileTypes());
    command.setSortAlbumsByYear(settingsService.isSortAlbumsByYear());
    command.setGettingStartedEnabled(settingsService.isGettingStartedEnabled());
    command.setWelcomeTitle(settingsService.getWelcomeTitle());
    command.setWelcomeSubtitle(settingsService.getWelcomeSubtitle());
    command.setWelcomeMessage(settingsService.getWelcomeMessage());
    command.setLoginMessage(settingsService.getLoginMessage());
    Theme[] themes = settingsService.getAvailableThemes();
    command.setThemes(themes);
    String currentThemeId = settingsService.getThemeId();
    for (int i = 0; i < themes.length; i++) {
        if (currentThemeId.equals(themes[i].getId())) {
            command.setThemeIndex(String.valueOf(i));
            break;
        }
    }
    Locale currentLocale = settingsService.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 (currentLocale.equals(locales[i])) {
            command.setLocaleIndex(String.valueOf(i));
        }
    }
    command.setLocales(localeStrings);
    model.addAttribute("command", command);
}
Also used : Locale(java.util.Locale) Theme(org.libresonic.player.domain.Theme) GeneralSettingsCommand(org.libresonic.player.command.GeneralSettingsCommand) ModelAttribute(org.springframework.web.bind.annotation.ModelAttribute)

Example 19 with ModelAttribute

use of org.springframework.web.bind.annotation.ModelAttribute in project oc-explorer by devgateway.

the class AwardsWonLostController method procurementsWonLost.

@ApiOperation(value = "Counts the won, lost procurements, flags and amounts. Receives any filters, " + "but most important here is the supplierId and bidderId. Requires bid extension. Use bidderId instead " + "of supplierId.")
@RequestMapping(value = "/api/procurementsWonLost", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
public List<ProcurementsWonLost> procurementsWonLost(@ModelAttribute @Valid final YearFilterPagingRequest filter) {
    Assert.notEmpty(filter.getBidderId(), "bidderId must not be empty!");
    Assert.isTrue(CollectionUtils.isEmpty(filter.getSupplierId()), "supplierId is not allowed here! Use bidderId to show results!");
    // supplier is the same thing as bidder for this particular query
    filter.setSupplierId(filter.getBidderId());
    Map<String, CriteriaDefinition> noSupplierCriteria = createDefaultFilterCriteriaMap(filter);
    noSupplierCriteria.remove(MongoConstants.Filters.SUPPLIER_ID);
    Aggregation agg1 = newAggregation(match(getYearDefaultFilterCriteria(filter, noSupplierCriteria, TENDER_PERIOD_START_DATE)), unwind("bids.details"), unwind("bids.details.tenderers"), match(getYearDefaultFilterCriteria(filter, noSupplierCriteria, TENDER_PERIOD_START_DATE)), group(BIDS_DETAILS_TENDERERS_ID).count().as("count").sum(BIDS_DETAILS_VALUE_AMOUNT).as("totalAmount").sum(FLAGS_TOTAL_FLAGGED).as("countFlags"), project("count", "totalAmount", "countFlags"));
    List<CountAmountFlags> applied = releaseAgg(agg1, CountAmountFlags.class);
    Aggregation agg2 = newAggregation(match(where(AWARDS_STATUS).is(Award.Status.active.toString()).andOperator(getYearDefaultFilterCriteria(filter, TENDER_PERIOD_START_DATE))), unwind("awards"), unwind("awards.suppliers"), match(where(AWARDS_STATUS).is(Award.Status.active.toString()).andOperator(getYearDefaultFilterCriteria(filter.awardFiltering(), TENDER_PERIOD_START_DATE))), group(MongoConstants.FieldNames.AWARDS_SUPPLIERS_ID).count().as("count").sum(MongoConstants.FieldNames.AWARDS_VALUE_AMOUNT).as("totalAmount").sum(FLAGS_TOTAL_FLAGGED).as("countFlags"), project("count", "totalAmount", "countFlags"));
    List<CountAmountFlags> won = releaseAgg(agg2, CountAmountFlags.class);
    ArrayList<ProcurementsWonLost> ret = new ArrayList<>();
    applied.forEach(a -> {
        ProcurementsWonLost r = new ProcurementsWonLost();
        r.setApplied(a);
        Optional<CountAmountFlags> optWon = won.stream().filter(w -> w.getId().equals(a.getId())).findFirst();
        if (optWon.isPresent()) {
            r.setWon(optWon.get());
            r.setLostAmount(r.getApplied().getTotalAmount().subtract(r.getWon().getTotalAmount()));
            r.setLostCount(r.getApplied().getCount() - r.getWon().getCount());
        } else {
            r.setLostAmount(r.getApplied().getTotalAmount());
            r.setLostCount(r.getLostCount());
        }
        ret.add(r);
    });
    return ret;
}
Also used : Aggregation.newAggregation(org.springframework.data.mongodb.core.aggregation.Aggregation.newAggregation) Aggregation(org.springframework.data.mongodb.core.aggregation.Aggregation) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) 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) AWARDS_SUPPLIERS_NAME(org.devgateway.ocds.persistence.mongo.constants.MongoConstants.FieldNames.AWARDS_SUPPLIERS_NAME) FLAGS_TOTAL_FLAGGED(org.devgateway.ocds.persistence.mongo.constants.MongoConstants.FieldNames.FLAGS_TOTAL_FLAGGED) Cacheable(org.springframework.cache.annotation.Cacheable) TENDER_PROCURING_ENTITY_ID(org.devgateway.ocds.persistence.mongo.constants.MongoConstants.FieldNames.TENDER_PROCURING_ENTITY_ID) Aggregation.sort(org.springframework.data.mongodb.core.aggregation.Aggregation.sort) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) Award(org.devgateway.ocds.persistence.mongo.Award) Aggregation.match(org.springframework.data.mongodb.core.aggregation.Aggregation.match) AggregationOperation(org.springframework.data.mongodb.core.aggregation.AggregationOperation) TENDER_PERIOD_START_DATE(org.devgateway.ocds.persistence.mongo.constants.MongoConstants.FieldNames.TENDER_PERIOD_START_DATE) Fields(org.springframework.data.mongodb.core.aggregation.Fields) MongoConstants(org.devgateway.ocds.persistence.mongo.constants.MongoConstants) Fields.field(org.springframework.data.mongodb.core.aggregation.Fields.field) 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) BIDS_DETAILS_TENDERERS_ID(org.devgateway.ocds.persistence.mongo.constants.MongoConstants.FieldNames.BIDS_DETAILS_TENDERERS_ID) AWARDS_STATUS(org.devgateway.ocds.persistence.mongo.constants.MongoConstants.FieldNames.AWARDS_STATUS) Map(java.util.Map) TENDER_PROCURING_ENTITY_NAME(org.devgateway.ocds.persistence.mongo.constants.MongoConstants.FieldNames.TENDER_PROCURING_ENTITY_NAME) Sort(org.springframework.data.domain.Sort) Aggregation.limit(org.springframework.data.mongodb.core.aggregation.Aggregation.limit) Criteria.where(org.springframework.data.mongodb.core.query.Criteria.where) Aggregation.skip(org.springframework.data.mongodb.core.aggregation.Aggregation.skip) AWARDS_SUPPLIERS_ID(org.devgateway.ocds.persistence.mongo.constants.MongoConstants.FieldNames.AWARDS_SUPPLIERS_ID) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) Aggregation.unwind(org.springframework.data.mongodb.core.aggregation.Aggregation.unwind) Aggregation(org.springframework.data.mongodb.core.aggregation.Aggregation) RestController(org.springframework.web.bind.annotation.RestController) Serializable(java.io.Serializable) List(java.util.List) BIDS_DETAILS_VALUE_AMOUNT(org.devgateway.ocds.persistence.mongo.constants.MongoConstants.FieldNames.BIDS_DETAILS_VALUE_AMOUNT) CriteriaDefinition(org.springframework.data.mongodb.core.query.CriteriaDefinition) CollectionUtils(org.springframework.util.CollectionUtils) Aggregation.project(org.springframework.data.mongodb.core.aggregation.Aggregation.project) CacheConfig(org.springframework.cache.annotation.CacheConfig) Optional(java.util.Optional) Assert(org.springframework.util.Assert) ArrayList(java.util.ArrayList) CriteriaDefinition(org.springframework.data.mongodb.core.query.CriteriaDefinition) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 20 with ModelAttribute

use of org.springframework.web.bind.annotation.ModelAttribute in project spring-framework by spring-projects.

the class ModelAttributeMethodProcessor method resolveArgument.

/**
	 * Resolve the argument from the model or if not found instantiate it with
	 * its default if it is available. The model attribute is then populated
	 * with request values via data binding and optionally validated
	 * if {@code @java.validation.Valid} is present on the argument.
	 * @throws BindException if data binding and validation result in an error
	 * and the next method parameter is not of type {@link Errors}.
	 * @throws Exception if WebDataBinder initialization fails.
	 */
@Override
public final Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
    String name = ModelFactory.getNameForParameter(parameter);
    Object attribute = (mavContainer.containsAttribute(name) ? mavContainer.getModel().get(name) : createAttribute(name, parameter, binderFactory, webRequest));
    if (!mavContainer.isBindingDisabled(name)) {
        ModelAttribute ann = parameter.getParameterAnnotation(ModelAttribute.class);
        if (ann != null && !ann.binding()) {
            mavContainer.setBindingDisabled(name);
        }
    }
    WebDataBinder binder = binderFactory.createBinder(webRequest, attribute, name);
    if (binder.getTarget() != null) {
        if (!mavContainer.isBindingDisabled(name)) {
            bindRequestParameters(binder, webRequest);
        }
        validateIfApplicable(binder, parameter);
        if (binder.getBindingResult().hasErrors() && isBindExceptionRequired(binder, parameter)) {
            throw new BindException(binder.getBindingResult());
        }
    }
    // Add resolved attribute and BindingResult at the end of the model
    Map<String, Object> bindingResultModel = binder.getBindingResult().getModel();
    mavContainer.removeAttributes(bindingResultModel);
    mavContainer.addAllAttributes(bindingResultModel);
    return binder.convertIfNecessary(binder.getTarget(), parameter.getParameterType(), parameter);
}
Also used : WebDataBinder(org.springframework.web.bind.WebDataBinder) ModelAttribute(org.springframework.web.bind.annotation.ModelAttribute) BindException(org.springframework.validation.BindException)

Aggregations

ModelAttribute (org.springframework.web.bind.annotation.ModelAttribute)35 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)15 ArrayList (java.util.ArrayList)3 LinkedHashMap (java.util.LinkedHashMap)3 Locale (java.util.Locale)3 DBObject (com.mongodb.DBObject)2 ApiOperation (io.swagger.annotations.ApiOperation)2 Method (java.lang.reflect.Method)2 BigDecimal (java.math.BigDecimal)2 List (java.util.List)2 Valid (javax.validation.Valid)2 MongoConstants (org.devgateway.ocds.persistence.mongo.constants.MongoConstants)2 YearFilterPagingRequest (org.devgateway.ocds.web.rest.controller.request.YearFilterPagingRequest)2 LoanProductRequest (org.mifos.dto.domain.LoanProductRequest)2 ReportCategoryDto (org.mifos.dto.domain.ReportCategoryDto)2 LoanProductFormDto (org.mifos.dto.screen.LoanProductFormDto)2 InvocableHandlerMethod (org.springframework.web.method.support.InvocableHandlerMethod)2 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 BasicDBObject (com.mongodb.BasicDBObject)1