diff --git a/microsoft-integration/admin-tool/src/main/java/org/sakaiproject/microsoft/controller/MainController.java b/microsoft-integration/admin-tool/src/main/java/org/sakaiproject/microsoft/controller/MainController.java index 5584108a4ec..46cc9a0f82a 100644 --- a/microsoft-integration/admin-tool/src/main/java/org/sakaiproject/microsoft/controller/MainController.java +++ b/microsoft-integration/admin-tool/src/main/java/org/sakaiproject/microsoft/controller/MainController.java @@ -49,6 +49,7 @@ import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; @@ -138,16 +139,18 @@ public String loadItems( List list; Map map; + ZonedDateTime fromDate = null; + ZonedDateTime toDate = null; + boolean filterByDate = !requestBody.getFromDate().isEmpty() && !requestBody.getToDate().isEmpty(); - if(requestBody.getFromDate().isEmpty() || requestBody.getToDate().isEmpty()) { - list = microsoftSynchronizationService.getFilteredSiteSynchronizations(true, SakaiSiteFilter.builder().siteProperty(requestBody.getSiteProperty()).build(), null, null); - } else { - ZonedDateTime fromDate = LocalDate.parse(requestBody.getFromDate(), DateTimeFormatter.ofPattern("yyyy-MM-dd")).atStartOfDay(ZoneOffset.UTC); - ZonedDateTime toDate = LocalDate.parse(requestBody.getToDate(), DateTimeFormatter.ofPattern("yyyy-MM-dd")).atStartOfDay(ZoneOffset.UTC); - list = microsoftSynchronizationService.getFilteredSiteSynchronizations(true, SakaiSiteFilter.builder().siteProperty(requestBody.getSiteProperty()).build(), fromDate, toDate); + if (filterByDate) { + fromDate = LocalDate.parse(requestBody.getFromDate(), DateTimeFormatter.ofPattern("yyyy-MM-dd")).atStartOfDay(ZoneOffset.UTC); + toDate = LocalDate.parse(requestBody.getToDate(), DateTimeFormatter.ofPattern("yyyy-MM-dd")).atStartOfDay(ZoneOffset.UTC); } - map = microsoftCommonService.getTeamsBySites(list); + list = microsoftSynchronizationService.getFilteredSiteSynchronizations(true, SakaiSiteFilter.builder().siteProperty(requestBody.getSiteProperty()).build(), fromDate, toDate); + + map = microsoftCommonService.retrieveCacheTeams(); //filter elements if (StringUtils.isNotBlank(search)) { @@ -282,6 +285,22 @@ public String runSiteSynchronization(@PathVariable String id, Model model) throw return ROW_SITE_SYNCH_FRAGMENT; } + + //called by AJAX - returns FRAGMENT + @GetMapping(value = {"/refreshSite/{id}"}) + public String refreshRow(@PathVariable String id, Model model) throws Exception { + SiteSynchronization ss = microsoftSynchronizationService.getSiteSynchronization(SiteSynchronization.builder().id(id).build(), true); + + if (ss != null) { + Map teams = model.getAttribute("teamsMap") == null ? new HashMap<>() : (Map) model.getAttribute("teamsMap"); + teams.put(ss.getTeamId(), microsoftCommonService.getTeam(ss.getTeamId(), true)); + model.addAttribute("row", ss); + model.addAttribute("teamsMap", teams); + } + + return ROW_SITE_SYNCH_FRAGMENT; + } + //called by AJAX - returns JSON @GetMapping(path = {"/setForced-siteSynchronization/{id}"}, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody diff --git a/microsoft-integration/admin-tool/src/main/java/org/sakaiproject/microsoft/controller/auxiliar/MainSessionBean.java b/microsoft-integration/admin-tool/src/main/java/org/sakaiproject/microsoft/controller/auxiliar/MainSessionBean.java index 794c10b5fc3..e87e4ef148c 100644 --- a/microsoft-integration/admin-tool/src/main/java/org/sakaiproject/microsoft/controller/auxiliar/MainSessionBean.java +++ b/microsoft-integration/admin-tool/src/main/java/org/sakaiproject/microsoft/controller/auxiliar/MainSessionBean.java @@ -30,6 +30,6 @@ public class MainSessionBean { private Integer pageSize = DEFAULT_PAGE_SIZE; private String search; private String siteProperty = ""; - private String fromDate = LocalDate.of(LocalDate.now().getMonthValue() >= 7 ? LocalDate.now().getYear() : LocalDate.now().getYear() - 1, Calendar.AUGUST, 15).toString(); - private String toDate = LocalDate.of(LocalDate.now().getMonthValue() >= 7 ? LocalDate.now().getYear() + 1 : LocalDate.now().getYear(), Calendar.AUGUST, 15).toString(); + private String fromDate = ""; + private String toDate = ""; } diff --git a/microsoft-integration/admin-tool/src/main/resources/Messages.properties b/microsoft-integration/admin-tool/src/main/resources/Messages.properties index 188d94d8ce8..7d49fb50f47 100644 --- a/microsoft-integration/admin-tool/src/main/resources/Messages.properties +++ b/microsoft-integration/admin-tool/src/main/resources/Messages.properties @@ -57,6 +57,7 @@ to=To filter_by_period=Filter by period: user_details=ID: {0}\nName: {1} {2}\nEmail: {3} filters=Filters ({0}) +clean_filters=Clean creation.status_started=Process started creation.status_create=Creating team's channels... diff --git a/microsoft-integration/admin-tool/src/main/resources/Messages_ca.properties b/microsoft-integration/admin-tool/src/main/resources/Messages_ca.properties index 12fd9f4f8aa..a876584a297 100644 --- a/microsoft-integration/admin-tool/src/main/resources/Messages_ca.properties +++ b/microsoft-integration/admin-tool/src/main/resources/Messages_ca.properties @@ -1,12 +1,12 @@ # Common messages -common_danger= Necessites permisos d\u0027administrador per utilitzar aquesta eina, per favor contacte amb el seu Administrador +common_danger= Necessites permisos d\u2019administrador per utilitzar aquesta eina, per favor contacte amb el seu Administrador # Menu messages menu_main = Administrador menu_new = Nou -menu_new.title= Crear una nova sincronitzaci\u00F3 de l\u0027espai +menu_new.title= Crear una nova sincronitzaci\u00F3 de l\u2019espai menu_edit = Editar -menu_edit.title = Editar la sincronitzaci\u00F3 de l\u0027espai +menu_edit.title = Editar la sincronitzaci\u00F3 de l\u2019espai menu_config = Configuraci\u00F3 menu_config.title = Editar la configuraci\u00F3 de Microsoft menu_credentials = Credencials @@ -57,6 +57,7 @@ to=Fins a filter_by_period=Filtrar per per\u00EDode: user_details=ID: {0}\nNom: {1} {2}\nEmail: {3} filters=Filtres ({0}) +clean_filters=Netejar creation.status_started=Proc\u00E9s inicialitzat creation.status_create=Creant canals dels teams... @@ -64,7 +65,7 @@ creation.status_bind=Vinculant canals existents dels teams... creation.status_finished=Proc\u00E9s finalitzat ​ #Index -index_title= Eina d\u0027Administrador de Microsoft +index_title= Eina d\u2019Administrador de Microsoft index.status_updated_at= Estat actualitzat al: {0} index.status_not_date= Estat no actualitzat index.run_updated_at= \u00DAltima execuci\u00F3: {0} @@ -91,9 +92,9 @@ index.end_date = Data fi #Auto-Config autoconfig_title= Auto-Configuraci\u00F3 autoconfig.count_sites= N\u00BA (filtered) espai disponibles -autoconfig.count_teams= N\u00BA disponible d\u0027equips -autoconfig.count_link= N\u00BA d\u0027espais i equips vinculats -autoconfig.count_new= N\u00BA d\u0027equips nous +autoconfig.count_teams= N\u00BA disponible d\u2019equips +autoconfig.count_link= N\u00BA d\u2019espais i equips vinculats +autoconfig.count_new= N\u00BA d\u2019equips nous autoconfig.confirm_title= Titol autoconfig.confirm_status= Estat autoconfig.confirm_confirm= Confirmar @@ -113,7 +114,7 @@ filter.site_property= Propietats del espai: filter.site_property_info= Valors acceptats:
  • SITE-PROPERTY-NAME
  • SITE-PROPERTY-NAME=VALUE
filter.new_team= Crear un nou Teams filter.new_channel= Crear un nou canal -filter.team_pattern= Patr\u00F3 del nom de l\u0027equip: +filter.team_pattern= Patr\u00F3 del nom de l\u2019equip: #New/Edit site synchronization messages @@ -145,16 +146,16 @@ config_title= Configuraci\u00F3 de Microsoft config.synchronization_config=Configuraci\u00F3 de sincronitzaci\u00F3 config.SYNCH\:CREATE_TEAM=Crear un nou Teams quan es crea un espai a Sakai -config.SYNCH\:DELETE_SYNCH = Elimina la sincronitzaci\u00F3 Espai-Teams quan s\u0027elimina l\u0027espai de Sakai -config.SYNCH\:DELETE_TEAM=Elimina el Teams quan s\u0027elimina l\u0027espai de Sakai (requereix una sincronitzaci\u00F3 espai-Teams v\u00E0lida) -config.SYNCH\:ADD_USER_TO_TEAM=Quan l\u0027usuari s\u0027agrega a un espai, afegiu-lo als Teams relacionats (requereix una sincronitzaci\u00F3 espai-Teams v\u00E0lida) -config.SYNCH\:REMOVE_USER_FROM_TEAM=Quan l\u0027usuari s\u0027elimina de l\u0027espai, suprimiu-lo dels Teams relacionats(requereix una sincronitzaci\u00F3 espai-Teams v\u00E0lida i for\u00E7ada) +config.SYNCH\:DELETE_SYNCH = Elimina la sincronitzaci\u00F3 Espai-Teams quan s\u2019elimina l\u2019espai de Sakai +config.SYNCH\:DELETE_TEAM=Elimina el Teams quan s\u2019elimina l\u2019espai de Sakai (requereix una sincronitzaci\u00F3 espai-Teams v\u00E0lida) +config.SYNCH\:ADD_USER_TO_TEAM=Quan l\u2019usuari s\u2019agrega a un espai, afegiu-lo als Teams relacionats (requereix una sincronitzaci\u00F3 espai-Teams v\u00E0lida) +config.SYNCH\:REMOVE_USER_FROM_TEAM=Quan l\u2019usuari s\u2019elimina de l\u2019espai, suprimiu-lo dels Teams relacionats(requereix una sincronitzaci\u00F3 espai-Teams v\u00E0lida i for\u00E7ada) config.SYNCH\:CREATE_CHANNEL=Crear un nou canal quan es crea un grup a Sakai (requereix una sincronitzaci\u00F3 espai-Teams v\u00E0lida) -config.SYNCH\:DELETE_CHANNEL=Eliminar canal quan s\u0027elimine un grup a Sakai (requereix una sincronitzaci\u00F3 grup-canal v\u00E0lida) -config.SYNCH\:ADD_USER_TO_CHANNEL=Quan s\u0027agrega un usuari a un grup, s\u0027agrega als canals relacionats (requereix una sincronitzaci\u00F3 grup-canal v\u00E0lida) -config.SYNCH\:REMOVE_USER_FROM_CHANNEL=Quan s\u0027elimine un usuari d\u0027un grup, eliminar-lo dels canals relacionats (requereix una sincronitzaci\u00F3 grup-canal v\u00E0lida i for\u00E7ada) -config.SYNCH\:REMOVE_USERS_WHEN_UNPUBLISH = Quan es despublica un espai, s\u0027eliminaran tots els usuaris dels Team(s) i canal(s) relacionats (requereix una sincronitzaci\u00F3 Espai-Teams v\u00E0lida) -config.SYNCH\:CREATE_INVITATION=Si l\u0027usuari de Microsoft no existeis, crea una nova invitaci\u00F3 +config.SYNCH\:DELETE_CHANNEL=Eliminar canal quan s\u2019elimine un grup a Sakai (requereix una sincronitzaci\u00F3 grup-canal v\u00E0lida) +config.SYNCH\:ADD_USER_TO_CHANNEL=Quan s\u2019agrega un usuari a un grup, s\u2019agrega als canals relacionats (requereix una sincronitzaci\u00F3 grup-canal v\u00E0lida) +config.SYNCH\:REMOVE_USER_FROM_CHANNEL=Quan s\u2019elimine un usuari d\u2019un grup, eliminar-lo dels canals relacionats (requereix una sincronitzaci\u00F3 grup-canal v\u00E0lida i for\u00E7ada) +config.SYNCH\:REMOVE_USERS_WHEN_UNPUBLISH = Quan es despublica un espai, s\u2019eliminaran tots els usuaris dels Team(s) i canal(s) relacionats (requereix una sincronitzaci\u00F3 Espai-Teams v\u00E0lida) +config.SYNCH\:CREATE_INVITATION=Si l\u2019usuari de Microsoft no existeis, crea una nova invitaci\u00F3 config.sync_duration=Duraci\u00F3 sincro (mesos): @@ -166,26 +167,26 @@ config.onedrive_enabled=OneDrive habilitat config.collaborative_documents_config=Configuraci\u00F3 dels Documents Col\u00B7laboratius config.max_upload_size=Grand\u00E0ria m\u00E0xima de pujada (MB) -config.id_mapping= Mapeig d\u0027Id -config.sakai_user_id=Id d\u0027usuari de Sakai -config.microsoft_user_id=Id d\u0027usuari de Microsoft -config.map_user_id=Id d\u0027usuari -config.map_user_property=Propietat de l\u0027usuari +config.id_mapping= Mapeig d\u2019Id +config.sakai_user_id=Id d\u2019usuari de Sakai +config.microsoft_user_id=Id d\u2019usuari de Microsoft +config.map_user_id=Id d\u2019usuari +config.map_user_property=Propietat de l\u2019usuari config.map_user_eid=Usuari Eid config.map_user_email=Correu electr\u00F2nic #Credentials messages credentials_title=Credencials de Microsoft credentials.test=Provar credencials -credentials.ok=Credentials d\u0027OK +credentials.ok=Credentials d\u2019OK credentials.authority=Autoritat credentials.clientId=Id de client credentials.secret=Secret credentials.scope=Scope credentials.delegated_scope = Scope Delegat credentials.scope_alt=Per defecte: {0} -credentials.email=Correu electr\u00F2nic d\u0027administrador de Microsoft -credentials.email_info=S\u0027utilitza en accions que requereixen un usuari. Per exemple: creeu un Teams nou (aquest usuari s\u0027inclour\u00E0 com a propietari inicial). +credentials.email=Correu electr\u00F2nic d\u2019administrador de Microsoft +credentials.email_info=S\u2019utilitza en accions que requereixen un usuari. Per exemple: creeu un Teams nou (aquest usuari s\u2019inclour\u00E0 com a propietari inicial). #Errors - frontend validation error.microsoft_teams=Selecciona almenys un equip de Microsoft @@ -194,34 +195,34 @@ error.groups=Selecciona almenys un grup error.channel=Selecciona almenys un canal #Errors - from exceptions -error.no_credentials_provided=No s\u0027han proporcionat credencials -error.invalid_credentials_provided=S\u0027ha proporcionat credencials inv\u00E0lides +error.no_credentials_provided=No s\u2019han proporcionat credencials +error.invalid_credentials_provided=S\u2019ha proporcionat credencials inv\u00E0lides error.invalid_token_provided=Token no v\u00E0lid -error.invalid_invitation=S\u0027ha enviat una invitaci\u00F3 inv\u00E0lida +error.invalid_invitation=S\u2019ha enviat una invitaci\u00F3 inv\u00E0lida error.invalid_team=Equip inv\u00E0lid -error.invalid_email=S\u0027ha proporcionat un correu electr\u00F2nic de Microsoft inv\u00E0lid +error.invalid_email=S\u2019ha proporcionat un correu electr\u00F2nic de Microsoft inv\u00E0lid error.no_admin=No sou administrador #Errors - backend -error.no_site_selected=No s\u0027ha seleccionat un espai -error.no_team_selected=No s\u0027ha seleccionat un equip -error.site_synchronization_not_found=No s\u0027ha trobat la sincronitzaci\u00F3 de l\u0027espai -error.site_synchronization_already_exists=Ja existeix una sincronitzaci\u00F3 amb el espai i l\u0027equip seleccionats. -error.site_synchronization_already_forced=Una sincronitzaci\u00F3 est\u00E0 for\u00E7ant l\u0027equip seleccionat. -error.site_synchronization_impossible_forced=Ja hi ha una sincronitzaci\u00F3 amb l\u0027equip seleccionat. Impossible for\u00E7ar l\u0027espai i l\u0027equip seleccionats. +error.no_site_selected=No s\u2019ha seleccionat un espai +error.no_team_selected=No s\u2019ha seleccionat un equip +error.site_synchronization_not_found=No s\u2019ha trobat la sincronitzaci\u00F3 de l\u2019espai +error.site_synchronization_already_exists=Ja existeix una sincronitzaci\u00F3 amb el espai i l\u2019equip seleccionats. +error.site_synchronization_already_forced=Una sincronitzaci\u00F3 est\u00E0 for\u00E7ant l\u2019equip seleccionat. +error.site_synchronization_impossible_forced=Ja hi ha una sincronitzaci\u00F3 amb l\u2019equip seleccionat. Impossible for\u00E7ar l\u2019espai i l\u2019equip seleccionats. error.group_synchronization_already_exists=La sincronitzaci\u00F3 del grup ja existeix amb el grup i el canal seleccionats. error.group_synchronization_already_forced= La sincronitzaci\u00F3 dels pares \u00E9s for\u00E7ada. No es pot enlla\u00E7ar el canal seleccionat. -error.creating_team= S\u0027ha produit un error creant l\u0027equip nou. -error.creating_team_param=S\u0027ha produit un error creant l\u0027equip nou: {0}. -error.creating_channel=s\u0027ha produit un error creant el nou canal: {0}. +error.creating_team= S\u2019ha produit un error creant l\u2019equip nou. +error.creating_team_param=S\u2019ha produit un error creant l\u2019equip nou: {0}. +error.creating_channel=s\u2019ha produit un error creant el nou canal: {0}. error.new_channel_empty=El nom del canal nou no pot estar buit -error.delete_group_synchronization=S\u0027ha produ\u00EFt un error en eliminar la sincronitzaci\u00F3 del grup seleccionat -error.set_forced_synchronization=Configuraci\u00F3 d\u0027error for\u00E7ada -error.deleting_site_synchronizations=S\u0027ha produ\u00EFt un error en eliminar una o m\u00E9s sincronitzacions seleccionades -error.cleaning_team=S\u0027ha produ\u00EFt un error en netejar una o m\u00E9s sincronitzacions seleccionades +error.delete_group_synchronization=S\u2019ha produ\u00EFt un error en eliminar la sincronitzaci\u00F3 del grup seleccionat +error.set_forced_synchronization=Configuraci\u00F3 d\u2019error for\u00E7ada +error.deleting_site_synchronizations=S\u2019ha produ\u00EFt un error en eliminar una o m\u00E9s sincronitzacions seleccionades +error.cleaning_team=S\u2019ha produ\u00EFt un error en netejar una o m\u00E9s sincronitzacions seleccionades error.set_dates = Error en establir les dates error.dates = Dates inv\u00E0lides -error.dates_order = La data d\u0027inici no pot ser posterior a la data de finalitzaci\u00F3 +error.dates_order = La data d\u2019inici no pot ser posterior a la data de finalitzaci\u00F3 error.new_channel_with_same_name= = El nom del nou canal no pot tindr\u00E9 el mateix nom que un dels canals ja creats. error.channel_number_more_than_30=No pots afegir altre canal perqu\u00E8 el equip ja t\u00E9 m\u00E9s de 30 canals. error.general_failure=Error general diff --git a/microsoft-integration/admin-tool/src/main/resources/Messages_es.properties b/microsoft-integration/admin-tool/src/main/resources/Messages_es.properties index 21eb1be05f9..83967b67b9e 100644 --- a/microsoft-integration/admin-tool/src/main/resources/Messages_es.properties +++ b/microsoft-integration/admin-tool/src/main/resources/Messages_es.properties @@ -57,6 +57,7 @@ to=Hasta filter_by_period=Filtrar por periodo: user_details=ID: {0}\nNombre: {1} {2}\nEmail: {3} filters=Filtros ({0}) +clean_filters=Limpiar creation.status_started=Proceso iniciado creation.status_create=Creando canales de los teams... diff --git a/microsoft-integration/admin-tool/src/main/resources/Messages_eu.properties b/microsoft-integration/admin-tool/src/main/resources/Messages_eu.properties index 73086322b1e..acc4b84b708 100644 --- a/microsoft-integration/admin-tool/src/main/resources/Messages_eu.properties +++ b/microsoft-integration/admin-tool/src/main/resources/Messages_eu.properties @@ -57,6 +57,7 @@ to=To filter_by_period=Filter by period: user_details=ID: {0}\nName: {1} {2}\nEmail: {3} filters=Filters ({0}) +clean_filters=Clean creation.status_started=Process started creation.status_create=Creating team's channels... diff --git a/microsoft-integration/admin-tool/src/main/webapp/WEB-INF/templates/body.html b/microsoft-integration/admin-tool/src/main/webapp/WEB-INF/templates/body.html index 07a442c1c46..c8210709e77 100644 --- a/microsoft-integration/admin-tool/src/main/webapp/WEB-INF/templates/body.html +++ b/microsoft-integration/admin-tool/src/main/webapp/WEB-INF/templates/body.html @@ -173,7 +173,7 @@ - + diff --git a/microsoft-integration/admin-tool/src/main/webapp/WEB-INF/templates/fragments/synchronizationRow.html b/microsoft-integration/admin-tool/src/main/webapp/WEB-INF/templates/fragments/synchronizationRow.html index fad604fc575..97a0af8abd0 100644 --- a/microsoft-integration/admin-tool/src/main/webapp/WEB-INF/templates/fragments/synchronizationRow.html +++ b/microsoft-integration/admin-tool/src/main/webapp/WEB-INF/templates/fragments/synchronizationRow.html @@ -64,13 +64,16 @@
- + - - + + + + + - +
diff --git a/microsoft-integration/admin-tool/src/main/webapp/WEB-INF/templates/index.html b/microsoft-integration/admin-tool/src/main/webapp/WEB-INF/templates/index.html index a03ba3bce1e..fc29cb2b23b 100644 --- a/microsoft-integration/admin-tool/src/main/webapp/WEB-INF/templates/index.html +++ b/microsoft-integration/admin-tool/src/main/webapp/WEB-INF/templates/index.html @@ -200,6 +200,14 @@

loadRow(rowId, baseURL); } + function refreshSite(elem) { + event.preventDefault(); + + let baseURL = "[(@{/refreshSite/})]"; + let rowId = elem.closest('.table-row').id.replace('row_', ''); + loadRow(rowId, baseURL); + } + async function loadRow(id, baseURL) { let rowElem = document.getElementById('row_' + id); rowElem.innerHTML = ''; diff --git a/microsoft-integration/api/src/java/org/sakaiproject/microsoft/api/MicrosoftCommonService.java b/microsoft-integration/api/src/java/org/sakaiproject/microsoft/api/MicrosoftCommonService.java index efe798e6599..80c58fd3614 100644 --- a/microsoft-integration/api/src/java/org/sakaiproject/microsoft/api/MicrosoftCommonService.java +++ b/microsoft-integration/api/src/java/org/sakaiproject/microsoft/api/MicrosoftCommonService.java @@ -79,6 +79,7 @@ public static enum PermissionRoles { READ, WRITE } MicrosoftUser createInvitation(String email, String redirectURL) throws MicrosoftGenericException; // ---------------------------------------- TEAMS / GROUPS ------------------------------------------------ + Map retrieveCacheTeams() throws MicrosoftCredentialsException; MicrosoftTeam getGroup(String id) throws MicrosoftCredentialsException; Map getTeams() throws MicrosoftCredentialsException; Map getTeams(boolean force) throws MicrosoftCredentialsException; diff --git a/microsoft-integration/impl/src/main/java/org/sakaiproject/microsoft/impl/MicrosoftCommonServiceImpl.java b/microsoft-integration/impl/src/main/java/org/sakaiproject/microsoft/impl/MicrosoftCommonServiceImpl.java index 3eda76b469f..9de31e1dbc0 100644 --- a/microsoft-integration/impl/src/main/java/org/sakaiproject/microsoft/impl/MicrosoftCommonServiceImpl.java +++ b/microsoft-integration/impl/src/main/java/org/sakaiproject/microsoft/impl/MicrosoftCommonServiceImpl.java @@ -42,6 +42,7 @@ import com.microsoft.graph.content.BatchRequestContent; import com.microsoft.graph.content.BatchResponseContent; +import com.microsoft.graph.http.GraphServiceException; import com.microsoft.graph.http.HttpMethod; import com.microsoft.graph.options.QueryOption; import com.microsoft.graph.requests.GroupRequest; @@ -477,6 +478,15 @@ public MicrosoftUser createInvitation(String email, String redirectURL) throws M // ---------------------------------------- TEAMS / GROUPS ------------------------------------------------ + @Override + public Map retrieveCacheTeams() throws MicrosoftCredentialsException { + Cache.ValueWrapper cachedValue = getCache().get(CACHE_TEAMS); + if (cachedValue != null) { + return (Map) cachedValue.get(); + } + return new HashMap<>(); + } + @Override public MicrosoftTeam getGroup(String id) throws MicrosoftCredentialsException { try { @@ -505,10 +515,11 @@ public MicrosoftTeam getTeam(String id) throws MicrosoftCredentialsException { @Override public MicrosoftTeam getTeam(String id, boolean force) throws MicrosoftCredentialsException { + Cache.ValueWrapper cachedValue = getCache().get(CACHE_TEAMS); + try { //get from cache (if not force) if (!force) { - Cache.ValueWrapper cachedValue = getCache().get(CACHE_TEAMS); if (cachedValue != null) { Map map = (Map) cachedValue.get(); if (map.containsKey(id)) { @@ -530,16 +541,16 @@ public MicrosoftTeam getTeam(String id, boolean force) throws MicrosoftCredentia .build(); //update cache - Cache.ValueWrapper cachedValue = getCache().get(CACHE_TEAMS); - if (cachedValue != null) { - Map teamsMap = (Map) cachedValue.get(); - teamsMap.put(id, mt); - - getCache().put(CACHE_TEAMS, teamsMap); - } + Map teamsMap = cachedValue != null ? (Map) cachedValue.get() : new HashMap<>(); + teamsMap.put(id, mt); + getCache().put(CACHE_TEAMS, teamsMap); return mt; } catch (MicrosoftCredentialsException e) { throw e; + } catch (GraphServiceException e) { + Map teamsMap = cachedValue != null ? (Map) cachedValue.get() : new HashMap<>(); + teamsMap.remove(id); + getCache().put(CACHE_TEAMS, teamsMap); } catch (Exception e) { log.debug("Microsoft Team not found with id={}", id); } diff --git a/microsoft-integration/impl/src/main/java/org/sakaiproject/microsoft/impl/MicrosoftSynchronizationServiceImpl.java b/microsoft-integration/impl/src/main/java/org/sakaiproject/microsoft/impl/MicrosoftSynchronizationServiceImpl.java index dd4f650281e..6057ddc4764 100644 --- a/microsoft-integration/impl/src/main/java/org/sakaiproject/microsoft/impl/MicrosoftSynchronizationServiceImpl.java +++ b/microsoft-integration/impl/src/main/java/org/sakaiproject/microsoft/impl/MicrosoftSynchronizationServiceImpl.java @@ -17,6 +17,7 @@ import java.time.LocalTime; import java.time.ZonedDateTime; +import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; import java.util.stream.StreamSupport; @@ -210,7 +211,7 @@ public List getAllSiteSynchronizations(boolean fillSite) { @Override public List getLinkedSiteSynchronizations(boolean fillSite) { - List result = StreamSupport.stream(microsoftSiteSynchronizationRepository.findDistinctByTeam("").spliterator(), false) + List result = microsoftSiteSynchronizationRepository.findDistinctByTeam("").stream() .map(ss -> { if (fillSite) { ss.setSite(sakaiProxy.getSite(ss.getSiteId())); @@ -224,14 +225,17 @@ public List getLinkedSiteSynchronizations(boolean fillSite) @Override public List getFilteredSiteSynchronizations(boolean fillSite, SakaiSiteFilter filter, ZonedDateTime fromDate, ZonedDateTime toDate) { final List sites = sakaiProxy.getSakaiSites(filter); - List result = StreamSupport.stream(microsoftSiteSynchronizationRepository.findByDate(fromDate, toDate).spliterator(), false) - .map(ss -> { + + List result = microsoftSiteSynchronizationRepository.findByDate(fromDate, toDate).stream().map(ss -> { + Site site = null; if (fillSite) { - ss.setSite(sakaiProxy.getSite(ss.getSiteId())); + site = sites.stream().filter(s -> s.getId().equals(ss.getSiteId())).findFirst().orElse(null); + if(Objects.nonNull(site)) + ss.setSite(site); } - return ss; + return Objects.nonNull(site) ? ss : null; }) - .filter(ss -> sites.contains(sakaiProxy.getSite(ss.getSiteId()))) + .filter(Objects::nonNull) .collect(Collectors.toList()); return result; }