com.sinch.sdk.domains.sms.adapters.converters.GroupsDtoConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sinch-sdk-java Show documentation
Show all versions of sinch-sdk-java Show documentation
SDK providing a Java API for the Sinch REST APIs.
package com.sinch.sdk.domains.sms.adapters.converters;
import com.sinch.sdk.core.utils.DateUtil;
import com.sinch.sdk.domains.sms.models.Group;
import com.sinch.sdk.domains.sms.models.GroupAutoUpdate;
import com.sinch.sdk.domains.sms.models.GroupAutoUpdateKeyword;
import com.sinch.sdk.domains.sms.models.dto.v1.AddKeywordDto;
import com.sinch.sdk.domains.sms.models.dto.v1.ApiGroupAutoUpdateDto;
import com.sinch.sdk.domains.sms.models.dto.v1.ApiGroupDto;
import com.sinch.sdk.domains.sms.models.dto.v1.ApiGroupListDto;
import com.sinch.sdk.domains.sms.models.dto.v1.CreateGroupResponseDto;
import com.sinch.sdk.domains.sms.models.dto.v1.GroupAutoUpdateDto;
import com.sinch.sdk.domains.sms.models.dto.v1.GroupObjectAutoUpdateDto;
import com.sinch.sdk.domains.sms.models.dto.v1.GroupObjectAutoUpdateRemoveDto;
import com.sinch.sdk.domains.sms.models.dto.v1.GroupObjectDto;
import com.sinch.sdk.domains.sms.models.dto.v1.RemoveKeywordDto;
import com.sinch.sdk.domains.sms.models.dto.v1.ReplaceGroupRequestDto;
import com.sinch.sdk.domains.sms.models.dto.v1.UpdateGroupRequestAutoUpdateAddDto;
import com.sinch.sdk.domains.sms.models.dto.v1.UpdateGroupRequestAutoUpdateDto;
import com.sinch.sdk.domains.sms.models.dto.v1.UpdateGroupRequestAutoUpdateRemoveDto;
import com.sinch.sdk.domains.sms.models.dto.v1.UpdateGroupRequestDto;
import com.sinch.sdk.domains.sms.models.requests.GroupAutoUpdateKeywordRequestParameters;
import com.sinch.sdk.domains.sms.models.requests.GroupAutoUpdateRequestParameters;
import com.sinch.sdk.domains.sms.models.requests.GroupCreateRequestParameters;
import com.sinch.sdk.domains.sms.models.requests.GroupReplaceRequestParameters;
import com.sinch.sdk.domains.sms.models.requests.GroupUpdateRequestParameters;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Set;
import java.util.stream.Collectors;
public class GroupsDtoConverter {
public static Group convert(CreateGroupResponseDto dto) {
return Group.builder()
.setId(dto.getId())
.setName(dto.getName())
.setSize(dto.getSize())
.setCreatedAt(DateUtil.toInstant(dto.getCreatedAt()))
.setModifiedAt(DateUtil.toInstant(dto.getModifiedAt()))
.setChildGroupIds(convertChildGroups(dto.getChildGroups()))
.setAutoUpdate(convert(dto.getAutoUpdate()))
.build();
}
public static GroupObjectDto convert(GroupCreateRequestParameters client) {
GroupObjectDto dto = new GroupObjectDto();
client.getName().ifPresent(dto::name);
client.getMembers().ifPresent(f -> dto.members(new ArrayList<>(f)));
client.getChildGroupIds().ifPresent(f -> dto.childGroups(new ArrayList<>(f)));
client.getAutoUpdate().ifPresent(f -> dto.autoUpdate(GroupsDtoConverter.convert(f)));
return dto;
}
public static Collection convert(ApiGroupListDto dto) {
Collection collection = dto.getGroups();
Collection pageContent = new ArrayList<>();
if (null != collection) {
for (ApiGroupDto innerDto : collection) {
Group convert = convert(innerDto);
pageContent.add(convert);
}
}
return pageContent;
}
public static ReplaceGroupRequestDto convert(GroupReplaceRequestParameters client) {
ReplaceGroupRequestDto dto = new ReplaceGroupRequestDto();
client.getName().ifPresent(dto::name);
client.getMembers().ifPresent(f -> dto.members(new ArrayList<>(f)));
return dto;
}
public static UpdateGroupRequestDto convert(GroupUpdateRequestParameters client) {
UpdateGroupRequestDto dto = new UpdateGroupRequestDto();
client.getName().ifPresent(dto::name);
client.getAdd().ifPresent(f -> dto.add(new ArrayList<>(f)));
client.getRemove().ifPresent(f -> dto.remove(new ArrayList<>(f)));
client.getAddFromGroup().ifPresent(dto::addFromGroup);
client.getRemoveFromGroup().ifPresent(dto::removeFromGroup);
client.getAutoUpdate().ifPresent(f -> dto.autoUpdate(GroupsDtoConverter.convertForUpdate(f)));
return dto;
}
private static Group convert(ApiGroupDto dto) {
return Group.builder()
.setId(dto.getId())
.setName(dto.getName())
.setSize(dto.getSize())
.setCreatedAt(DateUtil.toInstant(dto.getCreatedAt()))
.setModifiedAt(DateUtil.toInstant(dto.getModifiedAt()))
.setChildGroupIds(convertChildGroups(dto.getChildGroups()))
.setAutoUpdate(convert(dto.getAutoUpdate()))
.build();
}
private static Collection convertChildGroups(Set
© 2015 - 2024 Weber Informatics LLC | Privacy Policy