[TLC-254] Make type bind config dynamic, fix test comments

This commit is contained in:
Kim Shepherd
2022-05-06 15:43:15 +12:00
parent 78e187e6a8
commit 1abf906db8
4 changed files with 19 additions and 13 deletions

View File

@@ -31,6 +31,7 @@ import org.dspace.content.InProgressSubmission;
import org.dspace.content.MetadataValue; import org.dspace.content.MetadataValue;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.core.Utils; import org.dspace.core.Utils;
import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory; import org.dspace.services.factory.DSpaceServicesFactory;
/** /**
@@ -44,11 +45,11 @@ public class DescribeStep extends AbstractProcessingStep {
private static final Logger log = org.apache.logging.log4j.LogManager.getLogger(DescribeStep.class); private static final Logger log = org.apache.logging.log4j.LogManager.getLogger(DescribeStep.class);
// Input reader for form configuration
private DCInputsReader inputReader; private DCInputsReader inputReader;
// Configuration service
private static final String DOCUMENT_TYPE_FIELD = private final ConfigurationService configurationService =
DSpaceServicesFactory.getInstance().getConfigurationService().getProperty("submit.type-bind.field", DSpaceServicesFactory.getInstance().getConfigurationService();
"dc.type");
public DescribeStep() throws DCInputsReaderException { public DescribeStep() throws DCInputsReaderException {
inputReader = new DCInputsReader(); inputReader = new DCInputsReader();
@@ -70,7 +71,8 @@ public class DescribeStep extends AbstractProcessingStep {
private void readField(InProgressSubmission obj, SubmissionStepConfig config, DataDescribe data, private void readField(InProgressSubmission obj, SubmissionStepConfig config, DataDescribe data,
DCInputSet inputConfig) throws DCInputsReaderException { DCInputSet inputConfig) throws DCInputsReaderException {
String documentTypeValue = ""; String documentTypeValue = "";
List<MetadataValue> documentType = itemService.getMetadataByMetadataString(obj.getItem(), DOCUMENT_TYPE_FIELD); List<MetadataValue> documentType = itemService.getMetadataByMetadataString(obj.getItem(),
configurationService.getProperty("submit.type-bind.field", "dc.type"));
if (documentType.size() > 0) { if (documentType.size() > 0) {
documentTypeValue = documentType.get(0).getValue(); documentTypeValue = documentType.get(0).getValue();
} }

View File

@@ -26,7 +26,7 @@ import org.dspace.content.InProgressSubmission;
import org.dspace.content.MetadataValue; import org.dspace.content.MetadataValue;
import org.dspace.content.authority.service.MetadataAuthorityService; import org.dspace.content.authority.service.MetadataAuthorityService;
import org.dspace.content.service.ItemService; import org.dspace.content.service.ItemService;
import org.dspace.services.factory.DSpaceServicesFactory; import org.dspace.services.ConfigurationService;
/** /**
* Execute three validation check on fields validation: * Execute three validation check on fields validation:
@@ -44,10 +44,6 @@ public class MetadataValidation extends AbstractValidation {
private static final String ERROR_VALIDATION_REGEX = "error.validation.regex"; private static final String ERROR_VALIDATION_REGEX = "error.validation.regex";
private static final String DOCUMENT_TYPE_FIELD =
DSpaceServicesFactory.getInstance().getConfigurationService().getProperty("submit.type-bind.field",
"dc.type");
private static final Logger log = org.apache.logging.log4j.LogManager.getLogger(MetadataValidation.class); private static final Logger log = org.apache.logging.log4j.LogManager.getLogger(MetadataValidation.class);
private DCInputsReader inputReader; private DCInputsReader inputReader;
@@ -56,6 +52,8 @@ public class MetadataValidation extends AbstractValidation {
private MetadataAuthorityService metadataAuthorityService; private MetadataAuthorityService metadataAuthorityService;
private ConfigurationService configurationService;
@Override @Override
public List<ErrorRest> validate(SubmissionService submissionService, InProgressSubmission obj, public List<ErrorRest> validate(SubmissionService submissionService, InProgressSubmission obj,
SubmissionStepConfig config) throws DCInputsReaderException, SQLException { SubmissionStepConfig config) throws DCInputsReaderException, SQLException {
@@ -63,7 +61,8 @@ public class MetadataValidation extends AbstractValidation {
List<ErrorRest> errors = new ArrayList<>(); List<ErrorRest> errors = new ArrayList<>();
String documentTypeValue = ""; String documentTypeValue = "";
DCInputSet inputConfig = getInputReader().getInputsByFormName(config.getId()); DCInputSet inputConfig = getInputReader().getInputsByFormName(config.getId());
List<MetadataValue> documentType = itemService.getMetadataByMetadataString(obj.getItem(), DOCUMENT_TYPE_FIELD); List<MetadataValue> documentType = itemService.getMetadataByMetadataString(obj.getItem(),
configurationService.getProperty("submit.type-bind.field", "dc.type"));
if (documentType.size() > 0) { if (documentType.size() > 0) {
documentTypeValue = documentType.get(0).getValue(); documentTypeValue = documentType.get(0).getValue();
} }
@@ -150,6 +149,10 @@ public class MetadataValidation extends AbstractValidation {
} }
} }
public void setConfigurationService(ConfigurationService configurationService) {
this.configurationService = configurationService;
}
public void setItemService(ItemService itemService) { public void setItemService(ItemService itemService) {
this.itemService = itemService; this.itemService = itemService;
} }

View File

@@ -16,6 +16,7 @@
<bean name="metadataValidation" class="org.dspace.app.rest.submit.step.validation.MetadataValidation" <bean name="metadataValidation" class="org.dspace.app.rest.submit.step.validation.MetadataValidation"
scope="prototype"> scope="prototype">
<property name="name" value="submission-form"/> <property name="name" value="submission-form"/>
<property name="configurationService" ref="org.dspace.services.ConfigurationService"/>
<property name="itemService" ref="org.dspace.content.ItemServiceImpl"/> <property name="itemService" ref="org.dspace.content.ItemServiceImpl"/>
<property name="metadataAuthorityService" ref="org.dspace.content.authority.MetadataAuthorityServiceImpl"/> <property name="metadataAuthorityService" ref="org.dspace.content.authority.MetadataAuthorityServiceImpl"/>
</bean> </bean>

View File

@@ -2030,7 +2030,7 @@ public class WorkspaceItemRestRepositoryIT extends AbstractControllerIntegration
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("$.errors").doesNotExist()) .andExpect(jsonPath("$.errors").doesNotExist())
.andExpect(jsonPath("$", .andExpect(jsonPath("$",
// Check this - we should match an item with no series or type // Check this - we should match an item with the expected series and type
Matchers.is(WorkspaceItemMatcher.matchItemWithTypeAndSeries(witem, Matchers.is(WorkspaceItemMatcher.matchItemWithTypeAndSeries(witem,
"Technical Report", "New Series")))); "Technical Report", "New Series"))));
@@ -2039,7 +2039,7 @@ public class WorkspaceItemRestRepositoryIT extends AbstractControllerIntegration
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("$.errors").doesNotExist()) .andExpect(jsonPath("$.errors").doesNotExist())
.andExpect(jsonPath("$", .andExpect(jsonPath("$",
// Check this - we should match an item with no series or type // Check this - we should match an item with the expected series and type
Matchers.is(WorkspaceItemMatcher.matchItemWithTypeAndSeries(witem, Matchers.is(WorkspaceItemMatcher.matchItemWithTypeAndSeries(witem,
"Technical Report", "New Series")))); "Technical Report", "New Series"))));