@Test public void shouldSetOnlyFormatInMapIfTemplateParametersNotPresent() throws Exception { Template template = new Template(); HttpServletRequest request = mock(HttpServletRequest.class); Map<String,Object> parametersMap = service.getParametersMap(template, 1, request, "pdf"); assertThat(parametersMap.size(), is(1)); assertThat((String) parametersMap.get("format"), is("pdf")); }
public Map<String, Object> getParametersMap(Template template, int userId, HttpServletRequest request, String format) throws ParseException { List<TemplateParameter> templateParameters = template.getParameters(); Map<String, String[]> requestParameterMap = request.getParameterMap(); Map<String, Object> map = new HashMap<>(); if (templateParameters != null) { for (TemplateParameter templateParameter : templateParameters) { String templateParameterName = templateParameter.getName(); if (templateParameterName.equalsIgnoreCase(USER_ID_PARAM)) { map.put(templateParameterName, userId); } for (String requestParamName : requestParameterMap.keySet()) { if (templateParameterName.equalsIgnoreCase(requestParamName)) { String requestParamValue = request.getParameter(templateParameterName); if (!(isBlank(requestParamValue) || requestParamValue.equals("null") || requestParamValue.equals("undefined"))) { map.put(templateParameterName, templateParameter.getParsedValueOf(requestParamValue)); } } } } } String viewFormat = format == null ? PDF_VIEW : format; map.put("format", viewFormat); return map; }
TemplateService { public Map<String, Object> getParametersMap(Template template, int userId, HttpServletRequest request, String format) throws ParseException { List<TemplateParameter> templateParameters = template.getParameters(); Map<String, String[]> requestParameterMap = request.getParameterMap(); Map<String, Object> map = new HashMap<>(); if (templateParameters != null) { for (TemplateParameter templateParameter : templateParameters) { String templateParameterName = templateParameter.getName(); if (templateParameterName.equalsIgnoreCase(USER_ID_PARAM)) { map.put(templateParameterName, userId); } for (String requestParamName : requestParameterMap.keySet()) { if (templateParameterName.equalsIgnoreCase(requestParamName)) { String requestParamValue = request.getParameter(templateParameterName); if (!(isBlank(requestParamValue) || requestParamValue.equals("null") || requestParamValue.equals("undefined"))) { map.put(templateParameterName, templateParameter.getParsedValueOf(requestParamValue)); } } } } } String viewFormat = format == null ? PDF_VIEW : format; map.put("format", viewFormat); return map; } }
TemplateService { public Map<String, Object> getParametersMap(Template template, int userId, HttpServletRequest request, String format) throws ParseException { List<TemplateParameter> templateParameters = template.getParameters(); Map<String, String[]> requestParameterMap = request.getParameterMap(); Map<String, Object> map = new HashMap<>(); if (templateParameters != null) { for (TemplateParameter templateParameter : templateParameters) { String templateParameterName = templateParameter.getName(); if (templateParameterName.equalsIgnoreCase(USER_ID_PARAM)) { map.put(templateParameterName, userId); } for (String requestParamName : requestParameterMap.keySet()) { if (templateParameterName.equalsIgnoreCase(requestParamName)) { String requestParamValue = request.getParameter(templateParameterName); if (!(isBlank(requestParamValue) || requestParamValue.equals("null") || requestParamValue.equals("undefined"))) { map.put(templateParameterName, templateParameter.getParsedValueOf(requestParamValue)); } } } } } String viewFormat = format == null ? PDF_VIEW : format; map.put("format", viewFormat); return map; }  }
TemplateService { public Map<String, Object> getParametersMap(Template template, int userId, HttpServletRequest request, String format) throws ParseException { List<TemplateParameter> templateParameters = template.getParameters(); Map<String, String[]> requestParameterMap = request.getParameterMap(); Map<String, Object> map = new HashMap<>(); if (templateParameters != null) { for (TemplateParameter templateParameter : templateParameters) { String templateParameterName = templateParameter.getName(); if (templateParameterName.equalsIgnoreCase(USER_ID_PARAM)) { map.put(templateParameterName, userId); } for (String requestParamName : requestParameterMap.keySet()) { if (templateParameterName.equalsIgnoreCase(requestParamName)) { String requestParamValue = request.getParameter(templateParameterName); if (!(isBlank(requestParamValue) || requestParamValue.equals("null") || requestParamValue.equals("undefined"))) { map.put(templateParameterName, templateParameter.getParsedValueOf(requestParamValue)); } } } } } String viewFormat = format == null ? PDF_VIEW : format; map.put("format", viewFormat); return map; }  List<Template> getAllTemplatesForUser(Long userId); Template getByName(String name); Template getById(Long id); Template getLWById(Long id); void validateFileAndInsertTemplate(Template template, MultipartFile file); Map<String, Object> getParametersMap(Template template, int userId, HttpServletRequest request, String format); }
TemplateService { public Map<String, Object> getParametersMap(Template template, int userId, HttpServletRequest request, String format) throws ParseException { List<TemplateParameter> templateParameters = template.getParameters(); Map<String, String[]> requestParameterMap = request.getParameterMap(); Map<String, Object> map = new HashMap<>(); if (templateParameters != null) { for (TemplateParameter templateParameter : templateParameters) { String templateParameterName = templateParameter.getName(); if (templateParameterName.equalsIgnoreCase(USER_ID_PARAM)) { map.put(templateParameterName, userId); } for (String requestParamName : requestParameterMap.keySet()) { if (templateParameterName.equalsIgnoreCase(requestParamName)) { String requestParamValue = request.getParameter(templateParameterName); if (!(isBlank(requestParamValue) || requestParamValue.equals("null") || requestParamValue.equals("undefined"))) { map.put(templateParameterName, templateParameter.getParsedValueOf(requestParamValue)); } } } } } String viewFormat = format == null ? PDF_VIEW : format; map.put("format", viewFormat); return map; }  List<Template> getAllTemplatesForUser(Long userId); Template getByName(String name); Template getById(Long id); Template getLWById(Long id); void validateFileAndInsertTemplate(Template template, MultipartFile file); Map<String, Object> getParametersMap(Template template, int userId, HttpServletRequest request, String format); static final String PDF_VIEW; static final String USER_ID_PARAM; }