Skip to content

Commit

Permalink
updates per review
Browse files Browse the repository at this point in the history
  • Loading branch information
david-leifker committed Jan 20, 2024
1 parent 7d1b73f commit 298628a
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 38 deletions.
8 changes: 8 additions & 0 deletions buildSrc/src/main/java/io/datahubproject/OpenApiEntities.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ public ObjectNode entityExtension(List<ObjectNode> nodesList, ObjectNode schemas
return componentsNode;
}

/**
* Convert the pdl model names to desired class names. Upper case first letter unless the 3rd character is upper case.
* i.e. mlModel -> MLModel
* dataset -> Dataset
* dataProduct -> DataProduct
* @param s input string
* @return class name
*/
public static String toUpperFirst(String s) {
if (s.length() > 2 && s.substring(2, 3).equals(s.substring(2, 3).toUpperCase())) {
return s.substring(0, 2).toUpperCase() + s.substring(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,44 +289,42 @@ public static void buildSortOrder(
if (sortCriterion.isEmpty() && enableDefaultSort) {
searchSourceBuilder.sort(new ScoreSortBuilder().order(SortOrder.DESC));
} else {
sortCriterion.forEach(
sortCriteria -> {
Optional<SearchableAnnotation.FieldType> fieldTypeForDefault = Optional.empty();
for (EntitySpec entitySpec : entitySpecs) {
List<SearchableFieldSpec> fieldSpecs = entitySpec.getSearchableFieldSpecs();
for (SearchableFieldSpec fieldSpec : fieldSpecs) {
SearchableAnnotation annotation = fieldSpec.getSearchableAnnotation();
if (annotation.getFieldName().equals(sortCriteria.getField())
|| annotation.getFieldNameAliases().contains(sortCriteria.getField())) {
fieldTypeForDefault =
Optional.of(fieldSpec.getSearchableAnnotation().getFieldType());
break;
}
}
if (fieldTypeForDefault.isPresent()) {
break;
}
}
if (fieldTypeForDefault.isEmpty()) {
log.warn(
"Sort criterion field "
+ sortCriteria.getField()
+ " was not found in any entity spec to be searched");
}
final SortOrder esSortOrder =
(sortCriteria.getOrder() == com.linkedin.metadata.query.filter.SortOrder.ASCENDING)
? SortOrder.ASC
: SortOrder.DESC;
FieldSortBuilder sortBuilder =
new FieldSortBuilder(sortCriteria.getField()).order(esSortOrder);
if (fieldTypeForDefault.isPresent()) {
String esFieldtype = getElasticTypeForFieldType(fieldTypeForDefault.get());
if (esFieldtype != null) {
sortBuilder.unmappedType(esFieldtype);
}
for (SortCriterion sortCriteria : sortCriterion) {
Optional<SearchableAnnotation.FieldType> fieldTypeForDefault = Optional.empty();
for (EntitySpec entitySpec : entitySpecs) {
List<SearchableFieldSpec> fieldSpecs = entitySpec.getSearchableFieldSpecs();
for (SearchableFieldSpec fieldSpec : fieldSpecs) {
SearchableAnnotation annotation = fieldSpec.getSearchableAnnotation();
if (annotation.getFieldName().equals(sortCriteria.getField())
|| annotation.getFieldNameAliases().contains(sortCriteria.getField())) {
fieldTypeForDefault = Optional.of(fieldSpec.getSearchableAnnotation().getFieldType());
break;
}
searchSourceBuilder.sort(sortBuilder);
});
}
if (fieldTypeForDefault.isPresent()) {
break;
}
}
if (fieldTypeForDefault.isEmpty()) {
log.warn(
"Sort criterion field "
+ sortCriteria.getField()
+ " was not found in any entity spec to be searched");
}
final SortOrder esSortOrder =
(sortCriteria.getOrder() == com.linkedin.metadata.query.filter.SortOrder.ASCENDING)
? SortOrder.ASC
: SortOrder.DESC;
FieldSortBuilder sortBuilder =
new FieldSortBuilder(sortCriteria.getField()).order(esSortOrder);
if (fieldTypeForDefault.isPresent()) {
String esFieldtype = getElasticTypeForFieldType(fieldTypeForDefault.get());
if (esFieldtype != null) {
sortBuilder.unmappedType(esFieldtype);
}
}
searchSourceBuilder.sort(sortBuilder);
}
}
if (enableDefaultSort
&& (sortCriterion.isEmpty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ public Method lookupMethod(
return lookupMethod(builderPair.getFirst(), method, parameters);
}

/**
* Convert class name to the pdl model names. Upper case first letter unless the 3rd character is
* upper case. Reverse of {link ReflectionCache.toUpperFirst} i.e. MLModel -> mlModel Dataset ->
* dataset DataProduct -> dataProduct
*
* @param s input string
* @return class name
*/
public static String toLowerFirst(String s) {
if (s.length() > 2 && s.substring(2, 3).equals(s.substring(2, 3).toUpperCase())) {
return s.substring(0, 2).toLowerCase() + s.substring(2);
Expand All @@ -142,6 +150,13 @@ public static String toLowerFirst(String s) {
}
}

/**
* Convert the pdl model names to desired class names. Upper case first letter unless the 3rd
* character is upper case. i.e. mlModel -> MLModel dataset -> Dataset dataProduct -> DataProduct
*
* @param s input string
* @return class name
*/
public static String toUpperFirst(String s) {
if (s.length() > 2 && s.substring(2, 3).equals(s.substring(2, 3).toUpperCase())) {
return s.substring(0, 2).toUpperCase() + s.substring(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ private List<GenericEntity> toRecordTemplates(
}

private Boolean exists(Urn urn, @Nullable String aspect) {
return aspect == null ? entityService.exists(urn) : entityService.exists(urn, aspect);
return aspect == null ? entityService.exists(urn, true) : entityService.exists(urn, aspect);
}

private List<GenericEntity> toRecordTemplates(
Expand Down

0 comments on commit 298628a

Please sign in to comment.