for (FieldGroup group : fieldGroups) {
List<FieldDefinition> definitions = group.getFieldDefinitions();
for (FieldDefinition definition : definitions) {
Property property = new Property();
property.setName(definition.getName());
BasicFieldMetadata fieldMetadata = new BasicFieldMetadata();
property.setMetadata(fieldMetadata);
fieldMetadata.setFieldType(definition.getFieldType());
fieldMetadata.setMutable(true);
fieldMetadata.setInheritedFromType(inheritedType.getName());
fieldMetadata.setAvailableToTypes(new String[] {inheritedType.getName()});
fieldMetadata.setForeignKeyCollection(false);
fieldMetadata.setMergedPropertyType(MergedPropertyType.PRIMARY);
fieldMetadata.setLength(definition.getMaxLength());
if (definition.getDataDrivenEnumeration() != null && !CollectionUtils.isEmpty(definition.getDataDrivenEnumeration().getEnumValues())) {
int count = definition.getDataDrivenEnumeration().getEnumValues().size();
String[][] enumItems = new String[count][2];
for (int j = 0; j < count; j++) {
DataDrivenEnumerationValue item = definition.getDataDrivenEnumeration().getEnumValues().get(j);
enumItems[j][0] = item.getKey();
enumItems[j][1] = item.getDisplay();
}
fieldMetadata.setEnumerationValues(enumItems);
}
fieldMetadata.setName(definition.getName());
fieldMetadata.setFriendlyName(definition.getFriendlyName());
fieldMetadata.setSecurityLevel(definition.getSecurityLevel()==null?"":definition.getSecurityLevel());
fieldMetadata.setOrder(fieldCount++);
fieldMetadata.setVisibility(definition.getHiddenFlag()?VisibilityEnum.HIDDEN_ALL:VisibilityEnum.VISIBLE_ALL);
fieldMetadata.setGroup(group.getName());
fieldMetadata.setGroupOrder(groupCount);
fieldMetadata.setTab("General");
fieldMetadata.setTabOrder(100);
fieldMetadata.setGroupCollapsed(group.getInitCollapsedFlag());
fieldMetadata.setExplicitFieldType(SupportedFieldType.UNKNOWN);
fieldMetadata.setLargeEntry(definition.getTextAreaFlag());
fieldMetadata.setProminent(false);
fieldMetadata.setColumnWidth(String.valueOf(definition.getColumnWidth()));
fieldMetadata.setBroadleafEnumeration("");
fieldMetadata.setReadOnly(false);
fieldMetadata.setRequiredOverride(definition.getRequiredFlag());
if (definition.getValidationRegEx() != null) {
Map<String, String> itemMap = new HashMap<String, String>();
itemMap.put("regularExpression", definition.getValidationRegEx());
itemMap.put(ConfigurationItem.ERROR_MESSAGE, definition.getValidationErrorMesageKey());
fieldMetadata.getValidationConfigurations().put("org.broadleafcommerce.openadmin.server.service.persistence.validation.RegexPropertyValidator", itemMap);
}
if (definition.getFieldType().equals(SupportedFieldType.ADDITIONAL_FOREIGN_KEY)) {
fieldMetadata.setForeignKeyClass(definition.getAdditionalForeignKeyClass());
fieldMetadata.setOwningClass(definition.getAdditionalForeignKeyClass());
fieldMetadata.setForeignKeyDisplayValueProperty("__adminMainEntity");
}
propertiesList.add(property);
}
groupCount++;
fieldCount = 0;
}
Property property = new Property();
property.setName("id");
BasicFieldMetadata fieldMetadata = new BasicFieldMetadata();
property.setMetadata(fieldMetadata);
fieldMetadata.setFieldType(SupportedFieldType.ID);
fieldMetadata.setSecondaryType(SupportedFieldType.INTEGER);
fieldMetadata.setMutable(true);
fieldMetadata.setInheritedFromType(inheritedType.getName());
fieldMetadata.setAvailableToTypes(new String[] {inheritedType.getName()});
fieldMetadata.setForeignKeyCollection(false);
fieldMetadata.setMergedPropertyType(MergedPropertyType.PRIMARY);
fieldMetadata.setName("id");
fieldMetadata.setFriendlyName("ID");
fieldMetadata.setSecurityLevel("");
fieldMetadata.setVisibility(VisibilityEnum.HIDDEN_ALL);
fieldMetadata.setExplicitFieldType(SupportedFieldType.UNKNOWN);
fieldMetadata.setLargeEntry(false);
fieldMetadata.setProminent(false);
fieldMetadata.setColumnWidth("*");
fieldMetadata.setBroadleafEnumeration("");
fieldMetadata.setReadOnly(true);
propertiesList.add(property);
Property[] properties = new Property[propertiesList.size()];
properties = propertiesList.toArray(properties);
Arrays.sort(properties, new Comparator<Property>() {