Subversion Repository Public Repository

TransPort_Tracking

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bestray.transtracking.service.impl;

import com.bestray.transporttracking.DataSourceObject;
import com.bestray.transtracking.dao.AddressDao;
import com.bestray.transtracking.dao.CountryDao;
import com.bestray.transtracking.dao.EmployeeDao;
import com.bestray.transtracking.dao.impl.AddressDaoImpl;
import com.bestray.transtracking.dao.impl.CodeDaoImpl;
import com.bestray.transtracking.dao.impl.CountryDaoImpl;
import com.bestray.transtracking.dao.impl.EmployeeDaoImpl;
import com.bestray.transtracking.dto.EmployeeSearchResultDTO;
import com.bestray.transtracking.service.EmployeeService;
import com.bestray.trastrack.domain.Address;
import com.bestray.trastrack.domain.Code;
import com.bestray.trastrack.domain.Employee;
import java.util.Date;
import java.util.List;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.bestray.transtracking.exceptions.TransTrackException;

public class EmployeeServiceImpl implements EmployeeService {

    private EmployeeDao employeeDao;
    private AddressDao addressDao;
    private CodeDaoImpl codeDao;
    private CountryDao countryDao;

    public EmployeeServiceImpl() {
    }

    public boolean NewEmployee(Employee employee) {
        try {
            addressDao = new AddressDaoImpl(DataSourceObject.getDataSourceObject());
            employeeDao = new EmployeeDaoImpl(DataSourceObject.getDataSourceObject());
            if (employee.getId() != null && employee.getId() > 0) {
                if(employee.getPermanentAddress()!=null){
                    if (employee.getPermanentAddress() != null && employee.getPermanentAddress().getId() != null && employee.getPermanentAddress().getId() > 0) {
                        addressDao.updateAddress(employee.getPermanentAddress());
                    }else{
                          addressDao.addAddress(employee.getPermanentAddress());                         
                    }
                }
                if(employee.getPresentAddress()!=null){
                    if (employee.getPresentAddress() != null && employee.getPresentAddress().getId() != null && employee.getPresentAddress().getId() > 0) {
                        addressDao.updateAddress(employee.getPresentAddress());
                    }else{
                        addressDao.addAddress(employee.getPresentAddress());
                    }
                }
                employeeDao.updateEmployee(employee);
            } else {
                if (employee.getPermanentAddress() != null) /*&& 
                        employee.getPermanentAddress().getAddress1() != null &&
                         employee.getPermanentAddress().getState() != null && 
                         employee.getPermanentAddress().getCity() != null)*/ {
                    employee.getPermanentAddress().setUpdatedDate(new Date());
                    employee.getPermanentAddress().setCreatedDate(new Date());
                    Address emppermanentaddr = addressDao.addAddress(employee.getPermanentAddress());
                    employee.setPermanentAddress(emppermanentaddr);
                }
                if (employee.getPresentAddress() != null) {
                    employee.getPresentAddress().setUpdatedDate(new Date());
                    employee.getPresentAddress().setCreatedDate(new Date());
                    Address emppresentaddr = addressDao.addAddress(employee.getPresentAddress());
                    employee.setPresentAddress(emppresentaddr);
                }
                employee.setUpdatedDate(new Date());
                employee.setCreatedDate(new Date());
                employeeDao.addEmployee(employee);
            }
            //employeeDao = new EmployeeDaoImpl( DataSourceObject.getDataSourceObject());
            //employee.setUpdatedDate(new Date());
            // employee.setCreatedDate(new Date());
            // employeeDao.addEmployee(employee);
            return true;
        } catch (Exception ex) {
            Logger.getLogger(EmployeeServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
            throw new TransTrackException("Error in creating Employee Record");
        }

    }

    public Vector<Vector<String>> getEmplyoeeList() {
        try {
            employeeDao = new EmployeeDaoImpl(DataSourceObject.getDataSourceObject());
            addressDao = new AddressDaoImpl(DataSourceObject.getDataSourceObject());
            codeDao = new CodeDaoImpl(DataSourceObject.getDataSourceObject());
            Vector<Vector<String>> employees = new Vector<Vector<String>>();
            List<Employee> employeeList = employeeDao.findAllEmployees();
            for (Employee empl : employeeList) {

                Address address = new Address();
                Code code = new Code();
                Vector<String> employeeVector = new Vector<String>();
                employeeVector.add(String.valueOf(empl.getId()));
                employeeVector.add(empl.getEmployee_Name());
                code = codeDao.getCodeById(empl.getCategoryCodeId() != null ? empl.getCategoryCodeId() : 0);
                if (code != null) {
                    employeeVector.add(code.getName());
                }
                address = addressDao.findById(empl.getPresentAddressid() != null ? empl.getPresentAddressid() : 0);
                if (address != null) {
                    employeeVector.add(address.getAddress1());
                    //employeeVector.add(address.getCity());
                }
                employeeVector.add(String.valueOf(empl.getContact1()));
                employeeVector.add(String.valueOf(empl.getOpen_Balance()));
                employeeVector.add(String.valueOf(empl.getLock()));

                employees.add(employeeVector);

            }



            return employees;
        } catch (Exception ex) {
            Logger.getLogger(EmployeeServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
            throw new TransTrackException("Error in Fetching Employee Record");
        }

    }

    public Employee getEmployeeRegistrationDetails(Long employeeId) {
        Employee employee;
        try {
            employeeDao = new EmployeeDaoImpl(DataSourceObject.getDataSourceObject());            
            codeDao = new CodeDaoImpl(DataSourceObject.getDataSourceObject());
            employee = employeeDao.findEmplRegistraion(employeeId);
            if(employee.getPresentAddressid()!=null&&employee.getPresentAddressid()>0){
            addressDao = new AddressDaoImpl(DataSourceObject.getDataSourceObject());
            Address address = addressDao.findById(employee.getPresentAddressid());
            if (address != null) {
                countryDao = new CountryDaoImpl(DataSourceObject.getDataSourceObject());
                if (address.getCountryId() != null) {
                    address.setCounty(countryDao.getCountryById(address.getCountryId()));
                }
                if (address.getStateId() != null) {
                    address.setState(countryDao.getStateById(address.getStateId()));
                }
                employee.setPresentAddress(address);
            }
            }else{
                employee.setPresentAddress(null);
            }
            
            Address address2 = new Address();
            
             if(employee.getPermanentAddressid()!= null && employee.getPermanentAddressid()>0){
             address2 = addressDao.findById(employee.getPermanentAddressid());
            if (address2 != null) {
                countryDao = new CountryDaoImpl(DataSourceObject.getDataSourceObject());
                if (address2.getCountryId() != null) {
                    address2.setCounty(countryDao.getCountryById(address2.getCountryId()));
                }
                if (address2.getStateId() != null) {
                    address2.setState(countryDao.getStateById(address2.getStateId()));
                }
            }
                employee.setPermanentAddress(address2);
             }else{
                 employee.setPermanentAddress(null);
             }           
            
        } catch (Exception ex) {
            Logger.getLogger(EmployeeServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
            throw new TransTrackException("Error in Fething Employee Record");
        }
        return employee;
    }

    public void deleteEmployee(Long employeeId) throws TransTrackException {
        try {
             addressDao = new AddressDaoImpl(DataSourceObject.getDataSourceObject());
            employeeDao = new EmployeeDaoImpl(DataSourceObject.getDataSourceObject());
            Employee emp = employeeDao.findEmplRegistraion(employeeId);
            employeeDao.delete(employeeId);
            if (emp.getPermanentAddressid() != null&&emp.getPermanentAddressid()>0) {
                addressDao.delete(emp.getPermanentAddressid());
            }
            if (emp.getPresentAddressid() != null&&emp.getPresentAddressid()>0) {
                addressDao.delete(emp.getPresentAddressid());
            }
            
        } catch (Exception ex) {
            Logger.getLogger(EmployeeServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
            throw new TransTrackException("Employee Information cannot be deleted");
        }
    }

    public List<Employee> getDriverNameList() {
        try {
            employeeDao = new EmployeeDaoImpl(DataSourceObject.getDataSourceObject());
            return employeeDao.findAllEmployees();
        } catch (Exception ex) {
            Logger.getLogger(DriverStaffPaymentServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
            throw new TransTrackException("Error in fetching Driver Record");
        }
    }

    public Vector<Vector<String>> getEmployeeNameLists() {
        try {
            addressDao = new AddressDaoImpl(DataSourceObject.getDataSourceObject());
            employeeDao = new EmployeeDaoImpl(DataSourceObject.getDataSourceObject());
            Vector<Vector<String>> employees = new Vector<Vector<String>>();
            List<Employee> employeeList = employeeDao.findAllEmployees();
            for (Employee employeee : employeeList) {
                Address address = new Address();
                Vector<String> employee = new Vector<String>();
                employee.add(String.valueOf(employeee.getId()));
                employee.add(employeee.getEmployee_Name());
                address = addressDao.findById(employeee.getPresentAddressid() != null ? employeee.getPresentAddressid() : 0);
                if (address != null) {
                    employee.add(address.getAddress1());
                    employee.add(address.getCity());
                }
                employees.add(employee);
            }
            return employees;
        } catch (Exception ex) {
            Logger.getLogger(EmployeeServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
            throw new TransTrackException("Error in Fetching Employee Record");
        }
    }

    public Vector<Vector<String>> findAllEmployeesList() throws TransTrackException {
        try {
            Vector<Vector<String>> employees = new Vector<Vector<String>>();
            employeeDao = new EmployeeDaoImpl(DataSourceObject.getDataSourceObject());
            List<EmployeeSearchResultDTO> employeeList;
            try {
                employeeList = employeeDao.findAllEmployeesList();
            } catch (Exception ex) {
                throw new TransTrackException("Error in populating Employee Data");
            }
            for (EmployeeSearchResultDTO employeee : employeeList) {
                Vector<String> employee = new Vector<String>();
                employee.add(employeee.getEmployeeId());
                employee.add(employeee.getEmployeeName());
                employee.add(employeee.getEmpleoyeeCategory());
                employee.add(employeee.getAddress());
                employee.add(employeee.getContactNbr());
                employee.add(employeee.getOpeningBalance());
                employee.add(employeee.getLock());

                employees.add(employee);
            }
            return employees;
        } catch (Exception ex) {
           Logger.getLogger(EmployeeServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
            throw new TransTrackException("Error in fetching employee Records");
        }
    }
}

Commits for TransPort_Tracking/TransPortTracking/src/main/java/com/bestray/transtracking/service/impl/EmployeeServiceImpl.java

Diff revisions: vs.
Revision Author Commited Message
1 girijabapi picture girijabapi Sat 28 Jul, 2018 05:29:14 +0000