Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
minerva
core
Commits
bf097211
Commit
bf097211
authored
Mar 22, 2018
by
Piotr Gawron
Browse files
search by coordinates can be limited to the types
parent
6da94fbe
Changes
6
Hide whitespace changes
Inline
Side-by-side
rest-api/src/main/java/lcsb/mapviewer/api/projects/models/bioEntities/BioEntitiesController.java
View file @
bf097211
...
...
@@ -21,58 +21,61 @@ import lcsb.mapviewer.services.SecurityException;
@RestController
public
class
BioEntitiesController
extends
BaseController
{
@Autowired
private
BioEntitiesRestImpl
bioEntitiesRestImpl
;
@Autowired
private
BioEntitiesRestImpl
bioEntitiesRestImpl
;
@RequestMapping
(
value
=
"/projects/{projectId}/models/{modelId}/bioEntities:search"
,
method
=
{
RequestMethod
.
GET
},
produces
=
{
MediaType
.
APPLICATION_JSON_VALUE
})
public
List
<
Map
<
String
,
Object
>>
getClosestElementsByCoordinates
(
//
@PathVariable
(
value
=
"projectId"
)
String
projectId
,
//
@PathVariable
(
value
=
"modelId"
)
String
modelId
,
//
@CookieValue
(
value
=
Configuration
.
AUTH_TOKEN
)
String
token
,
//
@RequestParam
(
value
=
"coordinates"
,
defaultValue
=
""
)
String
coordinates
,
//
@RequestParam
(
value
=
"query"
,
defaultValue
=
""
)
String
query
,
//
@RequestParam
(
value
=
"count"
,
defaultValue
=
""
)
String
count
,
//
@RequestParam
(
value
=
"perfectMatch"
,
defaultValue
=
"false"
)
String
perfectMatch
//
)
throws
QueryException
,
SecurityException
{
if
(!
coordinates
.
trim
().
isEmpty
())
{
if
(
modelId
.
equals
(
"*"
))
{
throw
new
QueryException
(
"modelId must be defined when searching by coordinates"
);
}
if
(
count
.
trim
().
isEmpty
())
{
count
=
"5"
;
}
String
[]
tmp
=
coordinates
.
split
(
","
);
if
(
tmp
.
length
!=
2
)
{
throw
new
QueryException
(
"Coordinates must be in the format: 'xxx.xx,yyy.yy'"
);
}
Double
x
=
null
;
Double
y
=
null
;
try
{
x
=
Double
.
valueOf
(
tmp
[
0
]);
y
=
Double
.
valueOf
(
tmp
[
1
]);
}
catch
(
NumberFormatException
e
)
{
throw
new
QueryException
(
"Coordinates must be in the format: 'xxx.xx,yyy.yy'"
,
e
);
}
Point2D
pointCoordinates
=
new
Point2D
.
Double
(
x
,
y
);
return
bioEntitiesRestImpl
.
getClosestElementsByCoordinates
(
projectId
,
modelId
,
token
,
pointCoordinates
,
Integer
.
valueOf
(
count
),
perfectMatch
);
}
else
if
(!
query
.
trim
().
isEmpty
())
{
if
(
count
.
trim
().
isEmpty
())
{
count
=
"100"
;
}
return
bioEntitiesRestImpl
.
getElementsByQuery
(
projectId
,
token
,
modelId
,
query
,
Integer
.
valueOf
(
count
),
perfectMatch
);
}
else
{
return
new
ArrayList
<>();
}
}
@RequestMapping
(
value
=
"/projects/{projectId}/models/{modelId}/bioEntities:search"
,
method
=
{
RequestMethod
.
GET
},
produces
=
{
MediaType
.
APPLICATION_JSON_VALUE
})
public
List
<
Map
<
String
,
Object
>>
getClosestElementsByCoordinates
(
//
@PathVariable
(
value
=
"projectId"
)
String
projectId
,
//
@PathVariable
(
value
=
"modelId"
)
String
modelId
,
//
@CookieValue
(
value
=
Configuration
.
AUTH_TOKEN
)
String
token
,
//
@RequestParam
(
value
=
"coordinates"
,
defaultValue
=
""
)
String
coordinates
,
//
@RequestParam
(
value
=
"query"
,
defaultValue
=
""
)
String
query
,
//
@RequestParam
(
value
=
"count"
,
defaultValue
=
""
)
String
count
,
//
@RequestParam
(
value
=
"type"
,
defaultValue
=
""
)
String
type
,
//
@RequestParam
(
value
=
"perfectMatch"
,
defaultValue
=
"false"
)
String
perfectMatch
//
)
throws
QueryException
,
SecurityException
{
if
(!
coordinates
.
trim
().
isEmpty
())
{
if
(
modelId
.
equals
(
"*"
))
{
throw
new
QueryException
(
"modelId must be defined when searching by coordinates"
);
}
if
(
count
.
trim
().
isEmpty
())
{
count
=
"5"
;
}
String
[]
tmp
=
coordinates
.
split
(
","
);
if
(
tmp
.
length
!=
2
)
{
throw
new
QueryException
(
"Coordinates must be in the format: 'xxx.xx,yyy.yy'"
);
}
Double
x
=
null
;
Double
y
=
null
;
try
{
x
=
Double
.
valueOf
(
tmp
[
0
]);
y
=
Double
.
valueOf
(
tmp
[
1
]);
}
catch
(
NumberFormatException
e
)
{
throw
new
QueryException
(
"Coordinates must be in the format: 'xxx.xx,yyy.yy'"
,
e
);
}
Point2D
pointCoordinates
=
new
Point2D
.
Double
(
x
,
y
);
return
bioEntitiesRestImpl
.
getClosestElementsByCoordinates
(
projectId
,
modelId
,
token
,
pointCoordinates
,
Integer
.
valueOf
(
count
),
perfectMatch
,
type
);
}
else
if
(!
query
.
trim
().
isEmpty
())
{
if
(
count
.
trim
().
isEmpty
())
{
count
=
"100"
;
}
return
bioEntitiesRestImpl
.
getElementsByQuery
(
projectId
,
token
,
modelId
,
query
,
Integer
.
valueOf
(
count
),
perfectMatch
);
}
else
{
return
new
ArrayList
<>();
}
}
@RequestMapping
(
value
=
"/projects/{projectId}/models/{modelId}/bioEntities/suggestedQueryList"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
POST
},
produces
=
{
MediaType
.
APPLICATION_JSON_VALUE
})
public
String
[]
getSuggestedQueryList
(
//
@PathVariable
(
value
=
"projectId"
)
String
projectId
,
//
@CookieValue
(
value
=
Configuration
.
AUTH_TOKEN
)
String
token
//
)
throws
SecurityException
{
return
bioEntitiesRestImpl
.
getSuggestedQueryList
(
projectId
,
token
);
}
@RequestMapping
(
value
=
"/projects/{projectId}/models/{modelId}/bioEntities/suggestedQueryList"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
POST
},
produces
=
{
MediaType
.
APPLICATION_JSON_VALUE
})
public
String
[]
getSuggestedQueryList
(
//
@PathVariable
(
value
=
"projectId"
)
String
projectId
,
//
@CookieValue
(
value
=
Configuration
.
AUTH_TOKEN
)
String
token
//
)
throws
SecurityException
{
return
bioEntitiesRestImpl
.
getSuggestedQueryList
(
projectId
,
token
);
}
}
\ No newline at end of file
rest-api/src/main/java/lcsb/mapviewer/api/projects/models/bioEntities/BioEntitiesRestImpl.java
View file @
bf097211
...
...
@@ -2,8 +2,10 @@ package lcsb.mapviewer.api.projects.models.bioEntities;
import
java.awt.geom.Point2D
;
import
java.util.ArrayList
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
org.apache.log4j.Logger
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -31,15 +33,22 @@ public class BioEntitiesRestImpl extends BaseRestImpl {
private
ISearchService
searchService
;
public
List
<
Map
<
String
,
Object
>>
getClosestElementsByCoordinates
(
String
projectId
,
String
modelId
,
String
token
,
Point2D
coordinates
,
Integer
count
,
String
perfectMatch
)
throws
UserAccessException
,
SecurityException
{
Point2D
coordinates
,
Integer
count
,
String
perfectMatch
,
String
type
)
throws
UserAccessException
,
SecurityException
{
List
<
Map
<
String
,
Object
>>
resultMap
=
new
ArrayList
<>();
Model
model
=
getModelService
().
getLastModelByProjectId
(
projectId
,
token
);
Model
submodel
=
model
.
getSubmodelById
(
modelId
);
Set
<
String
>
types
=
new
HashSet
<>();
if
(!
type
.
isEmpty
())
{
for
(
String
str
:
type
.
split
(
","
))
{
types
.
add
(
str
.
toLowerCase
());
}
}
List
<
BioEntity
>
elements
=
searchService
.
getClosestElements
(
submodel
,
coordinates
,
count
,
perfectMatch
.
equalsIgnoreCase
(
"true"
));
perfectMatch
.
equalsIgnoreCase
(
"true"
)
,
types
);
for
(
BioEntity
object
:
elements
)
{
Map
<
String
,
Object
>
result
=
createMinifiedSearchResult
(
object
);
resultMap
.
add
(
result
);
...
...
rest-api/src/test/java/lcsb/mapviewer/api/projects/models/bioEntities/BioEntitiesControllerTest.java
View file @
bf097211
...
...
@@ -6,6 +6,7 @@ import static org.mockito.Matchers.any;
import
static
org
.
mockito
.
Matchers
.
anyString
;
import
java.awt.geom.Point2D
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -49,7 +50,7 @@ public class BioEntitiesControllerTest extends RestTestFunctions {
BioEntitiesRestImpl
projectRest
=
createMockProjectRest
(
"testFiles/model/sample.xml"
);
int
count
=
3
;
List
<
Map
<
String
,
Object
>>
result
=
projectRest
.
getClosestElementsByCoordinates
(
"sample"
,
"0"
,
token
,
new
Point2D
.
Double
(
1
,
2
),
count
,
"false"
);
new
Point2D
.
Double
(
1
,
2
),
count
,
"false"
,
""
);
assertEquals
(
count
,
result
.
size
());
String
json
=
mapper
.
writeValueAsString
(
result
);
...
...
service/src/main/java/lcsb/mapviewer/services/impl/SearchService.java
View file @
bf097211
...
...
@@ -3,6 +3,7 @@ package lcsb.mapviewer.services.impl;
import
java.awt.geom.Point2D
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.HashSet
;
...
...
@@ -44,10 +45,6 @@ import lcsb.mapviewer.model.map.statistics.SearchType;
import
lcsb.mapviewer.persist.dao.map.ModelDao
;
import
lcsb.mapviewer.services.interfaces.ISearchHistoryService
;
import
lcsb.mapviewer.services.interfaces.ISearchService
;
import
lcsb.mapviewer.services.search.data.FullAliasView
;
import
lcsb.mapviewer.services.search.data.FullAliasViewFactory
;
import
lcsb.mapviewer.services.search.data.FullReactionView
;
import
lcsb.mapviewer.services.search.data.FullReactionViewFactory
;
import
lcsb.mapviewer.services.search.data.SearchElementResult
;
import
lcsb.mapviewer.services.utils.SearchIndexer
;
...
...
@@ -567,7 +564,8 @@ public class SearchService implements ISearchService {
}
@Override
public
List
<
BioEntity
>
getClosestElements
(
Model
model
,
Point2D
point
,
int
numberOfElements
,
boolean
perfectHit
)
{
public
List
<
BioEntity
>
getClosestElements
(
Model
model
,
Point2D
point
,
int
numberOfElements
,
boolean
perfectHit
,
Collection
<
String
>
types
)
{
List
<
BioEntity
>
result
=
new
ArrayList
<>();
// probably this could be improved algorithmitically, right now all objects
...
...
@@ -575,11 +573,13 @@ public class SearchService implements ISearchService {
// of results
List
<
DistanceToObject
>
tmpList
=
new
ArrayList
<>();
for
(
Reaction
reaction
:
model
.
getReactions
())
{
tmpList
.
add
(
new
DistanceToObject
(
reaction
,
point
));
if
(
types
.
size
()
==
0
||
types
.
contains
(
reaction
.
getStringType
().
toLowerCase
()))
{
tmpList
.
add
(
new
DistanceToObject
(
reaction
,
point
));
}
}
for
(
Element
alias
:
model
.
getElements
())
{
if
(
alias
instanceof
Species
)
{
tmpList
.
add
(
new
DistanceToObject
(
alias
,
point
));
for
(
Element
element
:
model
.
getElements
())
{
if
(
(
element
instanceof
Species
&&
types
.
size
()
==
0
)
||
types
.
contains
(
element
.
getStringType
().
toLowerCase
())
)
{
tmpList
.
add
(
new
DistanceToObject
(
element
,
point
));
}
}
Collections
.
sort
(
tmpList
);
...
...
service/src/main/java/lcsb/mapviewer/services/interfaces/ISearchService.java
View file @
bf097211
package
lcsb.mapviewer.services.interfaces
;
import
java.awt.geom.Point2D
;
import
java.util.Collection
;
import
java.util.List
;
import
org.apache.log4j.Logger
;
...
...
@@ -296,7 +297,7 @@ public interface ISearchService {
* how many closest elements should be returned
* @return list of the closest elements
*/
List
<
BioEntity
>
getClosestElements
(
Model
model
,
Point2D
point
,
int
numberOfElements
,
boolean
perfectHit
);
List
<
BioEntity
>
getClosestElements
(
Model
model
,
Point2D
point
,
int
numberOfElements
,
boolean
perfectHit
,
Collection
<
String
>
types
);
/**
* Returns list of autocomplete strings for the partial query.
...
...
service/src/test/java/lcsb/mapviewer/services/impl/SearchServiceTest.java
View file @
bf097211
...
...
@@ -6,6 +6,7 @@ import static org.junit.Assert.assertNull;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
java.awt.geom.Point2D
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.List
;
...
...
@@ -287,7 +288,7 @@ public class SearchServiceTest extends ServiceTestFunctions {
public
void
testSearchClosest
()
throws
Exception
{
try
{
Model
model
=
getModelForFile
(
"testFiles/graph_path_example3.xml"
,
true
);
List
<
BioEntity
>
elements
=
searchService
.
getClosestElements
(
model
,
new
Point2D
.
Double
(
0
,
0
),
5
,
false
);
List
<
BioEntity
>
elements
=
searchService
.
getClosestElements
(
model
,
new
Point2D
.
Double
(
0
,
0
),
5
,
false
,
new
ArrayList
<>()
);
assertNotNull
(
elements
);
assertEquals
(
5
,
elements
.
size
());
assertTrue
(
elements
.
get
(
0
)
instanceof
Species
);
...
...
@@ -335,7 +336,7 @@ public class SearchServiceTest extends ServiceTestFunctions {
protein3
.
setY
(
0
);
model
.
addElement
(
protein3
);
List
<
BioEntity
>
elements
=
searchService
.
getClosestElements
(
model
,
new
Point2D
.
Double
(
10
,
10
),
5
,
false
);
List
<
BioEntity
>
elements
=
searchService
.
getClosestElements
(
model
,
new
Point2D
.
Double
(
10
,
10
),
5
,
false
,
new
ArrayList
<>()
);
assertNotNull
(
elements
);
assertEquals
(
3
,
elements
.
size
());
BioEntity
sAlias
=
elements
.
get
(
0
);
...
...
@@ -355,7 +356,7 @@ public class SearchServiceTest extends ServiceTestFunctions {
public
void
testSearchClosestWithEmptyModel
()
throws
Exception
{
try
{
Model
model
=
new
ModelFullIndexed
(
null
);
List
<
BioEntity
>
elements
=
searchService
.
getClosestElements
(
model
,
new
Point2D
.
Double
(
0
,
0
),
5
,
false
);
List
<
BioEntity
>
elements
=
searchService
.
getClosestElements
(
model
,
new
Point2D
.
Double
(
0
,
0
),
5
,
false
,
new
ArrayList
<>()
);
assertNotNull
(
elements
);
assertEquals
(
0
,
elements
.
size
());
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment