Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable default value fill in for all update behavior #469

Merged
merged 2 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -818,8 +818,8 @@ public <ASPECT extends RecordTemplate> ASPECT add(@Nonnull URN urn, AspectUpdate
maxTransactionRetry);

// skip MAE producing and post update hook in test mode or if the result is null (no actual update with addCommon)
return updateLambda.getIngestionParams().isTestMode() ? result.newValue
: result == null ? null : unwrapAddResult(urn, result, auditStamp, trackingContext);
return result == null ? null : (updateLambda.getIngestionParams().isTestMode() ? result.newValue
: unwrapAddResult(urn, result, auditStamp, trackingContext));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,30 +74,10 @@ static String capitalizeFirst(@Nonnull String name) {
@Nonnull
public static String toJsonString(@Nonnull RecordTemplate recordTemplate) {
try {
return DATA_TEMPLATE_CODEC.mapToString(recordTemplate.data());
} catch (IOException e) {
throw new ModelConversionException("Failed to serialize RecordTemplate: " + recordTemplate.toString());
}
}

/**
* Serializes a {@link RecordTemplate} to JSON string.
* Also take test mode as input to control the default value fill in strategy
* @param recordTemplate the record template to serialize
* @return the JSON string serialized using {@link JacksonDataTemplateCodec}.
*/
//Todo: we will remove this method once we verify it works and does not bring too much degrade in test mode.
@Nonnull
public static String toJsonString(@Nonnull RecordTemplate recordTemplate, boolean isTestMode) {
if (isTestMode) {
try {
DataMap dataWithDefaultValue = (DataMap) ResponseUtils.fillInDataDefault(recordTemplate.schema(), recordTemplate.data());
return DATA_TEMPLATE_CODEC.mapToString(dataWithDefaultValue);
} catch (RestLiServiceException | IOException e) {
throw new ModelConversionException("Failed to serialize RecordTemplate: " + recordTemplate.toString(), e);
}
} else {
return toJsonString(recordTemplate);
DataMap dataWithDefaultValue = (DataMap) ResponseUtils.fillInDataDefault(recordTemplate.schema(), recordTemplate.data());
return DATA_TEMPLATE_CODEC.mapToString(dataWithDefaultValue);
} catch (RestLiServiceException | IOException e) {
throw new ModelConversionException("Failed to serialize RecordTemplate: " + recordTemplate.toString(), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void testToJsonStringWithDefault() throws IOException {
String expected =
loadJsonFromResource("defaultValueAspect.json").replaceAll("\\s+", "").replaceAll("\\n", "").replaceAll("\\r", "");

String actual = RecordUtils.toJsonString(defaultValueAspect, true);
String actual = RecordUtils.toJsonString(defaultValueAspect);

assertEquals(actual, expected);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public <ASPECT extends RecordTemplate> int addWithOptimisticLocking(
}

AuditedAspect auditedAspect = new AuditedAspect()
.setAspect(RecordUtils.toJsonString(newValue, isTestMode))
.setAspect(RecordUtils.toJsonString(newValue))
.setCanonicalName(aspectClass.getCanonicalName())
.setLastmodifiedby(actor)
.setLastmodifiedon(new Timestamp(timestamp).toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ public void testToAndFromJson() throws NoSuchMethodException, InvocationTargetEx

Method extractAspectJsonString = EBeanDAOUtils.class.getDeclaredMethod("extractAspectJsonString", String.class);
extractAspectJsonString.setAccessible(true);
assertEquals("{\"lastmodifiedon\":\"1\",\"aspect\":{\"value\":\"test\"},\"lastmodifiedby\":\"0\"}", toJson);
assertEquals("{\"lastmodifiedon\":\"1\",\"lastmodifiedby\":\"0\",\"aspect\":{\"value\":\"test\"}}", toJson);
assertNotNull(RecordUtils.toRecordTemplate(AspectFoo.class, (String) extractAspectJsonString.invoke(EBeanDAOUtils.class, toJson)));
}

Expand Down
Loading