Commit d84b248e authored by Prasad Innamuri's avatar Prasad Innamuri

download and upload function is implemented

parent aee3615f
package com.nisum.myteam.controller;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
......@@ -8,6 +11,7 @@ import java.util.List;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.nisum.myteam.model.dao.EmployeeSubStatus;
import com.nisum.myteam.model.dao.EmployeeVisa;
......@@ -34,6 +38,7 @@ import com.nisum.myteam.model.dao.Employee;
import com.nisum.myteam.service.IEmployeeRoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.multipart.MultipartFile;
@RestController
@Slf4j
......@@ -309,6 +314,26 @@ public class EmployeeController {
return new ResponseEntity<ResponseDetails>(responseDetails, HttpStatus.OK);
}
@RequestMapping(value = "/employees/uploadProfile/{empid}", method = RequestMethod.POST)
public ResponseEntity<Employee> handleFileUpload(@PathVariable("empid") String empid, @RequestParam(value = "file") MultipartFile file) throws MyTeamException, IOException {
Employee employeeUpdated = empService.uploadProfile(empid, file);
return new ResponseEntity<>(null, HttpStatus.OK);
}
@RequestMapping(value = "/employees/downloadFile/{empId}", method = RequestMethod.GET)
public void downloadFile(@PathVariable("empId") String empId, HttpServletResponse response) throws IOException {
InputStream is = null;
is = new ByteArrayInputStream(empService.getUploadFile(empId));
response.setContentType("application/msword");
byte[] bytes = new byte[1024];
int bytesRead;
while ((bytesRead = is.read(bytes)) != -1) {
response.getOutputStream().write(bytes, 0, bytesRead);
}
is.close();
}
}
\ No newline at end of file
......@@ -10,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
......@@ -44,4 +45,35 @@ public class OrgLocationController {
return new ResponseEntity<>(getRespDetails, HttpStatus.OK);
}
@RequestMapping(value = "/organization/locations/{country}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> getSelectedLocations(@PathVariable("country") String country, HttpServletRequest request) throws MyTeamException {
List<String> locationsList = orgLocationService.getLocations().stream()
.filter(e -> (e.isActiveStatus() == true)&&(e.getCountry().equalsIgnoreCase(country))).map(OrgLocation::getLocation).sorted()
.collect(Collectors.toList());
log.info("getLocations " + locationsList);
ResponseDetails getRespDetails = new ResponseDetails(new Date(), 905,
"Retrieved Organization Locations successfully", "Organization Locations List", locationsList,
request.getRequestURI(), "Organization Location Details", null);
return new ResponseEntity<>(getRespDetails, HttpStatus.OK);
}
@RequestMapping(value = "/organization/countrys/", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> getCountrys(HttpServletRequest request) throws MyTeamException {
log.info("getCountrys Start ");
List<String> countryList = orgLocationService.getLocations().stream()
.filter(e -> (e.isActiveStatus() == true)).map(OrgLocation::getCountry).distinct().sorted()
.collect(Collectors.toList());
log.info("getLocations " + countryList);
ResponseDetails getRespDetails = new ResponseDetails(new Date(), 905,
"Retrieved Organization Locations successfully", "Organization Country List", countryList,
request.getRequestURI(), "Organization Country Details", null);
log.info("getCountrys End ");
return new ResponseEntity<>(getRespDetails, HttpStatus.OK);
}
}
......@@ -20,6 +20,7 @@ import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.springframework.data.mongodb.core.mapping.Field;
@Setter
@Getter
......@@ -134,6 +135,10 @@ public class Employee implements Serializable {
private String createdBy;
private String modifiedBy;
private String country;
private Date lastUpdateProfile;
@Field
private byte[] updateProfile;
......
......@@ -5,7 +5,9 @@ import com.nisum.myteam.model.FunctionalGroup;
import com.nisum.myteam.model.dao.Account;
import com.nisum.myteam.model.dao.Employee;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.text.ParseException;
import java.util.Date;
import java.util.HashMap;
......@@ -63,4 +65,8 @@ public interface IEmployeeService {
public int getEmployeesCountByDesignation(String designation);
Employee uploadProfile(String empId, MultipartFile file) throws MyTeamException, IOException;
byte[] getUploadFile(String empId);
}
......@@ -21,6 +21,8 @@ import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
......@@ -370,7 +372,8 @@ public class EmployeeService implements IEmployeeService {
} else if (status.equals("Resigned")) {
return employeeRepo.findByEmpSubStatusOrderByEmployeeNameAsc("Resigned");
} else {
return employeesList.stream().filter(e -> e.getEmpStatus().equals(status)).collect(Collectors.toList());
return employeesList.stream().filter(e->Optional.ofNullable(e.getEmpStatus()).isPresent() && e.getEmpStatus().equals(status)).collect(Collectors.toList());
}
}
......@@ -495,4 +498,22 @@ public class EmployeeService implements IEmployeeService {
return onDate.after(e.getDateOfJoining()) && Optional.ofNullable(e.getEndDate()).isPresent() ? onDate.before(e.getEndDate()):true;
}
@Override
public Employee uploadProfile(String empId, MultipartFile file) throws MyTeamException, IOException {
Employee existingEmployee = employeeRepo.findByEmployeeId(empId);
// Employee employee=new Employee();
// employee.setEmployeeId(empId);
existingEmployee.setUpdateProfile(file.getBytes());
existingEmployee.setLastUpdateProfile(new Date());
Employee employeePersisted = employeeRepo.save(existingEmployee);
return employeePersisted;
}
@Override
public byte[] getUploadFile(String empId) {
Employee emp= employeeRepo.findByEmployeeId(empId);
return emp.getUpdateProfile();
}
}
......@@ -11,6 +11,7 @@ myApp.controller("loginController",function($scope, myFactory, $compile, $window
getAllLocations();
getAllAccounts();
getMasterData();
getAllCountrys();
$("#start").trigger("click");
}
......@@ -86,6 +87,16 @@ myApp.controller("loginController",function($scope, myFactory, $compile, $window
});
};
function getAllCountrys(){
$http({
method : "GET",
url : appConfig.appUri +"/organization/countrys/"
}).then(function mySuccess(response) {
myFactory.setCountrys(response.data.records);
}, function myError(response) {
});
};
function getAllAccounts(){
$http({
method : "GET",
......@@ -132,7 +143,7 @@ myApp.controller("loginController",function($scope, myFactory, $compile, $window
$scope.empShift;
$scope.shifts = myFactory.getTechnologies();
$scope.locations = myFactory.getLocations();//["Shift 1(09:00 AM - 06:00 PM)","Shift 2(03:30 PM - 12:30 PM)", "Shift 3(09:00 PM - 06:00 AM)"];
$scope.country=myFactory.getAllCountrys();
$scope.getSelectedShift = function(){
if ($scope.empShift !== undefined) {
return $scope.empShift;
......@@ -140,6 +151,13 @@ myApp.controller("loginController",function($scope, myFactory, $compile, $window
return "Please select primary skill";
}
};
$scope.getSelectedCountry = function(){
if ($scope.empCountry !== undefined) {
return $scope.empCountry;
} else {
return "Please select work Country";
}
};
$scope.getSelectedLocation = function(){
if ($scope.empLocation !== undefined) {
return $scope.empLocation;
......@@ -205,13 +223,15 @@ myApp.controller("loginController",function($scope, myFactory, $compile, $window
}else if(empShift == undefined){
$scope.alertMsg = "Please select a primary skill";
document.getElementById('empShift').focus();
}
else if(empLocation == undefined){
}else if($scope.country == ""){
$scope.alertMsg = "Country is mandatory";
document.getElementById('empName').focus();
} else if(empLocation == undefined){
$scope.alertMsg = "Please select a work location";
document.getElementById('empLocation').focus();
}else{
$scope.alertMsg = "";
var record = {"employeeId":$scope.empId, "employeeName": $scope.empName, "emailId": $scope.empEmail, "role": "Employee", "shift": "Shift 1(09:00 AM - 06:00 PM)","mobileNumber":$scope.mobileNumber,"baseTechnology": $scope.empShift,"empLocation": $scope.empLocation};
var record = {"employeeId":$scope.empId, "employeeName": $scope.empName, "emailId": $scope.empEmail, "role": "Employee", "shift": "Shift 1(09:00 AM - 06:00 PM)","mobileNumber":$scope.mobileNumber,"baseTechnology": $scope.empShift,"empLocation": $scope.empLocation,"country": $scope.country};
addEmployee(record);
}
};
......@@ -372,7 +392,7 @@ myApp.controller("loginController",function($scope, myFactory, $compile, $window
auth2.disconnect();
//Clear if any values set to factory
var menuItems = [], designations = [], accounts = [], technologies = [], shifts = [],locations=[];
var menuItems = [], designations = [], accounts = [], technologies = [], shifts = [],locations=[], countrys = [];
myFactory.setEmpId("");
myFactory.setEmpName("");
myFactory.setEmpEmailId("");
......@@ -384,6 +404,7 @@ myApp.controller("loginController",function($scope, myFactory, $compile, $window
myFactory.setAccounts(accounts);
myFactory.setTechnologies(technologies);
myFactory.setShifts(shifts);
myFactory.setCountrys(countrys);
myFactory.setLocations(locations);
var element = document.getElementById('home');
var path = "'templates/login.html'";
......
myApp.controller("profileController", function($scope, $http, myFactory, $mdDialog, appConfig) {
myApp.controller("profileController", function($scope, $http, myFactory, $mdDialog, appConfig,$window) {
$scope.records = [];
$scope.empId = myFactory.getEmpId();
$scope.empName = myFactory.getEmpName();
......@@ -34,6 +34,29 @@ myApp.controller("profileController", function($scope, $http, myFactory, $mdDial
$scope.refreshPage();
});
};
$scope.download = function(){
var empId = $scope.empId;
var urlRequest = appConfig.appUri+ "/employees/downloadFile/"+empId;
$http({
method : "GET",
url : urlRequest,
headers:{'Content-type': 'application/msword'},
responseType : 'arraybuffer',
}).then(function mySuccess(response) {
var value=response.data;
var fileName=empId+".doc"
var file = new Blob([value], {type: 'application/msword'});
var url = window.URL || window.webkitURL;
var downloadLink = angular.element('<a></a>');
downloadLink.attr('href',url.createObjectURL(file));
downloadLink.attr('target','_self');
downloadLink.attr('download', fileName);
downloadLink[0].click();
}, function myError(response) {
showAlert(" Unable to find the profile , Please Upload profile ");
});
};
function UpdateProfileController($scope, $mdDialog, dataToPass) {
$scope.profile = dataToPass;
......@@ -45,6 +68,7 @@ myApp.controller("profileController", function($scope, $http, myFactory, $mdDial
$scope.personalEmailId=dataToPass.personalEmailId;
$scope.technologyKnown=dataToPass.technologyKnown;
$scope.designationEmp=(dataToPass.designation == null ? undefined: dataToPass.designation);
$scope.uploadFile=dataToPass.uploadFile;
$scope.cancel = function() {
$mdDialog.hide();
};
......@@ -63,6 +87,43 @@ myApp.controller("profileController", function($scope, $http, myFactory, $mdDial
return "Please select designation";
}
};
$scope.uploadFile = function(){
var file =$scope.file;
if(this.file == undefined ){
showAlert("Please Upload profile .DOC or .DOCX");
}
var ext=this.file.name.split(".").pop();
if(this.file == undefined &&(ext!="docx" || ext!="doc")){
showAlert("Please Upload profile .DOC and .DOCX");
}
var formData = new FormData();
formData.append('file',$scope.file);
$scope.alertMsg = "";
var empid=$scope.profile.employeeId
// var record = {"employeeId":$scope.profile.employeeId, "mobileNumber": $scope.mobileNumber, "alternateMobileNumber": $scope.alternateMobileNumber, "personalEmailId": $scope.personalEmailId, "baseTechnology": $scope.baseTechnology, "technologyKnown": $scope.technologyKnown};
var urlRequest = "";
urlRequest = appConfig.appUri+ "/employees/uploadProfile/"+$scope.profile.employeeId;
var req = {
method : 'POST',
url : urlRequest,
headers : {
"Content-type" : undefined
},
transformRequest: angular.identity,
data : formData
}
$http(req).then(function mySuccess(response) {
$mdDialog.hide('Success');
$scope.dataToPass=response.data;
}, function myError(response){
$mdDialog.hide('Error');
});
};
$scope.validateFields = function(){
var mobileNumber = $scope.mobileNumber;
$scope.alertMsg = "";
......
......@@ -46,6 +46,7 @@ myApp.factory('myFactory', function() {
var employeeSubStatus="";
var employementTypes="";
var domains="";
var countrys="";
function setEmpId(id) {
empId = id;
}
......@@ -177,7 +178,13 @@ myApp.factory('myFactory', function() {
return true;
}
return false;
}
}
function setCountrys(country1) {
countrys = country1;
}
function getCountrys() {
return countrys;
}
// function addFormDataCheck(form){
// var obj = {};
......@@ -255,6 +262,8 @@ myApp.factory('myFactory', function() {
getDomains : getDomains,
setTechnologies : setTechnologies,
getTechnologies : getTechnologies,
setCountrys : setCountrys,
getCountrys : getCountrys,
setLocations : setLocations,
getLocations : getLocations,
setFunctionalgroups : setFunctionalgroups,
......
......@@ -161,6 +161,14 @@
ng-value="designation" ng-repeat="designation in designations">{{designation}}</md-option>
</md-optgroup> </md-select></td>
</tr>
<tr>
<td colspan="4"><b>Country:</b><span class="mandatory"></span></td>
<td colspan="8"><md-select ng-model="empCountry" ng-blur="validateMessage()" name="empCountry"
md-selected-text="getSelectedCountry()" id="empCountry">
<md-optgroup label="countrys"> <md-option
ng-value="country" ng-repeat="country in countrys">{{country}}</md-option>
</md-optgroup> </md-select></td>
</tr>
<tr>
<td colspan="4"><b>Work &nbsp;Location:</b><span class="mandatory"></span></td>
......
<div class="md-padding my-profile" id="popupContainer" ng-controller="profileController" ng-init="getProfileData()">
<h1 class="no-padding">My Profile
<span class="right">
<md-button class="add-btn md-raised md-primary" ng-click="download()"> <i class="fa fa-pencil-square-o fa-1x"></i> Download Profile
</md-button>
<md-button class="add-btn md-raised md-primary" ng-click="updateProfile()"> <i class="fa fa-pencil-square-o fa-1x"></i> Update Profile
</md-button>
<i class="fa fa-refresh" aria-hidden="true" ng-click="refreshPage()"></i>
......@@ -244,6 +246,30 @@
</p>
</div>
</div>
<div class="row">
<div class="col-lg-4 col-xs-6">
<p>
<b>Country</b> <b class="right">:</b>
</p>
</div>
<div class="col-lg-7 col-xs-6">
<p>
{{profile.country}}
</p>
</div>
</div>
<div class="row">
<div class="col-lg-4 col-xs-6">
<p>
<b>Last Update Profile</b> <b class="right">:</b>
</p>
</div>
<div class="col-lg-7 col-xs-6">
<p>
{{profile.lastUpdateProfile | date:'dd-MMM-yyyy'}}
</p>
</div>
</div>
</div>
</div>
<div class="col-lg-2 col-xs-12"></div>
......
......@@ -24,6 +24,7 @@
ng-repeat="tech in technologies">{{tech}}</md-option> </md-optgroup> </md-select>
<textarea rows="4" cols="10" class="form-control" id="technologyKnown" name="technologyKnown"
ng-model="technologyKnown" placeholder="Technologies Known" />
<input type="file" file-model="file" class="form-control" id="uploadFile" name="uploadFile" ng-model="uploadFile" placeholder="Upload Profile" multiple/>
<div role="alert">
<span class="error" style="color: red;">{{alertMsg}}</span>
</div>
......@@ -31,10 +32,10 @@
</md-dialog-content>
<md-dialog-actions layout="row"> <md-button
class="md-raised" data-ng-click="validateFields()">
Update </md-button> <md-button class="md-raised" ng-click="cancel()">
Cancel </md-button> </md-dialog-actions>
<md-dialog-actions layout="row">
<md-button class="md-raised" data-ng-click="uploadFile()">Upload </md-button>
<md-button class="md-raised" data-ng-click="validateFields()"> Update </md-button>
<md-button class="md-raised" ng-click="cancel()"> Cancel </md-button> </md-dialog-actions>
</form>
</md-dialog>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment