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;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
|
|
@ -16,6 +13,7 @@ public class UserPackage {
|
|||
private Long id;
|
||||
private String userId;
|
||||
private String packageName;
|
||||
private Integer subjectType;
|
||||
private String signalTypes;
|
||||
private LocalDateTime createdAt;
|
||||
private String status;
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ public class SignalFacade {
|
|||
validationResult = monitoringRequestValidator.readAndValidateMonitoringRequest(tmpReqFilePath);
|
||||
if (!validationResult.getValidationErrors().isEmpty()) {
|
||||
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);
|
||||
throw firstError.getSignalException();
|
||||
}
|
||||
|
|
@ -123,6 +123,7 @@ public class SignalFacade {
|
|||
}
|
||||
|
||||
String packageName = validationResult.getPackageName();
|
||||
Integer subjectType = validationResult.getSubjectType();
|
||||
String userId = validationResult.getUserId();
|
||||
String password = validationResult.getPassword();
|
||||
List<Integer> signalTypes = validationResult.getSignalTypes();
|
||||
|
|
@ -137,17 +138,17 @@ public class SignalFacade {
|
|||
// проверка авторизации
|
||||
AuthorizationService.AuthResult authResult = authorizationService.findAuthInfo(userId, password);
|
||||
if (!authResult.isSuccess()) {
|
||||
userPackageService.rejectPackage(userId, packageName, signalTypes);
|
||||
userPackageService.rejectPackage(userId, packageName, subjectType, signalTypes);
|
||||
throw clientExcp(authResult.getError(), XmlErrorFormat.MonitoringError);
|
||||
}
|
||||
|
||||
// проверка на уникальность пакета
|
||||
if (userPackageService.isPackageNotUnique(userId, packageName)) {
|
||||
userPackageService.rejectPackage(userId, packageName, signalTypes);
|
||||
userPackageService.rejectPackage(userId, packageName, subjectType, signalTypes);
|
||||
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));
|
||||
log.info("Package registered. PackageId {}. Status: {}", packageId, Status.ACCEPTED.name());
|
||||
Pipeline pipeline = pipelinePackageManager.build(new SetupParam(packageId, parsedFilePath, PipelineMode.DEFAULT));
|
||||
|
|
|
|||
|
|
@ -1,15 +1,16 @@
|
|||
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.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
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
|
||||
@Service
|
||||
|
|
@ -24,7 +25,7 @@ public class UserPackageService {
|
|||
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());
|
||||
String types = "1,2";
|
||||
if (!signalTypes.isEmpty()) {
|
||||
|
|
@ -33,6 +34,7 @@ public class UserPackageService {
|
|||
UserPackage userPackage = UserPackage.builder()
|
||||
.userId(userId)
|
||||
.packageName(packageName)
|
||||
.subjectType(subjectType)
|
||||
.signalTypes(types)
|
||||
.createdAt(LocalDateTime.now())
|
||||
.status(Status.ACCEPTED.name())
|
||||
|
|
@ -40,7 +42,7 @@ public class UserPackageService {
|
|||
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";
|
||||
if (!signalTypes.isEmpty()) {
|
||||
types = signalTypes.stream().map(Object::toString).distinct().collect(Collectors.joining(","));
|
||||
|
|
@ -48,6 +50,7 @@ public class UserPackageService {
|
|||
UserPackage userPackage = UserPackage.builder()
|
||||
.userId(userId)
|
||||
.packageName(packageName)
|
||||
.subjectType(subjectType)
|
||||
.signalTypes(types)
|
||||
.createdAt(LocalDateTime.now())
|
||||
.status(Status.REJECTED.name())
|
||||
|
|
@ -66,6 +69,7 @@ public class UserPackageService {
|
|||
public void setFidChanged(List<Long> id) {
|
||||
userPackageMapper.setFidChanged(id);
|
||||
}
|
||||
|
||||
public List<UserPackage> findAllPackages(String userId) {
|
||||
return userPackageMapper.findAllPackagesByUserId(userId.substring(0, 6));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,8 +63,8 @@
|
|||
|
||||
<select id="insertPackage" resultType="java.lang.Long"
|
||||
parameterType="ru.nbch.credit_tracker.entities.app.UserPackage">
|
||||
INSERT INTO signals_user_packages (membercode, package_name, 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
|
||||
INSERT INTO signals_user_packages (membercode, package_name, subject_type, signal_types, created_at, status, external_package_name)
|
||||
values (#{userPackage.userId}, #{userPackage.packageName}, #{userPackage.subjectType}, #{userPackage.signalTypes}, #{userPackage.createdAt}, #{userPackage.status}, concat(substring(#{userPackage.userId}, 1, 6), '_', #{userPackage.packageName})) RETURNING id
|
||||
</select>
|
||||
|
||||
<update id="updatePackageStatus">
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue