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.Mappings;
28 import org.onap.sdc.workflow.persistence.types.ActivitySpecEntity;
29 import org.onap.sdc.workflow.services.ActivitySpecConstant;
30 import org.onap.sdc.workflow.services.impl.ItemType;
31 import org.openecomp.sdc.versioning.dao.types.VersionStatus;
32 import org.openecomp.sdc.versioning.types.Item;
34 @Mapper(componentModel = "spring", imports = {ItemType.class, ActivitySpecConstant.class})
35 public interface ActivitySpecMapper {
37 @Mappings({@Mapping(source = "versionStatusCounters", target = "status"),
38 @Mapping(source = "properties", target = "categoryList")})
39 ActivitySpecEntity itemToActivitySpec(Item item);
41 @InheritInverseConfiguration
42 @Mappings({@Mapping(expression = "java(ItemType.ACTIVITYSPEC.name())", target = "type"),
43 @Mapping(target = "versionStatusCounters", ignore = true), @Mapping(target = "status", ignore = true),
44 @Mapping(source = "categoryList", target = "properties")})
45 Item activitySpecToItem(ActivitySpecEntity activitySpec);
47 default String versionStatusCountersToStatus(Map<VersionStatus, Integer> versionStatusCounters) {
48 return versionStatusCounters.keySet().stream().findFirst().map(Enum::name).orElse(null);
51 default Map<String, Object> categoriesToProperties(List<String> categories) {
52 Map<String, Object> properties = new HashMap<>();
53 properties.put(CATEGORY_ATTRIBUTE_NAME, categories);
57 default List<String> propertiesToCategories(Map<String, Object> properties) {
58 return (List<String>) properties.get(CATEGORY_ATTRIBUTE_NAME);