2062fe273ba48be8b962987c2228b3d0867e0016
[sdc.git] /
1 /*
2  * Copyright © 2016-2018 European Support Limited
3  *
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
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
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
17 package org.openecomp.activityspec.api.rest.mapping;
18
19 import java.util.ArrayList;
20 import org.openecomp.activityspec.be.dao.types.ActivitySpecEntity;
21 import org.openecomp.activityspec.be.datatypes.ActivitySpecParameter;
22 import org.openecomp.activityspec.api.rest.types.ActivitySpecRequestDto;
23 import org.openecomp.sdcrests.mapping.MappingBase;
24
25 import java.util.Objects;
26 import java.util.stream.Collectors;
27
28 public class MapActivitySpecRequestDtoToActivitySpecEntity
29     extends MappingBase<ActivitySpecRequestDto,
30     ActivitySpecEntity> {
31
32   @Override
33   public void doMapping(ActivitySpecRequestDto source, ActivitySpecEntity target) {
34     target.setName(source.getName());
35     target.setDescription(source.getDescription());
36     target.setCategoryList(source.getCategoryList() == null ? new ArrayList<String>()
37         : source.getCategoryList());
38     if (Objects.nonNull(source.getInputParameters())) {
39       target.setInputParameters(source.getInputParameters().stream()
40           .map(activitySpecParameterDto -> new MapDtoToActivityParameter()
41               .applyMapping(activitySpecParameterDto, ActivitySpecParameter.class))
42                 .collect(Collectors.toList()));
43     }
44     if (Objects.nonNull(source.getOutputParameters())) {
45       target.setOutputParameters(source.getOutputParameters().stream()
46           .map(activitySpecParameterDto -> new MapDtoToActivityParameter()
47               .applyMapping(activitySpecParameterDto, ActivitySpecParameter.class))
48           .collect(Collectors.toList()));
49     }
50   }
51 }