use of org.broadleafcommerce.cms.field.domain.FieldDefinition in project BroadleafCommerce by BroadleafCommerce.
the class PageTemplateCustomPersistenceHandler method processFieldGroups.
protected void processFieldGroups(List<String> dirtyFields, Map<String, PageField> pageFieldMap, List<Property> propertiesList, List<FieldGroup> fieldGroups) {
for (FieldGroup fieldGroup : fieldGroups) {
for (FieldDefinition def : fieldGroup.getFieldDefinitions()) {
Property property = new Property();
propertiesList.add(property);
property.setName(def.getName());
String value = null;
if (!MapUtils.isEmpty(pageFieldMap)) {
PageField pageField = pageFieldMap.get(def.getName());
if (pageField == null) {
value = "";
} else {
value = pageField.getValue();
}
}
property.setValue(value);
if (!CollectionUtils.isEmpty(dirtyFields) && dirtyFields.contains(property.getName())) {
property.setIsDirty(true);
}
if (StringUtils.isNotBlank(def.getAdditionalForeignKeyClass())) {
property.getMetadata().setOwningClass(def.getAdditionalForeignKeyClass());
}
}
}
}
use of org.broadleafcommerce.cms.field.domain.FieldDefinition in project BroadleafCommerce by BroadleafCommerce.
the class DynamicFieldPersistenceHandlerHelper method buildDynamicPropertyList.
/**
* Builds all of the metadata for all of the dynamic properties within a {@link StructuredContentType}, gleaned from
* the {@link FieldGroup}s and {@link FieldDefinition}s.
*
* @param fieldGroups groups that the {@link Property}s are built from
* @param inheritedType the value that each built {@link FieldMetadata} for each property will use to notate where the
* dynamic field actually came from (meaning {@link FieldMetadata#setAvailableToTypes(String[])} and {@link FieldMetadata#setInheritedFromType(String)}
* @return
*/
public Property[] buildDynamicPropertyList(List<FieldGroup> fieldGroups, Class<?> inheritedType) {
List<Property> propertiesList = new ArrayList<Property>();
int groupCount = 1;
int fieldCount = 0;
for (FieldGroup group : fieldGroups) {
List<FieldDefinition> definitions = group.getFieldDefinitions();
for (FieldDefinition def : definitions) {
Property property = buildDynamicProperty(def, inheritedType);
BasicFieldMetadata fieldMetadata = (BasicFieldMetadata) property.getMetadata();
fieldMetadata.setOrder(fieldCount++);
fieldMetadata.setGroup(group.getName());
fieldMetadata.setGroupOrder(groupCount);
fieldMetadata.setGroupCollapsed(group.getInitCollapsedFlag());
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>() {
@Override
public int compare(Property o1, Property o2) {
/*
* First, compare properties based on order fields
*/
if (o1.getMetadata().getOrder() != null && o2.getMetadata().getOrder() != null) {
return o1.getMetadata().getOrder().compareTo(o2.getMetadata().getOrder());
} else if (o1.getMetadata().getOrder() != null && o2.getMetadata().getOrder() == null) {
/*
* Always favor fields that have an order identified
*/
return -1;
} else if (o1.getMetadata().getOrder() == null && o2.getMetadata().getOrder() != null) {
/*
* Always favor fields that have an order identified
*/
return 1;
} else if (o1.getMetadata().getFriendlyName() != null && o2.getMetadata().getFriendlyName() != null) {
return o1.getMetadata().getFriendlyName().compareTo(o2.getMetadata().getFriendlyName());
} else {
return o1.getName().compareTo(o2.getName());
}
}
});
return properties;
}
use of org.broadleafcommerce.cms.field.domain.FieldDefinition in project BroadleafCommerce by BroadleafCommerce.
the class PageServiceUtility method getFieldDefinition.
protected FieldDefinition getFieldDefinition(Page page, String fieldKey) {
ExtensionResultHolder<FieldDefinition> erh = new ExtensionResultHolder<FieldDefinition>();
ExtensionResultStatusType result = extensionManager.getProxy().getFieldDefinition(erh, page, fieldKey);
if (result == ExtensionResultStatusType.HANDLED) {
return erh.getResult();
}
if (page.getPageTemplate() != null) {
for (PageTemplateFieldGroupXref fgXrefs : page.getPageTemplate().getFieldGroupXrefs()) {
for (FieldDefinition fd : fgXrefs.getFieldGroup().getFieldDefinitions()) {
if (fd.getName().equals(fieldKey)) {
return fd;
}
}
}
}
return null;
}
Aggregations