/*
 * version 1.0 - MUSES prototype software
 * Copyright MUSES project (European Commission FP7) - 2013 
 * 
 */
package eu.musesproject.server.policyrulestransmitter;

/*
 * #%L
 * MUSES Server
 * %%
 * Copyright (C) 2013 - 2014 S2 Grupo
 * %%
 * 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
 * (at your option) 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 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/>.
 * #L%
 */

import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.doAnswer;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

import org.mockito.Mock;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;

import eu.musesproject.client.model.decisiontable.PolicyDT;
import eu.musesproject.server.connectionmanager.ConnectionManager;
import eu.musesproject.server.connectionmanager.DataHandler;
import eu.musesproject.server.connectionmanager.IConnectionManager;
import eu.musesproject.server.risktrust.Device;

/**
 * Class PolicyTransmitter
 * 
 * @author Sergio Zamarripa (S2)
 * @version Oct 7, 2013
 */

public class PolicyTransmitter {
	
	private List<DataHandler> dataHandlerList	 = new CopyOnWriteArrayList<DataHandler>();
	private ConnectionManager connManager;
	
	public PolicyTransmitter() {
		connManager = ConnectionManager.getInstance();
	}

	/**
	 * Info D
	 * 
	 * Once the policy decision table has been computed, this method sends this
	 * policy to the device
	 * 
	 * @param policy
	 * 
	 * @param device
	 * 
	 * @return result of sending the policy
	 */

	public Integer sendPolicyDT(PolicyDT policy, Device device) {
		sendData(policy.getRawPolicy());
		return 1;
	}
	
	private void sendData(String dataToSend){
				
		connManager.sendData("1", dataToSend);
		
	}

}

@@ -1021,19 +1021,68 @@
 va.util.
-Lis
+Iterator;%0Aimport java.util.List;%0Aimport java.util.Se
 t;%0Aimpor
@@ -1125,16 +1125,49 @@
 rayList;
+%0Aimport java.util.logging.Logger;
 %0A%0Aimport
@@ -1707,16 +1707,88 @@
 ter %7B%0A%09%0A
+%09private Logger logger = Logger.getLogger(this.getClass().getName());%0A%09%0A
 %09private
@@ -2372,19 +2372,322 @@
 end)%7B%0A%09%09
+%0A
 %09%09
-%0A
+Set%3CString%3E sessionIds = connManager.getSessionIds();%0A%09%09for (Iterator iterator = sessionIds.iterator(); iterator.hasNext();) %7B%0A%09%09%09String sessionId = (String) iterator.next();%0A%09%09%09logger.info(connManager.getSessionDetails(sessionId).getId());//TODO Identify the concrete sessionId coming from the device%0A%09
 %09%09connMa
@@ -2705,11 +2705,17 @@
 ata(
-%221%22
+sessionId
 , da
@@ -2725,16 +2725,23 @@
 oSend);%0A
+%09%09%7D%0A%09%09%0A
 %09%09%0A%09%7D%0A%0A%7D

Use sessionId to send through Connection Manager