diff --git a/src/main/java/org/eclipsefoundation/marketplace/config/SecretConfigSource.java b/src/main/java/org/eclipsefoundation/marketplace/config/SecretConfigSource.java index bcac9a47d97eda872cf43da6df55d04c908c5804..5d74a8a09c9e0c9550e69a01b567b66a4a98ec4b 100644 --- a/src/main/java/org/eclipsefoundation/marketplace/config/SecretConfigSource.java +++ b/src/main/java/org/eclipsefoundation/marketplace/config/SecretConfigSource.java @@ -32,8 +32,6 @@ import org.slf4j.LoggerFactory; */ public class SecretConfigSource implements ConfigSource { private static final Logger LOGGER = LoggerFactory.getLogger(SecretConfigSource.class); - - private String secretPath; private Map<String, String> secrets; @@ -41,7 +39,7 @@ public class SecretConfigSource implements ConfigSource { public Map<String, String> getProperties() { if (secrets == null) { this.secrets = new HashMap<>(); - this.secretPath = System.getProperty("config.secret.path"); + String secretPath = System.getProperty("config.secret.path"); if (StringUtils.isEmpty(secretPath)) { LOGGER.error("Configuration 'config.secret.path' not set, cannot generate secret properties"); return this.secrets; diff --git a/src/main/java/org/eclipsefoundation/marketplace/dto/Catalog.java b/src/main/java/org/eclipsefoundation/marketplace/dto/Catalog.java index 3c5b496b011dc47232ab51ac7905d61c319539d7..dec87b555d99f2f6bdeaf2f7d648213ee3f34e2f 100644 --- a/src/main/java/org/eclipsefoundation/marketplace/dto/Catalog.java +++ b/src/main/java/org/eclipsefoundation/marketplace/dto/Catalog.java @@ -11,16 +11,14 @@ package org.eclipsefoundation.marketplace.dto; import java.util.ArrayList; import java.util.List; +import java.util.Objects; /** * Represents a listing catalog. * * @author Martin Lowe */ -public class Catalog { - private String id; - private String title; - private String url; +public class Catalog extends NodeBase { private boolean selfContained; private boolean searchEnabled; private String icon; @@ -28,48 +26,6 @@ public class Catalog { private String dependenciesRepository; private List<Tab> tabs; - /** - * @return the id - */ - public String getId() { - return id; - } - - /** - * @param id the id to set - */ - public void setId(String id) { - this.id = id; - } - - /** - * @return the title - */ - public String getTitle() { - return title; - } - - /** - * @param title the title to set - */ - public void setTitle(String title) { - this.title = title; - } - - /** - * @return the url - */ - public String getUrl() { - return url; - } - - /** - * @param url the url to set - */ - public void setUrl(String url) { - this.url = url; - } - /** * @return the selfContained */ @@ -154,4 +110,31 @@ public class Catalog { this.tabs = new ArrayList<>(tabs); } + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + + Objects.hash(dependenciesRepository, description, icon, searchEnabled, selfContained, tabs); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!super.equals(obj)) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + Catalog other = (Catalog) obj; + return Objects.equals(dependenciesRepository, other.dependenciesRepository) + && Objects.equals(description, other.description) && Objects.equals(icon, other.icon) + && searchEnabled == other.searchEnabled && selfContained == other.selfContained + && Objects.equals(tabs, other.tabs); + } + } \ No newline at end of file diff --git a/src/main/java/org/eclipsefoundation/marketplace/dto/Category.java b/src/main/java/org/eclipsefoundation/marketplace/dto/Category.java index 1d9dbb4bdf83d10313555286ad6beb8c3cc494fa..789e25574f9ea02696a2eef25d1275a8c00cdc42 100644 --- a/src/main/java/org/eclipsefoundation/marketplace/dto/Category.java +++ b/src/main/java/org/eclipsefoundation/marketplace/dto/Category.java @@ -9,8 +9,6 @@ */ package org.eclipsefoundation.marketplace.dto; -import java.util.Objects; - import io.quarkus.runtime.annotations.RegisterForReflection; /** @@ -20,83 +18,6 @@ import io.quarkus.runtime.annotations.RegisterForReflection; * */ @RegisterForReflection -public class Category { - private String id; - private String name; - private String url; - - /** - * @return the id - */ - public String getId() { - return id; - } - - /** - * @param id the id to set - */ - public void setId(String id) { - this.id = id; - } - - /** - * @return the name - */ - public String getName() { - return name; - } - - /** - * @param name the name to set - */ - public void setName(String name) { - this.name = name; - } - - /** - * @return the url - */ - public String getUrl() { - return url; - } - - /** - * @param url the url to set - */ - public void setUrl(String url) { - this.url = url; - } - - @Override - public int hashCode() { - return Objects.hash(id, name, url); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - Category other = (Category) obj; - return Objects.equals(id, other.id) && Objects.equals(name, other.name) && Objects.equals(url, other.url); - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("Category [id="); - builder.append(id); - builder.append(", name="); - builder.append(name); - builder.append(", url="); - builder.append(url); - builder.append("]"); - return builder.toString(); - } +public class Category extends NodeBase { + // only needs bare node } diff --git a/src/main/java/org/eclipsefoundation/marketplace/dto/Listing.java b/src/main/java/org/eclipsefoundation/marketplace/dto/Listing.java index c4819e02cc86a35b7be6fd16a2741cb19f543036..a6450655534f251ae3f97f685931a5cc46c3a574 100644 --- a/src/main/java/org/eclipsefoundation/marketplace/dto/Listing.java +++ b/src/main/java/org/eclipsefoundation/marketplace/dto/Listing.java @@ -27,12 +27,8 @@ import io.quarkus.runtime.annotations.RegisterForReflection; * @author Martin Lowe */ @RegisterForReflection -public class Listing { +public class Listing extends NodeBase { - private String id; - @SortableField - private String title; - private String url; private String supportUrl; private String homepageUrl; private String teaser; @@ -80,48 +76,6 @@ public class Listing { this.categories = new ArrayList<>(); } - /** - * @return the id - */ - public String getId() { - return id; - } - - /** - * @param id the id to set - */ - public void setId(String id) { - this.id = id; - } - - /** - * @return the title - */ - public String getTitle() { - return title; - } - - /** - * @param title the title to set - */ - public void setTitle(String title) { - this.title = title; - } - - /** - * @return the url - */ - public String getUrl() { - return url; - } - - /** - * @param url the url to set - */ - public void setUrl(String url) { - this.url = url; - } - /** * @return the supportUrl */ @@ -394,12 +348,15 @@ public class Listing { Objects.requireNonNull(versions); this.versions = new ArrayList<>(versions); } - + @Override public int hashCode() { - return Objects.hash(authors, body, categories, categoryIds, creationDate, favoriteCount, foundationMember, - homepageUrl, id, installsRecent, installsTotal, license, logo, organizations, status, supportUrl, tags, - teaser, title, updateDate, url, versions); + final int prime = 31; + int result = super.hashCode(); + result = prime * result + Objects.hash(authors, body, categories, categoryIds, creationDate, favoriteCount, + foundationMember, homepageUrl, installsRecent, installsTotal, license, logo, organizations, status, + supportUrl, tags, teaser, updateDate, versions); + return result; } @Override @@ -407,7 +364,7 @@ public class Listing { if (this == obj) { return true; } - if (obj == null) { + if (!super.equals(obj)) { return false; } if (getClass() != obj.getClass()) { @@ -418,21 +375,20 @@ public class Listing { && Objects.equals(categories, other.categories) && Objects.equals(categoryIds, other.categoryIds) && creationDate == other.creationDate && favoriteCount == other.favoriteCount && foundationMember == other.foundationMember && Objects.equals(homepageUrl, other.homepageUrl) - && Objects.equals(id, other.id) && installsRecent == other.installsRecent - && installsTotal == other.installsTotal && Objects.equals(license, other.license) - && Objects.equals(logo, other.logo) && Objects.equals(organizations, other.organizations) - && Objects.equals(status, other.status) && Objects.equals(supportUrl, other.supportUrl) - && Objects.equals(tags, other.tags) && Objects.equals(teaser, other.teaser) - && Objects.equals(title, other.title) && updateDate == other.updateDate - && Objects.equals(url, other.url) && Objects.equals(versions, other.versions); + && installsRecent == other.installsRecent && installsTotal == other.installsTotal + && Objects.equals(license, other.license) && Objects.equals(logo, other.logo) + && Objects.equals(organizations, other.organizations) && Objects.equals(status, other.status) + && Objects.equals(supportUrl, other.supportUrl) && Objects.equals(tags, other.tags) + && Objects.equals(teaser, other.teaser) && updateDate == other.updateDate + && Objects.equals(versions, other.versions); } @Override public String toString() { StringBuilder sb = new StringBuilder(); - sb.append(", id=").append(id); - sb.append(", title=").append(title); - sb.append(", url=").append(url); + sb.append(", id=").append(getId()); + sb.append(", name=").append(getName()); + sb.append(", url=").append(getUrl()); sb.append(", supportUrl=").append(supportUrl); sb.append(", homepageUrl=").append(homepageUrl); sb.append(", teaser=").append(teaser); diff --git a/src/main/java/org/eclipsefoundation/marketplace/dto/Market.java b/src/main/java/org/eclipsefoundation/marketplace/dto/Market.java index 2b1c2e0b8a329ecbde4278ad6481f51a79ac4788..b7ce51aead624664474c3831732e0c45e6579f93 100644 --- a/src/main/java/org/eclipsefoundation/marketplace/dto/Market.java +++ b/src/main/java/org/eclipsefoundation/marketplace/dto/Market.java @@ -12,6 +12,7 @@ package org.eclipsefoundation.marketplace.dto; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; +import java.util.Objects; import javax.json.bind.annotation.JsonbTransient; @@ -24,13 +25,11 @@ import io.quarkus.runtime.annotations.RegisterForReflection; * @since 05/2019 */ @RegisterForReflection -public class Market { - private String id; - private String name; - private String url; +public class Market extends NodeBase { private List<String> categoryIds; private List<Category> categories; + /** * Default constructor. Creates an empty linkedlist for categories, as its * unknown how many categories the market will reference. @@ -40,48 +39,6 @@ public class Market { this.categoryIds = new LinkedList<>(); } - /** - * @return the id - */ - public String getId() { - return id; - } - - /** - * @param id the id to set - */ - public void setId(String id) { - this.id = id; - } - - /** - * @return the name - */ - public String getName() { - return name; - } - - /** - * @param name the name to set - */ - public void setName(String name) { - this.name = name; - } - - /** - * @return the url - */ - public String getUrl() { - return url; - } - - /** - * @param url the url to set - */ - public void setUrl(String url) { - this.url = url; - } - /** * @return the categories */ @@ -111,4 +68,27 @@ public class Market { public void setCategoryIds(List<String> categoryIds) { this.categoryIds = new ArrayList<>(categoryIds); } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + Objects.hash(categories, categoryIds); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!super.equals(obj)) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + Market other = (Market) obj; + return Objects.equals(categories, other.categories) && Objects.equals(categoryIds, other.categoryIds); + } } diff --git a/src/main/java/org/eclipsefoundation/marketplace/dto/NodeBase.java b/src/main/java/org/eclipsefoundation/marketplace/dto/NodeBase.java new file mode 100644 index 0000000000000000000000000000000000000000..278f294c6c834f67777103e0b1f13e0127790015 --- /dev/null +++ b/src/main/java/org/eclipsefoundation/marketplace/dto/NodeBase.java @@ -0,0 +1,82 @@ +/* Copyright (c) 2019 Eclipse Foundation and others. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License 2.0 + * which is available at http://www.eclipse.org/legal/epl-v20.html, + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipsefoundation.marketplace.dto; + +import java.util.Objects; + +/** + * Contains the basic fields for a node within Mongo + * + * @author Martin Lowe + */ +public class NodeBase { + private String id; + private String name; + private String url; + + /** + * @return the id + */ + public String getId() { + return id; + } + + /** + * @param id the id to set + */ + public void setId(String id) { + this.id = id; + } + + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @param name the name to set + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return the url + */ + public String getUrl() { + return url; + } + + /** + * @param url the url to set + */ + public void setUrl(String url) { + this.url = url; + } + + @Override + public int hashCode() { + return Objects.hash(id, name, url); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + NodeBase other = (NodeBase) obj; + return Objects.equals(id, other.id) && Objects.equals(name, other.name) && Objects.equals(url, other.url); + } +} diff --git a/src/main/java/org/eclipsefoundation/marketplace/dto/codecs/CatalogCodec.java b/src/main/java/org/eclipsefoundation/marketplace/dto/codecs/CatalogCodec.java index cbaa4dc0f091fb0c35720d72c29761a1f791a3b3..15626de124aa3256158b718275be6b370a1e5b1a 100644 --- a/src/main/java/org/eclipsefoundation/marketplace/dto/codecs/CatalogCodec.java +++ b/src/main/java/org/eclipsefoundation/marketplace/dto/codecs/CatalogCodec.java @@ -51,8 +51,8 @@ public class CatalogCodec implements CollectibleCodec<Catalog> { Document doc = new Document(); doc.put(DatabaseFieldNames.DOCID, value.getId()); - doc.put(DatabaseFieldNames.CATALOG_TITLE, value.getTitle()); - doc.put(DatabaseFieldNames.CATALOG_URL, value.getUrl()); + doc.put(DatabaseFieldNames.NAME, value.getName()); + doc.put(DatabaseFieldNames.URL, value.getUrl()); doc.put(DatabaseFieldNames.CATALOG_ICON, value.getIcon()); doc.put(DatabaseFieldNames.CATALOG_SELF_CONTAINED, value.isSelfContained()); doc.put(DatabaseFieldNames.CATALOG_SEARCH_ENABLED, value.isSearchEnabled()); @@ -72,8 +72,8 @@ public class CatalogCodec implements CollectibleCodec<Catalog> { Document document = documentCodec.decode(reader, decoderContext); Catalog out = new Catalog(); out.setId(document.getString(DatabaseFieldNames.DOCID)); - out.setUrl(document.getString(DatabaseFieldNames.CATALOG_URL)); - out.setTitle(document.getString(DatabaseFieldNames.CATALOG_TITLE)); + out.setUrl(document.getString(DatabaseFieldNames.URL)); + out.setName(document.getString(DatabaseFieldNames.NAME)); out.setIcon(document.getString(DatabaseFieldNames.CATALOG_ICON)); out.setSelfContained(document.getBoolean(DatabaseFieldNames.CATALOG_SELF_CONTAINED)); out.setSearchEnabled(document.getBoolean(DatabaseFieldNames.CATALOG_SEARCH_ENABLED)); diff --git a/src/main/java/org/eclipsefoundation/marketplace/dto/codecs/ListingCodec.java b/src/main/java/org/eclipsefoundation/marketplace/dto/codecs/ListingCodec.java index 993e0d00b0919cc9357fac81f5229a8536c45ba0..7962ee20e7fc8349b7ca038c77ebf31a40829d0f 100644 --- a/src/main/java/org/eclipsefoundation/marketplace/dto/codecs/ListingCodec.java +++ b/src/main/java/org/eclipsefoundation/marketplace/dto/codecs/ListingCodec.java @@ -65,7 +65,7 @@ public class ListingCodec implements CollectibleCodec<Listing> { // for each of the fields, get the value from the unencoded object and set it doc.put(DatabaseFieldNames.DOCID, value.getId()); - doc.put(DatabaseFieldNames.LISTING_TITLE, value.getTitle()); + doc.put(DatabaseFieldNames.NAME, value.getName()); doc.put(DatabaseFieldNames.URL, value.getUrl()); doc.put(DatabaseFieldNames.SUPPORT_PAGE_URL, value.getSupportUrl()); doc.put(DatabaseFieldNames.HOME_PAGE_URL, value.getHomepageUrl()); @@ -106,7 +106,7 @@ public class ListingCodec implements CollectibleCodec<Listing> { // for each field, get the value from the encoded object and set it in POJO out.setId(document.getString(DatabaseFieldNames.DOCID)); - out.setTitle(document.getString(DatabaseFieldNames.LISTING_TITLE)); + out.setName(document.getString(DatabaseFieldNames.NAME)); out.setUrl(document.getString(DatabaseFieldNames.URL)); out.setSupportUrl(document.getString(DatabaseFieldNames.SUPPORT_PAGE_URL)); out.setHomepageUrl(document.getString(DatabaseFieldNames.HOME_PAGE_URL)); diff --git a/src/main/java/org/eclipsefoundation/marketplace/dto/codecs/MarketCodec.java b/src/main/java/org/eclipsefoundation/marketplace/dto/codecs/MarketCodec.java index 52db3a960da6c0874543e3aa5f3cff4d32405086..610a0360f5164f7fbc08c8196132f289335d246f 100644 --- a/src/main/java/org/eclipsefoundation/marketplace/dto/codecs/MarketCodec.java +++ b/src/main/java/org/eclipsefoundation/marketplace/dto/codecs/MarketCodec.java @@ -47,7 +47,7 @@ public class MarketCodec implements CollectibleCodec<Market> { doc.put(DatabaseFieldNames.DOCID, value.getId()); doc.put(DatabaseFieldNames.URL, value.getUrl()); - doc.put(DatabaseFieldNames.MARKET_NAME, value.getName()); + doc.put(DatabaseFieldNames.NAME, value.getName()); doc.put(DatabaseFieldNames.CATEGORY_IDS, value.getCategoryIds()); documentCodec.encode(writer, doc, encoderContext); @@ -64,7 +64,7 @@ public class MarketCodec implements CollectibleCodec<Market> { Market out = new Market(); out.setId(document.getString(DatabaseFieldNames.DOCID)); out.setUrl(document.getString(DatabaseFieldNames.URL)); - out.setName(document.getString(DatabaseFieldNames.MARKET_NAME)); + out.setName(document.getString(DatabaseFieldNames.NAME)); return out; } diff --git a/src/main/java/org/eclipsefoundation/marketplace/dto/converters/CategoryConverter.java b/src/main/java/org/eclipsefoundation/marketplace/dto/converters/CategoryConverter.java index c307fcc9d4232887ee20e6e22b4d615e75e27c8e..d887ae2e94504b4b9c314a4ed11b53b3ae98865a 100644 --- a/src/main/java/org/eclipsefoundation/marketplace/dto/converters/CategoryConverter.java +++ b/src/main/java/org/eclipsefoundation/marketplace/dto/converters/CategoryConverter.java @@ -11,8 +11,9 @@ import org.eclipsefoundation.marketplace.dto.Category; import org.eclipsefoundation.marketplace.namespace.DatabaseFieldNames; /** - * @author martin - * + * Converter implementation for the {@link Category} object. + * + * @author Martin Lowe */ public class CategoryConverter implements Converter<Category> { @@ -20,8 +21,8 @@ public class CategoryConverter implements Converter<Category> { public Category convert(Document src) { Category out = new Category(); out.setId(src.getString(DatabaseFieldNames.DOCID)); - out.setName(src.getString(DatabaseFieldNames.CATEGORY_NAME)); - out.setUrl(src.getString(DatabaseFieldNames.CATEGORY_URL)); + out.setName(src.getString(DatabaseFieldNames.NAME)); + out.setUrl(src.getString(DatabaseFieldNames.URL)); return out; } @@ -29,8 +30,8 @@ public class CategoryConverter implements Converter<Category> { public Document convert(Category src) { Document doc = new Document(); doc.put(DatabaseFieldNames.DOCID, src.getId()); - doc.put(DatabaseFieldNames.CATEGORY_NAME, src.getName()); - doc.put(DatabaseFieldNames.CATEGORY_URL, src.getUrl()); + doc.put(DatabaseFieldNames.NAME, src.getName()); + doc.put(DatabaseFieldNames.URL, src.getUrl()); return doc; } diff --git a/src/main/java/org/eclipsefoundation/marketplace/dto/converters/TagConverter.java b/src/main/java/org/eclipsefoundation/marketplace/dto/converters/TagConverter.java index a82d5a0f0408147392cfe946b58b55be26d1ef25..5d06635ac7ee18d7a24a51301150a270a9b14e51 100644 --- a/src/main/java/org/eclipsefoundation/marketplace/dto/converters/TagConverter.java +++ b/src/main/java/org/eclipsefoundation/marketplace/dto/converters/TagConverter.java @@ -18,13 +18,10 @@ public class TagConverter implements Converter<Tag> { @Override public Tag convert(Document src) { - Tag org = new Tag(); - - org.setId(src.getString("id")); - org.setName(src.getString("name")); - org.setUrl(src.getString("url")); - - return org; + Tag tag = new Tag(); + tag.setId(src.getString("id")); + tag.setName(src.getString("name")); + return tag; } @Override @@ -32,7 +29,6 @@ public class TagConverter implements Converter<Tag> { Document doc = new Document(); doc.put("name", src.getName()); doc.put("id", src.getId()); - doc.put("url", src.getUrl()); return doc; } diff --git a/src/main/java/org/eclipsefoundation/marketplace/dto/filter/CatalogFilter.java b/src/main/java/org/eclipsefoundation/marketplace/dto/filter/CatalogFilter.java index cb4df1a65ba217dce1d2955acb4536024d19d70b..1d044a351de55cc1d2bd88b204cfdea9e710fd23 100644 --- a/src/main/java/org/eclipsefoundation/marketplace/dto/filter/CatalogFilter.java +++ b/src/main/java/org/eclipsefoundation/marketplace/dto/filter/CatalogFilter.java @@ -6,7 +6,6 @@ */ package org.eclipsefoundation.marketplace.dto.filter; -import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -17,11 +16,7 @@ import org.eclipsefoundation.marketplace.dto.Catalog; import org.eclipsefoundation.marketplace.model.RequestWrapper; /** - * Filter implementation for the Listing class. Checks the following fields: - * - * <ul> - - * </ul> + * Filter implementation for the Catalog class. * * @author Martin Lowe */ diff --git a/src/main/java/org/eclipsefoundation/marketplace/model/MongoQuery.java b/src/main/java/org/eclipsefoundation/marketplace/model/MongoQuery.java index f1f3aeeec58129ef362849d95304e093ec41e586..c1ae7dc4431775ae7a9a499b8a816f1c8424bab7 100644 --- a/src/main/java/org/eclipsefoundation/marketplace/model/MongoQuery.java +++ b/src/main/java/org/eclipsefoundation/marketplace/model/MongoQuery.java @@ -186,7 +186,7 @@ public class MongoQuery<T> { * @return the docType */ public Class<T> getDocType() { - return (Class<T>) qps.getAttribute(AnnotationClassInjectionFilter.ATTRIBUTE_NAME); + return (Class<T>) qps.getAttribute(AnnotationClassInjectionFilter.ATTRIBUTE_NAME).get(); } /** diff --git a/src/main/java/org/eclipsefoundation/marketplace/model/RequestWrapper.java b/src/main/java/org/eclipsefoundation/marketplace/model/RequestWrapper.java index 341ca9744eeeca2edc4073bf7956fdd10a9061f3..b6f103cbdf45f955bef4dbe16f053e97b554b392 100644 --- a/src/main/java/org/eclipsefoundation/marketplace/model/RequestWrapper.java +++ b/src/main/java/org/eclipsefoundation/marketplace/model/RequestWrapper.java @@ -20,8 +20,6 @@ import javax.ws.rs.core.UriInfo; import org.apache.commons.lang3.StringUtils; import org.jboss.resteasy.core.ResteasyContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * Wrapper class for query parameter functionality, wrapping a Map of String to @@ -33,17 +31,17 @@ import org.slf4j.LoggerFactory; */ @RequestScoped public class RequestWrapper { - private static final Logger LOGGER = LoggerFactory.getLogger(RequestWrapper.class); private static final String EMPTY_KEY_MESSAGE = "Key must not be null or blank"; private Map<String, List<String>> params; - + private UriInfo uriInfo; private HttpServletRequest request; private UserAgent userAgent; /** - * Generates a wrapper around the + * Generates a wrapper around the + * * @param uriInfo */ RequestWrapper() { @@ -51,7 +49,7 @@ public class RequestWrapper { this.request = ResteasyContext.getContextData(HttpServletRequest.class); this.userAgent = null; } - + /** * Retrieves the first value set in a list from the map for a given key. * @@ -91,7 +89,7 @@ public class RequestWrapper { } return vals; } - + /** * Adds the given value for the given key, preserving previous values if they * exist. @@ -109,14 +107,15 @@ public class RequestWrapper { } /** - * Returns this QueryParams object as a Map of param values indexed by the param name. + * Returns this QueryParams object as a Map of param values indexed by the param + * name. * * @return a copy of the internal param map */ public Map<String, List<String>> asMap() { return new HashMap<>(getParams()); } - + private Map<String, List<String>> getParams() { if (params == null) { params = new HashMap<>(); @@ -126,23 +125,41 @@ public class RequestWrapper { } return this.params; } - + /** * Returns the endpoint for the current call + * * @return */ public String getEndpoint() { return uriInfo.getPath(); } - - public Object getAttribute(String key) { - return request.getAttribute(key); + + /** + * Retrieve a request attribute + * + * @param key attribute key + * @return the attribute value, or an empty optional if missing. + */ + public Optional<Object> getAttribute(String key) { + return Optional.ofNullable(request.getAttribute(key)); } + /** + * Retrieve a request header value as an optional value. + * + * @param key the headers key value + * @return the value, or an empty optional if missing. + */ public String getHeader(String key) { return request.getHeader(key); } - + + /** + * Get the wrapped user agent object for the current request. + * + * @return the wrapped UserAgent object. + */ public UserAgent getUserAgent() { if (userAgent == null) { this.userAgent = new UserAgent(getHeader("user-agent")); diff --git a/src/main/java/org/eclipsefoundation/marketplace/namespace/DatabaseFieldNames.java b/src/main/java/org/eclipsefoundation/marketplace/namespace/DatabaseFieldNames.java index 2fd71bc80187cd910ec4ef57ef2f24223f2d5b84..dbcac257ecfb078b4271bf63dc279b73f2e0cf5b 100644 --- a/src/main/java/org/eclipsefoundation/marketplace/namespace/DatabaseFieldNames.java +++ b/src/main/java/org/eclipsefoundation/marketplace/namespace/DatabaseFieldNames.java @@ -20,9 +20,9 @@ public final class DatabaseFieldNames { // base fields public static final String DOCID = "_id"; public static final String URL = "url"; + public static final String NAME = "name"; // listing fields - public static final String LISTING_TITLE = "title"; public static final String LISTING_TEASER = "teaser"; public static final String LISTING_BODY = "body"; public static final String LISTING_AUTHORS = "authors"; @@ -49,18 +49,9 @@ public final class DatabaseFieldNames { public static final String CATALOG_SELF_CONTAINED = "self_contained"; public static final String CATALOG_SEARCH_ENABLED = "search_enabled"; public static final String CATALOG_ICON = "icon"; - public static final String CATALOG_URL = "url"; public static final String CATALOG_DESCRIPTION = "description"; - public static final String CATALOG_TITLE = "title"; public static final String CATALOG_DEPENDENCIES_REPOSITORY = "dependencies_repository"; - // category fields - public static final String MARKET_IDS = "market_ids"; - public static final String CATEGORY_NAME = "name"; - public static final String CATEGORY_URL = "url"; - - public static final String MARKET_NAME = "name"; - private DatabaseFieldNames() { } } diff --git a/src/main/java/org/eclipsefoundation/marketplace/namespace/UrlParameterNames.java b/src/main/java/org/eclipsefoundation/marketplace/namespace/UrlParameterNames.java index feb92164115d415fe4fab60cd4e362e501385a18..6d9791cb9fecb0843d5bc6aee96d0806a3566ca0 100644 --- a/src/main/java/org/eclipsefoundation/marketplace/namespace/UrlParameterNames.java +++ b/src/main/java/org/eclipsefoundation/marketplace/namespace/UrlParameterNames.java @@ -9,6 +9,11 @@ */ package org.eclipsefoundation.marketplace.namespace; +/** + * Namespace containing URL parameters used throughout the API. + * + * @author Martin Lowe + */ public final class UrlParameterNames { public static final String QUERY_STRING = "q"; diff --git a/src/main/node/hammer.js b/src/main/node/hammer.js index 9778db00d5b4903106e137a7ee73b417bdf30ced..3f0e3441651f1cd6faa9fa9d9577b943864fbac6 100644 --- a/src/main/node/hammer.js +++ b/src/main/node/hammer.js @@ -40,7 +40,7 @@ async function toodles() { } function report(result) { var d = result.data; - for (l in d) { + for (var l in d) { var id = d[l].id; if (arr.indexOf(id) == -1) { arr.push(id); diff --git a/src/main/node/index.js b/src/main/node/index.js index fd12f21a14421a895dbe419d888c2bc48193c447..03d5f459365f43493561d3e52e09ba563aca541f 100644 --- a/src/main/node/index.js +++ b/src/main/node/index.js @@ -25,7 +25,7 @@ for (var i=0;i<20;i++) { categoryIds.push(uuid.v4()); } const marketIds = []; -for (var i=0;i<5;i++) { +for (i=0;i<5;i++) { marketIds.push(uuid.v4()); } @@ -61,7 +61,7 @@ function createListing(count) { } count++; axios.post(argv.s+"/listings/", generateJSON(uuid.v4())) - .then(createListing(count)) + .then(() => createListing(count)) .catch(err => console.log(err)); } @@ -71,7 +71,7 @@ function createCategory(count) { } axios.post(argv.s+"/categories/", generateCategoryJSON(categoryIds[count++])) - .then(createCategory(count)) + .then(() => createCategory(count)) .catch(err => console.log(err)); } @@ -81,7 +81,7 @@ function createMarket(count) { } axios.post(argv.s+"/markets/", generateMarketJSON(marketIds[count++])) - .then(createMarket(count)) + .then(() => createMarket(count)) .catch(err => console.log(err)); } diff --git a/src/test/java/org/eclipsefoundation/marketplace/resource/ListingResourceTest.java b/src/test/java/org/eclipsefoundation/marketplace/resource/ListingResourceTest.java index 5d62b2feaa0e02e316dd8e9f62dbaa0b7d9346f0..272baf5421347930ca4785434be38f9d99480718 100644 --- a/src/test/java/org/eclipsefoundation/marketplace/resource/ListingResourceTest.java +++ b/src/test/java/org/eclipsefoundation/marketplace/resource/ListingResourceTest.java @@ -21,11 +21,6 @@ import io.quarkus.test.junit.QuarkusTest; @QuarkusTest public class ListingResourceTest { - @Test - public void testListingIdEndpointBadId() { - given().when().get("/listings/test").then().statusCode(400); - } - @Test public void testListingIdEndpoint() { given().when().get("/listings/1").then().statusCode(200);