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.openecomp.portalapp.portal.controller;
40 import java.io.IOException;
41 import java.util.List;
44 import javax.servlet.http.HttpServletRequest;
45 import javax.servlet.http.HttpServletResponse;
47 import org.openecomp.portalapp.controller.EPRestrictedBaseController;
48 import org.openecomp.portalapp.portal.domain.AdminUserApplications;
49 import org.openecomp.portalapp.portal.domain.AppIdAndNameTransportModel;
50 import org.openecomp.portalapp.portal.domain.AppsResponse;
51 import org.openecomp.portalapp.portal.domain.EPApp;
52 import org.openecomp.portalapp.portal.domain.EPUser;
53 import org.openecomp.portalapp.portal.domain.EcompApp;
54 import org.openecomp.portalapp.portal.domain.UserRoles;
55 import org.openecomp.portalapp.portal.logging.aop.EPAuditLog;
56 import org.openecomp.portalapp.portal.service.AdminRolesService;
57 import org.openecomp.portalapp.portal.service.EPAppService;
58 import org.openecomp.portalapp.portal.service.EPLeftMenuService;
59 import org.openecomp.portalapp.portal.transport.EPAppsManualPreference;
60 import org.openecomp.portalapp.portal.transport.EPAppsSortPreference;
61 import org.openecomp.portalapp.portal.transport.EPDeleteAppsManualSortPref;
62 import org.openecomp.portalapp.portal.transport.EPWidgetsSortPreference;
63 import org.openecomp.portalapp.portal.transport.FieldsValidator;
64 import org.openecomp.portalapp.portal.transport.LocalRole;
65 import org.openecomp.portalapp.portal.transport.OnboardingApp;
66 import org.openecomp.portalapp.portal.utils.EcompPortalUtils;
67 import org.openecomp.portalapp.util.EPUserUtils;
68 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
69 import org.openecomp.portalsdk.core.util.SystemProperties;
70 import org.openecomp.portalsdk.core.web.support.AppUtils;
71 import org.springframework.beans.factory.annotation.Autowired;
72 import org.springframework.context.annotation.EnableAspectJAutoProxy;
73 import org.springframework.http.HttpEntity;
74 import org.springframework.http.HttpHeaders;
75 import org.springframework.http.MediaType;
76 import org.springframework.web.bind.annotation.PathVariable;
77 import org.springframework.web.bind.annotation.RequestBody;
78 import org.springframework.web.bind.annotation.RequestMapping;
79 import org.springframework.web.bind.annotation.RequestMethod;
80 import org.springframework.web.bind.annotation.RestController;
83 @EnableAspectJAutoProxy
85 public class AppsController extends EPRestrictedBaseController {
86 private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(AppsController.class);
89 private AdminRolesService adminRolesService;
92 private EPAppService appService;
95 private EPLeftMenuService leftMenuService;
98 * RESTful service method to fetch all Applications available to current
104 * HttpServletResponse
105 * @return List<EcompApp>
107 @RequestMapping(value = { "/portalApi/userApps" }, method = RequestMethod.GET, produces = "application/json")
108 public List<EcompApp> getUserApps(HttpServletRequest request, HttpServletResponse response) {
109 EPUser user = EPUserUtils.getUserSession(request);
110 List<EcompApp> ecompApps = null;
114 EcompPortalUtils.setBadPermissions(user, response, "getUserApps");
116 ecompApps = appService.transformAppsToEcompApps(appService.getUserApps(user));
117 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/userApps", "GET result =", ecompApps);
119 } catch (Exception e) {
120 logger.error(EELFLoggerDelegate.errorLogger, "getUserApps failed", e);
127 * RESTful service method to fetch all applications accessible to the
128 * current user, with personalizations.
133 * HttpServletResponse
134 * @return List<EcompApp>
135 * @throws IOException
138 @RequestMapping(value = { "/portalApi/persUserApps" }, method = RequestMethod.GET, produces = "application/json")
139 public List<EcompApp> getPersUserApps(HttpServletRequest request, HttpServletResponse response) throws IOException {
140 EPUser user = EPUserUtils.getUserSession(request);
141 List<EcompApp> ecompApps = null;
144 EcompPortalUtils.setBadPermissions(user, response, "getPersUserApps");
146 List<EPApp> apps = null;
147 if (adminRolesService.isSuperAdmin(user))
148 apps = appService.getPersAdminApps(user);
150 apps = appService.getPersUserApps(user);
151 ecompApps = appService.transformAppsToEcompApps(apps);
152 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/userPersApps", "GET result =", ecompApps);
154 } catch (Exception e) {
155 logger.error(EELFLoggerDelegate.errorLogger, "getPersUserApps failed", e);
156 response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString());
162 * RESTful service method to fetch applications for which the current user
163 * is an Administrator
168 * HttpServletResponse
169 * @return List<AppIdAndNameTransportModel>
171 @RequestMapping(value = { "/portalApi/adminApps" }, method = RequestMethod.GET, produces = "application/json")
172 public List<AppIdAndNameTransportModel> getAdminApps(HttpServletRequest request, HttpServletResponse response) {
173 EPUser user = EPUserUtils.getUserSession(request);
174 List<AppIdAndNameTransportModel> adminApps = null;
177 if (!adminRolesService.isAccountAdmin(user)) {
178 EcompPortalUtils.setBadPermissions(user, response, "getAdminApps");
180 adminApps = appService.getAdminApps(user);
181 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/adminApps", "GET result =", adminApps);
183 } catch (Exception e) {
184 logger.error(EELFLoggerDelegate.errorLogger, "getAdminApps failed", e);
191 * RESTful service method to fetch Applications for user who is super admin
197 * HttpServletResponse
198 * @return List<AppIdAndNameTransportModel>
200 @RequestMapping(value = {
201 "/portalApi/appsForSuperAdminAndAccountAdmin" }, method = RequestMethod.GET, produces = "application/json")
202 public List<AppIdAndNameTransportModel> getAppsForSuperAdminAndAccountAdmin(HttpServletRequest request,
203 HttpServletResponse response) {
204 EPUser user = EPUserUtils.getUserSession(request);
205 List<AppIdAndNameTransportModel> adminApps = null;
208 if (!adminRolesService.isSuperAdmin(user) && !adminRolesService.isAccountAdmin(user)) {
209 EcompPortalUtils.setBadPermissions(user, response, "getAdminApps");
211 adminApps = appService.getAppsForSuperAdminAndAccountAdmin(user);
212 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/appsForSuperAdminAndAccountAdmin",
213 "GET result =", adminApps);
215 } catch (Exception e) {
216 logger.error(EELFLoggerDelegate.errorLogger, "getAppsForSuperAdminAndAccountAdmin failed", e);
223 * RESTful service method to fetch left menu items from the user's session.
228 * HttpServletResponse
229 * @return JSON with left menu
231 @SuppressWarnings({ "rawtypes", "unchecked" })
232 @RequestMapping(value = { "/portalApi/leftmenuItems" }, method = RequestMethod.GET, produces = "application/json")
233 public String getLeftMenuItems(HttpServletRequest request, HttpServletResponse response) {
234 String menuList = null;
235 Set menuSet = (Set) AppUtils.getSession(request)
236 .getAttribute(SystemProperties.getProperty(SystemProperties.APPLICATION_MENU_ATTRIBUTE_NAME));
238 Set roleFunctionSet = (Set) AppUtils.getSession(request)
239 .getAttribute(SystemProperties.getProperty(SystemProperties.ROLE_FUNCTIONS_ATTRIBUTE_NAME));
241 EPUser user = EPUserUtils.getUserSession(request);
244 menuList = leftMenuService.getLeftMenuItems(user, menuSet, roleFunctionSet);
245 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/leftmenuItems", "GET result =", menuList);
246 } catch (Exception e) {
247 logger.error(EELFLoggerDelegate.errorLogger, "getLeftMenuItems failed", e);
252 @RequestMapping(value = {
253 "/portalApi/userAppsOrderBySortPref" }, method = RequestMethod.GET, produces = "application/json")
254 public List<EcompApp> getUserAppsOrderBySortPref(HttpServletRequest request, HttpServletResponse response) {
255 EPUser user = EPUserUtils.getUserSession(request);
256 List<EcompApp> ecompApps = null;
259 EcompPortalUtils.setBadPermissions(user, response, "getUserAppsOrderBySortPref");
261 String usrSortPref = request.getParameter("mparams");
262 if (usrSortPref.equals("")) {
265 switch (usrSortPref) {
267 ecompApps = appService.transformAppsToEcompApps(appService.getAppsOrderByName(user));
268 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/userAppsOrderBySortPref", "GET result =",
272 ecompApps = appService.transformAppsToEcompApps(appService.getAppsOrderByLastUsed(user));
273 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/userAppsOrderBySortPref", "GET result =",
277 ecompApps = appService.transformAppsToEcompApps(appService.getAppsOrderByMostUsed(user));
278 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/userAppsOrderBySortPref", "GET result =",
282 ecompApps = appService.transformAppsToEcompApps(appService.getAppsOrderByManual(user));
283 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/userAppsOrderBySortPref", "GET result =",
287 logger.error(EELFLoggerDelegate.errorLogger,
288 "getUserAppsOrderBySortPref failed: no match for " + usrSortPref);
291 } catch (Exception e) {
292 logger.error(EELFLoggerDelegate.errorLogger, "getUserAppsOrderBySortPref failed", e);
298 * Sets the user apps manual sort preference
301 * HTTP servlet request
303 * HTTP servlet response
304 * @param epAppsManualPref
306 * @return FieldsValidator
308 @RequestMapping(value = {
309 "/portalApi/saveUserAppsSortingManual" }, method = RequestMethod.PUT, produces = "application/json")
310 public FieldsValidator putUserAppsSortingManual(HttpServletRequest request,
311 @RequestBody List<EPAppsManualPreference> epAppsManualPref, HttpServletResponse response) {
312 FieldsValidator fieldsValidator = null;
314 EPUser user = EPUserUtils.getUserSession(request);
315 fieldsValidator = appService.saveAppsSortManual(epAppsManualPref, user);
316 response.setStatus(fieldsValidator.httpStatusCode.intValue());
317 } catch (Exception e) {
318 logger.error(EELFLoggerDelegate.errorLogger, "putUserAppsSortingManual failed", e);
320 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/saveUserAppsSortingManual", "PUT result =",
321 response.getStatus());
322 return fieldsValidator;
325 @RequestMapping(value = {
326 "/portalApi/saveUserWidgetsSortManual" }, method = RequestMethod.PUT, produces = "application/json")
327 public FieldsValidator putUserWidgetsSortManual(HttpServletRequest request,
328 @RequestBody List<EPWidgetsSortPreference> saveManualWidgetSData, HttpServletResponse response) {
329 FieldsValidator fieldsValidator = null;
331 EPUser user = EPUserUtils.getUserSession(request);
332 fieldsValidator = appService.saveWidgetsSortManual(saveManualWidgetSData, user);
333 response.setStatus(fieldsValidator.httpStatusCode.intValue());
334 } catch (Exception e) {
335 logger.error(EELFLoggerDelegate.errorLogger, "putUserWidgetsSortManual failed", e);
337 // return fieldsValidator;
338 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/putUserWidgetsSortManual", "PUT result =",
339 response.getStatus());
340 return fieldsValidator;
343 @RequestMapping(value = {
344 "/portalApi/updateWidgetsSortPref" }, method = RequestMethod.PUT, produces = "application/json")
345 public FieldsValidator putUserWidgetsSortPref(HttpServletRequest request,
346 @RequestBody List<EPWidgetsSortPreference> delManualWidgetData, HttpServletResponse response) {
347 FieldsValidator fieldsValidator = null;
349 EPUser user = EPUserUtils.getUserSession(request);
350 fieldsValidator = appService.deleteUserWidgetSortPref(delManualWidgetData, user);
351 response.setStatus(fieldsValidator.httpStatusCode.intValue());
352 } catch (Exception e) {
353 logger.error(EELFLoggerDelegate.errorLogger, "putUserWidgetsSortPref failed", e);
356 // return fieldsValidator;
357 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/putUserWidgetsSortPref", "PUT result =",
358 response.getStatus());
359 return fieldsValidator;
363 * Deletes the user app manual sort preference record
366 * HTTP servlet request
368 * HTTP servlet response
369 * @param delManualAppData
371 * @return FieldsValidator
373 @RequestMapping(value = {
374 "/portalApi/UpdateUserAppsSortManual" }, method = RequestMethod.PUT, produces = "application/json")
375 public FieldsValidator deleteUserAppSortManual(HttpServletRequest request,
376 @RequestBody EPDeleteAppsManualSortPref delManualAppData, HttpServletResponse response) {
377 FieldsValidator fieldsValidator = null;
379 EPUser user = EPUserUtils.getUserSession(request);
380 fieldsValidator = appService.deleteUserAppSortManual(delManualAppData, user);
381 response.setStatus(fieldsValidator.httpStatusCode.intValue());
382 } catch (Exception e) {
383 logger.error(EELFLoggerDelegate.errorLogger, "deleteUserAppSortManual failed", e);
386 // return fieldsValidator;
387 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/deleteUserAppSortManual", "PUT result =",
388 response.getStatus());
389 return fieldsValidator;
392 @RequestMapping(value = {
393 "/portalApi/saveUserAppsSortingPreference" }, method = RequestMethod.PUT, produces = "application/json")
394 public FieldsValidator putUserAppsSortingPreference(HttpServletRequest request,
395 @RequestBody EPAppsSortPreference userAppsValue, HttpServletResponse response) {
396 FieldsValidator fieldsValidator = null;
398 EPUser user = EPUserUtils.getUserSession(request);
399 fieldsValidator = appService.saveAppsSortPreference(userAppsValue, user);
400 response.setStatus(fieldsValidator.httpStatusCode.intValue());
401 } catch (Exception e) {
402 logger.error(EELFLoggerDelegate.errorLogger, "putUserAppsSortingPreference failed", e);
406 // return fieldsValidator;
407 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/putUserAppsSortingPreference", "PUT result =",
408 response.getStatus());
409 return fieldsValidator;
412 @RequestMapping(value = {
413 "/portalApi/userAppsSortTypePreference" }, method = RequestMethod.GET, produces = "application/String")
414 public String getUserAppsSortTypePreference(HttpServletRequest request, HttpServletResponse response) {
415 EPUser user = EPUserUtils.getUserSession(request);
416 String userSortPreference = null;
420 EcompPortalUtils.setBadPermissions(user, response, "userAppsSortTypePreference");
422 userSortPreference = appService.getUserAppsSortTypePreference(user);
423 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/userAppsSortTypePreference", "GET result =",
426 } catch (Exception e) {
427 logger.error(EELFLoggerDelegate.errorLogger, "getUserAppsSortTypePreference failed", e);
430 return userSortPreference;
434 * RESTful service method to fetch Application Administrators to Super
435 * Administrator user. Attention: Users which have Super Administrator roles
436 * only are not included!
439 * HTTP servlet request
441 * HTTP servlet response
442 * @return List<AdminUserApplications>
444 @RequestMapping(value = { "/portalApi/accountAdmins" }, method = RequestMethod.GET, produces = "application/json")
445 public List<AdminUserApplications> getAppsAdministrators(HttpServletRequest request, HttpServletResponse response) {
446 EPUser user = EPUserUtils.getUserSession(request);
447 List<AdminUserApplications> admins = null;
449 if (!adminRolesService.isSuperAdmin(user)) {
450 EcompPortalUtils.setBadPermissions(user, response, "getAppsAdministrators");
452 admins = appService.getAppsAdmins();
453 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/accountAdmins", "GET result =", admins);
455 } catch (Exception e) {
456 logger.error(EELFLoggerDelegate.errorLogger, "getAppsAdministrators failed", e);
462 @RequestMapping(value = { "/portalApi/availableApps" }, method = RequestMethod.GET, produces = "application/json")
463 public List<AppsResponse> getApps(HttpServletRequest request, HttpServletResponse response) {
464 EPUser user = EPUserUtils.getUserSession(request);
465 List<AppsResponse> apps = null;
467 if (!adminRolesService.isSuperAdmin(user)) {
468 EcompPortalUtils.setBadPermissions(user, response, "getApps");
470 apps = appService.getAllApps(false);
471 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/availableApps", "GET result =", apps);
473 } catch (Exception e) {
474 logger.error(EELFLoggerDelegate.errorLogger, "getApps failed", e);
481 * Gets all apps, both active and inactive; i.e., all on-boarded apps,
482 * regardless of enabled status.
485 * HTTP servlet request
487 * HTTP servlet response
488 * @return List of applications
490 @RequestMapping(value = {
491 "/portalApi/allAvailableApps" }, method = RequestMethod.GET, produces = "application/json")
492 public List<AppsResponse> getAllApps(HttpServletRequest request, HttpServletResponse response) {
493 EPUser user = EPUserUtils.getUserSession(request);
494 List<AppsResponse> apps = null;
496 if (!adminRolesService.isSuperAdmin(user)) {
497 EcompPortalUtils.setBadPermissions(user, response, "getApps");
499 apps = appService.getAllApps(true);
500 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/availableApps", "GET result =", apps);
502 } catch (Exception e) {
503 logger.error(EELFLoggerDelegate.errorLogger, "getAllApps failed", e);
512 * HTTP servlet request
514 * HTTP servlet response
515 * @return List of applications
517 @RequestMapping(value = { "/portalApi/appsFullList" }, method = RequestMethod.GET, produces = "application/json")
518 public List<EcompApp> getAppsFullList(HttpServletRequest request, HttpServletResponse response) {
519 EPUser user = EPUserUtils.getUserSession(request);
520 List<EcompApp> ecompApps = null;
522 EcompPortalUtils.setBadPermissions(user, response, "getAppsFullList");
524 ecompApps = appService.getEcompAppAppsFullList();
525 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/appsFullList", "GET result =", ecompApps);
533 * HTTP servlet request
535 * HTTP servlet response
538 @RequestMapping(value = { "/portalApi/userProfile" }, method = RequestMethod.GET, produces = "application/json")
539 public UserRoles getUserProfile(HttpServletRequest request, HttpServletResponse response) {
540 EPUser user = EPUserUtils.getUserSession(request);
541 UserRoles userAndRoles = null;
544 EcompPortalUtils.setBadPermissions(user, response, "getUserProfile");
546 userAndRoles = appService.getUserProfileNormalized(user);
548 } catch (Exception e) {
549 logger.error(EELFLoggerDelegate.errorLogger, "getUserProfile failed", e);
552 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/userProfile", "getUserProfile result =",
560 * HTTP servlet request
563 * @return List<LocalRole>
565 @RequestMapping(value = { "/portalApi/appRoles/{appId}" }, method = {
566 RequestMethod.GET }, produces = "application/json")
567 public List<LocalRole> getAppRoles(HttpServletRequest request, @PathVariable("appId") Long appId) {
568 List<LocalRole> roleList = null;
570 roleList = appService.getAppRoles(appId);
571 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/appRoles/" + appId, "GET result =", roleList);
572 } catch (Exception e) {
573 logger.error(EELFLoggerDelegate.errorLogger, "getAppRoles failed", e);
582 * HTTP servlet request
584 * HTTP servlet response
585 * @return List<OnboardingApp>
587 @RequestMapping(value = { "/portalApi/onboardingApps" }, method = RequestMethod.GET, produces = "application/json")
588 public List<OnboardingApp> getOnboardingApps(HttpServletRequest request, HttpServletResponse response) {
589 EPUser user = EPUserUtils.getUserSession(request);
590 List<OnboardingApp> onboardingApps = null;
592 if (!adminRolesService.isSuperAdmin(user)) {
593 EcompPortalUtils.setBadPermissions(user, response, "getOnboardingApps");
595 onboardingApps = appService.getOnboardingApps();
596 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/onboardingApps", "GET result =",
597 "onboardingApps of size " + onboardingApps.size());
599 } catch (Exception e) {
600 logger.error(EELFLoggerDelegate.errorLogger, "getOnboardingApps failed", e);
603 return onboardingApps;
609 * HTTP servlet request
611 * HTTP servlet response
612 * @param modifiedOnboardingApp
614 * @return FieldsValidator
616 @RequestMapping(value = { "/portalApi/onboardingApps" }, method = RequestMethod.PUT, produces = "application/json")
617 public FieldsValidator putOnboardingApp(HttpServletRequest request,
618 @RequestBody OnboardingApp modifiedOnboardingApp, HttpServletResponse response) {
619 FieldsValidator fieldsValidator = null;
621 EPUser user = EPUserUtils.getUserSession(request);
622 if (!adminRolesService.isSuperAdmin(user)) {
623 EcompPortalUtils.setBadPermissions(user, response, "putOnboardingApp");
625 modifiedOnboardingApp.normalize();
626 fieldsValidator = appService.modifyOnboardingApp(modifiedOnboardingApp, user);
627 response.setStatus(fieldsValidator.httpStatusCode.intValue());
629 } catch (Exception e) {
630 logger.error(EELFLoggerDelegate.errorLogger, "putOnboardingApps failed", e);
633 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/onboardingApps", "PUT result =",
634 response.getStatus());
635 return fieldsValidator;
641 * HTTP servlet request
643 * HTTP servlet response
644 * @param newOnboardingApp
646 * @return FieldsValidator
648 @RequestMapping(value = { "/portalApi/onboardingApps" }, method = RequestMethod.POST, produces = "application/json")
649 public FieldsValidator postOnboardingApp(HttpServletRequest request, @RequestBody OnboardingApp newOnboardingApp,
650 HttpServletResponse response) {
651 FieldsValidator fieldsValidator = null;
653 EPUser user = EPUserUtils.getUserSession(request);
654 if (!adminRolesService.isSuperAdmin(user)) {
655 EcompPortalUtils.setBadPermissions(user, response, "postOnboardingApps");
657 newOnboardingApp.normalize();
658 fieldsValidator = appService.addOnboardingApp(newOnboardingApp, user);
659 response.setStatus(fieldsValidator.httpStatusCode.intValue());
661 } catch (Exception e) {
662 logger.error(EELFLoggerDelegate.errorLogger, "postOnboardingApp failed", e);
665 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/onboardingApps", "POST result =",
666 response.getStatus());
667 return fieldsValidator;
671 * REST endpoint to process a request to delete an on-boarded application.
674 * HTTP servlet request
676 * HTTP servlet response
678 * ID of app to delete
679 * @return FieldsValidator
681 @RequestMapping(value = { "/portalApi/onboardingApps/{appId}" }, method = {
682 RequestMethod.DELETE }, produces = "application/json")
683 public FieldsValidator deleteOnboardingApp(HttpServletRequest request, @PathVariable("appId") Long appId,
684 HttpServletResponse response) {
685 FieldsValidator fieldsValidator = null;
687 EPUser user = EPUserUtils.getUserSession(request);
688 if (!adminRolesService.isSuperAdmin(user)) {
689 EcompPortalUtils.setBadPermissions(user, response, "deleteOnboardingApps");
691 fieldsValidator = appService.deleteOnboardingApp(user, appId);
692 response.setStatus(fieldsValidator.httpStatusCode.intValue());
694 } catch (Exception e) {
695 logger.error(EELFLoggerDelegate.errorLogger, "deleteOnboardingApp failed", e);
696 response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
699 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/onboardingApps" + appId, "DELETE result =",
700 response.getStatus());
701 return fieldsValidator;
705 * Gets the application thumbnail image; sets status 404 if none exists.
708 * HTTP servlet request
710 * HTTP servlet response
713 * @return Bytes with the app thumbnail image; null if not available.
715 @RequestMapping(value = { "/portalApi/appThumbnail/{appId}" }, method = { RequestMethod.GET })
716 public HttpEntity<byte[]> getAppThumbnail(HttpServletRequest request, @PathVariable("appId") Long appId,
717 HttpServletResponse response) {
718 EPApp app = appService.getApp(appId);
719 if (app == null || app.getImageUrl() == null || app.getThumbnail() == null || app.getThumbnail().length == 0) {
720 logger.debug(EELFLoggerDelegate.debugLogger,
721 "getAppThumbnail: no app and/or no thumbnail for app " + appId);
722 response.setStatus(HttpServletResponse.SC_NOT_FOUND);
725 String url = app.getImageUrl();
726 int indexOfDot = url.lastIndexOf('.');
727 String urlSuffix = indexOfDot > 0 ? url.substring(indexOfDot + 1).toLowerCase() : "UNK";
728 // Default to JPG if no usable suffix.
729 MediaType mediaType = MediaType.IMAGE_JPEG;
730 if ("png".equals(urlSuffix))
731 mediaType = MediaType.IMAGE_PNG;
732 else if ("gif".equals(urlSuffix))
733 mediaType = MediaType.IMAGE_GIF;
734 HttpHeaders header = new HttpHeaders();
735 header.setContentType(mediaType);
736 header.setContentLength(app.getThumbnail().length);
737 return new HttpEntity<byte[]>(app.getThumbnail(), header);