Consistent usage of maintainers

Switch developers/authors to maintainers, developerId to id
This commit is contained in:
Michael McCaskill 2016-08-24 17:29:06 -04:00
parent 3dfd2aae2f
commit b9ff47002a
14 changed files with 97 additions and 98 deletions

View File

@ -87,14 +87,14 @@ Sample Response
}
----
=== GET /developers
=== GET /maintainers
Retrieve unique developer names in the plugin data.
Retrieve unique maintainers in the plugin data.
Sample Response
----
{
"developers": [
"maintainers": [
"Kohsuke Kawaguchi",
"Jesse Farinacci",
"Stephen Connolly",
@ -172,9 +172,9 @@ Sample Response
},
...
],
"developers": [
"maintainers": [
{
"developerId": "kohsuke",
"id": "kohsuke",
"name": "Kohsuke Kawaguchi",
"email": null
},
@ -276,9 +276,9 @@ Sample Response
},
...
],
"developers": [
"maintainers": [
{
"developerId": "kohsuke",
"id": "kohsuke",
"name": "Kohsuke Kawaguchi",
"email": null
},
@ -378,9 +378,9 @@ Sample Response
},
...
],
"developers": [
"maintainers": [
{
"developerId": "kohsuke",
"id": "kohsuke",
"name": "Kohsuke Kawaguchi",
"email": null
},
@ -480,9 +480,9 @@ Sample Response
},
...
],
"developers": [
"maintainers": [
{
"developerId": "kohsuke",
"id": "kohsuke",
"name": "Kohsuke Kawaguchi",
"email": null
},
@ -582,9 +582,9 @@ Sample Response
},
...
],
"developers": [
"maintainers": [
{
"developerId": "kohsuke",
"id": "kohsuke",
"name": "Kohsuke Kawaguchi",
"email": null
},

View File

@ -137,7 +137,7 @@ public class GeneratePluginData {
}
}
plugin.setDependencies(dependencies);
final List<Developer> developers = new ArrayList<>();
final List<Maintainer> maintainers = new ArrayList<>();
final JSONArray developersJson = pluginJson.getJSONArray("developers");
if (developersJson != null) {
StreamSupport.stream(developersJson.spliterator(), false).forEach((obj) -> {
@ -145,15 +145,15 @@ public class GeneratePluginData {
final String name = json.optString("name", null);
final String email = json.optString("email", null);
final String developerId = json.optString("developerId", (name != null ? name : email));
final Developer developer = new Developer(
final Maintainer maintainer = new Maintainer(
developerId,
name,
email
);
developers.add(developer);
maintainers.add(maintainer);
});
}
plugin.setDevelopers(developers);
plugin.setMaintainers(maintainers);
if (pluginJson.optString("buildDate", null) != null) {
final LocalDate buildDate = LocalDate.parse(pluginJson.getString("buildDate"), BUILD_DATE_FORMATTER);
plugin.setBuildDate(buildDate);

View File

@ -1,6 +1,6 @@
package io.jenkins.plugins.endpoints;
import io.jenkins.plugins.models.Developers;
import io.jenkins.plugins.models.Maintainers;
import io.jenkins.plugins.services.DatastoreService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -13,9 +13,9 @@ import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@Path("/developers")
@Path("/maintainers")
@Produces(MediaType.APPLICATION_JSON)
public class DevelopersEndpoint {
public class MaintainersEndpoint {
private Logger logger = LoggerFactory.getLogger(CategoriesEndpoint.class);
@ -23,11 +23,11 @@ public class DevelopersEndpoint {
private DatastoreService datastoreService;
@GET
public Developers getDevelopers() {
public Maintainers getMaintainers() {
try {
return datastoreService.getDevelopers();
return datastoreService.getMaintainers();
} catch (Exception e) {
logger.error("Problem getting developers", e);
logger.error("Problem getting maintainers", e);
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
}
}

View File

@ -29,12 +29,12 @@ public class PluginsEndpoint {
@DefaultValue("relevance") @QueryParam("sort") SortBy sortBy,
@DefaultValue("") @QueryParam("categories") String categories,
@DefaultValue("") @QueryParam("labels") String labels,
@DefaultValue("") @QueryParam("authors") String authors,
@DefaultValue("") @QueryParam("maintainers") String maintainers,
@DefaultValue("") @QueryParam("core")String core,
@DefaultValue("50") @QueryParam("limit") int limit,
@DefaultValue("1") @QueryParam("page") int page) {
try {
return datastoreService.search(new SearchOptions(query, sortBy, categories, labels, authors, core, limit, page));
return datastoreService.search(new SearchOptions(query, sortBy, categories, labels, maintainers, core, limit, page));
} catch (ServiceException e) {
logger.error("Problem getting plugins", e);
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);

View File

@ -4,10 +4,10 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
@JsonIgnoreProperties(ignoreUnknown = true)
public class Developer {
public class Maintainer {
@JsonProperty("developerId")
private String developerId;
@JsonProperty("id")
private String id;
@JsonProperty("name")
private String name;
@ -15,21 +15,21 @@ public class Developer {
@JsonProperty("email")
private String email;
public Developer() {
public Maintainer() {
}
public Developer(String developerId, String name, String email) {
this.developerId = developerId;
public Maintainer(String id, String name, String email) {
this.id = id;
this.name = name;
this.email = email;
}
public String getDeveloperId() {
return developerId;
public String getId() {
return id;
}
public void setDeveloperId(String developerId) {
this.developerId = developerId;
public void setId(String id) {
this.id = id;
}
public String getName() {

View File

@ -6,28 +6,28 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
@JsonIgnoreProperties(ignoreUnknown = true)
public class Developers {
public class Maintainers {
@JsonProperty("developers")
private List<String> developers;
@JsonProperty("maintainers")
private List<String> maintainers;
@JsonProperty("limit")
private int limit;
public Developers() {
public Maintainers() {
}
public Developers(List<String> developers) {
this.developers = developers;
this.limit = developers.size();
public Maintainers(List<String> maintainers) {
this.maintainers = maintainers;
this.limit = maintainers.size();
}
public List<String> getDevelopers() {
return developers;
public List<String> getMaintainers() {
return maintainers;
}
public void setDevelopers(List<String> developers) {
this.developers = developers;
public void setMaintainers(List<String> maintainers) {
this.maintainers = maintainers;
}
public int getLimit() {

View File

@ -31,8 +31,8 @@ public class Plugin {
@JsonProperty("dependencies")
private List<Dependency> dependencies;
@JsonProperty("developers")
private List<Developer> developers;
@JsonProperty("maintainers")
private List<Maintainer> maintainers;
@JsonProperty("excerpt")
private String excerpt;
@ -92,14 +92,14 @@ public class Plugin {
public Plugin() {
}
public Plugin(LocalDate buildDate, List<String> categories, List<Dependency> dependencies, List<Developer> developers,
public Plugin(LocalDate buildDate, List<String> categories, List<Dependency> dependencies, List<Maintainer> maintainers,
String excerpt, String gav, List<String> labels, String name, LocalDateTime previousTimestamp,
String previousVersion, LocalDateTime releaseTimestamp, String requiredCore, String scm, String sha1,
Stats stats, String title, String url, String version, Wiki wiki) {
this.buildDate = buildDate;
this.categories = categories;
this.dependencies = dependencies;
this.developers = developers;
this.maintainers = maintainers;
this.excerpt = excerpt;
this.gav = gav;
this.labels = labels;
@ -141,12 +141,12 @@ public class Plugin {
this.dependencies = dependencies;
}
public List<Developer> getDevelopers() {
return developers;
public List<Maintainer> getMaintainers() {
return maintainers;
}
public void setDevelopers(List<Developer> developers) {
this.developers = developers;
public void setMaintainers(List<Maintainer> maintainers) {
this.maintainers = maintainers;
}
public String getExcerpt() {

View File

@ -10,7 +10,7 @@ public interface DatastoreService {
Categories getCategories() throws ServiceException;
Developers getDevelopers() throws ServiceException;
Maintainers getMaintainers() throws ServiceException;
Labels getLabels() throws ServiceException;

View File

@ -10,28 +10,28 @@ public class SearchOptions {
private SortBy sortBy;
private List<String> categories;
private List<String> labels;
private List<String> authors;
private List<String> maintainers;
private String core;
private Integer limit;
private Integer page;
public SearchOptions(String query, SortBy sortBy, List<String> categories, List<String> labels, List<String> authors, String core, Integer limit, Integer page) {
public SearchOptions(String query, SortBy sortBy, List<String> categories, List<String> labels, List<String> maintainers, String core, Integer limit, Integer page) {
setQuery(query);
setSortBy(sortBy);
setCategories(categories);
setLabels(labels);
setAuthors(authors);
setMaintainers(maintainers);
setCore(core);
setLimit(limit);
setPage(page);
}
public SearchOptions(String query, SortBy sortBy, String categories, String labels, String authors, String core, Integer limit, Integer page) {
public SearchOptions(String query, SortBy sortBy, String categories, String labels, String maintainers, String core, Integer limit, Integer page) {
setQuery(query);
setSortBy(sortBy);
setCategories(categories != null && !categories.trim().isEmpty() ? Arrays.asList(categories.split(",")) : Collections.emptyList());
setLabels(labels != null && !labels.trim().isEmpty() ? Arrays.asList(labels.split(",")) : Collections.emptyList());
setAuthors(authors != null && !authors.trim().isEmpty() ? Arrays.asList(authors.split(",")) : Collections.emptyList());
setMaintainers(maintainers != null && !maintainers.trim().isEmpty() ? Arrays.asList(maintainers.split(",")) : Collections.emptyList());
setCore(core);
setLimit(limit);
setPage(page);
@ -69,12 +69,12 @@ public class SearchOptions {
this.labels = labels != null ? labels : Collections.emptyList();
}
public List<String> getAuthors() {
return authors;
public List<String> getMaintainers() {
return maintainers;
}
public void setAuthors(List<String> authors) {
this.authors = authors != null ? authors : Collections.emptyList();
public void setMaintainers(List<String> maintainers) {
this.maintainers = maintainers != null ? maintainers : Collections.emptyList();
}
public String getCore() {

View File

@ -45,12 +45,12 @@ public class ElasticsearchDatastoreService implements DatastoreService {
queryBuilder
.should(QueryBuilders.matchQuery("title", searchOptions.getQuery()))
.should(QueryBuilders.matchQuery("name", searchOptions.getQuery()))
.should(QueryBuilders.nestedQuery("developers", QueryBuilders.matchQuery("developers.name", searchOptions.getQuery())))
.should(QueryBuilders.nestedQuery("maintainers", QueryBuilders.matchQuery("maintainers.name", searchOptions.getQuery())))
.must(QueryBuilders.matchQuery("excerpt", searchOptions.getQuery()));
} else {
queryBuilder.must(QueryBuilders.matchAllQuery());
}
if (!searchOptions.getAuthors().isEmpty() || !searchOptions.getCategories().isEmpty()
if (!searchOptions.getMaintainers().isEmpty() || !searchOptions.getCategories().isEmpty()
|| searchOptions.getCore() != null || !searchOptions.getLabels().isEmpty()) {
final BoolQueryBuilder filter = QueryBuilders.boolQuery();
if (!searchOptions.getCategories().isEmpty() && !searchOptions.getLabels().isEmpty()) {
@ -74,10 +74,10 @@ public class ElasticsearchDatastoreService implements DatastoreService {
)
);
}
if (!searchOptions.getAuthors().isEmpty()) {
if (!searchOptions.getMaintainers().isEmpty()) {
filter.must(
QueryBuilders.boolQuery().should(
QueryBuilders.nestedQuery("developers", QueryBuilders.matchQuery("developers.name", searchOptions.getAuthors()))
QueryBuilders.nestedQuery("maintainers", QueryBuilders.matchQuery("maintainers.name", searchOptions.getMaintainers()))
)
);
}
@ -150,25 +150,25 @@ public class ElasticsearchDatastoreService implements DatastoreService {
}
@Override
public Developers getDevelopers() throws ServiceException {
public Maintainers getMaintainers() throws ServiceException {
try {
final SearchRequestBuilder requestBuilder = esClient.prepareSearch("plugins")
.addAggregation(AggregationBuilders.nested("developers").path("developers")
.subAggregation(AggregationBuilders.terms("developers").field("developers.developerId").size(0))
.addAggregation(AggregationBuilders.nested("maintainers").path("maintainers")
.subAggregation(AggregationBuilders.terms("maintainers").field("maintainers.id").size(0))
)
.setSize(0);
final SearchResponse response = requestBuilder.execute().get();
final List<String> developers = new ArrayList<>();
final InternalNested nested = response.getAggregations().get("developers");
final StringTerms agg = nested.getAggregations().get("developers");
final List<String> maintainers = new ArrayList<>();
final InternalNested nested = response.getAggregations().get("maintainers");
final StringTerms agg = nested.getAggregations().get("maintainers");
agg.getBuckets().forEach((entry) -> {
developers.add(entry.getKeyAsString());
maintainers.add(entry.getKeyAsString());
});
developers.sort(Comparator.naturalOrder());
return new Developers(developers);
maintainers.sort(Comparator.naturalOrder());
return new Maintainers(maintainers);
} catch (Exception e) {
logger.error("Problem getting developers", e);
throw new ServiceException("Problem getting developers", e);
logger.error("Problem getting maintainers", e);
throw new ServiceException("Problem getting maintainers", e);
}
}

View File

@ -25,10 +25,10 @@
}
}
},
"developers" : {
"maintainers" : {
"type" : "nested",
"properties" : {
"developerId" : {
"id" : {
"type" : "string",
"index" : "not_analyzed"
},

View File

@ -29,7 +29,7 @@ public class RestAppIntegrationTest extends JerseyTest {
Assert.assertEquals("git", plugin.getName());
Assert.assertFalse("Categories are empty", plugin.getCategories().isEmpty());
Assert.assertFalse("Dependencies are empty", plugin.getDependencies().isEmpty());
Assert.assertFalse("Developers are empty", plugin.getDevelopers().isEmpty());
Assert.assertFalse("Maintainers are empty", plugin.getMaintainers().isEmpty());
Assert.assertFalse("Labels are empty", plugin.getLabels().isEmpty());
Assert.assertNotNull("Stats are null", plugin.getStats());
}
@ -117,8 +117,8 @@ public class RestAppIntegrationTest extends JerseyTest {
final Plugins plugins = target("/plugins").queryParam("authors", "Kohsuke Kawaguchi").request().get(Plugins.class);
Assert.assertNotNull("Search for categories 'scm' is null", plugins);
for (Plugin plugin : plugins.getPlugins()) {
for (Developer developer : plugin.getDevelopers()) {
if (developer.getName().equalsIgnoreCase("Kohsuke Kawaguchi")) {
for (Maintainer maintainer : plugin.getMaintainers()) {
if (maintainer.getName().equalsIgnoreCase("Kohsuke Kawaguchi")) {
return;
}
}
@ -154,11 +154,11 @@ public class RestAppIntegrationTest extends JerseyTest {
}
@Test
public void testGetDevelopers() {
final Developers developers = target("/developers").request().get(Developers.class);
Assert.assertNotNull("Developers null", developers);
Assert.assertFalse("Developers empty", developers.getDevelopers().isEmpty());
Assert.assertEquals("Developers limit doesn't match", developers.getLimit(), developers.getDevelopers().size());
public void testGetMaintainers() {
final Maintainers maintainers = target("/maintainers").request().get(Maintainers.class);
Assert.assertNotNull("Maintainers null", maintainers);
Assert.assertFalse("Maintainers empty", maintainers.getMaintainers().isEmpty());
Assert.assertEquals("Maintainers limit doesn't match", maintainers.getLimit(), maintainers.getMaintainers().size());
}
@Test
@ -186,7 +186,6 @@ public class RestAppIntegrationTest extends JerseyTest {
Assert.assertTrue("Should return multiple results", plugins.getTotal() > 1);
Assert.assertTrue("Trend order not correct", plugins.getPlugins().get(0).getStats().getTrend() > plugins.getPlugins().get(1).getStats().getTrend());
Assert.assertEquals("Trend limit doesn't match", plugins.getLimit(), plugins.getPlugins().size());
}
@Test

View File

@ -38,7 +38,7 @@ public class DatastoreServiceIntegrationTest {
Assert.assertEquals("git", plugin.getName());
Assert.assertFalse("Categories are empty", plugin.getCategories().isEmpty());
Assert.assertFalse("Dependencies are empty", plugin.getDependencies().isEmpty());
Assert.assertFalse("Developers are empty", plugin.getDevelopers().isEmpty());
Assert.assertFalse("Maintainers are empty", plugin.getMaintainers().isEmpty());
Assert.assertFalse("Labels are empty", plugin.getLabels().isEmpty());
Assert.assertNotNull("Stats are null", plugin.getStats());
}
@ -126,8 +126,8 @@ public class DatastoreServiceIntegrationTest {
final Plugins plugins = datastoreService.search(new SearchOptions(null, null, Collections.emptyList(), Collections.emptyList(), Arrays.asList("Kohsuke Kawaguchi"), null, 50, 1));
Assert.assertNotNull("Search for categories 'scm' is null", plugins);
for (Plugin plugin : plugins.getPlugins()) {
for (Developer developer : plugin.getDevelopers()) {
if (developer.getName().equalsIgnoreCase("Kohsuke Kawaguchi")) {
for (Maintainer maintainer : plugin.getMaintainers()) {
if (maintainer.getName().equalsIgnoreCase("Kohsuke Kawaguchi")) {
return;
}
}
@ -155,11 +155,11 @@ public class DatastoreServiceIntegrationTest {
}
@Test
public void testGetDevelopers() {
final Developers developers = datastoreService.getDevelopers();
Assert.assertNotNull("Developers null", developers);
Assert.assertFalse("Developers empty", developers.getDevelopers().isEmpty());
Assert.assertEquals("Developers limit doesn't match", developers.getLimit(), developers.getDevelopers().size());
public void testGetMaintainers() {
final Maintainers maintainers = datastoreService.getMaintainers();
Assert.assertNotNull("Maintainers null", maintainers);
Assert.assertFalse("Maintainers empty", maintainers.getMaintainers().isEmpty());
Assert.assertEquals("Maintainers limit doesn't match", maintainers.getLimit(), maintainers.getMaintainers().size());
}
@Test