SUPPORT-8957: add service and controller for user management
This commit is contained in:
parent
b3deb8704b
commit
8e9ca630a4
10 changed files with 278 additions and 0 deletions
|
|
@ -216,6 +216,14 @@
|
|||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.validation</groupId>
|
||||
<artifactId>validation-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate.validator</groupId>
|
||||
<artifactId>hibernate-validator</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<finalName>${project.parent.artifactId}</finalName>
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import org.springframework.context.annotation.FilterType;
|
|||
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
|
||||
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;
|
||||
|
||||
/**
|
||||
|
|
@ -75,4 +76,9 @@ public class AppConfig {
|
|||
liquibase.setChangeLog("classpath:config/changelog-master.xml");
|
||||
return liquibase;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RestTemplate restTemplate() {
|
||||
return new RestTemplate();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,121 @@
|
|||
package ru.micord.ervu.account_applications.controller;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.client.HttpClientErrorException;
|
||||
import org.springframework.web.client.HttpServerErrorException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
import ru.micord.ervu.account_applications.dto.Account;
|
||||
import ru.micord.ervu.account_applications.dto.ProcessRequest;
|
||||
import ru.micord.ervu.account_applications.dto.create.CreateProcessRequest;
|
||||
import ru.micord.ervu.account_applications.dto.create.CreateUserDto;
|
||||
import ru.micord.ervu.account_applications.dto.create.Credential;
|
||||
import ru.micord.ervu.account_applications.dto.create.CreateData;
|
||||
import ru.micord.ervu.account_applications.dto.Person;
|
||||
import ru.micord.ervu.account_applications.dto.ProcessResponse;
|
||||
import ru.micord.ervu.account_applications.dto.Role;
|
||||
import ru.micord.ervu.account_applications.dto.Roles;
|
||||
import ru.micord.ervu.account_applications.dto.deactivate.DeactivateData;
|
||||
import ru.micord.ervu.account_applications.dto.deactivate.DeactivateProcessRequest;
|
||||
import ru.micord.ervu.account_applications.dto.edit.EditData;
|
||||
import ru.micord.ervu.account_applications.dto.edit.EditPersonDto;
|
||||
import ru.micord.ervu.account_applications.dto.edit.EditPersonProcessRequest;
|
||||
import ru.micord.ervu.account_applications.enums.ProcessKey;
|
||||
import ru.micord.ervu.account_applications.security.context.SecurityContext;
|
||||
|
||||
/**
|
||||
* @author gulnaz
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/user")
|
||||
public class AdminController {
|
||||
private static final String PROCESS_START_URI = "/service/wf/service/start";
|
||||
|
||||
private final RestTemplate restTemplate;
|
||||
private final SecurityContext securityContext;
|
||||
|
||||
@Value("${ervu.url}")
|
||||
String ervuServiceUrl;
|
||||
|
||||
public AdminController(RestTemplate restTemplate, SecurityContext securityContext) {
|
||||
this.restTemplate = restTemplate;
|
||||
this.securityContext = securityContext;
|
||||
}
|
||||
|
||||
@PostMapping(value = "/create", consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
public ResponseEntity<?> create(@RequestBody @Valid CreateUserDto dto) {
|
||||
Credential credential = new Credential(dto.username());
|
||||
Account account = new Account(dto.userDomain(), dto.position());
|
||||
Person person = new Person(dto.firstname(), dto.surname(), dto.middlename(), dto.sex(),
|
||||
dto.email(), dto.birthdate(), dto.snils(), dto.ipAddresses());
|
||||
List<Role> rolesList = dto.roles()
|
||||
.stream()
|
||||
.map(role -> new Role(role, ""))
|
||||
.collect(Collectors.toList());
|
||||
Roles roles = new Roles(rolesList);
|
||||
CreateProcessRequest request = new CreateProcessRequest(
|
||||
ProcessKey.CREATE.getValue(), getUserId(), new CreateData(credential, account, person, roles));
|
||||
return doRequest(request);
|
||||
}
|
||||
|
||||
@PostMapping(value = "/edit", consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
public ResponseEntity<?> edit(@RequestBody @Valid EditPersonDto dto) {
|
||||
Person person = new Person(dto.id(), dto.firstname(), dto.surname(), dto.middlename(), dto.sex(),
|
||||
dto.email(), dto.birthdate(), dto.snils(), dto.ipAddresses());
|
||||
EditPersonProcessRequest request = new EditPersonProcessRequest(ProcessKey.EDIT_PERSON.getValue(),
|
||||
getUserId(), new EditData(dto.accountId(), person));
|
||||
return doRequest(request);
|
||||
}
|
||||
|
||||
@PostMapping(value = "/deactivate", consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
public ResponseEntity<?> deactivate(@RequestBody DeactivateData data) {
|
||||
DeactivateProcessRequest request = new DeactivateProcessRequest(ProcessKey.DEACTIVATE.getValue(),
|
||||
getUserId(), data);
|
||||
return doRequest(request);
|
||||
}
|
||||
|
||||
private <R> ResponseEntity<?> doRequest(ProcessRequest<R> request) {
|
||||
HttpEntity<ProcessRequest<R>> entity = setEntity(getToken(), request);
|
||||
URI uri = UriComponentsBuilder.fromHttpUrl(ervuServiceUrl)
|
||||
.path(PROCESS_START_URI)
|
||||
.build()
|
||||
.toUri();
|
||||
|
||||
try {
|
||||
return restTemplate.postForEntity(uri, entity, ProcessResponse.class);
|
||||
}
|
||||
catch (HttpClientErrorException | HttpServerErrorException e) {
|
||||
return new ResponseEntity<>(e.getMessage(), e.getStatusCode());
|
||||
}
|
||||
}
|
||||
|
||||
private <R> HttpEntity<R> setEntity(String key, R body) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setBearerAuth(key);
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
return new HttpEntity<>(body, headers);
|
||||
}
|
||||
|
||||
private String getUserId() {
|
||||
return securityContext.getUserId();
|
||||
}
|
||||
|
||||
//TODO after SUPPORT-8975
|
||||
private String getToken() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
package ru.micord.ervu.account_applications.enums;
|
||||
|
||||
/**
|
||||
* @author gulnaz
|
||||
*/
|
||||
public enum ProcessKey {
|
||||
CREATE("milBaseCreateAccountProcess"),
|
||||
EDIT_PERSON("milBaseEditAccountPersonIDMProcess"),
|
||||
EDIT_ACCOUNT("milBaseEditAccountIDMProcess"),
|
||||
EDIT_ROLES("milBaseEditAccountRolesIDMSubProcess"),
|
||||
DEACTIVATE("milBaseMassDeActivateAccountIDMProcess");
|
||||
|
||||
private final String value;
|
||||
|
||||
ProcessKey(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
|
@ -56,6 +56,7 @@
|
|||
<property name="fias.enable" value="false"/>
|
||||
<property name="registration.enabled" value="false"/>
|
||||
<property name="com.arjuna.ats.arjuna.allowMultipleLastResources" value="true"/>
|
||||
<property name="ervu.url" value="https://ervu-uat.test.gosuslugi.ru"/>
|
||||
</system-properties>
|
||||
<management>
|
||||
<audit-log>
|
||||
|
|
|
|||
|
|
@ -11,3 +11,5 @@ DB_SEC_PASSWORD=ervu_account_applications
|
|||
DB_SEC_HOST=10.10.31.118
|
||||
DB_SEC_PORT=5432
|
||||
DB_SEC_NAME=account_applications
|
||||
|
||||
ERVU_URL=https://ervu-uat.test.gosuslugi.ru
|
||||
|
|
|
|||
|
|
@ -0,0 +1,73 @@
|
|||
import {
|
||||
AnalyticalScope,
|
||||
Behavior,
|
||||
NotNull,
|
||||
SaveButton
|
||||
} from "@webbpm/base-package";
|
||||
import {HttpClient} from "@angular/common/http";
|
||||
import {FormField} from "../field/FormField";
|
||||
import {AccountAction} from "../enum/AccountAction";
|
||||
import {AuthorizationService} from "../../../modules/app/service/authorization.service";
|
||||
|
||||
@AnalyticalScope(SaveButton)
|
||||
export class UserManagementService extends Behavior {
|
||||
|
||||
@NotNull()
|
||||
public action: AccountAction;
|
||||
|
||||
private button: SaveButton;
|
||||
private httpClient: HttpClient;
|
||||
private onClickFunction: Function;
|
||||
|
||||
initialize() {
|
||||
super.initialize();
|
||||
this.button = this.getScript(SaveButton);
|
||||
this.httpClient = this.injector.get(HttpClient);
|
||||
let authService = this.injector.get(AuthorizationService);
|
||||
this.onClickFunction = () => {
|
||||
if (!authService.hasRole('security_administrator')) {
|
||||
return;
|
||||
}
|
||||
let jsonObj = this.collectData();
|
||||
|
||||
switch (this.action) {
|
||||
case AccountAction.CREATE:
|
||||
this.doRequest("user/create", jsonObj);
|
||||
break;
|
||||
case AccountAction.EDIT:
|
||||
this.doRequest("user/edit", jsonObj);
|
||||
break;
|
||||
case AccountAction.DEACTIVATE:
|
||||
this.doRequest("user/deactivate", jsonObj);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private collectData(): any {
|
||||
let jsonObj = {};
|
||||
let fields: FormField[] = this.button.form.getScriptsInChildren(FormField);
|
||||
|
||||
for (let field of fields) {
|
||||
jsonObj[`${field.name}`] = field.getValue();
|
||||
}
|
||||
return jsonObj;
|
||||
}
|
||||
|
||||
private doRequest(url: string, jsonObj: any): void {
|
||||
this.httpClient.post(url, jsonObj).toPromise()
|
||||
.catch(() => {
|
||||
//TODO change status
|
||||
});
|
||||
}
|
||||
|
||||
bindEvents() {
|
||||
super.bindEvents();
|
||||
this.button.addClickListener(this.onClickFunction);
|
||||
}
|
||||
|
||||
unbindEvents() {
|
||||
super.unbindEvents();
|
||||
this.button.removeClickListener(this.onClickFunction);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
export enum AccountAction {
|
||||
CREATE = "CREATE",
|
||||
EDIT = "EDIT",
|
||||
DEACTIVATE = "DEACTIVATE"
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
import {
|
||||
AnalyticalScope,
|
||||
Autocomplete,
|
||||
Behavior,
|
||||
Control,
|
||||
GridV2,
|
||||
NotNull
|
||||
} from "@webbpm/base-package";
|
||||
|
||||
@AnalyticalScope(Control)
|
||||
export class FormField extends Behavior {
|
||||
|
||||
@NotNull()
|
||||
public name: string;
|
||||
|
||||
public gridValue: boolean = false;
|
||||
@NotNull("gridValue == true")
|
||||
public columnId: string;
|
||||
|
||||
public getValue(): any {
|
||||
if (this.gridValue) {
|
||||
let grid = this.getScript(GridV2);
|
||||
return grid.getAllRows().map(rowData => rowData[this.columnId])
|
||||
}
|
||||
|
||||
return this.context instanceof Autocomplete
|
||||
? this.getScript(Autocomplete).getBusinessId()
|
||||
: this.getScript('component.ControlWithValue').getValueForForm();
|
||||
}
|
||||
}
|
||||
10
pom.xml
10
pom.xml
|
|
@ -286,6 +286,16 @@
|
|||
<version>${webbpm-platform.version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.validation</groupId>
|
||||
<artifactId>validation-api</artifactId>
|
||||
<version>2.0.1.Final</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate.validator</groupId>
|
||||
<artifactId>hibernate-validator</artifactId>
|
||||
<version>9.0.0.CR1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
<repositories>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue