Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Devrim Gunyel
core
Commits
7cc29f33
Commit
7cc29f33
authored
Mar 06, 2019
by
Piotr Gawron
Browse files
fetching information about publication with invalid (non numeric) pubmed id triggered exception
parent
97bbfb8d
Changes
3
Hide whitespace changes
Inline
Side-by-side
CHANGELOG
View file @
7cc29f33
minerva
(
12.2.0
~
beta
.3
)
unstable
;
urgency
=
medium
*
Bug
fix
:
Icons
are
still
not
properly
loaded
on
Safari
(#
661
)
*
Bug
fix
:
fetching
information
about
publication
with
invalid
(
non
numeric
)
pubmed
id
triggered
exception
(#
737
)
--
Piotr
Gawron
<
piotr
.
gawron
@
uni
.
lu
>
Wed
,
6
Mar
2019
17
:
00
:
00
+
0200
minerva
(
12.2.0
~
beta
.2
)
unstable
;
urgency
=
medium
*
Bug
fix
:
order
of
the
overlays
is
defined
explicitly
also
for
general
...
...
rest-api/src/main/java/lcsb/mapviewer/api/projects/models/publications/PublicationsRestImpl.java
View file @
7cc29f33
...
...
@@ -11,6 +11,7 @@ import java.util.Set;
import
java.util.SortedMap
;
import
java.util.TreeMap
;
import
org.apache.commons.lang3.math.NumberUtils
;
import
org.apache.log4j.Logger
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
...
...
@@ -21,6 +22,7 @@ import lcsb.mapviewer.annotation.services.PubmedParser;
import
lcsb.mapviewer.annotation.services.PubmedSearchException
;
import
lcsb.mapviewer.api.BaseRestImpl
;
import
lcsb.mapviewer.api.QueryException
;
import
lcsb.mapviewer.common.comparator.IntegerComparator
;
import
lcsb.mapviewer.common.exception.InvalidArgumentException
;
import
lcsb.mapviewer.model.map.BioEntity
;
import
lcsb.mapviewer.model.map.MiriamData
;
...
...
@@ -89,7 +91,7 @@ public class PublicationsRestImpl extends BaseRestImpl {
this
.
searchService
=
searchService
;
}
private
enum
SortColumn
{
enum
SortColumn
{
PUBMED_ID
(
"pubmedId"
),
YEAR
(
"year"
),
JOURNAL
(
"journal"
),
...
...
@@ -122,8 +124,8 @@ public class PublicationsRestImpl extends BaseRestImpl {
List
<
Map
.
Entry
<
MiriamData
,
List
<
BioEntity
>>>
filteredList
=
new
ArrayList
<>();
for
(
Map
.
Entry
<
MiriamData
,
List
<
BioEntity
>>
entry
:
publications
.
entrySet
())
{
Set
<
Model
>
publicationModels
=
new
HashSet
<>();
for
(
BioEntity
bioEntity:
entry
.
getValue
())
{
Set
<
Model
>
publicationModels
=
new
HashSet
<>();
for
(
BioEntity
bioEntity
:
entry
.
getValue
())
{
publicationModels
.
add
(
bioEntity
.
getModel
());
}
if
(
isSearchResult
(
entry
.
getKey
(),
search
,
publicationModels
))
{
...
...
@@ -159,7 +161,7 @@ public class PublicationsRestImpl extends BaseRestImpl {
return
result
;
}
private
Comparator
<
Entry
<
MiriamData
,
List
<
BioEntity
>>>
getComparatorForColumn
(
SortColumn
sortColumnEnum
,
Comparator
<
Entry
<
MiriamData
,
List
<
BioEntity
>>>
getComparatorForColumn
(
SortColumn
sortColumnEnum
,
String
sortOrder
)
{
final
int
orderFactor
;
if
(
sortOrder
.
toLowerCase
().
equals
(
"desc"
))
{
...
...
@@ -171,13 +173,16 @@ public class PublicationsRestImpl extends BaseRestImpl {
return
null
;
}
else
if
(
sortColumnEnum
.
equals
(
SortColumn
.
PUBMED_ID
))
{
return
new
Comparator
<
Map
.
Entry
<
MiriamData
,
List
<
BioEntity
>>>()
{
IntegerComparator
integerComparator
=
new
IntegerComparator
();
@Override
public
int
compare
(
Entry
<
MiriamData
,
List
<
BioEntity
>>
o1
,
Entry
<
MiriamData
,
List
<
BioEntity
>>
o2
)
{
Integer
id1
=
Integer
.
valueOf
(
o1
.
getKey
().
getResource
());
Integer
id2
=
Integer
.
valueOf
(
o2
.
getKey
().
getResource
());
return
i
d1
.
compare
To
(
id2
)
*
orderFactor
;
Integer
id1
=
extractPubmedId
(
o1
.
getKey
());
Integer
id2
=
extractPubmedId
(
o2
.
getKey
());
return
i
ntegerComparator
.
compare
(
id1
,
id2
)
*
orderFactor
;
}
};
}
else
if
(
sortColumnEnum
.
equals
(
SortColumn
.
YEAR
))
{
return
new
Comparator
<
Map
.
Entry
<
MiriamData
,
List
<
BioEntity
>>>()
{
...
...
@@ -310,4 +315,13 @@ public class PublicationsRestImpl extends BaseRestImpl {
return
pubmedParser
.
getPubmedArticleById
(
Integer
.
valueOf
(
resource
));
}
private
Integer
extractPubmedId
(
MiriamData
md
)
{
if
(
NumberUtils
.
isDigits
(
md
.
getResource
()))
{
return
Integer
.
valueOf
(
md
.
getResource
());
}
else
{
return
null
;
}
}
}
rest-api/src/test/java/lcsb/mapviewer/api/projects/models/publications/PublicationsRestImplTest.java
View file @
7cc29f33
package
lcsb.mapviewer.api.projects.models.publications
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
junit
.
Assert
.
fail
;
import
static
org
.
mockito
.
Matchers
.
any
;
import
static
org
.
mockito
.
Matchers
.
anyString
;
import
static
org
.
mockito
.
Argument
Matchers
.
any
;
import
static
org
.
mockito
.
Argument
Matchers
.
anyString
;
import
java.util.ArrayList
;
import
java.util.Comparator
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.TreeMap
;
import
java.util.Map.Entry
;
import
org.apache.log4j.Logger
;
import
org.junit.After
;
...
...
@@ -19,6 +24,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import
lcsb.mapviewer.api.QueryException
;
import
lcsb.mapviewer.api.RestTestFunctions
;
import
lcsb.mapviewer.api.projects.models.publications.PublicationsRestImpl.SortColumn
;
import
lcsb.mapviewer.model.map.BioEntity
;
import
lcsb.mapviewer.model.map.MiriamData
;
import
lcsb.mapviewer.model.map.MiriamType
;
import
lcsb.mapviewer.model.map.model.Model
;
import
lcsb.mapviewer.services.interfaces.IModelService
;
...
...
@@ -124,4 +133,48 @@ public class PublicationsRestImplTest extends RestTestFunctions {
return
_projectRestImpl
;
}
@Test
public
void
testComparatorForColumnWithInvalidData
()
{
Entry
<
MiriamData
,
List
<
BioEntity
>>
valid
=
new
Entry
<
MiriamData
,
List
<
BioEntity
>>()
{
@Override
public
List
<
BioEntity
>
setValue
(
List
<
BioEntity
>
value
)
{
return
null
;
}
@Override
public
List
<
BioEntity
>
getValue
()
{
return
new
ArrayList
<>();
}
@Override
public
MiriamData
getKey
()
{
return
new
MiriamData
(
MiriamType
.
PUBMED
,
"12345"
);
}
};
Entry
<
MiriamData
,
List
<
BioEntity
>>
invalid
=
new
Entry
<
MiriamData
,
List
<
BioEntity
>>()
{
@Override
public
List
<
BioEntity
>
setValue
(
List
<
BioEntity
>
value
)
{
return
null
;
}
@Override
public
List
<
BioEntity
>
getValue
()
{
return
new
ArrayList
<>();
}
@Override
public
MiriamData
getKey
()
{
return
new
MiriamData
(
MiriamType
.
PUBMED
,
""
);
}
};
for
(
SortColumn
sortColumn
:
SortColumn
.
values
())
{
Comparator
<
Entry
<
MiriamData
,
List
<
BioEntity
>>>
comparator
=
_projectRestImpl
.
getComparatorForColumn
(
sortColumn
,
"desc"
);
assertNotNull
(
comparator
.
compare
(
valid
,
invalid
));
}
}
}
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