// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.athenz.client.zms.bindings;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.List;

/**
 * @author olaa
 */
@JsonIgnoreProperties(ignoreUnknown = true)
public class PolicyEntity {

    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private final List<AssertionEntity> assertions;
    private final String name;

    public PolicyEntity(@JsonProperty("name") String name,
                        @JsonProperty("assertions") List<AssertionEntity> assertions) {
        this.name = name;
        this.assertions = assertions;
    }

    public String getName() {
        return name;
    }

    public List<AssertionEntity> getAssertions() {
        return assertions;
    }
}

@@ -343,16 +343,80 @@
 il.List;
+%0Aimport java.util.regex.Matcher;%0Aimport java.util.regex.Pattern;
 %0A%0A/**%0A *
@@ -504,16 +504,123 @@
 Entity %7B
+%0A    private static final Pattern namePattern = Pattern.compile(%22%5E(?%3Cdomain%3E%5B%5E:%5D+):policy%5C%5C.(?%3Cname%3E.*)$%22);
 %0A%0A    @J
@@ -912,24 +912,48 @@
 .name = name
+FromResourceString(name)
 ;%0A        th
@@ -979,32 +979,346 @@
 ertions;%0A    %7D%0A%0A
+    private static String nameFromResourceString(String resource) %7B%0A        Matcher matcher = namePattern.matcher(resource);%0A        if (!matcher.matches())%0A            throw new IllegalArgumentException(%22Could not find policy name from resource string: %22 + resource);%0A        return matcher.group(%22name%22);%0A    %7D%0A%0A
     public Strin

Read policy from resource name