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
/*
 * 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.VehicleOwnerDao;
import com.bestray.transtracking.dao.impl.AddressDaoImpl;
import com.bestray.transtracking.dao.impl.CountryDaoImpl;
import com.bestray.transtracking.dao.impl.VehicleOwnerDaoImpl;
import com.bestray.transtracking.dto.VehicleOwnerSearchResultDTO;
import com.bestray.transtracking.exceptions.TransTrackException;
import com.bestray.transtracking.service.VehicleOwnerService;
import com.bestray.trastrack.domain.Address;
import com.bestray.trastrack.domain.VehicleOwner;
import java.util.Date;
import java.util.List;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author user3
 */
public class VehicleOwnerServiceImpl implements VehicleOwnerService {

    private VehicleOwnerDao vodao;
    private DataSourceObject dobj;
    private AddressDao addrDao;
    private CountryDao countryDao;

    public VehicleOwnerServiceImpl() {
    }

    public boolean registerOwner(VehicleOwner user) {
        try {
            addrDao = new AddressDaoImpl(DataSourceObject.getDataSourceObject());
            vodao = new VehicleOwnerDaoImpl(DataSourceObject.getDataSourceObject());
            if (user.getId() != null && user.getId() > 0) {
                if(user.getOwneraddress()!=null){
                if (user.getOwneraddress() != null && user.getOwneraddress().getId() != null && user.getOwneraddress().getId() > 0) {
                    addrDao.updateAddress(user.getOwneraddress());
                }
                else{
                    addrDao.addAddress(user.getOwneraddress());
                }
              } 
                vodao.updateVehicleOwner(user);
            } else {
                if (user.getOwneraddress() != null) {
                    user.getOwneraddress().setUpdatedDate(new Date());
                    user.getOwneraddress().setCreatedDate(new Date());
                    Address owneraddr = addrDao.addAddress(user.getOwneraddress());
                    user.setOwneraddress(owneraddr);
                }

                user.setUpdatedDate(new Date());
                user.setCreatedDate(new Date());
                vodao.saveOwner(user);

            }
            return true;
        } catch (Exception ex) {
            Logger.getLogger(VehicleOwnerServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
            throw new TransTrackException("Error in saving Vehicle Owner Details");
        }
    }

    public Vector<Vector<String>> getOwnerList() throws TransTrackException {
        /*try {
            addrDao = new AddressDaoImpl(DataSourceObject.getDataSourceObject());
            vodao = new VehicleOwnerDaoImpl(DataSourceObject.getDataSourceObject());
            Vector<Vector<String>> owners = new Vector<Vector<String>>();
            List<VehicleOwner> vehicleownerList = vodao.findAllOwners();
            for (VehicleOwner owner : vehicleownerList) {
                Address address = new Address();
                Vector<String> employee = new Vector<String>();
                employee.add(String.valueOf(owner.getId()));
                employee.add(owner.getOwnername()); //Empid
                employee.add(String.valueOf(owner.getOpeningbal()));
                employee.add(owner.getLock());
                address = addrDao.findById(owner.getAddressid() != null ? owner.getAddressid() : 0);
                if (address != null) {
                    employee.add(address.getAddress1());
                    employee.add(address.getCity());
                }
                owners.add(employee);
            }

            return owners;
        } catch (Exception ex) {
            Logger.getLogger(VehicleOwnerServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
            throw new TransTrackException("Error in fetching  Owner Details");
        }*/
        try {
            Vector<Vector<String>> owners = new Vector<Vector<String>>();
            vodao = new VehicleOwnerDaoImpl(DataSourceObject.getDataSourceObject());
            List<VehicleOwnerSearchResultDTO> ownerList;
            try {
                ownerList = vodao.findAllOwnersList();
            } catch (Exception ex) {
                throw new TransTrackException("Error in populating Employee Data");
            }
            for (VehicleOwnerSearchResultDTO owner : ownerList) {
                Vector<String> ownerr = new Vector<String>();
                ownerr.add(owner.getOwnerId());
                ownerr.add(owner.getOwnerName());
                ownerr.add(owner.getAddress());
                ownerr.add(owner.getCity());
                ownerr.add(owner.getOpeningBalance());
                ownerr.add(owner.getLock());
                                
                owners.add(ownerr);
            }
            return owners;
        } catch (Exception ex) {
            Logger.getLogger(VehicleOwnerServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
            throw new TransTrackException("Error in fetching employee Records");
        }

    }

    public VehicleOwner getVehicleOwnerRegistrationDetails(Long ownerId) {
        VehicleOwner owner;
        try {
            vodao = new VehicleOwnerDaoImpl(DataSourceObject.getDataSourceObject());
            owner = vodao.findVehicleOwnerRegistraion(ownerId);
            if(owner.getAddressid()!=null&&owner.getAddressid()>0){
            addrDao = new AddressDaoImpl(DataSourceObject.getDataSourceObject());
            Address address = addrDao.findById(owner.getAddressid());
            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()));
                }
                owner.setOwneraddress(address);
            }
           }else{
                owner.setOwneraddress(null);
            }            
        } catch (Exception ex) {
            Logger.getLogger(VehicleOwnerServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
            throw new TransTrackException("Error in fetching Vehicle Owner Details");
        }
        return owner;
    }

    public void deleteVehicleOwner(Long ownerId) {
        try {
            addrDao = new AddressDaoImpl(DataSourceObject.getDataSourceObject());
            vodao = new VehicleOwnerDaoImpl(DataSourceObject.getDataSourceObject());
            VehicleOwner owner = vodao.findVehicleOwnerRegistraion(ownerId);
            if (owner.getAddressid() != null && owner.getAddressid()>0) {
                vodao.delete(ownerId);
                addrDao.delete(owner.getAddressid());
            }
            else{
                vodao.delete(ownerId);
            }
        } catch (Exception ex) {
            Logger.getLogger(VehicleOwnerServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
            throw new TransTrackException("Error in deleting Vehicle Owner Details");
        }
    }

    public List<VehicleOwner> getOwnerNameList() {
        try {
            vodao = new VehicleOwnerDaoImpl(DataSourceObject.getDataSourceObject());
            return vodao.findAllOwners();
        } catch (Exception ex) {
            Logger.getLogger(VehicleOwnerServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
            throw new TransTrackException("Error in fetching  Owner Details");
        }

    }
    /*
     public Vector<VehicleOwner> getOwnerNameList(){
     return null;
      
                
     } */
}

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

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