Changeset 4619
- Timestamp:
- 03/05/14 09:16:20 (10 years ago)
- Location:
- vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/pojo/ResourceType.java
r4618 r4619 23 23 */ 24 24 public enum ResourceType { 25 VIDEO, AUDIO, TEXT, ANNOTATION, OTHER25 VIDEO, AUDIO, IMAGE, TEXT, ANNOTATION, OTHER 26 26 27 27 } -
vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/service/impl/ResourceTypeCountingServiceImpl.java
r4618 r4619 15 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 16 */ 17 18 17 package eu.clarin.cmdi.vlo.service.impl; 19 18 19 import com.google.common.collect.HashMultiset; 20 import com.google.common.collect.Multiset; 21 import eu.clarin.cmdi.vlo.CommonUtils; 22 import eu.clarin.cmdi.vlo.FacetConstants; 20 23 import eu.clarin.cmdi.vlo.pojo.ResourceType; 21 24 import eu.clarin.cmdi.vlo.pojo.ResourceTypeCount; 22 25 import eu.clarin.cmdi.vlo.service.ResourceTypeCountingService; 23 import java.util.Array s;26 import java.util.ArrayList; 24 27 import java.util.Collection; 28 import java.util.Collections; 29 import java.util.regex.Pattern; 25 30 26 31 /** 32 * Counts resource types in a resource string collection 27 33 * 28 34 * @author twagoo … … 30 36 public class ResourceTypeCountingServiceImpl implements ResourceTypeCountingService { 31 37 38 private final static String SPLIT_PATTERN = Pattern.quote(FacetConstants.FIELD_RESOURCE_SPLIT_CHAR); 39 32 40 @Override 33 41 public Collection<ResourceTypeCount> countResourceTypes(Collection<String> resources) { 34 //mock 35 return Arrays.asList(new ResourceTypeCount(ResourceType.TEXT, 2), 36 new ResourceTypeCount(ResourceType.VIDEO, 1), 37 new ResourceTypeCount(ResourceType.OTHER, 1) 38 ); 42 if (resources == null || resources.isEmpty()) { 43 return Collections.emptySet(); 44 } 45 46 final Multiset<ResourceType> countBag = HashMultiset.<ResourceType>create(ResourceType.values().length); 47 48 // loop over resources and count types 49 for (String resourceString : resources) { 50 // split resource string to find mime type 51 final String[] tokens = resourceString.split(SPLIT_PATTERN, 2); 52 final String mimeType = tokens[0]; 53 // normalise 54 final String normalizeMimeType = CommonUtils.normalizeMimeType(mimeType); 55 // map to ResourceType and add to bag (TODO: normalize to ResourceType directly?) 56 if (normalizeMimeType.equals(FacetConstants.RESOURCE_TYPE_ANNOTATION)) { 57 countBag.add(ResourceType.ANNOTATION); 58 } else if (normalizeMimeType.equals(FacetConstants.RESOURCE_TYPE_AUDIO)) { 59 countBag.add(ResourceType.AUDIO); 60 } else if (normalizeMimeType.equals(FacetConstants.RESOURCE_TYPE_IMAGE)) { 61 countBag.add(ResourceType.IMAGE); 62 } else if (normalizeMimeType.equals(FacetConstants.RESOURCE_TYPE_TEXT)) { 63 countBag.add(ResourceType.TEXT); 64 } else if (normalizeMimeType.equals(FacetConstants.RESOURCE_TYPE_VIDEO)) { 65 countBag.add(ResourceType.VIDEO); 66 } 67 } 68 69 // count items in bag for each resource type 70 final Collection<ResourceTypeCount> counts = new ArrayList<ResourceTypeCount>(countBag.elementSet().size()); 71 for (ResourceType type : ResourceType.values()) { 72 final int count = countBag.count(type); 73 // don't add zero counts 74 if (count > 0) { 75 counts.add(new ResourceTypeCount(type, count)); 76 } 77 } 78 return counts; 39 79 } 40 80 41 81 } -
vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/components/SearchResultItemPanel.java
r4618 r4619 53 53 // get model for resources 54 54 final SolrFieldModel<String> resourcesModel = new SolrFieldModel<String>(model, FacetConstants.FIELD_RESOURCE); 55 // wrap with a count provider 55 56 final ResouceTypeCountDataProvider countProvider = new ResouceTypeCountDataProvider(resourcesModel, countingService); 57 // view that shows provided counts 58 // TODO: hide if no resources 56 59 add(new ResourceCountDataView("resourceCount", countProvider)); 57 60 } 58 61 62 /** 63 * Label that shows the content of a Solr field by its string value (using 64 * {@link SolrFieldStringModel}) 65 */ 59 66 private static class SolrFieldLabel extends Label { 60 67 … … 71 78 } 72 79 80 /** 81 * Data view for resource type counts coming from a data provider for 82 * {@link ResourceTypeCount} 83 */ 73 84 private static class ResourceCountDataView extends DataView<ResourceTypeCount> { 74 85 … … 107 118 } 108 119 120 /** 121 * One-way converter for resource type counts that generates string 122 * representations like "1 video file", "2 video files" or "3 text 123 * documents" 124 */ 109 125 private static class ResourceTypeCountConverter implements IConverter<ResourceTypeCount> { 110 126 … … 134 150 case VIDEO: 135 151 return "video file"; 152 case IMAGE: 153 return "image"; 136 154 case TEXT: 137 155 return "text document"; … … 152 170 case VIDEO: 153 171 return "video files"; 172 case IMAGE: 173 return "images"; 154 174 case TEXT: 155 175 return "text documents";
Note: See TracChangeset
for help on using the changeset viewer.