Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EVDOC01-154: Correccions de la integració en Microsoft #27

Merged
merged 3 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ public void handleNewTeamCreation(AutoConfigSessionBean autoConfigSessionBean, S

for (Group g : groupsToProcess) {
Optional<MicrosoftChannel> channelOpt = channels.stream()
.filter(c -> c.getName().equalsIgnoreCase(microsoftCommonService.processMicrosoftChannelName(g.getTitle()))).findFirst();
.filter(c -> c.getName().replace(" ", "").equalsIgnoreCase(microsoftCommonService.processMicrosoftChannelName(g.getTitle()).replace(" ", ""))).findFirst();

channelOpt.ifPresent(channel -> {
GroupSynchronization gs = GroupSynchronization.builder()
Expand Down Expand Up @@ -406,7 +406,7 @@ public void handleExistingTeamBinding(AutoConfigSessionBean autoConfigSessionBea

for (Group g : groupsToProcess) {
MicrosoftChannel channel = channelsMap.values().stream()
.filter(c -> c.getName().equalsIgnoreCase(microsoftCommonService.processMicrosoftChannelName(g.getTitle())))
.filter(c -> c.getName().replace(" ", "").equalsIgnoreCase(microsoftCommonService.processMicrosoftChannelName(g.getTitle()).replace(" ", "")))
.findAny()
.orElse(null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ public String loadItems(
model.addAttribute("siteProperty", requestBody.getSiteProperty());
model.addAttribute("filterCount", requestBody.getFilterCount());

model.addAttribute("errorMembers", microsoftCommonService.getErrorUsers());

return BODY_TEMPLATE;
}

Expand Down Expand Up @@ -280,6 +282,8 @@ public String runSiteSynchronization(@PathVariable String id, Model model) throw
if (ss.getStatus().equals(SynchronizationStatus.ERROR)) {
model.addAttribute("errorMembers", microsoftCommonService.getErrorUsers());
model.addAttribute("errorGroupMembers", microsoftCommonService.getErrorGroupsUsers());
} else if (ss.getStatus().equals(SynchronizationStatus.PARTIAL_OK)) {
model.addAttribute("errorMembers", microsoftCommonService.getErrorUsers());
}
}
return ROW_SITE_SYNCH_FRAGMENT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,23 @@
<!-- Status -->
<div class="col-xs-1 container-flex" th:switch="${row.status}" th:title="${row.status}">
<div style="color: green;" th:case="${T(org.sakaiproject.microsoft.api.data.SynchronizationStatus).OK}" th:text="#{status.OK}" />
<div style="color: orange;" th:case="${T(org.sakaiproject.microsoft.api.data.SynchronizationStatus).PARTIAL_OK}" th:text="#{status.PARTIAL_OK}" />
<div style="flex-direction: row;display: flex;align-items: center;gap: 4px;" th:case="${T(org.sakaiproject.microsoft.api.data.SynchronizationStatus).PARTIAL_OK}">
<div style="color: orange;" th:text="#{status.PARTIAL_OK}"/>
<i th:if="${errorMembers != null && errorMembers[row.teamId] != null}" class="fa fa-info-circle" style="color: #a89e03; cursor: pointer;" th:onclick="toggleErrorsDropdown('dropdown-' +[[${row.teamId}]])"></i>
<div th:id="'dropdown-' + ${row.teamId}" class="dropdown-content" style="display: none; position: absolute; background-color: #f9f9f9; overflow: auto; width: 425px; height: 180px; box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); z-index: 1; align-items: center;padding: 10px; top: 35px;">
<div th:each="member : ${errorMembers}">
<ul th:if="${member.key == row.teamId}" style="margin: 0;padding: 0;">
<span th:text="#{error.user_synchronization}" style="margin: 0;padding: 0;"></span>
<ul style="margin: 0;padding: 0; margin-top: 10px; list-style: none;">
<li th:each="userEntry : ${member.value}" style="text-align: start; margin-bottom: 5px;">
<pre th:text="#{user_details(${userEntry.getEid()},${userEntry.getFirstName()},${userEntry.getLastName()},${userEntry.getEmail()})}" style="white-space: pre-wrap;"></pre>
</li>
</ul>
</ul>
</div>
<p th:if="${errorMembers == null || row.teamId == null || errorMembers[row.teamId] == null}">No users found for this group.</p>
</div>
</div>
<div style="color: orange;" th:case="${T(org.sakaiproject.microsoft.api.data.SynchronizationStatus).KO}" th:text="#{status.KO}" />
<div style="color: grey;" th:case="${T(org.sakaiproject.microsoft.api.data.SynchronizationStatus).NONE}" th:text="#{status.NONE}" />
<div style="color: red;" th:case="${T(org.sakaiproject.microsoft.api.data.SynchronizationStatus).ERROR}" th:text="#{status.ERROR}" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public interface MicrosoftCommonService {
public static final int MAX_CHANNELS = 30;
public static final int MAX_ADD_CHANNELS = 20;

public static List<User> errorUsers = new ArrayList<>();
Map<String, Set<User>> errorUsers = new HashMap<>();
Map<String, Set<User>> groupErrors = new HashMap<>();


Expand All @@ -65,8 +65,8 @@ public static enum PermissionRoles { READ, WRITE }

// ---------------------------------------- USERS ------------------------------------------------
List<MicrosoftUser> getUsers() throws MicrosoftCredentialsException;
List<User> getErrorUsers() throws MicrosoftCredentialsException;
void addErrorUsers(User user) throws MicrosoftCredentialsException;
Map<String, Set<User>> getErrorUsers() throws MicrosoftCredentialsException;
void addErrorUsers(String id, User user) throws MicrosoftCredentialsException;
Map<String, Set<User>> getErrorGroupsUsers() throws MicrosoftCredentialsException;
void addGroupUserErrors(String id, org.sakaiproject.user.api.User user) throws MicrosoftCredentialsException;
MicrosoftUser getUser(String identifier, MicrosoftUserIdentifier key) throws MicrosoftCredentialsException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public interface MicrosoftSynchronizationService {

// ------------ Site Synchronization ---------------------------
List<SiteSynchronization> getAllSiteSynchronizations(boolean fillSite);
List<SiteSynchronization> getLinkedSiteSynchronizations(boolean fillSite);
List<SiteSynchronization> getFilteredSiteSynchronizations(boolean fillSite, SakaiSiteFilter filter, ZonedDateTime fromDate, ZonedDateTime toDate);

SiteSynchronization getSiteSynchronization(SiteSynchronization ss);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public interface MicrosoftSiteSynchronizationRepository extends SerializableRepo
Optional<SiteSynchronization> findBySiteTeam(String siteId, String teamId);
List<SiteSynchronization> findBySite(String siteId);
List<SiteSynchronization> findByTeam(String teamId);
List<SiteSynchronization> findDistinctByTeam(String teamId);
List<SiteSynchronization> findByDate(ZonedDateTime fromDate, ZonedDateTime toDate);
List<String> findBySiteIdList(List<String> siteIds);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,14 +296,15 @@ public List<MicrosoftUser> getUsers() throws MicrosoftCredentialsException {
}

@Override
public List<org.sakaiproject.user.api.User> getErrorUsers() throws MicrosoftCredentialsException {
public Map<String, Set<org.sakaiproject.user.api.User>> getErrorUsers() throws MicrosoftCredentialsException {
return errorUsers;
}

@Override
public void addErrorUsers(org.sakaiproject.user.api.User user) throws MicrosoftCredentialsException {
if (user != null) {
errorUsers.add(user);
public void addErrorUsers(String id, org.sakaiproject.user.api.User user) throws MicrosoftCredentialsException {
if (id != null && user != null) {
Set<org.sakaiproject.user.api.User> existingUsers = errorUsers.computeIfAbsent(id, k -> new HashSet<>());
existingUsers.add(user);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,19 +209,6 @@ public List<SiteSynchronization> getAllSiteSynchronizations(boolean fillSite) {
return result;
}

@Override
public List<SiteSynchronization> getLinkedSiteSynchronizations(boolean fillSite) {
List<SiteSynchronization> result = microsoftSiteSynchronizationRepository.findDistinctByTeam("").stream()
.map(ss -> {
if (fillSite) {
ss.setSite(sakaiProxy.getSite(ss.getSiteId()));
}
return ss;
})
.collect(Collectors.toList());
return result;
}

@Override
public List<SiteSynchronization> getFilteredSiteSynchronizations(boolean fillSite, SakaiSiteFilter filter, ZonedDateTime fromDate, ZonedDateTime toDate) {
List<SiteSynchronization> result = microsoftSiteSynchronizationRepository.findByDate(fromDate, toDate);
Expand Down Expand Up @@ -674,7 +661,7 @@ public SynchronizationStatus runSiteSynchronization(SiteSynchronization ss) thro
//user does not exist -> create invitation
User u = (User) filteredSiteMembers.getMembers().get(id);
mu = createInvitation(ss, u, mappedSakaiUserId, mappedMicrosoftUserId);
microsoftCommonService.addErrorUsers(u);
microsoftCommonService.addErrorUsers(ss.getTeamId(), u);

if (mu != null) {
//store newly invited user in getsUsers map -> used in group synch in case this user do not appear yet in Microsoft registers
Expand Down Expand Up @@ -718,6 +705,7 @@ public SynchronizationStatus runSiteSynchronization(SiteSynchronization ss) thro
//user does not exist -> create invitation
User u = (User) filteredSiteMembers.getOwners().get(id);
mu = createInvitation(ss, u, mappedSakaiUserId, mappedMicrosoftUserId);
microsoftCommonService.addErrorUsers(ss.getTeamId(), u);

if (mu != null) {
//store newly invited user in getsUsers map -> used in group synch in case this user do not appear yet in Microsoft registers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,13 @@ public void init() {
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
log.info("RunSynchronizationsJob started.");

Session session = sessionManager.getCurrentSession();
try {
session.setUserEid("admin");
session.setUserId("admin");

SakaiSiteFilter siteFilter = microsoftConfigurationService.getJobSiteFilter();

List<SiteSynchronization> list = microsoftSynchronizationService.getLinkedSiteSynchronizations(true);
List<SiteSynchronization> list = microsoftSynchronizationService.getAllSiteSynchronizations(true);
for(SiteSynchronization ss : list) {
try {
//check filters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,6 @@ public List<SiteSynchronization> findByTeam(String teamId) {
.list();
}

@Override
public List<SiteSynchronization> findDistinctByTeam(String teamId) {
return (List<SiteSynchronization>)startCriteriaQuery()
.add(Restrictions.ne("teamId", teamId))
.list();
}

@Override
public List<SiteSynchronization> findByDate(ZonedDateTime fromDate, ZonedDateTime toDate) {
Criteria criteria = startCriteriaQuery();
Expand Down
Loading