Skip to content
Snippets Groups Projects
Commit 0b555dfb authored by Martin Lowe's avatar Martin Lowe :flag_ca: Committed by Martin Lowe
Browse files

Fixed install counts checking wrong ID, put listing IDs in market


Signed-off-by: Martin Lowe's avatarMartin Lowe <martin.lowe@eclipse-foundation.org>
parent 2a00d480
No related branches found
No related tags found
No related merge requests found
Showing
with 88 additions and 19 deletions
......@@ -25,6 +25,10 @@ public class Catalog extends NodeBase {
private String description;
private String dependenciesRepository;
private List<Tab> tabs;
public Catalog() {
this.tabs = new ArrayList<>();
}
/**
* @return the selfContained
......@@ -110,6 +114,11 @@ public class Catalog extends NodeBase {
this.tabs = new ArrayList<>(tabs);
}
@Override
public boolean validate() {
return super.validate() && tabs != null && !tabs.isEmpty();
}
@Override
public int hashCode() {
final int prime = 31;
......
......@@ -23,7 +23,7 @@ public class Install {
private String javaVersion;
private String eclipseVersion;
private String locale;
/**
* @return the id
*/
......@@ -136,6 +136,11 @@ public class Install {
this.locale = locale;
}
public boolean validate() {
return version != null && listingId != null && os != null && eclipseVersion.isEmpty() && javaVersion != null
&& installDate != null;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
......
......@@ -278,7 +278,6 @@ public class Listing extends NodeBase {
this.categoryIds = new ArrayList<>(categoryIds);
}
/**
* @return the categoryIds
*/
......@@ -382,6 +381,12 @@ public class Listing extends NodeBase {
this.versions = new ArrayList<>(versions);
}
@Override
public boolean validate() {
return super.validate() && license != null && !authors.isEmpty() && !categoryIds.isEmpty()
&& !versions.isEmpty();
}
@Override
public int hashCode() {
final int prime = 31;
......
......@@ -10,6 +10,8 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import org.apache.commons.lang3.StringUtils;
/**
* Domain object representing a marketplace listing version
*
......@@ -25,7 +27,7 @@ public class ListingVersion {
private String minJavaVersion;
private String updateSiteUrl;
private List<FeatureId> featureIds;
public ListingVersion() {
this.eclipseVersions = new ArrayList<>();
this.platforms = new ArrayList<>();
......@@ -147,4 +149,9 @@ public class ListingVersion {
this.featureIds = new ArrayList<>(featureIds);
}
public boolean validate() {
return version != null && listingId != null && StringUtils.isAnyBlank(minJavaVersion) && platforms.isEmpty()
&& !eclipseVersions.isEmpty();
}
}
......@@ -26,17 +26,32 @@ import io.quarkus.runtime.annotations.RegisterForReflection;
*/
@RegisterForReflection
public class Market extends NodeBase {
private List<String> listingIds;
private List<Category> categories;
/**
* Default constructor. Creates an empty linkedlist for categories, as its
* unknown how many categories the market will reference.
*/
public Market() {
this.listingIds = new LinkedList<>();
this.categories = new LinkedList<>();
}
/**
* @return the listingIds
*/
public List<String> getListingIds() {
return new ArrayList<>(listingIds);
}
/**
* @param listingIds the listingIds to set
*/
public void setListingIds(List<String> listingIds) {
this.listingIds = new ArrayList<>(listingIds);
}
/**
* @return the categories
*/
......@@ -56,7 +71,7 @@ public class Market extends NodeBase {
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + Objects.hash(categories);
result = prime * result + Objects.hash(categories, listingIds);
return result;
}
......@@ -72,6 +87,6 @@ public class Market extends NodeBase {
return false;
}
Market other = (Market) obj;
return Objects.equals(categories, other.categories);
return Objects.equals(categories, other.categories) && Objects.equals(listingIds, other.listingIds);
}
}
......@@ -8,12 +8,14 @@ package org.eclipsefoundation.marketplace.dto;
import java.util.Objects;
import org.apache.commons.lang3.StringUtils;
/**
* Contains the basic fields for a node within Mongo
*
* @author Martin Lowe
*/
public class NodeBase {
public abstract class NodeBase {
private String id;
private String title;
private String url;
......@@ -60,6 +62,15 @@ public class NodeBase {
this.url = url;
}
/**
* Call to check whether the current node is valid.
*
* @return whether the current node is valid.
*/
public boolean validate() {
return StringUtils.isAnyEmpty(title, url);
}
@Override
public int hashCode() {
return Objects.hash(id, title, url);
......
......@@ -52,6 +52,7 @@ public class MarketCodec implements CollectibleCodec<Market> {
doc.put(DatabaseFieldNames.DOCID, value.getId());
doc.put(DatabaseFieldNames.URL, value.getUrl());
doc.put(DatabaseFieldNames.TITLE, value.getTitle());
doc.put(DatabaseFieldNames.LISTING_IDS, value.getListingIds());
documentCodec.encode(writer, doc, encoderContext);
}
......@@ -69,6 +70,7 @@ public class MarketCodec implements CollectibleCodec<Market> {
out.setId(document.getString(DatabaseFieldNames.DOCID));
out.setUrl(document.getString(DatabaseFieldNames.URL));
out.setTitle(document.getString(DatabaseFieldNames.TITLE));
out.setListingIds(document.getList(DatabaseFieldNames.LISTING_IDS, String.class));
out.setCategories(document.getList(DatabaseFieldNames.LISTING_CATEGORIES, Document.class).stream()
.map(categoryConverter::convert).collect(Collectors.toList()));
......
......@@ -39,7 +39,7 @@ public class InstallFilter implements DtoFilter<Install> {
// ID check
Optional<String> id = wrap.getFirstParam(UrlParameterNames.ID);
if (id.isPresent()) {
filters.add(Filters.eq(DatabaseFieldNames.DOCID, id.get()));
filters.add(Filters.eq(DatabaseFieldNames.LISTING_ID, id.get()));
}
}
// version check
......
......@@ -61,13 +61,13 @@ public class MarketFilter implements DtoFilter<Market> {
List<Bson> pipeline = new ArrayList<>();
// match the listings on the given market_id
pipeline.add(
Aggregates.match(expr(eq("$in", Arrays.asList("$$market_id", "$" + DatabaseFieldNames.MARKET_IDS)))));
Aggregates.match(expr(eq("$in", Arrays.asList("$" + DatabaseFieldNames.DOCID, "$$listing_ids")))));
// suppress all fields except category_ids
pipeline.add(Aggregates.project(
Projections.fields(Projections.excludeId(), Projections.include(DatabaseFieldNames.CATEGORY_IDS))));
// set up a var reference for the _id
Variable<String> id = new Variable<>("market_id", "$" + DatabaseFieldNames.DOCID);
Variable<String> id = new Variable<>("listing_ids", "$listing_ids");
// lookup all category IDS from listings with the given market ID
aggs.add(Aggregates.lookup(DtoTableNames.LISTING.getTableName(), Arrays.asList(id), pipeline, tempFieldName));
// explode all category IDS for collection
......
......@@ -86,6 +86,7 @@ public final class DatabaseFieldNames {
// install metric fields
public static final String METRIC_PERIODS = "periods";
public static final String MONTH_OFFSET_PREFIX = "offset_";
public static final String LISTING_IDS = "listing_ids";
private DatabaseFieldNames() {
}
......
......@@ -38,12 +38,14 @@ for (var i=0;i<200;i++) {
}
const marketIds = [];
for (var i=0;i<5;i++) {
marketIds.push(uuid.v4());
marketIds.push({uuid: uuid.v4(), listings:[]});
}
createListing(0);
createCategory(0);
createMarket(0);
run();
async function run() {
var a = await createListing(0);
}
function shuff(arr) {
var out = Array.from(arr);
......@@ -69,13 +71,14 @@ function splice(arr) {
async function createListing(count) {
if (count >= max) {
createCategory(0);
return;
}
console.log(`Generating listing ${count} of ${max}`);
var json = generateJSON(uuid.v4());
instance.put(argv.s+"/listings/", json)
.then(listingCallback(json, count))
.then(await listingCallback(json, count))
.catch(err => console.log(err));
}
......@@ -96,6 +99,7 @@ async function listingCallback(json, count) {
function createCategory(count) {
if (count >= categoryIds.length) {
createMarket(0);
return;
}
......@@ -135,6 +139,16 @@ async function createVersion(curr, max, id) {
}
function generateJSON(id) {
var markets = splice(marketIds).splice(0,Math.ceil(Math.random()*2));
for (var marketIdx in markets) {
var currUuid = markets[marketIdx].uuid;
for (var actualMarketIdx in marketIds) {
if (marketIds[actualMarketIdx].uuid === currUuid) {
marketIds[actualMarketIdx].listings.push(id);
break;
}
}
}
return {
"id": id,
"title": "Sample",
......@@ -164,7 +178,6 @@ function generateJSON(id) {
"url": ""
}
],
"market_ids": splice(marketIds).splice(0,Math.ceil(Math.random()*2)),
"category_ids": splice(categoryIds).splice(0,Math.ceil(Math.random()*5)+1),
"screenshots": ["http://www.example.com/img/sample.png"]
};
......@@ -178,11 +191,12 @@ function generateCategoryJSON(id) {
};
}
function generateMarketJSON(id) {
function generateMarketJSON(market) {
return {
"id": id,
"id": market.uuid,
"title": randomWords({exactly:1, wordsPerString:Math.ceil(Math.random()*4)})[0],
"url": "https://www.eclipse.org"
"url": "https://www.eclipse.org",
"listing_ids": market.listings
};
}
......
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