importers
This commit is contained in:
parent
a49a9c9c01
commit
4ff77964ca
|
@ -1,22 +1,14 @@
|
||||||
package eu.dnetlib.is.context;
|
package eu.dnetlib.is.context;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
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.DocumentException;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@ -51,9 +43,6 @@ public class ContextRestController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private ConceptLevel2Repository conceptLevel2Repository;
|
private ConceptLevel2Repository conceptLevel2Repository;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ContextImporter contextImporter;
|
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(ContextRestController.class);
|
private static final Log log = LogFactory.getLog(ContextRestController.class);
|
||||||
|
|
||||||
@GetMapping("/")
|
@GetMapping("/")
|
||||||
|
@ -128,14 +117,4 @@ public class ContextRestController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping(value = "/load", consumes = "text/plain")
|
|
||||||
public List<String> loadFromOldProfile(final HttpServletRequest request) throws DocumentException, IOException {
|
|
||||||
|
|
||||||
final String xml = IOUtils.toString(request.getInputStream(), StandardCharsets.UTF_8);
|
|
||||||
|
|
||||||
contextImporter.loadFromOldProfile(xml);
|
|
||||||
|
|
||||||
return Arrays.asList("Done.");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package eu.dnetlib.is.context;
|
package eu.dnetlib.is.importer;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
|
@ -0,0 +1,73 @@
|
||||||
|
package eu.dnetlib.is.importer;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.dom4j.DocumentException;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import eu.dnetlib.is.resource.model.SimpleResource;
|
||||||
|
import eu.dnetlib.is.vocabulary.model.Vocabulary;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/import")
|
||||||
|
public class ImporterController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ContextImporter contextImporter;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private OldProfilesImporter oldProfilesImporter;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private WfHistoryImporter wfHistoryImporter;
|
||||||
|
|
||||||
|
@PostMapping(value = "/context", consumes = {
|
||||||
|
MediaType.TEXT_PLAIN_VALUE, MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE
|
||||||
|
})
|
||||||
|
public List<String> importContext(final HttpServletRequest request) throws DocumentException, IOException {
|
||||||
|
|
||||||
|
final String xml = IOUtils.toString(request.getInputStream(), StandardCharsets.UTF_8);
|
||||||
|
|
||||||
|
contextImporter.loadFromOldProfile(xml);
|
||||||
|
|
||||||
|
return Arrays.asList("Done.");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping(value = "/resource", consumes = {
|
||||||
|
MediaType.TEXT_PLAIN_VALUE, MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE
|
||||||
|
})
|
||||||
|
public SimpleResource importResource(final HttpServletRequest request) throws Exception {
|
||||||
|
final String xml = IOUtils.toString(request.getInputStream(), StandardCharsets.UTF_8);
|
||||||
|
return oldProfilesImporter.importSimpleResource(xml);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping(value = "/vocabulary", consumes = {
|
||||||
|
MediaType.TEXT_PLAIN_VALUE, MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE
|
||||||
|
})
|
||||||
|
public Vocabulary importVocabulary(final HttpServletRequest request) throws Exception, IOException {
|
||||||
|
final String xml = IOUtils.toString(request.getInputStream(), StandardCharsets.UTF_8);
|
||||||
|
return oldProfilesImporter.importVocabulary(xml);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping(value = "/wf_logs")
|
||||||
|
public List<String> importWfLogs(@RequestParam final String path) throws Exception {
|
||||||
|
// mongoexport -d dnet_logs -c wf_logs --jsonArray -o /tmp/mongodump.json
|
||||||
|
|
||||||
|
wfHistoryImporter.load(path);
|
||||||
|
|
||||||
|
return Arrays.asList("Done.");
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package eu.dnetlib.is.util;
|
package eu.dnetlib.is.importer;
|
||||||
|
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
|
@ -1,4 +1,4 @@
|
||||||
package eu.dnetlib.is.wfs;
|
package eu.dnetlib.is.importer;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
|
@ -26,18 +26,18 @@ import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import eu.dnetlib.is.resource.model.SimpleResource;
|
import eu.dnetlib.is.resource.model.SimpleResource;
|
||||||
import eu.dnetlib.is.resource.repository.SimpleResourceRepository;
|
import eu.dnetlib.is.resource.repository.SimpleResourceRepository;
|
||||||
|
import eu.dnetlib.is.util.DatabaseUtils;
|
||||||
import eu.dnetlib.is.util.InformationServiceException;
|
import eu.dnetlib.is.util.InformationServiceException;
|
||||||
import eu.dnetlib.is.util.OldProfilesImporter;
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/resources")
|
@RequestMapping("/api/resources")
|
||||||
public class ResourcesRestController {
|
public class ResourcesRestController {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private OldProfilesImporter oldProfilesImporter;
|
private SimpleResourceRepository simpleResourceRepository;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SimpleResourceRepository simpleResourceRepository;
|
private DatabaseUtils databaseUtils;
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(ResourcesRestController.class);
|
private static final Log log = LogFactory.getLog(ResourcesRestController.class);
|
||||||
|
|
||||||
|
@ -49,6 +49,17 @@ public class ResourcesRestController {
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/")
|
||||||
|
public SimpleResource newResource(@RequestParam final String name,
|
||||||
|
@RequestParam final String type,
|
||||||
|
@RequestParam(required = false, defaultValue = "") final String description,
|
||||||
|
@RequestParam(required = false, defaultValue = MediaType.APPLICATION_XML_VALUE) final String ctype,
|
||||||
|
@RequestParam final String content)
|
||||||
|
throws InformationServiceException {
|
||||||
|
|
||||||
|
return databaseUtils.saveNewResource(name, type, description, ctype, content);
|
||||||
|
}
|
||||||
|
|
||||||
@DeleteMapping("/{id}")
|
@DeleteMapping("/{id}")
|
||||||
public void deleteResource(@PathVariable final String id) {
|
public void deleteResource(@PathVariable final String id) {
|
||||||
log.info("Deleting resource: " + id);
|
log.info("Deleting resource: " + id);
|
||||||
|
@ -110,11 +121,4 @@ public class ResourcesRestController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping(value = "/operation/import", consumes = {
|
|
||||||
MediaType.TEXT_PLAIN_VALUE, MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE
|
|
||||||
})
|
|
||||||
public SimpleResource importFromOldProfile(final HttpServletRequest request) throws Exception {
|
|
||||||
final String xml = IOUtils.toString(request.getInputStream(), StandardCharsets.UTF_8);
|
|
||||||
return oldProfilesImporter.importSimpleResource(xml);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
package eu.dnetlib.is.util;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import eu.dnetlib.is.resource.model.SimpleResource;
|
||||||
|
import eu.dnetlib.is.resource.repository.SimpleResourceRepository;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class DatabaseUtils {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SimpleResourceRepository simpleResourceRepository;
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public SimpleResource saveNewResource(final String name,
|
||||||
|
final String type,
|
||||||
|
final String description,
|
||||||
|
final String ctype,
|
||||||
|
final String content) {
|
||||||
|
final Date now = new Date();
|
||||||
|
|
||||||
|
final SimpleResource res = new SimpleResource();
|
||||||
|
res.setId(UUID.randomUUID().toString());
|
||||||
|
res.setName(name);
|
||||||
|
res.setType(type);
|
||||||
|
res.setDescription(description);
|
||||||
|
res.setContentType(ctype);
|
||||||
|
res.setCreationDate(now);
|
||||||
|
res.setModificationDate(now);
|
||||||
|
|
||||||
|
simpleResourceRepository.save(res);
|
||||||
|
simpleResourceRepository.setContentById(res.getId(), content);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,13 +1,8 @@
|
||||||
package eu.dnetlib.is.vocabulary;
|
package eu.dnetlib.is.vocabulary;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
@ -21,7 +16,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import eu.dnetlib.common.controller.AbstractDnetController;
|
import eu.dnetlib.common.controller.AbstractDnetController;
|
||||||
import eu.dnetlib.is.util.OldProfilesImporter;
|
import eu.dnetlib.is.importer.OldProfilesImporter;
|
||||||
import eu.dnetlib.is.vocabulary.model.Vocabulary;
|
import eu.dnetlib.is.vocabulary.model.Vocabulary;
|
||||||
import eu.dnetlib.is.vocabulary.model.VocabularyTerm;
|
import eu.dnetlib.is.vocabulary.model.VocabularyTerm;
|
||||||
import eu.dnetlib.is.vocabulary.model.VocabularyTermPK;
|
import eu.dnetlib.is.vocabulary.model.VocabularyTermPK;
|
||||||
|
@ -70,12 +65,6 @@ public class VocabularyRestController extends AbstractDnetController {
|
||||||
return listVocs();
|
return listVocs();
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping(value = "/import", consumes = "text/plain")
|
|
||||||
public Vocabulary importFromOldProfile(final HttpServletRequest request) throws Exception, IOException {
|
|
||||||
final String xml = IOUtils.toString(request.getInputStream(), StandardCharsets.UTF_8);
|
|
||||||
return oldProfilesImporter.importVocabulary(xml);
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/{vocabulary}/terms")
|
@GetMapping("/{vocabulary}/terms")
|
||||||
public Iterable<VocabularyTerm> listTerms(@PathVariable final String vocabulary) {
|
public Iterable<VocabularyTerm> listTerms(@PathVariable final String vocabulary) {
|
||||||
return vocabularyTermRepository.findByVocabularyOrderByCode(vocabulary);
|
return vocabularyTermRepository.findByVocabularyOrderByCode(vocabulary);
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package eu.dnetlib.is.wfs;
|
package eu.dnetlib.is.wfs;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -23,9 +22,6 @@ public class WfHistoryRestController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private WfProcessExecutionRepository wfProcessExecutionRepository;
|
private WfProcessExecutionRepository wfProcessExecutionRepository;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private WfHistoryImporter wfHistoryImporter;
|
|
||||||
|
|
||||||
public static final int MAX_NUMBER_OF_RECENT_WFS = 100;
|
public static final int MAX_NUMBER_OF_RECENT_WFS = 100;
|
||||||
|
|
||||||
@GetMapping("/")
|
@GetMapping("/")
|
||||||
|
@ -46,13 +42,4 @@ public class WfHistoryRestController {
|
||||||
return wfProcessExecutionRepository.findById(processId).get();
|
return wfProcessExecutionRepository.findById(processId).get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(value = "/load")
|
|
||||||
public List<String> loadFromOldProfile(@RequestParam final String path) throws Exception {
|
|
||||||
// mongoexport -d dnet_logs -c wf_logs --jsonArray -o /tmp/mongodump.json
|
|
||||||
|
|
||||||
wfHistoryImporter.load(path);
|
|
||||||
|
|
||||||
return Arrays.asList("Done.");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue