Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
GGCE
GGCE Server
Commits
d055331c
Commit
d055331c
authored
May 16, 2022
by
Artem Hrybeniuk
Browse files
Merge branch 'filter_updates' into 'main'
Updated InventoryFilter and AccessionFilter See merge request grin-global/grin-global-server!397
parents
a8aef7b7
8911fed5
Changes
6
Hide whitespace changes
Inline
Side-by-side
server/src/main/java/org/gringlobal/service/filter/AccessionFilter.java
View file @
d055331c
...
...
@@ -115,6 +115,15 @@ public class AccessionFilter extends CooperatorOwnedModelFilter<AccessionFilter,
/** The Accession inventory group ids. */
public
Set
<
Long
>
accessionInvGroup
;
/** The Accession actions */
public
AccessionActionFilter
accessionActions
;
/** The Accession inventories */
public
InventoryFilter
inventories
;
/** The AccessionIprs */
public
AccessionIprFilter
accessionIprs
;
/**
* Builds the query.
*
...
...
@@ -204,6 +213,15 @@ public class AccessionFilter extends CooperatorOwnedModelFilter<AccessionFilter,
if
(
accessionInvGroup
!=
null
)
{
predicates
.
add
(
accession
.
inventories
.
any
().
id
.
in
(
getInventoryMembersOfGroups
(
accessionInvGroup
)));
}
if
(
accessionActions
!=
null
)
{
predicates
.
addAll
(
accessionActions
.
collectPredicates
(
accession
.
accessionActions
.
any
()));
}
if
(
inventories
!=
null
)
{
predicates
.
addAll
(
inventories
.
collectPredicates
(
accession
.
inventories
.
any
()));
}
if
(
accessionIprs
!=
null
)
{
predicates
.
addAll
(
accessionIprs
.
collectPredicates
(
accession
.
accessionIprs
.
any
()));
}
return
predicates
;
}
...
...
server/src/main/java/org/gringlobal/service/filter/AccessionInvNameFilter.java
0 → 100644
View file @
d055331c
/*
* Copyright 2022 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.gringlobal.service.filter
;
import
com.querydsl.core.types.Predicate
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.genesys.blocks.model.filters.NumberFilter
;
import
org.genesys.blocks.model.filters.StringFilter
;
import
org.gringlobal.model.AccessionInvName
;
import
org.gringlobal.model.QAccessionInvName
;
import
java.util.List
;
import
java.util.Set
;
/**
* Filters for {@link AccessionInvName}
*/
public
class
AccessionInvNameFilter
extends
CooperatorOwnedModelFilter
<
AccessionInvNameFilter
,
AccessionInvName
>
{
/** The Inventory */
public
InventoryFilter
inventory
;
/** The Category code */
public
Set
<
String
>
categoryCode
;
/** The Plant name */
public
StringFilter
plantName
;
/** The Plant name rank */
public
NumberFilter
<
Integer
>
plantNameRank
;
/** is web visible */
public
Boolean
webVisible
;
/** The Name group */
public
NameGroupFilter
nameGroup
;
@Override
public
List
<
Predicate
>
collectPredicates
()
{
return
null
;
}
public
List
<
Predicate
>
collectPredicates
(
QAccessionInvName
accessionInvName
)
{
final
List
<
Predicate
>
predicates
=
super
.
collectPredicates
(
accessionInvName
,
accessionInvName
.
_super
);
if
(
inventory
!=
null
)
{
predicates
.
addAll
(
inventory
.
collectPredicates
(
accessionInvName
.
inventory
));
}
if
(
CollectionUtils
.
isNotEmpty
(
categoryCode
))
{
predicates
.
add
(
accessionInvName
.
categoryCode
.
in
(
categoryCode
));
}
if
(
plantName
!=
null
)
{
predicates
.
add
(
plantName
.
buildQuery
(
accessionInvName
.
plantName
));
}
if
(
plantNameRank
!=
null
)
{
predicates
.
add
(
plantNameRank
.
buildQuery
(
accessionInvName
.
plantNameRank
));
}
if
(
webVisible
!=
null
)
{
predicates
.
add
(
accessionInvName
.
isWebVisible
.
eq
(
convertToString
(
webVisible
)));
}
if
(
nameGroup
!=
null
)
{
predicates
.
addAll
(
nameGroup
.
collectPredicates
(
accessionInvName
.
nameGroup
));
}
return
predicates
;
}
}
server/src/main/java/org/gringlobal/service/filter/AccessionIprFilter.java
0 → 100644
View file @
d055331c
/*
* Copyright 2022 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.gringlobal.service.filter
;
import
com.querydsl.core.types.Predicate
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.genesys.blocks.model.filters.DateFilter
;
import
org.genesys.blocks.model.filters.StringFilter
;
import
org.gringlobal.model.AccessionIpr
;
import
org.gringlobal.model.QAccessionIpr
;
import
java.util.List
;
import
java.util.Set
;
/**
* Filters for {@link AccessionIpr}
*/
public
class
AccessionIprFilter
extends
CooperatorOwnedModelFilter
<
AccessionIprFilter
,
AccessionIpr
>
{
private
static
final
long
serialVersionUID
=
8821111992670890751L
;
/** The accepted date. */
public
DateFilter
acceptedDate
;
/** The accession. */
public
AccessionFilter
accession
;
/** The expected date. */
public
DateFilter
expectedDate
;
/** The expired date. */
public
DateFilter
expiredDate
;
/** The ipr crop name. */
public
StringFilter
iprCropName
;
/** The ipr full name. */
public
StringFilter
iprFullName
;
/** The ipr full name. */
public
StringFilter
iprNumber
;
/** The issued date. */
public
DateFilter
issuedDate
;
/** The type code. */
public
Set
<
String
>
typeCode
;
@Override
public
List
<
Predicate
>
collectPredicates
()
{
return
collectPredicates
(
QAccessionIpr
.
accessionIpr
);
}
public
List
<
Predicate
>
collectPredicates
(
QAccessionIpr
accessionIpr
)
{
final
List
<
Predicate
>
predicates
=
super
.
collectPredicates
(
accessionIpr
,
accessionIpr
.
_super
);
if
(
acceptedDate
!=
null
)
{
predicates
.
add
(
acceptedDate
.
buildQuery
(
accessionIpr
.
acceptedDate
));
}
if
(
accession
!=
null
)
{
predicates
.
addAll
(
accession
.
collectPredicates
(
accessionIpr
.
accession
));
}
if
(
expectedDate
!=
null
)
{
predicates
.
add
(
expectedDate
.
buildQuery
(
accessionIpr
.
expectedDate
));
}
if
(
expiredDate
!=
null
)
{
predicates
.
add
(
expiredDate
.
buildQuery
(
accessionIpr
.
expiredDate
));
}
if
(
iprCropName
!=
null
)
{
predicates
.
add
(
iprCropName
.
buildQuery
(
accessionIpr
.
iprCropName
));
}
if
(
iprFullName
!=
null
)
{
predicates
.
add
(
iprFullName
.
buildQuery
(
accessionIpr
.
iprFullName
));
}
if
(
iprNumber
!=
null
)
{
predicates
.
add
(
iprNumber
.
buildQuery
(
accessionIpr
.
iprNumber
));
}
if
(
issuedDate
!=
null
)
{
predicates
.
add
(
issuedDate
.
buildQuery
(
accessionIpr
.
issuedDate
));
}
if
(
CollectionUtils
.
isNotEmpty
(
typeCode
))
{
predicates
.
add
(
accessionIpr
.
typeCode
.
in
(
typeCode
));
}
return
predicates
;
}
}
server/src/main/java/org/gringlobal/service/filter/InventoryFilter.java
View file @
d055331c
...
...
@@ -176,6 +176,12 @@ public class InventoryFilter extends CooperatorOwnedModelFilter<InventoryFilter,
/** The accession inventory group id. */
public
Set
<
Long
>
accessionInvGroup
;
/** The inventory action filter */
public
InventoryActionFilter
actions
;
/** The inventory action filter */
public
AccessionInvNameFilter
names
;
/**
* Builds the query.
*
...
...
@@ -333,6 +339,12 @@ public class InventoryFilter extends CooperatorOwnedModelFilter<InventoryFilter,
if
(
CollectionUtils
.
isNotEmpty
(
accessionInvGroup
))
{
predicates
.
add
(
inventory
.
accessionInvGroupMaps
.
any
().
accessionInvGroup
.
id
.
in
(
accessionInvGroup
));
}
if
(
actions
!=
null
)
{
predicates
.
addAll
(
actions
.
collectPredicates
(
inventory
.
actions
.
any
()));
}
if
(
names
!=
null
)
{
predicates
.
addAll
(
names
.
collectPredicates
(
inventory
.
names
.
any
()));
}
return
predicates
;
}
...
...
server/src/test/java/org/gringlobal/test/api/v1/AccessionControllerTest.java
View file @
d055331c
...
...
@@ -46,7 +46,10 @@ import org.gringlobal.service.AccessionInvGroupService;
import
org.gringlobal.service.AccessionService
;
import
org.gringlobal.service.AccessionService.AcquisitionData
;
import
org.gringlobal.service.AccessionSourceMapService
;
import
org.gringlobal.service.filter.AccessionActionFilter
;
import
org.gringlobal.service.filter.AccessionFilter
;
import
org.gringlobal.service.filter.AccessionIprFilter
;
import
org.gringlobal.service.filter.InventoryFilter
;
import
org.gringlobal.service.filter.TaxonomySpeciesFilter
;
import
org.gringlobal.spring.CSVMessageConverter
;
import
org.gringlobal.test.service.AbstractServicesTest
;
...
...
@@ -759,6 +762,198 @@ public class AccessionControllerTest extends AbstractApiV1Test {
/*@formatter:on*/
}
@Test
public
void
testAccessionsListByActions
()
throws
Exception
{
// build accessions
TaxonomySpecies
ts
=
addTaxonomySpeciesToDB
();
Accession
a1
=
new
Accession
();
a1
.
setAccessionNumberPart1
(
"AccessionNumberPart1"
);
a1
.
setIsBackedUp
(
TRUE
);
a1
.
setIsCore
(
TRUE
);
a1
.
setIsWebVisible
(
TRUE
);
a1
.
setStatusCode
(
ACCESSION_STATUS_CODE
);
a1
.
setSite
(
DEFAULT_SITE
);
a1
.
setBackupLocation1Site
(
IITA_SITE
);
a1
.
setBackupLocation2Site
(
CIP_SITE
);
a1
.
setTaxonomySpecies
(
ts
);
Accession
accession1
=
accessionService
.
create
(
a1
);
assertThat
(
accession1
,
notNullValue
());
assertThat
(
accession1
.
getId
(),
notNullValue
());
assertThat
(
accessionRepository
.
findById
(
accession1
.
getId
()).
isPresent
(),
is
(
true
));
AccessionAction
accessionAction1
=
new
AccessionAction
();
accessionAction1
.
setAccession
(
accession1
);
accessionAction1
.
setIsWebVisible
(
TRUE
);
accessionAction1
.
setStartedDate
(
new
Date
());
accessionAction1
.
setStartedDateCode
(
CommunityCodeValues
.
DATE_FORMAT_DATE
.
value
);
accessionAction1
.
setActionNameCode
(
"DUPECHECK"
);
accessionAction1
=
accessionActionRepository
.
save
(
accessionAction1
);
Accession
a2
=
new
Accession
();
a2
.
setAccessionNumberPart1
(
"AccessionNumberPart2"
);
a2
.
setIsBackedUp
(
TRUE
);
a2
.
setIsCore
(
TRUE
);
a2
.
setIsWebVisible
(
TRUE
);
a2
.
setStatusCode
(
ACCESSION_STATUS_CODE
);
a2
.
setSite
(
DEFAULT_SITE
);
a2
.
setBackupLocation1Site
(
IITA_SITE
);
a2
.
setBackupLocation2Site
(
CIP_SITE
);
a2
.
setTaxonomySpecies
(
ts
);
Accession
accession2
=
accessionService
.
create
(
a2
);
assertThat
(
accession2
,
notNullValue
());
assertThat
(
accession2
.
getId
(),
notNullValue
());
assertThat
(
accessionRepository
.
findById
(
accession2
.
getId
()).
isPresent
(),
is
(
true
));
AccessionAction
accessionAction2
=
new
AccessionAction
();
accessionAction2
.
setAccession
(
accession2
);
accessionAction2
.
setIsWebVisible
(
TRUE
);
accessionAction2
.
setStartedDate
(
new
Date
());
accessionAction2
.
setStartedDateCode
(
CommunityCodeValues
.
DATE_FORMAT_DATE
.
value
);
accessionAction2
.
setActionNameCode
(
"ACCNUMBERD"
);
accessionAction2
=
accessionActionRepository
.
save
(
accessionAction2
);
AccessionFilter
filter
=
new
AccessionFilter
();
filter
.
accessionActions
=
new
AccessionActionFilter
();
filter
.
accessionActions
.
actionNameCode
=
Set
.
of
(
"ACCNUMBERD"
);
/*@formatter:off*/
mockMvc
.
perform
(
post
(
AccessionController
.
API_URL
+
"/list"
)
.
contentType
(
MediaType
.
APPLICATION_JSON
)
.
content
(
verboseMapper
.
writeValueAsString
(
filter
))
)
// .andDo(org.springframework.test.web.servlet.result.MockMvcResultHandlers.print())
.
andExpect
(
status
().
isOk
())
.
andExpect
(
content
().
contentType
(
MediaType
.
APPLICATION_JSON
))
.
andExpect
(
jsonPath
(
"$"
,
not
(
nullValue
())))
.
andExpect
(
jsonPath
(
"$.totalElements"
,
is
(
1
)))
.
andExpect
(
jsonPath
(
"$.content"
).
isArray
())
.
andExpect
(
jsonPath
(
"$.content[0].id"
,
is
(
accession2
.
getId
().
intValue
())))
.
andExpect
(
jsonPath
(
"$.content[0].taxonomySpecies.id"
,
is
(
ts
.
getId
().
intValue
())))
;
/*@formatter:on*/
filter
=
new
AccessionFilter
();
filter
.
accessionActions
=
new
AccessionActionFilter
();
filter
.
accessionActions
.
actionNameCode
=
Set
.
of
(
"DUPECHECK"
);
/*@formatter:off*/
mockMvc
.
perform
(
post
(
AccessionController
.
API_URL
+
"/list"
)
.
contentType
(
MediaType
.
APPLICATION_JSON
)
.
content
(
verboseMapper
.
writeValueAsString
(
filter
))
)
// .andDo(org.springframework.test.web.servlet.result.MockMvcResultHandlers.print())
.
andExpect
(
status
().
isOk
())
.
andExpect
(
content
().
contentType
(
MediaType
.
APPLICATION_JSON
))
.
andExpect
(
jsonPath
(
"$"
,
not
(
nullValue
())))
.
andExpect
(
jsonPath
(
"$.totalElements"
,
is
(
1
)))
.
andExpect
(
jsonPath
(
"$.content"
).
isArray
())
.
andExpect
(
jsonPath
(
"$.content[0].id"
,
is
(
accession1
.
getId
().
intValue
())))
.
andExpect
(
jsonPath
(
"$.content[0].taxonomySpecies.id"
,
is
(
ts
.
getId
().
intValue
())))
;
/*@formatter:on*/
}
@Test
public
void
testAccessionsListByInventories
()
throws
Exception
{
// build accessions
Accession
accession
=
addAccessionToDB
();
Accession
accession2
=
addAccessionToDB
();
Inventory
inventory
=
addInventoryToDB
(
accession
);
Inventory
inventory2
=
addInventoryToDB
(
accession2
);
AccessionFilter
filter
=
new
AccessionFilter
();
filter
.
inventories
=
new
InventoryFilter
();
filter
.
inventories
.
id
=
Set
.
of
(
inventory2
.
getId
());
/*@formatter:off*/
mockMvc
.
perform
(
post
(
AccessionController
.
API_URL
+
"/list"
)
.
contentType
(
MediaType
.
APPLICATION_JSON
)
.
content
(
verboseMapper
.
writeValueAsString
(
filter
))
)
// .andDo(org.springframework.test.web.servlet.result.MockMvcResultHandlers.print())
.
andExpect
(
status
().
isOk
())
.
andExpect
(
content
().
contentType
(
MediaType
.
APPLICATION_JSON
))
.
andExpect
(
jsonPath
(
"$"
,
not
(
nullValue
())))
.
andExpect
(
jsonPath
(
"$.totalElements"
,
is
(
1
)))
.
andExpect
(
jsonPath
(
"$.content"
).
isArray
())
.
andExpect
(
jsonPath
(
"$.content[0].id"
,
is
(
accession2
.
getId
().
intValue
())))
;
/*@formatter:on*/
filter
=
new
AccessionFilter
();
filter
.
inventories
=
new
InventoryFilter
();
filter
.
inventories
.
id
=
Set
.
of
(
inventory
.
getId
());
/*@formatter:off*/
mockMvc
.
perform
(
post
(
AccessionController
.
API_URL
+
"/list"
)
.
contentType
(
MediaType
.
APPLICATION_JSON
)
.
content
(
verboseMapper
.
writeValueAsString
(
filter
))
)
// .andDo(org.springframework.test.web.servlet.result.MockMvcResultHandlers.print())
.
andExpect
(
status
().
isOk
())
.
andExpect
(
content
().
contentType
(
MediaType
.
APPLICATION_JSON
))
.
andExpect
(
jsonPath
(
"$"
,
not
(
nullValue
())))
.
andExpect
(
jsonPath
(
"$.totalElements"
,
is
(
1
)))
.
andExpect
(
jsonPath
(
"$.content"
).
isArray
())
.
andExpect
(
jsonPath
(
"$.content[0].id"
,
is
(
accession
.
getId
().
intValue
())))
;
/*@formatter:on*/
}
@Test
public
void
testAccessionsListByAccessionIprs
()
throws
Exception
{
// build accessions
Accession
accession
=
addAccessionToDB
();
Accession
accession2
=
addAccessionToDB
();
// adds ipr with linked accessions to DB
AccessionIpr
ipr
=
new
AccessionIpr
();
ipr
.
setAccession
(
accession
);
ipr
.
setTypeCode
(
CommunityCodeValues
.
ACCESSION_RESTRICTION_TYPE_SMTA
.
value
);
accessionIprRepository
.
save
(
ipr
);
AccessionIpr
ipr2
=
new
AccessionIpr
();
ipr2
.
setAccession
(
accession2
);
ipr2
.
setTypeCode
(
CommunityCodeValues
.
ACCESSION_RESTRICTION_TYPE_SMTA
.
value
);
accessionIprRepository
.
save
(
ipr2
);
AccessionFilter
filter
=
new
AccessionFilter
();
filter
.
accessionIprs
=
new
AccessionIprFilter
();
filter
.
accessionIprs
.
typeCode
=
Set
.
of
(
CommunityCodeValues
.
ACCESSION_RESTRICTION_TYPE_SMTA
.
value
);
/*@formatter:off*/
mockMvc
.
perform
(
post
(
AccessionController
.
API_URL
+
"/list"
)
.
contentType
(
MediaType
.
APPLICATION_JSON
)
.
content
(
verboseMapper
.
writeValueAsString
(
filter
))
)
// .andDo(org.springframework.test.web.servlet.result.MockMvcResultHandlers.print())
.
andExpect
(
status
().
isOk
())
.
andExpect
(
content
().
contentType
(
MediaType
.
APPLICATION_JSON
))
.
andExpect
(
jsonPath
(
"$"
,
not
(
nullValue
())))
.
andExpect
(
jsonPath
(
"$.totalElements"
,
is
(
2
)))
.
andExpect
(
jsonPath
(
"$.content"
).
isArray
())
.
andExpect
(
jsonPath
(
"$.content[0].id"
,
is
(
oneOf
(
accession
.
getId
().
intValue
(),
accession2
.
getId
().
intValue
()))))
.
andExpect
(
jsonPath
(
"$.content[1].id"
,
is
(
oneOf
(
accession
.
getId
().
intValue
(),
accession2
.
getId
().
intValue
()))))
;
/*@formatter:on*/
}
@Test
public
void
testAccessionsListAsCSV
()
throws
Exception
{
...
...
server/src/test/java/org/gringlobal/test/api/v1/InventoryControllerTest.java
View file @
d055331c
...
...
@@ -42,6 +42,7 @@ import org.gringlobal.model.Inventory;
import
org.gringlobal.model.InventoryAction
;
import
org.gringlobal.model.InventoryMaintenancePolicy
;
import
org.gringlobal.model.InventoryQualityStatus
;
import
org.gringlobal.model.NameGroup
;
import
org.gringlobal.model.community.CommunityCodeValues
;
import
org.gringlobal.persistence.AccessionInvAnnotationRepository
;
import
org.gringlobal.persistence.AccessionInvAttachRepository
;
...
...
@@ -50,13 +51,17 @@ import org.gringlobal.persistence.AccessionInvGroupRepository;
import
org.gringlobal.persistence.AccessionInvNameRepository
;
import
org.gringlobal.persistence.AppSettingRepository
;
import
org.gringlobal.persistence.InventoryQualityStatusRepository
;
import
org.gringlobal.persistence.NameGroupRepository
;
import
org.gringlobal.service.AccessionInvGroupService
;
import
org.gringlobal.service.AccessionService
;
import
org.gringlobal.service.AppSettingsService
;
import
org.gringlobal.service.InventoryAttachmentService
;
import
org.gringlobal.service.InventoryService
;
import
org.gringlobal.service.filter.AccessionInvNameFilter
;
import
org.gringlobal.service.filter.InventoryActionFilter
;
import
org.gringlobal.service.filter.InventoryFilter
;
import
org.gringlobal.service.filter.InventoryQualityStatusFilter
;
import
org.gringlobal.service.filter.NameGroupFilter
;
import
org.gringlobal.test.service.AbstractServicesTest
;
import
org.junit.After
;
import
org.junit.Test
;
...
...
@@ -94,6 +99,8 @@ public class InventoryControllerTest extends AbstractApiV1Test {
private
AppSettingRepository
appSettingRepository
;
@Autowired
private
InventoryQualityStatusRepository
inventoryQualityStatusRepository
;
@Autowired
private
NameGroupRepository
nameGroupRepository
;
@After
@Transactional
...
...
@@ -107,6 +114,7 @@ public class InventoryControllerTest extends AbstractApiV1Test {
annotationRepository
.
deleteAllInBatch
();
attachRepository
.
deleteAll
();
inventoryRepository
.
deleteAllInBatch
();
nameGroupRepository
.
deleteAllInBatch
();
repositoryFileRepository
.
deleteAll
();
deleteFolders
(
repositoryFolderRepository
.
findAll
());
...
...
@@ -356,6 +364,168 @@ public class InventoryControllerTest extends AbstractApiV1Test {
}
@Test
public
void
testInventoryListByActions
()
throws
Exception
{
Accession
accession
=
addAccessionToDB
();
Inventory
savedInventory1
=
addInventoryToDB
(
accession
,
"INV"
,
-
1L
,
null
);
assertThat
(
savedInventory1
,
is
(
notNullValue
()));
InventoryAction
inventoryAction
=
new
InventoryAction
();
inventoryAction
.
setInventory
(
savedInventory1
);
inventoryAction
.
setCooperator
(
cooperator
);
inventoryAction
.
setActionNameCode
(
"QUANTITYSET"
);
inventoryActionRepository
.
save
(
inventoryAction
);
InventoryAction
inventoryAction2
=
new
InventoryAction
();
inventoryAction2
.
setInventory
(
savedInventory1
);
inventoryAction2
.
setCooperator
(
cooperator
);
inventoryAction2
.
setActionNameCode
(
"100SEEDWEIGHT"
);
inventoryActionRepository
.
save
(
inventoryAction2
);
Accession
accession2
=
addAccessionToDB
();
Inventory
savedInventory2
=
addInventoryToDB
(
accession2
,
"INV"
,
-
1L
,
null
);
assertThat
(
savedInventory2
,
is
(
notNullValue
()));
InventoryAction
inventoryAction3
=
new
InventoryAction
();
inventoryAction3
.
setInventory
(
savedInventory2
);
inventoryAction3
.
setCooperator
(
cooperator
);
inventoryAction3
.
setActionNameCode
(
"WITHDRAW"
);
inventoryActionRepository
.
save
(
inventoryAction3
);
InventoryAction
inventoryAction4
=
new
InventoryAction
();
inventoryAction4
.
setInventory
(
savedInventory2
);
inventoryAction4
.
setCooperator
(
cooperator
);
inventoryAction4
.
setActionNameCode
(
"VABILITYTEST"
);
inventoryActionRepository
.
save
(
inventoryAction4
);
InventoryFilter
filter
=
new
InventoryFilter
();
filter
.
actions
=
new
InventoryActionFilter
();
filter
.
actions
.
actionNameCode
=
Set
.
of
(
"100SEEDWEIGHT"
);
/*@formatter:off*/
mockMvc
.
perform
(
post
(
InventoryController
.
API_URL
+
"/list"
)
.
contentType
(
MediaType
.
APPLICATION_JSON
)
.
content
(
verboseMapper
.
writeValueAsString
(
filter
))
)
// .andDo(org.springframework.test.web.servlet.result.MockMvcResultHandlers.print())
.
andExpect
(
status
().
isOk
())
.
andExpect
(
content
().
contentType
(
MediaType
.
APPLICATION_JSON
))
.
andExpect
(
jsonPath
(
"$"
,
not
(
nullValue
())))
.
andExpect
(
jsonPath
(
"$.totalElements"
,
is
(
1
)))
.
andExpect
(
jsonPath
(
"$.content"
).
isArray
())
.
andExpect
(
jsonPath
(
"$.content[0].id"
,
is
(
savedInventory1
.
getId
().
intValue
())))
.
andExpect
(
jsonPath
(
"$.totalPages"
,
is
(
1
)))
.
andExpect
(
jsonPath
(
"$.totalElements"
,
is
(
1
)))
;
/*@formatter:on*/
filter
=
new
InventoryFilter
();
filter
.
actions
=
new
InventoryActionFilter
();
filter
.
actions
.
actionNameCode
=
Set
.
of
(
"VABILITYTEST"
);
/*@formatter:off*/
mockMvc
.
perform
(
post
(
InventoryController
.
API_URL
+
"/list"
)
.
contentType
(
MediaType
.
APPLICATION_JSON
)
.
content
(
verboseMapper
.
writeValueAsString
(
filter
))
)
// .andDo(org.springframework.test.web.servlet.result.MockMvcResultHandlers.print())
.
andExpect
(
status
().
isOk
())
.
andExpect
(
content
().
contentType
(
MediaType
.
APPLICATION_JSON
))
.
andExpect
(
jsonPath
(
"$"
,
not
(
nullValue
())))
.
andExpect
(
jsonPath
(
"$.totalElements"
,
is
(
1
)))
.
andExpect
(
jsonPath
(
"$.content"
).
isArray
())
.
andExpect
(
jsonPath
(
"$.content[0].id"
,
is
(
savedInventory2
.
getId
().
intValue
())))
.
andExpect
(
jsonPath
(
"$.totalPages"
,
is
(
1
)))
.
andExpect
(
jsonPath
(
"$.totalElements"
,
is
(
1
)))
;
/*@formatter:on*/
}
@Test
public
void
testInventoryListByAccessionInvName
()
throws
Exception
{
Accession
accession
=
addAccessionToDB
();