Merge branch 'feature/SUPPORT-9422_fix' into develop
This commit is contained in:
commit
70a071bbf1
16 changed files with 114 additions and 28 deletions
|
|
@ -4,11 +4,15 @@ import java.sql.SQLException;
|
|||
import java.sql.Statement;
|
||||
import java.time.Duration;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||
import ervu_business_metrics.deserializer.DataWrapperDeserializer;
|
||||
import ervu_business_metrics.deserializer.ReferenceEntityDeserializer;
|
||||
import ervu_business_metrics.model.DataWrapper;
|
||||
import ervu_business_metrics.model.ReferenceEntity;
|
||||
import exception.AppInitializeException;
|
||||
import liquibase.integration.spring.SpringLiquibase;
|
||||
|
|
@ -131,7 +135,7 @@ public class AppConfig {
|
|||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
SimpleModule module = new SimpleModule();
|
||||
module.addDeserializer(ReferenceEntity.class, new ReferenceEntityDeserializer());
|
||||
customDeserializers().forEach(module::addDeserializer);
|
||||
|
||||
objectMapper.registerModule(module);
|
||||
return objectMapper;
|
||||
|
|
@ -142,4 +146,10 @@ public class AppConfig {
|
|||
return new RestTemplate();
|
||||
}
|
||||
|
||||
private Map<Class, JsonDeserializer> customDeserializers() {
|
||||
return Map.of(
|
||||
ReferenceEntity.class, new ReferenceEntityDeserializer(),
|
||||
DataWrapper.class, new DataWrapperDeserializer()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package ervu_business_metrics.dao;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
|
@ -66,11 +67,11 @@ public abstract class AbstractDataDao<T extends UpdatableRecord<T>> {
|
|||
.fetch(selectField);
|
||||
}
|
||||
|
||||
protected <V, F> void setFieldByField(Field<V> targetField, V value, Field<F> whereField,
|
||||
F whereValue) {
|
||||
protected <V, F> void setFieldWhereIn(Field<V> targetField, V value, Field<F> whereField,
|
||||
Collection<F> whereValues) {
|
||||
dsl.update(getTable())
|
||||
.set(targetField, value)
|
||||
.where(whereField.eq(whereValue))
|
||||
.where(whereField.in(whereValues))
|
||||
.execute();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,8 +26,8 @@ public class AccountDataDao extends AbstractDataDao<AccountRecord> {
|
|||
return getValuesByField(Tables.ACCOUNT.ID, Tables.ACCOUNT.PERSON_ID, personId);
|
||||
}
|
||||
|
||||
public void setActiveStatus(String id, boolean active) {
|
||||
setFieldByField(Tables.ACCOUNT.ACTIVE, active, Tables.ACCOUNT.ID, id);
|
||||
public void setActiveStatus(List<String> ids, boolean active) {
|
||||
setFieldWhereIn(Tables.ACCOUNT.ACTIVE, active, Tables.ACCOUNT.ID, ids);
|
||||
}
|
||||
|
||||
public void deleteByIds(List<String> ids) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
package ervu_business_metrics.dao;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import ervu_business_metrics.config.KafkaEnabledCondition;
|
||||
import org.jooq.DSLContext;
|
||||
import org.jooq.Table;
|
||||
|
|
@ -20,8 +22,8 @@ public class DomainDataDao extends AbstractDataDao<DomainRecord> {
|
|||
super(dsl);
|
||||
}
|
||||
|
||||
public void setActiveStatus(String id , boolean active){
|
||||
setFieldByField(Tables.DOMAIN.ACTIVE, active, Tables.DOMAIN.ID, id);
|
||||
public void setActiveStatus(List<String> ids , boolean active){
|
||||
setFieldWhereIn(Tables.DOMAIN.ACTIVE, active, Tables.DOMAIN.ID, ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package ervu_business_metrics.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import ervu_business_metrics.config.KafkaEnabledCondition;
|
||||
import org.jooq.DSLContext;
|
||||
import org.jooq.Table;
|
||||
|
|
@ -19,8 +21,8 @@ public class PersonDataDao extends AbstractDataDao<PersonRecord> {
|
|||
super(dsl);
|
||||
}
|
||||
|
||||
public void setActiveStatus(String id , boolean active){
|
||||
setFieldByField(Tables.PERSON.ACTIVE, active, Tables.PERSON.ID, id);
|
||||
public void setActiveStatus(List<String> ids , boolean active){
|
||||
setFieldWhereIn(Tables.PERSON.ACTIVE, active, Tables.PERSON.ID, ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package ervu_business_metrics.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import ervu_business_metrics.config.KafkaEnabledCondition;
|
||||
import org.jooq.DSLContext;
|
||||
import org.jooq.Table;
|
||||
|
|
@ -19,8 +21,8 @@ public class RoleDataDao extends AbstractDataDao<RoleRecord> {
|
|||
super(dsl);
|
||||
}
|
||||
|
||||
public void setActiveStatus(String id , boolean active){
|
||||
setFieldByField(Tables.ROLE.ACTIVE, active, Tables.ROLE.ID, id);
|
||||
public void setActiveStatus(List<String> ids , boolean active){
|
||||
setFieldWhereIn(Tables.ROLE.ACTIVE, active, Tables.ROLE.ID, ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -0,0 +1,39 @@
|
|||
package ervu_business_metrics.deserializer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.core.JacksonException;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import ervu_business_metrics.model.DataWrapper;
|
||||
|
||||
/**
|
||||
* @author Adel Kalimullin
|
||||
*/
|
||||
public class DataWrapperDeserializer extends JsonDeserializer<DataWrapper> {
|
||||
|
||||
@Override
|
||||
public DataWrapper deserialize(JsonParser jsonParser,
|
||||
DeserializationContext deserializationContext) throws IOException, JacksonException {
|
||||
JsonNode node = jsonParser.readValueAsTree();
|
||||
if (node.isTextual()){
|
||||
return new DataWrapper(List.of(node.asText()));
|
||||
}
|
||||
else if (node.isArray()){
|
||||
List<String> values = new ArrayList<>();
|
||||
for (JsonNode element : node) {
|
||||
if (element.isTextual()) {
|
||||
values.add(element.asText());
|
||||
}
|
||||
}
|
||||
return new DataWrapper(values);
|
||||
}
|
||||
|
||||
return new DataWrapper(Collections.emptyList());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,8 @@
|
|||
package ervu_business_metrics.kafka.model;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import ervu_business_metrics.model.ReferenceEntity;
|
||||
import ervu_business_metrics.model.DataWrapper;
|
||||
|
||||
/**
|
||||
* @author Adel Kalimullin
|
||||
|
|
@ -9,13 +10,13 @@ import ervu_business_metrics.model.ReferenceEntity;
|
|||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class ChangeActiveMessage {
|
||||
private boolean success;
|
||||
private ReferenceEntity data;
|
||||
private DataWrapper data;
|
||||
|
||||
public ReferenceEntity getData() {
|
||||
public DataWrapper getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(ReferenceEntity data) {
|
||||
public void setData(DataWrapper data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
package ervu_business_metrics.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Adel Kalimullin
|
||||
*/
|
||||
public class DataWrapper {
|
||||
private final List<String> ids;
|
||||
|
||||
public DataWrapper(List<String> values) {
|
||||
this.ids = values;
|
||||
}
|
||||
|
||||
public List<String> getIds() {
|
||||
return ids;
|
||||
}
|
||||
}
|
||||
|
|
@ -23,6 +23,7 @@ import org.springframework.context.annotation.DependsOn;
|
|||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
|
|
@ -102,13 +103,15 @@ public class IdmDirectoriesService {
|
|||
ChangeActiveMessage.class
|
||||
);
|
||||
|
||||
if (changeActiveMessage.isSuccess() && changeActiveMessage.getData() != null) {
|
||||
if (changeActiveMessage.isSuccess() &&
|
||||
changeActiveMessage.getData() != null &&
|
||||
!CollectionUtils.isEmpty(changeActiveMessage.getData().getIds())) {
|
||||
DataProcessor<T, ?> processor = (DataProcessor<T, ?>) dataProcessors.get(entityClass);
|
||||
if (processor == null) {
|
||||
throw new IllegalStateException("No processor found for " + entityClass.getSimpleName());
|
||||
}
|
||||
|
||||
processor.changeActiveStatus(changeActiveMessage.getData().getId(), active);
|
||||
processor.changeActiveStatus(changeActiveMessage.getData().getIds(), active);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
|
|
|
|||
|
|
@ -1,12 +1,14 @@
|
|||
package ervu_business_metrics.service.processor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Adel Kalimullin
|
||||
*/
|
||||
public interface DataProcessor<T, R> {
|
||||
void upsertData(T data);
|
||||
|
||||
void changeActiveStatus(String id, boolean active);
|
||||
void changeActiveStatus(List<String> ids, boolean active);
|
||||
|
||||
Class<T> getType();
|
||||
|
||||
|
|
|
|||
|
|
@ -37,8 +37,8 @@ public class AccountDataProcessor implements DataProcessor<AccountData, AccountR
|
|||
}
|
||||
|
||||
@Override
|
||||
public void changeActiveStatus(String id, boolean active) {
|
||||
dao.setActiveStatus(id, active);
|
||||
public void changeActiveStatus(List<String> ids, boolean active) {
|
||||
dao.setActiveStatus(ids, active);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ public class AccountRoleDataProcessor
|
|||
}
|
||||
|
||||
@Override
|
||||
public void changeActiveStatus(String id, boolean active) {
|
||||
public void changeActiveStatus(List<String> ids, boolean active) {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package ervu_business_metrics.service.processor.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import ervu_business_metrics.config.KafkaEnabledCondition;
|
||||
import ervu_business_metrics.dao.DomainDataDao;
|
||||
import ervu_business_metrics.model.idm.DomainData;
|
||||
|
|
@ -27,8 +29,8 @@ public class DomainDataProcessor implements DataProcessor<DomainData, DomainReco
|
|||
}
|
||||
|
||||
@Override
|
||||
public void changeActiveStatus(String id, boolean active) {
|
||||
dao.setActiveStatus(id, active);
|
||||
public void changeActiveStatus(List<String> ids, boolean active) {
|
||||
dao.setActiveStatus(ids, active);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package ervu_business_metrics.service.processor.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import ervu_business_metrics.config.KafkaEnabledCondition;
|
||||
import ervu_business_metrics.dao.PersonDataDao;
|
||||
import ervu_business_metrics.model.idm.PersonData;
|
||||
|
|
@ -34,8 +36,8 @@ public class PersonDataProcessor implements DataProcessor<PersonData, PersonReco
|
|||
}
|
||||
|
||||
@Override
|
||||
public void changeActiveStatus(String id, boolean active) {
|
||||
dao.setActiveStatus(id, active);
|
||||
public void changeActiveStatus(List<String> ids, boolean active) {
|
||||
dao.setActiveStatus(ids, active);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
package ervu_business_metrics.service.processor.impl;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import ervu_business_metrics.config.KafkaEnabledCondition;
|
||||
import ervu_business_metrics.dao.RoleDataDao;
|
||||
import ervu_business_metrics.model.idm.RoleData;
|
||||
|
|
@ -28,8 +30,8 @@ public class RoleDataProcessor implements DataProcessor<RoleData, RoleRecord> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void changeActiveStatus(String id, boolean active) {
|
||||
dao.setActiveStatus(id, active);
|
||||
public void changeActiveStatus(List<String> ids, boolean active) {
|
||||
dao.setActiveStatus(ids, active);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue