-
Notifications
You must be signed in to change notification settings - Fork 159
Expand file tree
/
Copy pathSyncController.java
More file actions
64 lines (60 loc) · 2.19 KB
/
SyncController.java
File metadata and controls
64 lines (60 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/** */
package controllers.sync;
import org.apache.pekko.actor.ActorRef;
import com.fasterxml.jackson.databind.JsonNode;
import controllers.BaseController;
import java.util.HashMap;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import javax.inject.Inject;
import javax.inject.Named;
import org.sunbird.exception.ProjectCommonException;
import org.sunbird.keys.JsonKey;
import org.sunbird.operations.ActorOperations;
import org.sunbird.request.Request;
import org.sunbird.validator.RequestValidator;
import play.mvc.Http;
import play.mvc.Result;
import util.Attrs;
import util.Common;
/**
* This controller will handle all the request related user and organization search.
*
* @author Manzarul
*/
public class SyncController extends BaseController {
@Inject
@Named("es_sync_actor")
private ActorRef esSyncActor;
/**
* This method will do data Sync form Cassandra db to Elasticsearch.
*
* @return CompletionStage<Result>
*/
public CompletionStage<Result> sync(Http.Request httpRequest) {
Request reqObj = new Request();
try {
JsonNode requestData = httpRequest.body().asJson();
reqObj = (Request) mapper.RequestMapper.mapRequest(requestData, Request.class);
RequestValidator.validateSyncRequest(reqObj);
reqObj.setOperation(ActorOperations.SYNC.getValue());
reqObj.setRequestId(Common.getFromRequest(httpRequest, Attrs.X_REQUEST_ID));
reqObj
.getRequest()
.put(JsonKey.CREATED_BY, Common.getFromRequest(httpRequest, Attrs.USER_ID));
reqObj.setEnv(getEnvironment());
HashMap<String, Object> map = new HashMap<>();
map.put(JsonKey.DATA, reqObj.getRequest());
reqObj.setRequest(map);
setContextAndPrintEntryLog(httpRequest, reqObj);
return actorResponseHandler(esSyncActor, reqObj, timeout, null, httpRequest);
} catch (Exception e) {
ProjectCommonException exception =
new ProjectCommonException(
(ProjectCommonException) e,
ActorOperations.getOperationCodeByActorOperation(reqObj.getOperation()));
return CompletableFuture.completedFuture(
createCommonExceptionResponse(exception, httpRequest));
}
}
}