gov.nasa.pds.registry.common.connection.aws.BulkRespWrap Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of registry-common Show documentation
Show all versions of registry-common Show documentation
Common code used by Harvest and Registry Manager.
The newest version!
package gov.nasa.pds.registry.common.connection.aws;
import java.util.ArrayList;
import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.opensearch.client.opensearch.core.BulkResponse;
import org.opensearch.client.opensearch.core.bulk.BulkResponseItem;
import gov.nasa.pds.registry.common.Response;
class BulkRespWrap implements Response.Bulk {
private class ItemWrap implements Response.Bulk.Item {
final BulkResponseItem parent;
ItemWrap (BulkResponseItem parent) {
this.parent = parent;
}
@Override
public String id() {
return this.parent.id();
}
@Override
public String index() {
return this.parent.index();
}
@Override
public String result() {
return this.parent.result();
}
@Override
public int status() {
return this.parent.status();
}
@Override
public boolean error() {
return this.parent.error() != null;
}
@Override
public String operation() {
return this.parent.operationType().jsonValue();
}
@Override
public String reason() {
return this.error() ? this.parent.error().reason() : "";
}
};
final private ArrayList items = new ArrayList();
final private BulkResponse parent;
final private Logger log;
BulkRespWrap(BulkResponse parent) {
this.log = LogManager.getLogger(this.getClass());
this.parent = parent;
}
@Override
public boolean errors() {
return this.parent.errors();
}
@Override
public synchronized List- items() {
if (this.parent.items().size() != this.items.size()) {
for (BulkResponseItem item : this.parent.items()) {
this.items.add(new ItemWrap(item));
}
}
return this.items;
}
@Override
public long took() {
return this.parent.took();
}
@Override
public void logErrors() {
if (this.parent.errors()) {
for (BulkResponseItem item : this.parent.items()) {
if (item.error() != null && item.error().reason() != null && !item.error().reason().isBlank()) {
log.error(item.error().reason());
}
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy