elastic changes
This commit is contained in:
parent
34ce4f6928
commit
f0264eefb9
|
@ -51,3 +51,4 @@ openDMP/dmp-backend/uploads/
|
|||
openDMP/dmp-backend/tmp/
|
||||
storage/
|
||||
logs/
|
||||
dmp-backend/web/src/main/resources/certificates/
|
||||
|
|
|
@ -39,6 +39,11 @@
|
|||
<groupId>gr.cite.opendmp</groupId>
|
||||
<artifactId>repositorydepositbase</artifactId>
|
||||
<version>1.0.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>gr.cite</groupId>
|
||||
<artifactId>elastic</artifactId>
|
||||
<version>2.1.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.angus</groupId>
|
||||
|
@ -52,8 +57,8 @@
|
|||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>17</source>
|
||||
<target>17</target>
|
||||
<source>21</source>
|
||||
<target>21</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
package eu.eudat.configurations.elastic;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(AppElasticProperties.class)
|
||||
public class AppElasticConfiguration {
|
||||
private final AppElasticProperties properties;
|
||||
|
||||
@Autowired
|
||||
public AppElasticConfiguration(AppElasticProperties properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
public AppElasticProperties getProperties() {
|
||||
return properties;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package eu.eudat.configurations.elastic;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
@ConfigurationProperties(prefix = "app-elastic")
|
||||
public class AppElasticProperties {
|
||||
private boolean enabled;
|
||||
private String dmpIndexName;
|
||||
private String descriptionIndexName;
|
||||
private boolean enableIcuAnalysisPlugin;
|
||||
|
||||
public String getDmpIndexName() {
|
||||
return dmpIndexName;
|
||||
}
|
||||
|
||||
public void setDmpIndexName(String dmpIndexName) {
|
||||
this.dmpIndexName = dmpIndexName;
|
||||
}
|
||||
|
||||
public boolean isEnableIcuAnalysisPlugin() {
|
||||
return enableIcuAnalysisPlugin;
|
||||
}
|
||||
|
||||
public void setEnableIcuAnalysisPlugin(boolean enableIcuAnalysisPlugin) {
|
||||
this.enableIcuAnalysisPlugin = enableIcuAnalysisPlugin;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public String getDescriptionIndexName() {
|
||||
return descriptionIndexName;
|
||||
}
|
||||
|
||||
public void setDescriptionIndexName(String descriptionIndexName) {
|
||||
this.descriptionIndexName = descriptionIndexName;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package eu.eudat.elastic;
|
||||
|
||||
|
||||
import eu.eudat.elastic.converter.*;
|
||||
import gr.cite.tools.elastic.configuration.AbstractElasticConfiguration;
|
||||
import gr.cite.tools.elastic.configuration.ElasticCertificateProvider;
|
||||
import gr.cite.tools.elastic.configuration.ElasticProperties;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.elasticsearch.core.convert.ElasticsearchCustomConversions;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(ElasticProperties.class)
|
||||
@ConditionalOnProperty(prefix = "elastic", name = "enabled", matchIfMissing = false)
|
||||
public class ElasticConfiguration extends AbstractElasticConfiguration {
|
||||
|
||||
public ElasticConfiguration(ApplicationContext applicationContext, ElasticProperties elasticProperties, ElasticCertificateProvider elasticCertificateProvider) {
|
||||
super(elasticProperties, elasticCertificateProvider);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Override
|
||||
public ElasticsearchCustomConversions elasticsearchCustomConversions() {
|
||||
return new ElasticsearchCustomConversions(
|
||||
List.of(
|
||||
new DmpUserRoleToShortConverter(),
|
||||
new DescriptionStatusToShortConverter(),
|
||||
new DmpStatusToShortConverter(),
|
||||
new IsActiveToShortConverter(),
|
||||
new DmpAccessTypeToShortConverter()
|
||||
));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package eu.eudat.elastic.converter;
|
||||
|
||||
import eu.eudat.commons.enums.DescriptionStatus;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.data.convert.WritingConverter;
|
||||
|
||||
@WritingConverter
|
||||
public class DescriptionStatusToShortConverter implements Converter<DescriptionStatus, Short> {
|
||||
@Override
|
||||
public Short convert(DescriptionStatus source) {
|
||||
return source.getValue();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package eu.eudat.elastic.converter;
|
||||
|
||||
import eu.eudat.commons.enums.DmpAccessType;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.data.convert.WritingConverter;
|
||||
|
||||
@WritingConverter
|
||||
public class DmpAccessTypeToShortConverter implements Converter<DmpAccessType, Short> {
|
||||
@Override
|
||||
public Short convert(DmpAccessType source) {
|
||||
return source.getValue();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package eu.eudat.elastic.converter;
|
||||
|
||||
import eu.eudat.commons.enums.DescriptionStatus;
|
||||
import eu.eudat.commons.enums.DmpStatus;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.data.convert.WritingConverter;
|
||||
|
||||
@WritingConverter
|
||||
public class DmpStatusToShortConverter implements Converter<DmpStatus, Short> {
|
||||
@Override
|
||||
public Short convert(DmpStatus source) {
|
||||
return source.getValue();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package eu.eudat.elastic.converter;
|
||||
|
||||
import eu.eudat.commons.enums.DmpUserRole;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.data.convert.WritingConverter;
|
||||
|
||||
@WritingConverter
|
||||
public class DmpUserRoleToShortConverter implements Converter<DmpUserRole, Short> {
|
||||
@Override
|
||||
public Short convert(DmpUserRole source) {
|
||||
return source.getValue();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package eu.eudat.elastic.converter;
|
||||
|
||||
import eu.eudat.commons.enums.DmpStatus;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.data.convert.WritingConverter;
|
||||
|
||||
@WritingConverter
|
||||
public class IsActiveToShortConverter implements Converter<DmpStatus, Short> {
|
||||
@Override
|
||||
public Short convert(DmpStatus source) {
|
||||
return source.getValue();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,126 @@
|
|||
package eu.eudat.elastic.data;
|
||||
|
||||
import eu.eudat.commons.enums.DescriptionStatus;
|
||||
import eu.eudat.elastic.data.nested.*;
|
||||
import gr.cite.tools.elastic.ElasticConstants;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.elasticsearch.annotations.*;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Document(indexName = "description")
|
||||
public class DescriptionElasticEntity {
|
||||
|
||||
@Id
|
||||
@Field(value = DescriptionElasticEntity._id, type = FieldType.Keyword)
|
||||
private UUID id;
|
||||
public final static String _id = "id";
|
||||
|
||||
@MultiField(mainField = @Field(value = DescriptionElasticEntity._label, type = FieldType.Text), otherFields = {
|
||||
@InnerField(suffix = ElasticConstants.SubFields.keyword, type = FieldType.Keyword)
|
||||
})
|
||||
private String label;
|
||||
public final static String _label = "label";
|
||||
|
||||
@Field(value = DescriptionElasticEntity._description, type = FieldType.Text)
|
||||
private String description;
|
||||
public final static String _description = "description";
|
||||
|
||||
@Field(value = DescriptionElasticEntity._status, type = FieldType.Short)
|
||||
private DescriptionStatus status;
|
||||
public final static String _status = "status";
|
||||
|
||||
@Field(value = DescriptionElasticEntity._finalizedAt, type = FieldType.Date)
|
||||
private Date finalizedAt;
|
||||
public final static String _finalizedAt = "finalizedAt";
|
||||
|
||||
@Field(value = DescriptionElasticEntity._tags, type = FieldType.Nested)
|
||||
private List<NestedTagElasticEntity> tags;
|
||||
public final static String _tags = "tags";
|
||||
|
||||
@Field(value = DescriptionElasticEntity._descriptionTemplate, type = FieldType.Object)
|
||||
private NestedDescriptionTemplateElasticEntity descriptionTemplate;
|
||||
public final static String _descriptionTemplate = "descriptionTemplate";
|
||||
|
||||
@Field(value = DescriptionElasticEntity._dmp, type = FieldType.Object)
|
||||
private NestedDmpElasticEntity dmp;
|
||||
public final static String _dmp = "dmp";
|
||||
|
||||
@Field(value = DescriptionElasticEntity._references, type = FieldType.Nested)
|
||||
private List<NestedReferenceElasticEntity> references;
|
||||
public final static String _references = "references";
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public DescriptionStatus getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(DescriptionStatus status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public Date getFinalizedAt() {
|
||||
return finalizedAt;
|
||||
}
|
||||
|
||||
public void setFinalizedAt(Date finalizedAt) {
|
||||
this.finalizedAt = finalizedAt;
|
||||
}
|
||||
|
||||
public List<NestedTagElasticEntity> getTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
public void setTags(List<NestedTagElasticEntity> tags) {
|
||||
this.tags = tags;
|
||||
}
|
||||
|
||||
public NestedDescriptionTemplateElasticEntity getDescriptionTemplate() {
|
||||
return descriptionTemplate;
|
||||
}
|
||||
|
||||
public void setDescriptionTemplate(NestedDescriptionTemplateElasticEntity descriptionTemplate) {
|
||||
this.descriptionTemplate = descriptionTemplate;
|
||||
}
|
||||
|
||||
public NestedDmpElasticEntity getDmp() {
|
||||
return dmp;
|
||||
}
|
||||
|
||||
public void setDmp(NestedDmpElasticEntity dmp) {
|
||||
this.dmp = dmp;
|
||||
}
|
||||
|
||||
public List<NestedReferenceElasticEntity> getReferences() {
|
||||
return references;
|
||||
}
|
||||
|
||||
public void setReferences(List<NestedReferenceElasticEntity> references) {
|
||||
this.references = references;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,198 @@
|
|||
package eu.eudat.elastic.data;
|
||||
|
||||
import eu.eudat.commons.enums.DmpAccessType;
|
||||
import eu.eudat.commons.enums.DmpStatus;
|
||||
import eu.eudat.elastic.data.nested.*;
|
||||
import gr.cite.tools.elastic.ElasticConstants;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.elasticsearch.annotations.*;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Document(indexName = "dmp")
|
||||
public class DmpElasticEntity {
|
||||
@Id
|
||||
@Field(value = DmpElasticEntity._id, type = FieldType.Keyword)
|
||||
private UUID id;
|
||||
public final static String _id = "id";
|
||||
|
||||
@MultiField(mainField = @Field(value = DmpElasticEntity._label, type = FieldType.Text), otherFields = {
|
||||
@InnerField(suffix = ElasticConstants.SubFields.keyword, type = FieldType.Keyword)
|
||||
})
|
||||
private String label;
|
||||
public final static String _label = "label";
|
||||
|
||||
@Field(value = DmpElasticEntity._description, type = FieldType.Text)
|
||||
private String description;
|
||||
public final static String _description = "description";
|
||||
|
||||
@Field(value = DmpElasticEntity._version, type = FieldType.Keyword)
|
||||
private Short version;
|
||||
public final static String _version = "version";
|
||||
|
||||
@Field(value = DmpElasticEntity._status, type = FieldType.Short)
|
||||
private DmpStatus status;
|
||||
public final static String _status = "status";
|
||||
|
||||
@Field(value = DmpElasticEntity._accessType, type = FieldType.Short)
|
||||
private DmpAccessType accessType;
|
||||
public final static String _accessType = "accessType";
|
||||
|
||||
@Field(value = DmpElasticEntity._language, type = FieldType.Keyword)
|
||||
private String language;
|
||||
public final static String _language = "language";
|
||||
|
||||
@Field(value = DmpElasticEntity._blueprintId, type = FieldType.Keyword)
|
||||
private UUID blueprintId;
|
||||
public final static String _blueprintId = "blueprintId";
|
||||
|
||||
@Field(value = DmpElasticEntity._groupId, type = FieldType.Keyword)
|
||||
private UUID groupId;
|
||||
public final static String _groupId = "groupId";
|
||||
|
||||
@Field(value = DmpElasticEntity._finalizedAt, type = FieldType.Date)
|
||||
private Date finalizedAt;
|
||||
public final static String _finalizedAt = "finalizedAt";
|
||||
|
||||
@Field(value = DmpElasticEntity._references, type = FieldType.Nested)
|
||||
private List<NestedReferenceElasticEntity> references;
|
||||
public final static String _references = "references";
|
||||
|
||||
@Field(value = DmpElasticEntity._collaborators, type = FieldType.Nested)
|
||||
private List<NestedCollaboratorElasticEntity> collaborators;
|
||||
public final static String _collaborators = "collaborators";
|
||||
|
||||
@Field(value = DmpElasticEntity._descriptionTemplates, type = FieldType.Nested)
|
||||
private List<NestedDescriptionTemplateElasticEntity> descriptionTemplates;
|
||||
public final static String _descriptionTemplates = "descriptionTemplates";
|
||||
|
||||
@Field(value = DmpElasticEntity._descriptions, type = FieldType.Nested)
|
||||
private List<NestedDescriptionElasticEntity> descriptions;
|
||||
public final static String _descriptions = "descriptions";
|
||||
|
||||
@Field(value = DmpElasticEntity._dois, type = FieldType.Nested)
|
||||
private List<NestedDoiElasticEntity> dois;
|
||||
public final static String _dois = "dois";
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public Short getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(Short version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public DmpStatus getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(DmpStatus status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public DmpAccessType getAccessType() {
|
||||
return accessType;
|
||||
}
|
||||
|
||||
public void setAccessType(DmpAccessType accessType) {
|
||||
this.accessType = accessType;
|
||||
}
|
||||
|
||||
public String getLanguage() {
|
||||
return language;
|
||||
}
|
||||
|
||||
public void setLanguage(String language) {
|
||||
this.language = language;
|
||||
}
|
||||
|
||||
public UUID getBlueprintId() {
|
||||
return blueprintId;
|
||||
}
|
||||
|
||||
public void setBlueprintId(UUID blueprintId) {
|
||||
this.blueprintId = blueprintId;
|
||||
}
|
||||
|
||||
public UUID getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
|
||||
public void setGroupId(UUID groupId) {
|
||||
this.groupId = groupId;
|
||||
}
|
||||
|
||||
public Date getFinalizedAt() {
|
||||
return finalizedAt;
|
||||
}
|
||||
|
||||
public void setFinalizedAt(Date finalizedAt) {
|
||||
this.finalizedAt = finalizedAt;
|
||||
}
|
||||
|
||||
public List<NestedReferenceElasticEntity> getReferences() {
|
||||
return references;
|
||||
}
|
||||
|
||||
public void setReferences(List<NestedReferenceElasticEntity> references) {
|
||||
this.references = references;
|
||||
}
|
||||
|
||||
public List<NestedCollaboratorElasticEntity> getCollaborators() {
|
||||
return collaborators;
|
||||
}
|
||||
|
||||
public void setCollaborators(List<NestedCollaboratorElasticEntity> collaborators) {
|
||||
this.collaborators = collaborators;
|
||||
}
|
||||
|
||||
public List<NestedDescriptionTemplateElasticEntity> getDescriptionTemplates() {
|
||||
return descriptionTemplates;
|
||||
}
|
||||
|
||||
public void setDescriptionTemplates(List<NestedDescriptionTemplateElasticEntity> descriptionTemplates) {
|
||||
this.descriptionTemplates = descriptionTemplates;
|
||||
}
|
||||
|
||||
public List<NestedDescriptionElasticEntity> getDescriptions() {
|
||||
return descriptions;
|
||||
}
|
||||
|
||||
public void setDescriptions(List<NestedDescriptionElasticEntity> descriptions) {
|
||||
this.descriptions = descriptions;
|
||||
}
|
||||
|
||||
public List<NestedDoiElasticEntity> getDois() {
|
||||
return dois;
|
||||
}
|
||||
|
||||
public void setDois(List<NestedDoiElasticEntity> dois) {
|
||||
this.dois = dois;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package eu.eudat.elastic.data.nested;
|
||||
|
||||
import eu.eudat.commons.enums.DmpUserRole;
|
||||
import gr.cite.tools.elastic.ElasticConstants;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.elasticsearch.annotations.*;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class NestedCollaboratorElasticEntity {
|
||||
@Id
|
||||
@Field(value = NestedCollaboratorElasticEntity._id, type = FieldType.Keyword)
|
||||
private UUID id;
|
||||
public final static String _id = "id";
|
||||
|
||||
@MultiField(mainField = @Field(value = NestedCollaboratorElasticEntity._name, type = FieldType.Text), otherFields = {
|
||||
@InnerField(suffix = ElasticConstants.SubFields.keyword, type = FieldType.Keyword)
|
||||
})
|
||||
private String name;
|
||||
public final static String _name = "name";
|
||||
|
||||
@Field(value = NestedCollaboratorElasticEntity._role, type = FieldType.Short)
|
||||
private DmpUserRole role;
|
||||
public final static String _role = "role";
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public DmpUserRole getRole() {
|
||||
return role;
|
||||
}
|
||||
|
||||
public void setRole(DmpUserRole role) {
|
||||
this.role = role;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,112 @@
|
|||
package eu.eudat.elastic.data.nested;
|
||||
|
||||
import eu.eudat.commons.enums.DescriptionStatus;
|
||||
import gr.cite.tools.elastic.ElasticConstants;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.elasticsearch.annotations.*;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class NestedDescriptionElasticEntity {
|
||||
|
||||
@Id
|
||||
@Field(value = NestedDescriptionElasticEntity._id, type = FieldType.Keyword)
|
||||
private UUID id;
|
||||
public final static String _id = "id";
|
||||
|
||||
@Field(value = NestedDescriptionElasticEntity._dmpId, type = FieldType.Keyword)
|
||||
private UUID dmpId;
|
||||
public final static String _dmpId = "dmpId";
|
||||
|
||||
@MultiField(mainField = @Field(value = NestedDescriptionElasticEntity._label, type = FieldType.Text), otherFields = {
|
||||
@InnerField(suffix = ElasticConstants.SubFields.keyword, type = FieldType.Keyword)
|
||||
})
|
||||
private String label;
|
||||
public final static String _label = "label";
|
||||
|
||||
@Field(value = NestedDescriptionElasticEntity._description, type = FieldType.Text)
|
||||
private String description;
|
||||
public final static String _description = "description";
|
||||
|
||||
@Field(value = NestedDescriptionElasticEntity._status, type = FieldType.Short)
|
||||
private DescriptionStatus status;
|
||||
public final static String _status = "status";
|
||||
|
||||
@Field(value = NestedDescriptionElasticEntity._finalizedAt, type = FieldType.Date)
|
||||
private Date finalizedAt;
|
||||
public final static String _finalizedAt = "finalizedAt";
|
||||
|
||||
@Field(value = NestedDescriptionElasticEntity._tags, type = FieldType.Nested)
|
||||
private List<NestedTagElasticEntity> tags;
|
||||
public final static String _tags = "tags";
|
||||
|
||||
@Field(value = NestedDescriptionElasticEntity._references, type = FieldType.Nested)
|
||||
private List<NestedReferenceElasticEntity> references;
|
||||
public final static String _references = "references";
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public UUID getDmpId() {
|
||||
return dmpId;
|
||||
}
|
||||
|
||||
public void setDmpId(UUID dmpId) {
|
||||
this.dmpId = dmpId;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public DescriptionStatus getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(DescriptionStatus status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public Date getFinalizedAt() {
|
||||
return finalizedAt;
|
||||
}
|
||||
|
||||
public void setFinalizedAt(Date finalizedAt) {
|
||||
this.finalizedAt = finalizedAt;
|
||||
}
|
||||
|
||||
public List<NestedTagElasticEntity> getTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
public void setTags(List<NestedTagElasticEntity> tags) {
|
||||
this.tags = tags;
|
||||
}
|
||||
|
||||
public List<NestedReferenceElasticEntity> getReferences() {
|
||||
return references;
|
||||
}
|
||||
|
||||
public void setReferences(List<NestedReferenceElasticEntity> references) {
|
||||
this.references = references;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package eu.eudat.elastic.data.nested;
|
||||
|
||||
import gr.cite.tools.elastic.ElasticConstants;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.elasticsearch.annotations.*;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class NestedDescriptionTemplateElasticEntity {
|
||||
|
||||
@Id
|
||||
@Field(value = NestedDescriptionTemplateElasticEntity._id, type = FieldType.Keyword)
|
||||
private UUID id;
|
||||
public final static String _id = "id";
|
||||
|
||||
@MultiField(mainField = @Field(value = NestedDescriptionTemplateElasticEntity._label, type = FieldType.Text), otherFields = {
|
||||
@InnerField(suffix = ElasticConstants.SubFields.keyword, type = FieldType.Keyword)
|
||||
})
|
||||
private String label;
|
||||
public final static String _label = "label";
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,172 @@
|
|||
package eu.eudat.elastic.data.nested;
|
||||
|
||||
import eu.eudat.commons.enums.DmpAccessType;
|
||||
import eu.eudat.commons.enums.DmpStatus;
|
||||
import gr.cite.tools.elastic.ElasticConstants;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.elasticsearch.annotations.*;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class NestedDmpElasticEntity {
|
||||
@Id
|
||||
@Field(value = NestedDmpElasticEntity._id, type = FieldType.Keyword)
|
||||
private UUID id;
|
||||
public final static String _id = "id";
|
||||
|
||||
@MultiField(mainField = @Field(value = NestedDmpElasticEntity._label, type = FieldType.Text), otherFields = {
|
||||
@InnerField(suffix = ElasticConstants.SubFields.keyword, type = FieldType.Keyword)
|
||||
})
|
||||
private String label;
|
||||
public final static String _label = "label";
|
||||
|
||||
@Field(value = NestedDmpElasticEntity._description, type = FieldType.Text)
|
||||
private String description;
|
||||
public final static String _description = "description";
|
||||
|
||||
@Field(value = NestedDmpElasticEntity._version, type = FieldType.Keyword)
|
||||
private Short version;
|
||||
public final static String _version = "version";
|
||||
|
||||
@Field(value = NestedDmpElasticEntity._status, type = FieldType.Short)
|
||||
private DmpStatus status;
|
||||
public final static String _status = "status";
|
||||
|
||||
@Field(value = NestedDmpElasticEntity._accessType, type = FieldType.Short)
|
||||
private DmpAccessType accessType;
|
||||
public final static String _accessType = "accessType";
|
||||
|
||||
@Field(value = NestedDmpElasticEntity._language, type = FieldType.Keyword)
|
||||
private String language;
|
||||
public final static String _language = "language";
|
||||
|
||||
@Field(value = NestedDmpElasticEntity._blueprintId, type = FieldType.Keyword)
|
||||
private UUID blueprintId;
|
||||
public final static String _blueprintId = "blueprintId";
|
||||
|
||||
@Field(value = NestedDmpElasticEntity._groupId, type = FieldType.Keyword)
|
||||
private UUID groupId;
|
||||
public final static String _groupId = "groupId";
|
||||
|
||||
@Field(value = NestedDmpElasticEntity._finalizedAt, type = FieldType.Date)
|
||||
private Date finalizedAt;
|
||||
public final static String _finalizedAt = "finalizedAt";
|
||||
|
||||
@Field(value = NestedDmpElasticEntity._references, type = FieldType.Nested)
|
||||
private List<NestedReferenceElasticEntity> references;
|
||||
public final static String _references = "references";
|
||||
|
||||
@Field(value = NestedDmpElasticEntity._collaborators, type = FieldType.Nested)
|
||||
private List<NestedCollaboratorElasticEntity> collaborators;
|
||||
public final static String _collaborators = "collaborators";
|
||||
|
||||
@Field(value = NestedDmpElasticEntity._dois, type = FieldType.Nested)
|
||||
private List<NestedDoiElasticEntity> dois;
|
||||
public final static String _dois = "dois";
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public Short getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(Short version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public DmpStatus getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(DmpStatus status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public DmpAccessType getAccessType() {
|
||||
return accessType;
|
||||
}
|
||||
|
||||
public void setAccessType(DmpAccessType accessType) {
|
||||
this.accessType = accessType;
|
||||
}
|
||||
|
||||
public String getLanguage() {
|
||||
return language;
|
||||
}
|
||||
|
||||
public void setLanguage(String language) {
|
||||
this.language = language;
|
||||
}
|
||||
|
||||
public UUID getBlueprintId() {
|
||||
return blueprintId;
|
||||
}
|
||||
|
||||
public void setBlueprintId(UUID blueprintId) {
|
||||
this.blueprintId = blueprintId;
|
||||
}
|
||||
|
||||
public UUID getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
|
||||
public void setGroupId(UUID groupId) {
|
||||
this.groupId = groupId;
|
||||
}
|
||||
|
||||
public Date getFinalizedAt() {
|
||||
return finalizedAt;
|
||||
}
|
||||
|
||||
public void setFinalizedAt(Date finalizedAt) {
|
||||
this.finalizedAt = finalizedAt;
|
||||
}
|
||||
|
||||
public List<NestedReferenceElasticEntity> getReferences() {
|
||||
return references;
|
||||
}
|
||||
|
||||
public void setReferences(List<NestedReferenceElasticEntity> references) {
|
||||
this.references = references;
|
||||
}
|
||||
|
||||
public List<NestedCollaboratorElasticEntity> getCollaborators() {
|
||||
return collaborators;
|
||||
}
|
||||
|
||||
public void setCollaborators(List<NestedCollaboratorElasticEntity> collaborators) {
|
||||
this.collaborators = collaborators;
|
||||
}
|
||||
|
||||
public List<NestedDoiElasticEntity> getDois() {
|
||||
return dois;
|
||||
}
|
||||
|
||||
public void setDois(List<NestedDoiElasticEntity> dois) {
|
||||
this.dois = dois;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package eu.eudat.elastic.data.nested;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.elasticsearch.annotations.*;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class NestedDoiElasticEntity {
|
||||
|
||||
@Id
|
||||
@Field(value = NestedDoiElasticEntity._id, type = FieldType.Keyword)
|
||||
private UUID id;
|
||||
public final static String _id = "id";
|
||||
|
||||
@Field(value = NestedDoiElasticEntity._repositoryId, type = FieldType.Keyword)
|
||||
private String repositoryId;
|
||||
public final static String _repositoryId = "repositoryId";
|
||||
|
||||
@Field(value = NestedDoiElasticEntity._doi, type = FieldType.Keyword)
|
||||
private String doi;
|
||||
public final static String _doi = "doi";
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getRepositoryId() {
|
||||
return repositoryId;
|
||||
}
|
||||
|
||||
public void setRepositoryId(String repositoryId) {
|
||||
this.repositoryId = repositoryId;
|
||||
}
|
||||
|
||||
public String getDoi() {
|
||||
return doi;
|
||||
}
|
||||
|
||||
public void setDoi(String doi) {
|
||||
this.doi = doi;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package eu.eudat.elastic.data.nested;
|
||||
|
||||
import gr.cite.tools.elastic.ElasticConstants;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.elasticsearch.annotations.*;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class NestedReferenceElasticEntity {
|
||||
@Id
|
||||
@Field(value = NestedReferenceElasticEntity._id, type = FieldType.Keyword)
|
||||
private UUID id;
|
||||
public final static String _id = "id";
|
||||
|
||||
@MultiField(mainField = @Field(value = NestedReferenceElasticEntity._label, type = FieldType.Text), otherFields = {
|
||||
@InnerField(suffix = ElasticConstants.SubFields.keyword, type = FieldType.Keyword)
|
||||
})
|
||||
private String label;
|
||||
public final static String _label = "label";
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package eu.eudat.elastic.data.nested;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.elasticsearch.annotations.*;
|
||||
import gr.cite.tools.elastic.ElasticConstants;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class NestedTagElasticEntity {
|
||||
@Id
|
||||
@Field(value = NestedTagElasticEntity._id, type = FieldType.Keyword)
|
||||
private UUID id;
|
||||
public final static String _id = "id";
|
||||
|
||||
@MultiField(mainField = @Field(value = NestedTagElasticEntity._label, type = FieldType.Text), otherFields = {
|
||||
@InnerField(suffix = ElasticConstants.SubFields.keyword, type = FieldType.Keyword)
|
||||
})
|
||||
private String label;
|
||||
public final static String _label = "label";
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,93 @@
|
|||
package eu.eudat.elastic.elasticbuilder;
|
||||
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import gr.cite.tools.data.builder.Builder;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public abstract class BaseElasticBuilder<M, D> implements Builder {
|
||||
protected final LoggerService logger;
|
||||
protected final ConventionService conventionService;
|
||||
|
||||
public BaseElasticBuilder(
|
||||
ConventionService conventionService,
|
||||
LoggerService logger
|
||||
) {
|
||||
this.conventionService = conventionService;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
public M build(D data) throws MyApplicationException {
|
||||
if (data == null) {
|
||||
M model = null;
|
||||
return null; //TODO
|
||||
}
|
||||
List<M> models = this.build(Arrays.asList(data));
|
||||
return models.stream().findFirst().orElse(null); //TODO
|
||||
}
|
||||
|
||||
public abstract List<M> build(List<D> datas) throws MyApplicationException;
|
||||
|
||||
public <K> Map<K, M> asForeignKey(QueryBase<D> query, Function<M, K> keySelector) throws MyApplicationException {
|
||||
this.logger.trace("Building references from query");
|
||||
List<D> datas = query.collect();
|
||||
this.logger.debug("collected {} items to build", Optional.ofNullable(datas).map(e -> e.size()).orElse(0));
|
||||
return this.asForeignKey(datas, keySelector);
|
||||
}
|
||||
|
||||
public <K> Map<K, M> asForeignKey(List<D> datas, Function<M, K> keySelector) throws MyApplicationException {
|
||||
this.logger.trace("building references");
|
||||
List<M> models = this.build(datas);
|
||||
this.logger.debug("mapping {} build items from {} requested", Optional.ofNullable(models).map(e -> e.size()).orElse(0), Optional.ofNullable(datas).map(e -> e.size()).orElse(0));
|
||||
Map<K, M> map = models.stream().collect(Collectors.toMap(o -> keySelector.apply(o), o -> o));
|
||||
return map;
|
||||
}
|
||||
|
||||
public <K> Map<K, List<M>> asMasterKey(QueryBase<D> query, Function<M, K> keySelector) throws MyApplicationException {
|
||||
this.logger.trace("Building details from query");
|
||||
List<D> datas = query.collect();
|
||||
this.logger.debug("collected {} items to build", Optional.ofNullable(datas).map(e -> e.size()).orElse(0));
|
||||
return this.asMasterKey(datas, keySelector);
|
||||
}
|
||||
|
||||
public <K> Map<K, List<M>> asMasterKey(List<D> datas, Function<M, K> keySelector) throws MyApplicationException {
|
||||
this.logger.trace("building details");
|
||||
List<M> models = this.build(datas);
|
||||
this.logger.debug("mapping {} build items from {} requested", Optional.ofNullable(models).map(e -> e.size()).orElse(0), Optional.ofNullable(datas).map(e -> e.size()).orElse(0));
|
||||
Map<K, List<M>> map = new HashMap<>();
|
||||
for (M model : models) {
|
||||
K key = keySelector.apply(model);
|
||||
if (!map.containsKey(key)) map.put(key, new ArrayList<M>());
|
||||
map.get(key).add(model);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public <FK, FM> Map<FK, FM> asEmpty(List<FK> keys, Function<FK, FM> mapper, Function<FM, FK> keySelector) {
|
||||
this.logger.trace("building static references");
|
||||
List<FM> models = keys.stream().map(x -> mapper.apply(x)).collect(Collectors.toList());
|
||||
this.logger.debug("mapping {} build items from {} requested", Optional.ofNullable(models).map(x -> x.size()).orElse(0), Optional.ofNullable(keys).map(x -> x.size()));
|
||||
Map<FK, FM> map = models.stream().collect(Collectors.toMap(o -> keySelector.apply(o), o -> o));
|
||||
return map;
|
||||
}
|
||||
|
||||
protected String hashValue(Instant value) throws MyApplicationException {
|
||||
return this.conventionService.hashValue(value);
|
||||
}
|
||||
|
||||
protected String asPrefix(String name) {
|
||||
return this.conventionService.asPrefix(name);
|
||||
}
|
||||
|
||||
protected String asIndexer(String... names) {
|
||||
return this.conventionService.asIndexer(names);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,148 @@
|
|||
package eu.eudat.elastic.elasticbuilder;
|
||||
|
||||
import eu.eudat.commons.enums.IsActive;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.data.DescriptionEntity;
|
||||
import eu.eudat.data.DescriptionReferenceEntity;
|
||||
import eu.eudat.data.DescriptionTagEntity;
|
||||
import eu.eudat.data.DmpDescriptionTemplateEntity;
|
||||
import eu.eudat.elastic.data.DescriptionElasticEntity;
|
||||
import eu.eudat.elastic.data.nested.*;
|
||||
import eu.eudat.elastic.elasticbuilder.nested.NestedDescriptionTemplateElasticBuilder;
|
||||
import eu.eudat.elastic.elasticbuilder.nested.NestedDmpElasticBuilder;
|
||||
import eu.eudat.elastic.elasticbuilder.nested.NestedReferenceElasticBuilder;
|
||||
import eu.eudat.elastic.elasticbuilder.nested.NestedTagElasticBuilder;
|
||||
import eu.eudat.model.*;
|
||||
import eu.eudat.model.builder.DescriptionBuilder;
|
||||
import eu.eudat.model.builder.ReferenceBuilder;
|
||||
import eu.eudat.query.*;
|
||||
import gr.cite.tools.data.builder.BuilderFactory;
|
||||
import gr.cite.tools.data.query.QueryFactory;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.fieldset.BaseFieldSet;
|
||||
import gr.cite.tools.fieldset.FieldSet;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class DescriptionElasticBuilder extends BaseElasticBuilder<DescriptionElasticEntity, DescriptionEntity> {
|
||||
|
||||
private final QueryFactory queryFactory;
|
||||
private final BuilderFactory builderFactory;
|
||||
|
||||
@Autowired
|
||||
public DescriptionElasticBuilder(
|
||||
ConventionService conventionService, QueryFactory queryFactory, BuilderFactory builderFactory) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(DescriptionElasticBuilder.class)));
|
||||
this.queryFactory = queryFactory;
|
||||
this.builderFactory = builderFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DescriptionElasticEntity> build(List<DescriptionEntity> data) throws MyApplicationException {
|
||||
if (data == null)
|
||||
return new ArrayList<>();
|
||||
|
||||
Map<UUID, List<NestedReferenceElasticEntity>> referenceElasticEntityMap = this.collectDescriptionReferences(data);
|
||||
Map<UUID, List<NestedTagElasticEntity>> tagElasticEntityMap = this.collectDescriptionTags(data);
|
||||
Map<UUID, NestedDmpElasticEntity> dmpElasticEntityMap = this.collectDmps(data);
|
||||
Map<UUID, NestedDescriptionTemplateElasticEntity> descriptionTemplateElasticEntityMap = this.collectDescriptionTemplates(data);
|
||||
|
||||
List<DescriptionElasticEntity> models = new ArrayList<>();
|
||||
for (DescriptionEntity d : data) {
|
||||
DescriptionElasticEntity m = new DescriptionElasticEntity();
|
||||
m.setId(d.getId());
|
||||
m.setLabel(d.getLabel());
|
||||
m.setDescription(d.getDescription());
|
||||
m.setStatus(d.getStatus());
|
||||
m.setFinalizedAt(Date.from(d.getFinalizedAt()));
|
||||
if (referenceElasticEntityMap != null) m.setReferences(referenceElasticEntityMap.getOrDefault(d.getId(), null));
|
||||
if (tagElasticEntityMap != null) m.setTags(tagElasticEntityMap.getOrDefault(d.getId(), null));
|
||||
if (dmpElasticEntityMap != null) m.setDmp(dmpElasticEntityMap.getOrDefault(d.getDmpId(), null));
|
||||
if (descriptionTemplateElasticEntityMap != null) m.setDescriptionTemplate(descriptionTemplateElasticEntityMap.getOrDefault(d.getDmpId(), null));
|
||||
models.add(m);
|
||||
}
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
return models;
|
||||
}
|
||||
|
||||
private Map<UUID, List<NestedReferenceElasticEntity>> collectDescriptionReferences(List<DescriptionEntity> data) throws MyApplicationException {
|
||||
if (data.isEmpty()) return null;
|
||||
this.logger.debug("checking related - {}", DescriptionReference.class.getSimpleName());
|
||||
|
||||
DescriptionReferenceQuery associationQuery = this.queryFactory.query(DescriptionReferenceQuery.class).descriptionIds(data.stream().map(DescriptionEntity::getId).collect(Collectors.toList())).isActive(IsActive.Active);
|
||||
List<DescriptionReferenceEntity> associationEntities = associationQuery.collect();
|
||||
|
||||
ReferenceQuery query = this.queryFactory.query(ReferenceQuery.class).isActive(IsActive.Active).ids(associationEntities.stream().map(DescriptionReferenceEntity::getReferenceId).distinct().collect(Collectors.toList()));
|
||||
Map<UUID, NestedReferenceElasticEntity> itemMapById = this.builderFactory.builder(NestedReferenceElasticBuilder.class).asForeignKey(query, NestedReferenceElasticEntity::getId);
|
||||
|
||||
Map<UUID, List<NestedReferenceElasticEntity>> itemMap = new HashMap<>();
|
||||
for (DescriptionReferenceEntity associationEntity : associationEntities){
|
||||
if (!itemMap.containsKey(associationEntity.getDescriptionId())) itemMap.put(associationEntity.getDescriptionId(), new ArrayList<>());
|
||||
NestedReferenceElasticEntity item = itemMapById.getOrDefault(associationEntity.getReferenceId(), null);
|
||||
if (item != null) itemMap.get(associationEntity.getDescriptionId()).add(item);
|
||||
}
|
||||
|
||||
return itemMap;
|
||||
}
|
||||
|
||||
private Map<UUID, List<NestedTagElasticEntity>> collectDescriptionTags(List<DescriptionEntity> data) throws MyApplicationException {
|
||||
if (data.isEmpty()) return null;
|
||||
this.logger.debug("checking related - {}", DescriptionTag.class.getSimpleName());
|
||||
|
||||
DescriptionTagQuery associationQuery = this.queryFactory.query(DescriptionTagQuery.class).descriptionIds(data.stream().map(DescriptionEntity::getId).collect(Collectors.toList())).isActive(IsActive.Active);
|
||||
List<DescriptionTagEntity> associationEntities = associationQuery.collect();
|
||||
|
||||
TagQuery query = this.queryFactory.query(TagQuery.class).isActive(IsActive.Active).ids(associationEntities.stream().map(DescriptionTagEntity::getTagId).distinct().collect(Collectors.toList()));
|
||||
Map<UUID, NestedTagElasticEntity> itemMapById = this.builderFactory.builder(NestedTagElasticBuilder.class).asForeignKey(query, NestedTagElasticEntity::getId);
|
||||
|
||||
Map<UUID, List<NestedTagElasticEntity>> itemMap = new HashMap<>();
|
||||
for (DescriptionTagEntity associationEntity : associationEntities){
|
||||
if (!itemMap.containsKey(associationEntity.getDescriptionId())) itemMap.put(associationEntity.getDescriptionId(), new ArrayList<>());
|
||||
NestedTagElasticEntity item = itemMapById.getOrDefault(associationEntity.getTagId(), null);
|
||||
if (item != null) itemMap.get(associationEntity.getDescriptionId()).add(item);
|
||||
}
|
||||
|
||||
return itemMap;
|
||||
}
|
||||
|
||||
private Map<UUID, NestedDmpElasticEntity> collectDmps(List<DescriptionEntity> data) throws MyApplicationException {
|
||||
if (data.isEmpty())
|
||||
return null;
|
||||
this.logger.debug("checking related - {}", Dmp.class.getSimpleName());
|
||||
|
||||
Map<UUID, NestedDmpElasticEntity> itemMap;
|
||||
DmpQuery q = this.queryFactory.query(DmpQuery.class).isActive(IsActive.Active).ids(data.stream().map(DescriptionEntity::getDmpId).distinct().collect(Collectors.toList()));
|
||||
itemMap = this.builderFactory.builder(NestedDmpElasticBuilder.class).asForeignKey(q, NestedDmpElasticEntity::getId);
|
||||
|
||||
return itemMap;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private Map<UUID, NestedDescriptionTemplateElasticEntity> collectDescriptionTemplates(List<DescriptionEntity> data) throws MyApplicationException {
|
||||
if (data.isEmpty())
|
||||
return null;
|
||||
this.logger.debug("checking related - {}", DescriptionTemplate.class.getSimpleName());
|
||||
|
||||
DmpDescriptionTemplateQuery associationQuery = this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(data.stream().map(DescriptionEntity::getDmpDescriptionTemplateId).collect(Collectors.toList())).isActive(IsActive.Active);
|
||||
List<DmpDescriptionTemplateEntity> associationEntities = associationQuery.collect();
|
||||
|
||||
DescriptionTemplateQuery query = this.queryFactory.query(DescriptionTemplateQuery.class).isActive(IsActive.Active).ids(associationEntities.stream().map(DmpDescriptionTemplateEntity::getDescriptionTemplateId).distinct().collect(Collectors.toList()));
|
||||
Map<UUID, NestedDescriptionTemplateElasticEntity> itemMapById = this.builderFactory.builder(NestedDescriptionTemplateElasticBuilder.class).asForeignKey(query, NestedDescriptionTemplateElasticEntity::getId);
|
||||
|
||||
Map<UUID, NestedDescriptionTemplateElasticEntity> itemMap = new HashMap<>();
|
||||
for (DmpDescriptionTemplateEntity associationEntity : associationEntities){
|
||||
itemMap.put(associationEntity.getId(), itemMapById.getOrDefault(associationEntity.getDescriptionTemplateId(), null));
|
||||
}
|
||||
return itemMap;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,163 @@
|
|||
package eu.eudat.elastic.elasticbuilder;
|
||||
|
||||
import eu.eudat.commons.enums.IsActive;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.data.*;
|
||||
import eu.eudat.elastic.data.DmpElasticEntity;
|
||||
import eu.eudat.elastic.data.nested.*;
|
||||
import eu.eudat.elastic.elasticbuilder.nested.*;
|
||||
import eu.eudat.model.DmpReference;
|
||||
import eu.eudat.query.*;
|
||||
import gr.cite.tools.data.builder.BuilderFactory;
|
||||
import gr.cite.tools.data.query.QueryFactory;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class DmpElasticBuilder extends BaseElasticBuilder<DmpElasticEntity, DmpEntity> {
|
||||
|
||||
private final QueryFactory queryFactory;
|
||||
private final BuilderFactory builderFactory;
|
||||
|
||||
@Autowired
|
||||
public DmpElasticBuilder(
|
||||
ConventionService conventionService, QueryFactory queryFactory, BuilderFactory builderFactory) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(DmpElasticBuilder.class)));
|
||||
this.queryFactory = queryFactory;
|
||||
this.builderFactory = builderFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DmpElasticEntity> build(List<DmpEntity> data) throws MyApplicationException {
|
||||
if (data == null)
|
||||
return new ArrayList<>();
|
||||
|
||||
Map<UUID, List<NestedReferenceElasticEntity>> referenceElasticEntityMap = this.collectDmpReferences(data);
|
||||
Map<UUID, List<NestedDescriptionElasticEntity>> dmpElasticEntityMap = this.collectDescriptions(data);
|
||||
Map<UUID, List<NestedCollaboratorElasticEntity>> collaboratorElasticEntityMap = this.collectCollaborators(data);
|
||||
Map<UUID, List<NestedDoiElasticEntity>> doiElasticEntityMap = this.collectDois(data);
|
||||
Map<UUID, List<NestedDescriptionTemplateElasticEntity>> descriptionTemplateElasticEntityMap = this.collectDescriptionTemplates(data);
|
||||
|
||||
List<DmpElasticEntity> models = new ArrayList<>();
|
||||
for (DmpEntity d : data) {
|
||||
DmpElasticEntity m = new DmpElasticEntity();
|
||||
m.setId(d.getId());
|
||||
m.setLabel(d.getLabel());
|
||||
m.setDescription(d.getDescription());
|
||||
m.setVersion(d.getVersion());
|
||||
m.setStatus(d.getStatus());
|
||||
m.setAccessType(d.getAccessType());
|
||||
m.setLanguage(d.getLanguage());
|
||||
m.setBlueprintId(d.getBlueprint());
|
||||
m.setGroupId(d.getGroupId());
|
||||
m.setFinalizedAt(Date.from(d.getFinalizedAt()));
|
||||
if (referenceElasticEntityMap != null) m.setReferences(referenceElasticEntityMap.getOrDefault(d.getId(), null));
|
||||
if (dmpElasticEntityMap != null) m.setDescriptions(dmpElasticEntityMap.getOrDefault(d.getId(), null));
|
||||
if (collaboratorElasticEntityMap != null) m.setCollaborators(collaboratorElasticEntityMap.getOrDefault(d.getId(), null));
|
||||
if (doiElasticEntityMap != null) m.setDois(doiElasticEntityMap.getOrDefault(d.getId(), null));
|
||||
if (descriptionTemplateElasticEntityMap != null) m.setDescriptionTemplates(descriptionTemplateElasticEntityMap.getOrDefault(d.getId(), null));
|
||||
models.add(m);
|
||||
}
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
return models;
|
||||
}
|
||||
|
||||
private Map<UUID, List<NestedReferenceElasticEntity>> collectDmpReferences(List<DmpEntity> data) throws MyApplicationException {
|
||||
if (data.isEmpty()) return null;
|
||||
this.logger.debug("checking related - {}", DmpReference.class.getSimpleName());
|
||||
|
||||
DmpReferenceQuery associationQuery = this.queryFactory.query(DmpReferenceQuery.class).dmpIds(data.stream().map(DmpEntity::getId).collect(Collectors.toList())).isActives(IsActive.Active);
|
||||
List<DmpReferenceEntity> associationEntities = associationQuery.collect();
|
||||
|
||||
ReferenceQuery query = this.queryFactory.query(ReferenceQuery.class).isActive(IsActive.Active).ids(associationEntities.stream().map(DmpReferenceEntity::getReferenceId).distinct().collect(Collectors.toList()));
|
||||
Map<UUID, NestedReferenceElasticEntity> itemMapById = this.builderFactory.builder(NestedReferenceElasticBuilder.class).asForeignKey(query, NestedReferenceElasticEntity::getId);
|
||||
|
||||
Map<UUID, List<NestedReferenceElasticEntity>> itemMap = new HashMap<>();
|
||||
for (DmpReferenceEntity associationEntity : associationEntities){
|
||||
if (!itemMap.containsKey(associationEntity.getDmpId())) itemMap.put(associationEntity.getDmpId(), new ArrayList<>());
|
||||
NestedReferenceElasticEntity item = itemMapById.getOrDefault(associationEntity.getReferenceId(), null);
|
||||
if (item != null) itemMap.get(associationEntity.getDmpId()).add(item);
|
||||
}
|
||||
|
||||
return itemMap;
|
||||
}
|
||||
|
||||
private Map<UUID, List<NestedDescriptionTemplateElasticEntity>> collectDescriptionTemplates(List<DmpEntity> data) throws MyApplicationException {
|
||||
if (data.isEmpty()) return null;
|
||||
this.logger.debug("checking related - {}", DmpReference.class.getSimpleName());
|
||||
|
||||
DmpDescriptionTemplateQuery associationQuery = this.queryFactory.query(DmpDescriptionTemplateQuery.class).dmpIds(data.stream().map(DmpEntity::getId).collect(Collectors.toList())).isActive(IsActive.Active);
|
||||
List<DmpDescriptionTemplateEntity> associationEntities = associationQuery.collect();
|
||||
|
||||
DescriptionTemplateQuery query = this.queryFactory.query(DescriptionTemplateQuery.class).isActive(IsActive.Active).ids(associationEntities.stream().map(DmpDescriptionTemplateEntity::getDescriptionTemplateId).distinct().collect(Collectors.toList()));
|
||||
Map<UUID, NestedDescriptionTemplateElasticEntity> itemMapById = this.builderFactory.builder(NestedDescriptionTemplateElasticBuilder.class).asForeignKey(query, NestedDescriptionTemplateElasticEntity::getId);
|
||||
|
||||
Map<UUID, List<NestedDescriptionTemplateElasticEntity>> itemMap = new HashMap<>();
|
||||
for (DmpDescriptionTemplateEntity associationEntity : associationEntities){
|
||||
if (!itemMap.containsKey(associationEntity.getDmpId())) itemMap.put(associationEntity.getDmpId(), new ArrayList<>());
|
||||
NestedDescriptionTemplateElasticEntity item = itemMapById.getOrDefault(associationEntity.getDescriptionTemplateId(), null);
|
||||
if (item != null) itemMap.get(associationEntity.getDmpId()).add(item);
|
||||
}
|
||||
|
||||
return itemMap;
|
||||
}
|
||||
|
||||
private Map<UUID, List<NestedDescriptionElasticEntity>> collectDescriptions(List<DmpEntity> data) throws MyApplicationException {
|
||||
if (data.isEmpty())
|
||||
return null;
|
||||
this.logger.debug("checking related - {}", DescriptionEntity.class.getSimpleName());
|
||||
|
||||
Map<UUID, List<NestedDescriptionElasticEntity>> itemMap;
|
||||
DescriptionQuery q = this.queryFactory.query(DescriptionQuery.class).isActive(IsActive.Active).dmpSubQuery(this.queryFactory.query(DmpQuery.class).ids(data.stream().map(DmpEntity::getId).distinct().collect(Collectors.toList())));
|
||||
itemMap = this.builderFactory.builder(NestedDescriptionElasticBuilder.class).asMasterKey(q, NestedDescriptionElasticEntity::getDmpId);
|
||||
|
||||
return itemMap;
|
||||
}
|
||||
|
||||
private Map<UUID, List<NestedCollaboratorElasticEntity>> collectCollaborators(List<DmpEntity> data) throws MyApplicationException {
|
||||
if (data.isEmpty())
|
||||
return null;
|
||||
this.logger.debug("checking related - {}", DmpUserEntity.class.getSimpleName());
|
||||
|
||||
DmpUserQuery associationQuery = this.queryFactory.query(DmpUserQuery.class).dmpIds(data.stream().map(DmpEntity::getId).collect(Collectors.toList())).isActives(IsActive.Active);
|
||||
List<DmpUserEntity> associationEntities = associationQuery.collect();
|
||||
|
||||
Map<UUID, NestedCollaboratorElasticEntity> itemMapById = this.builderFactory.builder(NestedCollaboratorElasticBuilder.class).asForeignKey(associationEntities, NestedCollaboratorElasticEntity::getId);
|
||||
|
||||
Map<UUID, List<NestedCollaboratorElasticEntity>> itemMap = new HashMap<>();
|
||||
for (DmpUserEntity associationEntity : associationEntities){
|
||||
if (!itemMap.containsKey(associationEntity.getId())) itemMap.put(associationEntity.getDmp(), new ArrayList<>());
|
||||
NestedCollaboratorElasticEntity item = itemMapById.getOrDefault(associationEntity.getId(), null);
|
||||
if (item != null) itemMap.get(associationEntity.getDmp()).add(item);
|
||||
}
|
||||
return itemMap;
|
||||
}
|
||||
|
||||
private Map<UUID, List<NestedDoiElasticEntity>> collectDois(List<DmpEntity> data) throws MyApplicationException {
|
||||
if (data.isEmpty())
|
||||
return null;
|
||||
this.logger.debug("checking related - {}", EntityDoiEntity.class.getSimpleName());
|
||||
|
||||
EntityDoiQuery associationQuery = this.queryFactory.query(EntityDoiQuery.class).entityIds(data.stream().map(DmpEntity::getId).collect(Collectors.toList())).isActive(IsActive.Active);
|
||||
List<EntityDoiEntity> associationEntities = associationQuery.collect();
|
||||
|
||||
Map<UUID, NestedDoiElasticEntity> itemMapById = this.builderFactory.builder(NestedDoiElasticBuilder.class).asForeignKey(associationEntities, NestedDoiElasticEntity::getId);
|
||||
|
||||
Map<UUID, List<NestedDoiElasticEntity>> itemMap = new HashMap<>();
|
||||
for (EntityDoiEntity associationEntity : associationEntities){
|
||||
if (!itemMap.containsKey(associationEntity.getId())) itemMap.put(associationEntity.getEntityId(), new ArrayList<>());
|
||||
NestedDoiElasticEntity item = itemMapById.getOrDefault(associationEntity.getId(), null);
|
||||
if (item != null) itemMap.get(associationEntity.getEntityId()).add(item);
|
||||
}
|
||||
return itemMap;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package eu.eudat.elastic.elasticbuilder.nested;
|
||||
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.data.DmpUserEntity;
|
||||
import eu.eudat.elastic.data.nested.NestedCollaboratorElasticEntity;
|
||||
import eu.eudat.elastic.elasticbuilder.BaseElasticBuilder;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class NestedCollaboratorElasticBuilder extends BaseElasticBuilder<NestedCollaboratorElasticEntity, DmpUserEntity> {
|
||||
|
||||
@Autowired
|
||||
public NestedCollaboratorElasticBuilder(
|
||||
ConventionService conventionService) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(NestedCollaboratorElasticBuilder.class)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<NestedCollaboratorElasticEntity> build(List<DmpUserEntity> data) throws MyApplicationException {
|
||||
if (data == null)
|
||||
return new ArrayList<>();
|
||||
|
||||
List<NestedCollaboratorElasticEntity> models = new ArrayList<>();
|
||||
for (DmpUserEntity d : data) {
|
||||
NestedCollaboratorElasticEntity m = new NestedCollaboratorElasticEntity();
|
||||
m.setId(d.getId());
|
||||
m.setRole(d.getRole());
|
||||
m.setName(d.getUser().toString()); //TODO: Get UserName
|
||||
models.add(m);
|
||||
}
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
return models;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,110 @@
|
|||
package eu.eudat.elastic.elasticbuilder.nested;
|
||||
|
||||
import eu.eudat.commons.enums.IsActive;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.data.DescriptionEntity;
|
||||
import eu.eudat.data.DescriptionReferenceEntity;
|
||||
import eu.eudat.data.DescriptionTagEntity;
|
||||
import eu.eudat.elastic.data.nested.NestedDescriptionElasticEntity;
|
||||
import eu.eudat.elastic.data.nested.NestedReferenceElasticEntity;
|
||||
import eu.eudat.elastic.data.nested.NestedTagElasticEntity;
|
||||
import eu.eudat.elastic.elasticbuilder.BaseElasticBuilder;
|
||||
import eu.eudat.model.DescriptionReference;
|
||||
import eu.eudat.model.DescriptionTag;
|
||||
import eu.eudat.query.DescriptionReferenceQuery;
|
||||
import eu.eudat.query.DescriptionTagQuery;
|
||||
import eu.eudat.query.ReferenceQuery;
|
||||
import eu.eudat.query.TagQuery;
|
||||
import gr.cite.tools.data.builder.BuilderFactory;
|
||||
import gr.cite.tools.data.query.QueryFactory;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class NestedDescriptionElasticBuilder extends BaseElasticBuilder<NestedDescriptionElasticEntity, DescriptionEntity> {
|
||||
|
||||
private final QueryFactory queryFactory;
|
||||
private final BuilderFactory builderFactory;
|
||||
|
||||
@Autowired
|
||||
public NestedDescriptionElasticBuilder(
|
||||
ConventionService conventionService, QueryFactory queryFactory, BuilderFactory builderFactory) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(NestedDescriptionElasticBuilder.class)));
|
||||
this.queryFactory = queryFactory;
|
||||
this.builderFactory = builderFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<NestedDescriptionElasticEntity> build(List<DescriptionEntity> data) throws MyApplicationException {
|
||||
if (data == null)
|
||||
return new ArrayList<>();
|
||||
|
||||
Map<UUID, List<NestedReferenceElasticEntity>> referenceElasticEntityMap = this.collectDescriptionReferences(data);
|
||||
Map<UUID, List<NestedTagElasticEntity>> tagElasticEntityMap = this.collectDescriptionTags(data);
|
||||
|
||||
List<NestedDescriptionElasticEntity> models = new ArrayList<>();
|
||||
for (DescriptionEntity d : data) {
|
||||
NestedDescriptionElasticEntity m = new NestedDescriptionElasticEntity();
|
||||
m.setId(d.getId());
|
||||
m.setDmpId(d.getDmpId());
|
||||
m.setLabel(d.getLabel());
|
||||
m.setDescription(d.getDescription());
|
||||
m.setStatus(d.getStatus());
|
||||
m.setFinalizedAt(Date.from(d.getFinalizedAt()));
|
||||
if (referenceElasticEntityMap != null) m.setReferences(referenceElasticEntityMap.getOrDefault(d.getId(), null));
|
||||
if (tagElasticEntityMap != null) m.setTags(tagElasticEntityMap.getOrDefault(d.getId(), null));
|
||||
models.add(m);
|
||||
}
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
return models;
|
||||
}
|
||||
|
||||
private Map<UUID, List<NestedReferenceElasticEntity>> collectDescriptionReferences(List<DescriptionEntity> data) throws MyApplicationException {
|
||||
if (data.isEmpty()) return null;
|
||||
this.logger.debug("checking related - {}", DescriptionReference.class.getSimpleName());
|
||||
|
||||
DescriptionReferenceQuery associationQuery = this.queryFactory.query(DescriptionReferenceQuery.class).descriptionIds(data.stream().map(DescriptionEntity::getId).collect(Collectors.toList())).isActive(IsActive.Active);
|
||||
List<DescriptionReferenceEntity> associationEntities = associationQuery.collect();
|
||||
|
||||
ReferenceQuery query = this.queryFactory.query(ReferenceQuery.class).isActive(IsActive.Active).ids(associationEntities.stream().map(DescriptionReferenceEntity::getReferenceId).distinct().collect(Collectors.toList()));
|
||||
Map<UUID, NestedReferenceElasticEntity> itemMapById = this.builderFactory.builder(NestedReferenceElasticBuilder.class).asForeignKey(query, NestedReferenceElasticEntity::getId);
|
||||
|
||||
Map<UUID, List<NestedReferenceElasticEntity>> itemMap = new HashMap<>();
|
||||
for (DescriptionReferenceEntity associationEntity : associationEntities){
|
||||
if (!itemMap.containsKey(associationEntity.getDescriptionId())) itemMap.put(associationEntity.getDescriptionId(), new ArrayList<>());
|
||||
NestedReferenceElasticEntity item = itemMapById.getOrDefault(associationEntity.getReferenceId(), null);
|
||||
if (item != null) itemMap.get(associationEntity.getDescriptionId()).add(item);
|
||||
}
|
||||
|
||||
return itemMap;
|
||||
}
|
||||
|
||||
private Map<UUID, List<NestedTagElasticEntity>> collectDescriptionTags(List<DescriptionEntity> data) throws MyApplicationException {
|
||||
if (data.isEmpty()) return null;
|
||||
this.logger.debug("checking related - {}", DescriptionTag.class.getSimpleName());
|
||||
|
||||
DescriptionTagQuery associationQuery = this.queryFactory.query(DescriptionTagQuery.class).descriptionIds(data.stream().map(DescriptionEntity::getId).collect(Collectors.toList())).isActive(IsActive.Active);
|
||||
List<DescriptionTagEntity> associationEntities = associationQuery.collect();
|
||||
|
||||
TagQuery query = this.queryFactory.query(TagQuery.class).isActive(IsActive.Active).ids(associationEntities.stream().map(DescriptionTagEntity::getTagId).distinct().collect(Collectors.toList()));
|
||||
Map<UUID, NestedTagElasticEntity> itemMapById = this.builderFactory.builder(NestedTagElasticBuilder.class).asForeignKey(query, NestedTagElasticEntity::getId);
|
||||
|
||||
Map<UUID, List<NestedTagElasticEntity>> itemMap = new HashMap<>();
|
||||
for (DescriptionTagEntity associationEntity : associationEntities){
|
||||
if (!itemMap.containsKey(associationEntity.getDescriptionId())) itemMap.put(associationEntity.getDescriptionId(), new ArrayList<>());
|
||||
NestedTagElasticEntity item = itemMapById.getOrDefault(associationEntity.getTagId(), null);
|
||||
if (item != null) itemMap.get(associationEntity.getDescriptionId()).add(item);
|
||||
}
|
||||
|
||||
return itemMap;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package eu.eudat.elastic.elasticbuilder.nested;
|
||||
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.data.DescriptionTemplateEntity;
|
||||
import eu.eudat.elastic.data.nested.NestedDescriptionTemplateElasticEntity;
|
||||
import eu.eudat.elastic.elasticbuilder.BaseElasticBuilder;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class NestedDescriptionTemplateElasticBuilder extends BaseElasticBuilder<NestedDescriptionTemplateElasticEntity, DescriptionTemplateEntity> {
|
||||
|
||||
@Autowired
|
||||
public NestedDescriptionTemplateElasticBuilder(
|
||||
ConventionService conventionService) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(NestedDescriptionTemplateElasticBuilder.class)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<NestedDescriptionTemplateElasticEntity> build(List<DescriptionTemplateEntity> data) throws MyApplicationException {
|
||||
if (data == null)
|
||||
return new ArrayList<>();
|
||||
|
||||
List<NestedDescriptionTemplateElasticEntity> models = new ArrayList<>();
|
||||
for (DescriptionTemplateEntity d : data) {
|
||||
NestedDescriptionTemplateElasticEntity m = new NestedDescriptionTemplateElasticEntity();
|
||||
m.setId(d.getId());
|
||||
m.setLabel(d.getLabel());
|
||||
models.add(m);
|
||||
}
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
return models;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,134 @@
|
|||
package eu.eudat.elastic.elasticbuilder.nested;
|
||||
|
||||
import eu.eudat.commons.enums.IsActive;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.data.DmpEntity;
|
||||
import eu.eudat.data.DmpReferenceEntity;
|
||||
import eu.eudat.data.DmpUserEntity;
|
||||
import eu.eudat.data.EntityDoiEntity;
|
||||
import eu.eudat.elastic.data.nested.*;
|
||||
import eu.eudat.elastic.elasticbuilder.BaseElasticBuilder;
|
||||
import eu.eudat.model.DmpReference;
|
||||
import eu.eudat.query.DmpReferenceQuery;
|
||||
import eu.eudat.query.DmpUserQuery;
|
||||
import eu.eudat.query.EntityDoiQuery;
|
||||
import eu.eudat.query.ReferenceQuery;
|
||||
import gr.cite.tools.data.builder.BuilderFactory;
|
||||
import gr.cite.tools.data.query.QueryFactory;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class NestedDmpElasticBuilder extends BaseElasticBuilder<NestedDmpElasticEntity, DmpEntity> {
|
||||
|
||||
private final QueryFactory queryFactory;
|
||||
private final BuilderFactory builderFactory;
|
||||
|
||||
@Autowired
|
||||
public NestedDmpElasticBuilder(
|
||||
ConventionService conventionService, QueryFactory queryFactory, BuilderFactory builderFactory) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(NestedDmpElasticBuilder.class)));
|
||||
this.queryFactory = queryFactory;
|
||||
this.builderFactory = builderFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<NestedDmpElasticEntity> build(List<DmpEntity> data) throws MyApplicationException {
|
||||
if (data == null)
|
||||
return new ArrayList<>();
|
||||
|
||||
Map<UUID, List<NestedReferenceElasticEntity>> referenceElasticEntityMap = this.collectDmpReferences(data);
|
||||
Map<UUID, List<NestedCollaboratorElasticEntity>> collaboratorElasticEntityMap = this.collectCollaborators(data);
|
||||
Map<UUID, List<NestedDoiElasticEntity>> doiElasticEntityMap = this.collectDois(data);
|
||||
|
||||
List<NestedDmpElasticEntity> models = new ArrayList<>();
|
||||
for (DmpEntity d : data) {
|
||||
NestedDmpElasticEntity m = new NestedDmpElasticEntity();
|
||||
m.setId(d.getId());
|
||||
m.setLabel(d.getLabel());
|
||||
m.setDescription(d.getDescription());
|
||||
m.setVersion(d.getVersion());
|
||||
m.setStatus(d.getStatus());
|
||||
m.setAccessType(d.getAccessType());
|
||||
m.setLanguage(d.getLanguage());
|
||||
m.setBlueprintId(d.getBlueprint());
|
||||
m.setGroupId(d.getGroupId());
|
||||
m.setGroupId(d.getGroupId());
|
||||
m.setFinalizedAt(Date.from(d.getFinalizedAt()));
|
||||
if (referenceElasticEntityMap != null) m.setReferences(referenceElasticEntityMap.getOrDefault(d.getId(), null));
|
||||
if (collaboratorElasticEntityMap != null) m.setCollaborators(collaboratorElasticEntityMap.getOrDefault(d.getId(), null));
|
||||
if (doiElasticEntityMap != null) m.setDois(doiElasticEntityMap.getOrDefault(d.getId(), null));
|
||||
models.add(m);
|
||||
}
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
return models;
|
||||
}
|
||||
|
||||
private Map<UUID, List<NestedReferenceElasticEntity>> collectDmpReferences(List<DmpEntity> data) throws MyApplicationException {
|
||||
if (data.isEmpty()) return null;
|
||||
this.logger.debug("checking related - {}", DmpReference.class.getSimpleName());
|
||||
|
||||
DmpReferenceQuery associationQuery = this.queryFactory.query(DmpReferenceQuery.class).dmpIds(data.stream().map(DmpEntity::getId).collect(Collectors.toList())).isActives(IsActive.Active);
|
||||
List<DmpReferenceEntity> associationEntities = associationQuery.collect();
|
||||
|
||||
ReferenceQuery query = this.queryFactory.query(ReferenceQuery.class).isActive(IsActive.Active).ids(associationEntities.stream().map(DmpReferenceEntity::getReferenceId).distinct().collect(Collectors.toList()));
|
||||
Map<UUID, NestedReferenceElasticEntity> itemMapById = this.builderFactory.builder(NestedReferenceElasticBuilder.class).asForeignKey(query, NestedReferenceElasticEntity::getId);
|
||||
|
||||
Map<UUID, List<NestedReferenceElasticEntity>> itemMap = new HashMap<>();
|
||||
for (DmpReferenceEntity associationEntity : associationEntities){
|
||||
if (!itemMap.containsKey(associationEntity.getDmpId())) itemMap.put(associationEntity.getDmpId(), new ArrayList<>());
|
||||
NestedReferenceElasticEntity item = itemMapById.getOrDefault(associationEntity.getReferenceId(), null);
|
||||
if (item != null) itemMap.get(associationEntity.getDmpId()).add(item);
|
||||
}
|
||||
|
||||
return itemMap;
|
||||
}
|
||||
|
||||
private Map<UUID, List<NestedCollaboratorElasticEntity>> collectCollaborators(List<DmpEntity> data) throws MyApplicationException {
|
||||
if (data.isEmpty())
|
||||
return null;
|
||||
this.logger.debug("checking related - {}", DmpUserEntity.class.getSimpleName());
|
||||
|
||||
DmpUserQuery associationQuery = this.queryFactory.query(DmpUserQuery.class).dmpIds(data.stream().map(DmpEntity::getId).collect(Collectors.toList())).isActives(IsActive.Active);
|
||||
List<DmpUserEntity> associationEntities = associationQuery.collect();
|
||||
|
||||
Map<UUID, NestedCollaboratorElasticEntity> itemMapById = this.builderFactory.builder(NestedCollaboratorElasticBuilder.class).asForeignKey(associationEntities, NestedCollaboratorElasticEntity::getId);
|
||||
|
||||
Map<UUID, List<NestedCollaboratorElasticEntity>> itemMap = new HashMap<>();
|
||||
for (DmpUserEntity associationEntity : associationEntities){
|
||||
if (!itemMap.containsKey(associationEntity.getId())) itemMap.put(associationEntity.getDmp(), new ArrayList<>());
|
||||
NestedCollaboratorElasticEntity item = itemMapById.getOrDefault(associationEntity.getId(), null);
|
||||
if (item != null) itemMap.get(associationEntity.getDmp()).add(item);
|
||||
}
|
||||
return itemMap;
|
||||
}
|
||||
|
||||
private Map<UUID, List<NestedDoiElasticEntity>> collectDois(List<DmpEntity> data) throws MyApplicationException {
|
||||
if (data.isEmpty())
|
||||
return null;
|
||||
this.logger.debug("checking related - {}", EntityDoiEntity.class.getSimpleName());
|
||||
|
||||
EntityDoiQuery associationQuery = this.queryFactory.query(EntityDoiQuery.class).entityIds(data.stream().map(DmpEntity::getId).collect(Collectors.toList())).isActive(IsActive.Active);
|
||||
List<EntityDoiEntity> associationEntities = associationQuery.collect();
|
||||
|
||||
Map<UUID, NestedDoiElasticEntity> itemMapById = this.builderFactory.builder(NestedDoiElasticBuilder.class).asForeignKey(associationEntities, NestedDoiElasticEntity::getId);
|
||||
|
||||
Map<UUID, List<NestedDoiElasticEntity>> itemMap = new HashMap<>();
|
||||
for (EntityDoiEntity associationEntity : associationEntities){
|
||||
if (!itemMap.containsKey(associationEntity.getId())) itemMap.put(associationEntity.getEntityId(), new ArrayList<>());
|
||||
NestedDoiElasticEntity item = itemMapById.getOrDefault(associationEntity.getId(), null);
|
||||
if (item != null) itemMap.get(associationEntity.getEntityId()).add(item);
|
||||
}
|
||||
return itemMap;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package eu.eudat.elastic.elasticbuilder.nested;
|
||||
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.data.EntityDoiEntity;
|
||||
import eu.eudat.elastic.data.nested.NestedDoiElasticEntity;
|
||||
import eu.eudat.elastic.elasticbuilder.BaseElasticBuilder;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class NestedDoiElasticBuilder extends BaseElasticBuilder<NestedDoiElasticEntity, EntityDoiEntity> {
|
||||
|
||||
@Autowired
|
||||
public NestedDoiElasticBuilder(
|
||||
ConventionService conventionService) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(NestedDoiElasticBuilder.class)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<NestedDoiElasticEntity> build(List<EntityDoiEntity> data) throws MyApplicationException {
|
||||
if (data == null)
|
||||
return new ArrayList<>();
|
||||
|
||||
List<NestedDoiElasticEntity> models = new ArrayList<>();
|
||||
for (EntityDoiEntity d : data) {
|
||||
NestedDoiElasticEntity m = new NestedDoiElasticEntity();
|
||||
m.setId(d.getId());
|
||||
m.setDoi(d.getDoi());
|
||||
m.setRepositoryId(d.getRepositoryId());
|
||||
models.add(m);
|
||||
}
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
return models;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
package eu.eudat.elastic.elasticbuilder.nested;
|
||||
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.data.ReferenceEntity;
|
||||
import eu.eudat.elastic.data.nested.NestedReferenceElasticEntity;
|
||||
import eu.eudat.elastic.elasticbuilder.BaseElasticBuilder;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class NestedReferenceElasticBuilder extends BaseElasticBuilder<NestedReferenceElasticEntity, ReferenceEntity> {
|
||||
|
||||
@Autowired
|
||||
public NestedReferenceElasticBuilder(
|
||||
ConventionService conventionService) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(NestedReferenceElasticBuilder.class)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<NestedReferenceElasticEntity> build(List<ReferenceEntity> data) throws MyApplicationException {
|
||||
if (data == null)
|
||||
return new ArrayList<>();
|
||||
|
||||
List<NestedReferenceElasticEntity> models = new ArrayList<>();
|
||||
for (ReferenceEntity d : data) {
|
||||
NestedReferenceElasticEntity m = new NestedReferenceElasticEntity();
|
||||
m.setId(d.getId());
|
||||
m.setLabel(d.getLabel());
|
||||
models.add(m);
|
||||
}
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
return models;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package eu.eudat.elastic.elasticbuilder.nested;
|
||||
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.data.TagEntity;
|
||||
import eu.eudat.elastic.data.nested.NestedTagElasticEntity;
|
||||
import eu.eudat.elastic.elasticbuilder.BaseElasticBuilder;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class NestedTagElasticBuilder extends BaseElasticBuilder<NestedTagElasticEntity, TagEntity> {
|
||||
|
||||
@Autowired
|
||||
public NestedTagElasticBuilder(
|
||||
ConventionService conventionService) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(NestedTagElasticBuilder.class)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<NestedTagElasticEntity> build(List<TagEntity> data) throws MyApplicationException {
|
||||
if (data == null)
|
||||
return new ArrayList<>();
|
||||
|
||||
List<NestedTagElasticEntity> models = new ArrayList<>();
|
||||
for (TagEntity d : data) {
|
||||
NestedTagElasticEntity m = new NestedTagElasticEntity();
|
||||
m.setId(d.getId());
|
||||
m.setLabel(d.getLabel());
|
||||
models.add(m);
|
||||
}
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
return models;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,164 @@
|
|||
package eu.eudat.elastic.query;
|
||||
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commons.enums.DescriptionStatus;
|
||||
import eu.eudat.configurations.elastic.AppElasticProperties;
|
||||
import eu.eudat.elastic.data.DescriptionElasticEntity;
|
||||
import eu.eudat.service.elastic.ElasticService;
|
||||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.QueryFactory;
|
||||
import gr.cite.tools.elastic.configuration.ElasticProperties;
|
||||
import gr.cite.tools.elastic.mapper.FieldBasedMapper;
|
||||
import gr.cite.tools.elastic.query.ElasticField;
|
||||
import gr.cite.tools.elastic.query.ElasticNestedQuery;
|
||||
import gr.cite.tools.elastic.query.ElasticQuery;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.data.elasticsearch.client.elc.ElasticsearchTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
//Like in C# make it Transient
|
||||
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
|
||||
public class DescriptionElasticQuery extends ElasticQuery<DescriptionElasticEntity, UUID> {
|
||||
|
||||
private Collection<UUID> ids;
|
||||
private Collection<DescriptionStatus> statuses;
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
|
||||
public DescriptionElasticQuery ids(UUID value) {
|
||||
this.ids = List.of(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public DescriptionElasticQuery ids(UUID... value) {
|
||||
this.ids = Arrays.asList(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public DescriptionElasticQuery ids(Collection<UUID> values) {
|
||||
this.ids = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DescriptionElasticQuery statuses(DescriptionStatus value) {
|
||||
this.statuses = List.of(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public DescriptionElasticQuery statuses(DescriptionStatus... value) {
|
||||
this.statuses = Arrays.asList(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public DescriptionElasticQuery statuses(Collection<DescriptionStatus> values) {
|
||||
this.statuses = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DescriptionElasticQuery authorize(EnumSet<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
private final QueryFactory queryFactory;
|
||||
private final AppElasticProperties appElasticProperties;
|
||||
private final ElasticService elasticService;
|
||||
@Autowired()
|
||||
public DescriptionElasticQuery(ElasticsearchTemplate elasticsearchTemplate, ElasticProperties elasticProperties, QueryFactory queryFactory, AppElasticProperties appElasticProperties, ElasticService elasticService) {
|
||||
super(elasticsearchTemplate, elasticProperties);
|
||||
this.queryFactory = queryFactory;
|
||||
this.appElasticProperties = appElasticProperties;
|
||||
this.elasticService = elasticService;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean isFalseQuery() {
|
||||
return this.isEmpty(this.ids) || this.isEmpty(this.statuses);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<DescriptionElasticEntity> entityClass() {
|
||||
return DescriptionElasticEntity.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Query applyFilters() {
|
||||
List<Query> predicates = new ArrayList<>();
|
||||
if (ids != null) {
|
||||
predicates.add(this.containsUUID(this.elasticFieldOf(DescriptionElasticEntity._id), ids)._toQuery());
|
||||
}
|
||||
if (statuses != null) {
|
||||
predicates.add(this.contains(this.elasticFieldOf(DescriptionElasticEntity._status), statuses.stream().map(x-> x.getValue()).collect(Collectors.toList()).toArray(new Short[statuses.size()]))._toQuery());
|
||||
}
|
||||
|
||||
if (!predicates.isEmpty()) {
|
||||
return this.and(predicates);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DescriptionElasticEntity convert(Map<String, Object> rawData, Set<String> columns) {
|
||||
DescriptionElasticEntity mocDoc = new DescriptionElasticEntity();
|
||||
if (columns.contains(DescriptionElasticEntity._id)) mocDoc.setId(FieldBasedMapper.shallowSafeConversion(rawData.get(DescriptionElasticEntity._id), UUID.class));
|
||||
if (columns.contains(DescriptionElasticEntity._label)) mocDoc.setLabel(FieldBasedMapper.shallowSafeConversion(rawData.get(DescriptionElasticEntity._label), String.class));
|
||||
if (columns.contains(DescriptionElasticEntity._description)) mocDoc.setDescription(FieldBasedMapper.shallowSafeConversion(rawData.get(DescriptionElasticEntity._description), String.class));
|
||||
if (columns.contains(DescriptionElasticEntity._status)) mocDoc.setStatus(FieldBasedMapper.shallowSafeConversion(rawData.get(DescriptionElasticEntity._status), DescriptionStatus.class));
|
||||
if (columns.contains(DescriptionElasticEntity._finalizedAt)) mocDoc.setFinalizedAt(FieldBasedMapper.shallowSafeConversion(rawData.get(DescriptionElasticEntity._finalizedAt), Date.class));
|
||||
mocDoc.setTags(this.convertNested(rawData, columns, this.queryFactory.query(NestedTagElasticQuery.class), DescriptionElasticEntity._tags, null));
|
||||
mocDoc.setReferences(this.convertNested(rawData, columns, this.queryFactory.query(NestedReferenceElasticQuery.class), DescriptionElasticEntity._references, null));
|
||||
mocDoc.setDescriptionTemplate(this.convertInnerObject(rawData, columns, this.queryFactory.query(InnerObjectDescriptionTemplateElasticQuery.class), DescriptionElasticEntity._descriptionTemplate, null));
|
||||
mocDoc.setDmp(this.convertInnerObject(rawData, columns, this.queryFactory.query(InnerObjectDmpElasticQuery.class), DescriptionElasticEntity._dmp, null));
|
||||
return mocDoc;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ElasticField fieldNameOf(FieldResolver item) {
|
||||
if (item.match(DescriptionElasticEntity._id)) return this.elasticFieldOf(DescriptionElasticEntity._id);
|
||||
else if (item.match(DescriptionElasticEntity._label)) return this.elasticFieldOf(DescriptionElasticEntity._label);
|
||||
else if (item.match(DescriptionElasticEntity._description)) return this.elasticFieldOf(DescriptionElasticEntity._description);
|
||||
else if (item.match(DescriptionElasticEntity._status)) return this.elasticFieldOf(DescriptionElasticEntity._status);
|
||||
else if (item.match(DescriptionElasticEntity._finalizedAt)) return this.elasticFieldOf(DescriptionElasticEntity._finalizedAt);
|
||||
else if (item.prefix(DescriptionElasticEntity._references)) return this.queryFactory.query(NestedReferenceElasticQuery.class).nestedPath(DescriptionElasticEntity._references).fieldNameOf(this.extractPrefixed(item, DescriptionElasticEntity._references));
|
||||
else if (item.prefix(DescriptionElasticEntity._tags)) return this.queryFactory.query(NestedTagElasticQuery.class).nestedPath(DescriptionElasticEntity._tags).fieldNameOf(this.extractPrefixed(item, DescriptionElasticEntity._tags));
|
||||
else if (item.prefix(DescriptionElasticEntity._descriptionTemplate)) return this.queryFactory.query(InnerObjectDescriptionTemplateElasticQuery.class).innerPath(DescriptionElasticEntity._descriptionTemplate).fieldNameOf(this.extractPrefixed(item, DescriptionElasticEntity._description));
|
||||
else if (item.prefix(DescriptionElasticEntity._dmp)) return this.queryFactory.query(InnerObjectDmpElasticQuery.class).innerPath(DescriptionElasticEntity._dmp).fieldNameOf(this.extractPrefixed(item, DescriptionElasticEntity._dmp));
|
||||
else return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getIndex() {
|
||||
List<String> indexNames = new ArrayList<>();
|
||||
indexNames.add(this.appElasticProperties.getDescriptionIndexName());
|
||||
try {
|
||||
this.elasticService.ensureDescriptionIndex();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return indexNames.toArray(new String[indexNames.size()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected UUID toKey(String key) {
|
||||
return UUID.fromString(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ElasticField getKeyField() {
|
||||
return this.elasticFieldOf(DescriptionElasticEntity._id);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ElasticNestedQuery<?, ?, ?> nestedQueryOf(FieldResolver item) {
|
||||
if (item.prefix(DescriptionElasticEntity._references)) return this.queryFactory.query(NestedReferenceElasticQuery.class).nestedPath(DescriptionElasticEntity._references);
|
||||
else if (item.prefix(DescriptionElasticEntity._tags)) return this.queryFactory.query(NestedTagElasticQuery.class).nestedPath(DescriptionElasticEntity._tags);
|
||||
else return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,171 @@
|
|||
package eu.eudat.elastic.query;
|
||||
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commons.enums.DmpAccessType;
|
||||
import eu.eudat.commons.enums.DmpStatus;
|
||||
import eu.eudat.configurations.elastic.AppElasticProperties;
|
||||
import eu.eudat.elastic.data.DmpElasticEntity;
|
||||
import eu.eudat.service.elastic.ElasticService;
|
||||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.QueryFactory;
|
||||
import gr.cite.tools.elastic.configuration.ElasticProperties;
|
||||
import gr.cite.tools.elastic.mapper.FieldBasedMapper;
|
||||
import gr.cite.tools.elastic.query.ElasticField;
|
||||
import gr.cite.tools.elastic.query.ElasticNestedQuery;
|
||||
import gr.cite.tools.elastic.query.ElasticQuery;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.data.elasticsearch.client.elc.ElasticsearchTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
//Like in C# make it Transient
|
||||
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
|
||||
public class DmpElasticQuery extends ElasticQuery<DmpElasticEntity, UUID> {
|
||||
|
||||
private Collection<UUID> ids;
|
||||
private Collection<DmpStatus> statuses;
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
|
||||
public DmpElasticQuery ids(UUID value) {
|
||||
this.ids = List.of(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public DmpElasticQuery ids(UUID... value) {
|
||||
this.ids = Arrays.asList(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public DmpElasticQuery ids(Collection<UUID> values) {
|
||||
this.ids = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DmpElasticQuery statuses(DmpStatus value) {
|
||||
this.statuses = List.of(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public DmpElasticQuery statuses(DmpStatus... value) {
|
||||
this.statuses = Arrays.asList(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public DmpElasticQuery statuses(Collection<DmpStatus> values) {
|
||||
this.statuses = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DmpElasticQuery authorize(EnumSet<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
private final QueryFactory queryFactory;
|
||||
private final AppElasticProperties appElasticProperties;
|
||||
private final ElasticService elasticService;
|
||||
@Autowired()
|
||||
public DmpElasticQuery(ElasticsearchTemplate elasticsearchTemplate, ElasticProperties elasticProperties, QueryFactory queryFactory, AppElasticProperties appElasticProperties, ElasticService elasticService) {
|
||||
super(elasticsearchTemplate, elasticProperties);
|
||||
this.queryFactory = queryFactory;
|
||||
this.appElasticProperties = appElasticProperties;
|
||||
this.elasticService = elasticService;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean isFalseQuery() {
|
||||
return this.isEmpty(this.ids) || this.isEmpty(this.statuses);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<DmpElasticEntity> entityClass() {
|
||||
return DmpElasticEntity.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Query applyFilters() {
|
||||
List<Query> predicates = new ArrayList<>();
|
||||
if (ids != null) {
|
||||
predicates.add(this.containsUUID(this.elasticFieldOf(DmpElasticEntity._id), ids)._toQuery());
|
||||
}
|
||||
if (statuses != null) {
|
||||
predicates.add(this.contains(this.elasticFieldOf(DmpElasticEntity._status), statuses.stream().map(x-> x.getValue()).collect(Collectors.toList()).toArray(new Short[statuses.size()]))._toQuery());
|
||||
}
|
||||
|
||||
if (!predicates.isEmpty()) {
|
||||
return this.and(predicates);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DmpElasticEntity convert(Map<String, Object> rawData, Set<String> columns) {
|
||||
DmpElasticEntity mocDoc = new DmpElasticEntity();
|
||||
if (columns.contains(DmpElasticEntity._id)) mocDoc.setId(FieldBasedMapper.shallowSafeConversion(rawData.get(DmpElasticEntity._id), UUID.class));
|
||||
if (columns.contains(DmpElasticEntity._label)) mocDoc.setLabel(FieldBasedMapper.shallowSafeConversion(rawData.get(DmpElasticEntity._label), String.class));
|
||||
if (columns.contains(DmpElasticEntity._description)) mocDoc.setDescription(FieldBasedMapper.shallowSafeConversion(rawData.get(DmpElasticEntity._description), String.class));
|
||||
if (columns.contains(DmpElasticEntity._status)) mocDoc.setStatus(FieldBasedMapper.shallowSafeConversion(rawData.get(DmpElasticEntity._status), DmpStatus.class));
|
||||
if (columns.contains(DmpElasticEntity._groupId)) mocDoc.setGroupId(FieldBasedMapper.shallowSafeConversion(rawData.get(DmpElasticEntity._groupId), UUID.class));
|
||||
if (columns.contains(DmpElasticEntity._accessType)) mocDoc.setAccessType(FieldBasedMapper.shallowSafeConversion(rawData.get(DmpElasticEntity._accessType), DmpAccessType.class));
|
||||
if (columns.contains(DmpElasticEntity._finalizedAt)) mocDoc.setFinalizedAt(FieldBasedMapper.shallowSafeConversion(rawData.get(DmpElasticEntity._finalizedAt), Date.class));
|
||||
mocDoc.setCollaborators(this.convertNested(rawData, columns, this.queryFactory.query(NestedCollaboratorElasticQuery.class), DmpElasticEntity._collaborators, null));
|
||||
mocDoc.setReferences(this.convertNested(rawData, columns, this.queryFactory.query(NestedReferenceElasticQuery.class), DmpElasticEntity._references, null));
|
||||
mocDoc.setDescriptionTemplates(this.convertNested(rawData, columns, this.queryFactory.query(NestedDescriptionTemplateElasticQuery.class), DmpElasticEntity._descriptionTemplates, null));
|
||||
mocDoc.setDescriptions(this.convertNested(rawData, columns, this.queryFactory.query(NestedDescriptionElasticQuery.class), DmpElasticEntity._descriptions, null));
|
||||
return mocDoc;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ElasticField fieldNameOf(FieldResolver item) {
|
||||
if (item.match(DmpElasticEntity._id)) return this.elasticFieldOf(DmpElasticEntity._id);
|
||||
else if (item.match(DmpElasticEntity._label)) return this.elasticFieldOf(DmpElasticEntity._label);
|
||||
else if (item.match(DmpElasticEntity._description)) return this.elasticFieldOf(DmpElasticEntity._description);
|
||||
else if (item.match(DmpElasticEntity._status)) return this.elasticFieldOf(DmpElasticEntity._status);
|
||||
else if (item.match(DmpElasticEntity._groupId)) return this.elasticFieldOf(DmpElasticEntity._groupId);
|
||||
else if (item.match(DmpElasticEntity._finalizedAt)) return this.elasticFieldOf(DmpElasticEntity._finalizedAt);
|
||||
else if (item.match(DmpElasticEntity._accessType)) return this.elasticFieldOf(DmpElasticEntity._accessType);
|
||||
else if (item.prefix(DmpElasticEntity._collaborators)) return this.queryFactory.query(NestedCollaboratorElasticQuery.class).nestedPath(DmpElasticEntity._collaborators).fieldNameOf(this.extractPrefixed(item, DmpElasticEntity._collaborators));
|
||||
else if (item.prefix(DmpElasticEntity._references)) return this.queryFactory.query(NestedReferenceElasticQuery.class).nestedPath(DmpElasticEntity._references).fieldNameOf(this.extractPrefixed(item, DmpElasticEntity._references));
|
||||
else if (item.prefix(DmpElasticEntity._descriptionTemplates)) return this.queryFactory.query(NestedDescriptionTemplateElasticQuery.class).nestedPath(DmpElasticEntity._descriptionTemplates).fieldNameOf(this.extractPrefixed(item, DmpElasticEntity._descriptionTemplates));
|
||||
else if (item.prefix(DmpElasticEntity._descriptions)) return this.queryFactory.query(NestedDescriptionElasticQuery.class).nestedPath(DmpElasticEntity._descriptions).fieldNameOf(this.extractPrefixed(item, DmpElasticEntity._descriptions));
|
||||
else return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getIndex() {
|
||||
List<String> indexNames = new ArrayList<>();
|
||||
indexNames.add(this.appElasticProperties.getDmpIndexName());
|
||||
try {
|
||||
this.elasticService.ensureDescriptionIndex();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return indexNames.toArray(new String[indexNames.size()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected UUID toKey(String key) {
|
||||
return UUID.fromString(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ElasticField getKeyField() {
|
||||
return this.elasticFieldOf(DmpElasticEntity._id);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ElasticNestedQuery<?, ?, ?> nestedQueryOf(FieldResolver item) {
|
||||
if (item.prefix(DmpElasticEntity._collaborators)) return this.queryFactory.query(NestedCollaboratorElasticQuery.class).nestedPath(DmpElasticEntity._collaborators);
|
||||
else if (item.prefix(DmpElasticEntity._references)) return this.queryFactory.query(NestedReferenceElasticQuery.class).nestedPath(DmpElasticEntity._references);
|
||||
else if (item.prefix(DmpElasticEntity._descriptionTemplates)) return this.queryFactory.query(NestedDescriptionTemplateElasticQuery.class).nestedPath(DmpElasticEntity._descriptionTemplates);
|
||||
else if (item.prefix(DmpElasticEntity._descriptions)) return this.queryFactory.query(NestedDescriptionElasticQuery.class).nestedPath(DmpElasticEntity._descriptions);
|
||||
else return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,94 @@
|
|||
package eu.eudat.elastic.query;
|
||||
|
||||
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
|
||||
import eu.eudat.elastic.data.nested.NestedDescriptionTemplateElasticEntity;
|
||||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.elastic.configuration.ElasticProperties;
|
||||
import gr.cite.tools.elastic.mapper.FieldBasedMapper;
|
||||
import gr.cite.tools.elastic.query.ElasticField;
|
||||
import gr.cite.tools.elastic.query.ElasticInnerObjectQuery;
|
||||
import gr.cite.tools.elastic.query.ElasticNestedQuery;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.data.elasticsearch.client.elc.ElasticsearchTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class InnerObjectDescriptionTemplateElasticQuery extends ElasticInnerObjectQuery<InnerObjectDescriptionTemplateElasticQuery, NestedDescriptionTemplateElasticEntity, UUID> {
|
||||
|
||||
private String innerPath;
|
||||
|
||||
@Override
|
||||
public InnerObjectDescriptionTemplateElasticQuery innerPath(String value) {
|
||||
this.innerPath = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public InnerObjectDescriptionTemplateElasticQuery(
|
||||
ElasticsearchTemplate elasticsearchRestTemplate,
|
||||
ElasticProperties elasticProperties
|
||||
) {
|
||||
super(elasticsearchRestTemplate, elasticProperties);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<NestedDescriptionTemplateElasticEntity> entityClass() {
|
||||
return NestedDescriptionTemplateElasticEntity.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean isFalseQuery() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Query applyAuthZ() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Query applyFilters() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NestedDescriptionTemplateElasticEntity convert(Map<String, Object> rawData, Set<String> columns) {
|
||||
NestedDescriptionTemplateElasticEntity mocDoc = new NestedDescriptionTemplateElasticEntity();
|
||||
if (columns.contains(NestedDescriptionTemplateElasticEntity._id)) mocDoc.setId(FieldBasedMapper.shallowSafeConversion(rawData.get(NestedDescriptionTemplateElasticEntity._id), UUID.class));
|
||||
if (columns.contains(NestedDescriptionTemplateElasticEntity._label)) mocDoc.setLabel(FieldBasedMapper.shallowSafeConversion(rawData.get(NestedDescriptionTemplateElasticEntity._label), String.class));
|
||||
return mocDoc;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ElasticField fieldNameOf(FieldResolver item) {
|
||||
if (item.match(NestedDescriptionTemplateElasticEntity._id)) return this.elasticFieldOf(NestedDescriptionTemplateElasticEntity._id).disableInfer(true);
|
||||
else if (item.match(NestedDescriptionTemplateElasticEntity._label)) return this.elasticFieldOf(NestedDescriptionTemplateElasticEntity._label).disableInfer(true);
|
||||
else return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getInnerPath() {
|
||||
return this.innerPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected UUID toKey(String key) {
|
||||
return UUID.fromString(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ElasticField getKeyField() {
|
||||
return this.elasticFieldOf(NestedDescriptionTemplateElasticEntity._id);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ElasticNestedQuery<?, ?, ?> nestedQueryOf(FieldResolver item) {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,107 @@
|
|||
package eu.eudat.elastic.query;
|
||||
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
|
||||
import eu.eudat.commons.enums.DmpAccessType;
|
||||
import eu.eudat.commons.enums.DmpStatus;
|
||||
import eu.eudat.elastic.data.nested.NestedDmpElasticEntity;
|
||||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.QueryFactory;
|
||||
import gr.cite.tools.elastic.configuration.ElasticProperties;
|
||||
import gr.cite.tools.elastic.mapper.FieldBasedMapper;
|
||||
import gr.cite.tools.elastic.query.ElasticField;
|
||||
import gr.cite.tools.elastic.query.ElasticInnerObjectQuery;
|
||||
import gr.cite.tools.elastic.query.ElasticNestedQuery;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.data.elasticsearch.client.elc.ElasticsearchTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Component
|
||||
//Like in C# make it Transient
|
||||
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
|
||||
public class InnerObjectDmpElasticQuery extends ElasticInnerObjectQuery<InnerObjectDmpElasticQuery, NestedDmpElasticEntity, UUID> {
|
||||
|
||||
private String innerPath;
|
||||
|
||||
@Override
|
||||
public InnerObjectDmpElasticQuery innerPath(String value) {
|
||||
this.innerPath = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
private final QueryFactory queryFactory;
|
||||
@Autowired()
|
||||
public InnerObjectDmpElasticQuery(ElasticsearchTemplate elasticsearchTemplate, ElasticProperties elasticProperties, QueryFactory queryFactory) {
|
||||
super(elasticsearchTemplate, elasticProperties);
|
||||
this.queryFactory = queryFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<NestedDmpElasticEntity> entityClass() {
|
||||
return NestedDmpElasticEntity.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean isFalseQuery() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Query applyFilters() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NestedDmpElasticEntity convert(Map<String, Object> rawData, Set<String> columns) {
|
||||
NestedDmpElasticEntity mocDoc = new NestedDmpElasticEntity();
|
||||
if (columns.contains(NestedDmpElasticEntity._id)) mocDoc.setId(FieldBasedMapper.shallowSafeConversion(rawData.get(NestedDmpElasticEntity._id), UUID.class));
|
||||
if (columns.contains(NestedDmpElasticEntity._label)) mocDoc.setLabel(FieldBasedMapper.shallowSafeConversion(rawData.get(NestedDmpElasticEntity._label), String.class));
|
||||
if (columns.contains(NestedDmpElasticEntity._description)) mocDoc.setDescription(FieldBasedMapper.shallowSafeConversion(rawData.get(NestedDmpElasticEntity._description), String.class));
|
||||
if (columns.contains(NestedDmpElasticEntity._status)) mocDoc.setStatus(FieldBasedMapper.shallowSafeConversion(rawData.get(NestedDmpElasticEntity._status), DmpStatus.class));
|
||||
if (columns.contains(NestedDmpElasticEntity._groupId)) mocDoc.setGroupId(FieldBasedMapper.shallowSafeConversion(rawData.get(NestedDmpElasticEntity._groupId), UUID.class));
|
||||
if (columns.contains(NestedDmpElasticEntity._accessType)) mocDoc.setAccessType(FieldBasedMapper.shallowSafeConversion(rawData.get(NestedDmpElasticEntity._accessType), DmpAccessType.class));
|
||||
if (columns.contains(NestedDmpElasticEntity._finalizedAt)) mocDoc.setFinalizedAt(FieldBasedMapper.shallowSafeConversion(rawData.get(NestedDmpElasticEntity._finalizedAt), Date.class));
|
||||
mocDoc.setCollaborators(this.convertNested(rawData, columns, this.queryFactory.query(NestedCollaboratorElasticQuery.class), NestedDmpElasticEntity._collaborators, null));
|
||||
mocDoc.setReferences(this.convertNested(rawData, columns, this.queryFactory.query(NestedReferenceElasticQuery.class), NestedDmpElasticEntity._references, null));
|
||||
return mocDoc;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ElasticField fieldNameOf(FieldResolver item) {
|
||||
if (item.match(NestedDmpElasticEntity._id)) return this.elasticFieldOf(NestedDmpElasticEntity._id);
|
||||
else if (item.match(NestedDmpElasticEntity._label)) return this.elasticFieldOf(NestedDmpElasticEntity._label);
|
||||
else if (item.match(NestedDmpElasticEntity._description)) return this.elasticFieldOf(NestedDmpElasticEntity._description);
|
||||
else if (item.match(NestedDmpElasticEntity._status)) return this.elasticFieldOf(NestedDmpElasticEntity._status);
|
||||
else if (item.match(NestedDmpElasticEntity._groupId)) return this.elasticFieldOf(NestedDmpElasticEntity._groupId);
|
||||
else if (item.match(NestedDmpElasticEntity._finalizedAt)) return this.elasticFieldOf(NestedDmpElasticEntity._finalizedAt);
|
||||
else if (item.match(NestedDmpElasticEntity._accessType)) return this.elasticFieldOf(NestedDmpElasticEntity._accessType);
|
||||
else if (item.prefix(NestedDmpElasticEntity._collaborators)) return this.queryFactory.query(NestedCollaboratorElasticQuery.class).nestedPath(NestedDmpElasticEntity._collaborators).fieldNameOf(this.extractPrefixed(item, NestedDmpElasticEntity._collaborators));
|
||||
else if (item.prefix(NestedDmpElasticEntity._references)) return this.queryFactory.query(NestedReferenceElasticQuery.class).nestedPath(NestedDmpElasticEntity._references).fieldNameOf(this.extractPrefixed(item, NestedDmpElasticEntity._references));
|
||||
else return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getInnerPath() {
|
||||
return this.innerPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected UUID toKey(String key) {
|
||||
return UUID.fromString(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ElasticField getKeyField() {
|
||||
return this.elasticFieldOf(NestedDmpElasticEntity._id);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ElasticNestedQuery<?, ?, ?> nestedQueryOf(FieldResolver item) {
|
||||
if (item.prefix(NestedDmpElasticEntity._collaborators)) return this.queryFactory.query(NestedCollaboratorElasticQuery.class).nestedPath(NestedDmpElasticEntity._collaborators);
|
||||
else if (item.prefix(NestedDmpElasticEntity._references)) return this.queryFactory.query(NestedReferenceElasticQuery.class).nestedPath(NestedDmpElasticEntity._references);
|
||||
else return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,94 @@
|
|||
package eu.eudat.elastic.query;
|
||||
|
||||
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
|
||||
import eu.eudat.commons.enums.DmpUserRole;
|
||||
import eu.eudat.elastic.data.nested.NestedCollaboratorElasticEntity;
|
||||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.elastic.configuration.ElasticProperties;
|
||||
import gr.cite.tools.elastic.mapper.FieldBasedMapper;
|
||||
import gr.cite.tools.elastic.query.ElasticField;
|
||||
import gr.cite.tools.elastic.query.ElasticNestedQuery;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.data.elasticsearch.client.elc.ElasticsearchTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class NestedCollaboratorElasticQuery extends ElasticNestedQuery<NestedCollaboratorElasticQuery, NestedCollaboratorElasticEntity, UUID> {
|
||||
|
||||
private String nestedPath;
|
||||
|
||||
@Override
|
||||
public NestedCollaboratorElasticQuery nestedPath(String value) {
|
||||
this.nestedPath = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public NestedCollaboratorElasticQuery(
|
||||
ElasticsearchTemplate elasticsearchRestTemplate,
|
||||
ElasticProperties elasticProperties
|
||||
) {
|
||||
super(elasticsearchRestTemplate, elasticProperties);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<NestedCollaboratorElasticEntity> entityClass() {
|
||||
return NestedCollaboratorElasticEntity.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean isFalseQuery() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Query applyAuthZ() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Query applyFilters() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NestedCollaboratorElasticEntity convert(Map<String, Object> rawData, Set<String> columns) {
|
||||
NestedCollaboratorElasticEntity mocDoc = new NestedCollaboratorElasticEntity();
|
||||
if (columns.contains(NestedCollaboratorElasticEntity._id)) mocDoc.setId(FieldBasedMapper.shallowSafeConversion(rawData.get(NestedCollaboratorElasticEntity._id), UUID.class));
|
||||
if (columns.contains(NestedCollaboratorElasticEntity._name)) mocDoc.setName(FieldBasedMapper.shallowSafeConversion(rawData.get(NestedCollaboratorElasticEntity._name), String.class));
|
||||
if (columns.contains(NestedCollaboratorElasticEntity._role)) mocDoc.setRole(FieldBasedMapper.shallowSafeConversion(rawData.get(NestedCollaboratorElasticEntity._role), DmpUserRole.class));
|
||||
return mocDoc;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ElasticField fieldNameOf(FieldResolver item) {
|
||||
if (item.match(NestedCollaboratorElasticEntity._id)) return this.elasticFieldOf(NestedCollaboratorElasticEntity._id).disableInfer(true);
|
||||
else if (item.match(NestedCollaboratorElasticEntity._name)) return this.elasticFieldOf(NestedCollaboratorElasticEntity._name).disableInfer(true);
|
||||
else if (item.match(NestedCollaboratorElasticEntity._role)) return this.elasticFieldOf(NestedCollaboratorElasticEntity._role).disableInfer(true);
|
||||
else return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getNestedPath() {
|
||||
return this.nestedPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected UUID toKey(String key) {
|
||||
return UUID.fromString(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ElasticField getKeyField() {
|
||||
return this.elasticFieldOf(NestedCollaboratorElasticEntity._id);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ElasticNestedQuery<?, ?, ?> nestedQueryOf(FieldResolver item) {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,114 @@
|
|||
package eu.eudat.elastic.query;
|
||||
|
||||
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
|
||||
import eu.eudat.commons.enums.DescriptionStatus;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.elastic.data.nested.NestedDescriptionElasticEntity;
|
||||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.QueryFactory;
|
||||
import gr.cite.tools.elastic.configuration.ElasticProperties;
|
||||
import gr.cite.tools.elastic.mapper.FieldBasedMapper;
|
||||
import gr.cite.tools.elastic.query.ElasticField;
|
||||
import gr.cite.tools.elastic.query.ElasticNestedQuery;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.data.elasticsearch.client.elc.ElasticsearchTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class NestedDescriptionElasticQuery extends ElasticNestedQuery<NestedDescriptionElasticQuery, NestedDescriptionElasticEntity, UUID> {
|
||||
|
||||
private String nestedPath;
|
||||
|
||||
@Override
|
||||
public NestedDescriptionElasticQuery nestedPath(String value) {
|
||||
this.nestedPath = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
private final QueryFactory queryFactory;
|
||||
private final ConventionService conventionService;
|
||||
public NestedDescriptionElasticQuery(
|
||||
ElasticsearchTemplate elasticsearchRestTemplate,
|
||||
ElasticProperties elasticProperties,
|
||||
QueryFactory queryFactory, ConventionService conventionService) {
|
||||
super(elasticsearchRestTemplate, elasticProperties);
|
||||
this.queryFactory = queryFactory;
|
||||
this.conventionService = conventionService;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<NestedDescriptionElasticEntity> entityClass() {
|
||||
return NestedDescriptionElasticEntity.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean isFalseQuery() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Query applyAuthZ() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Query applyFilters() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NestedDescriptionElasticEntity convert(Map<String, Object> rawData, Set<String> columns) {
|
||||
NestedDescriptionElasticEntity mocDoc = new NestedDescriptionElasticEntity();
|
||||
if (columns.contains(NestedDescriptionElasticEntity._id)) mocDoc.setId(FieldBasedMapper.shallowSafeConversion(rawData.get(NestedDescriptionElasticEntity._id), UUID.class));
|
||||
if (columns.contains(NestedDescriptionElasticEntity._label)) mocDoc.setLabel(FieldBasedMapper.shallowSafeConversion(rawData.get(NestedDescriptionElasticEntity._label), String.class));
|
||||
if (columns.contains(NestedDescriptionElasticEntity._dmpId)) mocDoc.setDmpId(FieldBasedMapper.shallowSafeConversion(rawData.get(NestedDescriptionElasticEntity._dmpId), UUID.class));
|
||||
if (columns.contains(NestedDescriptionElasticEntity._description)) mocDoc.setDescription(FieldBasedMapper.shallowSafeConversion(rawData.get(NestedDescriptionElasticEntity._description), String.class));
|
||||
if (columns.contains(NestedDescriptionElasticEntity._status)) mocDoc.setStatus(FieldBasedMapper.shallowSafeConversion(rawData.get(NestedDescriptionElasticEntity._status), DescriptionStatus.class));
|
||||
if (columns.contains(NestedDescriptionElasticEntity._finalizedAt)) mocDoc.setFinalizedAt(FieldBasedMapper.shallowSafeConversion(rawData.get(NestedDescriptionElasticEntity._finalizedAt), Date.class));
|
||||
mocDoc.setReferences(this.convertNested(rawData, columns, this.queryFactory.query(NestedReferenceElasticQuery.class), NestedDescriptionElasticEntity._references, this.getNestedPath()));
|
||||
mocDoc.setTags(this.convertNested(rawData, columns, this.queryFactory.query(NestedTagElasticQuery.class), NestedDescriptionElasticEntity._tags, this.getNestedPath()));
|
||||
return mocDoc;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ElasticField fieldNameOf(FieldResolver item) {
|
||||
if (item.match(NestedDescriptionElasticEntity._id)) return this.elasticFieldOf(NestedDescriptionElasticEntity._id);
|
||||
else if (item.match(NestedDescriptionElasticEntity._label)) return this.elasticFieldOf(NestedDescriptionElasticEntity._label);
|
||||
else if (item.match(NestedDescriptionElasticEntity._dmpId)) return this.elasticFieldOf(NestedDescriptionElasticEntity._dmpId);
|
||||
else if (item.match(NestedDescriptionElasticEntity._description)) return this.elasticFieldOf(NestedDescriptionElasticEntity._description);
|
||||
else if (item.match(NestedDescriptionElasticEntity._status)) return this.elasticFieldOf(NestedDescriptionElasticEntity._status);
|
||||
else if (item.match(NestedDescriptionElasticEntity._finalizedAt)) return this.elasticFieldOf(NestedDescriptionElasticEntity._finalizedAt);
|
||||
else if (item.prefix(NestedDescriptionElasticEntity._references)) return this.queryFactory.query(NestedReferenceElasticQuery.class).nestedPath(this.conventionService.asIndexer(this.getNestedPath(), NestedDescriptionElasticEntity._references)).fieldNameOf(this.extractPrefixed(item, NestedDescriptionElasticEntity._references));
|
||||
else if (item.prefix(NestedDescriptionElasticEntity._tags)) return this.queryFactory.query(NestedTagElasticQuery.class).nestedPath(this.conventionService.asIndexer(this.getNestedPath(), NestedDescriptionElasticEntity._tags)).fieldNameOf(this.extractPrefixed(item, NestedDescriptionElasticEntity._tags));
|
||||
else return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getNestedPath() {
|
||||
return this.nestedPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected UUID toKey(String key) {
|
||||
return UUID.fromString(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ElasticField getKeyField() {
|
||||
return this.elasticFieldOf(NestedDescriptionElasticEntity._id);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ElasticNestedQuery<?, ?, ?> nestedQueryOf(FieldResolver item) {
|
||||
if (item.prefix(NestedDescriptionElasticEntity._references)) return this.queryFactory.query(NestedReferenceElasticQuery.class).nestedPath(this.conventionService.asIndexer(this.getNestedPath(), NestedDescriptionElasticEntity._references));
|
||||
else if (item.prefix(NestedDescriptionElasticEntity._tags)) return this.queryFactory.query(NestedTagElasticQuery.class).nestedPath(this.conventionService.asIndexer(this.getNestedPath(), NestedDescriptionElasticEntity._tags));
|
||||
else return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,93 @@
|
|||
package eu.eudat.elastic.query;
|
||||
|
||||
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
|
||||
import eu.eudat.elastic.data.nested.NestedDescriptionTemplateElasticEntity;
|
||||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.elastic.configuration.ElasticProperties;
|
||||
import gr.cite.tools.elastic.mapper.FieldBasedMapper;
|
||||
import gr.cite.tools.elastic.query.ElasticField;
|
||||
import gr.cite.tools.elastic.query.ElasticNestedQuery;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.data.elasticsearch.client.elc.ElasticsearchTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class NestedDescriptionTemplateElasticQuery extends ElasticNestedQuery<NestedDescriptionTemplateElasticQuery, NestedDescriptionTemplateElasticEntity, UUID> {
|
||||
|
||||
private String nestedPath;
|
||||
|
||||
@Override
|
||||
public NestedDescriptionTemplateElasticQuery nestedPath(String value) {
|
||||
this.nestedPath = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public NestedDescriptionTemplateElasticQuery(
|
||||
ElasticsearchTemplate elasticsearchRestTemplate,
|
||||
ElasticProperties elasticProperties
|
||||
) {
|
||||
super(elasticsearchRestTemplate, elasticProperties);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<NestedDescriptionTemplateElasticEntity> entityClass() {
|
||||
return NestedDescriptionTemplateElasticEntity.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean isFalseQuery() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Query applyAuthZ() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Query applyFilters() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NestedDescriptionTemplateElasticEntity convert(Map<String, Object> rawData, Set<String> columns) {
|
||||
NestedDescriptionTemplateElasticEntity mocDoc = new NestedDescriptionTemplateElasticEntity();
|
||||
if (columns.contains(NestedDescriptionTemplateElasticEntity._id)) mocDoc.setId(FieldBasedMapper.shallowSafeConversion(rawData.get(NestedDescriptionTemplateElasticEntity._id), UUID.class));
|
||||
if (columns.contains(NestedDescriptionTemplateElasticEntity._label)) mocDoc.setLabel(FieldBasedMapper.shallowSafeConversion(rawData.get(NestedDescriptionTemplateElasticEntity._label), String.class));
|
||||
return mocDoc;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ElasticField fieldNameOf(FieldResolver item) {
|
||||
if (item.match(NestedDescriptionTemplateElasticEntity._id)) return this.elasticFieldOf(NestedDescriptionTemplateElasticEntity._id).disableInfer(true);
|
||||
else if (item.match(NestedDescriptionTemplateElasticEntity._label)) return this.elasticFieldOf(NestedDescriptionTemplateElasticEntity._label).disableInfer(true);
|
||||
else return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getNestedPath() {
|
||||
return this.nestedPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected UUID toKey(String key) {
|
||||
return UUID.fromString(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ElasticField getKeyField() {
|
||||
return this.elasticFieldOf(NestedDescriptionTemplateElasticEntity._id);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ElasticNestedQuery<?, ?, ?> nestedQueryOf(FieldResolver item) {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
package eu.eudat.elastic.query;
|
||||
|
||||
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
|
||||
import eu.eudat.elastic.data.nested.NestedReferenceElasticEntity;
|
||||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.elastic.configuration.ElasticProperties;
|
||||
import gr.cite.tools.elastic.mapper.FieldBasedMapper;
|
||||
import gr.cite.tools.elastic.query.ElasticField;
|
||||
import gr.cite.tools.elastic.query.ElasticNestedQuery;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.data.elasticsearch.client.elc.ElasticsearchTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class NestedReferenceElasticQuery extends ElasticNestedQuery<NestedReferenceElasticQuery, NestedReferenceElasticEntity, UUID> {
|
||||
|
||||
private String nestedPath;
|
||||
|
||||
@Override
|
||||
public NestedReferenceElasticQuery nestedPath(String value) {
|
||||
this.nestedPath = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
public NestedReferenceElasticQuery(
|
||||
ElasticsearchTemplate elasticsearchTemplate,
|
||||
ElasticProperties elasticProperties
|
||||
) {
|
||||
super(elasticsearchTemplate, elasticProperties);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<NestedReferenceElasticEntity> entityClass() {
|
||||
return NestedReferenceElasticEntity.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean isFalseQuery() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Query applyAuthZ() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Query applyFilters() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NestedReferenceElasticEntity convert(Map<String, Object> rawData, Set<String> columns) {
|
||||
NestedReferenceElasticEntity mocDoc = new NestedReferenceElasticEntity();
|
||||
if (columns.contains(NestedReferenceElasticEntity._id)) mocDoc.setId(FieldBasedMapper.shallowSafeConversion(rawData.get(NestedReferenceElasticEntity._id), UUID.class));
|
||||
if (columns.contains(NestedReferenceElasticEntity._label)) mocDoc.setLabel(FieldBasedMapper.shallowSafeConversion(rawData.get(NestedReferenceElasticEntity._label), String.class));
|
||||
return mocDoc;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ElasticField fieldNameOf(FieldResolver item) {
|
||||
if (item.match(NestedReferenceElasticEntity._id)) return this.elasticFieldOf(NestedReferenceElasticEntity._id).disableInfer(true);
|
||||
else if (item.match(NestedReferenceElasticEntity._label)) return this.elasticFieldOf(NestedReferenceElasticEntity._label).disableInfer(true);
|
||||
else return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getNestedPath() {
|
||||
return this.nestedPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected UUID toKey(String key) {
|
||||
return UUID.fromString(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ElasticField getKeyField() {
|
||||
return this.elasticFieldOf(NestedReferenceElasticEntity._id);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ElasticNestedQuery<?, ?, ?> nestedQueryOf(FieldResolver item) {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
package eu.eudat.elastic.query;
|
||||
|
||||
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
|
||||
import eu.eudat.elastic.data.nested.NestedTagElasticEntity;
|
||||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.elastic.configuration.ElasticProperties;
|
||||
import gr.cite.tools.elastic.mapper.FieldBasedMapper;
|
||||
import gr.cite.tools.elastic.query.ElasticField;
|
||||
import gr.cite.tools.elastic.query.ElasticNestedQuery;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.data.elasticsearch.client.elc.ElasticsearchTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class NestedTagElasticQuery extends ElasticNestedQuery<NestedTagElasticQuery, NestedTagElasticEntity, UUID> {
|
||||
|
||||
private String nestedPath;
|
||||
|
||||
@Override
|
||||
public NestedTagElasticQuery nestedPath(String value) {
|
||||
this.nestedPath = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public NestedTagElasticQuery(
|
||||
ElasticsearchTemplate elasticsearchTemplate,
|
||||
ElasticProperties elasticProperties
|
||||
) {
|
||||
super(elasticsearchTemplate, elasticProperties);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<NestedTagElasticEntity> entityClass() {
|
||||
return NestedTagElasticEntity.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean isFalseQuery() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Query applyAuthZ() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Query applyFilters() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NestedTagElasticEntity convert(Map<String, Object> rawData, Set<String> columns) {
|
||||
NestedTagElasticEntity mocDoc = new NestedTagElasticEntity();
|
||||
if (columns.contains(NestedTagElasticEntity._id)) mocDoc.setId(FieldBasedMapper.shallowSafeConversion(rawData.get(NestedTagElasticEntity._id), UUID.class));
|
||||
if (columns.contains(NestedTagElasticEntity._label)) mocDoc.setLabel(FieldBasedMapper.shallowSafeConversion(rawData.get(NestedTagElasticEntity._label), String.class));
|
||||
return mocDoc;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ElasticField fieldNameOf(FieldResolver item) {
|
||||
if (item.match(NestedTagElasticEntity._id)) return this.elasticFieldOf(NestedTagElasticEntity._id).disableInfer(true);
|
||||
else if (item.match(NestedTagElasticEntity._label)) return this.elasticFieldOf(NestedTagElasticEntity._label).disableInfer(true);
|
||||
else return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getNestedPath() {
|
||||
return this.nestedPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected UUID toKey(String key) {
|
||||
return UUID.fromString(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ElasticField getKeyField() {
|
||||
return this.elasticFieldOf(NestedTagElasticEntity._id);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ElasticNestedQuery<?, ?, ?> nestedQueryOf(FieldResolver item) {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -176,7 +176,11 @@ public class DmpQuery extends QueryBase<DmpEntity> {
|
|||
List<Predicate> predicates = new ArrayList<>();
|
||||
if (userId != null || usePublic ) {
|
||||
predicates.add(queryContext.CriteriaBuilder.or(
|
||||
usePublic ? queryContext.CriteriaBuilder.equal(queryContext.Root.get(DmpEntity._accessType), DmpAccessType.Public) : queryContext.CriteriaBuilder.or(), //Creates a false query
|
||||
usePublic ? queryContext.CriteriaBuilder.and(
|
||||
queryContext.CriteriaBuilder.equal(queryContext.Root.get(DmpEntity._status), DmpStatus.FINALISED),
|
||||
queryContext.CriteriaBuilder.equal(queryContext.Root.get(DmpEntity._accessType), DmpAccessType.Public)
|
||||
)
|
||||
: queryContext.CriteriaBuilder.or(), //Creates a false query
|
||||
userId != null ? queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpEntity._id)).value(this.queryUtilsService.buildDmpUserAuthZSubQuery(queryContext.Query, queryContext.CriteriaBuilder, userId)) : queryContext.CriteriaBuilder.or() //Creates a false query
|
||||
));
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package eu.eudat.query.utils;
|
||||
|
||||
import eu.eudat.commons.enums.DmpAccessType;
|
||||
import eu.eudat.commons.enums.DmpStatus;
|
||||
import eu.eudat.commons.enums.IsActive;
|
||||
import eu.eudat.data.DmpEntity;
|
||||
import eu.eudat.data.DmpUserEntity;
|
||||
|
@ -30,6 +31,7 @@ public class QueryUtilsServiceImpl implements QueryUtilsService {
|
|||
.filterFunc((subQueryRoot, cb) -> cb.or(
|
||||
usePublic ? cb.and(
|
||||
cb.equal(subQueryRoot.get(DmpEntity._accessType), DmpAccessType.Public),
|
||||
cb.equal(subQueryRoot.get(DmpEntity._status), DmpStatus.FINALISED),
|
||||
cb.equal(subQueryRoot.get(DmpEntity._isActive), IsActive.Active)
|
||||
): cb.or(), //Creates a false query
|
||||
userId != null ? cb.in(subQueryRoot.get(DmpEntity._id)).value(this.buildDmpUserAuthZSubQuery(query, criteriaBuilder, userId)) : cb.or() //Creates a false query
|
||||
|
@ -49,6 +51,7 @@ public class QueryUtilsServiceImpl implements QueryUtilsService {
|
|||
.filterFunc((subQueryRoot, cb) ->
|
||||
usePublic ? cb.and(
|
||||
cb.equal(subQueryRoot.get(DmpEntity._accessType), DmpAccessType.Public),
|
||||
cb.equal(subQueryRoot.get(DmpEntity._status), DmpStatus.FINALISED),
|
||||
cb.equal(subQueryRoot.get(DmpEntity._isActive), IsActive.Active)
|
||||
): cb.or() //Creates a false query
|
||||
)
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package eu.eudat.service.elastic;
|
||||
|
||||
import eu.eudat.data.DescriptionEntity;
|
||||
import eu.eudat.data.DmpEntity;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public interface ElasticService {
|
||||
boolean enabled();
|
||||
boolean existsDmpIndex() throws IOException;
|
||||
|
||||
boolean existsDescriptionIndex() throws IOException;
|
||||
|
||||
void ensureDmpIndex() throws IOException;
|
||||
|
||||
void ensureDescriptionIndex() throws IOException;
|
||||
|
||||
void ensureIndexes() throws IOException;
|
||||
|
||||
void persistDmp(DmpEntity dmp) throws IOException;
|
||||
|
||||
void deleteDmp(DmpEntity dmp) throws IOException;
|
||||
|
||||
void persistDescription(DescriptionEntity description) throws IOException;
|
||||
|
||||
void deleteDescription(DescriptionEntity description) throws IOException;
|
||||
}
|
|
@ -0,0 +1,306 @@
|
|||
package eu.eudat.service.elastic;
|
||||
|
||||
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
||||
import co.elastic.clients.elasticsearch._types.mapping.Property;
|
||||
import co.elastic.clients.elasticsearch._types.mapping.TypeMapping;
|
||||
import co.elastic.clients.elasticsearch.indices.*;
|
||||
import eu.eudat.commons.enums.IsActive;
|
||||
import eu.eudat.configurations.elastic.AppElasticProperties;
|
||||
import eu.eudat.data.DescriptionEntity;
|
||||
import eu.eudat.data.DmpEntity;
|
||||
import eu.eudat.elastic.data.DescriptionElasticEntity;
|
||||
import eu.eudat.elastic.data.DmpElasticEntity;
|
||||
import eu.eudat.elastic.data.nested.*;
|
||||
import eu.eudat.elastic.elasticbuilder.DescriptionElasticBuilder;
|
||||
import eu.eudat.elastic.elasticbuilder.DmpElasticBuilder;
|
||||
import eu.eudat.model.Description;
|
||||
import eu.eudat.model.Dmp;
|
||||
import eu.eudat.query.DescriptionQuery;
|
||||
import eu.eudat.query.DmpQuery;
|
||||
import gr.cite.tools.data.builder.BuilderFactory;
|
||||
import gr.cite.tools.data.query.QueryFactory;
|
||||
import gr.cite.tools.elastic.ElasticConstants;
|
||||
import gr.cite.tools.exception.MyNotFoundException;
|
||||
import gr.cite.tools.fieldset.BaseFieldSet;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.data.elasticsearch.annotations.FieldType;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
import org.springframework.data.elasticsearch.client.elc.ElasticsearchTemplate;
|
||||
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.context.annotation.RequestScope;
|
||||
|
||||
@Service
|
||||
public class ElasticServiceImpl implements ElasticService {
|
||||
public final AppElasticProperties appElasticProperties;
|
||||
private final ElasticsearchClient restHighLevelClient;
|
||||
private final ElasticsearchTemplate elasticsearchTemplate;
|
||||
private final QueryFactory queryFactory;
|
||||
private final BuilderFactory builderFactory;
|
||||
private final EntityManager entityManager;
|
||||
private final MessageSource messageSource;
|
||||
|
||||
public ElasticServiceImpl(AppElasticProperties appElasticProperties, ElasticsearchClient restHighLevelClient, ElasticsearchTemplate elasticsearchTemplate, QueryFactory queryFactory, BuilderFactory builderFactory, EntityManager entityManager, MessageSource messageSource) {
|
||||
this.appElasticProperties = appElasticProperties;
|
||||
this.restHighLevelClient = restHighLevelClient;
|
||||
this.elasticsearchTemplate = elasticsearchTemplate;
|
||||
this.queryFactory = queryFactory;
|
||||
this.builderFactory = builderFactory;
|
||||
this.entityManager = entityManager;
|
||||
this.messageSource = messageSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enabled() {
|
||||
return appElasticProperties.isEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean existsDmpIndex() throws IOException {
|
||||
if (!this.enabled()) return false;
|
||||
return restHighLevelClient.indices().exists(new ExistsRequest.Builder().index(this.appElasticProperties.getDmpIndexName()).includeDefaults(true).build()).value();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean existsDescriptionIndex() throws IOException {
|
||||
if (!this.enabled()) return false;
|
||||
return restHighLevelClient.indices().exists(new ExistsRequest.Builder().index(this.appElasticProperties.getDmpIndexName()).includeDefaults(true).build()).value();
|
||||
}
|
||||
|
||||
//region ensure index
|
||||
|
||||
@Override
|
||||
public void ensureDmpIndex() throws IOException {
|
||||
if (!this.enabled()) return ;
|
||||
boolean exists = this.existsDmpIndex();
|
||||
if (exists) return ;
|
||||
|
||||
this.ensureIndex(this.appElasticProperties.getDmpIndexName(), this.createDmpTemplatePropertyMap());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ensureDescriptionIndex() throws IOException {
|
||||
if (!this.enabled()) return ;
|
||||
boolean exists = this.existsDescriptionIndex();
|
||||
if (exists) return ;
|
||||
this.ensureIndex(this.appElasticProperties.getDescriptionIndexName(), this.createDescriptionTemplatePropertyMap());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ensureIndexes() throws IOException {
|
||||
if (!this.enabled()) return ;
|
||||
|
||||
this.ensureDmpIndex();
|
||||
this.ensureDescriptionIndex();
|
||||
}
|
||||
|
||||
private void ensureIndex(String indexName, Map<String, Property> propertyMap) throws IOException {
|
||||
TypeMapping.Builder typeMapping = new TypeMapping.Builder();
|
||||
typeMapping.properties(propertyMap);
|
||||
|
||||
IndexSettings.Builder indexSettings = new IndexSettings.Builder();
|
||||
IndexSettingsAnalysis.Builder indexSettingsAnalysis = new IndexSettingsAnalysis.Builder();
|
||||
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()){
|
||||
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")));
|
||||
}
|
||||
indexSettings.analysis(indexSettingsAnalysis.build());
|
||||
CreateIndexResponse createIndexResponse = restHighLevelClient.indices().create(new CreateIndexRequest.Builder().index(indexName).mappings(typeMapping.build()).settings(indexSettings.build()).build());
|
||||
|
||||
}
|
||||
|
||||
private Map<String, Property> createDescriptionTemplatePropertyMap(){
|
||||
Map<String, Property> propertyMap = new HashMap<>();
|
||||
propertyMap.put(DescriptionElasticEntity._id, this.createElastic(FieldType.Keyword, false));
|
||||
propertyMap.put(DescriptionElasticEntity._label, this.createElastic(FieldType.Keyword, false));
|
||||
propertyMap.put(DescriptionElasticEntity._description, this.createElastic(FieldType.Text, true));
|
||||
propertyMap.put(DescriptionElasticEntity._status, this.createElastic(FieldType.Short, false));
|
||||
propertyMap.put(DescriptionElasticEntity._finalizedAt, this.createElastic(FieldType.Date, false));
|
||||
|
||||
propertyMap.put(DescriptionElasticEntity._tags, new Property.Builder().nested(x -> x.properties(this.createNestedTagsTemplatePropertyMap())).build());
|
||||
propertyMap.put(DescriptionElasticEntity._references, new Property.Builder().nested(x -> x.properties(this.createNestedReferencesTemplatePropertyMap())).build());
|
||||
propertyMap.put(DescriptionElasticEntity._descriptionTemplate, new Property.Builder().object(x -> x.properties(this.createNestedDescriptionTemplateTemplatePropertyMap())).build());
|
||||
propertyMap.put(DescriptionElasticEntity._dmp, new Property.Builder().object(x -> x.properties(this.createNetsedDmpTemplatePropertyMap())).build());
|
||||
return propertyMap;
|
||||
}
|
||||
|
||||
private Map<String, Property> createDmpTemplatePropertyMap(){
|
||||
Map<String, Property> propertyMap = new HashMap<>();
|
||||
propertyMap.put(DmpElasticEntity._id, this.createElastic(FieldType.Keyword, false));
|
||||
propertyMap.put(DmpElasticEntity._label, this.createElastic(FieldType.Text, true));
|
||||
propertyMap.put(DmpElasticEntity._description, this.createElastic(FieldType.Text, false));
|
||||
propertyMap.put(DmpElasticEntity._status, this.createElastic(FieldType.Short, false));
|
||||
propertyMap.put(DmpElasticEntity._version, this.createElastic(FieldType.Short, false));
|
||||
propertyMap.put(DmpElasticEntity._language, this.createElastic(FieldType.Keyword, false));
|
||||
propertyMap.put(DmpElasticEntity._blueprintId, this.createElastic(FieldType.Keyword, false));
|
||||
propertyMap.put(DmpElasticEntity._accessType, this.createElastic(FieldType.Short, false));
|
||||
propertyMap.put(DmpElasticEntity._groupId, this.createElastic(FieldType.Keyword, false));
|
||||
propertyMap.put(DmpElasticEntity._finalizedAt, this.createElastic(FieldType.Date, false));
|
||||
|
||||
propertyMap.put(DmpElasticEntity._descriptions, new Property.Builder().nested(x -> x.properties(this.createNestedDescriptionTemplatePropertyMap())).build());
|
||||
propertyMap.put(DmpElasticEntity._references, new Property.Builder().nested(x -> x.properties(this.createNestedReferencesTemplatePropertyMap())).build());
|
||||
propertyMap.put(DmpElasticEntity._collaborators, new Property.Builder().nested(x -> x.properties(this.createNestedCollaboratorTemplatePropertyMap())).build());
|
||||
propertyMap.put(DmpElasticEntity._dois, new Property.Builder().nested(x -> x.properties(this.createNestedDoisTemplatePropertyMap())).build());
|
||||
return propertyMap;
|
||||
}
|
||||
|
||||
private Map<String, Property> createNestedDescriptionTemplatePropertyMap(){
|
||||
Map<String, Property> propertyMap = new HashMap<>();
|
||||
propertyMap.put(NestedDescriptionElasticEntity._id, this.createElastic(FieldType.Keyword, false));
|
||||
propertyMap.put(NestedDescriptionElasticEntity._label, this.createElastic(FieldType.Keyword, false));
|
||||
propertyMap.put(NestedDescriptionElasticEntity._dmpId, this.createElastic(FieldType.Keyword, false));
|
||||
propertyMap.put(NestedDescriptionElasticEntity._description, this.createElastic(FieldType.Text, true));
|
||||
propertyMap.put(NestedDescriptionElasticEntity._status, this.createElastic(FieldType.Short, false));
|
||||
propertyMap.put(NestedDescriptionElasticEntity._finalizedAt, this.createElastic(FieldType.Date, false));
|
||||
|
||||
propertyMap.put(NestedDescriptionElasticEntity._tags, new Property.Builder().nested(x -> x.properties(this.createNestedTagsTemplatePropertyMap())).build());
|
||||
propertyMap.put(NestedDescriptionElasticEntity._references, new Property.Builder().nested(x -> x.properties(this.createNestedReferencesTemplatePropertyMap())).build());
|
||||
|
||||
return propertyMap;
|
||||
}
|
||||
|
||||
private Map<String, Property> createNestedTagsTemplatePropertyMap(){
|
||||
Map<String, Property> propertyMap = new HashMap<>();
|
||||
propertyMap.put(NestedTagElasticEntity._id, this.createElastic(FieldType.Keyword, false));
|
||||
propertyMap.put(NestedTagElasticEntity._label, this.createElastic(FieldType.Text, true));
|
||||
|
||||
return propertyMap;
|
||||
}
|
||||
|
||||
private Map<String, Property> createNestedReferencesTemplatePropertyMap(){
|
||||
Map<String, Property> propertyMap = new HashMap<>();
|
||||
propertyMap.put(NestedReferenceElasticEntity._id, this.createElastic(FieldType.Keyword, false));
|
||||
propertyMap.put(NestedReferenceElasticEntity._label, this.createElastic(FieldType.Text, true));
|
||||
|
||||
return propertyMap;
|
||||
}
|
||||
|
||||
private Map<String, Property> createNestedDescriptionTemplateTemplatePropertyMap(){
|
||||
Map<String, Property> propertyMap = new HashMap<>();
|
||||
propertyMap.put(NestedDescriptionTemplateElasticEntity._id, this.createElastic(FieldType.Keyword, false));
|
||||
propertyMap.put(NestedDescriptionTemplateElasticEntity._label, this.createElastic(FieldType.Text, true));
|
||||
|
||||
return propertyMap;
|
||||
}
|
||||
|
||||
private Map<String, Property> createNetsedDmpTemplatePropertyMap(){
|
||||
Map<String, Property> propertyMap = new HashMap<>();
|
||||
propertyMap.put(NestedDmpElasticEntity._id, this.createElastic(FieldType.Keyword, false));
|
||||
propertyMap.put(NestedDmpElasticEntity._label, this.createElastic(FieldType.Text, true));
|
||||
propertyMap.put(NestedDmpElasticEntity._description, this.createElastic(FieldType.Text, false));
|
||||
propertyMap.put(NestedDmpElasticEntity._status, this.createElastic(FieldType.Short, false));
|
||||
propertyMap.put(NestedDmpElasticEntity._version, this.createElastic(FieldType.Short, false));
|
||||
propertyMap.put(NestedDmpElasticEntity._language, this.createElastic(FieldType.Keyword, false));
|
||||
propertyMap.put(NestedDmpElasticEntity._blueprintId, this.createElastic(FieldType.Keyword, false));
|
||||
propertyMap.put(NestedDmpElasticEntity._accessType, this.createElastic(FieldType.Short, false));
|
||||
propertyMap.put(NestedDmpElasticEntity._groupId, this.createElastic(FieldType.Keyword, false));
|
||||
propertyMap.put(NestedDmpElasticEntity._finalizedAt, this.createElastic(FieldType.Date, false));
|
||||
|
||||
propertyMap.put(NestedDmpElasticEntity._references, new Property.Builder().nested(x -> x.properties(this.createNestedReferencesTemplatePropertyMap())).build());
|
||||
propertyMap.put(NestedDmpElasticEntity._collaborators, new Property.Builder().nested(x -> x.properties(this.createNestedCollaboratorTemplatePropertyMap())).build());
|
||||
propertyMap.put(NestedDmpElasticEntity._dois, new Property.Builder().nested(x -> x.properties(this.createNestedDoisTemplatePropertyMap())).build());
|
||||
return propertyMap;
|
||||
}
|
||||
|
||||
private Map<String, Property> createNestedCollaboratorTemplatePropertyMap(){
|
||||
Map<String, Property> propertyMap = new HashMap<>();
|
||||
propertyMap.put(NestedCollaboratorElasticEntity._id, this.createElastic(FieldType.Keyword, false));
|
||||
propertyMap.put(NestedCollaboratorElasticEntity._name, this.createElastic(FieldType.Text, true));
|
||||
propertyMap.put(NestedCollaboratorElasticEntity._role, this.createElastic(FieldType.Short, false));
|
||||
|
||||
return propertyMap;
|
||||
}
|
||||
|
||||
private Map<String, Property> createNestedDoisTemplatePropertyMap(){
|
||||
Map<String, Property> propertyMap = new HashMap<>();
|
||||
propertyMap.put(NestedDoiElasticEntity._id, this.createElastic(FieldType.Keyword, false));
|
||||
propertyMap.put(NestedDoiElasticEntity._repositoryId, this.createElastic(FieldType.Keyword, false));
|
||||
propertyMap.put(NestedDoiElasticEntity._doi, this.createElastic(FieldType.Keyword, false));
|
||||
return propertyMap;
|
||||
}
|
||||
|
||||
private Property createElastic(FieldType fieldType, boolean hasKeywordSubField){
|
||||
switch (fieldType){
|
||||
case Keyword -> {
|
||||
return new Property.Builder().keyword(x -> x).build();
|
||||
}
|
||||
case Text -> {
|
||||
return hasKeywordSubField ? new Property.Builder().text(x -> x.analyzer("icu_analyzer_text").fields(ElasticConstants.SubFields.keyword, y -> y.keyword(z-> z))).build() : new Property.Builder().text(x -> x).build();
|
||||
}
|
||||
case Date -> {
|
||||
return new Property.Builder().date(x -> x).build();
|
||||
}
|
||||
case Short -> {
|
||||
return new Property.Builder().short_(x -> x).build();
|
||||
}
|
||||
case Boolean -> {
|
||||
return new Property.Builder().boolean_(x -> x).build();
|
||||
}
|
||||
default -> throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
|
||||
//endregion
|
||||
|
||||
@Override
|
||||
public void persistDmp(DmpEntity dmp) throws IOException {
|
||||
if (!this.enabled()) return;
|
||||
this.ensureIndexes();
|
||||
|
||||
DmpElasticEntity dmpElasticEntity = this.builderFactory.builder(DmpElasticBuilder.class).build(dmp);
|
||||
this.elasticsearchTemplate.save(dmpElasticEntity, IndexCoordinates.of(this.appElasticProperties.getDmpIndexName()));
|
||||
List<DescriptionElasticEntity> descriptions = this.builderFactory.builder(DescriptionElasticBuilder.class).build(this.queryFactory.query(DescriptionQuery.class).isActive(IsActive.Active).dmpSubQuery(this.queryFactory.query(DmpQuery.class).ids(dmp.getId())).collect());
|
||||
this.elasticsearchTemplate.save(descriptions, IndexCoordinates.of(this.appElasticProperties.getDescriptionIndexName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteDmp(DmpEntity dmp) throws IOException {
|
||||
if (!this.enabled()) return;
|
||||
this.ensureIndexes();
|
||||
|
||||
this.elasticsearchTemplate.delete(dmp.getId(), IndexCoordinates.of(this.appElasticProperties.getDmpIndexName()));
|
||||
List<DescriptionEntity> descriptions = this.queryFactory.query(DescriptionQuery.class).dmpSubQuery(this.queryFactory.query(DmpQuery.class).ids(dmp.getId())).collectAs(new BaseFieldSet().ensure(Description._id));
|
||||
for (DescriptionEntity description: descriptions) {
|
||||
this.elasticsearchTemplate.delete(description.getId(), IndexCoordinates.of(this.appElasticProperties.getDescriptionIndexName()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void persistDescription(DescriptionEntity description) throws IOException {
|
||||
if (!this.enabled()) return;
|
||||
this.ensureIndexes();
|
||||
|
||||
DescriptionElasticEntity descriptionElasticEntity = this.builderFactory.builder(DescriptionElasticBuilder.class).build(description);
|
||||
this.elasticsearchTemplate.save(descriptionElasticEntity, IndexCoordinates.of(this.appElasticProperties.getDescriptionIndexName()));
|
||||
DmpEntity dmpEntity = this.entityManager.find(DmpEntity.class, description.getDmpId());
|
||||
if (dmpEntity == null) throw new MyNotFoundException(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()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteDescription(DescriptionEntity description) throws IOException {
|
||||
if (!this.enabled()) return;
|
||||
this.ensureIndexes();
|
||||
|
||||
this.elasticsearchTemplate.delete(description.getId(), IndexCoordinates.of(this.appElasticProperties.getDescriptionIndexName()));
|
||||
DmpEntity dmpEntity = this.entityManager.find(DmpEntity.class, description.getDmpId());
|
||||
if (dmpEntity == null) throw new MyNotFoundException(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()));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
artifactId=core
|
||||
groupId=eu.eudat
|
||||
version=1.0.0-SNAPSHOT
|
|
@ -1,5 +1,6 @@
|
|||
package eu.eudat.elastic.repository;
|
||||
|
||||
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
||||
import eu.eudat.elastic.criteria.DatasetCriteria;
|
||||
import eu.eudat.elastic.entities.Dataset;
|
||||
import eu.eudat.elastic.entities.Dmp;
|
||||
|
@ -42,7 +43,7 @@ public class DatasetRepository extends ElasticRepository<Dataset, DatasetCriteri
|
|||
private final DmpRepository dmpRepository;
|
||||
private final Environment environment;
|
||||
|
||||
public DatasetRepository(RestHighLevelClient client, DmpRepository dmpRepository, Environment environment) {
|
||||
public DatasetRepository(ElasticsearchClient client, DmpRepository dmpRepository, Environment environment) {
|
||||
super(client, environment);
|
||||
this.dmpRepository = dmpRepository;
|
||||
this.environment = environment;
|
||||
|
@ -50,196 +51,196 @@ public class DatasetRepository extends ElasticRepository<Dataset, DatasetCriteri
|
|||
|
||||
@Override
|
||||
public Dataset createOrUpdate(Dataset entity) throws IOException {
|
||||
if (this.getClient() != null) {
|
||||
XContentBuilder builder = XContentFactory.jsonBuilder();
|
||||
Dmp dmp = this.dmpRepository.findDocument(entity.getDmp().toString());
|
||||
if (dmp != null) {
|
||||
boolean found = false;
|
||||
if (dmp.getDatasets() != null && !dmp.getDatasets().isEmpty()) {
|
||||
for (int i = 0; i < dmp.getDatasets().size(); i++) {
|
||||
if (dmp.getDatasets().get(i).getId().equals(entity.getId())) {
|
||||
dmp.getDatasets().set(i, entity);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
if (dmp.getDatasets() == null) {
|
||||
dmp.setDatasets(new ArrayList<>());
|
||||
}
|
||||
dmp.getDatasets().add(entity);
|
||||
}
|
||||
IndexRequest request = new IndexRequest(this.environment.getProperty("elasticsearch.index")).id(dmp.getId().toString()).source(dmp.toElasticEntity(builder));//new IndexRequest("datasets", "doc", entity.getId()).source(entity.toElasticEntity(builder));
|
||||
this.getClient().index(request, RequestOptions.DEFAULT);
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
// if (this.getClient() != null) {
|
||||
// XContentBuilder builder = XContentFactory.jsonBuilder();
|
||||
// Dmp dmp = this.dmpRepository.findDocument(entity.getDmp().toString());
|
||||
// if (dmp != null) {
|
||||
// boolean found = false;
|
||||
// if (dmp.getDatasets() != null && !dmp.getDatasets().isEmpty()) {
|
||||
// for (int i = 0; i < dmp.getDatasets().size(); i++) {
|
||||
// if (dmp.getDatasets().get(i).getId().equals(entity.getId())) {
|
||||
// dmp.getDatasets().set(i, entity);
|
||||
// found = true;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if (!found) {
|
||||
// if (dmp.getDatasets() == null) {
|
||||
// dmp.setDatasets(new ArrayList<>());
|
||||
// }
|
||||
// dmp.getDatasets().add(entity);
|
||||
// }
|
||||
// IndexRequest request = new IndexRequest(this.environment.getProperty("elasticsearch.index")).id(dmp.getId().toString()).source(dmp.toElasticEntity(builder));//new IndexRequest("datasets", "doc", entity.getId()).source(entity.toElasticEntity(builder));
|
||||
// this.getClient().index(request, RequestOptions.DEFAULT).index();
|
||||
// }
|
||||
// return entity;
|
||||
// }
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dataset findDocument(String id) throws IOException {
|
||||
if (this.getClient() != null) {
|
||||
SearchRequest searchRequest = new SearchRequest(this.environment.getProperty("elasticsearch.index"));
|
||||
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
|
||||
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery().should(QueryBuilders.termQuery("datasets.id.keyword", id));
|
||||
NestedQueryBuilder nestedQueryBuilder = QueryBuilders.nestedQuery( "datasets", boolQuery, ScoreMode.Avg).innerHit(new InnerHitBuilder());
|
||||
searchSourceBuilder.query(nestedQueryBuilder);
|
||||
searchRequest.source(searchSourceBuilder);
|
||||
SearchResponse response = this.getClient().search(searchRequest, RequestOptions.DEFAULT);
|
||||
return ((Stream<Dataset>)Arrays.stream(response.getHits().getHits())
|
||||
.map(hit -> hit.getInnerHits().values()).flatMap(Collection::stream)
|
||||
.map(SearchHits::getHits).flatMap(Arrays::stream)
|
||||
.map(x -> new Dataset().fromElasticEntity(this.transformFromString(x.getSourceAsString(), Map.class)))).findFirst().orElse(null);
|
||||
// GetRequest request = new GetRequest("datasets", id);
|
||||
// GetResponse response = this.getClient().get(request, RequestOptions.DEFAULT);
|
||||
// return new Dataset().fromElasticEntity(response.getSourceAsMap());
|
||||
}
|
||||
// if (this.getClient() != null) {
|
||||
// SearchRequest searchRequest = new SearchRequest(this.environment.getProperty("elasticsearch.index"));
|
||||
// SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
|
||||
// BoolQueryBuilder boolQuery = QueryBuilders.boolQuery().should(QueryBuilders.termQuery("datasets.id.keyword", id));
|
||||
// NestedQueryBuilder nestedQueryBuilder = QueryBuilders.nestedQuery( "datasets", boolQuery, ScoreMode.Avg).innerHit(new InnerHitBuilder());
|
||||
// searchSourceBuilder.query(nestedQueryBuilder);
|
||||
// searchRequest.source(searchSourceBuilder);
|
||||
// SearchResponse response = this.getClient().search(searchRequest, RequestOptions.DEFAULT);
|
||||
// return ((Stream<Dataset>)Arrays.stream(response.getHits().getHits())
|
||||
// .map(hit -> hit.getInnerHits().values()).flatMap(Collection::stream)
|
||||
// .map(SearchHits::getHits).flatMap(Arrays::stream)
|
||||
// .map(x -> new Dataset().fromElasticEntity(this.transformFromString(x.getSourceAsString(), Map.class)))).findFirst().orElse(null);
|
||||
//// GetRequest request = new GetRequest("datasets", id);
|
||||
//// GetResponse response = this.getClient().get(request, RequestOptions.DEFAULT);
|
||||
//// return new Dataset().fromElasticEntity(response.getSourceAsMap());
|
||||
// }
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Dataset> query(DatasetCriteria criteria) throws IOException {
|
||||
if (this.getClient() != null) {
|
||||
SearchRequest searchRequest = new SearchRequest(this.environment.getProperty("elasticsearch.index"));
|
||||
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
|
||||
|
||||
/*CountRequest countRequest = new CountRequest("dmps").routing("datasets").routing("id");
|
||||
countRequest.query(QueryBuilders.boolQuery().mustNot(QueryBuilders.termsQuery("datasets.status.keyword", Stream.of(Dataset.Status.DELETED.getValue(), Dataset.Status.CANCELED.getValue()).collect(Collectors.toList()))));
|
||||
CountResponse countResponse = getClient().count(countRequest, RequestOptions.DEFAULT);
|
||||
Long count = countResponse.getCount();*/
|
||||
|
||||
SearchRequest countRequest = new SearchRequest(this.environment.getProperty("elasticsearch.index"));
|
||||
NestedAggregationBuilder nestedAggregationBuilder = AggregationBuilders.nested("by_dataset", "datasets");
|
||||
FiltersAggregationBuilder filtersAggregationBuilder = AggregationBuilders.filters("dataset_query", QueryBuilders.boolQuery().mustNot(QueryBuilders.termsQuery("datasets.status.keyword", Stream.of(Dataset.Status.DELETED.getValue(), Dataset.Status.CANCELED.getValue()).collect(Collectors.toList()))));
|
||||
nestedAggregationBuilder.subAggregation(filtersAggregationBuilder);
|
||||
SearchSourceBuilder countSourceBuilder = new SearchSourceBuilder();
|
||||
countSourceBuilder.aggregation(nestedAggregationBuilder);
|
||||
countRequest.source(countSourceBuilder);
|
||||
SearchResponse countResponse = getClient().search(countRequest, RequestOptions.DEFAULT);
|
||||
Long count = ((ParsedFilters)((ParsedNested)countResponse.getAggregations().asMap().get("by_dataset")).getAggregations().get("dataset_query")).getBuckets().get(0).getDocCount();
|
||||
|
||||
|
||||
searchSourceBuilder.size(count.intValue());
|
||||
|
||||
List<SortBuilder> sortBuilders = new ArrayList<>();
|
||||
BoolQueryBuilder boolQuery = createBoolQuery(criteria);
|
||||
|
||||
|
||||
if (criteria.getSortCriteria() != null && !criteria.getSortCriteria().isEmpty()) {
|
||||
criteria.getSortCriteria().forEach(sortCriteria -> {
|
||||
switch(sortCriteria.getColumnType()) {
|
||||
case COLUMN:
|
||||
sortBuilders.add(SortBuilders.fieldSort("datasets." + sortCriteria.getFieldName()).order(SortOrder.fromString(sortCriteria.getOrderByType().name())));
|
||||
break;
|
||||
case JOIN_COLUMN:
|
||||
List<String> fields = Arrays.asList(sortCriteria.getFieldName().split(":"));
|
||||
fields.stream().filter(name -> !name.startsWith("dmp")).forEach(field -> {
|
||||
sortBuilders.add(SortBuilders.fieldSort(field).order(SortOrder.fromString(sortCriteria.getOrderByType().name())));
|
||||
});
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
NestedQueryBuilder nestedQueryBuilder = QueryBuilders.nestedQuery("datasets", boolQuery, ScoreMode.Avg).innerHit(new InnerHitBuilder().setFetchSourceContext(new FetchSourceContext(true, new String[]{"datasets.tags"}, null)).setSize(this.environment.getProperty("elasticsearch.innerHitsSize", Integer.class)));
|
||||
searchSourceBuilder.query(nestedQueryBuilder)/*.from(criteria.getOffset())*/.fetchSource("datasets.tags", null);
|
||||
/*if (criteria.getSize() > 0) {
|
||||
searchSourceBuilder.size(criteria.getSize());
|
||||
}*/
|
||||
sortBuilders.forEach(searchSourceBuilder::sort);
|
||||
searchRequest.source(searchSourceBuilder);
|
||||
SearchResponse response = this.getClient().search(searchRequest, RequestOptions.DEFAULT);
|
||||
return ((Stream<Dataset>)Arrays.stream(response.getHits().getHits())
|
||||
.map(hit -> hit.getInnerHits().values()).flatMap(Collection::stream)
|
||||
.map(SearchHits::getHits).flatMap(Arrays::stream)
|
||||
.map(x -> new Dataset().fromElasticEntity(this.transformFromString(x.getSourceAsString(), Map.class)))).collect(Collectors.toList());
|
||||
}
|
||||
// if (this.getClient() != null) {
|
||||
// SearchRequest searchRequest = new SearchRequest(this.environment.getProperty("elasticsearch.index"));
|
||||
// SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
|
||||
//
|
||||
// /*CountRequest countRequest = new CountRequest("dmps").routing("datasets").routing("id");
|
||||
// countRequest.query(QueryBuilders.boolQuery().mustNot(QueryBuilders.termsQuery("datasets.status.keyword", Stream.of(Dataset.Status.DELETED.getValue(), Dataset.Status.CANCELED.getValue()).collect(Collectors.toList()))));
|
||||
// CountResponse countResponse = getClient().count(countRequest, RequestOptions.DEFAULT);
|
||||
// Long count = countResponse.getCount();*/
|
||||
//
|
||||
// SearchRequest countRequest = new SearchRequest(this.environment.getProperty("elasticsearch.index"));
|
||||
// NestedAggregationBuilder nestedAggregationBuilder = AggregationBuilders.nested("by_dataset", "datasets");
|
||||
// FiltersAggregationBuilder filtersAggregationBuilder = AggregationBuilders.filters("dataset_query", QueryBuilders.boolQuery().mustNot(QueryBuilders.termsQuery("datasets.status.keyword", Stream.of(Dataset.Status.DELETED.getValue(), Dataset.Status.CANCELED.getValue()).collect(Collectors.toList()))));
|
||||
// nestedAggregationBuilder.subAggregation(filtersAggregationBuilder);
|
||||
// SearchSourceBuilder countSourceBuilder = new SearchSourceBuilder();
|
||||
// countSourceBuilder.aggregation(nestedAggregationBuilder);
|
||||
// countRequest.source(countSourceBuilder);
|
||||
// SearchResponse countResponse = getClient().search(countRequest, RequestOptions.DEFAULT);
|
||||
// Long count = ((ParsedFilters)((ParsedNested)countResponse.getAggregations().asMap().get("by_dataset")).getAggregations().get("dataset_query")).getBuckets().get(0).getDocCount();
|
||||
//
|
||||
//
|
||||
// searchSourceBuilder.size(count.intValue());
|
||||
//
|
||||
// List<SortBuilder> sortBuilders = new ArrayList<>();
|
||||
// BoolQueryBuilder boolQuery = createBoolQuery(criteria);
|
||||
//
|
||||
//
|
||||
// if (criteria.getSortCriteria() != null && !criteria.getSortCriteria().isEmpty()) {
|
||||
// criteria.getSortCriteria().forEach(sortCriteria -> {
|
||||
// switch(sortCriteria.getColumnType()) {
|
||||
// case COLUMN:
|
||||
// sortBuilders.add(SortBuilders.fieldSort("datasets." + sortCriteria.getFieldName()).order(SortOrder.fromString(sortCriteria.getOrderByType().name())));
|
||||
// break;
|
||||
// case JOIN_COLUMN:
|
||||
// List<String> fields = Arrays.asList(sortCriteria.getFieldName().split(":"));
|
||||
// fields.stream().filter(name -> !name.startsWith("dmp")).forEach(field -> {
|
||||
// sortBuilders.add(SortBuilders.fieldSort(field).order(SortOrder.fromString(sortCriteria.getOrderByType().name())));
|
||||
// });
|
||||
// break;
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// }
|
||||
//
|
||||
// NestedQueryBuilder nestedQueryBuilder = QueryBuilders.nestedQuery("datasets", boolQuery, ScoreMode.Avg).innerHit(new InnerHitBuilder().setFetchSourceContext(new FetchSourceContext(true, new String[]{"datasets.tags"}, null)).setSize(this.environment.getProperty("elasticsearch.innerHitsSize", Integer.class)));
|
||||
// searchSourceBuilder.query(nestedQueryBuilder)/*.from(criteria.getOffset())*/.fetchSource("datasets.tags", null);
|
||||
// /*if (criteria.getSize() > 0) {
|
||||
// searchSourceBuilder.size(criteria.getSize());
|
||||
// }*/
|
||||
// sortBuilders.forEach(searchSourceBuilder::sort);
|
||||
// searchRequest.source(searchSourceBuilder);
|
||||
// SearchResponse response = this.getClient().search(searchRequest, RequestOptions.DEFAULT);
|
||||
// return ((Stream<Dataset>)Arrays.stream(response.getHits().getHits())
|
||||
// .map(hit -> hit.getInnerHits().values()).flatMap(Collection::stream)
|
||||
// .map(SearchHits::getHits).flatMap(Arrays::stream)
|
||||
// .map(x -> new Dataset().fromElasticEntity(this.transformFromString(x.getSourceAsString(), Map.class)))).collect(Collectors.toList());
|
||||
// }
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<Dataset> queryIds(DatasetCriteria criteria) throws IOException {
|
||||
if (this.getClient() != null) {
|
||||
SearchRequest searchRequest = new SearchRequest(this.environment.getProperty("elasticsearch.index"));
|
||||
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
|
||||
|
||||
/*CountRequest countRequest = new CountRequest("dmps").routing("datasets").routing("id");
|
||||
countRequest.query(QueryBuilders.boolQuery().mustNot(QueryBuilders.termsQuery("datasets.status.keyword", Stream.of(Dataset.Status.DELETED.getValue(), Dataset.Status.CANCELED.getValue()).collect(Collectors.toList()))));
|
||||
CountResponse countResponse = getClient().count(countRequest, RequestOptions.DEFAULT);
|
||||
Long count = countResponse.getCount();*/
|
||||
|
||||
SearchRequest countRequest = new SearchRequest(this.environment.getProperty("elasticsearch.index"));
|
||||
NestedAggregationBuilder nestedAggregationBuilder = AggregationBuilders.nested("by_dataset", "datasets");
|
||||
FiltersAggregationBuilder filtersAggregationBuilder = AggregationBuilders.filters("dataset_query", QueryBuilders.boolQuery().mustNot(QueryBuilders.termsQuery("datasets.status.keyword", Stream.of(Dataset.Status.DELETED.getValue(), Dataset.Status.CANCELED.getValue()).collect(Collectors.toList()))));
|
||||
nestedAggregationBuilder.subAggregation(filtersAggregationBuilder);
|
||||
SearchSourceBuilder countSourceBuilder = new SearchSourceBuilder();
|
||||
countSourceBuilder.aggregation(nestedAggregationBuilder);
|
||||
countRequest.source(countSourceBuilder);
|
||||
SearchResponse countResponse = getClient().search(countRequest, RequestOptions.DEFAULT);
|
||||
Long count = ((ParsedFilters)((ParsedNested)countResponse.getAggregations().asMap().get("by_dataset")).getAggregations().get("dataset_query")).getBuckets().get(0).getDocCount();
|
||||
|
||||
|
||||
searchSourceBuilder.size(count.intValue());
|
||||
|
||||
List<SortBuilder> sortBuilders = new ArrayList<>();
|
||||
BoolQueryBuilder boolQuery = createBoolQuery(criteria);
|
||||
|
||||
|
||||
if (criteria.getSortCriteria() != null && !criteria.getSortCriteria().isEmpty()) {
|
||||
criteria.getSortCriteria().forEach(sortCriteria -> {
|
||||
switch(sortCriteria.getColumnType()) {
|
||||
case COLUMN:
|
||||
sortBuilders.add(SortBuilders.fieldSort("datasets." + sortCriteria.getFieldName()).order(SortOrder.fromString(sortCriteria.getOrderByType().name())));
|
||||
break;
|
||||
case JOIN_COLUMN:
|
||||
List<String> fields = Arrays.asList(sortCriteria.getFieldName().split(":"));
|
||||
fields.stream().filter(name -> !name.startsWith("dmp")).forEach(field -> {
|
||||
sortBuilders.add(SortBuilders.fieldSort(field).order(SortOrder.fromString(sortCriteria.getOrderByType().name())));
|
||||
});
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
NestedQueryBuilder nestedQueryBuilder = QueryBuilders.nestedQuery("datasets", boolQuery, ScoreMode.None).innerHit(new InnerHitBuilder().setFetchSourceContext(new FetchSourceContext(true, new String[]{"datasets.id"}, null)).setSize(this.environment.getProperty("elasticsearch.innerHitsSize", Integer.class)));
|
||||
searchSourceBuilder.query(nestedQueryBuilder)/*.from(criteria.getOffset()).size(criteria.getSize())*/.fetchSource("datasets.id", null);
|
||||
sortBuilders.forEach(searchSourceBuilder::sort);
|
||||
searchRequest.source(searchSourceBuilder);
|
||||
SearchResponse response = this.getClient().search(searchRequest, RequestOptions.DEFAULT);
|
||||
return ((Stream<Dataset>)Arrays.stream(response.getHits().getHits())
|
||||
.map(hit -> hit.getInnerHits().values()).flatMap(Collection::stream)
|
||||
.map(SearchHits::getHits).flatMap(Arrays::stream)
|
||||
.map(x -> new Dataset().fromElasticEntity(this.transformFromString(x.getSourceAsString(), Map.class)))).collect(Collectors.toList());
|
||||
}
|
||||
// if (this.getClient() != null) {
|
||||
// SearchRequest searchRequest = new SearchRequest(this.environment.getProperty("elasticsearch.index"));
|
||||
// SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
|
||||
//
|
||||
// /*CountRequest countRequest = new CountRequest("dmps").routing("datasets").routing("id");
|
||||
// countRequest.query(QueryBuilders.boolQuery().mustNot(QueryBuilders.termsQuery("datasets.status.keyword", Stream.of(Dataset.Status.DELETED.getValue(), Dataset.Status.CANCELED.getValue()).collect(Collectors.toList()))));
|
||||
// CountResponse countResponse = getClient().count(countRequest, RequestOptions.DEFAULT);
|
||||
// Long count = countResponse.getCount();*/
|
||||
//
|
||||
// SearchRequest countRequest = new SearchRequest(this.environment.getProperty("elasticsearch.index"));
|
||||
// NestedAggregationBuilder nestedAggregationBuilder = AggregationBuilders.nested("by_dataset", "datasets");
|
||||
// FiltersAggregationBuilder filtersAggregationBuilder = AggregationBuilders.filters("dataset_query", QueryBuilders.boolQuery().mustNot(QueryBuilders.termsQuery("datasets.status.keyword", Stream.of(Dataset.Status.DELETED.getValue(), Dataset.Status.CANCELED.getValue()).collect(Collectors.toList()))));
|
||||
// nestedAggregationBuilder.subAggregation(filtersAggregationBuilder);
|
||||
// SearchSourceBuilder countSourceBuilder = new SearchSourceBuilder();
|
||||
// countSourceBuilder.aggregation(nestedAggregationBuilder);
|
||||
// countRequest.source(countSourceBuilder);
|
||||
// SearchResponse countResponse = getClient().search(countRequest, RequestOptions.DEFAULT);
|
||||
// Long count = ((ParsedFilters)((ParsedNested)countResponse.getAggregations().asMap().get("by_dataset")).getAggregations().get("dataset_query")).getBuckets().get(0).getDocCount();
|
||||
//
|
||||
//
|
||||
// searchSourceBuilder.size(count.intValue());
|
||||
//
|
||||
// List<SortBuilder> sortBuilders = new ArrayList<>();
|
||||
// BoolQueryBuilder boolQuery = createBoolQuery(criteria);
|
||||
//
|
||||
//
|
||||
// if (criteria.getSortCriteria() != null && !criteria.getSortCriteria().isEmpty()) {
|
||||
// criteria.getSortCriteria().forEach(sortCriteria -> {
|
||||
// switch(sortCriteria.getColumnType()) {
|
||||
// case COLUMN:
|
||||
// sortBuilders.add(SortBuilders.fieldSort("datasets." + sortCriteria.getFieldName()).order(SortOrder.fromString(sortCriteria.getOrderByType().name())));
|
||||
// break;
|
||||
// case JOIN_COLUMN:
|
||||
// List<String> fields = Arrays.asList(sortCriteria.getFieldName().split(":"));
|
||||
// fields.stream().filter(name -> !name.startsWith("dmp")).forEach(field -> {
|
||||
// sortBuilders.add(SortBuilders.fieldSort(field).order(SortOrder.fromString(sortCriteria.getOrderByType().name())));
|
||||
// });
|
||||
// break;
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// }
|
||||
//
|
||||
// NestedQueryBuilder nestedQueryBuilder = QueryBuilders.nestedQuery("datasets", boolQuery, ScoreMode.None).innerHit(new InnerHitBuilder().setFetchSourceContext(new FetchSourceContext(true, new String[]{"datasets.id"}, null)).setSize(this.environment.getProperty("elasticsearch.innerHitsSize", Integer.class)));
|
||||
// searchSourceBuilder.query(nestedQueryBuilder)/*.from(criteria.getOffset()).size(criteria.getSize())*/.fetchSource("datasets.id", null);
|
||||
// sortBuilders.forEach(searchSourceBuilder::sort);
|
||||
// searchRequest.source(searchSourceBuilder);
|
||||
// SearchResponse response = this.getClient().search(searchRequest, RequestOptions.DEFAULT);
|
||||
// return ((Stream<Dataset>)Arrays.stream(response.getHits().getHits())
|
||||
// .map(hit -> hit.getInnerHits().values()).flatMap(Collection::stream)
|
||||
// .map(SearchHits::getHits).flatMap(Arrays::stream)
|
||||
// .map(x -> new Dataset().fromElasticEntity(this.transformFromString(x.getSourceAsString(), Map.class)))).collect(Collectors.toList());
|
||||
// }
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long count(DatasetCriteria criteria) throws IOException {
|
||||
if (this.getClient() != null) {
|
||||
//CountRequest countRequest = new CountRequest(this.environment.getProperty("elasticsearch.index"));
|
||||
|
||||
SearchRequest countRequest = new SearchRequest(this.environment.getProperty("elasticsearch.index"));
|
||||
BoolQueryBuilder boolQuery = createBoolQuery(criteria);
|
||||
NestedAggregationBuilder nestedAggregationBuilder = AggregationBuilders.nested("by_dataset", "datasets");
|
||||
FiltersAggregationBuilder filtersAggregationBuilder = AggregationBuilders.filters("dataset_query", boolQuery);
|
||||
nestedAggregationBuilder.subAggregation(filtersAggregationBuilder);
|
||||
SearchSourceBuilder countSourceBuilder = new SearchSourceBuilder();
|
||||
countSourceBuilder.aggregation(nestedAggregationBuilder);
|
||||
countRequest.source(countSourceBuilder);
|
||||
SearchResponse countResponse = getClient().search(countRequest, RequestOptions.DEFAULT);
|
||||
return ((ParsedFilters)((ParsedNested)countResponse.getAggregations().asMap().get("by_dataset")).getAggregations().get("dataset_query")).getBuckets().get(0).getDocCount();
|
||||
|
||||
|
||||
|
||||
/*NestedQueryBuilder nestedQueryBuilder = QueryBuilders.nestedQuery("datasets", boolQuery, ScoreMode.None).innerHit(new InnerHitBuilder());
|
||||
countRequest.query(nestedQueryBuilder);
|
||||
CountResponse response = this.getClient().count(countRequest, RequestOptions.DEFAULT);
|
||||
return response.getCount();*/
|
||||
}
|
||||
// if (this.getClient() != null) {
|
||||
// //CountRequest countRequest = new CountRequest(this.environment.getProperty("elasticsearch.index"));
|
||||
//
|
||||
// SearchRequest countRequest = new SearchRequest(this.environment.getProperty("elasticsearch.index"));
|
||||
// BoolQueryBuilder boolQuery = createBoolQuery(criteria);
|
||||
// NestedAggregationBuilder nestedAggregationBuilder = AggregationBuilders.nested("by_dataset", "datasets");
|
||||
// FiltersAggregationBuilder filtersAggregationBuilder = AggregationBuilders.filters("dataset_query", boolQuery);
|
||||
// nestedAggregationBuilder.subAggregation(filtersAggregationBuilder);
|
||||
// SearchSourceBuilder countSourceBuilder = new SearchSourceBuilder();
|
||||
// countSourceBuilder.aggregation(nestedAggregationBuilder);
|
||||
// countRequest.source(countSourceBuilder);
|
||||
// SearchResponse countResponse = getClient().search(countRequest, RequestOptions.DEFAULT);
|
||||
// return ((ParsedFilters)((ParsedNested)countResponse.getAggregations().asMap().get("by_dataset")).getAggregations().get("dataset_query")).getBuckets().get(0).getDocCount();
|
||||
//
|
||||
//
|
||||
//
|
||||
// /*NestedQueryBuilder nestedQueryBuilder = QueryBuilders.nestedQuery("datasets", boolQuery, ScoreMode.None).innerHit(new InnerHitBuilder());
|
||||
// countRequest.query(nestedQueryBuilder);
|
||||
// CountResponse response = this.getClient().count(countRequest, RequestOptions.DEFAULT);
|
||||
// return response.getCount();*/
|
||||
// }
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -324,11 +325,11 @@ public class DatasetRepository extends ElasticRepository<Dataset, DatasetCriteri
|
|||
|
||||
@Override
|
||||
public boolean exists() throws IOException {
|
||||
if (this.getClient() != null) {
|
||||
GetIndexRequest request = new GetIndexRequest(this.environment.getProperty("elasticsearch.index"));
|
||||
// request.indices("datasets");
|
||||
return this.getClient().indices().exists(request, RequestOptions.DEFAULT);
|
||||
}
|
||||
// if (this.getClient() != null) {
|
||||
// GetIndexRequest request = new GetIndexRequest(this.environment.getProperty("elasticsearch.index"));
|
||||
//// request.indices("datasets");
|
||||
// return this.getClient().indices().exists(request, RequestOptions.DEFAULT);
|
||||
// }
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package eu.eudat.elastic.repository;
|
||||
|
||||
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
||||
import eu.eudat.elastic.criteria.DmpCriteria;
|
||||
import eu.eudat.elastic.entities.Dmp;
|
||||
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
|
||||
|
@ -43,103 +44,103 @@ public class DmpRepository extends ElasticRepository<Dmp, DmpCriteria> {
|
|||
private final Environment environment;
|
||||
|
||||
@Autowired
|
||||
public DmpRepository(RestHighLevelClient client, Environment environment) {
|
||||
public DmpRepository(ElasticsearchClient client, Environment environment) {
|
||||
super(client, environment);
|
||||
this.environment = environment;
|
||||
}
|
||||
|
||||
private void generateMapping() throws IOException {
|
||||
if (this.getClient() != null) {
|
||||
XContentBuilder builder = XContentFactory.jsonBuilder();
|
||||
builder.startObject();
|
||||
builder.startObject("properties");
|
||||
builder.startObject("datasets");
|
||||
builder.field("type", "nested");
|
||||
builder.endObject();
|
||||
builder.endObject();
|
||||
builder.endObject();
|
||||
PutMappingRequest putMappingRequest = new PutMappingRequest(this.environment.getProperty("elasticsearch.index"));
|
||||
putMappingRequest.source(builder);
|
||||
this.getClient().indices().putMapping(putMappingRequest, RequestOptions.DEFAULT);
|
||||
}
|
||||
// if (this.getClient() != null) {
|
||||
// XContentBuilder builder = XContentFactory.jsonBuilder();
|
||||
// builder.startObject();
|
||||
// builder.startObject("properties");
|
||||
// builder.startObject("datasets");
|
||||
// builder.field("type", "nested");
|
||||
// builder.endObject();
|
||||
// builder.endObject();
|
||||
// builder.endObject();
|
||||
// PutMappingRequest putMappingRequest = new PutMappingRequest(this.environment.getProperty("elasticsearch.index"));
|
||||
// putMappingRequest.source(builder);
|
||||
// this.getClient().indices().putMapping(putMappingRequest, RequestOptions.DEFAULT);
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dmp createOrUpdate(Dmp entity) throws IOException {
|
||||
if (this.getClient() != null) {
|
||||
XContentBuilder builder = XContentFactory.jsonBuilder();
|
||||
IndexRequest request = new IndexRequest(this.environment.getProperty("elasticsearch.index")).id(entity.getId().toString()).source(entity.toElasticEntity(builder));
|
||||
IndexResponse response = this.getClient().index(request, RequestOptions.DEFAULT);
|
||||
return entity;
|
||||
}
|
||||
// if (this.getClient() != null) {
|
||||
// XContentBuilder builder = XContentFactory.jsonBuilder();
|
||||
// IndexRequest request = new IndexRequest(this.environment.getProperty("elasticsearch.index")).id(entity.getId().toString()).source(entity.toElasticEntity(builder));
|
||||
// IndexResponse response = this.getClient().index(request, RequestOptions.DEFAULT);
|
||||
// return entity;
|
||||
// }
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dmp findDocument(String id) throws IOException {
|
||||
if (this.getClient() != null) {
|
||||
GetRequest request = new GetRequest(this.environment.getProperty("elasticsearch.index"), id);
|
||||
GetResponse response = this.getClient().get(request, RequestOptions.DEFAULT);
|
||||
return new Dmp().fromElasticEntity(response.getSourceAsMap());
|
||||
}
|
||||
// if (this.getClient() != null) {
|
||||
// GetRequest request = new GetRequest(this.environment.getProperty("elasticsearch.index"), id);
|
||||
// GetResponse response = this.getClient().get(request, RequestOptions.DEFAULT);
|
||||
// return new Dmp().fromElasticEntity(response.getSourceAsMap());
|
||||
// }
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Dmp> query(DmpCriteria criteria) throws IOException {
|
||||
if (this.getClient() != null) {
|
||||
SearchRequest searchRequest = new SearchRequest(this.environment.getProperty("elasticsearch.index"));
|
||||
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
|
||||
|
||||
CountRequest countRequest = new CountRequest(this.environment.getProperty("elasticsearch.index"));
|
||||
countRequest.query(QueryBuilders.boolQuery().mustNot(QueryBuilders.termsQuery(Dmp.MapKey.STATUS.getName(), Collections.singletonList(Dmp.DMPStatus.DELETED.getValue()))));
|
||||
CountResponse countResponse = getClient().count(countRequest, RequestOptions.DEFAULT);
|
||||
Long count = countResponse.getCount();
|
||||
|
||||
searchSourceBuilder.size(count.intValue());
|
||||
|
||||
List<SortBuilder> sortBuilders = new ArrayList<>();
|
||||
BoolQueryBuilder boolQuery = createBoolQuery(criteria);
|
||||
|
||||
if (criteria.getSortCriteria() != null && !criteria.getSortCriteria().isEmpty()) {
|
||||
criteria.getSortCriteria().forEach(sortCriteria -> {
|
||||
switch(sortCriteria.getColumnType()) {
|
||||
case COLUMN:
|
||||
sortBuilders.add(SortBuilders.fieldSort(sortCriteria.getFieldName()).order(SortOrder.fromString(sortCriteria.getOrderByType().name())));
|
||||
break;
|
||||
case JOIN_COLUMN:
|
||||
List<String> fields = Arrays.asList(sortCriteria.getFieldName().split(":"));
|
||||
fields.forEach(field -> {
|
||||
sortBuilders.add(SortBuilders.fieldSort(sortCriteria.getFieldName()).order(SortOrder.fromString(sortCriteria.getOrderByType().name())));
|
||||
});
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
searchSourceBuilder.query(boolQuery).from(criteria.getOffset()).fetchSource("id", null);
|
||||
if (criteria.getSize() != null && criteria.getSize() > 0) {
|
||||
searchSourceBuilder.size(criteria.getSize());
|
||||
}
|
||||
sortBuilders.forEach(searchSourceBuilder::sort);
|
||||
searchRequest.source(searchSourceBuilder);
|
||||
SearchResponse response = this.getClient().search(searchRequest, RequestOptions.DEFAULT);
|
||||
return Arrays.stream(response.getHits().getHits()).map(x -> new Dmp().fromElasticEntity((Map<String, Object>) this.transformFromString(x.getSourceAsString(), Map.class))).collect(Collectors.toList());
|
||||
}
|
||||
// if (this.getClient() != null) {
|
||||
// SearchRequest searchRequest = new SearchRequest(this.environment.getProperty("elasticsearch.index"));
|
||||
// SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
|
||||
//
|
||||
// CountRequest countRequest = new CountRequest(this.environment.getProperty("elasticsearch.index"));
|
||||
// countRequest.query(QueryBuilders.boolQuery().mustNot(QueryBuilders.termsQuery(Dmp.MapKey.STATUS.getName(), Collections.singletonList(Dmp.DMPStatus.DELETED.getValue()))));
|
||||
// CountResponse countResponse = getClient().count(countRequest, RequestOptions.DEFAULT);
|
||||
// Long count = countResponse.getCount();
|
||||
//
|
||||
// searchSourceBuilder.size(count.intValue());
|
||||
//
|
||||
// List<SortBuilder> sortBuilders = new ArrayList<>();
|
||||
// BoolQueryBuilder boolQuery = createBoolQuery(criteria);
|
||||
//
|
||||
// if (criteria.getSortCriteria() != null && !criteria.getSortCriteria().isEmpty()) {
|
||||
// criteria.getSortCriteria().forEach(sortCriteria -> {
|
||||
// switch(sortCriteria.getColumnType()) {
|
||||
// case COLUMN:
|
||||
// sortBuilders.add(SortBuilders.fieldSort(sortCriteria.getFieldName()).order(SortOrder.fromString(sortCriteria.getOrderByType().name())));
|
||||
// break;
|
||||
// case JOIN_COLUMN:
|
||||
// List<String> fields = Arrays.asList(sortCriteria.getFieldName().split(":"));
|
||||
// fields.forEach(field -> {
|
||||
// sortBuilders.add(SortBuilders.fieldSort(sortCriteria.getFieldName()).order(SortOrder.fromString(sortCriteria.getOrderByType().name())));
|
||||
// });
|
||||
// break;
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// }
|
||||
// searchSourceBuilder.query(boolQuery).from(criteria.getOffset()).fetchSource("id", null);
|
||||
// if (criteria.getSize() != null && criteria.getSize() > 0) {
|
||||
// searchSourceBuilder.size(criteria.getSize());
|
||||
// }
|
||||
// sortBuilders.forEach(searchSourceBuilder::sort);
|
||||
// searchRequest.source(searchSourceBuilder);
|
||||
// SearchResponse response = this.getClient().search(searchRequest, RequestOptions.DEFAULT);
|
||||
// return Arrays.stream(response.getHits().getHits()).map(x -> new Dmp().fromElasticEntity((Map<String, Object>) this.transformFromString(x.getSourceAsString(), Map.class))).collect(Collectors.toList());
|
||||
// }
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long count(DmpCriteria criteria) throws IOException {
|
||||
if (this.getClient() != null) {
|
||||
CountRequest countRequest = new CountRequest(this.environment.getProperty("elasticsearch.index"));
|
||||
|
||||
BoolQueryBuilder boolQuery = createBoolQuery(criteria);
|
||||
|
||||
countRequest.query(boolQuery);
|
||||
CountResponse response = this.getClient().count(countRequest, RequestOptions.DEFAULT);
|
||||
return response.getCount();
|
||||
}
|
||||
// if (this.getClient() != null) {
|
||||
// CountRequest countRequest = new CountRequest(this.environment.getProperty("elasticsearch.index"));
|
||||
//
|
||||
// BoolQueryBuilder boolQuery = createBoolQuery(criteria);
|
||||
//
|
||||
// countRequest.query(boolQuery);
|
||||
// CountResponse response = this.getClient().count(countRequest, RequestOptions.DEFAULT);
|
||||
// return response.getCount();
|
||||
// }
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -198,11 +199,11 @@ public class DmpRepository extends ElasticRepository<Dmp, DmpCriteria> {
|
|||
|
||||
public boolean createIndex() {
|
||||
try {
|
||||
if (!this.exists()) {
|
||||
CreateIndexRequest createIndexRequest = new CreateIndexRequest(this.environment.getProperty("elasticsearch.index"));
|
||||
this.getClient().indices().create(createIndexRequest, RequestOptions.DEFAULT);
|
||||
this.generateMapping();
|
||||
}
|
||||
// if (!this.exists()) {
|
||||
// CreateIndexRequest createIndexRequest = new CreateIndexRequest(this.environment.getProperty("elasticsearch.index"));
|
||||
// this.getClient().indices().create(createIndexRequest, RequestOptions.DEFAULT);
|
||||
// this.generateMapping();
|
||||
// }
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
|
@ -212,21 +213,21 @@ public class DmpRepository extends ElasticRepository<Dmp, DmpCriteria> {
|
|||
|
||||
@Override
|
||||
public boolean exists() throws IOException {
|
||||
if (this.getClient() != null) {
|
||||
GetIndexRequest request = new GetIndexRequest(this.environment.getProperty("elasticsearch.index"));
|
||||
return this.getClient().indices().exists(request, RequestOptions.DEFAULT);
|
||||
}
|
||||
// if (this.getClient() != null) {
|
||||
// GetIndexRequest request = new GetIndexRequest(this.environment.getProperty("elasticsearch.index"));
|
||||
// return this.getClient().indices().exists(request, RequestOptions.DEFAULT);
|
||||
// }
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() throws IOException {
|
||||
if (exists()) {
|
||||
DeleteByQueryRequest delete = new DeleteByQueryRequest(this.environment.getProperty("elasticsearch.index"));
|
||||
delete.setQuery(QueryBuilders.matchAllQuery());
|
||||
this.getClient().deleteByQuery(delete, RequestOptions.DEFAULT);
|
||||
DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(this.environment.getProperty("elasticsearch.index"));
|
||||
this.getClient().indices().delete(deleteIndexRequest, RequestOptions.DEFAULT);
|
||||
}
|
||||
// if (exists()) {
|
||||
// DeleteByQueryRequest delete = new DeleteByQueryRequest(this.environment.getProperty("elasticsearch.index"));
|
||||
// delete.setQuery(QueryBuilders.matchAllQuery());
|
||||
// this.getClient().deleteByQuery(delete, RequestOptions.DEFAULT);
|
||||
// DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(this.environment.getProperty("elasticsearch.index"));
|
||||
// this.getClient().indices().delete(deleteIndexRequest, RequestOptions.DEFAULT);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package eu.eudat.elastic.repository;
|
||||
|
||||
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import eu.eudat.elastic.criteria.Criteria;
|
||||
import eu.eudat.elastic.entities.ElasticEntity;
|
||||
|
@ -16,19 +17,19 @@ import java.io.IOException;
|
|||
*/
|
||||
public abstract class ElasticRepository<T extends ElasticEntity,C extends Criteria> implements Repository<T,C> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ElasticRepository.class);
|
||||
private RestHighLevelClient client;
|
||||
private ElasticsearchClient client;
|
||||
|
||||
public RestHighLevelClient getClient() {
|
||||
public ElasticsearchClient getClient() {
|
||||
return client;
|
||||
}
|
||||
public ElasticRepository(RestHighLevelClient client, Environment environment) {
|
||||
public ElasticRepository(ElasticsearchClient client, Environment environment) {
|
||||
try {
|
||||
if (Boolean.FALSE.equals(environment.getProperty("elasticsearch.enabled", boolean.class))){
|
||||
if (!Boolean.TRUE.equals(environment.getProperty("elastic.enabled", boolean.class))){
|
||||
logger.warn("Unable to connect to Elastic Services");
|
||||
this.client = null;
|
||||
return;
|
||||
}
|
||||
if (client.ping(RequestOptions.DEFAULT)) {
|
||||
if (client.ping().value()) {
|
||||
this.client = client;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
<project.http.version>1.19.0</project.http.version>
|
||||
<project.oauth.version>1.19.0</project.oauth.version>
|
||||
<project.version>0.2.0</project.version>
|
||||
<java.version>17</java.version>
|
||||
<java.version>21</java.version>
|
||||
|
||||
<dmp-backend-commons.version>0.0.1-SNAPSHOT</dmp-backend-commons.version>
|
||||
|
||||
|
@ -34,8 +34,9 @@
|
|||
<log4j.version>1.2.17</log4j.version>
|
||||
<log4j2.version>2.15.0</log4j2.version>
|
||||
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<maven.compiler.release>21</maven.compiler.release>
|
||||
<maven.compiler.source>21</maven.compiler.source>
|
||||
<maven.compiler.target>21</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
@ -343,6 +344,11 @@
|
|||
<artifactId>oidc-authz</artifactId>
|
||||
<version>2.1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>gr.cite</groupId>
|
||||
<artifactId>elastic</artifactId>
|
||||
<version>2.1.2</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
|
|
@ -229,8 +229,8 @@
|
|||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>17</source>
|
||||
<target>17</target>
|
||||
<source>21</source>
|
||||
<target>21</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
@ -276,7 +276,8 @@
|
|||
<properties>
|
||||
<start-class>eu.eudat.EuDatApplication</start-class>
|
||||
<opensaml.version>4.0.1</opensaml.version>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<maven.compiler.release>21</maven.compiler.release>
|
||||
<maven.compiler.source>21</maven.compiler.source>
|
||||
<maven.compiler.target>21</maven.compiler.target>
|
||||
</properties>
|
||||
</project>
|
|
@ -1,118 +0,0 @@
|
|||
package eu.eudat.configurations;
|
||||
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.auth.AuthScope;
|
||||
import org.apache.http.auth.UsernamePasswordCredentials;
|
||||
import org.apache.http.client.CredentialsProvider;
|
||||
import org.apache.http.conn.ssl.NoopHostnameVerifier;
|
||||
import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
|
||||
import org.apache.http.impl.client.BasicCredentialsProvider;
|
||||
import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager;
|
||||
import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor;
|
||||
import org.apache.http.nio.reactor.IOReactorException;
|
||||
import org.apache.http.nio.reactor.IOReactorExceptionHandler;
|
||||
import org.apache.http.ssl.SSLContextBuilder;
|
||||
import org.apache.http.ssl.SSLContexts;
|
||||
import org.elasticsearch.client.RestClient;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.TrustManagerFactory;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.security.KeyStore;
|
||||
import java.security.cert.Certificate;
|
||||
import java.security.cert.CertificateFactory;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 7/5/2018.
|
||||
*/
|
||||
@Configuration
|
||||
public class ElasticSearchConfiguration {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ElasticSearchConfiguration.class);
|
||||
|
||||
private Environment environment;
|
||||
|
||||
@Autowired
|
||||
public ElasticSearchConfiguration(Environment environment) {
|
||||
this.environment = environment;
|
||||
}
|
||||
|
||||
@Bean(destroyMethod = "close")
|
||||
public RestHighLevelClient client() throws Exception {
|
||||
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
|
||||
credentialsProvider.setCredentials(AuthScope.ANY,
|
||||
new UsernamePasswordCredentials(this.environment.getProperty("elasticsearch.username"), this.environment.getProperty("elasticsearch.password")));
|
||||
|
||||
try {
|
||||
DefaultConnectingIOReactor ioReactor = new DefaultConnectingIOReactor();
|
||||
ioReactor.setExceptionHandler(new IOReactorExceptionHandler() {
|
||||
@Override
|
||||
public boolean handle(IOException e) {
|
||||
logger.warn("System may be unstable: IOReactor encountered a checked exception : " + e.getMessage(), e);
|
||||
return true; // Return true to note this exception as handled, it will not be re-thrown
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle(RuntimeException e) {
|
||||
logger.warn("System may be unstable: IOReactor encountered a runtime exception : " + e.getMessage(), e);
|
||||
return true; // Return true to note this exception as handled, it will not be re-thrown
|
||||
}
|
||||
});
|
||||
|
||||
RestHighLevelClient client;
|
||||
if(this.environment.getProperty("elasticsearch.usingssl", Boolean.class)){
|
||||
|
||||
// Path caCertificatePath = Paths.get(this.environment.getProperty("elasticsearch.certPath"));
|
||||
// CertificateFactory factory =
|
||||
// CertificateFactory.getInstance("X.509");
|
||||
// Certificate trustedCa;
|
||||
// try (InputStream is = Files.newInputStream(caCertificatePath)) {
|
||||
// trustedCa = factory.generateCertificate(is);
|
||||
// }
|
||||
// KeyStore trustStore = KeyStore.getInstance("pkcs12");
|
||||
// trustStore.load(null, null);
|
||||
// trustStore.setCertificateEntry("ca", trustedCa);
|
||||
//
|
||||
// TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
|
||||
// tmf.init(trustStore);
|
||||
//
|
||||
// SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
// sslContext.init(null, tmf.getTrustManagers(), null);
|
||||
|
||||
SSLContextBuilder sslBuilder = SSLContexts.custom()
|
||||
.loadTrustMaterial(null, (x509Certificates, s) -> true);
|
||||
final SSLContext sslContext = sslBuilder.build();
|
||||
client = new RestHighLevelClient(
|
||||
RestClient.builder(
|
||||
new HttpHost(this.environment.getProperty("elasticsearch.host"),
|
||||
Integer.parseInt(this.environment.getProperty("elasticsearch.port")), "https"))
|
||||
.setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder
|
||||
.setDefaultCredentialsProvider(credentialsProvider).setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE).setSSLContext(sslContext))
|
||||
.setRequestConfigCallback(requestConfigBuilder -> requestConfigBuilder.setConnectTimeout(5000).setSocketTimeout(120000))
|
||||
);
|
||||
}
|
||||
else {
|
||||
client = new RestHighLevelClient(
|
||||
RestClient.builder(
|
||||
new HttpHost(this.environment.getProperty("elasticsearch.host"),
|
||||
Integer.parseInt(this.environment.getProperty("elasticsearch.port")), "http"))
|
||||
.setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder
|
||||
.setDefaultCredentialsProvider(credentialsProvider).setConnectionManager(new PoolingNHttpClientConnectionManager(ioReactor))));
|
||||
}
|
||||
return client;
|
||||
}catch (IOReactorException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -12,6 +12,7 @@ import eu.eudat.model.result.QueryResult;
|
|||
import eu.eudat.query.*;
|
||||
import eu.eudat.query.lookup.DmpBlueprintLookup;
|
||||
import eu.eudat.service.dmpblueprint.DmpBlueprintService;
|
||||
import eu.eudat.service.elastic.ElasticService;
|
||||
import gr.cite.tools.auditing.AuditService;
|
||||
import gr.cite.tools.data.builder.BuilderFactory;
|
||||
import gr.cite.tools.data.censor.CensorFactory;
|
||||
|
@ -60,25 +61,37 @@ public class DmpBlueprintController {
|
|||
|
||||
private final MessageSource messageSource;
|
||||
|
||||
private final ElasticService elasticService;
|
||||
|
||||
public DmpBlueprintController(
|
||||
BuilderFactory builderFactory,
|
||||
AuditService auditService,
|
||||
DmpBlueprintService dmpBlueprintService,
|
||||
CensorFactory censorFactory,
|
||||
QueryFactory queryFactory,
|
||||
MessageSource messageSource) {
|
||||
MessageSource messageSource, ElasticService elasticService) {
|
||||
this.builderFactory = builderFactory;
|
||||
this.auditService = auditService;
|
||||
this.dmpBlueprintService = dmpBlueprintService;
|
||||
this.censorFactory = censorFactory;
|
||||
this.queryFactory = queryFactory;
|
||||
this.messageSource = messageSource;
|
||||
this.elasticService = elasticService;
|
||||
}
|
||||
|
||||
@PostMapping("query")
|
||||
public QueryResult<DmpBlueprint> query(@RequestBody DmpBlueprintLookup lookup) throws MyApplicationException, MyForbiddenException {
|
||||
logger.debug("querying {}", DmpBlueprint.class.getSimpleName());
|
||||
|
||||
var a = elasticService.enabled();
|
||||
try {
|
||||
var a1 = elasticService.existsDmpIndex();
|
||||
elasticService.ensureDmpIndex();
|
||||
elasticService.ensureDescriptionIndex();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
this.censorFactory.censor(DmpBlueprintCensor.class).censor(lookup.getProject(), null);
|
||||
DmpBlueprintQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrPermissionOrMemberOrPublic);
|
||||
|
||||
|
|
|
@ -1,10 +1,20 @@
|
|||
elasticsearch:
|
||||
host: localhost
|
||||
port: 9200
|
||||
username: elastic
|
||||
elastic:
|
||||
enabled: ${ELASTIC_ENABLED:}
|
||||
hosts:
|
||||
- ${ELASTIC_HOST:}
|
||||
username: ${ELASTIC_USER:}
|
||||
password: ${ELASTIC_PASS:}
|
||||
index: ${ELASTIC_INDEX:}
|
||||
usingssl: false
|
||||
certPath: ${ELASTIC_CERT_PATH:}
|
||||
certKey: ${ELASTIC_CERT_KEY:}
|
||||
innerHitsSize: 100
|
||||
useSSL: ${ELASTIC_USE_SSL:}
|
||||
socketTimeoutMillis: 30000
|
||||
connectTimeoutMillis: 30000
|
||||
defaultResultSize: 100
|
||||
defaultCollectAllResultSize: 1000
|
||||
defaultScrollSize: 100
|
||||
defaultScrollSeconds: 120
|
||||
defaultCompositeAggregationResultSize: 200000
|
||||
disableHostnameVerifier: false
|
||||
app-elastic:
|
||||
enabled: ${ELASTIC_ENABLED:}
|
||||
dmpIndexName: ${ELASTIC_DMP_INDEX:}
|
||||
descriptionIndexName: ${ELASTIC_DESCRIPTION_INDEX:}
|
||||
enableIcuAnalysisPlugin: false
|
Loading…
Reference in New Issue