From 6a2b74e5651e8f1e15eaf74f31d529cfa7578000 Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Tue, 16 Feb 2016 17:37:34 +0100 Subject: [PATCH] Enabled target.assignedDs load through action enitygraph. Signed-off-by: Kai Zimmermann --- .../hawkbit/repository/DeploymentManagement.java | 4 ++-- .../eclipse/hawkbit/repository/model/Action.java | 3 ++- .../repository/DeploymentManagementTest.java | 16 ++++++++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java index b0a61395b..c9b08a554 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java @@ -710,8 +710,8 @@ public class DeploymentManagement { } /** - * Get the {@link Action} entity for given actionId with all lazy - * attributes. + * Get the {@link Action} entity for given actionId with all lazy attributes + * (i.e. distributionSet, target, target.assignedDs). * * @param actionId * to be id of the action diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Action.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Action.java index 0554e6c58..1f8a71d76 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Action.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Action.java @@ -24,6 +24,7 @@ import javax.persistence.ManyToOne; import javax.persistence.NamedAttributeNode; import javax.persistence.NamedEntityGraph; import javax.persistence.NamedEntityGraphs; +import javax.persistence.NamedSubgraph; import javax.persistence.OneToMany; import javax.persistence.Table; import javax.persistence.Transient; @@ -55,7 +56,7 @@ import org.eclipse.persistence.annotations.CascadeOnDelete; @Index(name = "sp_idx_action_prim", columnList = "tenant,id") }) @NamedEntityGraphs({ @NamedEntityGraph(name = "Action.ds", attributeNodes = { @NamedAttributeNode("distributionSet") }), @NamedEntityGraph(name = "Action.all", attributeNodes = { @NamedAttributeNode("distributionSet"), - @NamedAttributeNode("target") }) }) + @NamedAttributeNode(value = "target", subgraph = "target.ds") }, subgraphs = @NamedSubgraph(name = "target.ds", attributeNodes = @NamedAttributeNode("assignedDistributionSet") ) ) }) @Entity public class Action extends BaseEntity implements Comparable { private static final long serialVersionUID = 1L; diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DeploymentManagementTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DeploymentManagementTest.java index 5ad98069a..248f630db 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DeploymentManagementTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DeploymentManagementTest.java @@ -66,6 +66,22 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { @Autowired private EventBus eventBus; + @Test + @Description("Test verifies that the repistory retrieves the action including all defined (lazy) details.") + public void findActionWithLazyDetails() { + final DistributionSet testDs = TestDataUtil.generateDistributionSet("TestDs", "1.0", softwareManagement, + distributionSetManagement, new ArrayList()); + final List testTarget = targetManagement.createTargets(TestDataUtil.generateTargets(1)); + // one action with one action status is generated + final Action action = deploymentManagement.findActionWithDetails( + deploymentManagement.assignDistributionSet(testDs, testTarget).getActions().get(0)); + + assertThat(action.getDistributionSet()).as("DistributionSet in action").isNotNull(); + assertThat(action.getTarget()).as("Target in action").isNotNull(); + assertThat(action.getTarget().getAssignedDistributionSet()).as("AssignedDistributionSet of target in action") + .isNotNull(); + } + @Test @Description("Test verifies that the custom query to find all actions include the count of action status is working correctly") public void findActionsWithStatusCountByTarget() {