From 5e86ab8723b2290485d20f681a9f96f12c0dd4d2 Mon Sep 17 00:00:00 2001 From: "michele.artini" Date: Fri, 2 Dec 2022 13:29:53 +0100 Subject: [PATCH] Add Dedup Confs --- .../eu/dnetlib/is/importer/ImporterController.java | 3 +-- .../eu/dnetlib/is/importer/OldProfilesImporter.java | 12 +++++++++--- .../src/main/resources/static/js/simpleResources.js | 6 +++++- .../dnet-is-common/src/main/resources/sql/schema.sql | 3 ++- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/apps/dnet-is-application/src/main/java/eu/dnetlib/is/importer/ImporterController.java b/apps/dnet-is-application/src/main/java/eu/dnetlib/is/importer/ImporterController.java index ef3d7359..04b4aed2 100644 --- a/apps/dnet-is-application/src/main/java/eu/dnetlib/is/importer/ImporterController.java +++ b/apps/dnet-is-application/src/main/java/eu/dnetlib/is/importer/ImporterController.java @@ -18,7 +18,6 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import eu.dnetlib.common.controller.AbstractDnetController; -import eu.dnetlib.is.resource.model.SimpleResource; import eu.dnetlib.is.vocabulary.model.Vocabulary; @RestController @@ -50,7 +49,7 @@ public class ImporterController extends AbstractDnetController { @PostMapping(value = "/resource", consumes = { MediaType.TEXT_PLAIN_VALUE, MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE }) - public SimpleResource importResource(final HttpServletRequest request) throws Exception { + public String importResource(final HttpServletRequest request) throws Exception { final String xml = IOUtils.toString(request.getInputStream(), StandardCharsets.UTF_8); return oldProfilesImporter.importSimpleResource(xml); } diff --git a/apps/dnet-is-application/src/main/java/eu/dnetlib/is/importer/OldProfilesImporter.java b/apps/dnet-is-application/src/main/java/eu/dnetlib/is/importer/OldProfilesImporter.java index 087a7b4e..dc3a1c4b 100644 --- a/apps/dnet-is-application/src/main/java/eu/dnetlib/is/importer/OldProfilesImporter.java +++ b/apps/dnet-is-application/src/main/java/eu/dnetlib/is/importer/OldProfilesImporter.java @@ -35,7 +35,7 @@ public class OldProfilesImporter { private VocabularyTermRepository vocabularyTermRepository; @Transactional - public SimpleResource importSimpleResource(final String xml) throws InformationServiceException { + public String importSimpleResource(final String xml) throws InformationServiceException { final SAXReader reader = new SAXReader(); try { @@ -83,14 +83,20 @@ public class OldProfilesImporter { res.setDescription(doc.valueOf("//HADOOP_JOB/DESCRIPTION")); resContent = doc.selectSingleNode("//HADOOP_JOB").asXML(); break; + case "DedupConfigurationDSResourceType": + res.setType("dedup_configuration"); + res.setName(doc.valueOf("//DESCRIPTION")); + res.setDescription(doc.valueOf("//DESCRIPTION")); + resContent = doc.valueOf("//DEDUPLICATION"); + break; default: throw new InformationServiceException("Invalid resource type: " + doc.valueOf("//RESOURCE_TYPE/@value")); } simpleResourceRepository.save(res); - simpleResourceRepository.setContentById(id, resContent); + simpleResourceRepository.setContentById(id, resContent.trim()); - return res; + return res.getId(); } catch (final Exception e) { throw new InformationServiceException("Error parsing file", e); } diff --git a/apps/dnet-is-application/src/main/resources/static/js/simpleResources.js b/apps/dnet-is-application/src/main/resources/static/js/simpleResources.js index fccd6a54..f950986b 100644 --- a/apps/dnet-is-application/src/main/resources/static/js/simpleResources.js +++ b/apps/dnet-is-application/src/main/resources/static/js/simpleResources.js @@ -30,7 +30,11 @@ app.controller('resourcesController', function($scope, $http) { $scope.tmpRes = angular.copy(r); $scope.tmpContent = "loading..."; $http.get('./api/resources/' + r.id + '/content?' + $.now()).then(function successCallback(res) { - $scope.tmpContent = res.data; + if (res.data instanceof Object) { + $scope.tmpContent = JSON.stringify(res.data, null, "\t"); + } else { + $scope.tmpContent = res.data; + } }, function errorCallback(res) { alert('ERROR: ' + res.data.message); }); diff --git a/libs/dnet-is-common/src/main/resources/sql/schema.sql b/libs/dnet-is-common/src/main/resources/sql/schema.sql index ea48e82e..c7af7cba 100644 --- a/libs/dnet-is-common/src/main/resources/sql/schema.sql +++ b/libs/dnet-is-common/src/main/resources/sql/schema.sql @@ -90,7 +90,8 @@ INSERT INTO resource_types(id, name, content_type) VALUES ('transformation_rule_xslt', 'Transformation Rules (xslt)', 'application/xml'), ('transformation_rule_legacy', 'Transformation Rules (legacy)', 'text/plain'), ('cleaning_rule', 'Cleaning Rules', 'application/xml'), - ('hadoop_job_configuration', 'Hadoop Job Configurations', 'application/xml'); + ('hadoop_job_configuration', 'Hadoop Job Configurations', 'application/xml') + ('dedup_configuration', 'Dedup Configurations', 'application/json'); CREATE TABLE resources ( id text PRIMARY KEY,