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

migrate2clarin7/authors-name-surname-autocomplete #235

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,19 @@ public Page<MetadataValueWrapperRest> findByValue(@Parameter(value = "schema", r
DiscoverResult searchResult = searchService.search(context, discoverQuery);
for (IndexableObject object : searchResult.getIndexableObjects()) {
if (object instanceof IndexableItem) {
// get metadata values of the item
// Get the item which has the metadata with the search value
List<MetadataValue> metadataValues = itemService.getMetadataByMetadataString(
((IndexableItem) object).getIndexedObject(), metadataField);

// The Item could have more metadata than the metadata with searching value, filter that metadata
String finalSearchValue = searchValue;
List<MetadataValue> filteredMetadataValues = metadataValues.stream()
.filter(metadataValue -> metadataValue.getValue().contains(finalSearchValue))
.collect(Collectors.toList());

// convert metadata values to the wrapper
List<MetadataValueWrapper> metadataValueWrapperList =
this.convertMetadataValuesToWrappers(metadataValues);
this.convertMetadataValuesToWrappers(filteredMetadataValues);
metadataValueWrappers.addAll(metadataValueWrapperList);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public class MetadataValueRestRepositoryIT extends AbstractControllerIntegration
private Item publicItem;
private Item sponsorItem;

private Collection col;

public static final String METADATAVALUES_ENDPOINT = "/api/core/metadatavalues/";
private static final String SEARCH_BYVALUE_ENDPOINT = METADATAVALUES_ENDPOINT + "search/byValue";

Expand All @@ -63,7 +65,7 @@ public void setup() throws Exception {
.withName("Parent Community")
.build();

Collection col = CollectionBuilder.createCollection(context, parentCommunity).withName("Collection").build();
col = CollectionBuilder.createCollection(context, parentCommunity).withName("Collection").build();

// 2. Create item and add it to the collection
publicItem = ItemBuilder.createItem(context, col)
Expand Down Expand Up @@ -287,6 +289,46 @@ public void shouldNotReturnSponsorSuggestion() throws Exception {
.andExpect(jsonPath("$.page.totalElements", is(0)));
}

/**
* If the Item has more metadata values in the metadata field e.g. it has more authors, return only the
* values which matches the search value.
*/
@Test
public void shouldReturnOneSuggestionWhenInputHasMoreMetadataValues() throws Exception {
context.turnOffAuthorisationSystem();
Item cuteItem = ItemBuilder.createItem(context, col)
.withAuthor(AUTHOR)
.withAuthor("second author")
.withAuthor("third author")
.withMetadata(SPONSOR_SCHEMA, SPONSOR_ELEMENT, null, SPONSOR_VALUE )
.build();
context.restoreAuthSystemState();

MetadataValue titleMetadataValue = itemService.getMetadataByMetadataString(cuteItem,
StringUtils.join(Arrays.asList(SCHEMA, ELEMENT, QUALIFIER),".")).get(0);

String metadataSchema = titleMetadataValue.getMetadataField().getMetadataSchema().getName();
String metadataElement = titleMetadataValue.getMetadataField().getElement();
String metadataQualifier = titleMetadataValue.getMetadataField().getQualifier();
String searchValue = titleMetadataValue.getValue();

getClient().perform(get(SEARCH_BYVALUE_ENDPOINT)
.param("schema", metadataSchema)
.param("element",metadataElement)
.param("qualifier",metadataQualifier)
.param("searchValue",searchValue))
.andExpect(status().isOk())
.andExpect(content().contentType(contentType))
.andExpect(jsonPath("$._embedded.metadatavalues", Matchers.hasItem(
MetadataValueMatcher.matchMetadataValueByKeys(titleMetadataValue.getValue(),
titleMetadataValue.getLanguage(), titleMetadataValue.getAuthority(),
titleMetadataValue.getConfidence(), titleMetadataValue.getPlace()))
))
.andExpect(jsonPath("$.page.size", is(20)))
.andExpect(jsonPath("$.page.totalElements", is(1)));
}


private MetadataValue getTitleMetadataValue() {
return itemService.getMetadataByMetadataString(publicItem,
StringUtils.join(Arrays.asList(SCHEMA, ELEMENT, QUALIFIER),".")).get(0);
Expand Down
2 changes: 1 addition & 1 deletion dspace/config/submission-forms.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
<dc-qualifier>author</dc-qualifier>
<repeatable>true</repeatable>
<label>Author</label>
<input-type>autocomplete</input-type>
<input-type>clarin-name</input-type>
<hint>Enter the author's name (Family name, Given names).</hint>
<required></required>
<!-- Example ACL field definition.
Expand Down