use of org.olat.modules.teams.model.ConnectionInfos in project OpenOLAT by OpenOLAT.
the class TeamsConfigurationController method validateConnection.
private boolean validateConnection() {
boolean allOk = true;
TeamsErrors errors = new TeamsErrors();
ConnectionInfos infos = teamsService.checkConnection(clientIdEl.getValue(), secretEl.getValue(), tenantEl.getValue(), producerIdEl.getValue(), errors);
producerIdEl.clearError();
if (infos != null) {
if (StringHelper.containsNonWhitespace(producerIdEl.getValue()) && !StringHelper.containsNonWhitespace(infos.getProducerDisplayName())) {
producerIdEl.setErrorKey("error.producerNotFound", null);
allOk &= false;
}
}
if (errors.hasErrors()) {
clientIdEl.setErrorKey("error.connection", null);
}
return allOk;
}
use of org.olat.modules.teams.model.ConnectionInfos in project OpenOLAT by OpenOLAT.
the class TeamsConfigurationController method loadModel.
private void loadModel() {
TeamsErrors errors = new TeamsErrors();
ConnectionInfos infos = teamsService.checkConnection(errors);
updateModel(infos);
}
use of org.olat.modules.teams.model.ConnectionInfos in project OpenOLAT by OpenOLAT.
the class TeamsConfigurationController method doCheckConnection.
private void doCheckConnection() {
String producerId = producerIdEl.getValue();
TeamsErrors errors = new TeamsErrors();
ConnectionInfos infos = teamsService.checkConnection(clientIdEl.getValue(), secretEl.getValue(), tenantEl.getValue(), producerId, errors);
updateModel(infos);
if (infos == null) {
if (errors.getErrors().isEmpty()) {
showError("error.connection");
} else {
String formattedErrors = TeamsUIHelper.formatErrors(getTranslator(), errors);
getWindowControl().setError(formattedErrors);
}
} else {
if (StringHelper.containsNonWhitespace(producerId) && !StringHelper.containsNonWhitespace(infos.getProducerDisplayName())) {
errors.append(new TeamsError(TeamsErrorCodes.producerNotFound));
}
if (errors.getErrors().isEmpty()) {
showInfo("info.connection.ok");
} else {
String formattedErrors = TeamsUIHelper.formatErrors(getTranslator(), errors);
getWindowControl().setError(formattedErrors);
}
}
}
use of org.olat.modules.teams.model.ConnectionInfos in project OpenOLAT by OpenOLAT.
the class MicrosoftGraphDAO method check.
public ConnectionInfos check(String clientId, String clientSecret, String tenantGuid, String producerId, TeamsErrors errors) {
try {
MicrosoftGraphAccessTokenManager accessTokenManager = new MicrosoftGraphAccessTokenManager(clientId, clientSecret, tenantGuid);
AuthenticationTokenProvider authProvider = new AuthenticationTokenProvider(accessTokenManager);
GraphServiceClient<Request> client = client(authProvider);
Organization org = getOrganisation(tenantGuid, client);
String organisation = org == null ? null : org.displayName;
String producerDisplayName = null;
if (StringHelper.containsNonWhitespace(producerId)) {
User producer = searchUserById(producerId, client, errors);
producerDisplayName = producer == null ? null : producer.displayName;
}
return new ConnectionInfos(organisation, producerDisplayName);
} catch (ClientException e) {
errors.append(extractMsalFrom(e));
log.error("", e);
return null;
} catch (NullPointerException | IllegalArgumentException e) {
errors.append(new TeamsError(TeamsErrorCodes.httpClientError));
log.error("", e);
return null;
} catch (Exception e) {
errors.append(new TeamsError(e.getMessage()));
log.error("", e);
return null;
}
}
use of org.olat.modules.teams.model.ConnectionInfos in project OpenOLAT by OpenOLAT.
the class MicrosoftGraphDAO method check.
public final ConnectionInfos check(TeamsErrors errors) {
try {
GraphServiceClient<Request> client = client();
String tenantId = teamsModule.getTenantGuid();
Organization org = getOrganisation(tenantId, client);
String organisation = org == null ? null : org.displayName;
String producerDisplayName = null;
if (StringHelper.containsNonWhitespace(teamsModule.getProducerId())) {
User producer = searchUserById(teamsModule.getProducerId(), client, errors);
producerDisplayName = producer == null ? null : producer.displayName;
}
return new ConnectionInfos(organisation, producerDisplayName);
} catch (ClientException | NullPointerException | IllegalArgumentException e) {
errors.append(new TeamsError(TeamsErrorCodes.httpClientError));
log.error("", e);
return null;
} catch (Exception e) {
errors.append(new TeamsError(e.getMessage(), ""));
log.error("", e);
return null;
}
}
Aggregations