-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update README.md * clean tmp graphs in case of error and on startup * relax jacoco * relax jacoco * elastic delete old instance after harvester
- Loading branch information
Showing
8 changed files
with
112 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/main/java/it/gov/innovazione/ndc/repository/SemanticAssetMetadataDeleter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package it.gov.innovazione.ndc.repository; | ||
|
||
import it.gov.innovazione.ndc.harvester.model.Instance; | ||
import it.gov.innovazione.ndc.harvester.model.index.SemanticAssetMetadata; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.elasticsearch.core.ElasticsearchOperations; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class SemanticAssetMetadataDeleter { | ||
private final ElasticsearchOperations esOps; | ||
|
||
public long deleteByRepoUrl(String repoUrl, Instance instance) { | ||
return esOps.delete( | ||
SemanticAssetMetadataQuery.getDeleteQueryBuilder(repoUrl, instance) | ||
.build(), | ||
SemanticAssetMetadata.class).getDeleted(); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/it/gov/innovazione/ndc/repository/SemanticAssetMetadataQuery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package it.gov.innovazione.ndc.repository; | ||
|
||
import co.elastic.clients.elasticsearch._types.FieldValue; | ||
import co.elastic.clients.elasticsearch._types.query_dsl.BoolQuery; | ||
import co.elastic.clients.elasticsearch._types.query_dsl.Query; | ||
import co.elastic.clients.elasticsearch._types.query_dsl.QueryVariant; | ||
import co.elastic.clients.elasticsearch._types.query_dsl.TermsQuery; | ||
import it.gov.innovazione.ndc.harvester.model.Instance; | ||
import org.springframework.data.elasticsearch.client.elc.NativeQuery; | ||
import org.springframework.data.elasticsearch.core.query.DeleteQuery; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
import java.util.stream.Stream; | ||
|
||
public class SemanticAssetMetadataQuery { | ||
static BoolQuery getBoolQueryForRepo(String url, Instance instance) { | ||
List<Query> termsQueries = Stream.of( | ||
termsQuery("repoUrl", url), | ||
termsQuery("instance", instance.name())) | ||
.map(QueryVariant::_toQuery) | ||
.toList(); | ||
|
||
return BoolQuery.of(bq -> bq.must(termsQueries)); | ||
} | ||
|
||
static TermsQuery termsQuery(String field, String value) { | ||
return termsQuery(field, Set.of(value)); | ||
} | ||
|
||
static TermsQuery termsQuery(String field, Set<String> values) { | ||
return TermsQuery.of(t -> t.field(field).terms( | ||
terms -> terms.value(values.stream() | ||
.filter(Objects::nonNull) | ||
.map(FieldValue::of) | ||
.toList()))); | ||
} | ||
|
||
static DeleteQuery.Builder getDeleteQueryBuilder(String repoUrl, Instance instance) { | ||
return DeleteQuery.builder( | ||
NativeQuery.builder() | ||
.withQuery(getBoolQueryForRepo(repoUrl, instance)._toQuery()) | ||
.build()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters