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
GRIN-Global Server
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
24
Issues
24
List
Boards
Labels
Service Desk
Milestones
Packages & Registries
Packages & Registries
Container Registry
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
GRIN-Global
GRIN-Global Server
Commits
e10591ed
Commit
e10591ed
authored
Oct 02, 2020
by
Maxym Borodenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP: handling list of inventories
parent
3043df8d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
19 deletions
+37
-19
src/main/java/org/gringlobal/component/repository/InventoryAspect.java
.../org/gringlobal/component/repository/InventoryAspect.java
+37
-19
No files found.
src/main/java/org/gringlobal/component/repository/InventoryAspect.java
View file @
e10591ed
...
...
@@ -18,7 +18,9 @@ package org.gringlobal.component.repository;
import
java.util.Date
;
import
java.util.Iterator
;
import
java.util.Objects
;
import
java.util.stream.Collectors
;
import
com.google.common.collect.Lists
;
import
com.querydsl.core.types.dsl.BooleanExpression
;
import
org.aspectj.lang.ProceedingJoinPoint
;
import
org.aspectj.lang.annotation.Around
;
...
...
@@ -61,8 +63,16 @@ public class InventoryAspect {
public
Object
aroundInventorySave
(
final
ProceedingJoinPoint
joinPoint
,
final
Iterable
<
Inventory
>
inventories
)
throws
Throwable
{
LOG
.
warn
(
"Many inventories are being saved!!! {}"
,
inventories
);
var
newInventories
=
Lists
.
newArrayList
(
inventories
).
stream
().
filter
(
i
->
i
.
getId
()
==
null
).
collect
(
Collectors
.
toList
());
var
existingInventories
=
Lists
.
newArrayList
(
inventories
).
stream
().
filter
(
i
->
i
.
getId
()
!=
null
).
collect
(
Collectors
.
toList
());
existingInventories
.
forEach
(
this
::
handleUpdatingOfExistingInventory
);
// Complete saving
return
joinPoint
.
proceed
();
Object
proceed
=
joinPoint
.
proceed
();
newInventories
.
forEach
(
this
::
handleCreatingNewInventory
);
return
proceed
;
}
@Around
(
value
=
"(execution(* org.gringlobal.persistence.InventoryRepository.save(..)) || execution(* org.gringlobal.persistence.InventoryRepository.saveAndFlush(..)) || execution(* org.gringlobal.persistence.InventoryRepository.save(..))) && args(inventory)"
)
...
...
@@ -75,25 +85,9 @@ public class InventoryAspect {
// Complete saving entity
joinPoint
.
proceed
();
// Register two PENDING inventory actions
addInventoryAction
(
inventory
,
CommunityCodeValues
.
INVENTORY_ACTION_QUANTITYSET
);
addInventoryAction
(
inventory
,
CommunityCodeValues
.
INVENTORY_ACTION_LOCATIONSET
);
handleCreatingNewInventory
(
inventory
);
}
else
{
// Detach the new version from the session to be able to load the old version with previous property values
entityManager
.
detach
(
inventory
);
// Load old version to compare with a new version
Inventory
loaded
=
inventoryService
.
get
(
inventory
.
getId
());
if
(!
Objects
.
equals
(
loaded
.
getQuantityOnHand
(),
inventory
.
getQuantityOnHand
())
||
!
Objects
.
equals
(
loaded
.
getQuantityOnHandUnitCode
(),
inventory
.
getQuantityOnHandUnitCode
()))
{
// Quantity is updated - close the QUANTITYSET action
closeInventoryAction
(
loaded
,
CommunityCodeValues
.
INVENTORY_ACTION_QUANTITYSET
);
}
if
(!
Objects
.
equals
(
loaded
.
getStorageLocationPart1
(),
inventory
.
getStorageLocationPart1
())
||
!
Objects
.
equals
(
loaded
.
getStorageLocationPart2
(),
inventory
.
getStorageLocationPart2
())
||
!
Objects
.
equals
(
loaded
.
getStorageLocationPart3
(),
inventory
.
getStorageLocationPart3
())
||
!
Objects
.
equals
(
loaded
.
getStorageLocationPart4
(),
inventory
.
getStorageLocationPart4
()))
{
// Storage location is updated - close the LOCATIONSET action
closeInventoryAction
(
loaded
,
CommunityCodeValues
.
INVENTORY_ACTION_LOCATIONSET
);
}
handleUpdatingOfExistingInventory
(
inventory
);
// Complete saving entity
return
joinPoint
.
proceed
();
...
...
@@ -102,6 +96,30 @@ public class InventoryAspect {
return
inventory
;
}
private
void
handleCreatingNewInventory
(
Inventory
newInventory
)
{
// Register two PENDING inventory actions
addInventoryAction
(
newInventory
,
CommunityCodeValues
.
INVENTORY_ACTION_QUANTITYSET
);
addInventoryAction
(
newInventory
,
CommunityCodeValues
.
INVENTORY_ACTION_LOCATIONSET
);
}
private
void
handleUpdatingOfExistingInventory
(
Inventory
inventory
)
{
// Detach the new version from the session to be able to load the old version with previous property values
entityManager
.
detach
(
inventory
);
// Load old version to compare with a new version
Inventory
loaded
=
inventoryService
.
get
(
inventory
.
getId
());
if
(!
Objects
.
equals
(
loaded
.
getQuantityOnHand
(),
inventory
.
getQuantityOnHand
())
||
!
Objects
.
equals
(
loaded
.
getQuantityOnHandUnitCode
(),
inventory
.
getQuantityOnHandUnitCode
()))
{
// Quantity is updated - close the QUANTITYSET action
closeInventoryAction
(
loaded
,
CommunityCodeValues
.
INVENTORY_ACTION_QUANTITYSET
);
}
if
(!
Objects
.
equals
(
loaded
.
getStorageLocationPart1
(),
inventory
.
getStorageLocationPart1
())
||
!
Objects
.
equals
(
loaded
.
getStorageLocationPart2
(),
inventory
.
getStorageLocationPart2
())
||
!
Objects
.
equals
(
loaded
.
getStorageLocationPart3
(),
inventory
.
getStorageLocationPart3
())
||
!
Objects
.
equals
(
loaded
.
getStorageLocationPart4
(),
inventory
.
getStorageLocationPart4
()))
{
// Storage location is updated - close the LOCATIONSET action
closeInventoryAction
(
loaded
,
CommunityCodeValues
.
INVENTORY_ACTION_LOCATIONSET
);
}
}
private
void
addInventoryAction
(
Inventory
inventory
,
CommunityCodeValues
.
CodeValueDef
actionCodeValue
)
{
InventoryAction
quantityAction
=
new
InventoryAction
();
quantityAction
.
setActionNameCode
(
actionCodeValue
.
value
);
...
...
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