Revision 44643
Added by Katerina Iatropoulou over 7 years ago
modules/uoa-search/branches/newAPI/src/main/java/eu/dnetlib/data/search/resources/SimpleResult.java | ||
---|---|---|
1 |
package eu.dnetlib.data.search.resources; |
|
2 |
|
|
3 |
import javax.xml.bind.annotation.XmlAccessType; |
|
4 |
import javax.xml.bind.annotation.XmlAccessorType; |
|
5 |
import javax.xml.bind.annotation.XmlRootElement; |
|
6 |
import java.util.ArrayList; |
|
7 |
import java.util.List; |
|
8 |
|
|
9 |
/** |
|
10 |
* Created by kiatrop on 7/6/2016. |
|
11 |
*/ |
|
12 |
|
|
13 |
@XmlAccessorType(XmlAccessType.FIELD) |
|
14 |
@XmlRootElement(name="result") |
|
15 |
public class SimpleResult { |
|
16 |
|
|
17 |
String objIdentifier; |
|
18 |
String title; |
|
19 |
String year; |
|
20 |
String description; |
|
21 |
|
|
22 |
List<String> authors = new ArrayList<String>(); |
|
23 |
|
|
24 |
} |
|
25 |
|
|
26 |
class Project { |
|
27 |
String objIdentifier; |
|
28 |
String code; |
|
29 |
String title; |
|
30 |
String funderId; |
|
31 |
String funderName; |
|
32 |
} |
|
33 |
|
|
34 |
|
modules/uoa-search/branches/newAPI/src/main/java/eu/dnetlib/data/search/resources/FieldQuery.java | ||
---|---|---|
1 |
package eu.dnetlib.data.search.resources; |
|
2 |
|
|
3 |
/** |
|
4 |
* Created by kiatrop on 10/11/2016. |
|
5 |
*/ |
|
6 |
public class FieldQuery { |
|
7 |
String indexField; |
|
8 |
String operator; //TODO change this |
|
9 |
String[] values; |
|
10 |
|
|
11 |
public String getIndexField() { |
|
12 |
return indexField; |
|
13 |
} |
|
14 |
|
|
15 |
public void setIndexField(String indexField) { |
|
16 |
this.indexField = indexField; |
|
17 |
} |
|
18 |
|
|
19 |
public String getOperator() { |
|
20 |
return operator; |
|
21 |
} |
|
22 |
|
|
23 |
public void setOperator(String operator) { |
|
24 |
this.operator = operator; |
|
25 |
} |
|
26 |
|
|
27 |
public String[] getValues() { |
|
28 |
return values; |
|
29 |
} |
|
30 |
|
|
31 |
public void setValues(String[] values) { |
|
32 |
this.values = values; |
|
33 |
} |
|
34 |
|
|
35 |
public FieldQuery(String indexField, String operator, String[] values) { |
|
36 |
this.indexField = indexField; |
|
37 |
this.operator = operator; |
|
38 |
this.values = values; |
|
39 |
} |
|
40 |
|
|
41 |
public FieldQuery(String indexField, String[] values) { |
|
42 |
this.indexField = indexField; |
|
43 |
this.operator = "AND"; |
|
44 |
this.values = values; |
|
45 |
} |
|
46 |
|
|
47 |
public String toSolrQuery() { |
|
48 |
StringBuilder stringBuilder = new StringBuilder(); |
|
49 |
|
|
50 |
if ( values!=null && values.length>0 ) { |
|
51 |
for(int i=0; i< values.length; i++) { |
|
52 |
stringBuilder.append(indexField).append(":").append("\"").append(values[i]).append("\""); |
|
53 |
if( i<values.length-1) { |
|
54 |
stringBuilder.append("+").append(operator).append("+"); |
|
55 |
} |
|
56 |
} |
|
57 |
} |
|
58 |
|
|
59 |
return stringBuilder.toString(); |
|
60 |
} |
|
61 |
|
|
62 |
@Override |
|
63 |
public String toString() { |
|
64 |
if(getValues()!=null) |
|
65 |
return indexField + "(" + operator + "): " + getValues(); |
|
66 |
return indexField; |
|
67 |
} |
|
68 |
} |
modules/uoa-search/branches/newAPI/src/test/java/eu/dnetlib/data/search/app/plan/web/api/APIResponseFormatterTest.java | ||
---|---|---|
56 | 56 |
|
57 | 57 |
@Test |
58 | 58 |
public void createEntitiesResponseTest(){ |
59 |
//SearchApiService.getResponseByEntity(String fullQuery, RequestResponseHandler.Entity entity, int offset, int limit, String format, HttpServletRequest request, boolean refine, List<String> refineFields, List<String> fieldQueries, String type) { |
|
59 | 60 |
SearchResult emptySearchResult = new SearchResult("oaftype=result", null, 0, 0, 0, null, null, null); |
60 |
System.out.println(APIResponseFormatter.createEntitiesResponse(requestMock, RequestResponseHandler.Entity.PUBLICATION, "oaftype=result", null, emptySearchResult, true, MediaType.APPLICATION_XML));
|
|
61 |
System.out.println(APIResponseFormatter.createEntitiesResponse(requestMock, RequestResponseHandler.Entity.PUBLICATION, "oaftype=result", null, emptySearchResult, true, MediaType.APPLICATION_JSON));
|
|
61 | 62 |
} |
62 | 63 |
} |
modules/uoa-search/branches/newAPI/src/main/java/eu/dnetlib/data/search/solr/SolrResultSet.java | ||
---|---|---|
257 | 257 |
|
258 | 258 |
Map<String,List<String>> response = new HashMap<String, List<String>>(); |
259 | 259 |
|
260 |
logger.debug("refine results " + refineSolrResults); |
|
261 |
logger.debug("search results " + searchSolrResults); |
|
260 |
//logger.debug("refine results " + refineSolrResults);
|
|
261 |
//logger.debug("search results " + searchSolrResults);
|
|
262 | 262 |
|
263 | 263 |
response.put("refine",refineSolrResults); |
264 | 264 |
response.put("search", searchSolrResults); |
modules/uoa-search/branches/newAPI/src/main/java/eu/dnetlib/data/search/app/SearchServiceImpl.java | ||
---|---|---|
756 | 756 |
|
757 | 757 |
|
758 | 758 |
public SearchResult newSearch (String text, String locale, List<String> refinefields, List<String> fieldQueries, int from, int to, String format) throws SearchServiceException { |
759 |
logger.info("Received NEW search request for: '" + text + "' and fields " + fieldQueries);
|
|
759 |
logger.info("Received new search request for: '" + text + "' and field queries " + fieldQueries + " and refine " + refinefields);
|
|
760 | 760 |
IndexService index = getIndexLocator().getService(); |
761 | 761 |
|
762 | 762 |
EPR epr = null; |
modules/uoa-search/branches/newAPI/src/main/java/eu/dnetlib/data/search/app/plan/PrefixRule.java | ||
---|---|---|
10 | 10 |
*/ |
11 | 11 |
public class PrefixRule extends QueryRewriteRule { |
12 | 12 |
|
13 |
public static Logger logger = Logger.getLogger(QueryRewriteRule.class); |
|
13 |
public static final Logger logger = Logger.getLogger(QueryRewriteRule.class);
|
|
14 | 14 |
|
15 | 15 |
private String prefix = null; |
16 | 16 |
|
modules/uoa-search/branches/newAPI/src/main/java/eu/dnetlib/data/search/web/utils/RequestResponseHandler.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.data.search.web.utils; |
2 | 2 |
|
3 |
import eu.dnetlib.data.search.web.api.CQLQueryGeneration; |
|
4 |
|
|
5 |
import java.util.Map; |
|
6 |
|
|
7 | 3 |
/** |
8 | 4 |
* Created by kiatrop on 19/9/2016. |
9 | 5 |
*/ |
... | ... | |
82 | 78 |
|
83 | 79 |
} |
84 | 80 |
|
85 |
public Map<String, String> geIndexParameterMap() { |
|
81 |
/*public Map<String, String> geIndexParameterMap() {
|
|
86 | 82 |
switch (this) { |
87 | 83 |
case PUBLICATION: |
88 | 84 |
return CQLQueryGeneration.resultIndexParameterMap; |
... | ... | |
139 | 135 |
default: |
140 | 136 |
throw new IllegalArgumentException(); |
141 | 137 |
} |
142 |
} |
|
138 |
}*/
|
|
143 | 139 |
} |
144 | 140 |
|
145 | 141 |
public final static String PUBLICATION_PREFIX = "(oaftype exact result) and (resulttypeid exact publication)"; |
modules/uoa-search/branches/newAPI/src/main/java/eu/dnetlib/data/search/web/servlet/SearchServlet.java | ||
---|---|---|
124 | 124 |
writer.append("</error>"); |
125 | 125 |
|
126 | 126 |
} finally { |
127 |
writer.close(); |
|
127 |
if (writer != null) { |
|
128 |
writer.close(); |
|
129 |
} |
|
128 | 130 |
} |
129 | 131 |
} |
130 | 132 |
|
... | ... | |
133 | 135 |
String[] paramfields = request.getParameterValues(parameterName); |
134 | 136 |
if (paramfields != null) { |
135 | 137 |
fields = new ArrayList<String>(); |
136 |
for (int i=0; i<paramfields.length; i++) |
|
138 |
for (int i=0; i<paramfields.length; i++) {
|
|
137 | 139 |
fields.add(paramfields[i]); |
140 |
} |
|
138 | 141 |
} |
139 | 142 |
return fields; |
140 | 143 |
} |
modules/uoa-search/branches/newAPI/src/main/java/eu/dnetlib/data/search/web/api/SearchApiService.java | ||
---|---|---|
18 | 18 |
import javax.ws.rs.core.MediaType; |
19 | 19 |
import javax.ws.rs.core.Response; |
20 | 20 |
import java.io.IOException; |
21 |
import java.util.Arrays; |
|
22 | 21 |
import java.util.List; |
23 | 22 |
import java.util.Locale; |
24 | 23 |
import java.util.Map; |
... | ... | |
581 | 580 |
|
582 | 581 |
return queryBuilder.toString(); |
583 | 582 |
} |
584 |
|
|
583 |
/* |
|
585 | 584 |
public void extractParameterNOperatorsValues(Map<String, String[]> parameterMap, Map<String, String[]> operatorTypeValues, Map<String, String[]> parameterTypeValues, RequestResponseHandler.Entity entity) { |
586 | 585 |
for (String parameter:parameterMap.keySet()) { |
587 | 586 |
Map<String, String> parameterIndexMap = entity.getParameterIndexMap(); |
... | ... | |
670 | 669 |
} |
671 | 670 |
} */ |
672 | 671 |
|
673 |
private Response getResponseByEntityId(RequestResponseHandler.Entity entity, String entityId) { |
|
672 |
private Response getResponseByEntityId(RequestResponseHandler.Entity entity, String entityId, String type) {
|
|
674 | 673 |
try { |
675 | 674 |
StringBuilder queryBuilder = new StringBuilder(); |
676 | 675 |
builtEntityIdQuery(queryBuilder, entity, entityId); |
... | ... | |
680 | 679 |
|
681 | 680 |
if (searchResult.getSearchResults() == null || searchResult.getSearchResults().isEmpty() || |
682 | 681 |
searchResult.getSearchResults().size() == 0 || searchResult.getSearchResults().get(0) == null) { |
683 |
return Response.status(Response.Status.NOT_FOUND).entity( |
|
684 |
ResponseFormatter.compose404Message("404 - " + entity +" with id " |
|
685 |
+ entityId + " not found.")).type(MediaType.APPLICATION_JSON).build(); |
|
682 |
return Response.status(Response.Status.NOT_FOUND).entity(APIResponseFormatter.compose404Message(type, "404 - " + entity +" with id " |
|
683 |
+ entityId + " not found.")).type(type).build(); |
|
686 | 684 |
} |
687 | 685 |
|
688 | 686 |
return Response.status(Response.Status.OK).entity(ResponseFormatter.createEntityResponse(entity, XML.toJSONObject(searchResult.getSearchResults().get(0)).toString())).type(MediaType.APPLICATION_JSON).build(); |
689 | 687 |
|
690 | 688 |
} catch (SearchServiceException sse) { |
691 | 689 |
logger.error("Fail to fetch "+ entity + " with id " + entityId, sse); |
692 |
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(ResponseFormatter.compose500Message("Fail to fetch " + entity + " with id " + entityId, sse.getMessage())).build();
|
|
690 |
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(APIResponseFormatter.compose500Message(type, "Fail to fetch " + entity + " with id " + entityId, sse.getMessage())).build();
|
|
693 | 691 |
} |
694 | 692 |
} |
695 | 693 |
|
696 | 694 |
private Response getResponseByEntity(String fullQuery, RequestResponseHandler.Entity entity, int offset, int limit, String format, HttpServletRequest request, boolean refine, List<String> refineFields, List<String> fieldQueries, String type) { |
697 | 695 |
try { |
698 |
|
|
699 | 696 |
SearchResult solrResults = searchService.newSearch(fullQuery, Locale.getDefault().toString(), refineFields, fieldQueries, offset, limit, format); |
700 |
|
|
701 |
//APIResponseFormatter.createEntitiesResponse(request,entity, fullQuery,"", fieldQueries, solrResults.getSize(), offset, limit, refine, solrResults.getBrowseResults().toString(), type); |
|
702 |
//return Response.status(Response.Status.OK).entity(ResponseFormatter.createEntitiesResponse(request, entity, fullQuery.replace("\"", "\\\""), |
|
703 |
//solrResults.getSearchResults().toString(), solrResults.getTotal()+"", offset+"", limit+"", refine, SolrResultsFormatter.jsonList2Json(solrResults.getBrowseResults()))).type(type).build(); |
|
704 | 697 |
return Response.status(Response.Status.OK).entity(APIResponseFormatter.createEntitiesResponse(request, entity, fullQuery, fieldQueries, solrResults, refine, type)).type(type).build(); |
705 | 698 |
|
706 | 699 |
} catch (SearchServiceException sse) { |
modules/uoa-search/branches/newAPI/src/main/java/eu/dnetlib/data/search/web/api/CQLQueryGeneration.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.data.search.web.api; |
2 | 2 |
|
3 |
import java.util.HashMap; |
|
4 | 3 |
import java.util.List; |
5 |
import java.util.Map; |
|
6 | 4 |
|
7 | 5 |
/** |
8 | 6 |
* Created by kiatrop on 28/9/2016. |
... | ... | |
32 | 30 |
|
33 | 31 |
} |
34 | 32 |
|
35 |
public static final Map<String, String> resultIndexParameterMap; |
|
36 |
static |
|
37 |
{ |
|
38 |
resultIndexParameterMap = new HashMap<String, String>(); |
|
39 |
resultIndexParameterMap.put("instancetypenameid", "type"); |
|
40 |
resultIndexParameterMap.put("resultlanguageid", "lang"); |
|
41 |
resultIndexParameterMap.put("communityid", "community"); |
|
42 |
resultIndexParameterMap.put("relfunderid", "funder"); |
|
43 |
resultIndexParameterMap.put("relfundinglevel0_id", "funderlv0"); |
|
44 |
resultIndexParameterMap.put("relfundinglevel1_id", "funderlv1"); |
|
45 |
resultIndexParameterMap.put("relfundinglevel2_id", "funderlv2"); |
|
46 |
resultIndexParameterMap.put("resultbestlicense", "access"); |
|
47 |
resultIndexParameterMap.put("collectedfromdatasourceid", "collectedFrom"); |
|
48 |
resultIndexParameterMap.put("resulthostingdatasourceid", "hostedBy"); |
|
49 |
resultIndexParameterMap.put("resulttitle", "title"); |
|
50 |
resultIndexParameterMap.put("relperson", "author"); |
|
51 |
resultIndexParameterMap.put("resultpublisher", "publisher"); |
|
52 |
resultIndexParameterMap.put("resultacceptanceyear", "year"); |
|
53 |
} |
|
54 |
|
|
55 |
|
|
56 |
public static final Map<String, String> resultParameterIndexMap; |
|
57 |
static |
|
58 |
{ |
|
59 |
resultParameterIndexMap = new HashMap<String, String>(); |
|
60 |
resultParameterIndexMap.put( "type", "instancetypenameid"); |
|
61 |
resultParameterIndexMap.put("lang", "resultlanguageid"); |
|
62 |
resultParameterIndexMap.put("community", "communityid"); |
|
63 |
resultParameterIndexMap.put("funder", "relfunderid"); |
|
64 |
resultParameterIndexMap.put("funderlv0", "relfundinglevel0_id"); |
|
65 |
resultParameterIndexMap.put("funderlv1", "relfundinglevel1_id"); |
|
66 |
resultParameterIndexMap.put("funderlv2", "relfundinglevel2_id"); |
|
67 |
resultParameterIndexMap.put("access", "resultbestlicense"); |
|
68 |
resultParameterIndexMap.put("collectedFrom", "collectedfromdatasourceid"); |
|
69 |
resultParameterIndexMap.put("hostedBy", "resulthostingdatasourceid"); |
|
70 |
resultParameterIndexMap.put("title", "resulttitle"); |
|
71 |
resultParameterIndexMap.put("author", "relperson"); |
|
72 |
resultParameterIndexMap.put("publisher", "resultpublisher"); |
|
73 |
resultParameterIndexMap.put("year", "resultacceptanceyear"); |
|
74 |
} |
|
75 |
|
|
76 |
public static final Map<String, String> resultOperatorParameterMap; |
|
77 |
static |
|
78 |
{ |
|
79 |
resultOperatorParameterMap = new HashMap<String, String>(); |
|
80 |
resultOperatorParameterMap.put("tp", "type"); |
|
81 |
resultOperatorParameterMap.put("ln", "lang"); |
|
82 |
resultOperatorParameterMap.put("cm", "community"); |
|
83 |
resultOperatorParameterMap.put("fn", "funder"); |
|
84 |
resultOperatorParameterMap.put("fn0", "funderlv0"); |
|
85 |
resultOperatorParameterMap.put("fn1", "funderlv1"); |
|
86 |
resultOperatorParameterMap.put("fn2", "funderlv2"); |
|
87 |
resultOperatorParameterMap.put("ac", "access"); |
|
88 |
resultOperatorParameterMap.put("cl", "collectedFrom"); |
|
89 |
resultOperatorParameterMap.put("hs", "hostedBy"); |
|
90 |
/* |
|
91 |
resultOperatorParameterMap.put("tt", "title"); |
|
92 |
resultOperatorParameterMap.put("at", "author"); |
|
93 |
resultOperatorParameterMap.put("pb", "publisher"); |
|
94 |
*/ |
|
95 |
resultOperatorParameterMap.put("ya", "year"); |
|
96 |
} |
|
97 |
|
|
98 |
public static final Map<String, String> resultParameterOperatorMap; |
|
99 |
static |
|
100 |
{ |
|
101 |
resultParameterOperatorMap = new HashMap<String, String>(); |
|
102 |
resultParameterOperatorMap.put("type", "tp"); |
|
103 |
resultParameterOperatorMap.put("lang", "ln"); |
|
104 |
resultParameterOperatorMap.put("community", "cm"); |
|
105 |
resultParameterOperatorMap.put("funder", "fn"); |
|
106 |
resultParameterOperatorMap.put("funderlv0", "fn0"); |
|
107 |
resultParameterOperatorMap.put("funderlv1", "fn1"); |
|
108 |
resultParameterOperatorMap.put("funderlv2", "fn2"); |
|
109 |
resultParameterOperatorMap.put("access", "ac"); |
|
110 |
resultParameterOperatorMap.put("collectedFrom", "cl"); |
|
111 |
resultParameterOperatorMap.put("hostedBy", "hs"); |
|
112 |
/* resultParameterOperatorMap.put("tt", "title"); |
|
113 |
resultParameterOperatorMap.put("at", "author"); |
|
114 |
resultParameterOperatorMap.put("pb", "publisher"); |
|
115 |
*/ |
|
116 |
resultParameterOperatorMap.put("year", "ya"); |
|
117 |
} |
|
118 |
|
|
119 |
public static final Map<String, String> projectParameterIndexMap; |
|
120 |
static |
|
121 |
{ |
|
122 |
projectParameterIndexMap = new HashMap<String, String>(); |
|
123 |
projectParameterIndexMap.put( "funder", "funderid"); |
|
124 |
projectParameterIndexMap.put("funderlv0", "fundinglevel0_id"); |
|
125 |
projectParameterIndexMap.put("funderlv1", "fundinglevel1_id"); |
|
126 |
projectParameterIndexMap.put("funderlv2", "fundinglevel2_id"); |
|
127 |
projectParameterIndexMap.put("startyear", "projectstartyear"); |
|
128 |
projectParameterIndexMap.put("endyear", "projectendyear"); |
|
129 |
projectParameterIndexMap.put("sc39", "projectecsc39"); |
|
130 |
projectParameterIndexMap.put("acronym", "projectacronym"); |
|
131 |
projectParameterIndexMap.put("title", "projecttitle"); |
|
132 |
projectParameterIndexMap.put("keywords", "projectkeywords"); |
|
133 |
projectParameterIndexMap.put("code", "projectcode"); |
|
134 |
} |
|
135 |
|
|
136 |
public static final Map<String, String> projectParameterOperatorMap; |
|
137 |
static |
|
138 |
{ |
|
139 |
projectParameterOperatorMap = new HashMap<String, String>(); |
|
140 |
projectParameterOperatorMap.put("fn", "funder"); |
|
141 |
projectParameterOperatorMap.put("fn0", "funderlv0"); |
|
142 |
projectParameterOperatorMap.put("fn1", "funderlv1"); |
|
143 |
projectParameterOperatorMap.put("fn2", "funderlv2"); |
|
144 |
projectParameterOperatorMap.put("sa", "startyear"); |
|
145 |
projectParameterOperatorMap.put("ed", "endyear"); |
|
146 |
projectParameterOperatorMap.put("sc", "sc39"); |
|
147 |
projectParameterOperatorMap.put("ar", "acronym"); |
|
148 |
projectParameterOperatorMap.put("tt", "title"); |
|
149 |
projectParameterOperatorMap.put("ky", "keywords"); |
|
150 |
projectParameterOperatorMap.put("cd", "code"); |
|
151 |
} |
|
152 |
|
|
153 |
public static final Map<String, String> datasourceParameterIndexMap; |
|
154 |
static |
|
155 |
{ |
|
156 |
datasourceParameterIndexMap = new HashMap<String, String>(); |
|
157 |
datasourceParameterIndexMap.put( "type", "datasourcetypeuiid"); |
|
158 |
datasourceParameterIndexMap.put("lang", "datasourceodlanguages"); |
|
159 |
datasourceParameterIndexMap.put("contenttype", "datasourceodcontenttypes"); |
|
160 |
datasourceParameterIndexMap.put("compatibility", "datasourcecompatibilityid"); |
|
161 |
datasourceParameterIndexMap.put("officialname", "datasourceofficialname"); |
|
162 |
datasourceParameterIndexMap.put("engname", "datasourceenglishname"); |
|
163 |
datasourceParameterIndexMap.put("subjects", "datasourceodsubjects"); |
|
164 |
|
|
165 |
} |
|
166 |
|
|
167 |
public static final Map<String, String> datasourceParameterOperatorMap; |
|
168 |
static |
|
169 |
{ |
|
170 |
datasourceParameterOperatorMap = new HashMap<String, String>(); |
|
171 |
datasourceParameterOperatorMap.put("tp", "type"); |
|
172 |
datasourceParameterOperatorMap.put("ln", "lang"); |
|
173 |
datasourceParameterOperatorMap.put("cn", "contenttype"); |
|
174 |
datasourceParameterOperatorMap.put("cm", "compatibility"); |
|
175 |
datasourceParameterOperatorMap.put("of", "officialname"); |
|
176 |
datasourceParameterOperatorMap.put("eg", "engname"); |
|
177 |
datasourceParameterOperatorMap.put("sc", "sc39"); |
|
178 |
datasourceParameterOperatorMap.put("sb", "subjects"); |
|
179 |
} |
|
180 |
|
|
181 |
public static final Map<String, String> organizationParameterIndexMap; |
|
182 |
static |
|
183 |
{ |
|
184 |
organizationParameterIndexMap = new HashMap<String, String>(); |
|
185 |
organizationParameterIndexMap.put( "country", "organizationcountryid"); |
|
186 |
organizationParameterIndexMap.put("type", "organizationeclegalbody"); |
|
187 |
organizationParameterIndexMap.put("contenttype", "organizationlegalname"); |
|
188 |
organizationParameterIndexMap.put("compatibility", "organizationlegalshortname"); |
|
189 |
} |
|
190 |
|
|
191 |
public static final Map<String, String> organizationParameterOperatorMap; |
|
192 |
static |
|
193 |
{ |
|
194 |
organizationParameterOperatorMap = new HashMap<String, String>(); |
|
195 |
organizationParameterOperatorMap.put("cu", "country"); |
|
196 |
organizationParameterOperatorMap.put("tp", "type"); |
|
197 |
organizationParameterOperatorMap.put("cn", "contenttype"); |
|
198 |
organizationParameterOperatorMap.put("cm", "compatibility"); |
|
199 |
} |
|
200 |
|
|
201 |
|
|
202 |
public static final Map<String, String> personParameterIndexMap; |
|
203 |
static |
|
204 |
{ |
|
205 |
personParameterIndexMap = new HashMap<String, String>(); |
|
206 |
personParameterIndexMap.put( "surname", "personsecondnames"); |
|
207 |
personParameterIndexMap.put("name", "personfirstname"); |
|
208 |
personParameterIndexMap.put("fullname", "personfullname"); |
|
209 |
} |
|
210 |
|
|
211 |
public static final Map<String, String> personParameterOperatorMap; |
|
212 |
static |
|
213 |
{ |
|
214 |
personParameterOperatorMap = new HashMap<String, String>(); |
|
215 |
personParameterOperatorMap.put("sr", "surname"); |
|
216 |
personParameterOperatorMap.put("nm", "name"); |
|
217 |
personParameterOperatorMap.put("fl", "fullname"); |
|
218 |
} |
|
219 |
|
|
220 |
|
|
221 | 33 |
public static void appendSimpleTerm(StringBuilder stringBuilder, Operator queryOperator, String termValue) { |
222 | 34 |
stringBuilder.append(' ').append(queryOperator).append(" (").append(termValue).append(')'); |
223 | 35 |
} |
... | ... | |
238 | 50 |
appendTerm(stringBuilder, queryOperator, termName, termOperator, termValue); |
239 | 51 |
} |
240 | 52 |
} |
241 |
|
|
242 |
/* |
|
243 |
public String resultQueryEnhancer(MultivaluedMap<String,String> parameterMap, Map<String,String> resultParameterFieldMap) { |
|
244 |
|
|
245 |
StringBuilder stringBuilder = new StringBuilder(); |
|
246 |
|
|
247 |
for (Map.Entry<String, String> entry: resultParameterFieldMap.entrySet()) { |
|
248 |
List<String> fieldValues = parameterMap.get(entry.getKey()); |
|
249 |
String fieldName = entry.getValue(); |
|
250 |
|
|
251 |
if (fieldName != null && !fieldName.isEmpty()) { |
|
252 |
if (fieldValues != null && !fieldValues.isEmpty()) { |
|
253 |
for(String value:fieldValues) { |
|
254 |
if (!fieldName.contains(",")) { |
|
255 |
stringBuilder.append(" and " + value); |
|
256 |
} |
|
257 |
} |
|
258 |
} |
|
259 |
} else { |
|
260 |
//TODO do something |
|
261 |
} |
|
262 |
|
|
263 |
|
|
264 |
} |
|
265 |
|
|
266 |
return null; |
|
267 |
} |
|
268 |
*/ |
|
269 |
|
|
270 | 53 |
} |
modules/uoa-search/branches/newAPI/src/main/java/eu/dnetlib/data/search/web/api/SearchRequestController.java | ||
---|---|---|
471 | 471 |
String[] paramfields = request.getParameterValues(parameterName); |
472 | 472 |
if (paramfields != null) { |
473 | 473 |
fields = new ArrayList<String>(); |
474 |
for (int i = 0; i < paramfields.length; i++) |
|
474 |
for (int i = 0; i < paramfields.length; i++) {
|
|
475 | 475 |
fields.add(paramfields[i]); |
476 |
} |
|
476 | 477 |
} |
477 | 478 |
return fields; |
478 | 479 |
} |
modules/uoa-search/branches/newAPI/src/main/java/eu/dnetlib/data/search/web/api/QueryEnhancer.java | ||
---|---|---|
518 | 518 |
* @return |
519 | 519 |
*/ |
520 | 520 |
public static String devocabularizedTerm(String value, Vocabulary vocabulary) { |
521 |
logger.debug("Vocabulary name " + vocabulary.getName() ); |
|
522 |
logger.debug("Vocabulary English names " + vocabulary.getEnglishNames()); |
|
523 |
|
|
524 | 521 |
if (vocabulary != null) { |
525 | 522 |
String term = vocabulary.getEncoding(value); |
526 | 523 |
if (term == null) { |
modules/uoa-search/branches/newAPI/src/main/java/eu/dnetlib/data/search/web/api/APIResponseFormatter.java | ||
---|---|---|
32 | 32 |
|
33 | 33 |
public static String compose500Message(String type, String message, String description) { |
34 | 34 |
if(type.equals(MediaType.APPLICATION_JSON)) { |
35 |
return String.format(JSONResponseFormat.error500Message, message); |
|
35 |
return String.format(JSONResponseFormat.error500Message, message, description);
|
|
36 | 36 |
} |
37 | 37 |
return String.format(XMLResponseFormat.error500Message, message, description); |
38 | 38 |
} |
... | ... | |
46 | 46 |
} |
47 | 47 |
|
48 | 48 |
if (type.equals(MediaType.APPLICATION_JSON)) { |
49 |
if (searchResult.getSearchResults()==null || searchResult.getSearchResults().isEmpty()) { |
|
50 | 49 |
return String.format(JSONResponseFormat.response, createMeta(request, type, query, filters, searchResult.getTotal(), searchResult.getPage(), searchResult.getSize()), formatSearchResults(type, searchResult.getSearchResults()), ""); |
51 |
} |
|
52 | 50 |
} |
53 |
|
|
54 | 51 |
return String.format(XMLResponseFormat.response, createMeta(request, type, query, filters, searchResult.getTotal(), searchResult.getPage(), searchResult.getSize()), formatSearchResults(type, searchResult.getSearchResults()), ""); |
55 | 52 |
|
56 | 53 |
} |
Also available in: Unified diff
code cleaning