Clover icon

sunshower-core

  1. Project Clover database Fri Apr 6 2018 03:27:42 UTC
  2. Package io.sunshower.service.orchestration

File JpaContentManager.java

 

Coverage histogram

../../../../img/srcFileCovDistChart6.png
31% of files have more coverage

Code metrics

2
28
7
1
116
104
9
0.32
4
7
1.29

Classes

Class Line # Actions
JpaContentManager 20 28 9
0.594594659.5%
 

Contributing tests

This file is covered by 4 tests. .

Source view

1    package io.sunshower.service.orchestration;
2   
3    import io.reactivex.subjects.Subject;
4    import io.sunshower.common.Identifier;
5    import io.sunshower.persistence.core.DistributableEntity;
6    import io.sunshower.service.git.GitRepository;
7    import io.sunshower.service.hal.core.GraphSerializationContext;
8    import io.sunshower.service.hal.core.contents.ContentHandler;
9    import io.sunshower.service.hal.core.contents.ContentManager;
10    import io.sunshower.service.orchestration.model.Template;
11    import io.sunshower.service.orchestration.model.TemplateEvent;
12    import java.util.HashMap;
13    import java.util.Map;
14    import java.util.Objects;
15    import javax.persistence.EntityManager;
16    import org.slf4j.Logger;
17    import org.slf4j.LoggerFactory;
18    import org.springframework.transaction.PlatformTransactionManager;
19   
 
20    public class JpaContentManager implements ContentManager {
21   
22    static final Logger logger = LoggerFactory.getLogger(JpaContentManager.class);
23   
24    private final Template template;
25    private final GitRepository repository;
26    private final GraphSerializationContext graphContext;
27    private final EntityManager entityManager;
28    private final PlatformTransactionManager transactionManager;
29    private final Subject<TemplateEvent> topic;
30   
31    private final Map<Identifier, ContentHandler> openHandlers;
32   
 
33  22 toggle public JpaContentManager(
34    Subject<TemplateEvent> topic,
35    GitRepository repository,
36    EntityManager entityManager,
37    Template template,
38    GraphSerializationContext graphContext,
39    PlatformTransactionManager transactionManager) {
40  22 this.topic = topic;
41  22 this.template = template;
42  22 this.repository = repository;
43  22 this.openHandlers = new HashMap<>();
44  22 this.graphContext = graphContext;
45  22 this.entityManager = entityManager;
46  22 this.transactionManager = transactionManager;
47    }
48   
 
49  0 toggle @Override
50    public void close(DistributableEntity entity) {
51  0 Objects.requireNonNull(entity, "Entity must not be null");
52  0 close(entity.getId());
53    }
54   
 
55  0 toggle @Override
56    public void close(Identifier id) {
57  0 final ContentHandler handler = openHandlers.get(id);
58  0 if (handler != null) {
59  0 handler.close();
60    }
61    }
62   
 
63  0 toggle @Override
64    public void close() {
65  0 for (Identifier o : openHandlers.keySet()) {
66  0 close(o);
67    }
68  0 try {
69  0 repository.close();
70    } catch (Exception e) {
71  0 logger.warn("Failed to close repository. Reason:", e);
72    }
73    }
74   
 
75  2 toggle @Override
76    public ContentHandler graphContent() {
77  2 final ContentHandler handler =
78    new JpaContentHandler(
79    true,
80    null,
81    topic,
82    repository,
83    entityManager,
84    template,
85    graphContext,
86    transactionManager);
87  2 openHandlers.put(Identifier.random(), handler);
88  2 return handler;
89    }
90   
 
91  18 toggle @Override
92    public ContentHandler contentFor(DistributableEntity e) {
93  18 Objects.requireNonNull(e);
94  18 final ContentHandler handler =
95    new JpaContentHandler(
96    e.getId(),
97    topic,
98    repository,
99    entityManager,
100    template,
101    graphContext,
102    transactionManager);
103  18 openHandlers.put(e.getId(), handler);
104  18 return handler;
105    }
106   
 
107  2 toggle @Override
108    public ContentHandler contentFor(Identifier id, Class<?> type) {
109  2 Objects.requireNonNull(id);
110  2 final ContentHandler handler =
111    new JpaContentHandler(
112    id, topic, repository, entityManager, template, graphContext, transactionManager);
113  2 openHandlers.put(id, handler);
114  2 return handler;
115    }
116    }