modify import helper subclass for domain/format to support export. Mostly this involves adding export getter methods to the ColumnSpec constructor invocations in getColumnSpecs(), e.g., "getName" in the following snippet:
add domain support for the export feature as needed. For example, to get the value for the "Manufacturer" column in the cable catalog export, a method is needed to find the Source item marked as manufacturer for the item and return its name, e.g.,:
@JsonIgnore
public Source getExportManufacturer() {
List<ItemSource> itemSourceList = getItemSourceList();
if (itemSourceList != null) {
for (ItemSource source : itemSourceList) {
if (source.getIsManufacturer()) {
return source.getSource();
}
}
}
return null;
}
Adding Transfer Support for a CDB Domain
override supportsModeTransfer() in import helper class to return true, e.g.,
public boolean supportsModeTransfer() {
return true;
}
add "exportTransferGetterMethod" parameter to column spec constructor invocations in helper class's getColumnSpecs() method (or the shared column specs that it utilizes). This is NOT necessary if you want the output spreadsheet for transfer mode to contain the same value as for regular export mode (e.g., an item's description would be the same in both cases). But it IS necessary when you want a different value, or no value, in the output spreadsheet for transfer mode. For example, the machine hierarchy format regular export output includes the id of the assigned catalog/inventory item, but in the transfer mode output, we want a multi-attribute json map string, so the regular exportGetterMethod parameter is "getAssignedItem", but the exportTransferGetterMethod is "getCatalogItemAttributeMap". In the case where the regular export output contains a value but we don't want a value in the transfer mode output (e.g., for existing item id), we use a special exportTransferGetterMethod of "ColumnSpec.BLANK_COLUMN_EXPORT_METHOD", e.g, this example shows the id column with "getId" as the exportGetterMethod for regular export mode, and BLANK_COLUMN_EXPORT_METHOD for transfer mode:
public IntegerColumnSpec existingItemIdColumnSpec() {
return new IntegerColumnSpec(
"Existing Item ID",
KEY_EXISTING_ITEM_ID,
"setImportExistingItemId",
"CDB ID of existing item to update.",
"getId",
ColumnSpec.BLANK_COLUMN_EXPORT_METHOD,
ColumnModeOptions.rUPDATErDELETErCOMPARE());
}
Enabling update/compare support for a CDB domain
override supportsModeUpdate() in import helper subclass e.g.,
@Override
public boolean supportsModeUpdate() {
return true;
}
override newInvalidUpdateInstance() in import helper subclass. It looks weird, but since the entities for the model behind the import wizard validation table are domain objects, we need to have an item even for an invalid request, so that we can display the various fields of the item. This method returns an object for use in that way, e.g.,
modify getColumnSpecs() in import helper subclass to add existing item id column (probably as first column). This will include a new column for the item's cdb id in the export spreadsheet, and expect it in the import/update spreadsheet, e.g.,
modify the domain object setter methods as needed to handle updating the item properties from the spreadsheet. The initial implementation of those methods is geared towards creating new items, and may not be appropriate for updating existing items. E.g.,
public void removeManufactuterInfo() {
List<ItemSource> itemSourceList = getItemSourceList();
if (itemSourceList != null) {
for (ItemSource itemSource : itemSourceList) {
if (itemSource.getIsManufacturer()) {
getImportDeletedItemSources().add(itemSource);
}
}
}
}
add support in controller, utility, and facade as needed to implement domain operations e.g., in the facade:
/**
* Updates catalog item. Overridden here because, if we edit a catalog item
* to remove ItemSource objects for manufacturer change, they are not removed from the database
* by updating the database for that cable type. Thus they are removed explicitly
* here.
*/
public ItemDomainCableCatalog edit(ItemDomainCableCatalog entity) {
ItemDomainCableCatalog result = super.edit(entity);
for (ItemSource itemSource : entity.getImportDeletedItemSources()) {
ItemSourceFacade.getInstance().remove(itemSource);
}
entity.clearImportDeletedItemSources();
return result;
}
Enabling delete support for a CDB domain
modify the helper subclass's getColumnSpecs() method to add a "delete existing item" column, e.g.,