detect touch state from description-editor's form-field
This commit is contained in:
commit
ec512727cf
|
@ -23,7 +23,7 @@ import org.opencdmp.commons.scope.user.UserScope;
|
|||
import org.opencdmp.elastic.data.DescriptionElasticEntity;
|
||||
import org.opencdmp.elastic.data.DmpElasticEntity;
|
||||
import org.opencdmp.elastic.data.nested.NestedDmpElasticEntity;
|
||||
import org.opencdmp.service.elastic.AppElasticProperties;
|
||||
import org.opencdmp.service.elastic.AppElasticConfiguration;
|
||||
import org.opencdmp.service.elastic.ElasticService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
|
@ -135,16 +135,16 @@ public class DescriptionElasticQuery extends ElasticQuery<DescriptionElasticEnti
|
|||
}
|
||||
|
||||
private final QueryFactory queryFactory;
|
||||
private final AppElasticProperties appElasticProperties;
|
||||
private final AppElasticConfiguration appElasticConfiguration;
|
||||
private final ElasticService elasticService;
|
||||
private final UserScope userScope;
|
||||
private final TenantScope tenantScope;
|
||||
private final AuthorizationService authService;
|
||||
@Autowired
|
||||
public DescriptionElasticQuery(ElasticsearchTemplate elasticsearchTemplate, ElasticProperties elasticProperties, QueryFactory queryFactory, AppElasticProperties appElasticProperties, ElasticService elasticService, UserScope userScope, TenantScope tenantScope, AuthorizationService authService) {
|
||||
public DescriptionElasticQuery(ElasticsearchTemplate elasticsearchTemplate, ElasticProperties elasticProperties, QueryFactory queryFactory, AppElasticConfiguration appElasticConfiguration, ElasticService elasticService, UserScope userScope, TenantScope tenantScope, AuthorizationService authService) {
|
||||
super(elasticsearchTemplate, elasticProperties);
|
||||
this.queryFactory = queryFactory;
|
||||
this.appElasticProperties = appElasticProperties;
|
||||
this.appElasticConfiguration = appElasticConfiguration;
|
||||
this.elasticService = elasticService;
|
||||
this.userScope = userScope;
|
||||
this.tenantScope = tenantScope;
|
||||
|
@ -306,7 +306,7 @@ public class DescriptionElasticQuery extends ElasticQuery<DescriptionElasticEnti
|
|||
@Override
|
||||
protected String[] getIndex() {
|
||||
List<String> indexNames = new ArrayList<>();
|
||||
indexNames.add(this.appElasticProperties.getDescriptionIndexName());
|
||||
indexNames.add(this.appElasticConfiguration.getAppElasticProperties().getDescriptionIndexName());
|
||||
try {
|
||||
this.elasticService.ensureDescriptionIndex();
|
||||
} catch (IOException e) {
|
||||
|
|
|
@ -22,7 +22,7 @@ import org.opencdmp.commons.scope.tenant.TenantScope;
|
|||
import org.opencdmp.commons.scope.user.UserScope;
|
||||
import org.opencdmp.elastic.data.DmpElasticEntity;
|
||||
import org.opencdmp.elastic.data.nested.NestedDescriptionElasticEntity;
|
||||
import org.opencdmp.service.elastic.AppElasticProperties;
|
||||
import org.opencdmp.service.elastic.AppElasticConfiguration;
|
||||
import org.opencdmp.service.elastic.ElasticService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
|
@ -184,16 +184,16 @@ public class DmpElasticQuery extends ElasticQuery<DmpElasticEntity, UUID> {
|
|||
}
|
||||
|
||||
private final QueryFactory queryFactory;
|
||||
private final AppElasticProperties appElasticProperties;
|
||||
private final AppElasticConfiguration appElasticConfiguration;
|
||||
private final ElasticService elasticService;
|
||||
private final UserScope userScope;
|
||||
private final TenantScope tenantScope;
|
||||
private final AuthorizationService authService;
|
||||
@Autowired
|
||||
public DmpElasticQuery(ElasticsearchTemplate elasticsearchTemplate, ElasticProperties elasticProperties, QueryFactory queryFactory, AppElasticProperties appElasticProperties, ElasticService elasticService, UserScope userScope, TenantScope tenantScope, AuthorizationService authService) {
|
||||
public DmpElasticQuery(ElasticsearchTemplate elasticsearchTemplate, ElasticProperties elasticProperties, QueryFactory queryFactory, AppElasticConfiguration appElasticConfiguration, ElasticService elasticService, UserScope userScope, TenantScope tenantScope, AuthorizationService authService) {
|
||||
super(elasticsearchTemplate, elasticProperties);
|
||||
this.queryFactory = queryFactory;
|
||||
this.appElasticProperties = appElasticProperties;
|
||||
this.appElasticConfiguration = appElasticConfiguration;
|
||||
this.elasticService = elasticService;
|
||||
this.userScope = userScope;
|
||||
this.tenantScope = tenantScope;
|
||||
|
@ -369,7 +369,7 @@ public class DmpElasticQuery extends ElasticQuery<DmpElasticEntity, UUID> {
|
|||
@Override
|
||||
protected String[] getIndex() {
|
||||
List<String> indexNames = new ArrayList<>();
|
||||
indexNames.add(this.appElasticProperties.getDmpIndexName());
|
||||
indexNames.add(this.appElasticConfiguration.getAppElasticProperties().getDmpIndexName());
|
||||
try {
|
||||
this.elasticService.ensureDescriptionIndex();
|
||||
} catch (IOException e) {
|
||||
|
|
|
@ -7,6 +7,7 @@ import gr.cite.tools.exception.MyNotFoundException;
|
|||
import gr.cite.tools.exception.MyValidationException;
|
||||
import gr.cite.tools.fieldset.FieldSet;
|
||||
import jakarta.xml.bind.JAXBException;
|
||||
import org.opencdmp.commonmodels.models.dmpblueprint.DmpBlueprintModel;
|
||||
import org.opencdmp.commons.enums.DmpBlueprintSystemFieldType;
|
||||
import org.opencdmp.commons.types.dmpblueprint.importexport.BlueprintImportExport;
|
||||
import org.opencdmp.data.DmpBlueprintEntity;
|
||||
|
@ -42,4 +43,5 @@ public interface DmpBlueprintService {
|
|||
DmpBlueprint importXml(BlueprintImportExport dmpDefinition, UUID groupId, String label, FieldSet fields) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, TransformerException, InvalidApplicationException, IOException, InstantiationException, IllegalAccessException, SAXException;
|
||||
|
||||
DmpBlueprint importXml(byte[] bytes, UUID groupId, String label, FieldSet fields) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, TransformerException, InvalidApplicationException, IOException, InstantiationException, IllegalAccessException, SAXException;
|
||||
DmpBlueprint importCommonModel(DmpBlueprintModel dmpDefinition, FieldSet fields) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, TransformerException, InvalidApplicationException, IOException, InstantiationException, IllegalAccessException, SAXException;
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ import jakarta.xml.bind.JAXBException;
|
|||
import org.jetbrains.annotations.NotNull;
|
||||
import org.opencdmp.authorization.AuthorizationFlags;
|
||||
import org.opencdmp.authorization.Permission;
|
||||
import org.opencdmp.commonmodels.models.dmpblueprint.*;
|
||||
import org.opencdmp.commons.XmlHandlingService;
|
||||
import org.opencdmp.commons.enums.*;
|
||||
import org.opencdmp.commons.scope.tenant.TenantScope;
|
||||
|
@ -804,5 +805,188 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService {
|
|||
}
|
||||
|
||||
//endregion
|
||||
|
||||
//region Import RDA Json
|
||||
|
||||
@Override
|
||||
public DmpBlueprint importCommonModel(DmpBlueprintModel dmpDefinition, FieldSet fields) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, TransformerException, InvalidApplicationException, IOException, InstantiationException, IllegalAccessException, SAXException {
|
||||
logger.debug(new MapLogEntry("import data").And("dmpDefinition", dmpDefinition).And("fields", fields));
|
||||
|
||||
this.authorizationService.authorizeForce(Permission.ImportDmpBlueprint);
|
||||
|
||||
long activeBlueprintForTheGroup = dmpDefinition.getGroupId() != null ? this.queryFactory.query(DmpBlueprintQuery.class).disableTracking()
|
||||
.isActive(IsActive.Active)
|
||||
.groupIds(dmpDefinition.getGroupId())
|
||||
.count() : 0;
|
||||
|
||||
if (activeBlueprintForTheGroup == 0) {
|
||||
DmpBlueprintPersist persist = new DmpBlueprintPersist();
|
||||
|
||||
persist.setLabel(dmpDefinition.getLabel());
|
||||
persist.setStatus(DmpBlueprintStatus.Draft);
|
||||
persist.setDefinition(this.commonModelDefinitionToPersist(dmpDefinition.getDefinition()));
|
||||
|
||||
this.validatorFactory.validator(DmpBlueprintPersist.DmpBlueprintPersistValidator.class).validateForce(persist);
|
||||
return this.persist(persist, dmpDefinition.getGroupId(), fields);
|
||||
} else {
|
||||
DmpBlueprintEntity latestVersionDmpBlueprint = this.queryFactory.query(DmpBlueprintQuery.class)
|
||||
.disableTracking()
|
||||
.versionStatuses(DmpBlueprintVersionStatus.Current)
|
||||
.isActive(IsActive.Active)
|
||||
.statuses(DmpBlueprintStatus.Finalized)
|
||||
.groupIds(dmpDefinition.getGroupId())
|
||||
.first();
|
||||
if (latestVersionDmpBlueprint == null) throw new MyValidationException(this.errors.getDmpIsNotFinalized().getCode(), this.errors.getDmpIsNotFinalized().getMessage());
|
||||
NewVersionDmpBlueprintPersist persist = new NewVersionDmpBlueprintPersist();
|
||||
persist.setId(latestVersionDmpBlueprint.getId());
|
||||
persist.setLabel(dmpDefinition.getLabel());
|
||||
persist.setStatus(DmpBlueprintStatus.Draft);
|
||||
persist.setDefinition(this.commonModelDefinitionToPersist(dmpDefinition.getDefinition()));
|
||||
persist.setHash(this.conventionService.hashValue(latestVersionDmpBlueprint.getUpdatedAt()));
|
||||
|
||||
this.validatorFactory.validator(NewVersionDmpBlueprintPersist.NewVersionDmpBlueprintPersistValidator.class).validateForce(persist);
|
||||
return this.createNewVersion(persist, fields);
|
||||
}
|
||||
}
|
||||
|
||||
private DefinitionPersist commonModelDefinitionToPersist(DefinitionModel commonModel) {
|
||||
if (commonModel == null)
|
||||
return null;
|
||||
DefinitionPersist persist = new DefinitionPersist();
|
||||
List<SectionPersist> dmpBlueprintSections = new ArrayList<>();
|
||||
if (!this.conventionService.isListNullOrEmpty(commonModel.getSections())) {
|
||||
for (SectionModel section : commonModel.getSections()) {
|
||||
dmpBlueprintSections.add(this.commonModelSectionToPersist(section));
|
||||
}
|
||||
}
|
||||
persist.setSections(dmpBlueprintSections);
|
||||
return persist;
|
||||
}
|
||||
|
||||
private SectionPersist commonModelSectionToPersist(SectionModel commonModel) {
|
||||
SectionPersist persist = new SectionPersist();
|
||||
persist.setId(commonModel.getId());
|
||||
persist.setLabel(commonModel.getLabel());
|
||||
persist.setDescription(commonModel.getDescription());
|
||||
persist.setOrdinal(commonModel.getOrdinal());
|
||||
persist.setHasTemplates(commonModel.getHasTemplates());
|
||||
List<FieldPersist> dmpBlueprintFieldModels = new LinkedList<>();
|
||||
if (!this.conventionService.isListNullOrEmpty(commonModel.getFields())) {
|
||||
for (SystemFieldModel systemField : commonModel.getFields().stream().filter(x-> org.opencdmp.commonmodels.enums.DmpBlueprintFieldCategory.System.equals(x.getCategory())).map(x-> (SystemFieldModel)x).toList()) {
|
||||
dmpBlueprintFieldModels.add(this.commonModelSystemFieldToPersist(systemField));
|
||||
}
|
||||
for (ReferenceTypeFieldModel referenceField : commonModel.getFields().stream().filter(x-> org.opencdmp.commonmodels.enums.DmpBlueprintFieldCategory.ReferenceType.equals(x.getCategory())).map(x-> (ReferenceTypeFieldModel)x).toList()) {
|
||||
dmpBlueprintFieldModels.add(this.commonModelReferenceFieldToPersist(referenceField));
|
||||
}
|
||||
for (ExtraFieldModel extraField : commonModel.getFields().stream().filter(x-> org.opencdmp.commonmodels.enums.DmpBlueprintFieldCategory.Extra.equals(x.getCategory())).map(x-> (ExtraFieldModel)x).toList()) {
|
||||
dmpBlueprintFieldModels.add(this.commonExtraFieldToPersist(extraField));
|
||||
}
|
||||
}
|
||||
persist.setFields(dmpBlueprintFieldModels);
|
||||
// List<DescriptionTemplatePersist> dmpBlueprintDescriptionTemplates = new LinkedList<>();
|
||||
// if (!this.conventionService.isListNullOrEmpty(importXml.getDescriptionTemplates())) {
|
||||
// for (BlueprintDescriptionTemplateImportExport descriptionTemplate : importXml.getDescriptionTemplates()) {
|
||||
// dmpBlueprintDescriptionTemplates.add(this.xmlDescriptionTemplateToPersist(descriptionTemplate));
|
||||
// }
|
||||
// }
|
||||
// persist.setDescriptionTemplates(dmpBlueprintDescriptionTemplates);
|
||||
//
|
||||
// List<UUID> prefillingSources = new LinkedList<>();
|
||||
// if (!this.conventionService.isListNullOrEmpty(importXml.getPrefillingSources())) {
|
||||
// for (BlueprintPrefillingSourceImportExport prefillingSource : importXml.getPrefillingSources()) {
|
||||
// prefillingSources.add(this.xmlPrefillingSourceToPersist(prefillingSource));
|
||||
// }
|
||||
// }
|
||||
// persist.setPrefillingSourcesIds(prefillingSources);
|
||||
return persist;
|
||||
}
|
||||
|
||||
// private DescriptionTemplatePersist xmlDescriptionTemplateToPersist(BlueprintDescriptionTemplateImportExport importXml) {
|
||||
// org.opencdmp.data.DescriptionTemplateEntity data = importXml.getDescriptionTemplateGroupId() != null ? this.queryFactory.query(DescriptionTemplateQuery.class).disableTracking().groupIds(importXml.getDescriptionTemplateGroupId()).disableTracking().firstAs(new BaseFieldSet().ensure(DescriptionTemplate._groupId)) : null;
|
||||
// if (data == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{importXml.getDescriptionTemplateGroupId(), DescriptionTemplate.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
||||
//
|
||||
// DescriptionTemplatePersist persist = new DescriptionTemplatePersist();
|
||||
// persist.setDescriptionTemplateGroupId(importXml.getDescriptionTemplateGroupId());
|
||||
// persist.setLabel(importXml.getLabel());
|
||||
// persist.setMinMultiplicity(importXml.getMinMultiplicity());
|
||||
// persist.setMaxMultiplicity(importXml.getMaxMultiplicity());
|
||||
// return persist;
|
||||
// }
|
||||
//
|
||||
// private UUID xmlPrefillingSourceToPersist(BlueprintPrefillingSourceImportExport importXml) {
|
||||
// org.opencdmp.data.PrefillingSourceEntity data = importXml.getId() != null ? this.queryFactory.query(PrefillingSourceQuery.class).disableTracking().ids(importXml.getId()).disableTracking().firstAs(new BaseFieldSet().ensure(PrefillingSource._id)) : null;
|
||||
// if (data == null) {
|
||||
// if (!this.conventionService.isNullOrEmpty(importXml.getCode())) data = this.queryFactory.query(PrefillingSourceQuery.class).disableTracking().codes(importXml.getCode()).disableTracking().firstAs(new BaseFieldSet().ensure(PrefillingSource._id));
|
||||
// if (data == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{importXml.getId(), DescriptionTemplate.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
||||
// }
|
||||
//
|
||||
// return data.getId();
|
||||
// }
|
||||
|
||||
private FieldPersist commonExtraFieldToPersist(ExtraFieldModel commonModel) {
|
||||
ExtraFieldPersist persist = new ExtraFieldPersist();
|
||||
persist.setId(commonModel.getId());
|
||||
persist.setCategory(DmpBlueprintFieldCategory.Extra);
|
||||
switch (commonModel.getDataType()){
|
||||
case Text -> persist.setDataType(DmpBlueprintExtraFieldDataType.Text);
|
||||
case Date -> persist.setDataType(DmpBlueprintExtraFieldDataType.Date);
|
||||
case Number -> persist.setDataType(DmpBlueprintExtraFieldDataType.Number);
|
||||
case RichTex -> persist.setDataType(DmpBlueprintExtraFieldDataType.RichTex);
|
||||
default -> throw new InternalError("unknown type: " + commonModel.getDataType());
|
||||
}
|
||||
persist.setLabel(commonModel.getLabel());
|
||||
persist.setPlaceholder(commonModel.getPlaceholder());
|
||||
persist.setDescription(commonModel.getDescription());
|
||||
persist.setOrdinal(commonModel.getOrdinal());
|
||||
persist.setRequired(commonModel.getRequired());
|
||||
persist.setSemantics(commonModel.getSemantics());
|
||||
return persist;
|
||||
}
|
||||
|
||||
private FieldPersist commonModelSystemFieldToPersist(SystemFieldModel commonModel) {
|
||||
SystemFieldPersist persist = new SystemFieldPersist();
|
||||
persist.setId(commonModel.getId());
|
||||
persist.setCategory(DmpBlueprintFieldCategory.System);
|
||||
switch (commonModel.getSystemFieldType()){
|
||||
case User -> persist.setSystemFieldType(DmpBlueprintSystemFieldType.User);
|
||||
case AccessRights -> persist.setSystemFieldType(DmpBlueprintSystemFieldType.AccessRights);
|
||||
case Contact -> persist.setSystemFieldType(DmpBlueprintSystemFieldType.Contact);
|
||||
case Description -> persist.setSystemFieldType(DmpBlueprintSystemFieldType.Description);
|
||||
case Language -> persist.setSystemFieldType(DmpBlueprintSystemFieldType.Language);
|
||||
case Title -> persist.setSystemFieldType(DmpBlueprintSystemFieldType.Title);
|
||||
default -> throw new InternalError("unknown type: " + commonModel.getSystemFieldType());
|
||||
}
|
||||
persist.setLabel(commonModel.getLabel());
|
||||
persist.setPlaceholder(commonModel.getPlaceholder());
|
||||
persist.setDescription(commonModel.getDescription());
|
||||
persist.setOrdinal(commonModel.getOrdinal());
|
||||
persist.setRequired(commonModel.getRequired());
|
||||
persist.setSemantics(commonModel.getSemantics());
|
||||
return persist;
|
||||
}
|
||||
|
||||
private FieldPersist commonModelReferenceFieldToPersist(ReferenceTypeFieldModel commonModel) {
|
||||
|
||||
ReferenceTypeEntity data = commonModel.getReferenceType() != null && commonModel.getReferenceType().getId() != null ? this.queryFactory.query(ReferenceTypeQuery.class).disableTracking().ids(commonModel.getReferenceType().getId()).disableTracking().firstAs(new BaseFieldSet().ensure(ReferenceType._id)) : null;
|
||||
if (data == null){
|
||||
if (commonModel.getReferenceType() != null && !this.conventionService.isNullOrEmpty(commonModel.getReferenceType().getCode())) data = this.queryFactory.query(ReferenceTypeQuery.class).disableTracking().codes(commonModel.getReferenceType().getCode()).disableTracking().firstAs(new BaseFieldSet().ensure(ReferenceType._id));
|
||||
if (data == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{commonModel.getReferenceType().getCode(), ReferenceType.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
||||
}
|
||||
|
||||
ReferenceTypeFieldPersist persist = new ReferenceTypeFieldPersist();
|
||||
persist.setId(commonModel.getId());
|
||||
persist.setCategory(DmpBlueprintFieldCategory.ReferenceType);
|
||||
persist.setReferenceTypeId(data.getId());
|
||||
persist.setLabel(commonModel.getLabel());
|
||||
persist.setPlaceholder(commonModel.getPlaceholder());
|
||||
persist.setDescription(commonModel.getDescription());
|
||||
persist.setOrdinal(commonModel.getOrdinal());
|
||||
persist.setRequired(commonModel.getRequired());
|
||||
persist.setMultipleSelect(commonModel.getMultipleSelect());
|
||||
persist.setSemantics(commonModel.getSemantics());
|
||||
return persist;
|
||||
}
|
||||
|
||||
//endregion
|
||||
}
|
||||
|
||||
|
|
|
@ -5,16 +5,22 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
|
|||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(AppElasticProperties.class)
|
||||
@EnableConfigurationProperties({AppElasticProperties.class, ElasticQueryHelperServiceProperties.class })
|
||||
public class AppElasticConfiguration {
|
||||
private final AppElasticProperties properties;
|
||||
private final AppElasticProperties appElasticProperties;
|
||||
private final ElasticQueryHelperServiceProperties elasticQueryHelperServiceProperties;
|
||||
|
||||
@Autowired
|
||||
public AppElasticConfiguration(AppElasticProperties properties) {
|
||||
this.properties = properties;
|
||||
public AppElasticConfiguration(AppElasticProperties appElasticProperties, ElasticQueryHelperServiceProperties elasticQueryHelperServiceProperties) {
|
||||
this.appElasticProperties = appElasticProperties;
|
||||
this.elasticQueryHelperServiceProperties = elasticQueryHelperServiceProperties;
|
||||
}
|
||||
|
||||
public AppElasticProperties getProperties() {
|
||||
return properties;
|
||||
public AppElasticProperties getAppElasticProperties() {
|
||||
return this.appElasticProperties;
|
||||
}
|
||||
|
||||
public ElasticQueryHelperServiceProperties getElasticQueryHelperServiceProperties() {
|
||||
return this.elasticQueryHelperServiceProperties;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ public class AppElasticProperties {
|
|||
private boolean enableIcuAnalysisPlugin;
|
||||
|
||||
public String getDmpIndexName() {
|
||||
return dmpIndexName;
|
||||
return this.dmpIndexName;
|
||||
}
|
||||
|
||||
public void setDmpIndexName(String dmpIndexName) {
|
||||
|
@ -19,7 +19,7 @@ public class AppElasticProperties {
|
|||
}
|
||||
|
||||
public boolean isEnableIcuAnalysisPlugin() {
|
||||
return enableIcuAnalysisPlugin;
|
||||
return this.enableIcuAnalysisPlugin;
|
||||
}
|
||||
|
||||
public void setEnableIcuAnalysisPlugin(boolean enableIcuAnalysisPlugin) {
|
||||
|
@ -27,7 +27,7 @@ public class AppElasticProperties {
|
|||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
|
@ -35,7 +35,7 @@ public class AppElasticProperties {
|
|||
}
|
||||
|
||||
public String getDescriptionIndexName() {
|
||||
return descriptionIndexName;
|
||||
return this.descriptionIndexName;
|
||||
}
|
||||
|
||||
public void setDescriptionIndexName(String descriptionIndexName) {
|
||||
|
@ -43,7 +43,7 @@ public class AppElasticProperties {
|
|||
}
|
||||
|
||||
public int getResetBatchSize() {
|
||||
return resetBatchSize;
|
||||
return this.resetBatchSize;
|
||||
}
|
||||
|
||||
public void setResetBatchSize(int resetBatchSize) {
|
||||
|
|
|
@ -4,6 +4,7 @@ import gr.cite.tools.data.builder.BuilderFactory;
|
|||
import gr.cite.tools.data.query.QueryFactory;
|
||||
import gr.cite.tools.fieldset.BaseFieldSet;
|
||||
import gr.cite.tools.fieldset.FieldSet;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.opencdmp.authorization.AuthorizationFlags;
|
||||
import org.opencdmp.data.DescriptionEntity;
|
||||
import org.opencdmp.data.DmpEntity;
|
||||
|
@ -22,6 +23,7 @@ import org.opencdmp.query.DescriptionQuery;
|
|||
import org.opencdmp.query.DmpQuery;
|
||||
import org.opencdmp.query.lookup.DescriptionLookup;
|
||||
import org.opencdmp.query.lookup.DmpLookup;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
@ -30,14 +32,17 @@ import java.util.function.Function;
|
|||
|
||||
@Service
|
||||
public class ElasticQueryHelperServiceImpl implements ElasticQueryHelperService {
|
||||
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(ElasticQueryHelperServiceImpl.class));
|
||||
|
||||
private final QueryFactory queryFactory;
|
||||
private final BuilderFactory builderFactory;
|
||||
private final ElasticService elasticService;
|
||||
public ElasticQueryHelperServiceImpl(QueryFactory queryFactory, BuilderFactory builderFactory, ElasticService elasticService) {
|
||||
private final AppElasticConfiguration appElasticConfiguration;
|
||||
public ElasticQueryHelperServiceImpl(QueryFactory queryFactory, BuilderFactory builderFactory, ElasticService elasticService, AppElasticConfiguration appElasticConfiguration) {
|
||||
this.queryFactory = queryFactory;
|
||||
this.builderFactory = builderFactory;
|
||||
this.elasticService = elasticService;
|
||||
this.appElasticConfiguration = appElasticConfiguration;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -55,12 +60,25 @@ public class ElasticQueryHelperServiceImpl implements ElasticQueryHelperService
|
|||
private <M> QueryResult<M> collect(DmpLookup lookup, Function<List<DmpEntity>, List<M>> buildFunc, EnumSet<AuthorizationFlags> flags) {
|
||||
DmpQuery query = null;
|
||||
QueryResult<M> result = new QueryResult<>();
|
||||
boolean elasticFilterUsed = false;
|
||||
if (lookup.useElastic() && this.elasticService.enabled()){
|
||||
List<DmpElasticEntity> elasticResponse = lookup.enrichElastic(this.queryFactory).authorize(flags).collectAs(new BaseFieldSet().ensure(DmpElasticEntity._id));
|
||||
query = this.queryFactory.query(DmpQuery.class).authorize(flags).ids(elasticResponse.stream().map(DmpElasticEntity::getId).toList());
|
||||
query.setOrder(lookup.enrich(this.queryFactory).getOrder());
|
||||
if (lookup.getMetadata() != null && lookup.getMetadata().countAll) result.setCount(lookup.enrichElastic(this.queryFactory).authorize(flags).count());
|
||||
} else {
|
||||
try {
|
||||
List<DmpElasticEntity> elasticResponse = lookup.enrichElastic(this.queryFactory).authorize(flags).collectAs(new BaseFieldSet().ensure(DmpElasticEntity._id));
|
||||
query = this.queryFactory.query(DmpQuery.class).authorize(flags).ids(elasticResponse.stream().map(DmpElasticEntity::getId).toList());
|
||||
query.setOrder(lookup.enrich(this.queryFactory).getOrder());
|
||||
if (lookup.getMetadata() != null && lookup.getMetadata().countAll) result.setCount(lookup.enrichElastic(this.queryFactory).authorize(flags).count());
|
||||
elasticFilterUsed = true;
|
||||
} catch (Exception e){
|
||||
elasticFilterUsed = false;
|
||||
if (this.appElasticConfiguration.getElasticQueryHelperServiceProperties().getEnableDbFallback()) {
|
||||
logger.error(e.getMessage(), e);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!elasticFilterUsed) {
|
||||
query = lookup.enrich(this.queryFactory).disableTracking().authorize(flags);
|
||||
if (lookup.getMetadata() != null && lookup.getMetadata().countAll) result.setCount(query.count());
|
||||
}
|
||||
|
@ -74,10 +92,17 @@ public class ElasticQueryHelperServiceImpl implements ElasticQueryHelperService
|
|||
public long count(DmpLookup lookup, EnumSet<AuthorizationFlags> authorizationFlags) {
|
||||
EnumSet<AuthorizationFlags> flags = authorizationFlags == null ? EnumSet.of(AuthorizationFlags.None) : authorizationFlags;
|
||||
if (lookup.useElastic() && this.elasticService.enabled()){
|
||||
return lookup.enrichElastic(this.queryFactory).authorize(flags).count();
|
||||
} else {
|
||||
return lookup.enrich(this.queryFactory).authorize(flags).count();
|
||||
try {
|
||||
return lookup.enrichElastic(this.queryFactory).authorize(flags).count();
|
||||
} catch (Exception e){
|
||||
if (this.appElasticConfiguration.getElasticQueryHelperServiceProperties().getEnableDbFallback()) {
|
||||
logger.error(e.getMessage(), e);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
return lookup.enrich(this.queryFactory).authorize(flags).count();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -96,12 +121,26 @@ public class ElasticQueryHelperServiceImpl implements ElasticQueryHelperService
|
|||
private <M> QueryResult<M> collect(DescriptionLookup lookup, Function<List<DescriptionEntity>, List<M>> buildFunc, EnumSet<AuthorizationFlags> flags) {
|
||||
DescriptionQuery query = null;
|
||||
QueryResult<M> result = new QueryResult<>();
|
||||
boolean elasticFilterUsed = false;
|
||||
if (lookup.useElastic() && this.elasticService.enabled()){
|
||||
List<DescriptionElasticEntity> elasticResponse = lookup.enrichElastic(this.queryFactory).authorize(flags).collectAs(new BaseFieldSet().ensure(DescriptionElasticEntity._id));
|
||||
query = this.queryFactory.query(DescriptionQuery.class).authorize(flags).ids(elasticResponse.stream().map(DescriptionElasticEntity::getId).toList());
|
||||
query.setOrder(lookup.enrich(this.queryFactory).getOrder());
|
||||
if (lookup.getMetadata() != null && lookup.getMetadata().countAll) result.setCount(lookup.enrichElastic(this.queryFactory).authorize(flags).count());
|
||||
} else {
|
||||
|
||||
try {
|
||||
List<DescriptionElasticEntity> elasticResponse = lookup.enrichElastic(this.queryFactory).authorize(flags).collectAs(new BaseFieldSet().ensure(DescriptionElasticEntity._id));
|
||||
query = this.queryFactory.query(DescriptionQuery.class).authorize(flags).ids(elasticResponse.stream().map(DescriptionElasticEntity::getId).toList());
|
||||
query.setOrder(lookup.enrich(this.queryFactory).getOrder());
|
||||
if (lookup.getMetadata() != null && lookup.getMetadata().countAll) result.setCount(lookup.enrichElastic(this.queryFactory).authorize(flags).count());
|
||||
elasticFilterUsed = true;
|
||||
} catch (Exception e){
|
||||
elasticFilterUsed = false;
|
||||
if (this.appElasticConfiguration.getElasticQueryHelperServiceProperties().getEnableDbFallback()) {
|
||||
logger.error(e.getMessage(), e);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if (!elasticFilterUsed) {
|
||||
query = lookup.enrich(this.queryFactory).disableTracking().authorize(flags);
|
||||
if (lookup.getMetadata() != null && lookup.getMetadata().countAll) result.setCount(query.count());
|
||||
}
|
||||
|
@ -115,9 +154,16 @@ public class ElasticQueryHelperServiceImpl implements ElasticQueryHelperService
|
|||
public long count(DescriptionLookup lookup, EnumSet<AuthorizationFlags> authorizationFlags) {
|
||||
EnumSet<AuthorizationFlags> flags = authorizationFlags == null ? EnumSet.of(AuthorizationFlags.None) : authorizationFlags;
|
||||
if (lookup.useElastic() && this.elasticService.enabled()){
|
||||
return lookup.enrichElastic(this.queryFactory).authorize(flags).count();
|
||||
} else {
|
||||
return lookup.enrich(this.queryFactory).authorize(flags).count();
|
||||
}
|
||||
try {
|
||||
return lookup.enrichElastic(this.queryFactory).authorize(flags).count();
|
||||
} catch (Exception e){
|
||||
if (this.appElasticConfiguration.getElasticQueryHelperServiceProperties().getEnableDbFallback()) {
|
||||
logger.error(e.getMessage(), e);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
return lookup.enrich(this.queryFactory).authorize(flags).count();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package org.opencdmp.service.elastic;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
@ConfigurationProperties(prefix = "elastic-query-helper")
|
||||
public class ElasticQueryHelperServiceProperties {
|
||||
private boolean enableDbFallback;
|
||||
|
||||
public boolean getEnableDbFallback() {
|
||||
return this.enableDbFallback;
|
||||
}
|
||||
|
||||
public void setEnableDbFallback(boolean enableDbFallback) {
|
||||
this.enableDbFallback = enableDbFallback;
|
||||
}
|
||||
}
|
|
@ -46,7 +46,7 @@ import java.util.Map;
|
|||
@Service
|
||||
public class ElasticServiceImpl implements ElasticService {
|
||||
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DmpBlueprintServiceImpl.class));
|
||||
public final AppElasticProperties appElasticProperties;
|
||||
public final AppElasticConfiguration appElasticConfiguration;
|
||||
private final ElasticsearchClient restHighLevelClient;
|
||||
private final ElasticsearchTemplate elasticsearchTemplate;
|
||||
private final QueryFactory queryFactory;
|
||||
|
@ -55,8 +55,8 @@ public class ElasticServiceImpl implements ElasticService {
|
|||
private final MessageSource messageSource;
|
||||
private final AuthorizationService authorizationService;
|
||||
|
||||
public ElasticServiceImpl(AppElasticProperties appElasticProperties, ElasticsearchClient restHighLevelClient, ElasticsearchTemplate elasticsearchTemplate, QueryFactory queryFactory, BuilderFactory builderFactory, TenantEntityManager entityManager, MessageSource messageSource, AuthorizationService authorizationService) {
|
||||
this.appElasticProperties = appElasticProperties;
|
||||
public ElasticServiceImpl(AppElasticConfiguration appElasticConfiguration, ElasticsearchClient restHighLevelClient, ElasticsearchTemplate elasticsearchTemplate, QueryFactory queryFactory, BuilderFactory builderFactory, TenantEntityManager entityManager, MessageSource messageSource, AuthorizationService authorizationService) {
|
||||
this.appElasticConfiguration = appElasticConfiguration;
|
||||
this.restHighLevelClient = restHighLevelClient;
|
||||
this.elasticsearchTemplate = elasticsearchTemplate;
|
||||
this.queryFactory = queryFactory;
|
||||
|
@ -68,20 +68,20 @@ public class ElasticServiceImpl implements ElasticService {
|
|||
|
||||
@Override
|
||||
public boolean enabled() {
|
||||
return this.appElasticProperties.isEnabled();
|
||||
return this.appElasticConfiguration.getAppElasticProperties().isEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean existsDmpIndex() throws IOException {
|
||||
if (!this.enabled()) return false;
|
||||
return this.restHighLevelClient.indices().exists(new ExistsRequest.Builder().index(this.appElasticProperties.getDmpIndexName()).includeDefaults(true).build()).value();
|
||||
return this.restHighLevelClient.indices().exists(new ExistsRequest.Builder().index(this.appElasticConfiguration.getAppElasticProperties().getDmpIndexName()).includeDefaults(true).build()).value();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean existsDescriptionIndex() throws IOException {
|
||||
if (!this.enabled()) return false;
|
||||
return this.restHighLevelClient.indices().exists(new ExistsRequest.Builder().index(this.appElasticProperties.getDescriptionIndexName()).includeDefaults(true).build()).value();
|
||||
return this.restHighLevelClient.indices().exists(new ExistsRequest.Builder().index(this.appElasticConfiguration.getAppElasticProperties().getDescriptionIndexName()).includeDefaults(true).build()).value();
|
||||
}
|
||||
|
||||
//region ensure index
|
||||
|
@ -92,7 +92,7 @@ public class ElasticServiceImpl implements ElasticService {
|
|||
boolean exists = this.existsDmpIndex();
|
||||
if (exists) return ;
|
||||
|
||||
this.ensureIndex(this.appElasticProperties.getDmpIndexName(), this.createDmpTemplatePropertyMap());
|
||||
this.ensureIndex(this.appElasticConfiguration.getAppElasticProperties().getDmpIndexName(), this.createDmpTemplatePropertyMap());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -100,7 +100,7 @@ public class ElasticServiceImpl implements ElasticService {
|
|||
if (!this.enabled()) return ;
|
||||
boolean exists = this.existsDescriptionIndex();
|
||||
if (exists) return ;
|
||||
this.ensureIndex(this.appElasticProperties.getDescriptionIndexName(), this.createDescriptionTemplatePropertyMap());
|
||||
this.ensureIndex(this.appElasticConfiguration.getAppElasticProperties().getDescriptionIndexName(), this.createDescriptionTemplatePropertyMap());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -120,7 +120,7 @@ public class ElasticServiceImpl implements ElasticService {
|
|||
indexSettingsAnalysis.filter("english_stemmer", ((tf) -> tf.definition(tfdb -> tfdb.stemmer(stemmerBuilder -> stemmerBuilder.language("english")))))
|
||||
.filter("english_stop", tf -> tf.definition(tfdb -> tfdb.stop(stopTokenBuilder -> stopTokenBuilder)));
|
||||
|
||||
if (this.appElasticProperties.isEnableIcuAnalysisPlugin()){
|
||||
if (this.appElasticConfiguration.getAppElasticProperties().isEnableIcuAnalysisPlugin()){
|
||||
indexSettingsAnalysis.analyzer("icu_analyzer_text", ab -> ab.custom(x-> x.filter("icu_folding", "english_stop", "english_stemmer").tokenizer("icu_tokenizer")));
|
||||
} else {
|
||||
indexSettingsAnalysis.analyzer("icu_analyzer_text", ab -> ab.custom(x-> x.filter("icu_folding", "english_stop", "english_stemmer").tokenizer("standard")));
|
||||
|
@ -291,23 +291,23 @@ public class ElasticServiceImpl implements ElasticService {
|
|||
this.ensureIndexes();
|
||||
|
||||
DmpElasticEntity dmpElasticEntity = this.builderFactory.builder(DmpElasticBuilder.class).build(dmp);
|
||||
this.elasticsearchTemplate.save(dmpElasticEntity, IndexCoordinates.of(this.appElasticProperties.getDmpIndexName()));
|
||||
this.elasticsearchTemplate.save(dmpElasticEntity, IndexCoordinates.of(this.appElasticConfiguration.getAppElasticProperties().getDmpIndexName()));
|
||||
List<DescriptionElasticEntity> descriptions = this.builderFactory.builder(DescriptionElasticBuilder.class).build(this.queryFactory.query(DescriptionQuery.class).disableTracking().isActive(IsActive.Active).dmpSubQuery(this.queryFactory.query(DmpQuery.class).ids(dmp.getId())).collect());
|
||||
this.elasticsearchTemplate.save(descriptions, IndexCoordinates.of(this.appElasticProperties.getDescriptionIndexName()));
|
||||
this.elasticsearchTemplate.save(descriptions, IndexCoordinates.of(this.appElasticConfiguration.getAppElasticProperties().getDescriptionIndexName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteDmp(DmpEntity dmp) throws IOException {
|
||||
if (!this.enabled()) return;
|
||||
this.ensureIndexes();
|
||||
DmpElasticEntity dmpElasticEntity = this.elasticsearchTemplate.get(dmp.getId().toString(),DmpElasticEntity.class, IndexCoordinates.of(this.appElasticProperties.getDmpIndexName()));
|
||||
DmpElasticEntity dmpElasticEntity = this.elasticsearchTemplate.get(dmp.getId().toString(),DmpElasticEntity.class, IndexCoordinates.of(this.appElasticConfiguration.getAppElasticProperties().getDmpIndexName()));
|
||||
if (dmpElasticEntity == null) return;
|
||||
this.elasticsearchTemplate.delete(dmpElasticEntity, IndexCoordinates.of(this.appElasticProperties.getDmpIndexName()));
|
||||
this.elasticsearchTemplate.delete(dmpElasticEntity, IndexCoordinates.of(this.appElasticConfiguration.getAppElasticProperties().getDmpIndexName()));
|
||||
List<DescriptionEntity> descriptions = this.queryFactory.query(DescriptionQuery.class).dmpSubQuery(this.queryFactory.query(DmpQuery.class).disableTracking().ids(dmp.getId())).collectAs(new BaseFieldSet().ensure(Description._id));
|
||||
for (DescriptionEntity description: descriptions) {
|
||||
DescriptionElasticEntity descriptionElasticEntity = this.elasticsearchTemplate.get(description.getId().toString(), DescriptionElasticEntity.class, IndexCoordinates.of(this.appElasticProperties.getDescriptionIndexName()));
|
||||
DescriptionElasticEntity descriptionElasticEntity = this.elasticsearchTemplate.get(description.getId().toString(), DescriptionElasticEntity.class, IndexCoordinates.of(this.appElasticConfiguration.getAppElasticProperties().getDescriptionIndexName()));
|
||||
if (descriptionElasticEntity == null) continue;
|
||||
this.elasticsearchTemplate.delete(descriptionElasticEntity, IndexCoordinates.of(this.appElasticProperties.getDescriptionIndexName()));
|
||||
this.elasticsearchTemplate.delete(descriptionElasticEntity, IndexCoordinates.of(this.appElasticConfiguration.getAppElasticProperties().getDescriptionIndexName()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -317,12 +317,12 @@ public class ElasticServiceImpl implements ElasticService {
|
|||
this.ensureIndexes();
|
||||
|
||||
DescriptionElasticEntity descriptionElasticEntity = this.builderFactory.builder(DescriptionElasticBuilder.class).build(description);
|
||||
this.elasticsearchTemplate.save(descriptionElasticEntity, IndexCoordinates.of(this.appElasticProperties.getDescriptionIndexName()));
|
||||
this.elasticsearchTemplate.save(descriptionElasticEntity, IndexCoordinates.of(this.appElasticConfiguration.getAppElasticProperties().getDescriptionIndexName()));
|
||||
DmpEntity dmpEntity = this.entityManager.find(DmpEntity.class, description.getDmpId(), true);
|
||||
if (dmpEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{description.getDmpId(), Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
||||
if (dmpEntity.getIsActive().equals(IsActive.Active)) {
|
||||
DmpElasticEntity dmpElasticEntity = this.builderFactory.builder(DmpElasticBuilder.class).build(dmpEntity);
|
||||
this.elasticsearchTemplate.save(dmpElasticEntity, IndexCoordinates.of(this.appElasticProperties.getDmpIndexName()));
|
||||
this.elasticsearchTemplate.save(dmpElasticEntity, IndexCoordinates.of(this.appElasticConfiguration.getAppElasticProperties().getDmpIndexName()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -331,15 +331,15 @@ public class ElasticServiceImpl implements ElasticService {
|
|||
if (!this.enabled()) return;
|
||||
this.ensureIndexes();
|
||||
|
||||
DescriptionElasticEntity descriptionElasticEntity = this.elasticsearchTemplate.get(description.getId().toString(), DescriptionElasticEntity.class, IndexCoordinates.of(this.appElasticProperties.getDescriptionIndexName()));
|
||||
DescriptionElasticEntity descriptionElasticEntity = this.elasticsearchTemplate.get(description.getId().toString(), DescriptionElasticEntity.class, IndexCoordinates.of(this.appElasticConfiguration.getAppElasticProperties().getDescriptionIndexName()));
|
||||
if (descriptionElasticEntity == null) return;
|
||||
this.elasticsearchTemplate.delete(descriptionElasticEntity, IndexCoordinates.of(this.appElasticProperties.getDescriptionIndexName()));
|
||||
this.elasticsearchTemplate.delete(descriptionElasticEntity, IndexCoordinates.of(this.appElasticConfiguration.getAppElasticProperties().getDescriptionIndexName()));
|
||||
|
||||
DmpEntity dmpEntity = this.entityManager.find(DmpEntity.class, description.getDmpId(), true);
|
||||
if (dmpEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{description.getDmpId(), Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
||||
if (dmpEntity.getIsActive().equals(IsActive.Active)) {
|
||||
DmpElasticEntity dmpElasticEntity = this.builderFactory.builder(DmpElasticBuilder.class).build(dmpEntity);
|
||||
this.elasticsearchTemplate.save(dmpElasticEntity, IndexCoordinates.of(this.appElasticProperties.getDmpIndexName()));
|
||||
this.elasticsearchTemplate.save(dmpElasticEntity, IndexCoordinates.of(this.appElasticConfiguration.getAppElasticProperties().getDmpIndexName()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -356,7 +356,7 @@ public class ElasticServiceImpl implements ElasticService {
|
|||
boolean exists = this.existsDmpIndex();
|
||||
if (!exists) return ;
|
||||
|
||||
this.restHighLevelClient.indices().delete(new DeleteIndexRequest.Builder().index(this.appElasticProperties.getDmpIndexName()).build());
|
||||
this.restHighLevelClient.indices().delete(new DeleteIndexRequest.Builder().index(this.appElasticConfiguration.getAppElasticProperties().getDmpIndexName()).build());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -367,7 +367,7 @@ public class ElasticServiceImpl implements ElasticService {
|
|||
if (!this.enabled()) return;
|
||||
boolean exists = this.existsDescriptionIndex();
|
||||
if (!exists) return ;
|
||||
this.restHighLevelClient.indices().delete(new DeleteIndexRequest.Builder().index(this.appElasticProperties.getDescriptionIndexName()).build());
|
||||
this.restHighLevelClient.indices().delete(new DeleteIndexRequest.Builder().index(this.appElasticConfiguration.getAppElasticProperties().getDescriptionIndexName()).build());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -382,7 +382,7 @@ public class ElasticServiceImpl implements ElasticService {
|
|||
try {
|
||||
this.entityManager.disableTenantFilters();
|
||||
int page = 0;
|
||||
int pageSize = this.appElasticProperties.getResetBatchSize();
|
||||
int pageSize = this.appElasticConfiguration.getAppElasticProperties().getResetBatchSize();
|
||||
List<DmpEntity> items;
|
||||
do {
|
||||
DmpQuery query = this.queryFactory.query(DmpQuery.class).disableTracking();
|
||||
|
@ -392,7 +392,7 @@ public class ElasticServiceImpl implements ElasticService {
|
|||
items = query.collect();
|
||||
if (items != null && !items.isEmpty()) {
|
||||
List<DmpElasticEntity> elasticEntities = this.builderFactory.builder(DmpElasticBuilder.class).build(items);
|
||||
this.elasticsearchTemplate.save(elasticEntities, IndexCoordinates.of(this.appElasticProperties.getDmpIndexName()));
|
||||
this.elasticsearchTemplate.save(elasticEntities, IndexCoordinates.of(this.appElasticConfiguration.getAppElasticProperties().getDmpIndexName()));
|
||||
page++;
|
||||
}
|
||||
} while (items != null && !items.isEmpty());
|
||||
|
@ -414,7 +414,7 @@ public class ElasticServiceImpl implements ElasticService {
|
|||
this.entityManager.disableTenantFilters();
|
||||
|
||||
int page = 0;
|
||||
int pageSize = this.appElasticProperties.getResetBatchSize();
|
||||
int pageSize = this.appElasticConfiguration.getAppElasticProperties().getResetBatchSize();
|
||||
List<DescriptionEntity> items;
|
||||
do {
|
||||
DescriptionQuery query = this.queryFactory.query(DescriptionQuery.class).disableTracking();
|
||||
|
@ -424,7 +424,7 @@ public class ElasticServiceImpl implements ElasticService {
|
|||
items = query.collect();
|
||||
if (items != null && !items.isEmpty()) {
|
||||
List<DescriptionElasticEntity> elasticEntities = this.builderFactory.builder(DescriptionElasticBuilder.class).build(items);
|
||||
this.elasticsearchTemplate.save(elasticEntities, IndexCoordinates.of(this.appElasticProperties.getDescriptionIndexName()));
|
||||
this.elasticsearchTemplate.save(elasticEntities, IndexCoordinates.of(this.appElasticConfiguration.getAppElasticProperties().getDescriptionIndexName()));
|
||||
page++;
|
||||
}
|
||||
} while (items != null && !items.isEmpty());
|
||||
|
|
|
@ -3,4 +3,6 @@ elastic:
|
|||
serverCertificatePaths:
|
||||
- classpath:certificates/elasticsearch_dev04.crt
|
||||
app-elastic:
|
||||
enableIcuAnalysisPlugin: true
|
||||
enableIcuAnalysisPlugin: true
|
||||
elastic-query-helper:
|
||||
enableDbFallback: false
|
|
@ -19,3 +19,5 @@ app-elastic:
|
|||
descriptionIndexName: ${ELASTIC_DESCRIPTION_INDEX}
|
||||
enableIcuAnalysisPlugin: false
|
||||
resetBatchSize: 1000
|
||||
elastic-query-helper:
|
||||
enableDbFallback: true
|
|
@ -50,13 +50,19 @@ export class UserListingFiltersComponent extends BaseComponent implements OnInit
|
|||
}
|
||||
|
||||
protected applyFilters(): void {
|
||||
const { isActive, like, userRoleSubQuery } = this.internalFilters ?? {}
|
||||
this.filterChange.emit({
|
||||
const { isActive, like, userRoleSubQuery } = this.internalFilters ?? {};
|
||||
let filter = {
|
||||
...this.filter,
|
||||
like,
|
||||
isActive: isActive ? [IsActive.Active] : [IsActive.Inactive],
|
||||
userRoleSubQuery
|
||||
})
|
||||
}
|
||||
if (userRoleSubQuery && userRoleSubQuery.roles != null && userRoleSubQuery.roles.length > 0) {
|
||||
filter = {
|
||||
...filter,
|
||||
userRoleSubQuery
|
||||
}
|
||||
}
|
||||
this.filterChange.emit(filter);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -265,6 +265,12 @@ public class DatasetMigrationService {
|
|||
|
||||
this.entityManager.flush();
|
||||
|
||||
this.sortFieldSets(propertyDefinitionEntity, createdDescriptionReferenceEntities);
|
||||
|
||||
return propertyDefinitionEntity;
|
||||
}
|
||||
|
||||
private void sortFieldSets(PropertyDefinitionEntity propertyDefinitionEntity, List<DescriptionReferenceEntity> createdDescriptionReferenceEntities){
|
||||
Map<UUID, DescriptionReferenceEntity> descriptionReferenceEntitiesMap = createdDescriptionReferenceEntities.stream().collect(Collectors.toMap(DescriptionReferenceEntity::getId, x-> x));
|
||||
Map<UUID, DescriptionReferenceDataEntity> descriptionReferenceDataEntityById = new HashMap<>();
|
||||
for (DescriptionReferenceEntity descriptionReferenceEntity : createdDescriptionReferenceEntities){
|
||||
|
@ -272,28 +278,24 @@ public class DatasetMigrationService {
|
|||
if (propertyDefinition != null) descriptionReferenceDataEntityById.put(descriptionReferenceEntity.getId(), propertyDefinition);
|
||||
}
|
||||
for (PropertyDefinitionFieldSetEntity fieldSetEntity : propertyDefinitionEntity.getFieldSets().values()){
|
||||
int newOrdinal = 0;
|
||||
PropertyDefinitionFieldSetItemEntity firstFieldSet = fieldSetEntity.getItems().stream().findFirst().filter(x-> x.getOrdinal() == SimpleFieldSetOrdinal).orElse(null);
|
||||
if (firstFieldSet != null){
|
||||
this.ensureDescriptionReferenceOrdinal(firstFieldSet, descriptionReferenceEntitiesMap, descriptionReferenceDataEntityById, newOrdinal);
|
||||
firstFieldSet.setOrdinal(newOrdinal);
|
||||
newOrdinal++;
|
||||
|
||||
}
|
||||
for (PropertyDefinitionFieldSetItemEntity propertyDefinitionFieldSetItemEntity : fieldSetEntity.getItems().stream().filter(x-> x.getOrdinal() >= 0 && x.getOrdinal() != SimpleFieldSetOrdinal).sorted(Comparator.comparingInt(PropertyDefinitionFieldSetItemEntity::getOrdinal)).toList()){
|
||||
this.ensureDescriptionReferenceOrdinal(propertyDefinitionFieldSetItemEntity, descriptionReferenceEntitiesMap, descriptionReferenceDataEntityById, newOrdinal);
|
||||
propertyDefinitionFieldSetItemEntity.setOrdinal(newOrdinal);
|
||||
newOrdinal++;
|
||||
LinkedList<PropertyDefinitionFieldSetItemEntity> sortedPropertyDefinitionFieldSetItemEntities = new LinkedList<>();
|
||||
fieldSetEntity.getItems().stream().findFirst().filter(x -> x.getOrdinal() == SimpleFieldSetOrdinal).ifPresent(sortedPropertyDefinitionFieldSetItemEntities::addLast);
|
||||
|
||||
for (PropertyDefinitionFieldSetItemEntity propertyDefinitionFieldSetItemEntity : fieldSetEntity.getItems().stream().filter(x-> x.getOrdinal() >= 0 && x.getOrdinal() != SimpleFieldSetOrdinal).sorted(Comparator.comparingInt(PropertyDefinitionFieldSetItemEntity::getOrdinal)).toList()){
|
||||
sortedPropertyDefinitionFieldSetItemEntities.addLast(propertyDefinitionFieldSetItemEntity);
|
||||
}
|
||||
for (PropertyDefinitionFieldSetItemEntity propertyDefinitionFieldSetItemEntity : fieldSetEntity.getItems().stream().filter(x-> x.getOrdinal() < 0 && x.getOrdinal() != SimpleFieldSetOrdinal).sorted(Comparator.comparingInt(PropertyDefinitionFieldSetItemEntity::getOrdinal)).toList()){
|
||||
this.ensureDescriptionReferenceOrdinal(propertyDefinitionFieldSetItemEntity, descriptionReferenceEntitiesMap, descriptionReferenceDataEntityById, newOrdinal);
|
||||
propertyDefinitionFieldSetItemEntity.setOrdinal(newOrdinal);
|
||||
newOrdinal++;
|
||||
sortedPropertyDefinitionFieldSetItemEntities.addLast(propertyDefinitionFieldSetItemEntity);
|
||||
}
|
||||
|
||||
for (int ordinal = 0; ordinal < sortedPropertyDefinitionFieldSetItemEntities.size(); ordinal++){
|
||||
PropertyDefinitionFieldSetItemEntity fieldSet = sortedPropertyDefinitionFieldSetItemEntities.get(ordinal);
|
||||
this.ensureDescriptionReferenceOrdinal(fieldSet, descriptionReferenceEntitiesMap, descriptionReferenceDataEntityById, ordinal);
|
||||
fieldSet.setOrdinal(ordinal);
|
||||
}
|
||||
}
|
||||
|
||||
this.entityManager.flush();
|
||||
return propertyDefinitionEntity;
|
||||
}
|
||||
|
||||
private void ensureDescriptionReferenceOrdinal(PropertyDefinitionFieldSetItemEntity propertyDefinitionFieldSetItemEntity, Map<UUID, DescriptionReferenceEntity> descriptionReferenceEntitiesMap, Map<UUID, DescriptionReferenceDataEntity> descriptionReferenceDataEntityById, int newOrdinal){
|
||||
|
|
Loading…
Reference in New Issue