Skip to content

Commit

Permalink
[Enhancement kbss-cvut/termit-ui#520] Use constants for api descripti…
Browse files Browse the repository at this point in the history
…on in TermController & add constructors for ChangeRecordFilterDto
  • Loading branch information
lukaskabc committed Nov 24, 2024
1 parent de1e76a commit 58302d9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@ public class ChangeRecordFilterDto {
private String authorName = "";
private URI changeType = null;

public ChangeRecordFilterDto() {
}

public ChangeRecordFilterDto(String changedAttributeName, String authorName, URI changeType) {
this.changedAttributeName = changedAttributeName;
this.authorName = authorName;
this.changeType = changeType;
}

public ChangeRecordFilterDto(String assetLabel, String changedAttributeName, String authorName, URI changeType) {
this.assetLabel = assetLabel;
this.changedAttributeName = changedAttributeName;
this.authorName = authorName;
this.changeType = changeType;
}

public String getAssetLabel() {
return assetLabel;
}
Expand Down
20 changes: 7 additions & 13 deletions src/main/java/cz/cvut/kbss/termit/rest/TermController.java
Original file line number Diff line number Diff line change
Expand Up @@ -700,16 +700,13 @@ public List<AbstractChangeRecord> getHistory(
@Parameter(description = ApiDoc.ID_NAMESPACE_DESCRIPTION, example = ApiDoc.ID_NAMESPACE_EXAMPLE)
@RequestParam(name = QueryParams.NAMESPACE, required = false) Optional<String> namespace,
@Parameter(description = ChangeRecordFilterDto.ApiDoc.CHANGE_TYPE_DESCRIPTION)
@RequestParam(name = "type", required = false) URI changeType,
@RequestParam(name = "changeType", required = false) URI changeType,
@Parameter(description = ChangeRecordFilterDto.ApiDoc.AUTHOR_NAME_DESCRIPTION)
@RequestParam(name = "author", required = false, defaultValue = "") String authorName,
@Parameter(description = ChangeRecordFilterDto.ApiDoc.CHANGED_ATTRIBUTE_DESCRIPTION)
@RequestParam(name = "attribute", required = false, defaultValue = "") String changedAttributeName) {
final URI termUri = getTermUri(localName, termLocalName, namespace);
final ChangeRecordFilterDto filterDto = new ChangeRecordFilterDto();
filterDto.setChangeType(changeType);
filterDto.setAuthorName(authorName);
filterDto.setChangedAttributeName(changedAttributeName);
final ChangeRecordFilterDto filterDto = new ChangeRecordFilterDto(changedAttributeName, authorName, changeType);
return termService.getChanges(termService.findRequired(termUri), filterDto);
}

Expand All @@ -734,19 +731,16 @@ public List<AbstractChangeRecord> getHistory(@Parameter(description = ApiDoc.ID_
@Parameter(description = ApiDoc.ID_STANDALONE_NAMESPACE_DESCRIPTION,
example = ApiDoc.ID_STANDALONE_NAMESPACE_EXAMPLE)
@RequestParam(name = QueryParams.NAMESPACE) String namespace,
@Parameter(description = "Change type used for filtering.")
@RequestParam(name = "type", required = false) URI changeType,
@Parameter(description = "Author name used for filtering.")
@Parameter(description = ChangeRecordFilterDto.ApiDoc.CHANGE_TYPE_DESCRIPTION)
@RequestParam(name = "changeType", required = false) URI changeType,
@Parameter(description = ChangeRecordFilterDto.ApiDoc.AUTHOR_NAME_DESCRIPTION)
@RequestParam(name = "author", required = false,
defaultValue = "") String authorName,
@Parameter(description = "Changed attribute name used for filtering.")
@Parameter(description = ChangeRecordFilterDto.ApiDoc.CHANGED_ATTRIBUTE_DESCRIPTION)
@RequestParam(name = "attribute", required = false,
defaultValue = "") String changedAttributeName) {
final URI termUri = idResolver.resolveIdentifier(namespace, localName);
final ChangeRecordFilterDto filter = new ChangeRecordFilterDto();
filter.setChangeType(changeType);
filter.setAuthorName(authorName);
filter.setChangedAttributeName(changedAttributeName);
final ChangeRecordFilterDto filter = new ChangeRecordFilterDto(changedAttributeName, authorName, changeType);
return termService.getChanges(termService.findRequired(termUri), filter);
}

Expand Down
11 changes: 2 additions & 9 deletions src/main/java/cz/cvut/kbss/termit/rest/VocabularyController.java
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,7 @@ public List<AbstractChangeRecord> getHistory(
@RequestParam(name = "attribute", required = false, defaultValue = "") String changedAttributeName) {
final Vocabulary vocabulary = vocabularyService.getReference(
resolveVocabularyUri(localName, namespace));
final ChangeRecordFilterDto filterDto = new ChangeRecordFilterDto();
filterDto.setChangeType(changeType);
filterDto.setAuthorName(authorName);
filterDto.setChangedAttributeName(changedAttributeName);
final ChangeRecordFilterDto filterDto = new ChangeRecordFilterDto(changedAttributeName, authorName, changeType);
return vocabularyService.getChanges(vocabulary, filterDto);
}

Expand Down Expand Up @@ -330,11 +327,7 @@ public List<AbstractChangeRecord> getDetailedHistoryOfContent(
name = Constants.QueryParams.PAGE, required = false, defaultValue = DEFAULT_PAGE) Integer pageNo) {
final Pageable pageReq = createPageRequest(pageSize, pageNo);
final Vocabulary vocabulary = vocabularyService.getReference(resolveVocabularyUri(localName, namespace));
final ChangeRecordFilterDto filter = new ChangeRecordFilterDto();
filter.setAssetLabel(termName);
filter.setChangeType(changeType);
filter.setAuthorName(authorName);
filter.setChangedAttributeName(changedAttributeName);
final ChangeRecordFilterDto filter = new ChangeRecordFilterDto(termName, changedAttributeName, authorName, changeType);
return vocabularyService.getDetailedHistoryOfContent(vocabulary, filter, pageReq);
}

Expand Down

0 comments on commit 58302d9

Please sign in to comment.