SUPPORT-8529: Добавлен вызов http

This commit is contained in:
malkov34 2024-09-05 09:06:50 +03:00
parent c246132121
commit f5854c7592
9 changed files with 185 additions and 130 deletions

View file

@ -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);
}
}

View file

@ -21,7 +21,7 @@ public class ConfigExecutorRpcService extends Behavior {
}
@RpcCall
public void callConfigExecutor(String path, List<String> ids) {
configExecutorService.callConfigExecutor(path, ids);
public void callConfigExecutor(String methodPath, List<String> ids) {
configExecutorService.call(methodPath, ids);
}
}

View file

@ -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<String> ids) {
LOGGER.info("host: " + host);
LOGGER.info("port " + port);
LOGGER.info("path: " + path);
ids.forEach(LOGGER::info);
public void call(String methodPath, List<String> ids) {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<List<String>> entity = new HttpEntity<>(ids, headers);
LOGGER.info("Starts call config executor service with method: {}, for ids: {}", methodPath, ids);
try {
ResponseEntity<Object> 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);
}
}
}

View file

@ -54,8 +54,9 @@
<property name="security.password.regex" value="^((?=(.*\d){1,})(?=.*[a-zа-яё])(?=.*[A-ZА-ЯЁ]).{8,})$"/>
<property name="fias.enable" value="false"/>
<property name="com.arjuna.ats.arjuna.allowMultipleLastResources" value="true"/>
<property name="config-data-executor.host" value="127.0.0.1"/>
<property name="config-data-executor.port" value="8080"/>
<property name="config-data-executor.url" value="http://127.0.0.1:8090/api"/>
<property name="config-data-executor.socket-timeout" value="10"/>
<property name="config-data-executor.connectionTimeout" value="10"/>
</system-properties>
<management>
<audit-log>

View file

@ -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<any> {
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');
}
}

View file

@ -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({

View file

@ -1,38 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xmlComponent>
<id>8a93fb89-9703-41de-95ec-ec1f700b12f5</id>
<name>ConfigExecuteBtn</name>
<internal>false</internal>
<versions>
<studioVersion>3.175.1-SUPPORT-8427v3-SNAPSHOT</studioVersion>
<packageVersions>
<entry>
<key>ru.cg.webbpm.packages.base.resources</key>
<value>3.175.1-8427v4-SNAPSHOT</value>
</entry>
</packageVersions>
</versions>
<rootObject id="491f2de3-6427-4144-afbd-d586e3789b05">
<prototypeId>c8dfe691-a84a-48da-b79e-6298d90db71d</prototypeId>
<componentRootId>491f2de3-6427-4144-afbd-d586e3789b05</componentRootId>
<name>ConfigExecuteBtn</name>
<container>false</container>
<childrenReordered>false</childrenReordered>
<scripts id="bf098f19-480e-44e4-9084-aa42955c4d0f">
<properties>
<entry>
<key>caption</key>
<value>
<simple>"Удалить данные по гражданам"</simple>
</value>
</entry>
<entry>
<key>navigateTo</key>
<value>
<simple>"delete"</simple>
</value>
</entry>
</properties>
</scripts>
</rootObject>
</xmlComponent>

View file

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xmlComponent>
<id>a027d79e-e214-423e-ae33-c5bb5e7383ba</id>
<name>ConfigExecuteButton</name>
<internal>false</internal>
<versions>
<studioVersion>3.175.1-SUPPORT-8427v3-SNAPSHOT</studioVersion>
<packageVersions>
<entry>
<key>ru.cg.webbpm.packages.base.resources</key>
<value>3.175.1-8427v4-SNAPSHOT</value>
</entry>
</packageVersions>
</versions>
<rootObject id="67d2e469-003f-48d1-99a5-bdd27bb36d58">
<name>ConfigExecuteButton</name>
<container>false</container>
<childrenReordered>false</childrenReordered>
<scripts id="1d7049ae-7dfb-4597-80e0-dd8648af72ef">
<classRef type="TS">
<className>ConfigExecuteBtn</className>
<packageName>ervu</packageName>
</classRef>
<enabled>true</enabled>
<expanded>true</expanded>
<properties>
<entry>
<key>visible</key>
<value>
<complex/>
<simple>true</simple>
</value>
</entry>
<entry>
<key>disabled</key>
<value>
<complex/>
<simple>false</simple>
</value>
</entry>
</properties>
</scripts>
<scripts id="829e8ac1-129c-4cab-b0c0-20db9f9d125d">
<classRef type="JAVA">
<className>ConfigExecutorRpcService</className>
<packageName>rpc</packageName>
</classRef>
<enabled>true</enabled>
<expanded>true</expanded>
<properties/>
</scripts>
</rootObject>
</xmlComponent>

View file

@ -418,13 +418,13 @@
<scripts id="fe04d7fb-6c5b-46c4-b723-667732d81f4f"/>
<scripts id="5c566210-2a60-4048-a2d1-84c7dd023248"/>
<scripts id="3171b2e1-b4af-4335-95fa-1b2592604b84"/>
<children id="f7553607-7133-4e0c-88dc-1c2d2ef3f174">
<prototypeId>c8dfe691-a84a-48da-b79e-6298d90db71d</prototypeId>
<componentRootId>f7553607-7133-4e0c-88dc-1c2d2ef3f174</componentRootId>
<name>Navigation Исключить граждан из списков вызова</name>
<children id="35269d46-0d55-4392-85af-16b6f11dcfe6">
<prototypeId>67d2e469-003f-48d1-99a5-bdd27bb36d58</prototypeId>
<componentRootId>35269d46-0d55-4392-85af-16b6f11dcfe6</componentRootId>
<name>ConfigExecuteButton Исключить граждан из списков вызова</name>
<container>false</container>
<childrenReordered>false</childrenReordered>
<scripts id="bf098f19-480e-44e4-9084-aa42955c4d0f">
<scripts id="1d7049ae-7dfb-4597-80e0-dd8648af72ef">
<properties>
<entry>
<key>caption</key>
@ -433,19 +433,20 @@
</value>
</entry>
<entry>
<key>confirmationText</key>
<key>ervuIdField</key>
<value>
<simple>null</simple>
<simple>{"objectId":"4eee5df5-93bd-490a-b980-80f256df9ce6","packageName":"component.field","className":"TextArea","type":"TS"}</simple>
</value>
</entry>
<entry>
<key>navigateTo</key>
<key>methodPath</key>
<value>
<simple>"exclude"</simple>
<simple>"/removeFromCallList"</simple>
</value>
</entry>
</properties>
</scripts>
<scripts id="829e8ac1-129c-4cab-b0c0-20db9f9d125d"/>
</children>
<children id="3740b4d8-04e0-46b7-8d3d-0d8786552829">
<prototypeId>c8dfe691-a84a-48da-b79e-6298d90db71d</prototypeId>
@ -835,38 +836,13 @@
<scripts id="fe04d7fb-6c5b-46c4-b723-667732d81f4f"/>
<scripts id="5c566210-2a60-4048-a2d1-84c7dd023248"/>
<scripts id="3171b2e1-b4af-4335-95fa-1b2592604b84"/>
<children id="b1eb1925-d767-4e3f-ba59-b8f1c152de9a">
<prototypeId>491f2de3-6427-4144-afbd-d586e3789b05</prototypeId>
<componentRootId>b1eb1925-d767-4e3f-ba59-b8f1c152de9a</componentRootId>
<name>ConfigExecuteBtn Удалить данные по гражданам</name>
<children id="ec4cdeb3-f05f-4a60-b3a9-5a4a6828bc0b">
<prototypeId>67d2e469-003f-48d1-99a5-bdd27bb36d58</prototypeId>
<componentRootId>ec4cdeb3-f05f-4a60-b3a9-5a4a6828bc0b</componentRootId>
<name>ConfigExecuteButton Удалить данные по гражданам</name>
<container>false</container>
<childrenReordered>false</childrenReordered>
<scripts id="bf098f19-480e-44e4-9084-aa42955c4d0f">
<enabled>false</enabled>
<properties>
<entry>
<key>visible</key>
<value>
<simple>false</simple>
</value>
</entry>
</properties>
</scripts>
<scripts id="6783ae7c-aeee-4b77-9a83-31eee4bf9cbb">
<classRef type="JAVA">
<className>ConfigExecutorRpcService</className>
<packageName>rpc</packageName>
</classRef>
<enabled>true</enabled>
<expanded>true</expanded>
</scripts>
<scripts id="6ad54463-00fd-4b17-a4d5-962321d82f7c">
<classRef type="TS">
<className>ConfigExecuteBtn</className>
<packageName>ervu</packageName>
</classRef>
<enabled>true</enabled>
<expanded>true</expanded>
<scripts id="1d7049ae-7dfb-4597-80e0-dd8648af72ef">
<properties>
<entry>
<key>caption</key>
@ -875,12 +851,6 @@
</value>
</entry>
<entry>
<key>confirmationText</key>
<value>
<simple>null</simple>
</value>
</entry>
<entry>
<key>ervuIdField</key>
<value>
<simple>{"objectId":"663b3639-2a6b-4f3d-b0a0-2ba829de6ea4","packageName":"component.field","className":"TextArea","type":"TS"}</simple>
@ -889,17 +859,12 @@
<entry>
<key>methodPath</key>
<value>
<simple>"delete"</simple>
</value>
</entry>
<entry>
<key>visible</key>
<value>
<simple>true</simple>
<simple>"/removeFromSystem"</simple>
</value>
</entry>
</properties>
</scripts>
<scripts id="829e8ac1-129c-4cab-b0c0-20db9f9d125d"/>
</children>
<children id="1307991b-12e9-4662-9443-e5e3654c76c8">
<prototypeId>c8dfe691-a84a-48da-b79e-6298d90db71d</prototypeId>
@ -1303,13 +1268,13 @@
<scripts id="fe04d7fb-6c5b-46c4-b723-667732d81f4f"/>
<scripts id="5c566210-2a60-4048-a2d1-84c7dd023248"/>
<scripts id="3171b2e1-b4af-4335-95fa-1b2592604b84"/>
<children id="c72d5f68-82f1-4f82-a7d5-0b3fe0a7fe91">
<prototypeId>c8dfe691-a84a-48da-b79e-6298d90db71d</prototypeId>
<componentRootId>c72d5f68-82f1-4f82-a7d5-0b3fe0a7fe91</componentRootId>
<name>Navigation Заблокировать граждан</name>
<children id="647bf0c5-1da2-43c2-8ed5-240bb305d87a">
<prototypeId>67d2e469-003f-48d1-99a5-bdd27bb36d58</prototypeId>
<componentRootId>647bf0c5-1da2-43c2-8ed5-240bb305d87a</componentRootId>
<name>ConfigExecuteButton Заблокировать граждан</name>
<container>false</container>
<childrenReordered>false</childrenReordered>
<scripts id="bf098f19-480e-44e4-9084-aa42955c4d0f">
<scripts id="1d7049ae-7dfb-4597-80e0-dd8648af72ef">
<properties>
<entry>
<key>caption</key>
@ -1318,13 +1283,20 @@
</value>
</entry>
<entry>
<key>navigateTo</key>
<key>ervuIdField</key>
<value>
<simple>"lock"</simple>
<simple>{"objectId":"71b3b7d0-513d-4a21-90d5-003f219238fa","packageName":"component.field","className":"TextArea","type":"TS"}</simple>
</value>
</entry>
<entry>
<key>methodPath</key>
<value>
<simple>"/block"</simple>
</value>
</entry>
</properties>
</scripts>
<scripts id="829e8ac1-129c-4cab-b0c0-20db9f9d125d"/>
</children>
<children id="fcae0c92-b51a-402e-8fc7-a686308bcfb3">
<prototypeId>c8dfe691-a84a-48da-b79e-6298d90db71d</prototypeId>
@ -1571,13 +1543,13 @@
<scripts id="fe04d7fb-6c5b-46c4-b723-667732d81f4f"/>
<scripts id="5c566210-2a60-4048-a2d1-84c7dd023248"/>
<scripts id="3171b2e1-b4af-4335-95fa-1b2592604b84"/>
<children id="a50ba8f4-1039-4bea-954d-e924fb3f627e">
<prototypeId>c8dfe691-a84a-48da-b79e-6298d90db71d</prototypeId>
<componentRootId>a50ba8f4-1039-4bea-954d-e924fb3f627e</componentRootId>
<name>Navigation Разблокировать</name>
<children id="5eaf872c-e89c-41be-9377-392387c83000">
<prototypeId>67d2e469-003f-48d1-99a5-bdd27bb36d58</prototypeId>
<componentRootId>5eaf872c-e89c-41be-9377-392387c83000</componentRootId>
<name>ConfigExecuteButton Разблокировать</name>
<container>false</container>
<childrenReordered>false</childrenReordered>
<scripts id="bf098f19-480e-44e4-9084-aa42955c4d0f">
<scripts id="1d7049ae-7dfb-4597-80e0-dd8648af72ef">
<properties>
<entry>
<key>caption</key>
@ -1586,13 +1558,27 @@
</value>
</entry>
<entry>
<key>navigateTo</key>
<key>ervuIdField</key>
<value>
<simple>"unlock"</simple>
<simple>{"objectId":"8c85fe31-bdb8-495e-8c4c-7addc9d7ba71","packageName":"component.field","className":"TextArea","type":"TS"}</simple>
</value>
</entry>
<entry>
<key>methodPath</key>
<value>
<simple>"/unblock"</simple>
</value>
</entry>
</properties>
</scripts>
<scripts id="829e8ac1-129c-4cab-b0c0-20db9f9d125d"/>
</children>
<children id="a50ba8f4-1039-4bea-954d-e924fb3f627e">
<prototypeId>c8dfe691-a84a-48da-b79e-6298d90db71d</prototypeId>
<componentRootId>a50ba8f4-1039-4bea-954d-e924fb3f627e</componentRootId>
<name>Navigation Разблокировать</name>
<container>false</container>
<removed>true</removed>
</children>
<children id="b79d8cf3-f367-4641-8fa2-baddf5f2dfa2">
<prototypeId>c8dfe691-a84a-48da-b79e-6298d90db71d</prototypeId>