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;
24 import javax.servlet.http.HttpServletRequest;
25 import javax.servlet.http.HttpServletResponse;
27 import org.hibernate.validator.internal.util.privilegedactions.GetMethodFromPropertyName;
28 import org.openecomp.portalsdk.core.controller.RestrictedBaseController;
29 import org.openecomp.portalsdk.core.controller.RestrictedRESTfulBaseController;
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.JsonMessage;
34 import org.openecomp.portalsdk.core.web.support.UserUtils;
35 import org.openecomp.portalsdk.rnotebookintegration.exception.RNotebookIntegrationException;
36 import org.openecomp.portalsdk.rnotebookintegration.service.RNoteBookIntegrationService;
37 import org.springframework.beans.factory.annotation.Autowired;
38 import org.springframework.http.HttpStatus;
39 import org.springframework.http.ResponseEntity;
40 import org.springframework.stereotype.Controller;
41 import org.springframework.web.bind.annotation.RequestBody;
42 import org.springframework.web.bind.annotation.RequestMapping;
43 import org.springframework.web.bind.annotation.RequestMethod;
44 import org.springframework.web.bind.annotation.ResponseBody;
46 import com.fasterxml.jackson.databind.DeserializationFeature;
47 import com.fasterxml.jackson.databind.JsonNode;
48 import com.fasterxml.jackson.databind.ObjectMapper;
51 @RequestMapping("/rNotebook/")
53 public class RNoteBookController extends RestrictedRESTfulBaseController {
56 private RNoteBookIntegrationService rNoteBookIntegrationService;
60 public RNoteBookIntegrationService getrNoteBookIntegrationService() {
61 return rNoteBookIntegrationService;
66 public void setrNoteBookIntegrationService(
67 RNoteBookIntegrationService rNoteBookIntegrationService) {
68 this.rNoteBookIntegrationService = rNoteBookIntegrationService;
73 @RequestMapping(value = { "authCr" }, method = RequestMethod.GET, produces = "application/json")
74 public @ResponseBody ResponseEntity<String> getRNotebookCredentials (String token) throws Exception {
75 //ObjectMapper mapper = new ObjectMapper();
76 //mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
77 //JsonNode root = mapper.readTree(request.getReader());
78 //String token = root.get("authenticationToken").textValue();
80 String returnJSON = "";
82 returnJSON = this.getrNoteBookIntegrationService().getRNotebookCredentials(token);
83 } catch(RNotebookIntegrationException re){
84 if (re.getErrorCode().equals(RNotebookIntegrationException.ERROR_CODE_TOKEN_EXPIRED)){
85 return new ResponseEntity<String>(JsonMessage.buildJsonResponse(false, re.getMessage()), HttpStatus.BAD_REQUEST);
88 return new ResponseEntity<String>(JsonMessage.buildJsonResponse(false, re.getMessage()), HttpStatus.BAD_REQUEST);
92 return new ResponseEntity<String>(JsonMessage.buildJsonResponse(false, e.getMessage()), HttpStatus.BAD_REQUEST);
95 return new ResponseEntity<String>(returnJSON, HttpStatus.OK);