00d97268ab28002460d63cddb3923c9bf39d9c8f
[portal/sdk.git] /
1 /*-
2  * ================================================================================
3  * eCOMP Portal SDK
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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  * ================================================================================
19  */
20 package org.openecomp.portalsdk.rnotebookintegration.controller;
21
22 import java.util.HashMap;
23
24 import javax.servlet.http.HttpServletRequest;
25 import javax.servlet.http.HttpServletResponse;
26
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;
45
46 import com.fasterxml.jackson.databind.DeserializationFeature;
47 import com.fasterxml.jackson.databind.JsonNode;
48 import com.fasterxml.jackson.databind.ObjectMapper;
49
50 @Controller
51 @RequestMapping("/rNotebook/")
52
53 public class RNoteBookController extends RestrictedRESTfulBaseController {
54         
55         @Autowired
56         private RNoteBookIntegrationService rNoteBookIntegrationService;
57         
58         
59
60         public RNoteBookIntegrationService getrNoteBookIntegrationService() {
61                 return rNoteBookIntegrationService;
62         }
63
64
65
66         public void setrNoteBookIntegrationService(
67                         RNoteBookIntegrationService rNoteBookIntegrationService) {
68                 this.rNoteBookIntegrationService = rNoteBookIntegrationService;
69         }
70
71
72
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();
79                 
80                 String returnJSON = "";
81                 try{
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);
86                         }
87                         else {
88                                 return new ResponseEntity<String>(JsonMessage.buildJsonResponse(false, re.getMessage()), HttpStatus.BAD_REQUEST);
89                         }
90                 } 
91                 catch (Exception e){
92                         return new ResponseEntity<String>(JsonMessage.buildJsonResponse(false, e.getMessage()), HttpStatus.BAD_REQUEST);
93                 }
94                 
95                 return new ResponseEntity<String>(returnJSON, HttpStatus.OK);
96                 
97         }
98         
99         
100 }