package org.sagebionetworks.web.client;

import java.util.HashMap;
import org.sagebionetworks.web.client.utils.Callback;
import org.sagebionetworks.web.shared.PublicPrincipalIds;
import org.sagebionetworks.web.shared.WebConstants;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.inject.Inject;

public class SynapsePropertiesImpl implements SynapseProperties {
	private HashMap<String, String> synapseProperties = new HashMap<>();
	private PublicPrincipalIds publicPrincipalIds;
	private StackConfigServiceAsync stackConfigService;
	private SynapseJSNIUtils synapseJSNIUtils;

	@Inject
	public SynapsePropertiesImpl(StackConfigServiceAsync stackConfigService, SynapseJSNIUtils synapseJSNIUtils) {
		this.stackConfigService = stackConfigService;
		this.synapseJSNIUtils = synapseJSNIUtils;
	}

	@Override
	public void initSynapseProperties(Callback c) {
		stackConfigService.getSynapseProperties(new AsyncCallback<HashMap<String, String>>() {
			@Override
			public void onSuccess(HashMap<String, String> properties) {
				for (String key : properties.keySet()) {
					synapseProperties.put(key, properties.get(key));
				}
				c.invoke();
			}

			@Override
			public void onFailure(Throwable caught) {
				synapseJSNIUtils.consoleError(caught.getMessage());
				c.invoke();
			}
		});
	}

	@Override
	public String getSynapseProperty(String key) {
		return synapseProperties.get(key);
	}

	@Override
	public PublicPrincipalIds getPublicPrincipalIds() {
		if (publicPrincipalIds == null) {
			publicPrincipalIds = new PublicPrincipalIds();
			publicPrincipalIds.setPublicAclPrincipalId(Long.parseLong(getSynapseProperty(WebConstants.PUBLIC_ACL_PRINCIPAL_ID)));
			publicPrincipalIds.setAnonymousUserId(Long.parseLong(getSynapseProperty(WebConstants.ANONYMOUS_USER_PRINCIPAL_ID)));
			publicPrincipalIds.setAuthenticatedAclPrincipalId(Long.parseLong(getSynapseProperty(WebConstants.AUTHENTICATED_ACL_PRINCIPAL_ID)));
		}
		return publicPrincipalIds;
	}

}

@@ -34,16 +34,106 @@
 lient;%0A%0A
+import static org.sagebionetworks.web.client.ServiceEntryPointUtils.fixServiceEntryPoint;%0A
 import j
@@ -851,16 +851,60 @@
 ervice;%0A
+%09%09fixServiceEntryPoint(stackConfigService);%0A
 %09%09this.s

fix gwt servlet entry point (do not point to cdn)