From 1f40b197e06c3d2719ad86b6c3a83bce2cad4613 Mon Sep 17 00:00:00 2001 From: Chris Morley Date: Mon, 23 May 2022 16:05:36 -0400 Subject: [PATCH 01/25] hello --- hello | 0 kevin_errors.txt | 19 +++++++++++++++++++ notes.txt | 1 + run.sh | 2 ++ run_helper.sh | 3 +++ 5 files changed, 25 insertions(+) create mode 100644 hello create mode 100644 kevin_errors.txt create mode 100644 notes.txt create mode 100755 run.sh create mode 100644 run_helper.sh diff --git a/hello b/hello new file mode 100644 index 00000000..e69de29b diff --git a/kevin_errors.txt b/kevin_errors.txt new file mode 100644 index 00000000..68f7b756 --- /dev/null +++ b/kevin_errors.txt @@ -0,0 +1,19 @@ +play.api.UnexpectedException: Unexpected exception[JsResultException: JsResultException(errors:List(((0),List(JsonValidationError(List(error.expected.jsstring),WrappedArray()))), ((1),List(JsonValidationError(List(error.expected.jsstring),WrappedArray())))))] +play.api.UnexpectedException: Unexpected exception[JsResultException: JsResultException(errors:List(((0),List(JsonValidationError(List(error.expected.jsstring),WrappedArray()))), ((1),List(JsonValidationError(List(error.expected.jsstring),WrappedArray())))))] +play.api.UnexpectedException: Unexpected exception[JsResultException: JsResultException(errors:List(((0),List(JsonValidationError(List(error.expected.jsstring),WrappedArray()))), ((1),List(JsonValidationError(List(error.expected.jsstring),WrappedArray())))))] +play.api.UnexpectedException: Unexpected exception[JsResultException: JsResultException(errors:List(((0),List(JsonValidationError(List(error.expected.jsstring),WrappedArray()))), ((1),List(JsonValidationError(List(error.expected.jsstring),WrappedArray())))))] +play.api.UnexpectedException: Unexpected exception[JsResultException: JsResultException(errors:List(((0),List(JsonValidationError(List(error.expected.jsstring),WrappedArray()))), ((1),List(JsonValidationError(List(error.expected.jsstring),WrappedArray())))))] +play.api.UnexpectedException: Unexpected exception[JsResultException: JsResultException(errors:List(((0),List(JsonValidationError(List(error.expected.jsstring),WrappedArray()))), ((1),List(JsonValidationError(List(error.expected.jsstring),WrappedArray())))))] +play.api.UnexpectedException: Unexpected exception[JsResultException: JsResultException(errors:List(((0),List(JsonValidationError(List(error.expected.jsstring),WrappedArray()))), ((1),List(JsonValidationError(List(error.expected.jsstring),WrappedArray())))))] +play.api.UnexpectedException: Unexpected exception[JsResultException: JsResultException(errors:List(((0),List(JsonValidationError(List(error.expected.jsstring),WrappedArray()))), ((1),List(JsonValidationError(List(error.expected.jsstring),WrappedArray())))))] +play.api.UnexpectedException: Unexpected exception[JsResultException: JsResultException(errors:List(((0),List(JsonValidationError(List(error.expected.jsstring),WrappedArray()))), ((1),List(JsonValidationError(List(error.expected.jsstring),WrappedArray())))))] +play.api.UnexpectedException: Unexpected exception[JsResultException: JsResultException(errors:List(((0),List(JsonValidationError(List(error.expected.jsstring),WrappedArray()))), ((1),List(JsonValidationError(List(error.expected.jsstring),WrappedArray())))))] +play.api.UnexpectedException: Unexpected exception[JsResultException: JsResultException(errors:List(((0),List(JsonValidationError(List(error.expected.jsstring),WrappedArray()))), ((1),List(JsonValidationError(List(error.expected.jsstring),WrappedArray())))))] +play.api.UnexpectedException: Unexpected exception[JsResultException: JsResultException(errors:List((/upDownRules,List(JsonValidationError(List(error.path.missing),WrappedArray()))), (/deleteRules,List(JsonValidationError(List(error.path.missing),WrappedArray()))), (/filterRules,List(JsonValidationError(List(error.path.missing),WrappedArray()))), (/synonymRules,List(JsonValidationError(List(error.path.missing),WrappedArray()))), (/redirectRules,List(JsonValidationError(List(error.path.missing),WrappedArray())))))] +play.api.UnexpectedException: Unexpected exception[JsResultException: JsResultException(errors:List((/upDownRules,List(JsonValidationError(List(error.path.missing),WrappedArray()))), (/deleteRules,List(JsonValidationError(List(error.path.missing),WrappedArray()))), (/filterRules,List(JsonValidationError(List(error.path.missing),WrappedArray()))), (/synonymRules,List(JsonValidationError(List(error.path.missing),WrappedArray()))), (/redirectRules,List(JsonValidationError(List(error.path.missing),WrappedArray())))))] +play.api.UnexpectedException: Unexpected exception[BatchUpdateException: Duplicate entry '5f4fa25d-21cd-4348-b6b0-908cafdf29e9' for key 'PRIMARY'] +play.api.UnexpectedException: Unexpected exception[BatchUpdateException: Duplicate entry 'e78aa12d-5941-4370-8489-3e15b94e02df' for key 'PRIMARY'] +play.api.UnexpectedException: Unexpected exception[SQLIntegrityConstraintViolationException: Duplicate entry 'ecommerce' for key 'solr_index_field_name'] +play.api.UnexpectedException: Unexpected exception[SQLIntegrityConstraintViolationException: Duplicate entry 'ecommerce' for key 'solr_index_field_name'] +play.api.UnexpectedException: Unexpected exception[SQLIntegrityConstraintViolationException: Duplicate entry 'ecommerce' for key 'solr_index_field_name'] +play.api.UnexpectedException: Unexpected exception[NoSuchElementException: head of empty list] \ No newline at end of file diff --git a/notes.txt b/notes.txt new file mode 100644 index 00000000..9420bc23 --- /dev/null +++ b/notes.txt @@ -0,0 +1 @@ +make docker-build-only \ No newline at end of file diff --git a/run.sh b/run.sh new file mode 100755 index 00000000..93831f91 --- /dev/null +++ b/run.sh @@ -0,0 +1,2 @@ +#!/bin/bash +source run_helper.sh \ No newline at end of file diff --git a/run_helper.sh b/run_helper.sh new file mode 100644 index 00000000..9d32e3ab --- /dev/null +++ b/run_helper.sh @@ -0,0 +1,3 @@ +#!/bin/bash +source ~/.zshrc +sbt run -Dconfig.file=./smui-dev.conf 9000 \ No newline at end of file From 73ffe512222f5565881482e2be218c1e1ce40c63 Mon Sep 17 00:00:00 2001 From: Chris Morley Date: Tue, 24 May 2022 13:46:47 -0400 Subject: [PATCH 02/25] rm test files; fix error messages on rules collection creation --- .../rules-collection-create.component.ts | 23 ++++++++++++++++--- hello | 0 kevin_errors.txt | 19 --------------- notes.txt | 1 - run.sh | 2 -- run_helper.sh | 3 --- 6 files changed, 20 insertions(+), 28 deletions(-) delete mode 100644 hello delete mode 100644 kevin_errors.txt delete mode 100644 notes.txt delete mode 100755 run.sh delete mode 100644 run_helper.sh diff --git a/frontend/src/app/components/admin/rules-collection-create/rules-collection-create.component.ts b/frontend/src/app/components/admin/rules-collection-create/rules-collection-create.component.ts index ea64f919..a678e507 100644 --- a/frontend/src/app/components/admin/rules-collection-create/rules-collection-create.component.ts +++ b/frontend/src/app/components/admin/rules-collection-create/rules-collection-create.component.ts @@ -64,9 +64,26 @@ export class RulesCollectionCreateComponent implements OnInit, OnChanges { .then(() => this.showSuccessMsg.emit("Created new Rules Collection " + this.description)) .then(() => this.solrService.emitRulesCollectionChangeEvent("")) .then(() => this.clearForm()) - .catch(error => this.showErrorMsg.emit(error)); + .catch(error => { + console.log(error); + var showAlreadyExists = false; + var errorMsg = 'Unknown Error' + if ('status' in error) { + errorMsg += ": " + error.status; + if (error.status == 500) { + showAlreadyExists = true; + } + } + if ('statusText' in error) { + errorMsg += " " + error.statusText; + } + if (showAlreadyExists) { + errorMsg += " (Rules collection for that search engine collection already exists?)" + } + this.showErrorMsg.emit(errorMsg); + }); + } else { + this.showErrorMsg.emit("Fill in both name fields."); } } - - } diff --git a/hello b/hello deleted file mode 100644 index e69de29b..00000000 diff --git a/kevin_errors.txt b/kevin_errors.txt deleted file mode 100644 index 68f7b756..00000000 --- a/kevin_errors.txt +++ /dev/null @@ -1,19 +0,0 @@ -play.api.UnexpectedException: Unexpected exception[JsResultException: JsResultException(errors:List(((0),List(JsonValidationError(List(error.expected.jsstring),WrappedArray()))), ((1),List(JsonValidationError(List(error.expected.jsstring),WrappedArray())))))] -play.api.UnexpectedException: Unexpected exception[JsResultException: JsResultException(errors:List(((0),List(JsonValidationError(List(error.expected.jsstring),WrappedArray()))), ((1),List(JsonValidationError(List(error.expected.jsstring),WrappedArray())))))] -play.api.UnexpectedException: Unexpected exception[JsResultException: JsResultException(errors:List(((0),List(JsonValidationError(List(error.expected.jsstring),WrappedArray()))), ((1),List(JsonValidationError(List(error.expected.jsstring),WrappedArray())))))] -play.api.UnexpectedException: Unexpected exception[JsResultException: JsResultException(errors:List(((0),List(JsonValidationError(List(error.expected.jsstring),WrappedArray()))), ((1),List(JsonValidationError(List(error.expected.jsstring),WrappedArray())))))] -play.api.UnexpectedException: Unexpected exception[JsResultException: JsResultException(errors:List(((0),List(JsonValidationError(List(error.expected.jsstring),WrappedArray()))), ((1),List(JsonValidationError(List(error.expected.jsstring),WrappedArray())))))] -play.api.UnexpectedException: Unexpected exception[JsResultException: JsResultException(errors:List(((0),List(JsonValidationError(List(error.expected.jsstring),WrappedArray()))), ((1),List(JsonValidationError(List(error.expected.jsstring),WrappedArray())))))] -play.api.UnexpectedException: Unexpected exception[JsResultException: JsResultException(errors:List(((0),List(JsonValidationError(List(error.expected.jsstring),WrappedArray()))), ((1),List(JsonValidationError(List(error.expected.jsstring),WrappedArray())))))] -play.api.UnexpectedException: Unexpected exception[JsResultException: JsResultException(errors:List(((0),List(JsonValidationError(List(error.expected.jsstring),WrappedArray()))), ((1),List(JsonValidationError(List(error.expected.jsstring),WrappedArray())))))] -play.api.UnexpectedException: Unexpected exception[JsResultException: JsResultException(errors:List(((0),List(JsonValidationError(List(error.expected.jsstring),WrappedArray()))), ((1),List(JsonValidationError(List(error.expected.jsstring),WrappedArray())))))] -play.api.UnexpectedException: Unexpected exception[JsResultException: JsResultException(errors:List(((0),List(JsonValidationError(List(error.expected.jsstring),WrappedArray()))), ((1),List(JsonValidationError(List(error.expected.jsstring),WrappedArray())))))] -play.api.UnexpectedException: Unexpected exception[JsResultException: JsResultException(errors:List(((0),List(JsonValidationError(List(error.expected.jsstring),WrappedArray()))), ((1),List(JsonValidationError(List(error.expected.jsstring),WrappedArray())))))] -play.api.UnexpectedException: Unexpected exception[JsResultException: JsResultException(errors:List((/upDownRules,List(JsonValidationError(List(error.path.missing),WrappedArray()))), (/deleteRules,List(JsonValidationError(List(error.path.missing),WrappedArray()))), (/filterRules,List(JsonValidationError(List(error.path.missing),WrappedArray()))), (/synonymRules,List(JsonValidationError(List(error.path.missing),WrappedArray()))), (/redirectRules,List(JsonValidationError(List(error.path.missing),WrappedArray())))))] -play.api.UnexpectedException: Unexpected exception[JsResultException: JsResultException(errors:List((/upDownRules,List(JsonValidationError(List(error.path.missing),WrappedArray()))), (/deleteRules,List(JsonValidationError(List(error.path.missing),WrappedArray()))), (/filterRules,List(JsonValidationError(List(error.path.missing),WrappedArray()))), (/synonymRules,List(JsonValidationError(List(error.path.missing),WrappedArray()))), (/redirectRules,List(JsonValidationError(List(error.path.missing),WrappedArray())))))] -play.api.UnexpectedException: Unexpected exception[BatchUpdateException: Duplicate entry '5f4fa25d-21cd-4348-b6b0-908cafdf29e9' for key 'PRIMARY'] -play.api.UnexpectedException: Unexpected exception[BatchUpdateException: Duplicate entry 'e78aa12d-5941-4370-8489-3e15b94e02df' for key 'PRIMARY'] -play.api.UnexpectedException: Unexpected exception[SQLIntegrityConstraintViolationException: Duplicate entry 'ecommerce' for key 'solr_index_field_name'] -play.api.UnexpectedException: Unexpected exception[SQLIntegrityConstraintViolationException: Duplicate entry 'ecommerce' for key 'solr_index_field_name'] -play.api.UnexpectedException: Unexpected exception[SQLIntegrityConstraintViolationException: Duplicate entry 'ecommerce' for key 'solr_index_field_name'] -play.api.UnexpectedException: Unexpected exception[NoSuchElementException: head of empty list] \ No newline at end of file diff --git a/notes.txt b/notes.txt deleted file mode 100644 index 9420bc23..00000000 --- a/notes.txt +++ /dev/null @@ -1 +0,0 @@ -make docker-build-only \ No newline at end of file diff --git a/run.sh b/run.sh deleted file mode 100755 index 93831f91..00000000 --- a/run.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -source run_helper.sh \ No newline at end of file diff --git a/run_helper.sh b/run_helper.sh deleted file mode 100644 index 9d32e3ab..00000000 --- a/run_helper.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -source ~/.zshrc -sbt run -Dconfig.file=./smui-dev.conf 9000 \ No newline at end of file From aac937988f1cb26636da52f96f7df37c357ccf1c Mon Sep 17 00:00:00 2001 From: Chris Morley Date: Tue, 24 May 2022 15:14:42 -0400 Subject: [PATCH 03/25] catch add solr index exception in api --- app/controllers/ApiController.scala | 17 +++++++++++++---- .../rules-collection-create.component.ts | 14 ++------------ 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/app/controllers/ApiController.scala b/app/controllers/ApiController.scala index 4a6085ab..7b1c143c 100644 --- a/app/controllers/ApiController.scala +++ b/app/controllers/ApiController.scala @@ -58,11 +58,20 @@ class ApiController @Inject()(authActionFactory: AuthActionFactory, jsonBody.map { json => val searchIndexName = (json \ "name").as[String] val searchIndexDescription = (json \ "description").as[String] - val solrIndexId = searchManagementRepository.addNewSolrIndex( - SolrIndex(name = searchIndexName, description = searchIndexDescription) - ) - Ok(Json.toJson(ApiResult(API_RESULT_OK, "Successfully added Deployment Channel '" + searchIndexName + "'.", Some(solrIndexId)))) + var solrIndexId: SolrIndexId = new SolrIndexId(""); + try { + solrIndexId = searchManagementRepository.addNewSolrIndex( + SolrIndex(name = searchIndexName, description = searchIndexDescription) + ); + logger.debug("solrIndexId:" + solrIndexId); + Ok(Json.toJson(ApiResult(API_RESULT_OK, "Successfully added Deployment Channel '" + searchIndexName + "'.", Some(solrIndexId)))) + } catch { + case e: Exception => { + BadRequest(Json.toJson(ApiResult(API_RESULT_FAIL, "Could not add new Solr index. Duplicate?", None))) + }; + } + }.getOrElse { BadRequest(Json.toJson(ApiResult(API_RESULT_FAIL, "Adding new Deployment Channel failed. Unexpected body data.", None))) } diff --git a/frontend/src/app/components/admin/rules-collection-create/rules-collection-create.component.ts b/frontend/src/app/components/admin/rules-collection-create/rules-collection-create.component.ts index a678e507..10eccfb9 100644 --- a/frontend/src/app/components/admin/rules-collection-create/rules-collection-create.component.ts +++ b/frontend/src/app/components/admin/rules-collection-create/rules-collection-create.component.ts @@ -66,19 +66,9 @@ export class RulesCollectionCreateComponent implements OnInit, OnChanges { .then(() => this.clearForm()) .catch(error => { console.log(error); - var showAlreadyExists = false; var errorMsg = 'Unknown Error' - if ('status' in error) { - errorMsg += ": " + error.status; - if (error.status == 500) { - showAlreadyExists = true; - } - } - if ('statusText' in error) { - errorMsg += " " + error.statusText; - } - if (showAlreadyExists) { - errorMsg += " (Rules collection for that search engine collection already exists?)" + if ('message' in error.error) { + errorMsg = error.error.message; } this.showErrorMsg.emit(errorMsg); }); From 301d8dac6f90fc7287765c4154f4e25043812ae4 Mon Sep 17 00:00:00 2001 From: Chris Morley Date: Tue, 24 May 2022 15:25:08 -0400 Subject: [PATCH 04/25] error handling in the API when search engine collection is a duplicate --- app/controllers/ApiController.scala | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/ApiController.scala b/app/controllers/ApiController.scala index 7b1c143c..21333c38 100644 --- a/app/controllers/ApiController.scala +++ b/app/controllers/ApiController.scala @@ -59,16 +59,16 @@ class ApiController @Inject()(authActionFactory: AuthActionFactory, val searchIndexName = (json \ "name").as[String] val searchIndexDescription = (json \ "description").as[String] - var solrIndexId: SolrIndexId = new SolrIndexId(""); try { - solrIndexId = searchManagementRepository.addNewSolrIndex( + var solrIndexId = searchManagementRepository.addNewSolrIndex( SolrIndex(name = searchIndexName, description = searchIndexDescription) ); logger.debug("solrIndexId:" + solrIndexId); Ok(Json.toJson(ApiResult(API_RESULT_OK, "Successfully added Deployment Channel '" + searchIndexName + "'.", Some(solrIndexId)))) } catch { case e: Exception => { - BadRequest(Json.toJson(ApiResult(API_RESULT_FAIL, "Could not add new Solr index. Duplicate?", None))) + logger.debug("The searchIndexDescription (Search Engine Collection Name) given was likely a duplicate."); + BadRequest(Json.toJson(ApiResult(API_RESULT_FAIL, "Could not add Rules Collection. Only one Rules Collection per Search Engine Collection is allowed.", None))) }; } From 5a2d99c8af29a20f74b8254ebf98a20bdb64e52c Mon Sep 17 00:00:00 2001 From: Chris Morley Date: Thu, 26 May 2022 14:28:31 -0400 Subject: [PATCH 05/25] download some json --- app/controllers/ApiController.scala | 25 ++++ app/models/SearchManagementRepository.scala | 13 ++ app/models/SolrIndex.scala | 6 + app/models/export/Something.scala | 42 +++++++ app/models/input/ListItem.scala | 1 + app/models/reports/RulesReport.scala | 1 + application-clean-run.sh | 4 + application-run.sh | 2 + conf/logback.xml | 6 +- conf/routes | 3 + docker-rm-mysql-containers.sh | 3 + docker-run-mysql-container.sh | 5 + docker-what-is-mysql-container-id.sh | 2 + frontend/src/app/app-routing.module.ts | 2 + frontend/src/app/app.module.ts | 30 ++++- .../rules-collection-list.component.html | 8 ++ .../rules-collection-list.component.ts | 119 +++++++++++++++++- ...ris-rules-collection-create.component.html | 32 +++++ ...chris-rules-collection-create.component.ts | 72 +++++++++++ .../chris-rules-collection-create/index.ts | 1 + ...chris-rules-collection-list.component.html | 26 ++++ .../chris-rules-collection-list.component.ts | 65 ++++++++++ .../chris-rules-collection-list/index.ts | 1 + ...ris-suggested-fields-create.component.html | 25 ++++ ...chris-suggested-fields-create.component.ts | 62 +++++++++ ...chris-suggested-fields-list.component.html | 20 +++ .../chris-suggested-fields-list.component.ts | 68 ++++++++++ .../chris-suggested-fields.component.html | 35 ++++++ .../chris-suggested-fields.component.ts | 100 +++++++++++++++ .../chris/chris-suggested-fields/index.ts | 3 + .../app/components/chris/chris.component.html | 24 ++++ .../app/components/chris/chris.component.ts | 56 +++++++++ frontend/src/app/components/chris/index.ts | 3 + .../header-nav/header-nav.component.html | 8 ++ .../src/app/models/downloadableRule.model.ts | 17 +++ .../src/app/models/downloadableRules.model.ts | 6 + frontend/src/app/models/export.ts | 3 + frontend/src/app/services/solr.service.ts | 1 - run_helper.sh | 7 ++ 39 files changed, 901 insertions(+), 6 deletions(-) create mode 100644 app/models/export/Something.scala create mode 100755 application-clean-run.sh create mode 100755 application-run.sh create mode 100755 docker-rm-mysql-containers.sh create mode 100755 docker-run-mysql-container.sh create mode 100755 docker-what-is-mysql-container-id.sh create mode 100644 frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.html create mode 100644 frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.ts create mode 100644 frontend/src/app/components/chris/chris-rules-collection-create/index.ts create mode 100644 frontend/src/app/components/chris/chris-rules-collection-list/chris-rules-collection-list.component.html create mode 100644 frontend/src/app/components/chris/chris-rules-collection-list/chris-rules-collection-list.component.ts create mode 100644 frontend/src/app/components/chris/chris-rules-collection-list/index.ts create mode 100644 frontend/src/app/components/chris/chris-suggested-fields/chris-suggested-fields-create/chris-suggested-fields-create.component.html create mode 100644 frontend/src/app/components/chris/chris-suggested-fields/chris-suggested-fields-create/chris-suggested-fields-create.component.ts create mode 100644 frontend/src/app/components/chris/chris-suggested-fields/chris-suggested-fields-list/chris-suggested-fields-list.component.html create mode 100644 frontend/src/app/components/chris/chris-suggested-fields/chris-suggested-fields-list/chris-suggested-fields-list.component.ts create mode 100644 frontend/src/app/components/chris/chris-suggested-fields/chris-suggested-fields.component.html create mode 100644 frontend/src/app/components/chris/chris-suggested-fields/chris-suggested-fields.component.ts create mode 100644 frontend/src/app/components/chris/chris-suggested-fields/index.ts create mode 100644 frontend/src/app/components/chris/chris.component.html create mode 100644 frontend/src/app/components/chris/chris.component.ts create mode 100644 frontend/src/app/components/chris/index.ts create mode 100644 frontend/src/app/models/downloadableRule.model.ts create mode 100644 frontend/src/app/models/downloadableRules.model.ts create mode 100644 frontend/src/app/models/export.ts create mode 100755 run_helper.sh diff --git a/app/controllers/ApiController.scala b/app/controllers/ApiController.scala index 21333c38..a60775e3 100644 --- a/app/controllers/ApiController.scala +++ b/app/controllers/ApiController.scala @@ -1,3 +1,4 @@ +//CJM 10 package controllers import java.io.{OutputStream, PipedInputStream, PipedOutputStream} @@ -23,6 +24,7 @@ import models.querqy.QuerqyRulesTxtGenerator import models.spellings.{CanonicalSpellingId, CanonicalSpellingValidator, CanonicalSpellingWithAlternatives} import org.checkerframework.checker.units.qual.A import services.{RulesTxtDeploymentService, RulesTxtImportService} +import scala.collection.JavaConverters._ // TODO Make ApiController pure REST- / JSON-Controller to ensure all implicit Framework responses (e.g. 400, 500) conformity @@ -104,6 +106,7 @@ class ApiController @Inject()(authActionFactory: AuthActionFactory, } } + //CJM 8 def downloadAllRulesTxtFiles = authActionFactory.getAuthenticatedAction(Action) { req => Ok.chunked( createStreamResultInBackground( @@ -214,6 +217,19 @@ class ApiController @Inject()(authActionFactory: AuthActionFactory, Ok(Json.toJson(ListItem.create(searchInputs, spellings))) } +// def listAll2(solrIndexId: String) = authActionFactory.getAuthenticatedAction(Action) { +// //val searchInputs = searchManagementRepository.listAllSearchInputsInclDirectedSynonyms(SolrIndexId(solrIndexId)) +// //val searchInputs = searchManagementRepository.listAllSearchInputsInclDirectedSynonyms(SolrIndexId(solrIndexId)) +// //val spellings = searchManagementRepository.listAllSpellingsWithAlternatives(SolrIndexId(solrIndexId)) +// Future { +// this.getSolrIndex(solrIndexId) +// Ok(Json.toJson(ApiResult(API_RESULT_OK, "Solr Index successful", None))) +// +// } +// //Ok(s); +// //Ok(Json.toJson(x)) +// } + def addNewSpelling(solrIndexId: String) = authActionFactory.getAuthenticatedAction(Action).async { request: Request[AnyContent] => Future { val userInfo: Option[String] = lookupUserInfo(request) @@ -583,4 +599,13 @@ class ApiController @Inject()(authActionFactory: AuthActionFactory, } } + + def getSomething(solrIndexId: String) = authActionFactory.getAuthenticatedAction(Action).async { + Future { + val something = searchManagementRepository.getSomething(solrIndexId) + Ok(Json.toJson(something.writer.writes("writesMsg1"))) + //Ok(Json.toJson( + } + } + } diff --git a/app/models/SearchManagementRepository.scala b/app/models/SearchManagementRepository.scala index 92b674cc..72d6b3b1 100644 --- a/app/models/SearchManagementRepository.scala +++ b/app/models/SearchManagementRepository.scala @@ -1,3 +1,4 @@ +//CJM 9 package models import java.time.LocalDateTime @@ -6,6 +7,7 @@ import javax.inject.Inject import play.api.db.DBApi import anorm._ import models.FeatureToggleModel.FeatureToggleService +import models.export.{Something} import models.input.{InputTag, InputTagId, PredefinedTag, SearchInput, SearchInputId, SearchInputWithRules, TagInputAssociation} import models.spellings.{CanonicalSpelling, CanonicalSpellingId, CanonicalSpellingWithAlternatives} import models.eventhistory.{ActivityLog, ActivityLogEntry, InputEvent} @@ -35,6 +37,10 @@ class SearchManagementRepository @Inject()(dbapi: DBApi, toggleService: FeatureT SolrIndex.loadById(solrIndexId) } +// def getSolrIndex(solrIndexId: String): SolrIndex = db.withConnection { implicit connection => +// SolrIndex.loadById(solrIndexId) +// } + def addNewSolrIndex(newSolrIndex: SolrIndex): SolrIndexId = db.withConnection { implicit connection => SolrIndex.insert(newSolrIndex) } @@ -304,4 +310,11 @@ class SearchManagementRepository @Inject()(dbapi: DBApi, toggleService: FeatureT } } + def getSomething(solrIndexId: String): Something = db.withConnection { + implicit connection => { + val something = new Something(solrIndexId) + something + } + } + } diff --git a/app/models/SolrIndex.scala b/app/models/SolrIndex.scala index c8b98979..6a9df97c 100644 --- a/app/models/SolrIndex.scala +++ b/app/models/SolrIndex.scala @@ -52,6 +52,12 @@ object SolrIndex { allMatchingIndeces.head } +// def loadById(solrIndexId: String)(implicit connection: Connection): SolrIndex = { +// val allMatchingIndeces = SQL"select * from #$TABLE_NAME where id = $solrIndexId".as(sqlParser.*) +// +// allMatchingIndeces.head +// } + def insert(newSolrIndex: SolrIndex)(implicit connection: Connection): SolrIndexId = { SQL"insert into #$TABLE_NAME (id, name, description, last_update) values (${newSolrIndex.id}, ${newSolrIndex.name}, ${newSolrIndex.description}, ${new Date()})".execute() newSolrIndex.id diff --git a/app/models/export/Something.scala b/app/models/export/Something.scala new file mode 100644 index 00000000..8edbcb56 --- /dev/null +++ b/app/models/export/Something.scala @@ -0,0 +1,42 @@ +package models.`export` + +import play.api.libs.json.{JsArray, JsNull, JsNumber, JsObject, JsString, JsValue, Json, Writes} + +case class MyJsObject( + value0: JsValue, + value1: JsValue, + value2: JsValue, + value3: JsValue + ) + +class Something(solrIndexId: String) { + + val myJavascriptObject: MyJsObject = + MyJsObject( + value0 = new JsString("solrIndexId = " + solrIndexId), + value1 = JsObject(Seq("simpleObject" -> JsString("simpleStringValue"))), + value2 = JsObject( + Seq( + "aString" -> JsString("simpleString"), + "aNumber" -> JsNumber(4.3), + "aNull" -> JsNull + ) + ), + value3 = JsArray( + IndexedSeq( + new JsString("first value of array"), + new JsString("second value of array")) + ) + ) + + implicit val writer = new Writes[(String)] { + def writes(t: (String)): JsValue = { + Json.obj( + "value0" -> myJavascriptObject.value0, + "value1" -> myJavascriptObject.value1, + "value2" -> myJavascriptObject.value2, + "value3" -> myJavascriptObject.value3) + } + } + +} diff --git a/app/models/input/ListItem.scala b/app/models/input/ListItem.scala index 05dc5070..2757ab26 100644 --- a/app/models/input/ListItem.scala +++ b/app/models/input/ListItem.scala @@ -1,3 +1,4 @@ +//CJM 5 package models.input import models.input.ListItemType.ListItemType diff --git a/app/models/reports/RulesReport.scala b/app/models/reports/RulesReport.scala index dea64c71..c2750640 100644 --- a/app/models/reports/RulesReport.scala +++ b/app/models/reports/RulesReport.scala @@ -94,6 +94,7 @@ object RulesReport extends Logging { unsortedRules.sortWith((a,b) => (compareRulesReportItem(a,b) < 0)) } + //CJM 7 // TODO write test def loadForSolrIndexId(solrIndexId: SolrIndexId)(implicit connection: Connection): RulesReport = { diff --git a/application-clean-run.sh b/application-clean-run.sh new file mode 100755 index 00000000..5612f2dd --- /dev/null +++ b/application-clean-run.sh @@ -0,0 +1,4 @@ +#!/bin/bash +./docker-rm-mysql-containers.sh +./docker-run-mysql-container.sh +source run_helper.sh \ No newline at end of file diff --git a/application-run.sh b/application-run.sh new file mode 100755 index 00000000..93831f91 --- /dev/null +++ b/application-run.sh @@ -0,0 +1,2 @@ +#!/bin/bash +source run_helper.sh \ No newline at end of file diff --git a/conf/logback.xml b/conf/logback.xml index 7831cacc..76f36d43 100644 --- a/conf/logback.xml +++ b/conf/logback.xml @@ -25,7 +25,7 @@ - + @@ -45,7 +45,7 @@ - + @@ -58,7 +58,7 @@ - + diff --git a/conf/routes b/conf/routes index 0bdf3e89..41e0f8f1 100644 --- a/conf/routes +++ b/conf/routes @@ -1,3 +1,5 @@ +# CJM + # Routes # This file defines all application routes (Higher priority routes first) # ~~~~ @@ -35,6 +37,7 @@ GET /api/v1/log/rule-activity-log controllers.ApiC GET /api/v1/report/rules-report/:solrIndexId controllers.ApiController.getRulesReport(solrIndexId: String) GET /api/v1/report/activity-report/:solrIndexId controllers.ApiController.getActivityReport(solrIndexId: String) GET /api/v1/version/latest-info controllers.ApiController.getLatestVersionInfo() +GET /api/v1/solr-index/:solrIndexId/something controllers.ApiController.getSomething(solrIndexId: String) # Map static resources from the /public folder to the /assets URL path GET /*file controllers.FrontendController.assetOrDefault(file) diff --git a/docker-rm-mysql-containers.sh b/docker-rm-mysql-containers.sh new file mode 100755 index 00000000..f32a7232 --- /dev/null +++ b/docker-rm-mysql-containers.sh @@ -0,0 +1,3 @@ +#!/bin/bash +docker ps -a -q --filter "ancestor=mysql:5.7" | xargs -I {} docker container stop {} +docker ps -a -q --filter "ancestor=mysql:5.7" | xargs -I {} docker container rm {} diff --git a/docker-run-mysql-container.sh b/docker-run-mysql-container.sh new file mode 100755 index 00000000..ead85fad --- /dev/null +++ b/docker-run-mysql-container.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +# make sure to start docker desktop first + +docker run --name smui-mysql -e MYSQL_ROOT_PASSWORD=smui -e MYSQL_USER=smui -e MYSQL_PASSWORD=smui -e MYSQL_DATABASE=smui -p 3306:3306 -d mysql:5.7 \ No newline at end of file diff --git a/docker-what-is-mysql-container-id.sh b/docker-what-is-mysql-container-id.sh new file mode 100755 index 00000000..13af3720 --- /dev/null +++ b/docker-what-is-mysql-container-id.sh @@ -0,0 +1,2 @@ +#!/bin/bash +docker ps -a -q --filter "ancestor=mysql:5.7" \ No newline at end of file diff --git a/frontend/src/app/app-routing.module.ts b/frontend/src/app/app-routing.module.ts index 62b5dfa6..976e38e2 100644 --- a/frontend/src/app/app-routing.module.ts +++ b/frontend/src/app/app-routing.module.ts @@ -4,6 +4,7 @@ import { Routes, RouterModule } from '@angular/router'; import { SearchManagementComponent } from './components/search-management'; import { ReportComponent } from './components/report'; import { AdminComponent } from './components/admin'; +import { ChrisComponent } from './components/chris'; import { SuggestedFieldsComponent } from './components/admin/suggested-fields'; const routes: Routes = [ @@ -11,6 +12,7 @@ const routes: Routes = [ { path: 'rules', component: SearchManagementComponent }, { path: 'report', component: ReportComponent }, { path: 'admin', component: AdminComponent }, + { path: 'chris', component: ChrisComponent }, { path: 'admin/suggested-fields/:solrIndexId', component: SuggestedFieldsComponent } ]; diff --git a/frontend/src/app/app.module.ts b/frontend/src/app/app.module.ts index 313ea99e..bed09d78 100644 --- a/frontend/src/app/app.module.ts +++ b/frontend/src/app/app.module.ts @@ -43,6 +43,28 @@ import { SuggestedFieldsCreateComponent, SuggestedFieldsListComponent } from './components/admin/suggested-fields'; + +import { + ChrisComponent, + //ChrisRulesCollectionListComponent, + //ChrisRulesCollectionCreateComponent +} from './components/chris'; + +import { + ChrisRulesCollectionCreateComponent +} from './components/chris/chris-rules-collection-create'; + +import { + ChrisRulesCollectionListComponent +} from './components/chris/chris-rules-collection-list'; + +// import { +// ChrisSuggestedFieldsComponent, +// ChrisSuggestedFieldsCreateComponent, +// ChrisSuggestedFieldsListComponent +// } from './components/chris/chris-suggested-fields'; + + import { ButtonRowComponent, CardComponent, @@ -96,7 +118,13 @@ import { RulesCollectionCreateComponent, SuggestedFieldsComponent, SuggestedFieldsCreateComponent, - SuggestedFieldsListComponent + SuggestedFieldsListComponent, + ChrisComponent, + // ChrisRulesCollectionListComponent, + ChrisRulesCollectionCreateComponent, + // ChrisSuggestedFieldsComponent, + // ChrisSuggestedFieldsCreateComponent, + // ChrisSuggestedFieldsListComponent ], providers: [ CommonsService, diff --git a/frontend/src/app/components/admin/rules-collection-list/rules-collection-list.component.html b/frontend/src/app/components/admin/rules-collection-list/rules-collection-list.component.html index f31e294b..d8ec2b05 100644 --- a/frontend/src/app/components/admin/rules-collection-list/rules-collection-list.component.html +++ b/frontend/src/app/components/admin/rules-collection-list/rules-collection-list.component.html @@ -13,6 +13,14 @@
Available Rules Collections in SMUIConfigure + + + + + + diff --git a/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.ts b/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.ts new file mode 100644 index 00000000..ab9a1769 --- /dev/null +++ b/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.ts @@ -0,0 +1,72 @@ +import { + Component, + Input, + Output, + EventEmitter, + OnChanges, + OnInit, + SimpleChanges +} from '@angular/core'; + +import { SolrIndex } from '../../../models'; +import { + SolrService, + ModalService +} from '../../../services'; + +@Component({ + selector: 'app-smui-chris-chris-rules-collection-create', + templateUrl: './chris-rules-collection-create.component.html' +}) +export class ChrisRulesCollectionCreateComponent implements OnInit, OnChanges { + + //@Output() updateRulesCollectionList: EventEmitter<> = new EventEmitter(); + @Output() showErrorMsg: EventEmitter = new EventEmitter(); + @Output() showSuccessMsg: EventEmitter = new EventEmitter(); + @Output() refreshChrisRulesCollectionList: EventEmitter = new EventEmitter(); + @Output() solrIndicesChange: EventEmitter = new EventEmitter(); + + solrIndices: SolrIndex[]; + name: string; + description: string; + + constructor( + private solrService: SolrService, + ) { + + } + ngOnInit() { + console.log('In ChrisRulesCollectionCreateComponent :: ngOnInit'); + //this.solrIndices = this.solrService.solrIndices; + } + + ngOnChanges(changes: SimpleChanges): void { + console.log('In ChrisRulesCollectionCreateComponent :: ngOnChanges'); + } + + refreshSolrIndicies() { + return this.solrService.listAllSolrIndices; + // : Promise.reject('No selected Solr index'); + } + + clearForm() { + this.name = ''; + this.description = ''; + } + + createChrisRulesCollection( event: Event){ + console.log('In ChrisRulesCollectionCreateComponent :: createChrisRulesCollection'); + if (this.name && this.description) { + this.solrService + .createSolrIndex(this.name, this.description) + .then(() => this.solrService.listAllSolrIndices()) + .then(() => this.solrIndicesChange.emit()) + .then(() => this.showSuccessMsg.emit("Created new Chris Rules Collection " + this.description)) + .then(() => this.solrService.emitRulesCollectionChangeEvent("")) + .then(() => this.clearForm()) + .catch(error => this.showErrorMsg.emit(error)); + } + } + + +} diff --git a/frontend/src/app/components/chris/chris-rules-collection-create/index.ts b/frontend/src/app/components/chris/chris-rules-collection-create/index.ts new file mode 100644 index 00000000..9f5db22b --- /dev/null +++ b/frontend/src/app/components/chris/chris-rules-collection-create/index.ts @@ -0,0 +1 @@ +export * from './chris-rules-collection-create.component'; diff --git a/frontend/src/app/components/chris/chris-rules-collection-list/chris-rules-collection-list.component.html b/frontend/src/app/components/chris/chris-rules-collection-list/chris-rules-collection-list.component.html new file mode 100644 index 00000000..d09d0418 --- /dev/null +++ b/frontend/src/app/components/chris/chris-rules-collection-list/chris-rules-collection-list.component.html @@ -0,0 +1,26 @@ + +
+
+
Chris Rules Collections
+
Available Chris Rules Collections in SMUI
+ +
    +
  • + {{ solrIndex.description }} ({{ solrIndex.name }})- Key: {{ solrIndex.id }} + + + + Configure + + +
  • +
+
+
diff --git a/frontend/src/app/components/chris/chris-rules-collection-list/chris-rules-collection-list.component.ts b/frontend/src/app/components/chris/chris-rules-collection-list/chris-rules-collection-list.component.ts new file mode 100644 index 00000000..b7e7954f --- /dev/null +++ b/frontend/src/app/components/chris/chris-rules-collection-list/chris-rules-collection-list.component.ts @@ -0,0 +1,65 @@ +import { + Component, + Input, + Output, + EventEmitter, + OnChanges, + OnInit, + SimpleChanges +} from '@angular/core'; + +import { SolrIndex } from '../../../models'; +import { + SolrService, + ModalService +} from '../../../services'; + +@Component({ + selector: 'app-smui-chris-chris-rules-collection-list', + templateUrl: './chris-rules-collection-list.component.html' +}) +export class ChrisRulesCollectionListComponent implements OnInit, OnChanges { + + @Output() openDeleteConfirmModal: EventEmitter = new EventEmitter(); + @Output() showErrorMsg: EventEmitter = new EventEmitter(); + @Output() showSuccessMsg: EventEmitter = new EventEmitter(); + @Output() solrIndicesChange: EventEmitter = new EventEmitter(); + + constructor( + private solrService: SolrService, + ) { + } + + getSolrIndices() { + return this.solrService.solrIndices + } + + ngOnInit() { + console.log('In ChrisRulesCollectionListComponent :: ngOnInit'); + } + + ngOnChanges(changes: SimpleChanges): void { + console.log('In ChrisRulesCollectionListComponent :: ngOnChanges'); + } + + deleteChrisRulesCollection(id: string, event: Event) { + event.stopPropagation(); + const deleteCallback = () => + this.solrService + .deleteSolrIndex(id) + .then(() => this.solrService.listAllSolrIndices()) + .then(() => this.solrIndicesChange.emit(id)) + .then(() => this.solrService.emitRulesCollectionChangeEvent("")) + .then(() => this.showSuccessMsg.emit("Chris Rule collection successfully deleted.")) + .catch(error => { + // unpack and emit error message + var errorMsg = 'Unknown error' + if( 'error' in error ) { + errorMsg = error.error.message + } + this.showErrorMsg.emit(errorMsg) + }); + + this.openDeleteConfirmModal.emit({ deleteCallback }); + } +} diff --git a/frontend/src/app/components/chris/chris-rules-collection-list/index.ts b/frontend/src/app/components/chris/chris-rules-collection-list/index.ts new file mode 100644 index 00000000..7e92b45b --- /dev/null +++ b/frontend/src/app/components/chris/chris-rules-collection-list/index.ts @@ -0,0 +1 @@ +export * from './chris-rules-collection-list.component'; diff --git a/frontend/src/app/components/chris/chris-suggested-fields/chris-suggested-fields-create/chris-suggested-fields-create.component.html b/frontend/src/app/components/chris/chris-suggested-fields/chris-suggested-fields-create/chris-suggested-fields-create.component.html new file mode 100644 index 00000000..8cb76657 --- /dev/null +++ b/frontend/src/app/components/chris/chris-suggested-fields/chris-suggested-fields-create/chris-suggested-fields-create.component.html @@ -0,0 +1,25 @@ +
+
+
Add Suggested Chris Field
+
Add a new Suggested Chris Field to the rules collection {{solrIndex.description}}
+ +
+ +
+ +
+
+ +
+
+ +
+
+
+
diff --git a/frontend/src/app/components/chris/chris-suggested-fields/chris-suggested-fields-create/chris-suggested-fields-create.component.ts b/frontend/src/app/components/chris/chris-suggested-fields/chris-suggested-fields-create/chris-suggested-fields-create.component.ts new file mode 100644 index 00000000..70d95e4c --- /dev/null +++ b/frontend/src/app/components/chris/chris-suggested-fields/chris-suggested-fields-create/chris-suggested-fields-create.component.ts @@ -0,0 +1,62 @@ +import { + Component, + Input, + Output, + EventEmitter, + OnChanges, + OnInit, + SimpleChanges +} from '@angular/core'; + +import { SolrIndex, SuggestedSolrField } from '../../../../models'; +import { + SolrService, + ModalService +} from '../../../../services'; + +@Component({ + selector: 'app-smui-chris-suggested-fields-create', + templateUrl: './chris-suggested-fields-create.component.html' +}) +export class ChrisSuggestedFieldsCreateComponent implements OnInit, OnChanges { + + @Input() solrIndex: SolrIndex; + @Output() showErrorMsg: EventEmitter = new EventEmitter(); + @Output() showSuccessMsg: EventEmitter = new EventEmitter(); + @Output() chrisSuggestedFieldsChange: EventEmitter = new EventEmitter(); + + name: string; + suggestedFields: SuggestedSolrField[] = []; + + constructor( + private solrService: SolrService, + ) { + + } + ngOnInit() { + console.log('In ChrisSuggestedFieldsCreateComponent :: ngOnInit'); + } + + ngOnChanges(changes: SimpleChanges): void { + console.log('In ChrisSuggestedFieldsCreateComponent :: ngOnChanges'); + } + + + clearForm() { + this.name = ''; + } + + createChrisSuggestedField( event: Event){ + console.log('In ChrisSuggestedFieldsCreateComponent :: createSuggestedField'); + if (this.name) { + this.solrService + .createSuggestedField(this.solrIndex.id, this.name) + .then(() => this.showSuccessMsg.emit("Created new Chris Suggested Field " + this.name)) + .then(() => this.chrisSuggestedFieldsChange.emit()) + .then(() => this.clearForm()) + .catch(error => this.showErrorMsg.emit(error)); + } + } + + +} diff --git a/frontend/src/app/components/chris/chris-suggested-fields/chris-suggested-fields-list/chris-suggested-fields-list.component.html b/frontend/src/app/components/chris/chris-suggested-fields/chris-suggested-fields-list/chris-suggested-fields-list.component.html new file mode 100644 index 00000000..77aa7058 --- /dev/null +++ b/frontend/src/app/components/chris/chris-suggested-fields/chris-suggested-fields-list/chris-suggested-fields-list.component.html @@ -0,0 +1,20 @@ +
+
+
Chris Suggested Fields
+
Available Chris suggested fields in SMUI
+ +
    +
  • + {{ chrisSuggestedField.name }} - Key: {{ chrisSuggestedField.id }} + + +
  • +
+
+
diff --git a/frontend/src/app/components/chris/chris-suggested-fields/chris-suggested-fields-list/chris-suggested-fields-list.component.ts b/frontend/src/app/components/chris/chris-suggested-fields/chris-suggested-fields-list/chris-suggested-fields-list.component.ts new file mode 100644 index 00000000..ff8458d4 --- /dev/null +++ b/frontend/src/app/components/chris/chris-suggested-fields/chris-suggested-fields-list/chris-suggested-fields-list.component.ts @@ -0,0 +1,68 @@ +import { + Component, + Input, + Output, + EventEmitter, + OnChanges, + OnInit, + SimpleChanges +} from '@angular/core'; + +import { SolrIndex, SuggestedSolrField } from '../../../../models'; +import { + SolrService +} from '../../../../services'; + +@Component({ + selector: 'app-smui-chris-suggested-fields-list', + templateUrl: './chris-suggested-fields-list.component.html' +}) +export class ChrisSuggestedFieldsListComponent implements OnInit, OnChanges { + + @Input() solrIndex: SolrIndex; + @Input() chrisSuggestedFields: Array; + + @Output() openDeleteConfirmModal: EventEmitter = new EventEmitter(); + @Output() showErrorMsg: EventEmitter = new EventEmitter(); + @Output() solrIndicesChange: EventEmitter = new EventEmitter(); + @Output() chrisSuggestedFieldsChange: EventEmitter = new EventEmitter(); + + constructor( + private solrService: SolrService, + ) { + + } + + ngOnInit() { + console.log('In ChrisSuggestedFieldsListComponent :: ngOnInit'); + + } + + ngOnChanges(changes: SimpleChanges): void { + console.log('In ChrisSuggestedFieldsListComponent :: ngOnChanges'); + } + + + lookupChrisSuggestedFields() { + console.log('In ChrisSuggestedFieldsListComponent :: lookupSuggestedFields'); + this.solrService.getSuggestedFields(this.solrIndex.id) + .then(chrisSuggestedFields => { + this.chrisSuggestedFields = chrisSuggestedFields; + }) + .catch(error => this.showErrorMsg.emit(error)); + + } + + deleteChrisSuggestedField(suggestedFieldId: string, event: Event) { + event.stopPropagation(); + const deleteCallback = () => + this.solrService + .deleteSuggestedField(this.solrIndex.id, suggestedFieldId) + .then(() => this.lookupChrisSuggestedFields()) + + .catch(error => this.showErrorMsg.emit(error)); + + + this.openDeleteConfirmModal.emit({ deleteCallback }); + } +} diff --git a/frontend/src/app/components/chris/chris-suggested-fields/chris-suggested-fields.component.html b/frontend/src/app/components/chris/chris-suggested-fields/chris-suggested-fields.component.html new file mode 100644 index 00000000..056500cc --- /dev/null +++ b/frontend/src/app/components/chris/chris-suggested-fields/chris-suggested-fields.component.html @@ -0,0 +1,35 @@ + + +

Suggested Fields for {{solrIndex.description}}

+ + + + + + + + +

Are you sure you want to delete the item?

+
+ + diff --git a/frontend/src/app/components/chris/chris-suggested-fields/chris-suggested-fields.component.ts b/frontend/src/app/components/chris/chris-suggested-fields/chris-suggested-fields.component.ts new file mode 100644 index 00000000..7c3994f7 --- /dev/null +++ b/frontend/src/app/components/chris/chris-suggested-fields/chris-suggested-fields.component.ts @@ -0,0 +1,100 @@ +import {Component, OnInit, Input, Output, EventEmitter, SimpleChanges} from '@angular/core'; +import { ActivatedRoute, Params, ParamMap } from '@angular/router'; +//import 'rxjs/add/operator/switchMap'; + +import { switchMap } from 'rxjs/operators'; + +import { ToasterService } from 'angular2-toaster'; + +import {SolrIndex, SuggestedSolrField} from '../../../models'; +import { + SolrService, + ModalService +} from '../../../services'; + + +@Component({ + selector: 'app-smui-chris-suggested-fields', + templateUrl: './chris-suggested-fields.component.html' +}) +export class ChrisSuggestedFieldsComponent implements OnInit { + + //@Input() solrIndex: SolrIndex; + //@Output() showErrorMsg: EventEmitter = new EventEmitter(); + chrisSuggestedFields: Array; + + constructor( + private route: ActivatedRoute, + private modalService: ModalService, + private solrService: SolrService, + private toasterService: ToasterService, + ) { + + } + + solrIndex: SolrIndex; + + + ngOnInit() { + console.log('In ChrisSuggestedFieldsComponent :: ngOnInit'); + + + this.route.paramMap.subscribe((params: ParamMap) => { + console.log(params); + console.log(params.get("solrIndexId")!.toLowerCase()); + //console.log(this.solrService.getSolrIndex(params.get("id"))) + this.solrService.getSolrIndex(params.get("solrIndexId")!.toLowerCase()) + .then(solrIndex => + this.solrIndex = solrIndex + ) + .then(() => this.lookupChrisSuggestedFields()) + .catch(error => this.showErrorMsg(error)); + + + }) + + } + + ngOnChanges(changes: SimpleChanges): void { + console.log('In ChrisSuggestedFieldsComponent :: ngOnChanges'); + this.lookupChrisSuggestedFields(); + } + + + lookupChrisSuggestedFields() { + console.log('In ChrisSuggestedFieldsListComponent :: lookupChrisSuggestedFields'); + console.log("Solr id?" + this.solrIndex.id) + this.solrService.getSuggestedFields(this.solrIndex.id) + .then(suggestedFields => { + this.chrisSuggestedFields = suggestedFields; + }) + .catch(error => this.showErrorMsg(error)); + + } + + public showSuccessMsg(msgText: string) { + this.toasterService.pop('success', '', msgText); + } + + public showErrorMsg(msgText: string) { + this.toasterService.pop('error', '', msgText); + } + + public chrisSuggestedFieldsChange( id: string){ + console.log("ChrisSuggestedFieldsComponent::chrisSuggestedFieldsChange") + this.lookupChrisSuggestedFields(); + + } + + // @ts-ignore + public openDeleteConfirmModal({ deleteCallback }) { + const deferred = this.modalService.open('confirm-delete'); + deferred.promise.then((isOk: boolean) => { + if (isOk) { deleteCallback(); } + this.modalService.close('confirm-delete'); + }); + } + + + +} diff --git a/frontend/src/app/components/chris/chris-suggested-fields/index.ts b/frontend/src/app/components/chris/chris-suggested-fields/index.ts new file mode 100644 index 00000000..ac9ee12b --- /dev/null +++ b/frontend/src/app/components/chris/chris-suggested-fields/index.ts @@ -0,0 +1,3 @@ +// export * from './chris-suggested-fields.component'; +// export * from './chris-suggested-fields-create/chris-suggested-fields-create.component'; +// export * from './chris-suggested-fields-list/chris-suggested-fields-list.component'; diff --git a/frontend/src/app/components/chris/chris.component.html b/frontend/src/app/components/chris/chris.component.html new file mode 100644 index 00000000..09b50ad9 --- /dev/null +++ b/frontend/src/app/components/chris/chris.component.html @@ -0,0 +1,24 @@ + + (showSuccessMsg)="showSuccessMsg($event)" + (showErrorMsg)="showErrorMsg($event)" + (solrIndicesChange)="solrIndicesChange($event)" + + + + + + + + + + + +

Are you sure you want to delete the item?

+
+ +Hi there. diff --git a/frontend/src/app/components/chris/chris.component.ts b/frontend/src/app/components/chris/chris.component.ts new file mode 100644 index 00000000..ebe4b230 --- /dev/null +++ b/frontend/src/app/components/chris/chris.component.ts @@ -0,0 +1,56 @@ +import { Component, OnInit, Input } from '@angular/core'; + +// import { ToasterService } from 'angular2-toaster'; +// +// import { SolrIndex } from '../../models'; + +// import { +// SolrService, +// ModalService +// } from '../../services'; + +@Component({ + selector: 'app-smui-chris', + templateUrl: './chris.component.html' +}) +export class ChrisComponent implements OnInit { + + constructor( + // private modalService: ModalService, + // private toasterService: ToasterService, + // private solrService: SolrService + ) { + + } + + //solrIndices: SolrIndex[]; + + ngOnInit() { + console.log('In ChrisComponent :: ngOnInit'); + //this.solrIndices = this.solrService.solrIndices; + } + + public showSuccessMsg(msgText: string) { + //this.toasterService.pop('success', '', msgText); + } + + public showErrorMsg(msgText: string) { + //this.toasterService.pop('error', '', msgText); + } + + + // @ts-ignore + public openDeleteConfirmModal({ deleteCallback }) { + //const deferred = this.modalService.open('confirm-delete'); + // deferred.promise.then((isOk: boolean) => { + // if (isOk) { deleteCallback(); } + // this.modalService.close('confirm-delete'); + // }); + } + + public solrIndicesChange(id: string){ + console.log("ChrisComponent :: solrIndicesChange :: id = " + id) + //this.solrIndices = this.solrService.solrIndices; + } + +} diff --git a/frontend/src/app/components/chris/index.ts b/frontend/src/app/components/chris/index.ts new file mode 100644 index 00000000..9b13bfaa --- /dev/null +++ b/frontend/src/app/components/chris/index.ts @@ -0,0 +1,3 @@ +export * from './chris.component'; +//export * from './chris-rules-collection-list/chris-rules-collection-list.component'; +//export * from './chris-rules-collection-create/chris-rules-collection-create.component'; diff --git a/frontend/src/app/components/header-nav/header-nav.component.html b/frontend/src/app/components/header-nav/header-nav.component.html index 5b0ecaaf..99974860 100644 --- a/frontend/src/app/components/header-nav/header-nav.component.html +++ b/frontend/src/app/components/header-nav/header-nav.component.html @@ -63,6 +63,14 @@ >Admin +
  • diff --git a/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.ts b/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.ts index ab9a1769..0af662ef 100644 --- a/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.ts +++ b/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.ts @@ -27,8 +27,7 @@ export class ChrisRulesCollectionCreateComponent implements OnInit, OnChanges { @Output() solrIndicesChange: EventEmitter = new EventEmitter(); solrIndices: SolrIndex[]; - name: string; - description: string; + thingName: string; constructor( private solrService: SolrService, @@ -50,22 +49,24 @@ export class ChrisRulesCollectionCreateComponent implements OnInit, OnChanges { } clearForm() { - this.name = ''; - this.description = ''; + this.thingName = ''; } - createChrisRulesCollection( event: Event){ - console.log('In ChrisRulesCollectionCreateComponent :: createChrisRulesCollection'); - if (this.name && this.description) { - this.solrService - .createSolrIndex(this.name, this.description) - .then(() => this.solrService.listAllSolrIndices()) - .then(() => this.solrIndicesChange.emit()) - .then(() => this.showSuccessMsg.emit("Created new Chris Rules Collection " + this.description)) - .then(() => this.solrService.emitRulesCollectionChangeEvent("")) - .then(() => this.clearForm()) - .catch(error => this.showErrorMsg.emit(error)); - } + doTheThing( event: Event){ + console.log("doTheThing() , thingName: " + this.thingName); + //console.log('In ChrisRulesCollectidonCreateComponent :: createChrisRulesCollection'); + this.solrService.putSomething2(this.thingName).then(() => console.log("done")); + // + // if (this.name && this.description) { + // this.solrService + // .createSolrIndex(this.name, this.description) + // .then(() => this.solrService.listAllSolrIndices()) + // .then(() => this.solrIndicesChange.emit()) + // .then(() => this.showSuccessMsg.emit("Created new Chris Rules Collection " + this.description)) + // .then(() => this.solrService.emitRulesCollectionChangeEvent("")) + // .then(() => this.clearForm()) + // .catch(error => this.showErrorMsg.emit(error)); + // } } diff --git a/frontend/src/app/components/chris/chris.component.html b/frontend/src/app/components/chris/chris.component.html index 09b50ad9..0b6d2a9a 100644 --- a/frontend/src/app/components/chris/chris.component.html +++ b/frontend/src/app/components/chris/chris.component.html @@ -12,13 +12,11 @@ - -

    Are you sure you want to delete the item?

    -
    - -Hi there. + + + + + + + + diff --git a/frontend/src/app/services/solr.service.ts b/frontend/src/app/services/solr.service.ts index d4a1e30d..15dd0533 100644 --- a/frontend/src/app/services/solr.service.ts +++ b/frontend/src/app/services/solr.service.ts @@ -158,4 +158,12 @@ export class SolrService { .toPromise(); } + putSomething2(thingName: string) { + const headers = { headers: this.jsonHeader }; + const body = JSON.stringify( { thingName: thingName }); + return this.http + .put(`${this.baseUrl}/put-something`, body, httpOptions) + .toPromise(); + } + } From 2d573295b752c66dc098836f84a39ca7f33f8449 Mon Sep 17 00:00:00 2001 From: Chris Morley Date: Fri, 27 May 2022 10:03:43 -0400 Subject: [PATCH 07/25] testing --- app/models/SearchManagementRepository.scala | 17 ++++++++++++++--- app/models/export/Exporter.scala | 12 ++++++++++++ ...chris-rules-collection-create.component.html | 17 +++++++++++++++++ .../chris-rules-collection-create.component.ts | 5 +++++ 4 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 app/models/export/Exporter.scala diff --git a/app/models/SearchManagementRepository.scala b/app/models/SearchManagementRepository.scala index 324d00ba..326c5175 100644 --- a/app/models/SearchManagementRepository.scala +++ b/app/models/SearchManagementRepository.scala @@ -7,7 +7,8 @@ import javax.inject.Inject import play.api.db.DBApi import anorm._ import models.FeatureToggleModel.FeatureToggleService -import models.export.{Something} +import models.`export`.Exporter +import models.export.Something import models.input.{InputTag, InputTagId, PredefinedTag, SearchInput, SearchInputId, SearchInputWithRules, TagInputAssociation} import models.spellings.{CanonicalSpelling, CanonicalSpellingId, CanonicalSpellingWithAlternatives} import models.eventhistory.{ActivityLog, ActivityLogEntry, InputEvent} @@ -319,9 +320,11 @@ class SearchManagementRepository @Inject()(dbapi: DBApi, toggleService: FeatureT def putSomething(thingName: String): Boolean = db.withConnection { implicit connection => { logger.debug("smr putSomething:0 " + thingName) - SQL("insert into something (id, value0, last_update) values (id, {value0}, {last_update})") + val uuid : String = UUID.randomUUID().toString + logger.debug("uuid: " + uuid) + SQL("insert into something (id, value0, last_update) values ({id}, {value0}, {last_update})") .on( - 'id -> UUID.randomUUID().toString, + 'id -> uuid, 'value0 -> thingName, 'last_update -> new Date() ) @@ -329,4 +332,12 @@ class SearchManagementRepository @Inject()(dbapi: DBApi, toggleService: FeatureT } } + def getAllSomethings(): Seq[Something] = db.withConnection { + implicit connection => { + val exporter : Exporter = new Exporter() + val somethings = exporter.getAllSomethings() + somethings + } + } + } diff --git a/app/models/export/Exporter.scala b/app/models/export/Exporter.scala new file mode 100644 index 00000000..a50df0fa --- /dev/null +++ b/app/models/export/Exporter.scala @@ -0,0 +1,12 @@ +package models.`export` + +class Exporter { + + def getAllSomethings(): Seq[Something] = { + val something1 : Something = new Something("something1") + val something2 : Something = new Something("something2") + val x : Seq[Something] = Seq(something1,something2) + x + } + +} diff --git a/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.html b/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.html index e1f56694..fa57b393 100644 --- a/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.html +++ b/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.html @@ -22,5 +22,22 @@
    Add a new thing.
    + + + + + +
    + +
    +
    +
    diff --git a/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.ts b/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.ts index 0af662ef..e31e4760 100644 --- a/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.ts +++ b/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.ts @@ -69,5 +69,10 @@ export class ChrisRulesCollectionCreateComponent implements OnInit, OnChanges { // } } + getSomethings(event: Event) { + this.solrService.putSomething2("something3").then(() => console.log("done")); + this.solrService.putSomething2("something4").then(() => console.log("done")); + console.log("getSomethings()"); + } } From c1156922bec2ca038944bf45bba09612ffebb691 Mon Sep 17 00:00:00 2001 From: Chris Morley Date: Fri, 27 May 2022 13:07:13 -0400 Subject: [PATCH 08/25] save / get rows --- app/controllers/ApiController.scala | 8 ++ app/models/SearchManagementRepository.scala | 40 +++++--- app/models/export/Exporter.scala | 33 +++++-- app/models/export/Something.scala | 91 ++++++++++++++++--- app/models/export/Somethings.scala | 48 ++++++++++ app/models/rules/SynonymRule.scala | 2 +- conf/routes | 1 + ...ris-rules-collection-create.component.html | 18 +++- ...chris-rules-collection-create.component.ts | 15 ++- frontend/src/app/services/solr.service.ts | 8 ++ 10 files changed, 229 insertions(+), 35 deletions(-) create mode 100644 app/models/export/Somethings.scala diff --git a/app/controllers/ApiController.scala b/app/controllers/ApiController.scala index 32de76f0..8e182513 100644 --- a/app/controllers/ApiController.scala +++ b/app/controllers/ApiController.scala @@ -630,5 +630,13 @@ class ApiController @Inject()(authActionFactory: AuthActionFactory, } } + def getSomethings() = authActionFactory.getAuthenticatedAction(Action).async { + Future { + logger.debug("In ApiController:getSomethings") + Ok(Json.toJson(searchManagementRepository.getAllSomethingsForJs())) + //Ok(Json.toJson( + } + } + } diff --git a/app/models/SearchManagementRepository.scala b/app/models/SearchManagementRepository.scala index 326c5175..3ddd101c 100644 --- a/app/models/SearchManagementRepository.scala +++ b/app/models/SearchManagementRepository.scala @@ -1,19 +1,24 @@ //CJM 9 package models +import anorm.SqlParser.get + import java.time.LocalDateTime import java.util.{Date, UUID} import javax.inject.Inject import play.api.db.DBApi import anorm._ import models.FeatureToggleModel.FeatureToggleService -import models.`export`.Exporter -import models.export.Something +import models.SolrIndex.TABLE_NAME +import models.`export`.SomethingRow +import models.export.{Exporter, Something, SomethingId} import models.input.{InputTag, InputTagId, PredefinedTag, SearchInput, SearchInputId, SearchInputWithRules, TagInputAssociation} import models.spellings.{CanonicalSpelling, CanonicalSpellingId, CanonicalSpellingWithAlternatives} import models.eventhistory.{ActivityLog, ActivityLogEntry, InputEvent} import models.reports.{ActivityReport, DeploymentLog, RulesReport} +import models.rules.SynonymRuleId import play.api.Logging +import play.api.libs.json.JsValue // TODO Make `userInfo` mandatory (for all input/spelling and deploymentLog CRUD operations), when removing unauthorized access. @javax.inject.Singleton @@ -311,32 +316,45 @@ class SearchManagementRepository @Inject()(dbapi: DBApi, toggleService: FeatureT } } - def getSomething(solrIndexId: String): Something = db.withConnection { + def getSomething(id: String): Something = db.withConnection { implicit connection => { - val something = new Something(solrIndexId) + val something = new Something(SomethingId(), "", LocalDateTime.now()) something } } def putSomething(thingName: String): Boolean = db.withConnection { implicit connection => { logger.debug("smr putSomething:0 " + thingName) - val uuid : String = UUID.randomUUID().toString - logger.debug("uuid: " + uuid) SQL("insert into something (id, value0, last_update) values ({id}, {value0}, {last_update})") .on( - 'id -> uuid, + 'id -> SomethingId(), 'value0 -> thingName, - 'last_update -> new Date() + 'last_update -> LocalDateTime.now() ) .execute() } } - def getAllSomethings(): Seq[Something] = db.withConnection { + def getSomethingsFromDatabase(): IndexedSeq[Something] = db.withConnection { + implicit connection => { + logger.debug("In SearchManagementRepository:getSomethingsFromDatabase():1") + val x : List[Something] = SQL(s"select id, value0, last_update from something") + .as(SomethingRow.sqlParser.*) + logger.debug("In SearchManagementRepository:getSomethingsFromDatabase():2") + x.toIndexedSeq + } + } + + def getAllSomethingsForJs(): JsValue = db.withConnection { implicit connection => { + logger.debug("In SearchManagementRepository:getAllSomethingsForJs():1") val exporter : Exporter = new Exporter() - val somethings = exporter.getAllSomethings() - somethings + logger.debug("In SearchManagementRepository:getAllSomethingsForJs():2") + val somethings1 : IndexedSeq[Something] = getSomethingsFromDatabase() + logger.debug("In SearchManagementRepository:getAllSomethingsForJs():3... length:" + somethings1.size) + val somethings2 = exporter.getAllSomethingsForJs(somethings1) + logger.debug("In SearchManagementRepository:getAllSomethingsForJs():4") + somethings2 } } diff --git a/app/models/export/Exporter.scala b/app/models/export/Exporter.scala index a50df0fa..5dacff06 100644 --- a/app/models/export/Exporter.scala +++ b/app/models/export/Exporter.scala @@ -1,12 +1,29 @@ package models.`export` -class Exporter { - - def getAllSomethings(): Seq[Something] = { - val something1 : Something = new Something("something1") - val something2 : Something = new Something("something2") - val x : Seq[Something] = Seq(something1,something2) - x - } +import play.api.libs.json.JsValue +import play.api.Logging + +import java.time.LocalDateTime + +class Exporter extends Logging { + + var somethings1: IndexedSeq[Something] = IndexedSeq( + new Something(SomethingId(), "something1", LocalDateTime.now()), + new Something(SomethingId(), "something2", LocalDateTime.now()) + ) + + def getAllSomethingsForJs(): JsValue = { + val source : IndexedSeq[Something] = this.somethings1 + val converter : Somethings = new Somethings() + val x : JsValue = converter.asIndexedSeqForJs(source) + x + } + + def getAllSomethingsForJs(somethingsInput : IndexedSeq[Something]): JsValue = { + logger.debug("In Exporter:getAllSomethingsForJs():1") + val converter : Somethings = new Somethings() + val x : JsValue = converter.asIndexedSeqForJs(somethingsInput) + x + } } diff --git a/app/models/export/Something.scala b/app/models/export/Something.scala index 8edbcb56..1e34203b 100644 --- a/app/models/export/Something.scala +++ b/app/models/export/Something.scala @@ -1,7 +1,57 @@ package models.`export` +import anorm.SqlParser.get +import anorm.{NamedParameter, RowParser, ~} +import models.`export`.SomethingRow.{id, last_update, myJavascriptObject, value0} +import models.input.SearchInputId +import models.rules.Rule.{ID, LAST_UPDATE, SEARCH_INPUT_ID, STATUS} +import models.rules.{RuleWithTerm, SynonymRule, SynonymRuleId} +import models.{Id, IdObject} import play.api.libs.json.{JsArray, JsNull, JsNumber, JsObject, JsString, JsValue, Json, Writes} +import java.time.LocalDateTime +import java.util.UUID + +case class Something(id: SomethingId = SomethingId(), + value0: String, + last_update: LocalDateTime) { +// override def toNamedParameters(searchInputId: SearchInputId): Seq[NamedParameter] = { +// super.toNamedParameters(searchInputId) ++ Seq[NamedParameter]( +// .TYPE -> synonymType +// ) +// } + def toNamedParameters(id: SomethingId): Seq[NamedParameter] = Seq( + ID -> id.id, + value0 -> value0, + LAST_UPDATE -> LocalDateTime.now() + ) + + implicit val writer: Writes[String] = new Writes[(String)] { + def writes(t: (String)): JsValue = { + Json.obj( + "value0" -> myJavascriptObject.value0, + "value1" -> myJavascriptObject.value1, + "value2" -> myJavascriptObject.value2, + "value3" -> myJavascriptObject.value3) + } + } + + def getJsValue(): JsValue = { + val x : JsObject = JsObject( + Seq ( + "id" -> JsString(id.toString), + "value0" -> JsString(value0), + "last_update" -> JsString(last_update.toString) + ) + ) + x + } + +} + +class SomethingId(id: String) extends Id(id) +object SomethingId extends IdObject[SomethingId](new SomethingId(_)) + case class MyJsObject( value0: JsValue, value1: JsValue, @@ -9,11 +59,22 @@ case class MyJsObject( value3: JsValue ) -class Something(solrIndexId: String) { +object SomethingRow extends Something(id=SomethingId(), value0="", last_update=LocalDateTime.now()) { + + val TABLE_NAME = "something" + val TYPE = "something" + + val sqlParser: RowParser[Something] = { + get[SomethingId] (s"$TABLE_NAME.id") ~ + get[String](s"$TABLE_NAME.value0") ~ + get[LocalDateTime](s"$TABLE_NAME.last_update") map { case id ~ value0 ~ last_update => + Something(id, value0, last_update) + } + } val myJavascriptObject: MyJsObject = MyJsObject( - value0 = new JsString("solrIndexId = " + solrIndexId), + value0 = new JsString("id = " + id), value1 = JsObject(Seq("simpleObject" -> JsString("simpleStringValue"))), value2 = JsObject( Seq( @@ -29,14 +90,22 @@ class Something(solrIndexId: String) { ) ) - implicit val writer = new Writes[(String)] { - def writes(t: (String)): JsValue = { - Json.obj( - "value0" -> myJavascriptObject.value0, - "value1" -> myJavascriptObject.value1, - "value2" -> myJavascriptObject.value2, - "value3" -> myJavascriptObject.value3) - } - } +// def getAsJsonRow(): JsObject = { +// value1 = JsObject(Seq("simpleObject" -> JsString("simpleStringValue"))), +// value2 = JsObject( +// Seq( +// "aString" -> JsString("simpleString"), +// "aNumber" -> JsNumber(4.3), +// "aNull" -> JsNull +// ) +// ), +// value3 = JsArray( +// IndexedSeq( +// new JsString("first value of array"), +// new JsString("second value of array")) +// ) +// ) +// } + } diff --git a/app/models/export/Somethings.scala b/app/models/export/Somethings.scala new file mode 100644 index 00000000..247ea09e --- /dev/null +++ b/app/models/export/Somethings.scala @@ -0,0 +1,48 @@ +package models.`export` + +import play.api.libs.json.{JsArray, JsNull, JsNumber, JsObject, JsString, JsValue, Json, Writes} + +//case class MyJsObject( +// somethings: JsValue, +// ) + +class Somethings() { + +// val myJavascriptObject: MyJsObject = +// MyJsObject( +// somethings = JsArray( +// IndexedSeq( +// new JsString("first value of array"), +// new JsString("second value of array")) +// ) +// ) + +// implicit val writer = new Writes[(String)] { +// def writes(t: (String)): JsValue = { +// Json.obj( +// "somethings" -> myJavascriptObject.somethings +// ) +// } +// } + + def asIndexedSeqForJs(indexedSeqSource : IndexedSeq[Something]): JsValue = { + val exporter : Exporter = new Exporter() + //var indexedSeqSource : IndexedSeq[Something] = exporter.getAllSomethings() + var target1: List[String] = List[String]() + println("#In Somethings.asIndexedSeqForJs : size of target1: " + target1.size) + target1 = target1 :+ "hi" + println("->In Somethings.asIndexedSeqForJs : size of target1: " + target1.size) + + var target: IndexedSeq[JsValue] = IndexedSeq[JsValue]() + target :+ JsString("hi") + println("->In Somethings.asIndexedSeqForJs : size of target: " + target.size) + for((element,index) <- indexedSeqSource.view.zipWithIndex) { + println("In Somethings.asIndexedSeqForJs : String #" + index + " is " + element.getJsValue()) //CJM DELETE + target = target :+ element.getJsValue() + } + println("%In Somethings.asIndexedSeqForJs : size of target: " + target.size) + val x : JsValue = JsObject(Seq("somethings-asIndexedSeqForJs-was-here" -> JsArray(target.toIndexedSeq))) + x + } + +} diff --git a/app/models/rules/SynonymRule.scala b/app/models/rules/SynonymRule.scala index c101e9b0..0a16131a 100644 --- a/app/models/rules/SynonymRule.scala +++ b/app/models/rules/SynonymRule.scala @@ -1,9 +1,9 @@ package models.rules import java.sql.Connection - import anorm.SqlParser.get import anorm._ +import models.`export`.{Something, SomethingId} import models.input.SearchInputId import models.{Id, IdObject, Status} import play.api.libs.json.{Json, OFormat} diff --git a/conf/routes b/conf/routes index b6238f8a..58c3a5e0 100644 --- a/conf/routes +++ b/conf/routes @@ -39,6 +39,7 @@ GET /api/v1/report/activity-report/:solrIndexId controllers.ApiC GET /api/v1/version/latest-info controllers.ApiController.getLatestVersionInfo() GET /api/v1/solr-index/:solrIndexId/something controllers.ApiController.getSomething(solrIndexId: String) PUT /api/v1/put-something controllers.ApiController.putSomething +GET /api/v1/get-somethings controllers.ApiController.getSomethings # Map static resources from the /public folder to the /assets URL path GET /*file controllers.FrontendController.assetOrDefault(file) diff --git a/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.html b/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.html index fa57b393..4ed4d5cd 100644 --- a/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.html +++ b/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.html @@ -35,9 +35,23 @@
    Add a new thing.
    id="getBtn" type="button" class="btn btn-primary" - (click)="getSomethings($event)" + (click)="putRows($event)" > - Test + Put Rows + + + + + +
    +
    +
    diff --git a/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.ts b/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.ts index e31e4760..6cf0326f 100644 --- a/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.ts +++ b/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.ts @@ -69,10 +69,21 @@ export class ChrisRulesCollectionCreateComponent implements OnInit, OnChanges { // } } - getSomethings(event: Event) { + putRows(event: Event) { this.solrService.putSomething2("something3").then(() => console.log("done")); this.solrService.putSomething2("something4").then(() => console.log("done")); - console.log("getSomethings()"); + console.log("putRows()"); + } + + getRows(event: Event) { + console.log("getRows()"); + //this.solrService.putSomething2("something3").then(() => console.log("done")); + //this.solrService.putSomething2("something4").then(() => console.log("done")); + this.solrService.getSomethings().then( + result => console.log(result) + ) + + } } diff --git a/frontend/src/app/services/solr.service.ts b/frontend/src/app/services/solr.service.ts index 15dd0533..af5e46e8 100644 --- a/frontend/src/app/services/solr.service.ts +++ b/frontend/src/app/services/solr.service.ts @@ -166,4 +166,12 @@ export class SolrService { .toPromise(); } + getSomethings() { + const headers = { headers: this.jsonHeader }; + const body = {};// JSON.stringify( { thingName: thingName }); + return this.http + .get(`${this.baseUrl}/get-somethings`, body) + .toPromise(); + } + } From 13935ebf334f12feb7fe204d6100207c6ab18e4f Mon Sep 17 00:00:00 2001 From: Chris Morley Date: Fri, 27 May 2022 15:11:55 -0400 Subject: [PATCH 09/25] download json from db, test --- ...ris-rules-collection-create.component.html | 27 +++++++++---- ...chris-rules-collection-create.component.ts | 40 +++++++++++++++---- frontend/src/app/services/solr.service.ts | 2 +- 3 files changed, 53 insertions(+), 16 deletions(-) diff --git a/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.html b/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.html index 4ed4d5cd..0a0609d7 100644 --- a/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.html +++ b/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.html @@ -1,12 +1,12 @@
    -
    Add a Thing
    -
    Add a new thing.
    +
    Add a Value
    +
    Add a new value.
    - +
    - +
    @@ -16,9 +16,9 @@
    Add a new thing.
    id="doTheThingBtn" type="button" class="btn btn-primary" - (click)="doTheThing($event)" + (click)="addOneValue($event)" > - Do The Thing + Add Value
    @@ -32,7 +32,7 @@
    Add a new thing.
  • + +
    +
    + +
    +
    diff --git a/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.ts b/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.ts index 6cf0326f..076e1926 100644 --- a/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.ts +++ b/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.ts @@ -27,7 +27,8 @@ export class ChrisRulesCollectionCreateComponent implements OnInit, OnChanges { @Output() solrIndicesChange: EventEmitter = new EventEmitter(); solrIndices: SolrIndex[]; - thingName: string; + valueName: string; + resultString: string; constructor( private solrService: SolrService, @@ -49,13 +50,13 @@ export class ChrisRulesCollectionCreateComponent implements OnInit, OnChanges { } clearForm() { - this.thingName = ''; + this.valueName = ''; } - doTheThing( event: Event){ - console.log("doTheThing() , thingName: " + this.thingName); + addOneValue( event: Event){ + console.log("addOneValue() , thingName: " + this.valueName); //console.log('In ChrisRulesCollectidonCreateComponent :: createChrisRulesCollection'); - this.solrService.putSomething2(this.thingName).then(() => console.log("done")); + this.solrService.putSomething2(this.valueName).then(() => console.log("done")); // // if (this.name && this.description) { // this.solrService @@ -70,8 +71,9 @@ export class ChrisRulesCollectionCreateComponent implements OnInit, OnChanges { } putRows(event: Event) { - this.solrService.putSomething2("something3").then(() => console.log("done")); - this.solrService.putSomething2("something4").then(() => console.log("done")); + this.solrService.putSomething2("test row 1").then(() => console.log("added test row 1")); + this.solrService.putSomething2("test row 2").then(() => console.log("added test row 2")); + this.solrService.putSomething2("test row 3").then(() => console.log("added test row 3")); console.log("putRows()"); } @@ -80,10 +82,32 @@ export class ChrisRulesCollectionCreateComponent implements OnInit, OnChanges { //this.solrService.putSomething2("something3").then(() => console.log("done")); //this.solrService.putSomething2("something4").then(() => console.log("done")); this.solrService.getSomethings().then( - result => console.log(result) + result => { + console.log(result) + } ) + } + download(event: Event) { + console.log("download()"); + this.solrService.getSomethings().then( + result => { + var str = JSON.stringify(result); + this.downloadStringAsFile( + "file.json.txt", + str); + } + ); + } + downloadStringAsFile(filename: string, text: string) { + var element = document.createElement('a'); + element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text)); + element.setAttribute('download', filename); + element.style.display = 'none'; + document.body.appendChild(element); + element.click(); + document.body.removeChild(element); } } diff --git a/frontend/src/app/services/solr.service.ts b/frontend/src/app/services/solr.service.ts index af5e46e8..cbbf44ed 100644 --- a/frontend/src/app/services/solr.service.ts +++ b/frontend/src/app/services/solr.service.ts @@ -168,7 +168,7 @@ export class SolrService { getSomethings() { const headers = { headers: this.jsonHeader }; - const body = {};// JSON.stringify( { thingName: thingName }); + const body = "{x: 1}"; return this.http .get(`${this.baseUrl}/get-somethings`, body) .toPromise(); From 8a0f60e35c67c87e748f0043bf4cc3044fa3fbc0 Mon Sep 17 00:00:00 2001 From: Chris Morley Date: Fri, 27 May 2022 15:14:24 -0400 Subject: [PATCH 10/25] small fix --- frontend/src/app/services/solr.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/app/services/solr.service.ts b/frontend/src/app/services/solr.service.ts index cbbf44ed..771be249 100644 --- a/frontend/src/app/services/solr.service.ts +++ b/frontend/src/app/services/solr.service.ts @@ -168,7 +168,7 @@ export class SolrService { getSomethings() { const headers = { headers: this.jsonHeader }; - const body = "{x: 1}"; + const body = {}; return this.http .get(`${this.baseUrl}/get-somethings`, body) .toPromise(); From 7f6a2b273d5b0e45f59413e9e4654c2994d6864b Mon Sep 17 00:00:00 2001 From: Chris Morley Date: Fri, 27 May 2022 16:02:25 -0400 Subject: [PATCH 11/25] restore toast, etc. --- .../app/components/admin/admin.component.ts | 1 - ...ris-rules-collection-create.component.html | 2 +- ...chris-rules-collection-create.component.ts | 40 ++++++++++-------- .../app/components/chris/chris.component.html | 23 ++++++----- .../app/components/chris/chris.component.ts | 41 +++++++++---------- 5 files changed, 56 insertions(+), 51 deletions(-) diff --git a/frontend/src/app/components/admin/admin.component.ts b/frontend/src/app/components/admin/admin.component.ts index cc66c607..42a87837 100644 --- a/frontend/src/app/components/admin/admin.component.ts +++ b/frontend/src/app/components/admin/admin.component.ts @@ -38,7 +38,6 @@ export class AdminComponent implements OnInit { this.toasterService.pop('error', '', msgText); } - // @ts-ignore public openDeleteConfirmModal({ deleteCallback }) { const deferred = this.modalService.open('confirm-delete'); diff --git a/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.html b/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.html index 0a0609d7..778d7686 100644 --- a/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.html +++ b/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.html @@ -6,7 +6,7 @@
    Add a new value.
    - +
    diff --git a/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.ts b/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.ts index 076e1926..8b00dbfc 100644 --- a/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.ts +++ b/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.ts @@ -28,7 +28,6 @@ export class ChrisRulesCollectionCreateComponent implements OnInit, OnChanges { solrIndices: SolrIndex[]; valueName: string; - resultString: string; constructor( private solrService: SolrService, @@ -37,7 +36,7 @@ export class ChrisRulesCollectionCreateComponent implements OnInit, OnChanges { } ngOnInit() { console.log('In ChrisRulesCollectionCreateComponent :: ngOnInit'); - //this.solrIndices = this.solrService.solrIndices; + this.solrIndices = this.solrService.solrIndices; } ngOnChanges(changes: SimpleChanges): void { @@ -54,27 +53,32 @@ export class ChrisRulesCollectionCreateComponent implements OnInit, OnChanges { } addOneValue( event: Event){ - console.log("addOneValue() , thingName: " + this.valueName); - //console.log('In ChrisRulesCollectidonCreateComponent :: createChrisRulesCollection'); - this.solrService.putSomething2(this.valueName).then(() => console.log("done")); - // - // if (this.name && this.description) { - // this.solrService - // .createSolrIndex(this.name, this.description) - // .then(() => this.solrService.listAllSolrIndices()) - // .then(() => this.solrIndicesChange.emit()) - // .then(() => this.showSuccessMsg.emit("Created new Chris Rules Collection " + this.description)) - // .then(() => this.solrService.emitRulesCollectionChangeEvent("")) - // .then(() => this.clearForm()) - // .catch(error => this.showErrorMsg.emit(error)); - // } + if (this.valueName) { + console.log("addOneValue() , thingName: " + this.valueName); + //console.log('In ChrisRulesCollectidonCreateComponent :: createChrisRulesCollection'); + this.solrService.putSomething2(this.valueName) + .then(() => this.showSuccessMsg.emit("Add Value: OK")); + // + // if (this.name && this.description) { + // this.solrService + // .createSolrIndex(this.name, this.description) + // .then(() => this.solrService.listAllSolrIndices()) + // .then(() => this.solrIndicesChange.emit()) + // .then(() => this.showSuccessMsg.emit("Created new Chris Rules Collection " + this.description)) + // .then(() => this.solrService.emitRulesCollectionChangeEvent("")) + // .then(() => this.clearForm()) + // .catch(error => this.showErrorMsg.emit(error)); + // } + } else { + this.showErrorMsg.emit("Add Value: oops"); + } } putRows(event: Event) { this.solrService.putSomething2("test row 1").then(() => console.log("added test row 1")); this.solrService.putSomething2("test row 2").then(() => console.log("added test row 2")); this.solrService.putSomething2("test row 3").then(() => console.log("added test row 3")); - console.log("putRows()"); + this.showSuccessMsg.emit("Put Rows: OK") } getRows(event: Event) { @@ -84,6 +88,7 @@ export class ChrisRulesCollectionCreateComponent implements OnInit, OnChanges { this.solrService.getSomethings().then( result => { console.log(result) + this.showSuccessMsg.emit("Get Rows: OK, see console log") } ) } @@ -96,6 +101,7 @@ export class ChrisRulesCollectionCreateComponent implements OnInit, OnChanges { this.downloadStringAsFile( "file.json.txt", str); + this.showSuccessMsg.emit("Download: OK") } ); } diff --git a/frontend/src/app/components/chris/chris.component.html b/frontend/src/app/components/chris/chris.component.html index 0b6d2a9a..31c4bbc9 100644 --- a/frontend/src/app/components/chris/chris.component.html +++ b/frontend/src/app/components/chris/chris.component.html @@ -1,22 +1,23 @@ - + - + - + - - - - - - - - + +

    Are you sure you want to delete the item?

    +
    diff --git a/frontend/src/app/components/chris/chris.component.ts b/frontend/src/app/components/chris/chris.component.ts index ebe4b230..636238a0 100644 --- a/frontend/src/app/components/chris/chris.component.ts +++ b/frontend/src/app/components/chris/chris.component.ts @@ -1,13 +1,13 @@ import { Component, OnInit, Input } from '@angular/core'; -// import { ToasterService } from 'angular2-toaster'; -// -// import { SolrIndex } from '../../models'; +import { ToasterService } from 'angular2-toaster'; -// import { -// SolrService, -// ModalService -// } from '../../services'; +import { SolrIndex } from '../../models'; + +import { + SolrService, + ModalService + } from '../../services'; @Component({ selector: 'app-smui-chris', @@ -16,41 +16,40 @@ import { Component, OnInit, Input } from '@angular/core'; export class ChrisComponent implements OnInit { constructor( - // private modalService: ModalService, - // private toasterService: ToasterService, - // private solrService: SolrService + private modalService: ModalService, + private toasterService: ToasterService, + private solrService: SolrService ) { } - //solrIndices: SolrIndex[]; + solrIndices: SolrIndex[]; ngOnInit() { console.log('In ChrisComponent :: ngOnInit'); - //this.solrIndices = this.solrService.solrIndices; + this.solrIndices = this.solrService.solrIndices; } public showSuccessMsg(msgText: string) { - //this.toasterService.pop('success', '', msgText); + this.toasterService.pop('success', '', msgText); } public showErrorMsg(msgText: string) { - //this.toasterService.pop('error', '', msgText); + this.toasterService.pop('error', '', msgText); } - // @ts-ignore public openDeleteConfirmModal({ deleteCallback }) { - //const deferred = this.modalService.open('confirm-delete'); - // deferred.promise.then((isOk: boolean) => { - // if (isOk) { deleteCallback(); } - // this.modalService.close('confirm-delete'); - // }); + const deferred = this.modalService.open('confirm-delete'); + deferred.promise.then((isOk: boolean) => { + if (isOk) { deleteCallback(); } + this.modalService.close('confirm-delete'); + }); } public solrIndicesChange(id: string){ console.log("ChrisComponent :: solrIndicesChange :: id = " + id) - //this.solrIndices = this.solrService.solrIndices; + this.solrIndices = this.solrService.solrIndices; } } From 945e465d3dc30f9597bd0d753249305080cace5b Mon Sep 17 00:00:00 2001 From: Chris Morley Date: Tue, 31 May 2022 15:31:22 -0400 Subject: [PATCH 12/25] progress --- app/controllers/ApiController.scala | 35 ++--- app/models/SearchManagementRepository.scala | 23 +--- app/models/export/Exporter.scala | 126 ++++++++++++++++-- app/models/export/JsonExportable.scala | 13 ++ app/models/export/Something.scala | 27 ++-- app/models/export/Somethings.scala | 48 ------- app/models/input/SearchInput.scala | 36 ++++- app/models/input/SearchInputExport.scala | 72 ++++++++++ app/models/rules/DeleteRule.scala | 4 + app/models/rules/DeleteRuleExport.scala | 63 +++++++++ app/models/rules/FilterRule.scala | 6 +- app/models/rules/FilterRuleExport.scala | 68 ++++++++++ app/models/rules/RedirectRule.scala | 34 ++++- app/models/rules/RedirectRuleExport.scala | 66 +++++++++ app/models/rules/Rule.scala | 8 +- app/models/rules/SynonymRule.scala | 6 +- app/models/rules/SynonymRuleExport.scala | 81 +++++++++++ app/models/rules/UpDownRule.scala | 5 +- app/models/rules/UpdownRuleExport.scala | 77 +++++++++++ conf/routes | 2 +- ...chris-rules-collection-create.component.ts | 4 +- frontend/src/app/services/solr.service.ts | 4 +- run_helper.sh | 1 + 23 files changed, 689 insertions(+), 120 deletions(-) create mode 100644 app/models/export/JsonExportable.scala delete mode 100644 app/models/export/Somethings.scala create mode 100644 app/models/input/SearchInputExport.scala create mode 100644 app/models/rules/DeleteRuleExport.scala create mode 100644 app/models/rules/FilterRuleExport.scala create mode 100644 app/models/rules/RedirectRuleExport.scala create mode 100644 app/models/rules/SynonymRuleExport.scala create mode 100644 app/models/rules/UpdownRuleExport.scala diff --git a/app/controllers/ApiController.scala b/app/controllers/ApiController.scala index 8e182513..247141aa 100644 --- a/app/controllers/ApiController.scala +++ b/app/controllers/ApiController.scala @@ -138,6 +138,7 @@ class ApiController @Inject()(authActionFactory: AuthActionFactory, def addNewSearchInput(solrIndexId: String) = authActionFactory.getAuthenticatedAction(Action).async { request: Request[AnyContent] => Future { + logger.debug("addNewSearchInput") val userInfo: Option[String] = lookupUserInfo(request) val body: AnyContent = request.body @@ -168,16 +169,26 @@ class ApiController @Inject()(authActionFactory: AuthActionFactory, def updateSearchInput(searchInputId: String) = authActionFactory.getAuthenticatedAction(Action) { request: Request[AnyContent] => - val body: AnyContent = request.body + logger.debug("updateSearchInput:1") + var body: AnyContent = request.body + //var jsonString: String = "{\"id\":\"ab116147-498a-427e-9481-9565739aa706\",\"term\":\"synonym1\",\"synonymRules\":[{\"id\":\"e7ab9b28-e6af-48dc-af7f-224b00381e62\",\"synonymType\":1,\"term\":\"synonym2\",\"isActive\":true,\"status\":1,\"lastUpdate\":\"2005\"}],\"upDownRules\":[],\"filterRules\":[],\"deleteRules\":[],\"redirectRules\":[],\"tags\":[],\"isActive\":true,\"comment\":\"synonym3\"}" + //val jsVal: JsValue = Json.parse(jsonString) + //body = AnyContentAsJson(jsVal) val jsonBody: Option[JsValue] = body.asJson val userInfo: Option[String] = lookupUserInfo(request) - + logger.debug("updateSearchInput:2") + logger.debug("updateSearchInput:body") + logger.debug(body.toString) + logger.debug("updateSearchInput:jsonBody") + logger.debug(jsonBody.toString) // Expecting json body jsonBody.map { json => + logger.debug("updateSearchInput:3") val searchInput = json.as[SearchInputWithRules] - + logger.debug("updateSearchInput:4") InputValidator.validateInputTerm(searchInput.term) match { case Nil => { + logger.debug("updateSearchInput:5") // proceed updating input with rules querqyRulesTxtGenerator.validateSearchInputToErrMsg(searchInput) match { case Some(strErrMsg: String) => @@ -192,6 +203,7 @@ class ApiController @Inject()(authActionFactory: AuthActionFactory, } } case errors => { + logger.debug("updateSearchInput:6") val msgs = s"Failed to update Search Input with new term ${searchInput.term}: " + errors.mkString("\n") logger.error(msgs) BadRequest(Json.toJson(ApiResult(API_RESULT_FAIL, msgs, None))) @@ -199,6 +211,7 @@ class ApiController @Inject()(authActionFactory: AuthActionFactory, } }.getOrElse { + logger.debug("updateSearchInput:7") BadRequest(Json.toJson(ApiResult(API_RESULT_FAIL, "Adding new Search Input failed. Unexpected body data.", None))) } } @@ -600,16 +613,14 @@ class ApiController @Inject()(authActionFactory: AuthActionFactory, } - def getSomething(solrIndexId: String) = authActionFactory.getAuthenticatedAction(Action).async { + def getSomething(solrIndexId: String): Action[AnyContent] = authActionFactory.getAuthenticatedAction(Action).async { Future { val something = searchManagementRepository.getSomething(solrIndexId) Ok(Json.toJson(something.writer.writes("writesMsg1"))) - //Ok(Json.toJson( } } - def putSomething() = authActionFactory.getAuthenticatedAction(Action) { request: Request[AnyContent] => - //Future { + def putSomething(): Action[AnyContent] = authActionFactory.getAuthenticatedAction(Action) { request: Request[AnyContent] => logger.debug("putSomething:0"); val body: AnyContent = request.body val jsonBody: Option[JsValue] = body.asJson @@ -619,22 +630,16 @@ class ApiController @Inject()(authActionFactory: AuthActionFactory, val thingName = (json \ "thingName").as[String] logger.debug("putSomething:2 we got " + thingName); searchManagementRepository.putSomething(thingName) -// val field = searchManagementRepository.addNewSuggestedSolrField( -// SolrIndexId(solrIndexId), searchSuggestedSolrFieldName -// ) - Ok(Json.toJson(ApiResult(API_RESULT_OK, "That worked.", None))) - // Ok(Json.toJson("ok")) }.getOrElse { BadRequest(Json.toJson(ApiResult(API_RESULT_FAIL, "That failed.", None))) } } - def getSomethings() = authActionFactory.getAuthenticatedAction(Action).async { + def getDatabaseJson: Action[AnyContent] = authActionFactory.getAuthenticatedAction(Action).async { Future { logger.debug("In ApiController:getSomethings") - Ok(Json.toJson(searchManagementRepository.getAllSomethingsForJs())) - //Ok(Json.toJson( + Ok(Json.toJson(searchManagementRepository.getDatabaseJson)) } } diff --git a/app/models/SearchManagementRepository.scala b/app/models/SearchManagementRepository.scala index 3ddd101c..56f46565 100644 --- a/app/models/SearchManagementRepository.scala +++ b/app/models/SearchManagementRepository.scala @@ -16,7 +16,7 @@ import models.input.{InputTag, InputTagId, PredefinedTag, SearchInput, SearchInp import models.spellings.{CanonicalSpelling, CanonicalSpellingId, CanonicalSpellingWithAlternatives} import models.eventhistory.{ActivityLog, ActivityLogEntry, InputEvent} import models.reports.{ActivityReport, DeploymentLog, RulesReport} -import models.rules.SynonymRuleId +import models.rules.{DeleteRule, FilterRule, SynonymRuleId} import play.api.Logging import play.api.libs.json.JsValue @@ -335,26 +335,11 @@ class SearchManagementRepository @Inject()(dbapi: DBApi, toggleService: FeatureT } } - def getSomethingsFromDatabase(): IndexedSeq[Something] = db.withConnection { - implicit connection => { - logger.debug("In SearchManagementRepository:getSomethingsFromDatabase():1") - val x : List[Something] = SQL(s"select id, value0, last_update from something") - .as(SomethingRow.sqlParser.*) - logger.debug("In SearchManagementRepository:getSomethingsFromDatabase():2") - x.toIndexedSeq - } - } - - def getAllSomethingsForJs(): JsValue = db.withConnection { + def getDatabaseJson: JsValue = db.withConnection { implicit connection => { logger.debug("In SearchManagementRepository:getAllSomethingsForJs():1") - val exporter : Exporter = new Exporter() - logger.debug("In SearchManagementRepository:getAllSomethingsForJs():2") - val somethings1 : IndexedSeq[Something] = getSomethingsFromDatabase() - logger.debug("In SearchManagementRepository:getAllSomethingsForJs():3... length:" + somethings1.size) - val somethings2 = exporter.getAllSomethingsForJs(somethings1) - logger.debug("In SearchManagementRepository:getAllSomethingsForJs():4") - somethings2 + val exporter : Exporter = new Exporter(dbapi, toggleService) + exporter.getDatabaseJson } } diff --git a/app/models/export/Exporter.scala b/app/models/export/Exporter.scala index 5dacff06..268965f9 100644 --- a/app/models/export/Exporter.scala +++ b/app/models/export/Exporter.scala @@ -1,29 +1,131 @@ package models.`export` -import play.api.libs.json.JsValue +import anorm.SQL +import models.DatabaseExecutionContext +import models.FeatureToggleModel.FeatureToggleService +import models.input.{SearchInput, SearchInputExport} +import models.rules.{DeleteRule, DeleteRuleExport, FilterRule, FilterRuleExport, SynonymRule, SynonymRuleExport, UpDownRuleExport} +import play.api.libs.json.{JsArray, JsObject, JsString, JsValue} import play.api.Logging +import play.api.db.DBApi import java.time.LocalDateTime +import javax.inject.Inject -class Exporter extends Logging { +@javax.inject.Singleton +class Exporter @Inject()(dbapi: DBApi, toggleService: FeatureToggleService)(implicit ec: DatabaseExecutionContext) extends Logging { + + private val db = dbapi.database("default") var somethings1: IndexedSeq[Something] = IndexedSeq( new Something(SomethingId(), "something1", LocalDateTime.now()), new Something(SomethingId(), "something2", LocalDateTime.now()) ) - def getAllSomethingsForJs(): JsValue = { - val source : IndexedSeq[Something] = this.somethings1 - val converter : Somethings = new Somethings() - val x : JsValue = converter.asIndexedSeqForJs(source) - x + def getAllTablesForJs(tables : IndexedSeq[IndexedSeq[JsonExportable]]): JsValue = { + var aggregation: Seq[JsValue] = Seq[JsValue]() + println("hello ------ ") + println(tables.size) + getAllTablesForJs1(tables, aggregation) + } + + def getAllTablesForJs1(tables : IndexedSeq[IndexedSeq[JsonExportable]], aggregation: Seq[JsValue]): JsValue = { + if (tables.nonEmpty) { + val headTable = tables.head + val remainingTables = tables.drop(1) + println("remaining") + println(remainingTables.size) + + if (headTable.nonEmpty) { + println("tablename") + println(headTable.seq(0).getTableName) + val name: (String, JsValue) = "tableName" -> headTable.seq(0).getTableName + val cols: (String, JsValue) = "columns" -> headTable.seq(0).getColumns + val rows: (String, JsValue) = "rows" -> asIndexedSeqForJs(headTable) + val obj: (JsValue) = JsObject(IndexedSeq(name, cols, rows)) + println("calling recursion") + getAllTablesForJs1(remainingTables, aggregation :+ obj) + } else { + logger.debug("In Exporter.getAllTablesForJs1 : return aggregation because headTable is empty") + JsArray(aggregation.toIndexedSeq) + } + } else { + logger.debug("In Exporter.getAllTablesForJs1 : return aggregation because tables is empty") + JsArray(aggregation.toIndexedSeq) + } + } + + def asIndexedSeqForJs(indexedSeqSource : IndexedSeq[JsonExportable]): JsValue = { + var target: IndexedSeq[JsValue] = IndexedSeq[JsValue]() + for((element,index) <- indexedSeqSource.view.zipWithIndex) { + logger.debug("In Exporter.asIndexedSeqForJs : String #" + index + " is " + element.getRow) + target = target :+ element.getRow + } + JsArray(target.toIndexedSeq) + } + +// def getSomethingsFromDatabase: IndexedSeq[Something] = db.withConnection { +// implicit connection => { +// logger.debug("In SearchManagementRepository:getSomethingsFromDatabase():1") +// val x : List[Something] = SQL(s"select id, value0, last_update from something") +// .as(SomethingRow.sqlParser.*) +// logger.debug("In SearchManagementRepository:getSomethingsFromDatabase():2") +// x.toIndexedSeq +// } +// } + + def getSearchInputsFromDatabase: IndexedSeq[SearchInputExport] = db.withConnection { + implicit connection => { + val x : List[SearchInputExport] = SQL(s"select id, term, solr_index_id, last_update, status, comment from search_input") + .as(SearchInputExport.sqlParser.*) + x.toIndexedSeq + } + } + + def getDeleteRulesFromDatabase: IndexedSeq[DeleteRuleExport] = db.withConnection { + implicit connection => { + val x : List[DeleteRuleExport] = SQL(s"select id, term, search_input_id, last_update, status from delete_rule") + .as(DeleteRuleExport.sqlParser.*) + x.toIndexedSeq + } + } + + def getFilterRulesFromDatabase: IndexedSeq[FilterRuleExport] = db.withConnection { + implicit connection => { + logger.debug("In getFilterRulesFromDatabase") + val x : List[FilterRuleExport] = SQL(s"select id, term, search_input_id, last_update, status from filter_rule") + .as(FilterRuleExport.sqlParser.*) + x.toIndexedSeq + } + } + + def getSynonymRulesFromDatabase: IndexedSeq[SynonymRuleExport] = db.withConnection { + implicit connection => { + val x : List[SynonymRuleExport] = SQL(s"select id, synonym_type, term, search_input_id, last_update, status from synonym_rule") + .as(SynonymRuleExport.sqlParser.*) + x.toIndexedSeq + } + } + + def getUpDownRulesFromDatabase: IndexedSeq[UpDownRuleExport] = db.withConnection { + implicit connection => { + val x : List[UpDownRuleExport] = SQL(s"select id, up_down_type, boost_malus_value, term, search_input_id, last_update, status from up_down_rule") + .as(UpDownRuleExport.sqlParser.*) + x.toIndexedSeq + } } - def getAllSomethingsForJs(somethingsInput : IndexedSeq[Something]): JsValue = { - logger.debug("In Exporter:getAllSomethingsForJs():1") - val converter : Somethings = new Somethings() - val x : JsValue = converter.asIndexedSeqForJs(somethingsInput) - x + def getDatabaseJson: JsValue = { + logger.debug("In getDatabaseJson") + val tableSeq = IndexedSeq( + //getSomethingsFromDatabase, + getSearchInputsFromDatabase, + getDeleteRulesFromDatabase, + getFilterRulesFromDatabase, + getSynonymRulesFromDatabase, + getUpDownRulesFromDatabase + ) + getAllTablesForJs(tableSeq) } } diff --git a/app/models/export/JsonExportable.scala b/app/models/export/JsonExportable.scala new file mode 100644 index 00000000..40fc0165 --- /dev/null +++ b/app/models/export/JsonExportable.scala @@ -0,0 +1,13 @@ +package models.`export` + +import play.api.libs.json.{JsString, JsValue} + +trait JsonExportable { + + def getTableName: JsString + + def getRow: JsValue + + def getColumns: JsValue + +} diff --git a/app/models/export/Something.scala b/app/models/export/Something.scala index 1e34203b..7cd71879 100644 --- a/app/models/export/Something.scala +++ b/app/models/export/Something.scala @@ -14,7 +14,7 @@ import java.util.UUID case class Something(id: SomethingId = SomethingId(), value0: String, - last_update: LocalDateTime) { + last_update: LocalDateTime) extends JsonExportable { // override def toNamedParameters(searchInputId: SearchInputId): Seq[NamedParameter] = { // super.toNamedParameters(searchInputId) ++ Seq[NamedParameter]( // .TYPE -> synonymType @@ -36,15 +36,26 @@ case class Something(id: SomethingId = SomethingId(), } } - def getJsValue(): JsValue = { - val x : JsObject = JsObject( - Seq ( - "id" -> JsString(id.toString), - "value0" -> JsString(value0), - "last_update" -> JsString(last_update.toString) + def getTableName: JsString = JsString("something") + + def getColumns: JsValue = { + JsArray( + IndexedSeq ( + JsString("id"), + JsString("value0"), + JsString("last_update") + ) + ) + } + + def getRow: JsValue = { + JsArray( + IndexedSeq ( + JsString(id.toString), + JsString(value0), + JsString(last_update.toString) ) ) - x } } diff --git a/app/models/export/Somethings.scala b/app/models/export/Somethings.scala deleted file mode 100644 index 247ea09e..00000000 --- a/app/models/export/Somethings.scala +++ /dev/null @@ -1,48 +0,0 @@ -package models.`export` - -import play.api.libs.json.{JsArray, JsNull, JsNumber, JsObject, JsString, JsValue, Json, Writes} - -//case class MyJsObject( -// somethings: JsValue, -// ) - -class Somethings() { - -// val myJavascriptObject: MyJsObject = -// MyJsObject( -// somethings = JsArray( -// IndexedSeq( -// new JsString("first value of array"), -// new JsString("second value of array")) -// ) -// ) - -// implicit val writer = new Writes[(String)] { -// def writes(t: (String)): JsValue = { -// Json.obj( -// "somethings" -> myJavascriptObject.somethings -// ) -// } -// } - - def asIndexedSeqForJs(indexedSeqSource : IndexedSeq[Something]): JsValue = { - val exporter : Exporter = new Exporter() - //var indexedSeqSource : IndexedSeq[Something] = exporter.getAllSomethings() - var target1: List[String] = List[String]() - println("#In Somethings.asIndexedSeqForJs : size of target1: " + target1.size) - target1 = target1 :+ "hi" - println("->In Somethings.asIndexedSeqForJs : size of target1: " + target1.size) - - var target: IndexedSeq[JsValue] = IndexedSeq[JsValue]() - target :+ JsString("hi") - println("->In Somethings.asIndexedSeqForJs : size of target: " + target.size) - for((element,index) <- indexedSeqSource.view.zipWithIndex) { - println("In Somethings.asIndexedSeqForJs : String #" + index + " is " + element.getJsValue()) //CJM DELETE - target = target :+ element.getJsValue() - } - println("%In Somethings.asIndexedSeqForJs : size of target: " + target.size) - val x : JsValue = JsObject(Seq("somethings-asIndexedSeqForJs-was-here" -> JsArray(target.toIndexedSeq))) - x - } - -} diff --git a/app/models/input/SearchInput.scala b/app/models/input/SearchInput.scala index 821c8eaa..1713cb63 100644 --- a/app/models/input/SearchInput.scala +++ b/app/models/input/SearchInput.scala @@ -2,13 +2,11 @@ package models.input import java.sql.Connection import java.time.LocalDateTime - -import play.api.libs.json.{Json, OFormat} - +import play.api.libs.json.{JsArray, JsNumber, JsObject, JsString, JsValue, Json, OFormat} import anorm.SqlParser.get import anorm._ - import models._ +import models.`export`.JsonExportable class SearchInputId(id: String) extends Id(id) object SearchInputId extends IdObject[SearchInputId](new SearchInputId(_)) @@ -18,7 +16,7 @@ case class SearchInput(id: SearchInputId = SearchInputId(), term: String, lastUpdate: LocalDateTime, isActive: Boolean, - comment: String) { + comment: String) extends JsonExportable { import SearchInput._ @@ -33,6 +31,34 @@ case class SearchInput(id: SearchInputId = SearchInputId(), COMMENT -> comment ) + def getTableName: JsString = JsString("search_input") + + def getRow: JsValue = { + JsArray( + IndexedSeq ( + JsString(id.toString), + JsString(term), + JsString(solrIndexId.toString), + JsString(lastUpdate.toString), + JsNumber(status), + JsString(comment) + ) + ) + } + + def getColumns: JsValue = { + JsArray( + IndexedSeq ( + JsString("id"), + JsString("term"), + JsString("solr_index_id"), + JsString("last_update"), + JsString("status"), + JsString("comment") + ) + ) + } + } object SearchInput { diff --git a/app/models/input/SearchInputExport.scala b/app/models/input/SearchInputExport.scala new file mode 100644 index 00000000..7dc68ec4 --- /dev/null +++ b/app/models/input/SearchInputExport.scala @@ -0,0 +1,72 @@ +package models.input + +import anorm.SqlParser.get +import anorm._ +import models._ +import models.`export`.JsonExportable +import play.api.libs.json._ + +import java.sql.Connection +import java.time.LocalDateTime + +case class SearchInputExport(id: SearchInputId, + solrIndexId: SolrIndexId, + term: String, + lastUpdate: LocalDateTime, + status: Int, + comment: String) extends JsonExportable { + + def getTableName: JsString = JsString("search_input") + + def getRow: JsValue = { + JsArray( + IndexedSeq ( + JsString(id.toString), + JsString(term), + JsString(solrIndexId.toString), + JsString(lastUpdate.toString), + JsNumber(status), + JsString(comment) + ) + ) + } + + def getColumns: JsValue = { + JsArray( + IndexedSeq ( + JsString("id"), + JsString("term"), + JsString("solr_index_id"), + JsString("last_update"), + JsString("status"), + JsString("comment") + ) + ) + } + +} + +object SearchInputExport { + + implicit val jsonFormat: OFormat[SearchInput] = Json.format[SearchInput] + + val TABLE_NAME = "search_input" + val ID = "id" + val TERM = "term" + val SOLR_INDEX_ID = "solr_index_id" + val LAST_UPDATE = "last_update" + val STATUS = "status" + val COMMENT = "comment" + + val sqlParser: RowParser[SearchInputExport] = { + get[SearchInputId](s"$TABLE_NAME.$ID") ~ + get[String](s"$TABLE_NAME.$TERM") ~ + get[SolrIndexId](s"$TABLE_NAME.$SOLR_INDEX_ID") ~ + get[LocalDateTime](s"$TABLE_NAME.$LAST_UPDATE") ~ + get[Int](s"$TABLE_NAME.$STATUS") ~ + get[String](s"$TABLE_NAME.$COMMENT") map { case id ~ term ~ indexId ~ lastUpdate ~ status ~ comment => + SearchInputExport(id, indexId, term, lastUpdate, status, comment) + } + } + +} diff --git a/app/models/rules/DeleteRule.scala b/app/models/rules/DeleteRule.scala index 9118bfb6..cd9151bd 100644 --- a/app/models/rules/DeleteRule.scala +++ b/app/models/rules/DeleteRule.scala @@ -2,9 +2,12 @@ package models.rules import anorm.SqlParser.get import anorm.{RowParser, ~} +import models.input.SearchInputId import models.{Id, IdObject, Status} import play.api.libs.json.{Json, OFormat} +import java.time.LocalDateTime + class DeleteRuleId(id: String) extends Id(id) object DeleteRuleId extends IdObject[DeleteRuleId](new DeleteRuleId(_)) @@ -28,4 +31,5 @@ object DeleteRule extends RuleObjectWithTerm[DeleteRule] { DeleteRule(id, term, Status.isActiveFromStatus(status)) } } + } \ No newline at end of file diff --git a/app/models/rules/DeleteRuleExport.scala b/app/models/rules/DeleteRuleExport.scala new file mode 100644 index 00000000..6c140a3a --- /dev/null +++ b/app/models/rules/DeleteRuleExport.scala @@ -0,0 +1,63 @@ +package models.rules + +import anorm.SqlParser.get +import anorm.{RowParser, ~} +import models.`export`.JsonExportable +import models.input.SearchInputId +import models.{Id, IdObject, Status} +import play.api.libs.json.{JsArray, JsNumber, JsString, JsValue, Json, OFormat} + +import java.time.LocalDateTime + +case class DeleteRuleExport(id: DeleteRuleId = DeleteRuleId(), + term: String, + isActive: Boolean, + status: Int, + searchInputId: SearchInputId, + lastUpdate: LocalDateTime) extends JsonExportable { + + def getTableName: JsString = JsString("delete_rule") + + def getColumns: JsValue = { + JsArray( + IndexedSeq ( + JsString("id"), + JsString("term"), + JsString("search_input_id"), + JsString("last_update"), + JsString("status") + ) + ) + } + + def getRow: JsValue = { + JsArray( + IndexedSeq ( + JsString(id.toString), + JsString(term), + JsString(searchInputId.toString), + JsString(lastUpdate.toString), + JsNumber(status) + ) + ) + } + +} + +object DeleteRuleExport extends CommonRuleFields { + + val TABLE_NAME = "delete_rule" + + implicit val jsonFormat: OFormat[DeleteRuleExport] = Json.format[DeleteRuleExport] + + val sqlParser: RowParser[DeleteRuleExport] = { + get[DeleteRuleId](s"$TABLE_NAME.$ID") ~ + get[String](s"$TABLE_NAME.$TERM") ~ + get[Int](s"$TABLE_NAME.$STATUS") ~ + get[SearchInputId](s"$TABLE_NAME.$SEARCH_INPUT_ID") ~ + get[LocalDateTime](s"$TABLE_NAME.$LAST_UPDATE") map { case id ~ term ~ status ~ searchInputId ~ lastUpdate => + DeleteRuleExport(id, term, Status.isActiveFromStatus(status), status, searchInputId, lastUpdate) + } + } + +} \ No newline at end of file diff --git a/app/models/rules/FilterRule.scala b/app/models/rules/FilterRule.scala index 7944eddc..14b37fff 100644 --- a/app/models/rules/FilterRule.scala +++ b/app/models/rules/FilterRule.scala @@ -2,8 +2,12 @@ package models.rules import anorm.SqlParser.get import anorm.{RowParser, ~} +import models.input.SearchInputId +import models.rules.DeleteRule.{LAST_UPDATE, SEARCH_INPUT_ID, TABLE_NAME} import models.{Id, IdObject, Status} -import play.api.libs.json.{Json, OFormat} +import play.api.libs.json.{JsArray, JsNumber, JsString, JsValue, Json, OFormat} + +import java.time.LocalDateTime class FilterRuleId(id: String) extends Id(id) object FilterRuleId extends IdObject[FilterRuleId](new FilterRuleId(_)) diff --git a/app/models/rules/FilterRuleExport.scala b/app/models/rules/FilterRuleExport.scala new file mode 100644 index 00000000..5e683804 --- /dev/null +++ b/app/models/rules/FilterRuleExport.scala @@ -0,0 +1,68 @@ +package models.rules + +import anorm.SqlParser.get +import anorm.{RowParser, ~} +import models.`export`.JsonExportable +import models.input.SearchInputId +import models.rules.DeleteRule.{LAST_UPDATE, SEARCH_INPUT_ID, TABLE_NAME} +import models.{Id, IdObject, Status} +import play.api.libs.json.{JsArray, JsNumber, JsString, JsValue, Json, OFormat} + +import java.time.LocalDateTime + +//class FilterRuleId(id: String) extends Id(id) +//object FilterRuleId extends IdObject[FilterRuleId](new FilterRuleId(_)) + + +case class FilterRuleExport(id: FilterRuleId, + term: String, + isActive: Boolean, + status: Int, + searchInputId: SearchInputId, + lastUpdate: LocalDateTime) extends JsonExportable { + + def getTableName: JsString = JsString("filter_rule") + + def getColumns: JsValue = { + JsArray( + IndexedSeq ( + JsString("id"), + JsString("term"), + JsString("search_input_id"), + JsString("last_update"), + JsString("status") + ) + ) + } + + def getRow: JsValue = { + JsArray( + IndexedSeq ( + JsString(id.toString), + JsString(term), + JsString(searchInputId.toString), + JsString(lastUpdate.toString), + JsNumber(status) + ) + ) + } + +} + +object FilterRuleExport extends CommonRuleFields { + + val TABLE_NAME = "filter_rule" + + implicit val jsonFormat: OFormat[FilterRule] = Json.format[FilterRule] + + val sqlParser: RowParser[FilterRuleExport] = { + get[FilterRuleId](s"$TABLE_NAME.$ID") ~ + get[String](s"$TABLE_NAME.$TERM") ~ + get[Int](s"$TABLE_NAME.$STATUS") ~ + get[SearchInputId](s"$TABLE_NAME.$SEARCH_INPUT_ID") ~ + get[LocalDateTime](s"$TABLE_NAME.$LAST_UPDATE") map { case id ~ term ~ status ~ searchInputId ~ lastUpdate => + FilterRuleExport(id, term, Status.isActiveFromStatus(status), status, searchInputId, lastUpdate) + } + } + +} \ No newline at end of file diff --git a/app/models/rules/RedirectRule.scala b/app/models/rules/RedirectRule.scala index 5f483025..1bab81bd 100644 --- a/app/models/rules/RedirectRule.scala +++ b/app/models/rules/RedirectRule.scala @@ -4,7 +4,9 @@ import anorm.SqlParser.get import anorm.{NamedParameter, RowParser, ~} import models.input.SearchInputId import models.{Id, IdObject, Status} -import play.api.libs.json.{Json, OFormat} +import play.api.libs.json.{JsArray, JsNumber, JsString, JsValue, Json, OFormat} + +import java.time.LocalDateTime class RedirectRuleId(id: String) extends Id(id) object RedirectRuleId extends IdObject[RedirectRuleId](new RedirectRuleId(_)) @@ -12,13 +14,41 @@ object RedirectRuleId extends IdObject[RedirectRuleId](new RedirectRuleId(_)) case class RedirectRule(id: RedirectRuleId = RedirectRuleId(), target: String, - isActive: Boolean) extends Rule { + isActive: Boolean, + searchInputId: SearchInputId = SearchInputId(), + lastUpdate: LocalDateTime = LocalDateTime.now()) extends Rule { override def toNamedParameters(searchInputId: SearchInputId): Seq[NamedParameter] = { super.toNamedParameters(searchInputId) ++ Seq[NamedParameter]( RedirectRule.TARGET -> target ) } + + def getTableName: JsString = JsString("delete_rule") + + def getColumns: JsValue = { + JsArray( + IndexedSeq ( + JsString("id"), + JsString("target"), + JsString("search_input_id"), + JsString("last_update"), + JsString("status") + ) + ) + } + + def getRow: JsValue = { + JsArray( + IndexedSeq ( + JsString(id.toString), + JsString(target), + JsString(searchInputId.toString), + JsString(lastUpdate.toString), + JsNumber(status) + ) + ) + } } object RedirectRule extends RuleObject[RedirectRule] { diff --git a/app/models/rules/RedirectRuleExport.scala b/app/models/rules/RedirectRuleExport.scala new file mode 100644 index 00000000..c2026a78 --- /dev/null +++ b/app/models/rules/RedirectRuleExport.scala @@ -0,0 +1,66 @@ +package models.rules + +import anorm.SqlParser.get +import anorm.{NamedParameter, RowParser, ~} +import models.`export`.JsonExportable +import models.input.SearchInputId +import models.{Id, IdObject, Status} +import play.api.libs.json.{JsArray, JsNumber, JsString, JsValue, Json, OFormat} + +import java.time.LocalDateTime + +case class RedirectRuleExport(id: RedirectRuleId = RedirectRuleId(), + target: String, + searchInputId: SearchInputId, + lastUpdate: LocalDateTime, + status: Int) extends JsonExportable { + + def getTableName: JsString = JsString("redirect_rule") + + def getColumns: JsValue = { + JsArray( + IndexedSeq ( + JsString("id"), + JsString("target"), + JsString("search_input_id"), + JsString("last_update"), + JsString("status") + ) + ) + } + + def getRow: JsValue = { + JsArray( + IndexedSeq ( + JsString(id.toString), + JsString(target), + JsString(searchInputId.toString), + JsString(lastUpdate.toString), + JsNumber(status) + ) + ) + } +} + +object RedirectRuleExport extends CommonRuleFields { + + val TABLE_NAME = "redirect_rule" + val TARGET = "target" + + implicit val jsonFormat: OFormat[RedirectRule] = Json.format[RedirectRule] + + //override def fieldNames: Seq[String] = super.fieldNames :+ TARGET + + //override def orderByField: String = TARGET + + val sqlParser: RowParser[RedirectRuleExport] = { + get[RedirectRuleId](s"$TABLE_NAME.$ID") ~ + get[String](s"$TABLE_NAME.$TARGET") ~ + get[SearchInputId](s"$TABLE_NAME.$SEARCH_INPUT_ID") ~ + get[LocalDateTime](s"$TABLE_NAME.$LAST_UPDATE") ~ + get[Int](s"$TABLE_NAME.$STATUS") map { case id ~ target ~ searchInputId ~ lastUpdate ~ status => + RedirectRuleExport(id, target, searchInputId, lastUpdate, status) + } + } + +} \ No newline at end of file diff --git a/app/models/rules/Rule.scala b/app/models/rules/Rule.scala index d3288852..4fc2265c 100644 --- a/app/models/rules/Rule.scala +++ b/app/models/rules/Rule.scala @@ -2,10 +2,11 @@ package models.rules import java.sql.Connection import java.time.LocalDateTime - import anorm._ import models.Id +import models.`export`.JsonExportable import models.input.SearchInputId +import play.api.Logging trait Rule { @@ -35,7 +36,7 @@ trait RuleWithTerm extends Rule { } -trait CommonRuleFields { +trait CommonRuleFields extends Logging { val ID = "id" val STATUS = "status" @@ -57,7 +58,7 @@ trait RuleObject[T <: Rule] extends CommonRuleFields { def updateForSearchInput(searchInputId: SearchInputId, rules: Seq[T])(implicit connection: Connection) { // TODO consider to really determine an update/delete diff to ensure that last_update timestamps only updated for affected rules - + logger.debug("RuleObject:updateForSearchInput") SQL"delete from #$TABLE_NAME where #$SEARCH_INPUT_ID = $searchInputId".execute() if (rules.nonEmpty) { @@ -74,6 +75,7 @@ trait RuleObject[T <: Rule] extends CommonRuleFields { } def loadByInputId(searchInputId: SearchInputId)(implicit connection: Connection): List[T] = { + logger.debug("RuleObject:loadByInputId") SQL"select * from #$TABLE_NAME where #$SEARCH_INPUT_ID = $searchInputId order by #$orderByField".as(sqlParser.*) } diff --git a/app/models/rules/SynonymRule.scala b/app/models/rules/SynonymRule.scala index 0a16131a..ece67b96 100644 --- a/app/models/rules/SynonymRule.scala +++ b/app/models/rules/SynonymRule.scala @@ -5,8 +5,11 @@ import anorm.SqlParser.get import anorm._ import models.`export`.{Something, SomethingId} import models.input.SearchInputId +import models.rules.FilterRule.{LAST_UPDATE, SEARCH_INPUT_ID, TABLE_NAME} import models.{Id, IdObject, Status} -import play.api.libs.json.{Json, OFormat} +import play.api.libs.json.{JsArray, JsNumber, JsString, JsValue, Json, OFormat} + +import java.time.LocalDateTime class SynonymRuleId(id: String) extends Id(id) object SynonymRuleId extends IdObject[SynonymRuleId](new SynonymRuleId(_)) @@ -21,6 +24,7 @@ case class SynonymRule(id: SynonymRuleId = SynonymRuleId(), SynonymRule.TYPE -> synonymType ) } + } object SynonymRule extends RuleObjectWithTerm[SynonymRule] { diff --git a/app/models/rules/SynonymRuleExport.scala b/app/models/rules/SynonymRuleExport.scala new file mode 100644 index 00000000..c9bd4ebe --- /dev/null +++ b/app/models/rules/SynonymRuleExport.scala @@ -0,0 +1,81 @@ +package models.rules + +import java.sql.Connection +import anorm.SqlParser.get +import anorm._ +import models.`export`.{JsonExportable, Something, SomethingId} +import models.input.SearchInputId +import models.rules.FilterRule.{LAST_UPDATE, SEARCH_INPUT_ID, TABLE_NAME} +import models.{Id, IdObject, Status} +import play.api.libs.json.{JsArray, JsNumber, JsString, JsValue, Json, OFormat} + +import java.time.LocalDateTime + +case class SynonymRuleExport(id: SynonymRuleId, + synonymType: Int, + term: String, + status: Int, + searchInputId: SearchInputId, + lastUpdate: LocalDateTime) extends JsonExportable { + + def getTableName: JsString = JsString("synonym_rule") + + def getColumns: JsValue = { + JsArray( + IndexedSeq ( + JsString("id"), + JsString("synonymType"), + JsString("term"), + JsString("search_input_id"), + JsString("last_update"), + JsString("status") + ) + ) + } + + def getRow: JsValue = { + JsArray( + IndexedSeq ( + JsString(id.toString), + JsNumber(synonymType), + JsString(term), + JsString(searchInputId.toString), + JsString(lastUpdate.toString), + JsNumber(status) + ) + ) + } +} + +object SynonymRuleExport extends CommonRuleFields { + + val TABLE_NAME = "synonym_rule" + val TYPE = "synonym_type" + + val TYPE_UNDIRECTED = 0 + val TYPE_DIRECTED = 1 + + implicit val jsonFormat: OFormat[SynonymRule] = Json.format[SynonymRule] + + //override def fieldNames: Seq[String] = super.fieldNames :+ TYPE + + val sqlParser: RowParser[SynonymRuleExport] = { + get[SynonymRuleId](s"$TABLE_NAME.$ID") ~ + get[Int](s"$TABLE_NAME.$TYPE") ~ + get[String](s"$TABLE_NAME.$TERM") ~ + get[Int](s"$TABLE_NAME.$STATUS") ~ + get[SearchInputId](s"$TABLE_NAME.$SEARCH_INPUT_ID") ~ + get[LocalDateTime](s"$TABLE_NAME.$LAST_UPDATE") map { case id ~ synonymType ~ term ~ status ~ searchInputId ~ lastUpdate => + SynonymRuleExport(id, synonymType, term, status, searchInputId, lastUpdate) + } + } +// +// def loadUndirectedBySearchInputIds(ids: Seq[SearchInputId])(implicit connection: Connection): Map[SearchInputId, Seq[SynonymRule]] = { +// ids.grouped(100).toSeq.flatMap { idGroup => +// SQL"select * from #$TABLE_NAME where #$TYPE = #$TYPE_UNDIRECTED AND #$SEARCH_INPUT_ID in ($idGroup)".as((sqlParser ~ get[SearchInputId](SEARCH_INPUT_ID)).*).map { case rule ~ id => +// id -> rule +// } +// }.groupBy(_._1).mapValues(_.map(_._2)) +// } + +} \ No newline at end of file diff --git a/app/models/rules/UpDownRule.scala b/app/models/rules/UpDownRule.scala index 9f446622..ef966ddf 100644 --- a/app/models/rules/UpDownRule.scala +++ b/app/models/rules/UpDownRule.scala @@ -4,7 +4,9 @@ import anorm.SqlParser.get import anorm.{NamedParameter, RowParser, ~} import models.input.SearchInputId import models.{Id, IdObject, Status} -import play.api.libs.json.{Json, OFormat} +import play.api.libs.json.{JsArray, JsNumber, JsString, JsValue, Json, OFormat} + +import java.time.LocalDateTime class UpDownRuleId(id: String) extends Id(id) object UpDownRuleId extends IdObject[UpDownRuleId](new UpDownRuleId(_)) @@ -22,6 +24,7 @@ case class UpDownRule(id: UpDownRuleId = UpDownRuleId(), UpDownRule.UP_DOWN_TYPE -> upDownType ) } + } object UpDownRule extends RuleObjectWithTerm[UpDownRule] { diff --git a/app/models/rules/UpdownRuleExport.scala b/app/models/rules/UpdownRuleExport.scala new file mode 100644 index 00000000..9b6454d7 --- /dev/null +++ b/app/models/rules/UpdownRuleExport.scala @@ -0,0 +1,77 @@ +package models.rules + +import anorm.SqlParser.get +import anorm.{NamedParameter, RowParser, ~} +import models.`export`.JsonExportable +import models.input.SearchInputId +import models.{Id, IdObject, Status} +import play.api.libs.json.{JsArray, JsNumber, JsString, JsValue, Json, OFormat} + +import java.time.LocalDateTime + +case class UpDownRuleExport(id: UpDownRuleId = UpDownRuleId(), + upDownType: Int, + boostMalusValue: Int, + term: String, + status: Int, + searchInputId: SearchInputId, + lastUpdate: LocalDateTime) extends JsonExportable { + + def getTableName: JsString = JsString("up_down_rule") + + def getColumns: JsValue = { + JsArray( + IndexedSeq ( + JsString("id"), + JsString("up_down_type"), + JsString("boost_malus_type"), + JsString("term"), + JsString("search_input_id"), + JsString("last_update"), + JsString("status") + ) + ) + } + + def getRow: JsValue = { + JsArray( + IndexedSeq ( + JsString(id.toString), + JsNumber(upDownType), + JsNumber(boostMalusValue), + JsString(term), + JsNumber(status), + JsString(searchInputId.toString), + JsString(lastUpdate.toString) + ) + ) + } +} + +object UpDownRuleExport extends CommonRuleFields { + + val TABLE_NAME = "up_down_rule" + + val UP_DOWN_TYPE = "up_down_type" + val BOOST_MALUS_VALUE = "boost_malus_value" + + val TYPE_UP = 0 + val TYPE_DOWN = 1 +// +// override def fieldNames: Seq[String] = super.fieldNames ++ Seq(BOOST_MALUS_VALUE, UP_DOWN_TYPE) + + implicit val jsonFormat: OFormat[UpDownRuleExport] = Json.format[UpDownRuleExport] + + val sqlParser: RowParser[UpDownRuleExport] = { + get[UpDownRuleId](s"$TABLE_NAME.$ID") ~ + get[Int](s"$TABLE_NAME.$UP_DOWN_TYPE") ~ + get[Int](s"$TABLE_NAME.$BOOST_MALUS_VALUE") ~ + get[String](s"$TABLE_NAME.$TERM") ~ + get[Int](s"$TABLE_NAME.$STATUS") ~ + get[SearchInputId](s"$TABLE_NAME.$SEARCH_INPUT_ID") ~ + get[LocalDateTime](s"$TABLE_NAME.$LAST_UPDATE") map { case id ~ upDownType ~ boostMalusValue ~ term ~ status ~ searchInputId ~ lastUpdate => + UpDownRuleExport(id, upDownType, boostMalusValue, term, status, searchInputId, lastUpdate) + } + } + +} \ No newline at end of file diff --git a/conf/routes b/conf/routes index 58c3a5e0..2ba2ecee 100644 --- a/conf/routes +++ b/conf/routes @@ -39,7 +39,7 @@ GET /api/v1/report/activity-report/:solrIndexId controllers.ApiC GET /api/v1/version/latest-info controllers.ApiController.getLatestVersionInfo() GET /api/v1/solr-index/:solrIndexId/something controllers.ApiController.getSomething(solrIndexId: String) PUT /api/v1/put-something controllers.ApiController.putSomething -GET /api/v1/get-somethings controllers.ApiController.getSomethings +GET /api/v1/get-export controllers.ApiController.getDatabaseJson # Map static resources from the /public folder to the /assets URL path GET /*file controllers.FrontendController.assetOrDefault(file) diff --git a/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.ts b/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.ts index 8b00dbfc..8eb9352b 100644 --- a/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.ts +++ b/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.ts @@ -85,7 +85,7 @@ export class ChrisRulesCollectionCreateComponent implements OnInit, OnChanges { console.log("getRows()"); //this.solrService.putSomething2("something3").then(() => console.log("done")); //this.solrService.putSomething2("something4").then(() => console.log("done")); - this.solrService.getSomethings().then( + this.solrService.getExport().then( result => { console.log(result) this.showSuccessMsg.emit("Get Rows: OK, see console log") @@ -95,7 +95,7 @@ export class ChrisRulesCollectionCreateComponent implements OnInit, OnChanges { download(event: Event) { console.log("download()"); - this.solrService.getSomethings().then( + this.solrService.getExport().then( result => { var str = JSON.stringify(result); this.downloadStringAsFile( diff --git a/frontend/src/app/services/solr.service.ts b/frontend/src/app/services/solr.service.ts index 771be249..18b2843a 100644 --- a/frontend/src/app/services/solr.service.ts +++ b/frontend/src/app/services/solr.service.ts @@ -166,11 +166,11 @@ export class SolrService { .toPromise(); } - getSomethings() { + getExport() { const headers = { headers: this.jsonHeader }; const body = {}; return this.http - .get(`${this.baseUrl}/get-somethings`, body) + .get(`${this.baseUrl}/get-export`, body) .toPromise(); } diff --git a/run_helper.sh b/run_helper.sh index 35a74380..b17f665f 100755 --- a/run_helper.sh +++ b/run_helper.sh @@ -1,6 +1,7 @@ #!/bin/bash source ~/.zshrc export SMUI_TOGGLE_SPELLING=true +export SMUI_TOGGLE_EVENTHISTORY=true #sbt "run -Dconfig.file=./smui-dev.conf 9000" #sbt "run -Dconfig.file=./smui-dev.conf 9000" sbt run "-Dconfig.file=./smui-dev.conf 9000" From 084eed64040db400c56e702031df827b7d9339a7 Mon Sep 17 00:00:00 2001 From: Chris Morley Date: Tue, 31 May 2022 16:58:33 -0400 Subject: [PATCH 13/25] delete extra comments --- app/models/rules/FilterRuleExport.scala | 4 ---- app/models/rules/RedirectRuleExport.scala | 4 ---- app/models/rules/SynonymRuleExport.scala | 10 ---------- app/models/rules/UpdownRuleExport.scala | 2 -- 4 files changed, 20 deletions(-) diff --git a/app/models/rules/FilterRuleExport.scala b/app/models/rules/FilterRuleExport.scala index 5e683804..6eecb5cc 100644 --- a/app/models/rules/FilterRuleExport.scala +++ b/app/models/rules/FilterRuleExport.scala @@ -10,10 +10,6 @@ import play.api.libs.json.{JsArray, JsNumber, JsString, JsValue, Json, OFormat} import java.time.LocalDateTime -//class FilterRuleId(id: String) extends Id(id) -//object FilterRuleId extends IdObject[FilterRuleId](new FilterRuleId(_)) - - case class FilterRuleExport(id: FilterRuleId, term: String, isActive: Boolean, diff --git a/app/models/rules/RedirectRuleExport.scala b/app/models/rules/RedirectRuleExport.scala index c2026a78..da99ca00 100644 --- a/app/models/rules/RedirectRuleExport.scala +++ b/app/models/rules/RedirectRuleExport.scala @@ -49,10 +49,6 @@ object RedirectRuleExport extends CommonRuleFields { implicit val jsonFormat: OFormat[RedirectRule] = Json.format[RedirectRule] - //override def fieldNames: Seq[String] = super.fieldNames :+ TARGET - - //override def orderByField: String = TARGET - val sqlParser: RowParser[RedirectRuleExport] = { get[RedirectRuleId](s"$TABLE_NAME.$ID") ~ get[String](s"$TABLE_NAME.$TARGET") ~ diff --git a/app/models/rules/SynonymRuleExport.scala b/app/models/rules/SynonymRuleExport.scala index c9bd4ebe..b168698c 100644 --- a/app/models/rules/SynonymRuleExport.scala +++ b/app/models/rules/SynonymRuleExport.scala @@ -57,8 +57,6 @@ object SynonymRuleExport extends CommonRuleFields { implicit val jsonFormat: OFormat[SynonymRule] = Json.format[SynonymRule] - //override def fieldNames: Seq[String] = super.fieldNames :+ TYPE - val sqlParser: RowParser[SynonymRuleExport] = { get[SynonymRuleId](s"$TABLE_NAME.$ID") ~ get[Int](s"$TABLE_NAME.$TYPE") ~ @@ -69,13 +67,5 @@ object SynonymRuleExport extends CommonRuleFields { SynonymRuleExport(id, synonymType, term, status, searchInputId, lastUpdate) } } -// -// def loadUndirectedBySearchInputIds(ids: Seq[SearchInputId])(implicit connection: Connection): Map[SearchInputId, Seq[SynonymRule]] = { -// ids.grouped(100).toSeq.flatMap { idGroup => -// SQL"select * from #$TABLE_NAME where #$TYPE = #$TYPE_UNDIRECTED AND #$SEARCH_INPUT_ID in ($idGroup)".as((sqlParser ~ get[SearchInputId](SEARCH_INPUT_ID)).*).map { case rule ~ id => -// id -> rule -// } -// }.groupBy(_._1).mapValues(_.map(_._2)) -// } } \ No newline at end of file diff --git a/app/models/rules/UpdownRuleExport.scala b/app/models/rules/UpdownRuleExport.scala index 9b6454d7..61ca001c 100644 --- a/app/models/rules/UpdownRuleExport.scala +++ b/app/models/rules/UpdownRuleExport.scala @@ -57,8 +57,6 @@ object UpDownRuleExport extends CommonRuleFields { val TYPE_UP = 0 val TYPE_DOWN = 1 -// -// override def fieldNames: Seq[String] = super.fieldNames ++ Seq(BOOST_MALUS_VALUE, UP_DOWN_TYPE) implicit val jsonFormat: OFormat[UpDownRuleExport] = Json.format[UpDownRuleExport] From 95f00303c9de37c26f882373ea25d1981fc7679d Mon Sep 17 00:00:00 2001 From: Chris Morley Date: Tue, 31 May 2022 19:08:27 -0400 Subject: [PATCH 14/25] add tags and spellings tables to export --- app/models/SearchManagementRepository.scala | 1 - .../export/AlternativeSpellingExport.scala | 75 +++++ .../export/CanonicalSpellingExport.scala | 81 +++++ .../{rules => export}/DeleteRuleExport.scala | 11 +- app/models/export/Exporter.scala | 114 ++++--- .../{rules => export}/FilterRuleExport.scala | 11 +- app/models/export/InputTagExport.scala | 85 +++++ .../RedirectRuleExport.scala | 13 +- .../{input => export}/SearchInputExport.scala | 8 +- app/models/export/SolrIndexExport.scala | 58 ++++ app/models/export/Something.scala | 94 +++--- .../export/SuggestedSolrFieldExport.scala | 62 ++++ .../{rules => export}/SynonymRuleExport.scala | 11 +- .../export/TagInputAssociationExport.scala | 67 ++++ .../{rules => export}/UpdownRuleExport.scala | 40 ++- .../export/example_export_file.json.txt | 292 ++++++++++++++++++ app/models/rules/RedirectRule.scala | 29 +- 17 files changed, 890 insertions(+), 162 deletions(-) create mode 100644 app/models/export/AlternativeSpellingExport.scala create mode 100644 app/models/export/CanonicalSpellingExport.scala rename app/models/{rules => export}/DeleteRuleExport.scala (81%) rename app/models/{rules => export}/FilterRuleExport.scala (83%) create mode 100644 app/models/export/InputTagExport.scala rename app/models/{rules => export}/RedirectRuleExport.scala (81%) rename app/models/{input => export}/SearchInputExport.scala (86%) create mode 100644 app/models/export/SolrIndexExport.scala create mode 100644 app/models/export/SuggestedSolrFieldExport.scala rename app/models/{rules => export}/SynonymRuleExport.scala (85%) create mode 100644 app/models/export/TagInputAssociationExport.scala rename app/models/{rules => export}/UpdownRuleExport.scala (65%) create mode 100644 app/models/export/example_export_file.json.txt diff --git a/app/models/SearchManagementRepository.scala b/app/models/SearchManagementRepository.scala index 56f46565..fdd778fd 100644 --- a/app/models/SearchManagementRepository.scala +++ b/app/models/SearchManagementRepository.scala @@ -10,7 +10,6 @@ import play.api.db.DBApi import anorm._ import models.FeatureToggleModel.FeatureToggleService import models.SolrIndex.TABLE_NAME -import models.`export`.SomethingRow import models.export.{Exporter, Something, SomethingId} import models.input.{InputTag, InputTagId, PredefinedTag, SearchInput, SearchInputId, SearchInputWithRules, TagInputAssociation} import models.spellings.{CanonicalSpelling, CanonicalSpellingId, CanonicalSpellingWithAlternatives} diff --git a/app/models/export/AlternativeSpellingExport.scala b/app/models/export/AlternativeSpellingExport.scala new file mode 100644 index 00000000..9e317b26 --- /dev/null +++ b/app/models/export/AlternativeSpellingExport.scala @@ -0,0 +1,75 @@ +package models.`export` + +import anorm.SqlParser.get +import anorm.{RowParser, ~} +import models.`export`.JsonExportable +import models.input.SearchInputId +import models.rules.{CommonRuleFields, DeleteRuleId} +import models.spellings.{AlternativeSpellingId, CanonicalSpellingId} +import models.{SolrIndexId, Status, `export`} +import play.api.libs.json._ + +import java.time.LocalDateTime + +case class AlternativeSpellingExport(id: AlternativeSpellingId = AlternativeSpellingId(), + canonicalSpellingId: CanonicalSpellingId, + term: String, + status: Int, + lastUpdate: LocalDateTime) extends JsonExportable { + + def getTableName: JsString = JsString("alternative_spelling") + + def getColumns: JsValue = { + JsArray( + IndexedSeq ( + JsString("id"), + JsString("canonical_spelling_id"), + JsString("term"), + JsString("status"), + JsString("last_update") + ) + ) + } + + def getRow: JsValue = { + JsArray( + IndexedSeq ( + JsString(id.toString), + JsString(canonicalSpellingId.toString), + JsString(term), + JsNumber(status), + JsString(lastUpdate.toString) + ) + ) + } + +} + +object AlternativeSpellingExport { + + val TABLE_NAME = "alternative_spelling" + val ID = "id" + val CANONICAL_SPELLING_ID = "canonical_spelling_id" + val TERM = "term" + val STATUS = "status" + val LAST_UPDATE = "last_update" + + val sqlParser: RowParser[AlternativeSpellingExport] = { + get[AlternativeSpellingId](s"$TABLE_NAME.$ID") ~ + get[CanonicalSpellingId](s"$TABLE_NAME.$CANONICAL_SPELLING_ID") ~ + get[String](s"$TABLE_NAME.$TERM") ~ + get[Int](s"$TABLE_NAME.$STATUS") ~ + get[LocalDateTime](s"$TABLE_NAME.$LAST_UPDATE") map { + case id ~ canonicalSpellingId ~ term ~ status ~ lastUpdate => + AlternativeSpellingExport(id, canonicalSpellingId, term, status, lastUpdate) + } + } + + val selectAllStatement : String = { + s"select $TABLE_NAME.$ID, " + + s"$TABLE_NAME.$CANONICAL_SPELLING_ID, " + + s"$TABLE_NAME.$TERM, " + + s"$TABLE_NAME.$STATUS, " + + s"$TABLE_NAME.$LAST_UPDATE from $TABLE_NAME" + } +} \ No newline at end of file diff --git a/app/models/export/CanonicalSpellingExport.scala b/app/models/export/CanonicalSpellingExport.scala new file mode 100644 index 00000000..18dc847e --- /dev/null +++ b/app/models/export/CanonicalSpellingExport.scala @@ -0,0 +1,81 @@ +package models.`export` + +import anorm.SqlParser.get +import anorm.{RowParser, ~} +import models.`export`.JsonExportable +import models.input.SearchInputId +import models.rules.{CommonRuleFields, DeleteRuleId} +import models.spellings.CanonicalSpellingId +import models.{SolrIndexId, Status, `export`} +import play.api.libs.json._ + +import java.time.LocalDateTime + +case class CanonicalSpellingExport(id: CanonicalSpellingId = CanonicalSpellingId(), + solrIndexId: SolrIndexId, + term: String, + status: Int, + comment: String, + lastUpdate: LocalDateTime) extends JsonExportable { + + def getTableName: JsString = JsString("canonical_spelling") + + def getColumns: JsValue = { + JsArray( + IndexedSeq ( + JsString("id"), + JsString("solr_index_id"), + JsString("term"), + JsString("status"), + JsString("comment"), + JsString("last_update") + ) + ) + } + + def getRow: JsValue = { + JsArray( + IndexedSeq ( + JsString(id.toString), + JsString(solrIndexId.toString), + JsString(term), + JsNumber(status), + JsString(comment), + JsString(lastUpdate.toString) + ) + ) + } + +} + +object CanonicalSpellingExport { + + val TABLE_NAME = "canonical_spelling" + val ID = "id" + val SOLR_INDEX_ID = "solr_index_id" + val TERM = "term" + val STATUS = "status" + val COMMENT = "comment" + val LAST_UPDATE = "last_update" + + val sqlParser: RowParser[CanonicalSpellingExport] = { + get[CanonicalSpellingId](s"$TABLE_NAME.$ID") ~ + get[SolrIndexId](s"$TABLE_NAME.$SOLR_INDEX_ID") ~ + get[String](s"$TABLE_NAME.$TERM") ~ + get[Int](s"$TABLE_NAME.$STATUS") ~ + get[String](s"$TABLE_NAME.$COMMENT") ~ + get[LocalDateTime](s"$TABLE_NAME.$LAST_UPDATE") map { + case id ~ solrIndexId ~ term ~ status ~ comment ~ lastUpdate => + CanonicalSpellingExport(id, solrIndexId, term, status, comment, lastUpdate) + } + } + + val selectAllStatement : String = { + s"select $TABLE_NAME.$ID, " + + s"$TABLE_NAME.$SOLR_INDEX_ID, " + + s"$TABLE_NAME.$TERM, " + + s"$TABLE_NAME.$STATUS, " + + s"$TABLE_NAME.$COMMENT, " + + s"$TABLE_NAME.$LAST_UPDATE from $TABLE_NAME" + } +} \ No newline at end of file diff --git a/app/models/rules/DeleteRuleExport.scala b/app/models/export/DeleteRuleExport.scala similarity index 81% rename from app/models/rules/DeleteRuleExport.scala rename to app/models/export/DeleteRuleExport.scala index 6c140a3a..3c6ead47 100644 --- a/app/models/rules/DeleteRuleExport.scala +++ b/app/models/export/DeleteRuleExport.scala @@ -1,11 +1,12 @@ -package models.rules +package models.`export` import anorm.SqlParser.get import anorm.{RowParser, ~} import models.`export`.JsonExportable import models.input.SearchInputId -import models.{Id, IdObject, Status} -import play.api.libs.json.{JsArray, JsNumber, JsString, JsValue, Json, OFormat} +import models.rules.{CommonRuleFields, DeleteRuleId} +import models.{Status, `export`} +import play.api.libs.json._ import java.time.LocalDateTime @@ -56,8 +57,10 @@ object DeleteRuleExport extends CommonRuleFields { get[Int](s"$TABLE_NAME.$STATUS") ~ get[SearchInputId](s"$TABLE_NAME.$SEARCH_INPUT_ID") ~ get[LocalDateTime](s"$TABLE_NAME.$LAST_UPDATE") map { case id ~ term ~ status ~ searchInputId ~ lastUpdate => - DeleteRuleExport(id, term, Status.isActiveFromStatus(status), status, searchInputId, lastUpdate) + `export`.DeleteRuleExport(id, term, Status.isActiveFromStatus(status), status, searchInputId, lastUpdate) } } + val selectAllStatement = s"select id, term, search_input_id, last_update, status from delete_rule" + } \ No newline at end of file diff --git a/app/models/export/Exporter.scala b/app/models/export/Exporter.scala index 268965f9..5162b8e9 100644 --- a/app/models/export/Exporter.scala +++ b/app/models/export/Exporter.scala @@ -1,10 +1,10 @@ package models.`export` import anorm.SQL -import models.DatabaseExecutionContext +import models.{DatabaseExecutionContext, SuggestedSolrField} import models.FeatureToggleModel.FeatureToggleService -import models.input.{SearchInput, SearchInputExport} -import models.rules.{DeleteRule, DeleteRuleExport, FilterRule, FilterRuleExport, SynonymRule, SynonymRuleExport, UpDownRuleExport} +import models.input.SearchInput +import models.rules.{DeleteRule, FilterRule, SynonymRule} import play.api.libs.json.{JsArray, JsObject, JsString, JsValue} import play.api.Logging import play.api.db.DBApi @@ -31,19 +31,14 @@ class Exporter @Inject()(dbapi: DBApi, toggleService: FeatureToggleService)(impl def getAllTablesForJs1(tables : IndexedSeq[IndexedSeq[JsonExportable]], aggregation: Seq[JsValue]): JsValue = { if (tables.nonEmpty) { - val headTable = tables.head - val remainingTables = tables.drop(1) - println("remaining") - println(remainingTables.size) - + val headTable = tables.head // the first table + val remainingTables = tables.drop(1) // a list of the tables AFTER the first table if (headTable.nonEmpty) { - println("tablename") - println(headTable.seq(0).getTableName) + logger.debug("In Exporter.getAllTablesForJs1 : head table was non-empty") val name: (String, JsValue) = "tableName" -> headTable.seq(0).getTableName val cols: (String, JsValue) = "columns" -> headTable.seq(0).getColumns val rows: (String, JsValue) = "rows" -> asIndexedSeqForJs(headTable) val obj: (JsValue) = JsObject(IndexedSeq(name, cols, rows)) - println("calling recursion") getAllTablesForJs1(remainingTables, aggregation :+ obj) } else { logger.debug("In Exporter.getAllTablesForJs1 : return aggregation because headTable is empty") @@ -64,66 +59,101 @@ class Exporter @Inject()(dbapi: DBApi, toggleService: FeatureToggleService)(impl JsArray(target.toIndexedSeq) } -// def getSomethingsFromDatabase: IndexedSeq[Something] = db.withConnection { -// implicit connection => { -// logger.debug("In SearchManagementRepository:getSomethingsFromDatabase():1") -// val x : List[Something] = SQL(s"select id, value0, last_update from something") -// .as(SomethingRow.sqlParser.*) -// logger.debug("In SearchManagementRepository:getSomethingsFromDatabase():2") -// x.toIndexedSeq -// } -// } + def getSomethingsFromDatabase: IndexedSeq[Something] = db.withConnection { + implicit connection => { + SQL(Something.selectAllStatement).as(Something.sqlParser.*).toIndexedSeq + } + } def getSearchInputsFromDatabase: IndexedSeq[SearchInputExport] = db.withConnection { implicit connection => { - val x : List[SearchInputExport] = SQL(s"select id, term, solr_index_id, last_update, status, comment from search_input") - .as(SearchInputExport.sqlParser.*) - x.toIndexedSeq + SQL(SearchInputExport.selectAllStatement).as(SearchInputExport.sqlParser.*).toIndexedSeq } } def getDeleteRulesFromDatabase: IndexedSeq[DeleteRuleExport] = db.withConnection { implicit connection => { - val x : List[DeleteRuleExport] = SQL(s"select id, term, search_input_id, last_update, status from delete_rule") - .as(DeleteRuleExport.sqlParser.*) - x.toIndexedSeq + SQL(DeleteRuleExport.selectAllStatement).as(DeleteRuleExport.sqlParser.*).toIndexedSeq } } def getFilterRulesFromDatabase: IndexedSeq[FilterRuleExport] = db.withConnection { implicit connection => { - logger.debug("In getFilterRulesFromDatabase") - val x : List[FilterRuleExport] = SQL(s"select id, term, search_input_id, last_update, status from filter_rule") - .as(FilterRuleExport.sqlParser.*) - x.toIndexedSeq + SQL(FilterRuleExport.selectAllStatement).as(FilterRuleExport.sqlParser.*).toIndexedSeq } } def getSynonymRulesFromDatabase: IndexedSeq[SynonymRuleExport] = db.withConnection { implicit connection => { - val x : List[SynonymRuleExport] = SQL(s"select id, synonym_type, term, search_input_id, last_update, status from synonym_rule") - .as(SynonymRuleExport.sqlParser.*) - x.toIndexedSeq + SQL(SynonymRuleExport.selectAllStatement).as(SynonymRuleExport.sqlParser.*).toIndexedSeq } } def getUpDownRulesFromDatabase: IndexedSeq[UpDownRuleExport] = db.withConnection { implicit connection => { - val x : List[UpDownRuleExport] = SQL(s"select id, up_down_type, boost_malus_value, term, search_input_id, last_update, status from up_down_rule") - .as(UpDownRuleExport.sqlParser.*) - x.toIndexedSeq + SQL(UpDownRuleExport.selectAllStatement).as(UpDownRuleExport.sqlParser.*).toIndexedSeq } } + def getRedirectRulesFromDatabase: IndexedSeq[RedirectRuleExport] = db.withConnection { + implicit connection => { + SQL(RedirectRuleExport.selectAllStatement).as(RedirectRuleExport.sqlParser.*).toIndexedSeq + } + } + + def getSolrIndexFromDatabase: IndexedSeq[SolrIndexExport] = db.withConnection { + implicit connection => { + SQL(SolrIndexExport.selectAllStatement).as(SolrIndexExport.sqlParser.*).toIndexedSeq + } + } + + def getSuggestedSolrFieldsFromDatabase: IndexedSeq[SuggestedSolrFieldExport] = db.withConnection { + implicit connection => { + SQL(SuggestedSolrFieldExport.selectAllStatement).as(SuggestedSolrFieldExport.sqlParser.*).toIndexedSeq + } + } + + def getInputTagsFromDatabase: IndexedSeq[InputTagExport] = db.withConnection { + implicit connection => { + SQL(InputTagExport.selectAllStatement).as(InputTagExport.sqlParser.*).toIndexedSeq + } + } + + def getTagInputAssociationsFromDatabase: IndexedSeq[TagInputAssociationExport] = db.withConnection { + implicit connection => { + SQL(TagInputAssociationExport.selectAllStatement).as(TagInputAssociationExport.sqlParser.*).toIndexedSeq + } + } + + def getCanonicalSpellingsFromDatabase: IndexedSeq[CanonicalSpellingExport] = db.withConnection { + implicit connection => { + SQL(CanonicalSpellingExport.selectAllStatement).as(CanonicalSpellingExport.sqlParser.*).toIndexedSeq + } + } + + def getAlternativeSpellingsFromDatabase: IndexedSeq[AlternativeSpellingExport] = db.withConnection { + implicit connection => { + SQL(AlternativeSpellingExport.selectAllStatement).as(AlternativeSpellingExport.sqlParser.*).toIndexedSeq + } + } + + def getDatabaseJson: JsValue = { logger.debug("In getDatabaseJson") val tableSeq = IndexedSeq( - //getSomethingsFromDatabase, - getSearchInputsFromDatabase, - getDeleteRulesFromDatabase, - getFilterRulesFromDatabase, - getSynonymRulesFromDatabase, - getUpDownRulesFromDatabase + getSolrIndexFromDatabase, //1 + getSearchInputsFromDatabase, //2 + getRedirectRulesFromDatabase, //3 + getSynonymRulesFromDatabase, //4 + getUpDownRulesFromDatabase, //5 + getDeleteRulesFromDatabase, //6 + getFilterRulesFromDatabase, //7 + getSuggestedSolrFieldsFromDatabase, //8 + getInputTagsFromDatabase, //9 + getTagInputAssociationsFromDatabase, //10 + getCanonicalSpellingsFromDatabase, //11 + getAlternativeSpellingsFromDatabase //12 + //getSomethingsFromDatabase //13 ) getAllTablesForJs(tableSeq) } diff --git a/app/models/rules/FilterRuleExport.scala b/app/models/export/FilterRuleExport.scala similarity index 83% rename from app/models/rules/FilterRuleExport.scala rename to app/models/export/FilterRuleExport.scala index 6eecb5cc..aa3d1508 100644 --- a/app/models/rules/FilterRuleExport.scala +++ b/app/models/export/FilterRuleExport.scala @@ -1,12 +1,11 @@ -package models.rules +package models.export import anorm.SqlParser.get import anorm.{RowParser, ~} -import models.`export`.JsonExportable import models.input.SearchInputId -import models.rules.DeleteRule.{LAST_UPDATE, SEARCH_INPUT_ID, TABLE_NAME} -import models.{Id, IdObject, Status} -import play.api.libs.json.{JsArray, JsNumber, JsString, JsValue, Json, OFormat} +import models.rules.{CommonRuleFields, FilterRule, FilterRuleId} +import models.{Status, `export`} +import play.api.libs.json._ import java.time.LocalDateTime @@ -61,4 +60,6 @@ object FilterRuleExport extends CommonRuleFields { } } + val selectAllStatement = s"select $TABLE_NAME.$ID, $TABLE_NAME.$TERM, $TABLE_NAME.$STATUS, $TABLE_NAME.$SEARCH_INPUT_ID, $TABLE_NAME.$LAST_UPDATE from $TABLE_NAME" + } \ No newline at end of file diff --git a/app/models/export/InputTagExport.scala b/app/models/export/InputTagExport.scala new file mode 100644 index 00000000..b8d942aa --- /dev/null +++ b/app/models/export/InputTagExport.scala @@ -0,0 +1,85 @@ +package models.export + +import anorm.SqlParser.get +import anorm.{RowParser, ~} +import models.SolrIndexId +import models.input.InputTagId +import models.rules.CommonRuleFields +import play.api.libs.json._ + +import java.time.LocalDateTime + +case class InputTagExport(id: InputTagId, + solrIndexId: SolrIndexId, + property: String, + tagValue: String, + exported: Int, + predefined: Int, + lastUpdate: LocalDateTime) extends JsonExportable { + + def getTableName: JsString = JsString("input_tag") + + def getColumns: JsValue = { + JsArray( + IndexedSeq ( + JsString("id"), + JsString("solr_index_id"), + JsString("property"), + JsString("tag_value"), + JsString("exported"), + JsString("predefined"), + JsString("last_update") + ) + ) + } + + def getRow: JsValue = { + JsArray( + IndexedSeq ( + JsString(id.toString), + JsString(solrIndexId.toString), + JsString(property), + JsString(tagValue), + JsNumber(exported), + JsNumber(predefined), + JsString(lastUpdate.toString) + ) + ) + } +} + +object InputTagExport { + + val TABLE_NAME = "input_tag" + val ID = "id" + val SOLR_INDEX_ID = "solr_index_id" + val PROPERTY = "property" + val TAG_VALUE = "tag_value" + val EXPORTED = "exported" + val PREDEFINED = "predefined" + val LAST_UPDATE = "last_update" + + val sqlParser: RowParser[InputTagExport] = { + get[InputTagId](s"$TABLE_NAME.$ID") ~ + get[SolrIndexId](s"$TABLE_NAME.$SOLR_INDEX_ID") ~ + get[String](s"$TABLE_NAME.$PROPERTY") ~ + get[String](s"$TABLE_NAME.$TAG_VALUE") ~ + get[Int](s"$TABLE_NAME.$EXPORTED") ~ + get[Int](s"$TABLE_NAME.$PREDEFINED") ~ + get[LocalDateTime](s"$TABLE_NAME.$LAST_UPDATE") map { + case id ~ solrIndexId ~ property ~ tagValue ~ exported ~ predefined ~ lastUpdate => + InputTagExport(id, solrIndexId, property, tagValue, exported, predefined, lastUpdate) + } + } + + val selectAllStatement: String = { + s"select $TABLE_NAME.$ID, " + + s"$TABLE_NAME.$SOLR_INDEX_ID, " + + s"$TABLE_NAME.$PROPERTY, " + + s"$TABLE_NAME.$TAG_VALUE, " + + s"$TABLE_NAME.$EXPORTED, " + + s"$TABLE_NAME.$PREDEFINED, " + + s"$TABLE_NAME.$LAST_UPDATE from $TABLE_NAME" + } + +} \ No newline at end of file diff --git a/app/models/rules/RedirectRuleExport.scala b/app/models/export/RedirectRuleExport.scala similarity index 81% rename from app/models/rules/RedirectRuleExport.scala rename to app/models/export/RedirectRuleExport.scala index da99ca00..18b351dc 100644 --- a/app/models/rules/RedirectRuleExport.scala +++ b/app/models/export/RedirectRuleExport.scala @@ -1,11 +1,12 @@ -package models.rules +package models.`export` import anorm.SqlParser.get -import anorm.{NamedParameter, RowParser, ~} +import anorm.{RowParser, ~} +import models.`export` import models.`export`.JsonExportable import models.input.SearchInputId -import models.{Id, IdObject, Status} -import play.api.libs.json.{JsArray, JsNumber, JsString, JsValue, Json, OFormat} +import models.rules.{CommonRuleFields, RedirectRule, RedirectRuleId} +import play.api.libs.json._ import java.time.LocalDateTime @@ -47,8 +48,6 @@ object RedirectRuleExport extends CommonRuleFields { val TABLE_NAME = "redirect_rule" val TARGET = "target" - implicit val jsonFormat: OFormat[RedirectRule] = Json.format[RedirectRule] - val sqlParser: RowParser[RedirectRuleExport] = { get[RedirectRuleId](s"$TABLE_NAME.$ID") ~ get[String](s"$TABLE_NAME.$TARGET") ~ @@ -59,4 +58,6 @@ object RedirectRuleExport extends CommonRuleFields { } } + val selectAllStatement = s"select $TABLE_NAME.$ID, $TABLE_NAME.$TARGET, $TABLE_NAME.$SEARCH_INPUT_ID, $TABLE_NAME.$LAST_UPDATE, $TABLE_NAME.$STATUS from $TABLE_NAME" + } \ No newline at end of file diff --git a/app/models/input/SearchInputExport.scala b/app/models/export/SearchInputExport.scala similarity index 86% rename from app/models/input/SearchInputExport.scala rename to app/models/export/SearchInputExport.scala index 7dc68ec4..65db5156 100644 --- a/app/models/input/SearchInputExport.scala +++ b/app/models/export/SearchInputExport.scala @@ -1,12 +1,12 @@ -package models.input +package models.`export` import anorm.SqlParser.get import anorm._ import models._ import models.`export`.JsonExportable +import models.input.{SearchInput, SearchInputId} import play.api.libs.json._ -import java.sql.Connection import java.time.LocalDateTime case class SearchInputExport(id: SearchInputId, @@ -65,8 +65,10 @@ object SearchInputExport { get[LocalDateTime](s"$TABLE_NAME.$LAST_UPDATE") ~ get[Int](s"$TABLE_NAME.$STATUS") ~ get[String](s"$TABLE_NAME.$COMMENT") map { case id ~ term ~ indexId ~ lastUpdate ~ status ~ comment => - SearchInputExport(id, indexId, term, lastUpdate, status, comment) + models.`export`.SearchInputExport(id, indexId, term, lastUpdate, status, comment) } } + val selectAllStatement = s"select id, term, solr_index_id, last_update, status, comment from search_input" + } diff --git a/app/models/export/SolrIndexExport.scala b/app/models/export/SolrIndexExport.scala new file mode 100644 index 00000000..2d2a6217 --- /dev/null +++ b/app/models/export/SolrIndexExport.scala @@ -0,0 +1,58 @@ +package models.`export` + +import anorm.SqlParser.get +import anorm.{RowParser, SQL, ~} +import models.{SolrIndexId, `export`} +import models.rules.CommonRuleFields +import play.api.libs.json._ + +import java.time.LocalDateTime + +case class SolrIndexExport(id: SolrIndexId, + name: String, + description: String, + lastUpdate: LocalDateTime) extends JsonExportable { + + def getTableName: JsString = JsString("solr_index") + + def getColumns: JsValue = { + JsArray( + IndexedSeq ( + JsString("id"), + JsString("name"), + JsString("description"), + JsString("last_update") + ) + ) + } + + def getRow: JsValue = { + JsArray( + IndexedSeq ( + JsString(id.toString), + JsString(name), + JsString(description), + JsString(lastUpdate.toString) + ) + ) + } +} + +object SolrIndexExport extends CommonRuleFields { + + val TABLE_NAME = "solr_index" + val NAME = "name" + val DESCRIPTION = "description" + + val sqlParser: RowParser[SolrIndexExport] = { + get[SolrIndexId](s"$TABLE_NAME.$ID") ~ + get[String](s"$TABLE_NAME.$ID") ~ + get[String](s"$TABLE_NAME.$DESCRIPTION") ~ + get[LocalDateTime](s"$TABLE_NAME.$LAST_UPDATE") map { case id ~ name ~ description ~ lastUpdate => + SolrIndexExport(id, name, description, lastUpdate) + } + } + + val selectAllStatement = s"select $TABLE_NAME.$ID, $TABLE_NAME.$ID, $TABLE_NAME.$DESCRIPTION, $TABLE_NAME.$LAST_UPDATE from $TABLE_NAME" + +} \ No newline at end of file diff --git a/app/models/export/Something.scala b/app/models/export/Something.scala index 7cd71879..2bc950bf 100644 --- a/app/models/export/Something.scala +++ b/app/models/export/Something.scala @@ -1,38 +1,27 @@ package models.`export` import anorm.SqlParser.get -import anorm.{NamedParameter, RowParser, ~} -import models.`export`.SomethingRow.{id, last_update, myJavascriptObject, value0} -import models.input.SearchInputId -import models.rules.Rule.{ID, LAST_UPDATE, SEARCH_INPUT_ID, STATUS} -import models.rules.{RuleWithTerm, SynonymRule, SynonymRuleId} +import anorm.{RowParser, ~} +import models.`export`.Something.myJavascriptObject import models.{Id, IdObject} -import play.api.libs.json.{JsArray, JsNull, JsNumber, JsObject, JsString, JsValue, Json, Writes} +import play.api.libs.json.{JsArray, JsString, JsValue, Json, Writes} import java.time.LocalDateTime import java.util.UUID +class SomethingId(id: String) extends Id(id) +object SomethingId extends IdObject[SomethingId](new SomethingId(_)) + case class Something(id: SomethingId = SomethingId(), - value0: String, + value_0: String, last_update: LocalDateTime) extends JsonExportable { -// override def toNamedParameters(searchInputId: SearchInputId): Seq[NamedParameter] = { -// super.toNamedParameters(searchInputId) ++ Seq[NamedParameter]( -// .TYPE -> synonymType -// ) -// } - def toNamedParameters(id: SomethingId): Seq[NamedParameter] = Seq( - ID -> id.id, - value0 -> value0, - LAST_UPDATE -> LocalDateTime.now() - ) implicit val writer: Writes[String] = new Writes[(String)] { def writes(t: (String)): JsValue = { Json.obj( - "value0" -> myJavascriptObject.value0, - "value1" -> myJavascriptObject.value1, - "value2" -> myJavascriptObject.value2, - "value3" -> myJavascriptObject.value3) + "id" -> myJavascriptObject.id, + "value_0" -> myJavascriptObject.value_0, + "last_update" -> myJavascriptObject.last_update) } } @@ -42,7 +31,7 @@ case class Something(id: SomethingId = SomethingId(), JsArray( IndexedSeq ( JsString("id"), - JsString("value0"), + JsString("value_0"), JsString("last_update") ) ) @@ -52,7 +41,7 @@ case class Something(id: SomethingId = SomethingId(), JsArray( IndexedSeq ( JsString(id.toString), - JsString(value0), + JsString(value_0), JsString(last_update.toString) ) ) @@ -60,49 +49,39 @@ case class Something(id: SomethingId = SomethingId(), } -class SomethingId(id: String) extends Id(id) -object SomethingId extends IdObject[SomethingId](new SomethingId(_)) - case class MyJsObject( - value0: JsValue, - value1: JsValue, - value2: JsValue, - value3: JsValue + id: JsValue, + value_0: JsValue, + last_update: JsValue ) -object SomethingRow extends Something(id=SomethingId(), value0="", last_update=LocalDateTime.now()) { +object Something { val TABLE_NAME = "something" - val TYPE = "something" + val ID = "id" + val VALUE_0 = "value_0" + val LAST_UPDATE = "last_update" val sqlParser: RowParser[Something] = { - get[SomethingId] (s"$TABLE_NAME.id") ~ - get[String](s"$TABLE_NAME.value0") ~ - get[LocalDateTime](s"$TABLE_NAME.last_update") map { case id ~ value0 ~ last_update => - Something(id, value0, last_update) + get[SomethingId] (s"$TABLE_NAME.$ID") ~ + get[String](s"$TABLE_NAME.$VALUE_0") ~ + get[LocalDateTime](s"$TABLE_NAME.last_update") map { case id ~ value_0 ~ last_update => + Something(id, value_0, last_update) } } - val myJavascriptObject: MyJsObject = - MyJsObject( - value0 = new JsString("id = " + id), - value1 = JsObject(Seq("simpleObject" -> JsString("simpleStringValue"))), - value2 = JsObject( - Seq( - "aString" -> JsString("simpleString"), - "aNumber" -> JsNumber(4.3), - "aNull" -> JsNull - ) - ), - value3 = JsArray( - IndexedSeq( - new JsString("first value of array"), - new JsString("second value of array")) - ) - ) + val selectAllStatement : String = { + s"select $TABLE_NAME.$ID, " + + s"$TABLE_NAME.$VALUE_0, " + + s"$TABLE_NAME.$LAST_UPDATE from $TABLE_NAME" + } -// def getAsJsonRow(): JsObject = { -// value1 = JsObject(Seq("simpleObject" -> JsString("simpleStringValue"))), + val myJavascriptObject: MyJsObject = { + MyJsObject( + id = JsString(UUID.randomUUID().toString), + value_0 = JsString("this is some value for value_0"), + last_update = JsString(LocalDateTime.now().toString) +// value1 = JsObject(Seq("simpleObject" -> JsString("simpleStringValue"))), // value2 = JsObject( // Seq( // "aString" -> JsString("simpleString"), @@ -115,8 +94,7 @@ object SomethingRow extends Something(id=SomethingId(), value0="", last_update=L // new JsString("first value of array"), // new JsString("second value of array")) // ) -// ) -// } - + ) + } } diff --git a/app/models/export/SuggestedSolrFieldExport.scala b/app/models/export/SuggestedSolrFieldExport.scala new file mode 100644 index 00000000..28813572 --- /dev/null +++ b/app/models/export/SuggestedSolrFieldExport.scala @@ -0,0 +1,62 @@ +package models.`export` + +import anorm.SqlParser.get +import anorm._ +import models._ +import models.`export`.JsonExportable +import models.input.{SearchInput, SearchInputId} +import play.api.libs.json._ + +import java.time.LocalDateTime + +case class SuggestedSolrFieldExport(id: SuggestedSolrFieldId, + name: String, + solrIndexId: SolrIndexId, + lastUpdate: LocalDateTime) extends JsonExportable { + + def getTableName: JsString = JsString("suggested_solr_field") + + def getRow: JsValue = { + JsArray( + IndexedSeq ( + JsString(id.toString), + JsString(name), + JsString(solrIndexId.toString), + JsString(lastUpdate.toString) + ) + ) + } + + def getColumns: JsValue = { + JsArray( + IndexedSeq ( + JsString("id"), + JsString("name"), + JsString("solr_index_id"), + JsString("last_update") + ) + ) + } + +} + +object SuggestedSolrFieldExport { + + val TABLE_NAME = "suggested_solr_field" + val ID = "id" + val NAME = "name" + val SOLR_INDEX_ID = "solr_index_id" + val LAST_UPDATE = "last_update" + + val sqlParser: RowParser[SuggestedSolrFieldExport] = { + get[SuggestedSolrFieldId](s"$TABLE_NAME.$ID") ~ + get[String](s"$TABLE_NAME.$NAME") ~ + get[SolrIndexId](s"$TABLE_NAME.$SOLR_INDEX_ID") ~ + get[LocalDateTime](s"$TABLE_NAME.$LAST_UPDATE") map { case id ~ name ~ solrIndexId ~ lastUpdate => + SuggestedSolrFieldExport(id, name, solrIndexId, lastUpdate) + } + } + + val selectAllStatement = s"select $TABLE_NAME.$ID, $TABLE_NAME.$NAME, $TABLE_NAME.$SOLR_INDEX_ID, $TABLE_NAME.$LAST_UPDATE from $TABLE_NAME" + +} diff --git a/app/models/rules/SynonymRuleExport.scala b/app/models/export/SynonymRuleExport.scala similarity index 85% rename from app/models/rules/SynonymRuleExport.scala rename to app/models/export/SynonymRuleExport.scala index b168698c..46928b55 100644 --- a/app/models/rules/SynonymRuleExport.scala +++ b/app/models/export/SynonymRuleExport.scala @@ -1,13 +1,10 @@ -package models.rules +package models.export -import java.sql.Connection import anorm.SqlParser.get import anorm._ -import models.`export`.{JsonExportable, Something, SomethingId} import models.input.SearchInputId -import models.rules.FilterRule.{LAST_UPDATE, SEARCH_INPUT_ID, TABLE_NAME} -import models.{Id, IdObject, Status} -import play.api.libs.json.{JsArray, JsNumber, JsString, JsValue, Json, OFormat} +import models.rules.{CommonRuleFields, SynonymRule, SynonymRuleId} +import play.api.libs.json._ import java.time.LocalDateTime @@ -68,4 +65,6 @@ object SynonymRuleExport extends CommonRuleFields { } } + val selectAllStatement = s"select $TABLE_NAME.$ID, $TABLE_NAME.$TYPE, $TABLE_NAME.$TERM, $TABLE_NAME.$STATUS, $TABLE_NAME.$SEARCH_INPUT_ID, $TABLE_NAME.$LAST_UPDATE from $TABLE_NAME" + } \ No newline at end of file diff --git a/app/models/export/TagInputAssociationExport.scala b/app/models/export/TagInputAssociationExport.scala new file mode 100644 index 00000000..f3209d28 --- /dev/null +++ b/app/models/export/TagInputAssociationExport.scala @@ -0,0 +1,67 @@ +package models.`export` + +import anorm.SqlParser.get +import anorm.{RowParser, SQL, ~} +import models.input.InputTagId +import models.rules.CommonRuleFields +import play.api.libs.json._ + +import java.time.LocalDateTime + +case class TagInputAssociationExport(id: InputTagId, + searchInputId: String, + lastUpdate: LocalDateTime) extends JsonExportable { + + def getTableName: JsString = JsString("tag_2_input") + + def getColumns: JsValue = { + JsArray( + IndexedSeq ( + JsString("id"), + JsString("searchInputId"), + JsString("last_update") + ) + ) + } + + def getRow: JsValue = { + JsArray( + IndexedSeq ( + JsString(id.toString), + JsString(searchInputId), + JsString(lastUpdate.toString) + ) + ) + } +} + +object TagInputAssociationExport { + + val TABLE_NAME = "tag_2_input" + val ID = "tag_id" + val SEARCH_INPUT_ID = "input_id" + val LAST_UPDATE = "last_update" + + val sqlParser: RowParser[TagInputAssociationExport] = { + (get[InputTagId](s"$TABLE_NAME.$ID") ~ + get[String](s"$TABLE_NAME.$SEARCH_INPUT_ID") ~ + get[LocalDateTime](s"$TABLE_NAME.$LAST_UPDATE")) map { + case + id ~ + searchInputId ~ + lastUpdate + => + TagInputAssociationExport( + id, + searchInputId, + lastUpdate) + } + } + + val selectAllStatement : String = { + s"select $TABLE_NAME.$ID, " + + s"$TABLE_NAME.$SEARCH_INPUT_ID, " + + s"$TABLE_NAME.$LAST_UPDATE from $TABLE_NAME" + } + +} \ No newline at end of file diff --git a/app/models/rules/UpdownRuleExport.scala b/app/models/export/UpdownRuleExport.scala similarity index 65% rename from app/models/rules/UpdownRuleExport.scala rename to app/models/export/UpdownRuleExport.scala index 61ca001c..aa3fbc64 100644 --- a/app/models/rules/UpdownRuleExport.scala +++ b/app/models/export/UpdownRuleExport.scala @@ -1,11 +1,10 @@ -package models.rules +package models.export import anorm.SqlParser.get -import anorm.{NamedParameter, RowParser, ~} -import models.`export`.JsonExportable +import anorm.{RowParser, ~} import models.input.SearchInputId -import models.{Id, IdObject, Status} -import play.api.libs.json.{JsArray, JsNumber, JsString, JsValue, Json, OFormat} +import models.rules.{CommonRuleFields, UpDownRuleId} +import play.api.libs.json._ import java.time.LocalDateTime @@ -61,15 +60,38 @@ object UpDownRuleExport extends CommonRuleFields { implicit val jsonFormat: OFormat[UpDownRuleExport] = Json.format[UpDownRuleExport] val sqlParser: RowParser[UpDownRuleExport] = { - get[UpDownRuleId](s"$TABLE_NAME.$ID") ~ + (get[UpDownRuleId](s"$TABLE_NAME.$ID") ~ get[Int](s"$TABLE_NAME.$UP_DOWN_TYPE") ~ get[Int](s"$TABLE_NAME.$BOOST_MALUS_VALUE") ~ get[String](s"$TABLE_NAME.$TERM") ~ get[Int](s"$TABLE_NAME.$STATUS") ~ get[SearchInputId](s"$TABLE_NAME.$SEARCH_INPUT_ID") ~ - get[LocalDateTime](s"$TABLE_NAME.$LAST_UPDATE") map { case id ~ upDownType ~ boostMalusValue ~ term ~ status ~ searchInputId ~ lastUpdate => - UpDownRuleExport(id, upDownType, boostMalusValue, term, status, searchInputId, lastUpdate) - } + get[LocalDateTime](s"$TABLE_NAME.$LAST_UPDATE")) map { + case id ~ + upDownType ~ + boostMalusValue ~ + term ~ + status ~ + searchInputId ~ + lastUpdate => + UpDownRuleExport(id, + upDownType, + boostMalusValue, + term, + status, + searchInputId, + lastUpdate) + } + } + + val selectAllStatement : String = { + s"select $TABLE_NAME.$ID, " + + s"$TABLE_NAME.$UP_DOWN_TYPE, " + + s"$TABLE_NAME.$BOOST_MALUS_VALUE, " + + s"$TABLE_NAME.$TERM, " + + s"$TABLE_NAME.$STATUS, " + + s"$TABLE_NAME.$SEARCH_INPUT_ID, " + + s"$TABLE_NAME.$LAST_UPDATE from $TABLE_NAME" } } \ No newline at end of file diff --git a/app/models/export/example_export_file.json.txt b/app/models/export/example_export_file.json.txt new file mode 100644 index 00000000..344c1b55 --- /dev/null +++ b/app/models/export/example_export_file.json.txt @@ -0,0 +1,292 @@ +[ + { + "tableName": "solr_index", + "columns": [ + "id", + "name", + "description", + "last_update" + ], + "rows": [ + [ + "b0eecea6-efa7-4575-9bb4-acba1aab146b", + "b0eecea6-efa7-4575-9bb4-acba1aab146b", + "test", + "2022-05-31T11:14:38" + ] + ] + }, + { + "tableName": "search_input", + "columns": [ + "id", + "term", + "solr_index_id", + "last_update", + "status", + "comment" + ], + "rows": [ + [ + "16c30efd-3139-4916-bfb6-57463af18250", + "test", + "b0eecea6-efa7-4575-9bb4-acba1aab146b", + "2022-05-31T17:25:25", + 1, + "updown comment" + ], + [ + "5418428c-0d4c-4464-a2a6-084f264be360", + "s", + "b0eecea6-efa7-4575-9bb4-acba1aab146b", + "2022-05-31T15:29:59", + 1, + "syn com" + ], + [ + "70823642-e7c6-4857-9d6c-a54b3c382f0d", + "test", + "b0eecea6-efa7-4575-9bb4-acba1aab146b", + "2022-05-31T14:43:54", + 1, + "" + ], + [ + "89c10061-26d9-4b5f-9e99-92696cc5da74", + "test two three", + "b0eecea6-efa7-4575-9bb4-acba1aab146b", + "2022-05-31T13:43:50", + 1, + "a comment" + ], + [ + "9fb7f8b4-5544-4df0-9d08-d485a0145dbe", + "redirect", + "b0eecea6-efa7-4575-9bb4-acba1aab146b", + "2022-05-31T17:20:36", + 1, + "redirect comment" + ], + [ + "ccc48739-f192-44b1-b552-995eed4a0a51", + "all", + "b0eecea6-efa7-4575-9bb4-acba1aab146b", + "2022-05-31T14:41:55", + 1, + "" + ], + [ + "dd1bd496-90ed-43ad-9895-e67a4f67adeb", + "test1", + "b0eecea6-efa7-4575-9bb4-acba1aab146b", + "2022-05-31T13:54:27", + 1, + "" + ], + [ + "e8064dd4-0e76-4e0b-963a-06ea8cae65e2", + "t345", + "b0eecea6-efa7-4575-9bb4-acba1aab146b", + "2022-05-31T14:56:51", + 1, + "c" + ] + ] + }, + { + "tableName": "redirect_rule", + "columns": [ + "id", + "target", + "search_input_id", + "last_update", + "status" + ], + "rows": [ + [ + "89e5833a-64b4-4a97-924b-a18b66694437", + "https://www.google.com", + "9fb7f8b4-5544-4df0-9d08-d485a0145dbe", + "2022-05-31T17:20:36", + 1 + ] + ] + }, + { + "tableName": "synonym_rule", + "columns": [ + "id", + "synonymType", + "term", + "search_input_id", + "last_update", + "status" + ], + "rows": [ + [ + "70d3eb55-ad67-4890-a157-130ea72637c1", + 0, + "y", + "5418428c-0d4c-4464-a2a6-084f264be360", + "2022-05-31T15:29:59", + 1 + ] + ] + }, + { + "tableName": "up_down_rule", + "columns": [ + "id", + "up_down_type", + "boost_malus_type", + "term", + "search_input_id", + "last_update", + "status" + ], + "rows": [ + [ + "a26f49ad-28ba-40e3-a968-ada168d948c7", + 0, + 5, + "* a:test", + 1, + "16c30efd-3139-4916-bfb6-57463af18250", + "2022-05-31T17:25:25" + ] + ] + }, + { + "tableName": "delete_rule", + "columns": [ + "id", + "term", + "search_input_id", + "last_update", + "status" + ], + "rows": [ + [ + "36d7a7d2-4133-4bcc-b4b3-19ec6d0404d1", + "two", + "89c10061-26d9-4b5f-9e99-92696cc5da74", + "2022-05-31T13:43:50", + 1 + ] + ] + }, + { + "tableName": "filter_rule", + "columns": [ + "id", + "term", + "search_input_id", + "last_update", + "status" + ], + "rows": [ + [ + "8ed6c4bd-ac69-4a94-898c-fabb13a7fc47", + "* test:* a:b", + "e8064dd4-0e76-4e0b-963a-06ea8cae65e2", + "2022-05-31T14:56:51", + 1 + ] + ] + }, + { + "tableName": "suggested_solr_field", + "columns": [ + "id", + "name", + "solr_index_id", + "last_update" + ], + "rows": [ + [ + "4ce83b3a-7263-4873-b4f2-a66a9321fdbb", + "test", + "b0eecea6-efa7-4575-9bb4-acba1aab146b", + "2022-05-31T17:37:43" + ] + ] + }, + { + "tableName": "input_tag", + "columns": [ + "id", + "solr_index_id", + "property", + "tag_value", + "exported", + "predefined", + "last_update" + ], + "rows": [ + [ + "wh", + "some solr_index_id", + "some property", + "some tag_value", + 2345, + 123, + "2022-05-31T18:23:47" + ] + ] + }, + { + "tableName": "tag_2_input", + "columns": [ + "id", + "searchInputId", + "last_update" + ], + "rows": [ + [ + "hi", + "3", + "2022-05-31T18:22:14" + ] + ] + }, + { + "tableName": "canonical_spelling", + "columns": [ + "id", + "solr_index_id", + "term", + "status", + "comment", + "last_update" + ], + "rows": [ + [ + "id8", + "id9", + "a_term_can_spell", + 0, + "can_spell_comment", + "2022-05-31T18:44:15" + ] + ] + }, + { + "tableName": "alternative_spelling", + "columns": [ + "id", + "canonical_spelling_id", + "term", + "status", + "last_update" + ], + "rows": [ + [ + "id10", + "id11", + "alt_spell_term", + 0, + "2022-05-31T18:44:15" + ] + ] + } +] diff --git a/app/models/rules/RedirectRule.scala b/app/models/rules/RedirectRule.scala index 1bab81bd..313eb89d 100644 --- a/app/models/rules/RedirectRule.scala +++ b/app/models/rules/RedirectRule.scala @@ -14,9 +14,7 @@ object RedirectRuleId extends IdObject[RedirectRuleId](new RedirectRuleId(_)) case class RedirectRule(id: RedirectRuleId = RedirectRuleId(), target: String, - isActive: Boolean, - searchInputId: SearchInputId = SearchInputId(), - lastUpdate: LocalDateTime = LocalDateTime.now()) extends Rule { + isActive: Boolean) extends Rule { override def toNamedParameters(searchInputId: SearchInputId): Seq[NamedParameter] = { super.toNamedParameters(searchInputId) ++ Seq[NamedParameter]( @@ -24,31 +22,6 @@ case class RedirectRule(id: RedirectRuleId = RedirectRuleId(), ) } - def getTableName: JsString = JsString("delete_rule") - - def getColumns: JsValue = { - JsArray( - IndexedSeq ( - JsString("id"), - JsString("target"), - JsString("search_input_id"), - JsString("last_update"), - JsString("status") - ) - ) - } - - def getRow: JsValue = { - JsArray( - IndexedSeq ( - JsString(id.toString), - JsString(target), - JsString(searchInputId.toString), - JsString(lastUpdate.toString), - JsNumber(status) - ) - ) - } } object RedirectRule extends RuleObject[RedirectRule] { From aede95cc632b76f69fbb77a4f3256543f35dcc22 Mon Sep 17 00:00:00 2001 From: Chris Morley Date: Thu, 2 Jun 2022 15:14:14 -0400 Subject: [PATCH 15/25] be able to upload an import; fix export in a few ways --- app/controllers/ApiController.scala | 56 +++++- app/models/SearchManagementRepository.scala | 45 ++++- .../export/AlternativeSpellingExport.scala | 6 +- .../export/CanonicalSpellingExport.scala | 4 + app/models/export/DeleteRuleExport.scala | 4 + app/models/export/Exporter.scala | 96 ++++++++- app/models/export/FilterRuleExport.scala | 4 + app/models/export/InputTagExport.scala | 4 + app/models/export/RedirectRuleExport.scala | 4 + app/models/export/SearchInputExport.scala | 4 + app/models/export/SolrIndexExport.scala | 4 + .../export/SuggestedSolrFieldExport.scala | 4 + app/models/export/SynonymRuleExport.scala | 5 +- .../export/TagInputAssociationExport.scala | 4 + app/models/export/UpdownRuleExport.scala | 10 +- .../validatedimport/ValidatedImportData.scala | 188 ++++++++++++++++++ .../ValidatedImportImporter.scala | 31 +++ conf/routes | 3 + frontend/src/app/app.module.ts | 2 + .../rules-collection-list.component.ts | 155 +++++++++------ ...ris-rules-collection-create.component.html | 146 ++++++++------ ...chris-rules-collection-create.component.ts | 11 + .../file-upload.component.html | 19 ++ .../file-upload.component.scss | 3 + .../file-upload.component.ts | 34 ++++ .../header-nav/header-nav.component.html | 2 +- frontend/src/app/services/solr.service.ts | 16 ++ 27 files changed, 725 insertions(+), 139 deletions(-) create mode 100644 app/models/validatedimport/ValidatedImportData.scala create mode 100644 app/models/validatedimport/ValidatedImportImporter.scala create mode 100644 frontend/src/app/components/chris/chris-rules-collection-create/file-upload.component.html create mode 100644 frontend/src/app/components/chris/chris-rules-collection-create/file-upload.component.scss create mode 100644 frontend/src/app/components/chris/chris-rules-collection-create/file-upload.component.ts diff --git a/app/controllers/ApiController.scala b/app/controllers/ApiController.scala index 247141aa..5c55e72d 100644 --- a/app/controllers/ApiController.scala +++ b/app/controllers/ApiController.scala @@ -1,7 +1,7 @@ //CJM 10 package controllers -import java.io.{OutputStream, PipedInputStream, PipedOutputStream} +import java.io.{File, OutputStream, PipedInputStream, PipedOutputStream} import akka.stream.scaladsl.{Source, StreamConverters} import akka.util.ByteString @@ -22,8 +22,13 @@ import models.config.SmuiVersion import models.input.{InputTagId, InputValidator, ListItem, SearchInputId, SearchInputWithRules} import models.querqy.QuerqyRulesTxtGenerator import models.spellings.{CanonicalSpellingId, CanonicalSpellingValidator, CanonicalSpellingWithAlternatives} +import models.validatedimport.ValidatedImportData import org.checkerframework.checker.units.qual.A +import play.api.libs.Files +import play.api.libs.Files.TemporaryFile.temporaryFileToPath import services.{RulesTxtDeploymentService, RulesTxtImportService} + +import java.util.UUID import scala.collection.JavaConverters._ @@ -638,10 +643,57 @@ class ApiController @Inject()(authActionFactory: AuthActionFactory, def getDatabaseJson: Action[AnyContent] = authActionFactory.getAuthenticatedAction(Action).async { Future { - logger.debug("In ApiController:getSomethings") + logger.debug("In ApiController:getDatabaseJson") Ok(Json.toJson(searchManagementRepository.getDatabaseJson)) } } + def getDatabaseJsonWithId(id: String): Action[AnyContent] = authActionFactory.getAuthenticatedAction(Action).async { + Future { + logger.debug("In ApiController:getDatabaseJsonWithId and got id: " + id) + Ok(Json.toJson(searchManagementRepository.getDatabaseJsonWithId(id))) + } + } + + def uploadImport: Action[MultipartFormData[Files.TemporaryFile]] = authActionFactory.getAuthenticatedAction(Action).async(parse.multipartFormData) { implicit request => + Future { + val tryDatabaseStuff: Boolean = true + logger.debug("In ApiController:uploadImport") + if (request.body.files.size == 1) { + + val fileName: String = request.body.files.head.filename + logger.debug(fileName) + import java.nio.file.Files + val content = Files.readString(temporaryFileToPath(request.body.files.head.ref)) + logger.debug(content) + val validatedImport: ValidatedImportData = new ValidatedImportData(content) + if (tryDatabaseStuff) { + searchManagementRepository.doImport(validatedImport) + } + Ok(Json.toJson(ApiResult(API_RESULT_OK, "Got file.", None))) + } else { + BadRequest("Only one upload file is allowed. Input must be valid") + } + } + } + +// def putty: Action[AnyContent] = authActionFactory.getAuthenticatedAction(Action).async { +// Future { +// logger.debug("ApiController.putty():1") +// searchManagementRepository.putty +// logger.debug("ApiController.putty():2") +// Ok(Json.toJson(ApiResult(API_RESULT_OK, "That worked.", None))) +// } +// } + + def putty: Action[AnyContent] = authActionFactory.getAuthenticatedAction(Action).async { + Future { + logger.debug("In ApiController:putty") + val content = "[{\"tableName\":\"solr_index\",\"columns\":[\"id\",\"name\",\"description\",\"last_update\"],\"rows\":[[\"b0eecea6-efa7-4575-9bb4-acba1aab146b\",\"b0eecea6-efa7-4575-9bb4-acba1aab146b\",\"test\",\"2022-05-31T11:14:38\"]]},{\"tableName\":\"search_input\",\"columns\":[\"id\",\"term\",\"solr_index_id\",\"last_update\",\"status\",\"comment\"],\"rows\":[[\"16c30efd-3139-4916-bfb6-57463af18250\",\"test\",\"b0eecea6-efa7-4575-9bb4-acba1aab146b\",\"2022-05-31T17:25:25\",1,\"updown comment\"],[\"5418428c-0d4c-4464-a2a6-084f264be360\",\"s\",\"b0eecea6-efa7-4575-9bb4-acba1aab146b\",\"2022-05-31T15:29:59\",1,\"syn com\"],[\"70823642-e7c6-4857-9d6c-a54b3c382f0d\",\"test\",\"b0eecea6-efa7-4575-9bb4-acba1aab146b\",\"2022-05-31T14:43:54\",1,\"\"],[\"89c10061-26d9-4b5f-9e99-92696cc5da74\",\"test two three\",\"b0eecea6-efa7-4575-9bb4-acba1aab146b\",\"2022-05-31T13:43:50\",1,\"a comment\"],[\"9fb7f8b4-5544-4df0-9d08-d485a0145dbe\",\"redirect\",\"b0eecea6-efa7-4575-9bb4-acba1aab146b\",\"2022-05-31T17:20:36\",1,\"redirect comment\"],[\"ccc48739-f192-44b1-b552-995eed4a0a51\",\"all\",\"b0eecea6-efa7-4575-9bb4-acba1aab146b\",\"2022-05-31T14:41:55\",1,\"\"],[\"dd1bd496-90ed-43ad-9895-e67a4f67adeb\",\"test1\",\"b0eecea6-efa7-4575-9bb4-acba1aab146b\",\"2022-05-31T13:54:27\",1,\"\"],[\"e8064dd4-0e76-4e0b-963a-06ea8cae65e2\",\"t345\",\"b0eecea6-efa7-4575-9bb4-acba1aab146b\",\"2022-05-31T14:56:51\",1,\"c\"]]},{\"tableName\":\"redirect_rule\",\"columns\":[\"id\",\"target\",\"search_input_id\",\"last_update\",\"status\"],\"rows\":[[\"89e5833a-64b4-4a97-924b-a18b66694437\",\"https://www.google.com\",\"9fb7f8b4-5544-4df0-9d08-d485a0145dbe\",\"2022-05-31T17:20:36\",1]]},{\"tableName\":\"synonym_rule\",\"columns\":[\"id\",\"synonymType\",\"term\",\"search_input_id\",\"last_update\",\"status\"],\"rows\":[[\"70d3eb55-ad67-4890-a157-130ea72637c1\",0,\"y\",\"5418428c-0d4c-4464-a2a6-084f264be360\",\"2022-05-31T15:29:59\",1]]},{\"tableName\":\"up_down_rule\",\"columns\":[\"id\",\"up_down_type\",\"boost_malus_type\",\"term\",\"search_input_id\",\"last_update\",\"status\"],\"rows\":[[\"a26f49ad-28ba-40e3-a968-ada168d948c7\",0,5,\"* a:test\",1,\"16c30efd-3139-4916-bfb6-57463af18250\",\"2022-05-31T17:25:25\"]]},{\"tableName\":\"delete_rule\",\"columns\":[\"id\",\"term\",\"search_input_id\",\"last_update\",\"status\"],\"rows\":[[\"36d7a7d2-4133-4bcc-b4b3-19ec6d0404d1\",\"two\",\"89c10061-26d9-4b5f-9e99-92696cc5da74\",\"2022-05-31T13:43:50\",1]]},{\"tableName\":\"filter_rule\",\"columns\":[\"id\",\"term\",\"search_input_id\",\"last_update\",\"status\"],\"rows\":[[\"8ed6c4bd-ac69-4a94-898c-fabb13a7fc47\",\"* test:* a:b\",\"e8064dd4-0e76-4e0b-963a-06ea8cae65e2\",\"2022-05-31T14:56:51\",1]]},{\"tableName\":\"suggested_solr_field\",\"columns\":[\"id\",\"name\",\"solr_index_id\",\"last_update\"],\"rows\":[[\"4ce83b3a-7263-4873-b4f2-a66a9321fdbb\",\"test\",\"b0eecea6-efa7-4575-9bb4-acba1aab146b\",\"2022-05-31T17:37:43\"]]},{\"tableName\":\"input_tag\",\"columns\":[\"id\",\"solr_index_id\",\"property\",\"tag_value\",\"exported\",\"predefined\",\"last_update\"],\"rows\":[[\"wh\",\"some solr_index_id\",\"some property\",\"some tag_value\",2345,123,\"2022-05-31T18:23:47\"]]},{\"tableName\":\"tag_2_input\",\"columns\":[\"id\",\"searchInputId\",\"last_update\"],\"rows\":[[\"hi\",\"3\",\"2022-05-31T18:22:14\"]]},{\"tableName\":\"canonical_spelling\",\"columns\":[\"id\",\"solr_index_id\",\"term\",\"status\",\"comment\",\"last_update\"],\"rows\":[[\"id8\",\"id9\",\"a_term_can_spell\",0,\"can_spell_comment\",\"2022-05-31T18:44:15\"]]},{\"tableName\":\"alternative_spelling\",\"columns\":[\"id\",\"canonical_spelling_id\",\"term\",\"status\",\"last_update\"],\"rows\":[[\"id10\",\"id11\",\"alt_spell_term\",0,\"2022-05-31T18:44:15\"]]}]" + val validatedImport: ValidatedImportData = new ValidatedImportData(content) + searchManagementRepository.doImport(validatedImport) + Ok(Json.toJson(ApiResult(API_RESULT_OK, "OK.", None))) + } + } } diff --git a/app/models/SearchManagementRepository.scala b/app/models/SearchManagementRepository.scala index fdd778fd..5cedc327 100644 --- a/app/models/SearchManagementRepository.scala +++ b/app/models/SearchManagementRepository.scala @@ -16,6 +16,7 @@ import models.spellings.{CanonicalSpelling, CanonicalSpellingId, CanonicalSpelli import models.eventhistory.{ActivityLog, ActivityLogEntry, InputEvent} import models.reports.{ActivityReport, DeploymentLog, RulesReport} import models.rules.{DeleteRule, FilterRule, SynonymRuleId} +import models.validatedimport.{ValidatedImportData, ValidatedImportImporter} import play.api.Logging import play.api.libs.json.JsValue @@ -336,10 +337,52 @@ class SearchManagementRepository @Inject()(dbapi: DBApi, toggleService: FeatureT def getDatabaseJson: JsValue = db.withConnection { implicit connection => { - logger.debug("In SearchManagementRepository:getAllSomethingsForJs():1") + logger.debug("In SearchManagementRepository:getDatabaseJson():1") val exporter : Exporter = new Exporter(dbapi, toggleService) exporter.getDatabaseJson } } + def getDatabaseJsonWithId(id: String): JsValue = db.withConnection { + implicit connection => { + logger.debug("In SearchManagementRepository:getDatabaseJsonWithId():1") + val exporter : Exporter = new Exporter(dbapi, toggleService) + exporter.getDatabaseJsonWithId(id) + } + } + + def putty: String = db.withTransaction { implicit connection => + var aString : String = "At SearchManagementRepository:putty():1" + logger.debug(aString) + SQL("insert into something (id,value0,last_update) values ({id}, {value0}, {last_update})") + .on( + 'id -> SomethingId(), + 'value0 -> "test22222", + 'last_update -> LocalDateTime.now() + ).execute() + + SQL("insert into something (id,value0,last_update) values ({id}, {value0}, {last_update})") + .on( + 'id -> SomethingId(), + 'value0 -> 3, + 'last_update -> LocalDateTime.now() + ).execute() + + aString = "At SearchManagementRepository:putty():2" + logger.debug(aString) + aString + } + + def doImport(validatedImport: ValidatedImportData): String = db.withTransaction { implicit connection => + var aString : String = "At SearchManagementRepository:doImport():1" + logger.debug(aString) + + val importer = new ValidatedImportImporter(validatedImport, dbapi, toggleService) + importer.performImport() + + aString = "At SearchManagementRepository:doImport():2" + logger.debug(aString) + aString + } + } diff --git a/app/models/export/AlternativeSpellingExport.scala b/app/models/export/AlternativeSpellingExport.scala index 9e317b26..da68cf10 100644 --- a/app/models/export/AlternativeSpellingExport.scala +++ b/app/models/export/AlternativeSpellingExport.scala @@ -9,7 +9,7 @@ import models.spellings.{AlternativeSpellingId, CanonicalSpellingId} import models.{SolrIndexId, Status, `export`} import play.api.libs.json._ -import java.time.LocalDateTime +import java.time.{LocalDateTime, ZoneOffset} case class AlternativeSpellingExport(id: AlternativeSpellingId = AlternativeSpellingId(), canonicalSpellingId: CanonicalSpellingId, @@ -72,4 +72,8 @@ object AlternativeSpellingExport { s"$TABLE_NAME.$STATUS, " + s"$TABLE_NAME.$LAST_UPDATE from $TABLE_NAME" } + + def selectStatement(id: String) : String = { + this.selectAllStatement + s" where canonical_spelling_id in (select id from canonical_spelling where solr_index_id = '" + id + "')" + } } \ No newline at end of file diff --git a/app/models/export/CanonicalSpellingExport.scala b/app/models/export/CanonicalSpellingExport.scala index 18dc847e..83ed4c74 100644 --- a/app/models/export/CanonicalSpellingExport.scala +++ b/app/models/export/CanonicalSpellingExport.scala @@ -78,4 +78,8 @@ object CanonicalSpellingExport { s"$TABLE_NAME.$COMMENT, " + s"$TABLE_NAME.$LAST_UPDATE from $TABLE_NAME" } + + def selectStatement(id: String) : String = { + this.selectAllStatement + " where solr_index_id = '" + id + "'" + } } \ No newline at end of file diff --git a/app/models/export/DeleteRuleExport.scala b/app/models/export/DeleteRuleExport.scala index 3c6ead47..08b2df81 100644 --- a/app/models/export/DeleteRuleExport.scala +++ b/app/models/export/DeleteRuleExport.scala @@ -63,4 +63,8 @@ object DeleteRuleExport extends CommonRuleFields { val selectAllStatement = s"select id, term, search_input_id, last_update, status from delete_rule" + def selectStatement(id: String) : String = { + this.selectAllStatement + " where search_input_id in (select id from search_input where solr_index_id = '" + id + "')" + } + } \ No newline at end of file diff --git a/app/models/export/Exporter.scala b/app/models/export/Exporter.scala index 5162b8e9..4c55a42c 100644 --- a/app/models/export/Exporter.scala +++ b/app/models/export/Exporter.scala @@ -24,8 +24,7 @@ class Exporter @Inject()(dbapi: DBApi, toggleService: FeatureToggleService)(impl def getAllTablesForJs(tables : IndexedSeq[IndexedSeq[JsonExportable]]): JsValue = { var aggregation: Seq[JsValue] = Seq[JsValue]() - println("hello ------ ") - println(tables.size) + //println(tables.size) getAllTablesForJs1(tables, aggregation) } @@ -36,6 +35,7 @@ class Exporter @Inject()(dbapi: DBApi, toggleService: FeatureToggleService)(impl if (headTable.nonEmpty) { logger.debug("In Exporter.getAllTablesForJs1 : head table was non-empty") val name: (String, JsValue) = "tableName" -> headTable.seq(0).getTableName + logger.debug("table name: "+ name) val cols: (String, JsValue) = "columns" -> headTable.seq(0).getColumns val rows: (String, JsValue) = "rows" -> asIndexedSeqForJs(headTable) val obj: (JsValue) = JsObject(IndexedSeq(name, cols, rows)) @@ -71,75 +71,146 @@ class Exporter @Inject()(dbapi: DBApi, toggleService: FeatureToggleService)(impl } } + def getSearchInputsFromDatabase(id: String): IndexedSeq[SearchInputExport] = db.withConnection { + implicit connection => { + SQL(SearchInputExport.selectStatement(id)).as(SearchInputExport.sqlParser.*).toIndexedSeq + } + } + def getDeleteRulesFromDatabase: IndexedSeq[DeleteRuleExport] = db.withConnection { implicit connection => { SQL(DeleteRuleExport.selectAllStatement).as(DeleteRuleExport.sqlParser.*).toIndexedSeq } } + def getDeleteRulesFromDatabase(id: String): IndexedSeq[DeleteRuleExport] = db.withConnection { + implicit connection => { + SQL(DeleteRuleExport.selectStatement(id)).as(DeleteRuleExport.sqlParser.*).toIndexedSeq + } + } + def getFilterRulesFromDatabase: IndexedSeq[FilterRuleExport] = db.withConnection { implicit connection => { SQL(FilterRuleExport.selectAllStatement).as(FilterRuleExport.sqlParser.*).toIndexedSeq } } + def getFilterRulesFromDatabase(id: String): IndexedSeq[FilterRuleExport] = db.withConnection { + implicit connection => { + SQL(FilterRuleExport.selectStatement(id)).as(FilterRuleExport.sqlParser.*).toIndexedSeq + } + } + def getSynonymRulesFromDatabase: IndexedSeq[SynonymRuleExport] = db.withConnection { implicit connection => { SQL(SynonymRuleExport.selectAllStatement).as(SynonymRuleExport.sqlParser.*).toIndexedSeq } } + def getSynonymRulesFromDatabase(id: String): IndexedSeq[SynonymRuleExport] = db.withConnection { + implicit connection => { + SQL(SynonymRuleExport.selectStatement(id)).as(SynonymRuleExport.sqlParser.*).toIndexedSeq + } + } + def getUpDownRulesFromDatabase: IndexedSeq[UpDownRuleExport] = db.withConnection { implicit connection => { SQL(UpDownRuleExport.selectAllStatement).as(UpDownRuleExport.sqlParser.*).toIndexedSeq } } + def getUpDownRulesFromDatabase(id: String): IndexedSeq[UpDownRuleExport] = db.withConnection { + implicit connection => { + SQL(UpDownRuleExport.selectStatement(id)).as(UpDownRuleExport.sqlParser.*).toIndexedSeq + } + } + def getRedirectRulesFromDatabase: IndexedSeq[RedirectRuleExport] = db.withConnection { implicit connection => { SQL(RedirectRuleExport.selectAllStatement).as(RedirectRuleExport.sqlParser.*).toIndexedSeq } } + def getRedirectRulesFromDatabase(id: String): IndexedSeq[RedirectRuleExport] = db.withConnection { + implicit connection => { + SQL(RedirectRuleExport.selectStatement(id)).as(RedirectRuleExport.sqlParser.*).toIndexedSeq + } + } + def getSolrIndexFromDatabase: IndexedSeq[SolrIndexExport] = db.withConnection { implicit connection => { SQL(SolrIndexExport.selectAllStatement).as(SolrIndexExport.sqlParser.*).toIndexedSeq } } + def getSolrIndexFromDatabase(id: String): IndexedSeq[SolrIndexExport] = db.withConnection { + implicit connection => { + SQL(SolrIndexExport.selectStatement(id)).as(SolrIndexExport.sqlParser.*).toIndexedSeq + } + } + def getSuggestedSolrFieldsFromDatabase: IndexedSeq[SuggestedSolrFieldExport] = db.withConnection { implicit connection => { SQL(SuggestedSolrFieldExport.selectAllStatement).as(SuggestedSolrFieldExport.sqlParser.*).toIndexedSeq } } + def getSuggestedSolrFieldsFromDatabase(id: String): IndexedSeq[SuggestedSolrFieldExport] = db.withConnection { + implicit connection => { + SQL(SuggestedSolrFieldExport.selectStatement(id)).as(SuggestedSolrFieldExport.sqlParser.*).toIndexedSeq + } + } + def getInputTagsFromDatabase: IndexedSeq[InputTagExport] = db.withConnection { implicit connection => { SQL(InputTagExport.selectAllStatement).as(InputTagExport.sqlParser.*).toIndexedSeq } } + def getInputTagsFromDatabase(id: String): IndexedSeq[InputTagExport] = db.withConnection { + implicit connection => { + SQL(InputTagExport.selectStatement(id)).as(InputTagExport.sqlParser.*).toIndexedSeq + } + } + def getTagInputAssociationsFromDatabase: IndexedSeq[TagInputAssociationExport] = db.withConnection { implicit connection => { SQL(TagInputAssociationExport.selectAllStatement).as(TagInputAssociationExport.sqlParser.*).toIndexedSeq } } + def getTagInputAssociationsFromDatabase(id: String): IndexedSeq[TagInputAssociationExport] = db.withConnection { + implicit connection => { + SQL(TagInputAssociationExport.selectStatement(id)).as(TagInputAssociationExport.sqlParser.*).toIndexedSeq + } + } + def getCanonicalSpellingsFromDatabase: IndexedSeq[CanonicalSpellingExport] = db.withConnection { implicit connection => { SQL(CanonicalSpellingExport.selectAllStatement).as(CanonicalSpellingExport.sqlParser.*).toIndexedSeq } } + def getCanonicalSpellingsFromDatabase(id: String): IndexedSeq[CanonicalSpellingExport] = db.withConnection { + implicit connection => { + SQL(CanonicalSpellingExport.selectStatement(id)).as(CanonicalSpellingExport.sqlParser.*).toIndexedSeq + } + } + def getAlternativeSpellingsFromDatabase: IndexedSeq[AlternativeSpellingExport] = db.withConnection { implicit connection => { SQL(AlternativeSpellingExport.selectAllStatement).as(AlternativeSpellingExport.sqlParser.*).toIndexedSeq } } + def getAlternativeSpellingsFromDatabase(id: String): IndexedSeq[AlternativeSpellingExport] = db.withConnection { + implicit connection => { + SQL(AlternativeSpellingExport.selectStatement(id)).as(AlternativeSpellingExport.sqlParser.*).toIndexedSeq + } + } def getDatabaseJson: JsValue = { - logger.debug("In getDatabaseJson") + logger.debug("In Exporter.getDatabaseJson") val tableSeq = IndexedSeq( getSolrIndexFromDatabase, //1 getSearchInputsFromDatabase, //2 @@ -158,4 +229,23 @@ class Exporter @Inject()(dbapi: DBApi, toggleService: FeatureToggleService)(impl getAllTablesForJs(tableSeq) } + def getDatabaseJsonWithId(id: String): JsValue = { + logger.debug("In Exporter.getDatabaseJsonWithId") + val tableSeq = IndexedSeq( + getSolrIndexFromDatabase(id), //1 + getSearchInputsFromDatabase(id), //2 + getRedirectRulesFromDatabase(id), //3 + getSynonymRulesFromDatabase(id), //4 + getUpDownRulesFromDatabase(id), //5 + getDeleteRulesFromDatabase(id), //6 + getFilterRulesFromDatabase(id), //7 + getSuggestedSolrFieldsFromDatabase(id), //8 + getInputTagsFromDatabase(id), //9 + getTagInputAssociationsFromDatabase(id), //10 + getCanonicalSpellingsFromDatabase(id), //11 + getAlternativeSpellingsFromDatabase(id) //12 + ) + getAllTablesForJs(tableSeq) + } + } diff --git a/app/models/export/FilterRuleExport.scala b/app/models/export/FilterRuleExport.scala index aa3d1508..96cf4a90 100644 --- a/app/models/export/FilterRuleExport.scala +++ b/app/models/export/FilterRuleExport.scala @@ -62,4 +62,8 @@ object FilterRuleExport extends CommonRuleFields { val selectAllStatement = s"select $TABLE_NAME.$ID, $TABLE_NAME.$TERM, $TABLE_NAME.$STATUS, $TABLE_NAME.$SEARCH_INPUT_ID, $TABLE_NAME.$LAST_UPDATE from $TABLE_NAME" + def selectStatement(id: String) : String = { + this.selectAllStatement + " where search_input_id in (select id from search_input where solr_index_id = '" + id + "')" + } + } \ No newline at end of file diff --git a/app/models/export/InputTagExport.scala b/app/models/export/InputTagExport.scala index b8d942aa..04c1bdb2 100644 --- a/app/models/export/InputTagExport.scala +++ b/app/models/export/InputTagExport.scala @@ -82,4 +82,8 @@ object InputTagExport { s"$TABLE_NAME.$LAST_UPDATE from $TABLE_NAME" } + def selectStatement(id: String) : String = { + this.selectAllStatement + s" where $TABLE_NAME.$SOLR_INDEX_ID = '" + id + "'" + } + } \ No newline at end of file diff --git a/app/models/export/RedirectRuleExport.scala b/app/models/export/RedirectRuleExport.scala index 18b351dc..48c572db 100644 --- a/app/models/export/RedirectRuleExport.scala +++ b/app/models/export/RedirectRuleExport.scala @@ -60,4 +60,8 @@ object RedirectRuleExport extends CommonRuleFields { val selectAllStatement = s"select $TABLE_NAME.$ID, $TABLE_NAME.$TARGET, $TABLE_NAME.$SEARCH_INPUT_ID, $TABLE_NAME.$LAST_UPDATE, $TABLE_NAME.$STATUS from $TABLE_NAME" + def selectStatement(id: String) : String = { + this.selectAllStatement + " where search_input_id in (select id from search_input where solr_index_id = '" + id + "')" + } + } \ No newline at end of file diff --git a/app/models/export/SearchInputExport.scala b/app/models/export/SearchInputExport.scala index 65db5156..4accfb48 100644 --- a/app/models/export/SearchInputExport.scala +++ b/app/models/export/SearchInputExport.scala @@ -71,4 +71,8 @@ object SearchInputExport { val selectAllStatement = s"select id, term, solr_index_id, last_update, status, comment from search_input" + def selectStatement(id: String) : String = { + s"select id, term, solr_index_id, last_update, status, comment from search_input where solr_index_id = '" + id + "'" + } + } diff --git a/app/models/export/SolrIndexExport.scala b/app/models/export/SolrIndexExport.scala index 2d2a6217..a98d0949 100644 --- a/app/models/export/SolrIndexExport.scala +++ b/app/models/export/SolrIndexExport.scala @@ -55,4 +55,8 @@ object SolrIndexExport extends CommonRuleFields { val selectAllStatement = s"select $TABLE_NAME.$ID, $TABLE_NAME.$ID, $TABLE_NAME.$DESCRIPTION, $TABLE_NAME.$LAST_UPDATE from $TABLE_NAME" + def selectStatement(id: String) = { + s"select $TABLE_NAME.$ID, $TABLE_NAME.$ID, $TABLE_NAME.$DESCRIPTION, $TABLE_NAME.$LAST_UPDATE from $TABLE_NAME where $TABLE_NAME.$ID = '" + id + "'" + } + } \ No newline at end of file diff --git a/app/models/export/SuggestedSolrFieldExport.scala b/app/models/export/SuggestedSolrFieldExport.scala index 28813572..456b75b0 100644 --- a/app/models/export/SuggestedSolrFieldExport.scala +++ b/app/models/export/SuggestedSolrFieldExport.scala @@ -59,4 +59,8 @@ object SuggestedSolrFieldExport { val selectAllStatement = s"select $TABLE_NAME.$ID, $TABLE_NAME.$NAME, $TABLE_NAME.$SOLR_INDEX_ID, $TABLE_NAME.$LAST_UPDATE from $TABLE_NAME" + def selectStatement(id: String) : String = { + this.selectAllStatement + " where solr_index_id = '" + id + "'" + } + } diff --git a/app/models/export/SynonymRuleExport.scala b/app/models/export/SynonymRuleExport.scala index 46928b55..871a6966 100644 --- a/app/models/export/SynonymRuleExport.scala +++ b/app/models/export/SynonymRuleExport.scala @@ -21,7 +21,7 @@ case class SynonymRuleExport(id: SynonymRuleId, JsArray( IndexedSeq ( JsString("id"), - JsString("synonymType"), + JsString("synonym_type"), JsString("term"), JsString("search_input_id"), JsString("last_update"), @@ -67,4 +67,7 @@ object SynonymRuleExport extends CommonRuleFields { val selectAllStatement = s"select $TABLE_NAME.$ID, $TABLE_NAME.$TYPE, $TABLE_NAME.$TERM, $TABLE_NAME.$STATUS, $TABLE_NAME.$SEARCH_INPUT_ID, $TABLE_NAME.$LAST_UPDATE from $TABLE_NAME" + def selectStatement(id: String) : String = { + this.selectAllStatement + " where search_input_id in " + s"(select id from search_input where solr_index_id = '" + id + "')" + } } \ No newline at end of file diff --git a/app/models/export/TagInputAssociationExport.scala b/app/models/export/TagInputAssociationExport.scala index f3209d28..f11ba269 100644 --- a/app/models/export/TagInputAssociationExport.scala +++ b/app/models/export/TagInputAssociationExport.scala @@ -64,4 +64,8 @@ object TagInputAssociationExport { s"$TABLE_NAME.$LAST_UPDATE from $TABLE_NAME" } + def selectStatement(id: String) : String = { + this.selectAllStatement + s" where $TABLE_NAME.$SEARCH_INPUT_ID in (select id from search_input where solr_index_id = '" + id + "')" + } + } \ No newline at end of file diff --git a/app/models/export/UpdownRuleExport.scala b/app/models/export/UpdownRuleExport.scala index aa3fbc64..e8d3c619 100644 --- a/app/models/export/UpdownRuleExport.scala +++ b/app/models/export/UpdownRuleExport.scala @@ -23,7 +23,7 @@ case class UpDownRuleExport(id: UpDownRuleId = UpDownRuleId(), IndexedSeq ( JsString("id"), JsString("up_down_type"), - JsString("boost_malus_type"), + JsString("boost_malus_value"), JsString("term"), JsString("search_input_id"), JsString("last_update"), @@ -39,9 +39,9 @@ case class UpDownRuleExport(id: UpDownRuleId = UpDownRuleId(), JsNumber(upDownType), JsNumber(boostMalusValue), JsString(term), - JsNumber(status), JsString(searchInputId.toString), - JsString(lastUpdate.toString) + JsString(lastUpdate.toString), + JsNumber(status) ) ) } @@ -94,4 +94,8 @@ object UpDownRuleExport extends CommonRuleFields { s"$TABLE_NAME.$LAST_UPDATE from $TABLE_NAME" } + def selectStatement(id: String) : String = { + this.selectAllStatement + " where search_input_id in (select id from search_input where solr_index_id = '" + id + "')" + } + } \ No newline at end of file diff --git a/app/models/validatedimport/ValidatedImportData.scala b/app/models/validatedimport/ValidatedImportData.scala new file mode 100644 index 00000000..5d92666e --- /dev/null +++ b/app/models/validatedimport/ValidatedImportData.scala @@ -0,0 +1,188 @@ +package models.validatedimport + +import play.api.Logging +import play.api.libs.json.{JsArray, JsObject, JsValue, Json} + +import java.util +import java.util.UUID +import scala.collection.mutable + +case class ValidatedImportData(content: String) extends Logging { + + var validTableNames: List[String] = List( + "alternative_spelling", + "canonical_spelling", + "synonym_rule", + "up_down_rule", + "redirect_rule", + "search_input", + "solr_index", + "delete_rule", + "input_tag", + "tag_2_input", + "suggested_solr_field", + "filter_rule") + + var inputJsonValue: Option[JsValue] = None + var tableCount: Int = 0 + var tableName: String = "" + var columnList: String = "" + var currentColumns: IndexedSeq[String] = IndexedSeq() + var statement: String = "" + var statements: IndexedSeq[String] = IndexedSeq() + var solr_index_id: String = "" + var old_solr_index_id: String = "" + val a_different_existing_solr_index_id: String = UUID.randomUUID().toString + val SUCCESS: Int = 0 + + var allStatementsConcatenated: String = "" + var replacementIds: mutable.HashMap[String, String] = mutable.HashMap() + + def isValid: Boolean = { + parseJson == SUCCESS + } + + def parseJson: Int = { + logger.debug("ValidatedImportData.parseJson():1 begin parsing") + inputJsonValue = Option(Json.parse(content)) + if (inputJsonValue.isDefined) { + val tables: IndexedSeq[JsValue] = inputJsonValue.get.as[JsArray].value + processTables(tables) + } + logger.debug("ValidatedImportData.parseJson():3 end parsing") + SUCCESS + } + + def processTables(input: IndexedSeq[JsValue]) : Unit = { + if (input.headOption.isEmpty) { + //printStatements(statements) + concatenateStatements(statements) + logger.debug(allStatementsConcatenated) + () + } else { + this.tableName = input.head.\("tableName").as[String] + if (validTableNames.contains(tableName)) { + this.tableCount = this.tableCount + 1 + + this.statement = "INSERT INTO " + tableName + " " + + val columns: IndexedSeq[JsValue] = input.head.\("columns").as[JsArray].value + this.currentColumns = IndexedSeq() + processColumns(columns, 0, (columns.size - 1)) + //logger.debug(currentColumns(1)) + + val rows: IndexedSeq[JsValue] = input.head.\("rows").as[JsArray].value + processRows(rows, 0, (rows.size - 1)) + this.statement += ";" + statements = statements :+ statement + //logger.debug(statement) + //logger.debug("tableCount: " + tableCount) + + processTables(input.drop(1)) + } + else { + logger.debug("Unrecognized tableName: " + tableName) + //skip any tables that we don't recognize + processTables(input.drop(1)) + } + } + } + + def processColumns(input: IndexedSeq[JsValue], index: Int, lastIndex: Int): Unit = { + if (input.headOption.isEmpty) { + this.statement += ") VALUES " + () + } else { + if (index == 0) this.statement += "(" + var columnName = input.head.toString().replace("\"", "") + this.currentColumns = this.currentColumns :+ columnName + this.statement += columnName + if (index != lastIndex) this.statement += "," + processColumns(input.drop(1), (index + 1), lastIndex) + } + } + + def processRow(input: IndexedSeq[JsValue], index: Int, lastIndex: Int): Unit = { + if (input.headOption.isEmpty) { + this.statement += ")" + () + } else { + if (index == 0) this.statement += "(" + var rawCellValue = input.head.toString().replace("\"", "") + var cellValue = input.head.toString().replace("\"", "\'") + + if (this.tableName.equals("solr_index")) { + //logger.debug(currentColumns(index)) + if (currentColumns(index).equals("id")) { + logger.debug("555 in id!") + this.old_solr_index_id = rawCellValue; + this.solr_index_id = "'" + this.a_different_existing_solr_index_id + "'" + cellValue = solr_index_id + } else if (currentColumns(index).equals("name")) { + logger.debug("555 in name!") + //this.solr_index_id = "'" + this.a_different_existing_solr_index_id + "'" + cellValue = "'" + rawCellValue + ", imported from (" + this.old_solr_index_id + ")'" + } else if (currentColumns(index).equals("description")) { + logger.debug("555 in description!") + cellValue = "'" + rawCellValue + ", imported from (" + this.old_solr_index_id + ")'" + } + } + else if (currentColumns(index).equals("id")) { + if (!replacementIds.contains(cellValue)) { + replacementIds.put(cellValue, UUID.randomUUID().toString) + } + //logger.debug("replacing " + cellValue) + cellValue = "'" + replacementIds.get(cellValue).head + "'" + //logger.debug("replaced it with :" + cellValue) + } + + if (this.tableName.equals("search_input") || + this.tableName.equals("suggested_solr_field") || + this.tableName.equals("input_tag") + ) { + if (currentColumns(index).equals("solr_index_id")) { + //logger.debug("replacing old solr_index_id " + cellValue + " with new one: '" + this.a_different_existing_solr_index_id + "''") + cellValue = "'" + this.a_different_existing_solr_index_id + "'" + } + } + + this.statement += cellValue + if (index != lastIndex) this.statement += "," + + processRow(input.drop(1), (index + 1), lastIndex) + } + } + + def processRows(input: IndexedSeq[JsValue], index: Int, lastIndex: Int): Unit = { + if (input.headOption.isEmpty) { + () + } else { + val row: IndexedSeq[JsValue] = input.head.as[JsArray].value + processRow(row, 0, (row.size - 1)) + if (index != lastIndex) { + this.statement += "," + } + processRows(input.drop(1), (index + 1), lastIndex) + } + } + + def printStatements(input: IndexedSeq[String]): Unit = { + if (input.headOption.isEmpty) { + () + } else { + logger.debug(input.head) + this.allStatementsConcatenated = this.allStatementsConcatenated + input.head + printStatements(input.drop(1)) + } + } + + def concatenateStatements(input: IndexedSeq[String]): Unit = { + if (input.headOption.isEmpty) { + () + } else { + this.allStatementsConcatenated = this.allStatementsConcatenated + " " + input.head + printStatements(input.drop(1)) + } + } + +} \ No newline at end of file diff --git a/app/models/validatedimport/ValidatedImportImporter.scala b/app/models/validatedimport/ValidatedImportImporter.scala new file mode 100644 index 00000000..01ba9c46 --- /dev/null +++ b/app/models/validatedimport/ValidatedImportImporter.scala @@ -0,0 +1,31 @@ +package models.validatedimport + +import anorm.SQL +import models.DatabaseExecutionContext +import models.FeatureToggleModel.FeatureToggleService +import play.api.{Logging, db} +import play.api.db.DBApi + +import javax.inject.Inject + +@javax.inject.Singleton +class ValidatedImportImporter @Inject()(validatedImportData: ValidatedImportData, + dbapi: DBApi, + toggleService: FeatureToggleService) + (implicit ec: DatabaseExecutionContext) extends Logging { + + private val db = dbapi.database("default") + + def performImport(): Unit = db.withTransaction { + implicit connection => { + if (validatedImportData.isValid) { + logger.debug(validatedImportData.allStatementsConcatenated) + validatedImportData.statements.foreach(statement => SQL(statement).execute()) + } + else { + logger.debug("ValidatedImportImporter.performImport():2: oops bad data?") + } + } + } + +} diff --git a/conf/routes b/conf/routes index 2ba2ecee..9e5b237a 100644 --- a/conf/routes +++ b/conf/routes @@ -40,6 +40,9 @@ GET /api/v1/version/latest-info controllers.ApiC GET /api/v1/solr-index/:solrIndexId/something controllers.ApiController.getSomething(solrIndexId: String) PUT /api/v1/put-something controllers.ApiController.putSomething GET /api/v1/get-export controllers.ApiController.getDatabaseJson +GET /api/v1/get-export-with-id/:id controllers.ApiController.getDatabaseJsonWithId(id: String) +POST /api/v1/upload-import controllers.ApiController.uploadImport +PUT /api/v1/putty controllers.ApiController.putty # Map static resources from the /public folder to the /assets URL path GET /*file controllers.FrontendController.assetOrDefault(file) diff --git a/frontend/src/app/app.module.ts b/frontend/src/app/app.module.ts index bed09d78..4248910e 100644 --- a/frontend/src/app/app.module.ts +++ b/frontend/src/app/app.module.ts @@ -81,6 +81,7 @@ import { RulesListComponent, RulesSearchComponent } from './components/rules-panel'; +import {FileUploadComponent} from "./components/chris/chris-rules-collection-create/file-upload.component"; @NgModule({ imports: [ @@ -122,6 +123,7 @@ import { ChrisComponent, // ChrisRulesCollectionListComponent, ChrisRulesCollectionCreateComponent, + FileUploadComponent // ChrisSuggestedFieldsComponent, // ChrisSuggestedFieldsCreateComponent, // ChrisSuggestedFieldsListComponent diff --git a/frontend/src/app/components/admin/rules-collection-list/rules-collection-list.component.ts b/frontend/src/app/components/admin/rules-collection-list/rules-collection-list.component.ts index fc2cecf8..115431e2 100644 --- a/frontend/src/app/components/admin/rules-collection-list/rules-collection-list.component.ts +++ b/frontend/src/app/components/admin/rules-collection-list/rules-collection-list.component.ts @@ -81,74 +81,97 @@ export class RulesCollectionListComponent implements OnInit, OnChanges { .catch(error => this.showErrorMsg.emit(error)); } - getSuggestedFields2(solrIndex: SolrIndex) { - //console.log("solrIndex.id is: " + solrIndex.id); - this.solrService.getSolrIndex(solrIndex.id) - .then(idx => { - //console.log('got here 2'); - this.getRulesReport(solrIndex.id); - }) - .catch(error => this.showErrorMsg.emit(error)); - } - - downloadRulesCollection(id: string, event: Event) { - this.solrService.getSolrIndex(id) - .then(solrIndex => this.getSuggestedFields2(solrIndex)) - this.toasterService.pop('success', '', 'Downloaded:' + id); - } - - getSomething(solrIndexId: string): Promise { - return this.http - //GET /api/v1/solr-index/:solrIndexId controllers.ApiController.getSolrIndex(solrIndexId: String) - .get(`${this.baseUrl}/solr-index/${solrIndexId}/something`) - .toPromise() - .then(returnValue => { - //this.savedOutput = output; - this.downloadFile(solrIndexId, JSON.stringify(returnValue)); //this.savedOutput)); - //this.downloadFile(solrIndexId + "json.txt", JSON.stringify(this.savedOutput)); - }); - } - - private getRulesReport(solrIndexId: string) { - this.getSomething(solrIndexId); - //this.solrService.listAllSolrIndices(solrIndexId).then(); - ///api/v1/:solrIndexId/rules-and-spellings - // this.reportService - // .getRulesReport(solrIndexId) - // .then(retReport => { - // this.rulesReport = retReport; - // this.downloadableRules = new DownloadableRules(); - // this.downloadableRules.id = solrIndexId; - // this.downloadableRules.rules = new Array(); - // - // this.rulesReport.items.forEach( - // (element) => { - // var x = new DownloadableRule(); - // x.inputId = element.inputId; - // x.inputTerm = element.inputTerm; - // x.details = element.details; - // x.term = element.term; - // x.isActive = element.isActive; - // x.inputModified = element.inputModified; - // x.inputTags = element.inputTags; - // x.modified = element.modified; - // this.downloadableRules?.rules?.push(x); - // } - // ); - // this.downloadFile(solrIndexId + ".json.txt", JSON.stringify(this.downloadableRules)); - // - // }) - // .catch(error => { - // // unpack and emit error message - // var errorMsg = 'Unknown error' - // if ('error' in error) { - // errorMsg = error.error.message; - // } - // this.showErrorMsg.emit(error) - // }); + // getSuggestedFields2(solrIndex: SolrIndex) { + // //console.log("solrIndex.id is: " + solrIndex.id); + // this.solrService.getSolrIndex(solrIndex.id) + // .then(idx => { + // //console.log('got here 2'); + // this.getRulesReport(solrIndex.id); + // }) + // .catch(error => this.showErrorMsg.emit(error)); + // } + + // downloadRulesCollection(id: string, event: Event) { + // this.solrService.getSolrIndex(id) + // .then(solrIndex => this.getSuggestedFields2(solrIndex)) + // this.toasterService.pop('success', '', 'Downloaded:' + id); + // } + + // getSomething(solrIndexId: string): Promise { + // return this.http + // //GET /api/v1/solr-index/:solrIndexId controllers.ApiController.getSolrIndex(solrIndexId: String) + // .get(`${this.baseUrl}/solr-index/${solrIndexId}/something`) + // .toPromise() + // .then(returnValue => { + // //this.savedOutput = output; + // this.downloadFile(solrIndexId, JSON.stringify(returnValue)); //this.savedOutput)); + // //this.downloadFile(solrIndexId + "json.txt", JSON.stringify(this.savedOutput)); + // }); + // } + + // private getRulesReport(solrIndexId: string) { + // this.getSomething(solrIndexId); + // //this.solrService.listAllSolrIndices(solrIndexId).then(); + // ///api/v1/:solrIndexId/rules-and-spellings + // // this.reportService + // // .getRulesReport(solrIndexId) + // // .then(retReport => { + // // this.rulesReport = retReport; + // // this.downloadableRules = new DownloadableRules(); + // // this.downloadableRules.id = solrIndexId; + // // this.downloadableRules.rules = new Array(); + // // + // // this.rulesReport.items.forEach( + // // (element) => { + // // var x = new DownloadableRule(); + // // x.inputId = element.inputId; + // // x.inputTerm = element.inputTerm; + // // x.details = element.details; + // // x.term = element.term; + // // x.isActive = element.isActive; + // // x.inputModified = element.inputModified; + // // x.inputTags = element.inputTags; + // // x.modified = element.modified; + // // this.downloadableRules?.rules?.push(x); + // // } + // // ); + // // this.downloadFile(solrIndexId + ".json.txt", JSON.stringify(this.downloadableRules)); + // // + // // }) + // // .catch(error => { + // // // unpack and emit error message + // // var errorMsg = 'Unknown error' + // // if ('error' in error) { + // // errorMsg = error.error.message; + // // } + // // this.showErrorMsg.emit(error) + // // }); + // } + + // private downloadFile(filename: string, text: string) { + // var element = document.createElement('a'); + // element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text)); + // element.setAttribute('download', filename); + // element.style.display = 'none'; + // document.body.appendChild(element); + // element.click(); + // document.body.removeChild(element); + // } + + downloadRulesCollection(id:String, event: Event) { + console.log("download()"); + this.solrService.getExportWithId(id).then( + result => { + var str = JSON.stringify(result); + this.downloadStringAsFile( + "file.json.txt", + str); + this.showSuccessMsg.emit("Download: OK") + } + ); } - private downloadFile(filename: string, text: string) { + downloadStringAsFile(filename: string, text: string) { var element = document.createElement('a'); element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text)); element.setAttribute('download', filename); diff --git a/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.html b/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.html index 778d7686..ceb1bace 100644 --- a/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.html +++ b/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.html @@ -1,70 +1,94 @@ -
    -
    -
    Add a Value
    -
    Add a new value.
    + + + + -
    - -
    - -
    -
    + + + + + + -
    -
    - -
    -
    + + + + + + + + + + + + -
    -
    + + + + + + + + + + + + + + + + + -
    -
    -
    - -
    -
    + + + + + + + + + + + + + + -
    -
    - -
    -
    + + + + + + + + + + + + + +
    +

    Import

    + + + -
    -
    - -
    -
    + + + + + + + + + + + + + + diff --git a/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.ts b/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.ts index 8eb9352b..5184d3d0 100644 --- a/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.ts +++ b/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.ts @@ -14,6 +14,8 @@ import { ModalService } from '../../../services'; +import {FileUploadComponent} from "./file-upload.component"; + @Component({ selector: 'app-smui-chris-chris-rules-collection-create', templateUrl: './chris-rules-collection-create.component.html' @@ -25,6 +27,7 @@ export class ChrisRulesCollectionCreateComponent implements OnInit, OnChanges { @Output() showSuccessMsg: EventEmitter = new EventEmitter(); @Output() refreshChrisRulesCollectionList: EventEmitter = new EventEmitter(); @Output() solrIndicesChange: EventEmitter = new EventEmitter(); + fuc: FileUploadComponent; solrIndices: SolrIndex[]; valueName: string; @@ -116,4 +119,12 @@ export class ChrisRulesCollectionCreateComponent implements OnInit, OnChanges { document.body.removeChild(element); } + onFileSelected(event: Event) { + console.log("event:" + event.target); + } + + putty(event: Event) { + this.solrService.putty().then(() => console.log("did putty")); + this.showSuccessMsg.emit("Putty: OK") + } } diff --git a/frontend/src/app/components/chris/chris-rules-collection-create/file-upload.component.html b/frontend/src/app/components/chris/chris-rules-collection-create/file-upload.component.html new file mode 100644 index 00000000..0d966101 --- /dev/null +++ b/frontend/src/app/components/chris/chris-rules-collection-create/file-upload.component.html @@ -0,0 +1,19 @@ + +
    +
    + + + +
    + + + + {{fileName || "No file uploaded yet."}} + +
    + +
    +
    diff --git a/frontend/src/app/components/chris/chris-rules-collection-create/file-upload.component.scss b/frontend/src/app/components/chris/chris-rules-collection-create/file-upload.component.scss new file mode 100644 index 00000000..8b9b1a2d --- /dev/null +++ b/frontend/src/app/components/chris/chris-rules-collection-create/file-upload.component.scss @@ -0,0 +1,3 @@ +.file-input { + display: none; +} diff --git a/frontend/src/app/components/chris/chris-rules-collection-create/file-upload.component.ts b/frontend/src/app/components/chris/chris-rules-collection-create/file-upload.component.ts new file mode 100644 index 00000000..3bb75b5a --- /dev/null +++ b/frontend/src/app/components/chris/chris-rules-collection-create/file-upload.component.ts @@ -0,0 +1,34 @@ +import {Component, ElementRef, ViewChild} from "@angular/core"; +import {HttpClient} from "@angular/common/http"; + +@Component({ + selector: 'file-upload', + templateUrl: "file-upload.component.html", + styleUrls: ["file-upload.component.scss"] +}) +export class FileUploadComponent { + fileName = ''; + target: EventTarget | null; + + @ViewChild('fileUpload') + myInputVariable: ElementRef; + + constructor(private http: HttpClient) { + } + + onFileSelected(event: Event) { + const target = event.target as HTMLInputElement; + if (target.files != null) { + const file: File = target.files[0]; + if (file) { + this.fileName = file.name; + const formData = new FormData(); + formData.append("uploadedFile", file); + const upload$ = this.http.post("/api/v1/upload-import", formData); + upload$.subscribe(); + this.fileName = 'Last file uploaded: ' + this.fileName; + this.myInputVariable.nativeElement.value = ''; + } + } + } +} diff --git a/frontend/src/app/components/header-nav/header-nav.component.html b/frontend/src/app/components/header-nav/header-nav.component.html index 99974860..15a94293 100644 --- a/frontend/src/app/components/header-nav/header-nav.component.html +++ b/frontend/src/app/components/header-nav/header-nav.component.html @@ -68,7 +68,7 @@ class="nav-link" [ngClass]="{ active: router.url === '/chris' }" routerLink="/chris" - >ChrisImport
  • diff --git a/frontend/src/app/services/solr.service.ts b/frontend/src/app/services/solr.service.ts index 18b2843a..426768f9 100644 --- a/frontend/src/app/services/solr.service.ts +++ b/frontend/src/app/services/solr.service.ts @@ -166,6 +166,14 @@ export class SolrService { .toPromise(); } + putty() { + const headers = { headers: this.jsonHeader }; + const body = JSON.stringify( { }); + return this.http + .put(`${this.baseUrl}/putty`, body, httpOptions) + .toPromise(); + } + getExport() { const headers = { headers: this.jsonHeader }; const body = {}; @@ -174,4 +182,12 @@ export class SolrService { .toPromise(); } + getExportWithId(id:String ) { + const headers = { headers: this.jsonHeader }; + const body = {}; + return this.http + .get(`${this.baseUrl}/get-export-with-id/${id}`, body) + .toPromise(); + } + } From d225b4036f5ffcde12accaa9f03ceaa08f355169 Mon Sep 17 00:00:00 2001 From: Chris Morley Date: Fri, 3 Jun 2022 13:06:42 -0400 Subject: [PATCH 16/25] chris->import --- app/controllers/ApiController.scala | 4 +-- app/models/SearchManagementRepository.scala | 5 --- .../validatedimport/ValidatedImportData.scala | 27 ++++++++++------ conf/routes | 1 + frontend/src/app/app-routing.module.ts | 4 +-- frontend/src/app/app.module.ts | 31 +++++-------------- .../chris-rules-collection-create/index.ts | 1 - .../chris-rules-collection-list/index.ts | 1 - ...chris-suggested-fields-list.component.html | 20 ------------ .../chris/chris-suggested-fields/index.ts | 3 -- frontend/src/app/components/chris/index.ts | 3 -- .../header-nav/header-nav.component.html | 4 +-- .../file-upload.component.html | 0 .../file-upload.component.scss | 0 .../file-upload.component.ts | 0 ...rt-rules-collection-create.component.html} | 0 ...port-rules-collection-create.component.ts} | 16 +++++----- .../import-rules-collection-create/index.ts | 1 + ...port-rules-collection-list.component.html} | 8 ++--- ...import-rules-collection-list.component.ts} | 14 ++++----- .../import-rules-collection-list/index.ts | 1 + ...rt-suggested-fields-create.component.html} | 12 +++---- ...port-suggested-fields-create.component.ts} | 20 ++++++------ ...mport-suggested-fields-list.component.html | 20 ++++++++++++ ...import-suggested-fields-list.component.ts} | 26 ++++++++-------- .../import-suggested-fields.component.html} | 14 ++++----- .../import-suggested-fields.component.ts} | 28 ++++++++--------- .../import/import-suggested-fields/index.ts | 0 .../import.component.html} | 4 +-- .../import.component.ts} | 10 +++--- frontend/src/app/components/import/index.ts | 1 + 31 files changed, 131 insertions(+), 148 deletions(-) delete mode 100644 frontend/src/app/components/chris/chris-rules-collection-create/index.ts delete mode 100644 frontend/src/app/components/chris/chris-rules-collection-list/index.ts delete mode 100644 frontend/src/app/components/chris/chris-suggested-fields/chris-suggested-fields-list/chris-suggested-fields-list.component.html delete mode 100644 frontend/src/app/components/chris/chris-suggested-fields/index.ts delete mode 100644 frontend/src/app/components/chris/index.ts rename frontend/src/app/components/{chris/chris-rules-collection-create => import/import-rules-collection-create}/file-upload.component.html (100%) rename frontend/src/app/components/{chris/chris-rules-collection-create => import/import-rules-collection-create}/file-upload.component.scss (100%) rename frontend/src/app/components/{chris/chris-rules-collection-create => import/import-rules-collection-create}/file-upload.component.ts (100%) rename frontend/src/app/components/{chris/chris-rules-collection-create/chris-rules-collection-create.component.html => import/import-rules-collection-create/import-rules-collection-create.component.html} (100%) rename frontend/src/app/components/{chris/chris-rules-collection-create/chris-rules-collection-create.component.ts => import/import-rules-collection-create/import-rules-collection-create.component.ts} (84%) create mode 100644 frontend/src/app/components/import/import-rules-collection-create/index.ts rename frontend/src/app/components/{chris/chris-rules-collection-list/chris-rules-collection-list.component.html => import/import-rules-collection-list/import-rules-collection-list.component.html} (65%) rename frontend/src/app/components/{chris/chris-rules-collection-list/chris-rules-collection-list.component.ts => import/import-rules-collection-list/import-rules-collection-list.component.ts} (73%) create mode 100644 frontend/src/app/components/import/import-rules-collection-list/index.ts rename frontend/src/app/components/{chris/chris-suggested-fields/chris-suggested-fields-create/chris-suggested-fields-create.component.html => import/import-suggested-fields/import-suggested-fields-create/import-suggested-fields-create.component.html} (63%) rename frontend/src/app/components/{chris/chris-suggested-fields/chris-suggested-fields-create/chris-suggested-fields-create.component.ts => import/import-suggested-fields/import-suggested-fields-create/import-suggested-fields-create.component.ts} (55%) create mode 100644 frontend/src/app/components/import/import-suggested-fields/import-suggested-fields-list/import-suggested-fields-list.component.html rename frontend/src/app/components/{chris/chris-suggested-fields/chris-suggested-fields-list/chris-suggested-fields-list.component.ts => import/import-suggested-fields/import-suggested-fields-list/import-suggested-fields-list.component.ts} (56%) rename frontend/src/app/components/{chris/chris-suggested-fields/chris-suggested-fields.component.html => import/import-suggested-fields/import-suggested-fields.component.html} (67%) rename frontend/src/app/components/{chris/chris-suggested-fields/chris-suggested-fields.component.ts => import/import-suggested-fields/import-suggested-fields.component.ts} (70%) create mode 100644 frontend/src/app/components/import/import-suggested-fields/index.ts rename frontend/src/app/components/{chris/chris.component.html => import/import.component.html} (86%) rename frontend/src/app/components/{chris/chris.component.ts => import/import.component.ts} (81%) create mode 100644 frontend/src/app/components/import/index.ts diff --git a/app/controllers/ApiController.scala b/app/controllers/ApiController.scala index 5c55e72d..7524c11d 100644 --- a/app/controllers/ApiController.scala +++ b/app/controllers/ApiController.scala @@ -666,7 +666,7 @@ class ApiController @Inject()(authActionFactory: AuthActionFactory, import java.nio.file.Files val content = Files.readString(temporaryFileToPath(request.body.files.head.ref)) logger.debug(content) - val validatedImport: ValidatedImportData = new ValidatedImportData(content) + val validatedImport: ValidatedImportData = new ValidatedImportData(fileName, content) if (tryDatabaseStuff) { searchManagementRepository.doImport(validatedImport) } @@ -690,7 +690,7 @@ class ApiController @Inject()(authActionFactory: AuthActionFactory, Future { logger.debug("In ApiController:putty") val content = "[{\"tableName\":\"solr_index\",\"columns\":[\"id\",\"name\",\"description\",\"last_update\"],\"rows\":[[\"b0eecea6-efa7-4575-9bb4-acba1aab146b\",\"b0eecea6-efa7-4575-9bb4-acba1aab146b\",\"test\",\"2022-05-31T11:14:38\"]]},{\"tableName\":\"search_input\",\"columns\":[\"id\",\"term\",\"solr_index_id\",\"last_update\",\"status\",\"comment\"],\"rows\":[[\"16c30efd-3139-4916-bfb6-57463af18250\",\"test\",\"b0eecea6-efa7-4575-9bb4-acba1aab146b\",\"2022-05-31T17:25:25\",1,\"updown comment\"],[\"5418428c-0d4c-4464-a2a6-084f264be360\",\"s\",\"b0eecea6-efa7-4575-9bb4-acba1aab146b\",\"2022-05-31T15:29:59\",1,\"syn com\"],[\"70823642-e7c6-4857-9d6c-a54b3c382f0d\",\"test\",\"b0eecea6-efa7-4575-9bb4-acba1aab146b\",\"2022-05-31T14:43:54\",1,\"\"],[\"89c10061-26d9-4b5f-9e99-92696cc5da74\",\"test two three\",\"b0eecea6-efa7-4575-9bb4-acba1aab146b\",\"2022-05-31T13:43:50\",1,\"a comment\"],[\"9fb7f8b4-5544-4df0-9d08-d485a0145dbe\",\"redirect\",\"b0eecea6-efa7-4575-9bb4-acba1aab146b\",\"2022-05-31T17:20:36\",1,\"redirect comment\"],[\"ccc48739-f192-44b1-b552-995eed4a0a51\",\"all\",\"b0eecea6-efa7-4575-9bb4-acba1aab146b\",\"2022-05-31T14:41:55\",1,\"\"],[\"dd1bd496-90ed-43ad-9895-e67a4f67adeb\",\"test1\",\"b0eecea6-efa7-4575-9bb4-acba1aab146b\",\"2022-05-31T13:54:27\",1,\"\"],[\"e8064dd4-0e76-4e0b-963a-06ea8cae65e2\",\"t345\",\"b0eecea6-efa7-4575-9bb4-acba1aab146b\",\"2022-05-31T14:56:51\",1,\"c\"]]},{\"tableName\":\"redirect_rule\",\"columns\":[\"id\",\"target\",\"search_input_id\",\"last_update\",\"status\"],\"rows\":[[\"89e5833a-64b4-4a97-924b-a18b66694437\",\"https://www.google.com\",\"9fb7f8b4-5544-4df0-9d08-d485a0145dbe\",\"2022-05-31T17:20:36\",1]]},{\"tableName\":\"synonym_rule\",\"columns\":[\"id\",\"synonymType\",\"term\",\"search_input_id\",\"last_update\",\"status\"],\"rows\":[[\"70d3eb55-ad67-4890-a157-130ea72637c1\",0,\"y\",\"5418428c-0d4c-4464-a2a6-084f264be360\",\"2022-05-31T15:29:59\",1]]},{\"tableName\":\"up_down_rule\",\"columns\":[\"id\",\"up_down_type\",\"boost_malus_type\",\"term\",\"search_input_id\",\"last_update\",\"status\"],\"rows\":[[\"a26f49ad-28ba-40e3-a968-ada168d948c7\",0,5,\"* a:test\",1,\"16c30efd-3139-4916-bfb6-57463af18250\",\"2022-05-31T17:25:25\"]]},{\"tableName\":\"delete_rule\",\"columns\":[\"id\",\"term\",\"search_input_id\",\"last_update\",\"status\"],\"rows\":[[\"36d7a7d2-4133-4bcc-b4b3-19ec6d0404d1\",\"two\",\"89c10061-26d9-4b5f-9e99-92696cc5da74\",\"2022-05-31T13:43:50\",1]]},{\"tableName\":\"filter_rule\",\"columns\":[\"id\",\"term\",\"search_input_id\",\"last_update\",\"status\"],\"rows\":[[\"8ed6c4bd-ac69-4a94-898c-fabb13a7fc47\",\"* test:* a:b\",\"e8064dd4-0e76-4e0b-963a-06ea8cae65e2\",\"2022-05-31T14:56:51\",1]]},{\"tableName\":\"suggested_solr_field\",\"columns\":[\"id\",\"name\",\"solr_index_id\",\"last_update\"],\"rows\":[[\"4ce83b3a-7263-4873-b4f2-a66a9321fdbb\",\"test\",\"b0eecea6-efa7-4575-9bb4-acba1aab146b\",\"2022-05-31T17:37:43\"]]},{\"tableName\":\"input_tag\",\"columns\":[\"id\",\"solr_index_id\",\"property\",\"tag_value\",\"exported\",\"predefined\",\"last_update\"],\"rows\":[[\"wh\",\"some solr_index_id\",\"some property\",\"some tag_value\",2345,123,\"2022-05-31T18:23:47\"]]},{\"tableName\":\"tag_2_input\",\"columns\":[\"id\",\"searchInputId\",\"last_update\"],\"rows\":[[\"hi\",\"3\",\"2022-05-31T18:22:14\"]]},{\"tableName\":\"canonical_spelling\",\"columns\":[\"id\",\"solr_index_id\",\"term\",\"status\",\"comment\",\"last_update\"],\"rows\":[[\"id8\",\"id9\",\"a_term_can_spell\",0,\"can_spell_comment\",\"2022-05-31T18:44:15\"]]},{\"tableName\":\"alternative_spelling\",\"columns\":[\"id\",\"canonical_spelling_id\",\"term\",\"status\",\"last_update\"],\"rows\":[[\"id10\",\"id11\",\"alt_spell_term\",0,\"2022-05-31T18:44:15\"]]}]" - val validatedImport: ValidatedImportData = new ValidatedImportData(content) + val validatedImport: ValidatedImportData = new ValidatedImportData("unknown.txt", content) searchManagementRepository.doImport(validatedImport) Ok(Json.toJson(ApiResult(API_RESULT_OK, "OK.", None))) } diff --git a/app/models/SearchManagementRepository.scala b/app/models/SearchManagementRepository.scala index 5cedc327..c944a67a 100644 --- a/app/models/SearchManagementRepository.scala +++ b/app/models/SearchManagementRepository.scala @@ -1,4 +1,3 @@ -//CJM 9 package models import anorm.SqlParser.get @@ -43,10 +42,6 @@ class SearchManagementRepository @Inject()(dbapi: DBApi, toggleService: FeatureT SolrIndex.loadById(solrIndexId) } -// def getSolrIndex(solrIndexId: String): SolrIndex = db.withConnection { implicit connection => -// SolrIndex.loadById(solrIndexId) -// } - def addNewSolrIndex(newSolrIndex: SolrIndex): SolrIndexId = db.withConnection { implicit connection => SolrIndex.insert(newSolrIndex) } diff --git a/app/models/validatedimport/ValidatedImportData.scala b/app/models/validatedimport/ValidatedImportData.scala index 5d92666e..5845f095 100644 --- a/app/models/validatedimport/ValidatedImportData.scala +++ b/app/models/validatedimport/ValidatedImportData.scala @@ -7,7 +7,7 @@ import java.util import java.util.UUID import scala.collection.mutable -case class ValidatedImportData(content: String) extends Logging { +case class ValidatedImportData(filename: String, content: String) extends Logging { var validTableNames: List[String] = List( "alternative_spelling", @@ -32,8 +32,10 @@ case class ValidatedImportData(content: String) extends Logging { var statements: IndexedSeq[String] = IndexedSeq() var solr_index_id: String = "" var old_solr_index_id: String = "" - val a_different_existing_solr_index_id: String = UUID.randomUUID().toString + var a_different_existing_solr_index_id: String = UUID.randomUUID().toString + var a_shorthand_id: String = "" val SUCCESS: Int = 0 + var inputFilename: String = "" var allStatementsConcatenated: String = "" var replacementIds: mutable.HashMap[String, String] = mutable.HashMap() @@ -43,6 +45,9 @@ case class ValidatedImportData(content: String) extends Logging { } def parseJson: Int = { + this.inputFilename = filename + a_different_existing_solr_index_id = UUID.randomUUID().toString + a_shorthand_id = a_different_existing_solr_index_id.substring(0, 8) logger.debug("ValidatedImportData.parseJson():1 begin parsing") inputJsonValue = Option(Json.parse(content)) if (inputJsonValue.isDefined) { @@ -114,17 +119,17 @@ case class ValidatedImportData(content: String) extends Logging { if (this.tableName.equals("solr_index")) { //logger.debug(currentColumns(index)) if (currentColumns(index).equals("id")) { - logger.debug("555 in id!") this.old_solr_index_id = rawCellValue; this.solr_index_id = "'" + this.a_different_existing_solr_index_id + "'" cellValue = solr_index_id - } else if (currentColumns(index).equals("name")) { - logger.debug("555 in name!") + } else if (currentColumns(index).equals("name") || currentColumns(index).equals("description")) { + var old_id_shorthand = this.old_solr_index_id.substring(0, 8) + var sds = shortDistinguishedString + logger.debug("cur col:" + currentColumns(index)) + logger.debug("rawCellValue: " + rawCellValue) + logger.debug("old_id_shorthand: " + old_id_shorthand) //this.solr_index_id = "'" + this.a_different_existing_solr_index_id + "'" - cellValue = "'" + rawCellValue + ", imported from (" + this.old_solr_index_id + ")'" - } else if (currentColumns(index).equals("description")) { - logger.debug("555 in description!") - cellValue = "'" + rawCellValue + ", imported from (" + this.old_solr_index_id + ")'" + cellValue = "'" + rawCellValue + ", (file: " + inputFilename + " copied from key: " + old_id_shorthand + ") " + sds + "'" } } else if (currentColumns(index).equals("id")) { @@ -185,4 +190,8 @@ case class ValidatedImportData(content: String) extends Logging { } } + def shortDistinguishedString: String = { + UUID.randomUUID().toString.substring(0, 8) + } + } \ No newline at end of file diff --git a/conf/routes b/conf/routes index 9e5b237a..19e8b458 100644 --- a/conf/routes +++ b/conf/routes @@ -37,6 +37,7 @@ GET /api/v1/log/rule-activity-log controllers.ApiC GET /api/v1/report/rules-report/:solrIndexId controllers.ApiController.getRulesReport(solrIndexId: String) GET /api/v1/report/activity-report/:solrIndexId controllers.ApiController.getActivityReport(solrIndexId: String) GET /api/v1/version/latest-info controllers.ApiController.getLatestVersionInfo() + GET /api/v1/solr-index/:solrIndexId/something controllers.ApiController.getSomething(solrIndexId: String) PUT /api/v1/put-something controllers.ApiController.putSomething GET /api/v1/get-export controllers.ApiController.getDatabaseJson diff --git a/frontend/src/app/app-routing.module.ts b/frontend/src/app/app-routing.module.ts index 976e38e2..b26156ca 100644 --- a/frontend/src/app/app-routing.module.ts +++ b/frontend/src/app/app-routing.module.ts @@ -4,7 +4,7 @@ import { Routes, RouterModule } from '@angular/router'; import { SearchManagementComponent } from './components/search-management'; import { ReportComponent } from './components/report'; import { AdminComponent } from './components/admin'; -import { ChrisComponent } from './components/chris'; +import { ImportComponent } from './components/import'; import { SuggestedFieldsComponent } from './components/admin/suggested-fields'; const routes: Routes = [ @@ -12,7 +12,7 @@ const routes: Routes = [ { path: 'rules', component: SearchManagementComponent }, { path: 'report', component: ReportComponent }, { path: 'admin', component: AdminComponent }, - { path: 'chris', component: ChrisComponent }, + { path: 'import', component: ImportComponent }, { path: 'admin/suggested-fields/:solrIndexId', component: SuggestedFieldsComponent } ]; diff --git a/frontend/src/app/app.module.ts b/frontend/src/app/app.module.ts index 4248910e..77ef5e99 100644 --- a/frontend/src/app/app.module.ts +++ b/frontend/src/app/app.module.ts @@ -45,25 +45,12 @@ import { } from './components/admin/suggested-fields'; import { - ChrisComponent, - //ChrisRulesCollectionListComponent, - //ChrisRulesCollectionCreateComponent -} from './components/chris'; + ImportComponent +} from './components/import'; import { - ChrisRulesCollectionCreateComponent -} from './components/chris/chris-rules-collection-create'; - -import { - ChrisRulesCollectionListComponent -} from './components/chris/chris-rules-collection-list'; - -// import { -// ChrisSuggestedFieldsComponent, -// ChrisSuggestedFieldsCreateComponent, -// ChrisSuggestedFieldsListComponent -// } from './components/chris/chris-suggested-fields'; - + ImportRulesCollectionCreateComponent +} from './components/import/import-rules-collection-create'; import { ButtonRowComponent, @@ -81,7 +68,7 @@ import { RulesListComponent, RulesSearchComponent } from './components/rules-panel'; -import {FileUploadComponent} from "./components/chris/chris-rules-collection-create/file-upload.component"; +import {FileUploadComponent} from "./components/import/import-rules-collection-create/file-upload.component"; @NgModule({ imports: [ @@ -120,13 +107,9 @@ import {FileUploadComponent} from "./components/chris/chris-rules-collection-cre SuggestedFieldsComponent, SuggestedFieldsCreateComponent, SuggestedFieldsListComponent, - ChrisComponent, - // ChrisRulesCollectionListComponent, - ChrisRulesCollectionCreateComponent, + ImportComponent, + ImportRulesCollectionCreateComponent, FileUploadComponent - // ChrisSuggestedFieldsComponent, - // ChrisSuggestedFieldsCreateComponent, - // ChrisSuggestedFieldsListComponent ], providers: [ CommonsService, diff --git a/frontend/src/app/components/chris/chris-rules-collection-create/index.ts b/frontend/src/app/components/chris/chris-rules-collection-create/index.ts deleted file mode 100644 index 9f5db22b..00000000 --- a/frontend/src/app/components/chris/chris-rules-collection-create/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './chris-rules-collection-create.component'; diff --git a/frontend/src/app/components/chris/chris-rules-collection-list/index.ts b/frontend/src/app/components/chris/chris-rules-collection-list/index.ts deleted file mode 100644 index 7e92b45b..00000000 --- a/frontend/src/app/components/chris/chris-rules-collection-list/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './chris-rules-collection-list.component'; diff --git a/frontend/src/app/components/chris/chris-suggested-fields/chris-suggested-fields-list/chris-suggested-fields-list.component.html b/frontend/src/app/components/chris/chris-suggested-fields/chris-suggested-fields-list/chris-suggested-fields-list.component.html deleted file mode 100644 index 77aa7058..00000000 --- a/frontend/src/app/components/chris/chris-suggested-fields/chris-suggested-fields-list/chris-suggested-fields-list.component.html +++ /dev/null @@ -1,20 +0,0 @@ -
    -
    -
    Chris Suggested Fields
    -
    Available Chris suggested fields in SMUI
    - -
      -
    • - {{ chrisSuggestedField.name }} - Key: {{ chrisSuggestedField.id }} - - -
    • -
    -
    -
    diff --git a/frontend/src/app/components/chris/chris-suggested-fields/index.ts b/frontend/src/app/components/chris/chris-suggested-fields/index.ts deleted file mode 100644 index ac9ee12b..00000000 --- a/frontend/src/app/components/chris/chris-suggested-fields/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -// export * from './chris-suggested-fields.component'; -// export * from './chris-suggested-fields-create/chris-suggested-fields-create.component'; -// export * from './chris-suggested-fields-list/chris-suggested-fields-list.component'; diff --git a/frontend/src/app/components/chris/index.ts b/frontend/src/app/components/chris/index.ts deleted file mode 100644 index 9b13bfaa..00000000 --- a/frontend/src/app/components/chris/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './chris.component'; -//export * from './chris-rules-collection-list/chris-rules-collection-list.component'; -//export * from './chris-rules-collection-create/chris-rules-collection-create.component'; diff --git a/frontend/src/app/components/header-nav/header-nav.component.html b/frontend/src/app/components/header-nav/header-nav.component.html index 15a94293..6761c06b 100644 --- a/frontend/src/app/components/header-nav/header-nav.component.html +++ b/frontend/src/app/components/header-nav/header-nav.component.html @@ -66,8 +66,8 @@
  • diff --git a/frontend/src/app/components/chris/chris-rules-collection-create/file-upload.component.html b/frontend/src/app/components/import/import-rules-collection-create/file-upload.component.html similarity index 100% rename from frontend/src/app/components/chris/chris-rules-collection-create/file-upload.component.html rename to frontend/src/app/components/import/import-rules-collection-create/file-upload.component.html diff --git a/frontend/src/app/components/chris/chris-rules-collection-create/file-upload.component.scss b/frontend/src/app/components/import/import-rules-collection-create/file-upload.component.scss similarity index 100% rename from frontend/src/app/components/chris/chris-rules-collection-create/file-upload.component.scss rename to frontend/src/app/components/import/import-rules-collection-create/file-upload.component.scss diff --git a/frontend/src/app/components/chris/chris-rules-collection-create/file-upload.component.ts b/frontend/src/app/components/import/import-rules-collection-create/file-upload.component.ts similarity index 100% rename from frontend/src/app/components/chris/chris-rules-collection-create/file-upload.component.ts rename to frontend/src/app/components/import/import-rules-collection-create/file-upload.component.ts diff --git a/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.html b/frontend/src/app/components/import/import-rules-collection-create/import-rules-collection-create.component.html similarity index 100% rename from frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.html rename to frontend/src/app/components/import/import-rules-collection-create/import-rules-collection-create.component.html diff --git a/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.ts b/frontend/src/app/components/import/import-rules-collection-create/import-rules-collection-create.component.ts similarity index 84% rename from frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.ts rename to frontend/src/app/components/import/import-rules-collection-create/import-rules-collection-create.component.ts index 5184d3d0..3f694872 100644 --- a/frontend/src/app/components/chris/chris-rules-collection-create/chris-rules-collection-create.component.ts +++ b/frontend/src/app/components/import/import-rules-collection-create/import-rules-collection-create.component.ts @@ -17,15 +17,15 @@ import { import {FileUploadComponent} from "./file-upload.component"; @Component({ - selector: 'app-smui-chris-chris-rules-collection-create', - templateUrl: './chris-rules-collection-create.component.html' + selector: 'app-smui-import-import-rules-collection-create', + templateUrl: './import-rules-collection-create.component.html' }) -export class ChrisRulesCollectionCreateComponent implements OnInit, OnChanges { +export class ImportRulesCollectionCreateComponent implements OnInit, OnChanges { //@Output() updateRulesCollectionList: EventEmitter<> = new EventEmitter(); @Output() showErrorMsg: EventEmitter = new EventEmitter(); @Output() showSuccessMsg: EventEmitter = new EventEmitter(); - @Output() refreshChrisRulesCollectionList: EventEmitter = new EventEmitter(); + @Output() refreshImportRulesCollectionList: EventEmitter = new EventEmitter(); @Output() solrIndicesChange: EventEmitter = new EventEmitter(); fuc: FileUploadComponent; @@ -38,12 +38,12 @@ export class ChrisRulesCollectionCreateComponent implements OnInit, OnChanges { } ngOnInit() { - console.log('In ChrisRulesCollectionCreateComponent :: ngOnInit'); + console.log('In ImportRulesCollectionCreateComponent :: ngOnInit'); this.solrIndices = this.solrService.solrIndices; } ngOnChanges(changes: SimpleChanges): void { - console.log('In ChrisRulesCollectionCreateComponent :: ngOnChanges'); + console.log('In ImportRulesCollectionCreateComponent :: ngOnChanges'); } refreshSolrIndicies() { @@ -58,7 +58,7 @@ export class ChrisRulesCollectionCreateComponent implements OnInit, OnChanges { addOneValue( event: Event){ if (this.valueName) { console.log("addOneValue() , thingName: " + this.valueName); - //console.log('In ChrisRulesCollectidonCreateComponent :: createChrisRulesCollection'); + //console.log('In ImportRulesCollectidonCreateComponent :: createImportRulesCollection'); this.solrService.putSomething2(this.valueName) .then(() => this.showSuccessMsg.emit("Add Value: OK")); // @@ -67,7 +67,7 @@ export class ChrisRulesCollectionCreateComponent implements OnInit, OnChanges { // .createSolrIndex(this.name, this.description) // .then(() => this.solrService.listAllSolrIndices()) // .then(() => this.solrIndicesChange.emit()) - // .then(() => this.showSuccessMsg.emit("Created new Chris Rules Collection " + this.description)) + // .then(() => this.showSuccessMsg.emit("Created new Import Rules Collection " + this.description)) // .then(() => this.solrService.emitRulesCollectionChangeEvent("")) // .then(() => this.clearForm()) // .catch(error => this.showErrorMsg.emit(error)); diff --git a/frontend/src/app/components/import/import-rules-collection-create/index.ts b/frontend/src/app/components/import/import-rules-collection-create/index.ts new file mode 100644 index 00000000..0a267e3f --- /dev/null +++ b/frontend/src/app/components/import/import-rules-collection-create/index.ts @@ -0,0 +1 @@ +export * from './import-rules-collection-create.component'; diff --git a/frontend/src/app/components/chris/chris-rules-collection-list/chris-rules-collection-list.component.html b/frontend/src/app/components/import/import-rules-collection-list/import-rules-collection-list.component.html similarity index 65% rename from frontend/src/app/components/chris/chris-rules-collection-list/chris-rules-collection-list.component.html rename to frontend/src/app/components/import/import-rules-collection-list/import-rules-collection-list.component.html index d09d0418..ac2cf855 100644 --- a/frontend/src/app/components/chris/chris-rules-collection-list/chris-rules-collection-list.component.html +++ b/frontend/src/app/components/import/import-rules-collection-list/import-rules-collection-list.component.html @@ -1,8 +1,8 @@
    -
    Chris Rules Collections
    -
    Available Chris Rules Collections in SMUI
    +
    Import Rules Collections
    +
    Available Import Rules Collections in SMUI
    • @@ -10,13 +10,13 @@
      Available Chris Rules Collections in S - + Configure diff --git a/frontend/src/app/components/chris/chris-rules-collection-list/chris-rules-collection-list.component.ts b/frontend/src/app/components/import/import-rules-collection-list/import-rules-collection-list.component.ts similarity index 73% rename from frontend/src/app/components/chris/chris-rules-collection-list/chris-rules-collection-list.component.ts rename to frontend/src/app/components/import/import-rules-collection-list/import-rules-collection-list.component.ts index b7e7954f..d2a1dc68 100644 --- a/frontend/src/app/components/chris/chris-rules-collection-list/chris-rules-collection-list.component.ts +++ b/frontend/src/app/components/import/import-rules-collection-list/import-rules-collection-list.component.ts @@ -15,10 +15,10 @@ import { } from '../../../services'; @Component({ - selector: 'app-smui-chris-chris-rules-collection-list', - templateUrl: './chris-rules-collection-list.component.html' + selector: 'app-smui-import-import-rules-collection-list', + templateUrl: './import-rules-collection-list.component.html' }) -export class ChrisRulesCollectionListComponent implements OnInit, OnChanges { +export class ImportRulesCollectionListComponent implements OnInit, OnChanges { @Output() openDeleteConfirmModal: EventEmitter = new EventEmitter(); @Output() showErrorMsg: EventEmitter = new EventEmitter(); @@ -35,14 +35,14 @@ export class ChrisRulesCollectionListComponent implements OnInit, OnChanges { } ngOnInit() { - console.log('In ChrisRulesCollectionListComponent :: ngOnInit'); + console.log('In ImportRulesCollectionListComponent :: ngOnInit'); } ngOnChanges(changes: SimpleChanges): void { - console.log('In ChrisRulesCollectionListComponent :: ngOnChanges'); + console.log('In ImportRulesCollectionListComponent :: ngOnChanges'); } - deleteChrisRulesCollection(id: string, event: Event) { + deleteImportRulesCollection(id: string, event: Event) { event.stopPropagation(); const deleteCallback = () => this.solrService @@ -50,7 +50,7 @@ export class ChrisRulesCollectionListComponent implements OnInit, OnChanges { .then(() => this.solrService.listAllSolrIndices()) .then(() => this.solrIndicesChange.emit(id)) .then(() => this.solrService.emitRulesCollectionChangeEvent("")) - .then(() => this.showSuccessMsg.emit("Chris Rule collection successfully deleted.")) + .then(() => this.showSuccessMsg.emit("Import Rule collection successfully deleted.")) .catch(error => { // unpack and emit error message var errorMsg = 'Unknown error' diff --git a/frontend/src/app/components/import/import-rules-collection-list/index.ts b/frontend/src/app/components/import/import-rules-collection-list/index.ts new file mode 100644 index 00000000..0332a6bd --- /dev/null +++ b/frontend/src/app/components/import/import-rules-collection-list/index.ts @@ -0,0 +1 @@ +export * from './import-rules-collection-list.component'; diff --git a/frontend/src/app/components/chris/chris-suggested-fields/chris-suggested-fields-create/chris-suggested-fields-create.component.html b/frontend/src/app/components/import/import-suggested-fields/import-suggested-fields-create/import-suggested-fields-create.component.html similarity index 63% rename from frontend/src/app/components/chris/chris-suggested-fields/chris-suggested-fields-create/chris-suggested-fields-create.component.html rename to frontend/src/app/components/import/import-suggested-fields/import-suggested-fields-create/import-suggested-fields-create.component.html index 8cb76657..07c24d23 100644 --- a/frontend/src/app/components/chris/chris-suggested-fields/chris-suggested-fields-create/chris-suggested-fields-create.component.html +++ b/frontend/src/app/components/import/import-suggested-fields/import-suggested-fields-create/import-suggested-fields-create.component.html @@ -1,12 +1,12 @@
      -
      Add Suggested Chris Field
      -
      Add a new Suggested Chris Field to the rules collection {{solrIndex.description}}
      +
      Add Suggested Import Field
      +
      Add a new Suggested Import Field to the rules collection {{solrIndex.description}}
      - +
      - +
      @@ -15,9 +15,9 @@
      Add a new Suggested Chris Field to the
      diff --git a/frontend/src/app/components/chris/chris-suggested-fields/chris-suggested-fields-create/chris-suggested-fields-create.component.ts b/frontend/src/app/components/import/import-suggested-fields/import-suggested-fields-create/import-suggested-fields-create.component.ts similarity index 55% rename from frontend/src/app/components/chris/chris-suggested-fields/chris-suggested-fields-create/chris-suggested-fields-create.component.ts rename to frontend/src/app/components/import/import-suggested-fields/import-suggested-fields-create/import-suggested-fields-create.component.ts index 70d95e4c..d729c9cd 100644 --- a/frontend/src/app/components/chris/chris-suggested-fields/chris-suggested-fields-create/chris-suggested-fields-create.component.ts +++ b/frontend/src/app/components/import/import-suggested-fields/import-suggested-fields-create/import-suggested-fields-create.component.ts @@ -15,15 +15,15 @@ import { } from '../../../../services'; @Component({ - selector: 'app-smui-chris-suggested-fields-create', - templateUrl: './chris-suggested-fields-create.component.html' + selector: 'app-smui-import-suggested-fields-create', + templateUrl: './import-suggested-fields-create.component.html' }) -export class ChrisSuggestedFieldsCreateComponent implements OnInit, OnChanges { +export class ImportSuggestedFieldsCreateComponent implements OnInit, OnChanges { @Input() solrIndex: SolrIndex; @Output() showErrorMsg: EventEmitter = new EventEmitter(); @Output() showSuccessMsg: EventEmitter = new EventEmitter(); - @Output() chrisSuggestedFieldsChange: EventEmitter = new EventEmitter(); + @Output() importSuggestedFieldsChange: EventEmitter = new EventEmitter(); name: string; suggestedFields: SuggestedSolrField[] = []; @@ -34,11 +34,11 @@ export class ChrisSuggestedFieldsCreateComponent implements OnInit, OnChanges { } ngOnInit() { - console.log('In ChrisSuggestedFieldsCreateComponent :: ngOnInit'); + console.log('In ImportSuggestedFieldsCreateComponent :: ngOnInit'); } ngOnChanges(changes: SimpleChanges): void { - console.log('In ChrisSuggestedFieldsCreateComponent :: ngOnChanges'); + console.log('In ImportSuggestedFieldsCreateComponent :: ngOnChanges'); } @@ -46,13 +46,13 @@ export class ChrisSuggestedFieldsCreateComponent implements OnInit, OnChanges { this.name = ''; } - createChrisSuggestedField( event: Event){ - console.log('In ChrisSuggestedFieldsCreateComponent :: createSuggestedField'); + createImportSuggestedField( event: Event){ + console.log('In ImportSuggestedFieldsCreateComponent :: createSuggestedField'); if (this.name) { this.solrService .createSuggestedField(this.solrIndex.id, this.name) - .then(() => this.showSuccessMsg.emit("Created new Chris Suggested Field " + this.name)) - .then(() => this.chrisSuggestedFieldsChange.emit()) + .then(() => this.showSuccessMsg.emit("Created new Import Suggested Field " + this.name)) + .then(() => this.importSuggestedFieldsChange.emit()) .then(() => this.clearForm()) .catch(error => this.showErrorMsg.emit(error)); } diff --git a/frontend/src/app/components/import/import-suggested-fields/import-suggested-fields-list/import-suggested-fields-list.component.html b/frontend/src/app/components/import/import-suggested-fields/import-suggested-fields-list/import-suggested-fields-list.component.html new file mode 100644 index 00000000..f2b9f190 --- /dev/null +++ b/frontend/src/app/components/import/import-suggested-fields/import-suggested-fields-list/import-suggested-fields-list.component.html @@ -0,0 +1,20 @@ +
      +
      +
      Import Suggested Fields
      +
      Available Import suggested fields in SMUI
      + +
        +
      • + {{ importSuggestedField.name }} - Key: {{ importSuggestedField.id }} + + +
      • +
      +
      +
      diff --git a/frontend/src/app/components/chris/chris-suggested-fields/chris-suggested-fields-list/chris-suggested-fields-list.component.ts b/frontend/src/app/components/import/import-suggested-fields/import-suggested-fields-list/import-suggested-fields-list.component.ts similarity index 56% rename from frontend/src/app/components/chris/chris-suggested-fields/chris-suggested-fields-list/chris-suggested-fields-list.component.ts rename to frontend/src/app/components/import/import-suggested-fields/import-suggested-fields-list/import-suggested-fields-list.component.ts index ff8458d4..baf03b6a 100644 --- a/frontend/src/app/components/chris/chris-suggested-fields/chris-suggested-fields-list/chris-suggested-fields-list.component.ts +++ b/frontend/src/app/components/import/import-suggested-fields/import-suggested-fields-list/import-suggested-fields-list.component.ts @@ -14,18 +14,18 @@ import { } from '../../../../services'; @Component({ - selector: 'app-smui-chris-suggested-fields-list', - templateUrl: './chris-suggested-fields-list.component.html' + selector: 'app-smui-import-suggested-fields-list', + templateUrl: './import-suggested-fields-list.component.html' }) -export class ChrisSuggestedFieldsListComponent implements OnInit, OnChanges { +export class ImportSuggestedFieldsListComponent implements OnInit, OnChanges { @Input() solrIndex: SolrIndex; - @Input() chrisSuggestedFields: Array; + @Input() importSuggestedFields: Array; @Output() openDeleteConfirmModal: EventEmitter = new EventEmitter(); @Output() showErrorMsg: EventEmitter = new EventEmitter(); @Output() solrIndicesChange: EventEmitter = new EventEmitter(); - @Output() chrisSuggestedFieldsChange: EventEmitter = new EventEmitter(); + @Output() importSuggestedFieldsChange: EventEmitter = new EventEmitter(); constructor( private solrService: SolrService, @@ -34,31 +34,31 @@ export class ChrisSuggestedFieldsListComponent implements OnInit, OnChanges { } ngOnInit() { - console.log('In ChrisSuggestedFieldsListComponent :: ngOnInit'); + console.log('In ImportSuggestedFieldsListComponent :: ngOnInit'); } ngOnChanges(changes: SimpleChanges): void { - console.log('In ChrisSuggestedFieldsListComponent :: ngOnChanges'); + console.log('In ImportSuggestedFieldsListComponent :: ngOnChanges'); } - lookupChrisSuggestedFields() { - console.log('In ChrisSuggestedFieldsListComponent :: lookupSuggestedFields'); + lookupImportSuggestedFields() { + console.log('In ImportSuggestedFieldsListComponent :: lookupSuggestedFields'); this.solrService.getSuggestedFields(this.solrIndex.id) - .then(chrisSuggestedFields => { - this.chrisSuggestedFields = chrisSuggestedFields; + .then(importSuggestedFields => { + this.importSuggestedFields = importSuggestedFields; }) .catch(error => this.showErrorMsg.emit(error)); } - deleteChrisSuggestedField(suggestedFieldId: string, event: Event) { + deleteImportSuggestedField(suggestedFieldId: string, event: Event) { event.stopPropagation(); const deleteCallback = () => this.solrService .deleteSuggestedField(this.solrIndex.id, suggestedFieldId) - .then(() => this.lookupChrisSuggestedFields()) + .then(() => this.lookupImportSuggestedFields()) .catch(error => this.showErrorMsg.emit(error)); diff --git a/frontend/src/app/components/chris/chris-suggested-fields/chris-suggested-fields.component.html b/frontend/src/app/components/import/import-suggested-fields/import-suggested-fields.component.html similarity index 67% rename from frontend/src/app/components/chris/chris-suggested-fields/chris-suggested-fields.component.html rename to frontend/src/app/components/import/import-suggested-fields/import-suggested-fields.component.html index 056500cc..1a5a81be 100644 --- a/frontend/src/app/components/chris/chris-suggested-fields/chris-suggested-fields.component.html +++ b/frontend/src/app/components/import/import-suggested-fields/import-suggested-fields.component.html @@ -7,21 +7,21 @@

      Suggested Fields for {{solrIndex.description}}

      - - + - - + = new EventEmitter(); - chrisSuggestedFields: Array; + importSuggestedFields: Array; constructor( private route: ActivatedRoute, @@ -36,7 +36,7 @@ export class ChrisSuggestedFieldsComponent implements OnInit { ngOnInit() { - console.log('In ChrisSuggestedFieldsComponent :: ngOnInit'); + console.log('In ImportSuggestedFieldsComponent :: ngOnInit'); this.route.paramMap.subscribe((params: ParamMap) => { @@ -47,7 +47,7 @@ export class ChrisSuggestedFieldsComponent implements OnInit { .then(solrIndex => this.solrIndex = solrIndex ) - .then(() => this.lookupChrisSuggestedFields()) + .then(() => this.lookupImportSuggestedFields()) .catch(error => this.showErrorMsg(error)); @@ -56,17 +56,17 @@ export class ChrisSuggestedFieldsComponent implements OnInit { } ngOnChanges(changes: SimpleChanges): void { - console.log('In ChrisSuggestedFieldsComponent :: ngOnChanges'); - this.lookupChrisSuggestedFields(); + console.log('In ImportSuggestedFieldsComponent :: ngOnChanges'); + this.lookupImportSuggestedFields(); } - lookupChrisSuggestedFields() { - console.log('In ChrisSuggestedFieldsListComponent :: lookupChrisSuggestedFields'); + lookupImportSuggestedFields() { + console.log('In ImportSuggestedFieldsListComponent :: lookupImportSuggestedFields'); console.log("Solr id?" + this.solrIndex.id) this.solrService.getSuggestedFields(this.solrIndex.id) .then(suggestedFields => { - this.chrisSuggestedFields = suggestedFields; + this.importSuggestedFields = suggestedFields; }) .catch(error => this.showErrorMsg(error)); @@ -80,9 +80,9 @@ export class ChrisSuggestedFieldsComponent implements OnInit { this.toasterService.pop('error', '', msgText); } - public chrisSuggestedFieldsChange( id: string){ - console.log("ChrisSuggestedFieldsComponent::chrisSuggestedFieldsChange") - this.lookupChrisSuggestedFields(); + public importSuggestedFieldsChange( id: string){ + console.log("ImportSuggestedFieldsComponent::importSuggestedFieldsChange") + this.lookupImportSuggestedFields(); } diff --git a/frontend/src/app/components/import/import-suggested-fields/index.ts b/frontend/src/app/components/import/import-suggested-fields/index.ts new file mode 100644 index 00000000..e69de29b diff --git a/frontend/src/app/components/chris/chris.component.html b/frontend/src/app/components/import/import.component.html similarity index 86% rename from frontend/src/app/components/chris/chris.component.html rename to frontend/src/app/components/import/import.component.html index 31c4bbc9..0d8a1c7e 100644 --- a/frontend/src/app/components/chris/chris.component.html +++ b/frontend/src/app/components/import/import.component.html @@ -1,9 +1,9 @@ - - + diff --git a/frontend/src/app/components/chris/chris.component.ts b/frontend/src/app/components/import/import.component.ts similarity index 81% rename from frontend/src/app/components/chris/chris.component.ts rename to frontend/src/app/components/import/import.component.ts index 636238a0..e91a736b 100644 --- a/frontend/src/app/components/chris/chris.component.ts +++ b/frontend/src/app/components/import/import.component.ts @@ -10,10 +10,10 @@ import { } from '../../services'; @Component({ - selector: 'app-smui-chris', - templateUrl: './chris.component.html' + selector: 'app-smui-import', + templateUrl: './import.component.html' }) -export class ChrisComponent implements OnInit { +export class ImportComponent implements OnInit { constructor( private modalService: ModalService, @@ -26,7 +26,7 @@ export class ChrisComponent implements OnInit { solrIndices: SolrIndex[]; ngOnInit() { - console.log('In ChrisComponent :: ngOnInit'); + console.log('In ImportComponent :: ngOnInit'); this.solrIndices = this.solrService.solrIndices; } @@ -48,7 +48,7 @@ export class ChrisComponent implements OnInit { } public solrIndicesChange(id: string){ - console.log("ChrisComponent :: solrIndicesChange :: id = " + id) + console.log("ImportComponent :: solrIndicesChange :: id = " + id) this.solrIndices = this.solrService.solrIndices; } diff --git a/frontend/src/app/components/import/index.ts b/frontend/src/app/components/import/index.ts new file mode 100644 index 00000000..bdc340d5 --- /dev/null +++ b/frontend/src/app/components/import/index.ts @@ -0,0 +1 @@ +export * from './import.component'; From d6abe154a089134e3ec69ddb94ca718c833e92d4 Mon Sep 17 00:00:00 2001 From: Chris Morley Date: Fri, 3 Jun 2022 13:09:12 -0400 Subject: [PATCH 17/25] get rid of unneeded components --- ...mport-rules-collection-list.component.html | 26 ----- .../import-rules-collection-list.component.ts | 65 ------------ .../import-rules-collection-list/index.ts | 1 - ...ort-suggested-fields-create.component.html | 25 ----- ...mport-suggested-fields-create.component.ts | 62 ----------- ...mport-suggested-fields-list.component.html | 20 ---- .../import-suggested-fields-list.component.ts | 68 ------------ .../import-suggested-fields.component.html | 35 ------ .../import-suggested-fields.component.ts | 100 ------------------ .../import/import-suggested-fields/index.ts | 0 .../components/import/import.component.html | 8 -- 11 files changed, 410 deletions(-) delete mode 100644 frontend/src/app/components/import/import-rules-collection-list/import-rules-collection-list.component.html delete mode 100644 frontend/src/app/components/import/import-rules-collection-list/import-rules-collection-list.component.ts delete mode 100644 frontend/src/app/components/import/import-rules-collection-list/index.ts delete mode 100644 frontend/src/app/components/import/import-suggested-fields/import-suggested-fields-create/import-suggested-fields-create.component.html delete mode 100644 frontend/src/app/components/import/import-suggested-fields/import-suggested-fields-create/import-suggested-fields-create.component.ts delete mode 100644 frontend/src/app/components/import/import-suggested-fields/import-suggested-fields-list/import-suggested-fields-list.component.html delete mode 100644 frontend/src/app/components/import/import-suggested-fields/import-suggested-fields-list/import-suggested-fields-list.component.ts delete mode 100644 frontend/src/app/components/import/import-suggested-fields/import-suggested-fields.component.html delete mode 100644 frontend/src/app/components/import/import-suggested-fields/import-suggested-fields.component.ts delete mode 100644 frontend/src/app/components/import/import-suggested-fields/index.ts diff --git a/frontend/src/app/components/import/import-rules-collection-list/import-rules-collection-list.component.html b/frontend/src/app/components/import/import-rules-collection-list/import-rules-collection-list.component.html deleted file mode 100644 index ac2cf855..00000000 --- a/frontend/src/app/components/import/import-rules-collection-list/import-rules-collection-list.component.html +++ /dev/null @@ -1,26 +0,0 @@ - -
      -
      -
      Import Rules Collections
      -
      Available Import Rules Collections in SMUI
      - -
        -
      • - {{ solrIndex.description }} ({{ solrIndex.name }})- Key: {{ solrIndex.id }} - - - - Configure - - -
      • -
      -
      -
      diff --git a/frontend/src/app/components/import/import-rules-collection-list/import-rules-collection-list.component.ts b/frontend/src/app/components/import/import-rules-collection-list/import-rules-collection-list.component.ts deleted file mode 100644 index d2a1dc68..00000000 --- a/frontend/src/app/components/import/import-rules-collection-list/import-rules-collection-list.component.ts +++ /dev/null @@ -1,65 +0,0 @@ -import { - Component, - Input, - Output, - EventEmitter, - OnChanges, - OnInit, - SimpleChanges -} from '@angular/core'; - -import { SolrIndex } from '../../../models'; -import { - SolrService, - ModalService -} from '../../../services'; - -@Component({ - selector: 'app-smui-import-import-rules-collection-list', - templateUrl: './import-rules-collection-list.component.html' -}) -export class ImportRulesCollectionListComponent implements OnInit, OnChanges { - - @Output() openDeleteConfirmModal: EventEmitter = new EventEmitter(); - @Output() showErrorMsg: EventEmitter = new EventEmitter(); - @Output() showSuccessMsg: EventEmitter = new EventEmitter(); - @Output() solrIndicesChange: EventEmitter = new EventEmitter(); - - constructor( - private solrService: SolrService, - ) { - } - - getSolrIndices() { - return this.solrService.solrIndices - } - - ngOnInit() { - console.log('In ImportRulesCollectionListComponent :: ngOnInit'); - } - - ngOnChanges(changes: SimpleChanges): void { - console.log('In ImportRulesCollectionListComponent :: ngOnChanges'); - } - - deleteImportRulesCollection(id: string, event: Event) { - event.stopPropagation(); - const deleteCallback = () => - this.solrService - .deleteSolrIndex(id) - .then(() => this.solrService.listAllSolrIndices()) - .then(() => this.solrIndicesChange.emit(id)) - .then(() => this.solrService.emitRulesCollectionChangeEvent("")) - .then(() => this.showSuccessMsg.emit("Import Rule collection successfully deleted.")) - .catch(error => { - // unpack and emit error message - var errorMsg = 'Unknown error' - if( 'error' in error ) { - errorMsg = error.error.message - } - this.showErrorMsg.emit(errorMsg) - }); - - this.openDeleteConfirmModal.emit({ deleteCallback }); - } -} diff --git a/frontend/src/app/components/import/import-rules-collection-list/index.ts b/frontend/src/app/components/import/import-rules-collection-list/index.ts deleted file mode 100644 index 0332a6bd..00000000 --- a/frontend/src/app/components/import/import-rules-collection-list/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './import-rules-collection-list.component'; diff --git a/frontend/src/app/components/import/import-suggested-fields/import-suggested-fields-create/import-suggested-fields-create.component.html b/frontend/src/app/components/import/import-suggested-fields/import-suggested-fields-create/import-suggested-fields-create.component.html deleted file mode 100644 index 07c24d23..00000000 --- a/frontend/src/app/components/import/import-suggested-fields/import-suggested-fields-create/import-suggested-fields-create.component.html +++ /dev/null @@ -1,25 +0,0 @@ -
      -
      -
      Add Suggested Import Field
      -
      Add a new Suggested Import Field to the rules collection {{solrIndex.description}}
      - -
      - -
      - -
      -
      - -
      -
      - -
      -
      -
      -
      diff --git a/frontend/src/app/components/import/import-suggested-fields/import-suggested-fields-create/import-suggested-fields-create.component.ts b/frontend/src/app/components/import/import-suggested-fields/import-suggested-fields-create/import-suggested-fields-create.component.ts deleted file mode 100644 index d729c9cd..00000000 --- a/frontend/src/app/components/import/import-suggested-fields/import-suggested-fields-create/import-suggested-fields-create.component.ts +++ /dev/null @@ -1,62 +0,0 @@ -import { - Component, - Input, - Output, - EventEmitter, - OnChanges, - OnInit, - SimpleChanges -} from '@angular/core'; - -import { SolrIndex, SuggestedSolrField } from '../../../../models'; -import { - SolrService, - ModalService -} from '../../../../services'; - -@Component({ - selector: 'app-smui-import-suggested-fields-create', - templateUrl: './import-suggested-fields-create.component.html' -}) -export class ImportSuggestedFieldsCreateComponent implements OnInit, OnChanges { - - @Input() solrIndex: SolrIndex; - @Output() showErrorMsg: EventEmitter = new EventEmitter(); - @Output() showSuccessMsg: EventEmitter = new EventEmitter(); - @Output() importSuggestedFieldsChange: EventEmitter = new EventEmitter(); - - name: string; - suggestedFields: SuggestedSolrField[] = []; - - constructor( - private solrService: SolrService, - ) { - - } - ngOnInit() { - console.log('In ImportSuggestedFieldsCreateComponent :: ngOnInit'); - } - - ngOnChanges(changes: SimpleChanges): void { - console.log('In ImportSuggestedFieldsCreateComponent :: ngOnChanges'); - } - - - clearForm() { - this.name = ''; - } - - createImportSuggestedField( event: Event){ - console.log('In ImportSuggestedFieldsCreateComponent :: createSuggestedField'); - if (this.name) { - this.solrService - .createSuggestedField(this.solrIndex.id, this.name) - .then(() => this.showSuccessMsg.emit("Created new Import Suggested Field " + this.name)) - .then(() => this.importSuggestedFieldsChange.emit()) - .then(() => this.clearForm()) - .catch(error => this.showErrorMsg.emit(error)); - } - } - - -} diff --git a/frontend/src/app/components/import/import-suggested-fields/import-suggested-fields-list/import-suggested-fields-list.component.html b/frontend/src/app/components/import/import-suggested-fields/import-suggested-fields-list/import-suggested-fields-list.component.html deleted file mode 100644 index f2b9f190..00000000 --- a/frontend/src/app/components/import/import-suggested-fields/import-suggested-fields-list/import-suggested-fields-list.component.html +++ /dev/null @@ -1,20 +0,0 @@ -
      -
      -
      Import Suggested Fields
      -
      Available Import suggested fields in SMUI
      - -
        -
      • - {{ importSuggestedField.name }} - Key: {{ importSuggestedField.id }} - - -
      • -
      -
      -
      diff --git a/frontend/src/app/components/import/import-suggested-fields/import-suggested-fields-list/import-suggested-fields-list.component.ts b/frontend/src/app/components/import/import-suggested-fields/import-suggested-fields-list/import-suggested-fields-list.component.ts deleted file mode 100644 index baf03b6a..00000000 --- a/frontend/src/app/components/import/import-suggested-fields/import-suggested-fields-list/import-suggested-fields-list.component.ts +++ /dev/null @@ -1,68 +0,0 @@ -import { - Component, - Input, - Output, - EventEmitter, - OnChanges, - OnInit, - SimpleChanges -} from '@angular/core'; - -import { SolrIndex, SuggestedSolrField } from '../../../../models'; -import { - SolrService -} from '../../../../services'; - -@Component({ - selector: 'app-smui-import-suggested-fields-list', - templateUrl: './import-suggested-fields-list.component.html' -}) -export class ImportSuggestedFieldsListComponent implements OnInit, OnChanges { - - @Input() solrIndex: SolrIndex; - @Input() importSuggestedFields: Array; - - @Output() openDeleteConfirmModal: EventEmitter = new EventEmitter(); - @Output() showErrorMsg: EventEmitter = new EventEmitter(); - @Output() solrIndicesChange: EventEmitter = new EventEmitter(); - @Output() importSuggestedFieldsChange: EventEmitter = new EventEmitter(); - - constructor( - private solrService: SolrService, - ) { - - } - - ngOnInit() { - console.log('In ImportSuggestedFieldsListComponent :: ngOnInit'); - - } - - ngOnChanges(changes: SimpleChanges): void { - console.log('In ImportSuggestedFieldsListComponent :: ngOnChanges'); - } - - - lookupImportSuggestedFields() { - console.log('In ImportSuggestedFieldsListComponent :: lookupSuggestedFields'); - this.solrService.getSuggestedFields(this.solrIndex.id) - .then(importSuggestedFields => { - this.importSuggestedFields = importSuggestedFields; - }) - .catch(error => this.showErrorMsg.emit(error)); - - } - - deleteImportSuggestedField(suggestedFieldId: string, event: Event) { - event.stopPropagation(); - const deleteCallback = () => - this.solrService - .deleteSuggestedField(this.solrIndex.id, suggestedFieldId) - .then(() => this.lookupImportSuggestedFields()) - - .catch(error => this.showErrorMsg.emit(error)); - - - this.openDeleteConfirmModal.emit({ deleteCallback }); - } -} diff --git a/frontend/src/app/components/import/import-suggested-fields/import-suggested-fields.component.html b/frontend/src/app/components/import/import-suggested-fields/import-suggested-fields.component.html deleted file mode 100644 index 1a5a81be..00000000 --- a/frontend/src/app/components/import/import-suggested-fields/import-suggested-fields.component.html +++ /dev/null @@ -1,35 +0,0 @@ - - -

      Suggested Fields for {{solrIndex.description}}

      - - - - - - - - -

      Are you sure you want to delete the item?

      -
      - - diff --git a/frontend/src/app/components/import/import-suggested-fields/import-suggested-fields.component.ts b/frontend/src/app/components/import/import-suggested-fields/import-suggested-fields.component.ts deleted file mode 100644 index 9413cfef..00000000 --- a/frontend/src/app/components/import/import-suggested-fields/import-suggested-fields.component.ts +++ /dev/null @@ -1,100 +0,0 @@ -import {Component, OnInit, Input, Output, EventEmitter, SimpleChanges} from '@angular/core'; -import { ActivatedRoute, Params, ParamMap } from '@angular/router'; -//import 'rxjs/add/operator/switchMap'; - -import { switchMap } from 'rxjs/operators'; - -import { ToasterService } from 'angular2-toaster'; - -import {SolrIndex, SuggestedSolrField} from '../../../models'; -import { - SolrService, - ModalService -} from '../../../services'; - - -@Component({ - selector: 'app-smui-import-suggested-fields', - templateUrl: './import-suggested-fields.component.html' -}) -export class ImportSuggestedFieldsComponent implements OnInit { - - //@Input() solrIndex: SolrIndex; - //@Output() showErrorMsg: EventEmitter = new EventEmitter(); - importSuggestedFields: Array; - - constructor( - private route: ActivatedRoute, - private modalService: ModalService, - private solrService: SolrService, - private toasterService: ToasterService, - ) { - - } - - solrIndex: SolrIndex; - - - ngOnInit() { - console.log('In ImportSuggestedFieldsComponent :: ngOnInit'); - - - this.route.paramMap.subscribe((params: ParamMap) => { - console.log(params); - console.log(params.get("solrIndexId")!.toLowerCase()); - //console.log(this.solrService.getSolrIndex(params.get("id"))) - this.solrService.getSolrIndex(params.get("solrIndexId")!.toLowerCase()) - .then(solrIndex => - this.solrIndex = solrIndex - ) - .then(() => this.lookupImportSuggestedFields()) - .catch(error => this.showErrorMsg(error)); - - - }) - - } - - ngOnChanges(changes: SimpleChanges): void { - console.log('In ImportSuggestedFieldsComponent :: ngOnChanges'); - this.lookupImportSuggestedFields(); - } - - - lookupImportSuggestedFields() { - console.log('In ImportSuggestedFieldsListComponent :: lookupImportSuggestedFields'); - console.log("Solr id?" + this.solrIndex.id) - this.solrService.getSuggestedFields(this.solrIndex.id) - .then(suggestedFields => { - this.importSuggestedFields = suggestedFields; - }) - .catch(error => this.showErrorMsg(error)); - - } - - public showSuccessMsg(msgText: string) { - this.toasterService.pop('success', '', msgText); - } - - public showErrorMsg(msgText: string) { - this.toasterService.pop('error', '', msgText); - } - - public importSuggestedFieldsChange( id: string){ - console.log("ImportSuggestedFieldsComponent::importSuggestedFieldsChange") - this.lookupImportSuggestedFields(); - - } - - // @ts-ignore - public openDeleteConfirmModal({ deleteCallback }) { - const deferred = this.modalService.open('confirm-delete'); - deferred.promise.then((isOk: boolean) => { - if (isOk) { deleteCallback(); } - this.modalService.close('confirm-delete'); - }); - } - - - -} diff --git a/frontend/src/app/components/import/import-suggested-fields/index.ts b/frontend/src/app/components/import/import-suggested-fields/index.ts deleted file mode 100644 index e69de29b..00000000 diff --git a/frontend/src/app/components/import/import.component.html b/frontend/src/app/components/import/import.component.html index 0d8a1c7e..6dcb1746 100644 --- a/frontend/src/app/components/import/import.component.html +++ b/frontend/src/app/components/import/import.component.html @@ -5,14 +5,6 @@ > - - - - - - - - Date: Fri, 3 Jun 2022 17:02:40 -0400 Subject: [PATCH 18/25] nicer buttons for rules collections --- .../rules-collection-list.component.html | 57 ++++++++++++------- .../rules-collection-list.component.ts | 2 +- frontend/src/styles.css | 15 +++++ 3 files changed, 54 insertions(+), 20 deletions(-) diff --git a/frontend/src/app/components/admin/rules-collection-list/rules-collection-list.component.html b/frontend/src/app/components/admin/rules-collection-list/rules-collection-list.component.html index d8ec2b05..0ffe0c1f 100644 --- a/frontend/src/app/components/admin/rules-collection-list/rules-collection-list.component.html +++ b/frontend/src/app/components/admin/rules-collection-list/rules-collection-list.component.html @@ -6,28 +6,47 @@
      Available Rules Collections in SMUI
    • - {{ solrIndex.description }} ({{ solrIndex.name }})- Key: {{ solrIndex.id }} + Description: {{ solrIndex.description }}
      + Name: {{ solrIndex.name }}
      + Key: {{ solrIndex.id }}
      - Configure +
      - + + +   + +   + +   +
      -
    diff --git a/frontend/src/app/components/admin/rules-collection-list/rules-collection-list.component.ts b/frontend/src/app/components/admin/rules-collection-list/rules-collection-list.component.ts index 115431e2..32e0835e 100644 --- a/frontend/src/app/components/admin/rules-collection-list/rules-collection-list.component.ts +++ b/frontend/src/app/components/admin/rules-collection-list/rules-collection-list.component.ts @@ -158,7 +158,7 @@ export class RulesCollectionListComponent implements OnInit, OnChanges { // document.body.removeChild(element); // } - downloadRulesCollection(id:String, event: Event) { + downloadRulesCollectionExport(id:String, event: Event) { console.log("download()"); this.solrService.getExportWithId(id).then( result => { diff --git a/frontend/src/styles.css b/frontend/src/styles.css index e0ff8ad0..d6c42bee 100644 --- a/frontend/src/styles.css +++ b/frontend/src/styles.css @@ -2,3 +2,18 @@ @import '~angular2-toaster/toaster.css'; @import '~angular2-multiselect-dropdown/themes/default.theme.css'; @import '~@fortawesome/fontawesome-free/css/all.css'; + +div.horizontalgap { + float: left; + overflow: hidden; + height: 1px; + width: 0px; +} + +.float-right-top { + position: absolute; + right: 0; + top: 0; + padding-top:10px; + padding-right:10px; +} From ae104f7323f41e43809eb15e27491d95625cc6e1 Mon Sep 17 00:00:00 2001 From: Chris Morley Date: Fri, 3 Jun 2022 17:14:56 -0400 Subject: [PATCH 19/25] pop toast on file import --- .../rules-collection-list.component.html | 3 +++ .../file-upload.component.html | 17 +++++++++++++---- .../file-upload.component.ts | 9 ++++++++- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/frontend/src/app/components/admin/rules-collection-list/rules-collection-list.component.html b/frontend/src/app/components/admin/rules-collection-list/rules-collection-list.component.html index 0ffe0c1f..cfff05cc 100644 --- a/frontend/src/app/components/admin/rules-collection-list/rules-collection-list.component.html +++ b/frontend/src/app/components/admin/rules-collection-list/rules-collection-list.component.html @@ -23,6 +23,7 @@
    Available Rules Collections in SMUI   + +   + - {{fileName || "No file uploaded yet."}} +   +   + +
    diff --git a/frontend/src/app/components/import/import-rules-collection-create/file-upload.component.ts b/frontend/src/app/components/import/import-rules-collection-create/file-upload.component.ts index 3bb75b5a..a2594b8e 100644 --- a/frontend/src/app/components/import/import-rules-collection-create/file-upload.component.ts +++ b/frontend/src/app/components/import/import-rules-collection-create/file-upload.component.ts @@ -1,5 +1,6 @@ import {Component, ElementRef, ViewChild} from "@angular/core"; import {HttpClient} from "@angular/common/http"; +import {ToasterService} from "angular2-toaster"; @Component({ selector: 'file-upload', @@ -13,7 +14,12 @@ export class FileUploadComponent { @ViewChild('fileUpload') myInputVariable: ElementRef; - constructor(private http: HttpClient) { + constructor(private http: HttpClient, + private toasterService: ToasterService) { + } + + public showSuccessMsg(msgText: string) { + this.toasterService.pop('success', '', msgText); } onFileSelected(event: Event) { @@ -28,6 +34,7 @@ export class FileUploadComponent { upload$.subscribe(); this.fileName = 'Last file uploaded: ' + this.fileName; this.myInputVariable.nativeElement.value = ''; + this.showSuccessMsg(this.fileName + " received and imported.") } } } From df825fe23a41d956f9a7b11bca07327990ca84ff Mon Sep 17 00:00:00 2001 From: Chris Morley Date: Wed, 8 Jun 2022 10:35:29 -0400 Subject: [PATCH 20/25] last_update override, reload collections after import --- .../validatedimport/ValidatedImportData.scala | 13 +++- .../file-upload.component.html | 2 +- .../file-upload.component.ts | 59 ++++++++++++++++--- 3 files changed, 64 insertions(+), 10 deletions(-) diff --git a/app/models/validatedimport/ValidatedImportData.scala b/app/models/validatedimport/ValidatedImportData.scala index 5845f095..eb88d8c6 100644 --- a/app/models/validatedimport/ValidatedImportData.scala +++ b/app/models/validatedimport/ValidatedImportData.scala @@ -3,9 +3,11 @@ package models.validatedimport import play.api.Logging import play.api.libs.json.{JsArray, JsObject, JsValue, Json} +import java.time.{LocalDateTime, LocalTime} import java.util import java.util.UUID import scala.collection.mutable +import anorm._ case class ValidatedImportData(filename: String, content: String) extends Logging { @@ -132,7 +134,7 @@ case class ValidatedImportData(filename: String, content: String) extends Loggin cellValue = "'" + rawCellValue + ", (file: " + inputFilename + " copied from key: " + old_id_shorthand + ") " + sds + "'" } } - else if (currentColumns(index).equals("id")) { + else if (currentColumns(index).equals("id") || currentColumns(index).equals("search_input_id") || currentColumns(index).equals("input_id")) { if (!replacementIds.contains(cellValue)) { replacementIds.put(cellValue, UUID.randomUUID().toString) } @@ -141,12 +143,19 @@ case class ValidatedImportData(filename: String, content: String) extends Loggin //logger.debug("replaced it with :" + cellValue) } + if (currentColumns(index).equals("last_update")) { + //ISO_LOCAL_DATE + " " + ISO_LOCAL_TIME + val sqlDate = java.sql.Date.valueOf(LocalDateTime.now.toLocalDate) + val sqlTime = java.sql.Time.valueOf(LocalTime.now) + var isoLocalDateTimeStr = sqlDate + " " + sqlTime + cellValue = "'" + isoLocalDateTimeStr + "'" + } + if (this.tableName.equals("search_input") || this.tableName.equals("suggested_solr_field") || this.tableName.equals("input_tag") ) { if (currentColumns(index).equals("solr_index_id")) { - //logger.debug("replacing old solr_index_id " + cellValue + " with new one: '" + this.a_different_existing_solr_index_id + "''") cellValue = "'" + this.a_different_existing_solr_index_id + "'" } } diff --git a/frontend/src/app/components/import/import-rules-collection-create/file-upload.component.html b/frontend/src/app/components/import/import-rules-collection-create/file-upload.component.html index 418a364b..db7cc65d 100644 --- a/frontend/src/app/components/import/import-rules-collection-create/file-upload.component.html +++ b/frontend/src/app/components/import/import-rules-collection-create/file-upload.component.html @@ -20,7 +20,7 @@     - + {{fileName || "No file imported yet."}} {{fileMessage}} diff --git a/frontend/src/app/components/import/import-rules-collection-create/file-upload.component.ts b/frontend/src/app/components/import/import-rules-collection-create/file-upload.component.ts index a2594b8e..e1c593cd 100644 --- a/frontend/src/app/components/import/import-rules-collection-create/file-upload.component.ts +++ b/frontend/src/app/components/import/import-rules-collection-create/file-upload.component.ts @@ -1,6 +1,12 @@ -import {Component, ElementRef, ViewChild} from "@angular/core"; +import {Component, ElementRef, EventEmitter, Output, ViewChild} from "@angular/core"; import {HttpClient} from "@angular/common/http"; import {ToasterService} from "angular2-toaster"; +import { + SolrService, + ModalService +} from '../../../services'; +import {SolrIndex} from "../../../models"; +import {RulesCollectionCreateComponent} from "../../admin"; @Component({ selector: 'file-upload', @@ -9,33 +15,72 @@ import {ToasterService} from "angular2-toaster"; }) export class FileUploadComponent { fileName = ''; + fileMessage = ''; target: EventTarget | null; @ViewChild('fileUpload') myInputVariable: ElementRef; + @Output() solrIndicesChange: EventEmitter = new EventEmitter(); + @Output() showErrorMsg: EventEmitter = new EventEmitter(); + @Output() refreshRulesCollectionList: EventEmitter = new EventEmitter(); constructor(private http: HttpClient, - private toasterService: ToasterService) { + private toasterService: ToasterService, + private solrService: SolrService) { } public showSuccessMsg(msgText: string) { this.toasterService.pop('success', '', msgText); } + refreshSolrIndicies() { + return this.solrService.listAllSolrIndices; + // : Promise.reject('No selected Solr index'); + } + onFileSelected(event: Event) { const target = event.target as HTMLInputElement; if (target.files != null) { const file: File = target.files[0]; if (file) { this.fileName = file.name; + this.fileMessage = '... processing ...'; const formData = new FormData(); formData.append("uploadedFile", file); - const upload$ = this.http.post("/api/v1/upload-import", formData); - upload$.subscribe(); - this.fileName = 'Last file uploaded: ' + this.fileName; - this.myInputVariable.nativeElement.value = ''; - this.showSuccessMsg(this.fileName + " received and imported.") + this.showSuccessMsg(this.fileName + this.fileMessage); + const upload$ = this.http.post("/api/v1/upload-import", formData).toPromise() + .then(() => { + this.myInputVariable.nativeElement.value = ''; + this.refreshSolrIndicies(); + }) + .then(() => { this.solrService.listAllSolrIndices().then(() => this.solrService.emitRulesCollectionChangeEvent("")); }) + //.then(() => { this.showSuccessMsg.emit(this.fileName + " received and imported."); }) + .then(() => { this.fileMessage = '... Done Processing.'; }) } + } } + // + // reateRulesCollection( event: Event){ + // console.log('In RulesCollectionCreateComponent :: createRulesCollection'); + // if (true) { + // this.solrService + // .createSolrIndex(this.name, this.description) + // .then(() => this.solrService.listAllSolrIndices()) + // .then(() => this.solrIndicesChange.emit()) + // .then(() => this.showSuccessMsg.emit("Created new Rules Collection " + this.description)) + // .then(() => this.solrService.emitRulesCollectionChangeEvent("")) + // .then(() => this.clearForm()) + // .catch(error => { + // console.log(error); + // var errorMsg = 'Unknown Error' + // if ('message' in error.error) { + // errorMsg = error.error.message; + // } + // this.showErrorMsg.emit(errorMsg); + // }); + // } else { + // this.showErrorMsg.emit("Fill in both name fields."); + // } + // } } From 902a8ab4a9349efc8c5f26d78b4ae2ab92b4f528 Mon Sep 17 00:00:00 2001 From: Chris Morley Date: Wed, 8 Jun 2022 11:00:19 -0400 Subject: [PATCH 21/25] make sure download has the collection name --- app/models/export/Exporter.scala | 2 -- .../export/{UpdownRuleExport.scala => UpDownRuleExport.scala} | 1 - .../rules-collection-list/rules-collection-list.component.ts | 4 +++- 3 files changed, 3 insertions(+), 4 deletions(-) rename app/models/export/{UpdownRuleExport.scala => UpDownRuleExport.scala} (99%) diff --git a/app/models/export/Exporter.scala b/app/models/export/Exporter.scala index 4c55a42c..5975d799 100644 --- a/app/models/export/Exporter.scala +++ b/app/models/export/Exporter.scala @@ -8,7 +8,6 @@ import models.rules.{DeleteRule, FilterRule, SynonymRule} import play.api.libs.json.{JsArray, JsObject, JsString, JsValue} import play.api.Logging import play.api.db.DBApi - import java.time.LocalDateTime import javax.inject.Inject @@ -224,7 +223,6 @@ class Exporter @Inject()(dbapi: DBApi, toggleService: FeatureToggleService)(impl getTagInputAssociationsFromDatabase, //10 getCanonicalSpellingsFromDatabase, //11 getAlternativeSpellingsFromDatabase //12 - //getSomethingsFromDatabase //13 ) getAllTablesForJs(tableSeq) } diff --git a/app/models/export/UpdownRuleExport.scala b/app/models/export/UpDownRuleExport.scala similarity index 99% rename from app/models/export/UpdownRuleExport.scala rename to app/models/export/UpDownRuleExport.scala index e8d3c619..8343a993 100644 --- a/app/models/export/UpdownRuleExport.scala +++ b/app/models/export/UpDownRuleExport.scala @@ -5,7 +5,6 @@ import anorm.{RowParser, ~} import models.input.SearchInputId import models.rules.{CommonRuleFields, UpDownRuleId} import play.api.libs.json._ - import java.time.LocalDateTime case class UpDownRuleExport(id: UpDownRuleId = UpDownRuleId(), diff --git a/frontend/src/app/components/admin/rules-collection-list/rules-collection-list.component.ts b/frontend/src/app/components/admin/rules-collection-list/rules-collection-list.component.ts index 32e0835e..e7ed488d 100644 --- a/frontend/src/app/components/admin/rules-collection-list/rules-collection-list.component.ts +++ b/frontend/src/app/components/admin/rules-collection-list/rules-collection-list.component.ts @@ -43,6 +43,7 @@ export class RulesCollectionListComponent implements OnInit, OnChanges { currentSolrIndexId = '-1'; currentSolrIndexIdSubject: Subject = new Subject(); + collectionName: String; constructor( private solrService: SolrService, @@ -160,11 +161,12 @@ export class RulesCollectionListComponent implements OnInit, OnChanges { downloadRulesCollectionExport(id:String, event: Event) { console.log("download()"); + this.solrService.getSolrIndex(id.toString()).then(solrIndex => this.collectionName = solrIndex.name); this.solrService.getExportWithId(id).then( result => { var str = JSON.stringify(result); this.downloadStringAsFile( - "file.json.txt", + this.collectionName + ".json.txt", str); this.showSuccessMsg.emit("Download: OK") } From 0ed6361819870b30244bc516f0128142f635af6c Mon Sep 17 00:00:00 2001 From: Chris Morley Date: Wed, 8 Jun 2022 11:16:30 -0400 Subject: [PATCH 22/25] toaster changes, comments cleanup --- .../file-upload.component.ts | 26 ++----------------- 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/frontend/src/app/components/import/import-rules-collection-create/file-upload.component.ts b/frontend/src/app/components/import/import-rules-collection-create/file-upload.component.ts index e1c593cd..664411ae 100644 --- a/frontend/src/app/components/import/import-rules-collection-create/file-upload.component.ts +++ b/frontend/src/app/components/import/import-rules-collection-create/file-upload.component.ts @@ -54,33 +54,11 @@ export class FileUploadComponent { this.refreshSolrIndicies(); }) .then(() => { this.solrService.listAllSolrIndices().then(() => this.solrService.emitRulesCollectionChangeEvent("")); }) - //.then(() => { this.showSuccessMsg.emit(this.fileName + " received and imported."); }) .then(() => { this.fileMessage = '... Done Processing.'; }) + .then(() => { this.showSuccessMsg("Imported: " + this.fileName); }) } } } - // - // reateRulesCollection( event: Event){ - // console.log('In RulesCollectionCreateComponent :: createRulesCollection'); - // if (true) { - // this.solrService - // .createSolrIndex(this.name, this.description) - // .then(() => this.solrService.listAllSolrIndices()) - // .then(() => this.solrIndicesChange.emit()) - // .then(() => this.showSuccessMsg.emit("Created new Rules Collection " + this.description)) - // .then(() => this.solrService.emitRulesCollectionChangeEvent("")) - // .then(() => this.clearForm()) - // .catch(error => { - // console.log(error); - // var errorMsg = 'Unknown Error' - // if ('message' in error.error) { - // errorMsg = error.error.message; - // } - // this.showErrorMsg.emit(errorMsg); - // }); - // } else { - // this.showErrorMsg.emit("Fill in both name fields."); - // } - // } + } From d687b0dececea40470c8e9486d7fdab35c039e16 Mon Sep 17 00:00:00 2001 From: Chris Morley Date: Wed, 8 Jun 2022 11:22:51 -0400 Subject: [PATCH 23/25] cleanup --- app/models/export/Exporter.scala | 57 +++++++++---------- .../file-upload.component.ts | 2 - 2 files changed, 28 insertions(+), 31 deletions(-) diff --git a/app/models/export/Exporter.scala b/app/models/export/Exporter.scala index 5975d799..5f581033 100644 --- a/app/models/export/Exporter.scala +++ b/app/models/export/Exporter.scala @@ -3,8 +3,6 @@ package models.`export` import anorm.SQL import models.{DatabaseExecutionContext, SuggestedSolrField} import models.FeatureToggleModel.FeatureToggleService -import models.input.SearchInput -import models.rules.{DeleteRule, FilterRule, SynonymRule} import play.api.libs.json.{JsArray, JsObject, JsString, JsValue} import play.api.Logging import play.api.db.DBApi @@ -12,9 +10,11 @@ import java.time.LocalDateTime import javax.inject.Inject @javax.inject.Singleton -class Exporter @Inject()(dbapi: DBApi, toggleService: FeatureToggleService)(implicit ec: DatabaseExecutionContext) extends Logging { +class Exporter @Inject()(dbApi: DBApi, + toggleService: FeatureToggleService) + (implicit ec: DatabaseExecutionContext) extends Logging { - private val db = dbapi.database("default") + private val db = dbApi.database("default") var somethings1: IndexedSeq[Something] = IndexedSeq( new Something(SomethingId(), "something1", LocalDateTime.now()), @@ -23,7 +23,6 @@ class Exporter @Inject()(dbapi: DBApi, toggleService: FeatureToggleService)(impl def getAllTablesForJs(tables : IndexedSeq[IndexedSeq[JsonExportable]]): JsValue = { var aggregation: Seq[JsValue] = Seq[JsValue]() - //println(tables.size) getAllTablesForJs1(tables, aggregation) } @@ -211,18 +210,18 @@ class Exporter @Inject()(dbapi: DBApi, toggleService: FeatureToggleService)(impl def getDatabaseJson: JsValue = { logger.debug("In Exporter.getDatabaseJson") val tableSeq = IndexedSeq( - getSolrIndexFromDatabase, //1 - getSearchInputsFromDatabase, //2 - getRedirectRulesFromDatabase, //3 - getSynonymRulesFromDatabase, //4 - getUpDownRulesFromDatabase, //5 - getDeleteRulesFromDatabase, //6 - getFilterRulesFromDatabase, //7 - getSuggestedSolrFieldsFromDatabase, //8 - getInputTagsFromDatabase, //9 - getTagInputAssociationsFromDatabase, //10 - getCanonicalSpellingsFromDatabase, //11 - getAlternativeSpellingsFromDatabase //12 + getSolrIndexFromDatabase, + getSearchInputsFromDatabase, + getRedirectRulesFromDatabase, + getSynonymRulesFromDatabase, + getUpDownRulesFromDatabase, + getDeleteRulesFromDatabase, + getFilterRulesFromDatabase, + getSuggestedSolrFieldsFromDatabase, + getInputTagsFromDatabase, + getTagInputAssociationsFromDatabase, + getCanonicalSpellingsFromDatabase, + getAlternativeSpellingsFromDatabase ) getAllTablesForJs(tableSeq) } @@ -230,18 +229,18 @@ class Exporter @Inject()(dbapi: DBApi, toggleService: FeatureToggleService)(impl def getDatabaseJsonWithId(id: String): JsValue = { logger.debug("In Exporter.getDatabaseJsonWithId") val tableSeq = IndexedSeq( - getSolrIndexFromDatabase(id), //1 - getSearchInputsFromDatabase(id), //2 - getRedirectRulesFromDatabase(id), //3 - getSynonymRulesFromDatabase(id), //4 - getUpDownRulesFromDatabase(id), //5 - getDeleteRulesFromDatabase(id), //6 - getFilterRulesFromDatabase(id), //7 - getSuggestedSolrFieldsFromDatabase(id), //8 - getInputTagsFromDatabase(id), //9 - getTagInputAssociationsFromDatabase(id), //10 - getCanonicalSpellingsFromDatabase(id), //11 - getAlternativeSpellingsFromDatabase(id) //12 + getSolrIndexFromDatabase(id), + getSearchInputsFromDatabase(id), + getRedirectRulesFromDatabase(id), + getSynonymRulesFromDatabase(id), + getUpDownRulesFromDatabase(id), + getDeleteRulesFromDatabase(id), + getFilterRulesFromDatabase(id), + getSuggestedSolrFieldsFromDatabase(id), + getInputTagsFromDatabase(id), + getTagInputAssociationsFromDatabase(id), + getCanonicalSpellingsFromDatabase(id), + getAlternativeSpellingsFromDatabase(id) ) getAllTablesForJs(tableSeq) } diff --git a/frontend/src/app/components/import/import-rules-collection-create/file-upload.component.ts b/frontend/src/app/components/import/import-rules-collection-create/file-upload.component.ts index 664411ae..7d0b902d 100644 --- a/frontend/src/app/components/import/import-rules-collection-create/file-upload.component.ts +++ b/frontend/src/app/components/import/import-rules-collection-create/file-upload.component.ts @@ -35,7 +35,6 @@ export class FileUploadComponent { refreshSolrIndicies() { return this.solrService.listAllSolrIndices; - // : Promise.reject('No selected Solr index'); } onFileSelected(event: Event) { @@ -57,7 +56,6 @@ export class FileUploadComponent { .then(() => { this.fileMessage = '... Done Processing.'; }) .then(() => { this.showSuccessMsg("Imported: " + this.fileName); }) } - } } From a0966764430a03dd8c160d81371963057b25a7bd Mon Sep 17 00:00:00 2001 From: Chris Morley Date: Wed, 8 Jun 2022 11:24:33 -0400 Subject: [PATCH 24/25] get rid of old commented code --- .../rules-collection-list.component.ts | 77 ------------------- 1 file changed, 77 deletions(-) diff --git a/frontend/src/app/components/admin/rules-collection-list/rules-collection-list.component.ts b/frontend/src/app/components/admin/rules-collection-list/rules-collection-list.component.ts index e7ed488d..5d7dbe73 100644 --- a/frontend/src/app/components/admin/rules-collection-list/rules-collection-list.component.ts +++ b/frontend/src/app/components/admin/rules-collection-list/rules-collection-list.component.ts @@ -82,83 +82,6 @@ export class RulesCollectionListComponent implements OnInit, OnChanges { .catch(error => this.showErrorMsg.emit(error)); } - // getSuggestedFields2(solrIndex: SolrIndex) { - // //console.log("solrIndex.id is: " + solrIndex.id); - // this.solrService.getSolrIndex(solrIndex.id) - // .then(idx => { - // //console.log('got here 2'); - // this.getRulesReport(solrIndex.id); - // }) - // .catch(error => this.showErrorMsg.emit(error)); - // } - - // downloadRulesCollection(id: string, event: Event) { - // this.solrService.getSolrIndex(id) - // .then(solrIndex => this.getSuggestedFields2(solrIndex)) - // this.toasterService.pop('success', '', 'Downloaded:' + id); - // } - - // getSomething(solrIndexId: string): Promise { - // return this.http - // //GET /api/v1/solr-index/:solrIndexId controllers.ApiController.getSolrIndex(solrIndexId: String) - // .get(`${this.baseUrl}/solr-index/${solrIndexId}/something`) - // .toPromise() - // .then(returnValue => { - // //this.savedOutput = output; - // this.downloadFile(solrIndexId, JSON.stringify(returnValue)); //this.savedOutput)); - // //this.downloadFile(solrIndexId + "json.txt", JSON.stringify(this.savedOutput)); - // }); - // } - - // private getRulesReport(solrIndexId: string) { - // this.getSomething(solrIndexId); - // //this.solrService.listAllSolrIndices(solrIndexId).then(); - // ///api/v1/:solrIndexId/rules-and-spellings - // // this.reportService - // // .getRulesReport(solrIndexId) - // // .then(retReport => { - // // this.rulesReport = retReport; - // // this.downloadableRules = new DownloadableRules(); - // // this.downloadableRules.id = solrIndexId; - // // this.downloadableRules.rules = new Array(); - // // - // // this.rulesReport.items.forEach( - // // (element) => { - // // var x = new DownloadableRule(); - // // x.inputId = element.inputId; - // // x.inputTerm = element.inputTerm; - // // x.details = element.details; - // // x.term = element.term; - // // x.isActive = element.isActive; - // // x.inputModified = element.inputModified; - // // x.inputTags = element.inputTags; - // // x.modified = element.modified; - // // this.downloadableRules?.rules?.push(x); - // // } - // // ); - // // this.downloadFile(solrIndexId + ".json.txt", JSON.stringify(this.downloadableRules)); - // // - // // }) - // // .catch(error => { - // // // unpack and emit error message - // // var errorMsg = 'Unknown error' - // // if ('error' in error) { - // // errorMsg = error.error.message; - // // } - // // this.showErrorMsg.emit(error) - // // }); - // } - - // private downloadFile(filename: string, text: string) { - // var element = document.createElement('a'); - // element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text)); - // element.setAttribute('download', filename); - // element.style.display = 'none'; - // document.body.appendChild(element); - // element.click(); - // document.body.removeChild(element); - // } - downloadRulesCollectionExport(id:String, event: Event) { console.log("download()"); this.solrService.getSolrIndex(id.toString()).then(solrIndex => this.collectionName = solrIndex.name); From ab022fbc4fd03d2554ad2ce60ab9dc32b7840369 Mon Sep 17 00:00:00 2001 From: Chris Morley Date: Wed, 8 Jun 2022 12:21:20 -0400 Subject: [PATCH 25/25] code cleanup, organize imports --- app/controllers/ApiController.scala | 57 +--- app/models/SearchManagementRepository.scala | 68 +--- app/models/export/Exporter.scala | 107 +------ app/models/export/Something.scala | 100 ------ .../export/example_export_file.json.txt | 292 ------------------ app/models/rules/Rule.scala | 6 +- app/models/rules/SynonymRule.scala | 7 +- app/models/rules/UpDownRule.scala | 4 +- conf/evolutions/default/9.sql | 11 - conf/routes | 5 - .../rules-collection-list.component.ts | 2 - frontend/src/app/models/export.ts | 3 - 12 files changed, 27 insertions(+), 635 deletions(-) delete mode 100644 app/models/export/Something.scala delete mode 100644 app/models/export/example_export_file.json.txt delete mode 100644 conf/evolutions/default/9.sql delete mode 100644 frontend/src/app/models/export.ts diff --git a/app/controllers/ApiController.scala b/app/controllers/ApiController.scala index 7524c11d..5d5effbb 100644 --- a/app/controllers/ApiController.scala +++ b/app/controllers/ApiController.scala @@ -1,35 +1,31 @@ //CJM 10 package controllers -import java.io.{File, OutputStream, PipedInputStream, PipedOutputStream} import akka.stream.scaladsl.{Source, StreamConverters} import akka.util.ByteString - -import javax.inject.Inject -import play.api.Logging -import play.api.mvc._ -import play.api.libs.json._ -import play.api.libs.json.Reads._ - -import java.nio.file.Paths -import java.time.format.DateTimeFormatter -import java.time.LocalDateTime -import scala.concurrent.{ExecutionContext, Future} import controllers.auth.{AuthActionFactory, UserRequest} import models.FeatureToggleModel.FeatureToggleService import models._ import models.config.SmuiVersion -import models.input.{InputTagId, InputValidator, ListItem, SearchInputId, SearchInputWithRules} +import models.input._ import models.querqy.QuerqyRulesTxtGenerator import models.spellings.{CanonicalSpellingId, CanonicalSpellingValidator, CanonicalSpellingWithAlternatives} import models.validatedimport.ValidatedImportData import org.checkerframework.checker.units.qual.A +import play.api.Logging import play.api.libs.Files import play.api.libs.Files.TemporaryFile.temporaryFileToPath +import play.api.libs.json.Reads._ +import play.api.libs.json._ +import play.api.mvc._ import services.{RulesTxtDeploymentService, RulesTxtImportService} -import java.util.UUID -import scala.collection.JavaConverters._ +import java.io.{OutputStream, PipedInputStream, PipedOutputStream} +import java.nio.file.Paths +import java.time.LocalDateTime +import java.time.format.DateTimeFormatter +import javax.inject.Inject +import scala.concurrent.{ExecutionContext, Future} // TODO Make ApiController pure REST- / JSON-Controller to ensure all implicit Framework responses (e.g. 400, 500) conformity @@ -617,37 +613,6 @@ class ApiController @Inject()(authActionFactory: AuthActionFactory, } } - - def getSomething(solrIndexId: String): Action[AnyContent] = authActionFactory.getAuthenticatedAction(Action).async { - Future { - val something = searchManagementRepository.getSomething(solrIndexId) - Ok(Json.toJson(something.writer.writes("writesMsg1"))) - } - } - - def putSomething(): Action[AnyContent] = authActionFactory.getAuthenticatedAction(Action) { request: Request[AnyContent] => - logger.debug("putSomething:0"); - val body: AnyContent = request.body - val jsonBody: Option[JsValue] = body.asJson - logger.debug("putSomething:1"); - // Expecting json body - jsonBody.map { json => - val thingName = (json \ "thingName").as[String] - logger.debug("putSomething:2 we got " + thingName); - searchManagementRepository.putSomething(thingName) - Ok(Json.toJson(ApiResult(API_RESULT_OK, "That worked.", None))) - }.getOrElse { - BadRequest(Json.toJson(ApiResult(API_RESULT_FAIL, "That failed.", None))) - } - } - - def getDatabaseJson: Action[AnyContent] = authActionFactory.getAuthenticatedAction(Action).async { - Future { - logger.debug("In ApiController:getDatabaseJson") - Ok(Json.toJson(searchManagementRepository.getDatabaseJson)) - } - } - def getDatabaseJsonWithId(id: String): Action[AnyContent] = authActionFactory.getAuthenticatedAction(Action).async { Future { logger.debug("In ApiController:getDatabaseJsonWithId and got id: " + id) diff --git a/app/models/SearchManagementRepository.scala b/app/models/SearchManagementRepository.scala index c944a67a..c3fb1b19 100644 --- a/app/models/SearchManagementRepository.scala +++ b/app/models/SearchManagementRepository.scala @@ -1,24 +1,21 @@ package models -import anorm.SqlParser.get - -import java.time.LocalDateTime -import java.util.{Date, UUID} -import javax.inject.Inject -import play.api.db.DBApi import anorm._ import models.FeatureToggleModel.FeatureToggleService -import models.SolrIndex.TABLE_NAME -import models.export.{Exporter, Something, SomethingId} -import models.input.{InputTag, InputTagId, PredefinedTag, SearchInput, SearchInputId, SearchInputWithRules, TagInputAssociation} -import models.spellings.{CanonicalSpelling, CanonicalSpellingId, CanonicalSpellingWithAlternatives} import models.eventhistory.{ActivityLog, ActivityLogEntry, InputEvent} +import models.export.Exporter +import models.input._ import models.reports.{ActivityReport, DeploymentLog, RulesReport} -import models.rules.{DeleteRule, FilterRule, SynonymRuleId} +import models.spellings.{CanonicalSpelling, CanonicalSpellingId, CanonicalSpellingWithAlternatives} import models.validatedimport.{ValidatedImportData, ValidatedImportImporter} import play.api.Logging +import play.api.db.DBApi import play.api.libs.json.JsValue +import java.time.LocalDateTime +import java.util.{Date, UUID} +import javax.inject.Inject + // TODO Make `userInfo` mandatory (for all input/spelling and deploymentLog CRUD operations), when removing unauthorized access. @javax.inject.Singleton class SearchManagementRepository @Inject()(dbapi: DBApi, toggleService: FeatureToggleService)(implicit ec: DatabaseExecutionContext) extends Logging { @@ -311,33 +308,6 @@ class SearchManagementRepository @Inject()(dbapi: DBApi, toggleService: FeatureT } } - def getSomething(id: String): Something = db.withConnection { - implicit connection => { - val something = new Something(SomethingId(), "", LocalDateTime.now()) - something - } - } - - def putSomething(thingName: String): Boolean = db.withConnection { implicit connection => { - logger.debug("smr putSomething:0 " + thingName) - SQL("insert into something (id, value0, last_update) values ({id}, {value0}, {last_update})") - .on( - 'id -> SomethingId(), - 'value0 -> thingName, - 'last_update -> LocalDateTime.now() - ) - .execute() - } - } - - def getDatabaseJson: JsValue = db.withConnection { - implicit connection => { - logger.debug("In SearchManagementRepository:getDatabaseJson():1") - val exporter : Exporter = new Exporter(dbapi, toggleService) - exporter.getDatabaseJson - } - } - def getDatabaseJsonWithId(id: String): JsValue = db.withConnection { implicit connection => { logger.debug("In SearchManagementRepository:getDatabaseJsonWithId():1") @@ -346,28 +316,6 @@ class SearchManagementRepository @Inject()(dbapi: DBApi, toggleService: FeatureT } } - def putty: String = db.withTransaction { implicit connection => - var aString : String = "At SearchManagementRepository:putty():1" - logger.debug(aString) - SQL("insert into something (id,value0,last_update) values ({id}, {value0}, {last_update})") - .on( - 'id -> SomethingId(), - 'value0 -> "test22222", - 'last_update -> LocalDateTime.now() - ).execute() - - SQL("insert into something (id,value0,last_update) values ({id}, {value0}, {last_update})") - .on( - 'id -> SomethingId(), - 'value0 -> 3, - 'last_update -> LocalDateTime.now() - ).execute() - - aString = "At SearchManagementRepository:putty():2" - logger.debug(aString) - aString - } - def doImport(validatedImport: ValidatedImportData): String = db.withTransaction { implicit connection => var aString : String = "At SearchManagementRepository:doImport():1" logger.debug(aString) diff --git a/app/models/export/Exporter.scala b/app/models/export/Exporter.scala index 5f581033..0092317f 100644 --- a/app/models/export/Exporter.scala +++ b/app/models/export/Exporter.scala @@ -1,12 +1,11 @@ package models.`export` import anorm.SQL -import models.{DatabaseExecutionContext, SuggestedSolrField} +import models.DatabaseExecutionContext import models.FeatureToggleModel.FeatureToggleService -import play.api.libs.json.{JsArray, JsObject, JsString, JsValue} +import play.api.libs.json.{JsArray, JsObject, JsValue} import play.api.Logging import play.api.db.DBApi -import java.time.LocalDateTime import javax.inject.Inject @javax.inject.Singleton @@ -16,11 +15,6 @@ class Exporter @Inject()(dbApi: DBApi, private val db = dbApi.database("default") - var somethings1: IndexedSeq[Something] = IndexedSeq( - new Something(SomethingId(), "something1", LocalDateTime.now()), - new Something(SomethingId(), "something2", LocalDateTime.now()) - ) - def getAllTablesForJs(tables : IndexedSeq[IndexedSeq[JsonExportable]]): JsValue = { var aggregation: Seq[JsValue] = Seq[JsValue]() getAllTablesForJs1(tables, aggregation) @@ -57,175 +51,78 @@ class Exporter @Inject()(dbApi: DBApi, JsArray(target.toIndexedSeq) } - def getSomethingsFromDatabase: IndexedSeq[Something] = db.withConnection { - implicit connection => { - SQL(Something.selectAllStatement).as(Something.sqlParser.*).toIndexedSeq - } - } - - def getSearchInputsFromDatabase: IndexedSeq[SearchInputExport] = db.withConnection { - implicit connection => { - SQL(SearchInputExport.selectAllStatement).as(SearchInputExport.sqlParser.*).toIndexedSeq - } - } - def getSearchInputsFromDatabase(id: String): IndexedSeq[SearchInputExport] = db.withConnection { implicit connection => { SQL(SearchInputExport.selectStatement(id)).as(SearchInputExport.sqlParser.*).toIndexedSeq } } - def getDeleteRulesFromDatabase: IndexedSeq[DeleteRuleExport] = db.withConnection { - implicit connection => { - SQL(DeleteRuleExport.selectAllStatement).as(DeleteRuleExport.sqlParser.*).toIndexedSeq - } - } - def getDeleteRulesFromDatabase(id: String): IndexedSeq[DeleteRuleExport] = db.withConnection { implicit connection => { SQL(DeleteRuleExport.selectStatement(id)).as(DeleteRuleExport.sqlParser.*).toIndexedSeq } } - def getFilterRulesFromDatabase: IndexedSeq[FilterRuleExport] = db.withConnection { - implicit connection => { - SQL(FilterRuleExport.selectAllStatement).as(FilterRuleExport.sqlParser.*).toIndexedSeq - } - } - def getFilterRulesFromDatabase(id: String): IndexedSeq[FilterRuleExport] = db.withConnection { implicit connection => { SQL(FilterRuleExport.selectStatement(id)).as(FilterRuleExport.sqlParser.*).toIndexedSeq } } - def getSynonymRulesFromDatabase: IndexedSeq[SynonymRuleExport] = db.withConnection { - implicit connection => { - SQL(SynonymRuleExport.selectAllStatement).as(SynonymRuleExport.sqlParser.*).toIndexedSeq - } - } - def getSynonymRulesFromDatabase(id: String): IndexedSeq[SynonymRuleExport] = db.withConnection { implicit connection => { SQL(SynonymRuleExport.selectStatement(id)).as(SynonymRuleExport.sqlParser.*).toIndexedSeq } } - def getUpDownRulesFromDatabase: IndexedSeq[UpDownRuleExport] = db.withConnection { - implicit connection => { - SQL(UpDownRuleExport.selectAllStatement).as(UpDownRuleExport.sqlParser.*).toIndexedSeq - } - } - def getUpDownRulesFromDatabase(id: String): IndexedSeq[UpDownRuleExport] = db.withConnection { implicit connection => { SQL(UpDownRuleExport.selectStatement(id)).as(UpDownRuleExport.sqlParser.*).toIndexedSeq } } - def getRedirectRulesFromDatabase: IndexedSeq[RedirectRuleExport] = db.withConnection { - implicit connection => { - SQL(RedirectRuleExport.selectAllStatement).as(RedirectRuleExport.sqlParser.*).toIndexedSeq - } - } - def getRedirectRulesFromDatabase(id: String): IndexedSeq[RedirectRuleExport] = db.withConnection { implicit connection => { SQL(RedirectRuleExport.selectStatement(id)).as(RedirectRuleExport.sqlParser.*).toIndexedSeq } } - def getSolrIndexFromDatabase: IndexedSeq[SolrIndexExport] = db.withConnection { - implicit connection => { - SQL(SolrIndexExport.selectAllStatement).as(SolrIndexExport.sqlParser.*).toIndexedSeq - } - } - def getSolrIndexFromDatabase(id: String): IndexedSeq[SolrIndexExport] = db.withConnection { implicit connection => { SQL(SolrIndexExport.selectStatement(id)).as(SolrIndexExport.sqlParser.*).toIndexedSeq } } - def getSuggestedSolrFieldsFromDatabase: IndexedSeq[SuggestedSolrFieldExport] = db.withConnection { - implicit connection => { - SQL(SuggestedSolrFieldExport.selectAllStatement).as(SuggestedSolrFieldExport.sqlParser.*).toIndexedSeq - } - } - def getSuggestedSolrFieldsFromDatabase(id: String): IndexedSeq[SuggestedSolrFieldExport] = db.withConnection { implicit connection => { SQL(SuggestedSolrFieldExport.selectStatement(id)).as(SuggestedSolrFieldExport.sqlParser.*).toIndexedSeq } } - def getInputTagsFromDatabase: IndexedSeq[InputTagExport] = db.withConnection { - implicit connection => { - SQL(InputTagExport.selectAllStatement).as(InputTagExport.sqlParser.*).toIndexedSeq - } - } - def getInputTagsFromDatabase(id: String): IndexedSeq[InputTagExport] = db.withConnection { implicit connection => { SQL(InputTagExport.selectStatement(id)).as(InputTagExport.sqlParser.*).toIndexedSeq } } - def getTagInputAssociationsFromDatabase: IndexedSeq[TagInputAssociationExport] = db.withConnection { - implicit connection => { - SQL(TagInputAssociationExport.selectAllStatement).as(TagInputAssociationExport.sqlParser.*).toIndexedSeq - } - } - def getTagInputAssociationsFromDatabase(id: String): IndexedSeq[TagInputAssociationExport] = db.withConnection { implicit connection => { SQL(TagInputAssociationExport.selectStatement(id)).as(TagInputAssociationExport.sqlParser.*).toIndexedSeq } } - def getCanonicalSpellingsFromDatabase: IndexedSeq[CanonicalSpellingExport] = db.withConnection { - implicit connection => { - SQL(CanonicalSpellingExport.selectAllStatement).as(CanonicalSpellingExport.sqlParser.*).toIndexedSeq - } - } - def getCanonicalSpellingsFromDatabase(id: String): IndexedSeq[CanonicalSpellingExport] = db.withConnection { implicit connection => { SQL(CanonicalSpellingExport.selectStatement(id)).as(CanonicalSpellingExport.sqlParser.*).toIndexedSeq } } - def getAlternativeSpellingsFromDatabase: IndexedSeq[AlternativeSpellingExport] = db.withConnection { - implicit connection => { - SQL(AlternativeSpellingExport.selectAllStatement).as(AlternativeSpellingExport.sqlParser.*).toIndexedSeq - } - } - def getAlternativeSpellingsFromDatabase(id: String): IndexedSeq[AlternativeSpellingExport] = db.withConnection { implicit connection => { SQL(AlternativeSpellingExport.selectStatement(id)).as(AlternativeSpellingExport.sqlParser.*).toIndexedSeq } } - def getDatabaseJson: JsValue = { - logger.debug("In Exporter.getDatabaseJson") - val tableSeq = IndexedSeq( - getSolrIndexFromDatabase, - getSearchInputsFromDatabase, - getRedirectRulesFromDatabase, - getSynonymRulesFromDatabase, - getUpDownRulesFromDatabase, - getDeleteRulesFromDatabase, - getFilterRulesFromDatabase, - getSuggestedSolrFieldsFromDatabase, - getInputTagsFromDatabase, - getTagInputAssociationsFromDatabase, - getCanonicalSpellingsFromDatabase, - getAlternativeSpellingsFromDatabase - ) - getAllTablesForJs(tableSeq) - } - def getDatabaseJsonWithId(id: String): JsValue = { logger.debug("In Exporter.getDatabaseJsonWithId") val tableSeq = IndexedSeq( diff --git a/app/models/export/Something.scala b/app/models/export/Something.scala deleted file mode 100644 index 2bc950bf..00000000 --- a/app/models/export/Something.scala +++ /dev/null @@ -1,100 +0,0 @@ -package models.`export` - -import anorm.SqlParser.get -import anorm.{RowParser, ~} -import models.`export`.Something.myJavascriptObject -import models.{Id, IdObject} -import play.api.libs.json.{JsArray, JsString, JsValue, Json, Writes} - -import java.time.LocalDateTime -import java.util.UUID - -class SomethingId(id: String) extends Id(id) -object SomethingId extends IdObject[SomethingId](new SomethingId(_)) - -case class Something(id: SomethingId = SomethingId(), - value_0: String, - last_update: LocalDateTime) extends JsonExportable { - - implicit val writer: Writes[String] = new Writes[(String)] { - def writes(t: (String)): JsValue = { - Json.obj( - "id" -> myJavascriptObject.id, - "value_0" -> myJavascriptObject.value_0, - "last_update" -> myJavascriptObject.last_update) - } - } - - def getTableName: JsString = JsString("something") - - def getColumns: JsValue = { - JsArray( - IndexedSeq ( - JsString("id"), - JsString("value_0"), - JsString("last_update") - ) - ) - } - - def getRow: JsValue = { - JsArray( - IndexedSeq ( - JsString(id.toString), - JsString(value_0), - JsString(last_update.toString) - ) - ) - } - -} - -case class MyJsObject( - id: JsValue, - value_0: JsValue, - last_update: JsValue - ) - -object Something { - - val TABLE_NAME = "something" - val ID = "id" - val VALUE_0 = "value_0" - val LAST_UPDATE = "last_update" - - val sqlParser: RowParser[Something] = { - get[SomethingId] (s"$TABLE_NAME.$ID") ~ - get[String](s"$TABLE_NAME.$VALUE_0") ~ - get[LocalDateTime](s"$TABLE_NAME.last_update") map { case id ~ value_0 ~ last_update => - Something(id, value_0, last_update) - } - } - - val selectAllStatement : String = { - s"select $TABLE_NAME.$ID, " + - s"$TABLE_NAME.$VALUE_0, " + - s"$TABLE_NAME.$LAST_UPDATE from $TABLE_NAME" - } - - val myJavascriptObject: MyJsObject = { - MyJsObject( - id = JsString(UUID.randomUUID().toString), - value_0 = JsString("this is some value for value_0"), - last_update = JsString(LocalDateTime.now().toString) -// value1 = JsObject(Seq("simpleObject" -> JsString("simpleStringValue"))), -// value2 = JsObject( -// Seq( -// "aString" -> JsString("simpleString"), -// "aNumber" -> JsNumber(4.3), -// "aNull" -> JsNull -// ) -// ), -// value3 = JsArray( -// IndexedSeq( -// new JsString("first value of array"), -// new JsString("second value of array")) -// ) - ) - } - -} diff --git a/app/models/export/example_export_file.json.txt b/app/models/export/example_export_file.json.txt deleted file mode 100644 index 344c1b55..00000000 --- a/app/models/export/example_export_file.json.txt +++ /dev/null @@ -1,292 +0,0 @@ -[ - { - "tableName": "solr_index", - "columns": [ - "id", - "name", - "description", - "last_update" - ], - "rows": [ - [ - "b0eecea6-efa7-4575-9bb4-acba1aab146b", - "b0eecea6-efa7-4575-9bb4-acba1aab146b", - "test", - "2022-05-31T11:14:38" - ] - ] - }, - { - "tableName": "search_input", - "columns": [ - "id", - "term", - "solr_index_id", - "last_update", - "status", - "comment" - ], - "rows": [ - [ - "16c30efd-3139-4916-bfb6-57463af18250", - "test", - "b0eecea6-efa7-4575-9bb4-acba1aab146b", - "2022-05-31T17:25:25", - 1, - "updown comment" - ], - [ - "5418428c-0d4c-4464-a2a6-084f264be360", - "s", - "b0eecea6-efa7-4575-9bb4-acba1aab146b", - "2022-05-31T15:29:59", - 1, - "syn com" - ], - [ - "70823642-e7c6-4857-9d6c-a54b3c382f0d", - "test", - "b0eecea6-efa7-4575-9bb4-acba1aab146b", - "2022-05-31T14:43:54", - 1, - "" - ], - [ - "89c10061-26d9-4b5f-9e99-92696cc5da74", - "test two three", - "b0eecea6-efa7-4575-9bb4-acba1aab146b", - "2022-05-31T13:43:50", - 1, - "a comment" - ], - [ - "9fb7f8b4-5544-4df0-9d08-d485a0145dbe", - "redirect", - "b0eecea6-efa7-4575-9bb4-acba1aab146b", - "2022-05-31T17:20:36", - 1, - "redirect comment" - ], - [ - "ccc48739-f192-44b1-b552-995eed4a0a51", - "all", - "b0eecea6-efa7-4575-9bb4-acba1aab146b", - "2022-05-31T14:41:55", - 1, - "" - ], - [ - "dd1bd496-90ed-43ad-9895-e67a4f67adeb", - "test1", - "b0eecea6-efa7-4575-9bb4-acba1aab146b", - "2022-05-31T13:54:27", - 1, - "" - ], - [ - "e8064dd4-0e76-4e0b-963a-06ea8cae65e2", - "t345", - "b0eecea6-efa7-4575-9bb4-acba1aab146b", - "2022-05-31T14:56:51", - 1, - "c" - ] - ] - }, - { - "tableName": "redirect_rule", - "columns": [ - "id", - "target", - "search_input_id", - "last_update", - "status" - ], - "rows": [ - [ - "89e5833a-64b4-4a97-924b-a18b66694437", - "https://www.google.com", - "9fb7f8b4-5544-4df0-9d08-d485a0145dbe", - "2022-05-31T17:20:36", - 1 - ] - ] - }, - { - "tableName": "synonym_rule", - "columns": [ - "id", - "synonymType", - "term", - "search_input_id", - "last_update", - "status" - ], - "rows": [ - [ - "70d3eb55-ad67-4890-a157-130ea72637c1", - 0, - "y", - "5418428c-0d4c-4464-a2a6-084f264be360", - "2022-05-31T15:29:59", - 1 - ] - ] - }, - { - "tableName": "up_down_rule", - "columns": [ - "id", - "up_down_type", - "boost_malus_type", - "term", - "search_input_id", - "last_update", - "status" - ], - "rows": [ - [ - "a26f49ad-28ba-40e3-a968-ada168d948c7", - 0, - 5, - "* a:test", - 1, - "16c30efd-3139-4916-bfb6-57463af18250", - "2022-05-31T17:25:25" - ] - ] - }, - { - "tableName": "delete_rule", - "columns": [ - "id", - "term", - "search_input_id", - "last_update", - "status" - ], - "rows": [ - [ - "36d7a7d2-4133-4bcc-b4b3-19ec6d0404d1", - "two", - "89c10061-26d9-4b5f-9e99-92696cc5da74", - "2022-05-31T13:43:50", - 1 - ] - ] - }, - { - "tableName": "filter_rule", - "columns": [ - "id", - "term", - "search_input_id", - "last_update", - "status" - ], - "rows": [ - [ - "8ed6c4bd-ac69-4a94-898c-fabb13a7fc47", - "* test:* a:b", - "e8064dd4-0e76-4e0b-963a-06ea8cae65e2", - "2022-05-31T14:56:51", - 1 - ] - ] - }, - { - "tableName": "suggested_solr_field", - "columns": [ - "id", - "name", - "solr_index_id", - "last_update" - ], - "rows": [ - [ - "4ce83b3a-7263-4873-b4f2-a66a9321fdbb", - "test", - "b0eecea6-efa7-4575-9bb4-acba1aab146b", - "2022-05-31T17:37:43" - ] - ] - }, - { - "tableName": "input_tag", - "columns": [ - "id", - "solr_index_id", - "property", - "tag_value", - "exported", - "predefined", - "last_update" - ], - "rows": [ - [ - "wh", - "some solr_index_id", - "some property", - "some tag_value", - 2345, - 123, - "2022-05-31T18:23:47" - ] - ] - }, - { - "tableName": "tag_2_input", - "columns": [ - "id", - "searchInputId", - "last_update" - ], - "rows": [ - [ - "hi", - "3", - "2022-05-31T18:22:14" - ] - ] - }, - { - "tableName": "canonical_spelling", - "columns": [ - "id", - "solr_index_id", - "term", - "status", - "comment", - "last_update" - ], - "rows": [ - [ - "id8", - "id9", - "a_term_can_spell", - 0, - "can_spell_comment", - "2022-05-31T18:44:15" - ] - ] - }, - { - "tableName": "alternative_spelling", - "columns": [ - "id", - "canonical_spelling_id", - "term", - "status", - "last_update" - ], - "rows": [ - [ - "id10", - "id11", - "alt_spell_term", - 0, - "2022-05-31T18:44:15" - ] - ] - } -] diff --git a/app/models/rules/Rule.scala b/app/models/rules/Rule.scala index 4fc2265c..529b1db8 100644 --- a/app/models/rules/Rule.scala +++ b/app/models/rules/Rule.scala @@ -1,13 +1,13 @@ package models.rules -import java.sql.Connection -import java.time.LocalDateTime import anorm._ import models.Id -import models.`export`.JsonExportable import models.input.SearchInputId import play.api.Logging +import java.sql.Connection +import java.time.LocalDateTime + trait Rule { def id: Id diff --git a/app/models/rules/SynonymRule.scala b/app/models/rules/SynonymRule.scala index ece67b96..a360abc1 100644 --- a/app/models/rules/SynonymRule.scala +++ b/app/models/rules/SynonymRule.scala @@ -1,15 +1,12 @@ package models.rules -import java.sql.Connection import anorm.SqlParser.get import anorm._ -import models.`export`.{Something, SomethingId} import models.input.SearchInputId -import models.rules.FilterRule.{LAST_UPDATE, SEARCH_INPUT_ID, TABLE_NAME} import models.{Id, IdObject, Status} -import play.api.libs.json.{JsArray, JsNumber, JsString, JsValue, Json, OFormat} +import play.api.libs.json.{Json, OFormat} -import java.time.LocalDateTime +import java.sql.Connection class SynonymRuleId(id: String) extends Id(id) object SynonymRuleId extends IdObject[SynonymRuleId](new SynonymRuleId(_)) diff --git a/app/models/rules/UpDownRule.scala b/app/models/rules/UpDownRule.scala index ef966ddf..fca9f8fa 100644 --- a/app/models/rules/UpDownRule.scala +++ b/app/models/rules/UpDownRule.scala @@ -4,9 +4,7 @@ import anorm.SqlParser.get import anorm.{NamedParameter, RowParser, ~} import models.input.SearchInputId import models.{Id, IdObject, Status} -import play.api.libs.json.{JsArray, JsNumber, JsString, JsValue, Json, OFormat} - -import java.time.LocalDateTime +import play.api.libs.json.{Json, OFormat} class UpDownRuleId(id: String) extends Id(id) object UpDownRuleId extends IdObject[UpDownRuleId](new UpDownRuleId(_)) diff --git a/conf/evolutions/default/9.sql b/conf/evolutions/default/9.sql deleted file mode 100644 index 631a50db..00000000 --- a/conf/evolutions/default/9.sql +++ /dev/null @@ -1,11 +0,0 @@ -# --- !Ups - -create table something ( - id varchar(36) not null primary key, - value0 varchar(1000) not null, - last_update timestamp not null -); - -# --- !Downs - -drop table something; \ No newline at end of file diff --git a/conf/routes b/conf/routes index 19e8b458..64596a8a 100644 --- a/conf/routes +++ b/conf/routes @@ -37,13 +37,8 @@ GET /api/v1/log/rule-activity-log controllers.ApiC GET /api/v1/report/rules-report/:solrIndexId controllers.ApiController.getRulesReport(solrIndexId: String) GET /api/v1/report/activity-report/:solrIndexId controllers.ApiController.getActivityReport(solrIndexId: String) GET /api/v1/version/latest-info controllers.ApiController.getLatestVersionInfo() - -GET /api/v1/solr-index/:solrIndexId/something controllers.ApiController.getSomething(solrIndexId: String) -PUT /api/v1/put-something controllers.ApiController.putSomething -GET /api/v1/get-export controllers.ApiController.getDatabaseJson GET /api/v1/get-export-with-id/:id controllers.ApiController.getDatabaseJsonWithId(id: String) POST /api/v1/upload-import controllers.ApiController.uploadImport -PUT /api/v1/putty controllers.ApiController.putty # Map static resources from the /public folder to the /assets URL path GET /*file controllers.FrontendController.assetOrDefault(file) diff --git a/frontend/src/app/components/admin/rules-collection-list/rules-collection-list.component.ts b/frontend/src/app/components/admin/rules-collection-list/rules-collection-list.component.ts index 5d7dbe73..f0bd7fb1 100644 --- a/frontend/src/app/components/admin/rules-collection-list/rules-collection-list.component.ts +++ b/frontend/src/app/components/admin/rules-collection-list/rules-collection-list.component.ts @@ -23,8 +23,6 @@ import { } from '../../../services'; import {HttpClient} from "@angular/common/http"; import {Subject} from "rxjs"; -import {Something} from "../../../models/export"; - @Component({ selector: 'app-smui-admin-rules-collection-list', diff --git a/frontend/src/app/models/export.ts b/frontend/src/app/models/export.ts deleted file mode 100644 index fc846ab7..00000000 --- a/frontend/src/app/models/export.ts +++ /dev/null @@ -1,3 +0,0 @@ -export class Something { - word: string; -}