Advertisement
cacing69

PersonAction.java

Jul 17th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.85 KB | None | 0 0
  1.  
  2. package id.co.duaagung.example.person.action;
  3.  
  4. import java.util.ArrayList;
  5. import java.util.Date;
  6. import java.util.Iterator;
  7. import java.util.List;
  8.  
  9. import org.apache.log4j.Logger;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11.  
  12. import id.co.duaagung.common.BaseAction;
  13. import id.co.duaagung.common.ProjectUtil;
  14. import id.co.duaagung.example.person.mapper.PersonContactMapper;
  15. import id.co.duaagung.example.person.mapper.PersonMapper;
  16. import id.co.duaagung.example.person.model.Person;
  17. import id.co.duaagung.example.person.model.PersonContact;
  18. import id.co.duaagung.modules.master.mapper.history.HistoryMapper;
  19. import id.co.duaagung.modules.master.model.history.History;
  20. public class PersonAction extends BaseAction {
  21.     private static final long serialVersionUID = 1L;
  22.     private static transient Logger log = Logger.getLogger(PersonAction.class);
  23.    
  24.     private Person person;
  25.     private List<Person> listPerson = new ArrayList<>();
  26.    
  27.     private List<String> tipe;
  28.     private List<String> kontak;
  29.    
  30.     private String name;
  31.    
  32.     @Autowired
  33.     private PersonMapper personMapper;
  34.    
  35.     @Autowired
  36.     private PersonContactMapper personContactMapper;
  37.    
  38.     @Autowired
  39.     private HistoryMapper historyMapper;
  40.  
  41.     public String searchPerson() {
  42.         log.info("[Begin] execute method searchPerson()");
  43.        
  44.         person = new Person();
  45.        
  46.         person.setName(name);
  47.        
  48.         System.out.println("name value form JSP : "+person.getName());
  49.        
  50.         try {
  51.             listPerson = personMapper.selectAll(person);
  52.         } catch (Exception e) {
  53.             // TODO Auto-generated catch block
  54.             e.printStackTrace();
  55.             setMessageError(e.getMessage());
  56.            
  57.             return ERROR;
  58.         }
  59.        
  60.         log.info("[end] execute method searchPerson()");
  61.         return SUCCESS;
  62.     }
  63.  
  64.     public String selectByPrimaryKey() {
  65.         log.info("[BEGIN] execute method selectByPrimaryKey()");
  66.        
  67.         person = personMapper.selectById(person.getId());
  68.        
  69.         log.info("[END] execute method selectByPrimaryKey()");
  70.         return SUCCESS;
  71.     }
  72.  
  73.     public String insertPerson() {
  74.         log.info("[BEGIN] execute method insertPerson()");
  75.         try {
  76.             personMapper.insertPerson(person);
  77.             if(tipe.size() > 0) {
  78.                 PersonContact pContact = new PersonContact();
  79.                 person = personMapper.selectByName(person.getName());
  80.                
  81.                 for (int i = 0; i < tipe.size(); i++) {
  82.                     pContact.setPersonId(person.getId());
  83.                     pContact.setKey(tipe.get(i));
  84.                     pContact.setValue(kontak.get(i));
  85.                    
  86.                     personContactMapper.insertPersonContact(pContact);
  87.                 }
  88.             } else {
  89.                 setMessageError("Kontak person masih kosong, silahkan isi minimal 1 kontak");
  90.                 return ERROR;
  91.             }
  92.         } catch (Exception e) {
  93.             e.printStackTrace();
  94.             setMessageError("Gagal melakukan insert Person karena : " + e.getMessage());
  95.             return ERROR;
  96.         }
  97.  
  98.         setMessage("Data Berhasil Disimpan");
  99.         setName("");
  100.         log.info("[END] execute method insertPerson()");
  101.         return searchPerson();
  102.     }
  103.  
  104.     public String updatePerson() {
  105.         log.info("[BEGIN] execute method updateModule()");
  106.        
  107.         try {
  108.             personMapper.updatePerson(person);
  109.            
  110.             if(tipe.size() > 0) {
  111.                 for (int i = 0; i < tipe.size(); i++) {
  112.                     PersonContact pContact = new PersonContact();
  113.                     pContact.setPersonId(person.getId());
  114.                     pContact.setKey(tipe.get(i));
  115.                     pContact.setValue(kontak.get(i));
  116.                    
  117.                     personContactMapper.insertPersonContact(pContact);
  118.                 }
  119.             } else {
  120.                 setMessageError("Kontak person masih kosong, silahkan isi minimal 1 kontak");
  121.                 return ERROR;
  122.             }
  123.            
  124.         } catch (Exception e) {
  125.             // TODO Auto-generated catch block
  126.             e.printStackTrace();
  127.             setMessageError(e.getMessage());
  128.             return ERROR;
  129.         }
  130.        
  131.        
  132.    
  133.         setName(person.getName()); 
  134.         log.info("[END] execute method updateModule()");
  135.            
  136.        
  137.         setMessage("data dengan nama : "+person.getName()+" berhasil diubah");
  138.  
  139.         //return ERROR;
  140.         return searchPerson();
  141.     }
  142.    
  143.     public String deletePerson() {
  144.         log.info("[BEGIN] execute method deletePerson()");
  145.  
  146.         try {
  147.             personMapper.deletePerson(person);
  148.         } catch (Exception e) {
  149.             e.printStackTrace();
  150.             setMessageError(e.getMessage());
  151.             return ERROR;
  152.         }
  153.        
  154.         setName("");
  155.         setMessage("Data berhasil di hapus!");
  156.        
  157.         log.info("[END] execute method deletePerson()");
  158.         return searchPerson();
  159.     }
  160.  
  161.     public Person getPerson() {
  162.         return person;
  163.     }
  164.  
  165.     public void setPerson(Person person) {
  166.         this.person = person;
  167.     }
  168.  
  169.     public List<Person> getListPerson() {
  170.         return listPerson;
  171.     }
  172.  
  173.     public void setListPerson(List<Person> listPerson) {
  174.         this.listPerson = listPerson;
  175.     }
  176.    
  177.     public String getName() {
  178.         return name;
  179.     }
  180.  
  181.     public List<String> getTipe() {
  182.         return tipe;
  183.     }
  184.  
  185.     public void setTipe(List<String> tipe) {
  186.         this.tipe = tipe;
  187.     }
  188.  
  189.     public List<String> getKontak() {
  190.         return kontak;
  191.     }
  192.  
  193.     public void setKontak(List<String> kontak) {
  194.         this.kontak = kontak;
  195.     }
  196.  
  197.     public void setName(String name) {
  198.         this.name = name;
  199.     }
  200. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement