-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from KB-iGOT/4.8.19-dev-v2
4.8.19 dev v2
- Loading branch information
Showing
17 changed files
with
545 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
src/main/java/com/tarento/commenthub/authentication/util/FetchUserDetails.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package com.tarento.commenthub.authentication.util; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.tarento.commenthub.constant.Constants; | ||
import com.tarento.commenthub.transactional.cassandrautils.CassandraOperation; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
import org.apache.commons.collections4.MapUtils; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.data.redis.core.RedisTemplate; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class FetchUserDetails { | ||
|
||
@Autowired | ||
private RedisTemplate<String, Object> redisTemplate; | ||
|
||
@Autowired | ||
private CassandraOperation cassandraOperation; | ||
|
||
ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
public List<Object> fetchDataForKeys(List<String> keys) { | ||
// Fetch values for all keys from Redis | ||
List<Object> values = redisTemplate.opsForValue().multiGet(keys); | ||
|
||
// Create a map of key-value pairs, converting stringified JSON objects to User objects | ||
return keys.stream() | ||
.filter(key -> values.get(keys.indexOf(key)) != null) // Filter out null values | ||
.map(key -> { | ||
String stringifiedJson = (String) values.get(keys.indexOf(key)); // Cast the value to String | ||
try { | ||
// Convert the stringified JSON to a User object using ObjectMapper | ||
return objectMapper.readValue(stringifiedJson, Object.class); // You can map this to a specific User type if needed | ||
} catch (Exception e) { | ||
// Handle any exceptions during deserialization | ||
e.printStackTrace(); | ||
return null; // Return null in case of error | ||
} | ||
}) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
public List<Object> fetchUserFromprimary(List<String> userIds) { | ||
List<Object> userList = new ArrayList<>(); | ||
Map<String, Object> propertyMap = new HashMap<>(); | ||
propertyMap.put(Constants.ID, userIds); | ||
List<Map<String, Object>> userInfoList = cassandraOperation.getRecordsByPropertiesWithoutFiltering( | ||
Constants.KEYSPACE_SUNBIRD, Constants.TABLE_USER, propertyMap, | ||
Arrays.asList(Constants.PROFILE_DETAILS, Constants.FIRST_NAME, Constants.ID), null); | ||
|
||
userList = userInfoList.stream() | ||
.map(userInfo -> { | ||
Map<String, Object> userMap = new HashMap<>(); | ||
|
||
// Extract user ID and user name | ||
String userId = (String) userInfo.get(Constants.ID); | ||
String userName = (String) userInfo.get(Constants.FIRST_NAME); | ||
|
||
userMap.put(Constants.USER_ID_KEY, userId); | ||
userMap.put(Constants.FIRST_NAME_KEY, userName); | ||
|
||
// Process profile details if present | ||
String profileDetails = (String) userInfo.get(Constants.PROFILE_DETAILS); | ||
if (StringUtils.isNotBlank(profileDetails)) { | ||
try { | ||
// Convert JSON profile details to a Map | ||
Map<String, Object> profileDetailsMap = objectMapper.readValue(profileDetails, | ||
new TypeReference<HashMap<String, Object>>() {}); | ||
|
||
// Check for profile image and add to userMap if available | ||
if (MapUtils.isNotEmpty(profileDetailsMap)) { | ||
if (profileDetailsMap.containsKey(Constants.PROFILE_IMG) && StringUtils.isNotBlank((String) profileDetailsMap.get(Constants.PROFILE_IMG))){ | ||
userMap.put(Constants.PROFILE_IMG_KEY, (String) profileDetailsMap.get(Constants.PROFILE_IMG)); | ||
} | ||
if (profileDetailsMap.containsKey(Constants.DESIGNATION_KEY) && StringUtils.isNotEmpty((String) profileDetailsMap.get(Constants.DESIGNATION_KEY))) { | ||
|
||
userMap.put(Constants.DESIGNATION_KEY, (String) profileDetailsMap.get(Constants.PROFILE_IMG)); | ||
} | ||
if(profileDetailsMap.containsKey(Constants.EMPLOYMENT_DETAILS) && MapUtils.isNotEmpty( | ||
(Map<?, ?>) profileDetailsMap.get(Constants.EMPLOYMENT_DETAILS)) && ((Map<?, ?>) profileDetailsMap.get(Constants.EMPLOYMENT_DETAILS)).containsKey(Constants.DEPARTMENT_KEY) && StringUtils.isNotBlank( | ||
(String) ((Map<?, ?>) profileDetailsMap.get(Constants.EMPLOYMENT_DETAILS)).get(Constants.DEPARTMENT_KEY))){ | ||
userMap.put(Constants.DEPARTMENT, (String) ((Map<?, ?>) profileDetailsMap.get(Constants.EMPLOYMENT_DETAILS)).get(Constants.DEPARTMENT_KEY)); | ||
|
||
} | ||
|
||
} | ||
} catch (JsonProcessingException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
return userMap; | ||
}) | ||
.collect(Collectors.toList()); | ||
return userList; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,4 +28,6 @@ public class SearchCriteria { | |
|
||
private boolean overrideCache; | ||
|
||
private boolean enrichedUser; | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
src/main/java/com/tarento/commenthub/dto/UserCourseCommentsId.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.tarento.commenthub.dto; | ||
|
||
import java.io.Serializable; | ||
import java.util.Objects; | ||
import java.util.UUID; | ||
import javax.persistence.Embeddable; | ||
|
||
@Embeddable | ||
public class UserCourseCommentsId implements Serializable { | ||
|
||
private String userId; // Corresponds to user_id in the table | ||
private String courseId; // Corresponds to course_id in the table | ||
|
||
// Default Constructor | ||
public UserCourseCommentsId() {} | ||
|
||
// Constructor with fields | ||
public UserCourseCommentsId(String userId, String courseId) { | ||
this.userId = userId; | ||
this.courseId = courseId; | ||
} | ||
|
||
// Getters and Setters | ||
public String getUserId() { | ||
return userId; | ||
} | ||
|
||
public void setUserId(String userId) { | ||
this.userId = userId; | ||
} | ||
|
||
public String getCourseId() { | ||
return courseId; | ||
} | ||
|
||
public void setCourseId(String courseId) { | ||
this.courseId = courseId; | ||
} | ||
|
||
// Equals and HashCode | ||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
UserCourseCommentsId that = (UserCourseCommentsId) o; | ||
return Objects.equals(userId, that.userId) && Objects.equals(courseId, that.courseId); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(userId, courseId); | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/com/tarento/commenthub/entity/UserCourseCommentLike.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.tarento.commenthub.entity; | ||
|
||
import com.tarento.commenthub.dto.UserCourseCommentsId; | ||
import com.vladmihalcea.hibernate.type.json.JsonBinaryType; | ||
import java.io.Serializable; | ||
import java.util.List; | ||
import javax.persistence.Column; | ||
import javax.persistence.Embeddable; | ||
import javax.persistence.EmbeddedId; | ||
import javax.persistence.Entity; | ||
import javax.persistence.Table; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import org.hibernate.annotations.Type; | ||
import com.vladmihalcea.hibernate.type.array.ListArrayType; | ||
import org.hibernate.annotations.TypeDef; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Entity | ||
@Table(name = "user_course_comments_like") | ||
@TypeDef(name = "jsonb", typeClass = JsonBinaryType.class) | ||
@Embeddable | ||
public class UserCourseCommentLike implements Serializable { | ||
|
||
@EmbeddedId | ||
private UserCourseCommentsId id; | ||
|
||
@Column(name = "comment_ids") | ||
@Type(type = "com.vladmihalcea.hibernate.type.array.ListArrayType") | ||
private List<String> commentIds; // Maps to the comment_ids column | ||
|
||
|
||
|
||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/tarento/commenthub/repository/UserCommentLikeRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.tarento.commenthub.repository; | ||
|
||
import com.tarento.commenthub.dto.UserCourseCommentsId; | ||
import com.tarento.commenthub.entity.UserCourseCommentLike; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface UserCommentLikeRepository extends JpaRepository<UserCourseCommentLike, UserCourseCommentsId> { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.