|
1 | | -package org.woehlke.simpleworklist.oodm.services.impl; |
2 | | - |
3 | | -import org.springframework.stereotype.Service; |
4 | | -import org.springframework.transaction.annotation.Propagation; |
5 | | -import org.springframework.transaction.annotation.Transactional; |
6 | | -import org.woehlke.simpleworklist.model.beans.NewContextForm; |
7 | | -import org.woehlke.simpleworklist.oodm.entities.Context; |
8 | | -import org.woehlke.simpleworklist.oodm.entities.UserAccount; |
9 | | -import org.woehlke.simpleworklist.oodm.repository.ContextRepository; |
10 | | -import org.woehlke.simpleworklist.oodm.repository.ProjectRepository; |
11 | | -import org.woehlke.simpleworklist.oodm.repository.TaskRepository; |
12 | | -import org.woehlke.simpleworklist.oodm.services.ContextService; |
13 | | - |
14 | | -import org.springframework.beans.factory.annotation.Autowired; |
15 | | -import java.util.List; |
16 | | - |
17 | | -/** |
18 | | - * Created by tw on 13.03.16. |
19 | | - */ |
20 | | -@Service |
21 | | -@Transactional(propagation = Propagation.REQUIRED, readOnly = true) |
22 | | -public class ContextServiceImpl implements ContextService { |
23 | | - |
24 | | - private final ContextRepository contextRepository; |
25 | | - |
26 | | - private final TaskRepository taskRepository; |
27 | | - |
28 | | - private final ProjectRepository projectRepository; |
29 | | - |
30 | | - @Autowired |
31 | | - public ContextServiceImpl(ContextRepository contextRepository, TaskRepository taskRepository, ProjectRepository projectRepository) { |
32 | | - this.contextRepository = contextRepository; |
33 | | - this.taskRepository = taskRepository; |
34 | | - this.projectRepository = projectRepository; |
35 | | - } |
36 | | - |
37 | | - @Override |
38 | | - public List<Context> getAllForUser(UserAccount user) { |
39 | | - return contextRepository.findByUserAccount(user); |
40 | | - } |
41 | | - |
42 | | - @Override |
43 | | - public Context findByIdAndUserAccount(long newContextId, UserAccount userAccount) { |
44 | | - if(newContextId == 0){ |
45 | | - newContextId = userAccount.getDefaultContext().getId(); |
46 | | - } |
47 | | - return contextRepository.findByIdAndUserAccount(newContextId,userAccount); |
48 | | - } |
49 | | - |
50 | | - @Override |
51 | | - @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false) |
52 | | - public void createNewContext(NewContextForm newContext, UserAccount user) { |
53 | | - Context context = new Context(); |
54 | | - context.setNameEn(newContext.getNameEn()); |
55 | | - context.setNameDe(newContext.getNameDe()); |
56 | | - context.setUserAccount(user); |
57 | | - contextRepository.saveAndFlush(context); |
58 | | - } |
59 | | - |
60 | | - @Override |
61 | | - @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false) |
62 | | - public void updateContext(Context context) { |
63 | | - contextRepository.saveAndFlush(context); |
64 | | - } |
65 | | - |
66 | | - @Override |
67 | | - @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false) |
68 | | - public boolean delete(Context context) { |
69 | | - long contextId = context.getId(); |
70 | | - contextRepository.delete(context); |
71 | | - return (!contextRepository.existsById(contextId)); |
72 | | - } |
73 | | - |
74 | | - @Override |
75 | | - public boolean contextHasItems(Context context) { |
76 | | - long numberOfTasks = taskRepository.findByContext(context).size(); |
77 | | - int numberOfProjects = projectRepository.findByContext(context).size(); |
78 | | - return ((numberOfTasks + numberOfProjects) > 0); |
79 | | - } |
80 | | -} |
| 1 | +package org.woehlke.simpleworklist.oodm.services.impl; |
| 2 | + |
| 3 | +import org.springframework.stereotype.Service; |
| 4 | +import org.springframework.transaction.annotation.Propagation; |
| 5 | +import org.springframework.transaction.annotation.Transactional; |
| 6 | +import org.woehlke.simpleworklist.model.beans.NewContextForm; |
| 7 | +import org.woehlke.simpleworklist.oodm.entities.Context; |
| 8 | +import org.woehlke.simpleworklist.oodm.entities.UserAccount; |
| 9 | +import org.woehlke.simpleworklist.oodm.repository.ContextRepository; |
| 10 | +import org.woehlke.simpleworklist.oodm.repository.ProjectRepository; |
| 11 | +import org.woehlke.simpleworklist.task.TaskRepository; |
| 12 | +import org.woehlke.simpleworklist.oodm.services.ContextService; |
| 13 | + |
| 14 | +import org.springframework.beans.factory.annotation.Autowired; |
| 15 | +import java.util.List; |
| 16 | + |
| 17 | +/** |
| 18 | + * Created by tw on 13.03.16. |
| 19 | + */ |
| 20 | +@Service |
| 21 | +@Transactional(propagation = Propagation.REQUIRED, readOnly = true) |
| 22 | +public class ContextServiceImpl implements ContextService { |
| 23 | + |
| 24 | + private final ContextRepository contextRepository; |
| 25 | + |
| 26 | + private final TaskRepository taskRepository; |
| 27 | + |
| 28 | + private final ProjectRepository projectRepository; |
| 29 | + |
| 30 | + @Autowired |
| 31 | + public ContextServiceImpl(ContextRepository contextRepository, TaskRepository taskRepository, ProjectRepository projectRepository) { |
| 32 | + this.contextRepository = contextRepository; |
| 33 | + this.taskRepository = taskRepository; |
| 34 | + this.projectRepository = projectRepository; |
| 35 | + } |
| 36 | + |
| 37 | + @Override |
| 38 | + public List<Context> getAllForUser(UserAccount user) { |
| 39 | + return contextRepository.findByUserAccount(user); |
| 40 | + } |
| 41 | + |
| 42 | + @Override |
| 43 | + public Context findByIdAndUserAccount(long newContextId, UserAccount userAccount) { |
| 44 | + if(newContextId == 0){ |
| 45 | + newContextId = userAccount.getDefaultContext().getId(); |
| 46 | + } |
| 47 | + return contextRepository.findByIdAndUserAccount(newContextId,userAccount); |
| 48 | + } |
| 49 | + |
| 50 | + @Override |
| 51 | + @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false) |
| 52 | + public void createNewContext(NewContextForm newContext, UserAccount user) { |
| 53 | + Context context = new Context(); |
| 54 | + context.setNameEn(newContext.getNameEn()); |
| 55 | + context.setNameDe(newContext.getNameDe()); |
| 56 | + context.setUserAccount(user); |
| 57 | + contextRepository.saveAndFlush(context); |
| 58 | + } |
| 59 | + |
| 60 | + @Override |
| 61 | + @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false) |
| 62 | + public void updateContext(Context context) { |
| 63 | + contextRepository.saveAndFlush(context); |
| 64 | + } |
| 65 | + |
| 66 | + @Override |
| 67 | + @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false) |
| 68 | + public boolean delete(Context context) { |
| 69 | + long contextId = context.getId(); |
| 70 | + contextRepository.delete(context); |
| 71 | + return (!contextRepository.existsById(contextId)); |
| 72 | + } |
| 73 | + |
| 74 | + @Override |
| 75 | + public boolean contextHasItems(Context context) { |
| 76 | + long numberOfTasks = taskRepository.findByContext(context).size(); |
| 77 | + int numberOfProjects = projectRepository.findByContext(context).size(); |
| 78 | + return ((numberOfTasks + numberOfProjects) > 0); |
| 79 | + } |
| 80 | +} |
0 commit comments