Skip to content

Commit

Permalink
Merge pull request #130 from project-sunbird/SB-6890
Browse files Browse the repository at this point in the history
Sb 6890
  • Loading branch information
bvinayakumar authored Sep 7, 2018
2 parents c637075 + c9f5af5 commit ab05c98
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.sunbird.actorutil.systemsettings;

import akka.actor.ActorRef;
import org.sunbird.models.systemsetting.SystemSetting;

/**
* This interface defines methods supported by System Setting service.
*
* @author Amit Kumar
*/
public interface SystemSettingClient {

/**
* @desc Get system setting information for given field (setting) name.
* @param actorRef Actor reference.
* @param field System setting field name.
* @return System setting details
*/
SystemSetting getSystemSettingByField(ActorRef actorRef, String field);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package org.sunbird.actorutil.systemsettings.impl;

import akka.actor.ActorRef;
import java.util.HashMap;
import java.util.Map;
import org.sunbird.actorutil.InterServiceCommunication;
import org.sunbird.actorutil.InterServiceCommunicationFactory;
import org.sunbird.actorutil.systemsettings.SystemSettingClient;
import org.sunbird.common.exception.ProjectCommonException;
import org.sunbird.common.models.response.Response;
import org.sunbird.common.models.util.ActorOperations;
import org.sunbird.common.models.util.JsonKey;
import org.sunbird.common.models.util.LoggerEnum;
import org.sunbird.common.models.util.ProjectLogger;
import org.sunbird.common.request.Request;
import org.sunbird.common.responsecode.ResponseCode;
import org.sunbird.models.systemsetting.SystemSetting;

public class SystemSettingClientImpl implements SystemSettingClient {

private static InterServiceCommunication interServiceCommunication =
InterServiceCommunicationFactory.getInstance();
private static SystemSettingClientImpl systemSettingClient = null;

public static SystemSettingClientImpl getInstance() {
if (null == systemSettingClient) {
systemSettingClient = new SystemSettingClientImpl();
}
return systemSettingClient;
}

@Override
public SystemSetting getSystemSettingByField(ActorRef actorRef, String field) {
return getSystemSetting(actorRef, JsonKey.FIELD, field);
}

private SystemSetting getSystemSetting(ActorRef actorRef, String param, Object value) {
Request request = new Request();
Map<String, Object> map = new HashMap<>();
map.put(param, value);
request.setRequest(map);
request.setOperation(ActorOperations.GET_SYSTEM_SETTING.getValue());
ProjectLogger.log("SystemSettingClientImpl: getSystemSetting called", LoggerEnum.INFO);
Object obj = interServiceCommunication.getResponse(actorRef, request);
if (obj instanceof Response) {
Response responseObj = (Response) obj;
return (SystemSetting) responseObj.getResult().get(JsonKey.RESPONSE);
} else if (obj instanceof ProjectCommonException) {
throw (ProjectCommonException) obj;
} else {
throw new ProjectCommonException(
ResponseCode.SERVER_ERROR.getErrorCode(),
ResponseCode.SERVER_ERROR.getErrorMessage(),
ResponseCode.SERVER_ERROR.getResponseCode());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,11 @@ public final class JsonKey {
public static final String ORIGINAL_EXTERNAL_ID = "originalExternalId";
public static final String ORIGINAL_ID_TYPE = "originalIdType";
public static final String ORIGINAL_PROVIDER = "originalProvider";
public static final String SUNBIRD_CASSANDRA_CONSISTENCY_LEVEL = "sunbird_cassandra_consistency_level";
public static final String SUNBIRD_CASSANDRA_CONSISTENCY_LEVEL =
"sunbird_cassandra_consistency_level";
public static final String VERSION_2 = "v2";
public static final String CUSTODIAN_ORG_CHANNEL = "custodianOrgChannel";
public static final String CUSTODIAN_ORG_ID = "custodianOrgId";

private JsonKey() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.sunbird.common.responsecode.ResponseCode;

/** @author Amit Kumar */
public class UserRequestValidator {
public class UserRequestValidator extends BaseRequestValidator {

private static final int ERROR_CODE = ResponseCode.CLIENT_ERROR.getResponseCode();

Expand Down Expand Up @@ -51,6 +51,20 @@ public static void validateCreateUser(Request userRequest) {
validateWebPages(userRequest);
}

/**
* This method will validate create user data.
*
* @param userRequest Request
*/
public static void validateCreateUserV2(Request userRequest) {
BaseRequestValidator requestValidator = new BaseRequestValidator();
requestValidator.validateParam(
(String) userRequest.getRequest().get(JsonKey.CHANNEL),
ResponseCode.mandatoryParamsMissing,
JsonKey.CHANNEL);
validateCreateUser(userRequest);
}

public static void fieldsNotAllowed(List<String> fields, Request userRequest) {
for (String field : fields) {
if (((userRequest.getRequest().get(field) instanceof String)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,8 @@ public enum ResponseCode {
ResponseMessage.Message.EMAIL_RECIPIENTS_EXCEEDS_MAX_LIMIT),
emailNotSentRecipientsZero(
ResponseMessage.Key.NO_EMAIL_RECIPIENTS, ResponseMessage.Message.NO_EMAIL_RECIPIENTS),
parameterMismatch(
ResponseMessage.Key.PARAMETER_MISMATCH, ResponseMessage.Message.PARAMETER_MISMATCH),
OK(200),
CLIENT_ERROR(400),
SERVER_ERROR(500),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ interface Message {
"Email notification is not sent as the number of recipients exceeded configured limit ({0}).";
String NO_EMAIL_RECIPIENTS =
"Email notification is not sent as the number of recipients is zero.";
String PARAMETER_MISMATCH = "Mismatch of given parameters: {0}.";
}

interface Key {
Expand Down Expand Up @@ -656,5 +657,6 @@ interface Key {
String INVALID_DUPLICATE_VALUE = "INVALID_DUPLICATE_VALUE";
String EMAIL_RECIPIENTS_EXCEEDS_MAX_LIMIT = "EMAIL_RECIPIENTS_EXCEEDS_MAX_LIMIT";
String NO_EMAIL_RECIPIENTS = "NO_EMAIL_RECIPIENTS";
String PARAMETER_MISMATCH = "PARAMETER_MISMATCH";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package org.sunbird.models.systemsetting;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import java.io.Serializable;

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(Include.NON_NULL)
public class SystemSetting implements Serializable {
private static final long serialVersionUID = 1L;
private String id;
private String field;
private String value;

public SystemSetting() {}

public SystemSetting(String id, String field, String value) {
this.id = id;
this.field = field;
this.value = value;
}

public String getId() {
return this.id;
}

public String getField() {
return this.field;
}

public String getValue() {
return this.value;
}

public void setId(String id) {
this.id = id;
}

public void setField(String field) {
this.field = field;
}

public void setValue(String value) {
this.value = value;
}
}
9 changes: 9 additions & 0 deletions models/src/main/java/org/sunbird/models/user/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,17 @@ public class User implements Serializable {
private String channel;
private String loginId;
private String registryId;
private String organisationId;
private List<Map<String, String>> externalIds;

public String getOrganisationId() {
return organisationId;
}

public void setOrganisationId(String organisationId) {
this.organisationId = organisationId;
}

public String getRegistryId() {
return registryId;
}
Expand Down

0 comments on commit ab05c98

Please sign in to comment.