Presented by: SIF3: First Consumer - Java Joerg Huber SIF3 Consumer: Get Students Exercise
© Systemic Pty Ltd September 2014 Training Course - Sydney: SIF3: First Consumer 2 How to develop a Consumer What is a Consumer Initial Considerations Data Model Classes Consumer Classes Steps developing a consumer Get Student & Get Students Exercise Develop Basic Consumer and Run it… Ensure Demo Provider returns data
© Systemic Pty Ltd September 2014 Training Course - Sydney: SIF3: First Consumer 3 What is a Consumer A Client in the traditional sense. Can be standalone executable or part of a larger web- and/or mobile application. It typically requests CRUD operations: Create, Read/Get, Update & Delete Objects (i.e. Students) It can subscribe to Events if events are supported by the provider of data. A consumer is not considered the “source of truth”, meaning CRUD requests might be rejected by the provider!
© Systemic Pty Ltd September 2014 Training Course - Sydney: SIF3: First Consumer 4 Initial Considerations What Data Model to use (i.e. SIF AU 1.3)? What SIF Objects do I need to deal with? What CRUD request do I need to deal with? Do I need to deal with SIF Events? Most likely only available in brokered environment Will be shown during this training course as part of a Live Demo. Are delayed request/responses required? Most likely only available in brokered environment Outside the scope of this training
© Systemic Pty Ltd September 2014 Training Course - Sydney: SIF3: First Consumer 5 Data Model Classes The SIF3 Framework has a library with the SIF AU 1.3 data model ( sifDataModel_au1.3.jar ). Generated based on SIF AU 1.3 XSD. Has methods to marshal/unmarshal to/from XML Classes are named as the SIF Object: Single Student: StudentPersonalType Student List: StudentPersonalCollectionType If another data model is required you can: Generate it using the data model’s XSD if available. Manually develop it. Get hold of 3 rd party library that encapsulates the data model. Ensure marshal/unmarshal to/from XML is available or you need to implement this.
© Systemic Pty Ltd September 2014 Training Course - Sydney: SIF3: First Consumer 6 Core Consumer Classes The following is a list of core classes required for developing a consumer. Details will follow as part of the exercise. ConsumerLoader initialise: Initialises a Consumer and allocates resources shutdown: Releases resources allocated with consumer. AbstractConsumer (CRUD) or AbstractEventConsumer (CRUD & Events) Each SIF Object used in the final consumer must extend one of these two classes. Forces a number of methods to be implemented
© Systemic Pty Ltd September 2014 Training Course - Sydney: SIF3: First Consumer 7 Steps developing a consumer For each SIF Object used in the consumer write a separate class extending AbstractConsumer or AbstractEventConsumer Implement abstract and/or interface methods Link marshal/unmarshal with consumer Ensures that SIF3 Framework produces correct XML Use DataModelUnmarshalFactory & DataModelMarshalFactory from sifDataModel_au1.3.jar! Link SIF Object Class with each consumer Implement getSingleObjectClassInfo and getMultiObjectClassInfo methods to return appropriate ModelObjectInfo (see demo code) Use predefined constants
© Systemic Pty Ltd September 2014 Training Course - Sydney: SIF3: First Consumer 8 Steps developing a consumer (cont.) Configure the following in the consumer.properties file: List each consumer class as a comma separated list in the “consumer.classes” property Set the package name of the consumer classes in the “consumer.basePackageName” property. As part of this training most of the above should be pre-set. Refer to Developer’s Guide for much more details on how to develop a consumer.
© Systemic Pty Ltd September 2014 Training Course - Sydney: SIF3: First Consumer 9 Exercise – StudentPersonal Consumer As part of this exercise we only use AbstractConsumer (we don’t do events) Implement StudentPersonalConsumer in sif3demo.consumer package Note what class it extends! Note it only requires methods related to data model and mapping to internal model classes. Implement DemoConsumer (executable) in sif3demo.service package: getStudent (get Single Students) getStudents(Get list of Students) Note where the ConsumerLoader methods are used. Also refer to javadoc of the SIF3 Framework for details about classes.
© Systemic Pty Ltd September 2014 Training Course - Sydney: SIF3: First Consumer 10 Exercise – Run DemoConsumer Ensure your provider is running in your web- or application container. Ensure that the provider has loaded the students. At start-up you should see a log entry indicating 608 students are loaded. If not check weather the property provider.student.file.location in the provider.properties file points to a valid location. Within your IDE you should be able to run the DemoConsumer class. It is an executable. Observe the output on the command line…