Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions QLACK-Fuse/qlack-fuse-acv/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
This module provides Object Auditing, Comparison and Versioning operations.

## Integration
Add following property in your projects application.properties file, in order to persist the
Add following property in your projects application.properties file, in order to persist the
object versions in the database used by your application.
`javers.sqlSchema.sqlSchemaManagementEnabled=true`
`javers.sqlSchemaManagementEnabled=true`

This is Javers' default, so the property only needs to be set explicitly when it has been
disabled elsewhere.

### Add qlack-fuse-acv dependency to your pom.xml:
```xml
<dependency>
<groupId>com.eurodyn.qlack.fuse</groupId>
<artifactId>qlack-fuse-acv</artifactId>
<version>${qlack.version}</version>
</dependency>
<groupId>com.eurodyn.qlack.fuse</groupId>
<artifactId>qlack-fuse-acv</artifactId>
<version>${qlack.version}</version>
</dependency>
```

### Add the packages in the Spring boot application main class declaration:
Expand Down
2 changes: 1 addition & 1 deletion QLACK-Fuse/qlack-fuse-acv/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


<properties>
<javers.version>5.15.0</javers.version>
<javers.version>7.11.7</javers.version>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import lombok.NonNull;
import org.javers.core.Javers;
import org.javers.core.diff.Diff;
import org.javers.core.diff.changetype.InitialValueChange;
import org.javers.core.diff.changetype.TerminalValueChange;
import org.javers.core.diff.changetype.ValueChange;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -56,12 +58,32 @@ public <T> List<ChangeDTO> compare(@NonNull T obj1, @NonNull T obj2) {
Diff result = javers.compare(obj1, obj2);

List<ChangeDTO> changes = result.getChangesByType(ValueChange.class)
.parallelStream()
.map(this::convertToChangeDTO).collect(Collectors.toList());
.parallelStream()
.filter(CompareService::isValueChange)
.map(this::convertToChangeDTO).collect(Collectors.toList());

return Collections.unmodifiableList(changes);
}

/**
* Keeps only real, before/after property value changes.
* <br><br>
* Javers 7 reports the whole state of an added or a removed object as
* {@link InitialValueChange} and {@link TerminalValueChange}. Both extend
* {@link ValueChange}, so they are also returned by
* {@link Diff#getChangesByType(Class)}, which would add one entry per
* property of every added/removed object, each having either the "from" or
* the "to" side always null. Such entries were not produced by earlier Javers
* versions and are filtered out here.
*
* @param change the change to examine
* @return true if the change is a plain value change, else false
*/
private static boolean isValueChange(ValueChange change) {
return !(change instanceof InitialValueChange)
&& !(change instanceof TerminalValueChange);
}

/**
* Compares two object versions and returns the changes.
* <br><br>
Expand All @@ -74,10 +96,10 @@ public <T> List<ChangeDTO> compare(@NonNull T obj1, @NonNull T obj2) {
* @return a list with the changes between the two comparing objects
*/
public List<ChangeDTO> compareVersions(Object object, long version1,
long version2) {
long version2) {

return compare(versioningService.retrieveVersion(object, version1),
versioningService.retrieveVersion(object, version2));
versioningService.retrieveVersion(object, version2));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.when;

import com.eurodyn.qlack.fuse.acv.dto.ChangeDTO;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import org.javers.core.Javers;
import org.javers.core.diff.Diff;
import org.javers.core.diff.changetype.InitialValueChange;
import org.javers.core.diff.changetype.PropertyChangeMetadata;
import org.javers.core.diff.changetype.PropertyChangeType;
import org.javers.core.diff.changetype.TerminalValueChange;
import org.javers.core.diff.changetype.ValueChange;
import org.javers.core.metamodel.object.GlobalId;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -69,7 +73,7 @@ public void compareVersionsTest() {
when(diff.getChangesByType(ValueChange.class)).thenReturn(valueChangeList);

assertEquals(Collections.emptyList(),
compareService.compareVersions(object1, 1L, 2L));
compareService.compareVersions(object1, 1L, 2L));
}

@Test
Expand All @@ -82,7 +86,7 @@ public void testHasChanges() {
@Test
public void hasChangesNullObj1Test() {
assertThrows(NullPointerException.class, () ->
compareService.hasChanges(null, object2));
compareService.hasChanges(null, object2));
}

@Test
Expand Down Expand Up @@ -113,7 +117,7 @@ public void compareObjectWithVersionTest() {
when(diff.getChangesByType(ValueChange.class)).thenReturn(valueChangeList);

assertEquals(Collections.emptyList(),
compareService.compareObjectWithVersion(object1, 1L));
compareService.compareObjectWithVersion(object1, 1L));
}

@Test
Expand All @@ -123,16 +127,48 @@ public void compareObjectWithLatestVersionTest() {
when(diff.getChangesByType(ValueChange.class)).thenReturn(valueChangeList);

assertEquals(Collections.emptyList(),
compareService.compareObjectWithLatestVersion(object1));
compareService.compareObjectWithLatestVersion(object1));
}

@Test
public void convertToChangeDTOTest() {

PropertyChangeMetadata metadata = new PropertyChangeMetadata(globalId, "property", Optional.empty(),
PropertyChangeType.PROPERTY_VALUE_CHANGED);
PropertyChangeType.PROPERTY_VALUE_CHANGED);
ValueChange valueChange = new ValueChange(metadata, object1, object2);
assertNotNull(compareService.convertToChangeDTO(valueChange));
}

/**
* Since Javers 7, {@link Diff#getChangesByType(Class)} also returns the
* {@link InitialValueChange} and {@link TerminalValueChange} subtypes, which
* describe the state of added/removed objects rather than an actual
* before/after change. Those must not end up in the reported changes.
*/
@Test
public void compareSkipsInitialAndTerminalValueChangesTest() {
ValueChange valueChange = new ValueChange(
propertyChangeMetadata("property"), object1, object2);
InitialValueChange initialValueChange = new InitialValueChange(
propertyChangeMetadata("addedProperty"), object2);
TerminalValueChange terminalValueChange = new TerminalValueChange(
propertyChangeMetadata("removedProperty"), object1);

when(javers.compare(object1, object2)).thenReturn(diff);
when(diff.getChangesByType(ValueChange.class)).thenReturn(
Arrays.asList(initialValueChange, valueChange, terminalValueChange));

List<ChangeDTO> changes = compareService.compare(object1, object2);

assertEquals(1, changes.size());
assertEquals("property", changes.get(0).getPropertyName());
assertEquals(object1, changes.get(0).getFrom());
assertEquals(object2, changes.get(0).getTo());
}

private PropertyChangeMetadata propertyChangeMetadata(String propertyName) {
return new PropertyChangeMetadata(globalId, propertyName, Optional.empty(),
PropertyChangeType.PROPERTY_VALUE_CHANGED);
}

}
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@
<mockito-junit-jupiter.version>5.15.2</mockito-junit-jupiter.version>

<!-- Third-party -->
<activiti.version>8.7.0</activiti.version>
<activiti.version>8.8.0</activiti.version>
<commons-email.version>1.6.0</commons-email.version>
<apache.poi.version>5.4.0</apache.poi.version>
<apache.tika.version>3.2.2</apache.tika.version>
<apache.tika.version>3.3.2</apache.tika.version>
<beanshell.version>2.0b6</beanshell.version>
<bouncycastle.version>1.80</bouncycastle.version>
<commons-io.version>2.18.0</commons-io.version>
Expand Down