class DomainJsonPathHelper {

    public static String getResourcePath(ClientDomain domain, String jsonPath){
        List<ResourceElement> resources = domain.getSchema() != null && domain.getSchema().getResources() != null ?
                domain.getSchema().getResources() : new ArrayList<ResourceElement>();
        final StringBuilder resourcePath = new StringBuilder();
        final Matcher matcher = ROOT_RESOURCES_ELEMENT_PATTERN.matcher(jsonPath);
        if(matcher.find()){
            Integer rootElementIndex = Integer.valueOf(matcher.group(1));
            final SchemaElement rootElement = resources.get(rootElementIndex);
            List<SchemaElement> elements;
            if(rootElement instanceof GroupElement){
                elements = ((GroupElement) rootElement).getElements();
            } else {
                elements = new ArrayList<SchemaElement>();
            }
            final String elementsPath = getElementsPath(elements, jsonPath);
            resourcePath.append(rootElement.getName());
            if (!elementsPath.isEmpty()) {
                resourcePath.append(".").append(elementsPath);
            }
        } else {
            throw new IllegalArgumentException("JSON Path " + jsonPath +
                    " should start from schema.resources[{rootResourceIndex}]. Where {rootResourceIndex} is a number");
        }
        return resourcePath.toString();
    }

}