Project

General

Profile

1
package eu.dnetlib.data.mapreduce.hbase.oai.config;
2

    
3
import java.util.Collection;
4
import java.util.List;
5
import java.util.Map;
6
import java.util.Set;
7
import javax.annotation.Nullable;
8

    
9
import com.google.common.base.Function;
10
import com.google.common.base.Joiner;
11
import com.google.common.collect.Collections2;
12
import com.google.common.collect.Multimap;
13
import com.google.common.collect.Multimaps;
14
import com.google.common.collect.Sets;
15
import com.google.gson.Gson;
16
import com.google.gson.GsonBuilder;
17
import eu.dnetlib.data.mapreduce.hbase.oai.utils.MDFInfo;
18
import eu.dnetlib.data.mapreduce.hbase.oai.utils.PublisherField;
19
import eu.dnetlib.data.mapreduce.hbase.oai.utils.SetInfo;
20

    
21
/**
22
 * An instance of this class represents an OAI Configuration profile.
23
 * 
24
 * @author alessia
25
 * 
26
 */
27
public class OAIConfiguration {
28

    
29
	/**
30
	 * Map for OAI sets. Keys: setSpec, values: SetInfo instances.
31
	 */
32
	private Map<String, SetInfo> setsMap;
33

    
34
	/**
35
	 * Map for metadata formats. Keys: metadata prefix, values: MDFInfo instances.
36
	 */
37
	private Map<String, MDFInfo> mdFormatsMap;
38

    
39
	private List<PublisherField> fields;
40

    
41
	private List<String> fieldNames;
42

    
43
	/**
44
	 * Used to generate the OAI identifiers compliant to the protocol. See
45
	 * http://www.openarchives.org/OAI/openarchivesprotocol.html#UniqueIdentifier. See property services.oai.publisher.id.scheme.
46
	 */
47
	private String idScheme;
48
	/**
49
	 * Used to generate the OAI identifiers compliant to the protocol. See
50
	 * http://www.openarchives.org/OAI/openarchivesprotocol.html#UniqueIdentifier. See property services.oai.publisher.id.namespace.
51
	 */
52
	private String idNamespace;
53

    
54
	private Set<MDFInfo> sourcesMDF = Sets.newHashSet();
55

    
56
	private Multimap<String, String> enrichmentXPaths;
57

    
58
	public Collection<PublisherField> getFieldsFor(final String format, final String layout, final String interpretation) {
59
		final String mdRef = Joiner.on("-").join(format, layout, interpretation);
60
		Collection<PublisherField> filtered = Collections2.filter(this.getFields(), theField -> {
61
			if (theField.getSources() == null) return false;
62
			return theField.getSources().containsKey(mdRef);
63
		});
64
		return Collections2.transform(filtered, new Function<PublisherField, PublisherField>() {
65
			@Nullable
66
			@Override
67
			public PublisherField apply(@Nullable final PublisherField publisherField) {
68
				Multimap<String, String> filtered = Multimaps.filterKeys(publisherField.getSources(), k -> k.equalsIgnoreCase(mdRef));
69
				return new PublisherField(publisherField.getFieldName(), publisherField.isRepeatable(), filtered);
70
			}
71
		});
72
	}
73

    
74
	public Collection<String> getEnrichmentXPathsFor(final String format, final String layout, final String interpretation) {
75
		final String mdRef = Joiner.on("-").join(format, layout, interpretation);
76
		return enrichmentXPaths.get(mdRef);
77
	}
78

    
79
	public Map<String, SetInfo> getSetsMap() {
80
		return setsMap;
81
	}
82

    
83
	public void setSetsMap(final Map<String, SetInfo> setsMap) {
84
		this.setsMap = setsMap;
85
	}
86

    
87
	public Map<String, MDFInfo> getMdFormatsMap() {
88
		return mdFormatsMap;
89
	}
90

    
91
	public void setMdFormatsMap(final Map<String, MDFInfo> mdFormatsMap) {
92
		this.mdFormatsMap = mdFormatsMap;
93
	}
94

    
95
	public List<PublisherField> getFields() {
96
		return fields;
97
	}
98

    
99
	public void setFields(final List<PublisherField> fields) {
100
		this.fields = fields;
101
	}
102

    
103
	public List<String> getFieldNames() {
104
		return fieldNames;
105
	}
106

    
107
	public void setFieldNames(final List<String> fieldNames) {
108
		this.fieldNames = fieldNames;
109
	}
110

    
111
	public Set<MDFInfo> getSourcesMDF() {
112
		return sourcesMDF;
113
	}
114

    
115
	public void setSourcesMDF(final Set<MDFInfo> sourcesMDF) {
116
		this.sourcesMDF = sourcesMDF;
117
	}
118

    
119
	public String getIdScheme() {
120
		return idScheme;
121
	}
122

    
123
	public void setIdScheme(final String idScheme) {
124
		this.idScheme = idScheme;
125
	}
126

    
127
	public String getIdNamespace() {
128
		return idNamespace;
129
	}
130

    
131
	public void setIdNamespace(final String idNamespace) {
132
		this.idNamespace = idNamespace;
133
	}
134

    
135
	public Multimap<String, String> getEnrichmentXPaths() {
136
		return enrichmentXPaths;
137
	}
138

    
139
	public void setEnrichmentXPaths(final Multimap<String, String> enrichmentXPaths) {
140
		this.enrichmentXPaths = enrichmentXPaths;
141
	}
142

    
143
	@Override
144
	public String toString() {
145
		Gson gson = new GsonBuilder().setPrettyPrinting().create();
146
		return gson.toJson(this);
147
	}
148

    
149
}
(1-1/4)