Skip to content

Commit

Permalink
Issue # SB-470 Developement : Development for location api.
Browse files Browse the repository at this point in the history
  • Loading branch information
arvindyadav108 committed Nov 2, 2017
1 parent 442bb86 commit 4d2518c
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.sunbird.learner.actors.bulkupload.BulkUploadBackGroundJobActor;
import org.sunbird.learner.actors.bulkupload.BulkUploadManagementActor;
import org.sunbird.learner.actors.bulkupload.UserDataEncryptionDecryptionServiceActor;
import org.sunbird.learner.actors.geolocation.GeoLocationManagementActor;
import org.sunbird.learner.actors.skill.SkillmanagementActor;
import org.sunbird.learner.actors.fileuploadservice.FileUploadServiceActor;
import org.sunbird.learner.actors.notificationservice.EmailServiceActor;
Expand Down Expand Up @@ -80,6 +81,7 @@ public class RequestRouterActor extends UntypedAbstractActor {
private ActorRef badgesActor;
private ActorRef skillManagementActor;
private ActorRef tenantPrefManagementActor;
private ActorRef geoLocationManagementActor;

private ExecutionContext ec;

Expand Down Expand Up @@ -115,6 +117,7 @@ public class RequestRouterActor extends UntypedAbstractActor {
"userDataEncryptionDecryptionServiceActor";
private static final String SKILL_MANAGEMENT_ACTOR = "skillManagementActor";
private static final String TENANT_PREFERENCE_MNGT_ACTOR = "tenantPreferenceManagementActor";
private static final String GEO_LOCATION_MANAGEMENT_ACTOR="geoLocationManagementActor";



Expand Down Expand Up @@ -198,6 +201,7 @@ public RequestRouterActor() {
auditLogManagementActor = getContext().actorOf(Props.create(ActorAuditLogServiceImpl.class), AUDIT_LOG_MGMT_ACTOR);
skillManagementActor = getContext().actorOf(FromConfig.getInstance().props(Props.create(SkillmanagementActor.class)), SKILL_MANAGEMENT_ACTOR);
tenantPrefManagementActor = getContext().actorOf(FromConfig.getInstance().props(Props.create(TenantPreferenceManagementActor.class)), TENANT_PREFERENCE_MNGT_ACTOR);
geoLocationManagementActor = getContext().actorOf(FromConfig.getInstance().props(Props.create(GeoLocationManagementActor.class)), GEO_LOCATION_MANAGEMENT_ACTOR);
ec = getContext().dispatcher();
initializeRouterMap();
}
Expand Down Expand Up @@ -340,6 +344,8 @@ private void initializeRouterMap() {
routerMap.put(ActorOperations.UPDATE_TENANT_PREFERENCE.getValue(), tenantPrefManagementActor);
routerMap.put(ActorOperations.GET_TENANT_PREFERENCE.getValue(), tenantPrefManagementActor);
routerMap.put(ActorOperations.UPDATE_TC_STATUS_OF_USER.getValue(), tenantPrefManagementActor);
routerMap.put(ActorOperations.GET_GEO_LOCATION.getValue() ,geoLocationManagementActor);
routerMap.put(ActorOperations.CREATE_GEO_LOCATION.getValue() ,geoLocationManagementActor);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ private void login(Request actorMessage) throws Exception{
userAuthMap.put(JsonKey.USER_ID, resultMap.get(JsonKey.ID));
userAuthMap.put(JsonKey.CREATED_DATE, ProjectUtil.getFormattedDate());

String userAuth = ProjectUtil.createUserAuthToken((String) resultMap.get(JsonKey.ID),
String userAuth = ProjectUtil.createAuthToken((String) resultMap.get(JsonKey.ID),
(String) reqMap.get(JsonKey.SOURCE));
userAuthMap.put(JsonKey.ID, userAuth);
checkForDuplicateUserAuthToken(userAuthMap, resultMap, reqMap);
Expand Down Expand Up @@ -1538,7 +1538,7 @@ private void checkForDuplicateUserAuthToken(Map<String, Object> userAuthMap,
} else {
cassandraOperation.deleteRecord(userAuthDbInfo.getKeySpace(), userAuthDbInfo.getTableName(),
(String) (userAuthList.get(0)).get(JsonKey.ID));
userAuth = ProjectUtil.createUserAuthToken((String) resultMap.get(JsonKey.ID),
userAuth = ProjectUtil.createAuthToken((String) resultMap.get(JsonKey.ID),
(String) reqMap.get(JsonKey.SOURCE));
userAuthMap.put(JsonKey.ID, userAuth);
userAuthMap.put(JsonKey.CREATED_DATE, ProjectUtil.getFormattedDate());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private void saveAssessment(Request actorMessage) {
try{
assmntResponse.put(JsonKey.RESPONSE, JsonKey.SUCCESS);
for(Map<String, Object> assmtMap : assmtItemMapList){
String uniqueId = ProjectUtil.createUserAuthToken((String)req.get(JsonKey.REQUESTED_BY),"");
String uniqueId = ProjectUtil.createAuthToken((String)req.get(JsonKey.REQUESTED_BY),"");
assmtMap.put(JsonKey.ID, uniqueId);
if(assmtMap.containsKey(JsonKey.TIME_TAKEN)){
assmtMap.put(JsonKey.TIME_TAKEN, ((BigInteger)assmtMap.get(JsonKey.TIME_TAKEN)).intValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import akka.actor.UntypedAbstractActor;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -117,6 +118,7 @@ private void updateTenantPreference(Request actorMessage) {
List<Map<String, Object>> reqList = (List<Map<String, Object>>) actorMessage.getRequest().get(JsonKey.TENANT_PREFERENCE);

Response finalResponse = new Response();
List<Map<String , Object>> responseList = new ArrayList<>();
String requestedBy = (String) actorMessage.getRequest().get(JsonKey.REQUESTED_BY);
String orgId = (String) actorMessage.getRequest().get(JsonKey.ORG_ID);

Expand All @@ -141,26 +143,11 @@ private void updateTenantPreference(Request actorMessage) {
String id = (String) map.get(JsonKey.ID);

if(ProjectUtil.isStringNullOREmpty(id)){
String requestedRole =(String)map.get(JsonKey.ROLE);
if(ProjectUtil.isStringNullOREmpty(requestedRole)){
//throw exception either Id or role is mandatory .
throw new ProjectCommonException(ResponseCode.invalidRequestData.getErrorCode(),
ResponseCode.invalidRequestData.getErrorMessage(),
ResponseCode.CLIENT_ERROR.getResponseCode());
}

boolean flag = false;
for(Map<String , Object> m : list){
if(requestedRole.equals((String)m.get(JsonKey.ROLE)) && orgId.equals((String)m.get(JsonKey.ORG_ID))){
dbMap = m;
flag = true;
break;
}
}
if(!flag){
// means data not found
finalResponse.getResult().put(requestedRole , " This role does not exist");
}
Map<String , Object> responseMap = new HashMap<>();
responseMap.put(JsonKey.ID , id);
responseMap.put(JsonKey.STATUS , JsonKey.FAILURE);
responseList.add(responseMap);
}else{
boolean flag = false;
for(Map<String , Object> m : list){
Expand All @@ -172,7 +159,10 @@ private void updateTenantPreference(Request actorMessage) {
}
if(!flag){
// means data not found
finalResponse.getResult().put(id , " This id does not exist");
Map<String , Object> responseMap = new HashMap<>();
responseMap.put(JsonKey.ID , id);
responseMap.put(JsonKey.STATUS , "Invalid Id");
responseList.add(responseMap);
}
}

Expand All @@ -184,10 +174,14 @@ private void updateTenantPreference(Request actorMessage) {
dbMap.put(JsonKey.DATA , map.get(JsonKey.DATA));
}
cassandraOperation.updateRecord(tenantPreferenceDbInfo.getKeySpace(), tenantPreferenceDbInfo.getTableName(), dbMap);
finalResponse.put((String) dbMap.get(JsonKey.ID), JsonKey.SUCCESS);
Map<String , Object> responseMap = new HashMap<>();
responseMap.put(JsonKey.ID , id);
responseMap.put(JsonKey.STATUS , JsonKey.SUCCESS);
responseList.add(responseMap);
}

}
finalResponse.getResult().put(JsonKey.RESPONSE , responseList);
sender().tell(finalResponse , self());

}
Expand All @@ -202,6 +196,7 @@ private void createTenantPreference(Request actorMessage) {
List<Map<String, Object>> req = (List<Map<String, Object>>) actorMessage.getRequest().get(JsonKey.TENANT_PREFERENCE);

Response finalResponse = new Response();
List<Map<String , Object>> responseList = new ArrayList<>();
String requestedBy = (String) actorMessage.getRequest().get(JsonKey.REQUESTED_BY);
String orgId = (String) actorMessage.getRequest().get(JsonKey.ORG_ID);

Expand Down Expand Up @@ -240,7 +235,10 @@ private void createTenantPreference(Request actorMessage) {
boolean flag = true;
for(Map<String,Object> m : list){
if(role.equalsIgnoreCase((String) m.get(JsonKey.ROLE))){
finalResponse.getResult().put(role , "Tenant preference already exist for role "+role);
Map<String, Object> responseMap = new HashMap<>();
responseMap.put(JsonKey.ROLE , role);
responseMap.put(JsonKey.STATUS , "Tenant preference already exist for role ");
responseList.add(responseMap);
flag = false;
break;
}
Expand All @@ -255,9 +253,15 @@ private void createTenantPreference(Request actorMessage) {
dbMap.put(JsonKey.DATA, (String) map.get(JsonKey.DATA));
cassandraOperation.insertRecord(tenantPreferenceDbInfo.getKeySpace(),
tenantPreferenceDbInfo.getTableName(), dbMap);
Map<String, Object> responseMap = new HashMap<>();
responseMap.put(JsonKey.ID ,id);
responseMap.put(JsonKey.ROLE , role);
responseMap.put(JsonKey.STATUS , JsonKey.SUCCESS);
responseList.add(responseMap);
finalResponse.getResult().put(role, JsonKey.SUCCESS);
}
}
finalResponse.getResult().put(JsonKey.RESPONSE , responseList);
sender().tell(finalResponse , self());
}

Expand Down
1 change: 1 addition & 0 deletions actors/src/main/java/org/sunbird/learner/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ private static void initializeDBProperty() {
dbInfoMap.put(JsonKey.USER_SKILL_DB , getDbInfoObject(KEY_SPACE_NAME, "user_skills"));
dbInfoMap.put(JsonKey.SKILLS_LIST_DB , getDbInfoObject(KEY_SPACE_NAME, "skills"));
dbInfoMap.put(JsonKey.TENANT_PREFERENCE_DB , getDbInfoObject(KEY_SPACE_NAME, "tenant_preference"));
dbInfoMap.put(JsonKey.GEO_LOCATION_DB , getDbInfoObject(KEY_SPACE_NAME, "geo_location"));

}

Expand Down
12 changes: 11 additions & 1 deletion actors/src/main/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ LocaleMWConfig {
router = round-robin-pool
nr-of-instances = 5
}
/RequestRouterActor/geoLocationManagementActor
{
router = round-robin-pool
nr-of-instances = 5
}

}

Expand Down Expand Up @@ -306,6 +311,11 @@ RemoteMWConfig {
router = round-robin-pool
nr-of-instances = 5
}
/RequestRouterActor/geoLocationManagementActor
{
router = round-robin-pool
nr-of-instances = 5
}
}

}
Expand All @@ -332,7 +342,7 @@ ActorConfig {
maximum-payload-bytes = 30000000 bytes
enabled-transports = ["akka.remote.netty.tcp"]
netty.tcp {
//hostname = learner-service
hostname = learner-service
port = 8099
message-frame-size = 30000000b
send-buffer-size = 30000000b
Expand Down
20 changes: 12 additions & 8 deletions actors/src/main/resources/cassandra.cql
Original file line number Diff line number Diff line change
Expand Up @@ -600,14 +600,6 @@ CREATE TABLE IF NOT EXISTS sunbird.tenant_preference(id text,tenantName text,org
CREATE INDEX inx_tp_userId ON sunbird.tenant_preference(orgId);

ALTER TABLE sunbird.user ADD tcstatus text;
ALTER TABLE sunbird.user ADD tcupdatedat text;










Expand All @@ -620,3 +612,15 @@ CREATE TABLE sunbirdplugin.metrics (id text,userid text,announcementid text,acti
CREATE TABLE sunbirdplugin.announcementtype (id text,rootorgid text,name text,status text,createddate text, PRIMARY KEY (id));
CREATE TABLE sunbirdplugin.announcementauth (id text,userid text,rootorgid text,permissions map<text, text>,status text,createddate text, PRIMARY KEY (id));

// Geo Location - Oct 31,2017

ALTER TABLE sunbird.user DROP tcupdatedat ;
ALTER TABLE sunbird.user ADD tcupdateddate text;

CREATE TABLE IF NOT EXISTS sunbird.geo_location(id text,locationName text,rootOrgId text,type text, createdDate text,createdBy text,updatedDate text,updatedBy text,topicName text,topicId text, PRIMARY KEY (id));
CREATE INDEX inx_gl_rootOrgId ON sunbird.geo_location(rootOrgId);
ALTER TABLE sunbird.geo_location DROP topicId ;
ALTER TABLE sunbird.geo_location DROP topicName ;
ALTER TABLE sunbird.geo_location ADD topic text;
ALTER TABLE sunbird.geo_location DROP locationName ;
ALTER TABLE sunbird.geo_location ADD location text;
Original file line number Diff line number Diff line change
Expand Up @@ -190,27 +190,6 @@ public void testUpdateTanentPreference(){
Response res= probe.expectMsgClass(duration("100 second"),Response.class);
}

@Test
public void testUpdateTanentPreferenceWithoutRole(){

TestKit probe = new TestKit(system);
ActorRef subject = system.actorOf(props);
Request actorMessage = new Request();
List<Map<String , Object>> reqList = new ArrayList<>();

Map<String , Object> map = new HashMap<>();
//map.put(JsonKey.ROLE , "admin");
reqList.add(map);

actorMessage.getRequest().put(JsonKey.TENANT_PREFERENCE , reqList);
actorMessage.getRequest().put(JsonKey.ORG_ID , orgId);
actorMessage.getRequest().put(JsonKey.REQUESTED_BY , USER_ID);
actorMessage.setOperation(ActorOperations.UPDATE_TENANT_PREFERENCE.getValue());

subject.tell(actorMessage, probe.getRef());
ProjectCommonException res= probe.expectMsgClass(duration("100 second"),ProjectCommonException.class);
}


@Test
public void testUpdateTanentPreferenceWithInvalidRequestData(){
Expand Down

0 comments on commit 4d2518c

Please sign in to comment.