2 * Copyright © 2018 European Support Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * 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.
17 package org.onap.sdc.workflow.services.impl.mappers;
19 import static org.onap.sdc.workflow.services.ActivitySpecConstant.CATEGORY_ATTRIBUTE_NAME;
21 import java.util.HashMap;
22 import java.util.List;
24 import org.mapstruct.InheritInverseConfiguration;
25 import org.mapstruct.Mapper;
26 import org.mapstruct.Mapping;
27 import org.mapstruct.MappingTarget;
28 import org.onap.sdc.common.versioning.services.types.Item;
29 import org.onap.sdc.common.versioning.services.types.VersionStatus;
30 import org.onap.sdc.workflow.persistence.types.ActivitySpecEntity;
31 import org.onap.sdc.workflow.services.ActivitySpecConstant;
32 import org.onap.sdc.workflow.services.impl.ItemType;
34 @Mapper(componentModel = "spring", imports = {ItemType.class, ActivitySpecConstant.class})
35 public interface ActivitySpecMapper {
37 @Mapping(source = "versionStatusCounters", target = "status")
38 @Mapping(source = "properties", target = "categoryList")
39 ActivitySpecEntity itemToActivitySpec(Item item);
41 @InheritInverseConfiguration
42 @Mapping(expression = "java(ItemType.ACTIVITYSPEC.name())", target = "type")
43 @Mapping(target = "versionStatusCounters", ignore = true)
44 @Mapping(target = "status", ignore = true)
45 @Mapping(source = "categoryList", target = "properties")
46 void toItem(ActivitySpecEntity activitySpec, @MappingTarget Item retrievedItem);
48 default String versionStatusCountersToStatus(Map<VersionStatus, Integer> versionStatusCounters) {
49 return versionStatusCounters.keySet().stream().findFirst().map(Enum::name).orElse(null);
52 default Map<String, Object> categoriesToProperties(List<String> categories) {
53 Map<String, Object> properties = new HashMap<>();
54 properties.put(CATEGORY_ATTRIBUTE_NAME, categories);
58 default List<String> propertiesToCategories(Map<String, Object> properties) {
59 return (List<String>) properties.get(CATEGORY_ATTRIBUTE_NAME);