-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
12 changed files
with
285 additions
and
12 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
distribution/src/main/resources/docker-compose/wiremock/hxinsight/__files/question-id.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"questionId": "5fca2c77-cdc0-4118-9373-e75f53177ff8" | ||
} |
10 changes: 10 additions & 0 deletions
10
...ribution/src/main/resources/docker-compose/wiremock/hxinsight/mappings/post-question.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"request": { | ||
"method": "POST", | ||
"urlPath": "/v1/questions" | ||
}, | ||
"response": { | ||
"status": 202, | ||
"bodyFileName": "question-id.json" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
...nsion/src/main/java/org/alfresco/hxi_connector/hxi_extension/service/HxInsightClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* #%L | ||
* Alfresco HX Insight Connector | ||
* %% | ||
* Copyright (C) 2023 - 2024 Alfresco Software Limited | ||
* %% | ||
* This file is part of the Alfresco software. | ||
* If the software was purchased under a paid Alfresco license, the terms of | ||
* the paid license agreement will prevail. Otherwise, the software is | ||
* provided under the following open source license terms: | ||
* | ||
* Alfresco is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Alfresco is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. | ||
* #L% | ||
*/ | ||
|
||
package org.alfresco.hxi_connector.hxi_extension.service; | ||
|
||
import static org.apache.hc.core5.http.ContentType.APPLICATION_JSON; | ||
import static org.apache.hc.core5.http.HttpStatus.SC_ACCEPTED; | ||
|
||
import static org.alfresco.hxi_connector.common.util.ErrorUtils.throwExceptionOnUnexpectedStatusCode; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
import jakarta.annotation.PreDestroy; | ||
|
||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import lombok.Cleanup; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.hc.client5.http.classic.methods.HttpPost; | ||
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; | ||
import org.apache.hc.client5.http.impl.classic.HttpClients; | ||
import org.apache.hc.core5.http.HttpEntity; | ||
import org.apache.hc.core5.http.io.entity.StringEntity; | ||
|
||
import org.alfresco.hxi_connector.common.exception.HxInsightConnectorRuntimeException; | ||
import org.alfresco.hxi_connector.hxi_extension.service.config.QuestionServiceConfig; | ||
import org.alfresco.hxi_connector.hxi_extension.service.model.Question; | ||
import org.alfresco.hxi_connector.hxi_extension.service.util.AuthService; | ||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class HxInsightClient | ||
{ | ||
private final static String QUESTION_ID_ENTRY = "questionId"; | ||
private final QuestionServiceConfig config; | ||
private final AuthService authService; | ||
private final ObjectMapper objectMapper; | ||
private final CloseableHttpClient client = HttpClients.createDefault(); | ||
|
||
public String askQuestion(Question question) | ||
{ | ||
try | ||
{ | ||
@Cleanup | ||
HttpEntity body = new StringEntity(objectMapper.writeValueAsString(question), APPLICATION_JSON); | ||
|
||
HttpPost httpPost = new HttpPost(config.getQuestionUrl()); | ||
httpPost.setEntity(body); | ||
|
||
authService.setAuthHeader(httpPost); | ||
|
||
return client.execute(httpPost, (response) -> { | ||
throwExceptionOnUnexpectedStatusCode(response.getCode(), SC_ACCEPTED); | ||
|
||
return objectMapper.readValue(response.getEntity().getContent(), new TypeReference<Map<String, String>>() {}).get(QUESTION_ID_ENTRY); | ||
}); | ||
} | ||
catch (IOException e) | ||
{ | ||
throw new HxInsightConnectorRuntimeException("Failed to ask question", e); | ||
} | ||
} | ||
|
||
@PreDestroy | ||
public void close() | ||
{ | ||
try | ||
{ | ||
log.trace("Closing the HTTP client"); | ||
client.close(); | ||
} | ||
catch (IOException e) | ||
{ | ||
log.error("Failed to close the HTTP client", e); | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...n/java/org/alfresco/hxi_connector/hxi_extension/service/config/QuestionServiceConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* #%L | ||
* Alfresco HX Insight Connector | ||
* %% | ||
* Copyright (C) 2023 - 2024 Alfresco Software Limited | ||
* %% | ||
* This file is part of the Alfresco software. | ||
* If the software was purchased under a paid Alfresco license, the terms of | ||
* the paid license agreement will prevail. Otherwise, the software is | ||
* provided under the following open source license terms: | ||
* | ||
* Alfresco is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Alfresco is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. | ||
* #L% | ||
*/ | ||
|
||
package org.alfresco.hxi_connector.hxi_extension.service.config; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
|
||
public final class QuestionServiceConfig | ||
{ | ||
private final String questionUrl; | ||
|
||
public QuestionServiceConfig(@NotBlank String baseUrl) | ||
{ | ||
this.questionUrl = baseUrl + "/v1/questions"; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...ension/src/main/java/org/alfresco/hxi_connector/hxi_extension/service/model/Question.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* #%L | ||
* Alfresco HX Insight Connector | ||
* %% | ||
* Copyright (C) 2023 - 2024 Alfresco Software Limited | ||
* %% | ||
* This file is part of the Alfresco software. | ||
* If the software was purchased under a paid Alfresco license, the terms of | ||
* the paid license agreement will prevail. Otherwise, the software is | ||
* provided under the following open source license terms: | ||
* | ||
* Alfresco is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Alfresco is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. | ||
* #L% | ||
*/ | ||
|
||
package org.alfresco.hxi_connector.hxi_extension.service.model; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
public class Question | ||
{ | ||
@NotBlank | ||
private final String question; | ||
@NotBlank | ||
private final String restrictionQuery; | ||
} |
44 changes: 44 additions & 0 deletions
44
...sion/src/main/java/org/alfresco/hxi_connector/hxi_extension/service/util/AuthService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* #%L | ||
* Alfresco HX Insight Connector | ||
* %% | ||
* Copyright (C) 2023 - 2024 Alfresco Software Limited | ||
* %% | ||
* This file is part of the Alfresco software. | ||
* If the software was purchased under a paid Alfresco license, the terms of | ||
* the paid license agreement will prevail. Otherwise, the software is | ||
* provided under the following open source license terms: | ||
* | ||
* Alfresco is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Alfresco is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. | ||
* #L% | ||
*/ | ||
|
||
package org.alfresco.hxi_connector.hxi_extension.service.util; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.apache.hc.client5.http.classic.methods.HttpPost; | ||
import org.apache.hc.core5.http.HttpHeaders; | ||
|
||
import org.alfresco.hxi_connector.common.adapters.auth.AccessTokenProvider; | ||
|
||
@RequiredArgsConstructor | ||
public class AuthService | ||
{ | ||
private final AccessTokenProvider accessTokenProvider; | ||
|
||
public void setAuthHeader(HttpPost request) | ||
{ | ||
request.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + accessTokenProvider.getAccessToken("hyland-experience")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.