2 * ========================LICENSE_START=================================
5 * Copyright (C) 2019 AT&T Intellectual Property
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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 * ========================LICENSE_END===================================
20 package org.oransc.ric.portal.dashboard.config;
22 import java.io.IOException;
23 import java.io.PrintWriter;
24 import java.lang.invoke.MethodHandles;
25 import java.util.Collection;
26 import java.util.HashSet;
27 import java.util.Locale;
30 import org.onap.portalsdk.core.onboarding.exception.PortalAPIException;
31 import org.onap.portalsdk.core.restful.domain.EcompRole;
32 import org.onap.portalsdk.core.restful.domain.EcompUser;
33 import org.oransc.ric.portal.dashboard.DashboardUserManager;
34 import org.oransc.ric.portal.dashboard.AppStatsManager;
35 import org.oransc.ric.portal.dashboard.exception.StatsManagerException;
36 import org.oransc.ric.portal.dashboard.model.AppStats;
37 import org.oransc.ric.portal.dashboard.model.StatsDetailsTransport;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
40 import org.springframework.beans.factory.annotation.Autowired;
41 import org.springframework.context.annotation.Bean;
42 import org.springframework.context.annotation.Configuration;
43 import org.springframework.context.annotation.Profile;
45 import javax.servlet.ServletOutputStream;
46 import javax.servlet.http.Cookie;
47 import javax.servlet.http.HttpServletResponse;
50 * Creates user manager and stats manager with mock data.
54 public class AdminMockConfiguration {
56 private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
59 public AdminMockConfiguration() {
63 // The bean (method) name must be globally unique
64 public DashboardUserManager userManager() throws IOException, PortalAPIException {
65 logger.debug("userManager: adding mock data");
66 DashboardUserManager mgr = new DashboardUserManager(true);
67 String[] firsts = { "John", "Alice", "Pierce", "Paul", "Jack" };
68 String[] lasts = { "Doe", "Nolan", "King", "Smith", "Reacher" };
69 String[] logins = { "jdoe", "anolan", "pking", "psmith", "jreacher" };
70 boolean[] actives = { true, true, false, false, true };
71 EcompRole role = new EcompRole();
73 Set<EcompRole> roles = new HashSet<>();
75 for (int i = 0; i < firsts.length; ++i) {
76 EcompUser eu = new EcompUser();
77 eu.setFirstName(firsts[i]);
78 eu.setLastName(lasts[i]);
79 eu.setLoginId(logins[i]);
80 eu.setActive(actives[i]);
88 // The bean (method) name must be globally unique
89 public AppStatsManager statsManager() throws IOException, StatsManagerException {
90 logger.debug("statsManager: adding mock data");
91 AppStatsManager mgr = new AppStatsManager(true);
92 String instanceKey = RICInstanceMockConfiguration.INSTANCE_KEY_1;
93 StatsDetailsTransport statsDetails = new StatsDetailsTransport();
94 statsDetails.setAppId(0);
95 statsDetails.setAppName("MachLearn");
96 statsDetails.setMetricUrl("https://www.example.com");
97 mgr.createStats(instanceKey, statsDetails);