package com.in28minutes.business;

import java.util.ArrayList;
import java.util.List;

import com.in28minutes.data.api.TodoService;
import com.unboundid.ldap.sdk.LDAPConnection;

public class TodoBusinessImpl {

	private TodoService todoService;

	TodoBusinessImpl(TodoService todoService) {
		this.todoService = todoService;
	} 

	public List<String> retrieveTodosRelatedToSpring(String user) {
		List<String> filteredTodos = new ArrayList<String>();
		List<String> allTodos = todoService.retrieveTodos(user);
		for (String todo : allTodos) {
			if (todo.contains("Spring")) {
				filteredTodos.add(todo);
			}
		}
		return filteredTodos;
	}

	public void deleteTodosNotRelatedToSpring(String user) {
		List<String> allTodos = todoService.retrieveTodos(user);
		for (String todo : allTodos) {
			if (!todo.contains("Spring")) {
				todoService.deleteTodo(todo);
			}
		}
	}

	public synchronized void finalizeClient()
	{
		  final LDAPConnection conn = new LDAPConnection();

	  conn.close();
	}

}

@@ -26,17 +26,19 @@
 usiness;
-%0A
+%0D%0A%0D
 %0Aimport 
@@ -57,16 +57,17 @@
 rayList;
+%0D
 %0Aimport 
@@ -81,17 +81,19 @@
 il.List;
-%0A
+%0D%0A%0D
 %0Aimport 
@@ -129,16 +129,17 @@
 Service;
+%0D
 %0Aimport 
@@ -176,17 +176,65 @@
 nection;
-%0A
+%0D%0Aimport com.unboundid.ldap.sdk.LDAPException;%0D%0A%0D
 %0Apublic 
@@ -257,17 +257,19 @@
 ssImpl %7B
-%0A
+%0D%0A%0D
 %0A%09privat
@@ -294,17 +294,19 @@
 Service;
-%0A
+%0D%0A%0D
 %0A%09TodoBu
@@ -342,16 +342,17 @@
 rvice) %7B
+%0D
 %0A%09%09this.
@@ -381,13 +381,16 @@
 ice;
+%0D
 %0A%09%7D 
-%0A
+%0D%0A%0D
 %0A%09pu
@@ -442,32 +442,33 @@
 g(String user) %7B
+%0D
 %0A%09%09List%3CString%3E 
@@ -507,16 +507,17 @@
 ring%3E();
+%0D
 %0A%09%09List%3C
@@ -559,32 +559,33 @@
 ieveTodos(user);
+%0D
 %0A%09%09for (String t
@@ -593,32 +593,33 @@
 do : allTodos) %7B
+%0D
 %0A%09%09%09if (todo.con
@@ -632,24 +632,25 @@
 %22Spring%22)) %7B
+%0D
 %0A%09%09%09%09filtere
@@ -666,25 +666,28 @@
 d(todo);
+%0D
 %0A%09%09%09%7D
+%0D
 %0A%09%09%7D
+%0D
 %0A%09%09retur
@@ -702,20 +702,23 @@
 edTodos;
+%0D
 %0A%09%7D
-%0A
+%0D%0A%0D
 %0A%09public
@@ -767,16 +767,17 @@
  user) %7B
+%0D
 %0A%09%09List%3C
@@ -827,16 +827,17 @@
 s(user);
+%0D
 %0A%09%09for (
@@ -861,16 +861,17 @@
 Todos) %7B
+%0D
 %0A%09%09%09if (
@@ -897,16 +897,17 @@
 ing%22)) %7B
+%0D
 %0A%09%09%09%09tod
@@ -936,142 +936,30 @@
 do);
+%0D
 %0A%09%09%09%7D
+%0D
 %0A%09%09%7D
+%0D
 %0A%09%7D
-%0A%0A%09public synchronized void finalizeClient()%0A%09%7B%0A%09%09  final LDAPConnection conn = new LDAPConnection();%0A%0A%09  conn.close();%0A%09%7D%0A%0A%7D
+%0D%0A%0D%0A%0D%0A%0D%0A%7D%0D
 %0A

add ldap