fixed import of legacy tr rules

This commit is contained in:
Michele Artini 2022-12-07 11:42:40 +01:00
parent 8933fa2273
commit b37eb84e91
5 changed files with 23 additions and 14 deletions

2
.gitignore vendored
View File

@ -7,7 +7,7 @@
*.iws *.iws
*.java-version *.java-version
*~ *~
/**/*.sh /**/ssh_tunnel_*.sh
/**/my_application.properties /**/my_application.properties
.vscode .vscode
.classpath .classpath

View File

@ -1,15 +1,13 @@
package eu.dnetlib.is.importer; package eu.dnetlib.is.importer;
import java.io.IOException; import java.io.IOException;
import java.io.StringReader;
import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.dom4j.Document;
import org.dom4j.DocumentException; import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Node; import org.dom4j.Node;
import org.dom4j.io.SAXReader;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -44,9 +42,9 @@ public class ContextImporter {
private static final Log log = LogFactory.getLog(ContextImporter.class); private static final Log log = LogFactory.getLog(ContextImporter.class);
public void loadFromOldProfile(final String xml) throws DocumentException, IOException { public void loadFromOldProfile(final String xml) throws DocumentException, IOException {
final SAXReader reader = new SAXReader(); DocumentHelper.parseText(xml)
final Document doc = reader.read(new StringReader(xml)); .selectNodes("//context")
doc.selectNodes("//context").forEach(this::saveContext); .forEach(this::saveContext);
} }
private void saveContext(final Node node) { private void saveContext(final Node node) {

View File

@ -24,6 +24,12 @@ import eu.dnetlib.is.vocabulary.model.Vocabulary;
@RequestMapping("/api/import") @RequestMapping("/api/import")
public class ImporterController extends AbstractDnetController { public class ImporterController extends AbstractDnetController {
// EXAMPLE:
// find ./VocabularyDSResourceType/ -name "*.xml" -exec curl -X POST "http://localhost:8280/api/import/vocabulary" -H "accept: */*" -H
// "Content-Type: text/plain" --data-binary @{} \;
// find ./DedupConfigurationDSResources/ -name "*.xml" -exec curl -X POST "http://localhost:8280/api/import/resource" -H "accept: */*"
// -H "Content-Type: text/plain" --data-binary @{} \;
@Autowired @Autowired
private ContextImporter contextImporter; private ContextImporter contextImporter;
@ -51,6 +57,7 @@ public class ImporterController extends AbstractDnetController {
}) })
public String importResource(final HttpServletRequest request) throws Exception { public String importResource(final HttpServletRequest request) throws Exception {
final String xml = IOUtils.toString(request.getInputStream(), StandardCharsets.UTF_8); final String xml = IOUtils.toString(request.getInputStream(), StandardCharsets.UTF_8);
return oldProfilesImporter.importSimpleResource(xml); return oldProfilesImporter.importSimpleResource(xml);
} }

View File

@ -1,6 +1,5 @@
package eu.dnetlib.is.importer; package eu.dnetlib.is.importer;
import java.io.StringReader;
import java.util.Date; import java.util.Date;
import javax.transaction.Transactional; import javax.transaction.Transactional;
@ -8,8 +7,8 @@ import javax.transaction.Transactional;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.dom4j.Document; import org.dom4j.Document;
import org.dom4j.DocumentException; import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Node; import org.dom4j.Node;
import org.dom4j.io.SAXReader;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -41,10 +40,9 @@ public class OldProfilesImporter {
@Transactional @Transactional
public String importSimpleResource(final String xml) throws InformationServiceException { public String importSimpleResource(final String xml) throws InformationServiceException {
final SAXReader reader = new SAXReader();
try { try {
final Document doc = reader.read(new StringReader(xml)); final Document doc = DocumentHelper.parseText(xml);
final String id = StringUtils.substringBefore(doc.valueOf("//RESOURCE_IDENTIFIER/@value"), "_"); final String id = StringUtils.substringBefore(doc.valueOf("//RESOURCE_IDENTIFIER/@value"), "_");
final Date now = new Date(); final Date now = new Date();
@ -70,8 +68,9 @@ public class OldProfilesImporter {
resContent = XmlIndenter.indent(doc.selectSingleNode("//*[local-name() = 'stylesheet']")); resContent = XmlIndenter.indent(doc.selectSingleNode("//*[local-name() = 'stylesheet']"));
} else { } else {
final String code = doc.valueOf("//SCRIPT/CODE").trim(); final String code = doc.valueOf("//SCRIPT/CODE").trim();
try { try {
final Document xsltDoc = reader.read(new StringReader(code)); final Document xsltDoc = DocumentHelper.parseText(code);
res.setType("transformation_rule_xslt"); res.setType("transformation_rule_xslt");
resContent = XmlIndenter.indent(xsltDoc); resContent = XmlIndenter.indent(xsltDoc);
} catch (final DocumentException e) { } catch (final DocumentException e) {
@ -109,8 +108,7 @@ public class OldProfilesImporter {
@Transactional @Transactional
public Vocabulary importVocabulary(final String xml) throws Exception { public Vocabulary importVocabulary(final String xml) throws Exception {
final SAXReader reader = new SAXReader(); final Document doc = DocumentHelper.parseText(xml);
final Document doc = reader.read(new StringReader(xml));
final Vocabulary voc = new Vocabulary(); final Vocabulary voc = new Vocabulary();
final String vocId = doc.valueOf("//VOCABULARY_NAME/@code"); final String vocId = doc.valueOf("//VOCABULARY_NAME/@code");

View File

@ -0,0 +1,6 @@
#!/bin/sh
find ./VocabularyDSResourceType/ -name "*.xml" -exec curl -X POST "http://localhost:8280/api/import/vocabulary" -H "accept: */*" -H "Content-Type: text/plain" --data-binary @{} \;
find ./DedupConfigurationDSResources/ -name "*.xml" -exec curl -X POST "http://localhost:8280/api/import/resource" -H "accept: */*" -H "Content-Type: text/plain" --data-binary @{} \;