-
Notifications
You must be signed in to change notification settings - Fork 25k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Connector API] Improve create connector endpoints (#108766)
- Loading branch information
Showing
17 changed files
with
291 additions
and
320 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ | |
}, | ||
"body": { | ||
"description": "The connector configuration.", | ||
"required": true | ||
"required": false | ||
} | ||
} | ||
} |
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
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
80 changes: 80 additions & 0 deletions
80
...a/org/elasticsearch/xpack/application/connector/action/ConnectorCreateActionResponse.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,80 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.application.connector.action; | ||
|
||
import org.elasticsearch.action.ActionResponse; | ||
import org.elasticsearch.action.DocWriteResponse; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
import org.elasticsearch.rest.RestStatus; | ||
import org.elasticsearch.xcontent.ToXContentObject; | ||
import org.elasticsearch.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
public class ConnectorCreateActionResponse extends ActionResponse implements ToXContentObject { | ||
|
||
private final String id; | ||
private final DocWriteResponse.Result result; | ||
|
||
public ConnectorCreateActionResponse(StreamInput in) throws IOException { | ||
super(in); | ||
this.id = in.readString(); | ||
this.result = DocWriteResponse.Result.readFrom(in); | ||
} | ||
|
||
public ConnectorCreateActionResponse(String id, DocWriteResponse.Result result) { | ||
this.id = id; | ||
this.result = result; | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public DocWriteResponse.Result getResult() { | ||
return result; | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeString(id); | ||
result.writeTo(out); | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(); | ||
builder.field("id", this.id); | ||
builder.field("result", this.result.getLowercase()); | ||
builder.endObject(); | ||
return builder; | ||
} | ||
|
||
public RestStatus status() { | ||
return switch (result) { | ||
case CREATED -> RestStatus.CREATED; | ||
case NOT_FOUND -> RestStatus.NOT_FOUND; | ||
default -> RestStatus.OK; | ||
}; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
ConnectorCreateActionResponse that = (ConnectorCreateActionResponse) o; | ||
return Objects.equals(id, that.id) && result == that.result; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(id, result); | ||
} | ||
} |
Oops, something went wrong.