package org.xcolab.utils;


import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.messaging.Message;
import com.liferay.portal.kernel.messaging.MessageListener;
import com.liferay.portal.kernel.messaging.MessageListenerException;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.model.Company;
import com.liferay.portal.service.CompanyLocalServiceUtil;
import com.liferay.portal.util.PortalUtil;
import com.liferay.util.portlet.PortletProps;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;

public class TestScheduler implements MessageListener {

	private static final Long COMPANY_ID = 10112L;


    @Override
    public void receive(Message message) throws MessageListenerException {
        System.out.println("digest-debug: TestScheduler reached");
	}

}

@@ -753,17 +753,20 @@
 ener %7B%0A%0A
-%09
+    
 private 
@@ -809,166 +809,2208 @@
 L;%0A%0A
-%0A    @Override%0A    public void receive(Message message) throws MessageListenerException %7B%0A        System.out.println(%22digest-debug: TestScheduler reached%22);%0A%09
+    private static final String EXECUTE_SCHEDULER_PATH = %22/c/portal/schedulerSendEmailNotifications%22;%0A%0A    private static final String SERVER_PORT_PROPS_KEY = %22climatecolab.server.port%22;%0A%0A    @Override%0A    public void receive(Message message) throws MessageListenerException %7B%0A        System.out.println(%22digest-debug: SendEmailNotifications line 30 reached%22);%0A%0A        String requestUrl = null;%0A        try %7B%0A            Company company = CompanyLocalServiceUtil.getCompany(COMPANY_ID);%0A            System.out.println(%22digest-debug: SendEmailNotifications line 35 reached%22);%0A%0A            // Workaround to get the right port (80) on production%0A            int port = GetterUtil.getInteger(PortletProps.get(SERVER_PORT_PROPS_KEY));%0A            if (Validator.isNull(port) %7C%7C port %3C= 0) %7B%0A                port = PortalUtil.getPortalPort(false);%0A            %7D%0A            System.out.println(%22digest-debug: SendEmailNotifications line 42 reached%22);%0A%0A            String baseUrl = PortalUtil.getPortalURL(company.getVirtualHostname(), port, false);%0A            //String baseUrl = %22http://localhost:8080%22;%0A%0A            requestUrl = baseUrl + EXECUTE_SCHEDULER_PATH;%0A            URL url = new URL(baseUrl + EXECUTE_SCHEDULER_PATH);%0A            HttpURLConnection con = (HttpURLConnection) url.openConnection();%0A            System.out.println(%22digest-debug: SendEmailNotifications line 50 reached%22);%0A%0A            con.setRequestMethod(%22GET%22);%0A            int statusCode = con.getResponseCode();%0A%0A            System.out.println(%22digest-debug: SendEmailNotifications line 55 reached, started request to scheduler path. Return status code: %22+statusCode+%22 URL called is: %22+baseUrl + EXECUTE_SCHEDULER_PATH);%0A%0A            if (statusCode != 200) %7B%0A                throw new MessageListenerException(String.format(%22Could not process request: Bad request: (%25s)%22, requestUrl));%0A            %7D%0A        %7D catch (IOException %7C SystemException %7C PortalException e) %7B%0A            e.printStackTrace();%0A            System.out.println(%22digest-debug: line 61 reached, exception thrown: %22+e.getMessage());%0A            throw new MessageListenerException(String.format(%22Could not process request (%25s)%22, requestUrl), e);%0A        %7D%0A    
 %7D%0A%0A%7D

copy email digest functionality to staffmembers portlet