org.kuali.kfs.module.purap.util
Class ItemParserBase

java.lang.Object
  extended by org.kuali.kfs.module.purap.util.ItemParserBase
All Implemented Interfaces:
ItemParser

public class ItemParserBase
extends Object
implements ItemParser


Field Summary
protected static String[] COMMODITY_CODE_DISABLED_FORMAT
           
protected static String[] DEFAULT_FORMAT
          The default format defines the expected item property names and their order in the import file.
 
Constructor Summary
ItemParserBase()
           
 
Method Summary
protected  void checkItemClass(Class<? extends PurApItem> itemClass)
          Checks whether the specified item class is a subclass of PurApItem; throws exceptions if not.
protected  void checkItemFile(org.apache.struts.upload.FormFile itemFile)
          Checks whether the specified item import file is not null and of a valid format; throws exceptions if conditions not satisfied.
protected  PurApItem genItemWithRetrievedAttributes(Map<String,String> itemMap, Class<? extends PurApItem> itemClass)
          Generates an item instance and populates it with the specified attribute map.
protected  String getAttributeLabel(Class clazz, String attributeName)
          Retrieves the attribute label for the specified attribute.
 String getExpectedItemFormatAsString(Class<? extends PurApItem> itemClass)
          Returns the expected format of the items to be imported.
 String[] getItemFormat()
          Returns the defined format of item lines in the item import file.
 List<PurApItem> importItems(org.apache.struts.upload.FormFile itemFile, Class<? extends PurApItem> itemClass, String documentNumber)
          Parses the items from the specified import file line by line, and generates items of the specified type from the parsed data.
 PurApItem parseItem(String itemLine, Class<? extends PurApItem> itemClass, String documentNumber)
          Parses the specified item line into an instance of the specified PurApItem subclass.
protected  void populateExtraAttributes(PurApItem item, String documentNumber)
          Populates extra item attributes not contained in the imported item data to default values.
protected  Map<String,String> retrieveItemAttributes(String itemLine)
          Parses a line of item data from a csv file and retrieves the attributes as key-value string pairs into a map.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_FORMAT

protected static final String[] DEFAULT_FORMAT
The default format defines the expected item property names and their order in the import file. Please update this if the import file format changes (i.e. adding/deleting item properties, changing their order).


COMMODITY_CODE_DISABLED_FORMAT

protected static final String[] COMMODITY_CODE_DISABLED_FORMAT
Constructor Detail

ItemParserBase

public ItemParserBase()
Method Detail

getItemFormat

public String[] getItemFormat()
Description copied from interface: ItemParser
Returns the defined format of item lines in the item import file.

Specified by:
getItemFormat in interface ItemParser
Returns:
the item line format as an array of item property names
See Also:
ItemParser.getItemFormat()

getExpectedItemFormatAsString

public String getExpectedItemFormatAsString(Class<? extends PurApItem> itemClass)
Description copied from interface: ItemParser
Returns the expected format of the items to be imported.

Specified by:
getExpectedItemFormatAsString in interface ItemParser
Parameters:
itemClass - the class of the items to be imported
Returns:
the concatenation of the actual property names of the items to be imported
See Also:
ItemParser.getExpectedItemFormatAsString(java.lang.Class)

getAttributeLabel

protected String getAttributeLabel(Class clazz,
                                   String attributeName)
Retrieves the attribute label for the specified attribute.

Parameters:
clazz - the class in which the specified attribute is defined
attributeName - the name of the specified attribute
Returns:
the attribute label for the specified attribute

checkItemClass

protected void checkItemClass(Class<? extends PurApItem> itemClass)
Checks whether the specified item class is a subclass of PurApItem; throws exceptions if not.

Parameters:
itemClass - the specified item class

checkItemFile

protected void checkItemFile(org.apache.struts.upload.FormFile itemFile)
Checks whether the specified item import file is not null and of a valid format; throws exceptions if conditions not satisfied.

Parameters:
itemClass - the specified item import file

retrieveItemAttributes

protected Map<String,String> retrieveItemAttributes(String itemLine)
Parses a line of item data from a csv file and retrieves the attributes as key-value string pairs into a map.

Parameters:
itemLine - a string read from a line in the item import file
Returns:
a map containing item attribute name-value string pairs

genItemWithRetrievedAttributes

protected PurApItem genItemWithRetrievedAttributes(Map<String,String> itemMap,
                                                   Class<? extends PurApItem> itemClass)
Generates an item instance and populates it with the specified attribute map.

Parameters:
itemMap - the specified attribute map from which attributes are populated
itemClass - the class of which the new item instance shall be created
Returns:
the populated item

populateExtraAttributes

protected void populateExtraAttributes(PurApItem item,
                                       String documentNumber)
Populates extra item attributes not contained in the imported item data to default values.

Parameters:
item - the item to be populated
documentNumber - the number of the docment that contains the item

parseItem

public PurApItem parseItem(String itemLine,
                           Class<? extends PurApItem> itemClass,
                           String documentNumber)
Description copied from interface: ItemParser
Parses the specified item line into an instance of the specified PurApItem subclass.

Specified by:
parseItem in interface ItemParser
Parameters:
itemLine - the item line string to be parsed
itemClass - the subclass of the item to be generated
documentNumber - the number of the docment that contains the item to be generated
Returns:
the generated item
See Also:
ItemParser.parseItem(java.lang.String,java.lang.Class,java.lang.String)

importItems

public List<PurApItem> importItems(org.apache.struts.upload.FormFile itemFile,
                                   Class<? extends PurApItem> itemClass,
                                   String documentNumber)
Description copied from interface: ItemParser
Parses the items from the specified import file line by line, and generates items of the specified type from the parsed data.

Specified by:
importItems in interface ItemParser
Parameters:
itemFile - the input file from which items are parsed
itemClass - a subclass of PurApItem, of which new items shall be generated
documentNumber - the number of the docment that contains the items to be imported
Returns:
a list of items of a subclass of PurApItem.
See Also:
org.kuali.kfs.module.purap.util.ItemParser#parseItem(org.apache.struts.upload.FormFile,java.lang.Class,java.lang.String)


Copyright © 2005-2012 The Kuali Foundation. All Rights Reserved.