Skip to content

Commit

Permalink
[kbss-cvut/termit-ui#449] Set imported term state to configured initi…
Browse files Browse the repository at this point in the history
…al if Excel does not specify it.
  • Loading branch information
ledsoft committed Aug 17, 2024
1 parent 8c9d086 commit 7d0ecbd
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,7 @@ private void mapRowToTermAttributes(Term term, Row termRow) {
getAttributeValue(termRow, SKOS.EXACT_MATCH).ifPresent(
exm -> mapSkosMatchProperties(term, SKOS.EXACT_MATCH, splitIntoMultipleValues(exm)));
getAttributeValue(termRow, JsonLd.TYPE).flatMap(this::resolveTermType).ifPresent(t -> term.setTypes(Set.of(t)));
getAttributeValue(termRow, Vocabulary.s_p_ma_stav_pojmu).flatMap(this::resolveTermState)
.ifPresent(term::setState);
resolveTermState(getAttributeValue(termRow, Vocabulary.s_p_ma_stav_pojmu).orElse(null)).ifPresent(term::setState);

}

Expand Down Expand Up @@ -290,10 +289,17 @@ private Optional<String> resolveTermType(String value) {
}

private Optional<URI> resolveTermState(String value) {
return languageService.getTermStates().stream()
if (value == null) {
return languageService.getInitialTermState().map(RdfsResource::getUri);
}
final Optional<URI> state = languageService.getTermStates().stream()
.filter(t -> value.equals(t.getLabel().get(langTag)) || value.equals(
t.getUri().toString())).findFirst()
.map(RdfsResource::getUri);
if (state.isPresent()) {
return state;
}
return languageService.getInitialTermState().map(RdfsResource::getUri);
}

List<ExcelImporter.TermRelationship> getRawDataToInsert() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -539,4 +539,34 @@ void importResolvesTermStateAndTypesUsingLabels() {
assertEquals(Set.of(type.getUri().toString()), result.getTypes());
assertEquals(state.getUri(), result.getState());
}

@Test
void importSetsConfiguredInitialTermStateWhenSheetDoesNotSpecifyIt() {
when(vocabularyDao.exists(vocabulary.getUri())).thenReturn(true);
when(vocabularyDao.find(vocabulary.getUri())).thenReturn(Optional.of(vocabulary));
final RdfsResource state = new RdfsResource(
URI.create("http://onto.fel.cvut.cz/ontologies/application/termit/pojem/navrhovaný-pojem"),
MultilingualString.create("Proposed term", Constants.DEFAULT_LANGUAGE), null,
"http://onto.fel.cvut.cz/ontologies/slovník/agendový/popis-dat/pojem/stav-pojmu");
when(languageService.getInitialTermState()).thenReturn(Optional.of(state));
initIdentifierGenerator(Constants.DEFAULT_LANGUAGE, false);

final Vocabulary result = sut.importVocabulary(
new VocabularyImporter.ImportConfiguration(false, vocabulary.getUri(), prePersist),
new VocabularyImporter.ImportInput(Constants.MediaType.EXCEL,
Environment.loadFile(
"data/import-simple-en.xlsx")));
assertEquals(vocabulary, result);
final ArgumentCaptor<Term> captor = ArgumentCaptor.forClass(Term.class);
verify(termService, times(2)).addRootTermToVocabulary(captor.capture(), eq(vocabulary));
assertEquals(2, captor.getAllValues().size());
final Optional<Term> building = captor.getAllValues().stream()
.filter(t -> "Building".equals(t.getLabel().get("en"))).findAny();
assertTrue(building.isPresent());
assertEquals(state.getUri(), building.get().getState());
final Optional<Term> construction = captor.getAllValues().stream()
.filter(t -> "Construction".equals(t.getLabel().get("en"))).findAny();
assertTrue(construction.isPresent());
assertEquals(state.getUri(), construction.get().getState());
}
}

0 comments on commit 7d0ecbd

Please sign in to comment.