RED-8702: Explore document databases to store entityLog
* added experimental logic for mongodb integration
This commit is contained in:
parent
99fdc9702d
commit
0b06c81c40
@ -38,7 +38,8 @@ dependencies {
|
|||||||
|
|
||||||
implementation("com.iqser.red.commons:dictionary-merge-commons:1.5.0")
|
implementation("com.iqser.red.commons:dictionary-merge-commons:1.5.0")
|
||||||
implementation("com.iqser.red.commons:storage-commons:2.45.0")
|
implementation("com.iqser.red.commons:storage-commons:2.45.0")
|
||||||
implementation("com.knecon.fforesight:tenant-commons:0.21.0")
|
implementation("com.knecon.fforesight:tenant-commons:maverick-mongo")
|
||||||
|
implementation("com.knecon.fforesight:mongo-database-commons:maverick-mongo")
|
||||||
implementation("com.knecon.fforesight:tracing-commons:0.5.0")
|
implementation("com.knecon.fforesight:tracing-commons:0.5.0")
|
||||||
|
|
||||||
implementation("com.fasterxml.jackson.module:jackson-module-afterburner:${jacksonVersion}")
|
implementation("com.fasterxml.jackson.module:jackson-module-afterburner:${jacksonVersion}")
|
||||||
@ -66,6 +67,11 @@ dependencies {
|
|||||||
//todo: remove
|
//todo: remove
|
||||||
implementation("io.minio:minio:8.5.9")
|
implementation("io.minio:minio:8.5.9")
|
||||||
|
|
||||||
|
|
||||||
|
implementation("org.liquibase:liquibase-core:4.24.0")
|
||||||
|
|
||||||
|
implementation("org.liquibase.ext:liquibase-mongodb:4.24.0")
|
||||||
|
|
||||||
testImplementation(project(":rules-management"))
|
testImplementation(project(":rules-management"))
|
||||||
testImplementation("org.apache.pdfbox:pdfbox:${pdfBoxVersion}")
|
testImplementation("org.apache.pdfbox:pdfbox:${pdfBoxVersion}")
|
||||||
testImplementation("org.apache.pdfbox:pdfbox-tools:${pdfBoxVersion}")
|
testImplementation("org.apache.pdfbox:pdfbox-tools:${pdfBoxVersion}")
|
||||||
|
|||||||
@ -24,6 +24,8 @@ import com.iqser.red.service.dictionarymerge.commons.DictionaryMergeService;
|
|||||||
import com.iqser.red.service.redaction.v1.server.client.RulesClient;
|
import com.iqser.red.service.redaction.v1.server.client.RulesClient;
|
||||||
import com.iqser.red.service.redaction.v1.server.mongo.CascadeSaveMongoEventListener;
|
import com.iqser.red.service.redaction.v1.server.mongo.CascadeSaveMongoEventListener;
|
||||||
import com.iqser.red.storage.commons.StorageAutoConfiguration;
|
import com.iqser.red.storage.commons.StorageAutoConfiguration;
|
||||||
|
import com.knecon.fforesight.mongo.database.commons.service.MongoClientCache;
|
||||||
|
import com.knecon.fforesight.mongo.database.commons.service.MongoDataSources;
|
||||||
import com.knecon.fforesight.tenantcommons.MultiTenancyAutoConfiguration;
|
import com.knecon.fforesight.tenantcommons.MultiTenancyAutoConfiguration;
|
||||||
|
|
||||||
import io.micrometer.core.aop.TimedAspect;
|
import io.micrometer.core.aop.TimedAspect;
|
||||||
@ -33,7 +35,7 @@ import io.micrometer.observation.aop.ObservedAspect;
|
|||||||
|
|
||||||
@EnableCaching
|
@EnableCaching
|
||||||
@ImportAutoConfiguration({MultiTenancyAutoConfiguration.class})
|
@ImportAutoConfiguration({MultiTenancyAutoConfiguration.class})
|
||||||
@Import({MetricsConfiguration.class, StorageAutoConfiguration.class})
|
@Import({MetricsConfiguration.class, StorageAutoConfiguration.class, MongoDataSources.class})
|
||||||
@EnableFeignClients(basePackageClasses = RulesClient.class)
|
@EnableFeignClients(basePackageClasses = RulesClient.class)
|
||||||
@EnableConfigurationProperties(RedactionServiceSettings.class)
|
@EnableConfigurationProperties(RedactionServiceSettings.class)
|
||||||
@SpringBootApplication(exclude = {SecurityAutoConfiguration.class, ManagementWebSecurityAutoConfiguration.class})
|
@SpringBootApplication(exclude = {SecurityAutoConfiguration.class, ManagementWebSecurityAutoConfiguration.class})
|
||||||
@ -75,42 +77,6 @@ public class Application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public MongoCustomConversions mongoCustomConversions() {
|
|
||||||
|
|
||||||
return new MongoCustomConversions(Arrays.asList(new MongoOffsetDateTimeWriter(), new MongoOffsetDateTimeReader()));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static class MongoOffsetDateTimeWriter implements Converter<OffsetDateTime, Document> {
|
|
||||||
|
|
||||||
public static final String DATE_FIELD = "dateTime";
|
|
||||||
public static final String OFFSET_FIELD = "offset";
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Document convert(final OffsetDateTime offsetDateTime) {
|
|
||||||
|
|
||||||
final Document document = new Document();
|
|
||||||
document.put(DATE_FIELD, Date.from(offsetDateTime.toInstant()));
|
|
||||||
document.put(OFFSET_FIELD, offsetDateTime.getOffset().toString());
|
|
||||||
return document;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class MongoOffsetDateTimeReader implements Converter<Document, OffsetDateTime> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public OffsetDateTime convert(final Document document) {
|
|
||||||
|
|
||||||
final Date dateTime = document.getDate(MongoOffsetDateTimeWriter.DATE_FIELD);
|
|
||||||
final ZoneOffset offset = ZoneOffset.of(document.getString(MongoOffsetDateTimeWriter.OFFSET_FIELD));
|
|
||||||
return OffsetDateTime.ofInstant(dateTime.toInstant(), offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public CascadeSaveMongoEventListener cascadingMongoEventListener() {
|
public CascadeSaveMongoEventListener cascadingMongoEventListener() {
|
||||||
return new CascadeSaveMongoEventListener();
|
return new CascadeSaveMongoEventListener();
|
||||||
|
|||||||
@ -27,7 +27,6 @@ public class EntityLogDocument {
|
|||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
private String dossierId;
|
private String dossierId;
|
||||||
|
|
||||||
private String fileId;
|
private String fileId;
|
||||||
|
|
||||||
private long analysisVersion;
|
private long analysisVersion;
|
||||||
@ -36,10 +35,12 @@ public class EntityLogDocument {
|
|||||||
@DBRef
|
@DBRef
|
||||||
@CascadeSave
|
@CascadeSave
|
||||||
private List<EntityLogEntryDocument> entityLogEntryDocument = new ArrayList<>();
|
private List<EntityLogEntryDocument> entityLogEntryDocument = new ArrayList<>();
|
||||||
|
|
||||||
private List<EntityLogLegalBasis> legalBasis = new ArrayList<>();
|
private List<EntityLogLegalBasis> legalBasis = new ArrayList<>();
|
||||||
|
|
||||||
private long dictionaryVersion = -1;
|
private long dictionaryVersion = -1;
|
||||||
private long dossierDictionaryVersion = -1;
|
private long dossierDictionaryVersion = -1;
|
||||||
|
|
||||||
private long rulesVersion = -1;
|
private long rulesVersion = -1;
|
||||||
private long legalBasisVersion = -1;
|
private long legalBasisVersion = -1;
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,13 @@
|
|||||||
package com.iqser.red.service.redaction.v1.server.mongo;
|
package com.iqser.red.service.redaction.v1.server.mongo;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.springframework.data.mongodb.repository.MongoRepository;
|
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||||
|
import org.springframework.data.mongodb.repository.Query;
|
||||||
|
import org.springframework.data.repository.query.Param;
|
||||||
|
|
||||||
public interface EntityLogDocumentRepository extends MongoRepository<EntityLogDocument, String> {
|
public interface EntityLogDocumentRepository extends MongoRepository<EntityLogDocument, String> {
|
||||||
|
|
||||||
|
@Query(value = "{ '_id' : ?0 }", fields = "{ 'analysisNumber' : 1 }")
|
||||||
|
Optional<EntityLogDocument> findAnalysisNumberById(@Param("_id") String id);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,15 @@
|
|||||||
|
package com.iqser.red.service.redaction.v1.server.mongo;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||||
|
import org.springframework.data.mongodb.repository.Query;
|
||||||
|
|
||||||
|
public interface EntityLogEntryDocumentRepository extends MongoRepository<EntityLogEntryDocument, String> {
|
||||||
|
|
||||||
|
@Query("{ 'entityLogId' : ?0, 'manualChanges' : { $exists: true, $not: { $size: 0 } } }")
|
||||||
|
List<EntityLogEntryDocument> findByEntityLogIdAndManualChangesNotEmpty(String entityLogId);
|
||||||
|
|
||||||
|
@Query("{ 'entityLogId' : ?0, 'changes.analysisNumber' : ?1 }")
|
||||||
|
List<EntityLogEntryDocument> findByEntityLogIdAndChangesAnalysisNumber(String entityLogId, int analysisNumber);
|
||||||
|
}
|
||||||
@ -2,6 +2,7 @@ package com.iqser.red.service.redaction.v1.server.mongo;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -14,9 +15,14 @@ import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog
|
|||||||
public class EntityLogMongoService {
|
public class EntityLogMongoService {
|
||||||
|
|
||||||
private final EntityLogDocumentRepository entityLogDocumentRepository;
|
private final EntityLogDocumentRepository entityLogDocumentRepository;
|
||||||
|
private final EntityLogEntryDocumentRepository entityLogEntryDocumentRepository;
|
||||||
|
|
||||||
|
|
||||||
public EntityLogMongoService(EntityLogDocumentRepository entityLogDocumentRepository) {this.entityLogDocumentRepository = entityLogDocumentRepository;}
|
public EntityLogMongoService(EntityLogDocumentRepository entityLogDocumentRepository, EntityLogEntryDocumentRepository entityLogEntryDocumentRepository) {
|
||||||
|
|
||||||
|
this.entityLogDocumentRepository = entityLogDocumentRepository;
|
||||||
|
this.entityLogEntryDocumentRepository = entityLogEntryDocumentRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void saveEntityLog(String dossierId, String fileId, EntityLog entityLog) {
|
public void saveEntityLog(String dossierId, String fileId, EntityLog entityLog) {
|
||||||
@ -27,7 +33,8 @@ public class EntityLogMongoService {
|
|||||||
|
|
||||||
public Optional<EntityLog> findEntityLogByDossierIdAndFileId(String dossierId, String fileId) {
|
public Optional<EntityLog> findEntityLogByDossierIdAndFileId(String dossierId, String fileId) {
|
||||||
|
|
||||||
return entityLogDocumentRepository.findById(EntityLogDocument.getDocumentId(dossierId, fileId)).map(EntityLogMongoService::fromDocument);
|
return entityLogDocumentRepository.findById(EntityLogDocument.getDocumentId(dossierId, fileId))
|
||||||
|
.map(EntityLogMongoService::fromDocument);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -37,11 +44,36 @@ public class EntityLogMongoService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Optional<Integer> findLatestAnalysisNumber(String dossierId, String fileId) {
|
||||||
|
|
||||||
|
return entityLogDocumentRepository.findAnalysisNumberById(EntityLogDocument.getDocumentId(dossierId, fileId))
|
||||||
|
.map(EntityLogDocument::getAnalysisNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public List<EntityLogEntry> findAllEntityLogEntriesWithManualChanges(String dossierId, String fileId) {
|
||||||
|
|
||||||
|
return entityLogEntryDocumentRepository.findByEntityLogIdAndManualChangesNotEmpty(EntityLogDocument.getDocumentId(dossierId, fileId))
|
||||||
|
.stream()
|
||||||
|
.map(EntityLogMongoService::fromDocument)
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
public List<EntityLogEntry> findAllEntityLogEntriesByAnalysisNumber(String dossierId, String fileId, int analysisNumber) {
|
||||||
|
|
||||||
|
return entityLogEntryDocumentRepository.findByEntityLogIdAndChangesAnalysisNumber(EntityLogDocument.getDocumentId(dossierId, fileId), analysisNumber)
|
||||||
|
.stream()
|
||||||
|
.map(EntityLogMongoService::fromDocument)
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private static EntityLog fromDocument(EntityLogDocument entityLogDocument) {
|
private static EntityLog fromDocument(EntityLogDocument entityLogDocument) {
|
||||||
|
|
||||||
EntityLog entityLog = new EntityLog();
|
EntityLog entityLog = new EntityLog();
|
||||||
entityLog.setAnalysisVersion(entityLogDocument.getAnalysisVersion());
|
entityLog.setAnalysisVersion(entityLogDocument.getAnalysisVersion());
|
||||||
entityLog.setAnalysisNumber(entityLogDocument.getAnalysisNumber());
|
entityLog.setAnalysisNumber(entityLogDocument.getAnalysisNumber());
|
||||||
entityLog.setEntityLogEntry(entityLogDocument.getEntityLogEntryDocument().stream()
|
entityLog.setEntityLogEntry(entityLogDocument.getEntityLogEntryDocument()
|
||||||
|
.stream()
|
||||||
.map(EntityLogMongoService::fromDocument)
|
.map(EntityLogMongoService::fromDocument)
|
||||||
.collect(Collectors.toList()));
|
.collect(Collectors.toList()));
|
||||||
entityLog.setLegalBasis(entityLogDocument.getLegalBasis());
|
entityLog.setLegalBasis(entityLogDocument.getLegalBasis());
|
||||||
@ -52,7 +84,9 @@ public class EntityLogMongoService {
|
|||||||
return entityLog;
|
return entityLog;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static EntityLogEntry fromDocument(EntityLogEntryDocument entityLogEntryDocument) {
|
private static EntityLogEntry fromDocument(EntityLogEntryDocument entityLogEntryDocument) {
|
||||||
|
|
||||||
EntityLogEntry entityLogEntry = new EntityLogEntry();
|
EntityLogEntry entityLogEntry = new EntityLogEntry();
|
||||||
entityLogEntry.setId(entityLogEntryDocument.getEntryId());
|
entityLogEntry.setId(entityLogEntryDocument.getEntryId());
|
||||||
entityLogEntry.setState(entityLogEntryDocument.getState());
|
entityLogEntry.setState(entityLogEntryDocument.getState());
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
package com.iqser.red.service.redaction.v1.server.mongo;
|
package com.iqser.red.service.redaction.v1.server.mongodeprecated;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@ -7,6 +7,9 @@ import org.springframework.data.mongodb.core.MongoTemplate;
|
|||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import com.iqser.red.service.redaction.v1.server.mongo.EntityLogDocument;
|
||||||
|
import com.iqser.red.service.redaction.v1.server.mongo.EntityLogDocumentRepository;
|
||||||
|
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.experimental.FieldDefaults;
|
import lombok.experimental.FieldDefaults;
|
||||||
@ -0,0 +1,37 @@
|
|||||||
|
package com.iqser.red.service.redaction.v1.server;
|
||||||
|
|
||||||
|
import static com.mongodb.client.model.Filters.eq;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import liquibase.Contexts;
|
||||||
|
import liquibase.Liquibase;
|
||||||
|
import liquibase.database.DatabaseFactory;
|
||||||
|
import liquibase.ext.mongodb.database.MongoLiquibaseDatabase;
|
||||||
|
import liquibase.resource.ClassLoaderResourceAccessor;
|
||||||
|
import lombok.SneakyThrows;
|
||||||
|
|
||||||
|
public class MyMongoLiquibaseTest {
|
||||||
|
|
||||||
|
private static final String HOSTNAME = "localhost";
|
||||||
|
private static final String PORT = "27017";
|
||||||
|
private static final String DATABASE = "redaction";
|
||||||
|
private static final String USERNAME = "root";
|
||||||
|
private static final String PASSWORD = "AP8ckozpAl55JDAAFR4rxpbPj1WXdBTL";
|
||||||
|
|
||||||
|
private static final String URL = String.format("mongodb://%s:%s/%s", HOSTNAME, PORT, DATABASE);
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SneakyThrows
|
||||||
|
public void testMongoDB() {
|
||||||
|
|
||||||
|
try (MongoLiquibaseDatabase database = (MongoLiquibaseDatabase) DatabaseFactory.getInstance().openDatabase(URL, USERNAME, PASSWORD, null, null)) {
|
||||||
|
Liquibase liquibase = new Liquibase("mongo/liquibase/test.changelog.xml", new ClassLoaderResourceAccessor(), database);
|
||||||
|
liquibase.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -2,49 +2,18 @@ package com.iqser.red.service.redaction.v1.server;
|
|||||||
|
|
||||||
import static com.mongodb.client.model.Filters.eq;
|
import static com.mongodb.client.model.Filters.eq;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import org.bson.BsonArray;
|
||||||
import java.util.Arrays;
|
import org.bson.BsonDocument;
|
||||||
import java.util.List;
|
import org.bson.BsonString;
|
||||||
|
|
||||||
import org.bson.Document;
|
import org.bson.Document;
|
||||||
import org.bson.conversions.Bson;
|
|
||||||
import org.junit.jupiter.api.Disabled;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
|
||||||
import org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration;
|
|
||||||
import org.springframework.boot.autoconfigure.mongo.MongoProperties;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.context.annotation.FilterType;
|
|
||||||
import org.springframework.context.annotation.Import;
|
|
||||||
import org.springframework.context.annotation.Primary;
|
|
||||||
import org.springframework.core.io.ClassPathResource;
|
|
||||||
import org.springframework.data.mongodb.config.AbstractMongoClientConfiguration;
|
|
||||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||||
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
|
|
||||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.knecon.fforesight.tenantcommons.model.TenantResponse;
|
||||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
|
||||||
import com.iqser.red.commons.jackson.ObjectMapperFactory;
|
|
||||||
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog.EntityLog;
|
|
||||||
import com.iqser.red.service.redaction.v1.server.mongo.EntityLogDocument;
|
|
||||||
import com.iqser.red.service.redaction.v1.server.mongo.EntityLogDocumentRepository;
|
|
||||||
import com.iqser.red.service.redaction.v1.server.mongo.EntityLogDocumentService;
|
|
||||||
import com.iqser.red.storage.commons.StorageAutoConfiguration;
|
|
||||||
import com.iqser.red.storage.commons.service.StorageService;
|
|
||||||
import com.iqser.red.storage.commons.utils.FileSystemBackedStorageService;
|
|
||||||
import com.mongodb.client.MongoClient;
|
import com.mongodb.client.MongoClient;
|
||||||
import com.mongodb.client.MongoClients;
|
import com.mongodb.client.MongoClients;
|
||||||
import com.mongodb.client.MongoCollection;
|
import com.mongodb.client.MongoCollection;
|
||||||
import com.mongodb.client.MongoDatabase;
|
import com.mongodb.client.MongoDatabase;
|
||||||
import com.mongodb.client.model.Aggregates;
|
|
||||||
|
|
||||||
import lombok.SneakyThrows;
|
|
||||||
|
|
||||||
public class MyMongoTest {
|
public class MyMongoTest {
|
||||||
|
|
||||||
@ -62,6 +31,38 @@ public class MyMongoTest {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void deleteMongoDBDatabase() {
|
||||||
|
|
||||||
|
try (MongoClient mongoClient = MongoClients.create(String.format("mongodb://%s:%s@%s:%s/",
|
||||||
|
USERNAME,
|
||||||
|
PASSWORD,
|
||||||
|
HOSTNAME,
|
||||||
|
PORT))) {
|
||||||
|
mongoClient.getDatabase("new_database").drop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void createDatabaseUser() {
|
||||||
|
|
||||||
|
try (MongoClient mongoClient = MongoClients.create(String.format("mongodb://%s:%s@%s:%s/",
|
||||||
|
USERNAME,
|
||||||
|
PASSWORD,
|
||||||
|
HOSTNAME,
|
||||||
|
PORT))) {
|
||||||
|
MongoDatabase database = mongoClient.getDatabase("last_database");
|
||||||
|
BsonDocument createUserCommand = new BsonDocument();
|
||||||
|
createUserCommand.append("createUser", new BsonString(USERNAME));
|
||||||
|
createUserCommand.append("pwd", new BsonString(PASSWORD));
|
||||||
|
BsonArray roles = new BsonArray();
|
||||||
|
roles.add(new BsonString("readWrite"));
|
||||||
|
createUserCommand.append("roles", roles);
|
||||||
|
|
||||||
|
database.runCommand(createUserCommand);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@Test
|
@Test
|
||||||
public void testMongoDB() {
|
public void testMongoDB() {
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,9 @@
|
|||||||
package com.iqser.red.service.redaction.v1.server;
|
package com.iqser.red.service.redaction.v1.server;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.time.OffsetDateTime;
|
import java.time.OffsetDateTime;
|
||||||
@ -9,6 +13,7 @@ import java.util.Date;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.bson.Document;
|
import org.bson.Document;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.kie.api.runtime.KieContainer;
|
import org.kie.api.runtime.KieContainer;
|
||||||
@ -39,12 +44,20 @@ import com.iqser.red.service.redaction.v1.server.client.DictionaryClient;
|
|||||||
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog.EntityLog;
|
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog.EntityLog;
|
||||||
import com.iqser.red.service.redaction.v1.server.mongo.EntityLogDocument;
|
import com.iqser.red.service.redaction.v1.server.mongo.EntityLogDocument;
|
||||||
import com.iqser.red.service.redaction.v1.server.mongo.EntityLogDocumentRepository;
|
import com.iqser.red.service.redaction.v1.server.mongo.EntityLogDocumentRepository;
|
||||||
import com.iqser.red.service.redaction.v1.server.mongo.EntityLogDocumentService;
|
import com.iqser.red.service.redaction.v1.server.mongodeprecated.EntityLogDocumentService;
|
||||||
import com.iqser.red.service.redaction.v1.server.mongo.EntityLogMongoService;
|
import com.iqser.red.service.redaction.v1.server.mongo.EntityLogMongoService;
|
||||||
import com.iqser.red.service.redaction.v1.server.mongodeprecated._EntityLogDocumentRepository;
|
import com.iqser.red.service.redaction.v1.server.mongodeprecated._EntityLogDocumentRepository;
|
||||||
import com.iqser.red.storage.commons.service.StorageServiceImpl;
|
import com.iqser.red.storage.commons.service.StorageServiceImpl;
|
||||||
|
import com.knecon.fforesight.mongo.database.commons.config.MongoDbConfiguration;
|
||||||
|
import com.knecon.fforesight.mongo.database.commons.config.MultiTenantMongoDBFactory;
|
||||||
|
import com.knecon.fforesight.mongo.database.commons.service.MongoClientCache;
|
||||||
|
import com.knecon.fforesight.mongo.database.commons.service.MongoConnectionProvider;
|
||||||
|
import com.knecon.fforesight.mongo.database.commons.service.MongoConnectionProviderImpl;
|
||||||
|
import com.knecon.fforesight.mongo.database.commons.service.MongoDataSources;
|
||||||
import com.knecon.fforesight.service.layoutparser.processor.LayoutParsingServiceProcessorConfiguration;
|
import com.knecon.fforesight.service.layoutparser.processor.LayoutParsingServiceProcessorConfiguration;
|
||||||
|
import com.knecon.fforesight.tenantcommons.TenantContext;
|
||||||
import com.knecon.fforesight.tenantcommons.TenantsClient;
|
import com.knecon.fforesight.tenantcommons.TenantsClient;
|
||||||
|
import com.knecon.fforesight.tenantcommons.model.MongoDBConnection;
|
||||||
|
|
||||||
import io.minio.MinioClient;
|
import io.minio.MinioClient;
|
||||||
import io.minio.PutObjectArgs;
|
import io.minio.PutObjectArgs;
|
||||||
@ -75,6 +88,8 @@ public class MyOtherMongoTest {
|
|||||||
private static final String USERNAME = "root";
|
private static final String USERNAME = "root";
|
||||||
private static final String PASSWORD = "AP8ckozpAl55JDAAFR4rxpbPj1WXdBTL";
|
private static final String PASSWORD = "AP8ckozpAl55JDAAFR4rxpbPj1WXdBTL";
|
||||||
|
|
||||||
|
private static final String TEST_DOSSIER_2_ID = "bigentestdossierid";
|
||||||
|
private static final String TEST_FILE_2_ID = "bigentityfileid";
|
||||||
private static final String TEST_DOSSIER_ID = "testdossierid";
|
private static final String TEST_DOSSIER_ID = "testdossierid";
|
||||||
private static final String TEST_FILE_ID = "b2cbdd4dca0aa1aa0ebbfc5cc1462df0";
|
private static final String TEST_FILE_ID = "b2cbdd4dca0aa1aa0ebbfc5cc1462df0";
|
||||||
public static final String COLLECTION_ENTITY_LOG = "entity-logs";
|
public static final String COLLECTION_ENTITY_LOG = "entity-logs";
|
||||||
@ -96,6 +111,65 @@ public class MyOtherMongoTest {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private EntityLogMongoService entityLogMongoService;
|
private EntityLogMongoService entityLogMongoService;
|
||||||
|
|
||||||
|
@MockBean
|
||||||
|
private MongoConnectionProvider mongoConnectionProvider;
|
||||||
|
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
public void setTenant() {
|
||||||
|
|
||||||
|
TenantContext.setTenantId("redaction");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SneakyThrows
|
||||||
|
public void testFindEntries() {
|
||||||
|
|
||||||
|
when(mongoConnectionProvider.getMongoDBConnection(any())).thenReturn(MongoDBConnection.builder()
|
||||||
|
.host("localhost")
|
||||||
|
.port("27017")
|
||||||
|
.database("redaction")
|
||||||
|
.username(USERNAME)
|
||||||
|
.password(PASSWORD)
|
||||||
|
.build());
|
||||||
|
|
||||||
|
var latest = entityLogMongoService.findLatestAnalysisNumber(TEST_DOSSIER_2_ID, TEST_FILE_2_ID)
|
||||||
|
.orElseThrow();
|
||||||
|
var latestChangedEntries = entityLogMongoService.findAllEntityLogEntriesByAnalysisNumber(TEST_DOSSIER_2_ID, TEST_FILE_2_ID, latest);
|
||||||
|
assertEquals(latestChangedEntries.size(), 491);
|
||||||
|
|
||||||
|
var manuallyChangedEntries = entityLogMongoService.findAllEntityLogEntriesWithManualChanges(TEST_DOSSIER_2_ID, TEST_FILE_2_ID);
|
||||||
|
assertEquals(manuallyChangedEntries.size(), 1014);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SneakyThrows
|
||||||
|
public void testFindLatestAnalysisNumber() {
|
||||||
|
|
||||||
|
assertEquals(entityLogMongoService.findLatestAnalysisNumber(TEST_DOSSIER_2_ID, TEST_FILE_2_ID)
|
||||||
|
.orElse(-1), 8);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SneakyThrows
|
||||||
|
public void testSaveBigEntityLogDocument() {
|
||||||
|
|
||||||
|
var file = new ClassPathResource(String.format("mongo/%s.ENTITY_LOG.json", TEST_FILE_2_ID));
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
objectMapper.registerModule(new JavaTimeModule());
|
||||||
|
|
||||||
|
EntityLog entityLog = objectMapper.readValue(file.getInputStream(), EntityLog.class);
|
||||||
|
|
||||||
|
entityLogMongoService.saveEntityLog(TEST_DOSSIER_2_ID, TEST_FILE_2_ID, entityLog);
|
||||||
|
|
||||||
|
Optional<EntityLog> found = entityLogMongoService.findEntityLogByDossierIdAndFileId(TEST_DOSSIER_2_ID, TEST_FILE_2_ID);
|
||||||
|
assert (found.isPresent());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -110,8 +184,6 @@ public class MyOtherMongoTest {
|
|||||||
|
|
||||||
entityLogMongoService.saveEntityLog(TEST_DOSSIER_ID, TEST_FILE_ID, entityLog);
|
entityLogMongoService.saveEntityLog(TEST_DOSSIER_ID, TEST_FILE_ID, entityLog);
|
||||||
|
|
||||||
//Optional<EntityLogDocument> found = entityLogDocumentService.findEntityLogDocumentById(TEST_FILE_ID);
|
|
||||||
//assert(found.isPresent());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -120,11 +192,10 @@ public class MyOtherMongoTest {
|
|||||||
public void testFindEntityLogDocumentById() {
|
public void testFindEntityLogDocumentById() {
|
||||||
|
|
||||||
Optional<EntityLog> entityLogDocumentById = entityLogMongoService.findEntityLogByDossierIdAndFileId(TEST_DOSSIER_ID, TEST_FILE_ID);
|
Optional<EntityLog> entityLogDocumentById = entityLogMongoService.findEntityLogByDossierIdAndFileId(TEST_DOSSIER_ID, TEST_FILE_ID);
|
||||||
assert(entityLogDocumentById.isPresent());
|
assert (entityLogDocumentById.isPresent());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public void testRedactionStorageService() {
|
public void testRedactionStorageService() {
|
||||||
@ -137,13 +208,9 @@ public class MyOtherMongoTest {
|
|||||||
EntityLogDocument entityLogDocument = new EntityLogDocument(TEST_DOSSIER_ID, TEST_FILE_ID, entityLog);
|
EntityLogDocument entityLogDocument = new EntityLogDocument(TEST_DOSSIER_ID, TEST_FILE_ID, entityLog);
|
||||||
|
|
||||||
String jsonData = objectMapper.writeValueAsString(entityLogDocument);
|
String jsonData = objectMapper.writeValueAsString(entityLogDocument);
|
||||||
// Convert JSON data to InputStream
|
|
||||||
InputStream jsonDataStream = new ByteArrayInputStream(jsonData.getBytes());
|
InputStream jsonDataStream = new ByteArrayInputStream(jsonData.getBytes());
|
||||||
|
|
||||||
minioInsert(jsonDataStream, jsonData.length());
|
minioInsert(jsonDataStream, jsonData.length());
|
||||||
|
|
||||||
//Optional<EntityLogDocument> found = entityLogDocumentService.findEntityLogDocumentById(TEST_FILE_ID);
|
|
||||||
//assert(found.isPresent());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -157,14 +224,8 @@ public class MyOtherMongoTest {
|
|||||||
|
|
||||||
String contentType = "application/json";
|
String contentType = "application/json";
|
||||||
|
|
||||||
minioClient.putObject(
|
minioClient.putObject(PutObjectArgs.builder().bucket(DATABASE).object(TEST_FILE_ID)
|
||||||
PutObjectArgs.builder()
|
.stream(inputStream, length, -1).contentType(contentType).build());
|
||||||
.bucket(DATABASE)
|
|
||||||
.object(TEST_FILE_ID)
|
|
||||||
.stream(inputStream, length, -1)
|
|
||||||
.contentType(contentType)
|
|
||||||
.build()
|
|
||||||
);
|
|
||||||
|
|
||||||
System.out.println("JSON file uploaded successfully!");
|
System.out.println("JSON file uploaded successfully!");
|
||||||
|
|
||||||
@ -174,64 +235,69 @@ public class MyOtherMongoTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableMongoRepositories
|
|
||||||
@EnableAutoConfiguration(exclude = {RabbitAutoConfiguration.class})
|
@EnableAutoConfiguration(exclude = {RabbitAutoConfiguration.class})
|
||||||
@Import({LayoutParsingServiceProcessorConfiguration.class})
|
@Import({MongoDbConfiguration.class, MultiTenantMongoDBFactory.class, MongoClientCache.class, MongoDataSources.class, MongoConnectionProviderImpl.class})
|
||||||
@ComponentScan(excludeFilters = {@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE)})
|
@ComponentScan(excludeFilters = {@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE)})
|
||||||
public static class MongoTestConfiguration {
|
public static class MongoTestConfiguration {
|
||||||
|
|
||||||
@Bean
|
|
||||||
public MongoCustomConversions mongoCustomConversions() {
|
|
||||||
return new MongoCustomConversions(Arrays.asList(new MongoOffsetDateTimeWriter(), new MongoOffsetDateTimeReader()
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
public static class MongoOffsetDateTimeWriter implements Converter<OffsetDateTime, Document> {
|
* @Configuration
|
||||||
|
* @EnableMongoRepositories
|
||||||
public static final String DATE_FIELD = "dateTime";
|
* @EnableAutoConfiguration(exclude = {RabbitAutoConfiguration.class})
|
||||||
public static final String OFFSET_FIELD = "offset";
|
* @Import({LayoutParsingServiceProcessorConfiguration.class})
|
||||||
|
* @ComponentScan(excludeFilters = {@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE)})
|
||||||
@Override
|
* public static class MongoTestConfiguration {
|
||||||
public Document convert(final OffsetDateTime offsetDateTime) {
|
* @Bean public MongoCustomConversions mongoCustomConversions() {
|
||||||
final Document document = new Document();
|
* return new MongoCustomConversions(Arrays.asList(new MongoOffsetDateTimeWriter(), new MongoOffsetDateTimeReader()
|
||||||
document.put(DATE_FIELD, Date.from(offsetDateTime.toInstant()));
|
* ));
|
||||||
document.put(OFFSET_FIELD, offsetDateTime.getOffset().toString());
|
* }
|
||||||
return document;
|
* <p>
|
||||||
}
|
* <p>
|
||||||
|
* }
|
||||||
}
|
* <p>
|
||||||
|
* <p>
|
||||||
public static class MongoOffsetDateTimeReader implements Converter<Document, OffsetDateTime> {
|
* public static class MongoOffsetDateTimeWriter implements Converter<OffsetDateTime, Document> {
|
||||||
|
* <p>
|
||||||
@Override
|
* public static final String DATE_FIELD = "dateTime";
|
||||||
public OffsetDateTime convert(final Document document) {
|
* public static final String OFFSET_FIELD = "offset";
|
||||||
final Date dateTime = document.getDate(MongoOffsetDateTimeWriter.DATE_FIELD);
|
* @Override public Document convert(final OffsetDateTime offsetDateTime) {
|
||||||
final ZoneOffset offset = ZoneOffset.of(document.getString(MongoOffsetDateTimeWriter.OFFSET_FIELD));
|
* final Document document = new Document();
|
||||||
return OffsetDateTime.ofInstant(dateTime.toInstant(), offset);
|
* document.put(DATE_FIELD, Date.from(offsetDateTime.toInstant()));
|
||||||
}
|
* document.put(OFFSET_FIELD, offsetDateTime.getOffset().toString());
|
||||||
|
* return document;
|
||||||
}
|
* }
|
||||||
|
* <p>
|
||||||
|
* }
|
||||||
|
* <p>
|
||||||
|
* public static class MongoOffsetDateTimeReader implements Converter<Document, OffsetDateTime> {
|
||||||
|
* @Override public OffsetDateTime convert(final Document document) {
|
||||||
|
* final Date dateTime = document.getDate(MongoOffsetDateTimeWriter.DATE_FIELD);
|
||||||
|
* final ZoneOffset offset = ZoneOffset.of(document.getString(MongoOffsetDateTimeWriter.OFFSET_FIELD));
|
||||||
|
* return OffsetDateTime.ofInstant(dateTime.toInstant(), offset);
|
||||||
|
* }
|
||||||
|
* <p>
|
||||||
|
* }
|
||||||
|
**/
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
|
static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
|
||||||
|
|
||||||
public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
|
public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
|
||||||
|
|
||||||
TestPropertyValues.of("MONGODB_HOST=" + HOSTNAME, "MONGODB_PORT=" + PORT, "MONGODB_USER=" + USERNAME, "MONGODB_PASSWORD=" + PASSWORD,
|
TestPropertyValues.of("MONGODB_HOST=" + HOSTNAME,
|
||||||
"storage.bucket=name=redaction", "storage.endpoint=http://localhost:9000",
|
"MONGODB_PORT=" + PORT,
|
||||||
"storage.key=L2U4tR5Beaqh6UHPwvtDKTJSxWBXIiya" , "storage.secret=Spbv4vleaFnIrSiLLG3AhbdQk6DMraBQ")
|
"MONGODB_USER=" + USERNAME,
|
||||||
.applyTo(configurableApplicationContext.getEnvironment());
|
"MONGODB_PASSWORD=" + PASSWORD,
|
||||||
|
"storage.bucket=name=redaction",
|
||||||
|
"storage.endpoint=http://localhost:9000",
|
||||||
|
"storage.key=L2U4tR5Beaqh6UHPwvtDKTJSxWBXIiya",
|
||||||
|
"storage.secret=Spbv4vleaFnIrSiLLG3AhbdQk6DMraBQ").applyTo(configurableApplicationContext.getEnvironment());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,45 @@
|
|||||||
|
<!--
|
||||||
|
#%L
|
||||||
|
Liquibase MongoDB Extension
|
||||||
|
%%
|
||||||
|
Copyright (C) 2019 Mastercard
|
||||||
|
%%
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License").
|
||||||
|
You may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
#L%
|
||||||
|
-->
|
||||||
|
<databaseChangeLog
|
||||||
|
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns:mongodb="http://www.liquibase.org/xml/ns/mongodb"
|
||||||
|
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.6.xsd
|
||||||
|
http://www.liquibase.org/xml/ns/mongodb http://www.liquibase.org/xml/ns/mongodb/liquibase-mongodb-latest.xsd">
|
||||||
|
|
||||||
|
<changeSet id="1" author="maverick">
|
||||||
|
<mongodb:runCommand>
|
||||||
|
<mongodb:command>
|
||||||
|
{
|
||||||
|
update: "entity-logs",
|
||||||
|
updates: [
|
||||||
|
{
|
||||||
|
q: {},
|
||||||
|
u: { $rename: { "dId": "dossierId" } },
|
||||||
|
multi: true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
</mongodb:command>
|
||||||
|
|
||||||
|
</mongodb:runCommand>
|
||||||
|
</changeSet>
|
||||||
|
|
||||||
|
</databaseChangeLog>
|
||||||
Loading…
x
Reference in New Issue
Block a user