/**
 * OpenCPS is the open source Core Public Services software
 * Copyright (C) 2016-present OpenCPS community
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>
 */

package org.opencps.backend.sync;

import org.opencps.dossiermgt.model.Dossier;
import org.opencps.dossiermgt.service.DossierLocalServiceUtil;

import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
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;


/**
 * @author khoavd
 *
 */
public class SyncFromFrontOffice implements MessageListener{

	/* (non-Javadoc)
     * @see com.liferay.portal.kernel.messaging.MessageListener#receive(com.liferay.portal.kernel.messaging.Message)
     */
    @Override
    public void receive(Message message)
        throws MessageListenerException {

        try {
            doReceive(message);
        }
        catch (Exception e) {
            _log.error("Unable to process message " + message, e);
        }	    
    }
    
    private void doReceive(Message message) {
    	String actionId = (String) message.get("action");
    	long dossierId = GetterUtil.getLong(message.get("dossierId"));
    	long fileGroupId = GetterUtil.getLong(message.get("fileGroupId"));
    	
    	System.out.println("actionId: " + actionId);
    	System.out.println("dossierId: " + dossierId);
    	System.out.println("fileGroupId: " + fileGroupId);
    	
		// DossierLocalServiceUtil.updateDossierStatus(userId, groupId,
		// companyId, dossierId, govAgencyOrganizationId, status, syncStatus,
		// fileGroupId, level, locale)
    	
    }
    
    
    /**
     * @param dossierId
     * @return
     */
    private boolean checkServiceMode(long dossierId) {
    	boolean trustServiceMode = false;
    	
    	int serviceMode = 0;
    	
    	try {
	        Dossier dossier = DossierLocalServiceUtil.fetchDossier(dossierId);
	        
	        if (Validator.isNotNull(dossier)) {
	        	serviceMode = dossier.getServiceMode();
	        }
        }
        catch (Exception e) {
        }
    	
    	if (serviceMode == 3) {
    		trustServiceMode = true;
    	}
    	
    	return trustServiceMode;
    }
    
    private boolean checkStatus(long dossierId, long fileGroupId, String action) {
    	return false;
    }
    
    private Log _log = LogFactoryUtil.getLog(SyncFromFrontOffice.class);

}

@@ -873,23 +873,143 @@
 mgt.
-service.Dossier
+model.DossierStatus;%0Aimport org.opencps.dossiermgt.service.DossierLocalServiceUtil;%0Aimport org.opencps.dossiermgt.service.DossierStatus
 Loca
@@ -2312,24 +2312,28 @@
 leGroupId);%0A
+  %09%0A
     %09%0A%09%09// D
@@ -3158,24 +3158,36 @@
 g action) %7B%0A
+    %09%0A    %09%0A
     %09return 

Update SyncBackOffice