| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package org.xwiki.wiki.internal.manager; |
| 21 |
|
|
| 22 |
|
import java.util.Collection; |
| 23 |
|
|
| 24 |
|
import javax.inject.Inject; |
| 25 |
|
import javax.inject.Singleton; |
| 26 |
|
|
| 27 |
|
import org.xwiki.cache.Cache; |
| 28 |
|
import org.xwiki.cache.CacheException; |
| 29 |
|
import org.xwiki.cache.CacheManager; |
| 30 |
|
import org.xwiki.cache.config.CacheConfiguration; |
| 31 |
|
import org.xwiki.component.annotation.Component; |
| 32 |
|
import org.xwiki.component.phase.Initializable; |
| 33 |
|
import org.xwiki.component.phase.InitializationException; |
| 34 |
|
import org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor; |
| 35 |
|
|
| 36 |
|
|
| 37 |
|
|
| 38 |
|
|
| 39 |
|
@version |
| 40 |
|
@since |
| 41 |
|
|
| 42 |
|
@Component(roles = WikiDescriptorCache.class) |
| 43 |
|
@Singleton |
| |
|
| 96.4% |
Uncovered Elements: 1 (28) |
Complexity: 11 |
Complexity Density: 0.61 |
|
| 44 |
|
public class WikiDescriptorCache implements Initializable |
| 45 |
|
{ |
| 46 |
|
@Inject |
| 47 |
|
private CacheManager cacheManager; |
| 48 |
|
|
| 49 |
|
private Cache<DefaultWikiDescriptor> wikiAliasCache; |
| 50 |
|
|
| 51 |
|
private Cache<DefaultWikiDescriptor> wikiIdCache; |
| 52 |
|
|
| 53 |
|
private Collection<String> wikiIds; |
| 54 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 55 |
69 |
@Override... |
| 56 |
|
public void initialize() throws InitializationException |
| 57 |
|
{ |
| 58 |
69 |
this.wikiAliasCache = createCache("wiki.descriptor.cache.wikiAlias"); |
| 59 |
69 |
this.wikiIdCache = createCache("wiki.descriptor.cache.wikiId"); |
| 60 |
|
} |
| 61 |
|
|
| |
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 62 |
138 |
private Cache<DefaultWikiDescriptor> createCache(String cacheId) throws InitializationException... |
| 63 |
|
{ |
| 64 |
138 |
CacheConfiguration configuration = new CacheConfiguration(cacheId); |
| 65 |
|
|
| 66 |
138 |
try { |
| 67 |
138 |
return this.cacheManager.createNewCache(configuration); |
| 68 |
|
} catch (CacheException e) { |
| 69 |
0 |
throw new InitializationException(String.format("Failed to initialize wiki descriptor caches [%s]", |
| 70 |
|
configuration.getConfigurationId()), e); |
| 71 |
|
} |
| 72 |
|
} |
| 73 |
|
|
| 74 |
|
|
| 75 |
|
|
| 76 |
|
|
| 77 |
|
@param |
| 78 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 79 |
106 |
public void add(DefaultWikiDescriptor descriptor)... |
| 80 |
|
{ |
| 81 |
|
|
| 82 |
106 |
addFromId(descriptor.getId(), descriptor); |
| 83 |
|
|
| 84 |
|
|
| 85 |
106 |
for (String alias : descriptor.getAliases()) { |
| 86 |
107 |
addFromAlias(alias, descriptor); |
| 87 |
|
} |
| 88 |
|
} |
| 89 |
|
|
| 90 |
|
|
| 91 |
|
|
| 92 |
|
|
| 93 |
|
@param |
| 94 |
|
@param |
| 95 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 96 |
107 |
public void addFromAlias(String wikiAlias, DefaultWikiDescriptor descriptor)... |
| 97 |
|
{ |
| 98 |
107 |
this.wikiAliasCache.set(wikiAlias, descriptor); |
| 99 |
|
} |
| 100 |
|
|
| 101 |
|
|
| 102 |
|
|
| 103 |
|
|
| 104 |
|
@param |
| 105 |
|
@param |
| 106 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 107 |
106 |
public void addFromId(String wikiId, DefaultWikiDescriptor descriptor)... |
| 108 |
|
{ |
| 109 |
106 |
this.wikiIdCache.set(wikiId, descriptor); |
| 110 |
|
} |
| 111 |
|
|
| 112 |
|
|
| 113 |
|
|
| 114 |
|
|
| 115 |
|
@param |
| 116 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 117 |
45 |
public void remove(DefaultWikiDescriptor descriptor)... |
| 118 |
|
{ |
| 119 |
|
|
| 120 |
45 |
this.wikiIdCache.remove(descriptor.getId()); |
| 121 |
|
|
| 122 |
|
|
| 123 |
45 |
for (String alias : descriptor.getAliases()) { |
| 124 |
46 |
this.wikiAliasCache.remove(alias); |
| 125 |
|
} |
| 126 |
|
} |
| 127 |
|
|
| 128 |
|
|
| 129 |
|
|
| 130 |
|
|
| 131 |
|
@param |
| 132 |
|
@return |
| 133 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 134 |
8201 |
public DefaultWikiDescriptor getFromId(String wikiId)... |
| 135 |
|
{ |
| 136 |
8202 |
return wikiIdCache.get(wikiId); |
| 137 |
|
} |
| 138 |
|
|
| 139 |
|
|
| 140 |
|
|
| 141 |
|
|
| 142 |
|
@param |
| 143 |
|
@return |
| 144 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 145 |
11586 |
public DefaultWikiDescriptor getFromAlias(String wikiAlias)... |
| 146 |
|
{ |
| 147 |
11586 |
return wikiAliasCache.get(wikiAlias); |
| 148 |
|
} |
| 149 |
|
|
| 150 |
|
|
| 151 |
|
@param |
| 152 |
|
@since |
| 153 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 154 |
199 |
public void setWikiIds(Collection<String> wikiIds)... |
| 155 |
|
{ |
| 156 |
199 |
this.wikiIds = wikiIds; |
| 157 |
|
} |
| 158 |
|
|
| 159 |
|
|
| 160 |
|
@return |
| 161 |
|
@since |
| 162 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 163 |
415 |
public Collection<String> getWikiIds()... |
| 164 |
|
{ |
| 165 |
415 |
return this.wikiIds; |
| 166 |
|
} |
| 167 |
|
} |