2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
20 package org.onap.so.sdcsimulator.models;
22 import static org.onap.so.sdcsimulator.utils.Constants.CATALOG_URL;
23 import static org.onap.so.sdcsimulator.utils.Constants.FORWARD_SLASH;
25 import java.io.IOException;
26 import org.springframework.core.io.Resource;
27 import com.fasterxml.jackson.databind.DeserializationFeature;
28 import com.fasterxml.jackson.databind.ObjectMapper;
32 * @author Waqas Ikram (waqas.ikram@est.tech)
35 public enum AssetType {
39 public AssetInfo getAssetInfo(final Resource resource) throws IOException {
40 return OBJ_MAPPER.readValue(resource.getInputStream(), ResourceAssetInfo.class);
44 public AssetInfo getAssetInfo(final File file) throws IOException {
45 return OBJ_MAPPER.readValue(file, ResourceAssetInfo.class);
49 public Metadata getMetadata(final Resource resource) throws IOException {
50 return OBJ_MAPPER.readValue(resource.getInputStream(), ResourceMetadata.class);
54 public Metadata getMetadata(final File file) throws IOException {
55 return OBJ_MAPPER.readValue(file, ResourceMetadata.class);
61 public AssetInfo getAssetInfo(final Resource resource) throws IOException {
62 return OBJ_MAPPER.readValue(resource.getInputStream(), ServiceAssetInfo.class);
66 public AssetInfo getAssetInfo(final File file) throws IOException {
67 return OBJ_MAPPER.readValue(file, ServiceAssetInfo.class);
71 public Metadata getMetadata(final Resource resource) throws IOException {
72 return OBJ_MAPPER.readValue(resource.getInputStream(), ServiceMetadata.class);
76 public Metadata getMetadata(final File file) throws IOException {
77 return OBJ_MAPPER.readValue(file, ServiceMetadata.class);
82 private static final ObjectMapper OBJ_MAPPER =
83 new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
86 public abstract AssetInfo getAssetInfo(final Resource resource) throws IOException;
88 public abstract AssetInfo getAssetInfo(final File file) throws IOException;
90 public abstract Metadata getMetadata(final Resource resource) throws IOException;
92 public abstract Metadata getMetadata(final File file) throws IOException;
94 public String getToscaModelUrl(final String filename) {
95 return CATALOG_URL + FORWARD_SLASH + this.toString().toLowerCase() + FORWARD_SLASH + filename + "/toscaModel";
98 public AssetInfo getDefaultAssetInfo(final String filename) {
99 AssetInfo defaultValue = null;
101 if (this.equals(RESOURCES)) {
102 defaultValue = new ResourceAssetInfo().subCategory("Network Service");
103 } else if (this.equals(SERVICES)) {
104 defaultValue = new ServiceAssetInfo().distributionStatus("DISTRIBUTED");
106 defaultValue = new AssetInfo();
109 return defaultValue.uuid(filename).invariantUuid(filename).name(filename).version("1.0")
110 .toscaModelUrl(getToscaModelUrl(filename)).category("Generic").lifecycleState("CERTIFIED")
111 .lastUpdaterUserId("SDC_SIMULATOR");