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