NF OAM Adopter RAN Mock application
[oam/nf-oam-adopter.git] / ves-nf-oam-adopter / ves-nf-oam-adopter-mock / src / main / java / org / o / ran / oam / nf / oam / adopter / mock / app / controller / RanController.java
1 /*
2  *  ============LICENSE_START=======================================================
3  *  O-RAN-SC
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
11  *
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=========================================================
18  */
19
20 package org.o.ran.oam.nf.oam.adopter.mock.app.controller;
21
22 import static org.o.ran.oam.nf.oam.adopter.mock.app.config.AuthTokenFilter.TOKEN;
23
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;
40
41 @RestController
42 public class RanController implements ControllerApi {
43
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();
47
48     @Override
49     public ResponseEntity<String> authenticateAndGenerateToken() {
50         return ResponseEntity.ok(GSON.toJson(new TokenResponse(TOKEN)));
51     }
52
53     @Override
54     public ResponseEntity<Resource> getPerformanceManagementFiles() {
55         LOG.info("Read pm files.");
56         final HttpHeaders headers = new HttpHeaders();
57         headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
58         return new ResponseEntity<>(ZipUtil.read(), headers, HttpStatus.OK);
59     }
60
61     @Override
62     public ResponseEntity<String> getTimeZone() {
63         final ZoneId 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))));
67     }
68 }