-
Notifications
You must be signed in to change notification settings - Fork 20
adding core metadata support for a CDB domain
The core metadata framework allows a metadata property type to be defined for a particular CDB domain class. The idea is that the metadata property will contain common fields for that domain object, beyond the core attributes managed for CDB items like name, description, identifiers, etc.
For example, the core metadata property for the cable catalog domain includes fields like documentation URL, image URL, weight, diameter, heat limit, bend radius, etc. We use the fields to capture information during the import process to further describe the cable catalog items.
The framework displays the core metadata fields and their values on the detailed item view page, and also allows the fields to be displayed as columns in the domain's list view.
Most of the framework is provided in the ItemController class.
Here are the steps necessary to add core metadata support for a CDB domain:
1. Override initializeCoreMetadataPropertyInfo() in the controller class
2. set/get core metadata field value from domain object
3. add display and filter settings for field to domain settings class
4. modify static sql to add display and filter settings keys to setting_type database table
5. add new settings keys to setting_type database table
To add a core metadata property for a domain class, simply override the method initializeCoreMetadataPropertyInfo() in the controller class. Here is an example from ItemDomainCableDesignController:
@Override protected ItemCoreMetadataPropertyInfo initializeCoreMetadataPropertyInfo() { ItemCoreMetadataPropertyInfo info = new ItemCoreMetadataPropertyInfo("Cable Design Metadata", CABLE_DESIGN_INTERNAL_PROPERTY_TYPE); info.addField(ItemDomainCableDesign.CABLE_DESIGN_PROPERTY_EXT_CABLE_NAME_KEY, "Ext Cable Name", "External cable name (e.g., from CAD or routing tool).", ItemCoreMetadataFieldType.STRING, ""); info.addField(ItemDomainCableDesign.CABLE_DESIGN_PROPERTY_IMPORT_CABLE_ID_KEY, "Import Cable ID", "Import cable identifier.", ItemCoreMetadataFieldType.STRING, ""); info.addField(ItemDomainCableDesign.CABLE_DESIGN_PROPERTY_ALT_CABLE_ID_KEY, "Alt Cable ID", "Alternate (e.g., group-specific) cable identifier.", ItemCoreMetadataFieldType.STRING, ""); info.addField(ItemDomainCableDesign.CABLE_DESIGN_PROPERTY_LEGACY_QR_ID_KEY, "Legacy QR ID", "Legacy QR identifier, e.g., for cables that have already been assigned a QR code.", ItemCoreMetadataFieldType.STRING, ""); info.addField(ItemDomainCableDesign.CABLE_DESIGN_PROPERTY_LAYING_KEY, "Laying", "Laying style e.g., S=single-layer, M=multi-layer, T=triangular, B=bundle", ItemCoreMetadataFieldType.STRING, ""); info.addField(ItemDomainCableDesign.CABLE_DESIGN_PROPERTY_VOLTAGE_KEY, "Voltage", "Voltage aplication e.g., COM=communication, CTRL=control, IW=instrumentation, LV=low voltage, MV=medium voltage", ItemCoreMetadataFieldType.STRING, ""); info.addField(ItemDomainCableDesign.CABLE_DESIGN_PROPERTY_ENDPOINT1_DESC_KEY, "Endpoint1 Desc", "Endpoint details useful for external editing.", ItemCoreMetadataFieldType.STRING, ""); info.addField(ItemDomainCableDesign.CABLE_DESIGN_PROPERTY_ENDPOINT2_DESC_KEY, "Endpoint2 Desc", "Endpoint details useful for external editing.", ItemCoreMetadataFieldType.STRING, ""); return info; }
For each key, the key name, key field label, field description, and field type are specified in the constructor. Supported fidld types include STRING, NUMERIC, and URL. These are used for displaying and editing the field value.
Then, you can set and get the field values using set/getCoreMetadataPropertyFieldValue() in the domain class's accessor methods. Here is an example from ItemDomainCableDesign:
public String getLaying() throws CdbException { if (laying == null) { laying = getCoreMetadataPropertyFieldValue(CABLE_DESIGN_PROPERTY_LAYING_KEY); } return laying; } public void setLaying(String l) throws CdbException { laying = l; setCoreMetadataPropertyFieldValue(CABLE_DESIGN_PROPERTY_LAYING_KEY, l); }
Each core metadata field that you define MUST have settings keys added to the domain settings class and the corresponding settings database table. This is unfortunately a messy, copy-paste endeavor. Here are the individual items that must be added to the settings class for a given core metadata key. This is an example from ItemDomainCableDesignSettings:
This is the key for the display setting in the "setting_type" database table.
private static final String DisplayLayingSettingTypeKey = "ItemDomainCableDesign.List.Display.Laying";
This is the key for the filter setting in the "setting_type" database table.
private static final String FilterLayingSettingTypeKey = "ItemDomainCableDesign.List.FilterBy.Laying";
These variables hold the display and filter settings selection for the key.
protected Boolean layingDisplay = null; protected String layingFilter = null;
public boolean isLayingDisplay() { return layingDisplay; } public void setLayingDisplay(boolean layingDisplay) { this.layingDisplay = layingDisplay; } public String getLayingFilter() { return layingFilter; } public void setLayingFilter(String layingFilter) { this.layingFilter = layingFilter; }
layingDisplay = Boolean.parseBoolean(settingTypeMap.get(DisplayLayingSettingTypeKey).getDefaultValue()); layingFilter = settingTypeMap.get(FilterLayingSettingTypeKey).getDefaultValue();
layingDisplay = settingEntity.getSettingValueAsBoolean(DisplayLayingSettingTypeKey, layingDisplay); layingFilter = settingEntity.getSettingValueAsString(FilterLayingSettingTypeKey, layingFilter);
settingEntity.setSettingValue(DisplayLayingSettingTypeKey, layingDisplay); settingEntity.setSettingValue(FilterLayingSettingTypeKey, layingFilter);
You must modify the static sql file "db/sql/static/populate_setting_type.sql" to add the new settings keys. There should be two for each new field. Continuing the example above:
(23014,'ItemDomainCableDesign.List.Display.Laying','Display column for laying in cable design list.','false'), (23018,'ItemDomainCableDesign.List.FilterBy.Laying','Filter for components by laying.',NULL),
Manually insert the new rows into the table. Make sure to replace the final comma with a semi-colon:
INSERT INTO `setting_type` VALUES -> (23046,'ItemDomainCableInventory.List.Display.Length','Display column for length in cable inventory list.','false'), -> (23047,'ItemDomainCableInventory.List.FilterBy.Length','Filter for components by length.',NULL);