diff options
Diffstat (limited to 'services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/mapping')
6 files changed, 239 insertions, 0 deletions
diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/mapping/MapActivityParameterToDto.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/mapping/MapActivityParameterToDto.java new file mode 100644 index 0000000000..bd644ff4d6 --- /dev/null +++ b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/mapping/MapActivityParameterToDto.java @@ -0,0 +1,31 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.openecomp.activityspec.api.rest.mapping; + +import org.openecomp.activityspec.be.datatypes.ActivitySpecParameter; +import org.openecomp.activityspec.api.rest.types.ActivitySpecParameterDto; +import org.openecomp.sdcrests.mapping.MappingBase; + +public class MapActivityParameterToDto extends MappingBase<ActivitySpecParameter, + ActivitySpecParameterDto> { + @Override + public void doMapping(ActivitySpecParameter source, ActivitySpecParameterDto target) { + target.setName(source.getName()); + target.setType(source.getType()); + target.setValue(source.getValue()); + } +} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/mapping/MapActivitySpecRequestDtoToActivitySpecEntity.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/mapping/MapActivitySpecRequestDtoToActivitySpecEntity.java new file mode 100644 index 0000000000..2062fe273b --- /dev/null +++ b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/mapping/MapActivitySpecRequestDtoToActivitySpecEntity.java @@ -0,0 +1,51 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.openecomp.activityspec.api.rest.mapping; + +import java.util.ArrayList; +import org.openecomp.activityspec.be.dao.types.ActivitySpecEntity; +import org.openecomp.activityspec.be.datatypes.ActivitySpecParameter; +import org.openecomp.activityspec.api.rest.types.ActivitySpecRequestDto; +import org.openecomp.sdcrests.mapping.MappingBase; + +import java.util.Objects; +import java.util.stream.Collectors; + +public class MapActivitySpecRequestDtoToActivitySpecEntity + extends MappingBase<ActivitySpecRequestDto, + ActivitySpecEntity> { + + @Override + public void doMapping(ActivitySpecRequestDto source, ActivitySpecEntity target) { + target.setName(source.getName()); + target.setDescription(source.getDescription()); + target.setCategoryList(source.getCategoryList() == null ? new ArrayList<String>() + : source.getCategoryList()); + if (Objects.nonNull(source.getInputParameters())) { + target.setInputParameters(source.getInputParameters().stream() + .map(activitySpecParameterDto -> new MapDtoToActivityParameter() + .applyMapping(activitySpecParameterDto, ActivitySpecParameter.class)) + .collect(Collectors.toList())); + } + if (Objects.nonNull(source.getOutputParameters())) { + target.setOutputParameters(source.getOutputParameters().stream() + .map(activitySpecParameterDto -> new MapDtoToActivityParameter() + .applyMapping(activitySpecParameterDto, ActivitySpecParameter.class)) + .collect(Collectors.toList())); + } + } +} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/mapping/MapActivitySpecToActivitySpecCreateResponse.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/mapping/MapActivitySpecToActivitySpecCreateResponse.java new file mode 100644 index 0000000000..13c881404f --- /dev/null +++ b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/mapping/MapActivitySpecToActivitySpecCreateResponse.java @@ -0,0 +1,32 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.openecomp.activityspec.api.rest.mapping; + +import java.util.Objects; +import org.openecomp.activityspec.be.dao.types.ActivitySpecEntity; +import org.openecomp.activityspec.api.rest.types.ActivitySpecCreateResponse; +import org.openecomp.sdcrests.mapping.MappingBase; + +public class MapActivitySpecToActivitySpecCreateResponse extends MappingBase<ActivitySpecEntity, + ActivitySpecCreateResponse> { + + @Override + public void doMapping(ActivitySpecEntity source, ActivitySpecCreateResponse target) { + target.setId(source.getId()); + target.setVersionId(Objects.nonNull(source.getVersion()) ? source.getVersion().getId() : null); + } +} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/mapping/MapActivitySpecToActivitySpecGetResponse.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/mapping/MapActivitySpecToActivitySpecGetResponse.java new file mode 100644 index 0000000000..25e0f6e9c4 --- /dev/null +++ b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/mapping/MapActivitySpecToActivitySpecGetResponse.java @@ -0,0 +1,49 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.openecomp.activityspec.api.rest.mapping; + +import org.openecomp.activityspec.be.dao.types.ActivitySpecEntity; +import org.openecomp.activityspec.api.rest.types.ActivitySpecGetResponse; +import org.openecomp.activityspec.api.rest.types.ActivitySpecParameterDto; +import org.openecomp.sdcrests.mapping.MappingBase; + +import java.util.Objects; +import java.util.stream.Collectors; + +public class MapActivitySpecToActivitySpecGetResponse extends MappingBase<ActivitySpecEntity, + ActivitySpecGetResponse> { + + @Override + public void doMapping(ActivitySpecEntity source, ActivitySpecGetResponse target) { + target.setName(source.getName()); + target.setDescription(source.getDescription()); + target.setCategoryList(source.getCategoryList()); + if (Objects.nonNull(source.getInputParameters())) { + target.setInputParameters(source.getInputParameters().stream().map( + activitySpecParameter -> new MapActivityParameterToDto() + .applyMapping(activitySpecParameter, ActivitySpecParameterDto + .class)).collect(Collectors.toList())); + } + if (Objects.nonNull(source.getOutputParameters())) { + target.setOutputParameters(source.getOutputParameters().stream().map( + activitySpecParameter -> new MapActivityParameterToDto() + .applyMapping(activitySpecParameter, ActivitySpecParameterDto + .class)).collect(Collectors.toList())); + } + target.setStatus(source.getStatus()); + } +} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/mapping/MapDtoToActivityParameter.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/mapping/MapDtoToActivityParameter.java new file mode 100644 index 0000000000..ccffaead76 --- /dev/null +++ b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/mapping/MapDtoToActivityParameter.java @@ -0,0 +1,31 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.openecomp.activityspec.api.rest.mapping; + +import org.openecomp.activityspec.be.datatypes.ActivitySpecParameter; +import org.openecomp.activityspec.api.rest.types.ActivitySpecParameterDto; +import org.openecomp.sdcrests.mapping.MappingBase; + +public class MapDtoToActivityParameter extends MappingBase<ActivitySpecParameterDto, + ActivitySpecParameter> { + @Override + public void doMapping(ActivitySpecParameterDto source, ActivitySpecParameter target) { + target.setName(source.getName()); + target.setType(source.getType()); + target.setValue(source.getValue()); + } +} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/mapping/MapItemToListResponseDto.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/mapping/MapItemToListResponseDto.java new file mode 100644 index 0000000000..c85d5af427 --- /dev/null +++ b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/mapping/MapItemToListResponseDto.java @@ -0,0 +1,45 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.openecomp.activityspec.api.rest.mapping; + +import org.openecomp.activityspec.api.rest.types.ActivitySpecListResponseDto; +import org.openecomp.sdc.versioning.dao.types.VersionStatus; +import org.openecomp.sdc.versioning.types.Item; +import org.openecomp.sdcrests.mapping.MappingBase; + +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; + +import static org.openecomp.activityspec.utils.ActivitySpecConstant.CATEGORY_ATTRIBUTE_NAME; + +public class MapItemToListResponseDto extends MappingBase<Item, ActivitySpecListResponseDto> { + @Override + public void doMapping(Item source, ActivitySpecListResponseDto target) { + target.setId(source.getId()); + target.setName(source.getName()); + target.setCategoryList((List<String>) source.getProperties().get( + CATEGORY_ATTRIBUTE_NAME)); + final Map<VersionStatus, Integer> versionStatusCounters = source.getVersionStatusCounters(); + if (Objects.nonNull(versionStatusCounters) && !versionStatusCounters.isEmpty()) { + final Set<VersionStatus> versionStatuses = versionStatusCounters.keySet(); + target.setStatus(versionStatuses.stream().findFirst().isPresent() + ? versionStatuses.stream().findFirst().get().name() : null); + } + } +} |