From b52e3bc23341deb5fbd31ec029ab0e215588c42a Mon Sep 17 00:00:00 2001 From: Maek Twain Date: Mon, 16 Nov 2015 20:56:11 +0530 Subject: [PATCH] Template ERROR bug --- .../service/TemplateMergeService.java | 30 +++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/mifosng-provider/src/main/java/org/mifosplatform/template/service/TemplateMergeService.java b/mifosng-provider/src/main/java/org/mifosplatform/template/service/TemplateMergeService.java index 41876d605..88b5b7eda 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/template/service/TemplateMergeService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/template/service/TemplateMergeService.java @@ -24,6 +24,7 @@ import java.util.Map; import java.util.Map.Entry; import org.codehaus.jackson.map.ObjectMapper; +import org.mifosplatform.infrastructure.core.service.ThreadLocalContextUtil; import org.mifosplatform.template.domain.Template; import org.mifosplatform.template.domain.TemplateFunctions; import org.slf4j.Logger; @@ -38,6 +39,7 @@ import com.github.mustachejava.MustacheFactory; @Service public class TemplateMergeService { private final static Logger logger = LoggerFactory.getLogger(TemplateMergeService.class); + // private final FromJsonHelper fromApiJsonHelper; private Map scopes; @@ -46,16 +48,19 @@ public class TemplateMergeService { // @Autowired // public TemplateMergeService(final FromJsonHelper fromApiJsonHelper) { // this.fromApiJsonHelper = fromApiJsonHelper; - // } + // public void setAuthToken(final String authToken) { - this.authToken = authToken; + //final String auth = ThreadLocalContextUtil.getAuthToken(); + this.authToken = authToken; } + public String compile(final Template template, final Map scopes) throws MalformedURLException, IOException { this.scopes = scopes; this.scopes.put("static", new TemplateFunctions()); - + final String auth = ThreadLocalContextUtil.getAuthToken(); + setAuthToken(auth); final MustacheFactory mf = new DefaultMustacheFactory(); final Mustache mustache = mf.compile(new StringReader(template.getText()), template.getName()); @@ -124,7 +129,7 @@ public class TemplateMergeService { try { connection = (HttpURLConnection) new URL(url).openConnection(); if (this.authToken != null) { - connection.setRequestProperty("Authorization", "Basic " + this.authToken); + connection.setRequestProperty("Authorization", "Bearer " + this.authToken); } TrustModifier.relaxHostChecking(connection); @@ -168,22 +173,37 @@ public class TemplateMergeService { @SuppressWarnings("unchecked") private void expandMapArrays(Object value) { if (value instanceof Map) { + System.out.println(value); Map valueAsMap = (Map) value; + //Map newValue = null; + Map myNewMap = new HashMap<>(); for (Entry valueAsMapEntry : valueAsMap.entrySet()) { + System.out.println(valueAsMapEntry); Object valueAsMapEntryValue = valueAsMapEntry.getValue(); + System.out.println(valueAsMapEntryValue); if (valueAsMapEntryValue instanceof Map) { // JSON Object expandMapArrays(valueAsMapEntryValue); + System.out.println(valueAsMapEntryValue); } else if (valueAsMapEntryValue instanceof Iterable) { // JSON Array Iterable valueAsMapEntryValueIterable = (Iterable) valueAsMapEntryValue; + System.out.println(valueAsMapEntryValue); String valueAsMapEntryKey = valueAsMapEntry.getKey(); int i = 0; for (Object object : valueAsMapEntryValueIterable) { - valueAsMap.put(valueAsMapEntryKey + "#" + i, object); + System.out.println(valueAsMapEntryValueIterable); + myNewMap.put(valueAsMapEntryKey + "#" + i, object); + //valueAsMap.putAll(myNewMap); + ++i; expandMapArrays(object); + System.out.println(object); + } } + } + valueAsMap.putAll(myNewMap); + } }