@Override
public EndpointAttachResponse attachEndpoint(EndpointProfileDto profile,
EndpointAttachRequest endpointAttachRequest) {
EndpointAttachResponse response = new EndpointAttachResponse();
response.setRequestId(endpointAttachRequest.getRequestId());
response.setResult(SyncStatus.FAILURE);
String endpointUserId = profile.getEndpointUserId();
if (isNotEmpty(endpointUserId)) {
try {
EndpointProfileDto attachedEndpoint = endpointService.attachEndpointToUser(
endpointUserId, endpointAttachRequest.getEndpointAccessToken());
response.setResult(SyncStatus.SUCCESS);
response.setEndpointKeyHash(Base64Util.encode(attachedEndpoint.getEndpointKeyHash()));
} catch (DatabaseProcessingException ex) {
LOG.warn("[{}] failed to attach endpoint with access token {} and "
+ "user {}, exception catched: {}",
Base64Util.encode(profile.getEndpointKeyHash()),
endpointAttachRequest.getEndpointAccessToken(),
profile.getEndpointUserId(),
ex);
}
} else {
LOG.warn("[{}] received attach endpoint request, but there is no user to attach.",
Base64Util.encode(profile.getEndpointKeyHash()));
}
return response;
}