-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Builder pattern for building Person and Tithe Entities
- Create Builder class - Create Head of family and family members, when a new family is created - Create a new Graphql schema for Person mutation input through family - Removed @NotNull constraint in PersonMutationInput for family field
- Loading branch information
1 parent
2fd02a9
commit ef8b007
Showing
13 changed files
with
364 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
Tithe-Spring/src/main/java/com/tithe/entity/PersonBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/** | ||
* | ||
*/ | ||
package com.tithe.entity; | ||
|
||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
import com.tithe.model.GenderEnum; | ||
import com.tithe.utils.ObjectValidation; | ||
|
||
|
||
/** | ||
* @author Ashish Sam T George | ||
* | ||
*/ | ||
public class PersonBuilder { | ||
|
||
private Long personId; | ||
private String baptismName; | ||
private String personName; | ||
private FamilyEntity family; | ||
private RelationEntity relation; | ||
private GenderEnum gender; | ||
private LocalDate dob; | ||
private String phone; | ||
private List<TitheEntity> tithes; | ||
private Boolean moved = false; | ||
private List<EducationEntity> educations; | ||
private List<OccupationEntity> occupations; | ||
private Boolean active = true; | ||
|
||
public PersonBuilder personId(Long personId) { | ||
this.personId = personId; | ||
return this; | ||
} | ||
|
||
public PersonBuilder baptismName(String baptismName) { | ||
this.baptismName = baptismName; | ||
return this; | ||
} | ||
|
||
public PersonBuilder personName(String personName) { | ||
this.personName = personName; | ||
return this; | ||
} | ||
|
||
public PersonBuilder family(FamilyEntity family) { | ||
this.family = family; | ||
return this; | ||
} | ||
|
||
public PersonBuilder relation(RelationEntity relation) { | ||
this.relation = relation; | ||
return this; | ||
} | ||
|
||
public PersonBuilder gender(GenderEnum gender) { | ||
this.gender = gender; | ||
return this; | ||
} | ||
|
||
public PersonBuilder dob(LocalDate dob) { | ||
this.dob = dob; | ||
return this; | ||
} | ||
|
||
public PersonBuilder phone(String phone) { | ||
this.phone = phone; | ||
return this; | ||
} | ||
|
||
// public PersonBuilder tithes(List<TitheEntity> tithes) { | ||
// this.tithes = tithes; | ||
// return this; | ||
// } | ||
|
||
public PersonBuilder moved(Boolean moved) { | ||
this.moved = moved; | ||
return this; | ||
} | ||
|
||
public PersonBuilder educations(List<EducationEntity> educations) { | ||
this.educations = educations; | ||
return this; | ||
} | ||
|
||
public PersonBuilder occupations(List<OccupationEntity> occupations) { | ||
this.occupations = occupations; | ||
return this; | ||
} | ||
|
||
public PersonBuilder active(Boolean active) { | ||
this.active = active; | ||
return this; | ||
} | ||
|
||
public PersonEntity build() { | ||
PersonEntity person = new PersonEntity(personId, baptismName, personName, family, relation, gender, dob, phone, | ||
tithes, moved, educations, occupations, active); | ||
return person; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
Tithe-Spring/src/main/java/com/tithe/entity/TitheBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/** | ||
* | ||
*/ | ||
package com.tithe.entity; | ||
|
||
|
||
import java.time.LocalDate; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import com.tithe.model.TitheMutationInput; | ||
|
||
|
||
/** | ||
* @author Ashish Sam T George | ||
* | ||
*/ | ||
public class TitheBuilder { | ||
|
||
private Long titheId; | ||
private Double titheAmount; | ||
private PersonEntity person; | ||
private FamilyEntity family; | ||
private KoottaymaEntity koottayma; | ||
private ParishEntity parish; | ||
private ForaneEntity forane; | ||
private LocalDate timeStamp; | ||
|
||
public TitheBuilder titheId(Long titheId) { | ||
this.titheId = titheId; | ||
return this; | ||
} | ||
|
||
public TitheBuilder titheAmount(Double titheAmount) { | ||
this.titheAmount = titheAmount; | ||
return this; | ||
} | ||
|
||
public TitheBuilder person(PersonEntity person) { | ||
this.person = person; | ||
return this; | ||
} | ||
|
||
public TitheBuilder family(FamilyEntity family) { | ||
this.family = family; | ||
return this; | ||
} | ||
|
||
public TitheBuilder koottayma(KoottaymaEntity koottayma) { | ||
this.koottayma = koottayma; | ||
return this; | ||
} | ||
|
||
public TitheBuilder parish(ParishEntity parish) { | ||
this.parish = parish; | ||
return this; | ||
} | ||
|
||
public TitheBuilder forane(ForaneEntity forane) { | ||
this.forane = forane; | ||
return this; | ||
} | ||
|
||
public TitheBuilder timeStamp(LocalDate timeStamp) { | ||
this.timeStamp = timeStamp; | ||
return this; | ||
} | ||
|
||
public TitheEntity build() { | ||
TitheEntity tithe = new TitheEntity(titheId, titheAmount, person, family, koottayma, parish, | ||
forane, timeStamp); | ||
return tithe; | ||
} | ||
|
||
public List<TitheEntity> buildTithe(PersonEntity person, | ||
List<TitheMutationInput> titheMutationInputs) { | ||
List<TitheEntity> tithes = new ArrayList<>(); | ||
if (titheMutationInputs != null && titheMutationInputs.size() != 0) { | ||
// objectValidation.validateObjects(titheMutationInputs); | ||
|
||
for (TitheMutationInput titheMutationInput : titheMutationInputs) { | ||
// New Builder object for each tithe | ||
TitheBuilder titheBuilder = new TitheBuilder(); | ||
TitheEntity tithe = titheBuilder.titheAmount(titheMutationInput.getTitheAmount()) | ||
.person(person) | ||
.family(person.getFamily()) | ||
.koottayma(person.getFamily().getKoottayma()) | ||
.parish(person.getFamily().getKoottayma().getParish()) | ||
.forane(person.getFamily().getKoottayma().getParish().getForane()) | ||
.timeStamp(titheMutationInput.getTimeStamp()) | ||
.build(); | ||
tithes.add(tithe); | ||
} | ||
} | ||
return tithes; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.