use of de.symeda.sormas.api.sormastosormas.sharerequest.ShareRequestDataType in project SORMAS-Project by hzi-braunschweig.
the class ImmunizationFacadeEjb method syncSharesAsync.
@RolesAllowed(UserRight._IMMUNIZATION_EDIT)
public void syncSharesAsync(Immunization immunization) {
// sync case/contact/event this immunization was shared with
List<DataHelper.Pair<ShareRequestDataType, ShareTreeCriteria>> syncParams = immunization.getSormasToSormasShares().stream().map(immunizationShare -> ShareInfoHelper.getLatestAcceptedRequest(immunizationShare.getRequests().stream()).orElse(null)).filter(Objects::nonNull).map(ShareRequestInfo::getShares).flatMap(Collection::stream).map(s -> {
if (s.getCaze() != null) {
return new DataHelper.Pair<>(ShareRequestDataType.CASE, new ShareTreeCriteria(s.getCaze().getUuid()));
}
if (s.getContact() != null) {
return new DataHelper.Pair<>(ShareRequestDataType.CONTACT, new ShareTreeCriteria(s.getContact().getUuid()));
}
if (s.getEvent() != null) {
return new DataHelper.Pair<>(ShareRequestDataType.EVENT, new ShareTreeCriteria(s.getContact().getUuid()));
}
return null;
}).filter(Objects::nonNull).collect(Collectors.toList());
executorService.schedule(() -> {
try {
syncParams.forEach((p -> {
if (p.getElement0() == ShareRequestDataType.CASE) {
sormasToSormasCaseFacade.syncShares(p.getElement1());
}
if (p.getElement0() == ShareRequestDataType.CONTACT) {
sormasToSormasContactFacade.syncShares(p.getElement1());
}
if (p.getElement0() == ShareRequestDataType.EVENT) {
sormasToSormasEventFacadeEjbLocal.syncShares(p.getElement1());
}
}));
} catch (Exception e) {
logger.error("Failed to sync shares of immunization", e);
}
}, 5, TimeUnit.SECONDS);
}
Aggregations