bug6095: don't choke on missing AI Core credentials and instead show empty caption panel

This commit is contained in:
Axel Uhl
2025-03-05 00:04:59 +01:00
parent c589f41cb6
commit dcff57b216
11 changed files with 44 additions and 24 deletions
@@ -12,3 +12,4 @@ Require-Bundle: com.sap.sailing.server,
org.junit;bundle-version="4.8.2",
com.sap.sse.common
Automatic-Module-Name: com.sap.sailing.expeditionconnector.test
Import-Package: org.apache.commons.math
@@ -43,6 +43,7 @@ public class AIAgentConfigurationPanel extends SimplePanel {
private final Set<EventDTO> selectedEvents;
private boolean selectionUpdatedAfterEventsHaveLoaded;
private boolean handleSelectionChangeEvents;
private String languageModelName;
public AIAgentConfigurationPanel(final Presenter presenter, final StringMessages stringMessages) {
this.sailingServiceWrite = presenter.getSailingService();
@@ -55,18 +56,6 @@ public class AIAgentConfigurationPanel extends SimplePanel {
final AccessControlledButtonPanel buttonPanel = new AccessControlledButtonPanel(userService, EVENT);
final AdminConsoleTableResources adminConsoleTableResources = GWT.create(AdminConsoleTableResources.class);
final Label languageModelNameLabel = new Label();
sailingServiceWrite.getAIAgentLanguageModelName(new AsyncCallback<String>() {
@Override
public void onFailure(Throwable caught) {
Notification.notify(stringMessages.errorObtainingAIAgentLanguageModelName(caught.getMessage()), NotificationType.ERROR);
}
@Override
public void onSuccess(String result) {
languageModelNameLabel.setText(stringMessages.languageModelUsedForAICommenting(result));
}
});
eventsTableWrapper = new TableWrapperWithMultiSelectionAndFilterForSecuredDTO<EventDTO, StringMessages, AdminConsoleTableResources>(stringMessages, this.errorReporter,
/* enablePager */ true, Optional.of(new EntityIdentityComparator<EventDTO>() {
@Override
@@ -86,8 +75,8 @@ public class AIAgentConfigurationPanel extends SimplePanel {
}
};
eventsTableWrapper.addColumn(EventDTO::getName, stringMessages.name());
SafeHtmlCell descriptionCell = new SafeHtmlCell();
Column<EventDTO, SafeHtml> descriptionColumn = new Column<EventDTO, SafeHtml>(descriptionCell) {
final SafeHtmlCell descriptionCell = new SafeHtmlCell();
final Column<EventDTO, SafeHtml> descriptionColumn = new Column<EventDTO, SafeHtml>(descriptionCell) {
@Override
public SafeHtml getValue(EventDTO event) {
final SafeHtmlBuilder builder = new SafeHtmlBuilder();
@@ -140,8 +129,27 @@ public class AIAgentConfigurationPanel extends SimplePanel {
contents.setWidth("100%");
contents.add(buttonPanel);
eventsTableWrapper.getTable().setWidth("100%");
contents.add(eventsTableWrapper);
captionPanel.setContentWidget(contents);
sailingServiceWrite.getAIAgentLanguageModelName(new AsyncCallback<String>() {
@Override
public void onFailure(Throwable caught) {
Notification.notify(stringMessages.errorObtainingAIAgentLanguageModelName(caught.getMessage()), NotificationType.ERROR);
}
@Override
public void onSuccess(String result) {
if (result != null) {
languageModelName = result;
languageModelNameLabel.setText(stringMessages.languageModelUsedForAICommenting(result));
contents.add(eventsTableWrapper);
captionPanel.setContentWidget(contents);
if (!selectionUpdatedAfterEventsHaveLoaded) {
presenter.getEventsRefresher().reloadAndCallFillAll();
}
} else {
languageModelNameLabel.setText(stringMessages.noValidAICoreConfiguration());
}
}
});
mainPanel.add(languageModelNameLabel);
mainPanel.add(captionPanel);
setWidget(mainPanel);
@@ -153,7 +161,7 @@ public class AIAgentConfigurationPanel extends SimplePanel {
public void fill(Iterable<EventDTO> result) {
handleSelectionChangeEvents = false;
eventsTableWrapper.getFilterPanel().updateAll(result);
if (!selectionUpdatedAfterEventsHaveLoaded) {
if (!selectionUpdatedAfterEventsHaveLoaded && languageModelName != null) {
selectionUpdatedAfterEventsHaveLoaded = true;
sailingServiceWrite.getIdsOfEventsWithAICommenting(new AsyncCallback<List<EventDTO>>() {
@Override
@@ -2519,4 +2519,5 @@ public interface StringMessages extends com.sap.sse.gwt.client.StringMessages,
String selectEventsForWhichToUseAICommenting();
String errorObtainingAIAgentLanguageModelName(String message);
String languageModelUsedForAICommenting(String modelName);
String noValidAICoreConfiguration();
}
@@ -2555,4 +2555,5 @@ errorStoppingAICommentingForEvent=Error trying to stop AI commenting for event {
errorTryingToFetchEventsWithAICommentingActive=Error trying to fetch events with AI commenting active: {0}
selectEventsForWhichToUseAICommenting=Select events for which to use AI commenting
errorObtainingAIAgentLanguageModelName=Error obtaining language model name used for AI commenting: {0}
languageModelUsedForAICommenting=Language model used for AI commenting: {0}
languageModelUsedForAICommenting=Language model used for AI commenting: {0}
noValidAICoreConfiguration=No valid AI Core configuration (maybe missing credentials?)
@@ -2549,4 +2549,5 @@ errorStoppingAICommentingForEvent=Fehler beim Versuch, die KI-Kommentierung für
errorTryingToFetchEventsWithAICommentingActive=Fehler beim ermitteln der Veranstaltungen, für welche die KI-Kommentierung aktiv ist: {0}
selectEventsForWhichToUseAICommenting=Veranstaltung selektieren, für die KI-Kommentierung aktiv sein soll
errorObtainingAIAgentLanguageModelName=Fehler beim Versuch, den Namen des für die KI-Komenntare verwendeten Sprachmodells zu ermitteln: {0}
languageModelUsedForAICommenting=Sprachmodell, das für die KI-Kommentierung verwendet wird: {0}
languageModelUsedForAICommenting=Sprachmodell, das für die KI-Kommentierung verwendet wird: {0}
noValidAICoreConfiguration=Keine gültige AI Core Konfiguration (evtl. fehlende Berechtigungs-Daten?)
@@ -2292,9 +2292,13 @@ public class SailingServiceImpl extends ResultCachingProxiedRemoteServiceServlet
} // grab the service
}
/**
* @return {@code null} if the agent is not found in the OSGi registry within 100ms; this then indicates that most
* likely the agent wasn't initialized because of missing credentials
*/
protected AIAgent getAIAgent() {
try {
return aiAgentTracker.waitForService(0);
return aiAgentTracker.waitForService(100);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
@@ -41,6 +41,7 @@ import org.apache.shiro.authz.AuthorizationException;
import org.apache.shiro.authz.UnauthorizedException;
import org.apache.shiro.subject.Subject;
import com.sap.sailing.aiagent.interfaces.AIAgent;
import com.sap.sailing.domain.abstractlog.AbstractLog;
import com.sap.sailing.domain.abstractlog.AbstractLogEvent;
import com.sap.sailing.domain.abstractlog.AbstractLogEventAuthor;
@@ -4077,6 +4078,7 @@ public class SailingServiceWriteImpl extends SailingServiceImpl implements Saili
public String getAIAgentLanguageModelName() {
final Subject subject = SecurityUtils.getSubject();
subject.checkPermission(SecuredSecurityTypes.SERVER.getStringPermissionForTypeRelativeIdentifier(ServerActions.CONFIGURE_AI_AGENT, new TypeRelativeObjectIdentifier(ServerInfo.getName())));
return getAIAgent().getModelName();
final AIAgent aiAgent = getAIAgent();
return aiAgent == null ? null : aiAgent.getModelName();
}
}
@@ -49,6 +49,7 @@ Import-Package: com.sap.sailing.domain.common,
com.sap.sailing.domain.common.racelog.tracking,
com.sap.sailing.domain.common.tracking,
com.sap.sailing.domain.common.tracking.impl,
com.sap.sailing.domain.tractracadapter.persistence.impl
com.sap.sailing.domain.tractracadapter.persistence.impl,
org.apache.commons.math;version="2.1.0"
Automatic-Module-Name: com.sap.sailing.mongodb.test
@@ -6,7 +6,8 @@ Bundle-Version: 1.0.0.qualifier
Bundle-Vendor: SAP
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Fragment-Host: com.sap.sse.replication
Import-Package: com.rabbitmq.client;version="2.8.4"
Import-Package: com.rabbitmq.client;version="2.8.4",
org.apache.commons.math;version="2.1.0"
Require-Bundle: com.sap.sailing.server,
com.sap.sailing.server.interface,
com.sap.sailing.domain.common,
@@ -43,5 +43,6 @@ Require-Bundle: com.sap.sailing.server,
com.sap.sse.mail
Automatic-Module-Name: com.sap.sailing.server.testsupport
Import-Package: com.sap.sse.security.userstore.mongodb,
org.apache.commons.math;version="2.1.0",
org.osgi.framework;version="1.8.0",
org.osgi.util.tracker;version="1.5.1"
@@ -25,7 +25,6 @@ import com.sap.sse.common.TypeBasedServiceFinderFactory;
*
*/
public abstract class RacingEventServiceImplMock extends RacingEventServiceImpl {
private DataImportLockWithProgress lock;
public RacingEventServiceImplMock() {