Example usage for org.springframework.ui ModelMap addAllAttributes

List of usage examples for org.springframework.ui ModelMap addAllAttributes

Introduction

In this page you can find the example usage for org.springframework.ui ModelMap addAllAttributes.

Prototype

public ModelMap addAllAttributes(@Nullable Map<String, ?> attributes) 

Source Link

Document

Copy all attributes in the supplied Map into this Map .

Usage

From source file:ru.codemine.ccms.router.SalesRouter.java

@Secured("ROLE_OFFICE")
@RequestMapping(value = "/management/setPlan", method = RequestMethod.GET)
public String getPlanSetupPage(@RequestParam(required = false) String dateMonth,
        @RequestParam(required = false) String dateYear, ModelMap model) {
    model.addAllAttributes(utils.prepareModel(dateMonth, dateYear));

    model.addAttribute("organisationList", organisationService.getAll());
    model.addAttribute("salesMap", utils.getShopSalesMap(dateMonth, dateYear));

    return "management/setPlan";
}

From source file:ru.codemine.ccms.router.SalesRouter.java

@Secured("ROLE_OFFICE")
@RequestMapping(value = "/reports/sales-pass", method = RequestMethod.GET)
public String getSalesPassReport(@RequestParam(required = false) String dateStartStr,
        @RequestParam(required = false) String dateEndStr, @RequestParam(required = false) String mode,
        ModelMap model) {

    model.addAllAttributes(utils.prepareModel());

    DateTimeFormatter formatter = DateTimeFormat.forPattern("dd.MM.YYYY");
    LocalDate dateStart = dateStartStr == null ? LocalDate.now().withDayOfMonth(1)
            : formatter.parseLocalDate(dateStartStr).withDayOfMonth(1);
    LocalDate dateEnd = dateEndStr == null ? LocalDate.now().dayOfMonth().withMaximumValue()
            : formatter.parseLocalDate(dateEndStr).dayOfMonth().withMaximumValue();

    if (dateEnd.isBefore(dateStart))
        dateEnd = dateStart.dayOfMonth().withMaximumValue();

    model.addAttribute("dateStartStr", dateStart.toString("dd.MM.YYYY"));
    model.addAttribute("dateEndStr", dateEnd.toString("dd.MM.YYYY"));

    List<String> subgridColNames = new ArrayList<>();
    subgridColNames.add("?");

    if (dateStart.getMonthOfYear() == dateEnd.getMonthOfYear()) {
        for (int i = 1; i <= dateEnd.getDayOfMonth(); i++) {
            subgridColNames.add(String.valueOf(i) + dateStart.toString(".MM.YY"));
        }//from  w ww. j  av a 2  s  . co m
    } else {
        LocalDate printDate = dateStart;
        while (printDate.isBefore(dateEnd)) {
            subgridColNames.add(printDate.toString("MMM YYYY"));
            printDate = printDate.plusMonths(1);
        }
    }

    subgridColNames.add("");

    model.addAttribute("subgridColNames", subgridColNames);

    return "print".equals(mode) ? "printforms/reports/salesAllFrm" : "reports/sales-pass";
}

From source file:ru.codemine.ccms.router.SalesRouter.java

@Secured("ROLE_OFFICE")
@RequestMapping(value = "/reports/graph/sales-pass", method = RequestMethod.GET)
public String getSalesPassGraph(@RequestParam(required = false) String dateStartStr,
        @RequestParam(required = false) String dateEndStr, @RequestParam(required = false) Integer shopid,
        ModelMap model) {
    model.addAllAttributes(utils.prepareModel());

    List<Shop> shopList = shopService.getAllOpen();
    List<String> graphDataDayTotal = new ArrayList<>();
    List<String> graphDataPassability = new ArrayList<>();

    Shop shop = shopid == null ? shopList.get(0) : shopService.getById(shopid);

    model.addAttribute("shop", shop);
    model.addAttribute("shopList", shopList);

    DateTimeFormatter formatter = DateTimeFormat.forPattern("dd.MM.YYYY");
    LocalDate dateStart = dateStartStr == null ? LocalDate.now().withDayOfMonth(1)
            : formatter.parseLocalDate(dateStartStr).withDayOfMonth(1);
    LocalDate dateEnd = dateEndStr == null ? LocalDate.now().dayOfMonth().withMaximumValue()
            : formatter.parseLocalDate(dateEndStr).dayOfMonth().withMaximumValue();

    if (dateEnd.isBefore(dateStart))
        dateEnd = dateStart.dayOfMonth().withMaximumValue();

    model.addAttribute("dateStartStr", dateStart.toString("dd.MM.YYYY"));
    model.addAttribute("dateEndStr", dateEnd.toString("dd.MM.YYYY"));

    List<SalesMeta> smList = salesService.getByPeriod(shop, dateStart, dateEnd);

    for (Sales sales : salesService.getAllSalesFromMetaList(smList)) {
        if (shop.isCountersEnabled()) {
            Counter counter = counterService.getByShopAndDate(shop,
                    sales.getDate().toDateTime(LocalTime.MIDNIGHT));
            if (sales.getPassability() == 0)
                sales.setPassability(counter == null ? 0 : counter.getIn());
        }/* w ww  .  j  a  va 2  s. c o  m*/

        graphDataDayTotal.add(sales.getGraphDataDayTotal());
        graphDataPassability.add(sales.getGraphDataPassability());
    }

    model.addAttribute("graphDataDayTotal", graphDataDayTotal);
    model.addAttribute("graphDataPassability", graphDataPassability);

    return "reports/sales-pass-graph";
}

From source file:org.agatom.springatom.cmp.wizards.data.context.WizardDataScopeHolder.java

@SuppressWarnings("unchecked")
private WizardDataScopeHolder addData(final DataScope scope, final String key, final Object data) {
    LOGGER.trace(//from w  ww  .j a v a  2  s .  co m
            String.format("addData(scope=%s,key=%s,data=%s)", scope, key, ObjectUtils.getDisplayString(data)));
    if (data == null) {
        LOGGER.trace(String.format("Cannot add data, because it is null"));
        return this;
    } else if (ClassUtils.isAssignableValue(Collection.class, data) && ((Collection<?>) data).isEmpty()) {
        LOGGER.trace(String.format("Data is an empty collection, wont be added"));
        return this;
    } else if (ClassUtils.isAssignableValue(Map.class, data) && ((Map<?, ?>) data).isEmpty()) {
        LOGGER.trace(String.format("Data is an empty collection, wont be added"));
        return this;
    }
    ModelMap localHolder = this.data.get(scope);
    if (localHolder == null) {
        localHolder = new ModelMap();
        this.data.put(scope, localHolder);
    }

    final boolean isMap = ClassUtils.isAssignableValue(Map.class, data);
    final boolean isCollection = ClassUtils.isAssignableValue(Collection.class, data);
    final boolean keyHasText = StringUtils.hasText(key);

    if (isMap && !keyHasText) {
        localHolder.addAllAttributes((Map<String, ?>) data);
    } else if (isCollection && !keyHasText) {
        localHolder.addAllAttributes((Collection<?>) data);
    } else if (!keyHasText) {
        localHolder.addAttribute(data);
    } else {
        localHolder.addAttribute(key, data);
    }

    return this;
}

From source file:ru.codemine.ccms.router.SalesRouter.java

@Secured("ROLE_USER")
@RequestMapping(value = "/sales", method = RequestMethod.GET)
public String getSalesPage(@RequestParam Integer shopid, @RequestParam(required = false) String dateMonth,
        @RequestParam(required = false) String dateYear, ModelMap model) {
    Shop shop = shopService.getById(shopid);

    model.addAllAttributes(utils.prepareModel(dateMonth, dateYear));

    LocalDate selectedStartDate;// w  w w . j a v  a 2 s.  co m
    LocalDate selectedEndDate;
    DateTimeFormatter formatter = DateTimeFormat.forPattern("dd MMMM YYYY");
    if (dateMonth != null && dateYear != null) //  
    {
        selectedStartDate = formatter.parseLocalDate("01 " + dateMonth + " " + dateYear);
        selectedEndDate = selectedStartDate.dayOfMonth().withMaximumValue();
    } else // -  ??,  
    {
        selectedStartDate = LocalDate.now().withDayOfMonth(1);
        selectedEndDate = selectedStartDate.dayOfMonth().withMaximumValue();
    }

    SalesMeta salesMeta = salesService.getByShopAndDate(shop, selectedStartDate, selectedEndDate);

    if (shop.isCountersEnabled()) {
        for (Sales s : salesMeta.getSales()) {
            Counter counter = counterService.getByShopAndDate(shop, s.getDate().toDateTime(LocalTime.MIDNIGHT));
            s.setPassability(counter == null ? 0 : counter.getIn());
        }
    }

    model.addAttribute("salesMeta", salesMeta);
    model.addAttribute("shop", shop);

    return "pages/shops/sales";
}

From source file:ru.codemine.ccms.router.TaskRouter.java

@Secured("ROLE_USER")
@RequestMapping(value = "/tasks/taskinfo", method = RequestMethod.GET)
public String getTaskinfo(@RequestParam("id") Integer id, ModelMap model) {
    Task task = taskService.getById(id);
    Employee currentUser = employeeService.getCurrentUser();

    if (!task.isInTask(currentUser) && !currentUser.getRoles().contains("ROLE_ADMIN") && task.hasPerformer())
        throw new ResourceNotFoundException();

    model.addAllAttributes(utils.prepareModel());
    model.addAttribute("openTasksCount", taskService.getOpenTaskCount());
    model.addAttribute("task", task);
    model.addAttribute("newcomment", new Comment(employeeService.getCurrentUser()));
    model.addAttribute("allEmps", employeeService.getActive());

    return "pages/tasks/taskinfo";
}

From source file:ru.codemine.ccms.router.ExpencesRouter.java

@Secured("ROLE_OFFICE")
@RequestMapping(value = "/expences", method = RequestMethod.GET)
public String getExpencesPage(@RequestParam(required = false) Integer shopid,
        @RequestParam(required = false) String dateYear, @RequestParam(required = false) String mode,
        ModelMap model) {
    if (dateYear == null)
        dateYear = LocalDate.now().toString("YYYY");
    if (shopid == null)
        shopid = shopService.getAll().get(0).getId();

    DateTimeFormatter formatter = DateTimeFormat.forPattern("dd.MM.YYYY");
    LocalDate startDate = formatter.parseLocalDate("01.01." + dateYear);
    LocalDate endDate = formatter.parseLocalDate("31.12." + dateYear);

    Shop shop = shopService.getById(shopid);
    List<Shop> shopList = shopService.getAllOpen();

    List<ExpenceType> allExpTypes = expenceTypeService.getAll();
    Set<ExpenceType> addedExpTypes = salesService.getExpenceTypesByPeriod(shop, startDate, endDate);

    model.addAllAttributes(utils.prepareModel());
    model.addAttribute("shop", shop);
    model.addAttribute("shopList", shopList);
    model.addAttribute("selectedYear", dateYear);
    model.addAttribute("yearList", utils.getYearStrings());
    model.addAttribute("allExpTypes", allExpTypes);
    model.addAttribute("addedExpTypes", addedExpTypes);
    model.addAttribute("expenceTypesForm", new ExpenceTypesForm());

    return "print".equals(mode) ? "printforms/expences" : "pages/shops/expences";
}

From source file:com.citrix.cpbm.portal.fragment.controllers.AbstractSubscriptionController.java

@RequestMapping(value = ("/browse_catalog"), method = RequestMethod.GET)
public String anonymousCatalog(ModelMap map,
        @RequestParam(value = "serviceInstanceUUID", required = false) final String serviceInstanceUUID,
        @RequestParam(value = "currencyCode", required = false) String currencyCode,
        @RequestParam(value = "resourceType", required = false) final String resourceType,
        @RequestParam(value = "channelCode", required = false) final String channelCode,
        final HttpServletRequest request) {
    logger.debug("### anonymousCatalog method starting...(GET)");
    final String successView = "anonymous.catalog";
    if (config.getValue(Names.com_citrix_cpbm_public_catalog_display).equals("true")) {

        Channel channel = null;//  ww w .ja  v a  2  s  .c  om
        if (StringUtils.isNotBlank(channelCode)) {
            channel = channelService.locateByChannelCode(channelCode);
        } else {
            channel = channelService.getDefaultServiceProviderChannel();
        }

        final Catalog catalog = channel.getCatalog();
        List<CurrencyValue> currencies = catalog.getSupportedCurrencyValuesByOrder();
        map.addAttribute("channel", channel);
        map.addAttribute("currencies", currencies);
        map.addAttribute("anonymousBrowsing", true);
        CurrencyValue currency = currencies.get(0);
        if (StringUtils.isNotBlank(currencyCode)) {
            currency = currencyValueService.locateBYCurrencyCode(currencyCode);
        }
        map.addAttribute("selectedCurrency", currency);
        map.addAttribute(UserContextInterceptor.MIN_FRACTION_DIGITS,
                Currency.getInstance(currency.getCurrencyCode()).getDefaultFractionDigits());

        final Tenant tenant = tenantService.getSystemTenant();
        final Channel finalChannel = channel;
        Map<String, Object> finalMap = privilegeService
                .runAsPortal(new PrivilegedAction<Map<String, Object>>() {

                    @Override
                    public Map<String, Object> run() {
                        ModelMap modelMap = new ModelMap();
                        try {
                            getResourceComponentsAndFilterData(tenant, null, serviceInstanceUUID, null,
                                    resourceType, modelMap, request, successView, finalChannel.getName());
                        } catch (ConnectorManagementServiceException e) {
                            logger.debug("Error occured ", e);
                        }
                        return modelMap;
                    }
                });
        map.addAllAttributes(finalMap);
        map.addAttribute("supportedLocaleList", this.getLocaleDisplayName(listSupportedLocales()));
        // anonymousBrowsing and preview catalog will have default UI Because in cutom UI SSO happens which can leads to
        // security threats
        map.addAttribute("customEditorTag", null);
        map.addAttribute("customComponentSelector", null);
    } else {
        throw new NoSuchDefinitionException();
    }
    return successView;
}

From source file:com.citrix.cpbm.portal.fragment.controllers.AbstractSubscriptionController.java

@RequestMapping(value = ("/view_catalog"), method = RequestMethod.GET)
public String previewCatalog(@RequestParam(value = "channelParam", required = false) String channelParam,
        ModelMap map, @RequestParam(value = "tenant", required = false) final String tenantParam,
        @RequestParam(value = "serviceInstanceUUID", required = false) final String serviceInstanceUUID,
        @RequestParam(value = "subscriptionId", required = false) String subscriptionId,
        @RequestParam(value = "revision", required = false) String revision,
        @RequestParam(value = "revisionDate", required = false) String revisionDate,
        @RequestParam(value = "dateFormat", required = false) String dateFormat,
        @RequestParam(value = "currencyCode", required = false) String currencyCode,
        @RequestParam(value = "resourceType", required = false) final String resourceType,
        final HttpServletRequest request) throws ConnectorManagementServiceException {
    logger.debug("### viewCatalog method starting...(GET)");
    Channel channel = null;//from   w w  w. j  a  va  2s  . co m
    String successView = "channels.catalog.view";
    if (channelParam != null && !channelParam.equals("null") && channelParam != "") {
        channel = channelService.getChannelById(channelParam);
    } else {
        channel = channelService.getDefaultServiceProviderChannel();
    }
    final Catalog catalog = channel.getCatalog();
    List<CurrencyValue> currencies = catalog.getSupportedCurrencyValuesByOrder();
    map.addAttribute("channel", channel);
    map.addAttribute("currencies", currencies);
    map.addAttribute("viewChannelCatalog", true);
    map.addAttribute("revision", revision);
    map.addAttribute("revisionDate", revisionDate);
    map.addAttribute("dateFormat", dateFormat);
    if (StringUtils.isNotBlank(currencyCode)) {
        CurrencyValue currency = currencyValueService.locateBYCurrencyCode(currencyCode);
        map.addAttribute("selectedCurrency", currency);
    } else {
        map.addAttribute("selectedCurrency", currencies.get(0));
    }

    final Tenant tenant = tenantService.getSystemTenant();
    final String finalView = successView;
    final Channel catalogChannel = channel;
    Map<String, Object> finalMap = privilegeService.runAsPortal(new PrivilegedAction<Map<String, Object>>() {

        @Override
        public Map<String, Object> run() {
            ModelMap modelMap = new ModelMap();
            try {
                getResourceComponentsAndFilterData(tenant, tenantParam, serviceInstanceUUID, null, resourceType,
                        modelMap, request, finalView, catalogChannel.getName());
            } catch (ConnectorManagementServiceException e) {
                logger.debug("Error occured ", e);
            }
            return modelMap;
        }
    });
    map.addAllAttributes(finalMap);
    // preview catalog will have default UI Because in cutom UI SSO happens which can leads to
    // security threats
    map.addAttribute("customEditorTag", null);
    map.addAttribute("customComponentSelector", null);
    return finalView;
}