SHARE
TWEET

entity dan pojo

a guest May 23rd, 2019 103 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     ## Entity : MstReminder.java ##
  2.  
  3. package id.co.sofcograha.gajiidapi.domain.hris.mst.reminder.remindersetting.entities;
  4.  
  5. import java.util.List;
  6.  
  7. import javax.persistence.ElementCollection;
  8. import javax.persistence.Entity;
  9. import javax.persistence.OneToMany;
  10.  
  11. import id.co.sofcograha.gajiidapi.base.extendables.BaseEntity;
  12. import id.co.sofcograha.gajiidapi.base.mst.user.entities.User;
  13.  
  14. @Entity
  15. public class MstReminder extends BaseEntity{
  16.     private String workplaceName;
  17.     private String departmentName;
  18.    
  19.     @OneToMany(targetEntity = User.class)
  20.     private List<User> users;
  21.    
  22.     @ElementCollection
  23.     private List<String> emails;
  24.    
  25.     private String type;
  26.    
  27.     public String getWorkplaceName() {
  28.         return workplaceName;
  29.     }
  30.    
  31.     public void setWorkplaceName(String workplaceName) {
  32.         this.workplaceName = workplaceName;
  33.     }
  34.    
  35.     public String getDepartmentName() {
  36.         return departmentName;
  37.     }
  38.    
  39.     public void setDepartmentName(String departmentName) {
  40.         this.departmentName = departmentName;
  41.     }
  42.    
  43.     public List<User> getUser() {
  44.         return users;
  45.     }
  46.    
  47.     public void setUser(List<User> users) {
  48.         this.users = users;
  49.     }
  50.    
  51.     public List<String> getEmail() {
  52.         return emails;
  53.     }
  54.    
  55.     public void setEmail(List<String> emails) {
  56.         this.emails = emails;
  57.     }
  58.    
  59.     public String getType() {
  60.         return type;
  61.     }
  62.    
  63.     public void setType(String type) {
  64.         this.type = type;
  65.     }
  66. }
  67. ==============================================================================
  68.     ## Pojo : MstReminderPojo.java ##
  69.  
  70. package id.co.sofcograha.gajiidapi.domain.hris.mst.reminder.remindersetting.pojos;
  71.  
  72. import java.util.ArrayList;
  73. import java.util.List;
  74.  
  75. import com.fasterxml.jackson.annotation.JsonInclude;
  76. import com.fasterxml.jackson.annotation.JsonInclude.Include;
  77.  
  78. import id.co.sofcograha.gajiidapi.base.constants.BaseConstants;
  79. import id.co.sofcograha.gajiidapi.base.extendables.BasePojo;
  80. import id.co.sofcograha.gajiidapi.base.mst.user.entities.User;
  81. import id.co.sofcograha.gajiidapi.base.mst.user.pojos.UserPojo;
  82. import id.co.sofcograha.gajiidapi.base.search.SearchFieldMapping;
  83. import id.co.sofcograha.gajiidapi.domain.hris.mst.reminder.remindersetting.entities.MstReminder;
  84.  
  85. @JsonInclude(Include.ALWAYS)
  86. public class MstReminderPojo extends BasePojo{
  87.    
  88.     public UserPojo userPojo;
  89.    
  90.     private static final long serialVersionUID = 1L;
  91.     public static final String SINGLE = "mstReminder";
  92.     public static final String MULTI = "mstReminders";
  93.    
  94.     public String workplaceName;
  95.     public String departmentName;
  96.     public List<UserPojo> users;
  97.     public List<String> emails;
  98.     public String type;
  99.    
  100.     public MstReminder toEntity() {
  101.         MstReminder entity = new MstReminder();
  102.         entity.setWorkplaceName(super.toEntityString(workplaceName));
  103.         entity.setDepartmentName(super.toEntityString(departmentName));
  104.        
  105.         for(UserPojo user : users) {
  106.             List<User> userList = new ArrayList<>();
  107.             userList.add(super.toReferenceEntity(user, User.class));
  108.         }
  109.        
  110.         for(String email : emails) {
  111.             List<String> emailList = new ArrayList<>();
  112.             emailList.add(super.toEntityString(email));
  113.         }
  114.        
  115.         entity.setType(super.toEntityString(type));
  116.        
  117.         return entity;
  118.     }
  119.    
  120.     public static MstReminderPojo fromEntity(MstReminder entity) {
  121.         return fromEntity(entity, BaseConstants.DEFAULT_QUERY_DEPTH);
  122.     }
  123.    
  124.     public static MstReminderPojo fromEntity(MstReminder entity, int depthLevel) {
  125.         if (entity == null) return null;
  126.         if (depthLevel < 0) depthLevel = BaseConstants.DEFAULT_QUERY_DEPTH;
  127.        
  128.         MstReminderPojo pojo = new MstReminderPojo();
  129.        
  130.         if (depthLevel > 0) {
  131.             depthLevel--;
  132.             pojo.workplaceName = entity.getWorkplaceName();
  133.             pojo.departmentName = entity.getDepartmentName();
  134.            
  135.             List<User> userList = entity.getUser();
  136.             for(User user : userList) {
  137.                 List<UserPojo> userPojoList = new ArrayList<>();
  138.                 userPojoList.add(UserPojo.fromEntity(user));
  139.             }
  140.             pojo.emails = entity.getEmail();
  141.             pojo.type = entity.getType();
  142.         }
  143.        
  144.         return pojo;
  145.     }
  146.    
  147.     public static List<MstReminderPojo> fromEntities(List<MstReminder> entities) {
  148.         return fromEntities(entities, BaseConstants.DEFAULT_QUERY_DEPTH);
  149.     }
  150.    
  151.     public static List<MstReminderPojo> fromEntities(List<MstReminder> entities, int depthLevel) {
  152.         if (entities == null) return new ArrayList<MstReminderPojo>();
  153.         if (depthLevel < 0) depthLevel = BaseConstants.DEFAULT_QUERY_DEPTH;
  154.        
  155.         List<MstReminderPojo> pojos = new ArrayList<MstReminderPojo>();
  156.         for(MstReminder entity: entities) {
  157.             pojos.add(MstReminderPojo.fromEntity(entity));
  158.         }
  159.         return pojos;
  160.     }
  161.    
  162.     public static List<SearchFieldMapping> getFieldMappings() {
  163.         List<SearchFieldMapping> mappings = BasePojo.getFieldMappings();
  164.        
  165.         mappings.add(new SearchFieldMapping("type", "type").searchOnly());
  166.         mappings.add(new SearchFieldMapping("workplaceId", "workplace.id").searchOnly());
  167.         mappings.add(new SearchFieldMapping("departmentId", "department.id").searchOnly());
  168.        
  169.         return mappings;
  170.     }
  171. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top