1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.extension.repository

File AbstractFilteredExtensionRepository.java

 

Coverage histogram

../../../../img/srcFileCovDistChart3.png
80% of files have more coverage

Code metrics

4
17
7
1
119
69
11
0.65
2.43
7
1.57

Classes

Class Line # Actions
AbstractFilteredExtensionRepository 46 17 0% 11 22
0.2142857221.4%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.extension.repository;
21   
22    import java.util.ArrayList;
23    import java.util.List;
24   
25    import javax.inject.Inject;
26   
27    import org.xwiki.extension.Extension;
28    import org.xwiki.extension.ExtensionDependency;
29    import org.xwiki.extension.ExtensionId;
30    import org.xwiki.extension.ResolveException;
31    import org.xwiki.extension.repository.internal.RepositoryUtils;
32    import org.xwiki.extension.repository.result.IterableResult;
33    import org.xwiki.extension.repository.search.ExtensionQuery;
34    import org.xwiki.extension.repository.search.ExtensionQuery.COMPARISON;
35    import org.xwiki.extension.repository.search.ExtensionQuery.Filter;
36    import org.xwiki.extension.repository.search.SearchException;
37    import org.xwiki.extension.version.Version;
38   
39    /**
40    * A base class to use for a repository proxy searching in all remote extension repositories but filtering the result on
41    * provided criteria.
42    *
43    * @version $Id: a67c8757eb2fff7e82b91cbefdf6fb565f6b862b $
44    * @since 8.3RC1
45    */
 
46    public abstract class AbstractFilteredExtensionRepository extends AbstractAdvancedSearchableExtensionRepository
47    {
48    @Inject
49    private ExtensionRepositoryManager repositories;
50   
51    private List<Filter> filters = new ArrayList<>();
52   
53    /**
54    * @param field the name of the field
55    * @param value the value to compare to
56    * @param comparison the comparison to apply
57    */
 
58  1 toggle public void addFilter(String field, Object value, COMPARISON comparison)
59    {
60  1 this.filters.add(new Filter(field, value, comparison));
61    }
62   
 
63  0 toggle @Override
64    public Extension resolve(ExtensionId extensionId) throws ResolveException
65    {
66  0 for (ExtensionRepository remoteRepository : this.repositories.getRepositories()) {
67  0 Extension extension = remoteRepository.resolve(extensionId);
68   
69  0 if (extension != null && RepositoryUtils.matches(this.filters, extension)) {
70  0 return extension;
71    }
72    }
73   
74  0 return null;
75    }
76   
 
77  0 toggle @Override
78    public Extension resolve(ExtensionDependency extensionDependency) throws ResolveException
79    {
80  0 for (ExtensionRepository remoteRepository : this.repositories.getRepositories()) {
81  0 Extension extension = remoteRepository.resolve(extensionDependency);
82   
83  0 if (extension != null && RepositoryUtils.matches(this.filters, extension)) {
84  0 return extension;
85    }
86    }
87   
88  0 return null;
89    }
90   
 
91  0 toggle @Override
92    public IterableResult<Version> resolveVersions(String id, int offset, int nb) throws ResolveException
93    {
94    // TODO Auto-generated method stub
95  0 return null;
96    }
97   
 
98  0 toggle @Override
99    public boolean isFilterable()
100    {
101  0 return this.repositories.isFilterable();
102    }
103   
 
104  0 toggle @Override
105    public boolean isSortable()
106    {
107  0 return this.repositories.isSortable();
108    }
109   
 
110  13 toggle @Override
111    public IterableResult<Extension> search(ExtensionQuery inputQuery) throws SearchException
112    {
113  13 ExtensionQuery query = new ExtensionQuery(inputQuery);
114   
115  13 query.addFilters(this.filters);
116   
117  13 return this.repositories.search(query);
118    }
119    }