Samp
Samp
databeans; import import import import import import import import import import import import import import import import import java.sql.Timestamp; java.text.SimpleDateFormat; java.util.ArrayList; java.util.List; java.util.logging.Logger; com.bluelinx.commerce.services.commands.BLXPODServicesTaskCmd; com.bluelinx.commerce.services.objects.BLXGetPODsRequest; com.bluelinx.commerce.services.objects.BLXPODServicesResponse; com.bluelinx.commerce.services.objects.BLXSearchByDateRangeRequest; com.bluelinx.commerce.services.objects.BLXSearchByInvoiceNumberRequest; com.bluelinx.commerce.services.objects.BLXSearchByPONumberRequest; com.bluelinx.commerce.services.objects.CustomerIds; com.bluelinx.commerce.services.objects.PODDetails; com.ibm.commerce.beans.SmartDataBean; com.ibm.commerce.beans.SmartDataBeanImpl; com.ibm.commerce.command.CommandFactory; com.ibm.commerce.command.NameValuePair;
public class PODServicesDataBean extends SmartDataBeanImpl implements SmartDataBean { private final static String CLASSNAME = PODServicesDataBean.class.getNam e(); private final static String COMPONENTNAME = PODServicesDataBean.class.ge tPackage().getName(); private final static Logger LOGGER = Logger.getLogger(COMPONENTNAME); private String invoiceNumber = ""; private String poNumber = ""; private String startDate = ""; private String endDate = ""; private List<PODDetails> podDetails =null; private List<NameValuePair> userData =null; /** * This method sets the invoice number for the search by invoice * number functionality. * @param invoiceNumber the invoiceNumber to set */ public void setInvoiceNumber(String invoiceNumber) { this.invoiceNumber = invoiceNumber; } /** * This method sets the PO number for the search by PO * number functionality. * @param poNumber the poNumber to set */ public void setPoNumber(String poNumber) { this.poNumber = poNumber; } /** * This method sets the start date for the search by date * functionality. * @param startDate the startDate to set
*/ public void setStartDate(String startDate) { this.startDate = startDate; } /** * This method sets the end date for the search by date * functionality. * @param endDate the endDate to set */ public void setEndDate(String endDate) { this.endDate = endDate; } /** * This method returns set of POD details that has been returned * as a result of the search. * * @return List<PODDetails> the list containing POD details. */ public List<PODDetails> getPodDetails() { if (null == podDetails) { podDetails = new ArrayList<PODDetails>(0); } return podDetails; } /** * This method returns set of userData that has been returned * as a result of the search. * * @return List<NameValuePair> the list containing userData. */ public List<NameValuePair> getUserData() { if (null == userData) { userData = new ArrayList<NameValuePair>(0); } return userData; } /** * This method returns set of customer ids for the current user. * * @return List<CustomerIds> the list containing customer ids. */ public List<CustomerIds> getCustomerIds() { List<CustomerIds> customerIds = new ArrayList<CustomerIds>(); /* * TODO - based on how the design will be done */ /* * passing Static fake customer ids * NEED TO IMPLEMENT */
CustomerIds customerId = new CustomerIds(); customerId.setRegionNumber(654); customerId.setCustomerNumber(98765); customerIds.add(customerId); return customerIds; } /** * This method will create an instance of BLXPODServicesTaskCmd and * invoke private method performSearch that will handle the search. * */ public void populate() throws Exception { final String METHODNAME = "populate()"; LOGGER.entering(CLASSNAME, METHODNAME); if (getCustomerIds().size() > 0) { BLXPODServicesTaskCmd blxPODServicesTaskCmd = (BLXPODSer vicesTaskCmd) CommandFactory.createCommand("com.blx.commerce.services. command.BLXPODServicesTaskCmd", this.getCommandContext().getStoreId()); blxPODServicesTaskCmd.setCommandContext(this.getCommandC ontext()); performSearch(blxPODServicesTaskCmd); } LOGGER.exiting(CLASSNAME, METHODNAME); } /** * This method will perform search based on the values that have been * set by the entity that invokes this bean. The possible values that * can be set are: * * invoiceNumber: if this value is not empty, BLXPODServicesTaskCmd's * searchByInvoiceNumber method will be called * poNumber: if this value is not empty, BLXPODServicesTaskCmd's * searchByPONumber method will be called * startDate and endDate: if this value is not empty, BLXPODServicesTas kCmd's * searchByDateRange method will be called * none: if all of the above values are empty, BLXPODServicesTaskCmd's * getPODs method will be called * * The method will set the pod details List to response's pod details l ist. * */ private void performSearch(BLXPODServicesTaskCmd blxPODServicesTaskCmd) throws Exception { BLXPODServicesResponse response = null; if (!invoiceNumber.equals("")) {
response = searchByInvoiceNumber(blxPODServicesTaskCmd); } else if (!poNumber.equals("")) { response = searchByPONumber(blxPODServicesTaskCmd); } else if (!startDate.equals("") && !endDate.equals("")) { response = searchByDateRange(blxPODServicesTaskCmd); } else { response = getP0Ds(blxPODServicesTaskCmd); } if (null != response) { podDetails = response.getPod(); } } /** * This method will perform the search for the search by invoice number * functionality. The method will set the POD details List to response 's * POD details list. * * @return BLXPODServicesResponse the response of the search. */ private BLXPODServicesResponse searchByInvoiceNumber (BLXPODServicesTaskCmd blxPODServicesTaskCmd) throws Exception { BLXSearchByInvoiceNumberRequest request = new BLXSearchByInvoice NumberRequest(); request.setCustomerIds(getCustomerIds()); request.setInvoiceNumber(Integer.getInteger(invoiceNumber)); return blxPODServicesTaskCmd.searchByInvoiceNumber(request); } /** * This method will perform the search for the search by invoice number * functionality. The method will set the POD details List to respons e's * POD details list. * * @return BLXPODServicesResponse the response of the search. */ private BLXPODServicesResponse searchByPONumber (BLXPODServicesTaskCmd blxPODServicesTaskCmd) throws Exception { BLXSearchByPONumberRequest request = new BLXSearchByPONumberRequ est(); request.setCustomerIds(getCustomerIds()); request.setPoNumber(poNumber); return blxPODServicesTaskCmd.searchByPONumber(request); } /** * This method will perform the search for the search by invoice number * functionality. The method will set the POD details List to response' s
* POD details list. * * @return BLXPODServicesResponse the response of the search. */ private BLXPODServicesResponse searchByDateRange (BLXPODServicesTaskCmd blxPODServicesTaskCmd) throws Exception { BLXSearchByDateRangeRequest request = new BLXSearchByDateRangeRe quest(); request.setCustomerIds(getCustomerIds()); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd") ; request.setStartDate(new Timestamp(dateFormat.parse(startDate).g etTime())); request.setEndDate(new Timestamp(dateFormat.parse(endDate).getTi me())); return blxPODServicesTaskCmd.searchByDateRange(request); } /** * This method will perform the search for the search by invoice number * functionality. The method will set the POD detail List to response's * POD detail list. * * @return BLXPODServicesResponse the response of the search. */ private BLXPODServicesResponse getP0Ds (BLXPODServicesTaskCmd blxPODServicesTaskCmd) throws Exception { BLXGetPODsRequest request = new BLXGetPODsRequest(); request.setCustomerIds(getCustomerIds()); return blxPODServicesTaskCmd.getP0Ds(request); } }