Skip to content
Snippets Groups Projects
Commit 5df49eaf authored by Martin Lowe's avatar Martin Lowe :flag_ca:
Browse files

Code clean up


Reduce duplicates by extracting NodeBase from DTOs, clean up unneeded
Database field name entries. Fix some minor JS code smells.

Change-Id: Ic53f2656964f22346edad031cc9c28c2900a69e2
Signed-off-by: Martin Lowe's avatarMartin Lowe <martin.lowe@eclipse-foundation.org>
parent d16bcf88
No related branches found
No related tags found
1 merge request!31Code clean up
Showing
with 221 additions and 301 deletions
...@@ -32,8 +32,6 @@ import org.slf4j.LoggerFactory; ...@@ -32,8 +32,6 @@ import org.slf4j.LoggerFactory;
*/ */
public class SecretConfigSource implements ConfigSource { public class SecretConfigSource implements ConfigSource {
private static final Logger LOGGER = LoggerFactory.getLogger(SecretConfigSource.class); private static final Logger LOGGER = LoggerFactory.getLogger(SecretConfigSource.class);
private String secretPath;
private Map<String, String> secrets; private Map<String, String> secrets;
...@@ -41,7 +39,7 @@ public class SecretConfigSource implements ConfigSource { ...@@ -41,7 +39,7 @@ public class SecretConfigSource implements ConfigSource {
public Map<String, String> getProperties() { public Map<String, String> getProperties() {
if (secrets == null) { if (secrets == null) {
this.secrets = new HashMap<>(); this.secrets = new HashMap<>();
this.secretPath = System.getProperty("config.secret.path"); String secretPath = System.getProperty("config.secret.path");
if (StringUtils.isEmpty(secretPath)) { if (StringUtils.isEmpty(secretPath)) {
LOGGER.error("Configuration 'config.secret.path' not set, cannot generate secret properties"); LOGGER.error("Configuration 'config.secret.path' not set, cannot generate secret properties");
return this.secrets; return this.secrets;
......
...@@ -11,16 +11,14 @@ package org.eclipsefoundation.marketplace.dto; ...@@ -11,16 +11,14 @@ package org.eclipsefoundation.marketplace.dto;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects;
/** /**
* Represents a listing catalog. * Represents a listing catalog.
* *
* @author Martin Lowe * @author Martin Lowe
*/ */
public class Catalog { public class Catalog extends NodeBase {
private String id;
private String title;
private String url;
private boolean selfContained; private boolean selfContained;
private boolean searchEnabled; private boolean searchEnabled;
private String icon; private String icon;
...@@ -28,48 +26,6 @@ public class Catalog { ...@@ -28,48 +26,6 @@ public class Catalog {
private String dependenciesRepository; private String dependenciesRepository;
private List<Tab> tabs; 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 * @return the selfContained
*/ */
...@@ -154,4 +110,31 @@ public class Catalog { ...@@ -154,4 +110,31 @@ public class Catalog {
this.tabs = new ArrayList<>(tabs); 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
...@@ -9,8 +9,6 @@ ...@@ -9,8 +9,6 @@
*/ */
package org.eclipsefoundation.marketplace.dto; package org.eclipsefoundation.marketplace.dto;
import java.util.Objects;
import io.quarkus.runtime.annotations.RegisterForReflection; import io.quarkus.runtime.annotations.RegisterForReflection;
/** /**
...@@ -20,83 +18,6 @@ import io.quarkus.runtime.annotations.RegisterForReflection; ...@@ -20,83 +18,6 @@ import io.quarkus.runtime.annotations.RegisterForReflection;
* *
*/ */
@RegisterForReflection @RegisterForReflection
public class Category { public class Category extends NodeBase {
private String id; // only needs bare node
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();
}
} }
...@@ -27,12 +27,8 @@ import io.quarkus.runtime.annotations.RegisterForReflection; ...@@ -27,12 +27,8 @@ import io.quarkus.runtime.annotations.RegisterForReflection;
* @author Martin Lowe * @author Martin Lowe
*/ */
@RegisterForReflection @RegisterForReflection
public class Listing { public class Listing extends NodeBase {
private String id;
@SortableField
private String title;
private String url;
private String supportUrl; private String supportUrl;
private String homepageUrl; private String homepageUrl;
private String teaser; private String teaser;
...@@ -80,48 +76,6 @@ public class Listing { ...@@ -80,48 +76,6 @@ public class Listing {
this.categories = new ArrayList<>(); 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 * @return the supportUrl
*/ */
...@@ -394,12 +348,15 @@ public class Listing { ...@@ -394,12 +348,15 @@ public class Listing {
Objects.requireNonNull(versions); Objects.requireNonNull(versions);
this.versions = new ArrayList<>(versions); this.versions = new ArrayList<>(versions);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(authors, body, categories, categoryIds, creationDate, favoriteCount, foundationMember, final int prime = 31;
homepageUrl, id, installsRecent, installsTotal, license, logo, organizations, status, supportUrl, tags, int result = super.hashCode();
teaser, title, updateDate, url, versions); 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 @Override
...@@ -407,7 +364,7 @@ public class Listing { ...@@ -407,7 +364,7 @@ public class Listing {
if (this == obj) { if (this == obj) {
return true; return true;
} }
if (obj == null) { if (!super.equals(obj)) {
return false; return false;
} }
if (getClass() != obj.getClass()) { if (getClass() != obj.getClass()) {
...@@ -418,21 +375,20 @@ public class Listing { ...@@ -418,21 +375,20 @@ public class Listing {
&& Objects.equals(categories, other.categories) && Objects.equals(categoryIds, other.categoryIds) && Objects.equals(categories, other.categories) && Objects.equals(categoryIds, other.categoryIds)
&& creationDate == other.creationDate && favoriteCount == other.favoriteCount && creationDate == other.creationDate && favoriteCount == other.favoriteCount
&& foundationMember == other.foundationMember && Objects.equals(homepageUrl, other.homepageUrl) && foundationMember == other.foundationMember && Objects.equals(homepageUrl, other.homepageUrl)
&& Objects.equals(id, other.id) && installsRecent == other.installsRecent && installsRecent == other.installsRecent && installsTotal == other.installsTotal
&& installsTotal == other.installsTotal && Objects.equals(license, other.license) && Objects.equals(license, other.license) && Objects.equals(logo, other.logo)
&& Objects.equals(logo, other.logo) && Objects.equals(organizations, other.organizations) && Objects.equals(organizations, other.organizations) && Objects.equals(status, other.status)
&& Objects.equals(status, other.status) && Objects.equals(supportUrl, other.supportUrl) && Objects.equals(supportUrl, other.supportUrl) && Objects.equals(tags, other.tags)
&& Objects.equals(tags, other.tags) && Objects.equals(teaser, other.teaser) && Objects.equals(teaser, other.teaser) && updateDate == other.updateDate
&& Objects.equals(title, other.title) && updateDate == other.updateDate && Objects.equals(versions, other.versions);
&& Objects.equals(url, other.url) && Objects.equals(versions, other.versions);
} }
@Override @Override
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append(", id=").append(id); sb.append(", id=").append(getId());
sb.append(", title=").append(title); sb.append(", name=").append(getName());
sb.append(", url=").append(url); sb.append(", url=").append(getUrl());
sb.append(", supportUrl=").append(supportUrl); sb.append(", supportUrl=").append(supportUrl);
sb.append(", homepageUrl=").append(homepageUrl); sb.append(", homepageUrl=").append(homepageUrl);
sb.append(", teaser=").append(teaser); sb.append(", teaser=").append(teaser);
......
...@@ -12,6 +12,7 @@ package org.eclipsefoundation.marketplace.dto; ...@@ -12,6 +12,7 @@ package org.eclipsefoundation.marketplace.dto;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Objects;
import javax.json.bind.annotation.JsonbTransient; import javax.json.bind.annotation.JsonbTransient;
...@@ -24,13 +25,11 @@ import io.quarkus.runtime.annotations.RegisterForReflection; ...@@ -24,13 +25,11 @@ import io.quarkus.runtime.annotations.RegisterForReflection;
* @since 05/2019 * @since 05/2019
*/ */
@RegisterForReflection @RegisterForReflection
public class Market { public class Market extends NodeBase {
private String id;
private String name;
private String url;
private List<String> categoryIds; private List<String> categoryIds;
private List<Category> categories; private List<Category> categories;
/** /**
* Default constructor. Creates an empty linkedlist for categories, as its * Default constructor. Creates an empty linkedlist for categories, as its
* unknown how many categories the market will reference. * unknown how many categories the market will reference.
...@@ -40,48 +39,6 @@ public class Market { ...@@ -40,48 +39,6 @@ public class Market {
this.categoryIds = new LinkedList<>(); 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 * @return the categories
*/ */
...@@ -111,4 +68,27 @@ public class Market { ...@@ -111,4 +68,27 @@ public class Market {
public void setCategoryIds(List<String> categoryIds) { public void setCategoryIds(List<String> categoryIds) {
this.categoryIds = new ArrayList<>(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);
}
} }
/* 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);
}
}
...@@ -51,8 +51,8 @@ public class CatalogCodec implements CollectibleCodec<Catalog> { ...@@ -51,8 +51,8 @@ public class CatalogCodec implements CollectibleCodec<Catalog> {
Document doc = new Document(); Document doc = new Document();
doc.put(DatabaseFieldNames.DOCID, value.getId()); doc.put(DatabaseFieldNames.DOCID, value.getId());
doc.put(DatabaseFieldNames.CATALOG_TITLE, value.getTitle()); doc.put(DatabaseFieldNames.NAME, value.getName());
doc.put(DatabaseFieldNames.CATALOG_URL, value.getUrl()); doc.put(DatabaseFieldNames.URL, value.getUrl());
doc.put(DatabaseFieldNames.CATALOG_ICON, value.getIcon()); doc.put(DatabaseFieldNames.CATALOG_ICON, value.getIcon());
doc.put(DatabaseFieldNames.CATALOG_SELF_CONTAINED, value.isSelfContained()); doc.put(DatabaseFieldNames.CATALOG_SELF_CONTAINED, value.isSelfContained());
doc.put(DatabaseFieldNames.CATALOG_SEARCH_ENABLED, value.isSearchEnabled()); doc.put(DatabaseFieldNames.CATALOG_SEARCH_ENABLED, value.isSearchEnabled());
...@@ -72,8 +72,8 @@ public class CatalogCodec implements CollectibleCodec<Catalog> { ...@@ -72,8 +72,8 @@ public class CatalogCodec implements CollectibleCodec<Catalog> {
Document document = documentCodec.decode(reader, decoderContext); Document document = documentCodec.decode(reader, decoderContext);
Catalog out = new Catalog(); Catalog out = new Catalog();
out.setId(document.getString(DatabaseFieldNames.DOCID)); out.setId(document.getString(DatabaseFieldNames.DOCID));
out.setUrl(document.getString(DatabaseFieldNames.CATALOG_URL)); out.setUrl(document.getString(DatabaseFieldNames.URL));
out.setTitle(document.getString(DatabaseFieldNames.CATALOG_TITLE)); out.setName(document.getString(DatabaseFieldNames.NAME));
out.setIcon(document.getString(DatabaseFieldNames.CATALOG_ICON)); out.setIcon(document.getString(DatabaseFieldNames.CATALOG_ICON));
out.setSelfContained(document.getBoolean(DatabaseFieldNames.CATALOG_SELF_CONTAINED)); out.setSelfContained(document.getBoolean(DatabaseFieldNames.CATALOG_SELF_CONTAINED));
out.setSearchEnabled(document.getBoolean(DatabaseFieldNames.CATALOG_SEARCH_ENABLED)); out.setSearchEnabled(document.getBoolean(DatabaseFieldNames.CATALOG_SEARCH_ENABLED));
......
...@@ -65,7 +65,7 @@ public class ListingCodec implements CollectibleCodec<Listing> { ...@@ -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 // for each of the fields, get the value from the unencoded object and set it
doc.put(DatabaseFieldNames.DOCID, value.getId()); 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.URL, value.getUrl());
doc.put(DatabaseFieldNames.SUPPORT_PAGE_URL, value.getSupportUrl()); doc.put(DatabaseFieldNames.SUPPORT_PAGE_URL, value.getSupportUrl());
doc.put(DatabaseFieldNames.HOME_PAGE_URL, value.getHomepageUrl()); doc.put(DatabaseFieldNames.HOME_PAGE_URL, value.getHomepageUrl());
...@@ -106,7 +106,7 @@ public class ListingCodec implements CollectibleCodec<Listing> { ...@@ -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 // for each field, get the value from the encoded object and set it in POJO
out.setId(document.getString(DatabaseFieldNames.DOCID)); 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.setUrl(document.getString(DatabaseFieldNames.URL));
out.setSupportUrl(document.getString(DatabaseFieldNames.SUPPORT_PAGE_URL)); out.setSupportUrl(document.getString(DatabaseFieldNames.SUPPORT_PAGE_URL));
out.setHomepageUrl(document.getString(DatabaseFieldNames.HOME_PAGE_URL)); out.setHomepageUrl(document.getString(DatabaseFieldNames.HOME_PAGE_URL));
......
...@@ -47,7 +47,7 @@ public class MarketCodec implements CollectibleCodec<Market> { ...@@ -47,7 +47,7 @@ public class MarketCodec implements CollectibleCodec<Market> {
doc.put(DatabaseFieldNames.DOCID, value.getId()); doc.put(DatabaseFieldNames.DOCID, value.getId());
doc.put(DatabaseFieldNames.URL, value.getUrl()); 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()); doc.put(DatabaseFieldNames.CATEGORY_IDS, value.getCategoryIds());
documentCodec.encode(writer, doc, encoderContext); documentCodec.encode(writer, doc, encoderContext);
...@@ -64,7 +64,7 @@ public class MarketCodec implements CollectibleCodec<Market> { ...@@ -64,7 +64,7 @@ public class MarketCodec implements CollectibleCodec<Market> {
Market out = new Market(); Market out = new Market();
out.setId(document.getString(DatabaseFieldNames.DOCID)); out.setId(document.getString(DatabaseFieldNames.DOCID));
out.setUrl(document.getString(DatabaseFieldNames.URL)); out.setUrl(document.getString(DatabaseFieldNames.URL));
out.setName(document.getString(DatabaseFieldNames.MARKET_NAME)); out.setName(document.getString(DatabaseFieldNames.NAME));
return out; return out;
} }
......
...@@ -11,8 +11,9 @@ import org.eclipsefoundation.marketplace.dto.Category; ...@@ -11,8 +11,9 @@ import org.eclipsefoundation.marketplace.dto.Category;
import org.eclipsefoundation.marketplace.namespace.DatabaseFieldNames; import org.eclipsefoundation.marketplace.namespace.DatabaseFieldNames;
/** /**
* @author martin * Converter implementation for the {@link Category} object.
* *
* @author Martin Lowe
*/ */
public class CategoryConverter implements Converter<Category> { public class CategoryConverter implements Converter<Category> {
...@@ -20,8 +21,8 @@ public class CategoryConverter implements Converter<Category> { ...@@ -20,8 +21,8 @@ public class CategoryConverter implements Converter<Category> {
public Category convert(Document src) { public Category convert(Document src) {
Category out = new Category(); Category out = new Category();
out.setId(src.getString(DatabaseFieldNames.DOCID)); out.setId(src.getString(DatabaseFieldNames.DOCID));
out.setName(src.getString(DatabaseFieldNames.CATEGORY_NAME)); out.setName(src.getString(DatabaseFieldNames.NAME));
out.setUrl(src.getString(DatabaseFieldNames.CATEGORY_URL)); out.setUrl(src.getString(DatabaseFieldNames.URL));
return out; return out;
} }
...@@ -29,8 +30,8 @@ public class CategoryConverter implements Converter<Category> { ...@@ -29,8 +30,8 @@ public class CategoryConverter implements Converter<Category> {
public Document convert(Category src) { public Document convert(Category src) {
Document doc = new Document(); Document doc = new Document();
doc.put(DatabaseFieldNames.DOCID, src.getId()); doc.put(DatabaseFieldNames.DOCID, src.getId());
doc.put(DatabaseFieldNames.CATEGORY_NAME, src.getName()); doc.put(DatabaseFieldNames.NAME, src.getName());
doc.put(DatabaseFieldNames.CATEGORY_URL, src.getUrl()); doc.put(DatabaseFieldNames.URL, src.getUrl());
return doc; return doc;
} }
......
...@@ -18,13 +18,10 @@ public class TagConverter implements Converter<Tag> { ...@@ -18,13 +18,10 @@ public class TagConverter implements Converter<Tag> {
@Override @Override
public Tag convert(Document src) { public Tag convert(Document src) {
Tag org = new Tag(); Tag tag = new Tag();
tag.setId(src.getString("id"));
org.setId(src.getString("id")); tag.setName(src.getString("name"));
org.setName(src.getString("name")); return tag;
org.setUrl(src.getString("url"));
return org;
} }
@Override @Override
...@@ -32,7 +29,6 @@ public class TagConverter implements Converter<Tag> { ...@@ -32,7 +29,6 @@ public class TagConverter implements Converter<Tag> {
Document doc = new Document(); Document doc = new Document();
doc.put("name", src.getName()); doc.put("name", src.getName());
doc.put("id", src.getId()); doc.put("id", src.getId());
doc.put("url", src.getUrl());
return doc; return doc;
} }
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
*/ */
package org.eclipsefoundation.marketplace.dto.filter; package org.eclipsefoundation.marketplace.dto.filter;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
...@@ -17,11 +16,7 @@ import org.eclipsefoundation.marketplace.dto.Catalog; ...@@ -17,11 +16,7 @@ import org.eclipsefoundation.marketplace.dto.Catalog;
import org.eclipsefoundation.marketplace.model.RequestWrapper; import org.eclipsefoundation.marketplace.model.RequestWrapper;
/** /**
* Filter implementation for the Listing class. Checks the following fields: * Filter implementation for the Catalog class.
*
* <ul>
* </ul>
* *
* @author Martin Lowe * @author Martin Lowe
*/ */
......
...@@ -186,7 +186,7 @@ public class MongoQuery<T> { ...@@ -186,7 +186,7 @@ public class MongoQuery<T> {
* @return the docType * @return the docType
*/ */
public Class<T> getDocType() { public Class<T> getDocType() {
return (Class<T>) qps.getAttribute(AnnotationClassInjectionFilter.ATTRIBUTE_NAME); return (Class<T>) qps.getAttribute(AnnotationClassInjectionFilter.ATTRIBUTE_NAME).get();
} }
/** /**
......
...@@ -20,8 +20,6 @@ import javax.ws.rs.core.UriInfo; ...@@ -20,8 +20,6 @@ import javax.ws.rs.core.UriInfo;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.jboss.resteasy.core.ResteasyContext; 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 * Wrapper class for query parameter functionality, wrapping a Map of String to
...@@ -33,17 +31,17 @@ import org.slf4j.LoggerFactory; ...@@ -33,17 +31,17 @@ import org.slf4j.LoggerFactory;
*/ */
@RequestScoped @RequestScoped
public class RequestWrapper { 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 static final String EMPTY_KEY_MESSAGE = "Key must not be null or blank";
private Map<String, List<String>> params; private Map<String, List<String>> params;
private UriInfo uriInfo; private UriInfo uriInfo;
private HttpServletRequest request; private HttpServletRequest request;
private UserAgent userAgent; private UserAgent userAgent;
/** /**
* Generates a wrapper around the * Generates a wrapper around the
*
* @param uriInfo * @param uriInfo
*/ */
RequestWrapper() { RequestWrapper() {
...@@ -51,7 +49,7 @@ public class RequestWrapper { ...@@ -51,7 +49,7 @@ public class RequestWrapper {
this.request = ResteasyContext.getContextData(HttpServletRequest.class); this.request = ResteasyContext.getContextData(HttpServletRequest.class);
this.userAgent = null; this.userAgent = null;
} }
/** /**
* Retrieves the first value set in a list from the map for a given key. * Retrieves the first value set in a list from the map for a given key.
* *
...@@ -91,7 +89,7 @@ public class RequestWrapper { ...@@ -91,7 +89,7 @@ public class RequestWrapper {
} }
return vals; return vals;
} }
/** /**
* Adds the given value for the given key, preserving previous values if they * Adds the given value for the given key, preserving previous values if they
* exist. * exist.
...@@ -109,14 +107,15 @@ public class RequestWrapper { ...@@ -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 * @return a copy of the internal param map
*/ */
public Map<String, List<String>> asMap() { public Map<String, List<String>> asMap() {
return new HashMap<>(getParams()); return new HashMap<>(getParams());
} }
private Map<String, List<String>> getParams() { private Map<String, List<String>> getParams() {
if (params == null) { if (params == null) {
params = new HashMap<>(); params = new HashMap<>();
...@@ -126,23 +125,41 @@ public class RequestWrapper { ...@@ -126,23 +125,41 @@ public class RequestWrapper {
} }
return this.params; return this.params;
} }
/** /**
* Returns the endpoint for the current call * Returns the endpoint for the current call
*
* @return * @return
*/ */
public String getEndpoint() { public String getEndpoint() {
return uriInfo.getPath(); 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) { public String getHeader(String key) {
return request.getHeader(key); return request.getHeader(key);
} }
/**
* Get the wrapped user agent object for the current request.
*
* @return the wrapped UserAgent object.
*/
public UserAgent getUserAgent() { public UserAgent getUserAgent() {
if (userAgent == null) { if (userAgent == null) {
this.userAgent = new UserAgent(getHeader("user-agent")); this.userAgent = new UserAgent(getHeader("user-agent"));
......
...@@ -20,9 +20,9 @@ public final class DatabaseFieldNames { ...@@ -20,9 +20,9 @@ public final class DatabaseFieldNames {
// base fields // base fields
public static final String DOCID = "_id"; public static final String DOCID = "_id";
public static final String URL = "url"; public static final String URL = "url";
public static final String NAME = "name";
// listing fields // listing fields
public static final String LISTING_TITLE = "title";
public static final String LISTING_TEASER = "teaser"; public static final String LISTING_TEASER = "teaser";
public static final String LISTING_BODY = "body"; public static final String LISTING_BODY = "body";
public static final String LISTING_AUTHORS = "authors"; public static final String LISTING_AUTHORS = "authors";
...@@ -49,18 +49,9 @@ public final class DatabaseFieldNames { ...@@ -49,18 +49,9 @@ public final class DatabaseFieldNames {
public static final String CATALOG_SELF_CONTAINED = "self_contained"; public static final String CATALOG_SELF_CONTAINED = "self_contained";
public static final String CATALOG_SEARCH_ENABLED = "search_enabled"; public static final String CATALOG_SEARCH_ENABLED = "search_enabled";
public static final String CATALOG_ICON = "icon"; 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_DESCRIPTION = "description";
public static final String CATALOG_TITLE = "title";
public static final String CATALOG_DEPENDENCIES_REPOSITORY = "dependencies_repository"; 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() { private DatabaseFieldNames() {
} }
} }
...@@ -9,6 +9,11 @@ ...@@ -9,6 +9,11 @@
*/ */
package org.eclipsefoundation.marketplace.namespace; package org.eclipsefoundation.marketplace.namespace;
/**
* Namespace containing URL parameters used throughout the API.
*
* @author Martin Lowe
*/
public final class UrlParameterNames { public final class UrlParameterNames {
public static final String QUERY_STRING = "q"; public static final String QUERY_STRING = "q";
......
...@@ -40,7 +40,7 @@ async function toodles() { ...@@ -40,7 +40,7 @@ async function toodles() {
} }
function report(result) { function report(result) {
var d = result.data; var d = result.data;
for (l in d) { for (var l in d) {
var id = d[l].id; var id = d[l].id;
if (arr.indexOf(id) == -1) { if (arr.indexOf(id) == -1) {
arr.push(id); arr.push(id);
......
...@@ -25,7 +25,7 @@ for (var i=0;i<20;i++) { ...@@ -25,7 +25,7 @@ for (var i=0;i<20;i++) {
categoryIds.push(uuid.v4()); categoryIds.push(uuid.v4());
} }
const marketIds = []; const marketIds = [];
for (var i=0;i<5;i++) { for (i=0;i<5;i++) {
marketIds.push(uuid.v4()); marketIds.push(uuid.v4());
} }
...@@ -61,7 +61,7 @@ function createListing(count) { ...@@ -61,7 +61,7 @@ function createListing(count) {
} }
count++; count++;
axios.post(argv.s+"/listings/", generateJSON(uuid.v4())) axios.post(argv.s+"/listings/", generateJSON(uuid.v4()))
.then(createListing(count)) .then(() => createListing(count))
.catch(err => console.log(err)); .catch(err => console.log(err));
} }
...@@ -71,7 +71,7 @@ function createCategory(count) { ...@@ -71,7 +71,7 @@ function createCategory(count) {
} }
axios.post(argv.s+"/categories/", generateCategoryJSON(categoryIds[count++])) axios.post(argv.s+"/categories/", generateCategoryJSON(categoryIds[count++]))
.then(createCategory(count)) .then(() => createCategory(count))
.catch(err => console.log(err)); .catch(err => console.log(err));
} }
...@@ -81,7 +81,7 @@ function createMarket(count) { ...@@ -81,7 +81,7 @@ function createMarket(count) {
} }
axios.post(argv.s+"/markets/", generateMarketJSON(marketIds[count++])) axios.post(argv.s+"/markets/", generateMarketJSON(marketIds[count++]))
.then(createMarket(count)) .then(() => createMarket(count))
.catch(err => console.log(err)); .catch(err => console.log(err));
} }
......
...@@ -21,11 +21,6 @@ import io.quarkus.test.junit.QuarkusTest; ...@@ -21,11 +21,6 @@ import io.quarkus.test.junit.QuarkusTest;
@QuarkusTest @QuarkusTest
public class ListingResourceTest { public class ListingResourceTest {
@Test
public void testListingIdEndpointBadId() {
given().when().get("/listings/test").then().statusCode(400);
}
@Test @Test
public void testListingIdEndpoint() { public void testListingIdEndpoint() {
given().when().get("/listings/1").then().statusCode(200); given().when().get("/listings/1").then().statusCode(200);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment