2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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
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.openecomp.sdc.generator.data;
23 import com.fasterxml.jackson.databind.DeserializationFeature;
24 import com.fasterxml.jackson.databind.ObjectMapper;
25 import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
26 import org.apache.commons.codec.digest.DigestUtils;
28 import java.io.IOException;
29 import java.util.Base64;
32 * Utility method class for artifact generation.
34 public class GeneratorUtil {
36 * Translate tosca yaml into the provided model class.
38 * @param tosca Tosca file content
39 * @param classOfT Model class for the translated object
40 * @param <T> Template parameter for the return object
41 * @return Object model for the provided tosca yaml file
43 public static <T> T translateTosca(String tosca, Class<T> classOfT) throws IOException {
46 ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); // jackson data-bind
47 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
48 tos = mapper.readValue(tosca, classOfT);
53 * Decodes Base64 encode byte array input.
55 * @param input Base64 encoded byte array
56 * @return Decoded byte array
58 public static byte[] decoder(byte[] input) {
60 byte[] output = Base64.getDecoder().decode(input);
67 * Encode a byte array input using Base64 encoding.
69 * @param input Input byte array to be encoded
70 * @return Base64 encoded byte array
72 public static byte[] encode(byte[] input) {
74 byte[] output = Base64.getEncoder().encode(input);
81 * Calculate the checksum for a given input.
83 * @param input Byte array for which the checksum has to be calculated
84 * @return Calculated checksum of the input byte array
86 public static String checkSum(byte[] input) {
87 String checksum = null;
89 checksum = (DigestUtils.md5Hex(input)).toUpperCase();
95 * Check if string is empty or null.
97 * @param input Input String
98 * @return true if string is empty/null and false otherwise
100 public static boolean isEmpty(String input) {
101 return input == null || input.length() == 0;