1
|
package eu.dnetlib.resolver.parser;
|
2
|
|
3
|
import java.util.Arrays;
|
4
|
import java.util.HashMap;
|
5
|
import java.util.List;
|
6
|
import java.util.Map;
|
7
|
import javax.xml.stream.XMLStreamReader;
|
8
|
|
9
|
|
10
|
import eu.dnetlib.dli.resolver.model.DLIResolvedObject;
|
11
|
import eu.dnetlib.pid.resolver.model.ObjectType;
|
12
|
import org.apache.commons.lang3.StringUtils;
|
13
|
import org.apache.commons.logging.Log;
|
14
|
import org.apache.commons.logging.LogFactory;
|
15
|
|
16
|
/**
|
17
|
* Created by sandro on 9/13/16.
|
18
|
*/
|
19
|
public abstract class AbstractResolverParser {
|
20
|
|
21
|
protected static final Log log = LogFactory.getLog(AbstractResolverParser.class);
|
22
|
private List<String> datasetSubTypes = Arrays.asList("dataset", "software", "film", "sound", "physicalobject", "audiovisual", "collection", "other", "study", "metadata");
|
23
|
|
24
|
public abstract DLIResolvedObject parseObject(final String record);
|
25
|
|
26
|
protected Map<String, String> getAttributes(final XMLStreamReader parser) {
|
27
|
final Map<String, String> attributesMap = new HashMap<>();
|
28
|
for (int i = 0; i < parser.getAttributeCount(); i++) {
|
29
|
attributesMap.put(parser.getAttributeLocalName(i), parser.getAttributeValue(i));
|
30
|
}
|
31
|
return attributesMap;
|
32
|
}
|
33
|
|
34
|
protected void setType(final DLIResolvedObject object, final String type) {
|
35
|
if (!StringUtils.isBlank(type)) {
|
36
|
if (datasetSubTypes.contains(type.toLowerCase())) {
|
37
|
object.setType(ObjectType.dataset);
|
38
|
return;
|
39
|
} else if (type.toLowerCase().contains("publication")) {
|
40
|
object.setType(ObjectType.publication);
|
41
|
return;
|
42
|
} else {
|
43
|
object.setType(ObjectType.unknown);
|
44
|
}
|
45
|
}
|
46
|
}
|
47
|
|
48
|
}
|