CommerceQuery.java
3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* aQute.bnd.annotation.ProviderType
* javax.servlet.http.HttpServletRequest
* org.apache.commons.lang.StringUtils
*/
package com.adobe.cq.commerce.api;
import aQute.bnd.annotation.ProviderType;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang.StringUtils;
@ProviderType
public class CommerceQuery {
public static final String PARAM_QUERYTEXT = "q";
public static final String PARAM_PAGE = "page";
public static final String PARAM_PAGESIZE = "pagesize";
public static final String PARAM_SORTID = "sort";
protected String queryText;
protected int page;
protected int pageSize;
protected String sortId;
protected Map<String, List<String>> facets;
protected CommerceQuery() {
}
public CommerceQuery(HttpServletRequest request) {
this.queryText = request.getParameter("q");
if (StringUtils.isNumeric((String)request.getParameter("page"))) {
this.page = Integer.parseInt(request.getParameter("page"));
}
if (StringUtils.isNumeric((String)request.getParameter("pagesize"))) {
this.pageSize = Integer.parseInt(request.getParameter("pagesize"));
}
this.sortId = request.getParameter("sort");
this.facets = new HashMap<String, List<String>>();
Map parameterMap = request.getParameterMap();
for (Map.Entry entry : parameterMap.entrySet()) {
if (!((String)entry.getKey()).startsWith("facet_")) continue;
String facetId = ((String)entry.getKey()).substring("facet_".length());
List<Object> values = Arrays.asList((Object[])entry.getValue());
this.facets.put(facetId, values);
}
}
public String getQueryText() {
return this.queryText;
}
public int getPage() {
return this.page;
}
public int getPageSize() {
return this.pageSize;
}
public String getSortId() {
return this.sortId;
}
public Map<String, List<String>> getFacets() {
return this.facets;
}
public static class Builder {
private CommerceQuery query = new CommerceQuery();
public Builder setQueryText(String queryText) {
this.query.queryText = queryText;
return this;
}
public Builder setPage(int page) {
this.query.page = page;
return this;
}
public Builder setPageSize(int pageSize) {
this.query.pageSize = pageSize;
return this;
}
public void setSortId(String sortId) {
this.query.sortId = sortId;
}
public CommerceQuery build() throws IllegalStateException {
if (this.query.queryText == null) {
throw new IllegalStateException("Cannot create query withthout queryText");
}
CommerceQuery result = this.query;
this.query = null;
return result;
}
}
}