Skip to content

Commit

Permalink
4.0.1 User SignUp, MDO CSV and other fixes (#139)
Browse files Browse the repository at this point in the history
Added user sign up API
Added MDO CSV file upload feature
Optimised Course Reminder notification email feature
  • Loading branch information
karthik-tarento authored Sep 23, 2022
1 parent 7e1ca1e commit 2c6ddb5
Show file tree
Hide file tree
Showing 26 changed files with 635 additions and 382 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -346,3 +346,18 @@ CREATE TABLE sunbird.ratings_lookup (
```sh
CREATE TABLE sunbird.explore_course_list ( identifier text primary key ) ;
```
```sh
CREATE TABLE sunbird.user_bulk_upload (
rootorgid text,
identifier text,
comment text,
createdby text,
datecreatedon timestamp,
dateupdatedon timestamp,
filename text,
filepath text,
status text,
updatedby text,
PRIMARY KEY (rootorgid, identifier)
) WITH CLUSTERING ORDER BY (identifier ASC);
```
26 changes: 0 additions & 26 deletions src/main/java/org/sunbird/common/executor/SchedulerTrigger.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@
*/
public interface CassandraConnectionManager {

/**
* Method to create the cassandra connection .
*
* @param hosts
*/
void createConnection();

/**
* Method to get the cassandra session oject on basis of keyspace name provided .
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,22 @@ public class CassandraConnectionManagerImpl implements CassandraConnectionManage
private static Map<String, Session> cassandraSessionMap = new ConcurrentHashMap<>(2);
public static CbExtLogger logger = new CbExtLogger(CassandraConnectionManagerImpl.class.getName());

static {
public CassandraConnectionManagerImpl() {
registerShutDownHook();
}

@Override
public void createConnection() {
createCassandraConnection();
}

@Override
public Session getSession(String keyspace) {
Session session = cassandraSessionMap.get(keyspace);
if (null != session) {
return session;
} else {
Session session2 = cluster.connect(keyspace);
cassandraSessionMap.put(keyspace, session2);
return session2;
}
}
public Session getSession(String keyspace) {
Session session = cassandraSessionMap.get(keyspace);
if (null != session) {
return session;
} else {
Session session2 = cluster.connect(keyspace);
cassandraSessionMap.put(keyspace, session2);
return session2;
}
}

private void createCassandraConnection() {
try {
Expand Down Expand Up @@ -153,7 +149,9 @@ public void run() {
for (Map.Entry<String, Session> entry : cassandraSessionMap.entrySet()) {
cassandraSessionMap.get(entry.getKey()).close();
}
cluster.close();
if (cluster != null) {
cluster.close();
}
logger.info("completed resource cleanup Cassandra.");
} catch (Exception ex) {
logger.error(ex);
Expand Down
92 changes: 68 additions & 24 deletions src/main/java/org/sunbird/common/util/CbExtServerProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,20 @@ public class CbExtServerProperties {
@Value("${cache.max.ttl}")
private long cacheMaxTTL;

@Value("${azure.container.name}")
private String azureContainerName;
@Value("${cloud.container.name}")
private String cloudContainerName;

@Value("${azure.type.name}")
private String azureTypeName;
@Value("${cloud.storage.type.name}")
private String cloudStorageTypeName;

@Value("${azure.identity.name}")
private String azureIdentityName;
@Value("${cloud.storage.key}")
private String cloudStorageKey;

@Value("${azure.storage.key}")
private String azureStorageKey;
@Value("${cloud.storage.secret}")
private String cloudStorageSecret;

@Value("${cloud.storage.cephs3.endpoint}")
private String cloudStorageCephs3Endpoint;

@Value("${redis.host.name}")
private String redisHostName;
Expand Down Expand Up @@ -357,6 +360,15 @@ public class CbExtServerProperties {
@Value("${sb.es.user.profile.index}")
private String sbEsUserProfileIndex;

@Value("${sb.service.signup.user}")
private String lmsUserSignUpPath;

@Value("${user.bulk.upload.status.fields}")
private String bulkUploadStatusFields;

@Value("${user.bulk.upload.container.name}")
private String bulkUploadContainerName;

public String getUserAssessmentSubmissionDuration() {
return userAssessmentSubmissionDuration;
}
Expand Down Expand Up @@ -840,36 +852,44 @@ public void setCacheMaxTTL(long cacheMaxTTL) {
this.cacheMaxTTL = cacheMaxTTL;
}

public String getAzureContainerName() {
return azureContainerName;
public String getCloudContainerName() {
return cloudContainerName;
}

public void setCloudContainerName(String cloudContainerName) {
this.cloudContainerName = cloudContainerName;
}

public String getCloudStorageTypeName() {
return cloudStorageTypeName;
}

public void setAzureContainerName(String azureContainerName) {
this.azureContainerName = azureContainerName;
public void setCloudStorageTypeName(String cloudStorageTypeName) {
this.cloudStorageTypeName = cloudStorageTypeName;
}

public String getAzureTypeName() {
return azureTypeName;
public String getCloudStorageKey() {
return cloudStorageKey;
}

public void setAzureTypeName(String azureTypeName) {
this.azureTypeName = azureTypeName;
public void setCloudStorageKey(String cloudStorageKey) {
this.cloudStorageKey = cloudStorageKey;
}

public String getAzureIdentityName() {
return azureIdentityName;
public String getCloudStorageSecret() {
return cloudStorageSecret;
}

public void setAzureIdentityName(String azureIdentityName) {
this.azureIdentityName = azureIdentityName;
public void setCloudStorageSecret(String cloudStorageSecret) {
this.cloudStorageSecret = cloudStorageSecret;
}

public String getAzureStorageKey() {
return azureStorageKey;
public String getCloudStorageCephs3Endpoint() {
return cloudStorageCephs3Endpoint;
}

public void setAzureStorageKey(String azureStorageKey) {
this.azureStorageKey = azureStorageKey;
public void setCloudStorageCephs3Endpoint(String cloudStorageCephs3Endpoint) {
this.cloudStorageCephs3Endpoint = cloudStorageCephs3Endpoint;
}

public String getUserUtilityTopic() {
Expand Down Expand Up @@ -1303,4 +1323,28 @@ public String getSbEsUserProfileIndex() {
public void setSbEsUserProfileIndex(String sbEsUserProfileIndex) {
this.sbEsUserProfileIndex = sbEsUserProfileIndex;
}

public String getLmsUserSignUpPath() {
return lmsUserSignUpPath;
}

public void setLmsUserSignUpPath(String lmsUserSignUpPath) {
this.lmsUserSignUpPath = lmsUserSignUpPath;
}

public List<String> getBulkUploadStatusFields() {
return Arrays.asList(bulkUploadStatusFields.split(",", -1));
}

public void setBulkUploadStatusFields(String bulkUploadStatusFields) {
this.bulkUploadStatusFields = bulkUploadStatusFields;
}

public String getBulkUploadContainerName() {
return bulkUploadContainerName;
}

public void setBulkUploadContainerName(String bulkUploadContainerName) {
this.bulkUploadContainerName = bulkUploadContainerName;
}
}
18 changes: 15 additions & 3 deletions src/main/java/org/sunbird/common/util/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,9 @@ public class Constants {
public static final String HIERARCHY = "hierarchy";
public static final String DEV_HIERARCHY_STORE = "dev_hierarchy_store";
public static final String CONTENT_HIERARCHY = "content_hierarchy";
public static final String BATCH_ID_ = "batchid";
public static final String COURSE_ID_ = "courseid";
public static final String COMPLETION_PERCENTAGE_ = "completionpercentage";
public static final String BATCH_ID_COLUMN = "batchid";
public static final String COURSE_ID_COLUMN = "courseid";
public static final String COMPLETION_PERCENTAGE_COLUMN = "completionpercentage";
public static final String LAST_ACCESS_TIME = "last_access_time";
public static final String SUNBIRD_KEY_SPACE_NAME = "sunbird";
public static final String SUNBIRD_COURSES_KEY_SPACE_NAME = "sunbird_courses";
Expand Down Expand Up @@ -504,6 +504,18 @@ public class Constants {
public static final String PUBLIC_COURSE_LIST = "exploreOpenCourseList";
public static final String LAST_UPDATED_ON = "lastUpdatedOn";
public static final String DESCENDING_ORDER = "desc";
public static final String X_AUTH_USER_ORG_ID = "x-authenticated-user-orgid";
public static final String API_USER_SIGNUP = "api.user.signup";
public static final String API_USER_BULK_UPLOAD = "api.user.bulk.upload";
public static final String API_USER_BULK_UPLOAD_STATUS = "api.user.bulk.upload.status";
public static final String TABLE_USER_BULK_UPLOAD = "user_bulk_upload";
public static final String FILE_NAME = "fileName";
public static final String FILE_PATH = "filePath";
public static final String DATE_CREATED_ON = "dateCreatedOn";
public static final String DATE_UPDATE_ON = "dateUpdatedOn";
public static final String INITIATED_CAPITAL = "INITIATED";
public static final List<String> COURSE_REMINDER_EMAIL_FIELDS = Arrays.asList(RATINGS_USER_ID, BATCH_ID_COLUMN,
COURSE_ID_COLUMN, COMPLETION_PERCENTAGE_COLUMN, LAST_ACCESS_TIME);

private Constants() {
throw new IllegalStateException("Utility class");
Expand Down
21 changes: 7 additions & 14 deletions src/main/java/org/sunbird/common/util/NotificationUtil.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.sunbird.common.util;

import static org.sunbird.common.util.Constants.INCOMPLETE_COURSES;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
Expand All @@ -14,7 +12,6 @@
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import org.sunbird.common.model.EmailConfig;
Expand All @@ -23,16 +20,12 @@

@Service(Constants.NOTIFICATION_UTIL)
public class NotificationUtil {
public static final Logger Logger;
private static final Logger logger = LoggerFactory.getLogger(NotificationUtil.class);
private static final String EXCEPTION = "Exception in Send Notification %s";

@Autowired
RestTemplate restTemplate;

static {
Logger = LoggerFactory.getLogger(NotificationUtil.class);
}

public <params> void sendNotification(List<String> sendTo, Map<String, Object> params, String senderMail,
String notificationUrl) {
new Thread(() -> {
Expand All @@ -43,17 +36,17 @@ public <params> void sendNotification(List<String> sendTo, Map<String, Object> p
Map<String, Object> notificationRequest = new HashMap<>();
List<Object> notificationTosend = new ArrayList<>(Arrays.asList(new Notification(Constants.EMAIL,
Constants.MESSAGE, new EmailConfig(senderMail, Constants.INCOMPLETE_COURSES_MAIL_SUBJECT),
sendTo, new Template(null, INCOMPLETE_COURSES, params))));
sendTo, new Template(null, Constants.INCOMPLETE_COURSES, params))));
notificationRequest.put(Constants.REQUEST, new HashMap<String, List<Object>>() {
{
put(Constants.NOTIFICATIONS, notificationTosend);
}
});
Logger.info(String.format("Notification Request : %s", notificationRequest));
logger.info(String.format("Notification Request : %s", notificationRequest));
HttpEntity<Object> req = new HttpEntity<>(notificationRequest, headers);
ResponseEntity<String> resp = restTemplate.postForEntity(notificationUrl, req, String.class);
restTemplate.postForEntity(notificationUrl, req, String.class);
} catch (Exception e) {
Logger.error(String.format(EXCEPTION, e.getMessage()));
logger.error(String.format(EXCEPTION, e.getMessage()));
}
}).start();
}
Expand All @@ -74,10 +67,10 @@ public void sendNotification(List<Map<String, Object>> notifications) {
});

HttpEntity<Object> req = new HttpEntity<>(notificationRequest, headers);
Logger.info(String.format("Notification Request : %s", notificationRequest));
logger.info(String.format("Notification Request : %s", notificationRequest));
restTemplate.postForEntity(notificationUrl, req, Object.class);
} catch (Exception e) {
Logger.error(String.format(EXCEPTION, e.getMessage()));
logger.error(String.format(EXCEPTION, e.getMessage()));
}
}).start();
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/sunbird/core/logger/CbExtLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ public void error(Exception exception) {
+ "\", \"trace\":\"" + Throwables.getStackTraceAsString(exception) + "\"}");
}
}

public void error(String errMsg, Exception exception) {
logger.error(errMsg, exception);
}

public void fatal(Exception exception) {
ObjectMapper ow = new ObjectMapper();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.sunbird.scheduler.model;
package org.sunbird.course.model;

import javax.annotation.Generated;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

@JsonInclude(JsonInclude.Include.NON_NULL)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sunbird.scheduler.model;
package org.sunbird.course.model;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sunbird.scheduler.model;
package org.sunbird.course.model;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
Expand Down
Loading

0 comments on commit 2c6ddb5

Please sign in to comment.