2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the “License”);
10 * you may not use this software except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the “License”);
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
36 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
38 package org.onap.portalsdk.rnotebookintegration.controller;
40 import java.util.HashMap;
42 import javax.servlet.http.HttpServletRequest;
43 import javax.servlet.http.HttpServletResponse;
45 import org.hibernate.validator.internal.util.privilegedactions.GetMethodFromPropertyName;
46 import org.onap.portalsdk.core.controller.RestrictedBaseController;
47 import org.onap.portalsdk.core.controller.RestrictedRESTfulBaseController;
48 import org.onap.portalsdk.core.domain.User;
49 import org.onap.portalsdk.core.restful.domain.EcompUser;
50 import org.onap.portalsdk.core.util.SystemProperties;
51 import org.onap.portalsdk.core.web.support.JsonMessage;
52 import org.onap.portalsdk.core.web.support.UserUtils;
53 import org.onap.portalsdk.rnotebookintegration.exception.RNotebookIntegrationException;
54 import org.onap.portalsdk.rnotebookintegration.service.RNoteBookIntegrationService;
55 import org.springframework.beans.factory.annotation.Autowired;
56 import org.springframework.http.HttpStatus;
57 import org.springframework.http.ResponseEntity;
58 import org.springframework.stereotype.Controller;
59 import org.springframework.web.bind.annotation.RequestBody;
60 import org.springframework.web.bind.annotation.RequestMapping;
61 import org.springframework.web.bind.annotation.RequestMethod;
62 import org.springframework.web.bind.annotation.ResponseBody;
64 import com.fasterxml.jackson.databind.DeserializationFeature;
65 import com.fasterxml.jackson.databind.JsonNode;
66 import com.fasterxml.jackson.databind.ObjectMapper;
69 @RequestMapping("/rNotebook/")
71 public class RNoteBookController extends RestrictedRESTfulBaseController {
74 private RNoteBookIntegrationService rNoteBookIntegrationService;
78 public RNoteBookIntegrationService getrNoteBookIntegrationService() {
79 return rNoteBookIntegrationService;
84 public void setrNoteBookIntegrationService(
85 RNoteBookIntegrationService rNoteBookIntegrationService) {
86 this.rNoteBookIntegrationService = rNoteBookIntegrationService;
91 @RequestMapping(value = { "authCr" }, method = RequestMethod.GET, produces = "application/json")
92 public @ResponseBody ResponseEntity<String> getRNotebookCredentials (String token) throws Exception {
93 //ObjectMapper mapper = new ObjectMapper();
94 //mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
95 //JsonNode root = mapper.readTree(request.getReader());
96 //String token = root.get("authenticationToken").textValue();
98 String returnJSON = "";
100 returnJSON = this.getrNoteBookIntegrationService().getRNotebookCredentials(token);
101 } catch(RNotebookIntegrationException re){
102 if (re.getErrorCode().equals(RNotebookIntegrationException.ERROR_CODE_TOKEN_EXPIRED)){
103 return new ResponseEntity<String>(JsonMessage.buildJsonResponse(false, re.getMessage()), HttpStatus.BAD_REQUEST);
106 return new ResponseEntity<String>(JsonMessage.buildJsonResponse(false, re.getMessage()), HttpStatus.BAD_REQUEST);
110 return new ResponseEntity<String>(JsonMessage.buildJsonResponse(false, e.getMessage()), HttpStatus.BAD_REQUEST);
113 return new ResponseEntity<String>(returnJSON, HttpStatus.OK);