mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 10:04:21 +00:00
Merge from ekt branch
This commit is contained in:
@@ -128,48 +128,44 @@ public abstract class ConfigurableLookupProvider implements SubmissionLookupProv
|
||||
shortName);
|
||||
Field[] fields = bean.getClass().getDeclaredFields();
|
||||
for (Field field : fields) {
|
||||
if (field.getType() == String.class) {
|
||||
Method getter = bean.getClass().getMethod(
|
||||
"get" + field.getName().substring(0, 1).toUpperCase()
|
||||
+ field.getName().substring(1));
|
||||
|
||||
String value = (String) getter.invoke(bean);
|
||||
|
||||
addMetadata(shortName, publication, field.getName(), value);
|
||||
|
||||
} else if (field.getType() == List.class) {
|
||||
ParameterizedType pt = (ParameterizedType) field
|
||||
.getGenericType();
|
||||
|
||||
Method getter = bean.getClass().getMethod(
|
||||
"get" + field.getName().substring(0, 1).toUpperCase()
|
||||
+ field.getName().substring(1));
|
||||
|
||||
ParameterizedType stringListType = (ParameterizedType) field.getGenericType();
|
||||
Class<?> stringListClass = (Class<?>) stringListType.getActualTypeArguments()[0];
|
||||
|
||||
if (String.class.isAssignableFrom(stringListClass)) { //repeatable metadata
|
||||
List<String> values = (List<String>) getter.invoke(bean);
|
||||
if (values != null) {
|
||||
for (String value : values) {
|
||||
addMetadata(shortName, publication,
|
||||
field.getName(), value);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//authors
|
||||
List<String[]> values = (List<String[]>) getter
|
||||
.invoke(bean);
|
||||
if (values != null) {
|
||||
for (String[] nvalue : values) {
|
||||
String value = nvalue[1] + ", " + nvalue[0];
|
||||
addMetadata(shortName, publication,
|
||||
field.getName(), value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if (field.getType() == String.class) {
|
||||
Method getter = bean.getClass().getMethod(
|
||||
"get" + field.getName().substring(0, 1).toUpperCase()
|
||||
+ field.getName().substring(1));
|
||||
|
||||
String value = (String) getter.invoke(bean);
|
||||
|
||||
addMetadata(shortName, publication, field.getName(), value);
|
||||
|
||||
} else if (field.getType() == List.class) {
|
||||
ParameterizedType pt = (ParameterizedType) field
|
||||
.getGenericType();
|
||||
|
||||
Method getter = bean.getClass().getMethod(
|
||||
"get" + field.getName().substring(0, 1).toUpperCase()
|
||||
+ field.getName().substring(1));
|
||||
|
||||
if (pt.getActualTypeArguments()[0] instanceof GenericArrayType) { // nomi
|
||||
// di
|
||||
// persone
|
||||
List<String[]> values = (List<String[]>) getter.invoke(bean);
|
||||
if (values != null) {
|
||||
for (String[] nvalue : values) {
|
||||
String value = nvalue[1] + ", " + nvalue[0];
|
||||
addMetadata(shortName, publication,
|
||||
field.getName(), value);
|
||||
}
|
||||
}
|
||||
} else { // metadati ripetibili
|
||||
List<String> values = (List<String>) getter.invoke(bean);
|
||||
if (values != null) {
|
||||
for (String value : values) {
|
||||
addMetadata(shortName, publication,
|
||||
field.getName(), value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return publication;
|
||||
}
|
||||
|
@@ -24,6 +24,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.app.util.DCInput;
|
||||
import org.dspace.app.util.DCInputSet;
|
||||
import org.dspace.app.util.DCInputsReader;
|
||||
@@ -43,6 +44,8 @@ import org.dspace.submit.util.ItemSubmissionLookupDTO;
|
||||
*/
|
||||
public class DSpaceWorkspaceItemOutputGenerator implements OutputGenerator {
|
||||
|
||||
private static Logger log = Logger.getLogger(DSpaceWorkspaceItemOutputGenerator.class);
|
||||
|
||||
private Context context;
|
||||
private String formName;
|
||||
private List<WorkspaceItem> witems;
|
||||
@@ -57,12 +60,21 @@ public class DSpaceWorkspaceItemOutputGenerator implements OutputGenerator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> generateOutput(RecordSet records) {
|
||||
public List<String> generateOutput(RecordSet recordSet) {
|
||||
|
||||
log.info("BTE OutputGenerator started. Records to output: " + recordSet.getRecords().size());
|
||||
|
||||
//Printing debug message
|
||||
String totalString = "";
|
||||
for (Record record : recordSet.getRecords()){
|
||||
totalString += SubmissionLookupUtils.getPrintableString(record)+"\n";
|
||||
}
|
||||
log.debug("Records to output:\n"+totalString);
|
||||
|
||||
|
||||
witems = new ArrayList<WorkspaceItem>();
|
||||
|
||||
Map<String, List<Record>> record_sets = new HashMap<String, List<Record>>();
|
||||
for(Record rec : records) {
|
||||
for(Record rec : recordSet.getRecords()) {
|
||||
try {
|
||||
WorkspaceItem wi = WorkspaceItem.create(context, collection, true);
|
||||
merge(formName, wi.getItem(), rec);
|
||||
|
@@ -34,7 +34,7 @@ public class FieldMergeModifier extends AbstractModifier {
|
||||
rec.addValue(target_field, value);
|
||||
}
|
||||
}
|
||||
rec.removeField(source_field);
|
||||
//rec.removeField(source_field);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -14,12 +14,14 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import gr.ekt.bte.core.DataLoader;
|
||||
import gr.ekt.bte.core.DataLoadingSpec;
|
||||
import gr.ekt.bte.core.Record;
|
||||
import gr.ekt.bte.core.RecordSet;
|
||||
import gr.ekt.bte.core.StringValue;
|
||||
import gr.ekt.bte.core.Value;
|
||||
import gr.ekt.bte.exceptions.MalformedSourceException;
|
||||
|
||||
/**
|
||||
@@ -28,6 +30,8 @@ import gr.ekt.bte.exceptions.MalformedSourceException;
|
||||
*/
|
||||
public class MultipleSubmissionLookupDataLoader implements DataLoader {
|
||||
|
||||
private static Logger log = Logger.getLogger(MultipleSubmissionLookupDataLoader.class);
|
||||
|
||||
private static final String NOT_FOUND_DOI = "NOT-FOUND-DOI";
|
||||
|
||||
List<ConfigurableLookupProvider> providers;
|
||||
@@ -91,8 +95,13 @@ public class MultipleSubmissionLookupDataLoader implements DataLoader {
|
||||
}
|
||||
}
|
||||
|
||||
//KSTA:ToDo: providers must only be the ones that support DOI search!
|
||||
for (SubmissionLookupProvider provider : providers) {
|
||||
|
||||
//Provider must support DOI
|
||||
if (provider.getSupportedIdentifiers().contains(SubmissionLookupProvider.DOI)){
|
||||
continue;
|
||||
}
|
||||
|
||||
//if (evictProviders != null
|
||||
// && evictProviders.contains(provider.getShortName())) {
|
||||
// continue;
|
||||
@@ -122,6 +131,16 @@ public class MultipleSubmissionLookupDataLoader implements DataLoader {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
log.info("BTE DataLoader finished. Items loaded: " + recordSet.getRecords().size());
|
||||
|
||||
//Printing debug message
|
||||
String totalString = "";
|
||||
for (Record record : recordSet.getRecords()){
|
||||
totalString += SubmissionLookupUtils.getPrintableString(record)+"\n";
|
||||
}
|
||||
log.debug("Records loaded:\n"+totalString);
|
||||
|
||||
return recordSet;
|
||||
}
|
||||
|
||||
|
@@ -16,6 +16,7 @@ import gr.ekt.bte.exceptions.MalformedSourceException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.submit.util.ItemSubmissionLookupDTO;
|
||||
|
||||
|
||||
@@ -26,7 +27,8 @@ public class SubmissionItemDataLoader implements DataLoader {
|
||||
private List<ItemSubmissionLookupDTO> dtoList;
|
||||
List<SubmissionLookupProvider> providers;
|
||||
|
||||
|
||||
private static Logger log = Logger.getLogger(SubmissionItemDataLoader.class);
|
||||
|
||||
public SubmissionItemDataLoader() {
|
||||
dtoList = null;
|
||||
providers = null;
|
||||
@@ -44,6 +46,15 @@ public class SubmissionItemDataLoader implements DataLoader {
|
||||
ret.addRecord(rec);
|
||||
}
|
||||
|
||||
log.info("BTE DataLoader finished. Items loaded: " + ret.getRecords().size());
|
||||
|
||||
//Printing debug message
|
||||
String totalString = "";
|
||||
for (Record record : ret.getRecords()){
|
||||
totalString += SubmissionLookupUtils.getPrintableString(record)+"\n";
|
||||
}
|
||||
log.debug("Records loaded:\n"+totalString);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@@ -58,6 +58,10 @@ public class SubmissionLookupOutputGenerator implements OutputGenerator {
|
||||
ItemSubmissionLookupDTO dto = new ItemSubmissionLookupDTO(entry.getValue());
|
||||
dtoList.add(dto);
|
||||
}
|
||||
|
||||
//Print debug messages
|
||||
|
||||
|
||||
return new ArrayList<String>();
|
||||
}
|
||||
|
||||
|
@@ -18,6 +18,7 @@ import java.util.Map;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.identifier.DOI;
|
||||
import org.dspace.submit.util.SubmissionLookupDTO;
|
||||
|
||||
import gr.ekt.bte.core.TransformationEngine;
|
||||
@@ -92,13 +93,19 @@ public class SubmissionLookupService {
|
||||
return phase2TransformationEngine;
|
||||
}
|
||||
|
||||
//KSTA:ToDo: Replace with something more dynamic
|
||||
public List<String> getIdentifiers() {
|
||||
List<String> identifiers = new ArrayList<String>();
|
||||
identifiers.add("doi");
|
||||
identifiers.add("pubmed");
|
||||
identifiers.add("arxiv");
|
||||
return identifiers;
|
||||
|
||||
List<String> allSupportedIdentifiers = new ArrayList<String>();
|
||||
MultipleSubmissionLookupDataLoader dataLoader = (MultipleSubmissionLookupDataLoader)phase1TransformationEngine.getDataLoader();
|
||||
for (SubmissionLookupProvider provider : dataLoader.getProviders()){
|
||||
for (String identifier : provider.getSupportedIdentifiers()){
|
||||
if (!allSupportedIdentifiers.contains(identifier)){
|
||||
allSupportedIdentifiers.add(identifier);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return allSupportedIdentifiers;
|
||||
}
|
||||
|
||||
public Map<String, List<SubmissionLookupProvider>> getProvidersIdentifiersMap() {
|
||||
|
@@ -126,11 +126,29 @@ public class SubmissionLookupUtils {
|
||||
public static List<String> getValues(Record rec, String field) {
|
||||
List<String> result = new ArrayList<String>();
|
||||
List<Value> values = rec.getValues(field);
|
||||
String value = null;
|
||||
if (values != null && values.size() > 0) {
|
||||
value = values.get(0).getAsString();
|
||||
result.add(value);
|
||||
for (Value value : values){
|
||||
result.add( value.getAsString());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String getPrintableString(Record record){
|
||||
StringBuilder result = new StringBuilder();
|
||||
|
||||
result.append("\nPublication {\n");
|
||||
|
||||
for (String field: record.getFields()){
|
||||
result.append("--"+field + ":\n");
|
||||
List<Value> values = record.getValues(field);
|
||||
for (Value value : values){
|
||||
result.append("\t"+value.getAsString()+"\n");
|
||||
}
|
||||
}
|
||||
|
||||
result.append("}\n");
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
|
@@ -208,6 +208,7 @@ public class StartSubmissionLookupStep extends AbstractProcessingStep
|
||||
if (transformationEngine != null){
|
||||
SubmissionItemDataLoader dataLoader = (SubmissionItemDataLoader)transformationEngine.getDataLoader();
|
||||
dataLoader.setDtoList(Arrays.asList(new ItemSubmissionLookupDTO[]{dto}));
|
||||
//dataLoader.setProviders()
|
||||
|
||||
DSpaceWorkspaceItemOutputGenerator outputGenerator = (DSpaceWorkspaceItemOutputGenerator)transformationEngine.getOutputGenerator();
|
||||
outputGenerator.setCollection(col);
|
||||
|
@@ -64,14 +64,14 @@ public class ItemSubmissionLookupDTO implements Serializable {
|
||||
else
|
||||
{
|
||||
MutableRecord pub = new SubmissionLookupPublication(MERGED_PUBLICATION_PROVIDER);
|
||||
for (SubmissionLookupProvider prov : providers)
|
||||
{
|
||||
//for (SubmissionLookupProvider prov : providers)
|
||||
//{
|
||||
for (Record p : publications)
|
||||
{
|
||||
if (!SubmissionLookupService.getProviderName(p).equals(prov.getShortName()))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
//if (!SubmissionLookupService.getProviderName(p).equals(prov.getShortName()))
|
||||
//{
|
||||
// continue;
|
||||
//}
|
||||
for (String field : p.getFields())
|
||||
{
|
||||
List<Value> values = p.getValues(field);
|
||||
@@ -87,7 +87,7 @@ public class ItemSubmissionLookupDTO implements Serializable {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//}
|
||||
return pub;
|
||||
}
|
||||
}
|
||||
|
@@ -83,7 +83,9 @@ public class SubmissionLookupJSONRequest extends JSONRequest {
|
||||
dataLoader.setIdentifiers(identifiers);
|
||||
|
||||
try {
|
||||
log.debug("BTE transformation is about to start!");
|
||||
transformationEngine.transform(new TransformationSpec());
|
||||
log.debug("BTE transformation finished!");
|
||||
|
||||
SubmissionLookupOutputGenerator outputGenerator = (SubmissionLookupOutputGenerator)transformationEngine.getOutputGenerator();
|
||||
result = outputGenerator.getDtoList();
|
||||
@@ -208,6 +210,7 @@ public class SubmissionLookupJSONRequest extends JSONRequest {
|
||||
data.put("authors",pub.getValues("authors")!=null?
|
||||
StringUtils.join(SubmissionLookupUtils.getValues(pub, "authors").iterator(), ", "):"");
|
||||
data.put("issued", SubmissionLookupUtils.getFirstValue(pub, "issued"));
|
||||
|
||||
publications.add(data);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user