Coverage Report - org.jtheque.primary.controller.impl.BorrowerController
 
Classes in this File Line Coverage Branch Coverage Complexity
BorrowerController
0 %
0/22
0 %
0/6
1.25
 
 1  
 package org.jtheque.primary.controller.impl;
 2  
 
 3  
 /*
 4  
  * This file is part of JTheque.
 5  
  *
 6  
  * JTheque is free software: you can redistribute it and/or modify
 7  
  * it under the terms of the GNU General Public License as published by
 8  
  * the Free Software Foundation, either version 3 of the License.
 9  
  *
 10  
  * JTheque is distributed in the hope that it will be useful,
 11  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13  
  * GNU General Public License for more details.
 14  
  *
 15  
  * You should have received a copy of the GNU General Public License
 16  
  * along with JTheque.  If not, see <http://www.gnu.org/licenses/>.
 17  
  */
 18  
 
 19  
 import org.jtheque.core.managers.Managers;
 20  
 import org.jtheque.core.managers.undo.IUndoRedoManager;
 21  
 import org.jtheque.core.managers.view.able.controller.AbstractController;
 22  
 import org.jtheque.primary.controller.able.IBorrowerController;
 23  
 import org.jtheque.primary.controller.impl.undo.GenericDataCreatedEdit;
 24  
 import org.jtheque.primary.od.able.Person;
 25  
 import org.jtheque.primary.services.able.IPersonService;
 26  
 import org.jtheque.primary.view.able.IBorrowerView;
 27  
 import org.jtheque.primary.view.able.ViewMode;
 28  
 
 29  
 import javax.annotation.Resource;
 30  
 
 31  
 /**
 32  
  * A Borrower Controller.
 33  
  *
 34  
  * @author Baptiste Wicht
 35  
  */
 36  0
 public final class BorrowerController extends AbstractController implements IBorrowerController {
 37  0
         private ViewMode state = ViewMode.NEW;
 38  
 
 39  
         @Resource
 40  
         private IPersonService borrowersService;
 41  
 
 42  
         @Resource
 43  
         private IBorrowerView borrowerView;
 44  
 
 45  
         @Override
 46  
         public void newBorrower(){
 47  0
                 state = ViewMode.NEW;
 48  
 
 49  0
         borrowerView.getModel().setBorrower(borrowersService.getEmptyPerson());
 50  0
                 borrowerView.reload();
 51  0
         }
 52  
 
 53  
         @Override
 54  
         public void editBorrower(Person borrower){
 55  0
                 assert borrower.getType().equals(borrowersService.getPersonType()) : "The person must be a borrower";
 56  
 
 57  0
                 state = ViewMode.EDIT;
 58  
 
 59  0
                 borrowerView.getModel().setBorrower(borrower);
 60  0
                 borrowerView.reload();
 61  
 
 62  0
                 displayView();
 63  0
         }
 64  
 
 65  
         @Override
 66  
         public void save(String firstName, String name, String email){
 67  0
         Person borrower = borrowerView.getModel().getBorrower();
 68  
 
 69  0
                 borrower.setFirstName(firstName);
 70  0
                 borrower.setEmail(email);
 71  0
                 borrower.setName(name);
 72  
 
 73  0
                 if (state == ViewMode.NEW){
 74  0
                         borrowersService.create(borrower);
 75  
 
 76  0
                         Managers.getManager(IUndoRedoManager.class).addEdit(new GenericDataCreatedEdit<Person>("personsService", borrower));
 77  
                 } else {
 78  0
                         borrowersService.save(borrower);
 79  
                 }
 80  0
         }
 81  
 
 82  
         @Override
 83  
         public IBorrowerView getView(){
 84  0
                 return borrowerView;
 85  
         }
 86  
 }