package org.opencps.dossiermgt.listenner;

import com.liferay.portal.kernel.exception.ModelListenerException;
import com.liferay.portal.kernel.json.JSONException;
import com.liferay.portal.kernel.json.JSONFactoryUtil;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.model.BaseModelListener;
import com.liferay.portal.kernel.model.ModelListener;

import org.opencps.deliverable.model.OpenCPSDeliverable;
import org.opencps.deliverable.service.OpenCPSDeliverableLocalServiceUtil;
import org.opencps.dossiermgt.model.Deliverable;
import org.osgi.service.component.annotations.Component;

@Component(immediate = true, service = ModelListener.class)
public class DeliverableListener extends BaseModelListener<Deliverable> {

	@Override
	public void onAfterCreate(Deliverable model) throws ModelListenerException {

		// Binhth add message bus to processing jasper file
		_log.info("IN DeliverableListener onAfterCreate");
		
	}

	@Override
	public void onAfterUpdate(Deliverable model) throws ModelListenerException {
		_log.info("IN DeliverableListener onAfterUpdate" + model.getPrimaryKey());
		_log.info("IN DeliverableListener onAfterUpdate" + model.getDeliverableId());
		_log.info("DossierFileListenner.onAfterUpdate(openCPSDeliverable)" + OpenCPSDeliverableLocalServiceUtil.getOpenCPSDeliverables(-1, -1));
		OpenCPSDeliverable openCPSDeliverable = OpenCPSDeliverableLocalServiceUtil.fetchOpenCPSDeliverable(model.getDeliverableId());

		_log.info("DossierFileListenner.onAfterUpdate(openCPSDeliverableId)" + model.getDeliverableId());
		_log.info("DossierFileListenner.onAfterUpdate(openCPSDeliverable)" + openCPSDeliverable);
		openCPSDeliverable.setDeliverableState(1);

		System.out.println("DossierFileListenner.onAfterUpdate(openCPSDeliverable)" + openCPSDeliverable);
		
		try {
			OpenCPSDeliverableLocalServiceUtil.adminProcessData(JSONFactoryUtil.createJSONObject(JSONFactoryUtil.looseSerialize(openCPSDeliverable)));
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		System.out.println("DossierFileListenner.onAfterUpdate(openCPSDeliverable22)" + openCPSDeliverable);
	}

	@Override
	public void onBeforeCreate(Deliverable model) throws ModelListenerException {
	}

	@Override
	public void onBeforeUpdate(Deliverable model) throws ModelListenerException {
	}

	private Log _log = LogFactoryUtil.getLog(DeliverableListener.class.getName());
}

@@ -658,16 +658,18 @@
 onent;%0A%0A
+//
 @Compone
@@ -1088,16 +1088,18 @@
 ption %7B%0A
+//
 %09%09_log.i
@@ -1163,24 +1163,26 @@
 maryKey());%0A
+//
 %09%09_log.info(
@@ -1241,32 +1241,34 @@
 liverableId());%0A
+//
 %09%09_log.info(%22Dos
@@ -1390,16 +1390,18 @@
 , -1));%0A
+//
 %09%09OpenCP
@@ -1521,16 +1521,18 @@
 Id());%0A%0A
+//
 %09%09_log.i
@@ -1623,16 +1623,18 @@
 eId());%0A
+//
 %09%09_log.i
@@ -1717,16 +1717,18 @@
 rable);%0A
+//
 %09%09openCP
@@ -1765,16 +1765,18 @@
 te(1);%0A%0A
+//
 %09%09System
@@ -1875,16 +1875,18 @@
 %0A%09%09%0A
+//
 %09%09try %7B%0A
 %09%09%09O
@@ -1881,16 +1881,18 @@
 %09%09try %7B%0A
+//
 %09%09%09OpenC
@@ -2025,16 +2025,18 @@
 ble)));%0A
+//
 %09%09%7D catc
@@ -2095,16 +2095,18 @@
 h block%0A
+//
 %09%09%09e.pri
@@ -2125,13 +2125,17 @@
 ();%0A
+//
 %09%09%7D%0A%0A
+//
 %09%09Sy

Remove deliverable listener