Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package id.co.duaagung.example.person.action;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.Iterator;
- import java.util.List;
- import org.apache.log4j.Logger;
- import org.springframework.beans.factory.annotation.Autowired;
- import id.co.duaagung.common.BaseAction;
- import id.co.duaagung.common.ProjectUtil;
- import id.co.duaagung.example.person.mapper.PersonContactMapper;
- import id.co.duaagung.example.person.mapper.PersonMapper;
- import id.co.duaagung.example.person.model.Person;
- import id.co.duaagung.example.person.model.PersonContact;
- import id.co.duaagung.modules.master.mapper.history.HistoryMapper;
- import id.co.duaagung.modules.master.model.history.History;
- public class PersonAction extends BaseAction {
- private static final long serialVersionUID = 1L;
- private static transient Logger log = Logger.getLogger(PersonAction.class);
- private Person person;
- private List<Person> listPerson = new ArrayList<>();
- private List<String> tipe;
- private List<String> kontak;
- private String name;
- @Autowired
- private PersonMapper personMapper;
- @Autowired
- private PersonContactMapper personContactMapper;
- @Autowired
- private HistoryMapper historyMapper;
- public String searchPerson() {
- log.info("[Begin] execute method searchPerson()");
- person = new Person();
- person.setName(name);
- System.out.println("name value form JSP : "+person.getName());
- try {
- listPerson = personMapper.selectAll(person);
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- setMessageError(e.getMessage());
- return ERROR;
- }
- log.info("[end] execute method searchPerson()");
- return SUCCESS;
- }
- public String selectByPrimaryKey() {
- log.info("[BEGIN] execute method selectByPrimaryKey()");
- person = personMapper.selectById(person.getId());
- log.info("[END] execute method selectByPrimaryKey()");
- return SUCCESS;
- }
- public String insertPerson() {
- log.info("[BEGIN] execute method insertPerson()");
- try {
- personMapper.insertPerson(person);
- if(tipe.size() > 0) {
- PersonContact pContact = new PersonContact();
- person = personMapper.selectByName(person.getName());
- for (int i = 0; i < tipe.size(); i++) {
- pContact.setPersonId(person.getId());
- pContact.setKey(tipe.get(i));
- pContact.setValue(kontak.get(i));
- personContactMapper.insertPersonContact(pContact);
- }
- } else {
- setMessageError("Kontak person masih kosong, silahkan isi minimal 1 kontak");
- return ERROR;
- }
- } catch (Exception e) {
- e.printStackTrace();
- setMessageError("Gagal melakukan insert Person karena : " + e.getMessage());
- return ERROR;
- }
- setMessage("Data Berhasil Disimpan");
- setName("");
- log.info("[END] execute method insertPerson()");
- return searchPerson();
- }
- public String updatePerson() {
- log.info("[BEGIN] execute method updateModule()");
- try {
- personMapper.updatePerson(person);
- if(tipe.size() > 0) {
- for (int i = 0; i < tipe.size(); i++) {
- PersonContact pContact = new PersonContact();
- pContact.setPersonId(person.getId());
- pContact.setKey(tipe.get(i));
- pContact.setValue(kontak.get(i));
- personContactMapper.insertPersonContact(pContact);
- }
- } else {
- setMessageError("Kontak person masih kosong, silahkan isi minimal 1 kontak");
- return ERROR;
- }
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- setMessageError(e.getMessage());
- return ERROR;
- }
- setName(person.getName());
- log.info("[END] execute method updateModule()");
- setMessage("data dengan nama : "+person.getName()+" berhasil diubah");
- //return ERROR;
- return searchPerson();
- }
- public String deletePerson() {
- log.info("[BEGIN] execute method deletePerson()");
- try {
- personMapper.deletePerson(person);
- } catch (Exception e) {
- e.printStackTrace();
- setMessageError(e.getMessage());
- return ERROR;
- }
- setName("");
- setMessage("Data berhasil di hapus!");
- log.info("[END] execute method deletePerson()");
- return searchPerson();
- }
- public Person getPerson() {
- return person;
- }
- public void setPerson(Person person) {
- this.person = person;
- }
- public List<Person> getListPerson() {
- return listPerson;
- }
- public void setListPerson(List<Person> listPerson) {
- this.listPerson = listPerson;
- }
- public String getName() {
- return name;
- }
- public List<String> getTipe() {
- return tipe;
- }
- public void setTipe(List<String> tipe) {
- this.tipe = tipe;
- }
- public List<String> getKontak() {
- return kontak;
- }
- public void setKontak(List<String> kontak) {
- this.kontak = kontak;
- }
- public void setName(String name) {
- this.name = name;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement