9a1784503117cff3b0723011eaeaff8db48ff283
[portal/sdk.git] /
1 /*
2  * ============LICENSE_START==========================================
3  * ONAP Portal SDK
4  * ===================================================================
5  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
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
12  *
13  *             http://www.apache.org/licenses/LICENSE-2.0
14  *
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.
20  *
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
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
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.
33  *
34  * ============LICENSE_END============================================
35  *
36  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
37  */
38 package org.onap.portalsdk.rnotebookintegration.controller;
39
40 import java.util.HashMap;
41
42 import javax.servlet.http.HttpServletRequest;
43 import javax.servlet.http.HttpServletResponse;
44
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;
63
64 import com.fasterxml.jackson.databind.DeserializationFeature;
65 import com.fasterxml.jackson.databind.JsonNode;
66 import com.fasterxml.jackson.databind.ObjectMapper;
67
68 @Controller
69 @RequestMapping("/rNotebook/")
70
71 public class RNoteBookController extends RestrictedRESTfulBaseController {
72         
73         @Autowired
74         private RNoteBookIntegrationService rNoteBookIntegrationService;
75         
76         
77
78         public RNoteBookIntegrationService getrNoteBookIntegrationService() {
79                 return rNoteBookIntegrationService;
80         }
81
82
83
84         public void setrNoteBookIntegrationService(
85                         RNoteBookIntegrationService rNoteBookIntegrationService) {
86                 this.rNoteBookIntegrationService = rNoteBookIntegrationService;
87         }
88
89
90
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();
97                 
98                 String returnJSON = "";
99                 try{
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);
104                         }
105                         else {
106                                 return new ResponseEntity<String>(JsonMessage.buildJsonResponse(false, re.getMessage()), HttpStatus.BAD_REQUEST);
107                         }
108                 } 
109                 catch (Exception e){
110                         return new ResponseEntity<String>(JsonMessage.buildJsonResponse(false, e.getMessage()), HttpStatus.BAD_REQUEST);
111                 }
112                 
113                 return new ResponseEntity<String>(returnJSON, HttpStatus.OK);
114                 
115         }
116         
117         
118 }