From f5854c7592d9fe1db6754a26ffa00dd54bbc7113 Mon Sep 17 00:00:00 2001 From: malkov34 Date: Thu, 5 Sep 2024 09:06:50 +0300 Subject: [PATCH] =?UTF-8?q?SUPPORT-8529:=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=20=D0=B2=D1=8B=D0=B7=D0=BE=D0=B2=20http?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/main/java/AppConfig.java | 35 +++++- .../java/rpc/ConfigExecutorRpcService.java | 4 +- .../java/service/ConfigExecutorService.java | 32 +++-- config/standalone.xml | 5 +- frontend/src/ts/ervu/ConfigExecuteBtn.ts | 26 ++-- frontend/src/ts/modules/app/app.module.ts | 4 +- .../business-model/ConfigExecuteBtn.component | 38 ------ .../ConfigExecuteButton.component | 53 ++++++++ .../main_process/main_page.page | 118 ++++++++---------- 9 files changed, 185 insertions(+), 130 deletions(-) delete mode 100644 resources/src/main/resources/business-model/ConfigExecuteBtn.component create mode 100644 resources/src/main/resources/business-model/ConfigExecuteButton.component diff --git a/backend/src/main/java/AppConfig.java b/backend/src/main/java/AppConfig.java index f7645b2..86b0458 100644 --- a/backend/src/main/java/AppConfig.java +++ b/backend/src/main/java/AppConfig.java @@ -1,21 +1,26 @@ -import java.time.Duration; -import javax.sql.DataSource; - import net.javacrumbs.shedlock.core.LockProvider; import net.javacrumbs.shedlock.provider.jdbctemplate.JdbcTemplateLockProvider; import net.javacrumbs.shedlock.spring.ScheduledLockConfiguration; import net.javacrumbs.shedlock.spring.ScheduledLockConfigurationBuilder; - +import org.apache.http.client.config.RequestConfig; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.EnableAspectJAutoProxy; import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; +import org.springframework.web.client.RestTemplate; import org.springframework.web.servlet.config.annotation.EnableWebMvc; +import javax.sql.DataSource; +import java.time.Duration; + /** * Root application context * This context imports XML configs from all the other jars, and is created by {@link WebAppInitializer} @@ -41,6 +46,11 @@ import org.springframework.web.servlet.config.annotation.EnableWebMvc; @EnableScheduling public class AppConfig { + @Value("${config-data-executor.socket-timeout:10}") + private int socketTimeout; + @Value("${config-data-executor.connection-timeout:10}") + private int connectionTimeout; + @Bean public PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer(){ return new PropertySourcesPlaceholderConfigurer(); @@ -62,4 +72,21 @@ public class AppConfig { public LockProvider lockProvider(@Qualifier("datasource") DataSource dataSource) { return new JdbcTemplateLockProvider(dataSource); } + + @Bean + public RestTemplate restTemplate() { + RequestConfig requestConfig = RequestConfig.custom() + .setSocketTimeout(socketTimeout) + .setConnectionRequestTimeout(connectionTimeout) + .setConnectTimeout(connectionTimeout) + .build(); + + CloseableHttpClient httpClient = HttpClients.custom() + .setDefaultRequestConfig(requestConfig) + .build(); + + HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(httpClient); + + return new RestTemplate(factory); + } } diff --git a/backend/src/main/java/rpc/ConfigExecutorRpcService.java b/backend/src/main/java/rpc/ConfigExecutorRpcService.java index 992009c..ff169b4 100644 --- a/backend/src/main/java/rpc/ConfigExecutorRpcService.java +++ b/backend/src/main/java/rpc/ConfigExecutorRpcService.java @@ -21,7 +21,7 @@ public class ConfigExecutorRpcService extends Behavior { } @RpcCall - public void callConfigExecutor(String path, List ids) { - configExecutorService.callConfigExecutor(path, ids); + public void callConfigExecutor(String methodPath, List ids) { + configExecutorService.call(methodPath, ids); } } diff --git a/backend/src/main/java/service/ConfigExecutorService.java b/backend/src/main/java/service/ConfigExecutorService.java index f49b4dd..47e936f 100644 --- a/backend/src/main/java/service/ConfigExecutorService.java +++ b/backend/src/main/java/service/ConfigExecutorService.java @@ -2,8 +2,11 @@ package service; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.*; import org.springframework.stereotype.Service; +import org.springframework.web.client.RestTemplate; import java.lang.invoke.MethodHandles; import java.util.List; @@ -14,18 +17,27 @@ import java.util.List; @Service public class ConfigExecutorService { - @Value("${config-data-executor.host}") - String host; - @Value("${config-data-executor.port}") - String port; - + private final RestTemplate restTemplate; + private final String url; private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + public ConfigExecutorService(@Autowired RestTemplate restTemplate, + @Value("${config-data-executor.url}") String url) { + this.restTemplate = restTemplate; + this.url = url; + } - public void callConfigExecutor(String path, List ids) { - LOGGER.info("host: " + host); - LOGGER.info("port " + port); - LOGGER.info("path: " + path); - ids.forEach(LOGGER::info); + public void call(String methodPath, List ids) { + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + HttpEntity> entity = new HttpEntity<>(ids, headers); + LOGGER.info("Starts call config executor service with method: {}, for ids: {}", methodPath, ids); + try { + ResponseEntity response = restTemplate.exchange(url.concat(methodPath), HttpMethod.POST, entity, Object.class); + LOGGER.info("Method: {}, executed with status: {}, for ids:{}", methodPath, response.getStatusCode().value(), ids); + } catch (Exception e) { + throw new RuntimeException(String.format( + "Failed call config executor service method: %s for ids: %s with error", methodPath, ids), e); + } } } diff --git a/config/standalone.xml b/config/standalone.xml index 55fb5ce..d694df1 100644 --- a/config/standalone.xml +++ b/config/standalone.xml @@ -54,8 +54,9 @@ - - + + + diff --git a/frontend/src/ts/ervu/ConfigExecuteBtn.ts b/frontend/src/ts/ervu/ConfigExecuteBtn.ts index 92bf9d7..59af9c2 100644 --- a/frontend/src/ts/ervu/ConfigExecuteBtn.ts +++ b/frontend/src/ts/ervu/ConfigExecuteBtn.ts @@ -7,7 +7,7 @@ import {ConfigExecutorRpcService} from "../generated/rpc/ConfigExecutorRpcServic */ @Component({ moduleId: module.id, - selector: 'button-component', + selector: 'config-execute-button-component', templateUrl: './../../../src/resources/template/app/component/ConfigExecuteBtn.html', changeDetection: ChangeDetectionStrategy.OnPush }) @@ -24,19 +24,31 @@ export class ConfigExecuteBtn extends AbstractButton { super(el, cd); } - public initialize() { + initialize() { super.initialize(); this.script = this.getScript(ConfigExecutorRpcService) } doClickActions(): Promise { - const methodPath = this.methodPath; - const idsValue = this.ervuIdField.getValue(); - this.script.callConfigExecutor(methodPath, idsValue, true); - return Promise.resolve(); + const value = this.ervuIdField.getValue(); + if (value && this.methodPath.trim().length !== 0) { + const ids = value.replace(/[{}]/g, '') + .split(',') + .map(id => id.trim().replace(/"/g, '')); + + return this.script.callConfigExecutor(this.methodPath, ids, true) + .then(response => { + console.log("Успешное выполнение:", response); + return response; + }) + .catch(error => { + console.error("Ошибка при выполнении скрипта:", error); + return Promise.reject(error); + }); + } } - protected getFocusElement(): HTMLInputElement { + getFocusElement(): HTMLInputElement { return this.el.nativeElement.querySelector('button'); } } diff --git a/frontend/src/ts/modules/app/app.module.ts b/frontend/src/ts/modules/app/app.module.ts index 33d67db..4305278 100644 --- a/frontend/src/ts/modules/app/app.module.ts +++ b/frontend/src/ts/modules/app/app.module.ts @@ -30,6 +30,7 @@ import {TaskListComponent} from "./component/task-list.component"; import {ProcessListComponent} from "./component/process-list.component"; import {TaskComponent} from "./component/task.component"; import {TaskNotFoundComponent} from "./component/task-not-found.component"; +import {ConfigExecuteBtn} from "../../ervu/ConfigExecuteBtn"; registerLocaleData(localeRu); export const DIRECTIVES = [ @@ -48,7 +49,8 @@ export const DIRECTIVES = [ forwardRef(() => TaskListComponent), forwardRef(() => ProcessListComponent), forwardRef(() => TaskComponent), - forwardRef(() => TaskNotFoundComponent) + forwardRef(() => TaskNotFoundComponent), + forwardRef(() => ConfigExecuteBtn) ]; @NgModule({ diff --git a/resources/src/main/resources/business-model/ConfigExecuteBtn.component b/resources/src/main/resources/business-model/ConfigExecuteBtn.component deleted file mode 100644 index 20df232..0000000 --- a/resources/src/main/resources/business-model/ConfigExecuteBtn.component +++ /dev/null @@ -1,38 +0,0 @@ - - - 8a93fb89-9703-41de-95ec-ec1f700b12f5 - ConfigExecuteBtn - false - - 3.175.1-SUPPORT-8427v3-SNAPSHOT - - - ru.cg.webbpm.packages.base.resources - 3.175.1-8427v4-SNAPSHOT - - - - - c8dfe691-a84a-48da-b79e-6298d90db71d - 491f2de3-6427-4144-afbd-d586e3789b05 - ConfigExecuteBtn - false - false - - - - caption - - "Удалить данные по гражданам" - - - - navigateTo - - "delete" - - - - - - diff --git a/resources/src/main/resources/business-model/ConfigExecuteButton.component b/resources/src/main/resources/business-model/ConfigExecuteButton.component new file mode 100644 index 0000000..ea6be8e --- /dev/null +++ b/resources/src/main/resources/business-model/ConfigExecuteButton.component @@ -0,0 +1,53 @@ + + + a027d79e-e214-423e-ae33-c5bb5e7383ba + ConfigExecuteButton + false + + 3.175.1-SUPPORT-8427v3-SNAPSHOT + + + ru.cg.webbpm.packages.base.resources + 3.175.1-8427v4-SNAPSHOT + + + + + ConfigExecuteButton + false + false + + + ConfigExecuteBtn + ervu + + true + true + + + visible + + + true + + + + disabled + + + false + + + + + + + ConfigExecutorRpcService + rpc + + true + true + + + + diff --git a/resources/src/main/resources/business-model/main_process/main_page.page b/resources/src/main/resources/business-model/main_process/main_page.page index e1de647..451b5c9 100644 --- a/resources/src/main/resources/business-model/main_process/main_page.page +++ b/resources/src/main/resources/business-model/main_process/main_page.page @@ -418,13 +418,13 @@ - - c8dfe691-a84a-48da-b79e-6298d90db71d - f7553607-7133-4e0c-88dc-1c2d2ef3f174 - Navigation Исключить граждан из списков вызова + + 67d2e469-003f-48d1-99a5-bdd27bb36d58 + 35269d46-0d55-4392-85af-16b6f11dcfe6 + ConfigExecuteButton Исключить граждан из списков вызова false false - + caption @@ -433,19 +433,20 @@ -confirmationText +ervuIdField - null + {"objectId":"4eee5df5-93bd-490a-b980-80f256df9ce6","packageName":"component.field","className":"TextArea","type":"TS"} -navigateTo +methodPath - "exclude" + "/removeFromCallList" + c8dfe691-a84a-48da-b79e-6298d90db71d @@ -835,38 +836,13 @@ - - 491f2de3-6427-4144-afbd-d586e3789b05 - b1eb1925-d767-4e3f-ba59-b8f1c152de9a - ConfigExecuteBtn Удалить данные по гражданам + + 67d2e469-003f-48d1-99a5-bdd27bb36d58 + ec4cdeb3-f05f-4a60-b3a9-5a4a6828bc0b + ConfigExecuteButton Удалить данные по гражданам false false - - false - - -visible - - false - - - - - - - ConfigExecutorRpcService - rpc - - true - true - - - - ConfigExecuteBtn - ervu - - true - true + caption @@ -875,12 +851,6 @@ -confirmationText - - null - - - ervuIdField {"objectId":"663b3639-2a6b-4f3d-b0a0-2ba829de6ea4","packageName":"component.field","className":"TextArea","type":"TS"} @@ -889,17 +859,12 @@ methodPath - "delete" - - - -visible - - true + "/removeFromSystem" + c8dfe691-a84a-48da-b79e-6298d90db71d @@ -1303,13 +1268,13 @@ - - c8dfe691-a84a-48da-b79e-6298d90db71d - c72d5f68-82f1-4f82-a7d5-0b3fe0a7fe91 - Navigation Заблокировать граждан + + 67d2e469-003f-48d1-99a5-bdd27bb36d58 + 647bf0c5-1da2-43c2-8ed5-240bb305d87a + ConfigExecuteButton Заблокировать граждан false false - + caption @@ -1318,13 +1283,20 @@ -navigateTo +ervuIdField - "lock" + {"objectId":"71b3b7d0-513d-4a21-90d5-003f219238fa","packageName":"component.field","className":"TextArea","type":"TS"} + + + +methodPath + + "/block" + c8dfe691-a84a-48da-b79e-6298d90db71d @@ -1571,13 +1543,13 @@ - - c8dfe691-a84a-48da-b79e-6298d90db71d - a50ba8f4-1039-4bea-954d-e924fb3f627e - Navigation Разблокировать + + 67d2e469-003f-48d1-99a5-bdd27bb36d58 + 5eaf872c-e89c-41be-9377-392387c83000 + ConfigExecuteButton Разблокировать false false - + caption @@ -1586,13 +1558,27 @@ -navigateTo +ervuIdField - "unlock" + {"objectId":"8c85fe31-bdb8-495e-8c4c-7addc9d7ba71","packageName":"component.field","className":"TextArea","type":"TS"} + + + +methodPath + + "/unblock" + + + + c8dfe691-a84a-48da-b79e-6298d90db71d + a50ba8f4-1039-4bea-954d-e924fb3f627e + Navigation Разблокировать + false + true c8dfe691-a84a-48da-b79e-6298d90db71d