DocumentLibraryDDMFormFieldTemplateContextContributor implements DDMFormFieldTemplateContextContributor { @Override public Map<String, Object> getParameters( DDMFormField ddmFormField, DDMFormFieldRenderingContext ddmFormFieldRenderingContext) { Map<String, Object> parameters = new HashMap<>(); HttpServletRequest httpServletRequest = ddmFormFieldRenderingContext.getHttpServletRequest(); if (Validator.isNotNull(ddmFormFieldRenderingContext.getValue())) { JSONObject valueJSONObject = getValueJSONObject( ddmFormFieldRenderingContext.getValue()); if ((valueJSONObject != null) && (valueJSONObject.length() > 0)) { FileEntry fileEntry = getFileEntry(valueJSONObject); parameters.put("fileEntryTitle", getFileEntryTitle(fileEntry)); parameters.put( "fileEntryURL", getFileEntryURL(httpServletRequest, fileEntry)); } } parameters.put( "groupId", ddmFormFieldRenderingContext.getProperty("groupId")); parameters.put( "itemSelectorAuthToken", getItemSelectorAuthToken(httpServletRequest)); parameters.put( "lexiconIconsPath", getLexiconIconsPath(httpServletRequest)); Locale displayLocale; if (ddmFormFieldRenderingContext.isViewMode()) { displayLocale = ddmFormFieldRenderingContext.getLocale(); } else { displayLocale = getDisplayLocale( ddmFormFieldRenderingContext.getHttpServletRequest()); } Map<String, String> stringsMap = new HashMap<>(); stringsMap.put( "select", LanguageUtil.get(getResourceBundle(displayLocale), "select")); parameters.put("strings", stringsMap); String value = ddmFormFieldRenderingContext.getValue(); if (Validator.isNull(value)) { value = "{}"; } parameters.put("value", value); return parameters; }  @Override Map<String, Object> getParameters(
		DDMFormField ddmFormField,
		DDMFormFieldRenderingContext ddmFormFieldRenderingContext);  }
@Test public void testGetParametersShouldContainFileEntryURL() { DDMFormField ddmFormField = new DDMFormField("field", "numeric"); DocumentLibraryDDMFormFieldTemplateContextContributor spy = createSpy(); DDMFormFieldRenderingContext ddmFormFieldRenderingContext = new DDMFormFieldRenderingContext(); ddmFormFieldRenderingContext.setHttpServletRequest( createHttpServletRequest()); ddmFormFieldRenderingContext.setProperty("groupId", 12345); ddmFormFieldRenderingContext.setReadOnly(true); ddmFormFieldRenderingContext.setValue( "{\"uuid\": \"0000-1111\", \"title\": \"File Title\"}"); Map<String, Object> parameters = spy.getParameters( ddmFormField, ddmFormFieldRenderingContext); Assert.assertTrue(parameters.containsKey("fileEntryURL")); }
@Test public void testGetParametersShouldContainItemSelectorAuthToken() { DDMFormField ddmFormField = new DDMFormField("field", "numeric"); DocumentLibraryDDMFormFieldTemplateContextContributor spy = createSpy(); DDMFormFieldRenderingContext ddmFormFieldRenderingContext = new DDMFormFieldRenderingContext(); ddmFormFieldRenderingContext.setHttpServletRequest( createHttpServletRequest()); ddmFormFieldRenderingContext.setValue( "{\"uuid\": \"0000-1111\", \"title\": \"Title\"}"); Map<String, Object> parameters = spy.getParameters( ddmFormField, ddmFormFieldRenderingContext); Assert.assertEquals("token", parameters.get("itemSelectorAuthToken")); }
@Test public void testGetParametersShouldUseFileEntryTitle() { DDMFormField ddmFormField = new DDMFormField("field", "numeric"); DocumentLibraryDDMFormFieldTemplateContextContributor spy = createSpy(); DDMFormFieldRenderingContext ddmFormFieldRenderingContext = new DDMFormFieldRenderingContext(); ddmFormFieldRenderingContext.setHttpServletRequest( createHttpServletRequest()); ddmFormFieldRenderingContext.setReadOnly(true); ddmFormFieldRenderingContext.setValue( "{\"uuid\": \"0000-1111\", \"title\": \"Old Title\"}"); Map<String, Object> parameters = spy.getParameters( ddmFormField, ddmFormFieldRenderingContext); Assert.assertEquals("New Title", parameters.get("fileEntryTitle")); }