Skip to main content

First Microservice - Lead Service

This is a continuation of my previous post where I listed the key domain components of CRM. For sake of simplicity, I will focus on just two key components - Lead and Opportunity respectively. These two modules will help me explore end to microservice implementation. I will be primarily using Spring framework's support to deliver the microservices. I am deliberating on a nice interesting Javascript framework for the front end. More on this later.

Goal

For the time being, I am just going to focus on building the backend and cloud enable it. Then slowly I am going to add the front end and security to the backend and front end. I will also explore the complete Sping Cloud gamut of projects and beyond. I will then deliberate on cloud-native applications, transactions and actually making this application suitable to run on virtually any cloud. I will also explore cloud and microservices application design patterns. Last but not the least we also need to check where this application fits in the maturity model for the 12-factor application.



Step 1 - Create a Spring Boot quickstart project using STS.

I am using the 64-bit version of STS 3.8.4 on my laptop.
The first step is to click in the following sequence:

File -> New -> Spring Starter Project. In the dialog fill out the data as shown in Figure 1.

Figure 1 - Configure Spring Starter Project
Then click on 'Next' to fill out the final dialog as shown in Figure 2. Once the final dialog is filled out with the selections click on 'Finish'.

Figure 2 - Select the dependencies

Step 2 - Add the Lead domain class.

Let's go ahead and add the lead domain class. I am assuming some familiarity with Eclipse/STS and will not show how to create a new package or a Java class.

Listing 1 - Lead.java

package com.effectiv.crm.domain;
import javax.persistence.*;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import lombok.EqualsAndHashCode;
@Entity
@Table(name="T_LEAD")
@Data
@EqualsAndHashCode(callSuper=true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Lead extends BaseEntity{
@Column(name="FIRST_NAME", nullable=true)
private String firstName;
@Column(name="LAST_NAME", nullable=true)
private String lastName;
@Column(name="COMPANY_NAME", nullable=true)
private String company;
@Column(name="EMAIL", nullable=true)
private String email;
@Column(name="PHONE", nullable=true)
private String phone;
@Column(name="MOBILE", nullable=true)
private String mobile;
@Column(name="DESIGNATION", nullable=true)
private String designation;
@Column(name="WEBSITE", nullable=true)
private String website;
@Column(name="FAX", nullable=true)
private String fax;
@Column(name="ANNUAL_REVENUE", nullable=true)
private double annualRevenue;
@Column(name="NO_OF_EMPLOYEES", nullable=true)
private int noOfEmployees;
@Column(name="INDUSTRY_LOV_ID", nullable=true)
private String industry;
@Column(name="SALUTATION_LOV_ID", nullable=true)
private String salutation;
@Column(name="LEADSOURCE_LOV_ID", nullable=true)
private String leadSource;
@Column(name="LEADSTATUS_LOV_ID", nullable=true)
private String leadStatus;
@Column(name="RATING_ID", nullable=true)
private String rating;
@Column(name="ASSIGNED_USER_ID", nullable=true)
private String assignedUser;
@Column(name="ASSIGNED_TEAM_ID", nullable=true)
private String assignedTeam;
@Column(name="EMAIL_OPT_OUT", nullable=true)
private boolean emailOptOut;
@Column(name="TWITTER", nullable=true)
private String twitter;
@Column(name="FACEBOOK", nullable=true)
private String facebook;
@Embedded
private Address address;
@Column(name="DESCRIPTION", nullable=true)
private String description;
}
view raw Lead.java hosted with ❤ by GitHub

The common properties are in the BaseEntity class which is shown in Listing 2.
Listing 2 - BaseEntity.java 

package com.effectiv.crm.domain;
import java.util.*;
import javax.persistence.*;
import javax.persistence.Id;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.*;
import org.springframework.data.annotation.Version;
import com.fasterxml.jackson.annotation.*;
import lombok.Data;
@Data
@MappedSuperclass
@JsonInclude(JsonInclude.Include.NON_NULL)
public class BaseEntity {
@Id
@GeneratedValue(generator = "system-uuid")
@GenericGenerator(name = "system-uuid", strategy = "uuid2")
@Column(name = "ID", length = 40)
private String id;
@Column(name = "DELETED")
private boolean deleted;
@Version
@Column(name = "VERSION")
private int version;
@ElementCollection
private Map<String, String> extensions = new HashMap<>();
@CreatedDate
@Column(name = "CREATED_DATE")
private Date createdDate;
@CreatedBy
@Column(name = "CREATED_BY")
private String createdBy;
@LastModifiedDate
@Column(name = "LAST_MODIFIED_DATE")
private Date lastModifiedDate;
@LastModifiedBy
@Column(name = "LAST_MODIFIED_BY")
private String lastModifiedBy;
@JsonAnySetter
public void anySet(String name, String value) {
extensions.put(name, value);
}
@JsonAnyGetter
public String anyGet(String name) {
return extensions.get(name);
}
}
view raw BaseEntity.java hosted with ❤ by GitHub
The Address class is embedded in the Lead class. This is shown in Listing 3.
Listing 3 - Address.java
package com.effectiv.crm.domain;
import javax.persistence.*;
import com.fasterxml.jackson.annotation.JsonInclude;
@JsonInclude(JsonInclude.Include.NON_NULL)
@Embeddable
public class Address {
@Column(name="STREET", nullable=true)
private String street;
@Column(name="ZIP", nullable=true)
private String zip;
@Column(name="PO_BOX", nullable=true)
private String poBox;
@Column(name="CITY", nullable=true)
private String city;
@Column(name="STATE", nullable=true)
private String state;
@Column(name="COUNTRY", nullable=true)
private String country;
}
view raw Address.java hosted with ❤ by GitHub

I will end the day today by adding the Lead JPA repository.

Listing 4 - LeadRepository.java
package com.effectiv.crm.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import com.effectiv.crm.domain.Lead;
public interface LeadRepository extends JpaRepository<Lead, String> {
}
The source code is hosted on Github.
GitHub Repo - https://github.com/kdhrubo/playground.git

Comments

Popular posts from this blog

Part 3 - Integrating Tiles, Thymeleaf and Spring MVC 3

In this post I will demonstrate how to integrate Apache Tiles with Thymeleaf. This is very simple. The first step is to include the tiles and thymeleaf-tiles extension dependencies. I will include them in the pom.xml. Note we wil lbe using Tiles 2.2.2 Listing 1 - parent/pom.xml --- thymeleaf-tiles and tiles dependencies <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --> <!-- Tiles --> <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --> <dependency> <groupId>org.apache.tiles</groupId> <artifactId>tiles-core</artifactId> <version>${tiles.version}</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.apache.tiles</groupId> <artifactId>tiles-template</artifactId> <version>${tiles.version}</version> <scope>compile</s...

Breaking down the CRM monolith

In my previous posts, I have shared some theory regarding microservices. But it's time to start some implementation. I love to write code and see and feel things working. So I will start a series to refactor a monolithic CRM system and transform it into microservices based flexible software. Big ball of mud. Customer Relationship Management(CRM) is that giant software which existed since time immemorial and is used by all companies in some form or shape. Big enterprises will buy CRM software (also known as packages) from top CRM vendors like Oracle, SAP, Salesforce etc and then employ an army of consultants to try and implement it. Most of the classic CRM systems in the market today, even if deployed on the cloud are the big monolithic ball of mud. They are the gigantic piece of software with the huge feature set. Most often those requirements are surplus to the requirement or they will not fit into the processes of the company. So the company has to hire these certified consu...

Getting started with Prime faces 2

Prime faces is an amazing JSF framework from Cagatay Civici ( http://cagataycivici.wordpress.com/ ). Its wonderful because it is easy to use, minimal dependencies, has probably the widest set of controls among all JSF frameworks, easy to integrate with Spring (including Spring Security) , Java EE EJBs, and last but not the least mobile UI support. So I decided to give Prime faces a try, before selecting it to use in my projects. Step 1 – Create Maven 2 project As a first step to integrating Prime faces, create a Maven 2 project in Eclipse. You will need to select ‘maven-archetype-webapp’. Step 2 – Add repositories and dependencies in pom.xml I will be using Prime faces 2 with JSF 2 on Tomcat 6. Since the dependencies for Prime Faces and JSF 2 (JSF 2.0.3 is required) are available on different repositories, I will add them to my pom file first. The listing below shows my pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/X...