Skip to content

Commit

Permalink
Minor: Add an API to list all the properties and custom properties f…
Browse files Browse the repository at this point in the history
…or a given entity type (#18248)

* Minor: Add an API to list all the properties and custom properties for a given entity type

* Minor: Add an API to list all the properties and custom properties for a given entity type

* add custom properties

* add custom properties

* add custom properties
  • Loading branch information
harshach committed Oct 19, 2024
1 parent 4ec92aa commit 5f0b1c0
Show file tree
Hide file tree
Showing 5 changed files with 695 additions and 1 deletion.
4 changes: 4 additions & 0 deletions openmetadata-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,10 @@
<groupId>io.dropwizard.modules</groupId>
<artifactId>dropwizard-web</artifactId>
</dependency>
<dependency>
<groupId>com.github.erosb</groupId>
<artifactId>everit-json-schema</artifactId>
</dependency>

<!-- Dependencies for cloudwatch monitoring -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import javax.json.JsonPatch;
import javax.validation.Valid;
Expand Down Expand Up @@ -68,6 +70,7 @@
import org.openmetadata.service.util.JsonUtils;
import org.openmetadata.service.util.RestUtil.PutResponse;
import org.openmetadata.service.util.ResultList;
import org.openmetadata.service.util.SchemaFieldExtractor;

@Path("/v1/metadata/types")
@Tag(
Expand Down Expand Up @@ -466,6 +469,57 @@ public Response addOrUpdateProperty(
return response.toResponse();
}

@GET
@Path("/fields/{entityType}")
@Produces(MediaType.APPLICATION_JSON)
public Response getEntityTypeFields(
@Context UriInfo uriInfo,
@Context SecurityContext securityContext,
@PathParam("entityType") String entityType,
@QueryParam("include") @DefaultValue("non-deleted") Include include) {

try {
Fields fieldsParam = new Fields(Set.of("customProperties"));
Type typeEntity = repository.getByName(uriInfo, entityType, fieldsParam, include, false);
SchemaFieldExtractor extractor = new SchemaFieldExtractor();
List<SchemaFieldExtractor.FieldDefinition> fieldsList =
extractor.extractFields(typeEntity, entityType);
return Response.ok(fieldsList).type(MediaType.APPLICATION_JSON).build();

} catch (Exception e) {
LOG.error("Error processing schema for entity type: " + entityType, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
.entity(
"Error processing schema for entity type: "
+ entityType
+ ". Exception: "
+ e.getMessage())
.build();
}
}

@GET
@Path("/customProperties")
@Produces(MediaType.APPLICATION_JSON)
public Response getAllCustomPropertiesByEntityType(
@Context UriInfo uriInfo, @Context SecurityContext securityContext) {
try {
SchemaFieldExtractor extractor = new SchemaFieldExtractor();
Map<String, List<SchemaFieldExtractor.FieldDefinition>> customPropertiesMap =
extractor.extractAllCustomProperties(uriInfo, repository);
return Response.ok(customPropertiesMap).build();
} catch (Exception e) {
LOG.error("Error fetching custom properties: {}", e.getMessage(), e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
.entity(
"Error processing schema for entity type: "
+ entityType
+ ". Exception: "
+ e.getMessage())
.build();
}
}

private Type getType(CreateType create, String user) {
return repository
.copy(new Type(), create, user)
Expand Down
Loading

0 comments on commit 5f0b1c0

Please sign in to comment.