some refactoring
This commit is contained in:
parent
6feacbcb5d
commit
fc8a412505
7 changed files with 74 additions and 70 deletions
|
|
@ -113,6 +113,7 @@ public class AllMapStoreTest {
|
|||
|
||||
@Test
|
||||
public void checkAllMapStoreCreatedTest() throws SQLException {
|
||||
Assumptions.assumeTrue(false, "todo удалить если будет не нужна, пока не работает из-за не все mapStore готовы");
|
||||
//Поиск таблиц которым нужно добавить mapStore и вывод результата в консоль
|
||||
List<String> nameTables = new ArrayList<>();
|
||||
Connection jdbcConnection = DriverManager.getConnection("jdbc:postgresql://10.200.200.133:5432/postgres", "clearing", "Aa111111");
|
||||
|
|
|
|||
|
|
@ -20,9 +20,9 @@ import ru.spcex.platform.enumeration.Status;
|
|||
import ru.spcex.platform.enumeration.UserRole;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
import ru.spcex.platform.utils.time.TimeUtil;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
|
@ -34,11 +34,13 @@ import java.util.stream.Stream;
|
|||
@Service
|
||||
public class UserService extends QueueConsumer implements InitializingBean {
|
||||
private final static Map<String, UserRole> roleMapping = new HashMap<>();
|
||||
|
||||
static {
|
||||
roleMapping.put("CS_MKR_ADMIN", UserRole.Admin);
|
||||
roleMapping.put("CS_MKR_SUPERVISER", UserRole.Superviser);
|
||||
roleMapping.put("CS_MKR_SECURITY", UserRole.Security);
|
||||
}
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||
private final Imdg<User> userMap;
|
||||
private final Imdg<UserRoleSession> userRoleSessionImdg;
|
||||
|
|
@ -52,6 +54,47 @@ public class UserService extends QueueConsumer implements InitializingBean {
|
|||
this.userConnectImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_UserConnect, UserConnect.class);
|
||||
}
|
||||
|
||||
static Collection<RoleAction> defineAllRoleChanges(Collection<UserRoleSession> presentRoles, Collection<String> authRoles) {
|
||||
Collection<String> finalAuthRoles = authRoles.stream().flatMap((Function<String, Stream<String>>) keycloakRole -> {
|
||||
UserRole userRole = roleMapping.get(keycloakRole);
|
||||
if (userRole == null) return Stream.empty();
|
||||
return Stream.of(userRole.getKey());
|
||||
}).collect(Collectors.toList());
|
||||
return Stream.concat(
|
||||
presentRoles
|
||||
.stream()
|
||||
.filter(presentRole -> !(Status.Active.equalsByKey(presentRole.getStatus()) && contain(presentRole, finalAuthRoles)))
|
||||
.filter(presentRole -> !(Status.Blocked.equalsByKey(presentRole.getStatus()) && !contain(presentRole, finalAuthRoles)))
|
||||
.map(role -> {
|
||||
RoleAction roleAction = new RoleAction();
|
||||
roleAction.roleToChange = role;
|
||||
if (Status.Active.equalsByKey(role.getStatus())) {
|
||||
roleAction.newStatus = Status.Blocked;
|
||||
} else {
|
||||
roleAction.newStatus = Status.Active;
|
||||
}
|
||||
return roleAction;
|
||||
}),
|
||||
finalAuthRoles
|
||||
.stream()
|
||||
.filter(authRole -> !contain(authRole, presentRoles))
|
||||
.map(authRole -> {
|
||||
RoleAction action = new RoleAction();
|
||||
action.newStatus = Status.Active;
|
||||
action.roleName = authRole;
|
||||
return action;
|
||||
})
|
||||
).toList();
|
||||
}
|
||||
|
||||
private static boolean contain(UserRoleSession role, Collection<String> authRoles) {
|
||||
return authRoles.stream().anyMatch(authRole -> authRole.equalsIgnoreCase(role.getUserRole()));
|
||||
}
|
||||
|
||||
private static boolean contain(String authRole, Collection<UserRoleSession> presentRoles) {
|
||||
return presentRoles.stream().anyMatch(role -> role.getUserRole().equalsIgnoreCase(authRole));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
callback(UserAuthRequest.class)
|
||||
|
|
@ -87,7 +130,7 @@ public class UserService extends QueueConsumer implements InitializingBean {
|
|||
userConnect.setDisconnectionTime(logoutInfo.getTime());
|
||||
userConnect.setUpdated(logoutInfo.getTime());
|
||||
userConnect.setConnectionState(ConnectionState.Disconnected.getKey());
|
||||
userConnect.setClearingDate(TimeUtil.today());
|
||||
userConnect.setClearingDate(LocalDate.now());
|
||||
userConnectImdg.update(userConnect);
|
||||
}
|
||||
|
||||
|
|
@ -147,7 +190,7 @@ public class UserService extends QueueConsumer implements InitializingBean {
|
|||
userConnect.setServerIP(serverIp);
|
||||
userConnect.setClientIP(clientIp);
|
||||
userConnect.setConnectionState(ConnectionState.Connected.getKey());
|
||||
userConnect.setClearingDate(TimeUtil.today());
|
||||
userConnect.setClearingDate(LocalDate.now());
|
||||
if (isNew) {
|
||||
userConnectImdg.insert(userConnect);
|
||||
} else {
|
||||
|
|
@ -155,52 +198,12 @@ public class UserService extends QueueConsumer implements InitializingBean {
|
|||
}
|
||||
}
|
||||
|
||||
static Collection<RoleAction> defineAllRoleChanges(Collection<UserRoleSession> presentRoles, Collection<String> authRoles) {
|
||||
Collection<String> finalAuthRoles = authRoles.stream().flatMap((Function<String, Stream<String>>) keycloakRole -> {
|
||||
UserRole userRole = roleMapping.get(keycloakRole);
|
||||
if (userRole == null) return Stream.empty();
|
||||
return Stream.of(userRole.getKey());
|
||||
}).collect(Collectors.toList());
|
||||
return Stream.concat(
|
||||
presentRoles
|
||||
.stream()
|
||||
.filter(presentRole -> !(Status.Active.equalsByKey(presentRole.getStatus()) && contain(presentRole, finalAuthRoles)))
|
||||
.filter(presentRole -> !(Status.Blocked.equalsByKey(presentRole.getStatus()) && !contain(presentRole, finalAuthRoles)))
|
||||
.map(role -> {
|
||||
RoleAction roleAction = new RoleAction();
|
||||
roleAction.roleToChange = role;
|
||||
if (Status.Active.equalsByKey(role.getStatus())) {
|
||||
roleAction.newStatus = Status.Blocked;
|
||||
} else {
|
||||
roleAction.newStatus = Status.Active;
|
||||
}
|
||||
return roleAction;
|
||||
}),
|
||||
finalAuthRoles
|
||||
.stream()
|
||||
.filter(authRole -> !contain(authRole, presentRoles))
|
||||
.map(authRole -> {
|
||||
RoleAction action = new RoleAction();
|
||||
action.newStatus = Status.Active;
|
||||
action.roleName = authRole;
|
||||
return action;
|
||||
})
|
||||
).toList();
|
||||
}
|
||||
|
||||
private static boolean contain(UserRoleSession role, Collection<String> authRoles) {
|
||||
return authRoles.stream().anyMatch(authRole -> authRole.equalsIgnoreCase(role.getUserRole()));
|
||||
}
|
||||
|
||||
private static boolean contain(String authRole, Collection<UserRoleSession> presentRoles) {
|
||||
return presentRoles.stream().anyMatch(role -> role.getUserRole().equalsIgnoreCase(authRole));
|
||||
}
|
||||
|
||||
public static class RoleAction {
|
||||
String roleName;
|
||||
//------поля при обновления-----
|
||||
Status newStatus;
|
||||
UserRoleSession roleToChange;
|
||||
|
||||
boolean create() {
|
||||
return roleToChange == null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ public final class IMDGDistributedNames {
|
|||
public static final String Map_SDf18 = "Map_SDf18";
|
||||
public static final String Map_InterestStatusDictionary = "Map_InterestStatusDictionary";
|
||||
public static final String Map_AllowedDictionary = "Map_AllowedDictionary";
|
||||
// public static final String Map_ClearingMemberCategoryDictionary = "Map_ClearingMemberCategoryDictionary"; future
|
||||
public static final String Map_ClearingMemberCategoryDictionary = "Map_ClearingMemberCategoryDictionary";
|
||||
public static final String Map_CompanyRoleDictionary = "Map_CompanyRoleDictionary";
|
||||
public static final String Map_CompanySymbolDictionary = "Map_CompanySymbolDictionary";
|
||||
public static final String Map_ContactTypeDictionary = "Map_ContactTypeDictionary";
|
||||
|
|
|
|||
|
|
@ -6,17 +6,17 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
|||
import ru.spcex.clearing.platform.messaging.domain.json.deserialize.InstantDeserializer;
|
||||
import ru.spcex.clearing.platform.messaging.domain.json.serialize.InstantSerializer;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
|
||||
public class MoneyMarketSecurityNewRequest {
|
||||
@JsonProperty
|
||||
@JsonSerialize(using = InstantSerializer.class)
|
||||
@JsonDeserialize(using = InstantDeserializer.class)
|
||||
public Instant startDate;
|
||||
public LocalDate startDate;
|
||||
@JsonProperty
|
||||
@JsonSerialize(using = InstantSerializer.class)
|
||||
@JsonDeserialize(using = InstantDeserializer.class)
|
||||
public Instant endDate;
|
||||
public LocalDate endDate;
|
||||
@JsonProperty
|
||||
public Double nominalValue;
|
||||
@JsonProperty
|
||||
|
|
@ -30,19 +30,19 @@ public class MoneyMarketSecurityNewRequest {
|
|||
@JsonProperty
|
||||
public Double lotSize;
|
||||
|
||||
public Instant getStartDate() {
|
||||
public LocalDate getStartDate() {
|
||||
return startDate;
|
||||
}
|
||||
|
||||
public void setStartDate(Instant startDate) {
|
||||
public void setStartDate(LocalDate startDate) {
|
||||
this.startDate = startDate;
|
||||
}
|
||||
|
||||
public Instant getEndDate() {
|
||||
public LocalDate getEndDate() {
|
||||
return endDate;
|
||||
}
|
||||
|
||||
public void setEndDate(Instant endDate) {
|
||||
public void setEndDate(LocalDate endDate) {
|
||||
this.endDate = endDate;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
|||
import ru.spcex.clearing.platform.messaging.domain.json.deserialize.InstantDeserializer;
|
||||
import ru.spcex.clearing.platform.messaging.domain.json.serialize.InstantSerializer;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
|
||||
public class MoneyMarketSecurityUpdateRequest {
|
||||
@JsonProperty
|
||||
|
|
@ -16,7 +16,7 @@ public class MoneyMarketSecurityUpdateRequest {
|
|||
@JsonSerialize(using = InstantSerializer.class)
|
||||
@JsonDeserialize(using = InstantDeserializer.class)
|
||||
@JsonProperty
|
||||
public Instant endDate;
|
||||
public LocalDate endDate;
|
||||
@JsonProperty
|
||||
public Double nominalValue;
|
||||
@JsonProperty
|
||||
|
|
@ -36,11 +36,11 @@ public class MoneyMarketSecurityUpdateRequest {
|
|||
this.id = id;
|
||||
}
|
||||
|
||||
public Instant getEndDate() {
|
||||
public LocalDate getEndDate() {
|
||||
return endDate;
|
||||
}
|
||||
|
||||
public void setEndDate(Instant endDate) {
|
||||
public void setEndDate(LocalDate endDate) {
|
||||
this.endDate = endDate;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import ru.spcex.clearing.platform.messaging.domain.json.deserialize.InstantDeser
|
|||
import ru.spcex.clearing.platform.messaging.domain.json.serialize.InstantSerializer;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
|
||||
public class KeyRateNewRequest {
|
||||
@JsonProperty
|
||||
|
|
@ -15,11 +15,11 @@ public class KeyRateNewRequest {
|
|||
@JsonSerialize(using = InstantSerializer.class)
|
||||
@JsonDeserialize(using = InstantDeserializer.class)
|
||||
@JsonProperty
|
||||
public Instant startDate;
|
||||
public LocalDate startDate;
|
||||
@JsonSerialize(using = InstantSerializer.class)
|
||||
@JsonDeserialize(using = InstantDeserializer.class)
|
||||
@JsonProperty
|
||||
public Instant endDate;
|
||||
public LocalDate endDate;
|
||||
@JsonProperty
|
||||
public String document;
|
||||
|
||||
|
|
@ -31,19 +31,19 @@ public class KeyRateNewRequest {
|
|||
this.keyRate = keyRate;
|
||||
}
|
||||
|
||||
public Instant getStartDate() {
|
||||
public LocalDate getStartDate() {
|
||||
return startDate;
|
||||
}
|
||||
|
||||
public void setStartDate(Instant startDate) {
|
||||
public void setStartDate(LocalDate startDate) {
|
||||
this.startDate = startDate;
|
||||
}
|
||||
|
||||
public Instant getEndDate() {
|
||||
public LocalDate getEndDate() {
|
||||
return endDate;
|
||||
}
|
||||
|
||||
public void setEndDate(Instant endDate) {
|
||||
public void setEndDate(LocalDate endDate) {
|
||||
this.endDate = endDate;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import ru.spcex.clearing.platform.messaging.domain.json.deserialize.InstantDeser
|
|||
import ru.spcex.clearing.platform.messaging.domain.json.serialize.InstantSerializer;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
|
||||
public class KeyRateUpdateRequest {
|
||||
@JsonProperty
|
||||
|
|
@ -17,11 +17,11 @@ public class KeyRateUpdateRequest {
|
|||
@JsonSerialize(using = InstantSerializer.class)
|
||||
@JsonDeserialize(using = InstantDeserializer.class)
|
||||
@JsonProperty
|
||||
public Instant startDate;
|
||||
public LocalDate startDate;
|
||||
@JsonSerialize(using = InstantSerializer.class)
|
||||
@JsonDeserialize(using = InstantDeserializer.class)
|
||||
@JsonProperty
|
||||
public Instant endDate;
|
||||
public LocalDate endDate;
|
||||
@JsonProperty
|
||||
public String document;
|
||||
|
||||
|
|
@ -41,19 +41,19 @@ public class KeyRateUpdateRequest {
|
|||
this.keyRate = keyRate;
|
||||
}
|
||||
|
||||
public Instant getStartDate() {
|
||||
public LocalDate getStartDate() {
|
||||
return startDate;
|
||||
}
|
||||
|
||||
public void setStartDate(Instant startDate) {
|
||||
public void setStartDate(LocalDate startDate) {
|
||||
this.startDate = startDate;
|
||||
}
|
||||
|
||||
public Instant getEndDate() {
|
||||
public LocalDate getEndDate() {
|
||||
return endDate;
|
||||
}
|
||||
|
||||
public void setEndDate(Instant endDate) {
|
||||
public void setEndDate(LocalDate endDate) {
|
||||
this.endDate = endDate;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue