Comment and minor improvements

This commit is contained in:
Pasquale Cavallo
2020-06-24 14:52:33 +02:00
parent 530a9d5fac
commit ecefb1a302
6 changed files with 35 additions and 25 deletions

View File

@@ -19,9 +19,10 @@ import org.dspace.importer.external.service.components.dto.PlainMetadataKeyValue
import org.dspace.importer.external.service.components.dto.PlainMetadataSourceDto; import org.dspace.importer.external.service.components.dto.PlainMetadataSourceDto;
/** /**
* Metadata contributor that takes an PlainMetadataSourceDto instance and turns it into a metadatum * Metadata contributor that takes an PlainMetadataSourceDto instance and turns it into a
* collection of metadatum
* *
* @author Roeland Dillen (roeland at atmire dot com) * @author Pasquale Cavallo (pasquale.cavallo at 4science dot it)
*/ */
public class SimpleMetadataContributor implements MetadataContributor<PlainMetadataSourceDto> { public class SimpleMetadataContributor implements MetadataContributor<PlainMetadataSourceDto> {
@@ -57,15 +58,14 @@ public class SimpleMetadataContributor implements MetadataContributor<PlainMetad
* In case of success, new metadatum is constructer (using field elements and PlainMetadataSourceDto value) * In case of success, new metadatum is constructer (using field elements and PlainMetadataSourceDto value)
* and added to the list. * and added to the list.
* *
* @param t A class to retrieve metadata and key to match from. * @param t A class to retrieve metadata and key to match from. t and contained list "metadata" MUST be not null.
* @return a collection of import records. Only the identifier of the found records may be put in the record. * @return a collection of import records. Only the identifier of the found records may be put in the record.
*/ */
@Override @Override
public Collection<MetadatumDTO> contributeMetadata(PlainMetadataSourceDto t) { public Collection<MetadatumDTO> contributeMetadata(PlainMetadataSourceDto t) {
List<MetadatumDTO> values = new LinkedList<>(); List<MetadatumDTO> values = new LinkedList<>();
try {
for (PlainMetadataKeyValueItem metadatum : t.getMetadata()) { for (PlainMetadataKeyValueItem metadatum : t.getMetadata()) {
if (metadatum.getKey().equals(key)) { if (key.equals(metadatum.getKey())) {
MetadatumDTO dcValue = new MetadatumDTO(); MetadatumDTO dcValue = new MetadatumDTO();
dcValue.setValue(metadatum.getValue()); dcValue.setValue(metadatum.getValue());
dcValue.setElement(field.getElement()); dcValue.setElement(field.getElement());
@@ -74,9 +74,6 @@ public class SimpleMetadataContributor implements MetadataContributor<PlainMetad
values.add(dcValue); values.add(dcValue);
} }
} }
} catch (Exception e) {
throw new RuntimeException(e);
}
return values; return values;
} }

View File

@@ -28,7 +28,8 @@ import org.springframework.beans.factory.annotation.Required;
* *
* @author Roeland Dillen (roeland at atmire dot com) * @author Roeland Dillen (roeland at atmire dot com)
*/ */
public abstract class AbstractImportMetadataSourceService<RecordType> extends AbstractRemoteMetadataSource { public abstract class AbstractImportMetadataSourceService<RecordType> extends AbstractRemoteMetadataSource
implements MetadataSource {
private GenerateQueryService generateQueryForItem = null; private GenerateQueryService generateQueryForItem = null;
private MetadataFieldMapping<RecordType, MetadataContributor<RecordType>> metadataFieldMapping; private MetadataFieldMapping<RecordType, MetadataContributor<RecordType>> metadataFieldMapping;

View File

@@ -12,24 +12,37 @@ package org.dspace.importer.external.service.components.dto;
* *
* @author Pasquale Cavallo (pasquale.cavallo at 4science dot it) * @author Pasquale Cavallo (pasquale.cavallo at 4science dot it)
*/ */
public class PlainMetadataKeyValueItem { public class PlainMetadataKeyValueItem {
private String key; private String key;
private String value; private String value;
/*
* In a key-value items, like PlainMetadata, this method get the item's key
*/
public String getKey() { public String getKey() {
return key; return key;
} }
/*
* In a key-value items, like PlainMetadata, this method set the item's key.
* Never set or leave this field to null
*
*/
public void setKey(String key) { public void setKey(String key) {
this.key = key; this.key = key;
} }
/*
* In key-value items, like PlainMetadata, this method get the item's value
*/
public String getValue() { public String getValue() {
return value; return value;
} }
/*
* In key-value items, like PlainMetadata, this method set the item's value
*/
public void setValue(String value) { public void setValue(String value) {
this.value = value; this.value = value;
} }

View File

@@ -21,10 +21,16 @@ public class PlainMetadataSourceDto {
private List<PlainMetadataKeyValueItem> metadata; private List<PlainMetadataKeyValueItem> metadata;
/*
* Method used to get the Metadata list
*/
public List<PlainMetadataKeyValueItem> getMetadata() { public List<PlainMetadataKeyValueItem> getMetadata() {
return metadata; return metadata;
} }
/*
* Method used to set the metadata list
*/
public void setMetadata(List<PlainMetadataKeyValueItem> metadata) { public void setMetadata(List<PlainMetadataKeyValueItem> metadata) {
this.metadata = metadata; this.metadata = metadata;
} }

View File

@@ -53,13 +53,6 @@
<!-- <property name="metadataFieldMapping" ref="BibtexMetadataFieldMapping"/> --> <!-- <property name="metadataFieldMapping" ref="BibtexMetadataFieldMapping"/> -->
</bean> </bean>
<!--
<bean id="BibtexMetadataFieldMapping"
class="org.dspace.importer.external.bibtex.service.BibtexFieldMapping">
</bean>
-->
<!-- Metadatafield used to check against if it's already imported or not during the JSONLookupSearcher--> <!-- Metadatafield used to check against if it's already imported or not during the JSONLookupSearcher-->
<bean id="lookupID" class="org.dspace.importer.external.metadatamapping.MetadataFieldConfig"> <bean id="lookupID" class="org.dspace.importer.external.metadatamapping.MetadataFieldConfig">
<constructor-arg value="dc.identifier.other"/> <constructor-arg value="dc.identifier.other"/>

View File

@@ -900,7 +900,7 @@ public class WorkspaceItemRestRepositoryIT extends AbstractControllerIntegration
String authToken = getAuthToken(eperson.getEmail(), password); String authToken = getAuthToken(eperson.getEmail(), password);
// bulk create workspaceitems in the default collection (col1) // bulk create workspaceitems in the default collection (col1)
getClient(authToken).perform(fileUpload("/api/submission/workspaceitems") getClient(authToken).perform(fileUpload("/api/submission/workspaceitems")
.file(bibtexFile).param("owningCollection", col1.getID().toString())) .file(bibtexFile).param("projection", "full"))
// bulk create should return 200, 201 (created) is better for single resource // bulk create should return 200, 201 (created) is better for single resource
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("$._embedded.workspaceitems[0].sections.traditionalpageone['dc.title'][0].value", .andExpect(jsonPath("$._embedded.workspaceitems[0].sections.traditionalpageone['dc.title'][0].value",