Skip to content
Permalink
Browse files
[JENKINS-31162] Another @tfennelly's comment was addresed
  • Loading branch information
recena committed Mar 13, 2016
1 parent 259cebe commit e0946ee9b1ed9e72c86a6c08a13d37e889ff15fb
Showing 2 changed files with 26 additions and 20 deletions.
@@ -345,28 +345,21 @@ public static Categories getCategories(Authentication a, ItemGroup c) {
Categories categories = new Categories();
for (TopLevelItemDescriptor descriptor : Items.all(a, c)) {
ItemCategory ic = ItemCategoryConfigurator.getCategory(descriptor);
int i = 0;
boolean found = false;
while (i < categories.getItems().size() && !found) {
if (categories.getItems().get(i).getId().equals(ic.getId())) {
Map<String, Object> metadata = new HashMap<String, Object>();
metadata.put("class", descriptor.clazz.getName());
metadata.put("iconClassName", "item-icon-" + descriptor.clazz.getName().substring(descriptor.clazz.getName().lastIndexOf(".") + 1).toLowerCase());
metadata.put("weight", ItemCategoryConfigurator.getWeight(descriptor));
categories.getItems().get(i).getItems().add(metadata);
found = true;
}
i++;
}
if (!found) {
Map<String, Object> metadata = new HashMap<String, Object>();
metadata.put("class", descriptor.clazz.getName());
metadata.put("iconClassName", "item-icon-" + descriptor.clazz.getName().substring(descriptor.clazz.getName().lastIndexOf(".") + 1).toLowerCase());
metadata.put("weight", ItemCategoryConfigurator.getWeight(descriptor));
Map<String, Object> metadata = new HashMap<String, Object>();

metadata.put("class", descriptor.clazz.getName());
metadata.put("iconClassName", "item-icon-" + descriptor.clazz.getName().substring(descriptor.clazz.getName().lastIndexOf(".") + 1).toLowerCase());
metadata.put("weight", ItemCategoryConfigurator.getWeight(descriptor));

Category category = categories.getItem(ic.getId());
if (category != null) {
category.getItems().add(metadata);
} else {
List<Map<String, Object>> temp = new ArrayList<Map<String, Object>>();
temp.add(metadata);
categories.getItems().add(new Category(ic.getId(), ic.getDisplayName(), ic.getDescription(),
ic.getIconClassName(), ic.getWeight(), temp));
category = new Category(ic.getId(), ic.getDisplayName(), ic.getDescription(), ic.getIconClassName(),
ic.getWeight(), temp);
categories.getItems().add(category);
}
}
return categories;
@@ -7,6 +7,8 @@
import org.kohsuke.stapler.export.ExportedBean;
import org.kohsuke.stapler.export.Flavor;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import javax.servlet.ServletException;
import java.io.IOException;
import java.io.Serializable;
@@ -34,4 +36,15 @@ public List<Category> getItems() {
public void generateResponse(StaplerRequest req, StaplerResponse rsp, Object node) throws IOException, ServletException {
rsp.serveExposedBean(req, this, Flavor.JSON);
}

@CheckForNull
public Category getItem(@Nonnull String id) {
for (Category category : items) {
if (category.getId().equals(id)) {
return category;
}
}
return null;
}

}

0 comments on commit e0946ee

Please sign in to comment.