Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • all the folders required including also the MANIFEST,
  • Eclipse files

in one step.

To create one of the tutorial project, you can follow the procedure described here

...

2) Import the generated eclipse project in Eclipse workspace
3) Delete readme.txt, build.properties and template.mf files
3) Enable dependency management (see sonatype site).

otherwise import the content of the unzipped file in your workspace. You will gain time.

Step 2 : Develop

...

layers model

It is time now to begin serious things. One of the most important part of a project (if not the most important) concerns the design of the model. The reportincident model is really simple because it only contains one class that we will use to map information with the database.

Here is the definition of the incident class (that you can create in the reportincident.model project or use the code imported)

Code Block

import java.io.Serializable;

public class Incident implements Serializable{

	private static final long serialVersionUID = 1L;
	
	protected long incidentId;

	protected String incidentRef;
	
	protected Date incidentDate;
	
	protected String givenName;
	
	protected String familyName;
	
	protected String summary;
	
	protected String details;
	
	protected String email;
	
	protected String phone;
	
	protected String creationUser;
	
	protected Date creationDate;
	
	
	public long getIncidentId() {
		return incidentId;
	}

	public void setIncidentId(long incidentId) {
		this.incidentId = incidentId;
	}
	
	public String getIncidentRef() {
		return incidentRef;
	}

	public void setIncidentRef(String incidentRef) {
		this.incidentRef = incidentRef;
	}

	public Date getIncidentDate() {
		return incidentDate;
	}

	public void setIncidentDate(Date incidentDate) {
		this.incidentDate = incidentDate;
	}

	public String getGivenName() {
		return givenName;
	}

	public void setGivenName(String givenName) {
		this.givenName = givenName;
	}

	public String getFamilyName() {
		return familyName;
	}

	public void setFamilyName(String familyName) {
		this.familyName = familyName;
	}

	public String getSummary() {
		return summary;
	}

	public void setSummary(String summary) {
		this.summary = summary;
	}

	public String getDetails() {
		return details;
	}

	public void setDetails(String details) {
		this.details = details;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getCreationUser() {
		return creationUser;
	}

	public void setCreationUser(String creationUser) {
		this.creationUser = creationUser;
	}

	public Date getCreationDate() {
		return creationDate;
	}

	public void setCreationDate(Date creationDate) {
		this.creationDate = creationDate;
	}

}

To facilitate the work of the modeler, we will use this class not only to persist the information in the database but also to read or generate Comma Separate Value file. To map the content of the class with a CSV file, we have used a new Camel component : camel-bindy. Like its name suggests, camel-bindy is a binding framework (similar to JAXB) to map non structured information with Java class using annotations. The current version supports CSV fields and key-value pairs (e.g. Financial FIX messages) but will be extended in the future to support Fixed Length format, ....

So, we will modify our existing class to add @Annotations required to map its content. This is very trivial to do and will be done in two steps :

1) Add CSVRecord annotation

This annotation will help camel-bindy to discover what is the parent class of the model and which separator is used to separate the fields. If required, you can also use the property 'skipFirstLine' to skip the first line of your CSV file

Code Block

import org.apache.camel.dataformat.bindy.annotation.CsvRecord;

@CsvRecord(separator =",")
public class Incident implements Serializable{
...
}

2) Add DataFields annotations

For each of the CSV field that you want to bind with your model, you must add the @DataField annotation with its position. This is not the only property available and you can also add 'pattern' property to by example define the pattern of your Date field.

Code Block

import org.apache.camel.dataformat.bindy.annotation.CsvRecord;
import org.apache.camel.dataformat.bindy.annotation.DataField;

@CsvRecord(separator =",")
public class Incident implements Serializable{

    @DataField(pos = 0)
    protected String incidentRef;
	
    @DataField(pos = 1, pattern = "dd-mm-yyyy")
    protected Date incidentDate;
	
    @DataField(pos = 2)
    protected String givenName;
	
    @DataField(pos = 3)
    protected String familyName;
	
    @DataField(pos = 4)
    protected String summary;

    @DataField(pos = 5)
    protected String details;
	
    @DataField(pos = 6)
    protected String email;
	
    @DataField(pos = 7)
    protected String phone;

...
}

#Resources

  • Attachments
    patterns.*part2.zip