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

File ExtensionRatingScriptService.java

 

Coverage histogram

../../../../img/srcFileCovDistChart0.png
83% of files have more coverage

Code metrics

2
21
4
1
127
63
8
0.38
5.25
4
2

Classes

Class Line # Actions
ExtensionRatingScriptService 46 21 0% 8 27
0.00%
 

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.script;
21   
22    import java.util.Collection;
23   
24    import javax.inject.Inject;
25    import javax.inject.Named;
26    import javax.inject.Singleton;
27   
28    import org.xwiki.component.annotation.Component;
29    import org.xwiki.extension.ExtensionId;
30    import org.xwiki.extension.ResolveException;
31    import org.xwiki.extension.rating.ExtensionRating;
32    import org.xwiki.extension.repository.ExtensionRepository;
33    import org.xwiki.extension.repository.ExtensionRepositoryManager;
34    import org.xwiki.extension.repository.rating.Ratable;
35    import org.xwiki.extension.version.Version;
36   
37    /**
38    * Various script APIs related to ratable extensions.
39    *
40    * @version $Id: f4857b3769a358bf836e0b6058bafdd0913d7c2c $
41    * @since 6.4M3
42    */
43    @Component
44    @Named(ExtensionManagerScriptService.ROLEHINT + '.' + ExtensionRatingScriptService.ID)
45    @Singleton
 
46    public class ExtensionRatingScriptService extends AbstractExtensionScriptService
47    {
48    /**
49    * The identifier of the sub extension {@link org.xwiki.script.service.ScriptService}.
50    */
51    public static final String ID = "rating";
52   
53    /**
54    * Repository manager, needed for cross-repository operations.
55    */
56    @Inject
57    private ExtensionRepositoryManager repositoryManager;
58   
59    /**
60    * @return all the remote repositories
61    */
 
62  0 toggle private Collection<ExtensionRepository> getRepositories()
63    {
64  0 return this.repositoryManager.getRepositories();
65    }
66   
67    /**
68    * @param extensionId the extension id
69    * @return the rating of an extension
70    */
 
71  0 toggle public ExtensionRating getRating(ExtensionId extensionId)
72    {
73  0 setError(null);
74   
75  0 try {
76  0 return getRating(extensionId.getId(), extensionId.getVersion());
77    } catch (Exception e) {
78  0 setError(e);
79    }
80   
81  0 return null;
82    }
83   
84    /**
85    * @param extensionId the extension id
86    * @param extensionVersion the extension version
87    * @return the rating of an extension
88    */
 
89  0 toggle public ExtensionRating getRating(String extensionId, Version extensionVersion)
90    {
91  0 setError(null);
92   
93  0 try {
94  0 return getRating(extensionId, extensionVersion.getValue());
95    } catch (Exception e) {
96  0 setError(e);
97    }
98   
99  0 return null;
100    }
101   
102    /**
103    * @param extensionId the extension id
104    * @param extensionVersion the extension version
105    * @return the rating of an extension
106    */
 
107  0 toggle public ExtensionRating getRating(String extensionId, String extensionVersion)
108    {
109  0 setError(null);
110   
111  0 Collection<ExtensionRepository> repositories = getRepositories();
112  0 for (ExtensionRepository repository : repositories) {
113  0 if (repository instanceof Ratable) {
114  0 try {
115  0 setError(null);
116  0 return ((Ratable) repository).getRating(extensionId, extensionVersion);
117    } catch (ResolveException e) {
118  0 setError(e);
119    // Keep looking. Maybe there's another repository with the same extension.
120  0 continue;
121    }
122    }
123    }
124   
125  0 return null;
126    }
127    }