Skip to content

Commit

Permalink
IS-134 It is now possible to give entire url for logotype
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-lindstrom committed Nov 2, 2023
1 parent f1a39c1 commit 4bbb732
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ public AttributeConsumingService createAttributeConsumingServiceElement() {

if (this.requestedAttributes != null) {
builder.requestedAttributes(this.requestedAttributes.stream()
.filter(ra -> ra.getName() != null)
.map(ra -> RequestedAttributeBuilder.builder(ra.getName()).isRequired(ra.isRequired()).build())
.collect(Collectors.toList()));
.filter(ra -> ra.getName() != null)
.map(ra -> RequestedAttributeBuilder.builder(ra.getName()).isRequired(ra.isRequired()).build())
.collect(Collectors.toList()));
}

return builder.build();
Expand Down Expand Up @@ -142,7 +142,11 @@ public static class UIInfoConfig {
public UIInfo toElement(final String baseUrl) {
final List<Logo> logos = this.getLogos() != null
? this.getLogos().stream()
.map(logo -> LogoBuilder.logo(String.format("%s%s", baseUrl, logo.getPath()),
.filter(logo -> StringUtils.isNotBlank(logo.getPath()) || StringUtils.isNoneBlank(logo.getUrl()))
.map(logo -> LogoBuilder.logo(
StringUtils.isNotBlank(logo.getUrl())
? logo.getUrl()
: String.format("%s%s", baseUrl, logo.getPath()),
StringUtils.isNotBlank(logo.getLang()) ? logo.getLang() : "sv",
logo.getHeight(), logo.getWidth()))
.collect(Collectors.toList())
Expand All @@ -164,10 +168,15 @@ public UIInfo toElement(final String baseUrl) {
public static class UIInfoLogo {

/**
* The logotype path (minus baseUri but including the context path).
* The logotype path (minus baseUri but including the context path). Mutually exclusive with {@code url}.
*/
private String path;

/**
* The logotype URL. Mutually exclusive with {@code path}.
*/
private String url;

/**
* The logotype height (in pixels).
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,56 @@ public void testLogo() {
final UIInfo uiInfo = ui.toElement("https://www.example.com");
Assertions.assertTrue(uiInfo.getLogos().size() == 2);
Assertions.assertEquals("sv", uiInfo.getLogos().get(0).getXMLLang());
Assertions.assertEquals("https://www.example.com/images/sv-pic.jpg", uiInfo.getLogos().get(0).getURI());
Assertions.assertEquals("en", uiInfo.getLogos().get(1).getXMLLang());
Assertions.assertEquals("https://www.example.com/images/en-pic.jpg", uiInfo.getLogos().get(1).getURI());
}

@Test
public void testLogoMissingPathAndUrl() {
final UIInfoConfig ui = new UIInfoConfig();
ui.setDescriptions(List.of(new LocalizedString("sv-Beskrivning"), new LocalizedString("en-Description")));
ui.setDisplayNames(List.of(new LocalizedString("sv-Visningsnamn"), new LocalizedString("en-Display Name")));
final UIInfoLogo logo1 = new UIInfoLogo();
logo1.setHeight(50);
logo1.setWidth(50);
final UIInfoLogo logo2 = new UIInfoLogo();
logo2.setPath("/images/en-pic.jpg");
logo2.setLang("en");
logo2.setHeight(50);
logo2.setWidth(50);
ui.setLogos(List.of(logo1, logo2));

final UIInfo uiInfo = ui.toElement("https://www.example.com");
Assertions.assertTrue(uiInfo.getLogos().size() == 1);
Assertions.assertEquals("en", uiInfo.getLogos().get(0).getXMLLang());
Assertions.assertEquals("https://www.example.com/images/en-pic.jpg", uiInfo.getLogos().get(0).getURI());
}

@Test
public void testLogoUrl() {
final UIInfoConfig ui = new UIInfoConfig();
ui.setDescriptions(List.of(new LocalizedString("sv-Beskrivning"), new LocalizedString("en-Description")));
ui.setDisplayNames(List.of(new LocalizedString("sv-Visningsnamn"), new LocalizedString("en-Display Name")));
final UIInfoLogo logo1 = new UIInfoLogo();
logo1.setUrl("https://www.other-example.com/images/sv-pic.jpg");
logo1.setHeight(50);
logo1.setWidth(50);
final UIInfoLogo logo2 = new UIInfoLogo();
logo2.setUrl("https://www.other-example.com/images/en-pic.jpg");
// Url has precedence ...
logo2.setPath("/images/en-pic.jpg");
logo2.setLang("en");
logo2.setHeight(50);
logo2.setWidth(50);
ui.setLogos(List.of(logo1, logo2));

final UIInfo uiInfo = ui.toElement("https://www.example.com");
Assertions.assertTrue(uiInfo.getLogos().size() == 2);
Assertions.assertEquals("sv", uiInfo.getLogos().get(0).getXMLLang());
Assertions.assertEquals("https://www.other-example.com/images/sv-pic.jpg", uiInfo.getLogos().get(0).getURI());
Assertions.assertEquals("en", uiInfo.getLogos().get(1).getXMLLang());
Assertions.assertEquals("https://www.other-example.com/images/en-pic.jpg", uiInfo.getLogos().get(1).getURI());
}

}

0 comments on commit 4bbb732

Please sign in to comment.