Skip to content

Commit 007c98a

Browse files
authored
Merge pull request #255 from eclipse/ISSUES-460
[BUG] Embeddable list of nested object cannot be saved
2 parents fd7de86 + dee487a commit 007c98a

File tree

16 files changed

+693
-22
lines changed

16 files changed

+693
-22
lines changed

CHANGELOG.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ and this project adheres to https://semver.org/spec/v2.0.0.html[Semantic Version
88

99
== [Unreleased]
1010

11+
=== Fixed
12+
13+
- Allow Embeddable list of nested object with null value work in MongoDB and ArangoDB
14+
1115
== [1.0.3] - 2023-12-02
1216

1317
=== Added

jnosql-arangodb/src/main/java/org/eclipse/jnosql/databases/arangodb/communication/ArangoDBUtil.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737

3838
import static java.util.Collections.singletonMap;
3939
import static java.util.stream.Collectors.toList;
40-
import static java.util.stream.Collectors.toMap;
4140
import static java.util.stream.StreamSupport.stream;
4241

4342
/**
@@ -48,11 +47,6 @@ public final class ArangoDBUtil {
4847
public static final String KEY = "_key";
4948
public static final String ID = "_id";
5049
public static final String REV = "_rev";
51-
52-
private static final Function<Object, String> KEY_DOCUMENT = d -> cast(d).name();
53-
private static final Function<Object, Object> VALUE_DOCUMENT = d -> ValueUtil.convert(cast(d).value());
54-
55-
5650
private static final Logger LOGGER = Logger.getLogger(ArangoDBUtil.class.getName());
5751

5852
private static final Function<Map.Entry<?, ?>, Document> ENTRY_DOCUMENT = entry ->
@@ -150,8 +144,13 @@ private static Object convert(Value value) {
150144
}
151145

152146
private static Object getMap(Object val) {
153-
return StreamSupport.stream(Iterable.class.cast(val).spliterator(), false)
154-
.collect(toMap(KEY_DOCUMENT, VALUE_DOCUMENT));
147+
Iterable<?> iterable = Iterable.class.cast(val);
148+
Map<Object, Object> map = new HashMap<>();
149+
for (Object item : iterable) {
150+
var document = cast(item);
151+
map.put(document.name(), document.get());
152+
}
153+
return map;
155154
}
156155

157156
private static boolean isSudDocumentList(Object value) {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright (c) 2023 Contributors to the Eclipse Foundation
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* and Apache License v2.0 which accompanies this distribution.
6+
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7+
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
8+
*
9+
* You may elect to redistribute this code under either of these licenses.
10+
*
11+
* Contributors:
12+
*
13+
* Otavio Santana
14+
*/
15+
package org.eclipse.jnosql.databases.arangodb.integration;
16+
17+
public enum MainStepType {
18+
MAIN, ENTRY
19+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright (c) 2023 Contributors to the Eclipse Foundation
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* and Apache License v2.0 which accompanies this distribution.
6+
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7+
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
8+
*
9+
* You may elect to redistribute this code under either of these licenses.
10+
*
11+
* Contributors:
12+
*
13+
* Otavio Santana
14+
*/
15+
package org.eclipse.jnosql.databases.arangodb.integration;
16+
17+
18+
public enum StepTransitionReason {
19+
REPEAT
20+
}

jnosql-arangodb/src/test/java/org/eclipse/jnosql/databases/arangodb/integration/TemplateIntegrationTest.java

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import jakarta.inject.Inject;
1919
import jakarta.nosql.document.DocumentTemplate;
20+
import org.assertj.core.api.SoftAssertions;
2021
import org.eclipse.jnosql.databases.arangodb.communication.ArangoDBConfigurations;
2122
import org.eclipse.jnosql.databases.arangodb.communication.DocumentDatabase;
2223
import org.eclipse.jnosql.mapping.Convert;
@@ -32,12 +33,14 @@
3233
import org.junit.jupiter.api.Test;
3334
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
3435

36+
import java.util.List;
3537
import java.util.Optional;
3638

3739
import static java.util.UUID.randomUUID;
3840
import static org.assertj.core.api.Assertions.assertThat;
3941
import static org.eclipse.jnosql.communication.driver.IntegrationTest.MATCHES;
4042
import static org.eclipse.jnosql.communication.driver.IntegrationTest.NAMED;
43+
import static org.eclipse.jnosql.databases.arangodb.integration.StepTransitionReason.REPEAT;
4144

4245
@EnableAutoWeld
4346
@AddPackages(value = {Convert.class, DocumentEntityConverter.class})
@@ -60,7 +63,7 @@ class TemplateIntegrationTest {
6063

6164

6265
@Test
63-
public void shouldInsert() {
66+
void shouldInsert() {
6467
Book book = new Book(randomUUID().toString(), "Effective Java", 1);
6568
template.insert(book);
6669
Optional<Book> optional = template.find(Book.class, book.id());
@@ -69,7 +72,7 @@ public void shouldInsert() {
6972
}
7073

7174
@Test
72-
public void shouldUpdate() {
75+
void shouldUpdate() {
7376
Book book = new Book(randomUUID().toString(), "Effective Java", 1);
7477
assertThat(template.insert(book))
7578
.isNotNull()
@@ -87,7 +90,7 @@ public void shouldUpdate() {
8790
}
8891

8992
@Test
90-
public void shouldFindById() {
93+
void shouldFindById() {
9194
Book book = new Book(randomUUID().toString(), "Effective Java", 1);
9295
assertThat(template.insert(book))
9396
.isNotNull()
@@ -98,7 +101,7 @@ public void shouldFindById() {
98101
}
99102

100103
@Test
101-
public void shouldDelete() {
104+
void shouldDelete() {
102105
Book book = new Book(randomUUID().toString(), "Effective Java", 1);
103106
assertThat(template.insert(book))
104107
.isNotNull()
@@ -109,5 +112,40 @@ public void shouldDelete() {
109112
.isNotNull().isEmpty();
110113
}
111114

115+
@Test
116+
void shouldUpdateEmbeddable() {
117+
var workflowStep = WorkflowStep.builder()
118+
.id("id")
119+
.key("key")
120+
.workflowSchemaKey("workflowSchemaKey")
121+
.stepName("stepName")
122+
.mainStepType(MainStepType.MAIN)
123+
.stepNo(1)
124+
.componentConfigurationKey("componentConfigurationKey")
125+
.relationTypeKey("relationTypeKey")
126+
.availableTransitions(List.of(new Transition("TEST_WORKFLOW_STEP_KEY", REPEAT,
127+
null, List.of("ADMIN"))))
128+
.build();
129+
var result = this.template.insert(workflowStep);
130+
131+
SoftAssertions.assertSoftly(soft ->{
132+
soft.assertThat(result).isNotNull();
133+
soft.assertThat(result.id()).isEqualTo("workflow_step/key");
134+
soft.assertThat(result.key()).isEqualTo("key");
135+
soft.assertThat(result.workflowSchemaKey()).isEqualTo("workflowSchemaKey");
136+
soft.assertThat(result.stepName()).isEqualTo("stepName");
137+
soft.assertThat(result.mainStepType()).isEqualTo(MainStepType.MAIN);
138+
soft.assertThat(result.stepNo()).isEqualTo(1);
139+
soft.assertThat(result.componentConfigurationKey()).isEqualTo("componentConfigurationKey");
140+
soft.assertThat(result.relationTypeKey()).isEqualTo("relationTypeKey");
141+
soft.assertThat(result.availableTransitions()).hasSize(1);
142+
soft.assertThat(result.availableTransitions().get(0).targetWorkflowStepKey()).isEqualTo("TEST_WORKFLOW_STEP_KEY");
143+
soft.assertThat(result.availableTransitions().get(0).stepTransitionReason()).isEqualTo(REPEAT);
144+
soft.assertThat(result.availableTransitions().get(0).mailTemplateKey()).isNull();
145+
soft.assertThat(result.availableTransitions().get(0).restrictedRoleGroups()).hasSize(1);
146+
soft.assertThat(result.availableTransitions().get(0).restrictedRoleGroups().get(0)).isEqualTo("ADMIN");
147+
});
148+
}
149+
112150

113151
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright (c) 2023 Contributors to the Eclipse Foundation
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* and Apache License v2.0 which accompanies this distribution.
6+
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7+
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
8+
*
9+
* You may elect to redistribute this code under either of these licenses.
10+
*
11+
* Contributors:
12+
*
13+
* Otavio Santana
14+
*/
15+
package org.eclipse.jnosql.databases.arangodb.integration;
16+
17+
import jakarta.nosql.Column;
18+
import org.eclipse.jnosql.mapping.Embeddable;
19+
20+
import java.util.List;
21+
22+
@Embeddable
23+
public class Transition {
24+
25+
@Column
26+
private String targetWorkflowStepKey;
27+
@Column
28+
private StepTransitionReason stepTransitionReason;
29+
@Column
30+
private String mailTemplateKey;
31+
@Column
32+
private List<String> restrictedRoleGroups;
33+
34+
public Transition(String targetWorkflowStepKey,
35+
StepTransitionReason stepTransitionReason,
36+
String mailTemplateKey,
37+
List<String> restrictedRoleGroups) {
38+
this.targetWorkflowStepKey = targetWorkflowStepKey;
39+
this.stepTransitionReason = stepTransitionReason;
40+
this.mailTemplateKey = mailTemplateKey;
41+
this.restrictedRoleGroups = restrictedRoleGroups;
42+
}
43+
44+
public Transition() {
45+
}
46+
47+
public String targetWorkflowStepKey() {
48+
return targetWorkflowStepKey;
49+
}
50+
51+
public StepTransitionReason stepTransitionReason() {
52+
return stepTransitionReason;
53+
}
54+
55+
public String mailTemplateKey() {
56+
return mailTemplateKey;
57+
}
58+
59+
public List<String> restrictedRoleGroups() {
60+
return restrictedRoleGroups;
61+
}
62+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
* Copyright (c) 2023 Contributors to the Eclipse Foundation
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* and Apache License v2.0 which accompanies this distribution.
6+
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7+
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
8+
*
9+
* You may elect to redistribute this code under either of these licenses.
10+
*
11+
* Contributors:
12+
*
13+
* Otavio Santana
14+
*/
15+
package org.eclipse.jnosql.databases.arangodb.integration;
16+
17+
import jakarta.nosql.Column;
18+
import jakarta.nosql.Entity;
19+
import jakarta.nosql.Id;
20+
21+
import java.util.List;
22+
23+
@Entity("workflow_step")
24+
public class WorkflowStep {
25+
26+
@Id
27+
private String id;
28+
29+
@Column("_key")
30+
private String key;
31+
32+
@Column
33+
private String workflowSchemaKey;
34+
35+
@Column
36+
private String stepName;
37+
38+
@Column
39+
private MainStepType mainStepType;
40+
41+
@Column
42+
private Integer stepNo;
43+
44+
@Column
45+
private String componentConfigurationKey;
46+
47+
@Column
48+
private String relationTypeKey;
49+
50+
@Column
51+
private List<Transition> availableTransitions;
52+
53+
WorkflowStep(String id, String key, String workflowSchemaKey,
54+
String stepName, MainStepType mainStepType,
55+
Integer stepNo, String componentConfigurationKey,
56+
String relationTypeKey, List<Transition> availableTransitions) {
57+
this.id = id;
58+
this.key = key;
59+
this.workflowSchemaKey = workflowSchemaKey;
60+
this.stepName = stepName;
61+
this.mainStepType = mainStepType;
62+
this.stepNo = stepNo;
63+
this.componentConfigurationKey = componentConfigurationKey;
64+
this.relationTypeKey = relationTypeKey;
65+
this.availableTransitions = availableTransitions;
66+
}
67+
68+
WorkflowStep() {
69+
}
70+
71+
public static WorkflowStepBuilder builder() {
72+
return new WorkflowStepBuilder();
73+
}
74+
75+
public String id() {
76+
return id;
77+
}
78+
79+
public String key() {
80+
return key;
81+
}
82+
83+
public String workflowSchemaKey() {
84+
return workflowSchemaKey;
85+
}
86+
87+
public String stepName() {
88+
return stepName;
89+
}
90+
91+
public MainStepType mainStepType() {
92+
return mainStepType;
93+
}
94+
95+
public Integer stepNo() {
96+
return stepNo;
97+
}
98+
99+
public String componentConfigurationKey() {
100+
return componentConfigurationKey;
101+
}
102+
103+
public String relationTypeKey() {
104+
return relationTypeKey;
105+
}
106+
107+
public List<Transition> availableTransitions() {
108+
return availableTransitions;
109+
}
110+
}

0 commit comments

Comments
 (0)