forked from Sunbird-Lern/lms-service
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* sunbird-course-getPatrcipantList changes * Batch listing updates (#35) * Changes for particpant list - includes crud * Fixes in user enrollment and lookup table * Modifications for CassandraOperations files * Removed unnecessary changes * Removed unnecessary changes --------- Co-authored-by: wilky singh <wilky.singh@tarento.com> * Updated code as per new version * Added limit for participants list * Removed unnecessary info statement --------- Co-authored-by: sreeragksgh <sreeragsajeesh@gmail.com> Co-authored-by: somvitbhowmik <38094153+somvitbhowmik@users.noreply.github.com> Co-authored-by: wilky singh <wilky.singh@tarento.com>
- Loading branch information
1 parent
7c53658
commit 84d4a47
Showing
10 changed files
with
241 additions
and
18 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
...-actors-common/src/main/java/org/sunbird/learner/actors/coursebatch/dao/BatchUserDao.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,28 @@ | ||
package org.sunbird.learner.actors.coursebatch.dao; | ||
import java.security.Timestamp; | ||
import java.util.List; | ||
import java.util.Map; | ||
import org.sunbird.common.models.response.Response; | ||
import org.sunbird.common.request.Request; | ||
import org.sunbird.common.request.RequestContext; | ||
import org.sunbird.models.batch.user.BatchUser; | ||
import org.sunbird.models.course.batch.CourseBatch; | ||
import org.sunbird.models.user.courses.UserCourses; | ||
|
||
public interface BatchUserDao { | ||
/** | ||
* Get user courses information. | ||
* | ||
* @param batchId,userId user courses identifiers | ||
* @param requestContext | ||
* @return User batch information | ||
*/ | ||
|
||
BatchUser readById(RequestContext requestContext, String batchId); | ||
BatchUser read(RequestContext requestContext, String batchId, String userId); | ||
Response insertBatchLookupRecord(RequestContext requestContext, Map<String, Object> userCoursesDetails); | ||
|
||
Response updateBatchLookupRecord(RequestContext requestContext, String courseId, String batchId, Map<String, Object> updateAttributes,Map<String, Object> activeStatus); | ||
|
||
|
||
} |
98 changes: 98 additions & 0 deletions
98
...ommon/src/main/java/org/sunbird/learner/actors/coursebatch/dao/impl/BatchUserDaoImpl.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,98 @@ | ||
package org.sunbird.learner.actors.coursebatch.dao.impl; | ||
|
||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.apache.commons.collections.CollectionUtils; | ||
import org.sunbird.cassandra.CassandraOperation; | ||
import org.sunbird.common.CassandraUtil; | ||
import org.sunbird.common.models.response.Response; | ||
import org.sunbird.common.models.util.JsonKey; | ||
import org.sunbird.common.request.RequestContext; | ||
import org.sunbird.helper.ServiceFactory; | ||
import org.sunbird.learner.actors.coursebatch.dao.BatchUserDao; | ||
import org.sunbird.learner.util.Util; | ||
import org.sunbird.models.batch.user.BatchUser; | ||
import org.sunbird.common.models.util.LoggerUtil; | ||
|
||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class BatchUserDaoImpl implements BatchUserDao{ | ||
protected LoggerUtil logger = new LoggerUtil(this.getClass()); | ||
private CassandraOperation cassandraOperation = ServiceFactory.getInstance(); | ||
private ObjectMapper mapper = new ObjectMapper(); | ||
static BatchUserDao batchUserDao; | ||
private static final String KEYSPACE_NAME = | ||
Util.dbInfoMap.get(JsonKey.ENROLLMENT_BATCH_DB).getKeySpace(); | ||
|
||
private static final String ENROLLMENT_BATCH = | ||
Util.dbInfoMap.get(JsonKey.ENROLLMENT_BATCH_DB).getTableName(); | ||
public static BatchUserDao getInstance() { | ||
if (batchUserDao == null) { | ||
batchUserDao = new BatchUserDaoImpl(); | ||
} | ||
return batchUserDao; | ||
} | ||
|
||
@Override | ||
public BatchUser readById(RequestContext requestContext, String batchId) { | ||
Map<String, Object> primaryKey = new HashMap<>(); | ||
primaryKey.put(JsonKey.BATCH_ID, batchId); | ||
Response response = cassandraOperation.getRecordByIdentifier(requestContext, KEYSPACE_NAME, ENROLLMENT_BATCH, primaryKey, null); | ||
try { | ||
List<Map<String, Object>> batchUserList = | ||
(List<Map<String, Object>>) response.get(JsonKey.RESPONSE); | ||
if (CollectionUtils.isEmpty(batchUserList)) { | ||
return null; | ||
} | ||
return mapper.convertValue((Map<String, Object>) batchUserList.get(0), BatchUser.class); | ||
} catch (Exception e) { | ||
logger.error(requestContext, "Failed to read BatchUser Table. Exception: ", e); | ||
return null; | ||
} | ||
} | ||
|
||
@Override | ||
public BatchUser read(RequestContext requestContext, String batchId, String userId) { | ||
Map<String, Object> primaryKey = new HashMap<>(); | ||
primaryKey.put(JsonKey.BATCH_ID, batchId); | ||
primaryKey.put(JsonKey.USER_ID, userId); | ||
Response response = cassandraOperation.getRecordByIdentifier(requestContext, KEYSPACE_NAME, ENROLLMENT_BATCH, primaryKey, null); | ||
try { | ||
List<Map<String, Object>> batchUserList = | ||
(List<Map<String, Object>>) response.get(JsonKey.RESPONSE); | ||
if (CollectionUtils.isEmpty(batchUserList)) { | ||
return null; | ||
} | ||
return mapper.readValue(mapper.writeValueAsString(batchUserList.get(0)), new TypeReference<BatchUser>() {}); | ||
} catch (Exception e) { | ||
logger.error(requestContext, "Failed to read BatchUser Table. Exception: ", e); | ||
return null; | ||
} | ||
} | ||
@Override | ||
public Response insertBatchLookupRecord(RequestContext requestContext, Map<String, Object> userCoursesDetails) { | ||
return cassandraOperation.insertRecord(requestContext, KEYSPACE_NAME, ENROLLMENT_BATCH, userCoursesDetails); | ||
} | ||
|
||
|
||
@Override | ||
public Response updateBatchLookupRecord(RequestContext requestContext, String batchId, String userId, Map<String, Object> map,Map<String, Object> activeStatus) { | ||
Map<String, Object> primaryKey = new HashMap<>(); | ||
primaryKey.put(JsonKey.BATCH_ID, batchId); | ||
primaryKey.put(JsonKey.USER_ID, userId); | ||
primaryKey.put(JsonKey.ENROLLED_DATE, map.get("enrolled_date")); | ||
Map<String, Object> attributeMap = new HashMap<>(); | ||
attributeMap.putAll(activeStatus); | ||
attributeMap.remove(JsonKey.BATCH_ID); | ||
attributeMap = CassandraUtil.changeCassandraColumnMapping(attributeMap); | ||
return cassandraOperation.updateRecord( | ||
requestContext, KEYSPACE_NAME, ENROLLMENT_BATCH, attributeMap, primaryKey); | ||
} | ||
} | ||
|
||
|
||
|
||
|
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
54 changes: 54 additions & 0 deletions
54
course-mw/course-actors-common/src/main/java/org/sunbird/models/batch/user/BatchUser.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 org.sunbird.models.batch.user; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
|
||
import java.io.Serializable; | ||
import java.sql.Timestamp; | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
public class BatchUser implements Serializable { | ||
|
||
private static final long serialVersionUID = 1L; | ||
private String batchId; | ||
|
||
private String userId; | ||
|
||
private Boolean active; | ||
|
||
private Timestamp enrolledDate; | ||
|
||
public String getBatchId() { | ||
return batchId; | ||
} | ||
|
||
public void setBatchId(String batchId) { | ||
this.batchId = batchId; | ||
} | ||
|
||
public String getUserId() { | ||
return userId; | ||
} | ||
|
||
public void setUserId(String userId) { | ||
this.userId = userId; | ||
} | ||
|
||
public Boolean getActive() { | ||
return active; | ||
} | ||
|
||
public void setActive(Boolean active) { | ||
this.active = active; | ||
} | ||
|
||
public Timestamp getEnrolledDate() { | ||
return enrolledDate; | ||
} | ||
|
||
public void setEnrolledDate(Timestamp enrolledDate) { | ||
this.enrolledDate = enrolledDate; | ||
} | ||
|
||
} |
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
Oops, something went wrong.