Skip to content
Snippets Groups Projects
Commit 1ddfc2c5 authored by Isha Kumari's avatar Isha Kumari
Browse files

Merge branch 'Legal_tag_exp' into 'master'

Legal tag exp

See merge request !598
parents 06dd1e4a 021551cb
No related branches found
No related tags found
2 merge requests!620Update version of default branch to 0.27.0-SNAPSHOT,!598Legal tag exp
Pipeline #288725 failed
package org.opengroup.osdu.legal.ibm.tags;
import org.opengroup.osdu.core.common.model.legal.LegalTag;
public class BanckendLegalTag extends LegalTag {
public Boolean getIs_Valid() {
return is_valid;
}
public void setIs_Valid(Boolean is_valid) {
this.is_valid = is_valid;
}
private Boolean is_valid = false;
}
......@@ -10,10 +10,11 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.sql.Date;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.*;
import java.util.stream.Collectors;
import com.cloudant.client.internal.views.AllDocsRequestResponse;
import jakarta.annotation.PostConstruct;
import jakarta.inject.Inject;
......@@ -172,7 +173,7 @@ public class CloudantLegalTagRepository implements ILegalTagRepository {
try {
Response resp = db.save(legalTag);
db.ensureFullCommit();
logger.info("Query on {}", db.info().getDbName());
if (200 <= resp.getStatusCode() && resp.getStatusCode() < 300) {
if (resp.getStatusCode() == 202) {
......@@ -339,43 +340,30 @@ public class CloudantLegalTagRepository implements ILegalTagRepository {
* @see org.opengroup.osdu.legal.provider.interfaces.LegalTagRepository#list(org.opengroup.osdu.legal.tags.dataaccess.ListLegalTagArgs)
*/
@Override
public Collection<LegalTag> list(ListLegalTagArgs args) {
Selector query = EmptyExpression.empty();
// Since the isValid attribute is a Boolean rather than a bool
// we will interpret this a three state flag
// The byoc doesn't help to clarify that because it hits a
// NullPointerException when comparing a bool this a null Boolean,
// But at least the behavior is consistent when the limit is not
// null
// Both the commented code and the code below pass all acceptance tests
// query = eq("is_valid", Optional.ofNullable(args.getIsValid()).orElse(true).booleanValue());
if (args.getIsValid() != null) {
query = eq("is_valid", args.getIsValid().booleanValue());
}
QueryBuilder builder = new QueryBuilder(query);
builder.bookmark(args.getCursor());
public Collection<LegalTag> list(ListLegalTagArgs args) {
if (logger.isDebugEnabled()) {
builder.executionStats(true);
AllDocsRequestResponse allDocResponse = null;
try {
allDocResponse = (AllDocsRequestResponse) db.getAllDocsRequestBuilder().includeDocs(true).build().getResponse();
} catch (IOException e) {
throw new RuntimeException(e);
}
List<LegalTag> legalTags;
try {
legalTags = allDocResponse.getResponse().getDocsAs(BanckendLegalTag.class)
.stream()
.filter(lTag -> lTag.getIs_Valid() == args.getIsValid())
.collect(Collectors.toList());
if (args.getLimit() > 0) {
builder.limit(args.getLimit());
} catch (IOException e) {
throw new RuntimeException(e);
}
QueryResult<CloudantBackedLegalTag> result = db.query(builder.build()
, CloudantBackedLegalTag.class);
logger.info("Query on {}", db.info().getDbName());
//logExecutionStat(db, legalTags);
logExecutionStat(db, result);
if (args.getLimit() > 0) {
args.setCursor(result.getBookmark());
}
return Collections.unmodifiableCollection(result.getDocs());
return Collections.unmodifiableCollection(legalTags);
}
private void logExecutionStat(Database db, QueryResult<?> result) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment