Package com.cin.service

Source Code of com.cin.service.StaticDataService

/**
*
*/
package com.cin.service;

import java.rmi.RemoteException;
import java.util.List;
import java.util.logging.Level;

import javax.naming.NamingException;

import com.cin.dto.UserDTO;
import com.cin.dto.WageDTO;
import com.cin.ejb.transactionejb.TransactionRemote;
import com.cin.jndi.lookup.EJBLookup;
import com.cin.log.EventLogger;

/**
* Class that handles all the updates/maintains
* the static data of the census insurance application.
*
*/
public class StaticDataService {
 
  private  static EventLogger log = EventLogger.getInstance();
  private static TransactionRemote aRemote;
   
  public StaticDataService(){
    try {      
      aRemote = (TransactionRemote)EJBLookup.getInstance().getTransactionEJB();
    }
    catch(NamingException pException) {
      log.log(Level.SEVERE, pException.getMessage());
    }
    catch(RemoteException pException) {
      log.log(Level.SEVERE, pException.getMessage());
    }
   
  }
 
  public void updateMeanWeekWage(){
    List<WageDTO> theWages = aRemote.findAllWageDetails();
    CensusInsuranceService aService = new CensusInsuranceService();
    WageDTO aWageDTO = new WageDTO();
    for(WageDTO aWage : theWages) {
     
     
      int anOccupationCode = aWage.getOccupationCode();
      int anIndustryCode = aWage.getIndustryCode();
      List<UserDTO> theUsers = aService.findUsersByCode(anIndustryCode,anOccupationCode);
     
      if(theUsers != null && !theUsers.isEmpty()) {
       
        aWageDTO.setMeanWeekWage(this.calculateMeanWeekWage(theUsers));
        aWageDTO.setIndustryCode(anIndustryCode);
        aWageDTO.setOccupationCode(anOccupationCode);
        aRemote.setMeanWage(aWageDTO);
      }
    }
   
    EventLogger.getInstance().info("All wage details updated");
  }
 
  public void updateMeanWeekWage(WageDTO pWage) {
   
    assert(pWage.getIndustryCode() > 0);
    assert( pWage.getOccupationCode() > 0 );
   
    int newMean = this.updateMeanWeekWage(pWage.getIndustryCode(), pWage.getOccupationCode());
    pWage.setMeanWeekWage(newMean);
  }
 
  public int updateMeanWeekWage(int industryCode, int occupationCode) {
   
    CensusInsuranceService aService = new CensusInsuranceService();
    List<UserDTO> theUsers = aService.findUsersByCode(industryCode, occupationCode);
    int meanWage = calculateMeanWeekWage( theUsers );
   
    WageDTO newWage = new WageDTO();
    newWage.setIndustryCode(industryCode);
    newWage.setOccupationCode(occupationCode);
    newWage.setMeanWeekWage(meanWage);
   
    aRemote.setMeanWage(newWage);
   
    return newWage.getMeanWeekWage();
  }
 
  public int calculateMeanWeekWage(List<UserDTO> pUsers) {
    int aTotalWeekWage = 0;
    int aTotalEmployedCount = 0;
   
    for(UserDTO aUser : pUsers) {
     
      if(aUser.getJobDetails() != null &&
          aUser.getEmploymentStatus() != null && !aUser.isUnemployed()) {
     
        aTotalWeekWage = aTotalWeekWage + aUser.getJobDetails().getWeekWage();
        aTotalEmployedCount++;
      }
    }
     
    if( aTotalEmployedCount > 0 ){
      return aTotalWeekWage/aTotalEmployedCount;
    } else {
      // nobody is working in this field, so the average wage is 0
      return 0;
    }
  } 
}
TOP

Related Classes of com.cin.service.StaticDataService

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.