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
A
App Blocks
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Genesys PGR
App Blocks
Commits
1805b003
Commit
1805b003
authored
Apr 16, 2020
by
Matija Obreza
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
BasicModel implements Persistable
- Updated equals() code for entities: NULL id means objects are not equal
parent
73f5ecb7
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
18 additions
and
17 deletions
+18
-17
auditlog/src/main/java/org/genesys/blocks/auditlog/component/AuditTrailInterceptor.java
...esys/blocks/auditlog/component/AuditTrailInterceptor.java
+1
-1
auditlog/src/test/java/org/genesys/blocks/auditlog/service/AuditTrailServiceTest.java
...enesys/blocks/auditlog/service/AuditTrailServiceTest.java
+2
-2
core/src/main/java/org/genesys/blocks/model/BasicModel.java
core/src/main/java/org/genesys/blocks/model/BasicModel.java
+8
-8
core/src/main/java/org/genesys/blocks/model/VersionedModel.java
...rc/main/java/org/genesys/blocks/model/VersionedModel.java
+3
-2
core/src/test/java/org/genesys/blocks/tests/model/UuidModelTest.java
...st/java/org/genesys/blocks/tests/model/UuidModelTest.java
+1
-1
core/src/test/java/org/genesys/blocks/tests/model/VersionedModelTest.java
...va/org/genesys/blocks/tests/model/VersionedModelTest.java
+1
-1
security/src/main/java/org/genesys/blocks/security/service/impl/CustomAclServiceImpl.java
...ys/blocks/security/service/impl/CustomAclServiceImpl.java
+2
-2
No files found.
auditlog/src/main/java/org/genesys/blocks/auditlog/component/AuditTrailInterceptor.java
View file @
1805b003
...
...
@@ -786,7 +786,7 @@ public class AuditTrailInterceptor extends EmptyInterceptor implements Initializ
@Override
public
Boolean
isTransient
(
final
Object
entity
)
{
if
(
entity
instanceof
BasicModel
)
{
return
!((
BasicModel
)
entity
).
isPersisted
();
return
((
BasicModel
)
entity
).
isNew
();
}
// TODO Use Spring field access methods?
try
{
...
...
auditlog/src/test/java/org/genesys/blocks/auditlog/service/AuditTrailServiceTest.java
View file @
1805b003
...
...
@@ -122,7 +122,7 @@ public class AuditTrailServiceTest extends ServiceTest {
public
void
testTransactionalListQuery
()
{
ExampleAuditedEntity
entity
=
exampleAuditedEntityService
.
testList
();
assertThat
(
entity
.
getId
(),
not
(
nullValue
()));
assertThat
(
entity
.
is
Persisted
(),
is
(
tru
e
));
assertThat
(
entity
.
is
New
(),
is
(
fals
e
));
assertThat
(
listAuditLogs
(
entity
),
hasSize
(
1
));
entity
=
exampleAuditedEntityService
.
get
(
entity
.
getId
());
...
...
@@ -140,7 +140,7 @@ public class AuditTrailServiceTest extends ServiceTest {
public
void
testDelete
()
{
ExampleAuditedEntity
entity
=
exampleAuditedEntityService
.
testList
();
assertThat
(
entity
.
getId
(),
not
(
nullValue
()));
assertThat
(
entity
.
is
Persisted
(),
is
(
tru
e
));
assertThat
(
entity
.
is
New
(),
is
(
fals
e
));
assertThat
(
entity
.
getName
(),
is
(
"Test 3"
));
assertThat
(
listAuditLogs
(
entity
),
hasSize
(
1
));
...
...
core/src/main/java/org/genesys/blocks/model/BasicModel.java
View file @
1805b003
...
...
@@ -22,6 +22,8 @@ import javax.persistence.Id;
import
javax.persistence.MappedSuperclass
;
import
javax.persistence.Transient
;
import
org.springframework.data.domain.Persistable
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
com.fasterxml.jackson.annotation.JsonView
;
...
...
@@ -29,7 +31,7 @@ import com.fasterxml.jackson.annotation.JsonView;
* The Class BasicModel.
*/
@MappedSuperclass
public
class
BasicModel
extends
EmptyModel
{
public
class
BasicModel
extends
EmptyModel
implements
Persistable
<
Long
>
{
/** The Constant serialVersionUID. */
private
static
final
long
serialVersionUID
=
2709998920148999956L
;
...
...
@@ -39,7 +41,7 @@ public class BasicModel extends EmptyModel {
@Id
@GeneratedValue
(
strategy
=
GenerationType
.
AUTO
)
@Column
(
name
=
"id"
,
unique
=
true
,
nullable
=
false
)
private
Long
id
=
InMemoryIdGenerator
.
nextId
();
private
Long
id
=
null
;
//
InMemoryIdGenerator.nextId();
/*
* (non-Javadoc)
...
...
@@ -68,8 +70,8 @@ public class BasicModel extends EmptyModel {
*/
@JsonIgnore
@Transient
public
final
boolean
is
Persisted
()
{
return
(
id
!=
null
)
&&
(
id
.
longValue
()
>
0
);
public
final
boolean
is
New
()
{
return
(
id
==
null
)
||
(
id
.
longValue
()
<
0
);
}
/*
...
...
@@ -100,10 +102,8 @@ public class BasicModel extends EmptyModel {
return
false
;
}
final
BasicModel
other
=
(
BasicModel
)
obj
;
if
(
id
==
null
)
{
if
(
other
.
id
!=
null
)
{
return
false
;
}
if
(
id
==
null
||
other
.
id
==
null
)
{
return
false
;
}
else
if
(!
id
.
equals
(
other
.
id
))
{
return
false
;
}
...
...
core/src/main/java/org/genesys/blocks/model/VersionedModel.java
View file @
1805b003
...
...
@@ -103,8 +103,9 @@ public abstract class VersionedModel extends BasicModel implements Activatable {
if
(
getClass
()
!=
obj
.
getClass
())
return
false
;
VersionedModel
other
=
(
VersionedModel
)
obj
;
if
(
active
!=
other
.
active
)
return
false
;
// We're only interested in id+version combination
// if (active != other.active)
// return false;
if
(
version
==
null
)
{
if
(
other
.
version
!=
null
)
return
false
;
...
...
core/src/test/java/org/genesys/blocks/tests/model/UuidModelTest.java
View file @
1805b003
...
...
@@ -41,7 +41,7 @@ public class UuidModelTest extends ServiceTest {
@Test
public
void
testConstructor
()
{
UuidEntity
entity
=
new
UuidEntity
();
assertThat
(
entity
.
getId
(),
n
ot
(
nullValue
()
));
assertThat
(
entity
.
getId
(),
n
ullValue
(
));
assertThat
(
entity
.
getUuid
(),
is
(
nullValue
()));
assertThat
(
entity
.
getVersion
(),
nullValue
());
}
...
...
core/src/test/java/org/genesys/blocks/tests/model/VersionedModelTest.java
View file @
1805b003
...
...
@@ -39,7 +39,7 @@ public class VersionedModelTest extends ServiceTest {
@Test
public
void
testConstructor
()
{
VersionedEntity
entity
=
new
VersionedEntity
();
assertThat
(
entity
.
getId
(),
n
ot
(
nullValue
()
));
assertThat
(
entity
.
getId
(),
n
ullValue
(
));
assertThat
(
entity
.
getVersion
(),
nullValue
());
assertThat
(
entity
.
isActive
(),
is
(
true
));
}
...
...
security/src/main/java/org/genesys/blocks/security/service/impl/CustomAclServiceImpl.java
View file @
1805b003
...
...
@@ -168,7 +168,7 @@ public class CustomAclServiceImpl implements CustomAclService {
final
AclSid
ownerSid
=
SecurityContextUtil
.
getCurrentUser
();
if
(
ownerSid
==
null
)
{
LOG
.
warn
(
"No SID in security context, not assigning creator permissions"
);
}
else
if
(
!
ownerSid
.
isPersisted
())
{
}
else
if
(
ownerSid
.
isNew
())
{
LOG
.
warn
(
"Owner SID not persisted, not assigning creator permissions"
);
}
else
{
objectIdentity
.
setOwnerSid
(
ownerSid
);
...
...
@@ -202,7 +202,7 @@ public class CustomAclServiceImpl implements CustomAclService {
if
(
objectIdentity
.
getOwnerSid
()
==
null
)
{
final
AclSid
ownerSid
=
SecurityContextUtil
.
getCurrentUser
();
if
(
ownerSid
!=
null
&&
ownerSid
.
isPersisted
())
{
if
(
ownerSid
!=
null
&&
!
ownerSid
.
isNew
())
{
objectIdentity
.
setOwnerSid
(
ownerSid
);
// Grant permissions to owner
...
...
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