protected Field getFieldsDisplayField(long ddmStructureId, String value) { Field fieldsDisplayField = new Field(); fieldsDisplayField.setDDMStructureId(ddmStructureId); fieldsDisplayField.setName(DDMImpl.FIELDS_DISPLAY_NAME); fieldsDisplayField.setValue(value); return fieldsDisplayField; }
protected HashMap<String, Fields> getFieldsMap( ServiceContext serviceContext, long fileEntryTypeId) throws PortalException, SystemException { HashMap<String, Fields> fieldsMap = new HashMap<String, Fields>(); if (fileEntryTypeId <= 0) { return fieldsMap; } DLFileEntryType fileEntryType = DLFileEntryTypeLocalServiceUtil.getFileEntryType(fileEntryTypeId); List<DDMStructure> ddmStructures = fileEntryType.getDDMStructures(); for (DDMStructure ddmStructure : ddmStructures) { String namespace = String.valueOf(ddmStructure.getStructureId()); Set<String> fieldNames = ddmStructure.getFieldNames(); Fields fields = (Fields) serviceContext.getAttribute(Fields.class.getName() + ddmStructure.getStructureId()); if (fields == null) { fields = new Fields(); for (String name : fieldNames) { Field field = new Field(); field.setName(name); String value = ParamUtil.getString(serviceContext, namespace + name); field.setValue(value); fields.put(field); } } fieldsMap.put(ddmStructure.getStructureKey(), fields); } return fieldsMap; }
protected void updateServiceContext(String expando, long fileEntryTypeId, String metadata) throws PortalException { Map<String, Serializable> expandoBridgeAttributes = _serviceContext.getExpandoBridgeAttributes(); expandoBridgeAttributes.put(_EXPANDO_ATTRIBUTE_NAME, expando); _serviceContext.setExpandoBridgeAttributes(expandoBridgeAttributes); _serviceContext.setAttribute("fileEntryTypeId", fileEntryTypeId); if (fileEntryTypeId <= 0) { return; } DLFileEntryType fileEntryType = DLFileEntryTypeLocalServiceUtil.getFileEntryType(fileEntryTypeId); List<DDMStructure> ddmStructures = fileEntryType.getDDMStructures(); for (DDMStructure ddmStructure : ddmStructures) { Fields fields = (Fields) _serviceContext.getAttribute(Fields.class.getName() + ddmStructure.getStructureId()); for (Field field : fields) { String type = field.getType(); if (!field.isPrivate() && type.equals("text")) { field.setValue(metadata); } } _serviceContext.setAttribute(Fields.class.getName() + ddmStructure.getStructureId(), fields); } }
protected ServiceContext getServiceContext() throws Exception { ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(group.getGroupId()); serviceContext.setAttribute("fileEntryTypeId", _contractDLFileEntryTypeId); Map<String, Serializable> expandoBridgeAttributes = serviceContext.getExpandoBridgeAttributes(); expandoBridgeAttributes.put(_EXPANDO_ATTRIBUTE_NAME, StringPool.BLANK); serviceContext.setExpandoBridgeAttributes(expandoBridgeAttributes); DLFileEntryType fileEntryType = DLFileEntryTypeLocalServiceUtil.getFileEntryType(_contractDLFileEntryTypeId); List<DDMStructure> ddmStructures = fileEntryType.getDDMStructures(); for (DDMStructure ddmStructure : ddmStructures) { Fields fields = new Fields(); Set<String> names = ddmStructure.getFieldNames(); for (String name : names) { Field field = new Field(ddmStructure.getStructureId(), name, StringPool.BLANK); if (ddmStructure.isFieldPrivate(name)) { field.setValue(RandomTestUtil.randomString()); } fields.put(field); } serviceContext.setAttribute(Fields.class.getName() + ddmStructure.getStructureId(), fields); } return serviceContext; }
@Override public Fields getFields(DDMStructure structure, XPath xPath, String xml, List<String> fieldNames) throws PortalException { Document document = null; try { document = SAXReaderUtil.read(xml); } catch (DocumentException de) { return null; } if ((xPath != null) && !xPath.booleanValueOf(document)) { return null; } Fields fields = new Fields(); Element rootElement = document.getRootElement(); List<Element> dynamicElementElements = rootElement.elements("dynamic-element"); for (Element dynamicElementElement : dynamicElementElements) { String fieldName = dynamicElementElement.attributeValue("name"); if (!structure.hasField(fieldName) || ((fieldNames != null) && !fieldNames.contains(fieldName))) { continue; } String fieldDataType = structure.getFieldDataType(fieldName); List<Element> dynamicContentElements = dynamicElementElement.elements("dynamic-content"); for (Element dynamicContentElement : dynamicContentElements) { String fieldValue = dynamicContentElement.getText(); String languageId = dynamicContentElement.attributeValue("language-id"); Locale locale = LocaleUtil.fromLanguageId(languageId); Serializable fieldValueSerializable = FieldConstants.getSerializable(fieldDataType, fieldValue); Field field = fields.get(fieldName); if (field == null) { field = new Field(); String defaultLanguageId = dynamicElementElement.attributeValue("default-language-id"); Locale defaultLocale = LocaleUtil.fromLanguageId(defaultLanguageId); field.setDefaultLocale(defaultLocale); field.setDDMStructureId(structure.getStructureId()); field.setName(fieldName); field.setValue(locale, fieldValueSerializable); fields.put(field); } else { field.addValue(locale, fieldValueSerializable); } } } return fields; }