-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(openapiv3): v3 scroll response fix (#10654)
Co-authored-by: Kevin Chun <kevin1chun@gmail.com>
- Loading branch information
1 parent
bd7d570
commit 156323f
Showing
17 changed files
with
1,071 additions
and
626 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
641 changes: 641 additions & 0 deletions
641
.../models/src/main/java/io/datahubproject/openapi/controller/GenericEntitiesController.java
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
7 changes: 7 additions & 0 deletions
7
.../openapi-servlet/models/src/main/java/io/datahubproject/openapi/models/GenericEntity.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,7 @@ | ||
package io.datahubproject.openapi.models; | ||
|
||
import java.util.Map; | ||
|
||
public interface GenericEntity { | ||
Map<String, Object> getAspects(); | ||
} |
3 changes: 3 additions & 0 deletions
3
...vlet/models/src/main/java/io/datahubproject/openapi/models/GenericEntityScrollResult.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,3 @@ | ||
package io.datahubproject.openapi.models; | ||
|
||
public interface GenericEntityScrollResult<T extends GenericEntity> {} |
2 changes: 1 addition & 1 deletion
2
...penapi/v2/models/GenericScrollResult.java → ...t/openapi/models/GenericScrollResult.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
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
15 changes: 15 additions & 0 deletions
15
...models/src/main/java/io/datahubproject/openapi/v2/models/GenericEntityScrollResultV2.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,15 @@ | ||
package io.datahubproject.openapi.v2.models; | ||
|
||
import io.datahubproject.openapi.models.GenericEntity; | ||
import io.datahubproject.openapi.models.GenericEntityScrollResult; | ||
import java.util.List; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
|
||
@Data | ||
@Builder | ||
public class GenericEntityScrollResultV2<T extends GenericEntity> | ||
implements GenericEntityScrollResult<T> { | ||
private String scrollId; | ||
private List<T> results; | ||
} |
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
15 changes: 15 additions & 0 deletions
15
...models/src/main/java/io/datahubproject/openapi/v3/models/GenericEntityScrollResultV3.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,15 @@ | ||
package io.datahubproject.openapi.v3.models; | ||
|
||
import io.datahubproject.openapi.models.GenericEntity; | ||
import io.datahubproject.openapi.models.GenericEntityScrollResult; | ||
import java.util.List; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
|
||
@Data | ||
@Builder | ||
public class GenericEntityScrollResultV3<T extends GenericEntity> | ||
implements GenericEntityScrollResult<T> { | ||
private String scrollId; | ||
private List<T> entities; | ||
} |
77 changes: 77 additions & 0 deletions
77
...api-servlet/models/src/main/java/io/datahubproject/openapi/v3/models/GenericEntityV3.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,77 @@ | ||
package io.datahubproject.openapi.v3.models; | ||
|
||
import com.datahub.util.RecordUtils; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.linkedin.common.urn.Urn; | ||
import com.linkedin.data.template.RecordTemplate; | ||
import com.linkedin.mxe.SystemMetadata; | ||
import com.linkedin.util.Pair; | ||
import io.datahubproject.openapi.models.GenericEntity; | ||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
import javax.annotation.Nonnull; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
|
||
@EqualsAndHashCode(callSuper = true) | ||
@Data | ||
@Builder | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
@AllArgsConstructor | ||
public class GenericEntityV3 extends LinkedHashMap<String, Object> implements GenericEntity { | ||
|
||
public GenericEntityV3(Map<? extends String, ?> m) { | ||
super(m); | ||
} | ||
|
||
@Override | ||
public Map<String, Object> getAspects() { | ||
return this; | ||
} | ||
|
||
public static class GenericEntityV3Builder { | ||
|
||
public GenericEntityV3 build( | ||
ObjectMapper objectMapper, | ||
@Nonnull Urn urn, | ||
Map<String, Pair<RecordTemplate, SystemMetadata>> aspects) { | ||
Map<String, Object> jsonObjectMap = | ||
aspects.entrySet().stream() | ||
.map( | ||
e -> { | ||
try { | ||
Map<String, Object> valueMap = | ||
Map.of( | ||
"value", | ||
objectMapper.readTree( | ||
RecordUtils.toJsonString(e.getValue().getFirst()) | ||
.getBytes(StandardCharsets.UTF_8))); | ||
|
||
if (e.getValue().getSecond() != null) { | ||
return Map.entry( | ||
e.getKey(), | ||
Map.of( | ||
"systemMetadata", e.getValue().getSecond(), | ||
"value", valueMap.get("value"))); | ||
} else { | ||
return Map.entry(e.getKey(), Map.of("value", valueMap.get("value"))); | ||
} | ||
} catch (IOException ex) { | ||
throw new RuntimeException(ex); | ||
} | ||
}) | ||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); | ||
|
||
GenericEntityV3 genericEntityV3 = new GenericEntityV3(); | ||
genericEntityV3.put("urn", urn.toString()); | ||
genericEntityV3.putAll(jsonObjectMap); | ||
return genericEntityV3; | ||
} | ||
} | ||
} |
Oops, something went wrong.