LP: added package registration
This commit is contained in:
parent
15c651debd
commit
6767a8c204
4 changed files with 33 additions and 30 deletions
|
|
@ -1,11 +1,8 @@
|
||||||
package ru.nbch.credit_tracker.entities.app;
|
package ru.nbch.credit_tracker.entities.app;
|
||||||
|
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
|
|
@ -16,6 +13,7 @@ public class UserPackage {
|
||||||
private Long id;
|
private Long id;
|
||||||
private String userId;
|
private String userId;
|
||||||
private String packageName;
|
private String packageName;
|
||||||
|
private Integer subjectType;
|
||||||
private String signalTypes;
|
private String signalTypes;
|
||||||
private LocalDateTime createdAt;
|
private LocalDateTime createdAt;
|
||||||
private String status;
|
private String status;
|
||||||
|
|
|
||||||
|
|
@ -106,7 +106,7 @@ public class SignalFacade {
|
||||||
validationResult = monitoringRequestValidator.readAndValidateMonitoringRequest(tmpReqFilePath);
|
validationResult = monitoringRequestValidator.readAndValidateMonitoringRequest(tmpReqFilePath);
|
||||||
if (!validationResult.getValidationErrors().isEmpty()) {
|
if (!validationResult.getValidationErrors().isEmpty()) {
|
||||||
MonitoringValidationError firstError = validationResult.getValidationErrors().getFirst();
|
MonitoringValidationError firstError = validationResult.getValidationErrors().getFirst();
|
||||||
userPackageService.rejectPackage(validationResult.getUserId(), validationResult.getPackageName(), validationResult.getSignalTypes());
|
userPackageService.rejectPackage(validationResult.getUserId(), validationResult.getPackageName(), validationResult.getSubjectType(), validationResult.getSignalTypes());
|
||||||
Files.delete(tmpReqFilePath);
|
Files.delete(tmpReqFilePath);
|
||||||
throw firstError.getSignalException();
|
throw firstError.getSignalException();
|
||||||
}
|
}
|
||||||
|
|
@ -123,6 +123,7 @@ public class SignalFacade {
|
||||||
}
|
}
|
||||||
|
|
||||||
String packageName = validationResult.getPackageName();
|
String packageName = validationResult.getPackageName();
|
||||||
|
Integer subjectType = validationResult.getSubjectType();
|
||||||
String userId = validationResult.getUserId();
|
String userId = validationResult.getUserId();
|
||||||
String password = validationResult.getPassword();
|
String password = validationResult.getPassword();
|
||||||
List<Integer> signalTypes = validationResult.getSignalTypes();
|
List<Integer> signalTypes = validationResult.getSignalTypes();
|
||||||
|
|
@ -137,17 +138,17 @@ public class SignalFacade {
|
||||||
// проверка авторизации
|
// проверка авторизации
|
||||||
AuthorizationService.AuthResult authResult = authorizationService.findAuthInfo(userId, password);
|
AuthorizationService.AuthResult authResult = authorizationService.findAuthInfo(userId, password);
|
||||||
if (!authResult.isSuccess()) {
|
if (!authResult.isSuccess()) {
|
||||||
userPackageService.rejectPackage(userId, packageName, signalTypes);
|
userPackageService.rejectPackage(userId, packageName, subjectType, signalTypes);
|
||||||
throw clientExcp(authResult.getError(), XmlErrorFormat.MonitoringError);
|
throw clientExcp(authResult.getError(), XmlErrorFormat.MonitoringError);
|
||||||
}
|
}
|
||||||
|
|
||||||
// проверка на уникальность пакета
|
// проверка на уникальность пакета
|
||||||
if (userPackageService.isPackageNotUnique(userId, packageName)) {
|
if (userPackageService.isPackageNotUnique(userId, packageName)) {
|
||||||
userPackageService.rejectPackage(userId, packageName, signalTypes);
|
userPackageService.rejectPackage(userId, packageName, subjectType, signalTypes);
|
||||||
throw clientExcp(SignalError.ERROR_007, XmlErrorFormat.MonitoringError);
|
throw clientExcp(SignalError.ERROR_007, XmlErrorFormat.MonitoringError);
|
||||||
}
|
}
|
||||||
|
|
||||||
Long packageId = userPackageService.registerPackage(userId, packageName, signalTypes);
|
Long packageId = userPackageService.registerPackage(userId, packageName, subjectType, signalTypes);
|
||||||
LogUtil.addMdcLogKey("%s %d".formatted(packageName, packageId));
|
LogUtil.addMdcLogKey("%s %d".formatted(packageName, packageId));
|
||||||
log.info("Package registered. PackageId {}. Status: {}", packageId, Status.ACCEPTED.name());
|
log.info("Package registered. PackageId {}. Status: {}", packageId, Status.ACCEPTED.name());
|
||||||
Pipeline pipeline = pipelinePackageManager.build(new SetupParam(packageId, parsedFilePath, PipelineMode.DEFAULT));
|
Pipeline pipeline = pipelinePackageManager.build(new SetupParam(packageId, parsedFilePath, PipelineMode.DEFAULT));
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,16 @@
|
||||||
package ru.nbch.credit_tracker.service;
|
package ru.nbch.credit_tracker.service;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import ru.nbch.credit_tracker.entities.app.UserPackage;
|
||||||
|
import ru.nbch.credit_tracker.enums.Status;
|
||||||
|
import ru.nbch.credit_tracker.mapper.signal.UserPackageMapper;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import ru.nbch.credit_tracker.entities.app.UserPackage;
|
|
||||||
import ru.nbch.credit_tracker.enums.Status;
|
|
||||||
import ru.nbch.credit_tracker.mapper.signal.UserPackageMapper;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
|
|
@ -24,34 +25,36 @@ public class UserPackageService {
|
||||||
return userPackageMapper.isPackageNotUnique(userId.substring(0, 6), packageName);
|
return userPackageMapper.isPackageNotUnique(userId.substring(0, 6), packageName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long registerPackage(String userId, String packageName, List<Integer> signalTypes) {
|
public Long registerPackage(String userId, String packageName, Integer subjectType, List<Integer> signalTypes) {
|
||||||
signalTypes.sort(Comparator.naturalOrder());
|
signalTypes.sort(Comparator.naturalOrder());
|
||||||
String types = "1,2";
|
String types = "1,2";
|
||||||
if (!signalTypes.isEmpty()) {
|
if (!signalTypes.isEmpty()) {
|
||||||
types = signalTypes.stream().map(Object::toString).distinct().collect(Collectors.joining(","));
|
types = signalTypes.stream().map(Object::toString).distinct().collect(Collectors.joining(","));
|
||||||
}
|
}
|
||||||
UserPackage userPackage = UserPackage.builder()
|
UserPackage userPackage = UserPackage.builder()
|
||||||
.userId(userId)
|
.userId(userId)
|
||||||
.packageName(packageName)
|
.packageName(packageName)
|
||||||
.signalTypes(types)
|
.subjectType(subjectType)
|
||||||
.createdAt(LocalDateTime.now())
|
.signalTypes(types)
|
||||||
.status(Status.ACCEPTED.name())
|
.createdAt(LocalDateTime.now())
|
||||||
.build();
|
.status(Status.ACCEPTED.name())
|
||||||
|
.build();
|
||||||
return userPackageMapper.insertPackage(userPackage);
|
return userPackageMapper.insertPackage(userPackage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void rejectPackage(String userId, String packageName, List<Integer> signalTypes) {
|
public void rejectPackage(String userId, String packageName, Integer subjectType, List<Integer> signalTypes) {
|
||||||
String types = "1,2";
|
String types = "1,2";
|
||||||
if (!signalTypes.isEmpty()) {
|
if (!signalTypes.isEmpty()) {
|
||||||
types = signalTypes.stream().map(Object::toString).distinct().collect(Collectors.joining(","));
|
types = signalTypes.stream().map(Object::toString).distinct().collect(Collectors.joining(","));
|
||||||
}
|
}
|
||||||
UserPackage userPackage = UserPackage.builder()
|
UserPackage userPackage = UserPackage.builder()
|
||||||
.userId(userId)
|
.userId(userId)
|
||||||
.packageName(packageName)
|
.packageName(packageName)
|
||||||
.signalTypes(types)
|
.subjectType(subjectType)
|
||||||
.createdAt(LocalDateTime.now())
|
.signalTypes(types)
|
||||||
.status(Status.REJECTED.name())
|
.createdAt(LocalDateTime.now())
|
||||||
.build();
|
.status(Status.REJECTED.name())
|
||||||
|
.build();
|
||||||
userPackageMapper.insertPackage(userPackage);
|
userPackageMapper.insertPackage(userPackage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -66,6 +69,7 @@ public class UserPackageService {
|
||||||
public void setFidChanged(List<Long> id) {
|
public void setFidChanged(List<Long> id) {
|
||||||
userPackageMapper.setFidChanged(id);
|
userPackageMapper.setFidChanged(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<UserPackage> findAllPackages(String userId) {
|
public List<UserPackage> findAllPackages(String userId) {
|
||||||
return userPackageMapper.findAllPackagesByUserId(userId.substring(0, 6));
|
return userPackageMapper.findAllPackagesByUserId(userId.substring(0, 6));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -63,8 +63,8 @@
|
||||||
|
|
||||||
<select id="insertPackage" resultType="java.lang.Long"
|
<select id="insertPackage" resultType="java.lang.Long"
|
||||||
parameterType="ru.nbch.credit_tracker.entities.app.UserPackage">
|
parameterType="ru.nbch.credit_tracker.entities.app.UserPackage">
|
||||||
INSERT INTO signals_user_packages (membercode, package_name, signal_types, created_at, status, external_package_name)
|
INSERT INTO signals_user_packages (membercode, package_name, subject_type, signal_types, created_at, status, external_package_name)
|
||||||
values (#{userPackage.userId}, #{userPackage.packageName}, #{userPackage.signalTypes}, #{userPackage.createdAt}, #{userPackage.status}, concat(substring(#{userPackage.userId}, 1, 6), '_', #{userPackage.packageName})) RETURNING id
|
values (#{userPackage.userId}, #{userPackage.packageName}, #{userPackage.subjectType}, #{userPackage.signalTypes}, #{userPackage.createdAt}, #{userPackage.status}, concat(substring(#{userPackage.userId}, 1, 6), '_', #{userPackage.packageName})) RETURNING id
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<update id="updatePackageStatus">
|
<update id="updatePackageStatus">
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue