/introsde-2017-assignment-1

Assignment 01: Reading/Writing objects to and from XML and JSON

Primary LanguageJava

First Assignment

Identification

Student: Federico Baldessari Email: federico.baldessari@studenti.unitn.it

Project

About the code

The project is divided into 3 packages:

  • default package: it contains XMLPeopleReader.java that loads the people.xml file and parses it using XPath to implement methods like getActivityDescription, getActivityPlace, printing all people in the list with details and more.
  • jaxb: it contains JaxbMarshaller.java, JaxbUnMarshaller.java, JsonMarshaller.java that does the marshalling and un-marshalling
  • model.generated: it contains classes generated with JAXB XJC from people.xsd that are used by JaxbMarshaller, JaxbUnMarshaller and JsonMarshaller

About the task

    1. "Extend the example above to include 20 people (maybe your friends with fake names)" The result can be see in src/people.xml
    1. "Use XPath to implement methods like getActivityDescription and getActivityPlace. Use the person ID as parameter of the getters." The functions are inside XMLPeopleReader.java
    1. "Make a function that prints all people in the list with details." The function is inside XMLPeopleReader.java. It was decided to print the people in the form:
    ------ Person info -------
    -> person
    firstname           Elia
    lastname            Tasini
    birthdate           1993-01-02
    -> activitypreference
    name                Running
    description         Sprint Running
    place               Harena Stadium
    startdate           2017-09-13T11:50:00.0
    --------------------------
    
    using the private function printListPerson and printPerson
    1. "Make a function that accepts the person id as parameter and prints the ActivityPreference of the person with that id." The function is inside XMLPeopleReader.java. It was decided to use the same print format to print people details showing only activitypreference information
    1. "Make a function which accepts a date and an operator (=, > , <) as parameters and prints people which preferred activity start_date fulfill that condition (i.e., startdate>2017-13-10, startdate=2017-13-10, etc.)" The function is inside XMLPeopleReader.java
    1. "Create the XML schema XSD file for the example XML document of people." The XSD file can be found in the root of the project people.xsd
    1. "Write a java application that does the marshalling and un-marshalling using classes generated with JAXB XJC." In the package jaxb: JaxbMarshaller.java and JaxbUnMarshaller.java uses classes generated with JAXB XJC inside package model.generated. JaxbUnMarshaller.java generates a file 3people.xml in the root
    1. "Make your java application to convert also JSON (Create 3 persons using java and marshal them to JSON)" In the package jaxb: JsonMarshaller uses library jackson to generate file 3people.json. This is possible because classes in model.generated uses JAXB annotation and Jackson allow use of JAXB annotations as an alternative (in addition to or instead of) standard Jackson annotations.

Execution

First clone the repository to a location of your choice by running:

git clone https://github.com/balde73/introsde-2017-assignment-1.git
cd introsde-2017-assignment-1

Now you are ready to execute

ant execute.evaluation

To make thing cleaner it is also possible to run a single step of the evaluation. Remember to run ant before to compile classes and download libraries

// As default ant compiles and downloads everything needed
ant
// 1. Runs instruction 3 based on Lab 3
ant execute.step1
// 2. Runs instruction 4 based on Lab 3 with id = 5
ant execute.step2
// 3. Runs instruction 5 based on Lab 3 with startdate > 2017-10-13
ant execute.step3
// 4. > Runs instruction 7 based on Lab 4, executing marshaling to XML. Create 3 persons using java and marshal them to XML
ant execute.step4
// 5. > Runs instruction 7 based on Lab 4, executing un-marshaling from XML
ant execute.step5
// 6. > Runs instruction 8 based on Lab 4, executing marshaling to JSON. Create 3 persons using java and marshal them to JSON
ant execute.step6