2 * ================================================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ================================================================================
20 package org.openecomp.portalsdk.rnotebookintegration.controller;
22 import java.util.HashMap;
23 import java.util.Iterator;
25 import javax.servlet.http.HttpServletRequest;
26 import javax.servlet.http.HttpServletResponse;
28 import org.json.JSONObject;
29 import org.openecomp.portalsdk.core.controller.RestrictedBaseController;
30 import org.openecomp.portalsdk.core.domain.User;
31 import org.openecomp.portalsdk.core.restful.domain.EcompUser;
32 import org.openecomp.portalsdk.core.util.SystemProperties;
33 import org.openecomp.portalsdk.core.web.support.UserUtils;
34 import org.openecomp.portalsdk.rnotebookintegration.exception.RNotebookIntegrationException;
35 import org.openecomp.portalsdk.rnotebookintegration.service.RNoteBookIntegrationService;
36 import org.springframework.beans.factory.annotation.Autowired;
37 import org.springframework.http.HttpStatus;
38 import org.springframework.http.ResponseEntity;
39 import org.springframework.stereotype.Controller;
40 import org.springframework.web.bind.annotation.RequestBody;
41 import org.springframework.web.bind.annotation.RequestMapping;
42 import org.springframework.web.bind.annotation.RequestMethod;
43 import org.springframework.web.bind.annotation.ResponseBody;
46 @RequestMapping("/rNotebookFE/")
47 public class RNoteBookFEController extends RestrictedBaseController {
49 private RNoteBookIntegrationService rNoteBookIntegrationService;
53 public RNoteBookIntegrationService getrNoteBookIntegrationService() {
54 return rNoteBookIntegrationService;
59 public void setrNoteBookIntegrationService(
60 RNoteBookIntegrationService rNoteBookIntegrationService) {
61 this.rNoteBookIntegrationService = rNoteBookIntegrationService;
64 @RequestMapping(value = { "authCr" }, method = RequestMethod.POST, produces = "application/json")
65 public @ResponseBody ResponseEntity<String> saveRNotebookCredentials (@RequestBody String notebookId, HttpServletRequest request,
66 HttpServletResponse response) throws Exception {
67 //ObjectMapper mapper = new ObjectMapper();
68 //mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
69 //JsonNode root = mapper.readTree(request.getReader());
70 //String token = root.get("authenticationToken").textValue();
71 System.out.println("Notebook id "+notebookId);
72 System.out.println("Query parameters "+request.getParameter("qparams"));
76 User user = UserUtils.getUserSession(request);
77 user = (User) this.getDataAccessService().getDomainObject(User.class, user.getId(), null);
79 EcompUser ecUser =UserUtils.convertToEcompUser(user);
81 HashMap<String, String> map = new HashMap<String, String>();
82 JSONObject jObject = new JSONObject(request.getParameter("qparams"));
83 Iterator<?> keys = jObject.keys();
85 while( keys.hasNext() ){
86 String key = (String)keys.next();
87 String value = jObject.getString(key);
92 System.out.println("json : "+jObject);
93 System.out.println("map : "+map);
95 // String token = this.getrNoteBookIntegrationService().saveRNotebookCredentials(notebookId, ecUser, new HashMap<String, String>());
96 String token = this.getrNoteBookIntegrationService().saveRNotebookCredentials(notebookId, ecUser, map);
98 String guard = SystemProperties.getProperty("guard_notebook_url");
100 retUrl = guard + "id=" + token;
103 } catch (RNotebookIntegrationException re){
104 return new ResponseEntity<String>(re.getMessage(), HttpStatus.BAD_REQUEST);
105 } catch (Exception e){
106 return new ResponseEntity<String>(e.getMessage(), HttpStatus.BAD_REQUEST);
109 return new ResponseEntity<String>(retUrl, HttpStatus.OK);