Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public class BatchResultToBulkOperationTransformer extends AbstractDiscoverableTransformer {
public BatchResultToBulkOperationTransformer() {
this.registerSourceType(DataTypeFactory.create(List.class, BatchResult.class, null));
this.setReturnDataType(DataTypeFactory.create(BulkOperationResult.class));
}
@Override
protected Object doTransform(Object src, String enc) throws TransformerException {
List<BatchResult> results = (List<BatchResult>) src;
BulkOperationResultBuilder<BaseEntry<?>> builder = BulkOperationResult.<BaseEntry<?>>builder();
if (results != null) {
for (BatchResult result : results) {
BatchStatus status = result.getStatus();
int code = status.getCode();
builder.addItem(BulkItem.<BaseEntry<?>>builder()
.setRecordId(result.getId())
.setPayload(result.getEntry())
.setMessage(status.getContent())
.setStatusCode(String.format("%d - %s", code, status.getReason()))
.setSuccessful(code == 200 || code == 201 || code == 204)
);
}
}
return builder.build();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.