|
| 1 | +package org.sunbird.actorutil.systemsettings.impl; |
| 2 | + |
| 3 | +import akka.actor.ActorRef; |
| 4 | +import java.util.HashMap; |
| 5 | +import java.util.Map; |
| 6 | +import org.sunbird.actorutil.InterServiceCommunication; |
| 7 | +import org.sunbird.actorutil.InterServiceCommunicationFactory; |
| 8 | +import org.sunbird.actorutil.systemsettings.SystemSettingClient; |
| 9 | +import org.sunbird.common.exception.ProjectCommonException; |
| 10 | +import org.sunbird.common.models.response.Response; |
| 11 | +import org.sunbird.common.models.util.ActorOperations; |
| 12 | +import org.sunbird.common.models.util.JsonKey; |
| 13 | +import org.sunbird.common.models.util.LoggerEnum; |
| 14 | +import org.sunbird.common.models.util.ProjectLogger; |
| 15 | +import org.sunbird.common.request.Request; |
| 16 | +import org.sunbird.common.responsecode.ResponseCode; |
| 17 | +import org.sunbird.models.systemsetting.SystemSetting; |
| 18 | + |
| 19 | +public class SystemSettingClientImpl implements SystemSettingClient { |
| 20 | + |
| 21 | + private static InterServiceCommunication interServiceCommunication = |
| 22 | + InterServiceCommunicationFactory.getInstance(); |
| 23 | + private static SystemSettingClientImpl systemSettingClient = null; |
| 24 | + |
| 25 | + public static SystemSettingClientImpl getInstance() { |
| 26 | + if (null == systemSettingClient) { |
| 27 | + systemSettingClient = new SystemSettingClientImpl(); |
| 28 | + } |
| 29 | + return systemSettingClient; |
| 30 | + } |
| 31 | + |
| 32 | + @Override |
| 33 | + public SystemSetting getSystemSettingByField(ActorRef actorRef, String field) { |
| 34 | + return getSystemSetting(actorRef, JsonKey.FIELD, field); |
| 35 | + } |
| 36 | + |
| 37 | + private SystemSetting getSystemSetting(ActorRef actorRef, String param, Object value) { |
| 38 | + Request request = new Request(); |
| 39 | + Map<String, Object> map = new HashMap<>(); |
| 40 | + map.put(param, value); |
| 41 | + request.setRequest(map); |
| 42 | + request.setOperation(ActorOperations.GET_SYSTEM_SETTING.getValue()); |
| 43 | + ProjectLogger.log("SystemSettingClientImpl: getSystemSetting called", LoggerEnum.INFO); |
| 44 | + Object obj = interServiceCommunication.getResponse(actorRef, request); |
| 45 | + if (obj instanceof Response) { |
| 46 | + Response responseObj = (Response) obj; |
| 47 | + return (SystemSetting) responseObj.getResult().get(JsonKey.RESPONSE); |
| 48 | + } else if (obj instanceof ProjectCommonException) { |
| 49 | + throw (ProjectCommonException) obj; |
| 50 | + } else { |
| 51 | + throw new ProjectCommonException( |
| 52 | + ResponseCode.SERVER_ERROR.getErrorCode(), |
| 53 | + ResponseCode.SERVER_ERROR.getErrorMessage(), |
| 54 | + ResponseCode.SERVER_ERROR.getResponseCode()); |
| 55 | + } |
| 56 | + } |
| 57 | +} |
0 commit comments