package sotechat.domainService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import sotechat.domain.Conversation;
import sotechat.domain.Person;
import sotechat.repo.ConversationRepo;
import sotechat.repo.PersonRepo;

import java.util.List;

/**
 * Created by varkoi on 8.6.2016.
 */
@Service
public class PersonService {

    private PersonRepo personRepo;

    @Autowired
    public PersonService(PersonRepo personRepo){
        this.personRepo = personRepo;
    }

    @Transactional
    public boolean addPerson(Person person, String password){
        try {
            person.setPassword(password);
            personRepo.save(person);
            return true;
        }catch(Exception e){
            return false;
        }
    }

    public Person findOne(String personId) throws Exception {
        return personRepo.findOne(personId);
    }

    public List<Person> findAll(){
        return personRepo.findAll();
    }

    @Transactional
    public void delete(String personId) throws Exception {
        personRepo.delete(personId);
    }

    @Transactional
    public boolean changePassword(String personId, String password){
        try {
            Person person = personRepo.findOne(personId);
            person.setPassword(password);
            personRepo.save(person);
            return true;
        }catch(Exception e){
            return false;
        }
    }

    @Transactional
    public boolean changeScreenName(String personId, String newName){
        try {
            Person person = personRepo.findOne(personId);
            person.setScreenName(newName);
            personRepo.save(person);
            return true;
        }catch(Exception e){
            return false;
        }
    }

    /**
     * Palauttaa listan kaikista henkilon keskusteluista, eli listan
     * Conversation oliota, jotka on liitetty parametrina annettua henkilon
     * id:ta vastaavaan Person olioon
     * @param personId henkikon id
     * @return lista henkilon keskusteluista Conversation olioina
     * @throws Exception IllegalArgumentException
     */
    public List<Conversation> personsConversations(String personId)
            throws Exception {
        personRepo.findOne(personId).getConversationsOfPerson();
    }
}

@@ -622,23 +622,20 @@
  public 
-boolean
+void
  addPers
@@ -664,37 +664,41 @@
 ng password)
-%7B%0A        try
+ throws Exception
  %7B%0A         
@@ -771,98 +771,8 @@
 n);%0A
-            return true;%0A        %7Dcatch(Exception e)%7B%0A            return false;%0A        %7D%0A
     
@@ -1175,16 +1175,17 @@
 assword)
+ 
 %7B%0A      
@@ -1355,32 +1355,33 @@
  true;%0A        %7D
+ 
 catch(Exception 
@@ -1514,16 +1514,17 @@
 newName)
+ 
 %7B%0A      
@@ -2211,32 +2211,32 @@
 Exception %7B%0A
-
         
 personRepo.f
@@ -2215,32 +2215,39 @@
 ption %7B%0A        
+return 
 personRepo.findO

Update PersonService.java