fixed path reports

This commit is contained in:
Michele Artini 2024-02-15 08:52:28 +01:00
parent 8d85c1e97e
commit e254720377
2 changed files with 45 additions and 47 deletions

View File

@ -48,8 +48,7 @@ public class BaseAnalyzerJob {
public static void main(final String[] args) throws Exception {
final String jsonConfiguration = IOUtils
.toString(
BaseAnalyzerJob.class
.toString(BaseAnalyzerJob.class
.getResourceAsStream("/eu/dnetlib/dhp/collection/plugin/base/action_set_parameters.json"));
final ArgumentApplicationParser parser = new ArgumentApplicationParser(jsonConfiguration);
@ -124,27 +123,28 @@ public class BaseAnalyzerJob {
final List<String> recTypes = new ArrayList<>();
for (final Object o : record.selectNodes("//*[local-name()='metadata']//*")) {
for (final Object o : record.selectNodes("//*|//@*")) {
incrementMapCounter(fields, ((Node) o).getPath());
final String nodeName = ((Node) o).getName();
if ("collection".equals(nodeName)) {
if (o instanceof Element) {
final Element n = (Element) o;
if ("collection".equals(nodeName)) {
final String collName = n.getText().trim();
if (StringUtils.isNotBlank(collName)) {
final Map<String, String> map = new HashMap<>();
for (final Object ao : n.attributes()) {
map.put(((Attribute) ao).getName(), ((Attribute) ao).getValue());
}
incrementMapCounter(collections, collName + ": " + OBJECT_MAPPER.writeValueAsString(map));
}
} else if ("type".equals(nodeName)) {
recTypes.add("TYPE: " + nodeName);
recTypes.add("TYPE: " + n.getText().trim());
} else if ("typenorm".equals(nodeName)) {
recTypes.add("TYPE_NORM: " + nodeName);
recTypes.add("TYPE_NORM: " + n.getText().trim());
}
}
}
@ -165,12 +165,9 @@ public class BaseAnalyzerJob {
private static void saveReport(final FileSystem fs, final String outputPath, final Map<String, AtomicLong> fields)
throws JsonProcessingException, IOException {
try (final SequenceFile.Writer writer = SequenceFile
.createWriter(
fs.getConf(), SequenceFile.Writer.file(new Path(outputPath)), SequenceFile.Writer
.keyClass(IntWritable.class),
SequenceFile.Writer
.valueClass(Text.class),
SequenceFile.Writer.compression(SequenceFile.CompressionType.BLOCK, new DeflateCodec()))) {
.createWriter(fs.getConf(), SequenceFile.Writer.file(new Path(outputPath)), SequenceFile.Writer
.keyClass(IntWritable.class), SequenceFile.Writer
.valueClass(Text.class), SequenceFile.Writer.compression(SequenceFile.CompressionType.BLOCK, new DeflateCodec()))) {
final Text key = new Text();
final Text value = new Text();

View File

@ -47,7 +47,7 @@ public class BaseCollectorIteratorTest {
// System.out.println(record.asXML());
for (final Object o : record.selectNodes("//*[local-name()='metadata']//*")) {
for (final Object o : record.selectNodes("//*|//@*")) {
final String path = ((Node) o).getPath();
if (fields.containsKey(path)) {
@ -56,8 +56,10 @@ public class BaseCollectorIteratorTest {
fields.put(path, new AtomicInteger(1));
}
if ("collection".equals(((Node) o).getName())) {
if (o instanceof Element) {
final Element n = (Element) o;
if ("collection".equals(n.getName())) {
final String collName = n.getText().trim();
if (StringUtils.isNotBlank(collName) && !collections.containsKey(collName)) {
final Map<String, String> collAttrs = new HashMap<>();
@ -66,12 +68,11 @@ public class BaseCollectorIteratorTest {
}
collections.put(collName, collAttrs);
}
} else if ("type".equals(n.getName())) {
types.add(n.getText().trim());
}
if ("type".equals(((Node) o).getName())) {
types.add(((Element) o).getText().trim());
}
}
}