nexus site path corrected
[portal.git] / ecomp-portal-BE / src / main / java / org / openecomp / portalapp / portal / controller / ManifestController.java
1 /*-
2  * ================================================================================
3  * eCOMP Portal
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.portalapp.portal.controller;
21
22 import java.util.HashMap;
23 import java.util.Map;
24 import java.util.jar.Attributes;
25
26 import javax.servlet.http.HttpServletRequest;
27
28 import org.openecomp.portalapp.portal.logging.aop.EPAuditLog;
29 import org.openecomp.portalapp.portal.service.ManifestService;
30 import org.openecomp.portalsdk.core.controller.RestrictedBaseController;
31 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.context.annotation.Configuration;
34 import org.springframework.context.annotation.EnableAspectJAutoProxy;
35 import org.springframework.stereotype.Controller;
36 import org.springframework.web.bind.annotation.RequestMapping;
37 import org.springframework.web.bind.annotation.RequestMethod;
38 import org.springframework.web.bind.annotation.ResponseBody;
39 import org.springframework.web.bind.annotation.RestController;
40
41
42
43 /**
44  * This controller responds to a request for the web application manifest,
45  * returning a JSON with the information that was created at build time.
46  * 
47  * Manifest entries have names with hyphens, which means Javascript code can't
48  * simply use the shorthand object.key; instead use object['key'].
49  */
50 @RestController
51 @Configuration
52 @EnableAspectJAutoProxy
53 @RequestMapping("/")
54 @EPAuditLog
55 @Controller
56 public class ManifestController extends RestrictedBaseController {
57
58         private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ManifestController.class);
59         
60         @Autowired
61         ManifestService manifestService;
62         
63         /**
64          * Gets the webapp manifest contents as a JSON object.
65          * 
66          * @param request
67          * @return A map of key-value pairs. On success:
68          * 
69          *         <pre>
70          * { "manifest" : { "key1": "value1", "key2": "value2" } }
71          *         </pre>
72          * 
73          *         On failure:
74          * 
75          *         <pre>
76          * { "error": "message" }
77          *         </pre>
78          */
79         @RequestMapping(value = { "/portalApi/manifest" }, method = RequestMethod.GET, produces = "application/json")
80         @ResponseBody
81         public Map<String, Object> getManifest(HttpServletRequest request) {
82                 Map<String, Object> response = new HashMap<String, Object>();
83                 try {
84                         Attributes attributes = manifestService.getWebappManifest();
85                         response.put("manifest", attributes);
86                 } catch (Exception ex) {
87                         logger.error(EELFLoggerDelegate.errorLogger, "getManifest: failed to read manifest", ex);
88                         response.put("error", "failed to get manifest: " + ex.toString());
89                 }
90                 return response;
91         }
92
93 }