Java tutorial
/** * Class Name: TrackUpdatesServiceImpl * * Created By: soumya.b2 * Created On: 4:33:58 PM, Nov 5, 2014 * * Modified By: soumya.b2 * Modified On: 4:33:58 PM, Nov 5, 2014 * * Description: * * Copyright (c) 2013 Ugam Interactive. All rights reserved. * * Use is subject to license terms. */ package com.ugam.collage.plus.service.people_count.impl; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.transaction.Transactional; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import com.ugam.collage.plus.dao.EmployeeMonthlyAssignmentDao; import com.ugam.collage.plus.dao.TsCommentsDao; import com.ugam.collage.plus.model.EmployeeMonthlyAssignment; import com.ugam.collage.plus.model.TsComments; import com.ugam.collage.plus.service.people_count.TrackUpdatesService; import com.ugam.collage.plus.vo.ReportTrackVo; import com.ugam.collage.plus.vo.ResponseTrackVo; import com.ugam.collage.plus.vo.TsCommentsVo; @Transactional public class TrackUpdatesServiceImpl implements TrackUpdatesService { private static final Logger logger = LoggerFactory.getLogger(TrackUpdatesServiceImpl.class); @Autowired TsCommentsDao tsCommentsDao; @Autowired EmployeeMonthlyAssignmentDao employeeMonthlyAssignmentDao; @Override public List<TsCommentsVo> getReportingsTrackDetails(Integer yearId, Integer monthId) { List<TsCommentsVo> tsCommentsVoList = new ArrayList<TsCommentsVo>(); List<TsComments> tsCommentsList = tsCommentsDao.findByYearIdMonthId(yearId, monthId); if (tsCommentsList.isEmpty()) { return null; } for (TsComments tsComments : tsCommentsList) { StringBuffer strBuffer = new StringBuffer(); if (!tsComments.getReportAdditions().isEmpty()) { strBuffer.append(tsComments.getReportAdditions()); } if (!tsComments.getReportAttrResign().isEmpty()) { if (strBuffer.length() > 0) { strBuffer.append(", "); } strBuffer.append(tsComments.getReportAttrResign()); } if (!tsComments.getReportChanges().isEmpty()) { if (strBuffer.length() > 0) { strBuffer.append(", "); } strBuffer.append(tsComments.getReportChanges()); } TsCommentsVo TsCommentsVo = new TsCommentsVo(tsComments.getId(), tsComments.getEmpFsAccess().getEmployeeId(), tsComments.getReportedOn().toString(), strBuffer.toString(), tsComments.getStatus(), tsComments.getComment()); tsCommentsVoList.add(TsCommentsVo); } return tsCommentsVoList; } @Override public boolean updateReportingsTrackDetails(ReportTrackVo reportTrackVo) { if (reportTrackVo == null) { return false; } Integer yearId = reportTrackVo.getYearId(); Integer monthId = reportTrackVo.getMonthId(); List<TsCommentsVo> tsCommentsVoList = reportTrackVo.getTsCommentsVo(); List<TsComments> tsCommentsList = tsCommentsDao.findByYearIdMonthId(yearId, monthId); Map<Integer, TsComments> tsCommentsMap = new HashMap<Integer, TsComments>(); if (tsCommentsList.isEmpty()) { return false; } for (TsComments tsComments : tsCommentsList) { tsCommentsMap.put(tsComments.getId(), tsComments); } for (TsCommentsVo tsCommentsVo : tsCommentsVoList) { TsComments tsComments = tsCommentsMap.get(tsCommentsVo.getId()); if (tsComments != null) { tsComments.setComment(tsCommentsVo.getComment()); tsComments.setStatus(tsCommentsVo.getStatus()); tsCommentsDao.saveOrUpdate(tsComments); } } return true; } @Override public List<ResponseTrackVo> getResponseTrackDetails(Integer yearId, Integer monthId) { List<ResponseTrackVo> responseTrackVoList = new ArrayList<ResponseTrackVo>(); List<EmployeeMonthlyAssignment> employeeMonthlyAssignmentList = employeeMonthlyAssignmentDao .findByYearIdMonthId(yearId, monthId); if (employeeMonthlyAssignmentList.isEmpty()) { return responseTrackVoList; } for (EmployeeMonthlyAssignment employeeMonthlyAssignment : employeeMonthlyAssignmentList) { String date = ""; String employeeName = ""; Integer employeeId = null; if (employeeMonthlyAssignment.getUpdatedOn() != null) { date = employeeMonthlyAssignment.getUpdatedOn().toString(); } if (employeeMonthlyAssignment.getEmpFsAccessByUpdatedBy() != null && employeeMonthlyAssignment.getEmpFsAccessByUpdatedBy().getEmployeeId() > 0) { employeeId = employeeMonthlyAssignment.getEmpFsAccessByUpdatedBy().getEmployeeId(); employeeName = employeeMonthlyAssignment.getEmpFsAccessByUpdatedBy().getPersonMaster() .getDisplayName(); } ResponseTrackVo responseTrackVo = new ResponseTrackVo(employeeMonthlyAssignment.getId(), employeeId, employeeName, date); responseTrackVoList.add(responseTrackVo); } return responseTrackVoList; } }