2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2021 AT&T Intellectual Property. All rights reserved.
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 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ============LICENSE_END=========================================================
20 package org.o.ran.oam.nf.oam.adopter.mock.app.controller;
22 import static org.o.ran.oam.nf.oam.adopter.mock.app.config.AuthTokenFilter.TOKEN;
24 import com.google.gson.Gson;
25 import java.time.Instant;
26 import java.time.ZoneId;
27 import java.time.ZoneOffset;
28 import java.time.format.DateTimeFormatter;
29 import org.o.ran.oam.nf.oam.adopter.mock.api.ControllerApi;
30 import org.o.ran.oam.nf.oam.adopter.mock.app.pojo.TimeZoneOffsetResponse;
31 import org.o.ran.oam.nf.oam.adopter.mock.app.pojo.TokenResponse;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34 import org.springframework.core.io.Resource;
35 import org.springframework.http.HttpHeaders;
36 import org.springframework.http.HttpStatus;
37 import org.springframework.http.MediaType;
38 import org.springframework.http.ResponseEntity;
39 import org.springframework.web.bind.annotation.RestController;
42 public class RanController implements ControllerApi {
44 private static final Logger LOG = LoggerFactory.getLogger(RanController.class);
45 private static final DateTimeFormatter OFFSET_FORMATTER = DateTimeFormatter.ofPattern("xxx");
46 private static final Gson GSON = new Gson();
49 public ResponseEntity<String> authenticateAndGenerateToken() {
50 return ResponseEntity.ok(GSON.toJson(new TokenResponse(TOKEN)));
54 public ResponseEntity<Resource> getPerformanceManagementFiles() {
55 LOG.info("Read pm files.");
56 final var headers = new HttpHeaders();
57 headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
58 return new ResponseEntity<>(ZipUtil.read(), headers, HttpStatus.OK);
62 public ResponseEntity<String> getTimeZone() {
63 final var zoneId = ZoneId.systemDefault();
64 final ZoneOffset offset = zoneId.getRules().getOffset(Instant.now());
65 LOG.info("ZoneId {} / Offset {}", zoneId, offset);
66 return ResponseEntity.ok(GSON.toJson(new TimeZoneOffsetResponse(OFFSET_FORMATTER.format(offset))));