-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue #SC-1193 read data from registry if es fails #45
base: release-2.2.0-prime
Are you sure you want to change the base?
Changes from all commits
619f664
eb6a1c1
b6d548d
8d997e0
8545473
e7eb734
e3f64f2
7d17c4d
f5a61f5
a6dd6d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
[submodule "sunbird-user-registry"] | ||
path = sunbird-user-registry | ||
url = https://github.com/project-sunbird/sunbird-user-registry | ||
branch = release-2.2.0-prime | ||
url = https://github.com/project-sunbird/sunbird-user-registry.git | ||
branch = release-2.2.0-prime |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.sunbird; | ||
|
||
public enum ServiceImplType { | ||
|
||
USER("userService"); | ||
|
||
private String serviceType; | ||
|
||
ServiceImplType(String serviceType) { | ||
this.serviceType = serviceType; | ||
} | ||
|
||
public String getServiceType() { | ||
return this.serviceType; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.sunbird.factory; | ||
|
||
import org.sunbird.ServiceImplType; | ||
import org.sunbird.user.service.UserServiceImpl; | ||
|
||
/** | ||
* This class is created for keeping all service's object creation. | ||
*/ | ||
public class ServiceFactory { | ||
|
||
public static Object getService(String serviceName) { | ||
Object serviceObj = null; | ||
if(serviceName.equals(ServiceImplType.USER.getServiceType())) { | ||
serviceObj = UserServiceImpl.getInstance(); | ||
} | ||
return serviceObj; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,18 @@ | |
|
||
import org.sunbird.BaseActor; | ||
import org.sunbird.DaoImplType; | ||
import org.sunbird.ServiceImplType; | ||
import org.sunbird.actor.core.ActorConfig; | ||
import org.sunbird.actorOperation.UserActorOperations; | ||
import org.sunbird.exception.BaseException; | ||
import org.sunbird.factory.ServiceFactory; | ||
import org.sunbird.request.Request; | ||
import org.sunbird.response.Response; | ||
import org.sunbird.user.dao.IUserDao; | ||
import org.sunbird.user.dao.UserDaoFactory; | ||
import org.sunbird.user.service.IUserService; | ||
import org.sunbird.util.LoggerEnum; | ||
import org.sunbird.util.ProjectLogger; | ||
import org.sunbird.util.jsonkey.JsonKey; | ||
|
||
/** | ||
|
@@ -23,29 +28,43 @@ | |
) | ||
public class UserReadActor extends BaseActor { | ||
|
||
IUserDao userESDao = (IUserDao) UserDaoFactory.getDaoImpl(DaoImplType.ES.getType()); | ||
private IUserService userService = null; | ||
IUserDao userESDao = (IUserDao) UserDaoFactory.getDaoImpl(DaoImplType.ES.getType()); | ||
|
||
@Override | ||
public void onReceive(Request request) throws Throwable { | ||
if (UserActorOperations.READ_USER_BY_ID | ||
.getOperation() | ||
.equalsIgnoreCase(request.getOperation())) { | ||
readUserById(request); | ||
} else { | ||
onReceiveUnsupportedMessage(this.getClass().getName()); | ||
} | ||
} | ||
|
||
@Override | ||
public void onReceive(Request request) throws Throwable { | ||
if (UserActorOperations.READ_USER_BY_ID | ||
.getOperation() | ||
.equalsIgnoreCase(request.getOperation())) { | ||
readUserById(request); | ||
} else { | ||
onReceiveUnsupportedMessage(this.getClass().getName()); | ||
} | ||
} | ||
|
||
/** | ||
* this method is used to read user from elastic search. | ||
* | ||
* @param request | ||
* @throws BaseException | ||
*/ | ||
public void readUserById(Request request) throws BaseException { | ||
startTrace("readUserById"); | ||
Response response = userESDao.getUserById((String) request.getRequest().get(JsonKey.USER_ID)); | ||
endTrace("readUserById"); | ||
sender().tell(response, self()); | ||
} | ||
/** | ||
* this method is used to read user from elastic search. | ||
* | ||
* @param request | ||
* @throws BaseException | ||
*/ | ||
public void readUserById(Request request) throws BaseException { | ||
startTrace("readUserById"); | ||
Response response = null; | ||
try { | ||
response = userESDao.getUserById((String) request.getRequest().get(JsonKey.USER_ID)); | ||
} catch (Exception e) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add logger in catch block to print sacktrace, to know what went wrong. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
ProjectLogger.log( | ||
"UserReadActor:readUserById: " | ||
+ "Exception in getting the record from ES : " | ||
+ e.getMessage(), | ||
LoggerEnum.ERROR.name()); | ||
ProjectLogger.log("Exception occurred while reading user ES.", e); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Logger parretn need to be same for all places, we are following "className:methodName message,LoggerEum.Value.name" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove ProjectLogger.log("Exception occurred while reading user ES.", e); because we already have logger above. |
||
userService = (IUserService) ServiceFactory.getService(ServiceImplType.USER.getServiceType()); | ||
response = userService.readUser((String) request.getRequest().get(JsonKey.USER_ID)); | ||
} | ||
endTrace("readUserById"); | ||
sender().tell(response, self()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,54 @@ | ||
package org.sunbird.user.dao; | ||
|
||
import java.util.Map; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import org.sunbird.response.Response; | ||
|
||
/** This class contains method to interact with open saber */ | ||
import java.util.Map; | ||
|
||
/** | ||
* This class contains method to interact with open saber | ||
*/ | ||
public interface IOSDao { | ||
|
||
/** | ||
* This method will add entity to open saber | ||
* | ||
* @param entity | ||
* @return Response | ||
* @throws Exception | ||
*/ | ||
Response addEntity(Map<String, Object> entity) throws Exception; | ||
|
||
/** | ||
* This method will read data from open saber and return response in JsonLD | ||
* | ||
* @param entity | ||
* @return Response | ||
* @throws Exception | ||
*/ | ||
Response readJSONLDEntity(Map<String, Object> entity) throws Exception; | ||
|
||
/** | ||
* This method will read data from open saber | ||
* | ||
* @param entity | ||
* @return response | ||
* @throws Exception | ||
*/ | ||
Response readEntity(Map<String, Object> entity) throws Exception; | ||
|
||
/** | ||
* This method will search entity from open saber | ||
* | ||
* @param entity | ||
* @return response | ||
* @throws Exception | ||
*/ | ||
Response searchEntity(Map<String, Object> entity) throws Exception; | ||
|
||
/** | ||
* This method will update the existing entity in open saber. | ||
* | ||
* @param entity | ||
* @param entityId | ||
* @return Response | ||
* @throws Exception | ||
*/ | ||
Response updateEntity(Map<String, Object> entity, String entityId) throws Exception; | ||
/** | ||
* This method will add entity to open saber | ||
* @param entity | ||
* @return Response | ||
* @throws Exception | ||
*/ | ||
Response addEntity(Map<String,Object> entity) throws Exception; | ||
|
||
/** | ||
* This method will read data from open saber and return response in JsonLD | ||
* @param entity | ||
* @return Response | ||
* @throws Exception | ||
*/ | ||
Response readJSONLDEntity(Map<String,Object> entity) throws Exception; | ||
|
||
/** | ||
* This method will read data from open saber | ||
* @param entity | ||
* @return response | ||
* @throws Exception | ||
*/ | ||
Response readEntity(JsonNode entity) throws Exception; | ||
|
||
/** | ||
* This method will search entity from open saber | ||
* @param entity | ||
* @return response | ||
* @throws Exception | ||
*/ | ||
Response searchEntity(Map<String,Object> entity) throws Exception; | ||
|
||
/** | ||
* This method will update the existing entity in open saber. | ||
* @param entity | ||
* @param entityId | ||
* @return Response | ||
* @throws Exception | ||
*/ | ||
Response updateEntity(Map<String,Object> entity, String entityId) throws Exception; | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DO reverse check to avoid NPE.
serviceName.equals(ServiceImplType.USER.getServiceType()) to ServiceImplType.USER.getServiceType().equals(serviceName)