Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User activity logs sync. #36

Merged
merged 1 commit into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.iemr.hwc.controller.CHOApp;
package com.iemr.hwc.controller.choApp;

import com.iemr.hwc.service.CHOApp.CHOAppSyncService;
import com.iemr.hwc.service.choApp.CHOAppSyncService;
import com.iemr.hwc.utils.request.SyncSearchRequest;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -50,4 +50,13 @@ public ResponseEntity<String> flowStatusesSyncToAppLocal(@RequestBody SyncSearch
return choappSyncService.getFlowRecordsByVillageIDAndLastModifiedDate(villageIDAndLastSyncDate, Authorization);
}

// Login logout logs sync from CHO app to AMRIT server
@ApiOperation(value = "Sync user activity logs to AMRIT server", consumes = "application/json", produces = "application/json")
@RequestMapping(value = { "/userActivityLogsToServer" }, method = { RequestMethod.POST })
public ResponseEntity<String> userActivityLogsSyncToServer(@RequestBody String comingReq,
@RequestHeader(value = "Authorization") String Authorization) {

return choappSyncService.saveUserActivityLogs(comingReq, Authorization);
}

}
56 changes: 56 additions & 0 deletions src/main/java/com/iemr/hwc/data/choApp/UserActivityLogs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.iemr.hwc.data.choApp;

import com.google.gson.annotations.Expose;
import lombok.Data;
import javax.persistence.*;
import java.sql.Timestamp;

@Data
@Entity
@Table(name = "t_user_activity_logs")
public class UserActivityLogs {

@Id
@Expose
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "Id")
private int logId;

@Expose
@Column(name = "UserId")
private String userId;

@Expose
@Column(name = "UserName")
private String userName;

@Expose
@Column(name = "LoginType")
private String loginType;

@Expose
@Column(name = "LoginOption")
private String option;

@Expose
@Column(name = "LogoutType")
private String logoutType;

@Expose
@Column(name = "LoginTime")
private Timestamp loginTimeStamp;

@Expose
@Column(name = "LogoutTime")
private Timestamp logoutTimeStamp;

@Expose
@Column(name = "Latitude")
private Double latitude ;

@Expose
@Column(name = "Longitude")
private Double longitude;

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.iemr.hwc.repo.choApp;

import com.iemr.hwc.data.choApp.UserActivityLogs;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface UserActivityLogsRepo extends CrudRepository<UserActivityLogs,Integer> {
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.iemr.hwc.service.CHOApp;
package com.iemr.hwc.service.choApp;

import com.iemr.hwc.utils.request.SyncSearchRequest;
import org.springframework.http.ResponseEntity;
Expand All @@ -9,4 +9,6 @@ public interface CHOAppSyncService {
ResponseEntity<String> getBeneficiaryByVillageIDAndLastModifiedDate(SyncSearchRequest villageIDAndLastSyncDate, String authorization);

ResponseEntity<String> getFlowRecordsByVillageIDAndLastModifiedDate(SyncSearchRequest villageIDAndLastSyncDate, String authorization);

ResponseEntity<String> saveUserActivityLogs(String comingReq, String authorization);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.iemr.hwc.service.CHOApp;
package com.iemr.hwc.service.choApp;

import com.google.gson.*;
import com.iemr.hwc.data.benFlowStatus.BeneficiaryFlowStatus;
import com.iemr.hwc.data.choApp.UserActivityLogs;
import com.iemr.hwc.repo.benFlowStatus.BeneficiaryFlowStatusRepo;
import com.iemr.hwc.repo.choApp.UserActivityLogsRepo;
import com.iemr.hwc.service.benFlowStatus.CommonBenStatusFlowServiceImpl;
import com.iemr.hwc.utils.exception.IEMRException;
import com.iemr.hwc.utils.mapper.InputMapper;
import com.iemr.hwc.utils.request.SyncSearchRequest;
import com.iemr.hwc.utils.response.OutputResponse;
import org.joda.time.DateTime;
Expand All @@ -17,6 +21,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
Expand All @@ -28,6 +33,8 @@
import javax.ws.rs.core.MediaType;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Service
@PropertySource("classpath:application.properties")
Expand All @@ -45,6 +52,8 @@ public class CHOAppSyncServiceImpl implements CHOAppSyncService {

private BeneficiaryFlowStatusRepo beneficiaryFlowStatusRepo;

private UserActivityLogsRepo userActivityLogsRepo;

@Autowired
public void setCommonBenStatusFlowServiceImpl(CommonBenStatusFlowServiceImpl commonBenStatusFlowServiceImpl) {
this.commonBenStatusFlowServiceImpl = commonBenStatusFlowServiceImpl;
Expand All @@ -55,6 +64,11 @@ public void setBeneficiaryFlowStatusRepo(BeneficiaryFlowStatusRepo beneficiaryFl
this.beneficiaryFlowStatusRepo = beneficiaryFlowStatusRepo;
}

@Autowired
public void setUserActivityLogsRepo(UserActivityLogsRepo userActivityLogsRepo){
this.userActivityLogsRepo = userActivityLogsRepo;
}

public ResponseEntity<String> registerCHOAPPBeneficiary(String comingRequest, String Authorization){

OutputResponse outputResponse = new OutputResponse();
Expand Down Expand Up @@ -226,4 +240,41 @@ public ResponseEntity<String> getFlowRecordsByVillageIDAndLastModifiedDate(SyncS
return new ResponseEntity<>(outputResponse.toStringWithSerializeNulls(),headers,statusCode);

}

@Override
public ResponseEntity<String> saveUserActivityLogs(String comingReq, String authorization) {

OutputResponse outputResponse = new OutputResponse();
HttpStatus statusCode = HttpStatus.OK;

MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
headers.add("Content-Type", "application/json");

try{
UserActivityLogs[] logs = InputMapper.gson().fromJson(comingReq,UserActivityLogs[].class);
List<UserActivityLogs> logsList = Arrays.asList(logs);

List<UserActivityLogs> savedList = (List<UserActivityLogs>) userActivityLogsRepo.save(logsList);

if (savedList.size() == logsList.size()){
outputResponse.setResponse("Data saved successfully");
}else {
throw new Exception();
}

} catch (IEMRException | DataIntegrityViolationException |
JsonSyntaxException | NumberFormatException e){
logger.error("Encountered exception EITHER due to incorrect payload syntax OR" +
" because of missing userId. " + e);
outputResponse.setError(400,"Encountered exception EITHER due to incorrect payload syntax OR " +
"because of missing userId. Please check the payload. " + e);
statusCode = HttpStatus.BAD_REQUEST;
} catch (Exception e){
logger.error("Encountered exception while saving UserActivityLogs. " + e);
outputResponse.setError(500,"Encountered exception while saving UserActivityLogs. " + e);
statusCode = HttpStatus.INTERNAL_SERVER_ERROR;
}

return new ResponseEntity<>(outputResponse.toString(),headers,statusCode);
}
}
Loading