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

[Enhancement #270] Pass repository username and password to annotace. #271

Merged
merged 1 commit into from
Jul 16, 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
26 changes: 26 additions & 0 deletions src/main/java/cz/cvut/kbss/termit/dto/TextAnalysisInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ public class TextAnalysisInput {
*/
private URI vocabularyRepository;

/**
* Username to access the repository
*/
private String vocabularyRepositoryUserName;

/**
* Password to access the repository
*/
private String vocabularyRepositoryPassword;

/**
* URIs of contexts containing vocabularies whose terms are used in the text analysis. Optional.
* <p>
Expand Down Expand Up @@ -84,6 +94,22 @@ public void setVocabularyRepository(URI vocabularyRepository) {
this.vocabularyRepository = vocabularyRepository;
}

public String getVocabularyRepositoryUserName() {
return vocabularyRepositoryUserName;
}

public void setVocabularyRepositoryUserName(String vocabularyRepositoryUserName) {
this.vocabularyRepositoryUserName = vocabularyRepositoryUserName;
}

public String getVocabularyRepositoryPassword() {
return vocabularyRepositoryPassword;
}

public void setVocabularyRepositoryPassword(String vocabularyRepositoryPassword) {
this.vocabularyRepositoryPassword = vocabularyRepositoryPassword;
}

public Set<URI> getVocabularyContexts() {
return vocabularyContexts;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ private TextAnalysisInput createAnalysisInput(File file) {
);
input.setVocabularyRepository(repositoryUrl);
input.setLanguage(config.getPersistence().getLanguage());
input.setVocabularyRepositoryUserName(config.getRepository().getUsername());
input.setVocabularyRepositoryPassword(config.getRepository().getPassword());
return input;
}

Expand Down Expand Up @@ -169,6 +171,8 @@ public void analyzeTermDefinition(AbstractTerm term, URI vocabularyContext) {
final TextAnalysisInput input = new TextAnalysisInput(term.getDefinition().get(language), language,
URI.create(config.getRepository().getUrl()));
input.addVocabularyContext(vocabularyContext);
input.setVocabularyRepositoryUserName(config.getRepository().getUsername());
input.setVocabularyRepositoryPassword(config.getRepository().getPassword());

invokeTextAnalysisOnTerm(term, input);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ private TextAnalysisInput textAnalysisInput() {
);
input.setVocabularyRepository(repositoryUrl);
input.setLanguage(config.getPersistence().getLanguage());
input.setVocabularyRepositoryUserName(config.getRepository().getUsername());
input.setVocabularyRepositoryPassword(config.getRepository().getPassword());
return input;
}

Expand All @@ -183,6 +185,23 @@ void analyzeFilePassesContentTypeAndAcceptHeadersToService() throws Exception {
mockServer.verify();
}

@Test
void analyzeFilePassesRepositoryUsernameAndPasswordToServiceWhenProvided() throws Exception {
final String username = "user";
config.getRepository().setUsername(username);
final String password = "password";
config.getRepository().setPassword(password);
final TextAnalysisInput input = textAnalysisInput();
input.setVocabularyRepositoryUserName(username);
input.setVocabularyRepositoryPassword(password);
mockServer.expect(requestTo(config.getTextAnalysis().getUrl()))
.andExpect(method(HttpMethod.POST))
.andExpect(content().string(objectMapper.writeValueAsString(input)))
.andRespond(withSuccess(CONTENT, MediaType.APPLICATION_XML));
sut.analyzeFile(file, Collections.singleton(vocabulary.getUri()));
mockServer.verify();
}

@Test
void analyzeFileThrowsWebServiceIntegrationExceptionOnError() throws Exception {
final TextAnalysisInput input = textAnalysisInput();
Expand Down Expand Up @@ -353,4 +372,26 @@ void analyzeTermDefinitionDoesNothingWhenTextAnalysisServiceUrlIsNotConfigured()
verify(annotationGeneratorMock, never()).generateAnnotations(any(), any(Term.class));
verify(textAnalysisRecordDao, never()).persist(any());
}

@Test
void analyzeTermDefinitionInvokesTextAnalysisServiceWithVocabularyRepositoryUsernameAndPassword()
throws Exception {
final Term term = Generator.generateTermWithId();
term.setVocabulary(vocabulary.getUri());
final TextAnalysisInput input = textAnalysisInput();
input.setContent(term.getDefinition().get(Environment.LANGUAGE));
final String username = "user";
config.getRepository().setUsername(username);
final String password = "password";
config.getRepository().setPassword(password);
input.setVocabularyRepositoryUserName(username);
input.setVocabularyRepositoryPassword(password);
mockServer.expect(requestTo(config.getTextAnalysis().getUrl()))
.andExpect(method(HttpMethod.POST))
.andExpect(content().string(objectMapper.writeValueAsString(input)))
.andRespond(withSuccess(CONTENT, MediaType.APPLICATION_XML));

sut.analyzeTermDefinition(term, vocabulary.getUri());
mockServer.verify();
}
}