protected JSONArray getDDMFormFieldsJSONArray(DDMForm ddmForm, String script) { if (Validator.isNull(script)) { return null; } JSONArray defaultDDMFormFieldsJSONArray = null; if (ddmForm != null) { defaultDDMFormFieldsJSONArray = getDDMFormFieldsJSONArray( ddmForm.getDDMFormFields(), ddmForm.getAvailableLocales(), ddmForm.getDefaultLocale()); } try { DDMForm scriptDDMForm = DDMFormJSONDeserializerUtil.deserialize(script); return getDDMFormFieldsJSONArray( scriptDDMForm.getDDMFormFields(), scriptDDMForm.getAvailableLocales(), scriptDDMForm.getDefaultLocale()); } catch (PortalException pe) { if (_log.isWarnEnabled()) { _log.warn("Unable to deserialize script", pe); } return defaultDDMFormFieldsJSONArray; } }
protected void validateDDMFormLocales(DDMForm ddmForm) throws DDMFormValidationException { Locale defaultLocale = ddmForm.getDefaultLocale(); if (defaultLocale == null) { throw new MustSetDefaultLocale(); } validateDDMFormAvailableLocales(ddmForm.getAvailableLocales(), defaultLocale); }
public static int addResource(WebDAVRequest webDavRequest, long classNameId) throws Exception { String[] pathArray = webDavRequest.getPathArray(); if (pathArray.length != 4) { return HttpServletResponse.SC_FORBIDDEN; } String type = pathArray[2]; String typeId = pathArray[3]; if (type.equals(TYPE_STRUCTURES)) { HttpServletRequest request = webDavRequest.getHttpServletRequest(); String definition = StringUtil.read(request.getInputStream()); DDMForm ddmForm = getDDMForm(definition); DDMFormLayout ddmFormLayout = DDMUtil.getDefaultDDMFormLayout(ddmForm); Map<Locale, String> nameMap = new HashMap<>(); Locale defaultLocale = ddmForm.getDefaultLocale(); nameMap.put(defaultLocale, typeId); ServiceContext serviceContext = new ServiceContext(); serviceContext.setAddGroupPermissions(true); serviceContext.setAddGuestPermissions(true); DDMStructureLocalServiceUtil.addStructure( webDavRequest.getUserId(), webDavRequest.getGroupId(), classNameId, nameMap, null, ddmForm, ddmFormLayout, StorageType.JSON.toString(), serviceContext); return HttpServletResponse.SC_CREATED; } else if (type.equals(TYPE_TEMPLATES)) { // DDM templates can not be added via WebDAV because there is no way // to know the associated class name or class PK return HttpServletResponse.SC_FORBIDDEN; } return HttpServletResponse.SC_FORBIDDEN; }
@Override public void validate(DDMForm ddmForm) throws DDMFormValidationException { validateDDMFormLocales(ddmForm); List<DDMFormField> ddmFormFields = ddmForm.getDDMFormFields(); if (ddmFormFields.isEmpty()) { throw new MustSetFieldsForForm(); } validateDDMFormFields( ddmFormFields, new HashSet<String>(), ddmForm.getAvailableLocales(), ddmForm.getDefaultLocale()); }
@Override public DDMFormLayout getDefaultDDMFormLayout(DDMForm ddmForm) { DDMFormLayout ddmFormLayout = new DDMFormLayout(); Locale defaultLocale = ddmForm.getDefaultLocale(); ddmFormLayout.setDefaultLocale(defaultLocale); ddmFormLayout.setPaginationMode(DDMFormLayout.SINGLE_PAGE_MODE); DDMFormLayoutPage ddmFormLayoutPage = new DDMFormLayoutPage(); LocalizedValue title = getDefaultDDMFormPageTitle(defaultLocale); ddmFormLayoutPage.setTitle(title); for (DDMFormField ddmFormField : ddmForm.getDDMFormFields()) { ddmFormLayoutPage.addDDMFormLayoutRow(getDefaultDDMFormLayoutRow(ddmFormField)); } ddmFormLayout.addDDMFormLayoutPage(ddmFormLayoutPage); return ddmFormLayout; }