Skip to content
Open
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
3 changes: 2 additions & 1 deletion src/main/java/org/sunbird/core/config/SunbirdConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@

@Configuration
@ConfigurationProperties("spring.data.cassandra.sb")
@EnableCassandraRepositories(basePackages = { "org.sunbird.assessment.repo" }, cassandraTemplateRef = "sunbirdTemplate")
@EnableCassandraRepositories(basePackages = { "org.sunbird.assessment.repo",
"org.sunbird.learnerPath.repository" }, cassandraTemplateRef = "sunbirdTemplate")
public class SunbirdConfig extends CassandraConfig {

private Logger logger = LoggerFactory.getLogger(SunbirdConfig.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.sunbird.learnerPath.repository;

import java.util.List;

import org.springframework.data.cassandra.repository.CassandraRepository;
import org.springframework.stereotype.Repository;
import org.sunbird.learnerPath.repository.model.LearnerPath;


@Repository
public interface LearnerPathRepository extends CassandraRepository<LearnerPath, String> {
List<LearnerPath> findByUserid(String userid);
List<LearnerPath> findByUseridAndCourseid(String userId, String courseId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.sunbird.learnerPath.repository;

import org.springframework.data.cassandra.repository.CassandraRepository;
import org.springframework.stereotype.Repository;
import org.sunbird.learnerPath.repository.model.UserPassbook;

import java.util.List;

@Repository
public interface UserPassbookRepository extends CassandraRepository<UserPassbook, String> {

List<UserPassbook> findByUserid(String userid);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package org.sunbird.learnerPath.repository.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.sunbird.learnerPath.repository.model.LearnerPath;
import org.sunbird.learnerPath.repository.service.LearnerPathService;
import org.sunbird.learnerPath.repository.service.UserPassbookService;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

@RestController
public class LearnerPathController {

@Autowired
private LearnerPathService learnerpathservice;
@Autowired
private UserPassbookService userPassbookService;

@PostMapping(value = "/learnerpath")
public ResponseEntity<LearnerPath> createOrUpdateLearnerPath(@RequestBody LearnerPath learnerPath) {
return ResponseEntity.ok(learnerpathservice.insertOrUpdate(learnerPath));
}


@GetMapping("/learnerpath")
public ResponseEntity<List<LearnerPath>> getLearnerPath(@RequestParam(value = "userId", required = true) String userId,
@RequestParam(value = "courseId", required = false) String courseId) {

List<LearnerPath> learnerPaths;
List<LearnerPath> userPassbooks;
if (courseId != null) {

userPassbooks= userPassbookService.getUserPassbookByUseridAndCourseId(userId, courseId);
learnerPaths = learnerpathservice.findByUserIdAndCourseId(userId, courseId);

} else {
userPassbooks = userPassbookService.getUserPassbookByUserid(userId);
learnerPaths = learnerpathservice.findByUserId(userId);
}
// Set<LearnerPath> learnerPathSet = new HashSet<>(learnerPaths); // Convert to set to eliminate duplicates
// learnerPathSet.removeAll(userPassbooks); // Remove userPassbooks from learnerPaths set
Set<LearnerPath> mergedSet = new HashSet<>(learnerPaths);
mergedSet.addAll(userPassbooks);

List<LearnerPath> mergedList = new ArrayList<>(mergedSet);

if (mergedList.isEmpty()) {
return ResponseEntity.notFound().build();
}

return ResponseEntity.ok(mergedList);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
package org.sunbird.learnerPath.repository.model;

import java.time.LocalDateTime;

import org.springframework.data.cassandra.core.mapping.PrimaryKey;
import org.springframework.data.cassandra.core.mapping.Table;

@Table(value = "asha_learnerpath")
public class LearnerPath {
@PrimaryKey("userid")
private String userid; // Unique user identifier
private String courseid; // Identifier for the course
private String batchid; // Identifier for the batch
private String contentid; // Identifier for the content
private String competencyid;
private int competencylevel; // competency level
private double completionpercentage; // Percentage of completion
private LocalDateTime datetime; // Date and time of enrollment
private LocalDateTime last_access_time; // Last access time of the learner
private LocalDateTime last_completed_time; // Last completion time of the learner
private String content_type; // Progress status (e.g., "In Progress", "Completed")
private String pass_fail_status = "Fail"; // Default value set to "Fail"
private int attemptcount = 0; // Default value set to 0


// 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;
}

public String getBatchid() {
return batchid;
}

public void setBatchid(String batchid) {
this.batchid = batchid;
}

public String getContentid() {
return contentid;
}

public void setContentid(String contentid) {
this.contentid = contentid;
}

public String getCompetencyid() {
return competencyid;
}

public void setCompetencyid(String competencyid) {
this.competencyid = competencyid;
}

public int getcompetencylevel() {
return competencylevel;
}

public void setcompetencylevel(int competencylevel) {
this.competencylevel = competencylevel;
}

public double getCompletionpercentage() {
return completionpercentage;
}

public void setCompletionpercentage(double completionpercentage) {
this.completionpercentage = completionpercentage;
// Update passFailStatus if completionpercentage is 100
if (completionpercentage == 100) {
this.pass_fail_status = "Pass";
updateLastCompletedTime();
}
}

public LocalDateTime getDatetime() {
return datetime;
}

// Only set this once when the user enrolls
public void setDatetime(LocalDateTime datetime) {
if (this.datetime == null) {
this.datetime = datetime;
}
}

public LocalDateTime getLastAccessTime() {
return last_access_time;
}

public void setLastAccessTime(LocalDateTime lastAccessTime) {
this.last_access_time = lastAccessTime;
}

public LocalDateTime getLastCompletedTime() {
return last_completed_time;
}

private void updateLastCompletedTime() {
this.last_completed_time = LocalDateTime.now(); // Update to current time
}

public String getContentType() {
return content_type;
}

public void setContentType(String content_type) {
this.content_type = content_type;
}


public String getPassFailStatus() {
return pass_fail_status;
}

public void setPassFailStatus(String passFailStatus) {
this.pass_fail_status = passFailStatus;
}

public int getAttemptcount() {
return attemptcount;
}

// Method to increment attempt count
public void incrementAttemptCount() {
this.attemptcount++;
}

public void setAttemptcount(int attemptcount) {
this.attemptcount = attemptcount;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
package org.sunbird.learnerPath.repository.model;

import org.springframework.data.cassandra.core.mapping.Column;
import org.springframework.data.cassandra.core.mapping.PrimaryKey;
import org.springframework.data.cassandra.core.mapping.Table;
import java.time.Instant;
import java.util.Map;

@Table(value="user_passbook_v2") // table name in Cassandra
public class UserPassbook {

@PrimaryKey("userid")
@Column("userid")
private String userid;

@Column("typename")
private String typename;

@Column("acquiredchannel")
private String acquiredChannel;

@Column("typeid")
private String typeId;

@Column("contextid")
private String contextId;

@Column("effectivedate")
private Instant effectiveDate;

@Column("acquireddetails")
private Map<String, String> acquiredDetails;

@Column("additionalparams")
private Map<String, String> additionalParams;

// Top-level fields for final response
private String resourceId;
private String courseId;
private String competencyName;

// Getters and setters for all fields

public String getUserid() {
return userid;
}

public void setUserid(String userid) {
this.userid = userid;
}

public String getTypename() {
return typename;
}

public void setTypename(String typename) {
this.typename = typename;
}

public String getAcquiredChannel() {
return acquiredChannel;
}

public void setAcquiredChannel(String acquiredChannel) {
this.acquiredChannel = acquiredChannel;
}

public String getTypeId() {
return typeId;
}

public void setTypeId(String typeId) {
this.typeId = typeId;
}

public String getContextId() {
return contextId;
}

public void setContextId(String contextId) {
this.contextId = contextId;
}

public Instant getEffectiveDate() {
return effectiveDate;
}

public void setEffectiveDate(Instant effectiveDate) {
this.effectiveDate = effectiveDate;
}

public Map<String, String> getAcquiredDetails() {
return acquiredDetails;
}

public void setAcquiredDetails(Map<String, String> acquiredDetails) {
this.acquiredDetails = acquiredDetails;
}

public Map<String, String> getAdditionalParams() {
return additionalParams;
}

public void setAdditionalParams(Map<String, String> additionalParams) {
this.additionalParams = additionalParams;
}

// Getters and setters for new top-level fields
public String getResourceId() {
return resourceId;
}

public void setResourceId(String resourceId) {
this.resourceId = resourceId;
}

public String getCourseId() {
return courseId;
}

public void setCourseId(String courseId) {
this.courseId = courseId;
}

public String getCompetencyName() {
return competencyName;
}

public void setCompetencyName(String competencyName) {
this.competencyName = competencyName;
}
}

Loading