Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Genesys Backend
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
13
Issues
13
List
Boards
Labels
Service Desk
Milestones
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Genesys PGR
Genesys Backend
Commits
47a282b5
Commit
47a282b5
authored
Dec 29, 2014
by
Matija Obreza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Accession#storage (MCPD)
parent
4220f74d
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
329 additions
and
21 deletions
+329
-21
src/main/java/org/genesys2/server/model/genesys/Accession.java
...ain/java/org/genesys2/server/model/genesys/Accession.java
+31
-0
src/main/java/org/genesys2/server/service/impl/DownloadServiceImpl.java
...org/genesys2/server/service/impl/DownloadServiceImpl.java
+1
-15
src/main/java/org/genesys2/util/MCPDUtil.java
src/main/java/org/genesys2/util/MCPDUtil.java
+39
-0
src/test/java/org/genesys2/server/model/impl/AccessionStorageTest.java
.../org/genesys2/server/model/impl/AccessionStorageTest.java
+169
-0
src/test/java/org/genesys2/server/test/BatchRESTServiceTest.java
...t/java/org/genesys2/server/test/BatchRESTServiceTest.java
+81
-4
src/test/java/org/genesys2/server/test/JpaDataConfig.java
src/test/java/org/genesys2/server/test/JpaDataConfig.java
+8
-2
No files found.
src/main/java/org/genesys2/server/model/genesys/Accession.java
View file @
47a282b5
...
...
@@ -28,11 +28,14 @@ import javax.persistence.FetchType;
import
javax.persistence.JoinColumn
;
import
javax.persistence.ManyToOne
;
import
javax.persistence.OrderBy
;
import
javax.persistence.PrePersist
;
import
javax.persistence.PreUpdate
;
import
javax.persistence.Table
;
import
org.genesys2.server.model.VersionedAuditedModel
;
import
org.genesys2.server.model.impl.Country
;
import
org.genesys2.server.model.impl.FaoInstitute
;
import
org.genesys2.util.MCPDUtil
;
@Entity
@Table
(
name
=
"accession"
)
...
...
@@ -106,9 +109,21 @@ public class Accession extends VersionedAuditedModel {
@OrderBy
(
"storage"
)
private
List
<
Integer
>
stoRage
=
new
ArrayList
<
Integer
>();
@Column
(
name
=
"storage"
,
length
=
50
,
nullable
=
true
)
private
String
storage
;
public
Accession
()
{
}
/**
* Update MCPD {@link #storage}
*/
@PrePersist
@PreUpdate
private
void
prePersist
()
{
this
.
storage
=
MCPDUtil
.
toMcpdArray
(
this
.
stoRage
);
}
public
String
getUuid
()
{
return
uuid
;
}
...
...
@@ -262,6 +277,22 @@ public class Accession extends VersionedAuditedModel {
this
.
stoRage
=
stoRage
;
}
/**
* Returns {@link #getStoRage()} as MCPD string
*
* @return MCPD array string
*/
public
String
getStorage
()
{
return
storage
;
}
/**
* Use {@link #setStoRage(List)} instead.
*/
protected
void
setStorage
(
String
storage
)
{
this
.
storage
=
storage
;
}
@Override
public
String
toString
()
{
return
MessageFormat
.
format
(
"Accession id={0,number,#} A={3} inst={1} genus={2}"
,
id
,
instituteCode
,
taxGenus
,
accessionName
);
...
...
src/main/java/org/genesys2/server/service/impl/DownloadServiceImpl.java
View file @
47a282b5
...
...
@@ -230,7 +230,7 @@ public class DownloadServiceImpl implements DownloadService {
}
createCell
(
row
,
33
,
accession
.
getDuplSite
());
createCell
(
row
,
35
,
toMcpdArray
(
accession
.
getStoRage
()
));
createCell
(
row
,
35
,
accession
.
getStorage
(
));
createCell
(
row
,
36
,
accession
.
getMlsStatus
());
if
(
names
!=
null
&&
names
.
size
()
>
0
)
{
...
...
@@ -321,18 +321,4 @@ public class DownloadServiceImpl implements DownloadService {
return
name
;
return
otherNames
+
";"
+
name
;
}
public
static
String
toMcpdArray
(
List
<
Integer
>
integers
)
{
if
(
integers
==
null
||
integers
.
size
()
==
0
)
return
null
;
String
s
=
""
;
for
(
Integer
i
:
integers
)
{
if
(
i
==
null
)
continue
;
if
(
s
.
length
()
>
0
)
s
+=
";"
;
s
+=
i
;
}
return
s
;
}
}
src/main/java/org/genesys2/util/MCPDUtil.java
0 → 100644
View file @
47a282b5
/**
* Copyright 2014 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package
org.genesys2.util
;
import
java.util.List
;
import
org.apache.commons.lang.StringUtils
;
public
class
MCPDUtil
{
public
static
String
toMcpdArray
(
List
<
Integer
>
integers
)
{
if
(
integers
==
null
||
integers
.
size
()
==
0
)
return
null
;
String
s
=
""
;
for
(
Integer
i
:
integers
)
{
if
(
i
==
null
)
continue
;
if
(
s
.
length
()
>
0
)
s
+=
";"
;
s
+=
i
;
}
return
StringUtils
.
defaultIfBlank
(
s
,
null
);
}
}
src/test/java/org/genesys2/server/model/impl/AccessionStorageTest.java
0 → 100644
View file @
47a282b5
/**
* Copyright 2014 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package
org.genesys2.server.model.impl
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
hamcrest
.
Matchers
.
nullValue
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.genesys2.server.model.genesys.Accession
;
import
org.genesys2.server.service.GenesysService
;
import
org.genesys2.server.test.BatchRESTServiceTest
;
import
org.genesys2.server.test.PropertyPlacholderInitializer
;
import
org.genesys2.util.MCPDUtil
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.test.context.ActiveProfiles
;
import
org.springframework.test.context.ContextConfiguration
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@ContextConfiguration
(
classes
=
BatchRESTServiceTest
.
Config
.
class
,
initializers
=
PropertyPlacholderInitializer
.
class
)
@ActiveProfiles
(
"dev"
)
public
class
AccessionStorageTest
{
@Autowired
private
GenesysService
genesysService
;
@Test
public
void
nullStorage
()
{
Accession
a
=
new
Accession
();
a
.
setInstituteCode
(
"INS000"
);
a
.
setAccessionName
(
"A-1"
);
genesysService
.
saveAccession
(
a
);
}
@Test
public
void
blankStorage
()
{
Accession
a
=
new
Accession
();
a
.
setInstituteCode
(
"INS000"
);
a
.
setAccessionName
(
"A-"
+
System
.
currentTimeMillis
());
List
<
Integer
>
stoRage
=
new
ArrayList
<
Integer
>();
a
.
setStoRage
(
stoRage
);
genesysService
.
saveAccession
(
a
);
Long
accessionId
=
a
.
getId
();
Accession
b
=
genesysService
.
getAccession
(
accessionId
);
assertTrue
(
b
.
getStorage
()
==
null
);
assertTrue
(
b
.
getStoRage
()
!=
null
);
assertThat
(
"Accession#stoRage size is not 0"
,
b
.
getStoRage
().
size
(),
is
(
0
));
}
@Test
public
void
oneStorage
()
{
Accession
a
=
new
Accession
();
a
.
setInstituteCode
(
"INS000"
);
a
.
setAccessionName
(
"A-"
+
System
.
currentTimeMillis
());
List
<
Integer
>
stoRage
=
new
ArrayList
<
Integer
>();
stoRage
.
add
(
1
);
a
.
setStoRage
(
stoRage
);
genesysService
.
saveAccession
(
a
);
Long
accessionId
=
a
.
getId
();
Accession
b
=
genesysService
.
getAccession
(
accessionId
);
assertTrue
(
b
.
getStorage
()
!=
null
);
assertThat
(
"Storage value should be '1'"
,
a
.
getStorage
(),
is
(
"1"
));
assertTrue
(
b
.
getStoRage
()
!=
null
);
}
@Test
public
void
twoStorage
()
{
Accession
a
=
new
Accession
();
a
.
setInstituteCode
(
"INS000"
);
a
.
setAccessionName
(
"A-"
+
System
.
currentTimeMillis
());
List
<
Integer
>
stoRage
=
new
ArrayList
<
Integer
>();
stoRage
.
add
(
1
);
stoRage
.
add
(
2
);
a
.
setStoRage
(
stoRage
);
genesysService
.
saveAccession
(
a
);
Long
accessionId
=
a
.
getId
();
Accession
b
=
genesysService
.
getAccession
(
accessionId
);
assertTrue
(
b
.
getStorage
()
!=
null
);
assertThat
(
"Storage value should be '1'"
,
a
.
getStorage
(),
is
(
"1;2"
));
assertTrue
(
b
.
getStoRage
()
!=
null
);
}
@Test
public
void
clearStorage
()
{
Accession
a
=
new
Accession
();
a
.
setInstituteCode
(
"INS000"
);
a
.
setAccessionName
(
"A-"
+
System
.
currentTimeMillis
());
List
<
Integer
>
stoRage
=
new
ArrayList
<
Integer
>();
stoRage
.
add
(
1
);
stoRage
.
add
(
2
);
a
.
setStoRage
(
stoRage
);
genesysService
.
saveAccession
(
a
);
Long
accessionId
=
a
.
getId
();
assertNotNull
(
"Accession#id must not be null"
,
a
.
getId
());
Accession
b
=
genesysService
.
getAccession
(
accessionId
);
assertTrue
(
b
.
getStorage
()
!=
null
);
assertThat
(
"Storage value should be '1'"
,
a
.
getStorage
(),
is
(
"1;2"
));
assertTrue
(
b
.
getStoRage
()
!=
null
);
b
.
getStoRage
().
clear
();
genesysService
.
saveAccession
(
b
);
Accession
c
=
genesysService
.
getAccession
(
accessionId
);
assertNotNull
(
"Accession#stoRage must not be null"
,
c
.
getStoRage
());
assertThat
(
"Accession#stoRage size is not 0"
,
c
.
getStoRage
().
size
(),
is
(
0
));
assertThat
(
"Accession#storage is not null"
,
c
.
getStorage
(),
is
(
nullValue
()));
}
@Test
public
void
updateStorage
()
{
Accession
a
=
new
Accession
();
a
.
setInstituteCode
(
"INS000"
);
a
.
setAccessionName
(
"A-"
+
System
.
currentTimeMillis
());
List
<
Integer
>
stoRage
=
new
ArrayList
<
Integer
>();
stoRage
.
add
(
1
);
stoRage
.
add
(
2
);
stoRage
.
add
(
3
);
a
.
setStoRage
(
stoRage
);
System
.
out
.
println
(
"Saving 1"
);
genesysService
.
saveAccession
(
a
);
System
.
out
.
println
(
"Saving 2"
);
genesysService
.
saveAccession
(
a
);
Long
accessionId
=
a
.
getId
();
assertNotNull
(
"Accession#id must not be null"
,
a
.
getId
());
Accession
b
=
genesysService
.
getAccession
(
accessionId
);
assertNotNull
(
b
.
getStorage
());
assertNotNull
(
b
.
getStoRage
());
assertThat
(
"StoRage length is not 3"
,
a
.
getStoRage
().
size
(),
is
(
3
));
assertThat
(
"Storage value should be '1;2;3'"
,
a
.
getStorage
(),
is
(
"1;2;3"
));
b
.
getStoRage
().
remove
(
0
);
genesysService
.
saveAccession
(
b
);
Accession
c
=
genesysService
.
getAccession
(
accessionId
);
assertNotNull
(
"Accession#stoRage must not be null"
,
c
.
getStoRage
());
assertThat
(
"Accession#stoRage size is not 2"
,
c
.
getStoRage
().
size
(),
is
(
2
));
assertThat
(
"Accession#storage is not '2;3'"
,
c
.
getStorage
(),
is
(
"2;3"
));
assertThat
(
"Accession#stoRage does not generate MCPD style string'"
,
c
.
getStorage
(),
is
(
MCPDUtil
.
toMcpdArray
(
c
.
getStoRage
())));
System
.
out
.
println
(
"Saving 3"
);
genesysService
.
saveAccession
(
c
);
}
}
src/test/java/org/genesys2/server/test/BatchRESTServiceTest.java
View file @
47a282b5
...
...
@@ -16,9 +16,8 @@
package
org.genesys2.server.test
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
junit
.
Assert
.
fail
;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
hamcrest
.
Matchers
.*;
import
java.io.IOException
;
import
java.util.ArrayList
;
...
...
@@ -37,6 +36,7 @@ import org.genesys2.server.persistence.domain.CountryRepository;
import
org.genesys2.server.service.AclService
;
import
org.genesys2.server.service.BatchRESTService
;
import
org.genesys2.server.service.ContentService
;
import
org.genesys2.server.service.CropService
;
import
org.genesys2.server.service.GenesysService
;
import
org.genesys2.server.service.GeoService
;
import
org.genesys2.server.service.HtmlSanitizer
;
...
...
@@ -47,6 +47,7 @@ import org.genesys2.server.service.UserService;
import
org.genesys2.server.service.impl.AclServiceImpl
;
import
org.genesys2.server.service.impl.BatchRESTServiceImpl
;
import
org.genesys2.server.service.impl.ContentServiceImpl
;
import
org.genesys2.server.service.impl.CropServiceImpl
;
import
org.genesys2.server.service.impl.GenesysServiceImpl
;
import
org.genesys2.server.service.impl.GeoServiceImpl
;
import
org.genesys2.server.service.impl.InstituteServiceImpl
;
...
...
@@ -57,6 +58,7 @@ import org.genesys2.server.service.impl.RESTApiException;
import
org.genesys2.server.service.impl.TaxonomyServiceImpl
;
import
org.genesys2.server.service.impl.UserServiceImpl
;
import
org.genesys2.server.servlet.controller.rest.model.AccessionHeaderJson
;
import
org.genesys2.spring.config.HazelcastConfig
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Test
;
...
...
@@ -68,6 +70,7 @@ import org.springframework.context.annotation.Bean;
import
org.springframework.context.annotation.ComponentScan
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.data.domain.PageRequest
;
import
org.springframework.test.context.ActiveProfiles
;
import
org.springframework.test.context.ContextConfiguration
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.ui.velocity.VelocityEngineFactoryBean
;
...
...
@@ -76,11 +79,12 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@ActiveProfiles
(
"dev"
)
@ContextConfiguration
(
classes
=
BatchRESTServiceTest
.
Config
.
class
,
initializers
=
PropertyPlacholderInitializer
.
class
)
public
class
BatchRESTServiceTest
{
private
final
ObjectMapper
mapper
=
new
ObjectMapper
();
@Import
(
JpaDataConfig
.
class
)
@Import
(
{
JpaDataConfig
.
class
,
HazelcastConfig
.
class
}
)
@ComponentScan
(
basePackages
=
{
"org.genesys2.server.persistence.domain"
})
public
static
class
Config
{
...
...
@@ -109,6 +113,11 @@ public class BatchRESTServiceTest {
return
new
BatchRESTServiceImpl
();
}
@Bean
public
CropService
cropService
()
{
return
new
CropServiceImpl
();
}
@Bean
public
GenesysService
genesysService
()
{
return
new
GenesysServiceImpl
();
...
...
@@ -311,4 +320,72 @@ public class BatchRESTServiceTest {
assertTrue
(
accession
.
getCountryOfOrigin
()
==
null
);
}
@Test
public
void
testUpdateStorage
()
throws
NonUniqueAccessionException
{
final
String
instCode
=
"INS002"
;
final
FaoInstitute
institute
=
instituteService
.
getInstitute
(
instCode
);
assertTrue
(
"institute is null"
,
institute
!=
null
);
System
.
err
.
println
(
institute
);
final
Map
<
AccessionHeaderJson
,
ObjectNode
>
batch
=
new
HashMap
<
AccessionHeaderJson
,
ObjectNode
>();
final
AccessionHeaderJson
dataJson
=
new
AccessionHeaderJson
();
dataJson
.
acceNumb
=
"AC 100"
;
dataJson
.
instCode
=
instCode
;
final
ObjectNode
json
=
mapper
.
createObjectNode
();
json
.
put
(
"genus"
,
"Hordeum"
);
json
.
put
(
"orgCty"
,
"CTY"
);
json
.
put
(
"storage"
,
"10;30"
);
batch
.
put
(
dataJson
,
json
);
System
.
err
.
println
(
json
);
try
{
batchRESTService
.
upsertAccessionData
(
institute
,
batch
);
}
catch
(
final
RESTApiException
e
)
{
fail
(
e
.
getMessage
());
}
Accession
accession
=
genesysService
.
getAccession
(
instCode
,
"AC 100"
);
assertTrue
(
accession
.
getId
()
!=
null
);
assertTrue
(
accession
.
getInstituteCode
().
equals
(
instCode
));
assertTrue
(
accession
.
getInstitute
().
getId
().
equals
(
institute
.
getId
()));
assertTrue
(
accession
.
getOrigin
()
!=
null
);
assertTrue
(
"CTY"
.
equals
(
accession
.
getOrigin
()));
assertTrue
(
accession
.
getCountryOfOrigin
()
!=
null
);
assertTrue
(
"Country"
.
equals
(
accession
.
getCountryOfOrigin
().
getName
()));
assertNotNull
(
"StoRage must be"
,
accession
.
getStoRage
());
assertNotNull
(
"Storage must be"
,
accession
.
getStorage
());
assertThat
(
"Storage must be 10;30"
,
accession
.
getStorage
(),
is
(
"10;30"
));
// Modify STORAGE
json
.
put
(
"storage"
,
"40"
);
System
.
err
.
println
(
json
);
try
{
batchRESTService
.
upsertAccessionData
(
institute
,
batch
);
}
catch
(
final
RESTApiException
e
)
{
fail
(
e
.
getMessage
());
}
// reload
accession
=
genesysService
.
getAccession
(
instCode
,
"AC 100"
);
assertNotNull
(
"storage should not be null"
,
accession
.
getStorage
());
assertThat
(
"stoRage should 40"
,
accession
.
getStorage
(),
is
(
"40"
));
assertThat
(
"stoRage should be 0-size"
,
accession
.
getStoRage
().
size
(),
is
(
1
));
// Clear STORAGE
json
.
putNull
(
"storage"
);
System
.
err
.
println
(
json
);
try
{
batchRESTService
.
upsertAccessionData
(
institute
,
batch
);
}
catch
(
final
RESTApiException
e
)
{
fail
(
e
.
getMessage
());
}
// reload
accession
=
genesysService
.
getAccession
(
instCode
,
"AC 100"
);
assertNull
(
"storage should be null"
,
accession
.
getStorage
());
assertNotNull
(
"stoRage should be null"
,
accession
.
getStoRage
());
assertThat
(
"stoRage should be 0-size"
,
accession
.
getStoRage
().
size
(),
is
(
0
));
}
}
src/test/java/org/genesys2/server/test/JpaDataConfig.java
View file @
47a282b5
...
...
@@ -30,6 +30,7 @@ import org.springframework.context.annotation.PropertySource;
import
org.springframework.core.env.Environment
;
import
org.springframework.dao.support.PersistenceExceptionTranslator
;
import
org.springframework.data.jpa.repository.config.EnableJpaRepositories
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.jdbc.datasource.DriverManagerDataSource
;
import
org.springframework.orm.hibernate4.HibernateExceptionTranslator
;
import
org.springframework.orm.jpa.JpaTransactionManager
;
...
...
@@ -44,7 +45,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
@PropertySource
(
"classpath:/spring/spring.properties"
)
@EnableJpaRepositories
(
basePackages
=
{
"org.genesys2.server.persistence.acl"
,
"org.genesys2.server.persistence.domain"
},
repositoryImplementationPostfix
=
"CustomImpl"
,
entityManagerFactoryRef
=
"entityManagerFactory"
,
transactionManagerRef
=
"transactionManager"
)
@EnableTransactionManagement
@TransactionConfiguration
(
transactionManager
=
"transactionManager"
)
@TransactionConfiguration
(
defaultRollback
=
false
,
transactionManager
=
"transactionManager"
)
public
class
JpaDataConfig
{
@Autowired
private
Environment
env
;
...
...
@@ -61,6 +62,11 @@ public class JpaDataConfig {
return
dataSource
;
}
@Bean
public
JdbcTemplate
jdbcTemplate
(
DataSource
dataSource
)
{
return
new
JdbcTemplate
(
dataSource
);
}
@Bean
(
name
=
"entityManagerFactory"
)
public
LocalContainerEntityManagerFactoryBean
entityManagerFactory
()
throws
Exception
{
final
LocalContainerEntityManagerFactoryBean
bean
=
new
LocalContainerEntityManagerFactoryBean
();
...
...
@@ -93,7 +99,7 @@ public class JpaDataConfig {
public
PersistenceExceptionTranslator
hibernateExceptionTranslator
()
{
return
new
HibernateExceptionTranslator
();
}
private
Properties
jpaProperties
()
throws
Exception
{
Properties
jpaProp
=
new
Properties
();
jpaProp
.
load
(
getClass
().
getResourceAsStream
(
"/spring/hibernate.properties"
));
...
...
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