Code review comment: Currently raw ID is generated based on user ID and cloud environment only. Under some circumstances, rawId from `CommunicationIdentifierModel` could be a totally different value (like `123abc`), which could not be generated. I'm not sure what expected behaviour is, but not setting a rawID explicitly will change the previous logic.

Code before review:
public static CommunicationIdentifier convert(CommunicationIdentifierModel identifier) {
if (identifier == null) {
return null;
}
assertSingleType(identifier);
String rawId = identifier.getRawId();
CommunicationIdentifierModelKind kind = identifier.getKind();
if (kind != null) {
if (kind == CommunicationIdentifierModelKind.COMMUNICATION_USER
&& identifier.getCommunicationUser() != null) {
Objects.requireNonNull(identifier.getCommunicationUser().getId());
return new CommunicationUserIdentifier(identifier.getCommunicationUser().getId());
}
if (kind == CommunicationIdentifierModelKind.PHONE_NUMBER
&& identifier.getPhoneNumber() != null) {
PhoneNumberIdentifierModel phoneNumberModel = identifier.getPhoneNumber();
Objects.requireNonNull(phoneNumberModel.getValue());
return new PhoneNumberIdentifier(phoneNumberModel.getValue()).setRawId(rawId);
}
if (kind == CommunicationIdentifierModelKind.MICROSOFT_TEAMS_USER
&& identifier.getMicrosoftTeamsUser() != null) {
MicrosoftTeamsUserIdentifierModel teamsUserIdentifierModel = identifier.getMicrosoftTeamsUser();
Objects.requireNonNull(teamsUserIdentifierModel.getUserId());
Objects.requireNonNull(teamsUserIdentifierModel.getCloud());
Objects.requireNonNull(rawId);
return new MicrosoftTeamsUserIdentifier(teamsUserIdentifierModel.getUserId(),
teamsUserIdentifierModel.isAnonymous())
.setRawId(rawId)
.setCloudEnvironment(CommunicationCloudEnvironment
.fromString(teamsUserIdentifierModel.getCloud().toString()));
}
Objects.requireNonNull(rawId);
return new UnknownIdentifier(rawId);
}
if (identifier.getCommunicationUser() != null) {
Objects.requireNonNull(identifier.getCommunicationUser().getId());
return new CommunicationUserIdentifier(identifier.getCommunicationUser().getId());
}
if (identifier.getPhoneNumber() != null) {
PhoneNumberIdentifierModel phoneNumberModel = identifier.getPhoneNumber();
Objects.requireNonNull(phoneNumberModel.getValue());
return new PhoneNumberIdentifier(phoneNumberModel.getValue()).setRawId(rawId);
}
if (identifier.getMicrosoftTeamsUser() != null) {
MicrosoftTeamsUserIdentifierModel teamsUserIdentifierModel = identifier.getMicrosoftTeamsUser();
Objects.requireNonNull(teamsUserIdentifierModel.getUserId());
Objects.requireNonNull(teamsUserIdentifierModel.getCloud());
Objects.requireNonNull(rawId);
return new MicrosoftTeamsUserIdentifier(teamsUserIdentifierModel.getUserId(),
teamsUserIdentifierModel.isAnonymous())
.setRawId(rawId)
.setCloudEnvironment(CommunicationCloudEnvironment
.fromString(teamsUserIdentifierModel.getCloud().toString()));
}
Objects.requireNonNull(rawId);
return new UnknownIdentifier(rawId);
}

Line under review: .setRawId(rawId)

Code after addressing the review:
public static CommunicationIdentifier convert(CommunicationIdentifierModel identifier) {
if (identifier == null) {
return null;
}
assertSingleType(identifier);
String rawId = identifier.getRawId();
CommunicationIdentifierModelKind kind = (identifier.getKind() != null) ? identifier.getKind() : extractKind(identifier);
if (kind == CommunicationIdentifierModelKind.COMMUNICATION_USER
&& identifier.getCommunicationUser() != null) {
Objects.requireNonNull(identifier.getCommunicationUser().getId(),
"'ID' of the CommunicationIdentifierModel cannot be null.");
return new CommunicationUserIdentifier(identifier.getCommunicationUser().getId());
}
if (kind == CommunicationIdentifierModelKind.PHONE_NUMBER
&& identifier.getPhoneNumber() != null) {
String phoneNumber = identifier.getPhoneNumber().getValue();
Objects.requireNonNull(phoneNumber, "'PhoneNumber' of the CommunicationIdentifierModel cannot be null.");
Objects.requireNonNull(rawId, "'RawID' of the CommunicationIdentifierModel cannot be null.");
return new PhoneNumberIdentifier(phoneNumber).setRawId(rawId);
}
if (kind == CommunicationIdentifierModelKind.MICROSOFT_TEAMS_USER
&& identifier.getMicrosoftTeamsUser() != null) {
MicrosoftTeamsUserIdentifierModel teamsUserIdentifierModel = identifier.getMicrosoftTeamsUser();
Objects.requireNonNull(teamsUserIdentifierModel.getUserId(), "'UserID' of the CommunicationIdentifierModel cannot be null.");
Objects.requireNonNull(teamsUserIdentifierModel.getCloud(), "'Cloud' of the CommunicationIdentifierModel cannot be null.");
Objects.requireNonNull(rawId, "'RawID' of the CommunicationIdentifierModel cannot be null.");
return new MicrosoftTeamsUserIdentifier(teamsUserIdentifierModel.getUserId(),
teamsUserIdentifierModel.isAnonymous())
.setRawId(rawId)
.setCloudEnvironment(CommunicationCloudEnvironment
.fromString(teamsUserIdentifierModel.getCloud().toString()));
}
Objects.requireNonNull(rawId, "'RawID' of the CommunicationIdentifierModel cannot be null.");
return new UnknownIdentifier(rawId);
}