Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Genesys PGR
Genesys Backend
Commits
e049ca95
Commit
e049ca95
authored
Jan 02, 2015
by
Matija Obreza
Browse files
MCPDUtil#toIntegers, #toStrings
parent
b26d0a06
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/genesys2/server/model/elastic/AccessionDetails.java
View file @
e049ca95
package
org.genesys2.server.model.elastic
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Date
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.regex.Pattern
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.log4j.Logger
;
...
...
@@ -20,6 +18,7 @@ import org.genesys2.server.model.genesys.AccessionRemark;
import
org.genesys2.server.model.genesys.SvalbardData
;
import
org.genesys2.server.model.impl.Crop
;
import
org.genesys2.server.model.impl.Organization
;
import
org.genesys2.util.MCPDUtil
;
import
org.springframework.data.annotation.Id
;
import
org.springframework.data.annotation.Version
;
import
org.springframework.data.elasticsearch.annotations.Document
;
...
...
@@ -31,8 +30,6 @@ import org.springframework.data.elasticsearch.annotations.FieldType;
public
class
AccessionDetails
{
private
static
final
Logger
LOG
=
Logger
.
getLogger
(
AccessionDetails
.
class
);
static
Pattern
mcpdSplit
=
Pattern
.
compile
(
"\\w*;\\w*"
);
@Version
private
Long
version
;
@Id
...
...
@@ -97,13 +94,12 @@ public class AccessionDetails {
ad
.
acqSrc
=
accession
.
getAcquisitionSource
();
ad
.
available
=
accession
.
getAvailability
();
ad
.
orgCty
=
Country
.
from
(
accession
.
getCountryOfOrigin
());
if
(
StringUtils
.
isNotBlank
(
accession
.
getDuplSite
()))
ad
.
duplSite
=
Arrays
.
asList
(
mcpdSplit
.
split
(
accession
.
getDuplSite
()));
ad
.
duplSite
=
MCPDUtil
.
toStrings
(
accession
.
getDuplSite
());
ad
.
institute
=
Institute
.
from
(
accession
.
getInstitute
());
ad
.
mlsStatus
=
accession
.
getMlsStatus
();
ad
.
art15
=
accession
.
getInTrust
();
ad
.
sampStat
=
accession
.
getSampleStatus
();
ad
.
storage
=
accession
.
getSto
R
age
();
ad
.
storage
=
MCPDUtil
.
toIntegers
(
accession
.
getSto
r
age
()
)
;
ad
.
taxonomy
=
Taxonomy
.
from
(
accession
.
getTaxonomy
());
if
(
ad
.
taxonomy
==
null
)
{
...
...
src/main/java/org/genesys2/server/model/elastic/Collect.java
View file @
e049ca95
package
org.genesys2.server.model.elastic
;
import
java.util.Arrays
;
import
java.util.Date
;
import
java.util.HashSet
;
import
java.util.Set
;
import
org.apache.commons.lang.StringUtils
;
import
org.genesys2.server.model.genesys.AccessionCollect
;
import
org.genesys2.util.MCPDUtil
;
import
org.springframework.data.elasticsearch.annotations.Field
;
import
org.springframework.data.elasticsearch.annotations.FieldIndex
;
import
org.springframework.data.elasticsearch.annotations.FieldType
;
...
...
@@ -31,7 +31,7 @@ public class Collect {
Collect
c
=
new
Collect
();
if
(
StringUtils
.
isNotBlank
(
collect
.
getCollCode
()))
c
.
collCode
=
new
HashSet
<
String
>(
Arrays
.
asList
(
AccessionDetails
.
mcpdSplit
.
split
(
collect
.
getCollCode
()))
)
;
c
.
collCode
=
new
HashSet
<
String
>(
MCPDUtil
.
toStrings
(
collect
.
getCollCode
()));
c
.
collDate
=
StringUtils
.
defaultIfBlank
(
collect
.
getCollDate
(),
null
);
c
.
collInstAddr
=
StringUtils
.
defaultIfBlank
(
collect
.
getCollInstAddress
(),
null
);
c
.
collMissId
=
StringUtils
.
defaultIfBlank
(
collect
.
getCollMissId
(),
null
);
...
...
src/main/java/org/genesys2/util/MCPDUtil.java
View file @
e049ca95
...
...
@@ -16,11 +16,15 @@
package
org.genesys2.util
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.regex.Pattern
;
import
org.apache.commons.lang.StringUtils
;
public
class
MCPDUtil
{
static
Pattern
mcpdSplit
=
Pattern
.
compile
(
"\\w*;\\w*"
);
public
static
String
toMcpdArray
(
List
<
Integer
>
integers
)
{
if
(
integers
==
null
||
integers
.
size
()
==
0
)
...
...
@@ -36,4 +40,26 @@ public class MCPDUtil {
return
StringUtils
.
defaultIfBlank
(
s
,
null
);
}
public
static
List
<
Integer
>
toIntegers
(
String
ints
)
{
if
(
StringUtils
.
isBlank
(
ints
))
return
null
;
List
<
Integer
>
is
=
new
ArrayList
<
Integer
>();
for
(
String
i
:
mcpdSplit
.
split
(
ints
))
{
if
(
StringUtils
.
isBlank
(
i
))
continue
;
try
{
is
.
add
(
Integer
.
parseInt
(
i
));
}
catch
(
NumberFormatException
e
)
{
}
}
return
is
;
}
public
static
List
<
String
>
toStrings
(
String
strings
)
{
if
(
StringUtils
.
isBlank
(
strings
))
return
null
;
return
Arrays
.
asList
(
mcpdSplit
.
split
(
strings
));
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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