Skip to content

Commit

Permalink
DeviceFactory: added a model.raw option
Browse files Browse the repository at this point in the history
If "model.raw" is set to true, then the model string is not sanitized.
This allows to give existing URLs as models instead of simple names.
  • Loading branch information
tcalmant committed Jan 2, 2024
1 parent 2d51ad6 commit 1351095
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,8 @@ public class DeviceMappingOptionsDTO {
public NullAction nullAction = NullAction.UPDATE;

@JsonProperty("names.ascii")
public boolean asciiNames;
public boolean asciiNames = false;

@JsonProperty("model.raw")
public boolean useRawModel = false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ private List<GenericDto> handleRecord(final DeviceMappingConfigurationDTO config
final String rawModel = getFieldString(record, recordState.placeholders.get(KEY_MODEL), options);
if (rawModel == null || rawModel.isBlank()) {
throw new ParserException("Empty model field for " + provider);
} else if (configuration.mappingOptions.useRawModel) {
model = rawModel;
} else if (configuration.mappingOptions.asciiNames) {
model = NamingUtils.asciiSanitizeName(rawModel, false);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,4 +378,29 @@ void testNameAsciiSanitize() throws Exception {
assertEquals(value, getResourceValue(provider, "_Greek", "________", Integer.class));
assertEquals(value, getResourceValue(provider, "_int", "_finally", Integer.class));
}

@Test
void testRawModel() throws Exception {
final String rawModel = "http://user:[email protected]:8080/model.xml?format=emf#";
final String provider = "provider";
parser.setRecords(Map.of("m", rawModel, "p", provider));

// Test with an escaped model
final DeviceMappingConfigurationDTO config = prepareConfig();
config.mappingOptions.useRawModel = false;
config.mapping.put("@model", "m");
config.mapping.put("@provider", "p");
config.mapping.put("@name", "p");
deviceMapper.handle(config, Map.of(), new byte[0]);

GenericDto dto = getResourceValue(provider, "admin", "friendlyName");
assertEquals("http___user_test_some_emf_model_8080_model_xml_format_emf_", dto.model);

// Test with a raw model
bulks.clear();
config.mappingOptions.useRawModel = true;
deviceMapper.handle(config, Map.of(), new byte[0]);
dto = getResourceValue(provider, "admin", "friendlyName");
assertEquals(rawModel, dto.model);
}
}

0 comments on commit 1351095

Please sign in to comment.