X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=sample-services%2Fics-producer-consumer%2Fconsumer%2Fsrc%2Fmain%2Fjava%2Fcom%2Fdemo%2Fconsumer%2Frepository%2FInfoTypes.java;fp=sample-services%2Fics-producer-consumer%2Fconsumer%2Fsrc%2Fmain%2Fjava%2Fcom%2Fdemo%2Fconsumer%2Frepository%2FInfoTypes.java;h=f1e83be5ebf894fe1419b0eca12dc39e22aec88c;hb=af9b38ae549e2d6a128a00e5d8b9f5f56fc32755;hp=0000000000000000000000000000000000000000;hpb=9ddce2b0e23655371aa311c94ce9605dcc74f74e;p=nonrtric.git diff --git a/sample-services/ics-producer-consumer/consumer/src/main/java/com/demo/consumer/repository/InfoTypes.java b/sample-services/ics-producer-consumer/consumer/src/main/java/com/demo/consumer/repository/InfoTypes.java new file mode 100644 index 00000000..f1e83be5 --- /dev/null +++ b/sample-services/ics-producer-consumer/consumer/src/main/java/com/demo/consumer/repository/InfoTypes.java @@ -0,0 +1,81 @@ +/*- + * ========================LICENSE_START================================= + * O-RAN-SC + * + * Copyright (C) 2024: OpenInfra Foundation Europe + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ========================LICENSE_END=================================== + */ + +package com.demo.consumer.repository; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.Vector; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Component; + +@Component +public class InfoTypes { + private static final Logger logger = LoggerFactory.getLogger(InfoTypes.class); + + private Map allTypes = new HashMap<>(); + + public InfoTypes(Collection types) { + for (InfoType type : types) { + put(type); + } + } + + public synchronized InfoType get(String id) { + return allTypes.get(id); + } + + public synchronized InfoType getType(String id) throws Exception { + InfoType type = allTypes.get(id); + if (type == null) { + throw new Exception("Could not find type: " + id + HttpStatus.NOT_FOUND.toString()); + } + return type; + } + + public static class ConfigFile { + Collection types; + } + + public synchronized void put(InfoType type) { + logger.debug("Put type: {}", type.getId()); + allTypes.put(type.getId(), type); + } + + public synchronized Iterable getAll() { + return new Vector<>(allTypes.values()); + } + + public synchronized Collection typeIds() { + return allTypes.keySet(); + } + + public synchronized int size() { + return allTypes.size(); + } + + public synchronized void clear() { + allTypes.clear(); + } +}