|
60 | 60 | import java.time.format.DateTimeFormatter; |
61 | 61 | import java.util.Collections; |
62 | 62 | import java.util.Comparator; |
| 63 | +import java.util.HashMap; |
63 | 64 | import java.util.List; |
64 | 65 | import java.util.Map; |
65 | 66 | import java.util.NoSuchElementException; |
@@ -280,109 +281,63 @@ public ResponseEntity<Map<String, ConnectionStatusResponse>> connectionStatus(@R |
280 | 281 | return ResponseEntity.ok(Map.of()); |
281 | 282 | } |
282 | 283 | Organisation organisation = optionalOrganisation.get(); |
283 | | - if (connectionStatus.connected()) { |
284 | | - Map<String, ConnectionStatusResponse> responseMap = userRepository.findByOrganisation(organisation) |
285 | | - .stream() |
286 | | - .collect(Collectors.toMap( |
287 | | - user -> user.getCrmContactId(), |
288 | | - user -> new ConnectionStatusResponse( |
289 | | - user.getCrmContactId(), |
290 | | - user.getGivenName(), |
291 | | - user.getMiddleName(), |
292 | | - user.getFamilyName(), |
293 | | - user.getName(), |
294 | | - user.getEmail(), |
295 | | - "", |
296 | | - Map.of( |
297 | | - "id", 0, |
298 | | - "abbrev", organisation.getCrmOrganisationAbbrevation(), |
299 | | - "name", organisation.getCrmOrganisationName(), |
300 | | - "oid", 0, |
301 | | - "guid", organisation.getCrmOrganisationId() |
302 | | - ), |
303 | | - Map.of( |
304 | | - "uid", user.getUid(), |
305 | | - "idp", user.getSchacHomeOrganization() |
306 | | - ), |
307 | | - CRMStatusCode.Paired.getStatus(), |
308 | | - CRMStatusCode.Paired.getStatusCode() |
309 | | - ), |
310 | | - (existing, replacement) -> replacement |
311 | | - )); |
312 | | - if (LOG.isDebugEnabled()) { |
313 | | - LOG.debug(String.format("/crm/api/v1/profiles connectionStatus.connected is true. Returning %s", responseMap)); |
314 | | - } |
315 | | - return ResponseEntity.ok(responseMap); |
316 | | - } else { |
317 | | - Map<String, ConnectionStatusResponse> responseMap = invitationRepository |
318 | | - .findByCrmOrganisationIdAndStatus(crmOrganisationId, Status.OPEN) |
319 | | - .stream() |
320 | | - .collect(Collectors.toMap( |
321 | | - invitation -> invitation.getCrmContactId(), |
322 | | - invitation -> { |
323 | | - CRMStatusCode crmStatusCode = crmStatusCode(invitation); |
324 | | - return userRepository.findByCrmContactIdAndOrganisation(invitation.getCrmContactId(), organisation) |
325 | | - .map(user -> new ConnectionStatusResponse( |
326 | | - invitation.getCrmContactId(), |
327 | | - user.getGivenName(), |
328 | | - user.getMiddleName(), |
329 | | - user.getFamilyName(), |
330 | | - user.getName(), |
331 | | - user.getEmail(), |
332 | | - "", |
333 | | - Map.of( |
334 | | - "id", 0, |
335 | | - "abbrev", organisation.getCrmOrganisationAbbrevation(), |
336 | | - "name", organisation.getCrmOrganisationName(), |
337 | | - "oid", 0, |
338 | | - "guid", organisation.getCrmOrganisationId() |
339 | | - ), |
340 | | - Map.of( |
341 | | - "uid", resolveUserUid(user), |
342 | | - "idp", user.getSchacHomeOrganization() |
343 | | - ), |
344 | | - crmStatusCode.getStatus(), |
345 | | - crmStatusCode.getStatusCode() |
346 | | - )).orElse(new ConnectionStatusResponse( |
347 | | - invitation.getCrmContactId(), |
348 | | - null, |
349 | | - null, |
350 | | - null, |
351 | | - null, |
352 | | - invitation.getEmail(), |
353 | | - "", |
354 | | - Map.of( |
355 | | - "id", 0, |
356 | | - "abbrev", organisation.getCrmOrganisationAbbrevation(), |
357 | | - "name", organisation.getCrmOrganisationName(), |
358 | | - "oid", 0, |
359 | | - "guid", organisation.getCrmOrganisationId() |
360 | | - ), |
361 | | - Map.of(), |
362 | | - crmStatusCode.getStatus(), |
363 | | - crmStatusCode.getStatusCode() |
364 | | - )); |
365 | | - }, |
366 | | - (existing, replacement) -> replacement |
367 | | - )); |
368 | | - if (LOG.isDebugEnabled()) { |
369 | | - LOG.debug(String.format("/crm/api/v1/profiles connectionStatus.connected is false. Returning %s", responseMap)); |
370 | | - } |
371 | | - return ResponseEntity.ok(responseMap); |
372 | | - } |
373 | | - } |
374 | | - |
375 | | - private String resolveUserUid(User user) { |
376 | | - String uid = user.getUid(); |
377 | | - if (StringUtils.hasText(uid)) { |
378 | | - return uid; |
| 284 | + Map<String, ConnectionStatusResponse> responseMap = new HashMap<>(); |
| 285 | + userRepository.findByOrganisation(organisation) |
| 286 | + .forEach(user -> responseMap.put( |
| 287 | + user.getCrmContactId(), |
| 288 | + new ConnectionStatusResponse( |
| 289 | + user.getCrmContactId(), |
| 290 | + user.getGivenName(), |
| 291 | + user.getMiddleName(), |
| 292 | + user.getFamilyName(), |
| 293 | + user.getName(), |
| 294 | + user.getEmail(), |
| 295 | + "", |
| 296 | + Map.of( |
| 297 | + "id", 0, |
| 298 | + "abbrev", organisation.getCrmOrganisationAbbrevation(), |
| 299 | + "name", organisation.getCrmOrganisationName(), |
| 300 | + "oid", 0, |
| 301 | + "guid", organisation.getCrmOrganisationId() |
| 302 | + ), |
| 303 | + Map.of( |
| 304 | + "uid", user.getUid(), |
| 305 | + "idp", user.getSchacHomeOrganization() |
| 306 | + ), |
| 307 | + CRMStatusCode.Paired.getStatus(), |
| 308 | + CRMStatusCode.Paired.getStatusCode() |
| 309 | + ) |
| 310 | + ) |
| 311 | + ); |
| 312 | + |
| 313 | + invitationRepository |
| 314 | + .findByCrmOrganisationIdAndStatus(crmOrganisationId, Status.OPEN) |
| 315 | + .forEach(invitation -> responseMap.put( |
| 316 | + invitation.getCrmContactId(), |
| 317 | + new ConnectionStatusResponse( |
| 318 | + invitation.getCrmContactId(), |
| 319 | + null, |
| 320 | + null, |
| 321 | + null, |
| 322 | + null, |
| 323 | + invitation.getEmail(), |
| 324 | + "", |
| 325 | + Map.of( |
| 326 | + "id", 0, |
| 327 | + "abbrev", organisation.getCrmOrganisationAbbrevation(), |
| 328 | + "name", organisation.getCrmOrganisationName(), |
| 329 | + "oid", 0, |
| 330 | + "guid", organisation.getCrmOrganisationId() |
| 331 | + ), |
| 332 | + Map.of(), |
| 333 | + CRMStatusCode.InProcess.getStatus(), |
| 334 | + CRMStatusCode.InProcess.getStatusCode() |
| 335 | + ) |
| 336 | + )); |
| 337 | + if (LOG.isDebugEnabled()) { |
| 338 | + LOG.debug(String.format("/crm/api/v1/profiles Returning %s", responseMap)); |
379 | 339 | } |
380 | | - String sub = user.getSub(); |
381 | | - return sub.substring(sub.lastIndexOf(":") + 1); |
382 | | - } |
383 | | - |
384 | | - private CRMStatusCode crmStatusCode(Invitation invitation) { |
385 | | - return invitation.getExpiryDate().isBefore(Instant.now()) ? CRMStatusCode.NotPaired : CRMStatusCode.InProcess; |
| 340 | + return ResponseEntity.ok(responseMap); |
386 | 341 | } |
387 | 342 |
|
388 | 343 | @PostMapping(value = "/crm/api/v1/invite/resend", produces = MediaType.APPLICATION_JSON_VALUE) |
|
0 commit comments