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

Entities: configuring whether name variants should be used #2561

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions dspace-api/src/main/java/org/dspace/app/util/DCInput.java
Expand Up @@ -89,6 +89,11 @@ public class DCInput {
*/
private boolean repeatable = false;

/**
* should name-variants be used?
*/
private boolean nameVariants = false;

/**
* 'hint' text to display
*/
Expand Down Expand Up @@ -183,6 +188,9 @@ public DCInput(Map<String, String> fieldMap, Map<String, List<String>> listMap)
String repStr = fieldMap.get("repeatable");
repeatable = "true".equalsIgnoreCase(repStr)
|| "yes".equalsIgnoreCase(repStr);
String nameVariantsString = fieldMap.get("name-variants");
nameVariants = (StringUtils.isNotBlank(nameVariantsString)) ?
nameVariantsString.equalsIgnoreCase("true") : false;
label = fieldMap.get("label");
inputType = fieldMap.get("input-type");
// these types are list-controlled
Expand Down Expand Up @@ -269,6 +277,15 @@ public boolean getRepeatable() {
return isRepeatable();
}

/**
* Get the nameVariants flag for this row
*
* @return the nameVariants flag
*/
public boolean areNameVariantsAllowed() {
tdonohue marked this conversation as resolved.
Show resolved Hide resolved
return nameVariants;
}

/**
* Get the input type for this row
*
Expand Down
Expand Up @@ -14,11 +14,12 @@
<!-- Each form set contains an ordered set of pages; each page defines -->
<!-- one submission metadata entry screen. Each page has an ordered list -->
<!-- of field definitions, Each field definition corresponds to one -->
<!-- metadata entry (a so-called row), which has a DC element name, a -->
<!-- metadata entry (a so-called row), which has a DC element name, a -->
<!-- displayed label, a text string prompt which is called a hint, and -->
<!-- an input-type. Each field also may hold optional elements: DC -->
<!-- qualifier name, a repeatable flag, and a text string whose presence -->
<!-- serves as a 'this field is required' flag. -->
<!-- qualifier name, a repeatable flag, an optional name-variants allowed -->
<!-- flag, and a text string whose presence &ndash;&gt; serves as a -->
benbosman marked this conversation as resolved.
Show resolved Hide resolved
<!-- 'this field is required' flag. -->

<form-definitions>
<form name="bitstream-metadata">
Expand Down Expand Up @@ -53,6 +54,7 @@
<relationship-type>isAuthorOfPublication</relationship-type>
<search-configuration>personConfiguration</search-configuration>
<repeatable>true</repeatable>
<name-variants>true</name-variants>
<label>Author</label>
<hint>Add an author</hint>
<linked-metadata-field>
Expand Down
Expand Up @@ -170,6 +170,7 @@ private SelectableRelationship getSelectableRelationships(DCInput dcinput) {
selectableRelationship.setRelationshipType(dcinput.getRelationshipType());
selectableRelationship.setFilter(dcinput.getFilter());
selectableRelationship.setSearchConfiguration(dcinput.getSearchConfiguration());
selectableRelationship.setNameVariants(String.valueOf(dcinput.areNameVariantsAllowed()));
return selectableRelationship;
}

Expand Down
Expand Up @@ -23,6 +23,7 @@ public class SelectableRelationship {
private String relationshipType;
private String filter;
private String searchConfiguration;
private String nameVariants;

public void setRelationshipType(String relationshipType) {
this.relationshipType = relationshipType;
Expand All @@ -47,4 +48,12 @@ public void setSearchConfiguration(String searchConfiguration) {
public String getSearchConfiguration() {
return searchConfiguration;
}

public void setNameVariants(String nameVariants) {
this.nameVariants = nameVariants;
}

public String getNameVariants() {
return nameVariants;
}
}
Expand Up @@ -78,7 +78,7 @@ public void findTraditionalPageOne() throws Exception {
// check the first two rows
.andExpect(jsonPath("$.rows[0].fields", contains(
SubmissionFormFieldMatcher.matchFormFieldDefinition("name", "Author",
null, true, "Add an author", "dc.contributor.author"))))
null, true,"Add an author", "dc.contributor.author"))))
.andExpect(jsonPath("$.rows[1].fields", contains(
SubmissionFormFieldMatcher.matchFormFieldDefinition("onebox", "Title",
"You must enter a main title for this item.", false,
Expand All @@ -90,9 +90,9 @@ public void findTraditionalPageOne() throws Exception {
"You must enter at least the year.", false,
"Please give the date", "col-sm-4",
"dc.date.issued"),
SubmissionFormFieldMatcher.matchFormFieldDefinition("onebox", "Publisher", null, false,
"Enter the name of", "col-sm-8",
"dc.publisher"))))
SubmissionFormFieldMatcher.matchFormFieldDefinition("onebox", "Publisher",
null, false,"Enter the name of",
"col-sm-8","dc.publisher"))))
;
}

Expand All @@ -114,9 +114,9 @@ public void findOpenRelationshipConfig() throws Exception {
// check the first two rows
.andExpect(jsonPath("$.rows[0].fields", contains(
SubmissionFormFieldMatcher.matchFormOpenRelationshipFieldDefinition("name",
"Author", null, true, "Add an author",
"Author", null, true,"Add an author",
"dc.contributor.author", "isAuthorOfPublication", null,
"personConfiguration"))))
"personConfiguration", true))))
;
}

Expand All @@ -138,8 +138,8 @@ public void findClosedRelationshipConfig() throws Exception {
// check the first two rows
.andExpect(jsonPath("$.rows[0].fields", contains(
SubmissionFormFieldMatcher.matchFormClosedRelationshipFieldDefinition("Journal", null,
false, "Select the journal related to this volume.", "isVolumeOfJournal",
"creativework.publisher:somepublishername", "periodicalConfiguration"))))
false,"Select the journal related to this volume.", "isVolumeOfJournal",
"creativework.publisher:somepublishername", "periodicalConfiguration", false))))
;
}
}
}
Expand Up @@ -13,6 +13,8 @@
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;

import javax.annotation.Nullable;

import org.hamcrest.Matcher;

/**
Expand Down Expand Up @@ -47,7 +49,8 @@ private SubmissionFormFieldMatcher() {
* @return a Matcher for all the condition above
*/
public static Matcher<? super Object> matchFormFieldDefinition(String type, String label, String mandatoryMessage,
boolean repeatable, String hints, String metadata) {
boolean repeatable,
String hints, String metadata) {
return matchFormFieldDefinition(type, label, mandatoryMessage, repeatable, hints, null, metadata);
}

Expand All @@ -73,8 +76,8 @@ public static Matcher<? super Object> matchFormFieldDefinition(String type, Stri
* @return a Matcher for all the condition above
*/
public static Matcher<? super Object> matchFormFieldDefinition(String type, String label, String mandatoryMessage,
boolean repeatable, String hints, String style,
String metadata) {
boolean repeatable,
String hints, String style, String metadata) {
return allOf(
// check each field definition
hasJsonPath("$.input.type", is(type)),
Expand Down Expand Up @@ -113,19 +116,26 @@ public static Matcher<? super Object> matchFormFieldDefinition(String type, Stri
* the optional filter to be used for the lookup
* @param searchConfiguration
* the searchConfiguration to be used for the lookup
* @param nameVariants
* the optional name variants allowed flag
* @return a Matcher for all the condition above
*/
public static Matcher<? super Object> matchFormOpenRelationshipFieldDefinition(String type, String label,
String mandatoryMessage,
boolean repeatable, String hints,
boolean repeatable,
String hints,
String metadata,
String relationshipType,
String filter,
String searchConfiguration) {
String searchConfiguration,
@Nullable Boolean nameVariants) {
benbosman marked this conversation as resolved.
Show resolved Hide resolved
return allOf(
hasJsonPath("$.selectableRelationship.relationshipType", is(relationshipType)),
hasJsonPath("$.selectableRelationship.filter", is(filter)),
hasJsonPath("$.selectableRelationship.searchConfiguration", is(searchConfiguration)),
nameVariants != null ?
hasJsonPath("$.selectableRelationship.nameVariants", is(nameVariants.toString()))
benbosman marked this conversation as resolved.
Show resolved Hide resolved
: hasNoJsonPath("$.selectableRelationship.nameVariants"),
matchFormFieldDefinition(type, label, mandatoryMessage, repeatable, hints, metadata));
}

Expand All @@ -148,18 +158,25 @@ public static Matcher<? super Object> matchFormOpenRelationshipFieldDefinition(S
* the optional filter to be used for the lookup
* @param searchConfiguration
* the searchConfiguration to be used for the lookup
* @param nameVariants
* the optional name variants allowed flag
* @return a Matcher for all the condition above
*/
public static Matcher<? super Object> matchFormClosedRelationshipFieldDefinition(String label,
String mandatoryMessage,
boolean repeatable, String hints,
boolean repeatable,
String hints,
String relationshipType,
String filter,
String searchConfiguration) {
String searchConfiguration,
@Nullable Boolean nameVariants) {
return allOf(
hasJsonPath("$.selectableRelationship.relationshipType", is(relationshipType)),
hasJsonPath("$.selectableRelationship.filter", is(filter)),
hasJsonPath("$.selectableRelationship.searchConfiguration", is(searchConfiguration)),
nameVariants != null ?
hasJsonPath("$.selectableRelationship.nameVariants", is(nameVariants.toString()))
: hasNoJsonPath("$.selectableRelationship.nameVariants"),
hasJsonPath("$.label", is(label)),
mandatoryMessage != null ? hasJsonPath("$.mandatoryMessage", containsString(mandatoryMessage)) :
hasNoJsonPath("$.mandatoryMessage"),
Expand Down
3 changes: 2 additions & 1 deletion dspace/config/submission-forms.dtd
Expand Up @@ -22,6 +22,7 @@

<!ELEMENT hint (#PCDATA) >
<!ELEMENT required (#PCDATA)>
<!ELEMENT name-variants (#PCDATA)>
<!ELEMENT regex (#PCDATA) >

<!ELEMENT form-value-pairs (value-pairs)* >
Expand Down Expand Up @@ -59,5 +60,5 @@
<!ELEMENT relationship-type (#PCDATA) >
<!ELEMENT search-configuration (#PCDATA) >
<!ELEMENT filter (#PCDATA) >
<!ELEMENT relation-field (relationship-type, search-configuration, filter?, repeatable?, label, type-bind?, hint, linked-metadata-field?, required?, visibility?)>
<!ELEMENT relation-field (relationship-type, search-configuration, filter?, repeatable?, name-variants?, label, type-bind?, hint, linked-metadata-field?, required?, visibility?)>
<!ELEMENT linked-metadata-field (dc-schema, dc-element, dc-qualifier?, input-type)>