TaggedResourcePath[] taggedPaths = registry.getResourcePathsWithTag(tag);
resourceDataList = new ResourceData [taggedPaths.length];
for (int i=0; i<taggedPaths.length; i++) {
String resultPath = taggedPaths[i].getResourcePath();
ResourceData resourceData = new ResourceData();
resourceData.setResourcePath(resultPath);
if (resultPath != null) {
if (resultPath.equals(RegistryConstants.ROOT_PATH)) {
resourceData.setName(RegistryConstants.ROOT_PATH);
} else {
String[] parts = resultPath.split(RegistryConstants.PATH_SEPARATOR);
resourceData.setName(parts[parts.length - 1]);
}
}
try {
Resource child = registry.get(resultPath);
resourceData.setResourceType(child instanceof Collection ?
"collection" : "resource");
resourceData.setAuthorUserName(child.getAuthorUserName());
resourceData.setDescription(child.getDescription());
resourceData.setAverageRating(registry.getAverageRating(child.getPath()));
Calendar createdDateTime = Calendar.getInstance();
createdDateTime.setTime(child.getCreatedTime());
resourceData.setCreatedOn(createdDateTime);
Map counts = taggedPaths[i].getTagCounts();
Object [] keySet = counts.keySet().toArray();
TagCount [] tagCounts = new TagCount [counts.size()];
for(int j=0; j<counts.size(); j++) {
TagCount tagCount = new TagCount();
tagCount.setKey((String)keySet[j]);
tagCount.setValue(new Long((String)counts.get(keySet[j])));
tagCounts[j] = tagCount;
}
resourceData.setTagCounts(tagCounts);
CommonUtil.populateAverageStars(resourceData);
child.discard();