Skip to content
Snippets Groups Projects
Commit 52bf3c85 authored by mbrodhu's avatar mbrodhu
Browse files

extracted function for field loading into an extra class

parent b1150039
No related branches found
No related tags found
No related merge requests found
package info.textgrid.middleware;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import javax.xml.datatype.DatatypeConfigurationException;
import org.apache.commons.logging.LogFactory;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.search.SearchHit;
public class DublinCoreFieldLoader {
public static List<String> contributors = new ArrayList<String>();
public static List<String> coverages = new ArrayList<String>();
public static List<String> creators = new ArrayList<String>();
public static List<String> dates = new ArrayList<String>();
public static List<String> descriptions = new ArrayList<String>();
public static List<String> formats = new ArrayList<String>();
public static List<String> identifiers = new ArrayList<String>();
public static List<String> languages = new ArrayList<String>();
public static List<String> publishers = new ArrayList<String>();
public static List<String> relations = new ArrayList<String>();
public static List<String> rights = new ArrayList<String>();
public static List<String> sources = new ArrayList<String>();
public static List<String> subjects = new ArrayList<String>();
public static List<String> titles = new ArrayList<String>();
public static List<String> types = new ArrayList<String>();
private static org.apache.commons.logging.Log log = LogFactory.getLog(RecordDeliverer.class);
public static List<String> setContributor(SearchHit hit, String[] values){
for(String field : values){
if (hit.getFields().get(field) != null) {
contributors.add(hit.getFields().get(field)
.values().get(0).toString());
}
}
return contributors;
}
public static List<String> setCreator(GetResponse responseWorkValues, String field){
if (responseWorkValues.getField(field) != null) {
creators.add(responseWorkValues.getField(field).getValue()
.toString());
}
return creators;
}
public static List<String> setCoverage(GetResponse responseWorkValues, String[] values){
for(String field : values){
if (responseWorkValues.getField(field) != null) {
coverages.add(responseWorkValues.getField(field)
.getValue().toString());
}
}
return coverages;
}
public static List<String> setDate(GetResponse responseWorkValues, String[] values){
for(String field : values){
try {
if (responseWorkValues.getField(field) != null) {
dates.add(OAIPMHUtillities.convertDateFormat(
responseWorkValues.getField(field).getValue()
.toString()).toXMLFormat());
}
} catch (ParseException e) {
log.debug(e);
} catch (DatatypeConfigurationException e) {
log.debug(e);
}
}
return dates;
}
public static List<String> setDescription(GetResponse responseWorkValues, String[] values){
for(String field : values){
if (responseWorkValues.getField(field) != null) {
descriptions.add(responseWorkValues.getField(field)
.getValue().toString());
}
}
return descriptions;
}
public static List<String> setFormat(SearchHit hit, String[] values){
for(String field : values){
if (hit.getFields().get(field) != null) {
formats.add(hit.getFields().get(field)
.values().get(0).toString());
}
}
return formats;
}
public static List<String> setIdentifier(SearchHit hit, String[] values){
for(String field : values){
if (hit.getFields().get(field) != null) {
identifiers.add(hit.getFields().get(field)
.values().get(0).toString());
}
}
return identifiers;
}
public static List<String> setLanguage(SearchHit hit, String[] values){
for(String field : values){
if (hit.getFields().get(field) != null) {
languages.add(hit.getFields().get(field)
.values().get(0).toString());
}
}
return languages;
}
public static List<String> setPublisher(SearchHit hit, String[] values){
for(String field : values){
if (hit.getFields().get(field) != null) {
publishers.add(hit.getFields().get(field)
.values().get(0).toString());
}
}
return publishers;
}
public static List<String> setRelation(SearchHit hit, String[] values){
for(String field : values){
if (hit.getFields().get(field) != null) {
relations.add(hit.getFields().get(field)
.values().get(0).toString());
}
}
return relations;
}
public static List<String> setRelationForWork(GetResponse responseWorkValues, String[] values){
for(String field : values){
if (responseWorkValues.getField(field) != null) {
relations.add(responseWorkValues.getField(field)
.getValue().toString());
}
}
return relations;
}
public static List<String> setRights(SearchHit hit, String[] values){
for(String field : values){
if (hit.getFields().get(field) != null) {
rights.add(hit.getFields().get(field)
.values().get(0).toString());
}
}
return rights;
}
public static List<String> setSources(SearchHit hit, String[] values){
for(String field : values){
if (hit.getFields().get(field) != null) {
sources.add(hit.getFields().get(field)
.values().get(0).toString());
}
}
return sources;
}
public static List<String> setSubject(GetResponse responseWorkValues, String[] values){
for(String field : values){
if (responseWorkValues.getField(field) != null) {
subjects.add(responseWorkValues.getField(field)
.getValue().toString());
}
}
return subjects;
}
public static List<String> setTitle(SearchHit hit, String[] values){
for(String field : values){
if (hit.getFields().get(field) != null) {
for (int i = 0; i < hit.getFields().get(field)
.getValues().size(); i++) {
titles.add(hit.getFields().get(field).values()
.get(i).toString());
}
}
}
return titles;
}
public static List<String> setType(GetResponse responseWorkValues, String[] values){
for(String field : values){
if (responseWorkValues.getField(field) != null) {
types.add(responseWorkValues.getField(field)
.getValue().toString());
}
}
return types;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment