-
Notifications
You must be signed in to change notification settings - Fork 19
adding export, transfer, update, and delete support for a CDB domain
craigmcchesney edited this page Jun 4, 2021
·
2 revisions
- override getEntityDisplayExportButton() in domain controller class to return true, e.g.,
@Override public boolean getEntityDisplayExportButton() { return true; }
- override initializeDomainExportInfo() in domain controller class, e.g.,
@Override protected DomainImportExportInfo initializeDomainExportInfo() { List<ImportExportFormatInfo> formatInfo = new ArrayList<>(); formatInfo.add( new ImportExportFormatInfo("Basic Cable Catalog Create/Update Format", ImportHelperCableCatalog.class)); String completionUrl = "/views/itemDomainCableCatalog/list?faces-redirect=true"; return new DomainImportExportInfo(formatInfo, completionUrl); }
- add domain export view export.xhtml file for displaying export wizard e.g.,
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://xmlns.jcp.org/jsf/html" xmlns:p="http://primefaces.org/ui" template="../../templates/contentViewTemplate.xhtml"> <f:metadata> <f:viewAction action="#{settingController.updateGlobalSettings()}" /> <f:viewAction action="#{logController.processPreRender()}"/> </f:metadata> <ui:param name="entityController" value="#{itemDomainCableCatalogController}"/> <ui:define name="middleCenter"> <h:form id="exportCableCatalogForm"> <div class="pageTitle"> <h1>Export Cable Catalog</h1> </div> <ui:include src="../item/private/exportWizard/exportWizard.xhtml"> <ui:param name="entityController" value="#{entityController}" /> </ui:include> </h:form> </ui:define> </ui:composition>
- 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:
@Override protected List<ColumnSpec> getColumnSpecs() { List<ColumnSpec> specs = new ArrayList<>(); specs.add(new StringColumnSpec( "Name", "name", "setName", "Cable type name, uniquely identifies cable type.", "getName", ColumnModeOptions.rCREATErUPDATE(), 128)); <snip>
- 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; }
- 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()); }
- 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.,
@Override protected ItemDomainCableCatalog newInvalidUpdateInstance() { return getEntityController().createEntityInstance(); }
- 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.,
@Override protected List<ColumnSpec> getColumnSpecs() { List<ColumnSpec> specs = new ArrayList<>(); specs.add(existingItemIdColumnSpec()); <snip>
- modify existing import spreadsheets to include new "Existing Item ID" column
- add override of updateEntityInstance() to customize the entity update process, if desired, e.g.,
@Override protected ValidInfo updateEntityInstance(CatalogEntityType entity, Map<String, Object> rowMap) { boolean isValid = true; String validString = ""; // update or delete ItemSource if manufacturer is updated Source itemSource = (Source) rowMap.get(KEY_MFR); String itemPartNum = (String) rowMap.get(KEY_PART_NUM); if (itemSource != null) { entity.updateManufacturerInfo(itemSource, itemPartNum); } else { entity.removeManufactuterInfo(); } return new ValidInfo(isValid, validString); }
- 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; }
- modify the helper subclass's getColumnSpecs() method to add a "delete existing item" column, e.g.,
@Override protected List<ColumnSpec> getColumnSpecs() { List<ColumnSpec> specs = new ArrayList<>(); specs.add(existingItemIdColumnSpec()); specs.add(deleteExistingItemColumnSpec()); <snip>
- override supportsDeleteMode() to return true in the helper subclass, e.g.,
@Override public boolean supportsModeDelete() { return true; }