package uk.gov.register.core;

import javax.inject.Inject;
import java.net.URI;

public class UriTemplateLinkResolver implements LinkResolver {
    private static final String recordTemplate = "/record/%s";
    private final RegisterResolver registerResolver;

    @Inject
    public UriTemplateLinkResolver(RegisterResolver registerResolver) {
        this.registerResolver = registerResolver;
    }

    // OGNL (Thymeleaf's language) can't find default methods by reflection
    @Override
    public URI resolve(LinkValue linkValue) {
        return LinkResolver.super.resolve(linkValue);
    }

    @Override
    public URI resolve(String register, String linkKey) {
        URI baseUri = registerResolver.baseUriFor(register);

        String record = String.format(recordTemplate, linkKey);
        URI recordUri = URI.create(record);
        return baseUri.resolve(recordUri);
    }
}

@@ -52,16 +52,52 @@
 Inject;%0A
+import javax.ws.rs.core.UriBuilder;%0A
 import j
@@ -177,71 +177,8 @@
 r %7B%0A
-    private static final String recordTemplate = %22/record/%25s%22;%0A
     
@@ -711,148 +711,78 @@
     
-String record = String.format(recordTemplate, linkKey);%0A        URI recordUri = URI.create(record);%0A        return baseUri.resolve(recordUri
+return UriBuilder.fromUri(baseUri).path(%22record%22).path(linkKey).build(
 );%0A 

Simplify UriTemplateLinkResolver