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
package com.bestray.transtracking.service.impl;

import com.bestray.transporttracking.DataSourceObject;
import com.bestray.transtracking.dao.AddressDao;
import com.bestray.transtracking.dao.ClientDao;
import com.bestray.transtracking.dao.impl.AddressDaoImpl;
import com.bestray.transtracking.dao.impl.ClientDaoImpl;
import com.bestray.transtracking.service.ClientService;
import com.bestray.trastrack.domain.Address;
import com.bestray.trastrack.domain.ClientUser;
import java.util.Date;
import java.util.List;
import java.util.Vector;
import com.bestray.transtracking.dao.CountryDao;
import com.bestray.transtracking.dao.EmployeeDao;
import com.bestray.transtracking.dao.impl.CountryDaoImpl;
import com.bestray.transtracking.dto.ClientSearchResultDTO;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.bestray.transtracking.exceptions.TransTrackException;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author user3
 */
public class ClientServiceImpl implements ClientService{
    
    private ClientDao clientDao;
    private EmployeeDao employeeDao;
    private DataSourceObject dobj;
    private AddressDao addrDao;
    private CountryDao countryDao;
    public ClientServiceImpl(){
        
    }
    
    public boolean registerClient(ClientUser user){
        
        /*cdao = new ClientDaoImpl( DataSourceObject.getDataSourceObject());
        cdao.saveClient(user);
        return true;*/
        boolean flag = false;
        try{
         addrDao = new AddressDaoImpl( DataSourceObject.getDataSourceObject());
          clientDao = new ClientDaoImpl( DataSourceObject.getDataSourceObject());
        if(user.getId() != null && user.getId()>0){
            if(user.getClientaddress() !=null){
            if(user.getClientaddress() != null && user.getClientaddress().getId() != null && user.getClientaddress().getId()>0){
               addrDao.updateAddress(user.getClientaddress()) ;
               //clientDao.updateClient(user);
            }else{
                addrDao.addAddress(user.getClientaddress());
            }
            }
            clientDao.updateClient(user);
        }else{
        
       
        if(user.getClientaddress()!=null){
            //System.out.println("Adding Address");
            user.getClientaddress().setUpdatedDate(new Date());
            user.getClientaddress().setCreatedDate(new Date());
            Address clientaddr = addrDao.addAddress(user.getClientaddress());
            user.setClientaddress(clientaddr);
        }      
        
        user.setUpdatedDate(new Date());
        user.setCreatedDate(new Date());
        clientDao.saveClient(user);
        
        }
        flag = true;
         } catch (Exception ex) {
            Logger.getLogger(ClientCollectionServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
            throw new TransTrackException("Error in Fetching Employee Name List");
        }
         return flag;
    }

    public Vector<Vector<String>> getClientList() throws TransTrackException{
        /*Vector<Vector<String>> clients = new Vector<Vector<String>>();
        try{
        addrDao = new AddressDaoImpl( DataSourceObject.getDataSourceObject());
        clientDao = new ClientDaoImpl( DataSourceObject.getDataSourceObject());
         
       List<ClientUser> clientList = clientDao.findAllClients();
         for(ClientUser client:clientList){
             Address address = new Address();
              Vector<String> employee = new Vector<String>();
              employee.add(String.valueOf(client.getId()));  
              employee.add(client.getClientname()); //Empid
              employee.add(String.valueOf(client.getOpeningbal()));
              employee.add(client.getLock());
              address = addrDao.findById(client.getAddressid()!= null?client.getAddressid():0);
              if (address != null){
              employee.add(address.getAddress1());
              employee.add(address.getCity());
              }
               clients.add(employee);
          }
           }catch(Exception e){
           throw new TransTrackException("Error in Fetching Client List");
       }
        return clients;*/
        try {
            Vector<Vector<String>> clients = new Vector<Vector<String>>();
            clientDao = new ClientDaoImpl(DataSourceObject.getDataSourceObject());
            List<ClientSearchResultDTO> clientList;
            try {
                clientList = clientDao.findAllClientsList();
            } catch (Exception ex) {
                throw new TransTrackException("Error in populating Client Data");
            }
            for (ClientSearchResultDTO clientt : clientList) {
                Vector<String> client = new Vector<String>();
                client.add(clientt.getClientId());
                client.add(clientt.getClientName());                
                client.add(clientt.getAddress());
                client.add(clientt.getCity());
                client.add(clientt.getOpeningBalance());
                client.add(clientt.getLock());
                clients.add(client);
            }
            return clients;
        } catch (Exception ex) {
            Logger.getLogger(ClientServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
            throw new TransTrackException("Error in fetching client Records");
        }
    
    }

    public ClientUser getClientRegistrationDetails(Long clientId) {
       ClientUser client;
       try{ 
       clientDao = new ClientDaoImpl( DataSourceObject.getDataSourceObject());
        client = clientDao.findClientRegistraion(clientId);
        if(client.getAddressid()!=null&&client.getAddressid()>0){  
                //System.out.println("Client Address find out: "+client.getAddressid());
                addrDao = new AddressDaoImpl( DataSourceObject.getDataSourceObject());
                Address address = addrDao.findById(client.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()));
                 }
            client.setClientaddress(address);  
            }
                
      }
      else{
            client.setClientaddress(null);
          }
      }
      catch(Exception e){
           throw new TransTrackException("Error in Fetching Client Registration");
      }
       return client;
    }

    public void deleteClient(Long clientId)  throws TransTrackException{
        try {
            clientDao = new ClientDaoImpl( DataSourceObject.getDataSourceObject());
            addrDao = new AddressDaoImpl( DataSourceObject.getDataSourceObject());
        ClientUser client = clientDao.findClientRegistraion(clientId);
        if(client.getAddressid() != null && client.getAddressid()>0){
            //clientDao.delete(clientId);
        //addrDao.delete(client.getAddressid());
        
            //System.out.println("Deleted client......");
            clientDao.delete(clientId);
            addrDao.delete(client.getAddressid());
            }
        else{
            //System.out.println("Deleted client");
            clientDao.delete(clientId);
        }
        } catch (Exception ex) {
            Logger.getLogger(ClientServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
            throw new TransTrackException("Error in Delete Client");
            //throw new Exception("Client Information cannot be deleted");
        }
        
        
    }

    public List<ClientUser> getClientNameList() {
        try{
        clientDao = new ClientDaoImpl( DataSourceObject.getDataSourceObject());
        return clientDao.findAllClients();
        }catch(Exception e){
           throw new TransTrackException("Error in Fetching Client List");
       }
    }

    /*public Vector<Vector<String>> getClientNameLists() {
        addrDao = new AddressDaoImpl( DataSourceObject.getDataSourceObject());
        clientDao = new ClientDaoImpl( DataSourceObject.getDataSourceObject());
        Vector<Vector<String>> clients = new Vector<Vector<String>>();
        List<ClientUser> clientList = clientDao.findAllClients();
        for(ClientUser client:clientList){
             Address address = new Address();
             Vector<String> employee = new Vector<String>();
             employee.add(String.valueOf(client.getId()));  
              employee.add(client.getClientname());
              address = addrDao.findById(client.getAddressid()!= null?client.getAddressid():0);
              if (address != null){
              employee.add(address.getAddress1());
              employee.add(address.getCity());
        }
        clients.add(employee);
    }
    return clients;
  } */

    /*public boolean collectClient(ClientCollection collect) {
        
        clientDao = new ClientDaoImpl( DataSourceObject.getDataSourceObject());
        clientDao.saveCollection(collect);
        return true;
    }*/

    /*public List<ClientCollection> getSearchResult(ClientCollectionSearchDTO search) {
         DataSource ds =  DataSourceObject.getDataSourceObject();
         clientDao = new ClientDaoImpl(ds);
          List<ClientCollection> results = clientDao.getSearchResults(search);
          for(ClientCollection object :results){
                object.setCollection_type_id(partyDao.findPartyRegistraion(object.getPartyId()));
                object.setVehicle(vehicleService.getVehicleRegistrationDetails(object.getVehicleId()));
            }
    }*/
}

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

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