68ad91d29aeb3b818507d369e5a8e3fbc4b64024
[sdc.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019 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
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  *
16  *  SPDX-License-Identifier: Apache-2.0
17  *  ============LICENSE_END=========================================================
18  */
19
20 package org.openecomp.sdc.tosca.csar;
21
22 import java.util.Arrays;
23 import java.util.Optional;
24
25 public enum ManifestTokenType {
26     ALGORITHM("Algorithm"),
27     ATTRIBUTE_VALUE_SEPARATOR(":"),
28     CMS_BEGIN("-----BEGIN CMS-----"),
29     CMS_END("-----END CMS-----"),
30     HASH("Hash"),
31     METADATA("metadata"),
32     NON_MANO_ARTIFACT_SETS("non_mano_artifact_sets"),
33     SOURCE("Source"),
34     VNF_PRODUCT_NAME("vnf_product_name"),
35     VNF_PROVIDER_ID("vnf_provider_id"),
36     VNF_PACKAGE_VERSION("vnf_package_version"),
37     VNF_RELEASE_DATE_TIME("vnf_release_date_time"),
38     PNFD_NAME("pnfd_name"),
39     PNFD_PROVIDER("pnfd_provider"),
40     PNFD_ARCHIVE_VERSION("pnfd_archive_version"),
41     PNFD_RELEASE_DATE_TIME("pnfd_release_date_time");
42
43     private final String token;
44
45     ManifestTokenType(final String token) {
46         this.token = token;
47     }
48
49     public String getToken() {
50         return token;
51     }
52
53     public static Optional<ManifestTokenType> parse(final String token) {
54         return Arrays.stream(values()).filter(it -> it.getToken() != null && it.getToken().equals(token)).findFirst();
55     }
56
57     public boolean isMetadataEntry() {
58         return isMetadataVnfEntry() || isMetadataPnfEntry();
59     }
60
61     public boolean isMetadataVnfEntry() {
62         switch (this) {
63             case VNF_PRODUCT_NAME:
64             case VNF_PROVIDER_ID:
65             case VNF_PACKAGE_VERSION:
66             case VNF_RELEASE_DATE_TIME:
67                 return true;
68             default:
69                 return false;
70         }
71     }
72
73     public boolean isMetadataPnfEntry() {
74         switch (this) {
75             case PNFD_NAME:
76             case PNFD_PROVIDER:
77             case PNFD_ARCHIVE_VERSION:
78             case PNFD_RELEASE_DATE_TIME:
79                 return true;
80             default:
81                 return false;
82         }
83     }
84 }