< Previous | Next >

Generate Java components

  1. Click the ClicksAndTacksF1 – Assembly diagram tab. Then right-click CheckCustomerAccountStatus and select Generate Implementation > Java.
    ClicksAndTacksF1 – Assembly diagram
  2. Keep the defaults and click OK. CheckCustomerAccountStatusImpl.java opens.
  3. Replace the contents of the following method:
    public DataObject InputCriterion(DataObject input) {
    		//TODO Needs to be implemented.
    		return null;
    	}

    with the following content:

    public DataObject InputCriterion(DataObject input) {
    		System.out.println(
    "Check Customer Account Status Invoked");
        //	create CreditRating bean
    		com.clipstacks.credit.CreditRating creditRating =
    		new com.clipstacks.credit.CreditRating();
        //	call CreditRating bean to update the BO
    		DataObject orderOut = creditRating.calculateCreditRating(input);
    		return orderOut;
    	}
  4. Save your work. Ignore the errors at this time because they will be fixed after you create the Java™ components in the steps to follow.
  5. To create the other two Java components, complete the previous steps to generate Java implementations for the following components and then replace the following methods.
    1. For UpdateOrderDatabase, replace the contents of the following method:
      public DataObject InputCriterion(DataObject input) {
      		//TODO Needs to be implemented.
      		return null;
      }

      with the following content:

      public DataObject InputCriterion(DataObject input) {
      	   System.out.println("Update Order Database invoked");
      	   return input;
      }
    2. For CancelOrderandSendNotification, generating the Java component builds the text part of the Notification business object. Replace the contents of the Java file with this content and then save the changes:
      package sca.component.java.impl;
      
      import commonj.sdo.DataObject;
      import com.ibm.websphere.sca.ServiceManager;
      import java.math.BigDecimal;
      import java.util.List;
      
      public class CancelOrderandSendNotificationImpl {
      	/**
      	 * Default constructor.
      	 */
      	private com.ibm.websphere.sca.ServiceManager serviceManager = null;
      	private com.ibm.websphere.bo.BOFactory boFactory = null;
      	String namespace = "http://ClipsAndTacksF1/Businessitems";
      	public CancelOrderandSendNotificationImpl() {
      		super();
      		serviceManager = new com.ibm.websphere.sca.ServiceManager();
      		boFactory = (com.ibm.websphere.bo.BOFactory)serviceManager
      		.locateService("com/ibm/websphere/bo/BOFactory");
      	}
      
      	/**
      	 * Return a reference to the component service instance for this implementation
      	 * class. This method should be used when passing this service to a partner 
      			reference
      	 * or if you want to invoke this component service asynchronously.  
      	 *
      	 * @generated (com.ibm.wbit.java)
      	 */
      	private Object getMyService() {
      		return (Object) ServiceManager.INSTANCE.locateService("self");
      	}
      
      	/**
      	 * Method generated to support implemention of operation "InputCriterion" defined 
      			for WSDL port type 
      	 * named "CancelOrderandSendNotification".
      	 * 
      	 * The presence of commonj.sdo.DataObject as the return type and/or as a parameter 
      	 * type conveys that its a complex type. 
      		Please refer to the WSDL Definition for more information 
      	 * on the type of input, output and fault(s).
      	 */
      	public DataObject InputCriterion(DataObject Input) {
      		System.out.println("Cancel order invoked");
      		// retrieve customer e-mail address
      		DataObject customer = Input.getDataObject("Customer");
      		String emailAddress = customer.getString("Email");
      
      		// create e-mail text
      		String text1 = "Shipment for order: " + Input.getInt("OrderNumber") + "\n";
      		String text2 = "Dear " + customer.getString("ContactFirstName") + " " + customer
      		.getString("ContactLastName") + "\n";
      		String text3 = "We are sorry that your order was cancelled.\n";
      		String text4 = "The amount of $" + Input.getDouble("TotalPrice") + " was too 
      			much at this time\n";
      		String text5 = "We hope to serve you again in the future.\n";
      		List orderitems = Input.getList("OrderItems");
      		int nrofitems = orderitems.size();
      		System.out.println("orderitems.size = " + nrofitems);
      		String itemtext[] = new String[nrofitems];
      		String text6 = ""; 
      		String fortyBlanks = "                    "; //need this to ensure the product 
      			name has at least 40 chars
      		for (int i=0; i<nrofitems; i++) {
      			DataObject item = (DataObject)orderitems.get(i);
      			String productName = (item.getString("ProductName") + fortyBlanks)
      			.substring(0, 40);
      			itemtext[i] = item.getInt("Quantity") + " " + item.
      			getString("ProductNumber") + " " + productName + " $" + new 
      			BigDecimal(item.getDouble("Price"));
      			text6 = text6 + itemtext[i] + "\n";
      		}
      		String emailText = "\n" + text1 + text2 + text3 + text4 + text5 + text6;
      		
      		// build notification data object
      		DataObject notification = boFactory.create(namespace, "Notification");
      		notification.setString("email", emailAddress);
      		notification.setString("text", emailText);
      		System.out.println("Cancel order email address: " + emailAddress);
      		System.out.println("Cancel order email text: " + emailText);
      		
      		return notification;
      	}
      
      }
      Important: If you cut and paste this content into the Java editor, ensure that the variable fortyBlanks does not get compressed down to a single blank. It must be 40 blanks (spaces) for the code to work correctly.
  6. Save your work and close the window.

Provide the implementation for calculating customer credit ratings

  1. Create a Java package by selecting File > New > Other and then Java > Package. Then click Next >.
  2. For the source folder, click Browse and select ClipsAndTacksF1 > gen/src. Click OK.
  3. For the Java package name, enter com.clipstacks.credit and then click Finish.
    New Java Package wizard
  4. Switch to the Physical Resources view by clicking the Physical Resources tab (where the Business Integration tab is).
  5. Expand ClipsAndTacksF1 > com > clipstacks > credit and copy the CreditRating.java file that you downloaded following the directions in the Download section. Then paste the file into the credit folder.
    Credit folder
  6. Switch back to the assembly diagram editor and save it.
  7. Save any unsaved items. An open window with an asterisk (*) on the tab indicates that it is not saved. You should not have errors now. If there are errors, fix them before generating the user interface.
  8. Rebuild all projects by selecting Project > Clean and then OK.
    Project menu
    Important: Ensure that the Building workspace action is completed before you generate the user interface. When building is complete, you will not see the following sign percent and status bar indicators. If the icon clears quickly, it is best to wait approximately one minute to be sure all build activity has completed.
    Status bar
< Previous | Next >