2 * ========================LICENSE_START=================================
4 * ======================================================================
5 * Copyright (C) 2019-2020 Nordix Foundation. 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
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===================================
21 package org.onap.ccsdk.oran.a1policymanagementservice.repository;
23 import lombok.Builder;
26 import org.onap.ccsdk.oran.a1policymanagementservice.exceptions.ServiceException;
27 import org.springframework.http.HttpStatus;
30 public class PolicyType {
34 private String schema;
37 public static class Version {
38 public final int major;
39 public final int minor;
40 public final int patch;
42 public Version(int major, int minor, int patch) {
48 public static Version ofString(String version) throws ServiceException {
49 String[] versionTokenized = version.split("\\.");
50 if (versionTokenized.length != 3) {
51 throw new ServiceException("Version must contain major.minor.patch code: " + version,
52 HttpStatus.BAD_REQUEST);
56 return new Version( //
57 Integer.parseInt(versionTokenized[0]), //
58 Integer.parseInt(versionTokenized[1]), //
59 Integer.parseInt(versionTokenized[2]) //
61 } catch (Exception e) {
62 throw new ServiceException("Syntax error in " + version, HttpStatus.BAD_REQUEST);
68 public static class TypeId {
69 private final String name;
70 private final String version;
72 public TypeId(String name, String version) {
74 this.version = version;
77 public static TypeId ofString(String typeId) {
78 StringBuilder name = new StringBuilder();
80 String[] tokens = typeId.split("_");
82 if (tokens.length >= 2) {
83 version = tokens[tokens.length - 1]; // Last token
84 for (int i = 0; i < tokens.length - 1; ++i) {
88 name.append(tokens[i]); // All other tokens
90 return new TypeId(name.toString(), version);
92 return new TypeId(typeId, "");
97 public TypeId getTypeId() {
98 return TypeId.ofString(getId());