package sg.ncl.service.adapter;

import org.springframework.http.*;
import org.springframework.web.client.RestTemplate;


/**
 * This is to invoke python scripts on the BOSS
 * Created by Te Ye on 15-Jun-16.
 */
public class AdapterDeterlab {

    private RestTemplate restTemplate = new RestTemplate();
    private ConnectionProperties properties = new ConnectionProperties();

    public String addUsers(String jsonString) {
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        HttpEntity<String> request = new HttpEntity<String>(jsonString, headers);

        ResponseEntity responseEntity = restTemplate.exchange(properties.getADD_USERS_URI(), HttpMethod.POST, request, String.class);

        // Will return the following JSON:
        // msg: no user created, uid: xxx
        // msg: user is created, uid: xxx
        // msg: user not found, uid: xxx
//        System.out.println(responseEntity.getBody().toString());
        return responseEntity.getBody().toString();
    }
}

@@ -26,16 +26,44 @@
 apter;%0A%0A
+import org.json.JSONObject;%0A
 import o
@@ -141,16 +141,223 @@
 mplate;%0A
+import sg.ncl.service.adapter.data.jpa.DeterlabUserRepository;%0Aimport sg.ncl.service.adapter.domain.DeterlabUser;%0Aimport sg.ncl.service.adapter.dtos.entities.DeterlabUserEntity;%0A%0Aimport javax.inject.Inject;%0A
 %0A%0A/**%0A *
@@ -472,16 +472,75 @@
 rlab %7B%0A%0A
+    private DeterlabUserRepository deterlabUserRepository;%0A
     priv
@@ -1333,11 +1333,336 @@
 );%0A    %7D
+%0A%0A    public void saveDeterUserIdMapping(String deterUserId, String nclUserId) %7B%0A        DeterlabUserEntity deterlabUserEntity = new DeterlabUserEntity();%0A        deterlabUserEntity.setNclUserId(nclUserId);%0A        deterlabUserEntity.setDeterUserId(deterUserId);%0A        deterlabUserRepository.save(deterlabUserEntity);%0A    %7D
 %0A%7D%0A

add the mapping function from ncl user id to deter user id