Skip to content

Commit 4a12fb4

Browse files
committed
docs: generate javadoc for classes missing documentation
1 parent 3817cf1 commit 4a12fb4

28 files changed

+1690
-546
lines changed

com.developer.nefarious.zjoule.plugin/src/com/developer/nefarious/zjoule/plugin/auth/SessionManager.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,20 @@
2020
public abstract class SessionManager {
2121

2222

23+
/**
24+
* Checks if the user is logged in by verifying both SAP and Ollama sessions.
25+
*
26+
* @return {@code true} if the user is logged into either SAP or Ollama, {@code false} otherwise.
27+
*/
2328
public static boolean isUserLoggedIn() {
2429
return (isSapSession() || isOllamaSession()) ? true : false;
2530
}
2631

32+
/**
33+
* Checks if an SAP session is active by verifying required memory components.
34+
*
35+
* @return {@code true} if all required SAP session components are present, {@code false} otherwise.
36+
*/
2737
public static boolean isSapSession() {
2838
MemoryAccessToken memoryAccessToken = MemoryAccessToken.getInstance();
2939
MemoryServiceKey memoryServiceKey = MemoryServiceKey.getInstance();
@@ -34,6 +44,11 @@ public static boolean isSapSession() {
3444
|| memoryDeployment.isEmpty()) ? false : true;
3545
}
3646

47+
/**
48+
* Checks if an Ollama session is active by verifying required memory components.
49+
*
50+
* @return {@code true} if all required Ollama session components are present, {@code false} otherwise.
51+
*/
3752
public static boolean isOllamaSession() {
3853
MemoryOllamaEndpoint memoryOllamaEndpoint = MemoryOllamaEndpoint.getInstance();
3954
MemoryOllamaModel memoryOllamaModel = MemoryOllamaModel.getInstance();
@@ -69,18 +84,34 @@ public static void logout(final Browser browser, final EclipseMemory eclipseMemo
6984
}
7085
}
7186

87+
/**
88+
* Clears all active sessions, including both SAP and Ollama sessions.
89+
*/
7290
public static void clearAllSessions() {
7391
clearSapSession();
7492
clearOllamaSession();
7593
}
7694

95+
/**
96+
* Clears all SAP session-related memory components.
97+
* <p>
98+
* This method resets stored access tokens, service keys, resource groups,
99+
* and deployment information associated with the SAP session.
100+
* </p>
101+
*/
77102
private static void clearSapSession() {
78103
MemoryAccessToken.getInstance().clear();
79104
MemoryServiceKey.getInstance().clear();
80105
MemoryResourceGroup.getInstance().clear();
81106
MemoryDeployment.getInstance().clear();
82107
}
83108

109+
/**
110+
* Clears all Ollama session-related memory components.
111+
* <p>
112+
* This method resets stored Ollama endpoint and model information.
113+
* </p>
114+
*/
84115
private static void clearOllamaSession() {
85116
MemoryOllamaEndpoint.getInstance().clear();
86117
MemoryOllamaModel.getInstance().clear();

com.developer.nefarious.zjoule.plugin/src/com/developer/nefarious/zjoule/plugin/chat/AIClientFactory.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ public static IAIClient getClient() {
4747
}
4848
}
4949

50+
/**
51+
* Creates and returns an {@link IAIClient} for SAP AI Core.
52+
* <p>
53+
* This method initializes the required memory components, authentication client,
54+
* and deployment details. If the deployment's model name matches an OpenAI model,
55+
* an {@link OpenAIClient} is returned. Otherwise, it returns {@code null}.
56+
* </p>
57+
*
58+
* @return an instance of {@link IAIClient} for SAP AI Core, or {@code null} if unsupported.
59+
*/
5060
private static IAIClient getClientForSapAiCore() {
5161
// Load memory components for access token, service key, resource group, deployment, and message history.
5262
MemoryMessageHistory memoryMessageHistory = MemoryMessageHistory.getInstance();
@@ -71,6 +81,16 @@ private static IAIClient getClientForSapAiCore() {
7181
}
7282
}
7383

84+
/**
85+
* Creates and returns an {@link IAIClient} for Ollama.
86+
* <p>
87+
* This method initializes the required memory components and
88+
* returns an {@link OllamaClient} instance configured with
89+
* an {@link OllamaClientHelper}.
90+
* </p>
91+
*
92+
* @return an instance of {@link OllamaClient}.
93+
*/
7494
private static IAIClient getClientForOllama() {
7595
MemoryMessageHistory memoryMessageHistory = MemoryMessageHistory.getInstance();
7696
IMemoryObject<String> memoryOllamaEndpoint = MemoryOllamaEndpoint.getInstance();

com.developer.nefarious.zjoule.plugin/src/com/developer/nefarious/zjoule/plugin/chat/ollama/OllamaClient.java

Lines changed: 103 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -18,50 +18,94 @@
1818
import com.developer.nefarious.zjoule.plugin.memory.IMemoryObject;
1919
import com.developer.nefarious.zjoule.plugin.models.Role;
2020

21+
/**
22+
* A client implementation for interacting with the Ollama AI chat system.
23+
* <p>
24+
* The {@code OllamaClient} facilitates chat interactions by sending requests
25+
* to an Ollama chat API endpoint and processing responses. It also manages
26+
* message history using an in-memory storage system.
27+
* </p>
28+
*/
2129
public class OllamaClient implements IAIClient {
22-
23-
private HttpClient httpClient;
24-
25-
private IMemoryMessageHistory memoryMessageHistory;
26-
27-
private IMemoryObject<String> memoryOllamaEndpoint;
28-
29-
private IOllamaClientHelper helper;
30-
31-
public OllamaClient(
32-
final IMemoryMessageHistory memoryMessageHistory,
33-
final IMemoryObject<String> memoryOllamaEndpoint,
34-
final IOllamaClientHelper ollamaClientHelper) {
35-
this.httpClient = HttpClient.newHttpClient();
36-
this.memoryMessageHistory = memoryMessageHistory;
37-
this.memoryOllamaEndpoint = memoryOllamaEndpoint;
38-
helper = ollamaClientHelper;
39-
}
40-
41-
@Override
42-
public IChatMessage chatCompletion(final List<IChatMessage> messages) throws IOException, InterruptedException {
43-
URI endpoint = createChatEndpoint();
44-
45-
BodyPublisher requestBody = helper.createRequestBody(messages);
46-
30+
31+
/** The HTTP client used for sending chat requests. */
32+
private HttpClient httpClient;
33+
34+
/** Memory storage for maintaining chat message history. */
35+
private IMemoryMessageHistory memoryMessageHistory;
36+
37+
/** Memory storage for retrieving the Ollama chat API endpoint. */
38+
private IMemoryObject<String> memoryOllamaEndpoint;
39+
40+
/** Helper class for constructing request payloads and processing responses. */
41+
private IOllamaClientHelper helper;
42+
43+
/**
44+
* Constructs an {@code OllamaClient} with the specified dependencies.
45+
*
46+
* @param memoryMessageHistory the in-memory storage for chat message history.
47+
* @param memoryOllamaEndpoint the in-memory storage containing the Ollama chat API endpoint.
48+
* @param ollamaClientHelper the helper class for handling request and response transformations.
49+
*/
50+
public OllamaClient(
51+
final IMemoryMessageHistory memoryMessageHistory,
52+
final IMemoryObject<String> memoryOllamaEndpoint,
53+
final IOllamaClientHelper ollamaClientHelper) {
54+
this.httpClient = HttpClient.newHttpClient();
55+
this.memoryMessageHistory = memoryMessageHistory;
56+
this.memoryOllamaEndpoint = memoryOllamaEndpoint;
57+
helper = ollamaClientHelper;
58+
}
59+
60+
/**
61+
* Sends a chat completion request to the Ollama API.
62+
* <p>
63+
* This method constructs a request using the provided chat messages and sends
64+
* it to the configured API endpoint. It then processes the response and returns
65+
* the generated AI message.
66+
* </p>
67+
*
68+
* @param messages the list of chat messages forming the conversation history.
69+
* @return the AI-generated response as an {@link IChatMessage}.
70+
* @throws IOException if an I/O error occurs when sending the request.
71+
* @throws InterruptedException if the request is interrupted while waiting for a response.
72+
*/
73+
@Override
74+
public IChatMessage chatCompletion(final List<IChatMessage> messages) throws IOException, InterruptedException {
75+
URI endpoint = createChatEndpoint();
76+
BodyPublisher requestBody = helper.createRequestBody(messages);
77+
4778
HttpRequest request = HttpRequest.newBuilder()
48-
.uri(endpoint)
49-
.POST(requestBody)
50-
.build();
51-
79+
.uri(endpoint)
80+
.POST(requestBody)
81+
.build();
82+
5283
HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
53-
84+
5485
return helper.convertResponseToObject(response.body());
55-
}
86+
}
5687

57-
@Override
58-
public IChatMessage createMessage(final Role role, final String userPrompt) {
59-
return new OllamaChatMessage(role, userPrompt);
60-
}
88+
/**
89+
* Creates a new chat message with the specified role and user input.
90+
*
91+
* @param role the role of the message (e.g., user or assistant).
92+
* @param userPrompt the message content.
93+
* @return an instance of {@link IChatMessage} representing the user input.
94+
*/
95+
@Override
96+
public IChatMessage createMessage(final Role role, final String userPrompt) {
97+
return new OllamaChatMessage(role, userPrompt);
98+
}
6199

62-
@Override
63-
public List<IChatMessage> getMessageHistory() {
64-
MessageHistory messageHistory = memoryMessageHistory.load();
100+
/**
101+
* Retrieves the chat message history stored in memory.
102+
*
103+
* @return a list of {@link IChatMessage} representing the chat history,
104+
* or an empty list if no history is available.
105+
*/
106+
@Override
107+
public List<IChatMessage> getMessageHistory() {
108+
MessageHistory messageHistory = memoryMessageHistory.load();
65109
if (messageHistory == null) {
66110
return Collections.emptyList();
67111
}
@@ -72,23 +116,32 @@ public List<IChatMessage> getMessageHistory() {
72116
}
73117

74118
return messages.stream().map(message ->
75-
new OllamaChatMessage(message.getRole(), message.getContent()))
119+
new OllamaChatMessage(message.getRole(), message.getContent()))
76120
.collect(Collectors.toList());
77-
}
121+
}
78122

79-
@Override
80-
public void setMessageHistory(final List<IChatMessage> chatMessages) {
81-
MessageHistory newMessageHistory = new MessageHistory();
123+
/**
124+
* Stores the given chat message history in memory.
125+
*
126+
* @param chatMessages the list of chat messages to save.
127+
*/
128+
@Override
129+
public void setMessageHistory(final List<IChatMessage> chatMessages) {
130+
MessageHistory newMessageHistory = new MessageHistory();
82131
newMessageHistory.setMessages(chatMessages.stream().map(
83-
chatMessage -> new Message(chatMessage.getRole(), chatMessage.getMessage()))
84-
.collect(Collectors.toList()));
132+
chatMessage -> new Message(chatMessage.getRole(), chatMessage.getMessage()))
133+
.collect(Collectors.toList()));
85134
memoryMessageHistory.save(newMessageHistory);
86-
}
87-
88-
private URI createChatEndpoint() {
135+
}
136+
137+
/**
138+
* Creates a URI representing the chat endpoint for sending requests.
139+
*
140+
* @return the {@link URI} of the chat API endpoint.
141+
*/
142+
private URI createChatEndpoint() {
89143
String endpoint = memoryOllamaEndpoint.load();
90144
String endpointInStringFormat = endpoint + "/api/chat";
91145
return URI.create(endpointInStringFormat);
92146
}
93-
94-
}
147+
}

com.developer.nefarious.zjoule.plugin/src/com/developer/nefarious/zjoule/plugin/chat/ollama/OllamaClientHelper.java

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,59 @@
99
import com.developer.nefarious.zjoule.plugin.models.OllamaModel;
1010
import com.google.gson.Gson;
1111

12+
/**
13+
* A helper class for constructing requests and processing responses for the Ollama AI chat system.
14+
* <p>
15+
* The {@code OllamaClientHelper} is responsible for serializing chat request bodies,
16+
* deserializing chat responses, and retrieving the currently selected Ollama model.
17+
* </p>
18+
*/
1219
public class OllamaClientHelper implements IOllamaClientHelper {
13-
14-
private IMemoryObject<OllamaModel> memoryOllamaModel;
15-
16-
public OllamaClientHelper(final IMemoryObject<OllamaModel> memoryOllamaModel) {
17-
this.memoryOllamaModel = memoryOllamaModel;
18-
}
19-
20-
@Override
21-
public IChatMessage convertResponseToObject(final String serializedResponseBody) {
20+
21+
/** In-memory storage for the selected Ollama model. */
22+
private IMemoryObject<OllamaModel> memoryOllamaModel;
23+
24+
/**
25+
* Constructs an {@code OllamaClientHelper} with the specified memory storage.
26+
*
27+
* @param memoryOllamaModel the in-memory storage containing the selected Ollama model.
28+
*/
29+
public OllamaClientHelper(final IMemoryObject<OllamaModel> memoryOllamaModel) {
30+
this.memoryOllamaModel = memoryOllamaModel;
31+
}
32+
33+
/**
34+
* {@inheritDoc}
35+
*/
36+
@Override
37+
public IChatMessage convertResponseToObject(final String serializedResponseBody) {
2238
Gson gson = new Gson();
2339
OllamaRequestResponse deserializedResponseBody = gson.fromJson(serializedResponseBody, OllamaRequestResponse.class);
2440
return deserializedResponseBody.getMessage();
25-
}
41+
}
2642

27-
@Override
28-
public BodyPublisher createRequestBody(final List<IChatMessage> messages) {
43+
/**
44+
* {@inheritDoc}
45+
*/
46+
@Override
47+
public BodyPublisher createRequestBody(final List<IChatMessage> messages) {
2948
OllamaRequestBody requestBody = new OllamaRequestBody();
30-
49+
3150
requestBody.setModel(getSelectedModel());
3251
requestBody.setMessages(messages);
3352
requestBody.setStream(false);
3453

3554
BodyPublisher bodyPublisher = HttpRequest.BodyPublishers.ofString(requestBody.toString());
3655
return HttpRequest.BodyPublishers.fromPublisher(bodyPublisher);
37-
}
38-
39-
private String getSelectedModel() {
40-
OllamaModel ollamaModel = memoryOllamaModel.load();
41-
return ollamaModel.getName();
42-
}
56+
}
4357

58+
/**
59+
* Retrieves the name of the currently selected Ollama model from memory.
60+
*
61+
* @return the name of the selected Ollama model.
62+
*/
63+
private String getSelectedModel() {
64+
OllamaModel ollamaModel = memoryOllamaModel.load();
65+
return ollamaModel.getName();
66+
}
4467
}

0 commit comments

Comments
 (0)