diff --git a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java index 279f882b9..7edf70c73 100644 --- a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java +++ b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java @@ -35,7 +35,6 @@ import org.eclipse.hawkbit.repository.ArtifactManagement; import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.RepositoryConstants; -import org.eclipse.hawkbit.repository.SoftwareModuleManagement; import org.eclipse.hawkbit.repository.SystemManagement; import org.eclipse.hawkbit.repository.builder.ActionStatusCreate; import org.eclipse.hawkbit.repository.event.remote.DownloadProgressEvent; @@ -94,9 +93,6 @@ public class DdiRootController implements DdiRootControllerRestApi { @Autowired private ControllerManagement controllerManagement; - @Autowired - private SoftwareModuleManagement softwareModuleManagement; - @Autowired private ArtifactManagement artifactManagement; @@ -124,10 +120,10 @@ public class DdiRootController implements DdiRootControllerRestApi { @PathVariable("softwareModuleId") final Long softwareModuleId) { LOG.debug("getSoftwareModulesArtifacts({})", controllerId); - final Target target = controllerManagement.findByControllerId(controllerId) + final Target target = controllerManagement.getByControllerId(controllerId) .orElseThrow(() -> new EntityNotFoundException(Target.class, controllerId)); - final SoftwareModule softwareModule = softwareModuleManagement.findSoftwareModuleById(softwareModuleId) + final SoftwareModule softwareModule = controllerManagement.getSoftwareModule(softwareModuleId) .orElseThrow(() -> new EntityNotFoundException(SoftwareModule.class, softwareModuleId)); return new ResponseEntity<>( @@ -155,9 +151,9 @@ public class DdiRootController implements DdiRootControllerRestApi { @PathVariable("fileName") final String fileName) { final ResponseEntity result; - final Target target = controllerManagement.findByControllerId(controllerId) + final Target target = controllerManagement.getByControllerId(controllerId) .orElseThrow(() -> new EntityNotFoundException(Target.class, controllerId)); - final SoftwareModule module = softwareModuleManagement.findSoftwareModuleById(softwareModuleId) + final SoftwareModule module = controllerManagement.getSoftwareModule(softwareModuleId) .orElseThrow(() -> new EntityNotFoundException(SoftwareModule.class, softwareModuleId)); if (checkModule(fileName, module)) { @@ -225,10 +221,10 @@ public class DdiRootController implements DdiRootControllerRestApi { @PathVariable("controllerId") final String controllerId, @PathVariable("softwareModuleId") final Long softwareModuleId, @PathVariable("fileName") final String fileName) { - controllerManagement.findByControllerId(controllerId) + controllerManagement.getByControllerId(controllerId) .orElseThrow(() -> new EntityNotFoundException(Target.class, controllerId)); - final SoftwareModule module = softwareModuleManagement.findSoftwareModuleById(softwareModuleId) + final SoftwareModule module = controllerManagement.getSoftwareModule(softwareModuleId) .orElseThrow(() -> new EntityNotFoundException(SoftwareModule.class, softwareModuleId)); if (checkModule(fileName, module)) { @@ -259,7 +255,7 @@ public class DdiRootController implements DdiRootControllerRestApi { @RequestParam(value = "actionHistory", defaultValue = DdiRestConstants.NO_ACTION_HISTORY) final Integer actionHistoryMessageCount) { LOG.debug("getControllerBasedeploymentAction({},{})", controllerId, resource); - final Target target = controllerManagement.findByControllerId(controllerId) + final Target target = controllerManagement.getByControllerId(controllerId) .orElseThrow(() -> new EntityNotFoundException(Target.class, controllerId)); final Action action = findActionWithExceptionIfNotFound(actionId); @@ -303,7 +299,7 @@ public class DdiRootController implements DdiRootControllerRestApi { @PathVariable("actionId") @NotEmpty final Long actionId) { LOG.debug("provideBasedeploymentActionFeedback for target [{},{}]: {}", controllerId, actionId, feedback); - final Target target = controllerManagement.findByControllerId(controllerId) + final Target target = controllerManagement.getByControllerId(controllerId) .orElseThrow(() -> new EntityNotFoundException(Target.class, controllerId)); if (!actionId.equals(feedback.getId())) { @@ -404,7 +400,7 @@ public class DdiRootController implements DdiRootControllerRestApi { @PathVariable("actionId") @NotEmpty final Long actionId) { LOG.debug("getControllerCancelAction({})", controllerId); - final Target target = controllerManagement.findByControllerId(controllerId) + final Target target = controllerManagement.getByControllerId(controllerId) .orElseThrow(() -> new EntityNotFoundException(Target.class, controllerId)); final Action action = findActionWithExceptionIfNotFound(actionId); @@ -435,7 +431,7 @@ public class DdiRootController implements DdiRootControllerRestApi { @PathVariable("actionId") @NotEmpty final Long actionId) { LOG.debug("provideCancelActionFeedback for target [{}]: {}", controllerId, feedback); - final Target target = controllerManagement.findByControllerId(controllerId) + final Target target = controllerManagement.getByControllerId(controllerId) .orElseThrow(() -> new EntityNotFoundException(Target.class, controllerId)); if (!actionId.equals(feedback.getId())) { diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactDownloadTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactDownloadTest.java index b84de5467..982d1547d 100644 --- a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactDownloadTest.java +++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactDownloadTest.java @@ -85,7 +85,7 @@ public class DdiArtifactDownloadTest extends AbstractDDiApiIntegrationTest { // create artifact final byte random[] = RandomUtils.nextBytes(5 * 1024); - final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random), + final Artifact artifact = artifactManagement.create(new ByteArrayInputStream(random), ds.findFirstModuleByType(osType).get().getId(), "file1", false); // no artifact available @@ -160,7 +160,7 @@ public class DdiArtifactDownloadTest extends AbstractDDiApiIntegrationTest { public void downloadArtifactThroughFileName() throws Exception { downLoadProgress = 1; shippedBytes = 0; - assertThat(softwareModuleManagement.findSoftwareModulesAll(PAGE)).hasSize(0); + assertThat(softwareModuleManagement.findAll(PAGE)).hasSize(0); // create target final Target target = testdataFactory.createTarget(); @@ -171,7 +171,7 @@ public class DdiArtifactDownloadTest extends AbstractDDiApiIntegrationTest { // create artifact final byte random[] = RandomUtils.nextBytes(ARTIFACT_SIZE); - final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random), + final Artifact artifact = artifactManagement.create(new ByteArrayInputStream(random), ds.findFirstModuleByType(osType).get().getId(), "file1", false); // download fails as artifact is not yet assigned @@ -210,7 +210,7 @@ public class DdiArtifactDownloadTest extends AbstractDDiApiIntegrationTest { // create artifact final byte random[] = RandomUtils.nextBytes(5 * 1024); - final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random), getOsModule(ds), + final Artifact artifact = artifactManagement.create(new ByteArrayInputStream(random), getOsModule(ds), "file1", false); // download @@ -242,7 +242,7 @@ public class DdiArtifactDownloadTest extends AbstractDDiApiIntegrationTest { // create artifact final byte random[] = RandomUtils.nextBytes(resultLength); - final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random), getOsModule(ds), + final Artifact artifact = artifactManagement.create(new ByteArrayInputStream(random), getOsModule(ds), "file1", false); assertThat(random.length).isEqualTo(resultLength); diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiCancelActionTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiCancelActionTest.java index fee39c205..56f395741 100644 --- a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiCancelActionTest.java +++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiCancelActionTest.java @@ -92,8 +92,9 @@ public class DdiCancelActionTest extends AbstractDDiApiIntegrationTest { .isEqualTo(ds); assertThat(deploymentManagement.getInstalledDistributionSet(TestdataFactory.DEFAULT_CONTROLLER_ID).get()) .isEqualTo(ds); - assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get() - .getInstallationDate()).isGreaterThanOrEqualTo(current); + assertThat( + targetManagement.getByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get().getInstallationDate()) + .isGreaterThanOrEqualTo(current); } @@ -117,10 +118,10 @@ public class DdiCancelActionTest extends AbstractDDiApiIntegrationTest { Thread.sleep(1); // is required: otherwise processing the next line is // often too fast and // the following assert will fail - assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get() - .getLastTargetQuery()).isLessThanOrEqualTo(System.currentTimeMillis()); - assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get() - .getLastTargetQuery()).isGreaterThanOrEqualTo(current); + assertThat(targetManagement.getByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get().getLastTargetQuery()) + .isLessThanOrEqualTo(System.currentTimeMillis()); + assertThat(targetManagement.getByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get().getLastTargetQuery()) + .isGreaterThanOrEqualTo(current); // Retrieved is reported @@ -150,22 +151,22 @@ public class DdiCancelActionTest extends AbstractDDiApiIntegrationTest { Thread.sleep(1); // is required: otherwise processing the next line is // often too fast and // the following assert will fail - assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get() - .getLastTargetQuery()).isLessThanOrEqualTo(System.currentTimeMillis()); - assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get() - .getLastTargetQuery()).isGreaterThanOrEqualTo(current); + assertThat(targetManagement.getByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get().getLastTargetQuery()) + .isLessThanOrEqualTo(System.currentTimeMillis()); + assertThat(targetManagement.getByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get().getLastTargetQuery()) + .isGreaterThanOrEqualTo(current); current = System.currentTimeMillis(); - assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get() - .getLastTargetQuery()).isLessThanOrEqualTo(System.currentTimeMillis()); + assertThat(targetManagement.getByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get().getLastTargetQuery()) + .isLessThanOrEqualTo(System.currentTimeMillis()); mvc.perform(get("/{tenant}/controller/v1/" + TestdataFactory.DEFAULT_CONTROLLER_ID + "/cancelAction/" + cancelAction.getId(), tenantAware.getCurrentTenant()).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andExpect(jsonPath("$.id", equalTo(String.valueOf(cancelAction.getId())))) .andExpect(jsonPath("$.cancelAction.stopId", equalTo(String.valueOf(actionId)))); - assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get() - .getLastTargetQuery()).isLessThanOrEqualTo(System.currentTimeMillis()); + assertThat(targetManagement.getByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get().getLastTargetQuery()) + .isLessThanOrEqualTo(System.currentTimeMillis()); // controller confirmed cancelled action, should not be active anymore mvc.perform(post("/{tenant}/controller/v1/" + TestdataFactory.DEFAULT_CONTROLLER_ID + "/cancelAction/" diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiConfigDataTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiConfigDataTest.java index 0dd4d321a..4baf38ec7 100644 --- a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiConfigDataTest.java +++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiConfigDataTest.java @@ -60,9 +60,9 @@ public class DdiConfigDataTest extends AbstractDDiApiIntegrationTest { Thread.sleep(1); // is required: otherwise processing the next line is // often too fast and // the following assert will fail - assertThat(targetManagement.findTargetByControllerID("4712").get().getLastTargetQuery()) + assertThat(targetManagement.getByControllerID("4712").get().getLastTargetQuery()) .isLessThanOrEqualTo(System.currentTimeMillis()); - assertThat(targetManagement.findTargetByControllerID("4712").get().getLastTargetQuery()) + assertThat(targetManagement.getByControllerID("4712").get().getLastTargetQuery()) .isGreaterThanOrEqualTo(current); final Map attributes = Maps.newHashMapWithExpectedSize(1); diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiDeploymentBaseTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiDeploymentBaseTest.java index bc6d2ef73..a7a4409eb 100644 --- a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiDeploymentBaseTest.java +++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiDeploymentBaseTest.java @@ -111,9 +111,9 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest { final DistributionSet ds2 = testdataFactory.createDistributionSet("2", true); final byte random[] = RandomUtils.nextBytes(5 * 1024); - final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random), getOsModule(ds), + final Artifact artifact = artifactManagement.create(new ByteArrayInputStream(random), getOsModule(ds), "test1", false); - final Artifact artifactSignature = artifactManagement.createArtifact(new ByteArrayInputStream(random), + final Artifact artifactSignature = artifactManagement.create(new ByteArrayInputStream(random), getOsModule(ds), "test1.signature", false); final Target savedTarget = testdataFactory.createTarget("4712"); @@ -147,16 +147,15 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest { .andExpect(jsonPath("$.config.polling.sleep", equalTo("00:01:00"))) .andExpect(jsonPath("$._links.deploymentBase.href", startsWith("http://localhost/" + tenantAware.getCurrentTenant() + "/controller/v1/4712/deploymentBase/" + uaction.getId()))); - assertThat(targetManagement.findTargetByControllerID("4712").get().getLastTargetQuery()) + assertThat(targetManagement.getByControllerID("4712").get().getLastTargetQuery()) .isGreaterThanOrEqualTo(current); - assertThat(targetManagement.findTargetByControllerID("4712").get().getLastTargetQuery()) + assertThat(targetManagement.getByControllerID("4712").get().getLastTargetQuery()) .isLessThanOrEqualTo(System.currentTimeMillis()); assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(2); current = System.currentTimeMillis(); - final DistributionSet findDistributionSetByAction = distributionSetManagement - .findDistributionSetByAction(action.getId()).get(); + final DistributionSet findDistributionSetByAction = distributionSetManagement.getByAction(action.getId()).get(); mvc.perform( get("/{tenant}/controller/v1/4712/deploymentBase/" + uaction.getId(), tenantAware.getCurrentTenant()) @@ -268,9 +267,9 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest { final DistributionSet ds2 = testdataFactory.createDistributionSet("2", true); final byte random[] = RandomUtils.nextBytes(5 * 1024); - final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random), getOsModule(ds), + final Artifact artifact = artifactManagement.create(new ByteArrayInputStream(random), getOsModule(ds), "test1", false); - final Artifact artifactSignature = artifactManagement.createArtifact(new ByteArrayInputStream(random), + final Artifact artifactSignature = artifactManagement.create(new ByteArrayInputStream(random), getOsModule(ds), "test1.signature", false); final Target savedTarget = testdataFactory.createTarget("4712"); @@ -305,14 +304,13 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest { .andExpect(jsonPath("$.config.polling.sleep", equalTo("00:01:00"))) .andExpect(jsonPath("$._links.deploymentBase.href", startsWith("http://localhost/" + tenantAware.getCurrentTenant() + "/controller/v1/4712/deploymentBase/" + uaction.getId()))); - assertThat(targetManagement.findTargetByControllerID("4712").get().getLastTargetQuery()) + assertThat(targetManagement.getByControllerID("4712").get().getLastTargetQuery()) .isGreaterThanOrEqualTo(current); - assertThat(targetManagement.findTargetByControllerID("4712").get().getLastTargetQuery()) + assertThat(targetManagement.getByControllerID("4712").get().getLastTargetQuery()) .isLessThanOrEqualTo(System.currentTimeMillis()); assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(2); - final DistributionSet findDistributionSetByAction = distributionSetManagement - .findDistributionSetByAction(action.getId()).get(); + final DistributionSet findDistributionSetByAction = distributionSetManagement.getByAction(action.getId()).get(); mvc.perform( get("/{tenant}/controller/v1/4712/deploymentBase/" + uaction.getId(), tenantAware.getCurrentTenant()) @@ -383,9 +381,9 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest { final DistributionSet ds2 = testdataFactory.createDistributionSet("2", true); final byte random[] = RandomUtils.nextBytes(5 * 1024); - final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random), getOsModule(ds), + final Artifact artifact = artifactManagement.create(new ByteArrayInputStream(random), getOsModule(ds), "test1", false); - final Artifact artifactSignature = artifactManagement.createArtifact(new ByteArrayInputStream(random), + final Artifact artifactSignature = artifactManagement.create(new ByteArrayInputStream(random), getOsModule(ds), "test1.signature", false); final Target savedTarget = testdataFactory.createTarget("4712"); @@ -419,16 +417,15 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest { .andExpect(jsonPath("$.config.polling.sleep", equalTo("00:01:00"))) .andExpect(jsonPath("$._links.deploymentBase.href", startsWith("http://localhost/" + tenantAware.getCurrentTenant() + "/controller/v1/4712/deploymentBase/" + uaction.getId()))); - assertThat(targetManagement.findTargetByControllerID("4712").get().getLastTargetQuery()) + assertThat(targetManagement.getByControllerID("4712").get().getLastTargetQuery()) .isGreaterThanOrEqualTo(current); - assertThat(targetManagement.findTargetByControllerID("4712").get().getLastTargetQuery()) + assertThat(targetManagement.getByControllerID("4712").get().getLastTargetQuery()) .isLessThanOrEqualTo(System.currentTimeMillis()); assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(2); current = System.currentTimeMillis(); - final DistributionSet findDistributionSetByAction = distributionSetManagement - .findDistributionSetByAction(action.getId()).get(); + final DistributionSet findDistributionSetByAction = distributionSetManagement.getByAction(action.getId()).get(); mvc.perform(get("/{tenant}/controller/v1/4712/deploymentBase/{actionId}", tenantAware.getCurrentTenant(), uaction.getId()).accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()) @@ -596,13 +593,12 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest { final Long actionId2 = assignDistributionSet(ds2.getId(), "4712").getActions().get(0); final Long actionId3 = assignDistributionSet(ds3.getId(), "4712").getActions().get(0); - Target myT = targetManagement.findTargetByControllerID("4712").get(); + Target myT = targetManagement.getByControllerID("4712").get(); assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING); assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, myT.getControllerId())).hasSize(3); assertThat(deploymentManagement.getAssignedDistributionSet(myT.getControllerId()).get()).isEqualTo(ds3); assertThat(deploymentManagement.getInstalledDistributionSet(myT.getControllerId())).isNotPresent(); - assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.UNKNOWN)) - .hasSize(2); + assertThat(targetManagement.findByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.UNKNOWN)).hasSize(2); // action1 done @@ -611,7 +607,7 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest { .content(JsonBuilder.deploymentActionFeedback(actionId1.toString(), "closed")) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); - myT = targetManagement.findTargetByControllerID("4712").get(); + myT = targetManagement.getByControllerID("4712").get(); assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING); assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, myT.getControllerId())).hasSize(2); assertThat(deploymentManagement.getAssignedDistributionSet(myT.getControllerId()).get()).isEqualTo(ds3); @@ -628,7 +624,7 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest { .content(JsonBuilder.deploymentActionFeedback(actionId2.toString(), "closed")) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); - myT = targetManagement.findTargetByControllerID("4712").get(); + myT = targetManagement.getByControllerID("4712").get(); assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING); assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, myT.getControllerId())).hasSize(1); @@ -645,7 +641,7 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest { .content(JsonBuilder.deploymentActionFeedback(actionId3.toString(), "closed")) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); - myT = targetManagement.findTargetByControllerID("4712").get(); + myT = targetManagement.getByControllerID("4712").get(); assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC); assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, myT.getControllerId())).hasSize(0); assertThat(deploymentManagement.getAssignedDistributionSet(myT.getControllerId()).get()).isEqualTo(ds3); @@ -666,7 +662,7 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest { final List toAssign = new ArrayList<>(); toAssign.add(savedTarget); - assertThat(targetManagement.findTargetByControllerID("4712").get().getUpdateStatus()) + assertThat(targetManagement.getByControllerID("4712").get().getUpdateStatus()) .isEqualTo(TargetUpdateStatus.UNKNOWN); assignDistributionSet(ds, toAssign); final Action action = deploymentManagement.findActionsByDistributionSet(PAGE, ds.getId()).getContent().get(0); @@ -677,15 +673,12 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest { "error message")) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); - Target myT = targetManagement.findTargetByControllerID("4712").get(); - assertThat(targetManagement.findTargetByControllerID("4712").get().getUpdateStatus()) + Target myT = targetManagement.getByControllerID("4712").get(); + assertThat(targetManagement.getByControllerID("4712").get().getUpdateStatus()) .isEqualTo(TargetUpdateStatus.ERROR); - assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.PENDING)) - .hasSize(0); - assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.ERROR)) - .hasSize(1); - assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.IN_SYNC)) - .hasSize(0); + assertThat(targetManagement.findByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.PENDING)).hasSize(0); + assertThat(targetManagement.findByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.ERROR)).hasSize(1); + assertThat(targetManagement.findByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.IN_SYNC)).hasSize(0); assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, myT.getControllerId())).hasSize(0); assertThat(deploymentManagement.countActionsByTarget(myT.getControllerId())).isEqualTo(1); final Iterable actionStatusMessages = deploymentManagement @@ -694,8 +687,8 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest { assertThat(actionStatusMessages).haveAtLeast(1, new ActionStatusCondition(Status.ERROR)); // redo - ds = distributionSetManagement.findDistributionSetByIdWithDetails(ds.getId()).get(); - assignDistributionSet(ds, Arrays.asList(targetManagement.findTargetByControllerID("4712").get())); + ds = distributionSetManagement.getWithDetails(ds.getId()).get(); + assignDistributionSet(ds, Arrays.asList(targetManagement.getByControllerID("4712").get())); final Action action2 = deploymentManagement.findActiveActionsByTarget(PAGE, myT.getControllerId()).getContent() .get(0); @@ -705,14 +698,11 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest { .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); - myT = targetManagement.findTargetByControllerID("4712").get(); + myT = targetManagement.getByControllerID("4712").get(); assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC); - assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.PENDING)) - .hasSize(0); - assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.ERROR)) - .hasSize(0); - assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.IN_SYNC)) - .hasSize(1); + assertThat(targetManagement.findByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.PENDING)).hasSize(0); + assertThat(targetManagement.findByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.ERROR)).hasSize(0); + assertThat(targetManagement.findByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.IN_SYNC)).hasSize(1); assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, myT.getControllerId())).hasSize(0); assertThat(deploymentManagement.findInActiveActionsByTarget(PAGE, myT.getControllerId())).hasSize(2); assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(4); @@ -732,15 +722,15 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest { final List toAssign = Arrays.asList(savedTarget); - Target myT = targetManagement.findTargetByControllerID("4712").get(); + Target myT = targetManagement.getByControllerID("4712").get(); assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.UNKNOWN); assignDistributionSet(ds, toAssign); final Action action = deploymentManagement.findActionsByDistributionSet(PAGE, ds.getId()).getContent().get(0); - myT = targetManagement.findTargetByControllerID("4712").get(); + myT = targetManagement.getByControllerID("4712").get(); assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING); - assertThat(targetManagement.findTargetByInstalledDistributionSet(ds.getId(), PAGE)).hasSize(0); - assertThat(targetManagement.findTargetByAssignedDistributionSet(ds.getId(), PAGE)).hasSize(1); + assertThat(targetManagement.findByInstalledDistributionSet(PAGE, ds.getId())).hasSize(0); + assertThat(targetManagement.findByAssignedDistributionSet(PAGE, ds.getId())).hasSize(1); // Now valid Feedback for (int i = 0; i < 4; i++) { @@ -751,14 +741,11 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest { .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); } - myT = targetManagement.findTargetByControllerID("4712").get(); + myT = targetManagement.getByControllerID("4712").get(); assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING); - assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.PENDING)) - .hasSize(1); - assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.ERROR)) - .hasSize(0); - assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.IN_SYNC)) - .hasSize(0); + assertThat(targetManagement.findByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.PENDING)).hasSize(1); + assertThat(targetManagement.findByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.ERROR)).hasSize(0); + assertThat(targetManagement.findByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.IN_SYNC)).hasSize(0); assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, myT.getControllerId())).hasSize(1); assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(5); assertThat(deploymentManagement.findActionStatusAll(PAGE).getContent()).haveAtLeast(5, @@ -769,14 +756,11 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest { .content(JsonBuilder.deploymentActionFeedback(action.getId().toString(), "scheduled")) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); - myT = targetManagement.findTargetByControllerID("4712").get(); + myT = targetManagement.getByControllerID("4712").get(); assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING); - assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.PENDING)) - .hasSize(1); - assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.ERROR)) - .hasSize(0); - assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.IN_SYNC)) - .hasSize(0); + assertThat(targetManagement.findByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.PENDING)).hasSize(1); + assertThat(targetManagement.findByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.ERROR)).hasSize(0); + assertThat(targetManagement.findByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.IN_SYNC)).hasSize(0); assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, myT.getControllerId())).hasSize(1); assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(6); assertThat(deploymentManagement.findActionStatusAll(PAGE).getContent()).haveAtLeast(5, @@ -787,14 +771,11 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest { .content(JsonBuilder.deploymentActionFeedback(action.getId().toString(), "resumed")) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); - myT = targetManagement.findTargetByControllerID("4712").get(); + myT = targetManagement.getByControllerID("4712").get(); assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING); - assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.PENDING)) - .hasSize(1); - assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.ERROR)) - .hasSize(0); - assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.IN_SYNC)) - .hasSize(0); + assertThat(targetManagement.findByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.PENDING)).hasSize(1); + assertThat(targetManagement.findByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.ERROR)).hasSize(0); + assertThat(targetManagement.findByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.IN_SYNC)).hasSize(0); assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, myT.getControllerId())).hasSize(1); assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(7); assertThat(deploymentManagement.findActionStatusAll(PAGE).getContent()).haveAtLeast(6, @@ -805,15 +786,12 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest { .content(JsonBuilder.deploymentActionFeedback(action.getId().toString(), "canceled")) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); - myT = targetManagement.findTargetByControllerID("4712").get(); + myT = targetManagement.getByControllerID("4712").get(); assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING); assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, myT.getControllerId())).hasSize(1); - assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.PENDING)) - .hasSize(1); - assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.ERROR)) - .hasSize(0); - assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.IN_SYNC)) - .hasSize(0); + assertThat(targetManagement.findByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.PENDING)).hasSize(1); + assertThat(targetManagement.findByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.ERROR)).hasSize(0); + assertThat(targetManagement.findByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.IN_SYNC)).hasSize(0); assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(8); assertThat(deploymentManagement.findActionStatusAll(PAGE).getContent()).haveAtLeast(7, @@ -826,7 +804,7 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest { .content(JsonBuilder.deploymentActionFeedback(action.getId().toString(), "rejected")) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); - myT = targetManagement.findTargetByControllerID("4712").get(); + myT = targetManagement.getByControllerID("4712").get(); assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING); assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, myT.getControllerId())).hasSize(1); assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(9); @@ -842,13 +820,11 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest { .content(JsonBuilder.deploymentActionFeedback(action.getId().toString(), "closed")) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); - myT = targetManagement.findTargetByControllerID("4712").get(); + myT = targetManagement.getByControllerID("4712").get(); assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC); assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, myT.getControllerId())).hasSize(0); - assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.ERROR)) - .hasSize(0); - assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.IN_SYNC)) - .hasSize(1); + assertThat(targetManagement.findByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.ERROR)).hasSize(0); + assertThat(targetManagement.findByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.IN_SYNC)).hasSize(1); assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(10); assertThat(deploymentManagement.findActionStatusAll(PAGE).getContent()).haveAtLeast(7, @@ -860,8 +836,8 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest { assertThat(deploymentManagement.findActionStatusAll(PAGE).getContent()).haveAtLeast(1, new ActionStatusCondition(Status.FINISHED)); - assertThat(targetManagement.findTargetByInstalledDistributionSet(ds.getId(), PAGE)).hasSize(1); - assertThat(targetManagement.findTargetByAssignedDistributionSet(ds.getId(), PAGE)).hasSize(1); + assertThat(targetManagement.findByInstalledDistributionSet(PAGE, ds.getId())).hasSize(1); + assertThat(targetManagement.findByAssignedDistributionSet(PAGE, ds.getId())).hasSize(1); } @Test diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootControllerTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootControllerTest.java index 10fb35e3a..bad2d28f0 100644 --- a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootControllerTest.java +++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootControllerTest.java @@ -103,8 +103,7 @@ public class DdiRootControllerTest extends AbstractDDiApiIntegrationTest { final String knownTargetControllerId = "target1"; final String knownCreatedBy = "knownPrincipal"; testdataFactory.createTarget(knownTargetControllerId); - final Target findTargetByControllerID = targetManagement.findTargetByControllerID(knownTargetControllerId) - .get(); + final Target findTargetByControllerID = targetManagement.getByControllerID(knownTargetControllerId).get(); assertThat(findTargetByControllerID.getCreatedBy()).isEqualTo(knownCreatedBy); assertThat(findTargetByControllerID.getCreatedAt()).isNotNull(); @@ -117,7 +116,7 @@ public class DdiRootControllerTest extends AbstractDDiApiIntegrationTest { }); // verify that audit information has not changed - final Target targetVerify = targetManagement.findTargetByControllerID(knownTargetControllerId).get(); + final Target targetVerify = targetManagement.getByControllerID(knownTargetControllerId).get(); assertThat(targetVerify.getCreatedBy()).isEqualTo(findTargetByControllerID.getCreatedBy()); assertThat(targetVerify.getCreatedAt()).isEqualTo(findTargetByControllerID.getCreatedAt()); assertThat(targetVerify.getLastModifiedBy()).isEqualTo(findTargetByControllerID.getLastModifiedBy()); @@ -141,10 +140,10 @@ public class DdiRootControllerTest extends AbstractDDiApiIntegrationTest { mvc.perform(get("/default-tenant/controller/v1/4711")).andDo(MockMvcResultPrinter.print()) .andExpect(status().isOk()).andExpect(content().contentType(APPLICATION_JSON_HAL_UTF)) .andExpect(jsonPath("$.config.polling.sleep", equalTo("00:01:00"))); - assertThat(targetManagement.findTargetByControllerID("4711").get().getLastTargetQuery()) + assertThat(targetManagement.getByControllerID("4711").get().getLastTargetQuery()) .isGreaterThanOrEqualTo(current); - assertThat(targetManagement.findTargetByControllerID("4711").get().getUpdateStatus()) + assertThat(targetManagement.getByControllerID("4711").get().getUpdateStatus()) .isEqualTo(TargetUpdateStatus.REGISTERED); // not allowed methods @@ -198,7 +197,7 @@ public class DdiRootControllerTest extends AbstractDDiApiIntegrationTest { mvc.perform(get("/{tenant}/controller/v1/4711", tenantAware.getCurrentTenant()).header("If-None-Match", etag)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isNotModified()); - final Target target = targetManagement.findTargetByControllerID("4711").get(); + final Target target = targetManagement.getByControllerID("4711").get(); final DistributionSet ds = testdataFactory.createDistributionSet(""); assignDistributionSet(ds.getId(), "4711"); @@ -259,7 +258,7 @@ public class DdiRootControllerTest extends AbstractDDiApiIntegrationTest { public void rootRsPrecommissioned() throws Exception { final Target target = testdataFactory.createTarget("4711"); - assertThat(targetManagement.findTargetByControllerID("4711").get().getUpdateStatus()) + assertThat(targetManagement.getByControllerID("4711").get().getUpdateStatus()) .isEqualTo(TargetUpdateStatus.UNKNOWN); final long current = System.currentTimeMillis(); @@ -268,12 +267,12 @@ public class DdiRootControllerTest extends AbstractDDiApiIntegrationTest { .andExpect(content().contentType(APPLICATION_JSON_HAL_UTF)) .andExpect(jsonPath("$.config.polling.sleep", equalTo("00:01:00"))); - assertThat(targetManagement.findTargetByControllerID("4711").get().getLastTargetQuery()) + assertThat(targetManagement.getByControllerID("4711").get().getLastTargetQuery()) .isLessThanOrEqualTo(System.currentTimeMillis()); - assertThat(targetManagement.findTargetByControllerID("4711").get().getLastTargetQuery()) + assertThat(targetManagement.getByControllerID("4711").get().getLastTargetQuery()) .isGreaterThanOrEqualTo(current); - assertThat(targetManagement.findTargetByControllerID("4711").get().getUpdateStatus()) + assertThat(targetManagement.getByControllerID("4711").get().getUpdateStatus()) .isEqualTo(TargetUpdateStatus.REGISTERED); } @@ -295,7 +294,7 @@ public class DdiRootControllerTest extends AbstractDDiApiIntegrationTest { }); // verify - final Target target = targetManagement.findTargetByControllerID(knownControllerId1).get(); + final Target target = targetManagement.getByControllerID(knownControllerId1).get(); assertThat(target.getAddress()).isEqualTo(IpUtil.createHttpUri("127.0.0.1")); assertThat(target.getCreatedBy()).isEqualTo("CONTROLLER_PLUG_AND_PLAY"); assertThat(target.getCreatedAt()).isGreaterThanOrEqualTo(create); @@ -317,7 +316,7 @@ public class DdiRootControllerTest extends AbstractDDiApiIntegrationTest { .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); // verify - final Target target = targetManagement.findTargetByControllerID(knownControllerId1).get(); + final Target target = targetManagement.getByControllerID(knownControllerId1).get(); assertThat(target.getAddress()).isEqualTo(IpUtil.createHttpUri("***")); securityProperties.getClients().setTrackRemoteIp(true); @@ -336,8 +335,8 @@ public class DdiRootControllerTest extends AbstractDDiApiIntegrationTest { Target savedTarget = testdataFactory.createTarget("911"); savedTarget = assignDistributionSet(ds.getId(), savedTarget.getControllerId()).getAssignedEntity().iterator() .next(); - final Action savedAction = deploymentManagement - .findActiveActionsByTarget(PAGE, savedTarget.getControllerId()).getContent().get(0); + final Action savedAction = deploymentManagement.findActiveActionsByTarget(PAGE, savedTarget.getControllerId()) + .getContent().get(0); mvc.perform(post("/{tenant}/controller/v1/911/deploymentBase/" + savedAction.getId() + "/feedback", tenantAware.getCurrentTenant()) .content(JsonBuilder.deploymentActionFeedback(savedAction.getId().toString(), "proceeding")) diff --git a/hawkbit-dmf/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpAuthenticationMessageHandler.java b/hawkbit-dmf/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpAuthenticationMessageHandler.java index 504368b49..a3f7e4351 100644 --- a/hawkbit-dmf/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpAuthenticationMessageHandler.java +++ b/hawkbit-dmf/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpAuthenticationMessageHandler.java @@ -168,19 +168,19 @@ public class AmqpAuthenticationMessageHandler extends BaseAmqpService { } if (fileResource.getSha1() != null) { - return artifactManagement.findFirstArtifactBySHA1(fileResource.getSha1()); + return artifactManagement.findFirstBySHA1(fileResource.getSha1()); } if (fileResource.getFilename() != null) { - return artifactManagement.findArtifactByFilename(fileResource.getFilename()); + return artifactManagement.getByFilename(fileResource.getFilename()); } if (fileResource.getArtifactId() != null) { - return artifactManagement.findArtifact(fileResource.getArtifactId()); + return artifactManagement.get(fileResource.getArtifactId()); } if (fileResource.getSoftwareModuleFilenameResource() != null) { - return artifactManagement.findByFilenameAndSoftwareModule( + return artifactManagement.getByFilenameAndSoftwareModule( fileResource.getSoftwareModuleFilenameResource().getFilename(), fileResource.getSoftwareModuleFilenameResource().getSoftwareModuleId()); } diff --git a/hawkbit-dmf/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java b/hawkbit-dmf/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java index abe32bdf2..efc3e4ab8 100644 --- a/hawkbit-dmf/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java +++ b/hawkbit-dmf/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java @@ -113,7 +113,7 @@ public class AmqpMessageDispatcherService extends BaseAmqpService { LOG.debug("targetAssignDistributionSet retrieved for controller {}. I will forward it to DMF broker.", assignedEvent.getControllerId()); - targetManagement.findTargetByControllerID(assignedEvent.getControllerId()) + targetManagement.getByControllerID(assignedEvent.getControllerId()) .ifPresent(target -> sendUpdateMessageToTarget(assignedEvent.getTenant(), target, assignedEvent.getActionId(), assignedEvent.getModules())); diff --git a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpControllerAuthenticationTest.java b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpControllerAuthenticationTest.java index f91c40824..075650ee5 100644 --- a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpControllerAuthenticationTest.java +++ b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpControllerAuthenticationTest.java @@ -137,8 +137,8 @@ public class AmqpControllerAuthenticationTest { .thenReturn(CONFIG_VALUE_FALSE); final ControllerManagement controllerManagement = mock(ControllerManagement.class); - when(controllerManagement.findByControllerId(anyString())).thenReturn(Optional.of(targteMock)); - when(controllerManagement.findByTargetId(any(Long.class))).thenReturn(Optional.of(targteMock)); + when(controllerManagement.getByControllerId(anyString())).thenReturn(Optional.of(targteMock)); + when(controllerManagement.get(any(Long.class))).thenReturn(Optional.of(targteMock)); when(targteMock.getSecurityToken()).thenReturn(CONTROLLER_ID); when(targteMock.getControllerId()).thenReturn(CONTROLLER_ID); @@ -159,8 +159,8 @@ public class AmqpControllerAuthenticationTest { new JpaSoftwareModuleType("a key", "a name", null, 1), "a name", null, null, null)); testArtifact.setId(1L); - when(artifactManagementMock.findArtifact(ARTIFACT_ID)).thenReturn(Optional.of(testArtifact)); - when(artifactManagementMock.findFirstArtifactBySHA1(SHA1)).thenReturn(Optional.of(testArtifact)); + when(artifactManagementMock.get(ARTIFACT_ID)).thenReturn(Optional.of(testArtifact)); + when(artifactManagementMock.findFirstBySHA1(SHA1)).thenReturn(Optional.of(testArtifact)); final AbstractDbArtifact artifact = new ArtifactFilesystem(new File("does not exist"), SHA1, new DbArtifactHash(SHA1, "md5 test"), ARTIFACT_SIZE, null); diff --git a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java index dcc110dcb..65b727bf8 100644 --- a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java +++ b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java @@ -88,7 +88,7 @@ public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTest { @Override public void before() throws Exception { super.before(); - testTarget = targetManagement.createTarget(entityFactory.target().create().controllerId(CONTROLLER_ID) + testTarget = targetManagement.create(entityFactory.target().create().controllerId(CONTROLLER_ID) .securityToken(TEST_TOKEN).address(AMQP_URI.toString())); this.rabbitTemplate = Mockito.mock(RabbitTemplate.class); @@ -128,8 +128,8 @@ public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTest { } private Message getCaptureAdressEvent(final TargetAssignDistributionSetEvent targetAssignDistributionSetEvent) { - final Target target = targetManagement - .findTargetByControllerID(targetAssignDistributionSetEvent.getControllerId()).get(); + final Target target = targetManagement.getByControllerID(targetAssignDistributionSetEvent.getControllerId()) + .get(); final Message sendMessage = createArgumentCapture(target.getAddress()); return sendMessage; } @@ -181,8 +181,8 @@ public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTest { receivedList.add(new ArtifactFilesystem(new File("./test"), artifact.getSha1Hash(), new DbArtifactHash(artifact.getSha1Hash(), null), artifact.getSize(), null)); } - module = softwareModuleManagement.findSoftwareModuleById(module.getId()).get(); - dsA = distributionSetManagement.findDistributionSetById(dsA.getId()).get(); + module = softwareModuleManagement.get(module.getId()).get(); + dsA = distributionSetManagement.get(dsA.getId()).get(); final Action action = createAction(dsA); diff --git a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java index 85892a3e1..a70e11c1d 100644 --- a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java +++ b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java @@ -129,7 +129,7 @@ public class AmqpMessageHandlerServiceTest { public void before() throws Exception { messageConverter = new Jackson2JsonMessageConverter(); when(rabbitTemplate.getMessageConverter()).thenReturn(messageConverter); - when(artifactManagementMock.findFirstArtifactBySHA1(SHA1)).thenReturn(Optional.empty()); + when(artifactManagementMock.findFirstBySHA1(SHA1)).thenReturn(Optional.empty()); amqpMessageHandlerService = new AmqpMessageHandlerService(rabbitTemplate, amqpMessageDispatcherServiceMock, controllerManagementMock, entityFactoryMock); @@ -344,7 +344,7 @@ public class AmqpMessageHandlerServiceTest { messageProperties); final Artifact localArtifactMock = mock(Artifact.class); - when(artifactManagementMock.findFirstArtifactBySHA1(anyString())).thenReturn(Optional.of(localArtifactMock)); + when(artifactManagementMock.findFirstBySHA1(anyString())).thenReturn(Optional.of(localArtifactMock)); when(controllerManagementMock.getActionForDownloadByTargetAndSoftwareModule(anyObject(), anyObject())) .thenThrow(EntityNotFoundException.class); @@ -372,7 +372,7 @@ public class AmqpMessageHandlerServiceTest { when(localArtifactMock.getSha1Hash()).thenReturn(SHA1); final AbstractDbArtifact dbArtifactMock = mock(AbstractDbArtifact.class); - when(artifactManagementMock.findFirstArtifactBySHA1(SHA1)).thenReturn(Optional.of(localArtifactMock)); + when(artifactManagementMock.findFirstBySHA1(SHA1)).thenReturn(Optional.of(localArtifactMock)); when(controllerManagementMock.hasTargetArtifactAssigned(securityToken.getControllerId(), SHA1)) .thenReturn(true); when(artifactManagementMock.loadArtifactBinary(anyString())).thenReturn(Optional.of(dbArtifactMock)); diff --git a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpAuthenticationMessageHandlerIntegrationTest.java b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpAuthenticationMessageHandlerIntegrationTest.java index 91b71202b..0c93c514c 100644 --- a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpAuthenticationMessageHandlerIntegrationTest.java +++ b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpAuthenticationMessageHandlerIntegrationTest.java @@ -399,7 +399,7 @@ public class AmqpAuthenticationMessageHandlerIntegrationTest extends AbstractAmq } private Target createTarget(final String controllerId) { - return targetManagement.createTarget( + return targetManagement.create( entityFactory.target().create().controllerId(controllerId).securityToken(TARGET_SECRUITY_TOKEN)); } diff --git a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpMessageDispatcherServiceIntegrationTest.java b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpMessageDispatcherServiceIntegrationTest.java index cb115dfea..60e129ca2 100644 --- a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpMessageDispatcherServiceIntegrationTest.java +++ b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpMessageDispatcherServiceIntegrationTest.java @@ -108,13 +108,13 @@ public class AmqpMessageDispatcherServiceIntegrationTest extends AmqpServiceInte final String controllerId = TARGET_PREFIX + "sendDeleteMessage"; registerAndAssertTargetWithExistingTenant(controllerId, 1); - targetManagement.deleteTarget(controllerId); + targetManagement.deleteByControllerID(controllerId); assertDeleteMessage(controllerId); } private void waitUntilTargetStatusIsPending(final String controllerId) { waitUntil(() -> { - final Optional findTargetByControllerID = targetManagement.findTargetByControllerID(controllerId); + final Optional findTargetByControllerID = targetManagement.getByControllerID(controllerId); return findTargetByControllerID.isPresent() && TargetUpdateStatus.PENDING.equals(findTargetByControllerID.get().getUpdateStatus()); }); diff --git a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpServiceIntegrationTest.java b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpServiceIntegrationTest.java index 39dac2dab..62e83e3c3 100644 --- a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpServiceIntegrationTest.java +++ b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpServiceIntegrationTest.java @@ -165,7 +165,7 @@ public abstract class AmqpServiceIntegrationTest extends AbstractAmqpIntegration Assert.assertThat(dsModules, SoftwareModuleJsonMatcher.containsExactly(downloadAndUpdateRequest.getSoftwareModules())); - final Target updatedTarget = waitUntilIsPresent(() -> targetManagement.findTargetByControllerID(controllerId)); + final Target updatedTarget = waitUntilIsPresent(() -> targetManagement.getByControllerID(controllerId)); assertThat(updatedTarget.getSecurityToken()).isEqualTo(downloadAndUpdateRequest.getTargetSecurityToken()); } @@ -199,7 +199,7 @@ public abstract class AmqpServiceIntegrationTest extends AbstractAmqpIntegration } protected void assertAllTargetsCount(final long expectedTargetsCount) { - assertThat(targetManagement.countTargetsAll()).isEqualTo(expectedTargetsCount); + assertThat(targetManagement.count()).isEqualTo(expectedTargetsCount); } private Message assertReplyMessageHeader(final EventTopic eventTopic, final String controllerId) { @@ -226,14 +226,14 @@ public abstract class AmqpServiceIntegrationTest extends AbstractAmqpIntegration final int existingTargetsAfterCreation, final TargetUpdateStatus expectedTargetStatus, final String createdBy) { createAndSendTarget(target, TENANT_EXIST); - final Target registerdTarget = waitUntilIsPresent(() -> targetManagement.findTargetByControllerID(target)); + final Target registerdTarget = waitUntilIsPresent(() -> targetManagement.getByControllerID(target)); assertAllTargetsCount(existingTargetsAfterCreation); assertTarget(registerdTarget, expectedTargetStatus, createdBy); } protected void registerSameTargetAndAssertBasedOnVersion(final String controllerId, final int existingTargetsAfterCreation, final TargetUpdateStatus expectedTargetStatus) { - final int version = controllerManagement.findByControllerId(controllerId).get().getOptLockRevision(); + final int version = controllerManagement.getByControllerId(controllerId).get().getOptLockRevision(); createAndSendTarget(controllerId, TENANT_EXIST); final Target registeredTarget = waitUntilIsPresent(() -> findTargetBasedOnNewVersion(controllerId, version)); assertAllTargetsCount(existingTargetsAfterCreation); @@ -241,7 +241,7 @@ public abstract class AmqpServiceIntegrationTest extends AbstractAmqpIntegration } private Optional findTargetBasedOnNewVersion(final String controllerId, final int version) { - final Optional target2 = controllerManagement.findByControllerId(controllerId); + final Optional target2 = controllerManagement.getByControllerId(controllerId); if (version < target2.get().getOptLockRevision()) { return target2; } @@ -305,7 +305,7 @@ public abstract class AmqpServiceIntegrationTest extends AbstractAmqpIntegration protected void assertUpdateAttributes(final String controllerId, final Map attributes) { final Target findByControllerId = waitUntilIsPresent( - () -> controllerManagement.findByControllerId(controllerId)); + () -> controllerManagement.getByControllerId(controllerId)); final Map controllerAttributes = targetManagement .getControllerAttributes(findByControllerId.getControllerId()); assertThat(controllerAttributes.size()).isEqualTo(attributes.size()); diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java index ddf81abca..241833d60 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java @@ -46,6 +46,7 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; import org.springframework.data.domain.Sort; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -97,15 +98,18 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi { final Sort sorting = PagingUtility.sanitizeDistributionSetSortParam(sortParam); final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting); - final Page findDsPage; + final Slice findDsPage; + final long countModulesAll; if (rsqlParam != null) { - findDsPage = distributionSetManagement.findDistributionSetsAll(rsqlParam, pageable, false); + findDsPage = distributionSetManagement.findByRsql(pageable, rsqlParam); + countModulesAll = ((Page) findDsPage).getTotalElements(); } else { - findDsPage = distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageable, false, null); + findDsPage = distributionSetManagement.findAll(pageable); + countModulesAll = distributionSetManagement.count(); } final List rest = MgmtDistributionSetMapper.toResponseFromDsList(findDsPage.getContent()); - return ResponseEntity.ok(new PagedList<>(rest, findDsPage.getTotalElements())); + return ResponseEntity.ok(new PagedList<>(rest, countModulesAll)); } @Override @@ -127,7 +131,7 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi { sets.stream().filter(ds -> ds.getType() == null).forEach(ds -> ds.setType(defaultDsKey)); final Collection createdDSets = distributionSetManagement - .createDistributionSets(MgmtDistributionSetMapper.dsFromRequest(sets, entityFactory)); + .create(MgmtDistributionSetMapper.dsFromRequest(sets, entityFactory)); LOG.debug("{} distribution sets created, return status {}", sets.size(), HttpStatus.CREATED); return new ResponseEntity<>(MgmtDistributionSetMapper.toResponseDistributionSets(createdDSets), @@ -136,7 +140,7 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi { @Override public ResponseEntity deleteDistributionSet(@PathVariable("distributionSetId") final Long distributionSetId) { - distributionSetManagement.deleteDistributionSet(distributionSetId); + distributionSetManagement.delete(distributionSetId); return ResponseEntity.ok().build(); } @@ -145,8 +149,8 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi { @PathVariable("distributionSetId") final Long distributionSetId, @RequestBody final MgmtDistributionSetRequestBodyPut toUpdate) { - return ResponseEntity.ok(MgmtDistributionSetMapper - .toResponse(distributionSetManagement.updateDistributionSet(entityFactory.distributionSet() + return ResponseEntity.ok( + MgmtDistributionSetMapper.toResponse(distributionSetManagement.update(entityFactory.distributionSet() .update(distributionSetId).name(toUpdate.getName()).description(toUpdate.getDescription()) .version(toUpdate.getVersion()).requiredMigrationStep(toUpdate.isRequiredMigrationStep())))); } @@ -166,10 +170,10 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi { final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting); final Page targetsAssignedDS; if (rsqlParam != null) { - targetsAssignedDS = this.targetManagement.findTargetByAssignedDistributionSet(distributionSetId, rsqlParam, - pageable); + targetsAssignedDS = this.targetManagement.findByAssignedDistributionSetAndRsql(pageable, distributionSetId, + rsqlParam); } else { - targetsAssignedDS = this.targetManagement.findTargetByAssignedDistributionSet(distributionSetId, pageable); + targetsAssignedDS = this.targetManagement.findByAssignedDistributionSet(pageable, distributionSetId); } return ResponseEntity.ok(new PagedList<>(MgmtTargetMapper.toResponse(targetsAssignedDS.getContent()), @@ -194,11 +198,10 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi { final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting); final Page targetsInstalledDS; if (rsqlParam != null) { - targetsInstalledDS = this.targetManagement.findTargetByInstalledDistributionSet(distributionSetId, - rsqlParam, pageable); + targetsInstalledDS = this.targetManagement.findByInstalledDistributionSetAndRsql(pageable, + distributionSetId, rsqlParam); } else { - targetsInstalledDS = this.targetManagement.findTargetByInstalledDistributionSet(distributionSetId, - pageable); + targetsInstalledDS = this.targetManagement.findByInstalledDistributionSet(pageable, distributionSetId); } return ResponseEntity.ok(new PagedList<>(MgmtTargetMapper.toResponse(targetsInstalledDS.getContent()), @@ -218,7 +221,7 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi { final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting); final Page targetFilterQueries = targetFilterQueryManagement - .findTargetFilterQueryByAutoAssignDS(pageable, distributionSetId, rsqlParam); + .findByAutoAssignDSAndRsql(pageable, distributionSetId, rsqlParam); return ResponseEntity .ok(new PagedList<>(MgmtTargetFilterQueryMapper.toResponse(targetFilterQueries.getContent()), @@ -262,11 +265,10 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi { final Page metaDataPage; if (rsqlParam != null) { - metaDataPage = distributionSetManagement.findDistributionSetMetadataByDistributionSetId(distributionSetId, - rsqlParam, pageable); + metaDataPage = distributionSetManagement.findMetaDataByDistributionSetIdAndRsql(pageable, distributionSetId, + rsqlParam); } else { - metaDataPage = distributionSetManagement.findDistributionSetMetadataByDistributionSetId(distributionSetId, - pageable); + metaDataPage = distributionSetManagement.findMetaDataByDistributionSetId(pageable, distributionSetId); } return ResponseEntity @@ -282,7 +284,7 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi { // check if distribution set exists otherwise throw exception // immediately final DistributionSetMetadata findOne = distributionSetManagement - .findDistributionSetMetadata(distributionSetId, metadataKey) + .getMetaDataByDistributionSetId(distributionSetId, metadataKey) .orElseThrow(() -> new EntityNotFoundException(DistributionSetMetadata.class, distributionSetId, metadataKey)); return ResponseEntity.ok(MgmtDistributionSetMapper.toResponseDsMetadata(findOne)); @@ -293,8 +295,8 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi { @PathVariable("metadataKey") final String metadataKey, @RequestBody final MgmtMetadata metadata) { // check if distribution set exists otherwise throw exception // immediately - final DistributionSetMetadata updated = distributionSetManagement.updateDistributionSetMetadata( - distributionSetId, entityFactory.generateMetadata(metadataKey, metadata.getValue())); + final DistributionSetMetadata updated = distributionSetManagement.updateMetaData(distributionSetId, + entityFactory.generateMetadata(metadataKey, metadata.getValue())); return ResponseEntity.ok(MgmtDistributionSetMapper.toResponseDsMetadata(updated)); } @@ -303,7 +305,7 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi { @PathVariable("metadataKey") final String metadataKey) { // check if distribution set exists otherwise throw exception // immediately - distributionSetManagement.deleteDistributionSetMetadata(distributionSetId, metadataKey); + distributionSetManagement.deleteMetaData(distributionSetId, metadataKey); return ResponseEntity.ok().build(); } @@ -313,8 +315,8 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi { @RequestBody final List metadataRest) { // check if distribution set exists otherwise throw exception // immediately - final List created = distributionSetManagement.createDistributionSetMetadata( - distributionSetId, MgmtDistributionSetMapper.fromRequestDsMetadata(metadataRest, entityFactory)); + final List created = distributionSetManagement.createMetaData(distributionSetId, + MgmtDistributionSetMapper.fromRequestDsMetadata(metadataRest, entityFactory)); return new ResponseEntity<>(MgmtDistributionSetMapper.toResponseDsMetadata(created), HttpStatus.CREATED); } @@ -347,14 +349,14 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi { final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam); final Sort sorting = PagingUtility.sanitizeSoftwareModuleSortParam(sortParam); final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting); - final Page softwaremodules = softwareModuleManagement.findSoftwareModuleByAssignedTo(pageable, + final Page softwaremodules = softwareModuleManagement.findByAssignedTo(pageable, distributionSetId); return ResponseEntity.ok(new PagedList<>(MgmtSoftwareModuleMapper.toResponse(softwaremodules.getContent()), softwaremodules.getTotalElements())); } private DistributionSet findDistributionSetWithExceptionIfNotFound(final Long distributionSetId) { - return distributionSetManagement.findDistributionSetById(distributionSetId) + return distributionSetManagement.get(distributionSetId) .orElseThrow(() -> new EntityNotFoundException(DistributionSet.class, distributionSetId)); } } diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResource.java index e9541792d..4d4069437 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResource.java @@ -20,9 +20,9 @@ import org.eclipse.hawkbit.mgmt.json.model.tag.MgmtTagRequestBodyPut; import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetTagRestApi; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.repository.DistributionSetManagement; +import org.eclipse.hawkbit.repository.DistributionSetTagManagement; import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; -import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetTag; @@ -33,6 +33,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; import org.springframework.data.domain.Sort; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -50,7 +51,7 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes private static final Logger LOG = LoggerFactory.getLogger(MgmtDistributionSetTagResource.class); @Autowired - private TagManagement tagManagement; + private DistributionSetTagManagement distributionSetTagManagement; @Autowired private DistributionSetManagement distributionSetManagement; @@ -70,17 +71,21 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes final Sort sorting = PagingUtility.sanitizeTagSortParam(sortParam); final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting); - final Page findTargetsAll; + final Slice distributionSetTags; + final long count; if (rsqlParam == null) { - findTargetsAll = tagManagement.findAllDistributionSetTags(pageable); + distributionSetTags = distributionSetTagManagement.findAll(pageable); + count = distributionSetTagManagement.count(); } else { - findTargetsAll = tagManagement.findAllDistributionSetTags(rsqlParam, pageable); + final Page page = distributionSetTagManagement.findByRsql(pageable, rsqlParam); + distributionSetTags = page; + count = page.getTotalElements(); } - final List rest = MgmtTagMapper.toResponseDistributionSetTag(findTargetsAll.getContent()); - return ResponseEntity.ok(new PagedList<>(rest, findTargetsAll.getTotalElements())); + final List rest = MgmtTagMapper.toResponseDistributionSetTag(distributionSetTags.getContent()); + return ResponseEntity.ok(new PagedList<>(rest, count)); } @Override @@ -95,8 +100,8 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes @RequestBody final List tags) { LOG.debug("creating {} ds tags", tags.size()); - final List createdTags = this.tagManagement - .createDistributionSetTags(MgmtTagMapper.mapTagFromRequest(entityFactory, tags)); + final List createdTags = distributionSetTagManagement + .create(MgmtTagMapper.mapTagFromRequest(entityFactory, tags)); return new ResponseEntity<>(MgmtTagMapper.toResponseDistributionSetTag(createdTags), HttpStatus.CREATED); } @@ -106,8 +111,8 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes @PathVariable("distributionsetTagId") final Long distributionsetTagId, @RequestBody final MgmtTagRequestBodyPut restDSTagRest) { - return ResponseEntity.ok(MgmtTagMapper.toResponse(tagManagement - .updateDistributionSetTag(entityFactory.tag().update(distributionsetTagId).name(restDSTagRest.getName()) + return ResponseEntity.ok(MgmtTagMapper.toResponse(distributionSetTagManagement + .update(entityFactory.tag().update(distributionsetTagId).name(restDSTagRest.getName()) .description(restDSTagRest.getDescription()).colour(restDSTagRest.getColour())))); } @@ -117,7 +122,7 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes LOG.debug("Delete {} distribution set tag", distributionsetTagId); final DistributionSetTag tag = findDistributionTagById(distributionsetTagId); - this.tagManagement.deleteDistributionSetTag(tag.getName()); + distributionSetTagManagement.delete(tag.getName()); return ResponseEntity.ok().build(); } @@ -126,7 +131,7 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes public ResponseEntity> getAssignedDistributionSets( @PathVariable("distributionsetTagId") final Long distributionsetTagId) { return ResponseEntity.ok(MgmtDistributionSetMapper.toResponseDistributionSets(distributionSetManagement - .findDistributionSetsByTag(new PageRequest(0, MgmtRestConstants.REQUEST_PARAMETER_PAGING_MAX_LIMIT), + .findByTag(new PageRequest(0, MgmtRestConstants.REQUEST_PARAMETER_PAGING_MAX_LIMIT), distributionsetTagId) .getContent())); } @@ -145,11 +150,10 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting); Page findDistrAll; if (rsqlParam == null) { - findDistrAll = distributionSetManagement.findDistributionSetsByTag(pageable, distributionsetTagId); + findDistrAll = distributionSetManagement.findByTag(pageable, distributionsetTagId); } else { - findDistrAll = distributionSetManagement.findDistributionSetsByTag(pageable, rsqlParam, - distributionsetTagId); + findDistrAll = distributionSetManagement.findByRsqlAndTag(pageable, rsqlParam, distributionsetTagId); } final List rest = MgmtDistributionSetMapper @@ -202,7 +206,7 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes } private DistributionSetTag findDistributionTagById(final Long distributionsetTagId) { - return tagManagement.findDistributionSetTagById(distributionsetTagId) + return distributionSetTagManagement.get(distributionsetTagId) .orElseThrow(() -> new EntityNotFoundException(DistributionSetTag.class, distributionsetTagId)); } diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResource.java index 8e6bba67e..082563293 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResource.java @@ -70,13 +70,13 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting); final Slice findModuleTypessAll; - Long countModulesAll; + long countModulesAll; if (rsqlParam != null) { - findModuleTypessAll = distributionSetTypeManagement.findDistributionSetTypesAll(rsqlParam, pageable); + findModuleTypessAll = distributionSetTypeManagement.findByRsql(pageable, rsqlParam); countModulesAll = ((Page) findModuleTypessAll).getTotalElements(); } else { - findModuleTypessAll = distributionSetTypeManagement.findDistributionSetTypesAll(pageable); - countModulesAll = distributionSetTypeManagement.countDistributionSetTypesAll(); + findModuleTypessAll = distributionSetTypeManagement.findAll(pageable); + countModulesAll = distributionSetTypeManagement.count(); } final List rest = MgmtDistributionSetTypeMapper @@ -95,7 +95,7 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR @Override public ResponseEntity deleteDistributionSetType( @PathVariable("distributionSetTypeId") final Long distributionSetTypeId) { - distributionSetTypeManagement.deleteDistributionSetType(distributionSetTypeId); + distributionSetTypeManagement.delete(distributionSetTypeId); return ResponseEntity.ok().build(); } @@ -106,7 +106,7 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR @RequestBody final MgmtDistributionSetTypeRequestBodyPut restDistributionSetType) { return ResponseEntity.ok(MgmtDistributionSetTypeMapper - .toResponse(distributionSetTypeManagement.updateDistributionSetType(entityFactory.distributionSetType() + .toResponse(distributionSetTypeManagement.update(entityFactory.distributionSetType() .update(distributionSetTypeId).description(restDistributionSetType.getDescription()) .colour(restDistributionSetType.getColour())))); } @@ -116,15 +116,14 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR @RequestBody final List distributionSetTypes) { final List createdSoftwareModules = distributionSetTypeManagement - .createDistributionSetTypes( - MgmtDistributionSetTypeMapper.smFromRequest(entityFactory, distributionSetTypes)); + .create(MgmtDistributionSetTypeMapper.smFromRequest(entityFactory, distributionSetTypes)); return ResponseEntity.status(HttpStatus.CREATED) .body(MgmtDistributionSetTypeMapper.toTypesResponse(createdSoftwareModules)); } private DistributionSetType findDistributionSetTypeWithExceptionIfNotFound(final Long distributionSetTypeId) { - return distributionSetTypeManagement.findDistributionSetTypeById(distributionSetTypeId) + return distributionSetTypeManagement.get(distributionSetTypeId) .orElseThrow(() -> new EntityNotFoundException(DistributionSetType.class, distributionSetTypeId)); } @@ -213,7 +212,7 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR private SoftwareModuleType findSoftwareModuleTypeWithExceptionIfNotFound(final Long softwareModuleTypeId) { - return softwareModuleTypeManagement.findSoftwareModuleTypeById(softwareModuleTypeId) + return softwareModuleTypeManagement.get(softwareModuleTypeId) .orElseThrow(() -> new EntityNotFoundException(SoftwareModuleType.class, softwareModuleTypeId)); } } diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDownloadArtifactResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDownloadArtifactResource.java index 42064fcc5..654839018 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDownloadArtifactResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDownloadArtifactResource.java @@ -63,7 +63,7 @@ public class MgmtDownloadArtifactResource implements MgmtDownloadArtifactRestApi public ResponseEntity downloadArtifact(@PathVariable("softwareModuleId") final Long softwareModuleId, @PathVariable("artifactId") final Long artifactId) { - final SoftwareModule module = softwareModuleManagement.findSoftwareModuleById(softwareModuleId) + final SoftwareModule module = softwareModuleManagement.get(softwareModuleId) .orElseThrow(() -> new EntityNotFoundException(SoftwareModule.class, softwareModuleId)); final Artifact artifact = module.getArtifact(artifactId) .orElseThrow(() -> new EntityNotFoundException(Artifact.class, artifactId)); diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResource.java index 01d95a25e..cb40208fd 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResource.java @@ -81,7 +81,7 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi { final Page findModulesAll; if (rsqlParam != null) { - findModulesAll = this.rolloutManagement.findAllByPredicate(rsqlParam, pageable, false); + findModulesAll = this.rolloutManagement.findByRsql(pageable, rsqlParam, false); } else { findModulesAll = this.rolloutManagement.findAll(pageable, false); } @@ -92,7 +92,7 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi { @Override public ResponseEntity getRollout(@PathVariable("rolloutId") final Long rolloutId) { - final Rollout findRolloutById = rolloutManagement.findRolloutWithDetailedStatus(rolloutId) + final Rollout findRolloutById = rolloutManagement.getWithDetailedStatus(rolloutId) .orElseThrow(() -> new EntityNotFoundException(Rollout.class, rolloutId)); return ResponseEntity.ok(MgmtRolloutMapper.toResponseRollout(findRolloutById, true)); @@ -116,10 +116,10 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi { final List rolloutGroups = rolloutRequestBody.getGroups().stream() .map(mgmtRolloutGroup -> MgmtRolloutMapper.fromRequest(entityFactory, mgmtRolloutGroup)) .collect(Collectors.toList()); - rollout = rolloutManagement.createRollout(create, rolloutGroups, rolloutGroupConditions); + rollout = rolloutManagement.create(create, rolloutGroups, rolloutGroupConditions); } else if (rolloutRequestBody.getAmountGroups() != null) { - rollout = rolloutManagement.createRollout(create, rolloutRequestBody.getAmountGroups(), + rollout = rolloutManagement.create(create, rolloutRequestBody.getAmountGroups(), rolloutGroupConditions); } else { @@ -131,7 +131,7 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi { @Override public ResponseEntity start(@PathVariable("rolloutId") final Long rolloutId) { - this.rolloutManagement.startRollout(rolloutId); + this.rolloutManagement.start(rolloutId); return ResponseEntity.ok().build(); } @@ -143,7 +143,7 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi { @Override public ResponseEntity delete(@PathVariable("rolloutId") final Long rolloutId) { - this.rolloutManagement.deleteRollout(rolloutId); + this.rolloutManagement.delete(rolloutId); return ResponseEntity.ok().build(); } @@ -168,9 +168,9 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi { final Page findRolloutGroupsAll; if (rsqlParam != null) { - findRolloutGroupsAll = this.rolloutGroupManagement.findRolloutGroupsAll(rolloutId, rsqlParam, pageable); + findRolloutGroupsAll = this.rolloutGroupManagement.findByRolloutAndRsql(pageable, rolloutId, rsqlParam); } else { - findRolloutGroupsAll = this.rolloutGroupManagement.findRolloutGroupsByRolloutId(rolloutId, pageable); + findRolloutGroupsAll = this.rolloutGroupManagement.findByRollout(pageable, rolloutId); } final List rest = MgmtRolloutMapper @@ -183,7 +183,7 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi { @PathVariable("groupId") final Long groupId) { findRolloutOrThrowException(rolloutId); - final RolloutGroup rolloutGroup = rolloutGroupManagement.findRolloutGroupWithDetailedStatus(groupId) + final RolloutGroup rolloutGroup = rolloutGroupManagement.getWithDetailedStatus(groupId) .orElseThrow(() -> new EntityNotFoundException(RolloutGroup.class, rolloutId)); return ResponseEntity.ok(MgmtRolloutMapper.toResponseRolloutGroup(rolloutGroup, true)); } @@ -210,9 +210,9 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi { final Page rolloutGroupTargets; if (rsqlParam != null) { - rolloutGroupTargets = this.rolloutGroupManagement.findRolloutGroupTargets(groupId, rsqlParam, pageable); + rolloutGroupTargets = this.rolloutGroupManagement.findTargetsOfRolloutGroupByRsql(pageable, groupId, rsqlParam); } else { - final Page pageTargets = this.rolloutGroupManagement.findRolloutGroupTargets(groupId, pageable); + final Page pageTargets = this.rolloutGroupManagement.findTargetsOfRolloutGroup(pageable, groupId); rolloutGroupTargets = pageTargets; } final List rest = MgmtTargetMapper.toResponse(rolloutGroupTargets.getContent()); @@ -220,7 +220,7 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi { } private DistributionSet findDistributionSetOrThrowException(final MgmtRolloutRestRequestBody rolloutRequestBody) { - return this.distributionSetManagement.findDistributionSetById(rolloutRequestBody.getDistributionSetId()) + return this.distributionSetManagement.get(rolloutRequestBody.getDistributionSetId()) .orElseThrow(() -> new EntityNotFoundException(DistributionSet.class, rolloutRequestBody.getDistributionSetId())); diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResource.java index 9c17bc380..c01127d09 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResource.java @@ -79,7 +79,7 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi { } try { - final Artifact result = artifactManagement.createArtifact(file.getInputStream(), softwareModuleId, fileName, + final Artifact result = artifactManagement.create(file.getInputStream(), softwareModuleId, fileName, md5Sum == null ? null : md5Sum.toLowerCase(), sha1Sum == null ? null : sha1Sum.toLowerCase(), false, file.getContentType()); return ResponseEntity.status(HttpStatus.CREATED).body(MgmtSoftwareModuleMapper.toResponse(result)); @@ -117,7 +117,7 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi { @PathVariable("artifactId") final Long artifactId) { findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, artifactId); - artifactManagement.deleteArtifact(artifactId); + artifactManagement.delete(artifactId); return ResponseEntity.ok().build(); } @@ -136,13 +136,13 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi { final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting); final Slice findModulesAll; - Long countModulesAll; + long countModulesAll; if (rsqlParam != null) { - findModulesAll = softwareModuleManagement.findSoftwareModulesByPredicate(rsqlParam, pageable); + findModulesAll = softwareModuleManagement.findByRsql(pageable, rsqlParam); countModulesAll = ((Page) findModulesAll).getTotalElements(); } else { - findModulesAll = softwareModuleManagement.findSoftwareModulesAll(pageable); - countModulesAll = softwareModuleManagement.countSoftwareModulesAll(); + findModulesAll = softwareModuleManagement.findAll(pageable); + countModulesAll = softwareModuleManagement.count(); } final List rest = MgmtSoftwareModuleMapper.toResponse(findModulesAll.getContent()); @@ -163,7 +163,7 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi { LOG.debug("creating {} softwareModules", softwareModules.size()); final Collection createdSoftwareModules = softwareModuleManagement - .createSoftwareModule(MgmtSoftwareModuleMapper.smFromRequest(entityFactory, softwareModules)); + .create(MgmtSoftwareModuleMapper.smFromRequest(entityFactory, softwareModules)); LOG.debug("{} softwareModules created, return status {}", softwareModules.size(), HttpStatus.CREATED); return ResponseEntity.status(HttpStatus.CREATED) @@ -175,8 +175,8 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi { @PathVariable("softwareModuleId") final Long softwareModuleId, @RequestBody final MgmtSoftwareModuleRequestBodyPut restSoftwareModule) { - return ResponseEntity.ok(MgmtSoftwareModuleMapper.toResponse( - softwareModuleManagement.updateSoftwareModule(entityFactory.softwareModule().update(softwareModuleId) + return ResponseEntity.ok(MgmtSoftwareModuleMapper + .toResponse(softwareModuleManagement.update(entityFactory.softwareModule().update(softwareModuleId) .description(restSoftwareModule.getDescription()).vendor(restSoftwareModule.getVendor())))); } @@ -184,7 +184,7 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi { public ResponseEntity deleteSoftwareModule(@PathVariable("softwareModuleId") final Long softwareModuleId) { final SoftwareModule module = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null); - softwareModuleManagement.deleteSoftwareModule(module.getId()); + softwareModuleManagement.delete(module.getId()); return ResponseEntity.ok().build(); } @@ -208,11 +208,9 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi { final Page metaDataPage; if (rsqlParam != null) { - metaDataPage = softwareModuleManagement.findSoftwareModuleMetadataBySoftwareModuleId(softwareModuleId, - rsqlParam, pageable); + metaDataPage = softwareModuleManagement.findMetaDataByRsql(pageable, softwareModuleId, rsqlParam); } else { - metaDataPage = softwareModuleManagement.findSoftwareModuleMetadataBySoftwareModuleId(softwareModuleId, - pageable); + metaDataPage = softwareModuleManagement.findMetaDataBySoftwareModuleId(pageable, softwareModuleId); } return ResponseEntity @@ -224,8 +222,8 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi { public ResponseEntity getMetadataValue(@PathVariable("softwareModuleId") final Long softwareModuleId, @PathVariable("metadataKey") final String metadataKey) { - final SoftwareModuleMetadata findOne = softwareModuleManagement - .findSoftwareModuleMetadata(softwareModuleId, metadataKey).orElseThrow( + final SoftwareModuleMetadata findOne = softwareModuleManagement.getMetaDataBySoftwareModuleId(softwareModuleId, metadataKey) + .orElseThrow( () -> new EntityNotFoundException(SoftwareModuleMetadata.class, softwareModuleId, metadataKey)); return ResponseEntity.ok(MgmtSoftwareModuleMapper.toResponseSwMetadata(findOne)); @@ -234,7 +232,7 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi { @Override public ResponseEntity updateMetadata(@PathVariable("softwareModuleId") final Long softwareModuleId, @PathVariable("metadataKey") final String metadataKey, @RequestBody final MgmtMetadata metadata) { - final SoftwareModuleMetadata updated = softwareModuleManagement.updateSoftwareModuleMetadata(softwareModuleId, + final SoftwareModuleMetadata updated = softwareModuleManagement.updateMetaData(softwareModuleId, entityFactory.generateMetadata(metadataKey, metadata.getValue())); return ResponseEntity.ok(MgmtSoftwareModuleMapper.toResponseSwMetadata(updated)); @@ -243,7 +241,7 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi { @Override public ResponseEntity deleteMetadata(@PathVariable("softwareModuleId") final Long softwareModuleId, @PathVariable("metadataKey") final String metadataKey) { - softwareModuleManagement.deleteSoftwareModuleMetadata(softwareModuleId, metadataKey); + softwareModuleManagement.deleteMetaData(softwareModuleId, metadataKey); return ResponseEntity.ok().build(); } @@ -253,8 +251,8 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi { @PathVariable("softwareModuleId") final Long softwareModuleId, @RequestBody final List metadataRest) { - final List created = softwareModuleManagement.createSoftwareModuleMetadata( - softwareModuleId, MgmtSoftwareModuleMapper.fromRequestSwMetadata(entityFactory, metadataRest)); + final List created = softwareModuleManagement.createMetaData(softwareModuleId, + MgmtSoftwareModuleMapper.fromRequestSwMetadata(entityFactory, metadataRest)); return ResponseEntity.status(HttpStatus.CREATED).body(MgmtSoftwareModuleMapper.toResponseSwMetadata(created)); } @@ -262,7 +260,7 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi { private SoftwareModule findSoftwareModuleWithExceptionIfNotFound(final Long softwareModuleId, final Long artifactId) { - final SoftwareModule module = softwareModuleManagement.findSoftwareModuleById(softwareModuleId) + final SoftwareModule module = softwareModuleManagement.get(softwareModuleId) .orElseThrow(() -> new EntityNotFoundException(SoftwareModule.class, softwareModuleId)); if (artifactId != null && !module.getArtifact(artifactId).isPresent()) { diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResource.java index 82e9cddf4..a235dd38b 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResource.java @@ -64,11 +64,11 @@ public class MgmtSoftwareModuleTypeResource implements MgmtSoftwareModuleTypeRes final Slice findModuleTypessAll; Long countModulesAll; if (rsqlParam != null) { - findModuleTypessAll = softwareModuleTypeManagement.findSoftwareModuleTypesAll(rsqlParam, pageable); + findModuleTypessAll = softwareModuleTypeManagement.findByRsql(pageable, rsqlParam); countModulesAll = ((Page) findModuleTypessAll).getTotalElements(); } else { - findModuleTypessAll = softwareModuleTypeManagement.findSoftwareModuleTypesAll(pageable); - countModulesAll = softwareModuleTypeManagement.countSoftwareModuleTypesAll(); + findModuleTypessAll = softwareModuleTypeManagement.findAll(pageable); + countModulesAll = softwareModuleTypeManagement.count(); } final List rest = MgmtSoftwareModuleTypeMapper @@ -87,7 +87,7 @@ public class MgmtSoftwareModuleTypeResource implements MgmtSoftwareModuleTypeRes @Override public ResponseEntity deleteSoftwareModuleType( @PathVariable("softwareModuleTypeId") final Long softwareModuleTypeId) { - softwareModuleTypeManagement.deleteSoftwareModuleType(softwareModuleTypeId); + softwareModuleTypeManagement.delete(softwareModuleTypeId); return ResponseEntity.ok().build(); } @@ -97,7 +97,7 @@ public class MgmtSoftwareModuleTypeResource implements MgmtSoftwareModuleTypeRes @RequestBody final MgmtSoftwareModuleTypeRequestBodyPut restSoftwareModuleType) { final SoftwareModuleType updatedSoftwareModuleType = softwareModuleTypeManagement - .updateSoftwareModuleType(entityFactory.softwareModuleType().update(softwareModuleTypeId) + .update(entityFactory.softwareModuleType().update(softwareModuleTypeId) .description(restSoftwareModuleType.getDescription()) .colour(restSoftwareModuleType.getColour())); @@ -108,7 +108,7 @@ public class MgmtSoftwareModuleTypeResource implements MgmtSoftwareModuleTypeRes public ResponseEntity> createSoftwareModuleTypes( @RequestBody final List softwareModuleTypes) { - final List createdSoftwareModules = softwareModuleTypeManagement.createSoftwareModuleType( + final List createdSoftwareModules = softwareModuleTypeManagement.create( MgmtSoftwareModuleTypeMapper.smFromRequest(entityFactory, softwareModuleTypes)); return new ResponseEntity<>(MgmtSoftwareModuleTypeMapper.toTypesResponse(createdSoftwareModules), @@ -116,7 +116,7 @@ public class MgmtSoftwareModuleTypeResource implements MgmtSoftwareModuleTypeRes } private SoftwareModuleType findSoftwareModuleTypeWithExceptionIfNotFound(final Long softwareModuleTypeId) { - return softwareModuleTypeManagement.findSoftwareModuleTypeById(softwareModuleTypeId) + return softwareModuleTypeManagement.get(softwareModuleTypeId) .orElseThrow(() -> new EntityNotFoundException(SoftwareModuleType.class, softwareModuleTypeId)); } diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetFilterQueryResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetFilterQueryResource.java index f9a669ba6..4a6e82696 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetFilterQueryResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetFilterQueryResource.java @@ -74,13 +74,13 @@ public class MgmtTargetFilterQueryResource implements MgmtTargetFilterQueryRestA final Slice findTargetFiltersAll; final Long countTargetsAll; if (rsqlParam != null) { - final Page findFilterPage = filterManagement.findTargetFilterQueryByFilter(pageable, + final Page findFilterPage = filterManagement.findByRsql(pageable, rsqlParam); countTargetsAll = findFilterPage.getTotalElements(); findTargetFiltersAll = findFilterPage; } else { - findTargetFiltersAll = filterManagement.findAllTargetFilterQuery(pageable); - countTargetsAll = filterManagement.countAllTargetFilterQuery(); + findTargetFiltersAll = filterManagement.findAll(pageable); + countTargetsAll = filterManagement.count(); } final List rest = MgmtTargetFilterQueryMapper @@ -92,7 +92,7 @@ public class MgmtTargetFilterQueryResource implements MgmtTargetFilterQueryRestA public ResponseEntity createFilter( @RequestBody final MgmtTargetFilterQueryRequestBody filter) { final TargetFilterQuery createdTarget = filterManagement - .createTargetFilterQuery(MgmtTargetFilterQueryMapper.fromRequest(entityFactory, filter)); + .create(MgmtTargetFilterQueryMapper.fromRequest(entityFactory, filter)); return new ResponseEntity<>(MgmtTargetFilterQueryMapper.toResponse(createdTarget), HttpStatus.CREATED); } @@ -103,7 +103,7 @@ public class MgmtTargetFilterQueryResource implements MgmtTargetFilterQueryRestA LOG.debug("updating target filter query {}", filterId); final TargetFilterQuery updateFilter = filterManagement - .updateTargetFilterQuery(entityFactory.targetFilterQuery().update(filterId) + .update(entityFactory.targetFilterQuery().update(filterId) .name(targetFilterRest.getName()).query(targetFilterRest.getQuery())); return ResponseEntity.ok(MgmtTargetFilterQueryMapper.toResponse(updateFilter)); @@ -111,7 +111,7 @@ public class MgmtTargetFilterQueryResource implements MgmtTargetFilterQueryRestA @Override public ResponseEntity deleteFilter(@PathVariable("filterId") final Long filterId) { - filterManagement.deleteTargetFilterQuery(filterId); + filterManagement.delete(filterId); LOG.debug("{} target filter query deleted, return status {}", filterId, HttpStatus.OK); return ResponseEntity.ok().build(); } @@ -120,7 +120,7 @@ public class MgmtTargetFilterQueryResource implements MgmtTargetFilterQueryRestA public ResponseEntity postAssignedDistributionSet( @PathVariable("filterId") final Long filterId, @RequestBody final MgmtId dsId) { - final TargetFilterQuery updateFilter = filterManagement.updateTargetFilterQueryAutoAssignDS(filterId, + final TargetFilterQuery updateFilter = filterManagement.updateAutoAssignDS(filterId, dsId.getId()); return ResponseEntity.ok(MgmtTargetFilterQueryMapper.toResponse(updateFilter)); @@ -138,13 +138,13 @@ public class MgmtTargetFilterQueryResource implements MgmtTargetFilterQueryRestA @Override public ResponseEntity deleteAssignedDistributionSet(@PathVariable("filterId") final Long filterId) { - filterManagement.updateTargetFilterQueryAutoAssignDS(filterId, null); + filterManagement.updateAutoAssignDS(filterId, null); return ResponseEntity.noContent().build(); } private TargetFilterQuery findFilterWithExceptionIfNotFound(final Long filterId) { - return filterManagement.findTargetFilterQueryById(filterId) + return filterManagement.get(filterId) .orElseThrow(() -> new EntityNotFoundException(TargetFilterQuery.class, filterId)); } diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResource.java index 385810baf..39f5f2408 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResource.java @@ -91,14 +91,14 @@ public class MgmtTargetResource implements MgmtTargetRestApi { final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting); final Slice findTargetsAll; - final Long countTargetsAll; + final long countTargetsAll; if (rsqlParam != null) { - final Page findTargetPage = this.targetManagement.findTargetsAll(rsqlParam, pageable); + final Page findTargetPage = this.targetManagement.findByRsql(pageable, rsqlParam); countTargetsAll = findTargetPage.getTotalElements(); findTargetsAll = findTargetPage; } else { - findTargetsAll = this.targetManagement.findTargetsAll(pageable); - countTargetsAll = this.targetManagement.countTargetsAll(); + findTargetsAll = this.targetManagement.findAll(pageable); + countTargetsAll = this.targetManagement.count(); } final List rest = MgmtTargetMapper.toResponse(findTargetsAll.getContent()); @@ -109,7 +109,7 @@ public class MgmtTargetResource implements MgmtTargetRestApi { public ResponseEntity> createTargets(@RequestBody final List targets) { LOG.debug("creating {} targets", targets.size()); final Collection createdTargets = this.targetManagement - .createTargets(MgmtTargetMapper.fromRequest(entityFactory, targets)); + .create(MgmtTargetMapper.fromRequest(entityFactory, targets)); LOG.debug("{} targets created, return status {}", targets.size(), HttpStatus.CREATED); return new ResponseEntity<>(MgmtTargetMapper.toResponse(createdTargets), HttpStatus.CREATED); } @@ -118,7 +118,7 @@ public class MgmtTargetResource implements MgmtTargetRestApi { public ResponseEntity updateTarget(@PathVariable("controllerId") final String controllerId, @RequestBody final MgmtTargetRequestBody targetRest) { - final Target updateTarget = this.targetManagement.updateTarget(entityFactory.target().update(controllerId) + final Target updateTarget = this.targetManagement.update(entityFactory.target().update(controllerId) .name(targetRest.getName()).description(targetRest.getDescription()).address(targetRest.getAddress()) .securityToken(targetRest.getSecurityToken())); @@ -127,7 +127,7 @@ public class MgmtTargetResource implements MgmtTargetRestApi { @Override public ResponseEntity deleteTarget(@PathVariable("controllerId") final String controllerId) { - this.targetManagement.deleteTarget(controllerId); + this.targetManagement.deleteByControllerID(controllerId); LOG.debug("{} target deleted, return status {}", controllerId, HttpStatus.OK); return ResponseEntity.ok().build(); } @@ -284,7 +284,7 @@ public class MgmtTargetResource implements MgmtTargetRestApi { } private Target findTargetWithExceptionIfNotFound(final String controllerId) { - return targetManagement.findTargetByControllerID(controllerId) + return targetManagement.getByControllerID(controllerId) .orElseThrow(() -> new EntityNotFoundException(Target.class, controllerId)); } diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTagResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTagResource.java index 9d851ad41..5765128ed 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTagResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTagResource.java @@ -21,7 +21,7 @@ import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetTagRestApi; import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; -import org.eclipse.hawkbit.repository.TagManagement; +import org.eclipse.hawkbit.repository.TargetTagManagement; import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.model.Target; @@ -50,7 +50,7 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi { private static final Logger LOG = LoggerFactory.getLogger(MgmtTargetTagResource.class); @Autowired - private TagManagement tagManagement; + private TargetTagManagement tagManagement; @Autowired private TargetManagement targetManagement; @@ -72,10 +72,10 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi { final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting); Page findTargetsAll; if (rsqlParam == null) { - findTargetsAll = this.tagManagement.findAllTargetTags(pageable); + findTargetsAll = this.tagManagement.findAll(pageable); } else { - findTargetsAll = this.tagManagement.findAllTargetTags(rsqlParam, pageable); + findTargetsAll = this.tagManagement.findByRsql(pageable, rsqlParam); } final List rest = MgmtTagMapper.toResponse(findTargetsAll.getContent()); @@ -92,7 +92,7 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi { public ResponseEntity> createTargetTags(@RequestBody final List tags) { LOG.debug("creating {} target tags", tags.size()); final List createdTargetTags = this.tagManagement - .createTargetTags(MgmtTagMapper.mapTagFromRequest(entityFactory, tags)); + .create(MgmtTagMapper.mapTagFromRequest(entityFactory, tags)); return new ResponseEntity<>(MgmtTagMapper.toResponse(createdTargetTags), HttpStatus.CREATED); } @@ -102,7 +102,7 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi { LOG.debug("update {} target tag", restTargetTagRest); final TargetTag updateTargetTag = tagManagement - .updateTargetTag(entityFactory.tag().update(targetTagId).name(restTargetTagRest.getName()) + .update(entityFactory.tag().update(targetTagId).name(restTargetTagRest.getName()) .description(restTargetTagRest.getDescription()).colour(restTargetTagRest.getColour())); LOG.debug("target tag updated"); @@ -115,7 +115,7 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi { LOG.debug("Delete {} target tag", targetTagId); final TargetTag targetTag = findTargetTagById(targetTagId); - this.tagManagement.deleteTargetTag(targetTag.getName()); + this.tagManagement.delete(targetTag.getName()); return ResponseEntity.ok().build(); } @@ -124,7 +124,7 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi { public ResponseEntity> getAssignedTargets(@PathVariable("targetTagId") final Long targetTagId) { return ResponseEntity.ok(MgmtTargetMapper.toResponse(targetManagement - .findTargetsByTag(new PageRequest(0, MgmtRestConstants.REQUEST_PARAMETER_PAGING_MAX_LIMIT), targetTagId) + .findByTag(new PageRequest(0, MgmtRestConstants.REQUEST_PARAMETER_PAGING_MAX_LIMIT), targetTagId) .getContent())); } @@ -142,10 +142,10 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi { final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting); Page findTargetsAll; if (rsqlParam == null) { - findTargetsAll = targetManagement.findTargetsByTag(pageable, targetTagId); + findTargetsAll = targetManagement.findByTag(pageable, targetTagId); } else { - findTargetsAll = targetManagement.findTargetsByTag(pageable, rsqlParam, targetTagId); + findTargetsAll = targetManagement.findByRsqlAndTag(pageable, rsqlParam, targetTagId); } final Long countTargetsAll = findTargetsAll.getTotalElements(); @@ -188,7 +188,7 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi { } private TargetTag findTargetTagById(final Long targetTagId) { - return tagManagement.findTargetTagById(targetTagId) + return tagManagement.get(targetTagId) .orElseThrow(() -> new EntityNotFoundException(TargetTag.class, targetTagId)); } diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java index b9e12c958..fb08061cb 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java @@ -220,7 +220,7 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr .andExpect(jsonPath("$.alreadyAssigned", equalTo(1))) .andExpect(jsonPath("$.total", equalTo(targets.size()))); - assertThat(targetManagement.findTargetByAssignedDistributionSet(createdDs.getId(), PAGE).getContent()) + assertThat(targetManagement.findByAssignedDistributionSet(PAGE, createdDs.getId()).getContent()) .as("Five targets in repository have DS assigned").hasSize(5); } @@ -241,11 +241,10 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr .andExpect(jsonPath("$.alreadyAssigned", equalTo(1))) .andExpect(jsonPath("$.total", equalTo(targets.size()))); - assertThat(targetManagement.findTargetByAssignedDistributionSet(createdDs.getId(), PAGE).getContent()) + assertThat(targetManagement.findByAssignedDistributionSet(PAGE, createdDs.getId()).getContent()) .as("Five targets in repository have DS assigned").hasSize(5); - assertThat(targetManagement.findTargetByInstalledDistributionSet(createdDs.getId(), PAGE).getContent()) - .hasSize(4); + assertThat(targetManagement.findByInstalledDistributionSet(PAGE, createdDs.getId()).getContent()).hasSize(4); } @Test @@ -306,16 +305,14 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr final Set createDistributionSetsAlphabetical = createDistributionSetsAlphabetical(1); final DistributionSet createdDs = createDistributionSetsAlphabetical.iterator().next(); - targetFilterQueryManagement.updateTargetFilterQueryAutoAssignDS( - targetFilterQueryManagement.createTargetFilterQuery( - entityFactory.targetFilterQuery().create().name(knownFilterName).query("x==y")).getId(), + targetFilterQueryManagement.updateAutoAssignDS( + targetFilterQueryManagement + .create(entityFactory.targetFilterQuery().create().name(knownFilterName).query("x==y")).getId(), createdDs.getId()); // create some dummy target filter queries - targetFilterQueryManagement - .createTargetFilterQuery(entityFactory.targetFilterQuery().create().name("b").query("x==y")); - targetFilterQueryManagement - .createTargetFilterQuery(entityFactory.targetFilterQuery().create().name("c").query("x==y")); + targetFilterQueryManagement.create(entityFactory.targetFilterQuery().create().name("b").query("x==y")); + targetFilterQueryManagement.create(entityFactory.targetFilterQuery().create().name("c").query("x==y")); mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId() + "/autoAssignTargetFilters")).andExpect(status().isOk()).andExpect(jsonPath("$.size", equalTo(1))) @@ -369,21 +366,17 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr private void prepareTestFilters(final String filterNamePrefix, final DistributionSet createdDs) { // create target filter queries that should be found - targetFilterQueryManagement - .updateTargetFilterQueryAutoAssignDS(targetFilterQueryManagement - .createTargetFilterQuery( - entityFactory.targetFilterQuery().create().name(filterNamePrefix + "1").query("x==y")) - .getId(), createdDs.getId()); - targetFilterQueryManagement - .updateTargetFilterQueryAutoAssignDS(targetFilterQueryManagement - .createTargetFilterQuery( - entityFactory.targetFilterQuery().create().name(filterNamePrefix + "2").query("x==y")) - .getId(), createdDs.getId()); + targetFilterQueryManagement.updateAutoAssignDS(targetFilterQueryManagement + .create(entityFactory.targetFilterQuery().create().name(filterNamePrefix + "1").query("x==y")).getId(), + createdDs.getId()); + targetFilterQueryManagement.updateAutoAssignDS(targetFilterQueryManagement + .create(entityFactory.targetFilterQuery().create().name(filterNamePrefix + "2").query("x==y")).getId(), + createdDs.getId()); // create some dummy target filter queries - targetFilterQueryManagement.createTargetFilterQuery( - entityFactory.targetFilterQuery().create().name(filterNamePrefix + "b").query("x==y")); - targetFilterQueryManagement.createTargetFilterQuery( - entityFactory.targetFilterQuery().create().name(filterNamePrefix + "c").query("x==y")); + targetFilterQueryManagement + .create(entityFactory.targetFilterQuery().create().name(filterNamePrefix + "b").query("x==y")); + targetFilterQueryManagement + .create(entityFactory.targetFilterQuery().create().name(filterNamePrefix + "c").query("x==y")); } @Test @@ -433,16 +426,16 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr @Description("Ensures that multiple DS requested are listed with expected payload.") public void getDistributionSets() throws Exception { // prepare test data - assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(PAGE, false, true)).hasSize(0); + assertThat(distributionSetManagement.findByCompleted(PAGE, true)).hasSize(0); DistributionSet set = testdataFactory.createDistributionSet("one"); - set = distributionSetManagement.updateDistributionSet(entityFactory.distributionSet().update(set.getId()) + set = distributionSetManagement.update(entityFactory.distributionSet().update(set.getId()) .version("anotherVersion").requiredMigrationStep(true)); // load also lazy stuff - set = distributionSetManagement.findDistributionSetByIdWithDetails(set.getId()).get(); + set = distributionSetManagement.getWithDetails(set.getId()).get(); - assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(PAGE, false, true)).hasSize(1); + assertThat(distributionSetManagement.findByCompleted(PAGE, true)).hasSize(1); // perform request mvc.perform(get("/rest/v1/distributionsets").accept(MediaType.APPLICATION_JSON)) @@ -505,7 +498,7 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr @WithUser(principal = "uploadTester", allSpPermissions = true) @Description("Ensures that multipe DS posted to API are created in the repository.") public void createDistributionSets() throws Exception { - assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(PAGE, false, true)).hasSize(0); + assertThat(distributionSetManagement.findByCompleted(PAGE, true)).hasSize(0); final SoftwareModule ah = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_APP); final SoftwareModule jvm = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_RT); @@ -522,14 +515,15 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr final MvcResult mvcResult = executeMgmtTargetPost(one, two, three); - one = distributionSetManagement.findDistributionSetByIdWithDetails( - distributionSetManagement.findDistributionSetsAll("name==one", PAGE, false).getContent().get(0).getId()) + one = distributionSetManagement + .getWithDetails(distributionSetManagement.findByRsql(PAGE, "name==one").getContent().get(0).getId()) .get(); - two = distributionSetManagement.findDistributionSetByIdWithDetails( - distributionSetManagement.findDistributionSetsAll("name==two", PAGE, false).getContent().get(0).getId()) + two = distributionSetManagement + .getWithDetails(distributionSetManagement.findByRsql(PAGE, "name==two").getContent().get(0).getId()) + .get(); + three = distributionSetManagement + .getWithDetails(distributionSetManagement.findByRsql(PAGE, "name==three").getContent().get(0).getId()) .get(); - three = distributionSetManagement.findDistributionSetByIdWithDetails(distributionSetManagement - .findDistributionSetsAll("name==three", PAGE, false).getContent().get(0).getId()).get(); assertThat( JsonPath.compile("[0]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString()) @@ -560,7 +554,7 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr .isEqualTo(String.valueOf(three.getId())); // check in database - assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(PAGE, false, true)).hasSize(3); + assertThat(distributionSetManagement.findByCompleted(PAGE, true)).hasSize(3); assertThat(one.isRequiredMigrationStep()).isEqualTo(false); assertThat(two.isRequiredMigrationStep()).isEqualTo(false); assertThat(three.isRequiredMigrationStep()).isEqualTo(true); @@ -624,19 +618,19 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr @Description("Ensures that DS deletion request to API is reflected by the repository.") public void deleteUnassignedistributionSet() throws Exception { // prepare test data - assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(PAGE, false, true)).hasSize(0); + assertThat(distributionSetManagement.findByCompleted(PAGE, true)).hasSize(0); final DistributionSet set = testdataFactory.createDistributionSet("one"); - assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(PAGE, false, true)).hasSize(1); + assertThat(distributionSetManagement.findByCompleted(PAGE, true)).hasSize(1); // perform request mvc.perform(delete("/rest/v1/distributionsets/{smId}", set.getId())).andDo(MockMvcResultPrinter.print()) .andExpect(status().isOk()); // check repository content - assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(PAGE, false, true)).isEmpty(); - assertThat(distributionSetManagement.countDistributionSetsAll()).isEqualTo(0); + assertThat(distributionSetManagement.findByCompleted(PAGE, true)).isEmpty(); + assertThat(distributionSetManagement.count()).isEqualTo(0); } @Test @@ -650,21 +644,20 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr @Description("Ensures that assigned DS deletion request to API is reflected by the repository by means of deleted flag set.") public void deleteAssignedDistributionSet() throws Exception { // prepare test data - assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(PAGE, false, true)).hasSize(0); + assertThat(distributionSetManagement.findByCompleted(PAGE, true)).hasSize(0); final DistributionSet set = testdataFactory.createDistributionSet("one"); testdataFactory.createTarget("test"); assignDistributionSet(set.getId(), "test"); - assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(PAGE, false, true)).hasSize(1); + assertThat(distributionSetManagement.findByCompleted(PAGE, true)).hasSize(1); // perform request mvc.perform(delete("/rest/v1/distributionsets/{smId}", set.getId())).andDo(MockMvcResultPrinter.print()) .andExpect(status().isOk()); // check repository content - assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(PAGE, false, true)).hasSize(0); - assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(PAGE, true, true)).hasSize(1); + assertThat(distributionSetManagement.findByCompleted(PAGE, true)).hasSize(0); } @Test @@ -672,18 +665,18 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr public void updateDistributionSet() throws Exception { // prepare test data - assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(PAGE, false, true)).hasSize(0); + assertThat(distributionSetManagement.findByCompleted(PAGE, true)).hasSize(0); final DistributionSet set = testdataFactory.createDistributionSet("one"); - assertThat(distributionSetManagement.countDistributionSetsAll()).isEqualTo(1); + assertThat(distributionSetManagement.count()).isEqualTo(1); mvc.perform(put("/rest/v1/distributionsets/{dsId}", set.getId()) .content("{\"version\":\"anotherVersion\",\"requiredMigrationStep\":\"true\"}") .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); - final DistributionSet setupdated = distributionSetManagement.findDistributionSetById(set.getId()).get(); + final DistributionSet setupdated = distributionSetManagement.get(set.getId()).get(); assertThat(setupdated.isRequiredMigrationStep()).isEqualTo(true); assertThat(setupdated.getVersion()).isEqualTo("anotherVersion"); @@ -695,20 +688,20 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr public void updateRequiredMigrationStepFailsIfDistributionSetisInUse() throws Exception { // prepare test data - assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(PAGE, false, true)).hasSize(0); + assertThat(distributionSetManagement.findByCompleted(PAGE, true)).hasSize(0); final DistributionSet set = testdataFactory.createDistributionSet("one"); deploymentManagement.assignDistributionSet(set.getId(), Arrays.asList(new TargetWithActionType(testdataFactory.createTarget().getControllerId()))); - assertThat(distributionSetManagement.countDistributionSetsAll()).isEqualTo(1); + assertThat(distributionSetManagement.count()).isEqualTo(1); mvc.perform(put("/rest/v1/distributionsets/{dsId}", set.getId()) .content("{\"version\":\"anotherVersion\",\"requiredMigrationStep\":\"true\"}") .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isForbidden()); - final DistributionSet setupdated = distributionSetManagement.findDistributionSetById(set.getId()).get(); + final DistributionSet setupdated = distributionSetManagement.get(set.getId()).get(); assertThat(setupdated.isRequiredMigrationStep()).isEqualTo(false); assertThat(setupdated.getVersion()).isEqualTo(set.getVersion()); @@ -790,9 +783,9 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr .andExpect(jsonPath("[1]value", equalTo(knownValue2))); final DistributionSetMetadata metaKey1 = distributionSetManagement - .findDistributionSetMetadata(testDS.getId(), knownKey1).get(); + .getMetaDataByDistributionSetId(testDS.getId(), knownKey1).get(); final DistributionSetMetadata metaKey2 = distributionSetManagement - .findDistributionSetMetadata(testDS.getId(), knownKey2).get(); + .getMetaDataByDistributionSetId(testDS.getId(), knownKey2).get(); assertThat(metaKey1.getValue()).isEqualTo(knownValue1); assertThat(metaKey2.getValue()).isEqualTo(knownValue2); @@ -818,7 +811,7 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr .andExpect(jsonPath("key", equalTo(knownKey))).andExpect(jsonPath("value", equalTo(updateValue))); final DistributionSetMetadata assertDS = distributionSetManagement - .findDistributionSetMetadata(testDS.getId(), knownKey).get(); + .getMetaDataByDistributionSetId(testDS.getId(), knownKey).get(); assertThat(assertDS.getValue()).isEqualTo(updateValue); } @@ -836,7 +829,7 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr mvc.perform(delete("/rest/v1/distributionsets/{dsId}/metadata/{key}", testDS.getId(), knownKey)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); - assertThat(distributionSetManagement.findDistributionSetMetadata(testDS.getId(), knownKey)).isNotPresent(); + assertThat(distributionSetManagement.getMetaDataByDistributionSetId(testDS.getId(), knownKey)).isNotPresent(); } @Test @@ -855,7 +848,7 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr mvc.perform(delete("/rest/v1/distributionsets/1234/metadata/{key}", knownKey)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isNotFound()); - assertThat(distributionSetManagement.findDistributionSetMetadata(testDS.getId(), knownKey)).isPresent(); + assertThat(distributionSetManagement.getMetaDataByDistributionSetId(testDS.getId(), knownKey)).isPresent(); } @Test @@ -918,8 +911,8 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr public void filterDistributionSetComplete() throws Exception { final int amount = 10; testdataFactory.createDistributionSets(amount); - distributionSetManagement.createDistributionSet( - entityFactory.distributionSet().create().name("incomplete").version("2").type("os")); + distributionSetManagement + .create(entityFactory.distributionSet().create().name("incomplete").version("2").type("os")); final String rsqlFindLikeDs1OrDs2 = "complete==" + Boolean.TRUE; @@ -937,8 +930,8 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr // prepare targets final Collection knownTargetIds = Arrays.asList("1", "2", "3", "4", "5"); - knownTargetIds.forEach(controllerId -> targetManagement - .createTarget(entityFactory.target().create().controllerId(controllerId))); + knownTargetIds.forEach( + controllerId -> targetManagement.create(entityFactory.target().create().controllerId(controllerId))); // assign already one target to DS assignDistributionSet(createdDs.getId(), knownTargetIds.iterator().next()); diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResourceTest.java index 84d7049c2..28d2a9835 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResourceTest.java @@ -113,11 +113,11 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt .andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)); - final Tag createdOne = tagManagement.findAllDistributionSetTags("name==thetest1", PAGE).getContent().get(0); + final Tag createdOne = distributionSetTagManagement.findByRsql(PAGE, "name==thetest1").getContent().get(0); assertThat(createdOne.getName()).isEqualTo(tagOne.getName()); assertThat(createdOne.getDescription()).isEqualTo(tagOne.getDescription()); assertThat(createdOne.getColour()).isEqualTo(tagOne.getColour()); - final Tag createdTwo = tagManagement.findAllDistributionSetTags("name==thetest2", PAGE).getContent().get(0); + final Tag createdTwo = distributionSetTagManagement.findByRsql(PAGE, "name==thetest2").getContent().get(0); assertThat(createdTwo.getName()).isEqualTo(tagTwo.getName()); assertThat(createdTwo.getDescription()).isEqualTo(tagTwo.getDescription()); assertThat(createdTwo.getColour()).isEqualTo(tagTwo.getColour()); @@ -143,7 +143,7 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)); - final Tag updated = tagManagement.findAllDistributionSetTags("name==updatedName", PAGE).getContent().get(0); + final Tag updated = distributionSetTagManagement.findByRsql(PAGE, "name==updatedName").getContent().get(0); assertThat(updated.getName()).isEqualTo(update.getName()); assertThat(updated.getDescription()).isEqualTo(update.getDescription()); assertThat(updated.getColour()).isEqualTo(update.getColour()); @@ -162,7 +162,7 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt mvc.perform(delete(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/" + original.getId())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); - assertThat(tagManagement.findDistributionSetTagById(original.getId())).isNotPresent(); + assertThat(distributionSetTagManagement.get(original.getId())).isNotPresent(); } @Test @@ -242,8 +242,7 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt // 2 DistributionSetUpdateEvent ResultActions result = toggle(tag, sets); - List updated = distributionSetManagement.findDistributionSetsByTag(PAGE, tag.getId()) - .getContent(); + List updated = distributionSetManagement.findByTag(PAGE, tag.getId()).getContent(); assertThat(updated.stream().map(DistributionSet::getId).collect(Collectors.toList())) .containsAll(sets.stream().map(DistributionSet::getId).collect(Collectors.toList())); @@ -254,12 +253,12 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt // 2 DistributionSetUpdateEvent result = toggle(tag, sets); - updated = distributionSetManagement.findDistributionSetsAll(PAGE, false).getContent(); + updated = distributionSetManagement.findAll(PAGE).getContent(); result.andExpect(applyBaseEntityMatcherOnArrayResult(updated.get(0), "unassignedDistributionSets")) .andExpect(applyBaseEntityMatcherOnArrayResult(updated.get(1), "unassignedDistributionSets")); - assertThat(distributionSetManagement.findDistributionSetsByTag(PAGE, tag.getId())).isEmpty(); + assertThat(distributionSetManagement.findByTag(PAGE, tag.getId())).isEmpty(); } private ResultActions toggle(final DistributionSetTag tag, final List sets) throws Exception { @@ -291,8 +290,7 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)); - final List updated = distributionSetManagement.findDistributionSetsByTag(PAGE, tag.getId()) - .getContent(); + final List updated = distributionSetManagement.findByTag(PAGE, tag.getId()).getContent(); assertThat(updated.stream().map(DistributionSet::getId).collect(Collectors.toList())) .containsAll(sets.stream().map(DistributionSet::getId).collect(Collectors.toList())); @@ -319,8 +317,7 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt mvc.perform(delete(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned/" + unassigned.getId())).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); - final List updated = distributionSetManagement.findDistributionSetsByTag(PAGE, tag.getId()) - .getContent(); + final List updated = distributionSetManagement.findByTag(PAGE, tag.getId()).getContent(); assertThat(updated.stream().map(DistributionSet::getId).collect(Collectors.toList())) .containsOnly(assigned.getId()); diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResourceTest.java index 411cbe6bb..8c6f706fc 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResourceTest.java @@ -59,9 +59,9 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn public void getDistributionSetTypes() throws Exception { DistributionSetType testType = distributionSetTypeManagement - .createDistributionSetType(entityFactory.distributionSetType().create().key("test123") + .create(entityFactory.distributionSetType().create().key("test123") .name("TestName123").description("Desc123").colour("col12")); - testType = distributionSetTypeManagement.updateDistributionSetType( + testType = distributionSetTypeManagement.update( entityFactory.distributionSetType().update(testType.getId()).description("Desc1234")); // 4 types overall (2 hawkbit tenant default, 1 test default and 1 @@ -100,9 +100,9 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn public void getDistributionSetTypesSortedByKey() throws Exception { DistributionSetType testType = distributionSetTypeManagement - .createDistributionSetType(entityFactory.distributionSetType().create().key("zzzzz").name("TestName123") + .create(entityFactory.distributionSetType().create().key("zzzzz").name("TestName123") .description("Desc123").colour("col12")); - testType = distributionSetTypeManagement.updateDistributionSetType( + testType = distributionSetTypeManagement.update( entityFactory.distributionSetType().update(testType.getId()).description("Desc1234")); // descending @@ -148,11 +148,11 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn @Step private void verifyCreatedDistributionSetTypes(final MvcResult mvcResult) throws UnsupportedEncodingException { - final DistributionSetType created1 = distributionSetTypeManagement.findDistributionSetTypeByKey("testKey1") + final DistributionSetType created1 = distributionSetTypeManagement.getByKey("testKey1") .get(); - final DistributionSetType created2 = distributionSetTypeManagement.findDistributionSetTypeByKey("testKey2") + final DistributionSetType created2 = distributionSetTypeManagement.getByKey("testKey2") .get(); - final DistributionSetType created3 = distributionSetTypeManagement.findDistributionSetTypeByKey("testKey3") + final DistributionSetType created3 = distributionSetTypeManagement.getByKey("testKey3") .get(); assertThat(created1.getMandatoryModuleTypes()).containsOnly(osType); @@ -190,7 +190,7 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn .toString()).isEqualTo( "http://localhost/rest/v1/distributionsettypes/" + created3.getId() + "/optionalmoduletypes"); - assertThat(distributionSetTypeManagement.countDistributionSetTypesAll()).isEqualTo(6); + assertThat(distributionSetTypeManagement.count()).isEqualTo(6); } @Step @@ -217,7 +217,7 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn @Step private List createTestDistributionSetTestTypes() { - assertThat(distributionSetTypeManagement.countDistributionSetTypesAll()).isEqualTo(DEFAULT_DS_TYPES); + assertThat(distributionSetTypeManagement.count()).isEqualTo(DEFAULT_DS_TYPES); return Arrays.asList( entityFactory.distributionSetType().create().key("testKey1").name("TestName1").description("Desc1") @@ -235,7 +235,7 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn @Description("Checks the correct behaviour of /rest/v1/distributionsettypes/{ID}/mandatorymoduletypes POST requests.") public void addMandatoryModuleToDistributionSetType() throws Exception { DistributionSetType testType = distributionSetTypeManagement - .createDistributionSetType(entityFactory.distributionSetType().create().key("test123") + .create(entityFactory.distributionSetType().create().key("test123") .name("TestName123").description("Desc123").colour("col12")); assertThat(testType.getOptLockRevision()).isEqualTo(1); @@ -243,7 +243,7 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn .content("{\"id\":" + osType.getId() + "}").contentType(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); - testType = distributionSetTypeManagement.findDistributionSetTypeById(testType.getId()).get(); + testType = distributionSetTypeManagement.get(testType.getId()).get(); assertThat(testType.getLastModifiedBy()).isEqualTo("uploadTester"); assertThat(testType.getOptLockRevision()).isEqualTo(2); assertThat(testType.getMandatoryModuleTypes()).containsExactly(osType); @@ -255,7 +255,7 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn @Description("Checks the correct behaviour of /rest/v1/distributionsettypes/{ID}/optionalmoduletypes POST requests.") public void addOptionalModuleToDistributionSetType() throws Exception { DistributionSetType testType = distributionSetTypeManagement - .createDistributionSetType(entityFactory.distributionSetType().create().key("test123") + .create(entityFactory.distributionSetType().create().key("test123") .name("TestName123").description("Desc123").colour("col12")); assertThat(testType.getOptLockRevision()).isEqualTo(1); @@ -263,7 +263,7 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn .content("{\"id\":" + osType.getId() + "}").contentType(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); - testType = distributionSetTypeManagement.findDistributionSetTypeById(testType.getId()).get(); + testType = distributionSetTypeManagement.get(testType.getId()).get(); assertThat(testType.getLastModifiedBy()).isEqualTo("uploadTester"); assertThat(testType.getOptLockRevision()).isEqualTo(2); assertThat(testType.getOptionalModuleTypes()).containsExactly(osType); @@ -318,7 +318,7 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn } private DistributionSetType generateTestType() { - final DistributionSetType testType = distributionSetTypeManagement.createDistributionSetType(entityFactory + final DistributionSetType testType = distributionSetTypeManagement.create(entityFactory .distributionSetType().create().key("test123").name("TestName123").description("Desc123").colour("col") .mandatory(Arrays.asList(osType.getId())).optional(Arrays.asList(appType.getId()))); assertThat(testType.getOptLockRevision()).isEqualTo(1); @@ -354,7 +354,7 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn osType.getId()).contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()) .andExpect(status().isOk()); - testType = distributionSetTypeManagement.findDistributionSetTypeById(testType.getId()).get(); + testType = distributionSetTypeManagement.get(testType.getId()).get(); assertThat(testType.getLastModifiedBy()).isEqualTo("uploadTester"); assertThat(testType.getOptLockRevision()).isEqualTo(2); assertThat(testType.getOptionalModuleTypes()).containsExactly(appType); @@ -371,7 +371,7 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn appType.getId()).contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()) .andExpect(status().isOk()); - testType = distributionSetTypeManagement.findDistributionSetTypeById(testType.getId()).get(); + testType = distributionSetTypeManagement.get(testType.getId()).get(); assertThat(testType.getLastModifiedBy()).isEqualTo("uploadTester"); assertThat(testType.getOptLockRevision()).isEqualTo(2); assertThat(testType.getOptionalModuleTypes()).isEmpty(); @@ -384,9 +384,9 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn public void getDistributionSetType() throws Exception { DistributionSetType testType = distributionSetTypeManagement - .createDistributionSetType(entityFactory.distributionSetType().create().key("test123") + .create(entityFactory.distributionSetType().create().key("test123") .name("TestName123").description("Desc123").colour("col12")); - testType = distributionSetTypeManagement.updateDistributionSetType( + testType = distributionSetTypeManagement.update( entityFactory.distributionSetType().update(testType.getId()).description("Desc1234")); mvc.perform(get("/rest/v1/distributionsettypes/{dstId}", testType.getId()).accept(MediaType.APPLICATION_JSON)) @@ -404,15 +404,15 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn @Description("Checks the correct behaviour of /rest/v1/DistributionSetTypes/{ID} DELETE requests (hard delete scenario).") public void deleteDistributionSetTypeUnused() throws Exception { final DistributionSetType testType = distributionSetTypeManagement - .createDistributionSetType(entityFactory.distributionSetType().create().key("test123") + .create(entityFactory.distributionSetType().create().key("test123") .name("TestName123").description("Desc123").colour("col12")); - assertThat(distributionSetTypeManagement.countDistributionSetTypesAll()).isEqualTo(DEFAULT_DS_TYPES + 1); + assertThat(distributionSetTypeManagement.count()).isEqualTo(DEFAULT_DS_TYPES + 1); mvc.perform(delete("/rest/v1/distributionsettypes/{dsId}", testType.getId())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); - assertThat(distributionSetTypeManagement.countDistributionSetTypesAll()).isEqualTo(DEFAULT_DS_TYPES); + assertThat(distributionSetTypeManagement.count()).isEqualTo(DEFAULT_DS_TYPES); } @Test @@ -427,27 +427,27 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn @Description("Checks the correct behaviour of /rest/v1/DistributionSetTypes/{ID} DELETE requests (soft delete scenario).") public void deleteDistributionSetTypeUsed() throws Exception { final DistributionSetType testType = distributionSetTypeManagement - .createDistributionSetType(entityFactory.distributionSetType().create().key("test123") + .create(entityFactory.distributionSetType().create().key("test123") .name("TestName123").description("Desc123").colour("col12")); - distributionSetManagement.createDistributionSet(entityFactory.distributionSet().create().name("sdfsd") + distributionSetManagement.create(entityFactory.distributionSet().create().name("sdfsd") .description("dsfsdf").version("1").type(testType)); - assertThat(distributionSetTypeManagement.countDistributionSetTypesAll()).isEqualTo(DEFAULT_DS_TYPES + 1); - assertThat(distributionSetManagement.countDistributionSetsAll()).isEqualTo(1); + assertThat(distributionSetTypeManagement.count()).isEqualTo(DEFAULT_DS_TYPES + 1); + assertThat(distributionSetManagement.count()).isEqualTo(1); mvc.perform(delete("/rest/v1/distributionsettypes/{smId}", testType.getId())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); - assertThat(distributionSetManagement.countDistributionSetsAll()).isEqualTo(1); - assertThat(distributionSetTypeManagement.countDistributionSetTypesAll()).isEqualTo(DEFAULT_DS_TYPES); + assertThat(distributionSetManagement.count()).isEqualTo(1); + assertThat(distributionSetTypeManagement.count()).isEqualTo(DEFAULT_DS_TYPES); } @Test @Description("Checks the correct behaviour of /rest/v1/distributionsettypes/{ID} PUT requests.") public void updateDistributionSetTypeOnlyDescriptionAndNameUntouched() throws Exception { final DistributionSetType testType = distributionSetTypeManagement - .createDistributionSetType(entityFactory.distributionSetType().create().key("test123") + .create(entityFactory.distributionSetType().create().key("test123") .name("TestName123").description("Desc123").colour("col")); final String body = new JSONObject().put("id", testType.getId()).put("description", "foobardesc") @@ -510,7 +510,7 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn // .createDistributionSetType(entityFactory.distributionSetType().create().key("test123") // .name("TestName123").description("Desc123").colour("col")); - final SoftwareModuleType testSmType = softwareModuleTypeManagement.createSoftwareModuleType( + final SoftwareModuleType testSmType = softwareModuleTypeManagement.create( entityFactory.softwareModuleType().create().key("test123").name("TestName123")); // DST does not exist @@ -598,9 +598,9 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn @Test @Description("Search erquest of software module types.") public void searchDistributionSetTypeRsql() throws Exception { - distributionSetTypeManagement.createDistributionSetType( + distributionSetTypeManagement.create( entityFactory.distributionSetType().create().key("test123").name("TestName123")); - distributionSetTypeManagement.createDistributionSetType( + distributionSetTypeManagement.create( entityFactory.distributionSetType().create().key("test1234").name("TestName1234")); final String rsqlFindLikeDs1OrDs2 = "name==TestName123,name==TestName1234"; @@ -615,7 +615,7 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn char character = 'a'; for (int index = 0; index < amount; index++) { final String str = String.valueOf(character); - softwareModuleManagement.createSoftwareModule( + softwareModuleManagement.create( entityFactory.softwareModule().create().name(str).description(str).vendor(str).version(str)); character++; } diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResourceTest.java index 2096a43c8..19fdbc1a6 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResourceTest.java @@ -223,7 +223,7 @@ public class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTes final DistributionSet dsA = testdataFactory.createDistributionSet(""); // create rollout including the created targets with prefix 'rollout' - final Rollout rollout = rolloutManagement.createRollout( + final Rollout rollout = rolloutManagement.create( entityFactory.rollout().create().name("rollout1").set(dsA.getId()) .targetFilterQuery("controllerId==rollout*"), 4, new RolloutGroupConditionBuilder().withDefaults() @@ -254,7 +254,7 @@ public class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTes @Step private void retrieveAndVerifyRolloutInStarting(final Rollout rollout) throws Exception { - rolloutManagement.startRollout(rollout.getId()); + rolloutManagement.start(rollout.getId()); mvc.perform(get("/rest/v1/rollouts/" + rollout.getId()).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) @@ -592,17 +592,17 @@ public class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTes final DistributionSet dsA = testdataFactory.createDistributionSet(""); // create rollout including the created targets with prefix 'rollout' - final Rollout rollout = rolloutManagement.createRollout( + final Rollout rollout = rolloutManagement.create( entityFactory.rollout().create().name("rollout1").set(dsA.getId()) .targetFilterQuery("controllerId==rollout*"), 4, new RolloutGroupConditionBuilder().withDefaults() .successCondition(RolloutGroupSuccessCondition.THRESHOLD, "100").build()); final RolloutGroup firstGroup = rolloutGroupManagement - .findRolloutGroupsByRolloutId(rollout.getId(), new PageRequest(0, 1, Direction.ASC, "id")).getContent() + .findByRollout(new PageRequest(0, 1, Direction.ASC, "id"), rollout.getId()).getContent() .get(0); final RolloutGroup secondGroup = rolloutGroupManagement - .findRolloutGroupsByRolloutId(rollout.getId(), new PageRequest(1, 1, Direction.ASC, "id")).getContent() + .findByRollout(new PageRequest(1, 1, Direction.ASC, "id"), rollout.getId()).getContent() .get(0); retrieveAndVerifyRolloutGroupInCreating(rollout, firstGroup); @@ -613,7 +613,7 @@ public class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTes @Step private void retrieveAndVerifyRolloutGroupInRunningAndScheduled(final Rollout rollout, final RolloutGroup firstGroup, final RolloutGroup secondGroup) throws Exception { - rolloutManagement.startRollout(rollout.getId()); + rolloutManagement.start(rollout.getId()); rolloutManagement.handleRollouts(); mvc.perform(get("/rest/v1/rollouts/{rolloutId}/deploygroups/{groupId}", rollout.getId(), firstGroup.getId()) .accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) @@ -696,7 +696,7 @@ public class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTes final Rollout rollout = createRollout("rollout1", 2, dsA.getId(), "controllerId==rollout*"); final RolloutGroup firstGroup = rolloutGroupManagement - .findRolloutGroupsByRolloutId(rollout.getId(), new PageRequest(0, 1, Direction.ASC, "id")).getContent() + .findByRollout(new PageRequest(0, 1, Direction.ASC, "id"), rollout.getId()).getContent() .get(0); // retrieve targets from the first rollout group with known ID @@ -720,10 +720,10 @@ public class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTes final Rollout rollout = createRollout("rollout1", 2, dsA.getId(), "controllerId==rollout*"); final RolloutGroup firstGroup = rolloutGroupManagement - .findRolloutGroupsByRolloutId(rollout.getId(), new PageRequest(0, 1, Direction.ASC, "id")).getContent() + .findByRollout(new PageRequest(0, 1, Direction.ASC, "id"), rollout.getId()).getContent() .get(0); - final String targetInGroup = rolloutGroupManagement.findRolloutGroupTargets(firstGroup.getId(), PAGE) + final String targetInGroup = rolloutGroupManagement.findTargetsOfRolloutGroup(PAGE, firstGroup.getId()) .getContent().get(0).getControllerId(); // retrieve targets from the first rollout group with known ID @@ -746,13 +746,13 @@ public class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTes // create rollout including the created targets with prefix 'rollout' final Rollout rollout = createRollout("rollout1", 2, dsA.getId(), "controllerId==rollout*"); - rolloutManagement.startRollout(rollout.getId()); + rolloutManagement.start(rollout.getId()); // Run here, because scheduler is disabled during tests rolloutManagement.handleRollouts(); final RolloutGroup firstGroup = rolloutGroupManagement - .findRolloutGroupsByRolloutId(rollout.getId(), new PageRequest(0, 1, Direction.ASC, "id")).getContent() + .findByRollout(new PageRequest(0, 1, Direction.ASC, "id"), rollout.getId()).getContent() .get(0); // retrieve targets from the first rollout group with known ID @@ -945,7 +945,7 @@ public class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTes private Rollout createRollout(final String name, final int amountGroups, final long distributionSetId, final String targetFilterQuery) { - final Rollout rollout = rolloutManagement.createRollout( + final Rollout rollout = rolloutManagement.create( entityFactory.rollout().create().name(name).set(distributionSetId).targetFilterQuery(targetFilterQuery), amountGroups, new RolloutGroupConditionBuilder().withDefaults() .successCondition(RolloutGroupSuccessCondition.THRESHOLD, "100").build()); @@ -953,7 +953,7 @@ public class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTes // Run here, because Scheduler is disabled during tests rolloutManagement.handleRollouts(); - return rolloutManagement.findRolloutById(rollout.getId()).get(); + return rolloutManagement.get(rollout.getId()).get(); } protected boolean success(final Rollout result) { @@ -961,7 +961,7 @@ public class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTes } public Rollout getRollout(final Long rolloutId) throws Exception { - return rolloutManagement.findRolloutById(rolloutId).get(); + return rolloutManagement.get(rolloutId).get(); } } diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java index 828d05796..713ad2aa3 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java @@ -70,7 +70,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra @Before public void assertPreparationOfRepo() { - assertThat(softwareModuleManagement.findSoftwareModulesAll(PAGE)).as("no softwaremodule should be founded") + assertThat(softwareModuleManagement.findAll(PAGE)).as("no softwaremodule should be founded") .hasSize(0); } @@ -87,7 +87,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra final String updateDescription = "newDescription1"; SoftwareModule sm = softwareModuleManagement - .createSoftwareModule(entityFactory.softwareModule().create().type(osType).name(knownSWName) + .create(entityFactory.softwareModule().create().type(osType).name(knownSWName) .version(knownSWVersion).description(knownSWDescription).vendor(knownSWVendor)); assertThat(sm.getName()).as("Wrong name of the software module").isEqualTo(knownSWName); @@ -108,7 +108,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra .andExpect(jsonPath("$.description", equalTo(updateDescription))) .andExpect(jsonPath("$.name", equalTo(knownSWName))).andReturn(); - sm = softwareModuleManagement.findSoftwareModuleById(sm.getId()).get(); + sm = softwareModuleManagement.get(sm.getId()).get(); assertThat(sm.getName()).isEqualTo(knownSWName); assertThat(sm.getVendor()).isEqualTo(updateVendor); assertThat(sm.getLastModifiedBy()).isEqualTo("smUpdateTester"); @@ -141,7 +141,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra // check rest of response compared to DB final MgmtArtifact artResult = ResourceUtility .convertArtifactResponse(mvcResult.getResponse().getContentAsString()); - final Long artId = softwareModuleManagement.findSoftwareModuleById(sm.getId()).get().getArtifacts().get(0) + final Long artId = softwareModuleManagement.get(sm.getId()).get().getArtifacts().get(0) .getId(); assertThat(artResult.getArtifactId()).as("Wrong artifact id").isEqualTo(artId); assertThat(JsonPath.compile("$._links.self.href").read(mvcResult.getResponse().getContentAsString()).toString()) @@ -157,34 +157,34 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra private void assertArtifact(final SoftwareModule sm, final byte[] random) throws IOException { // check result in db... // repo - assertThat(artifactManagement.countArtifactsAll()).as("Wrong artifact size").isEqualTo(1); + assertThat(artifactManagement.count()).as("Wrong artifact size").isEqualTo(1); // binary try (InputStream fileInputStream = artifactManagement.loadArtifactBinary( - softwareModuleManagement.findSoftwareModuleById(sm.getId()).get().getArtifacts().get(0).getSha1Hash()) + softwareModuleManagement.get(sm.getId()).get().getArtifacts().get(0).getSha1Hash()) .get().getFileInputStream()) { assertTrue("Wrong artifact content", IOUtils.contentEquals(new ByteArrayInputStream(random), fileInputStream)); } // hashes - assertThat(artifactManagement.findArtifactByFilename("origFilename").get().getSha1Hash()).as("Wrong sha1 hash") + assertThat(artifactManagement.getByFilename("origFilename").get().getSha1Hash()).as("Wrong sha1 hash") .isEqualTo(HashGeneratorUtils.generateSHA1(random)); - assertThat(artifactManagement.findArtifactByFilename("origFilename").get().getMd5Hash()).as("Wrong md5 hash") + assertThat(artifactManagement.getByFilename("origFilename").get().getMd5Hash()).as("Wrong md5 hash") .isEqualTo(HashGeneratorUtils.generateMD5(random)); // metadata assertThat( - softwareModuleManagement.findSoftwareModuleById(sm.getId()).get().getArtifacts().get(0).getFilename()) + softwareModuleManagement.get(sm.getId()).get().getArtifacts().get(0).getFilename()) .as("wrong metadata of the filename").isEqualTo("origFilename"); } @Test @Description("Verfies that the system does not accept empty artifact uploads. Expected response: BAD REQUEST") public void emptyUploadArtifact() throws Exception { - assertThat(softwareModuleManagement.findSoftwareModulesAll(PAGE)).hasSize(0); - assertThat(artifactManagement.countArtifactsAll()).isEqualTo(0); + assertThat(softwareModuleManagement.findAll(PAGE)).hasSize(0); + assertThat(artifactManagement.count()).isEqualTo(0); final SoftwareModule sm = testdataFactory.createSoftwareModuleOs(); @@ -220,7 +220,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra @Description("verfies that option to upload artifacts with a custom defined by metadata, i.e. not the file name of the binary itself.") public void uploadArtifactWithCustomName() throws Exception { final SoftwareModule sm = testdataFactory.createSoftwareModuleOs(); - assertThat(artifactManagement.countArtifactsAll()).isEqualTo(0); + assertThat(artifactManagement.count()).isEqualTo(0); // create test file final byte random[] = RandomStringUtils.random(5 * 1024).getBytes(); @@ -235,10 +235,10 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra // check result in db... // repo - assertThat(artifactManagement.countArtifactsAll()).isEqualTo(1); + assertThat(artifactManagement.count()).isEqualTo(1); // hashes - assertThat(artifactManagement.findArtifactByFilename("customFilename")).as("Local artifact is wrong") + assertThat(artifactManagement.getByFilename("customFilename")).as("Local artifact is wrong") .isPresent(); } @@ -246,7 +246,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra @Description("Verfies that the system refuses upload of an artifact where the provided hash sums do not match. Expected result: BAD REQUEST") public void uploadArtifactWithHashCheck() throws Exception { final SoftwareModule sm = testdataFactory.createSoftwareModuleOs(); - assertThat(artifactManagement.countArtifactsAll()).isEqualTo(0); + assertThat(artifactManagement.count()).isEqualTo(0); // create test file final byte random[] = RandomStringUtils.random(5 * 1024).getBytes(); @@ -292,16 +292,16 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra final byte random[] = RandomStringUtils.random(5 * 1024).getBytes(); - final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), + final Artifact artifact = artifactManagement.create(new ByteArrayInputStream(random), sm.getId(), "file1", false); - final Artifact artifact2 = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), + final Artifact artifact2 = artifactManagement.create(new ByteArrayInputStream(random), sm.getId(), "file2", false); downloadAndVerify(sm, random, artifact); downloadAndVerify(sm, random, artifact2); - assertThat(softwareModuleManagement.findSoftwareModulesAll(PAGE)).as("Softwaremodule size is wrong").hasSize(1); - assertThat(artifactManagement.countArtifactsAll()).isEqualTo(2); + assertThat(softwareModuleManagement.findAll(PAGE)).as("Softwaremodule size is wrong").hasSize(1); + assertThat(artifactManagement.count()).isEqualTo(2); } private void downloadAndVerify(final SoftwareModule sm, final byte[] random, final Artifact artifact) @@ -322,7 +322,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra final SoftwareModule sm = testdataFactory.createSoftwareModuleOs(); final byte random[] = RandomStringUtils.random(5 * 1024).getBytes(); - final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), + final Artifact artifact = artifactManagement.create(new ByteArrayInputStream(random), sm.getId(), "file1", false); // perform test @@ -348,9 +348,9 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra final byte random[] = RandomStringUtils.random(5 * 1024).getBytes(); - final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), + final Artifact artifact = artifactManagement.create(new ByteArrayInputStream(random), sm.getId(), "file1", false); - final Artifact artifact2 = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), + final Artifact artifact2 = artifactManagement.create(new ByteArrayInputStream(random), sm.getId(), "file2", false); mvc.perform(get("/rest/v1/softwaremodules/{smId}/artifacts", sm.getId()).accept(MediaType.APPLICATION_JSON)) @@ -394,7 +394,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra .andDo(MockMvcResultPrinter.print()).andExpect(status().isNotFound()); // SM does not exist - artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", false); + artifactManagement.create(new ByteArrayInputStream(random), sm.getId(), "file1", false); mvc.perform(get("/rest/v1/softwaremodules/1234567890/artifacts")).andDo(MockMvcResultPrinter.print()) .andExpect(status().isNotFound()); @@ -548,7 +548,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra .andExpect(jsonPath("$.content.[?(@.id==" + app.getId() + ")]._links.self.href", contains("http://localhost/rest/v1/softwaremodules/" + app.getId()))); - assertThat(softwareModuleManagement.findSoftwareModulesAll(PAGE)).as("Softwaremodule size is wrong").hasSize(2); + assertThat(softwareModuleManagement.findAll(PAGE)).as("Softwaremodule size is wrong").hasSize(2); } @Test @@ -559,7 +559,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra testdataFactory.createSoftwareModuleOs("2"); final SoftwareModule app2 = testdataFactory.createSoftwareModuleApp("2"); - assertThat(softwareModuleManagement.findSoftwareModulesAll(PAGE)).hasSize(4); + assertThat(softwareModuleManagement.findAll(PAGE)).hasSize(4); // only by name, only one exists per name mvc.perform(get("/rest/v1/softwaremodules?q=name==" + os1.getName()).accept(MediaType.APPLICATION_JSON)) @@ -649,7 +649,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra .andExpect(jsonPath("$._links.artifacts.href", equalTo("http://localhost/rest/v1/softwaremodules/" + os.getId() + "/artifacts"))); - assertThat(softwareModuleManagement.findSoftwareModulesAll(PAGE)).as("Softwaremodule size is wrong").hasSize(1); + assertThat(softwareModuleManagement.findAll(PAGE)).as("Softwaremodule size is wrong").hasSize(1); } @Test @@ -684,9 +684,9 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra .andExpect(jsonPath("[1].createdAt", not(equalTo(0)))).andReturn(); final SoftwareModule osCreated = softwareModuleManagement - .findSoftwareModuleByNameAndVersion("name1", "version1", osType.getId()).get(); + .getByNameAndVersionAndType("name1", "version1", osType.getId()).get(); final SoftwareModule appCreated = softwareModuleManagement - .findSoftwareModuleByNameAndVersion("name3", "version3", appType.getId()).get(); + .getByNameAndVersionAndType("name3", "version3", appType.getId()).get(); assertThat( JsonPath.compile("[0]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString()) @@ -704,16 +704,16 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra .toString()).as("Response contains invalid artifacts href") .isEqualTo("http://localhost/rest/v1/softwaremodules/" + appCreated.getId() + "/artifacts"); - assertThat(softwareModuleManagement.findSoftwareModulesAll(PAGE)).as("Wrong softwaremodule size").hasSize(2); + assertThat(softwareModuleManagement.findAll(PAGE)).as("Wrong softwaremodule size").hasSize(2); assertThat( - softwareModuleManagement.findSoftwareModulesByType(PAGE, osType.getId()).getContent().get(0).getName()) + softwareModuleManagement.findByType(PAGE, osType.getId()).getContent().get(0).getName()) .as("Softwaremoudle name is wrong").isEqualTo(os.getName()); - assertThat(softwareModuleManagement.findSoftwareModulesByType(PAGE, osType.getId()).getContent().get(0) + assertThat(softwareModuleManagement.findByType(PAGE, osType.getId()).getContent().get(0) .getCreatedBy()).as("Softwaremoudle created by is wrong").isEqualTo("uploadTester"); - assertThat(softwareModuleManagement.findSoftwareModulesByType(PAGE, osType.getId()).getContent().get(0) + assertThat(softwareModuleManagement.findByType(PAGE, osType.getId()).getContent().get(0) .getCreatedAt()).as("Softwaremoudle created at is wrong").isGreaterThanOrEqualTo(current); assertThat( - softwareModuleManagement.findSoftwareModulesByType(PAGE, appType.getId()).getContent().get(0).getName()) + softwareModuleManagement.findByType(PAGE, appType.getId()).getContent().get(0).getName()) .as("Softwaremoudle name is wrong").isEqualTo(ah.getName()); } @@ -725,17 +725,17 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra final byte random[] = RandomStringUtils.random(5 * 1024).getBytes(); - artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", false); + artifactManagement.create(new ByteArrayInputStream(random), sm.getId(), "file1", false); - assertThat(softwareModuleManagement.findSoftwareModulesAll(PAGE)).as("Softwaremoudle size is wrong").hasSize(1); - assertThat(artifactManagement.countArtifactsAll()).isEqualTo(1); + assertThat(softwareModuleManagement.findAll(PAGE)).as("Softwaremoudle size is wrong").hasSize(1); + assertThat(artifactManagement.count()).isEqualTo(1); mvc.perform(delete("/rest/v1/softwaremodules/{smId}", sm.getId())).andDo(MockMvcResultPrinter.print()) .andExpect(status().isOk()); - assertThat(softwareModuleManagement.findSoftwareModulesAll(PAGE)) + assertThat(softwareModuleManagement.findAll(PAGE)) .as("After delete no softwarmodule should be available").isEmpty(); - assertThat(artifactManagement.countArtifactsAll()).isEqualTo(0); + assertThat(artifactManagement.count()).isEqualTo(0); } @Test @@ -745,11 +745,11 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra final byte random[] = RandomStringUtils.random(5 * 1024).getBytes(); - artifactManagement.createArtifact(new ByteArrayInputStream(random), + artifactManagement.create(new ByteArrayInputStream(random), ds1.findFirstModuleByType(appType).get().getId(), "file1", false); - assertThat(softwareModuleManagement.findSoftwareModulesAll(PAGE)).hasSize(3); - assertThat(artifactManagement.countArtifactsAll()).isEqualTo(1); + assertThat(softwareModuleManagement.findAll(PAGE)).hasSize(3); + assertThat(artifactManagement.count()).isEqualTo(1); mvc.perform(delete("/rest/v1/softwaremodules/{smId}", ds1.findFirstModuleByType(appType).get().getId())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); @@ -759,9 +759,9 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); // all 3 are now marked as deleted - assertThat(softwareModuleManagement.findSoftwareModulesAll(PAGE).getNumber()) + assertThat(softwareModuleManagement.findAll(PAGE).getNumber()) .as("After delete no softwarmodule should be available").isEqualTo(0); - assertThat(artifactManagement.countArtifactsAll()).isEqualTo(1); + assertThat(artifactManagement.count()).isEqualTo(1); } @Test @@ -773,25 +773,25 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra final byte random[] = RandomStringUtils.random(5 * 1024).getBytes(); // Create 2 artifacts - final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), + final Artifact artifact = artifactManagement.create(new ByteArrayInputStream(random), sm.getId(), "file1", false); - artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), "file2", false); + artifactManagement.create(new ByteArrayInputStream(random), sm.getId(), "file2", false); // check repo before delete - assertThat(softwareModuleManagement.findSoftwareModulesAll(PAGE)).hasSize(1); + assertThat(softwareModuleManagement.findAll(PAGE)).hasSize(1); - assertThat(softwareModuleManagement.findSoftwareModuleById(sm.getId()).get().getArtifacts()).hasSize(2); - assertThat(artifactManagement.countArtifactsAll()).isEqualTo(2); + assertThat(softwareModuleManagement.get(sm.getId()).get().getArtifacts()).hasSize(2); + assertThat(artifactManagement.count()).isEqualTo(2); // delete mvc.perform(delete("/rest/v1/softwaremodules/{smId}/artifacts/{artId}", sm.getId(), artifact.getId())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); // check that only one artifact is still alive and still assigned - assertThat(softwareModuleManagement.findSoftwareModulesAll(PAGE)).as("After the sm should be marked as deleted") + assertThat(softwareModuleManagement.findAll(PAGE)).as("After the sm should be marked as deleted") .hasSize(1); - assertThat(artifactManagement.countArtifactsAll()).isEqualTo(1); - assertThat(softwareModuleManagement.findSoftwareModuleById(sm.getId()).get().getArtifacts()) + assertThat(artifactManagement.count()).isEqualTo(1); + assertThat(softwareModuleManagement.get(sm.getId()).get().getArtifacts()) .as("After delete artifact should available for marked as deleted sm's").hasSize(1); } @@ -820,9 +820,9 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra .andExpect(jsonPath("[1]value", equalTo(knownValue2))); final SoftwareModuleMetadata metaKey1 = softwareModuleManagement - .findSoftwareModuleMetadata(sm.getId(), knownKey1).get(); + .getMetaDataBySoftwareModuleId(sm.getId(), knownKey1).get(); final SoftwareModuleMetadata metaKey2 = softwareModuleManagement - .findSoftwareModuleMetadata(sm.getId(), knownKey2).get(); + .getMetaDataBySoftwareModuleId(sm.getId(), knownKey2).get(); assertThat(metaKey1.getValue()).as("Metadata key is wrong").isEqualTo(knownValue1); assertThat(metaKey2.getValue()).as("Metadata key is wrong").isEqualTo(knownValue2); @@ -837,7 +837,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra final String updateValue = "valueForUpdate"; final SoftwareModule sm = testdataFactory.createSoftwareModuleOs(); - softwareModuleManagement.createSoftwareModuleMetadata(sm.getId(), + softwareModuleManagement.createMetaData(sm.getId(), entityFactory.generateMetadata(knownKey, knownValue)); final JSONObject jsonObject = new JSONObject().put("key", knownKey).put("value", updateValue); @@ -849,7 +849,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra .andExpect(jsonPath("key", equalTo(knownKey))).andExpect(jsonPath("value", equalTo(updateValue))); final SoftwareModuleMetadata assertDS = softwareModuleManagement - .findSoftwareModuleMetadata(sm.getId(), knownKey).get(); + .getMetaDataBySoftwareModuleId(sm.getId(), knownKey).get(); assertThat(assertDS.getValue()).as("Metadata is wrong").isEqualTo(updateValue); } @@ -861,13 +861,13 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra final String knownValue = "knownValue"; final SoftwareModule sm = testdataFactory.createSoftwareModuleOs(); - softwareModuleManagement.createSoftwareModuleMetadata(sm.getId(), + softwareModuleManagement.createMetaData(sm.getId(), entityFactory.generateMetadata(knownKey, knownValue)); mvc.perform(delete("/rest/v1/softwaremodules/{swId}/metadata/{key}", sm.getId(), knownKey)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); - assertThat(softwareModuleManagement.findSoftwareModuleMetadata(sm.getId(), knownKey)).isNotPresent(); + assertThat(softwareModuleManagement.getMetaDataBySoftwareModuleId(sm.getId(), knownKey)).isNotPresent(); } @Test @@ -878,7 +878,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra final String knownValue = "knownValue"; final SoftwareModule sm = testdataFactory.createSoftwareModuleOs(); - softwareModuleManagement.createSoftwareModuleMetadata(sm.getId(), + softwareModuleManagement.createMetaData(sm.getId(), entityFactory.generateMetadata(knownKey, knownValue)); mvc.perform(delete("/rest/v1/softwaremodules/{swId}/metadata/XXX", sm.getId(), knownKey)) @@ -887,7 +887,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra mvc.perform(delete("/rest/v1/softwaremodules/1234/metadata/{key}", knownKey)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isNotFound()); - assertThat(softwareModuleManagement.findSoftwareModuleMetadata(sm.getId(), knownKey)).isPresent(); + assertThat(softwareModuleManagement.getMetaDataBySoftwareModuleId(sm.getId(), knownKey)).isPresent(); } @Test @@ -906,7 +906,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra final SoftwareModule sm = testdataFactory.createSoftwareModuleOs(); for (int index = 0; index < totalMetadata; index++) { - softwareModuleManagement.createSoftwareModuleMetadata(sm.getId(), + softwareModuleManagement.createMetaData(sm.getId(), entityFactory.generateMetadata(knownKeyPrefix + index, knownValuePrefix + index)); } @@ -922,7 +922,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra char character = 'a'; for (int index = 0; index < amount; index++) { final String str = String.valueOf(character); - softwareModuleManagement.createSoftwareModule(entityFactory.softwareModule().create().type(osType).name(str) + softwareModuleManagement.create(entityFactory.softwareModule().create().type(osType).name(str) .description(str).vendor(str).version(str)); character++; } diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResourceTest.java index d1d17ec39..71069b8ed 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResourceTest.java @@ -91,9 +91,9 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt private SoftwareModuleType createTestType() { SoftwareModuleType testType = softwareModuleTypeManagement - .createSoftwareModuleType(entityFactory.softwareModuleType().create().key("test123").name("TestName123") + .create(entityFactory.softwareModuleType().create().key("test123").name("TestName123") .description("Desc123").maxAssignments(5)); - testType = softwareModuleTypeManagement.updateSoftwareModuleType( + testType = softwareModuleTypeManagement.update( entityFactory.softwareModuleType().update(testType.getId()).description("Desc1234")); return testType; } @@ -190,9 +190,9 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt .andExpect(jsonPath("[2].createdAt", not(equalTo(0)))) .andExpect(jsonPath("[2].maxAssignments", equalTo(3))).andReturn(); - final SoftwareModuleType created1 = softwareModuleTypeManagement.findSoftwareModuleTypeByKey("test1").get(); - final SoftwareModuleType created2 = softwareModuleTypeManagement.findSoftwareModuleTypeByKey("test2").get(); - final SoftwareModuleType created3 = softwareModuleTypeManagement.findSoftwareModuleTypeByKey("test3").get(); + final SoftwareModuleType created1 = softwareModuleTypeManagement.getByKey("test1").get(); + final SoftwareModuleType created2 = softwareModuleTypeManagement.getByKey("test2").get(); + final SoftwareModuleType created3 = softwareModuleTypeManagement.getByKey("test3").get(); assertThat( JsonPath.compile("[0]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString()) @@ -204,7 +204,7 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt JsonPath.compile("[2]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString()) .isEqualTo("http://localhost/rest/v1/softwaremoduletypes/" + created3.getId()); - assertThat(softwareModuleTypeManagement.countSoftwareModuleTypesAll()).isEqualTo(6); + assertThat(softwareModuleTypeManagement.count()).isEqualTo(6); } @Test @@ -231,12 +231,12 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt public void deleteSoftwareModuleTypeUnused() throws Exception { final SoftwareModuleType testType = createTestType(); - assertThat(softwareModuleTypeManagement.countSoftwareModuleTypesAll()).isEqualTo(4); + assertThat(softwareModuleTypeManagement.count()).isEqualTo(4); mvc.perform(delete("/rest/v1/softwaremoduletypes/{smId}", testType.getId())).andDo(MockMvcResultPrinter.print()) .andExpect(status().isOk()); - assertThat(softwareModuleTypeManagement.countSoftwareModuleTypesAll()).isEqualTo(3); + assertThat(softwareModuleTypeManagement.count()).isEqualTo(3); } @Test @@ -251,15 +251,15 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt @Description("Checks the correct behaviour of /rest/v1/softwaremoduletypes/{ID} DELETE requests (soft delete scenario).") public void deleteSoftwareModuleTypeUsed() throws Exception { final SoftwareModuleType testType = createTestType(); - softwareModuleManagement.createSoftwareModule( + softwareModuleManagement.create( entityFactory.softwareModule().create().type(testType).name("name").version("version")); - assertThat(softwareModuleTypeManagement.countSoftwareModuleTypesAll()).isEqualTo(4); + assertThat(softwareModuleTypeManagement.count()).isEqualTo(4); mvc.perform(delete("/rest/v1/softwaremoduletypes/{smId}", testType.getId())).andDo(MockMvcResultPrinter.print()) .andExpect(status().isOk()); - assertThat(softwareModuleTypeManagement.countSoftwareModuleTypesAll()).isEqualTo(3); + assertThat(softwareModuleTypeManagement.count()).isEqualTo(3); } @Test @@ -370,9 +370,9 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt @Test @Description("Search erquest of software module types.") public void searchSoftwareModuleTypeRsql() throws Exception { - softwareModuleTypeManagement.createSoftwareModuleType(entityFactory.softwareModuleType().create().key("test123") + softwareModuleTypeManagement.create(entityFactory.softwareModuleType().create().key("test123") .name("TestName123").description("Desc123").maxAssignments(5)); - softwareModuleTypeManagement.createSoftwareModuleType(entityFactory.softwareModuleType().create() + softwareModuleTypeManagement.create(entityFactory.softwareModuleType().create() .key("test1234").name("TestName1234").description("Desc1234").maxAssignments(5)); final String rsqlFindLikeDs1OrDs2 = "name==TestName123,name==TestName1234"; @@ -388,7 +388,7 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt char character = 'a'; for (int index = 0; index < amount; index++) { final String str = String.valueOf(character); - softwareModuleManagement.createSoftwareModule(entityFactory.softwareModule().create().type(osType).name(str) + softwareModuleManagement.create(entityFactory.softwareModule().create().type(osType).name(str) .description(str).vendor(str).version(str)); character++; } diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetFilterQueryResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetFilterQueryResourceTest.java index 888d067a2..9ccf8ebc6 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetFilterQueryResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetFilterQueryResourceTest.java @@ -74,7 +74,7 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractManagementApiInte mvc.perform(delete(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING + "/" + filterQuery.getId())) .andExpect(status().isOk()); - assertThat(targetFilterQueryManagement.findTargetFilterQueryById(filterQuery.getId())).isNotPresent(); + assertThat(targetFilterQueryManagement.get(filterQuery.getId())).isNotPresent(); } @Test @@ -112,7 +112,7 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractManagementApiInte .andExpect(jsonPath("$.query", equalTo(filterQuery2))) .andExpect(jsonPath("$.name", equalTo(filterName))); - final TargetFilterQuery tfqCheck = targetFilterQueryManagement.findTargetFilterQueryById(tfq.getId()).get(); + final TargetFilterQuery tfqCheck = targetFilterQueryManagement.get(tfq.getId()).get(); assertThat(tfqCheck.getQuery()).isEqualTo(filterQuery2); assertThat(tfqCheck.getName()).isEqualTo(filterName); } @@ -126,7 +126,7 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractManagementApiInte final String body = new JSONObject().put("name", filterName2).toString(); // prepare - final TargetFilterQuery tfq = targetFilterQueryManagement.createTargetFilterQuery( + final TargetFilterQuery tfq = targetFilterQueryManagement.create( entityFactory.targetFilterQuery().create().name(filterName).query(filterQuery)); mvc.perform(put(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING + "/" + tfq.getId()).content(body) @@ -135,7 +135,7 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractManagementApiInte .andExpect(jsonPath("$.query", equalTo(filterQuery))) .andExpect(jsonPath("$.name", equalTo(filterName2))); - final TargetFilterQuery tfqCheck = targetFilterQueryManagement.findTargetFilterQueryById(tfq.getId()).get(); + final TargetFilterQuery tfqCheck = targetFilterQueryManagement.get(tfq.getId()).get(); assertThat(tfqCheck.getQuery()).isEqualTo(filterQuery); assertThat(tfqCheck.getName()).isEqualTo(filterName2); } @@ -270,7 +270,7 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractManagementApiInte .contentType(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest()).andReturn(); - assertThat(targetFilterQueryManagement.countAllTargetFilterQuery()).isEqualTo(0); + assertThat(targetFilterQueryManagement.count()).isEqualTo(0); // verify response json exception message final ExceptionInfo exceptionInfo = ResourceUtility @@ -293,7 +293,7 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractManagementApiInte .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); assertThat( - targetFilterQueryManagement.findTargetFilterQueryById(tfq.getId()).get().getAutoAssignDistributionSet()) + targetFilterQueryManagement.get(tfq.getId()).get().getAutoAssignDistributionSet()) .isEqualTo(set); final String hrefPrefix = "http://localhost" + MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING + "/" @@ -317,10 +317,10 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractManagementApiInte final DistributionSet set = testdataFactory.createDistributionSet(dsName); final TargetFilterQuery tfq = createSingleTargetFilterQuery(knownName, knownQuery); - targetFilterQueryManagement.updateTargetFilterQueryAutoAssignDS(tfq.getId(), set.getId()); + targetFilterQueryManagement.updateAutoAssignDS(tfq.getId(), set.getId()); assertThat( - targetFilterQueryManagement.findTargetFilterQueryById(tfq.getId()).get().getAutoAssignDistributionSet()) + targetFilterQueryManagement.get(tfq.getId()).get().getAutoAssignDistributionSet()) .isEqualTo(set); mvc.perform(get(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING + "/" + tfq.getId() + "/autoAssignDS")) @@ -330,7 +330,7 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractManagementApiInte .andExpect(status().isNoContent()); assertThat( - targetFilterQueryManagement.findTargetFilterQueryById(tfq.getId()).get().getAutoAssignDistributionSet()) + targetFilterQueryManagement.get(tfq.getId()).get().getAutoAssignDistributionSet()) .isNull(); mvc.perform(get(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING + "/" + tfq.getId() + "/autoAssignDS")) @@ -340,7 +340,7 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractManagementApiInte private TargetFilterQuery createSingleTargetFilterQuery(final String name, final String query) { return targetFilterQueryManagement - .createTargetFilterQuery(entityFactory.targetFilterQuery().create().name(name).query(query)); + .create(entityFactory.targetFilterQuery().create().name(name).query(query)); } } diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResourceTest.java index 191712807..1d20fe0c4 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResourceTest.java @@ -183,7 +183,7 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest } private void createTarget(final String controllerId) { - targetManagement.createTarget(entityFactory.target().create().controllerId(controllerId) + targetManagement.create(entityFactory.target().create().controllerId(controllerId) .address(IpUtil.createHttpUri("127.0.0.1").toString())); } @@ -311,7 +311,7 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest mvc.perform(delete(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownControllerId)) .andExpect(status().isOk()); - assertThat(targetManagement.findTargetByControllerID(knownControllerId)).isNotPresent(); + assertThat(targetManagement.getByControllerID(knownControllerId)).isNotPresent(); } @Test @@ -341,8 +341,8 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest final String body = new JSONObject().put("description", knownNewDescription).toString(); // prepare - targetManagement.createTarget(entityFactory.target().create().controllerId(knownControllerId) - .name(knownNameNotModiy).description("old description")); + targetManagement.create(entityFactory.target().create().controllerId(knownControllerId).name(knownNameNotModiy) + .description("old description")); mvc.perform(put(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownControllerId).content(body) .contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) @@ -350,7 +350,7 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest .andExpect(jsonPath("$.description", equalTo(knownNewDescription))) .andExpect(jsonPath("$.name", equalTo(knownNameNotModiy))); - final Target findTargetByControllerID = targetManagement.findTargetByControllerID(knownControllerId).get(); + final Target findTargetByControllerID = targetManagement.getByControllerID(knownControllerId).get(); assertThat(findTargetByControllerID.getDescription()).isEqualTo(knownNewDescription); assertThat(findTargetByControllerID.getName()).isEqualTo(knownNameNotModiy); } @@ -364,14 +364,14 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest final String body = new JSONObject().put("description", knownNewDescription).toString(); // prepare - targetManagement.createTarget(entityFactory.target().create().controllerId(knownControllerId) - .name(knownNameNotModiy).description("old description")); + targetManagement.create(entityFactory.target().create().controllerId(knownControllerId).name(knownNameNotModiy) + .description("old description")); mvc.perform(put(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownControllerId).content(body) .contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()) .andExpect(status().isBadRequest()); - final Target findTargetByControllerID = targetManagement.findTargetByControllerID(knownControllerId).get(); + final Target findTargetByControllerID = targetManagement.getByControllerID(knownControllerId).get(); assertThat(findTargetByControllerID.getDescription()).isEqualTo("old description"); } @@ -385,7 +385,7 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest // prepare targetManagement - .createTarget(entityFactory.target().create().controllerId(knownControllerId).name(knownNameNotModiy)); + .create(entityFactory.target().create().controllerId(knownControllerId).name(knownNameNotModiy)); mvc.perform(put(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownControllerId).content(body) .contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) @@ -393,7 +393,7 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest .andExpect(jsonPath("$.securityToken", equalTo(knownNewToken))) .andExpect(jsonPath("$.name", equalTo(knownNameNotModiy))); - final Target findTargetByControllerID = targetManagement.findTargetByControllerID(knownControllerId).get(); + final Target findTargetByControllerID = targetManagement.getByControllerID(knownControllerId).get(); assertThat(findTargetByControllerID.getSecurityToken()).isEqualTo(knownNewToken); assertThat(findTargetByControllerID.getName()).isEqualTo(knownNameNotModiy); } @@ -407,8 +407,8 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest final String body = new JSONObject().put("address", knownNewAddress).toString(); // prepare - targetManagement.createTarget(entityFactory.target().create().controllerId(knownControllerId) - .name(knownNameNotModiy).address(knownNewAddress)); + targetManagement.create(entityFactory.target().create().controllerId(knownControllerId).name(knownNameNotModiy) + .address(knownNewAddress)); mvc.perform(put(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownControllerId).content(body) .contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) @@ -416,7 +416,7 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest .andExpect(jsonPath("$.address", equalTo(knownNewAddress))) .andExpect(jsonPath("$.name", equalTo(knownNameNotModiy))); - final Target findTargetByControllerID = targetManagement.findTargetByControllerID(knownControllerId).get(); + final Target findTargetByControllerID = targetManagement.getByControllerID(knownControllerId).get(); assertThat(findTargetByControllerID.getAddress().toString()).isEqualTo(knownNewAddress); assertThat(findTargetByControllerID.getName()).isEqualTo(knownNameNotModiy); } @@ -665,7 +665,7 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest .perform(post(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING).contentType(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest()).andReturn(); - assertThat(targetManagement.countTargetsAll()).isEqualTo(0); + assertThat(targetManagement.count()).isEqualTo(0); // verify response json exception message final ExceptionInfo exceptionInfo = ResourceUtility @@ -684,7 +684,7 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest .contentType(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest()).andReturn(); - assertThat(targetManagement.countTargetsAll()).isEqualTo(0); + assertThat(targetManagement.count()).isEqualTo(0); // verify response json exception message final ExceptionInfo exceptionInfo = ResourceUtility @@ -701,7 +701,7 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest .contentType(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest()).andReturn(); - assertThat(targetManagement.countTargetsAll()).isEqualTo(0); + assertThat(targetManagement.count()).isEqualTo(0); // verify response json exception message final ExceptionInfo exceptionInfo = ResourceUtility @@ -720,7 +720,7 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest .content(JsonBuilder.targets(Arrays.asList(test1), true)).contentType(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest()).andReturn(); - assertThat(targetManagement.countTargetsAll()).isEqualTo(0); + assertThat(targetManagement.count()).isEqualTo(0); // verify response json exception message final ExceptionInfo exceptionInfo = ResourceUtility @@ -775,18 +775,18 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest JsonPath.compile("[2]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString()) .isEqualTo("http://localhost/rest/v1/targets/id3"); - assertThat(targetManagement.findTargetByControllerID("id1")).isNotNull(); - assertThat(targetManagement.findTargetByControllerID("id1").get().getName()).isEqualTo("testname1"); - assertThat(targetManagement.findTargetByControllerID("id1").get().getDescription()).isEqualTo("testid1"); - assertThat(targetManagement.findTargetByControllerID("id1").get().getSecurityToken()).isEqualTo("token"); - assertThat(targetManagement.findTargetByControllerID("id1").get().getAddress().toString()) + assertThat(targetManagement.getByControllerID("id1")).isNotNull(); + assertThat(targetManagement.getByControllerID("id1").get().getName()).isEqualTo("testname1"); + assertThat(targetManagement.getByControllerID("id1").get().getDescription()).isEqualTo("testid1"); + assertThat(targetManagement.getByControllerID("id1").get().getSecurityToken()).isEqualTo("token"); + assertThat(targetManagement.getByControllerID("id1").get().getAddress().toString()) .isEqualTo("amqp://test123/foobar"); - assertThat(targetManagement.findTargetByControllerID("id2")).isNotNull(); - assertThat(targetManagement.findTargetByControllerID("id2").get().getName()).isEqualTo("testname2"); - assertThat(targetManagement.findTargetByControllerID("id2").get().getDescription()).isEqualTo("testid2"); - assertThat(targetManagement.findTargetByControllerID("id3")).isNotNull(); - assertThat(targetManagement.findTargetByControllerID("id3").get().getName()).isEqualTo("testname3"); - assertThat(targetManagement.findTargetByControllerID("id3").get().getDescription()).isEqualTo("testid3"); + assertThat(targetManagement.getByControllerID("id2")).isNotNull(); + assertThat(targetManagement.getByControllerID("id2").get().getName()).isEqualTo("testname2"); + assertThat(targetManagement.getByControllerID("id2").get().getDescription()).isEqualTo("testid2"); + assertThat(targetManagement.getByControllerID("id3")).isNotNull(); + assertThat(targetManagement.getByControllerID("id3").get().getName()).isEqualTo("testname3"); + assertThat(targetManagement.getByControllerID("id3").get().getDescription()).isEqualTo("testid3"); } @Test @@ -801,9 +801,9 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest .contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()) .andExpect(status().is2xxSuccessful()); - final Slice findTargetsAll = targetManagement.findTargetsAll(new PageRequest(0, 100)); + final Slice findTargetsAll = targetManagement.findAll(new PageRequest(0, 100)); final Target target = findTargetsAll.getContent().get(0); - assertThat(targetManagement.countTargetsAll()).isEqualTo(1); + assertThat(targetManagement.count()).isEqualTo(1); assertThat(target.getControllerId()).isEqualTo(knownControllerId); assertThat(target.getName()).isEqualTo(knownName); assertThat(target.getDescription()).isEqualTo(knownDescription); @@ -829,7 +829,7 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest .andExpect(status().is(HttpStatus.CONFLICT.value())).andReturn(); // verify only one entry - assertThat(targetManagement.countTargetsAll()).isEqualTo(1); + assertThat(targetManagement.count()).isEqualTo(1); // verify response json exception message final ExceptionInfo exceptionInfo = ResourceUtility @@ -1151,7 +1151,7 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest .andExpect(jsonPath("total", equalTo(1))); assertThat(deploymentManagement.getAssignedDistributionSet(target.getControllerId()).get()).isEqualTo(set); - target = targetManagement.findTargetByControllerID(target.getControllerId()).get(); + target = targetManagement.getByControllerID(target.getControllerId()).get(); // repeating DS assignment leads again to OK mvc.perform(post(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + target.getControllerId() + "/assignedDS") @@ -1161,7 +1161,7 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest .andExpect(jsonPath("total", equalTo(1))); // ...but does not change the target - assertThat(targetManagement.findTargetByControllerID(target.getControllerId()).get()).isEqualTo(target); + assertThat(targetManagement.getByControllerID(target.getControllerId()).get()).isEqualTo(target); } @Test @@ -1181,7 +1181,7 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest assertThat(deploymentManagement.getAssignedDistributionSet(target.getControllerId()).get()).isEqualTo(set); assertThat(deploymentManagement.getInstalledDistributionSet(target.getControllerId()).get()).isEqualTo(set); - target = targetManagement.findTargetByControllerID(target.getControllerId()).get(); + target = targetManagement.getByControllerID(target.getControllerId()).get(); assertThat(target.getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC); // repeating DS assignment leads again to OK @@ -1193,7 +1193,7 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest .andExpect(jsonPath("total", equalTo(1))); // ...but does not change the target - assertThat(targetManagement.findTargetByControllerID(target.getControllerId()).get()).isEqualTo(target); + assertThat(targetManagement.getByControllerID(target.getControllerId()).get()).isEqualTo(target); } @Test @@ -1359,7 +1359,7 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest } private Target createSingleTarget(final String controllerId, final String name) { - targetManagement.createTarget(entityFactory.target().create().controllerId(controllerId).name(name) + targetManagement.create(entityFactory.target().create().controllerId(controllerId).name(name) .description(TARGET_DESCRIPTION_TEST)); return controllerManagement.findOrRegisterTargetIfItDoesNotexist(controllerId, LOCALHOST); } @@ -1376,7 +1376,7 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest char character = 'a'; for (int index = 0; index < amount; index++) { final String str = String.valueOf(character); - targetManagement.createTarget(entityFactory.target().create().controllerId(str).name(str).description(str)); + targetManagement.create(entityFactory.target().create().controllerId(str).name(str).description(str)); controllerManagement.findOrRegisterTargetIfItDoesNotexist(str, LOCALHOST); character++; } @@ -1396,6 +1396,6 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest // verify active action final Slice actionsByTarget = deploymentManagement.findActionsByTarget(tA.getControllerId(), PAGE); assertThat(actionsByTarget.getContent()).hasSize(1); - return targetManagement.findTargetByControllerID(tA.getControllerId()).get(); + return targetManagement.getByControllerID(tA.getControllerId()).get(); } } diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTagResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTagResourceTest.java index a93cfb084..6bafd127f 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTagResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTagResourceTest.java @@ -113,11 +113,11 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT .andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)); - final Tag createdOne = tagManagement.findAllTargetTags("name==thetest1", PAGE).getContent().get(0); + final Tag createdOne = targetTagManagement.findByRsql(PAGE, "name==thetest1").getContent().get(0); assertThat(createdOne.getName()).isEqualTo(tagOne.getName()); assertThat(createdOne.getDescription()).isEqualTo(tagOne.getDescription()); assertThat(createdOne.getColour()).isEqualTo(tagOne.getColour()); - final Tag createdTwo = tagManagement.findAllTargetTags("name==thetest2", PAGE).getContent().get(0); + final Tag createdTwo = targetTagManagement.findByRsql(PAGE, "name==thetest2").getContent().get(0); assertThat(createdTwo.getName()).isEqualTo(tagTwo.getName()); assertThat(createdTwo.getDescription()).isEqualTo(tagTwo.getDescription()); assertThat(createdTwo.getColour()).isEqualTo(tagTwo.getColour()); @@ -143,7 +143,7 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)); - final Tag updated = tagManagement.findAllTargetTags("name==updatedName", PAGE).getContent().get(0); + final Tag updated = targetTagManagement.findByRsql(PAGE, "name==updatedName").getContent().get(0); assertThat(updated.getName()).isEqualTo(update.getName()); assertThat(updated.getDescription()).isEqualTo(update.getDescription()); assertThat(updated.getColour()).isEqualTo(update.getColour()); @@ -162,7 +162,7 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT mvc.perform(delete(MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING + "/" + original.getId())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); - assertThat(tagManagement.findTargetTagById(original.getId())).isNotPresent(); + assertThat(targetTagManagement.get(original.getId())).isNotPresent(); } @Test @@ -237,7 +237,7 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT ResultActions result = toggle(tag, targets); - List updated = targetManagement.findTargetsByTag(PAGE, tag.getId()).getContent(); + List updated = targetManagement.findByTag(PAGE, tag.getId()).getContent(); assertThat(updated.stream().map(Target::getControllerId).collect(Collectors.toList())) .containsAll(targets.stream().map(Target::getControllerId).collect(Collectors.toList())); @@ -247,12 +247,12 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT result = toggle(tag, targets); - updated = targetManagement.findTargetsAll(PAGE).getContent(); + updated = targetManagement.findAll(PAGE).getContent(); result.andExpect(applyTargetEntityMatcherOnArrayResult(updated.get(0), "unassignedTargets")) .andExpect(applyTargetEntityMatcherOnArrayResult(updated.get(1), "unassignedTargets")); - assertThat(targetManagement.findTargetsByTag(PAGE, tag.getId())).isEmpty(); + assertThat(targetManagement.findByTag(PAGE, tag.getId())).isEmpty(); } private ResultActions toggle(final TargetTag tag, final List targets) throws Exception { @@ -283,7 +283,7 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)); - final List updated = targetManagement.findTargetsByTag(PAGE, tag.getId()).getContent(); + final List updated = targetManagement.findByTag(PAGE, tag.getId()).getContent(); assertThat(updated.stream().map(Target::getControllerId).collect(Collectors.toList())) .containsAll(targets.stream().map(Target::getControllerId).collect(Collectors.toList())); @@ -309,7 +309,7 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT mvc.perform(delete(MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned/" + unassigned.getControllerId())).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); - final List updated = targetManagement.findTargetsByTag(PAGE, tag.getId()).getContent(); + final List updated = targetManagement.findByTag(PAGE, tag.getId()).getContent(); assertThat(updated.stream().map(Target::getControllerId).collect(Collectors.toList())) .containsOnly(assigned.getControllerId()); diff --git a/hawkbit-repository/hawkbit-repository-api/README.md b/hawkbit-repository/hawkbit-repository-api/README.md index 8000ad390..7b108d5eb 100644 --- a/hawkbit-repository/hawkbit-repository-api/README.md +++ b/hawkbit-repository/hawkbit-repository-api/README.md @@ -3,4 +3,48 @@ API for repository access. Contains: - Entity Model -- Management service API \ No newline at end of file +- Management service API + +## Method naming concept (example target management) + +``` +// Count all targets +Long count() + +// Count by filter parameter (example) +Long countByTargetFilterQuery(@NotEmpty String targetFilterQuery); + +//Create entity +List create(@NotEmpty Collection create) +Target create(@NotNull TargetCreate create) + +//Delete entities (throws EntityNotFoundException if one element does not exist (at least one not found in collection case)) +void delete(@NotEmpty Collection targetIDs); +void delete(@NotNull Long targetID); +void deleteByControllerId(@NotEmpty String controllerId); +void deleteByControllerId(@NotEmpty Collection controllerId); + +//Update Target (throws EntityNotFoundException if one element does not exist (at least one not found in collection case)) +List update(@NotEmpty Collection update); +Target update(@NotNull TargetUpdate update); + +//Exist +boolean exists(@NotNull Long targetId) +boolean existsByAssignedDistributionSet(@NotNull Long distributionSetID); + +// Read methods +// Find one on technical ID (Optional, no EntityNotFoundException) +Optional get(@NotNull Long targetId); +List get(@NotEmpty Collection targetId); + +// Find one on non-ID but unique constraint (Optional, no EntityNotFoundException) +Optional getByControllerID(@NotEmpty String controllerId); +List getByControllerID(@NotEmpty Collection controllerId); + +// Find one on non-ID but and non unique constraint (Optional, no EntityNotFoundException) +Optional findFirstByDescription(@NotEmpty String description); + +// Query/search repository (page might be empty, no EntityNotFoundException) (note: pageReq always first in signature) +Page findByAssignedDistributionSet(@NotNull Pageable pageReq, @NotNull Long distributionSetID); + +``` \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ArtifactManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ArtifactManagement.java index fc9b633eb..65790d882 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ArtifactManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ArtifactManagement.java @@ -39,7 +39,7 @@ public interface ArtifactManagement { * management */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Long countArtifactsAll(); + long count(); /** * Persists artifact binary as provided by given InputStream. assign the @@ -63,7 +63,7 @@ public interface ArtifactManagement { * if given software module does not exist */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) - Artifact createArtifact(@NotNull InputStream inputStream, @NotNull Long moduleId, final String filename, + Artifact create(@NotNull InputStream inputStream, @NotNull Long moduleId, final String filename, final boolean overrideExisting); /** @@ -99,7 +99,7 @@ public interface ArtifactManagement { * if check against provided SHA1 checksum failed */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) - Artifact createArtifact(@NotNull InputStream stream, @NotNull Long moduleId, @NotEmpty String filename, + Artifact create(@NotNull InputStream stream, @NotNull Long moduleId, @NotEmpty String filename, String providedMd5Sum, String providedSha1Sum, boolean overrideExisting, String contentType); /** @@ -129,7 +129,7 @@ public interface ArtifactManagement { * if artifact with given ID does not exist */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY) - void deleteArtifact(@NotNull Long id); + void delete(@NotNull Long id); /** * Searches for {@link Artifact} with given {@link Identifiable}. @@ -140,7 +140,7 @@ public interface ArtifactManagement { */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY + SpringEvalExpressions.HAS_AUTH_OR + SpringEvalExpressions.IS_CONTROLLER) - Optional findArtifact(@NotNull Long id); + Optional get(@NotNull Long id); /** * Find by artifact by software module id and filename. @@ -156,7 +156,7 @@ public interface ArtifactManagement { */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY + SpringEvalExpressions.HAS_AUTH_OR + SpringEvalExpressions.IS_CONTROLLER) - Optional findByFilenameAndSoftwareModule(@NotNull String filename, @NotNull Long softwareModuleId); + Optional getByFilenameAndSoftwareModule(@NotNull String filename, @NotNull Long softwareModuleId); /** * Find all local artifact by sha1 and return the first artifact. @@ -167,7 +167,7 @@ public interface ArtifactManagement { */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY + SpringEvalExpressions.HAS_AUTH_OR + SpringEvalExpressions.IS_CONTROLLER) - Optional findFirstArtifactBySHA1(@NotNull String sha1); + Optional findFirstBySHA1(@NotNull String sha1); /** * Searches for {@link Artifact} with given file name. @@ -178,13 +178,13 @@ public interface ArtifactManagement { */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY + SpringEvalExpressions.HAS_AUTH_OR + SpringEvalExpressions.IS_CONTROLLER) - Optional findArtifactByFilename(@NotNull String filename); + Optional getByFilename(@NotNull String filename); /** * Get local artifact for a base software module. * * @param pageReq - * Pageable + * Pageable parameter * @param swId * software module id * @return Page @@ -193,7 +193,7 @@ public interface ArtifactManagement { * if software module with given ID does not exist */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Page findArtifactBySoftwareModule(@NotNull Pageable pageReq, @NotNull Long swId); + Page findBySoftwareModule(@NotNull Pageable pageReq, @NotNull Long swId); /** * Loads {@link AbstractDbArtifact} from store for given {@link Artifact}. diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java index e717ff70a..863212a25 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java @@ -64,6 +64,16 @@ public interface ControllerManagement { @PreAuthorize(SpringEvalExpressions.IS_CONTROLLER) Action addCancelActionStatus(@NotNull ActionStatusCreate create); + /** + * Retrieves assigned {@link SoftwareModule} of a target. + * + * @param moduleId + * of the {@link SoftwareModule} + * @return {@link SoftwareModule} identified by ID + */ + @PreAuthorize(SpringEvalExpressions.IS_CONTROLLER) + Optional getSoftwareModule(@NotNull final Long moduleId); + /** * Simple addition of a new {@link ActionStatus} entry to the {@link Action} * . No state changes. @@ -282,7 +292,7 @@ public interface ControllerManagement { */ @PreAuthorize(SpringEvalExpressions.IS_CONTROLLER + SpringEvalExpressions.HAS_AUTH_OR + SpringEvalExpressions.IS_SYSTEM_CODE) - Optional findByControllerId(@NotEmpty String controllerId); + Optional getByControllerId(@NotEmpty String controllerId); /** * Finds {@link Target} based on given ID returns found Target without @@ -296,7 +306,7 @@ public interface ControllerManagement { */ @PreAuthorize(SpringEvalExpressions.IS_CONTROLLER + SpringEvalExpressions.HAS_AUTH_OR + SpringEvalExpressions.IS_SYSTEM_CODE) - Optional findByTargetId(@NotNull Long targetId); + Optional get(@NotNull Long targetId); /** * Retrieves the specified number of messages from action history of the diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java index 046d9e954..30f4c2786 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java @@ -187,19 +187,19 @@ public interface DeploymentManagement { * if target with given ID does not exist */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - Long countActionsByTarget(@NotNull String rsqlParam, @NotEmpty String controllerId); + long countActionsByTarget(@NotNull String rsqlParam, @NotEmpty String controllerId); /** * @return the total amount of stored action status */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - Long countActionStatusAll(); + long countActionStatusAll(); /** * @return the total amount of stored actions */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - Long countActionsAll(); + long countActionsAll(); /** * counts all actions associated to a specific target. @@ -212,7 +212,7 @@ public interface DeploymentManagement { * if target with given ID does not exist */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - Long countActionsByTarget(@NotEmpty String controllerId); + long countActionsByTarget(@NotEmpty String controllerId); /** * Get the {@link Action} entity for given actionId. diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java index acc067ce8..754dfd6d3 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java @@ -12,20 +12,17 @@ import java.util.Collection; import java.util.List; import java.util.Optional; -import javax.validation.ConstraintViolationException; import javax.validation.constraints.NotNull; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; import org.eclipse.hawkbit.repository.builder.DistributionSetCreate; import org.eclipse.hawkbit.repository.builder.DistributionSetUpdate; -import org.eclipse.hawkbit.repository.exception.DistributionSetCreationFailedMissingMandatoryModuleException; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.exception.EntityReadOnlyException; import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException; import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException; import org.eclipse.hawkbit.repository.exception.UnsupportedSoftwareModuleForThisDistributionSetException; -import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetFilter; import org.eclipse.hawkbit.repository.model.DistributionSetFilter.DistributionSetFilterBuilder; @@ -45,7 +42,8 @@ import org.springframework.security.access.prepost.PreAuthorize; * Management service for {@link DistributionSet}s. * */ -public interface DistributionSetManagement { +public interface DistributionSetManagement + extends RepositoryManagement { /** * Assigns {@link SoftwareModule} to existing {@link DistributionSet}. @@ -66,8 +64,6 @@ public interface DistributionSetManagement { * @throws UnsupportedSoftwareModuleForThisDistributionSetException * is {@link SoftwareModule#getType()} is not supported by this * {@link DistributionSet#getType()}. - * - * */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) DistributionSet assignSoftwareModules(@NotNull Long setId, @NotEmpty Collection moduleIds); @@ -76,7 +72,7 @@ public interface DistributionSetManagement { * Assign a {@link DistributionSetTag} assignment to given * {@link DistributionSet}s. * - * @param dsIds + * @param setIds * to assign for * @param tagId * to assign @@ -87,42 +83,12 @@ public interface DistributionSetManagement { * distribution sets. */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) - List assignTag(@NotEmpty Collection dsIds, @NotNull Long tagId); - - /** - * Count all {@link DistributionSet}s in the repository that are not marked - * as deleted. - * - * @return number of {@link DistributionSet}s - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Long countDistributionSetsAll(); - - /** - * Creates a new {@link DistributionSet}. - * - * @param create - * {@link DistributionSet} to be created - * @return the new persisted {@link DistributionSet} - * - * @throws EntityNotFoundException - * if a provided linked entity does not exists ( - * {@link DistributionSet#getModules()} or - * {@link DistributionSet#getType()}) - * @throws DistributionSetCreationFailedMissingMandatoryModuleException - * is {@link DistributionSet} does not contain mandatory - * {@link SoftwareModule}s. - * @throws ConstraintViolationException - * if fields are not filled as specified. Check - * {@link DistributionSetCreate} for field constraints. - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) - DistributionSet createDistributionSet(@NotNull DistributionSetCreate create); + List assignTag(@NotEmpty Collection setIds, @NotNull Long tagId); /** * creates a list of distribution set meta data entries. * - * @param dsId + * @param setId * if the {@link DistributionSet} the metadata has to be created * for * @param metadata @@ -136,69 +102,12 @@ public interface DistributionSetManagement { * specific key */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) - List createDistributionSetMetadata(@NotNull Long dsId, - @NotEmpty Collection metadata); - - /** - * Creates multiple {@link DistributionSet}s. - * - * @param creates - * to be created - * @return the new {@link DistributionSet}s - * @throws EntityNotFoundException - * if a provided linked entity does not exists ( - * {@link DistributionSet#getModules()} or - * {@link DistributionSet#getType()}) - * @throws DistributionSetCreationFailedMissingMandatoryModuleException - * is {@link DistributionSet} does not contain mandatory - * {@link SoftwareModule}s. - * @throws ConstraintViolationException - * if fields are not filled as specified. Check - * {@link DistributionSetCreate} for field constraints. - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) - List createDistributionSets(@NotNull Collection creates); - - /** - *

- * {@link DistributionSet} can be deleted/erased from the repository if they - * have never been assigned to any {@link Action} or {@link Target}. - *

- * - *

- * If they have been assigned that need to be marked as deleted which as a - * result means that they cannot be assigned anymore to any targets. (define - * e.g. findByDeletedFalse()) - *

- * - * @param setId - * to delete - * - * @throws EntityNotFoundException - * if given {@link DistributionSet} does not exist - * - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY) - void deleteDistributionSet(@NotNull Long setId); - - /** - * Deleted {@link DistributionSet}s by their IDs. That is either a soft - * delete of the entities have been linked to an {@link Action} before or a - * hard delete if not. - * - * @param dsIds - * to be deleted - * - * @throws EntityNotFoundException - * if (at least one) given distribution set does not exist - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY) - void deleteDistributionSet(@NotEmpty Collection dsIds); + List createMetaData(@NotNull Long setId, @NotEmpty Collection metadata); /** * deletes a distribution set meta data entry. * - * @param dsId + * @param setId * where meta data has to be deleted * @param key * of the meta data element @@ -207,7 +116,7 @@ public interface DistributionSetManagement { * if given set does not exist */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) - void deleteDistributionSetMetadata(@NotNull final Long dsId, @NotEmpty final String key); + void deleteMetaData(@NotNull Long setId, @NotEmpty String key); /** * retrieves the distribution set for a given action. @@ -220,33 +129,21 @@ public interface DistributionSetManagement { * if action with given ID does not exist */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Optional findDistributionSetByAction(@NotNull Long actionId); - - /** - * Find {@link DistributionSet} based on given ID without details, e.g. - * {@link DistributionSet#getModules()}. - * - * @param distid - * to look for. - * @return {@link DistributionSet} - * - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Optional findDistributionSetById(@NotNull Long distid); + Optional getByAction(@NotNull Long actionId); /** * Find {@link DistributionSet} based on given ID including (lazy loaded) * details, e.g. {@link DistributionSet#getModules()}. * - * Note: for performance reasons it is recommended to use - * {@link #findDistributionSetById(Long)} if details are not necessary. + * Note: for performance reasons it is recommended to use {@link #get(Long)} + * if details are not necessary. * - * @param distid + * @param setId * to look for. * @return {@link DistributionSet} */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Optional findDistributionSetByIdWithDetails(@NotNull Long distid); + Optional getWithDetails(@NotNull Long setId); /** * Find distribution set by name and version. @@ -258,16 +155,16 @@ public interface DistributionSetManagement { * @return the page with the found {@link DistributionSet} */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Optional findDistributionSetByNameAndVersion(@NotEmpty String distributionName, - @NotEmpty String version); + Optional getByNameAndVersion(@NotEmpty String distributionName, @NotEmpty String version); /** * finds all meta data by the given distribution set id. - * - * @param distributionSetId - * the distribution set id to retrieve the meta data from + * * @param pageable * the page request to page the result + * @param setId + * the distribution set id to retrieve the meta data from + * * @return a paged result of all meta data entries for a given distribution * set id * @@ -275,18 +172,18 @@ public interface DistributionSetManagement { * if distribution set with given ID does not exist */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Page findDistributionSetMetadataByDistributionSetId(@NotNull Long distributionSetId, - @NotNull Pageable pageable); + Page findMetaDataByDistributionSetId(@NotNull Pageable pageable, @NotNull Long setId); /** * finds all meta data by the given distribution set id. - * - * @param distributionSetId + * + * @param pageable + * the page request to page the result + * @param setId * the distribution set id to retrieve the meta data from * @param rsqlParam * rsql query string - * @param pageable - * the page request to page the result + * * @return a paged result of all meta data entries for a given distribution * set id * @@ -300,19 +197,14 @@ public interface DistributionSetManagement { * of distribution set with given ID does not exist */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Page findDistributionSetMetadataByDistributionSetId(@NotNull Long distributionSetId, - @NotNull String rsqlParam, @NotNull Pageable pageable); + Page findMetaDataByDistributionSetIdAndRsql(@NotNull Pageable pageable, + @NotNull Long setId, @NotNull String rsqlParam); /** * finds all {@link DistributionSet}s. * - * @param pageReq + * @param pageable * the pagination parameter - * @param deleted - * if TRUE, {@link DistributionSet}s marked as deleted are - * returned. If FALSE, on {@link DistributionSet}s with - * {@link DistributionSet#isDeleted()} == FALSE are returned. - * null if both are to be returned * @param complete * to true for returning only completed distribution * sets or false for only incomplete ones nor @@ -322,47 +214,7 @@ public interface DistributionSetManagement { * @return all found {@link DistributionSet}s */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Page findDistributionSetsByDeletedAndOrCompleted(@NotNull Pageable pageReq, Boolean deleted, - Boolean complete); - - /** - * finds all {@link DistributionSet}s. - * - * @param rsqlParam - * rsql query string - * @param pageReq - * the pagination parameter - * @param deleted - * if TRUE, {@link DistributionSet}s marked as deleted are - * returned. If FALSE, on {@link DistributionSet}s not marked as - * deleted are returned. null if both are to be - * returned - * @return all found {@link DistributionSet}s - * - * @throws RSQLParameterUnsupportedFieldException - * if a field in the RSQL string is used but not provided by the - * given {@code fieldNameProvider} - * @throws RSQLParameterSyntaxException - * if the RSQL syntax is wrong - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Page findDistributionSetsAll(@NotNull String rsqlParam, @NotNull Pageable pageReq, - Boolean deleted); - - /** - * finds all {@link DistributionSet}s. - * - * @param pageReq - * the pagination parameter - * @param deleted - * if TRUE, {@link DistributionSet}s marked as deleted are - * returned. If FALSE, on {@link DistributionSet}s not marked as - * deleted are returned. null if both are to be - * returned - * @return all found {@link DistributionSet}s - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Page findDistributionSetsAll(@NotNull Pageable pageReq, Boolean deleted); + Page findByCompleted(@NotNull Pageable pageable, Boolean complete); /** * method retrieves all {@link DistributionSet}s from the repository in the @@ -386,7 +238,7 @@ public interface DistributionSetManagement { * @return {@link DistributionSet}s */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Page findDistributionSetsAllOrderedByLinkTarget(@NotNull Pageable pageable, + Page findByFilterAndAssignedInstalledDsOrderedByLinkTarget(@NotNull Pageable pageable, @NotNull DistributionSetFilterBuilder distributionSetFilterBuilder, @NotEmpty String assignedOrInstalled); /** @@ -399,7 +251,7 @@ public interface DistributionSetManagement { * @return the page of found {@link DistributionSet} */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Page findDistributionSetsByFilters(@NotNull Pageable pageable, + Page findByDistributionSetFilter(@NotNull Pageable pageable, @NotNull DistributionSetFilter distributionSetFilter); /** @@ -421,7 +273,7 @@ public interface DistributionSetManagement { * of distribution set tag with given ID does not exist */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Page findDistributionSetsByTag(@NotNull final Pageable pageable, @NotNull final Long tagId); + Page findByTag(@NotNull Pageable pageable, @NotNull Long tagId); /** * retrieves {@link DistributionSet}s by filtering on the given parameters. @@ -438,8 +290,7 @@ public interface DistributionSetManagement { * of distribution set tag with given ID does not exist */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Page findDistributionSetsByTag(@NotNull final Pageable pageable, @NotNull String rsqlParam, - @NotNull final Long tagId); + Page findByRsqlAndTag(@NotNull Pageable pageable, @NotNull String rsqlParam, @NotNull Long tagId); /** * finds a single distribution set meta data by its id. @@ -454,7 +305,7 @@ public interface DistributionSetManagement { * is set with given ID does not exist */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Optional findDistributionSetMetadata(@NotNull Long setId, @NotEmpty String key); + Optional getMetaDataByDistributionSetId(@NotNull Long setId, @NotEmpty String key); /** * Checks if a {@link DistributionSet} is currently in use by a target in @@ -466,7 +317,7 @@ public interface DistributionSetManagement { * @return true if in use */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - boolean isDistributionSetInUse(@NotNull Long setId); + boolean isInUse(@NotNull Long setId); /** * Toggles {@link DistributionSetTag} assignment to given @@ -474,7 +325,7 @@ public interface DistributionSetManagement { * the list have the {@link Tag} not yet assigned, they will be. If all of * theme have the tag already assigned they will be removed instead. * - * @param dsIds + * @param setIds * to toggle for * @param tagName * to toggle @@ -485,7 +336,7 @@ public interface DistributionSetManagement { * if given tag does not exist or (at least one) module */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) - DistributionSetTagAssignmentResult toggleTagAssignment(@NotEmpty Collection dsIds, @NotNull String tagName); + DistributionSetTagAssignmentResult toggleTagAssignment(@NotEmpty Collection setIds, @NotNull String tagName); /** * Unassigns a {@link SoftwareModule} form an existing @@ -511,7 +362,7 @@ public interface DistributionSetManagement { * Unassign a {@link DistributionSetTag} assignment to given * {@link DistributionSet}. * - * @param dsId + * @param setId * to unassign for * @param tagId * to unassign @@ -521,34 +372,14 @@ public interface DistributionSetManagement { * if set or tag with given ID does not exist */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) - DistributionSet unAssignTag(@NotNull Long dsId, @NotNull Long tagId); - - /** - * Updates existing {@link DistributionSet}. - * - * @param update - * to update - * - * @return the saved entity. - * - * @throws EntityNotFoundException - * if given set does not exist - * @throws EntityReadOnlyException - * if user tries to change requiredMigrationStep or type on a DS - * that is already assigned to targets - * @throws ConstraintViolationException - * if fields are not filled as specified. Check - * {@link DistributionSetUpdate} for field constraints. - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) - DistributionSet updateDistributionSet(@NotNull DistributionSetUpdate update); + DistributionSet unAssignTag(@NotNull Long setId, @NotNull Long tagId); /** * updates a distribution set meta data value if corresponding entry exists. * - * @param dsId + * @param setId * {@link DistributionSet} of the meta data entry to be updated - * @param md + * @param metadata * meta data entry to be updated * @return the updated meta data entry * @@ -557,16 +388,21 @@ public interface DistributionSetManagement { * updated */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) - DistributionSetMetadata updateDistributionSetMetadata(@NotNull Long dsId, @NotNull MetaData md); + DistributionSetMetadata updateMetaData(@NotNull Long setId, @NotNull MetaData metadata); /** - * Retrieves all distribution set without details. + * Count all {@link DistributionSet}s in the repository that are not marked + * as deleted. + * + * @param typeId + * to look for * - * @param ids - * the ids to for - * @return the found {@link DistributionSet}s + * @return number of {@link DistributionSet}s + * + * @throws EntityNotFoundException + * if type with given ID does not exist */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - List findDistributionSetsById(@NotEmpty Collection ids); + long countByTypeId(@NotNull Long typeId); } diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DistributionSetTagManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DistributionSetTagManagement.java new file mode 100644 index 000000000..c2e360d1e --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DistributionSetTagManagement.java @@ -0,0 +1,73 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository; + +import java.util.Optional; + +import javax.validation.constraints.NotNull; + +import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; +import org.eclipse.hawkbit.repository.builder.TagCreate; +import org.eclipse.hawkbit.repository.builder.TagUpdate; +import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; +import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.DistributionSetTag; +import org.eclipse.hawkbit.repository.model.Target; +import org.eclipse.hawkbit.repository.model.TargetTag; +import org.hibernate.validator.constraints.NotEmpty; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.security.access.prepost.PreAuthorize; + +/** + * Management service for {@link DistributionSetTag}s. + * + */ +public interface DistributionSetTagManagement extends RepositoryManagement { + + /** + * Deletes {@link DistributionSetTag} by given + * {@link DistributionSetTag#getName()}. + * + * @param tagName + * to be deleted + * + * @throws EntityNotFoundException + * if tag with given name does not exist + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY) + void delete(@NotEmpty String tagName); + + /** + * Find {@link DistributionSet} based on given name. + * + * @param name + * to look for. + * @return {@link DistributionSet} + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + Optional getByName(@NotEmpty String name); + + /** + * Finds all {@link TargetTag} assigned to given {@link Target}. + * + * @param pageable + * information for page size, offset and sort order. + * + * @param setId + * of the {@link DistributionSet} + * @return page of the found {@link TargetTag}s + * + * @throws EntityNotFoundException + * if {@link DistributionSet} with given ID does not exist + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + Page findByDistributionSet(@NotNull Pageable pageable, @NotNull Long setId); + +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DistributionSetTypeManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DistributionSetTypeManagement.java index 6d48d23c2..9de6bf36d 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DistributionSetTypeManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DistributionSetTypeManagement.java @@ -9,10 +9,8 @@ package org.eclipse.hawkbit.repository; import java.util.Collection; -import java.util.List; import java.util.Optional; -import javax.validation.ConstraintViolationException; import javax.validation.constraints.NotNull; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; @@ -20,84 +18,18 @@ import org.eclipse.hawkbit.repository.builder.DistributionSetTypeCreate; import org.eclipse.hawkbit.repository.builder.DistributionSetTypeUpdate; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.exception.EntityReadOnlyException; -import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException; -import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.hibernate.validator.constraints.NotEmpty; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; import org.springframework.security.access.prepost.PreAuthorize; /** * Management service for {@link DistributionSetType}s. * */ -public interface DistributionSetTypeManagement { - - /** - * Creates new {@link DistributionSetType}. - * - * @param create - * to create - * @return created entity - * - * @throws EntityNotFoundException - * if a provided linked entity does not exists ( - * {@link DistributionSetType#getMandatoryModuleTypes()} or - * {@link DistributionSetType#getOptionalModuleTypes()} - * @throws ConstraintViolationException - * if fields are not filled as specified. Check - * {@link DistributionSetTypeCreate} for field constraints. - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) - DistributionSetType createDistributionSetType(@NotNull DistributionSetTypeCreate create); - - /** - * Creates multiple {@link DistributionSetType}s. - * - * @param creates - * to create - * @return created entity - * - * @throws EntityNotFoundException - * if a provided linked entity does not exists ( - * {@link DistributionSetType#getMandatoryModuleTypes()} or - * {@link DistributionSetType#getOptionalModuleTypes()} - * @throws ConstraintViolationException - * if fields are not filled as specified. Check - * {@link DistributionSetTypeCreate} for field constraints. - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) - List createDistributionSetTypes(@NotNull Collection creates); - - /** - * Count all {@link DistributionSet}s in the repository that are not marked - * as deleted. - * - * @param typeId - * to look for - * - * @return number of {@link DistributionSet}s - * - * @throws EntityNotFoundException - * if type with given ID does not exist - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Long countDistributionSetsByType(@NotNull Long typeId); - - /** - * Deletes or mark as delete in case the type is in use. - * - * @param typeId - * to delete - * - * @throws EntityNotFoundException - * if given set does not exist - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY) - void deleteDistributionSetType(@NotNull Long typeId); +public interface DistributionSetTypeManagement + extends RepositoryManagement { /** * @param key @@ -106,7 +38,7 @@ public interface DistributionSetTypeManagement { */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Optional findDistributionSetTypeByKey(@NotEmpty String key); + Optional getByKey(@NotEmpty String key); /** * @param name @@ -114,66 +46,7 @@ public interface DistributionSetTypeManagement { * @return {@link DistributionSetType} */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Optional findDistributionSetTypeByName(@NotEmpty String name); - - /** - * @param pageable - * parameter - * @return all {@link DistributionSetType}s in the repository. - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Page findDistributionSetTypesAll(@NotNull Pageable pageable); - - /** - * Generic predicate based query for {@link DistributionSetType}. - * - * @param rsqlParam - * rsql query string - * @param pageable - * parameter for paging - * - * @return the found {@link SoftwareModuleType}s - * - * @throws RSQLParameterUnsupportedFieldException - * if a field in the RSQL string is used but not provided by the - * given {@code fieldNameProvider} - * @throws RSQLParameterSyntaxException - * if the RSQL syntax is wrong - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Page findDistributionSetTypesAll(@NotNull String rsqlParam, @NotNull Pageable pageable); - - /** - * @param id - * as {@link DistributionSetType#getId()} - * @return {@link DistributionSetType} - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Optional findDistributionSetTypeById(@NotNull Long id); - - /** - * Updates existing {@link DistributionSetType}. Resets assigned - * {@link SoftwareModuleType}s as well and sets as provided. - * - * @param update - * to update - * - * @return updated entity - * - * @throws EntityNotFoundException - * in case the {@link DistributionSetType} does not exists and - * cannot be updated - * - * @throws EntityReadOnlyException - * if the {@link DistributionSetType} is already in use by a - * {@link DistributionSet} and user tries to change list of - * {@link SoftwareModuleType}s - * @throws ConstraintViolationException - * if fields are not filled as specified. Check - * {@link DistributionSetTypeUpdate} for field constraints. - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) - DistributionSetType updateDistributionSetType(@NotNull DistributionSetTypeUpdate update); + Optional getByName(@NotEmpty String name); /** * Assigns {@link DistributionSetType#getMandatoryModuleTypes()}. @@ -238,10 +111,4 @@ public interface DistributionSetTypeManagement { @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) DistributionSetType unassignSoftwareModuleType(@NotNull Long dsTypeId, @NotNull Long softwareModuleId); - /** - * @return number of {@link DistributionSetType}s in the repository. - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Long countDistributionSetTypesAll(); - } diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/FilterParams.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/FilterParams.java index 33bafaa3c..8780cd26f 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/FilterParams.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/FilterParams.java @@ -21,17 +21,17 @@ import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; */ public class FilterParams { - private Collection filterByStatus; - private Boolean overdueState; - private String filterBySearchText; - private Boolean selectTargetWithNoTag; - private String[] filterByTagNames; - private Long filterByDistributionId; + private final Collection filterByStatus; + private final Boolean overdueState; + private final String filterBySearchText; + private final Boolean selectTargetWithNoTag; + private final String[] filterByTagNames; + private final Long filterByDistributionId; /** * Constructor. * - * @param filterByDistributionId + * @param filterByInstalledOrAssignedDistributionSetId * if set, a filter is added for the given * {@link DistributionSet#getId()} * @param filterByStatus @@ -47,13 +47,13 @@ public class FilterParams { * if tag-filtering is enabled, a filter is added for the given * tag-names */ - public FilterParams(Long filterByDistributionId, Collection filterByStatus, - Boolean overdueState, String filterBySearchText, Boolean selectTargetWithNoTag, - String... filterByTagNames) { + public FilterParams(final Collection filterByStatus, final Boolean overdueState, + final String filterBySearchText, final Long filterByInstalledOrAssignedDistributionSetId, + final Boolean selectTargetWithNoTag, final String... filterByTagNames) { this.filterByStatus = filterByStatus; this.overdueState = overdueState; this.filterBySearchText = filterBySearchText; - this.filterByDistributionId = filterByDistributionId; + this.filterByDistributionId = filterByInstalledOrAssignedDistributionSetId; this.selectTargetWithNoTag = selectTargetWithNoTag; this.filterByTagNames = filterByTagNames; } @@ -68,16 +68,6 @@ public class FilterParams { return filterByDistributionId; } - /** - * Sets {@link DistributionSet#getId()} to filter the result. - * - * @param filterByDistributionId - * the distribution set id - */ - public void setFilterByDistributionId(Long filterByDistributionId) { - this.filterByDistributionId = filterByDistributionId; - } - /** * Gets a collection of target states to filter for.
* If set to null this filter is disabled. @@ -88,16 +78,6 @@ public class FilterParams { return filterByStatus; } - /** - * Sets the collection of target states to filter for. - * - * @param filterByStatus - * collection of target update status - */ - public void setFilterByStatus(Collection filterByStatus) { - this.filterByStatus = filterByStatus; - } - /** * Gets the flag for overdue filter; if set to true, the * overdue filter is activated. Overdued targets a targets that did not @@ -110,17 +90,6 @@ public class FilterParams { return overdueState; } - /** - * Sets the flag for overdue filter; if set to true, the - * overdue filter is activated. - * - * @param overdueState - * if the overdue filter should be activates - */ - public void setOverdueState(Boolean overdueState) { - this.overdueState = overdueState; - } - /** * Gets the search text to filter for. This is used to find targets having * the text anywhere in name or description
@@ -132,16 +101,6 @@ public class FilterParams { return filterBySearchText; } - /** - * Sets the search text to filter for. - * - * @param filterBySearchText - * search text - */ - public void setFilterBySearchText(String filterBySearchText) { - this.filterBySearchText = filterBySearchText; - } - /** * Gets the flag indicating if tagging filter is used.
* If set to null this filter is disabled. @@ -152,16 +111,6 @@ public class FilterParams { return selectTargetWithNoTag; } - /** - * Sets the flag indicating if tagging filter is used. - * - * @param selectTargetWithNoTag - * should the tagging filter be used? - */ - public void setSelectTargetWithNoTag(Boolean selectTargetWithNoTag) { - this.selectTargetWithNoTag = selectTargetWithNoTag; - } - /** * Gets the tags that are used to filter for. The activation of this filter * is done by {@link #setSelectTargetWithNoTag(Boolean)}. @@ -171,14 +120,4 @@ public class FilterParams { public String[] getFilterByTagNames() { return filterByTagNames; } - - /** - * Sets the tags that are used to filter for. - * - * @param filterByTagNames - * array of tag names - */ - public void setFilterByTagNames(String[] filterByTagNames) { - this.filterByTagNames = filterByTagNames; - } } diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RepositoryManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RepositoryManagement.java new file mode 100644 index 000000000..39a252f48 --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RepositoryManagement.java @@ -0,0 +1,183 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository; + +import java.util.Collection; +import java.util.List; +import java.util.Optional; + +import javax.validation.ConstraintViolationException; +import javax.validation.constraints.NotNull; + +import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; +import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; +import org.eclipse.hawkbit.repository.exception.EntityReadOnlyException; +import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException; +import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException; +import org.eclipse.hawkbit.repository.model.BaseEntity; +import org.eclipse.hawkbit.repository.model.SoftwareModuleType; +import org.hibernate.validator.constraints.NotEmpty; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; +import org.springframework.security.access.prepost.PreAuthorize; + +/** + * Generic management methods common to (software) repository content. + * + * @param + * type of the {@link BaseEntity} + * @param + * entity create builder + * @param + * entity update builder + */ +public interface RepositoryManagement { + + /** + * Creates multiple {@link BaseEntity}s. + * + * @param creates + * to create + * @return created Entity + * + * @throws ConstraintViolationException + * if fields are not filled as specified. Check + * {@link BaseEntity} for field constraints. + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) + List create(@NotNull Collection creates); + + /** + * Creates new {@link SoftwareModuleType}. + * + * @param create + * to create + * @return created Entity + * + * @throws ConstraintViolationException + * if fields are not filled as specified. Check + * {@link BaseEntity} for field constraints. + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) + T create(@NotNull C create); + + /** + * Updates existing {@link BaseEntity}. + * + * @param update + * to update + * + * @return updated Entity + * + * @throws EntityReadOnlyException + * if the {@link BaseEntity} cannot be updated (e.g. is already + * in use) + * @throws EntityNotFoundException + * in case the {@link BaseEntity} does not exists and cannot be + * updated + * @throws ConstraintViolationException + * if fields are not filled as specified. Check + * {@link BaseEntity} for field constraints. + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) + T update(@NotNull U update); + + /** + * @return number of {@link BaseEntity}s in the repository. + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + long count(); + + /** + * Deletes or marks as delete in case the {@link BaseEntity} is in use. + * + * @param id + * to delete + * + * @throws EntityNotFoundException + * BaseEntity with given ID does not exist + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY) + void delete(@NotNull Long id); + + /** + * Delete {@link BaseEntity}s by their IDs. That is either a soft delete of + * the entities have been linked to another entity before or a hard delete + * if not. + * + * @param ids + * to be deleted + * + * @throws EntityNotFoundException + * if (at least one) given distribution set does not exist + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY) + void delete(@NotEmpty Collection ids); + + /** + * Retrieves all {@link BaseEntity}s without details. + * + * @param ids + * the ids to for + * @return the found {@link BaseEntity}s + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + List get(@NotEmpty Collection ids); + + /** + * Verifies that {@link BaseEntity} with given ID exists in the repository. + * + * @param id + * of entity to check existence + * @return true if entity with given ID exists + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + boolean exists(@NotNull Long id); + + /** + * Retrieve {@link BaseEntity} + * + * @param id + * to search for + * @return {@link BaseEntity} in the repository with given + * {@link BaseEntity#getId()} + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + Optional get(@NotNull Long id); + + /** + * Retrieves {@link Page} of all {@link BaseEntity} of given type. + * + * @param pageable + * paging parameter + * @return all {@link BaseEntity}s in the repository. + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + Slice findAll(@NotNull Pageable pageable); + + /** + * Retrieves all {@link BaseEntity}s with a given specification. + * + * @param pageable + * pagination parameter + * @param rsqlParam + * filter definition in RSQL syntax + * + * @return the found {@link BaseEntity}s + * + * @throws RSQLParameterUnsupportedFieldException + * if a field in the RSQL string is used but not provided by the + * given {@code fieldNameProvider} + * @throws RSQLParameterSyntaxException + * if the RSQL syntax is wrong + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + Page findByRsql(@NotNull Pageable pageable, @NotNull String rsqlParam); +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupManagement.java index 2e23b246e..f785cbb4f 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupManagement.java @@ -34,17 +34,18 @@ public interface RolloutGroupManagement { * Retrieves a page of {@link RolloutGroup}s filtered by a given * {@link Rollout} with the detailed status. * - * @param rolloutId - * the ID of the rollout to filter the {@link RolloutGroup}s * @param pageable * the page request to sort and limit the result + * @param rolloutId + * the ID of the rollout to filter the {@link RolloutGroup}s + * * @return a page of found {@link RolloutGroup}s * * @throws EntityNotFoundException * of rollout with given ID does not exist */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - Page findAllRolloutGroupsWithDetailedStatus(@NotNull Long rolloutId, @NotNull Pageable pageable); + Page findByRolloutWithDetailedStatus(@NotNull Pageable pageable, @NotNull Long rolloutId); /** * @@ -63,7 +64,7 @@ public interface RolloutGroupManagement { * if rollout group with given ID does not exist */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ_AND_TARGET_READ) - Page findAllTargetsWithActionStatus(@NotNull Pageable pageable, + Page findAllTargetsOfRolloutGroupWithActionStatus(@NotNull Pageable pageable, @NotNull Long rolloutGroupId); /** @@ -76,19 +77,20 @@ public interface RolloutGroupManagement { * */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - Optional findRolloutGroupById(@NotNull Long rolloutGroupId); + Optional get(@NotNull Long rolloutGroupId); /** * Retrieves a page of {@link RolloutGroup}s filtered by a given * {@link Rollout} and the an rsql filter. * + * @param pageable + * the page request to sort and limit the result * @param rolloutId * the rollout to filter the {@link RolloutGroup}s * @param rsqlParam * the specification to filter the result set based on attributes * of the {@link RolloutGroup} - * @param pageable - * the page request to sort and limit the result + * * @return a page of found {@link RolloutGroup}s * * @throws RSQLParameterUnsupportedFieldException @@ -98,8 +100,22 @@ public interface RolloutGroupManagement { * if the RSQL syntax is wrong */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - Page findRolloutGroupsAll(@NotNull Long rolloutId, @NotNull String rsqlParam, - @NotNull Pageable pageable); + Page findByRolloutAndRsql(@NotNull Pageable pageable, @NotNull Long rolloutId, + @NotNull String rsqlParam); + + /** + * Retrieves a page of {@link RolloutGroup}s filtered by a given + * {@link Rollout}. + * + * @param pageable + * the page request to sort and limit the result + * @param rolloutId + * the ID of the rollout to filter the {@link RolloutGroup}s + * + * @return a page of found {@link RolloutGroup}s + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) + Page findByRollout(@NotNull Pageable pageable, @NotNull Long rolloutId); /** * Retrieves a page of {@link RolloutGroup}s filtered by a given @@ -112,28 +128,15 @@ public interface RolloutGroupManagement { * @return a page of found {@link RolloutGroup}s */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - Page findRolloutGroupsByRolloutId(@NotNull Long rolloutId, @NotNull Pageable pageable); - - /** - * Retrieves a page of {@link RolloutGroup}s filtered by a given - * {@link Rollout}. - * - * @param rolloutId - * the ID of the rollout to filter the {@link RolloutGroup}s - * @param pageable - * the page request to sort and limit the result - * @return a page of found {@link RolloutGroup}s - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - long countRolloutGroupsByRolloutId(@NotNull Long rolloutId); + long countByRollout(@NotNull Long rolloutId); /** * Get targets of specified rollout group. * + * @param pageable + * the page request to sort and limit the result * @param rolloutGroupId * rollout group - * @param page - * the page request to sort and limit the result * * @return Page list of targets of a rollout group * @@ -141,17 +144,17 @@ public interface RolloutGroupManagement { * if group with ID does not exist */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ_AND_TARGET_READ) - Page findRolloutGroupTargets(@NotNull Long rolloutGroupId, @NotNull Pageable page); + Page findTargetsOfRolloutGroup(@NotNull Pageable pageable, @NotNull Long rolloutGroupId); /** * Get targets of specified rollout group. * + * @param pageable + * the page request to sort and limit the result * @param rolloutGroupId * rollout group * @param rsqlParam * the specification for filtering the targets of a rollout group - * @param pageable - * the page request to sort and limit the result * * @return Page list of targets of a rollout group * @@ -162,8 +165,8 @@ public interface RolloutGroupManagement { * if the RSQL syntax is wrong */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ_AND_TARGET_READ) - Page findRolloutGroupTargets(@NotNull Long rolloutGroupId, @NotNull String rsqlParam, - @NotNull Pageable pageable); + Page findTargetsOfRolloutGroupByRsql(@NotNull Pageable pageable, @NotNull Long rolloutGroupId, + @NotNull String rsqlParam); /** * Get {@link RolloutGroup} by Id. @@ -174,7 +177,7 @@ public interface RolloutGroupManagement { * */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - Optional findRolloutGroupWithDetailedStatus(@NotNull Long rolloutGroupId); + Optional getWithDetailedStatus(@NotNull Long rolloutGroupId); /** * Count targets of rollout group. @@ -187,5 +190,5 @@ public interface RolloutGroupManagement { * if rollout group with given ID does not exist */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - Long countTargetsOfRolloutsGroup(@NotNull Long rolloutGroupId); + long countTargetsOfRolloutsGroup(@NotNull Long rolloutGroupId); } diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java index d5a844b19..c06082d27 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java @@ -55,7 +55,7 @@ public interface RolloutManagement { * For {@link RolloutStatus#READY} that means switching to * {@link RolloutStatus#STARTING} if the {@link Rollout#getStartAt()} is set * and time of calling this method is beyond this point in time. This auto - * start mechanism is optional. Call {@link #startRollout(Long)} otherwise. + * start mechanism is optional. Call {@link #start(Long)} otherwise. * * For {@link RolloutStatus#STARTING} that means starting the first * {@link RolloutGroup}s in line and when finished switch to @@ -81,7 +81,7 @@ public interface RolloutManagement { * @return number of roll outs */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - Long countRolloutsAll(); + long count(); /** * Count rollouts by given text in name or description. @@ -91,7 +91,7 @@ public interface RolloutManagement { * @return total count rollouts for specified filter text. */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - Long countRolloutsAllByFilters(@NotEmpty String searchText); + long countByFilters(@NotEmpty String searchText); /** * Persists a new rollout entity. The filter within the @@ -107,7 +107,7 @@ public interface RolloutManagement { * The RolloutScheduler will start to assign targets to the groups. Once all * targets have been assigned to the groups, the rollout status is changed * to {@link RolloutStatus#READY} so it can be started with - * {@link #startRollout(Rollout)}. + * {@link #start(Rollout)}. * * @param create * the rollout entity to create @@ -124,7 +124,7 @@ public interface RolloutManagement { * if rollout or group parameters are invalid. */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_WRITE) - Rollout createRollout(@NotNull RolloutCreate create, int amountGroup, @NotNull RolloutGroupConditions conditions); + Rollout create(@NotNull RolloutCreate create, int amountGroup, @NotNull RolloutGroupConditions conditions); /** * Persists a new rollout entity. The filter within the @@ -140,7 +140,7 @@ public interface RolloutManagement { * The RolloutScheduler will start to assign targets to the groups. Once all * targets have been assigned to the groups, the rollout status is changed * to {@link RolloutStatus#READY} so it can be started with - * {@link #startRollout(Rollout)}. + * {@link #start(Rollout)}. * * @param rollout * the rollout entity to create @@ -158,7 +158,7 @@ public interface RolloutManagement { * if rollout or group parameters are invalid */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_WRITE) - Rollout createRollout(@NotNull RolloutCreate rollout, @NotNull List groups, + Rollout create(@NotNull RolloutCreate rollout, @NotNull List groups, RolloutGroupConditions conditions); /** @@ -205,17 +205,18 @@ public interface RolloutManagement { * statuses */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - Page findAllRolloutsWithDetailedStatus(@NotNull Pageable pageable, boolean deleted); + Page findAllWithDetailedStatus(@NotNull Pageable pageable, boolean deleted); /** * Retrieves all rollouts found by the given specification. - * - * @param rsqlParam - * the specification to filter rollouts + * * @param pageable * the page request to sort and limit the result + * @param rsqlParam + * the specification to filter rollouts * @param deleted * flag if deleted rollouts should be included + * * @return a page of found rollouts * * @throws RSQLParameterUnsupportedFieldException @@ -225,7 +226,7 @@ public interface RolloutManagement { * if the RSQL syntax is wrong */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - Page findAllByPredicate(@NotNull String rsqlParam, @NotNull Pageable pageable, boolean deleted); + Page findByRsql(@NotNull Pageable pageable, @NotNull String rsqlParam, boolean deleted); /** * Finds rollouts by given text in name or description. @@ -240,7 +241,7 @@ public interface RolloutManagement { * not exists */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - Slice findRolloutWithDetailedStatusByFilters(@NotNull Pageable pageable, @NotEmpty String searchText, + Slice findByFiltersWithDetailedStatus(@NotNull Pageable pageable, @NotEmpty String searchText, boolean deleted); /** @@ -252,7 +253,7 @@ public interface RolloutManagement { * not exists */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - Optional findRolloutById(@NotNull Long rolloutId); + Optional get(@NotNull Long rolloutId); /** * Retrieves a specific rollout by its name. @@ -263,7 +264,7 @@ public interface RolloutManagement { * does not exists */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - Optional findRolloutByName(@NotEmpty String rolloutName); + Optional getByName(@NotEmpty String rolloutName); /** * Get count of targets in different status in rollout. @@ -277,7 +278,7 @@ public interface RolloutManagement { * */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - Optional findRolloutWithDetailedStatus(@NotNull Long rolloutId); + Optional getWithDetailedStatus(@NotNull Long rolloutId); /** * Checks if rollout with given ID exists. @@ -350,7 +351,7 @@ public interface RolloutManagement { * ready rollouts can be started. */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_WRITE) - Rollout startRollout(@NotNull Long rolloutId); + Rollout start(@NotNull Long rolloutId); /** * Update rollout details. @@ -368,7 +369,7 @@ public interface RolloutManagement { * */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_WRITE) - Rollout updateRollout(@NotNull RolloutUpdate update); + Rollout update(@NotNull RolloutUpdate update); /** * Deletes a rollout. A rollout might be deleted asynchronously by @@ -379,6 +380,6 @@ public interface RolloutManagement { * the ID of the rollout to be deleted */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_WRITE) - void deleteRollout(long rolloutId); + void delete(@NotNull Long rolloutId); } diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SoftwareModuleManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SoftwareModuleManagement.java index 57d5671a2..dc5076444 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SoftwareModuleManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SoftwareModuleManagement.java @@ -12,7 +12,6 @@ import java.util.Collection; import java.util.List; import java.util.Optional; -import javax.validation.ConstraintViolationException; import javax.validation.constraints.NotNull; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; @@ -38,7 +37,8 @@ import org.springframework.security.access.prepost.PreAuthorize; * Service for managing {@link SoftwareModule}s. * */ -public interface SoftwareModuleManagement { +public interface SoftwareModuleManagement + extends RepositoryManagement { /** * Counts {@link SoftwareModule}s with given @@ -55,51 +55,7 @@ public interface SoftwareModuleManagement { * if software module type with given ID does not exist */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Long countSoftwareModuleByFilters(String searchText, Long typeId); - - /** - * Count all {@link SoftwareModule}s in the repository that are not marked - * as deleted. - * - * @return number of {@link SoftwareModule}s - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Long countSoftwareModulesAll(); - - /** - * Create {@link SoftwareModule}s in the repository. - * - * @param creates - * {@link SoftwareModule}s to create - * @return SoftwareModule - * - * @throws EntityAlreadyExistsException - * if a given entity already exists - * @throws EntityNotFoundException - * of given software module type does not exist - * @throws ConstraintViolationException - * if fields are not filled as specified. Check - * {@link SoftwareModuleCreate} for field constraints. - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) - List createSoftwareModule(@NotNull Collection creates); - - /** - * - * @param create - * SoftwareModule to create - * @return SoftwareModule - * - * @throws EntityAlreadyExistsException - * if a given entity already exists - * @throws EntityNotFoundException - * of given software module type does not exist - * @throws ConstraintViolationException - * if fields are not filled as specified. Check - * {@link SoftwareModuleCreate} for field constraints. - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) - SoftwareModule createSoftwareModule(@NotNull SoftwareModuleCreate create); + long countByTextAndType(String searchText, Long typeId); /** * creates a list of software module meta data entries. @@ -116,8 +72,7 @@ public interface SoftwareModuleManagement { * if software module with given ID does not exist */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) - List createSoftwareModuleMetadata(@NotNull Long moduleId, - @NotNull Collection metadata); + List createMetaData(@NotNull Long moduleId, @NotNull Collection metadata); /** * creates or updates a single software module meta data entry. @@ -134,16 +89,7 @@ public interface SoftwareModuleManagement { * if software module with given ID does not exist */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) - SoftwareModuleMetadata createSoftwareModuleMetadata(@NotNull Long moduleId, @NotNull MetaData metadata); - - /** - * Deletes the given {@link SoftwareModule} Entity. - * - * @param moduleId - * is the {@link SoftwareModule} to be deleted - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY) - void deleteSoftwareModule(@NotNull Long moduleId); + SoftwareModuleMetadata createMetaData(@NotNull Long moduleId, @NotNull MetaData metadata); /** * deletes a software module meta data entry. @@ -157,19 +103,7 @@ public interface SoftwareModuleManagement { * of module or metadata entry does not exist */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) - void deleteSoftwareModuleMetadata(@NotNull Long moduleId, @NotEmpty String key); - - /** - * Deletes {@link SoftwareModule}s which is any if the given ids. - * - * @param moduleIds - * of the Software Modules to be deleted - * - * @throws EntityNotFoundException - * if (at least one) module with given ID does not exist - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY) - void deleteSoftwareModules(@NotNull Collection moduleIds); + void deleteMetaData(@NotNull Long moduleId, @NotEmpty String key); /** * @param pageable @@ -183,7 +117,7 @@ public interface SoftwareModuleManagement { * if distribution set with given ID does not exist */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Page findSoftwareModuleByAssignedTo(@NotNull Pageable pageable, @NotNull Long setId); + Page findByAssignedTo(@NotNull Pageable pageable, @NotNull Long setId); /** * Filter {@link SoftwareModule}s with given @@ -202,30 +136,7 @@ public interface SoftwareModuleManagement { * if given software module type does not exist */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Slice findSoftwareModuleByFilters(@NotNull Pageable pageable, String searchText, Long typeId); - - /** - * Finds {@link SoftwareModuleType} by given id. - * - * @param ids - * to search for - * @return the found {@link SoftwareModuleType}s - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY + SpringEvalExpressions.HAS_AUTH_OR - + SpringEvalExpressions.IS_CONTROLLER) - List findSoftwareModuleTypesById(@NotEmpty Collection ids); - - /** - * Finds {@link SoftwareModule} by given id. - * - * @param id - * to search for - * @return the found {@link SoftwareModule}s - * - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY + SpringEvalExpressions.HAS_AUTH_OR - + SpringEvalExpressions.IS_CONTROLLER) - Optional findSoftwareModuleById(@NotNull Long id); + Slice findByTextAndType(@NotNull Pageable pageable, String searchText, Long typeId); /** * retrieves {@link SoftwareModule} by their name AND version AND type.. @@ -242,7 +153,7 @@ public interface SoftwareModuleManagement { * if software module type with given ID does not exist */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Optional findSoftwareModuleByNameAndVersion(@NotEmpty String name, @NotEmpty String version, + Optional getByNameAndVersionAndType(@NotEmpty String name, @NotEmpty String version, @NotNull Long typeId); /** @@ -258,15 +169,16 @@ public interface SoftwareModuleManagement { * is module with given ID does not exist */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Optional findSoftwareModuleMetadata(@NotNull Long moduleId, @NotEmpty String key); + Optional getMetaDataBySoftwareModuleId(@NotNull Long moduleId, @NotEmpty String key); /** * finds all meta data by the given software module id. - * - * @param swId - * the software module id to retrieve the meta data from + * * @param pageable * the page request to page the result + * @param moduleId + * the software module id to retrieve the meta data from + * * @return a paged result of all meta data entries for a given software * module id * @@ -274,18 +186,18 @@ public interface SoftwareModuleManagement { * if software module with given ID does not exist */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Page findSoftwareModuleMetadataBySoftwareModuleId(@NotNull Long swId, - @NotNull Pageable pageable); + Page findMetaDataBySoftwareModuleId(@NotNull Pageable pageable, @NotNull Long moduleId); /** * finds all meta data by the given software module id. - * + * + * @param pageable + * the page request to page the result * @param moduleId * the software module id to retrieve the meta data from * @param rsqlParam * filter definition in RSQL syntax - * @param pageable - * the page request to page the result + * * @return a paged result of all meta data entries for a given software * module id * @@ -298,25 +210,8 @@ public interface SoftwareModuleManagement { * if software module with given ID does not exist */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Page findSoftwareModuleMetadataBySoftwareModuleId(@NotNull Long moduleId, - @NotNull String rsqlParam, @NotNull Pageable pageable); - - /** - * Finds all meta data by the given software module id. - * - * @param pageable - * pagination parameter - * - * @param moduleId - * the software module id to retrieve the meta data from - * @return page with found software module metadata - * - * @throws EntityNotFoundException - * of software module with given ID does not exist - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Page findSoftwareModuleMetadataBySoftwareModuleId(@NotNull Pageable pageable, - @NotNull Long moduleId); + Page findMetaDataByRsql(@NotNull Pageable pageable, @NotNull Long moduleId, + @NotNull String rsqlParam); /** * Filter {@link SoftwareModule}s with given @@ -342,48 +237,9 @@ public interface SoftwareModuleManagement { * if given software module type does not exist */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Slice findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc( + Slice findAllOrderBySetAssignmentAndModuleNameAscModuleVersionAsc( @NotNull Pageable pageable, @NotNull Long orderByDistributionId, String searchText, Long typeId); - /** - * Retrieves all software modules. Deleted ones are filtered. - * - * @param pageable - * pagination parameter - * @return the found {@link SoftwareModule}s - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Slice findSoftwareModulesAll(@NotNull Pageable pageable); - - /** - * Retrieves all software modules with a given list of ids - * {@link SoftwareModule#getId()}. - * - * @param ids - * to search for - * @return {@link List} of found {@link SoftwareModule}s - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - List findSoftwareModulesById(@NotEmpty Collection ids); - - /** - * Retrieves all {@link SoftwareModule}s with a given specification. - * - * @param rsqlParam - * filter definition in RSQL syntax - * @param pageable - * pagination parameter - * @return the found {@link SoftwareModule}s - * - * @throws RSQLParameterUnsupportedFieldException - * if a field in the RSQL string is used but not provided by the - * given {@code fieldNameProvider} - * @throws RSQLParameterSyntaxException - * if the RSQL syntax is wrong - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Page findSoftwareModulesByPredicate(@NotNull String rsqlParam, @NotNull Pageable pageable); - /** * retrieves the {@link SoftwareModule}s by their {@link SoftwareModuleType} * . @@ -398,29 +254,7 @@ public interface SoftwareModuleManagement { * if software module type with given ID does not exist */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Slice findSoftwareModulesByType(@NotNull Pageable pageable, @NotNull Long typeId); - - /** - * Updates existing {@link SoftwareModule}. Update-able values are - * {@link SoftwareModule#getDescription()} - * {@link SoftwareModule#getVendor()}. - * - * @param update - * contains properties to update - * - * @throws EntityNotFoundException - * if given module does not exist - * - * @return the saved Entity. - * - * @throws EntityNotFoundException - * if given {@link SoftwareModule} does not exist - * @throws ConstraintViolationException - * if fields are not filled as specified. Check - * {@link SoftwareModuleUpdate} for field constraints. - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) - SoftwareModule updateSoftwareModule(@NotNull SoftwareModuleUpdate update); + Slice findByType(@NotNull Pageable pageable, @NotNull Long typeId); /** * updates a distribution set meta data value if corresponding entry exists. @@ -437,5 +271,5 @@ public interface SoftwareModuleManagement { * updated */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) - SoftwareModuleMetadata updateSoftwareModuleMetadata(@NotNull Long moduleId, @NotNull MetaData metadata); + SoftwareModuleMetadata updateMetaData(@NotNull Long moduleId, @NotNull MetaData metadata); } diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SoftwareModuleTypeManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SoftwareModuleTypeManagement.java index 4ac48a82e..86bf56032 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SoftwareModuleTypeManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SoftwareModuleTypeManagement.java @@ -8,86 +8,21 @@ */ package org.eclipse.hawkbit.repository; -import java.util.Collection; -import java.util.List; import java.util.Optional; -import javax.validation.ConstraintViolationException; -import javax.validation.constraints.NotNull; - import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; import org.eclipse.hawkbit.repository.builder.SoftwareModuleTypeCreate; import org.eclipse.hawkbit.repository.builder.SoftwareModuleTypeUpdate; -import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; -import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException; -import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.hibernate.validator.constraints.NotEmpty; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; import org.springframework.security.access.prepost.PreAuthorize; /** * Service for managing {@link SoftwareModuleType}s. * */ -public interface SoftwareModuleTypeManagement { - - /** - * @return number of {@link SoftwareModuleType}s in the repository. - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Long countSoftwareModuleTypesAll(); - - /** - * Creates multiple {@link SoftwareModuleType}s. - * - * @param creates - * to create - * @return created Entity - * - * @throws ConstraintViolationException - * if fields are not filled as specified. Check - * {@link SoftwareModuleTypeCreate} for field constraints. - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) - List createSoftwareModuleType(@NotNull Collection creates); - - /** - * Creates new {@link SoftwareModuleType}. - * - * @param create - * to create - * @return created Entity - * - * @throws ConstraintViolationException - * if fields are not filled as specified. Check - * {@link SoftwareModuleTypeCreate} for field constraints. - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) - SoftwareModuleType createSoftwareModuleType(@NotNull SoftwareModuleTypeCreate create); - - /** - * Deletes or marks as delete in case the type is in use. - * - * @param typeId - * to delete - * - * @throws EntityNotFoundException - * not found is type with given ID does not exist - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY) - void deleteSoftwareModuleType(@NotNull Long typeId); - - /** - * - * @param id - * to search for - * @return {@link SoftwareModuleType} in the repository with given - * {@link SoftwareModuleType#getId()} - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Optional findSoftwareModuleTypeById(@NotNull Long id); +public interface SoftwareModuleTypeManagement + extends RepositoryManagement { /** * @@ -97,7 +32,7 @@ public interface SoftwareModuleTypeManagement { * {@link SoftwareModuleType#getKey()} */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Optional findSoftwareModuleTypeByKey(@NotEmpty String key); + Optional getByKey(@NotEmpty String key); /** * @@ -107,50 +42,5 @@ public interface SoftwareModuleTypeManagement { * {@link SoftwareModuleType#getName()} */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Optional findSoftwareModuleTypeByName(@NotEmpty String name); - - /** - * @param pageable - * parameter - * @return all {@link SoftwareModuleType}s in the repository. - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Page findSoftwareModuleTypesAll(@NotNull Pageable pageable); - - /** - * Retrieves all {@link SoftwareModuleType}s with a given specification. - * - * @param rsqlParam - * filter definition in RSQL syntax - * @param pageable - * pagination parameter - * @return the found {@link SoftwareModuleType}s - * - * @throws RSQLParameterUnsupportedFieldException - * if a field in the RSQL string is used but not provided by the - * given {@code fieldNameProvider} - * @throws RSQLParameterSyntaxException - * if the RSQL syntax is wrong - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Page findSoftwareModuleTypesAll(@NotNull String rsqlParam, @NotNull Pageable pageable); - - /** - * Updates existing {@link SoftwareModuleType}. - * - * @param update - * to update - * - * @return updated Entity - * - * @throws EntityNotFoundException - * in case the {@link SoftwareModuleType} does not exists and - * cannot be updated - * @throws ConstraintViolationException - * if fields are not filled as specified. Check - * {@link SoftwareModuleTypeUpdate} for field constraints. - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) - SoftwareModuleType updateSoftwareModuleType(@NotNull SoftwareModuleTypeUpdate update); - + Optional getByName(@NotEmpty String name); } diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TagManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TagManagement.java deleted file mode 100644 index 3c7f4424b..000000000 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TagManagement.java +++ /dev/null @@ -1,303 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository; - -import java.util.Collection; -import java.util.List; -import java.util.Optional; - -import javax.validation.ConstraintViolationException; -import javax.validation.constraints.NotNull; - -import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; -import org.eclipse.hawkbit.repository.builder.TagCreate; -import org.eclipse.hawkbit.repository.builder.TagUpdate; -import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; -import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; -import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException; -import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException; -import org.eclipse.hawkbit.repository.model.DistributionSet; -import org.eclipse.hawkbit.repository.model.DistributionSetTag; -import org.eclipse.hawkbit.repository.model.Tag; -import org.eclipse.hawkbit.repository.model.Target; -import org.eclipse.hawkbit.repository.model.TargetTag; -import org.hibernate.validator.constraints.NotEmpty; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; -import org.springframework.security.access.prepost.PreAuthorize; - -/** - * Management service for {@link Tag}s. - * - */ -public interface TagManagement { - - /** - * count {@link TargetTag}s. - * - * @return size of {@link TargetTag}s - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - long countTargetTags(); - - /** - * Creates a {@link DistributionSet}. - * - * @param create - * to be created. - * @return the new {@link DistributionSet} - * - * @throws EntityAlreadyExistsException - * if distributionSetTag already exists - * @throws ConstraintViolationException - * if fields are not filled as specified. Check - * {@link TagCreate} for field constraints. - * - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) - DistributionSetTag createDistributionSetTag(@NotNull TagCreate create); - - /** - * Creates multiple {@link DistributionSetTag}s. - * - * @param creates - * to be created - * @return the new {@link DistributionSetTag} - * - * @throws EntityAlreadyExistsException - * if a given entity already exists - * @throws ConstraintViolationException - * if fields are not filled as specified. Check - * {@link TagCreate} for field constraints. - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) - List createDistributionSetTags(@NotNull Collection creates); - - /** - * Creates a new {@link TargetTag}. - * - * @param create - * to be created - * - * @return the new created {@link TargetTag} - * - * @throws EntityAlreadyExistsException - * if given object already exists - * @throws ConstraintViolationException - * if fields are not filled as specified. Check - * {@link TagCreate} for field constraints. - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_TARGET) - TargetTag createTargetTag(@NotNull TagCreate create); - - /** - * created multiple {@link TargetTag}s. - * - * @param creates - * to be created - * @return the new created {@link TargetTag}s - * - * @throws EntityAlreadyExistsException - * if given object has already an ID. - * @throws ConstraintViolationException - * if fields are not filled as specified. Check - * {@link TagCreate} for field constraints. - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_TARGET) - List createTargetTags(@NotNull Collection creates); - - /** - * Deletes {@link DistributionSetTag} by given - * {@link DistributionSetTag#getName()}. - * - * @param tagName - * to be deleted - * - * @throws EntityNotFoundException - * if tag with given name does not exist - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY) - void deleteDistributionSetTag(@NotEmpty String tagName); - - /** - * Deletes {@link TargetTag} with given name. - * - * @param targetTagName - * tag name of the {@link TargetTag} to be deleted - * - * @throws EntityNotFoundException - * if tag with given name does not exist - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_TARGET) - void deleteTargetTag(@NotEmpty String targetTagName); - - /** - * returns all {@link DistributionSetTag}s. - * - * @param pageReq - * page parameter - * @return all {@link DistributionSetTag}s - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Page findAllDistributionSetTags(@NotNull Pageable pageReq); - - /** - * Retrieves all DistributionSet tags based on the given specification. - * - * @param rsqlParam - * rsql query string - * @param pageable - * pagination parameter - * @return the found {@link DistributionSetTag}s, never {@code null} - * - * @throws RSQLParameterUnsupportedFieldException - * if a field in the RSQL string is used but not provided by the - * given {@code fieldNameProvider} - * @throws RSQLParameterSyntaxException - * if the RSQL syntax is wrong - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Page findAllDistributionSetTags(@NotNull String rsqlParam, @NotNull Pageable pageable); - - /** - * returns all {@link TargetTag}s. - * - * @param pageable - * page parameter - * - * @return all {@link TargetTag}s - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - Page findAllTargetTags(@NotNull Pageable pageable); - - /** - * Returns all {@link TargetTag}s assigned to {@link Target} with given ID. - * - * @param pageable - * page parameter - * @param controllerId - * - * @return {@link TargetTag}s assigned to {@link Target} with given ID - * - * @throws EntityNotFoundException - * if target with given ID does not exist - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - Page findAllTargetTags(@NotNull Pageable pageable, @NotEmpty String controllerId); - - /** - * Retrieves all target tags based on the given specification. - * - * @param rsqlParam - * rsql query string - * @param pageable - * pagination parameter - * @return the found {@link Target}s, never {@code null} - * - * @throws RSQLParameterUnsupportedFieldException - * if a field in the RSQL string is used but not provided by the - * given {@code fieldNameProvider} - * @throws RSQLParameterSyntaxException - * if the RSQL syntax is wrong - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - Page findAllTargetTags(@NotNull String rsqlParam, @NotNull Pageable pageable); - - /** - * Find {@link DistributionSet} based on given name. - * - * @param name - * to look for. - * @return {@link DistributionSet} - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Optional findDistributionSetTag(@NotEmpty String name); - - /** - * Finds {@link DistributionSetTag} by given id. - * - * @param id - * to search for - * @return the found {@link DistributionSetTag} - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Optional findDistributionSetTagById(@NotNull Long id); - - /** - * Find {@link TargetTag} based on given Name. - * - * @param name - * to look for. - * @return {@link TargetTag} - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - Optional findTargetTag(@NotEmpty String name); - - /** - * Finds {@link TargetTag} by given id. - * - * @param id - * to search for - * @return the found {@link TargetTag} - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - Optional findTargetTagById(@NotNull Long id); - - /** - * Finds all {@link TargetTag} assigned to given {@link Target}. - * - * @param pageable - * information for page size, offset and sort order. - * - * @param setId - * of the {@link DistributionSet} - * @return page of the found {@link TargetTag}s - * - * @throws EntityNotFoundException - * if {@link DistributionSet} with given ID does not exist - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Page findDistributionSetTagsByDistributionSet(@NotNull Pageable pageable, @NotNull Long setId); - - /** - * Updates an existing {@link DistributionSetTag}. - * - * @param update - * to be updated - * - * @return the updated {@link DistributionSet} - * - * @throws EntityNotFoundException - * in case the {@link DistributionSetTag} does not exists and - * cannot be updated - * @throws ConstraintViolationException - * if fields are not filled as specified. Check - * {@link TagUpdate} for field constraints. - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) - DistributionSetTag updateDistributionSetTag(@NotNull TagUpdate update); - - /** - * updates the {@link TargetTag}. - * - * @param update - * the {@link TargetTag} with updated values - * @return the updated {@link TargetTag} - * - * @throws EntityNotFoundException - * in case the {@link TargetTag} does not exists and cannot be - * updated - * @throws ConstraintViolationException - * if fields are not filled as specified. Check - * {@link TagUpdate} for field constraints. - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET) - TargetTag updateTargetTag(@NotNull TagUpdate update); - -} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagement.java index a8eda5de6..f102a6b39 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagement.java @@ -41,7 +41,7 @@ public interface TargetFilterQueryManagement { * {@link TargetFilterQueryCreate} for field constraints. */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_TARGET) - TargetFilterQuery createTargetFilterQuery(@NotNull TargetFilterQueryCreate create); + TargetFilterQuery create(@NotNull TargetFilterQueryCreate create); /** * Delete target filter query. @@ -53,7 +53,7 @@ public interface TargetFilterQueryManagement { * if filter with given ID does not exist */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_TARGET) - void deleteTargetFilterQuery(@NotNull Long targetFilterQueryId); + void delete(@NotNull Long targetFilterQueryId); /** * Verifies provided filter syntax. @@ -81,7 +81,7 @@ public interface TargetFilterQueryManagement { * @return the found {@link TargetFilterQuery}s */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - Page findAllTargetFilterQuery(@NotNull Pageable pageable); + Page findAll(@NotNull Pageable pageable); /** * Counts all target filter queries @@ -89,7 +89,7 @@ public interface TargetFilterQueryManagement { * @return the number of all target filter queries */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - Long countAllTargetFilterQuery(); + long count(); /** * Retrieves all target filter query which {@link TargetFilterQuery}. @@ -102,7 +102,7 @@ public interface TargetFilterQueryManagement { * @return the page with the found {@link TargetFilterQuery} */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - Page findTargetFilterQueryByName(@NotNull Pageable pageable, @NotNull String name); + Page findByName(@NotNull Pageable pageable, @NotNull String name); /** * Retrieves all target filter query which {@link TargetFilterQuery}. @@ -115,7 +115,7 @@ public interface TargetFilterQueryManagement { * @return the page with the found {@link TargetFilterQuery} */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - Page findTargetFilterQueryByFilter(@NotNull Pageable pageable, @NotNull String rsqlFilter); + Page findByRsql(@NotNull Pageable pageable, @NotNull String rsqlFilter); /** * Retrieves all target filter query which have exactly the provided query. @@ -127,7 +127,7 @@ public interface TargetFilterQueryManagement { * @return the page with the found {@link TargetFilterQuery} */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - Page findTargetFilterQueryByQuery(@NotNull Pageable pageable, @NotNull String query); + Page findByQuery(@NotNull Pageable pageable, @NotNull String query); /** * Retrieves all target filter query which {@link TargetFilterQuery}. @@ -145,7 +145,7 @@ public interface TargetFilterQueryManagement { * if DS with given ID does not exist */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - Page findTargetFilterQueryByAutoAssignDS(@NotNull Pageable pageable, @NotNull Long setId, + Page findByAutoAssignDSAndRsql(@NotNull Pageable pageable, @NotNull Long setId, String rsqlParam); /** @@ -157,7 +157,7 @@ public interface TargetFilterQueryManagement { * @param pageable */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - Page findTargetFilterQueryWithAutoAssignDS(@NotNull Pageable pageable); + Page findWithAutoAssignDS(@NotNull Pageable pageable); /** * Find target filter query by id. @@ -168,7 +168,7 @@ public interface TargetFilterQueryManagement { * */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - Optional findTargetFilterQueryById(@NotNull Long targetFilterQueryId); + Optional get(@NotNull Long targetFilterQueryId); /** * Find target filter query by name. @@ -179,7 +179,7 @@ public interface TargetFilterQueryManagement { * */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - Optional findTargetFilterQueryByName(@NotNull String targetFilterQueryName); + Optional getByName(@NotNull String targetFilterQueryName); /** * updates the {@link TargetFilterQuery}. @@ -197,7 +197,7 @@ public interface TargetFilterQueryManagement { * {@link TargetFilterQueryUpdate} for field constraints. */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET) - TargetFilterQuery updateTargetFilterQuery(@NotNull TargetFilterQueryUpdate update); + TargetFilterQuery update(@NotNull TargetFilterQueryUpdate update); /** * updates the {@link TargetFilterQuery#getAutoAssignDistributionSet()}. @@ -213,6 +213,6 @@ public interface TargetFilterQueryManagement { * provided but not found */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET) - TargetFilterQuery updateTargetFilterQueryAutoAssignDS(@NotNull Long queryId, Long dsId); + TargetFilterQuery updateAutoAssignDS(@NotNull Long queryId, Long dsId); } diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java index ce45f4c68..9d7c8c0fe 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java @@ -72,7 +72,7 @@ public interface TargetManagement { */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET + SpringEvalExpressions.HAS_AUTH_OR + SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Long countTargetByAssignedDistributionSet(@NotNull Long distId); + long countByAssignedDistributionSet(@NotNull Long distId); /** * Count {@link Target}s for all the given filter parameters. @@ -104,7 +104,7 @@ public interface TargetManagement { * if distribution set with given ID does not exist */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - Long countTargetByFilters(Collection status, Boolean overdueState, String searchText, + long countByFilters(Collection status, Boolean overdueState, String searchText, Long installedOrAssignedDistributionSetId, Boolean selectTargetWithNoTag, String... tagNames); /** @@ -120,7 +120,7 @@ public interface TargetManagement { */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET + SpringEvalExpressions.HAS_AUTH_OR + SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Long countTargetByInstalledDistributionSet(@NotNull Long distId); + long countByInstalledDistributionSet(@NotNull Long distId); /** * Count {@link TargetFilterQuery}s for given target filter query. @@ -130,7 +130,7 @@ public interface TargetManagement { * @return the found number {@link Target}s */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - Long countTargetByTargetFilterQuery(@NotEmpty String rsqlParam); + long countByRsql(@NotEmpty String rsqlParam); /** * Count {@link TargetFilterQuery}s for given target filter query. @@ -143,7 +143,7 @@ public interface TargetManagement { * if {@link TargetFilterQuery} with given ID does not exist */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - Long countTargetByTargetFilterQuery(@NotNull Long targetFilterQueryId); + long countByTargetFilterQuery(@NotNull Long targetFilterQueryId); /** * Counts all {@link Target}s in the repository. @@ -151,7 +151,7 @@ public interface TargetManagement { * @return number of targets */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - Long countTargetsAll(); + long count(); /** * creating a new {@link Target}. @@ -167,9 +167,8 @@ public interface TargetManagement { * {@link TargetCreate} for field constraints. * */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_TARGET + SpringEvalExpressions.HAS_AUTH_OR - + SpringEvalExpressions.IS_CONTROLLER) - Target createTarget(@NotNull TargetCreate create); + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_TARGET) + Target create(@NotNull TargetCreate create); /** * creates multiple {@link Target}s. If some of the given {@link Target}s @@ -188,7 +187,7 @@ public interface TargetManagement { * {@link TargetCreate} for field constraints. */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_TARGET) - List createTargets(@NotNull Collection creates); + List create(@NotNull Collection creates); /** * Deletes all targets with the given IDs. @@ -200,7 +199,7 @@ public interface TargetManagement { * if (at least one) of the given target IDs does not exist */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_TARGET) - void deleteTargets(@NotEmpty Collection targetIDs); + void delete(@NotEmpty Collection targetIDs); /** * Deletes target with the given IDs. @@ -212,7 +211,7 @@ public interface TargetManagement { * if target with given ID does not exist */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_TARGET) - void deleteTarget(@NotEmpty String controllerID); + void deleteByControllerID(@NotEmpty String controllerID); /** * Finds all targets for all the given parameter {@link TargetFilterQuery} @@ -231,8 +230,8 @@ public interface TargetManagement { * if distribution set with given ID does not exist */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - Page findAllTargetsByTargetFilterQueryAndNonDS(@NotNull Pageable pageRequest, - @NotNull Long distributionSetId, @NotNull String rsqlParam); + Page findByTargetFilterQueryAndNonDS(@NotNull Pageable pageRequest, @NotNull Long distributionSetId, + @NotNull String rsqlParam); /** * Counts all targets for all the given parameter {@link TargetFilterQuery} @@ -249,7 +248,7 @@ public interface TargetManagement { * if distribution set with given ID does not exist */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - Long countTargetsByTargetFilterQueryAndNonDS(@NotNull Long distributionSetId, @NotNull String rsqlParam); + long countByRsqlAndNonDS(@NotNull Long distributionSetId, @NotNull String rsqlParam); /** * Finds all targets for all the given parameter {@link TargetFilterQuery} @@ -264,7 +263,7 @@ public interface TargetManagement { * @return a page of the found {@link Target}s */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - Page findAllTargetsByTargetFilterQueryAndNotInRolloutGroups(@NotNull Pageable pageRequest, + Page findByTargetFilterQueryAndNotInRolloutGroups(@NotNull Pageable pageRequest, @NotEmpty Collection groups, @NotNull String rsqlParam); /** @@ -278,8 +277,7 @@ public interface TargetManagement { * @return count of the found {@link Target}s */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - Long countAllTargetsByTargetFilterQueryAndNotInRolloutGroups(@NotEmpty Collection groups, - @NotNull String rsqlParam); + long countByRsqlAndNotInRolloutGroups(@NotEmpty Collection groups, @NotNull String rsqlParam); /** * Finds all targets of the provided {@link RolloutGroup} that have no @@ -295,37 +293,36 @@ public interface TargetManagement { * if rollout group with given ID does not exist */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - Page findAllTargetsInRolloutGroupWithoutAction(@NotNull Pageable pageRequest, @NotNull Long group); + Page findByInRolloutGroupWithoutAction(@NotNull Pageable pageRequest, @NotNull Long group); /** - * retrieves {@link Target}s by the assigned {@link DistributionSet} without - * details, i.e. NO {@link Target#getTags()} and {@link Target#getActions()} - * possible. - * - * - * @param distributionSetID - * the ID of the {@link DistributionSet} + * retrieves {@link Target}s by the assigned {@link DistributionSet}. + * * @param pageReq * page parameter + * @param distributionSetID + * the ID of the {@link DistributionSet} + * + * * @return the found {@link Target}s * * @throws EntityNotFoundException * if distribution set with given ID does not exist */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_READ_TARGET) - Page findTargetByAssignedDistributionSet(@NotNull Long distributionSetID, @NotNull Pageable pageReq); + Page findByAssignedDistributionSet(@NotNull Pageable pageReq, @NotNull Long distributionSetID); /** - * Retrieves {@link Target}s by the assigned {@link DistributionSet} without - * details, i.e. NO {@link Target#getTags()} and {@link Target#getActions()} + * Retrieves {@link Target}s by the assigned {@link DistributionSet} * possible including additional filtering based on the given {@code spec}. - * + * + * @param pageReq + * page parameter * @param distributionSetID * the ID of the {@link DistributionSet} * @param rsqlParam * the specification to filter the result set - * @param pageReq - * page parameter + * * @return the found {@link Target}s, never {@code null} * @throws RSQLParameterUnsupportedFieldException * if a field in the RSQL string is used but not provided by the @@ -336,20 +333,18 @@ public interface TargetManagement { * if distribution set with given ID does not exist */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_READ_TARGET) - Page findTargetByAssignedDistributionSet(@NotNull Long distributionSetID, @NotNull String rsqlParam, - @NotNull Pageable pageReq); + Page findByAssignedDistributionSetAndRsql(@NotNull Pageable pageReq, @NotNull Long distributionSetID, + @NotNull String rsqlParam); /** - * Find {@link Target}s based a given IDs. The returned target will not - * contain details (e.g {@link Target#getTags()} and - * {@link Target#getActions()}) + * Find {@link Target}s based a given IDs. * * @param controllerIDs * to look for. * @return List of found{@link Target}s */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - List findTargetsByControllerID(@NotEmpty Collection controllerIDs); + List getByControllerID(@NotEmpty Collection controllerIDs); /** * Find a {@link Target} based a given ID. @@ -359,7 +354,7 @@ public interface TargetManagement { * @return {@link Target} */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - Optional findTargetByControllerID(@NotEmpty String controllerId); + Optional getByControllerID(@NotEmpty String controllerId); /** * Filter {@link Target}s for all the given parameters. If all parameters @@ -367,25 +362,9 @@ public interface TargetManagement { * * @param pageable * page parameters - * @param status - * find targets having this {@link TargetUpdateStatus}s. Set to - * null in case this is not required. - * @param overdueState - * find targets that are overdue (targets that did not respond - * during the configured intervals: poll_itvl + overdue_itvl). - * @param searchText - * to find targets having the text anywhere in name or - * description. Set null in case this is not - * required. - * @param installedOrAssignedDistributionSetId - * to find targets having the {@link DistributionSet} as - * installed or assigned. Set to null in case this - * is not required. - * @param tagNames - * to find targets which are having any one in this tag names. - * Set null in case this is not required. - * @param selectTargetWithNoTag - * flag to select targets with no tag assigned + * @param filterParams + * the filters to apply; only filters are enabled that have + * non-null value; filters are AND-gated * * @return the found {@link Target}s * @@ -393,38 +372,35 @@ public interface TargetManagement { * if distribution set with given ID does not exist */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - Slice findTargetByFilters(@NotNull Pageable pageable, Collection status, - Boolean overdueState, String searchText, Long installedOrAssignedDistributionSetId, - Boolean selectTargetWithNoTag, String... tagNames); + Slice findByFilters(@NotNull Pageable pageable, @NotNull FilterParams filterParams); /** - * retrieves {@link Target}s by the installed {@link DistributionSet}without - * details, i.e. NO {@link Target#getTags()} and {@link Target#getActions()} - * possible. - * - * @param distributionSetID - * the ID of the {@link DistributionSet} + * retrieves {@link Target}s by the installed {@link DistributionSet}. + * * @param pageReq * page parameter + * @param distributionSetID + * the ID of the {@link DistributionSet} + * * @return the found {@link Target}s * * @throws EntityNotFoundException * if distribution set with given ID does not exist */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_READ_TARGET) - Page findTargetByInstalledDistributionSet(@NotNull Long distributionSetID, @NotNull Pageable pageReq); + Page findByInstalledDistributionSet(@NotNull Pageable pageReq, @NotNull Long distributionSetID); /** - * retrieves {@link Target}s by the installed {@link DistributionSet}without - * details, i.e. NO {@link Target#getTags()} and {@link Target#getActions()} - * possible including additional filtering based on the given {@code spec}. - * + * retrieves {@link Target}s by the installed {@link DistributionSet} + * including additional filtering based on the given {@code spec}. + * + * @param pageReq + * page parameter * @param distributionSetId * the ID of the {@link DistributionSet} * @param rsqlParam * the specification to filter the result - * @param pageReq - * page parameter + * * @return the found {@link Target}s, never {@code null} * * @throws RSQLParameterUnsupportedFieldException @@ -437,13 +413,12 @@ public interface TargetManagement { * if distribution set with given ID does not exist */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_READ_TARGET) - Page findTargetByInstalledDistributionSet(@NotNull Long distributionSetId, @NotNull String rsqlParam, - @NotNull Pageable pageReq); + Page findByInstalledDistributionSetAndRsql(@NotNull Pageable pageReq, @NotNull Long distributionSetId, + @NotNull String rsqlParam); /** * Retrieves the {@link Target} which have a certain - * {@link TargetUpdateStatus} without details, i.e. NO - * {@link Target#getTags()} and {@link Target#getActions()} possible. + * {@link TargetUpdateStatus}. * * @param pageable * page parameter @@ -452,29 +427,25 @@ public interface TargetManagement { * @return the found {@link Target}s */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - Page findTargetByUpdateStatus(@NotNull Pageable pageable, @NotNull TargetUpdateStatus status); + Page findByUpdateStatus(@NotNull Pageable pageable, @NotNull TargetUpdateStatus status); /** - * Retrieves all targets without details, i.e. NO {@link Target#getTags()} - * and {@link Target#getActions()} possible + * Retrieves all targets. * * @param pageable * pagination parameter * @return the found {@link Target}s */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - Slice findTargetsAll(@NotNull Pageable pageable); + Slice findAll(@NotNull Pageable pageable); /** - * Retrieves all targets without details, i.e. NO {@link Target#getTags()} - * and {@link Target#getActions()} possible based on - * {@link TargetFilterQuery#getQuery()} - * - * @param rsqlParam - * in RSQL notation + * Retrieves all targets. * * @param pageable * pagination parameter + * @param rsqlParam + * in RSQL notation * * @return the found {@link Target}s, never {@code null} * @@ -486,17 +457,15 @@ public interface TargetManagement { * if the RSQL syntax is wrong */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - Page findTargetsAll(@NotNull String rsqlParam, @NotNull Pageable pageable); + Page findByRsql(@NotNull Pageable pageable, @NotNull String rsqlParam); /** - * Retrieves all targets without details, i.e. NO {@link Target#getTags()} - * and {@link Target#getActions()} possible based on - * {@link TargetFilterQuery#getQuery()} - * - * @param targetFilterQueryId - * {@link TargetFilterQuery#getId()} + * Retrieves all target based on {@link TargetFilterQuery}. + * * @param pageable * pagination parameter + * @param targetFilterQueryId + * {@link TargetFilterQuery#getId()} * * @return the found {@link Target}s, never {@code null} * @@ -509,7 +478,7 @@ public interface TargetManagement { * if the RSQL syntax is wrong */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - Slice findTargetsByTargetFilterQuery(@NotNull Long targetFilterQueryId, @NotNull Pageable pageable); + Slice findByTargetFilterQuery(@NotNull Pageable pageable, @NotNull Long targetFilterQueryId); /** * method retrieves all {@link Target}s from the repo in the following @@ -538,8 +507,8 @@ public interface TargetManagement { * if distribution set with given ID does not exist */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - Slice findTargetsAllOrderByLinkedDistributionSet(@NotNull Pageable pageable, - @NotNull Long orderByDistributionId, FilterParams filterParams); + Slice findByFilterOrderByLinkedDistributionSet(@NotNull Pageable pageable, + @NotNull Long orderByDistributionId, @NotNull FilterParams filterParams); /** * Find targets by tag name. @@ -554,7 +523,7 @@ public interface TargetManagement { * if target tag with given ID does not exist */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - Page findTargetsByTag(@NotNull Pageable pageable, @NotNull Long tagId); + Page findByTag(@NotNull Pageable pageable, @NotNull Long tagId); /** * Find targets by tag name. @@ -577,7 +546,7 @@ public interface TargetManagement { * if the RSQL syntax is wrong */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - Page findTargetsByTag(@NotNull Pageable pageable, @NotNull String rsqlParam, @NotNull Long tagId); + Page findByRsqlAndTag(@NotNull Pageable pageable, @NotNull String rsqlParam, @NotNull Long tagId); /** * Toggles {@link TargetTag} assignment to given {@link Target}s by means @@ -626,32 +595,28 @@ public interface TargetManagement { * if fields are not filled as specified. Check * {@link TargetUpdate} for field constraints. */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET + SpringEvalExpressions.HAS_AUTH_OR - + SpringEvalExpressions.IS_CONTROLLER) - Target updateTarget(@NotNull TargetUpdate update); + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET) + Target update(@NotNull TargetUpdate update); /** - * Find a {@link Target} based a given ID. The returned target will not - * contain details (e.g {@link Target#getTags()} and - * {@link Target#getActions()}) + * Find a {@link Target} based a given ID. * * @param id * to look for * @return {@link Target} */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - Optional findTargetById(Long id); + Optional get(@NotNull Long id); /** - * Retrieves all targets without details, i.e. NO {@link Target#getTags()} - * and {@link Target#getActions()} possible + * Retrieves all targets. * * @param ids * the ids to for * @return the found {@link Target}s */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - List findTargetsById(@NotNull Collection ids); + List get(@NotNull Collection ids); /** * Get controller attributes of given {@link Target}. diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetTagManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetTagManagement.java new file mode 100644 index 000000000..13be0aa30 --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetTagManagement.java @@ -0,0 +1,173 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository; + +import java.util.Collection; +import java.util.List; +import java.util.Optional; + +import javax.validation.ConstraintViolationException; +import javax.validation.constraints.NotNull; + +import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; +import org.eclipse.hawkbit.repository.builder.TagCreate; +import org.eclipse.hawkbit.repository.builder.TagUpdate; +import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; +import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; +import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException; +import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException; +import org.eclipse.hawkbit.repository.model.Target; +import org.eclipse.hawkbit.repository.model.TargetTag; +import org.hibernate.validator.constraints.NotEmpty; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.security.access.prepost.PreAuthorize; + +/** + * Management service for {@link TargetTag}s. + * + */ +public interface TargetTagManagement { + + /** + * count {@link TargetTag}s. + * + * @return size of {@link TargetTag}s + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + long count(); + + /** + * Creates a new {@link TargetTag}. + * + * @param create + * to be created + * + * @return the new created {@link TargetTag} + * + * @throws EntityAlreadyExistsException + * if given object already exists + * @throws ConstraintViolationException + * if fields are not filled as specified. Check + * {@link TagCreate} for field constraints. + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_TARGET) + TargetTag create(@NotNull TagCreate create); + + /** + * created multiple {@link TargetTag}s. + * + * @param creates + * to be created + * @return the new created {@link TargetTag}s + * + * @throws EntityAlreadyExistsException + * if given object has already an ID. + * @throws ConstraintViolationException + * if fields are not filled as specified. Check + * {@link TagCreate} for field constraints. + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_TARGET) + List create(@NotNull Collection creates); + + /** + * Deletes {@link TargetTag} with given name. + * + * @param targetTagName + * tag name of the {@link TargetTag} to be deleted + * + * @throws EntityNotFoundException + * if tag with given name does not exist + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_TARGET) + void delete(@NotEmpty String targetTagName); + + /** + * returns all {@link TargetTag}s. + * + * @param pageable + * page parameter + * + * @return all {@link TargetTag}s + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + Page findAll(@NotNull Pageable pageable); + + /** + * Returns all {@link TargetTag}s assigned to {@link Target} with given ID. + * + * @param pageable + * page parameter + * @param controllerId + * of the assigned target + * + * @return {@link TargetTag}s assigned to {@link Target} with given ID + * + * @throws EntityNotFoundException + * if target with given ID does not exist + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + Page findByTarget(@NotNull Pageable pageable, @NotEmpty String controllerId); + + /** + * Retrieves all target tags based on the given specification. + * @param pageable + * pagination parameter + * @param rsqlParam + * rsql query string + * + * @return the found {@link Target}s, never {@code null} + * + * @throws RSQLParameterUnsupportedFieldException + * if a field in the RSQL string is used but not provided by the + * given {@code fieldNameProvider} + * @throws RSQLParameterSyntaxException + * if the RSQL syntax is wrong + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + Page findByRsql(@NotNull Pageable pageable, @NotNull String rsqlParam); + + /** + * Find {@link TargetTag} based on given Name. + * + * @param name + * to look for. + * @return {@link TargetTag} + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + Optional getByName(@NotEmpty String name); + + /** + * Finds {@link TargetTag} by given id. + * + * @param id + * to search for + * @return the found {@link TargetTag} + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + Optional get(@NotNull Long id); + + /** + * updates the {@link TargetTag}. + * + * @param update + * the {@link TargetTag} with updated values + * @return the updated {@link TargetTag} + * + * @throws EntityNotFoundException + * in case the {@link TargetTag} does not exists and cannot be + * updated + * @throws ConstraintViolationException + * if fields are not filled as specified. Check + * {@link TagUpdate} for field constraints. + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET) + TargetTag update(@NotNull TagUpdate update); + +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/DistributionSetCreationFailedMissingMandatoryModuleException.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/DistributionSetCreationFailedMissingMandatoryModuleException.java deleted file mode 100644 index 841cd9fd2..000000000 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/DistributionSetCreationFailedMissingMandatoryModuleException.java +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository.exception; - -import org.eclipse.hawkbit.exception.AbstractServerRtException; -import org.eclipse.hawkbit.exception.SpServerError; - -/** - * Thrown if DS creation failed. - * - * - * - * - */ -public final class DistributionSetCreationFailedMissingMandatoryModuleException extends AbstractServerRtException { - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * Creates a new FileUploadFailedException with - * {@link SpServerError#SP_DS_CREATION_FAILED_MISSING_MODULE} error. - */ - public DistributionSetCreationFailedMissingMandatoryModuleException() { - super(SpServerError.SP_DS_CREATION_FAILED_MISSING_MODULE); - } - - /** - * @param cause - * for the exception - */ - public DistributionSetCreationFailedMissingMandatoryModuleException(final Throwable cause) { - super(SpServerError.SP_DS_CREATION_FAILED_MISSING_MODULE, cause); - } - - /** - * @param message - * of the error - */ - public DistributionSetCreationFailedMissingMandatoryModuleException(final String message) { - super(message, SpServerError.SP_DS_CREATION_FAILED_MISSING_MODULE); - } -} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetAssignmentResult.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetAssignmentResult.java index f1273131e..350373daf 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetAssignmentResult.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetAssignmentResult.java @@ -70,7 +70,7 @@ public class DistributionSetAssignmentResult extends AssignmentResult { return Collections.emptyList(); } - return targetManagement.findTargetsByControllerID(assignedTargets); + return targetManagement.getByControllerID(assignedTargets); } } diff --git a/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/AbstractRolloutManagement.java b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/AbstractRolloutManagement.java index 0fa84d11f..742be2a70 100644 --- a/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/AbstractRolloutManagement.java +++ b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/AbstractRolloutManagement.java @@ -90,7 +90,7 @@ public abstract class AbstractRolloutManagement implements RolloutManagement { final List groupTargetCounts = new ArrayList<>(groups.size()); final Map targetFilterCounts = groups.stream() .map(group -> RolloutHelper.getGroupTargetFilter(baseFilter, group)).distinct() - .collect(Collectors.toMap(Function.identity(), targetManagement::countTargetByTargetFilterQuery)); + .collect(Collectors.toMap(Function.identity(), targetManagement::countByRsql)); long unusedTargetsCount = 0; @@ -136,7 +136,7 @@ public abstract class AbstractRolloutManagement implements RolloutManagement { if (targetFilterCounts.containsKey(overlappingTargetsFilter)) { return targetFilterCounts.get(overlappingTargetsFilter); } else { - final long overlappingTargets = targetManagement.countTargetByTargetFilterQuery(overlappingTargetsFilter); + final long overlappingTargets = targetManagement.countByRsql(overlappingTargetsFilter); targetFilterCounts.put(overlappingTargetsFilter, overlappingTargets); return overlappingTargets; } @@ -145,7 +145,7 @@ public abstract class AbstractRolloutManagement implements RolloutManagement { protected long calculateRemainingTargets(final List groups, final String targetFilter, final Long createdAt) { final String baseFilter = RolloutHelper.getTargetFilterQuery(targetFilter, createdAt); - final long totalTargets = targetManagement.countTargetByTargetFilterQuery(baseFilter); + final long totalTargets = targetManagement.countByRsql(baseFilter); if (totalTargets == 0) { throw new ConstraintDeclarationException("Rollout target filter does not match any targets"); } @@ -161,7 +161,7 @@ public abstract class AbstractRolloutManagement implements RolloutManagement { final String targetFilter, final Long createdAt) { final String baseFilter = RolloutHelper.getTargetFilterQuery(targetFilter, createdAt); - final long totalTargets = targetManagement.countTargetByTargetFilterQuery(baseFilter); + final long totalTargets = targetManagement.countByRsql(baseFilter); if (totalTargets == 0) { throw new ConstraintDeclarationException("Rollout target filter does not match any targets"); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetRepository.java index 28305207a..b15bc5b48 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetRepository.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetRepository.java @@ -47,22 +47,9 @@ public interface DistributionSetRepository * to be found * @return list of found {@link DistributionSet}s */ - @Query(value = "Select Distinct ds from JpaDistributionSet ds join ds.tags dst where dst.id = :tag") + @Query(value = "Select Distinct ds from JpaDistributionSet ds join ds.tags dst where dst.id = :tag and ds.deleted = 0") Page findByTag(Pageable pageable, @Param("tag") final Long tagId); - /** - * Finds {@link DistributionSet}s by assigned {@link Tag}. - * - * @param pageable - * paging and sorting information - * - * @param tagId - * to be found - * @return page of found {@link DistributionSet}s - */ - @Query(value = "Select Distinct ds from JpaDistributionSet ds join ds.tags dst where dst.id = :tagId") - Page findByTagId(Pageable pageable, @Param("tagId") final Long tagId); - /** * deletes the {@link DistributionSet}s with the given IDs. * @@ -175,4 +162,5 @@ public interface DistributionSetRepository @Transactional @Query("DELETE FROM JpaDistributionSet t WHERE t.tenant = :tenant") void deleteByTenant(@Param("tenant") String tenant); + } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetTagRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetTagRepository.java index 9243655dd..f7f85dfe5 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetTagRepository.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetTagRepository.java @@ -82,4 +82,9 @@ public interface DistributionSetTagRepository @Transactional @Query("DELETE FROM JpaDistributionSetTag t WHERE t.tenant = :tenant") void deleteByTenant(@Param("tenant") String tenant); + + @Override + // Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=349477 + @Query("SELECT d FROM JpaDistributionSetTag d WHERE d.id IN ?1") + List findAll(Iterable ids); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetTypeRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetTypeRepository.java index 5c7f765f4..5f35625ae 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetTypeRepository.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetTypeRepository.java @@ -8,6 +8,8 @@ */ package org.eclipse.hawkbit.repository.jpa; +import java.util.List; + import javax.persistence.EntityManager; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType; @@ -48,7 +50,7 @@ public interface DistributionSetTypeRepository * count or all undeleted. * @return number of {@link DistributionSetType}s in the repository. */ - Long countByDeleted(boolean isDeleted); + long countByDeleted(boolean isDeleted); /** * Counts all distribution set type where a specific software module type is @@ -60,7 +62,7 @@ public interface DistributionSetTypeRepository * @return the number of {@link DistributionSetType}s in the repository * assigned to the given software module type */ - Long countByElementsSmType(JpaSoftwareModuleType softwareModuleType); + long countByElementsSmType(JpaSoftwareModuleType softwareModuleType); /** * Deletes all {@link TenantAwareBaseEntity} of a given tenant. For safety @@ -75,4 +77,9 @@ public interface DistributionSetTypeRepository @Transactional @Query("DELETE FROM JpaDistributionSetType t WHERE t.tenant = :tenant") void deleteByTenant(@Param("tenant") String tenant); + + @Override + // Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=349477 + @Query("SELECT d FROM JpaDistributionSetType d WHERE d.id IN ?1") + List findAll(Iterable ids); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaArtifactManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaArtifactManagement.java index 900faf890..b88b43ae2 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaArtifactManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaArtifactManagement.java @@ -85,7 +85,7 @@ public class JpaArtifactManagement implements ArtifactManagement { @Transactional @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) - public Artifact createArtifact(final InputStream stream, final Long moduleId, final String filename, + public Artifact create(final InputStream stream, final Long moduleId, final String filename, final String providedMd5Sum, final String providedSha1Sum, final boolean overrideExisting, final String contentType) { AbstractDbArtifact result = null; @@ -137,8 +137,8 @@ public class JpaArtifactManagement implements ArtifactManagement { @Transactional @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) - public void deleteArtifact(final Long id) { - final JpaArtifact existing = (JpaArtifact) findArtifact(id) + public void delete(final Long id) { + final JpaArtifact existing = (JpaArtifact) get(id) .orElseThrow(() -> new EntityNotFoundException(Artifact.class, id)); clearArtifactBinary(existing.getSha1Hash(), existing.getSoftwareModule().getId()); @@ -149,29 +149,29 @@ public class JpaArtifactManagement implements ArtifactManagement { } @Override - public Optional findArtifact(final Long id) { + public Optional get(final Long id) { return Optional.ofNullable(localArtifactRepository.findOne(id)); } @Override - public Optional findByFilenameAndSoftwareModule(final String filename, final Long softwareModuleId) { + public Optional getByFilenameAndSoftwareModule(final String filename, final Long softwareModuleId) { throwExceptionIfSoftwareModuleDoesNotExist(softwareModuleId); return localArtifactRepository.findFirstByFilenameAndSoftwareModuleId(filename, softwareModuleId); } @Override - public Optional findFirstArtifactBySHA1(final String sha1Hash) { + public Optional findFirstBySHA1(final String sha1Hash) { return localArtifactRepository.findFirstBySha1Hash(sha1Hash); } @Override - public Optional findArtifactByFilename(final String filename) { + public Optional getByFilename(final String filename) { return localArtifactRepository.findFirstByFilename(filename); } @Override - public Page findArtifactBySoftwareModule(final Pageable pageReq, final Long swId) { + public Page findBySoftwareModule(final Pageable pageReq, final Long swId) { throwExceptionIfSoftwareModuleDoesNotExist(swId); return localArtifactRepository.findBySoftwareModuleId(pageReq, swId); @@ -206,13 +206,13 @@ public class JpaArtifactManagement implements ArtifactManagement { @Transactional @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) - public Artifact createArtifact(final InputStream inputStream, final Long moduleId, final String filename, + public Artifact create(final InputStream inputStream, final Long moduleId, final String filename, final boolean overrideExisting) { - return createArtifact(inputStream, moduleId, filename, null, null, overrideExisting, null); + return create(inputStream, moduleId, filename, null, null, overrideExisting, null); } @Override - public Long countArtifactsAll() { + public long count() { return localArtifactRepository.count(); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java index d6fd63f71..de0af20a9 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java @@ -483,12 +483,12 @@ public class JpaControllerManagement implements ControllerManagement { } @Override - public Optional findByControllerId(final String controllerId) { + public Optional getByControllerId(final String controllerId) { return targetRepository.findByControllerId(controllerId); } @Override - public Optional findByTargetId(final Long targetId) { + public Optional get(final Long targetId) { return Optional.ofNullable(targetRepository.findOne(targetId)); } @@ -522,4 +522,9 @@ public class JpaControllerManagement implements ControllerManagement { return messages.getContent(); } + + @Override + public Optional getSoftwareModule(final Long id) { + return Optional.ofNullable(softwareModuleRepository.findOne(id)); + } } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java index d01473989..406847596 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java @@ -496,14 +496,14 @@ public class JpaDeploymentManagement implements DeploymentManagement { } @Override - public Long countActionsByTarget(final String controllerId) { + public long countActionsByTarget(final String controllerId) { throwExceptionIfTargetDoesNotExist(controllerId); return actionRepository.countByTargetControllerId(controllerId); } @Override - public Long countActionsByTarget(final String rsqlParam, final String controllerId) { + public long countActionsByTarget(final String rsqlParam, final String controllerId) { throwExceptionIfTargetDoesNotExist(controllerId); return actionRepository.count(createSpecificationFor(controllerId, rsqlParam)); @@ -578,12 +578,12 @@ public class JpaDeploymentManagement implements DeploymentManagement { } @Override - public Long countActionStatusAll() { + public long countActionStatusAll() { return actionStatusRepository.count(); } @Override - public Long countActionsAll() { + public long countActionsAll() { return actionRepository.count(); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java index d01b6b8e6..8c806e04d 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java @@ -21,9 +21,9 @@ import javax.persistence.EntityManager; import org.eclipse.hawkbit.repository.DistributionSetFields; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.DistributionSetMetadataFields; +import org.eclipse.hawkbit.repository.DistributionSetTagManagement; import org.eclipse.hawkbit.repository.DistributionSetTypeManagement; import org.eclipse.hawkbit.repository.SystemManagement; -import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.builder.DistributionSetCreate; import org.eclipse.hawkbit.repository.builder.DistributionSetUpdate; import org.eclipse.hawkbit.repository.builder.GenericDistributionSetUpdate; @@ -63,6 +63,7 @@ import org.springframework.dao.ConcurrencyFailureException; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; import org.springframework.data.jpa.domain.Specification; import org.springframework.retry.annotation.Backoff; import org.springframework.retry.annotation.Retryable; @@ -88,7 +89,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { private DistributionSetRepository distributionSetRepository; @Autowired - private TagManagement tagManagement; + private DistributionSetTagManagement distributionSetTagManagement; @Autowired private SystemManagement systemManagement; @@ -105,6 +106,9 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { @Autowired private ActionRepository actionRepository; + @Autowired + private NoCountPagingRepository criteriaNoCountDao; + @Autowired private ApplicationEventPublisher eventPublisher; @@ -127,13 +131,17 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { private AfterTransactionCommitExecutor afterCommit; @Override - public Optional findDistributionSetByIdWithDetails(final Long distid) { + public Optional getWithDetails(final Long distid) { return Optional.ofNullable(distributionSetRepository.findOne(DistributionSetSpecification.byId(distid))); } @Override - public Optional findDistributionSetById(final Long distid) { - return Optional.ofNullable(distributionSetRepository.findOne(distid)); + public long countByTypeId(final Long typeId) { + if (!distributionSetTypeManagement.exists(typeId)) { + throw new EntityNotFoundException(DistributionSetType.class, typeId); + } + + return distributionSetRepository.countByTypeId(typeId); } @Override @@ -148,7 +156,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { sets.stream().map(DistributionSet::getId).collect(Collectors.toList())); } - final DistributionSetTag myTag = tagManagement.findDistributionSetTag(tagName) + final DistributionSetTag myTag = distributionSetTagManagement.getByName(tagName) .orElseThrow(() -> new EntityNotFoundException(DistributionSetTag.class, tagName)); DistributionSetTagAssignmentResult result; @@ -189,7 +197,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { @Transactional @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) - public DistributionSet updateDistributionSet(final DistributionSetUpdate u) { + public DistributionSet update(final DistributionSetUpdate u) { final GenericDistributionSetUpdate update = (GenericDistributionSetUpdate) u; final JpaDistributionSet set = findDistributionSetAndThrowExceptionIfNotFound(update.getId()); @@ -217,13 +225,13 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { } private JpaDistributionSetType findDistributionSetTypeAndThrowExceptionIfNotFound(final String key) { - return (JpaDistributionSetType) distributionSetTypeManagement.findDistributionSetTypeByKey(key) + return (JpaDistributionSetType) distributionSetTypeManagement.getByKey(key) .orElseThrow(() -> new EntityNotFoundException(DistributionSetType.class, key)); } private JpaDistributionSet findDistributionSetAndThrowExceptionIfNotFound(final Long setId) { - return (JpaDistributionSet) findDistributionSetById(setId) + return (JpaDistributionSet) get(setId) .orElseThrow(() -> new EntityNotFoundException(DistributionSet.class, setId)); } @@ -236,8 +244,8 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { @Transactional @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) - public void deleteDistributionSet(final Collection distributionSetIDs) { - final List setsFound = findDistributionSetsById(distributionSetIDs); + public void delete(final Collection distributionSetIDs) { + final List setsFound = get(distributionSetIDs); if (setsFound.size() < distributionSetIDs.size()) { throw new EntityNotFoundException(DistributionSet.class, distributionSetIDs, @@ -275,7 +283,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { @Transactional @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) - public DistributionSet createDistributionSet(final DistributionSetCreate c) { + public DistributionSet create(final DistributionSetCreate c) { final JpaDistributionSetCreate create = (JpaDistributionSetCreate) c; if (create.getType() == null) { create.type(systemManagement.getTenantMetadata().getDefaultDsType().getKey()); @@ -288,8 +296,8 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { @Transactional @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) - public List createDistributionSets(final Collection creates) { - return creates.stream().map(this::createDistributionSet).collect(Collectors.toList()); + public List create(final Collection creates) { + return creates.stream().map(this::create).collect(Collectors.toList()); } @Override @@ -329,7 +337,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { } @Override - public Page findDistributionSetsByFilters(final Pageable pageable, + public Page findByDistributionSetFilter(final Pageable pageable, final DistributionSetFilter distributionSetFilter) { final List> specList = buildDistributionSetSpecifications( distributionSetFilter); @@ -341,6 +349,11 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { return new PageImpl<>(Collections.unmodifiableList(findAll.getContent()), pageable, findAll.getTotalElements()); } + private static Slice convertDsPage(final Slice findAll, + final Pageable pageable) { + return new PageImpl<>(Collections.unmodifiableList(findAll.getContent()), pageable, 0); + } + /** * * @param distributionSetFilter @@ -359,52 +372,21 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { } @Override - public Page findDistributionSetsByDeletedAndOrCompleted(final Pageable pageReq, - final Boolean deleted, final Boolean complete) { - final List> specList = new ArrayList<>(2); - - if (deleted != null) { - final Specification spec = DistributionSetSpecification.isDeleted(deleted); - specList.add(spec); - } + public Page findByCompleted(final Pageable pageReq, final Boolean complete) { + List> specList; if (complete != null) { - final Specification spec = DistributionSetSpecification.isCompleted(complete); - specList.add(spec); + specList = Arrays.asList(DistributionSetSpecification.isDeleted(false), + DistributionSetSpecification.isCompleted(complete)); + } else { + specList = Arrays.asList(DistributionSetSpecification.isDeleted(false)); } return convertDsPage(findByCriteriaAPI(pageReq, specList), pageReq); } @Override - public Page findDistributionSetsAll(final String rsqlParam, final Pageable pageReq, - final Boolean deleted) { - - final Specification spec = RSQLUtility.parse(rsqlParam, DistributionSetFields.class, - virtualPropertyReplacer); - - final List> specList = new ArrayList<>(2); - if (deleted != null) { - specList.add(DistributionSetSpecification.isDeleted(deleted)); - } - specList.add(spec); - - return convertDsPage(findByCriteriaAPI(pageReq, specList), pageReq); - } - - @Override - public Page findDistributionSetsAll(final Pageable pageReq, final Boolean deleted) { - - final List> specList = new ArrayList<>(1); - if (deleted != null) { - specList.add(DistributionSetSpecification.isDeleted(deleted)); - } - - return convertDsPage(findByCriteriaAPI(pageReq, specList), pageReq); - } - - @Override - public Page findDistributionSetsAllOrderedByLinkTarget(final Pageable pageable, + public Page findByFilterAndAssignedInstalledDsOrderedByLinkTarget(final Pageable pageable, final DistributionSetFilterBuilder distributionSetFilterBuilder, final String assignedOrInstalled) { final DistributionSetFilter filterWithInstalledTargets = distributionSetFilterBuilder @@ -421,7 +403,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { .setAssignedTargetId(null).build(); // first fine the distribution sets filtered by the given filter // parameters - final Page findDistributionSetsByFilters = findDistributionSetsByFilters(pageable, + final Page findDistributionSetsByFilters = findByDistributionSetFilter(pageable, dsFilterWithNoTargetLinked); final List resultSet = new ArrayList<>(findDistributionSetsByFilters.getContent()); @@ -446,8 +428,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { } @Override - public Optional findDistributionSetByNameAndVersion(final String distributionName, - final String version) { + public Optional getByNameAndVersion(final String distributionName, final String version) { final Specification spec = DistributionSetSpecification .equalsNameAndVersionIgnoreCase(distributionName, version); return Optional.ofNullable(distributionSetRepository.findOne(spec)); @@ -455,7 +436,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { } @Override - public Long countDistributionSetsAll() { + public long count() { final Specification spec = DistributionSetSpecification.isDeleted(Boolean.FALSE); return distributionSetRepository.count(SpecificationsBuilder.combineWithAnd(Arrays.asList(spec))); @@ -465,7 +446,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { @Transactional @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) - public List createDistributionSetMetadata(final Long dsId, final Collection md) { + public List createMetaData(final Long dsId, final Collection md) { md.forEach(meta -> checkAndThrowAlreadyIfDistributionSetMetadataExists( new DsMetadataCompositeKey(dsId, meta.getKey()))); @@ -482,10 +463,10 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { @Transactional @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) - public DistributionSetMetadata updateDistributionSetMetadata(final Long dsId, final MetaData md) { + public DistributionSetMetadata updateMetaData(final Long dsId, final MetaData md) { // check if exists otherwise throw entity not found exception - final JpaDistributionSetMetadata toUpdate = (JpaDistributionSetMetadata) findDistributionSetMetadata(dsId, + final JpaDistributionSetMetadata toUpdate = (JpaDistributionSetMetadata) getMetaDataByDistributionSetId(dsId, md.getKey()).orElseThrow( () -> new EntityNotFoundException(DistributionSetMetadata.class, dsId, md.getKey())); toUpdate.setValue(md.getValue()); @@ -499,8 +480,8 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { @Transactional @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) - public void deleteDistributionSetMetadata(final Long distributionSetId, final String key) { - final JpaDistributionSetMetadata metadata = (JpaDistributionSetMetadata) findDistributionSetMetadata( + public void deleteMetaData(final Long distributionSetId, final String key) { + final JpaDistributionSetMetadata metadata = (JpaDistributionSetMetadata) getMetaDataByDistributionSetId( distributionSetId, key).orElseThrow( () -> new EntityNotFoundException(DistributionSetMetadata.class, distributionSetId, key)); @@ -535,13 +516,12 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { * of the DS to touch */ private JpaDistributionSet touch(final Long distId) { - return touch(findDistributionSetById(distId) - .orElseThrow(() -> new EntityNotFoundException(DistributionSet.class, distId))); + return touch(get(distId).orElseThrow(() -> new EntityNotFoundException(DistributionSet.class, distId))); } @Override - public Page findDistributionSetMetadataByDistributionSetId(final Long distributionSetId, - final Pageable pageable) { + public Page findMetaDataByDistributionSetId(final Pageable pageable, + final Long distributionSetId) { throwExceptionIfDistributionSetDoesNotExist(distributionSetId); return convertMdPage(distributionSetMetadataRepository @@ -552,8 +532,8 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { } @Override - public Page findDistributionSetMetadataByDistributionSetId(final Long distributionSetId, - final String rsqlParam, final Pageable pageable) { + public Page findMetaDataByDistributionSetIdAndRsql(final Pageable pageable, + final Long distributionSetId, final String rsqlParam) { throwExceptionIfDistributionSetDoesNotExist(distributionSetId); @@ -575,14 +555,14 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { } @Override - public Optional findDistributionSetMetadata(final Long setId, final String key) { + public Optional getMetaDataByDistributionSetId(final Long setId, final String key) { throwExceptionIfDistributionSetDoesNotExist(setId); return Optional.ofNullable(distributionSetMetadataRepository.findOne(new DsMetadataCompositeKey(setId, key))); } @Override - public Optional findDistributionSetByAction(final Long actionId) { + public Optional getByAction(final Long actionId) { if (!actionRepository.exists(actionId)) { throw new EntityNotFoundException(Action.class, actionId); } @@ -591,7 +571,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { } @Override - public boolean isDistributionSetInUse(final Long setId) { + public boolean isInUse(final Long setId) { throwExceptionIfDistributionSetDoesNotExist(setId); return actionRepository.countByDistributionSetId(setId) > 0; @@ -693,7 +673,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { allDs.stream().map(DistributionSet::getId).collect(Collectors.toList())); } - final DistributionSetTag distributionSetTag = tagManagement.findDistributionSetTagById(dsTagId) + final DistributionSetTag distributionSetTag = distributionSetTagManagement.get(dsTagId) .orElseThrow(() -> new EntityNotFoundException(DistributionSetTag.class, dsTagId)); allDs.forEach(ds -> ds.addTag(distributionSetTag)); @@ -711,10 +691,10 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) public DistributionSet unAssignTag(final Long dsId, final Long dsTagId) { - final JpaDistributionSet set = (JpaDistributionSet) findDistributionSetByIdWithDetails(dsId) + final JpaDistributionSet set = (JpaDistributionSet) getWithDetails(dsId) .orElseThrow(() -> new EntityNotFoundException(DistributionSet.class, dsId)); - final DistributionSetTag distributionSetTag = tagManagement.findDistributionSetTagById(dsTagId) + final DistributionSetTag distributionSetTag = distributionSetTagManagement.get(dsTagId) .orElseThrow(() -> new EntityNotFoundException(DistributionSetTag.class, dsTagId)); set.removeTag(distributionSetTag); @@ -730,10 +710,10 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { @Transactional @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) - public void deleteDistributionSet(final Long setId) { + public void delete(final Long setId) { throwExceptionIfDistributionSetDoesNotExist(setId); - deleteDistributionSet(Arrays.asList(setId)); + delete(Arrays.asList(setId)); } private void throwExceptionIfDistributionSetDoesNotExist(final Long setId) { @@ -743,12 +723,12 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { } @Override - public List findDistributionSetsById(final Collection ids) { + public List get(final Collection ids) { return Collections.unmodifiableList(distributionSetRepository.findAll(ids)); } @Override - public Page findDistributionSetsByTag(final Pageable pageable, final Long tagId) { + public Page findByTag(final Pageable pageable, final Long tagId) { throwEntityNotFoundExceptionIfDsTagDoesNotExist(tagId); return convertDsPage(distributionSetRepository.findByTag(pageable, tagId), pageable); @@ -762,17 +742,40 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { } @Override - public Page findDistributionSetsByTag(final Pageable pageable, final String rsqlParam, - final Long tagId) { + public Page findByRsqlAndTag(final Pageable pageable, final String rsqlParam, final Long tagId) { throwEntityNotFoundExceptionIfDsTagDoesNotExist(tagId); final Specification spec = RSQLUtility.parse(rsqlParam, DistributionSetFields.class, virtualPropertyReplacer); - return convertDsPage(distributionSetRepository.findAll((Specification) (root, query, - cb) -> cb.and(DistributionSetSpecification.hasTag(tagId).toPredicate(root, query, cb), - spec.toPredicate(root, query, cb)), - pageable), pageable); + return convertDsPage(findByCriteriaAPI(pageable, Arrays.asList(spec, DistributionSetSpecification.hasTag(tagId), + DistributionSetSpecification.isDeleted(false))), pageable); + } + + @Override + public Slice findAll(final Pageable pageable) { + return convertDsPage(criteriaNoCountDao.findAll(DistributionSetSpecification.isDeleted(false), pageable, + JpaDistributionSet.class), pageable); + } + + @Override + public Page findByRsql(final Pageable pageable, final String rsqlParam) { + final Specification spec = RSQLUtility.parse(rsqlParam, DistributionSetFields.class, + virtualPropertyReplacer); + + return convertDsPage( + findByCriteriaAPI(pageable, Arrays.asList(spec, DistributionSetSpecification.isDeleted(false))), + pageable); + } + + @Override + public Optional get(final Long id) { + return Optional.ofNullable(distributionSetRepository.findOne(id)); + } + + @Override + public boolean exists(final Long id) { + return distributionSetRepository.exists(id); } } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTagManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetTagManagement.java similarity index 53% rename from hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTagManagement.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetTagManagement.java index b9165dd55..f6a72e377 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTagManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetTagManagement.java @@ -14,8 +14,9 @@ import java.util.List; import java.util.Optional; import java.util.stream.Collectors; +import org.eclipse.hawkbit.repository.DistributionSetTagManagement; import org.eclipse.hawkbit.repository.TagFields; -import org.eclipse.hawkbit.repository.TagManagement; +import org.eclipse.hawkbit.repository.TargetTagManagement; import org.eclipse.hawkbit.repository.builder.GenericTagUpdate; import org.eclipse.hawkbit.repository.builder.TagCreate; import org.eclipse.hawkbit.repository.builder.TagUpdate; @@ -23,19 +24,16 @@ import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.jpa.builder.JpaTagCreate; import org.eclipse.hawkbit.repository.jpa.configuration.Constants; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag; -import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag; import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility; import org.eclipse.hawkbit.repository.jpa.specifications.TagSpecification; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetTag; -import org.eclipse.hawkbit.repository.model.Target; -import org.eclipse.hawkbit.repository.model.TargetTag; import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.ConcurrencyFailureException; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; import org.springframework.data.jpa.domain.Specification; import org.springframework.retry.annotation.Backoff; import org.springframework.retry.annotation.Retryable; @@ -43,111 +41,35 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; /** - * JP>A implementation of {@link TagManagement}. + * JPA implementation of {@link TargetTagManagement}. * */ @Transactional(readOnly = true) @Validated -public class JpaTagManagement implements TagManagement { +public class JpaDistributionSetTagManagement implements DistributionSetTagManagement { - @Autowired - private TargetTagRepository targetTagRepository; + private final DistributionSetTagRepository distributionSetTagRepository; - @Autowired - private TargetRepository targetRepository; + private final DistributionSetRepository distributionSetRepository; - @Autowired - private DistributionSetTagRepository distributionSetTagRepository; + private final VirtualPropertyReplacer virtualPropertyReplacer; - @Autowired - private DistributionSetRepository distributionSetRepository; + private final NoCountPagingRepository criteriaNoCountDao; - @Autowired - private VirtualPropertyReplacer virtualPropertyReplacer; - - @Override - public Optional findTargetTag(final String name) { - return targetTagRepository.findByNameEquals(name); + JpaDistributionSetTagManagement(final DistributionSetTagRepository distributionSetTagRepository, + final DistributionSetRepository distributionSetRepository, + final VirtualPropertyReplacer virtualPropertyReplacer, final NoCountPagingRepository criteriaNoCountDao) { + this.distributionSetTagRepository = distributionSetTagRepository; + this.distributionSetRepository = distributionSetRepository; + this.virtualPropertyReplacer = virtualPropertyReplacer; + this.criteriaNoCountDao = criteriaNoCountDao; } @Override @Transactional @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) - public TargetTag createTargetTag(final TagCreate c) { - final JpaTagCreate create = (JpaTagCreate) c; - - return targetTagRepository.save(create.buildTargetTag()); - } - - @Override - @Transactional - @Retryable(include = { - ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) - public List createTargetTags(final Collection tt) { - @SuppressWarnings({ "unchecked", "rawtypes" }) - final Collection targetTags = (Collection) tt; - - return Collections.unmodifiableList(targetTags.stream() - .map(ttc -> targetTagRepository.save(ttc.buildTargetTag())).collect(Collectors.toList())); - } - - @Override - @Transactional - @Retryable(include = { - ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) - public void deleteTargetTag(final String targetTagName) { - if (!targetTagRepository.existsByName(targetTagName)) { - throw new EntityNotFoundException(TargetTag.class, targetTagName); - } - - // finally delete the tag itself - targetTagRepository.deleteByName(targetTagName); - } - - @Override - public Page findAllTargetTags(final String rsqlParam, final Pageable pageable) { - - final Specification spec = RSQLUtility.parse(rsqlParam, TagFields.class, virtualPropertyReplacer); - return convertTPage(targetTagRepository.findAll(spec, pageable), pageable); - } - - private static Page convertTPage(final Page findAll, final Pageable pageable) { - return new PageImpl<>(Collections.unmodifiableList(findAll.getContent()), pageable, findAll.getTotalElements()); - } - - private static Page convertDsPage(final Page findAll, - final Pageable pageable) { - return new PageImpl<>(Collections.unmodifiableList(findAll.getContent()), pageable, findAll.getTotalElements()); - } - - @Override - public long countTargetTags() { - return targetTagRepository.count(); - } - - @Override - @Transactional - @Retryable(include = { - ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) - public TargetTag updateTargetTag(final TagUpdate u) { - final GenericTagUpdate update = (GenericTagUpdate) u; - - final JpaTargetTag tag = targetTagRepository.findById(update.getId()) - .orElseThrow(() -> new EntityNotFoundException(TargetTag.class, update.getId())); - - update.getName().ifPresent(tag::setName); - update.getDescription().ifPresent(tag::setDescription); - update.getColour().ifPresent(tag::setColour); - - return targetTagRepository.save(tag); - } - - @Override - @Transactional - @Retryable(include = { - ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) - public DistributionSetTag updateDistributionSetTag(final TagUpdate u) { + public DistributionSetTag update(final TagUpdate u) { final GenericTagUpdate update = (GenericTagUpdate) u; final JpaDistributionSetTag tag = distributionSetTagRepository.findById(update.getId()) @@ -161,7 +83,7 @@ public class JpaTagManagement implements TagManagement { } @Override - public Optional findDistributionSetTag(final String name) { + public Optional getByName(final String name) { return distributionSetTagRepository.findByNameEquals(name); } @@ -169,7 +91,7 @@ public class JpaTagManagement implements TagManagement { @Transactional @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) - public DistributionSetTag createDistributionSetTag(final TagCreate c) { + public DistributionSetTag create(final TagCreate c) { final JpaTagCreate create = (JpaTagCreate) c; return distributionSetTagRepository.save(create.buildDistributionSetTag()); } @@ -178,7 +100,7 @@ public class JpaTagManagement implements TagManagement { @Transactional @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) - public List createDistributionSetTags(final Collection dst) { + public List create(final Collection dst) { @SuppressWarnings({ "rawtypes", "unchecked" }) final Collection creates = (Collection) dst; @@ -192,7 +114,7 @@ public class JpaTagManagement implements TagManagement { @Transactional @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) - public void deleteDistributionSetTag(final String tagName) { + public void delete(final String tagName) { if (!distributionSetTagRepository.existsByName(tagName)) { throw new EntityNotFoundException(DistributionSetTag.class, tagName); } @@ -201,27 +123,12 @@ public class JpaTagManagement implements TagManagement { } @Override - public Optional findTargetTagById(final Long id) { - return Optional.ofNullable(targetTagRepository.findOne(id)); + public Slice findAll(final Pageable pageable) { + return convertDsPage(criteriaNoCountDao.findAll(pageable, JpaDistributionSetTag.class), pageable); } @Override - public Optional findDistributionSetTagById(final Long id) { - return Optional.ofNullable(distributionSetTagRepository.findOne(id)); - } - - @Override - public Page findAllTargetTags(final Pageable pageable) { - return convertTPage(targetTagRepository.findAll(pageable), pageable); - } - - @Override - public Page findAllDistributionSetTags(final Pageable pageable) { - return convertDsPage(distributionSetTagRepository.findAll(pageable), pageable); - } - - @Override - public Page findAllDistributionSetTags(final String rsqlParam, final Pageable pageable) { + public Page findByRsql(final Pageable pageable, final String rsqlParam) { final Specification spec = RSQLUtility.parse(rsqlParam, TagFields.class, virtualPropertyReplacer); @@ -229,17 +136,7 @@ public class JpaTagManagement implements TagManagement { } @Override - public Page findAllTargetTags(final Pageable pageable, final String controllerId) { - if (!targetRepository.existsByControllerId(controllerId)) { - throw new EntityNotFoundException(Target.class, controllerId); - } - - return convertTPage(targetTagRepository.findAll(TagSpecification.ofTarget(controllerId), pageable), pageable); - } - - @Override - public Page findDistributionSetTagsByDistributionSet(final Pageable pageable, - final Long setId) { + public Page findByDistributionSet(final Pageable pageable, final Long setId) { if (!distributionSetRepository.exists(setId)) { throw new EntityNotFoundException(DistributionSet.class, setId); } @@ -247,4 +144,58 @@ public class JpaTagManagement implements TagManagement { return convertDsPage(distributionSetTagRepository.findAll(TagSpecification.ofDistributionSet(setId), pageable), pageable); } + + private static Page convertDsPage(final Page findAll, + final Pageable pageable) { + return new PageImpl<>(Collections.unmodifiableList(findAll.getContent()), pageable, findAll.getTotalElements()); + } + + private static Slice convertDsPage(final Slice findAll, + final Pageable pageable) { + return new PageImpl<>(Collections.unmodifiableList(findAll.getContent()), pageable, 0); + } + + @Override + @Transactional + @Retryable(include = { + ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) + public void delete(final Collection ids) { + final List setsFound = distributionSetTagRepository.findAll(ids); + + if (setsFound.size() < ids.size()) { + throw new EntityNotFoundException(DistributionSetTag.class, ids, + setsFound.stream().map(DistributionSetTag::getId).collect(Collectors.toList())); + } + + distributionSetTagRepository.delete(setsFound); + } + + @Override + public List get(final Collection ids) { + return Collections.unmodifiableList(distributionSetTagRepository.findAll(ids)); + } + + @Override + public Optional get(final Long id) { + return Optional.ofNullable(distributionSetTagRepository.findOne(id)); + } + + @Override + @Transactional + @Retryable(include = { + ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) + public void delete(final Long id) { + distributionSetTagRepository.delete(id); + } + + @Override + public boolean exists(final Long id) { + return distributionSetTagRepository.exists(id); + } + + @Override + public long count() { + return distributionSetTagRepository.count(); + } + } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetTypeManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetTypeManagement.java index e886006d8..f8b1040e6 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetTypeManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetTypeManagement.java @@ -8,6 +8,7 @@ */ package org.eclipse.hawkbit.repository.jpa; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.List; @@ -27,6 +28,7 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType; import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType; import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility; import org.eclipse.hawkbit.repository.jpa.specifications.DistributionSetTypeSpecification; +import org.eclipse.hawkbit.repository.jpa.specifications.SpecificationsBuilder; import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer; @@ -34,10 +36,12 @@ import org.springframework.dao.ConcurrencyFailureException; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; import org.springframework.data.jpa.domain.Specification; import org.springframework.retry.annotation.Backoff; import org.springframework.retry.annotation.Retryable; import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; import org.springframework.validation.annotation.Validated; /** @@ -56,21 +60,24 @@ public class JpaDistributionSetTypeManagement implements DistributionSetTypeMana private final VirtualPropertyReplacer virtualPropertyReplacer; + private final NoCountPagingRepository criteriaNoCountDao; + JpaDistributionSetTypeManagement(final DistributionSetTypeRepository distributionSetTypeRepository, final SoftwareModuleTypeRepository softwareModuleTypeRepository, final DistributionSetRepository distributionSetRepository, - final VirtualPropertyReplacer virtualPropertyReplacer) { + final VirtualPropertyReplacer virtualPropertyReplacer, final NoCountPagingRepository criteriaNoCountDao) { this.distributionSetTypeRepository = distributionSetTypeRepository; this.softwareModuleTypeRepository = softwareModuleTypeRepository; this.distributionSetRepository = distributionSetRepository; this.virtualPropertyReplacer = virtualPropertyReplacer; + this.criteriaNoCountDao = criteriaNoCountDao; } @Override @Transactional @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) - public DistributionSetType updateDistributionSetType(final DistributionSetTypeUpdate u) { + public DistributionSetType update(final DistributionSetTypeUpdate u) { final GenericDistributionSetTypeUpdate update = (GenericDistributionSetTypeUpdate) u; final JpaDistributionSetType type = findDistributionSetTypeAndThrowExceptionIfNotFound(update.getId()); @@ -82,9 +89,9 @@ public class JpaDistributionSetTypeManagement implements DistributionSetTypeMana checkDistributionSetTypeSoftwareModuleTypesIsAllowedToModify(update.getId()); update.getMandatory().ifPresent( - mand -> softwareModuleTypeRepository.findByIdIn(mand).forEach(type::addMandatoryModuleType)); - update.getOptional().ifPresent( - opt -> softwareModuleTypeRepository.findByIdIn(opt).forEach(type::addOptionalModuleType)); + mand -> softwareModuleTypeRepository.findAll(mand).forEach(type::addMandatoryModuleType)); + update.getOptional() + .ifPresent(opt -> softwareModuleTypeRepository.findAll(opt).forEach(type::addOptionalModuleType)); } return distributionSetTypeRepository.save(type); @@ -96,8 +103,7 @@ public class JpaDistributionSetTypeManagement implements DistributionSetTypeMana ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) public DistributionSetType assignMandatorySoftwareModuleTypes(final Long dsTypeId, final Collection softwareModulesTypeIds) { - final Collection modules = softwareModuleTypeRepository - .findByIdIn(softwareModulesTypeIds); + final Collection modules = softwareModuleTypeRepository.findAll(softwareModulesTypeIds); if (modules.size() < softwareModulesTypeIds.size()) { throw new EntityNotFoundException(SoftwareModuleType.class, softwareModulesTypeIds, @@ -119,8 +125,7 @@ public class JpaDistributionSetTypeManagement implements DistributionSetTypeMana public DistributionSetType assignOptionalSoftwareModuleTypes(final Long dsTypeId, final Collection softwareModulesTypeIds) { - final Collection modules = softwareModuleTypeRepository - .findByIdIn(softwareModulesTypeIds); + final Collection modules = softwareModuleTypeRepository.findAll(softwareModulesTypeIds); if (modules.size() < softwareModulesTypeIds.size()) { throw new EntityNotFoundException(SoftwareModuleType.class, softwareModulesTypeIds, @@ -149,37 +154,32 @@ public class JpaDistributionSetTypeManagement implements DistributionSetTypeMana } @Override - public Page findDistributionSetTypesAll(final String rsqlParam, final Pageable pageable) { - final Specification spec = RSQLUtility.parse(rsqlParam, DistributionSetTypeFields.class, - virtualPropertyReplacer); - - return convertDsTPage(distributionSetTypeRepository.findAll(spec, pageable)); + public Page findByRsql(final Pageable pageable, final String rsqlParam) { + return convertPage(findByCriteriaAPI(pageable, + Arrays.asList(RSQLUtility.parse(rsqlParam, DistributionSetTypeFields.class, virtualPropertyReplacer), + DistributionSetTypeSpecification.isDeleted(false))), + pageable); } @Override - public Page findDistributionSetTypesAll(final Pageable pageable) { - return convertDsTPage(distributionSetTypeRepository.findByDeleted(pageable, false)); + public Slice findAll(final Pageable pageable) { + return convertPage(criteriaNoCountDao.findAll(DistributionSetTypeSpecification.isDeleted(false), pageable, + JpaDistributionSetType.class), pageable); } @Override - public Long countDistributionSetTypesAll() { + public long count() { return distributionSetTypeRepository.countByDeleted(false); } @Override - public Optional findDistributionSetTypeByName(final String name) { + public Optional getByName(final String name) { return Optional .ofNullable(distributionSetTypeRepository.findOne(DistributionSetTypeSpecification.byName(name))); } @Override - public Optional findDistributionSetTypeById(final Long typeId) { - return Optional - .ofNullable(distributionSetTypeRepository.findOne(DistributionSetTypeSpecification.byId(typeId))); - } - - @Override - public Optional findDistributionSetTypeByKey(final String key) { + public Optional getByKey(final String key) { return Optional.ofNullable(distributionSetTypeRepository.findOne(DistributionSetTypeSpecification.byKey(key))); } @@ -187,7 +187,7 @@ public class JpaDistributionSetTypeManagement implements DistributionSetTypeMana @Transactional @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) - public DistributionSetType createDistributionSetType(final DistributionSetTypeCreate c) { + public DistributionSetType create(final DistributionSetTypeCreate c) { final JpaDistributionSetTypeCreate create = (JpaDistributionSetTypeCreate) c; return distributionSetTypeRepository.save(create.build()); @@ -197,7 +197,7 @@ public class JpaDistributionSetTypeManagement implements DistributionSetTypeMana @Transactional @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) - public void deleteDistributionSetType(final Long typeId) { + public void delete(final Long typeId) { final JpaDistributionSetType toDelete = distributionSetTypeRepository.findById(typeId) .orElseThrow(() -> new EntityNotFoundException(DistributionSetType.class, typeId)); @@ -214,21 +214,12 @@ public class JpaDistributionSetTypeManagement implements DistributionSetTypeMana @Transactional @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) - public List createDistributionSetTypes(final Collection types) { - return types.stream().map(this::createDistributionSetType).collect(Collectors.toList()); - } - - @Override - public Long countDistributionSetsByType(final Long typeId) { - if (!distributionSetTypeRepository.exists(typeId)) { - throw new EntityNotFoundException(DistributionSetType.class, typeId); - } - - return distributionSetRepository.countByTypeId(typeId); + public List create(final Collection types) { + return types.stream().map(this::create).collect(Collectors.toList()); } private JpaDistributionSetType findDistributionSetTypeAndThrowExceptionIfNotFound(final Long setId) { - return (JpaDistributionSetType) findDistributionSetTypeById(setId) + return (JpaDistributionSetType) get(setId) .orElseThrow(() -> new EntityNotFoundException(DistributionSetType.class, setId)); } @@ -243,8 +234,54 @@ public class JpaDistributionSetTypeManagement implements DistributionSetTypeMana } } - private static Page convertDsTPage(final Page findAll) { - return new PageImpl<>(Collections.unmodifiableList(findAll.getContent())); + private static Page convertPage(final Page findAll, + final Pageable pageable) { + return new PageImpl<>(Collections.unmodifiableList(findAll.getContent()), pageable, findAll.getTotalElements()); + } + + private static Slice convertPage(final Slice findAll, + final Pageable pageable) { + return new PageImpl<>(Collections.unmodifiableList(findAll.getContent()), pageable, 0); + } + + private Page findByCriteriaAPI(final Pageable pageable, + final List> specList) { + + if (CollectionUtils.isEmpty(specList)) { + return distributionSetTypeRepository.findAll(pageable); + } + + return distributionSetTypeRepository.findAll(SpecificationsBuilder.combineWithAnd(specList), pageable); + } + + @Override + @Transactional + @Retryable(include = { + ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) + public void delete(final Collection ids) { + final List setsFound = distributionSetTypeRepository.findAll(ids); + + if (setsFound.size() < ids.size()) { + throw new EntityNotFoundException(DistributionSetType.class, ids, + setsFound.stream().map(DistributionSetType::getId).collect(Collectors.toList())); + } + + distributionSetTypeRepository.delete(setsFound); + } + + @Override + public List get(final Collection ids) { + return Collections.unmodifiableList(distributionSetTypeRepository.findAll(ids)); + } + + @Override + public Optional get(final Long id) { + return Optional.ofNullable(distributionSetTypeRepository.findOne(id)); + } + + @Override + public boolean exists(final Long id) { + return distributionSetTypeRepository.exists(id); } } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutGroupManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutGroupManagement.java index 961c91de2..d580b7c45 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutGroupManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutGroupManagement.java @@ -85,12 +85,12 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement { private RolloutStatusCache rolloutStatusCache; @Override - public Optional findRolloutGroupById(final Long rolloutGroupId) { + public Optional get(final Long rolloutGroupId) { return Optional.ofNullable(rolloutGroupRepository.findOne(rolloutGroupId)); } @Override - public Page findRolloutGroupsByRolloutId(final Long rolloutId, final Pageable pageable) { + public Page findByRollout(final Pageable pageable, final Long rolloutId) { throwEntityNotFoundExceptionIfRolloutDoesNotExist(rolloutId); return convertPage(rolloutGroupRepository.findByRolloutId(rolloutId, pageable), pageable); @@ -105,8 +105,8 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement { } @Override - public Page findRolloutGroupsAll(final Long rolloutId, final String rsqlParam, - final Pageable pageable) { + public Page findByRolloutAndRsql(final Pageable pageable, final Long rolloutId, + final String rsqlParam) { throwEntityNotFoundExceptionIfRolloutDoesNotExist(rolloutId); final Specification specification = RSQLUtility.parse(rsqlParam, RolloutGroupFields.class, @@ -130,7 +130,7 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement { } @Override - public Page findAllRolloutGroupsWithDetailedStatus(final Long rolloutId, final Pageable pageable) { + public Page findByRolloutWithDetailedStatus(final Pageable pageable, final Long rolloutId) { throwEntityNotFoundExceptionIfRolloutDoesNotExist(rolloutId); final Page rolloutGroups = rolloutGroupRepository.findByRolloutId(rolloutId, pageable); @@ -155,8 +155,8 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement { } @Override - public Optional findRolloutGroupWithDetailedStatus(final Long rolloutGroupId) { - final Optional rolloutGroup = findRolloutGroupById(rolloutGroupId); + public Optional getWithDetailedStatus(final Long rolloutGroupId) { + final Optional rolloutGroup = get(rolloutGroupId); if (!rolloutGroup.isPresent()) { return rolloutGroup; @@ -201,8 +201,8 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement { } @Override - public Page findRolloutGroupTargets(final Long rolloutGroupId, final String rsqlParam, - final Pageable pageable) { + public Page findTargetsOfRolloutGroupByRsql(final Pageable pageable, final Long rolloutGroupId, + final String rsqlParam) { throwExceptionIfRolloutGroupDoesNotExist(rolloutGroupId); @@ -219,7 +219,7 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement { } @Override - public Page findRolloutGroupTargets(final Long rolloutGroupId, final Pageable page) { + public Page findTargetsOfRolloutGroup(final Pageable page, final Long rolloutGroupId) { final JpaRolloutGroup rolloutGroup = rolloutGroupRepository.findById(rolloutGroupId) .orElseThrow(() -> new EntityNotFoundException(RolloutGroup.class, rolloutGroupId)); @@ -237,7 +237,7 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement { } @Override - public Page findAllTargetsWithActionStatus(final Pageable pageRequest, + public Page findAllTargetsOfRolloutGroupWithActionStatus(final Pageable pageRequest, final Long rolloutGroupId) { throwExceptionIfRolloutGroupDoesNotExist(rolloutGroupId); @@ -269,7 +269,7 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement { } @Override - public Long countTargetsOfRolloutsGroup(@NotNull final Long rolloutGroupId) { + public long countTargetsOfRolloutsGroup(@NotNull final Long rolloutGroupId) { throwExceptionIfRolloutGroupDoesNotExist(rolloutGroupId); final CriteriaBuilder cb = entityManager.getCriteriaBuilder(); @@ -287,7 +287,7 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement { } @Override - public long countRolloutGroupsByRolloutId(final Long rolloutId) { + public long countByRollout(final Long rolloutId) { throwEntityNotFoundExceptionIfRolloutDoesNotExist(rolloutId); return rolloutGroupRepository.countByRolloutId(rolloutId); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java index 6a7cbd9d9..7996656f6 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java @@ -165,7 +165,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement { } @Override - public Page findAllByPredicate(final String rsqlParam, final Pageable pageable, final boolean deleted) { + public Page findByRsql(final Pageable pageable, final String rsqlParam, final boolean deleted) { final List> specList = Lists.newArrayListWithExpectedSize(2); specList.add(RSQLUtility.parse(rsqlParam, RolloutFields.class, virtualPropertyReplacer)); specList.add(RolloutSpecification.isDeletedWithDistributionSet(deleted)); @@ -186,7 +186,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement { } @Override - public Optional findRolloutById(final Long rolloutId) { + public Optional get(final Long rolloutId) { return Optional.ofNullable(rolloutRepository.findOne(rolloutId)); } @@ -194,8 +194,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement { @Transactional @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) - public Rollout createRollout(final RolloutCreate rollout, final int amountGroup, - final RolloutGroupConditions conditions) { + public Rollout create(final RolloutCreate rollout, final int amountGroup, final RolloutGroupConditions conditions) { RolloutHelper.verifyRolloutGroupParameter(amountGroup, quotaManagement); final JpaRollout savedRollout = createRollout((JpaRollout) rollout.build()); return createRolloutGroups(amountGroup, conditions, savedRollout); @@ -205,7 +204,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement { @Transactional @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) - public Rollout createRollout(final RolloutCreate rollout, final List groups, + public Rollout create(final RolloutCreate rollout, final List groups, final RolloutGroupConditions conditions) { RolloutHelper.verifyRolloutGroupParameter(groups.size(), quotaManagement); final JpaRollout savedRollout = createRollout((JpaRollout) rollout.build()); @@ -214,7 +213,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement { private JpaRollout createRollout(final JpaRollout rollout) { - final Long totalTargets = targetManagement.countTargetByTargetFilterQuery(rollout.getTargetFilterQuery()); + final Long totalTargets = targetManagement.countByRsql(rollout.getTargetFilterQuery()); if (totalTargets == 0) { throw new ValidationException("Rollout does not match any existing targets"); } @@ -320,9 +319,9 @@ public class JpaRolloutManagement extends AbstractRolloutManagement { private void handleCreateRollout(final JpaRollout rollout) { LOGGER.debug("handleCreateRollout called for rollout {}", rollout.getId()); - final List rolloutGroups = rolloutGroupManagement.findRolloutGroupsByRolloutId(rollout.getId(), - new PageRequest(0, quotaManagement.getMaxRolloutGroupsPerRollout(), new Sort(Direction.ASC, "id"))) - .getContent(); + final List rolloutGroups = rolloutGroupManagement.findByRollout( + new PageRequest(0, quotaManagement.getMaxRolloutGroupsPerRollout(), new Sort(Direction.ASC, "id")), + rollout.getId()).getContent(); int readyGroups = 0; int totalTargets = 0; @@ -368,7 +367,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement { RolloutGroupStatus.READY, group); final long targetsInGroupFilter = runInNewTransaction("countAllTargetsByTargetFilterQueryAndNotInRolloutGroups", - count -> targetManagement.countAllTargetsByTargetFilterQueryAndNotInRolloutGroups(readyGroups, + count -> targetManagement.countByRsqlAndNotInRolloutGroups(readyGroups, groupTargetFilter)); final long expectedInGroup = Math.round(group.getTargetPercentage() / 100 * (double) targetsInGroupFilter); final long currentlyInGroup = runInNewTransaction("countRolloutTargetGroupByRolloutGroup", @@ -410,7 +409,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement { final List readyGroups = RolloutHelper.getGroupsByStatusIncludingGroup(rollout.getRolloutGroups(), RolloutGroupStatus.READY, group); final Page targets = targetManagement - .findAllTargetsByTargetFilterQueryAndNotInRolloutGroups(pageRequest, readyGroups, targetFilter); + .findByTargetFilterQueryAndNotInRolloutGroups(pageRequest, readyGroups, targetFilter); createAssignmentOfTargetsToGroup(targets, group); @@ -428,7 +427,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement { final String targetFilter, final Long createdAt) { final String baseFilter = RolloutHelper.getTargetFilterQuery(targetFilter, createdAt); - final long totalTargets = targetManagement.countTargetByTargetFilterQuery(baseFilter); + final long totalTargets = targetManagement.countByRsql(baseFilter); if (totalTargets == 0) { throw new ConstraintDeclarationException("Rollout target filter does not match any targets"); } @@ -441,7 +440,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement { @Transactional @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) - public Rollout startRollout(final Long rolloutId) { + public Rollout start(final Long rolloutId) { LOGGER.debug("startRollout called for rollout {}", rolloutId); final JpaRollout rollout = getRolloutAndThrowExceptionIfNotFound(rolloutId); @@ -531,7 +530,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement { final ActionType actionType = rollout.getActionType(); final long forceTime = rollout.getForcedTime(); - final Page targets = targetManagement.findAllTargetsInRolloutGroupWithoutAction(pageRequest, + final Page targets = targetManagement.findByInRolloutGroupWithoutAction(pageRequest, groupId); if (targets.getTotalElements() > 0) { createScheduledAction(targets.getContent(), distributionSet, actionType, forceTime, rollout, group); @@ -812,7 +811,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement { LOGGER.debug( "handleReadyRollout called for rollout {} with autostart beyond define time. Switch to STARTING", rollout.getId()); - startRollout(rollout.getId()); + start(rollout.getId()); } } @@ -820,7 +819,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement { @Transactional @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) - public void deleteRollout(final long rolloutId) { + public void delete(final Long rolloutId) { final JpaRollout jpaRollout = rolloutRepository.findOne(rolloutId); if (jpaRollout == null) { @@ -915,17 +914,17 @@ public class JpaRolloutManagement extends AbstractRolloutManagement { } @Override - public Long countRolloutsAll() { + public long count() { return rolloutRepository.count(RolloutSpecification.isDeletedWithDistributionSet(false)); } @Override - public Long countRolloutsAllByFilters(final String searchText) { + public long countByFilters(final String searchText) { return rolloutRepository.count(JpaRolloutHelper.likeNameOrDescription(searchText, false)); } @Override - public Slice findRolloutWithDetailedStatusByFilters(final Pageable pageable, final String searchText, + public Slice findByFiltersWithDetailedStatus(final Pageable pageable, final String searchText, final boolean deleted) { final Slice findAll = findByCriteriaAPI(pageable, Arrays.asList(JpaRolloutHelper.likeNameOrDescription(searchText, deleted))); @@ -934,7 +933,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement { } @Override - public Optional findRolloutByName(final String rolloutName) { + public Optional getByName(final String rolloutName) { return rolloutRepository.findByName(rolloutName); } @@ -942,7 +941,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement { @Transactional @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) - public Rollout updateRollout(final RolloutUpdate u) { + public Rollout update(final RolloutUpdate u) { final GenericRolloutUpdate update = (GenericRolloutUpdate) u; final JpaRollout rollout = getRolloutAndThrowExceptionIfNotFound(update.getId()); @@ -954,7 +953,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement { update.getForcedTime().ifPresent(rollout::setForcedTime); update.getStartAt().ifPresent(rollout::setStartAt); update.getSet().ifPresent(setId -> { - final DistributionSet set = distributionSetManagement.findDistributionSetById(setId) + final DistributionSet set = distributionSetManagement.get(setId) .orElseThrow(() -> new EntityNotFoundException(DistributionSet.class, setId)); rollout.setDistributionSet(set); @@ -975,7 +974,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement { } @Override - public Page findAllRolloutsWithDetailedStatus(final Pageable pageable, final boolean deleted) { + public Page findAllWithDetailedStatus(final Pageable pageable, final boolean deleted) { Page rollouts; final Specification spec = RolloutSpecification.isDeletedWithDistributionSet(deleted); rollouts = rolloutRepository.findAll(spec, pageable); @@ -984,8 +983,8 @@ public class JpaRolloutManagement extends AbstractRolloutManagement { } @Override - public Optional findRolloutWithDetailedStatus(final Long rolloutId) { - final Optional rollout = findRolloutById(rolloutId); + public Optional getWithDetailedStatus(final Long rolloutId) { + final Optional rollout = get(rolloutId); if (!rollout.isPresent()) { return rollout; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareModuleManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareModuleManagement.java index 4e3e3598a..c06c8f244 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareModuleManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareModuleManagement.java @@ -113,7 +113,7 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement { @Transactional @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) - public SoftwareModule updateSoftwareModule(final SoftwareModuleUpdate u) { + public SoftwareModule update(final SoftwareModuleUpdate u) { final GenericSoftwareModuleUpdate update = (GenericSoftwareModuleUpdate) u; final JpaSoftwareModule module = softwareModuleRepository.findById(update.getId()) @@ -129,7 +129,7 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement { @Transactional @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) - public SoftwareModule createSoftwareModule(final SoftwareModuleCreate c) { + public SoftwareModule create(final SoftwareModuleCreate c) { final JpaSoftwareModuleCreate create = (JpaSoftwareModuleCreate) c; return softwareModuleRepository.save(create.build()); @@ -139,12 +139,12 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement { @Transactional @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) - public List createSoftwareModule(final Collection swModules) { - return swModules.stream().map(this::createSoftwareModule).collect(Collectors.toList()); + public List create(final Collection swModules) { + return swModules.stream().map(this::create).collect(Collectors.toList()); } @Override - public Slice findSoftwareModulesByType(final Pageable pageable, final Long typeId) { + public Slice findByType(final Pageable pageable, final Long typeId) { throwExceptionIfSoftwareModuleTypeDoesNotExist(typeId); final List> specList = Lists.newArrayListWithExpectedSize(2); @@ -152,7 +152,7 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement { specList.add(SoftwareModuleSpecification.equalType(typeId)); specList.add(SoftwareModuleSpecification.isDeletedFalse()); - return convertSmPage(findSwModuleByCriteriaAPI(pageable, specList), pageable); + return convertSmPage(findByCriteriaAPI(pageable, specList), pageable); } private void throwExceptionIfSoftwareModuleTypeDoesNotExist(final Long typeId) { @@ -176,12 +176,12 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement { } @Override - public Optional findSoftwareModuleById(final Long id) { + public Optional get(final Long id) { return Optional.ofNullable(softwareModuleRepository.findOne(id)); } @Override - public Optional findSoftwareModuleByNameAndVersion(final String name, final String version, + public Optional getByNameAndVersionAndType(final String name, final String version, final Long typeId) { throwExceptionIfSoftwareModuleTypeDoesNotExist(typeId); @@ -193,7 +193,7 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement { return distributionSetRepository.countByModulesId(moduleId) <= 0; } - private Slice findSwModuleByCriteriaAPI(final Pageable pageable, + private Slice findByCriteriaAPI(final Pageable pageable, final List> specList) { return criteriaNoCountDao.findAll(SpecificationsBuilder.combineWithAnd(specList), pageable, JpaSoftwareModule.class); @@ -213,7 +213,7 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement { @Transactional @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) - public void deleteSoftwareModules(final Collection ids) { + public void delete(final Collection ids) { final List swModulesToDelete = softwareModuleRepository.findByIdIn(ids); if (swModulesToDelete.size() < ids.size()) { @@ -245,7 +245,7 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement { } @Override - public Slice findSoftwareModulesAll(final Pageable pageable) { + public Slice findAll(final Pageable pageable) { final List> specList = new ArrayList<>(2); @@ -261,18 +261,18 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement { specList.add(spec); - return convertSmPage(findSwModuleByCriteriaAPI(pageable, specList), pageable); + return convertSmPage(findByCriteriaAPI(pageable, specList), pageable); } @Override - public Long countSoftwareModulesAll() { + public long count() { final Specification spec = SoftwareModuleSpecification.isDeletedFalse(); return countSwModuleByCriteriaAPI(Arrays.asList(spec)); } @Override - public Page findSoftwareModulesByPredicate(final String rsqlParam, final Pageable pageable) { + public Page findByRsql(final Pageable pageable, final String rsqlParam) { final Specification spec = RSQLUtility.parse(rsqlParam, SoftwareModuleFields.class, virtualPropertyReplacer); @@ -281,12 +281,12 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement { @Override @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - public List findSoftwareModulesById(final Collection ids) { + public List get(final Collection ids) { return Collections.unmodifiableList(softwareModuleRepository.findByIdIn(ids)); } @Override - public Slice findSoftwareModuleByFilters(final Pageable pageable, final String searchText, + public Slice findByTextAndType(final Pageable pageable, final String searchText, final Long typeId) { final List> specList = new ArrayList<>(4); @@ -315,11 +315,11 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement { specList.add(spec); - return convertSmPage(findSwModuleByCriteriaAPI(pageable, specList), pageable); + return convertSmPage(findByCriteriaAPI(pageable, specList), pageable); } @Override - public Slice findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc( + public Slice findAllOrderBySetAssignmentAndModuleNameAscModuleVersionAsc( final Pageable pageable, final Long orderByDistributionId, final String searchText, final Long typeId) { final List resultList = new ArrayList<>(); @@ -408,7 +408,7 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement { } @Override - public Long countSoftwareModuleByFilters(final String searchText, final Long typeId) { + public long countByTextAndType(final String searchText, final Long typeId) { final List> specList = new ArrayList<>(3); @@ -431,7 +431,7 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement { } @Override - public Page findSoftwareModuleByAssignedTo(final Pageable pageable, final Long setId) { + public Page findByAssignedTo(final Pageable pageable, final Long setId) { if (!distributionSetRepository.exists(setId)) { throw new EntityNotFoundException(DistributionSet.class, setId); } @@ -443,7 +443,7 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement { @Transactional @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) - public SoftwareModuleMetadata createSoftwareModuleMetadata(final Long moduleId, final MetaData md) { + public SoftwareModuleMetadata createMetaData(final Long moduleId, final MetaData md) { checkAndThrowAlreadyIfSoftwareModuleMetadataExists(moduleId, md); @@ -461,8 +461,7 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement { @Transactional @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) - public List createSoftwareModuleMetadata(final Long moduleId, - final Collection md) { + public List createMetaData(final Long moduleId, final Collection md) { md.forEach(meta -> checkAndThrowAlreadyIfSoftwareModuleMetadataExists(moduleId, meta)); final JpaSoftwareModule module = touch(moduleId); @@ -477,10 +476,10 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement { @Transactional @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) - public SoftwareModuleMetadata updateSoftwareModuleMetadata(final Long moduleId, final MetaData md) { + public SoftwareModuleMetadata updateMetaData(final Long moduleId, final MetaData md) { // check if exists otherwise throw entity not found exception - final JpaSoftwareModuleMetadata metadata = (JpaSoftwareModuleMetadata) findSoftwareModuleMetadata(moduleId, + final JpaSoftwareModuleMetadata metadata = (JpaSoftwareModuleMetadata) getMetaDataBySoftwareModuleId(moduleId, md.getKey()).orElseThrow( () -> new EntityNotFoundException(SoftwareModuleMetadata.class, moduleId, md.getKey())); metadata.setValue(md.getValue()); @@ -515,30 +514,21 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement { * of the module to touch */ private JpaSoftwareModule touch(final Long moduleId) { - return touch(findSoftwareModuleById(moduleId) - .orElseThrow(() -> new EntityNotFoundException(SoftwareModule.class, moduleId))); + return touch(get(moduleId).orElseThrow(() -> new EntityNotFoundException(SoftwareModule.class, moduleId))); } @Override @Transactional @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) - public void deleteSoftwareModuleMetadata(final Long moduleId, final String key) { - final JpaSoftwareModuleMetadata metadata = (JpaSoftwareModuleMetadata) findSoftwareModuleMetadata(moduleId, key) - .orElseThrow(() -> new EntityNotFoundException(SoftwareModuleMetadata.class, moduleId, key)); + public void deleteMetaData(final Long moduleId, final String key) { + final JpaSoftwareModuleMetadata metadata = (JpaSoftwareModuleMetadata) getMetaDataBySoftwareModuleId(moduleId, + key).orElseThrow(() -> new EntityNotFoundException(SoftwareModuleMetadata.class, moduleId, key)); touch(metadata.getSoftwareModule()); softwareModuleMetadataRepository.delete(metadata.getId()); } - @Override - public Page findSoftwareModuleMetadataBySoftwareModuleId(final Long swId, - final Pageable pageable) { - throwExceptionIfSoftwareModuleDoesNotExist(swId); - - return softwareModuleMetadataRepository.findBySoftwareModuleId(swId, pageable); - } - private void throwExceptionIfSoftwareModuleDoesNotExist(final Long swId) { if (!softwareModuleRepository.exists(swId)) { throw new EntityNotFoundException(SoftwareModule.class, swId); @@ -546,8 +536,8 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement { } @Override - public Page findSoftwareModuleMetadataBySoftwareModuleId(final Long softwareModuleId, - final String rsqlParam, final Pageable pageable) { + public Page findMetaDataByRsql(final Pageable pageable, final Long softwareModuleId, + final String rsqlParam) { throwExceptionIfSoftwareModuleDoesNotExist(softwareModuleId); @@ -564,18 +554,23 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement { pageable); } - @Override - public Page findSoftwareModuleMetadataBySoftwareModuleId(final Pageable pageable, - final Long softwareModuleId) { - throwExceptionIfSoftwareModuleDoesNotExist(softwareModuleId); + private static Page convertMdPage(final Page findAll, + final Pageable pageable) { + return new PageImpl<>(Collections.unmodifiableList(findAll.getContent()), pageable, findAll.getTotalElements()); + } - return convertSmMdPage(softwareModuleMetadataRepository.findAll((root, query, cb) -> cb.equal( - root.get(JpaSoftwareModuleMetadata_.softwareModule).get(JpaSoftwareModule_.id), softwareModuleId), + @Override + public Page findMetaDataBySoftwareModuleId(final Pageable pageable, final Long swId) { + throwExceptionIfSoftwareModuleDoesNotExist(swId); + + return convertMdPage(softwareModuleMetadataRepository.findAll( + (Specification) (root, query, cb) -> cb + .equal(root.get(JpaSoftwareModuleMetadata_.softwareModule).get(JpaSoftwareModule_.id), swId), pageable), pageable); } @Override - public Optional findSoftwareModuleMetadata(final Long moduleId, final String key) { + public Optional getMetaDataBySoftwareModuleId(final Long moduleId, final String key) { throwExceptionIfSoftwareModuleDoesNotExist(moduleId); return Optional.ofNullable(softwareModuleMetadataRepository.findOne(new SwMetadataCompositeKey(moduleId, key))); @@ -589,13 +584,13 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement { @Transactional @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) - public void deleteSoftwareModule(final Long moduleId) { - deleteSoftwareModules(Arrays.asList(moduleId)); + public void delete(final Long moduleId) { + delete(Arrays.asList(moduleId)); } @Override - public List findSoftwareModuleTypesById(final Collection ids) { - return Collections.unmodifiableList(softwareModuleTypeRepository.findByIdIn(ids)); + public boolean exists(final Long id) { + return softwareModuleRepository.exists(id); } } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareModuleTypeManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareModuleTypeManagement.java index 0a5709aff..bcf022371 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareModuleTypeManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareModuleTypeManagement.java @@ -23,6 +23,7 @@ import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.jpa.builder.JpaSoftwareModuleTypeCreate; import org.eclipse.hawkbit.repository.jpa.configuration.Constants; import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType; +import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType_; import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer; @@ -30,6 +31,7 @@ import org.springframework.dao.ConcurrencyFailureException; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; import org.springframework.data.jpa.domain.Specification; import org.springframework.retry.annotation.Backoff; import org.springframework.retry.annotation.Retryable; @@ -52,24 +54,27 @@ public class JpaSoftwareModuleTypeManagement implements SoftwareModuleTypeManage private final SoftwareModuleRepository softwareModuleRepository; + private final NoCountPagingRepository criteriaNoCountDao; + JpaSoftwareModuleTypeManagement(final DistributionSetTypeRepository distributionSetTypeRepository, final SoftwareModuleTypeRepository softwareModuleTypeRepository, final VirtualPropertyReplacer virtualPropertyReplacer, - final SoftwareModuleRepository softwareModuleRepository) { + final SoftwareModuleRepository softwareModuleRepository, final NoCountPagingRepository criteriaNoCountDao) { this.distributionSetTypeRepository = distributionSetTypeRepository; this.softwareModuleTypeRepository = softwareModuleTypeRepository; this.virtualPropertyReplacer = virtualPropertyReplacer; this.softwareModuleRepository = softwareModuleRepository; + this.criteriaNoCountDao = criteriaNoCountDao; } @Override @Transactional @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) - public SoftwareModuleType updateSoftwareModuleType(final SoftwareModuleTypeUpdate u) { + public SoftwareModuleType update(final SoftwareModuleTypeUpdate u) { final GenericSoftwareModuleTypeUpdate update = (GenericSoftwareModuleTypeUpdate) u; - final JpaSoftwareModuleType type = (JpaSoftwareModuleType) findSoftwareModuleTypeById(update.getId()) + final JpaSoftwareModuleType type = (JpaSoftwareModuleType) get(update.getId()) .orElseThrow(() -> new EntityNotFoundException(SoftwareModuleType.class, update.getId())); update.getDescription().ifPresent(type::setDescription); @@ -79,36 +84,33 @@ public class JpaSoftwareModuleTypeManagement implements SoftwareModuleTypeManage } @Override - public Page findSoftwareModuleTypesAll(final String rsqlParam, final Pageable pageable) { + public Page findByRsql(final Pageable pageable, final String rsqlParam) { final Specification spec = RSQLUtility.parse(rsqlParam, SoftwareModuleTypeFields.class, virtualPropertyReplacer); - return convertSmTPage(softwareModuleTypeRepository.findAll(spec, pageable), pageable); + return convertPage(softwareModuleTypeRepository.findAll(spec, pageable), pageable); } @Override - public Page findSoftwareModuleTypesAll(final Pageable pageable) { - return softwareModuleTypeRepository.findByDeleted(pageable, false); + public Slice findAll(final Pageable pageable) { + return convertPage(criteriaNoCountDao.findAll( + (targetRoot, query, cb) -> cb.equal(targetRoot. get(JpaSoftwareModuleType_.deleted), false), + pageable, JpaSoftwareModuleType.class), pageable); } @Override - public Long countSoftwareModuleTypesAll() { + public long count() { return softwareModuleTypeRepository.countByDeleted(false); } @Override - public Optional findSoftwareModuleTypeByKey(final String key) { + public Optional getByKey(final String key) { return softwareModuleTypeRepository.findByKey(key); } @Override - public Optional findSoftwareModuleTypeById(final Long smTypeId) { - return Optional.ofNullable(softwareModuleTypeRepository.findOne(smTypeId)); - } - - @Override - public Optional findSoftwareModuleTypeByName(final String name) { + public Optional getByName(final String name) { return softwareModuleTypeRepository.findByName(name); } @@ -116,7 +118,7 @@ public class JpaSoftwareModuleTypeManagement implements SoftwareModuleTypeManage @Transactional @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) - public SoftwareModuleType createSoftwareModuleType(final SoftwareModuleTypeCreate c) { + public SoftwareModuleType create(final SoftwareModuleTypeCreate c) { final JpaSoftwareModuleTypeCreate create = (JpaSoftwareModuleTypeCreate) c; return softwareModuleTypeRepository.save(create.build()); @@ -126,7 +128,7 @@ public class JpaSoftwareModuleTypeManagement implements SoftwareModuleTypeManage @Transactional @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) - public void deleteSoftwareModuleType(final Long typeId) { + public void delete(final Long typeId) { final JpaSoftwareModuleType toDelete = softwareModuleTypeRepository.findById(typeId) .orElseThrow(() -> new EntityNotFoundException(SoftwareModuleType.class, typeId)); @@ -143,13 +145,48 @@ public class JpaSoftwareModuleTypeManagement implements SoftwareModuleTypeManage @Transactional @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) - public List createSoftwareModuleType(final Collection creates) { - return creates.stream().map(this::createSoftwareModuleType).collect(Collectors.toList()); + public List create(final Collection creates) { + return creates.stream().map(this::create).collect(Collectors.toList()); } - private static Page convertSmTPage(final Page findAll, + private static Page convertPage(final Page findAll, final Pageable pageable) { return new PageImpl<>(Collections.unmodifiableList(findAll.getContent()), pageable, findAll.getTotalElements()); } + private static Slice convertPage(final Slice findAll, + final Pageable pageable) { + return new PageImpl<>(Collections.unmodifiableList(findAll.getContent()), pageable, 0); + } + + @Override + @Transactional + @Retryable(include = { + ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) + public void delete(final Collection ids) { + final List setsFound = softwareModuleTypeRepository.findAll(ids); + + if (setsFound.size() < ids.size()) { + throw new EntityNotFoundException(SoftwareModuleType.class, ids, + setsFound.stream().map(SoftwareModuleType::getId).collect(Collectors.toList())); + } + + softwareModuleTypeRepository.delete(setsFound); + } + + @Override + public List get(final Collection ids) { + return Collections.unmodifiableList(softwareModuleTypeRepository.findAll(ids)); + } + + @Override + public Optional get(final Long id) { + return Optional.ofNullable(softwareModuleTypeRepository.findOne(id)); + } + + @Override + public boolean exists(final Long id) { + return softwareModuleTypeRepository.exists(id); + } + } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetFilterQueryManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetFilterQueryManagement.java index 592d98fae..883ca63ac 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetFilterQueryManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetFilterQueryManagement.java @@ -74,7 +74,7 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme @Transactional @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) - public TargetFilterQuery createTargetFilterQuery(final TargetFilterQueryCreate c) { + public TargetFilterQuery create(final TargetFilterQueryCreate c) { final JpaTargetFilterQueryCreate create = (JpaTargetFilterQueryCreate) c; return targetFilterQueryRepository.save(create.build()); @@ -84,20 +84,20 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme @Transactional @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) - public void deleteTargetFilterQuery(final Long targetFilterQueryId) { - findTargetFilterQueryById(targetFilterQueryId) + public void delete(final Long targetFilterQueryId) { + get(targetFilterQueryId) .orElseThrow(() -> new EntityNotFoundException(TargetFilterQuery.class, targetFilterQueryId)); targetFilterQueryRepository.delete(targetFilterQueryId); } @Override - public Page findAllTargetFilterQuery(final Pageable pageable) { + public Page findAll(final Pageable pageable) { return convertPage(targetFilterQueryRepository.findAll(pageable), pageable); } @Override - public Long countAllTargetFilterQuery() { + public long count() { return targetFilterQueryRepository.count(); } @@ -107,7 +107,7 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme } @Override - public Page findTargetFilterQueryByName(final Pageable pageable, final String name) { + public Page findByName(final Pageable pageable, final String name) { List> specList = Collections.emptyList(); if (!StringUtils.isEmpty(name)) { specList = Collections.singletonList(TargetFilterQuerySpecification.likeName(name)); @@ -116,7 +116,7 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme } @Override - public Page findTargetFilterQueryByFilter(final Pageable pageable, final String rsqlFilter) { + public Page findByRsql(final Pageable pageable, final String rsqlFilter) { List> specList = Collections.emptyList(); if (!StringUtils.isEmpty(rsqlFilter)) { specList = Collections.singletonList( @@ -126,7 +126,7 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme } @Override - public Page findTargetFilterQueryByQuery(final Pageable pageable, final String query) { + public Page findByQuery(final Pageable pageable, final String query) { List> specList = Collections.emptyList(); if (!StringUtils.isEmpty(query)) { specList = Collections.singletonList(TargetFilterQuerySpecification.equalsQuery(query)); @@ -135,7 +135,7 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme } @Override - public Page findTargetFilterQueryByAutoAssignDS(final Pageable pageable, final Long setId, + public Page findByAutoAssignDSAndRsql(final Pageable pageable, final Long setId, final String rsqlFilter) { final List> specList = Lists.newArrayListWithExpectedSize(2); @@ -150,7 +150,7 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme } @Override - public Page findTargetFilterQueryWithAutoAssignDS(final Pageable pageable) { + public Page findWithAutoAssignDS(final Pageable pageable) { final List> specList = Collections .singletonList(TargetFilterQuerySpecification.withAutoAssignDS()); return convertPage(findTargetFilterQueryByCriteriaAPI(pageable, specList), pageable); @@ -167,18 +167,18 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme } @Override - public Optional findTargetFilterQueryByName(final String targetFilterQueryName) { + public Optional getByName(final String targetFilterQueryName) { return targetFilterQueryRepository.findByName(targetFilterQueryName); } @Override - public Optional findTargetFilterQueryById(final Long targetFilterQueryId) { + public Optional get(final Long targetFilterQueryId) { return Optional.ofNullable(targetFilterQueryRepository.findOne(targetFilterQueryId)); } @Override @Transactional - public TargetFilterQuery updateTargetFilterQuery(final TargetFilterQueryUpdate u) { + public TargetFilterQuery update(final TargetFilterQueryUpdate u) { final GenericTargetFilterQueryUpdate update = (GenericTargetFilterQueryUpdate) u; final JpaTargetFilterQuery targetFilterQuery = findTargetFilterQueryOrThrowExceptionIfNotFound(update.getId()); @@ -191,7 +191,7 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme @Override @Transactional - public TargetFilterQuery updateTargetFilterQueryAutoAssignDS(final Long queryId, final Long dsId) { + public TargetFilterQuery updateAutoAssignDS(final Long queryId, final Long dsId) { final JpaTargetFilterQuery targetFilterQuery = findTargetFilterQueryOrThrowExceptionIfNotFound(queryId); targetFilterQuery.setAutoAssignDistributionSet( @@ -201,7 +201,7 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme } private JpaDistributionSet findDistributionSetAndThrowExceptionIfNotFound(final Long setId) { - return (JpaDistributionSet) distributionSetManagement.findDistributionSetByIdWithDetails(setId) + return (JpaDistributionSet) distributionSetManagement.getWithDetails(setId) .orElseThrow(() -> new EntityNotFoundException(DistributionSet.class, setId)); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetManagement.java index c75deed7a..18887cbc9 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetManagement.java @@ -116,28 +116,28 @@ public class JpaTargetManagement implements TargetManagement { private VirtualPropertyReplacer virtualPropertyReplacer; @Override - public Optional findTargetByControllerID(final String controllerId) { + public Optional getByControllerID(final String controllerId) { return targetRepository.findByControllerId(controllerId); } @Override - public List findTargetsByControllerID(final Collection controllerIDs) { + public List getByControllerID(final Collection controllerIDs) { return Collections.unmodifiableList( targetRepository.findAll(TargetSpecifications.byControllerIdWithAssignedDsInJoin(controllerIDs))); } @Override - public Long countTargetsAll() { + public long count() { return targetRepository.count(); } @Override - public Slice findTargetsAll(final Pageable pageable) { + public Slice findAll(final Pageable pageable) { return convertPage(criteriaNoCountDao.findAll(pageable, JpaTarget.class), pageable); } @Override - public Slice findTargetsByTargetFilterQuery(final Long targetFilterQueryId, final Pageable pageable) { + public Slice findByTargetFilterQuery(final Pageable pageable, final Long targetFilterQueryId) { final TargetFilterQuery targetFilterQuery = targetFilterQueryRepository.findById(targetFilterQueryId) .orElseThrow(() -> new EntityNotFoundException(TargetFilterQuery.class, targetFilterQueryId)); @@ -146,7 +146,7 @@ public class JpaTargetManagement implements TargetManagement { } @Override - public Page findTargetsAll(final String targetFilterQuery, final Pageable pageable) { + public Page findByRsql(final Pageable pageable, final String targetFilterQuery) { return findTargetsBySpec(RSQLUtility.parse(targetFilterQuery, TargetFields.class, virtualPropertyReplacer), pageable); } @@ -159,7 +159,7 @@ public class JpaTargetManagement implements TargetManagement { @Transactional @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) - public Target updateTarget(final TargetUpdate u) { + public Target update(final TargetUpdate u) { final JpaTargetUpdate update = (JpaTargetUpdate) u; final JpaTarget target = (JpaTarget) targetRepository.findByControllerId(update.getControllerId()) @@ -177,7 +177,7 @@ public class JpaTargetManagement implements TargetManagement { @Transactional @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) - public void deleteTargets(final Collection targetIDs) { + public void delete(final Collection targetIDs) { final List targets = targetRepository.findAll(targetIDs); if (targets.size() < targetIDs.size()) { @@ -197,7 +197,7 @@ public class JpaTargetManagement implements TargetManagement { @Transactional @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) - public void deleteTarget(final String controllerID) { + public void deleteByControllerID(final String controllerID) { final Target target = targetRepository.findByControllerId(controllerID) .orElseThrow(() -> new EntityNotFoundException(Target.class, controllerID)); @@ -205,15 +205,15 @@ public class JpaTargetManagement implements TargetManagement { } @Override - public Page findTargetByAssignedDistributionSet(final Long distributionSetID, final Pageable pageReq) { + public Page findByAssignedDistributionSet(final Pageable pageReq, final Long distributionSetID) { throwEntityNotFoundIfDsDoesNotExist(distributionSetID); return targetRepository.findByAssignedDistributionSetId(pageReq, distributionSetID); } @Override - public Page findTargetByAssignedDistributionSet(final Long distributionSetID, final String rsqlParam, - final Pageable pageReq) { + public Page findByAssignedDistributionSetAndRsql(final Pageable pageReq, final Long distributionSetID, + final String rsqlParam) { throwEntityNotFoundIfDsDoesNotExist(distributionSetID); final Specification spec = RSQLUtility.parse(rsqlParam, TargetFields.class, virtualPropertyReplacer); @@ -242,14 +242,14 @@ public class JpaTargetManagement implements TargetManagement { } @Override - public Page findTargetByInstalledDistributionSet(final Long distributionSetID, final Pageable pageReq) { + public Page findByInstalledDistributionSet(final Pageable pageReq, final Long distributionSetID) { throwEntityNotFoundIfDsDoesNotExist(distributionSetID); return targetRepository.findByInstalledDistributionSetId(pageReq, distributionSetID); } @Override - public Page findTargetByInstalledDistributionSet(final Long distributionSetId, final String rsqlParam, - final Pageable pageable) { + public Page findByInstalledDistributionSetAndRsql(final Pageable pageable, final Long distributionSetId, + final String rsqlParam) { throwEntityNotFoundIfDsDoesNotExist(distributionSetId); final Specification spec = RSQLUtility.parse(rsqlParam, TargetFields.class, virtualPropertyReplacer); @@ -264,27 +264,22 @@ public class JpaTargetManagement implements TargetManagement { } @Override - public Page findTargetByUpdateStatus(final Pageable pageable, final TargetUpdateStatus status) { + public Page findByUpdateStatus(final Pageable pageable, final TargetUpdateStatus status) { return targetRepository.findByUpdateStatus(pageable, status); } @Override - public Slice findTargetByFilters(final Pageable pageable, final Collection status, - final Boolean overdueState, final String searchText, final Long installedOrAssignedDistributionSetId, - final Boolean selectTargetWithNoTag, final String... tagNames) { - final List> specList = buildSpecificationList( - new FilterParams(installedOrAssignedDistributionSetId, status, overdueState, searchText, - selectTargetWithNoTag, tagNames)); + public Slice findByFilters(final Pageable pageable, final FilterParams filterParams) { + final List> specList = buildSpecificationList(filterParams); return findByCriteriaAPI(pageable, specList); } @Override - public Long countTargetByFilters(final Collection status, final Boolean overdueState, + public long countByFilters(final Collection status, final Boolean overdueState, final String searchText, final Long installedOrAssignedDistributionSetId, final Boolean selectTargetWithNoTag, final String... tagNames) { - final List> specList = buildSpecificationList( - new FilterParams(installedOrAssignedDistributionSetId, status, overdueState, searchText, - selectTargetWithNoTag, tagNames)); + final List> specList = buildSpecificationList(new FilterParams(status, overdueState, + searchText, installedOrAssignedDistributionSetId, selectTargetWithNoTag, tagNames)); return countByCriteriaAPI(specList); } @@ -421,7 +416,7 @@ public class JpaTargetManagement implements TargetManagement { } @Override - public Slice findTargetsAllOrderByLinkedDistributionSet(final Pageable pageable, + public Slice findByFilterOrderByLinkedDistributionSet(final Pageable pageable, final Long orderByDistributionId, final FilterParams filterParams) { final CriteriaBuilder cb = entityManager.getCriteriaBuilder(); final CriteriaQuery query = cb.createQuery(JpaTarget.class); @@ -475,22 +470,22 @@ public class JpaTargetManagement implements TargetManagement { } @Override - public Long countTargetByAssignedDistributionSet(final Long distId) { + public long countByAssignedDistributionSet(final Long distId) { throwEntityNotFoundIfDsDoesNotExist(distId); return targetRepository.countByAssignedDistributionSetId(distId); } @Override - public Long countTargetByInstalledDistributionSet(final Long distId) { + public long countByInstalledDistributionSet(final Long distId) { throwEntityNotFoundIfDsDoesNotExist(distId); return targetRepository.countByInstalledDistributionSetId(distId); } @Override - public Page findAllTargetsByTargetFilterQueryAndNonDS(final Pageable pageRequest, - final Long distributionSetId, final String targetFilterQuery) { + public Page findByTargetFilterQueryAndNonDS(final Pageable pageRequest, final Long distributionSetId, + final String targetFilterQuery) { throwEntityNotFoundIfDsDoesNotExist(distributionSetId); final Specification spec = RSQLUtility.parse(targetFilterQuery, TargetFields.class, @@ -505,7 +500,7 @@ public class JpaTargetManagement implements TargetManagement { } @Override - public Page findAllTargetsByTargetFilterQueryAndNotInRolloutGroups(final Pageable pageRequest, + public Page findByTargetFilterQueryAndNotInRolloutGroups(final Pageable pageRequest, final Collection groups, final String targetFilterQuery) { final Specification spec = RSQLUtility.parse(targetFilterQuery, TargetFields.class, @@ -517,7 +512,7 @@ public class JpaTargetManagement implements TargetManagement { } @Override - public Page findAllTargetsInRolloutGroupWithoutAction(@NotNull final Pageable pageRequest, + public Page findByInRolloutGroupWithoutAction(@NotNull final Pageable pageRequest, @NotNull final Long group) { if (!rolloutGroupRepository.exists(group)) { throw new EntityNotFoundException(RolloutGroup.class, group); @@ -529,8 +524,7 @@ public class JpaTargetManagement implements TargetManagement { } @Override - public Long countAllTargetsByTargetFilterQueryAndNotInRolloutGroups(final Collection groups, - final String targetFilterQuery) { + public long countByRsqlAndNotInRolloutGroups(final Collection groups, final String targetFilterQuery) { final Specification spec = RSQLUtility.parse(targetFilterQuery, TargetFields.class, virtualPropertyReplacer); final List> specList = Arrays.asList(spec, @@ -540,7 +534,7 @@ public class JpaTargetManagement implements TargetManagement { } @Override - public Long countTargetsByTargetFilterQueryAndNonDS(final Long distributionSetId, final String targetFilterQuery) { + public long countByRsqlAndNonDS(final Long distributionSetId, final String targetFilterQuery) { throwEntityNotFoundIfDsDoesNotExist(distributionSetId); final Specification spec = RSQLUtility.parse(targetFilterQuery, TargetFields.class, @@ -556,7 +550,7 @@ public class JpaTargetManagement implements TargetManagement { @Transactional @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) - public Target createTarget(final TargetCreate c) { + public Target create(final TargetCreate c) { final JpaTargetCreate create = (JpaTargetCreate) c; return targetRepository.save(create.build()); } @@ -565,12 +559,12 @@ public class JpaTargetManagement implements TargetManagement { @Transactional @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) - public List createTargets(final Collection targets) { - return targets.stream().map(this::createTarget).collect(Collectors.toList()); + public List create(final Collection targets) { + return targets.stream().map(this::create).collect(Collectors.toList()); } @Override - public Page findTargetsByTag(final Pageable pageable, final Long tagId) { + public Page findByTag(final Pageable pageable, final Long tagId) { throwEntityNotFoundExceptionIfTagDoesNotExist(tagId); return convertPage(targetRepository.findByTag(pageable, tagId), pageable); @@ -583,7 +577,7 @@ public class JpaTargetManagement implements TargetManagement { } @Override - public Page findTargetsByTag(final Pageable pageable, final String rsqlParam, final Long tagId) { + public Page findByRsqlAndTag(final Pageable pageable, final String rsqlParam, final Long tagId) { throwEntityNotFoundExceptionIfTagDoesNotExist(tagId); @@ -595,7 +589,7 @@ public class JpaTargetManagement implements TargetManagement { } @Override - public Long countTargetByTargetFilterQuery(final Long targetFilterQueryId) { + public long countByTargetFilterQuery(final Long targetFilterQueryId) { final TargetFilterQuery targetFilterQuery = targetFilterQueryRepository.findById(targetFilterQueryId) .orElseThrow(() -> new EntityNotFoundException(TargetFilterQuery.class, targetFilterQueryId)); @@ -605,7 +599,7 @@ public class JpaTargetManagement implements TargetManagement { } @Override - public Long countTargetByTargetFilterQuery(final String targetFilterQuery) { + public long countByRsql(final String targetFilterQuery) { final Specification specs = RSQLUtility.parse(targetFilterQuery, TargetFields.class, virtualPropertyReplacer); return targetRepository.count((root, query, cb) -> { @@ -615,18 +609,18 @@ public class JpaTargetManagement implements TargetManagement { } @Override - public Optional findTargetById(final Long id) { + public Optional get(final Long id) { return Optional.ofNullable(targetRepository.findOne(id)); } @Override - public List findTargetsById(final Collection ids) { + public List get(final Collection ids) { return Collections.unmodifiableList(targetRepository.findAll(ids)); } @Override public Map getControllerAttributes(final String controllerId) { - final JpaTarget target = (JpaTarget) findTargetByControllerID(controllerId) + final JpaTarget target = (JpaTarget) getByControllerID(controllerId) .orElseThrow(() -> new EntityNotFoundException(Target.class, controllerId)); return target.getControllerAttributes(); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetTagManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetTagManagement.java new file mode 100644 index 000000000..a28ee58df --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetTagManagement.java @@ -0,0 +1,153 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.jpa; + +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + +import org.eclipse.hawkbit.repository.TagFields; +import org.eclipse.hawkbit.repository.TargetTagManagement; +import org.eclipse.hawkbit.repository.builder.GenericTagUpdate; +import org.eclipse.hawkbit.repository.builder.TagCreate; +import org.eclipse.hawkbit.repository.builder.TagUpdate; +import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; +import org.eclipse.hawkbit.repository.jpa.builder.JpaTagCreate; +import org.eclipse.hawkbit.repository.jpa.configuration.Constants; +import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag; +import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility; +import org.eclipse.hawkbit.repository.jpa.specifications.TagSpecification; +import org.eclipse.hawkbit.repository.model.Target; +import org.eclipse.hawkbit.repository.model.TargetTag; +import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer; +import org.springframework.dao.ConcurrencyFailureException; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.retry.annotation.Backoff; +import org.springframework.retry.annotation.Retryable; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.validation.annotation.Validated; + +/** + * JPA implementation of {@link TargetTagManagement}. + * + */ +@Transactional(readOnly = true) +@Validated +public class JpaTargetTagManagement implements TargetTagManagement { + + private final TargetTagRepository targetTagRepository; + + private final TargetRepository targetRepository; + + private final VirtualPropertyReplacer virtualPropertyReplacer; + + JpaTargetTagManagement(final TargetTagRepository targetTagRepository, final TargetRepository targetRepository, + final VirtualPropertyReplacer virtualPropertyReplacer) { + this.targetTagRepository = targetTagRepository; + this.targetRepository = targetRepository; + this.virtualPropertyReplacer = virtualPropertyReplacer; + } + + @Override + public Optional getByName(final String name) { + return targetTagRepository.findByNameEquals(name); + } + + @Override + @Transactional + @Retryable(include = { + ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) + public TargetTag create(final TagCreate c) { + final JpaTagCreate create = (JpaTagCreate) c; + + return targetTagRepository.save(create.buildTargetTag()); + } + + @Override + @Transactional + @Retryable(include = { + ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) + public List create(final Collection tt) { + @SuppressWarnings({ "unchecked", "rawtypes" }) + final Collection targetTags = (Collection) tt; + + return Collections.unmodifiableList(targetTags.stream() + .map(ttc -> targetTagRepository.save(ttc.buildTargetTag())).collect(Collectors.toList())); + } + + @Override + @Transactional + @Retryable(include = { + ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) + public void delete(final String targetTagName) { + if (!targetTagRepository.existsByName(targetTagName)) { + throw new EntityNotFoundException(TargetTag.class, targetTagName); + } + + // finally delete the tag itself + targetTagRepository.deleteByName(targetTagName); + } + + @Override + public Page findByRsql(final Pageable pageable, final String rsqlParam) { + + final Specification spec = RSQLUtility.parse(rsqlParam, TagFields.class, virtualPropertyReplacer); + return convertTPage(targetTagRepository.findAll(spec, pageable), pageable); + } + + private static Page convertTPage(final Page findAll, final Pageable pageable) { + return new PageImpl<>(Collections.unmodifiableList(findAll.getContent()), pageable, findAll.getTotalElements()); + } + + @Override + public long count() { + return targetTagRepository.count(); + } + + @Override + @Transactional + @Retryable(include = { + ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) + public TargetTag update(final TagUpdate u) { + final GenericTagUpdate update = (GenericTagUpdate) u; + + final JpaTargetTag tag = targetTagRepository.findById(update.getId()) + .orElseThrow(() -> new EntityNotFoundException(TargetTag.class, update.getId())); + + update.getName().ifPresent(tag::setName); + update.getDescription().ifPresent(tag::setDescription); + update.getColour().ifPresent(tag::setColour); + + return targetTagRepository.save(tag); + } + + @Override + public Optional get(final Long id) { + return Optional.ofNullable(targetTagRepository.findOne(id)); + } + + @Override + public Page findAll(final Pageable pageable) { + return convertTPage(targetTagRepository.findAll(pageable), pageable); + } + + @Override + public Page findByTarget(final Pageable pageable, final String controllerId) { + if (!targetRepository.existsByControllerId(controllerId)) { + throw new EntityNotFoundException(Target.class, controllerId); + } + + return convertTPage(targetTagRepository.findAll(TagSpecification.ofTarget(controllerId), pageable), pageable); + } +} diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/RepositoryApplicationConfiguration.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/RepositoryApplicationConfiguration.java index ecdb65b3d..e9017a310 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/RepositoryApplicationConfiguration.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/RepositoryApplicationConfiguration.java @@ -18,6 +18,7 @@ import org.eclipse.hawkbit.repository.ArtifactManagement; import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.DistributionSetManagement; +import org.eclipse.hawkbit.repository.DistributionSetTagManagement; import org.eclipse.hawkbit.repository.DistributionSetTypeManagement; import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.PropertiesQuotaManagement; @@ -28,9 +29,9 @@ import org.eclipse.hawkbit.repository.RolloutStatusCache; import org.eclipse.hawkbit.repository.SoftwareModuleManagement; import org.eclipse.hawkbit.repository.SoftwareModuleTypeManagement; import org.eclipse.hawkbit.repository.SystemManagement; -import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.TargetFilterQueryManagement; import org.eclipse.hawkbit.repository.TargetManagement; +import org.eclipse.hawkbit.repository.TargetTagManagement; import org.eclipse.hawkbit.repository.TenantConfigurationManagement; import org.eclipse.hawkbit.repository.TenantStatsManagement; import org.eclipse.hawkbit.repository.builder.DistributionSetBuilder; @@ -165,8 +166,9 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration { * @return DistributionSetTypeBuilder bean */ @Bean - DistributionSetTypeBuilder distributionSetTypeBuilder(final SoftwareModuleManagement softwareManagement) { - return new JpaDistributionSetTypeBuilder(softwareManagement); + DistributionSetTypeBuilder distributionSetTypeBuilder( + final SoftwareModuleTypeManagement softwareModuleTypeManagement) { + return new JpaDistributionSetTypeBuilder(softwareModuleTypeManagement); } /** @@ -369,9 +371,9 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration { final DistributionSetTypeRepository distributionSetTypeRepository, final SoftwareModuleTypeRepository softwareModuleTypeRepository, final DistributionSetRepository distributionSetRepository, - final VirtualPropertyReplacer virtualPropertyReplacer) { + final VirtualPropertyReplacer virtualPropertyReplacer, final NoCountPagingRepository criteriaNoCountDao) { return new JpaDistributionSetTypeManagement(distributionSetTypeRepository, softwareModuleTypeRepository, - distributionSetRepository, virtualPropertyReplacer); + distributionSetRepository, virtualPropertyReplacer, criteriaNoCountDao); } /** @@ -430,14 +432,30 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration { } /** - * {@link JpaTagManagement} bean. + * {@link JpaTargetTagManagement} bean. * - * @return a new {@link TagManagement} + * @return a new {@link TargetTagManagement} */ @Bean @ConditionalOnMissingBean - TagManagement tagManagement() { - return new JpaTagManagement(); + TargetTagManagement targetTagManagement(final TargetTagRepository targetTagRepository, + final TargetRepository targetRepository, final VirtualPropertyReplacer virtualPropertyReplacer) { + return new JpaTargetTagManagement(targetTagRepository, targetRepository, virtualPropertyReplacer); + } + + /** + * {@link JpaDistributionSetTagManagement} bean. + * + * @return a new {@link JpaDistributionSetTagManagement} + */ + @Bean + @ConditionalOnMissingBean + DistributionSetTagManagement distributionSetTagManagement( + final DistributionSetTagRepository distributionSetTagRepository, + final DistributionSetRepository distributionSetRepository, + final VirtualPropertyReplacer virtualPropertyReplacer, final NoCountPagingRepository criteriaNoCountDao) { + return new JpaDistributionSetTagManagement(distributionSetTagRepository, distributionSetRepository, + virtualPropertyReplacer, criteriaNoCountDao); } /** @@ -462,9 +480,9 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration { final DistributionSetTypeRepository distributionSetTypeRepository, final SoftwareModuleTypeRepository softwareModuleTypeRepository, final VirtualPropertyReplacer virtualPropertyReplacer, - final SoftwareModuleRepository softwareModuleRepository) { + final SoftwareModuleRepository softwareModuleRepository, final NoCountPagingRepository criteriaNoCountDao) { return new JpaSoftwareModuleTypeManagement(distributionSetTypeRepository, softwareModuleTypeRepository, - virtualPropertyReplacer, softwareModuleRepository); + virtualPropertyReplacer, softwareModuleRepository, criteriaNoCountDao); } @Bean @@ -537,7 +555,7 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration { */ @Bean @ConditionalOnMissingBean - public EntityFactory entityFactory() { + EntityFactory entityFactory() { return new JpaEntityFactory(); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleMetadataRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleMetadataRepository.java index f30c8b33e..d874025a0 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleMetadataRepository.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleMetadataRepository.java @@ -11,8 +11,6 @@ package org.eclipse.hawkbit.repository.jpa; import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleMetadata; import org.eclipse.hawkbit.repository.jpa.model.SwMetadataCompositeKey; import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.transaction.annotation.Transactional; @@ -26,15 +24,4 @@ public interface SoftwareModuleMetadataRepository extends PagingAndSortingRepository, JpaSpecificationExecutor { - /** - * finds all software module meta data of the given software module id. - * - * @param swId - * the ID of the software module to retrieve the meta data - * @param pageable - * the page request to page the result set - * @return the paged result of all meta data of an given software module id - */ - Page findBySoftwareModuleId(final Long swId, Pageable pageable); - } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleTypeRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleTypeRepository.java index abd0b4939..dffce476c 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleTypeRepository.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleTypeRepository.java @@ -14,7 +14,6 @@ import java.util.Optional; import javax.persistence.EntityManager; import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType; -import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity; import org.springframework.data.domain.Page; @@ -68,18 +67,6 @@ public interface SoftwareModuleTypeRepository */ Optional findByName(String name); - /** - * retrieves all software module types with a given - * {@link SoftwareModuleType#getId()}. - * - * @param ids - * to search for - * @return {@link List} of found {@link SoftwareModule}s - */ - // Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=349477 - @Query("SELECT sm FROM JpaSoftwareModuleType sm WHERE sm.id IN ?1") - List findByIdIn(Iterable ids); - /** * Deletes all {@link TenantAwareBaseEntity} of a given tenant. For safety * reasons (this is a "delete everything" query after all) we add the tenant @@ -93,4 +80,9 @@ public interface SoftwareModuleTypeRepository @Transactional @Query("DELETE FROM JpaSoftwareModuleType t WHERE t.tenant = :tenant") void deleteByTenant(@Param("tenant") String tenant); + + @Override + // Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=349477 + @Query("SELECT d FROM JpaSoftwareModuleType d WHERE d.id IN ?1") + List findAll(Iterable ids); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/autoassign/AutoAssignChecker.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/autoassign/AutoAssignChecker.java index 13ec2788a..a2fdff410 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/autoassign/AutoAssignChecker.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/autoassign/AutoAssignChecker.java @@ -105,7 +105,7 @@ public class AutoAssignChecker { final PageRequest pageRequest = new PageRequest(0, PAGE_SIZE); final Page filterQueries = targetFilterQueryManagement - .findTargetFilterQueryWithAutoAssignDS(pageRequest); + .findWithAutoAssignDS(pageRequest); for (final TargetFilterQuery filterQuery : filterQueries) { checkByTargetFilterQueryAndAssignDS(filterQuery); @@ -176,7 +176,7 @@ public class AutoAssignChecker { private List getTargetsWithActionType(final String targetFilterQuery, final Long dsId, final int count) { final Page targets = targetManagement - .findAllTargetsByTargetFilterQueryAndNonDS(new PageRequest(0, count), dsId, targetFilterQuery); + .findByTargetFilterQueryAndNonDS(new PageRequest(0, count), dsId, targetFilterQuery); return targets.getContent().stream().map(t -> new TargetWithActionType(t.getControllerId(), Action.ActionType.FORCED, RepositoryModelConstants.NO_FORCE_TIME)).collect(Collectors.toList()); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/builder/JpaDistributionSetCreate.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/builder/JpaDistributionSetCreate.java index c729506f4..1ca32147f 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/builder/JpaDistributionSetCreate.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/builder/JpaDistributionSetCreate.java @@ -47,7 +47,7 @@ public class JpaDistributionSetCreate extends AbstractDistributionSetUpdateCreat } private DistributionSetType findDistributionSetTypeWithExceptionIfNotFound(final String distributionSetTypekey) { - return distributionSetTypeManagement.findDistributionSetTypeByKey(distributionSetTypekey) + return distributionSetTypeManagement.getByKey(distributionSetTypekey) .orElseThrow(() -> new EntityNotFoundException(DistributionSetType.class, distributionSetTypekey)); } @@ -57,7 +57,7 @@ public class JpaDistributionSetCreate extends AbstractDistributionSetUpdateCreat return Collections.emptyList(); } - final Collection module = softwareModuleManagement.findSoftwareModulesById(softwareModuleId); + final Collection module = softwareModuleManagement.get(softwareModuleId); if (module.size() < softwareModuleId.size()) { throw new EntityNotFoundException(SoftwareModule.class, softwareModuleId); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/builder/JpaDistributionSetTypeBuilder.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/builder/JpaDistributionSetTypeBuilder.java index d7806e422..01bac1916 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/builder/JpaDistributionSetTypeBuilder.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/builder/JpaDistributionSetTypeBuilder.java @@ -8,7 +8,7 @@ */ package org.eclipse.hawkbit.repository.jpa.builder; -import org.eclipse.hawkbit.repository.SoftwareModuleManagement; +import org.eclipse.hawkbit.repository.SoftwareModuleTypeManagement; import org.eclipse.hawkbit.repository.builder.DistributionSetTypeBuilder; import org.eclipse.hawkbit.repository.builder.DistributionSetTypeCreate; import org.eclipse.hawkbit.repository.builder.DistributionSetTypeUpdate; @@ -21,10 +21,10 @@ import org.eclipse.hawkbit.repository.model.DistributionSetType; */ public class JpaDistributionSetTypeBuilder implements DistributionSetTypeBuilder { - private final SoftwareModuleManagement softwareModuleManagement; + private final SoftwareModuleTypeManagement softwareModuleTypeManagement; - public JpaDistributionSetTypeBuilder(final SoftwareModuleManagement softwareManagement) { - this.softwareModuleManagement = softwareManagement; + public JpaDistributionSetTypeBuilder(final SoftwareModuleTypeManagement softwareModuleTypeManagement) { + this.softwareModuleTypeManagement = softwareModuleTypeManagement; } @Override @@ -34,7 +34,7 @@ public class JpaDistributionSetTypeBuilder implements DistributionSetTypeBuilder @Override public DistributionSetTypeCreate create() { - return new JpaDistributionSetTypeCreate(softwareModuleManagement); + return new JpaDistributionSetTypeCreate(softwareModuleTypeManagement); } } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/builder/JpaDistributionSetTypeCreate.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/builder/JpaDistributionSetTypeCreate.java index b9b192b74..f645efa35 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/builder/JpaDistributionSetTypeCreate.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/builder/JpaDistributionSetTypeCreate.java @@ -11,7 +11,7 @@ package org.eclipse.hawkbit.repository.jpa.builder; import java.util.Collection; import java.util.Collections; -import org.eclipse.hawkbit.repository.SoftwareModuleManagement; +import org.eclipse.hawkbit.repository.SoftwareModuleTypeManagement; import org.eclipse.hawkbit.repository.builder.AbstractDistributionSetTypeUpdateCreate; import org.eclipse.hawkbit.repository.builder.DistributionSetTypeCreate; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; @@ -26,10 +26,10 @@ import org.springframework.util.CollectionUtils; public class JpaDistributionSetTypeCreate extends AbstractDistributionSetTypeUpdateCreate implements DistributionSetTypeCreate { - private final SoftwareModuleManagement softwareModuleManagement; + private final SoftwareModuleTypeManagement softwareModuleTypeManagement; - JpaDistributionSetTypeCreate(final SoftwareModuleManagement softwareManagement) { - this.softwareModuleManagement = softwareManagement; + JpaDistributionSetTypeCreate(final SoftwareModuleTypeManagement softwareModuleTypeManagement) { + this.softwareModuleTypeManagement = softwareModuleTypeManagement; } @Override @@ -48,8 +48,7 @@ public class JpaDistributionSetTypeCreate extends AbstractDistributionSetTypeUpd return Collections.emptyList(); } - final Collection module = softwareModuleManagement - .findSoftwareModuleTypesById(softwareModuleTypeId); + final Collection module = softwareModuleTypeManagement.get(softwareModuleTypeId); if (module.size() < softwareModuleTypeId.size()) { throw new EntityNotFoundException(SoftwareModuleType.class, softwareModuleTypeId); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/builder/JpaRolloutCreate.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/builder/JpaRolloutCreate.java index 9974ae7e2..f9e791b4f 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/builder/JpaRolloutCreate.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/builder/JpaRolloutCreate.java @@ -44,7 +44,7 @@ public class JpaRolloutCreate extends AbstractRolloutUpdateCreate } private DistributionSet findDistributionSetAndThrowExceptionIfNotFound(final Long setId) { - return distributionSetManagement.findDistributionSetById(setId) + return distributionSetManagement.get(setId) .orElseThrow(() -> new EntityNotFoundException(DistributionSet.class, setId)); } } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/builder/JpaSoftwareModuleCreate.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/builder/JpaSoftwareModuleCreate.java index 1f30c7fe9..964aee9bc 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/builder/JpaSoftwareModuleCreate.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/builder/JpaSoftwareModuleCreate.java @@ -40,7 +40,7 @@ public class JpaSoftwareModuleCreate extends AbstractSoftwareModuleUpdateCreate< throw new ValidationException("type cannot be null"); } - return softwareModuleTypeManagement.findSoftwareModuleTypeByKey(type.trim()) + return softwareModuleTypeManagement.getByKey(type.trim()) .orElseThrow(() -> new EntityNotFoundException(SoftwareModuleType.class, type.trim())); } } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/builder/JpaTargetFilterQueryCreate.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/builder/JpaTargetFilterQueryCreate.java index c6d77e59c..96f06379d 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/builder/JpaTargetFilterQueryCreate.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/builder/JpaTargetFilterQueryCreate.java @@ -36,7 +36,7 @@ public class JpaTargetFilterQueryCreate extends AbstractTargetFilterQueryUpdateC } private DistributionSet findDistributionSetAndThrowExceptionIfNotFound(final Long setId) { - return distributionSetManagement.findDistributionSetById(setId) + return distributionSetManagement.get(setId) .orElseThrow(() -> new EntityNotFoundException(DistributionSet.class, setId)); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaActionStatus.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaActionStatus.java index c7c7b79a0..3d92f7b87 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaActionStatus.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaActionStatus.java @@ -37,7 +37,7 @@ import com.google.common.base.Splitter; /** * Entity to store the status for a specific action. */ -@Table(name = "sp_action_status", indexes = { @Index(name = "sp_idx_action_status_01", columnList = "tenant,action"), +@Table(name = "sp_action_status", indexes = { @Index(name = "sp_idx_action_status_02", columnList = "tenant,action,status"), @Index(name = "sp_idx_action_status_prim", columnList = "tenant,id") }) @NamedEntityGraph(name = "ActionStatus.withMessages", attributeNodes = { @NamedAttributeNode("messages") }) diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSet.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSet.java index 7917b7afc..9ff4962f3 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSet.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSet.java @@ -60,8 +60,7 @@ import org.springframework.context.ApplicationEvent; @Entity @Table(name = "sp_distribution_set", uniqueConstraints = { @UniqueConstraint(columnNames = { "name", "version", "tenant" }, name = "uk_distrib_set") }, indexes = { - @Index(name = "sp_idx_distribution_set_01", columnList = "tenant,deleted,name,complete"), - @Index(name = "sp_idx_distribution_set_02", columnList = "tenant,required_migration_step"), + @Index(name = "sp_idx_distribution_set_01", columnList = "tenant,deleted,complete"), @Index(name = "sp_idx_distribution_set_prim", columnList = "tenant,id") }) @NamedEntityGraph(name = "DistributionSet.detail", attributeNodes = { @NamedAttributeNode("modules"), @NamedAttributeNode("tags"), @NamedAttributeNode("type") }) diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRollout.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRollout.java index 95d2b338f..1d26f4bc5 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRollout.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRollout.java @@ -19,7 +19,6 @@ import javax.persistence.EnumType; import javax.persistence.Enumerated; import javax.persistence.FetchType; import javax.persistence.ForeignKey; -import javax.persistence.Index; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; @@ -52,9 +51,8 @@ import org.hibernate.validator.constraints.NotEmpty; * */ @Entity -@Table(name = "sp_rollout", indexes = { - @Index(name = "sp_idx_rollout_01", columnList = "tenant,name") }, uniqueConstraints = @UniqueConstraint(columnNames = { - "name", "tenant" }, name = "uk_rollout")) +@Table(name = "sp_rollout", uniqueConstraints = @UniqueConstraint(columnNames = { "name", + "tenant" }, name = "uk_rollout")) // exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for // sub entities @SuppressWarnings("squid:S2160") diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRolloutGroup.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRolloutGroup.java index 336d0b5cf..734621240 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRolloutGroup.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRolloutGroup.java @@ -17,7 +17,6 @@ import javax.persistence.ConstraintMode; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.ForeignKey; -import javax.persistence.Index; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; @@ -44,9 +43,8 @@ import org.eclipse.persistence.descriptors.DescriptorEvent; * */ @Entity -@Table(name = "sp_rolloutgroup", indexes = { - @Index(name = "sp_idx_rolloutgroup_01", columnList = "tenant,name") }, uniqueConstraints = @UniqueConstraint(columnNames = { - "name", "rollout", "tenant" }, name = "uk_rolloutgroup")) +@Table(name = "sp_rolloutgroup", uniqueConstraints = @UniqueConstraint(columnNames = { "name", "rollout", + "tenant" }, name = "uk_rolloutgroup")) // exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for // sub entities @SuppressWarnings("squid:S2160") diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModuleMetadata.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModuleMetadata.java index 02b77457f..5f92aa466 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModuleMetadata.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModuleMetadata.java @@ -32,9 +32,9 @@ public class JpaSoftwareModuleMetadata extends JpaMetaData implements SoftwareMo private static final long serialVersionUID = 1L; @Id - @ManyToOne(optional = false, targetEntity = JpaSoftwareModule.class, fetch = FetchType.LAZY) + @ManyToOne(fetch = FetchType.LAZY, optional = false) @JoinColumn(name = "sw_id", nullable = false, updatable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_metadata_sw")) - private SoftwareModule softwareModule; + private JpaSoftwareModule softwareModule; public JpaSoftwareModuleMetadata() { // default public constructor for JPA @@ -42,7 +42,7 @@ public class JpaSoftwareModuleMetadata extends JpaMetaData implements SoftwareMo public JpaSoftwareModuleMetadata(final String key, final SoftwareModule softwareModule, final String value) { super(key, value); - this.softwareModule = softwareModule; + this.softwareModule = (JpaSoftwareModule) softwareModule; } public SwMetadataCompositeKey getId() { @@ -54,7 +54,7 @@ public class JpaSoftwareModuleMetadata extends JpaMetaData implements SoftwareMo return softwareModule; } - public void setSoftwareModule(final SoftwareModule softwareModule) { + public void setSoftwareModule(final JpaSoftwareModule softwareModule) { this.softwareModule = softwareModule; } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTarget.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTarget.java index fa4138289..70196b0be 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTarget.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTarget.java @@ -74,7 +74,6 @@ import org.slf4j.LoggerFactory; @Entity @Table(name = "sp_target", indexes = { @Index(name = "sp_idx_target_01", columnList = "tenant,name,assigned_distribution_set"), - @Index(name = "sp_idx_target_02", columnList = "tenant,name"), @Index(name = "sp_idx_target_03", columnList = "tenant,controller_id,assigned_distribution_set"), @Index(name = "sp_idx_target_04", columnList = "tenant,created_at"), @Index(name = "sp_idx_target_prim", columnList = "tenant,id") }, uniqueConstraints = @UniqueConstraint(columnNames = { diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetFilterQuery.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetFilterQuery.java index aa87e6c4d..2bc05dab9 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetFilterQuery.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetFilterQuery.java @@ -13,7 +13,6 @@ import javax.persistence.ConstraintMode; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.ForeignKey; -import javax.persistence.Index; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; @@ -30,9 +29,8 @@ import org.hibernate.validator.constraints.NotEmpty; * */ @Entity -@Table(name = "sp_target_filter_query", indexes = { - @Index(name = "sp_idx_target_filter_query_01", columnList = "tenant,name") }, uniqueConstraints = @UniqueConstraint(columnNames = { - "name", "tenant" }, name = "uk_tenant_custom_filter_name")) +@Table(name = "sp_target_filter_query", uniqueConstraints = @UniqueConstraint(columnNames = { "name", + "tenant" }, name = "uk_tenant_custom_filter_name")) // exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for // sub entities @SuppressWarnings("squid:S2160") diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/RsqlParserValidationOracle.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/RsqlParserValidationOracle.java index 9a61b27c9..b270a2f3a 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/RsqlParserValidationOracle.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/RsqlParserValidationOracle.java @@ -74,7 +74,7 @@ public class RsqlParserValidationOracle implements RsqlValidationOracle { context.setSyntaxErrorContext(errorContext); try { - targetManagement.findTargetsAll(rsqlQuery, new PageRequest(0, 1)); + targetManagement.findByRsql(new PageRequest(0, 1), rsqlQuery); context.setSyntaxError(false); suggestionContext.getSuggestions().addAll(getLogicalOperatorSuggestion(rsqlQuery)); } catch (final RSQLParameterSyntaxException | RSQLParserException ex) { diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/resources/db/migration/H2/V1_11_2__remove_unused_idexes___H2.sql b/hawkbit-repository/hawkbit-repository-jpa/src/main/resources/db/migration/H2/V1_11_2__remove_unused_idexes___H2.sql new file mode 100644 index 000000000..190250dfa --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/resources/db/migration/H2/V1_11_2__remove_unused_idexes___H2.sql @@ -0,0 +1,8 @@ +ALTER TABLE sp_action_status DROP INDEX sp_idx_action_status_01; +ALTER TABLE sp_rollout DROP INDEX sp_idx_rollout_01; +ALTER TABLE sp_rolloutgroup DROP INDEX sp_idx_rolloutgroup_01; +ALTER TABLE sp_target DROP INDEX sp_idx_target_02; +ALTER TABLE sp_target_filter_query DROP INDEX sp_idx_target_filter_query_01; +ALTER TABLE sp_distribution_set DROP INDEX sp_idx_distribution_set_01; +ALTER TABLE sp_distribution_set DROP INDEX sp_idx_distribution_set_02; +CREATE INDEX sp_idx_distribution_set_01 ON sp_distribution_set (tenant, deleted, complete); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/resources/db/migration/MYSQL/V1_11_2__remove_unused_idexes___MYSQL.sql b/hawkbit-repository/hawkbit-repository-jpa/src/main/resources/db/migration/MYSQL/V1_11_2__remove_unused_idexes___MYSQL.sql new file mode 100644 index 000000000..190250dfa --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/resources/db/migration/MYSQL/V1_11_2__remove_unused_idexes___MYSQL.sql @@ -0,0 +1,8 @@ +ALTER TABLE sp_action_status DROP INDEX sp_idx_action_status_01; +ALTER TABLE sp_rollout DROP INDEX sp_idx_rollout_01; +ALTER TABLE sp_rolloutgroup DROP INDEX sp_idx_rolloutgroup_01; +ALTER TABLE sp_target DROP INDEX sp_idx_target_02; +ALTER TABLE sp_target_filter_query DROP INDEX sp_idx_target_filter_query_01; +ALTER TABLE sp_distribution_set DROP INDEX sp_idx_distribution_set_01; +ALTER TABLE sp_distribution_set DROP INDEX sp_idx_distribution_set_02; +CREATE INDEX sp_idx_distribution_set_01 ON sp_distribution_set (tenant, deleted, complete); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/entity/DistributionSetCreatedEventTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/entity/DistributionSetCreatedEventTest.java index c50fb68be..cfe9dbbb3 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/entity/DistributionSetCreatedEventTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/entity/DistributionSetCreatedEventTest.java @@ -30,7 +30,7 @@ public class DistributionSetCreatedEventTest extends AbstractRemoteEntityEventTe @Override protected DistributionSet createEntity() { - return distributionSetManagement.createDistributionSet(entityFactory.distributionSet().create() + return distributionSetManagement.create(entityFactory.distributionSet().create() .name("incomplete").version("2").description("incomplete").type("os")); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/entity/DistributionSetTagEventTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/entity/DistributionSetTagEventTest.java index 84f109b40..3dab35d75 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/entity/DistributionSetTagEventTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/entity/DistributionSetTagEventTest.java @@ -36,7 +36,7 @@ public class DistributionSetTagEventTest extends AbstractRemoteEntityEventTest { @Override protected Rollout createEntity() { testdataFactory.createTarget("12345"); - final DistributionSet ds = distributionSetManagement.createDistributionSet(entityFactory.distributionSet() + final DistributionSet ds = distributionSetManagement.create(entityFactory.distributionSet() .create().name("incomplete").version("2").description("incomplete").type("os")); - return rolloutManagement.createRollout( + return rolloutManagement.create( entityFactory.rollout().create().name("exampleRollout").targetFilterQuery("controllerId==*").set(ds), 10, new RolloutGroupConditionBuilder().withDefaults() .successCondition(RolloutGroupSuccessCondition.THRESHOLD, "10").build()); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/entity/RolloutGroupEventTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/entity/RolloutGroupEventTest.java index ecc727be4..017138c5b 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/entity/RolloutGroupEventTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/entity/RolloutGroupEventTest.java @@ -91,15 +91,15 @@ public class RolloutGroupEventTest extends AbstractRemoteEntityEventTest @Override protected TargetTag createEntity() { - return tagManagement.createTargetTag(entityFactory.tag().create().name("tag1")); + return targetTagManagement.create(entityFactory.tag().create().name("tag1")); } } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementTest.java index 31a1c064a..d3e33b7bd 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementTest.java @@ -53,11 +53,11 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest { public void nonExistingEntityAccessReturnsNotPresent() { final SoftwareModule module = testdataFactory.createSoftwareModuleOs(); - assertThat(artifactManagement.findArtifact(NOT_EXIST_IDL)).isNotPresent(); - assertThat(artifactManagement.findByFilenameAndSoftwareModule(NOT_EXIST_ID, module.getId()).isPresent()) + assertThat(artifactManagement.get(NOT_EXIST_IDL)).isNotPresent(); + assertThat(artifactManagement.getByFilenameAndSoftwareModule(NOT_EXIST_ID, module.getId()).isPresent()) .isFalse(); - assertThat(artifactManagement.findFirstArtifactBySHA1(NOT_EXIST_ID)).isNotPresent(); + assertThat(artifactManagement.findFirstBySHA1(NOT_EXIST_ID)).isNotPresent(); assertThat(artifactManagement.loadArtifactBinary(NOT_EXIST_ID)).isNotPresent(); } @@ -67,20 +67,20 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest { @ExpectEvents({ @Expect(type = SoftwareModuleDeletedEvent.class, count = 0) }) public void entityQueriesReferringToNotExistingEntitiesThrowsException() throws URISyntaxException { - verifyThrownExceptionBy(() -> artifactManagement.createArtifact(IOUtils.toInputStream("test", "UTF-8"), + verifyThrownExceptionBy(() -> artifactManagement.create(IOUtils.toInputStream("test", "UTF-8"), NOT_EXIST_IDL, "xxx", null, null, false, null), "SoftwareModule"); verifyThrownExceptionBy( - () -> artifactManagement.createArtifact(IOUtils.toInputStream("test", "UTF-8"), 1234L, "xxx", false), + () -> artifactManagement.create(IOUtils.toInputStream("test", "UTF-8"), 1234L, "xxx", false), "SoftwareModule"); - verifyThrownExceptionBy(() -> artifactManagement.deleteArtifact(NOT_EXIST_IDL), "Artifact"); + verifyThrownExceptionBy(() -> artifactManagement.delete(NOT_EXIST_IDL), "Artifact"); - verifyThrownExceptionBy(() -> artifactManagement.findArtifactBySoftwareModule(PAGE, NOT_EXIST_IDL), + verifyThrownExceptionBy(() -> artifactManagement.findBySoftwareModule(PAGE, NOT_EXIST_IDL), "SoftwareModule"); - assertThat(artifactManagement.findArtifactByFilename(NOT_EXIST_ID).isPresent()).isFalse(); + assertThat(artifactManagement.getByFilename(NOT_EXIST_ID).isPresent()).isFalse(); - verifyThrownExceptionBy(() -> artifactManagement.findByFilenameAndSoftwareModule("xxx", NOT_EXIST_IDL), + verifyThrownExceptionBy(() -> artifactManagement.getByFilenameAndSoftwareModule("xxx", NOT_EXIST_IDL), "SoftwareModule"); } @@ -102,11 +102,11 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest { final byte random[] = RandomStringUtils.random(5 * 1024).getBytes(); - final Artifact result = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", + final Artifact result = artifactManagement.create(new ByteArrayInputStream(random), sm.getId(), "file1", false); - artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), "file11", false); - artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), "file12", false); - final Artifact result2 = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm2.getId(), + artifactManagement.create(new ByteArrayInputStream(random), sm.getId(), "file11", false); + artifactManagement.create(new ByteArrayInputStream(random), sm.getId(), "file12", false); + final Artifact result2 = artifactManagement.create(new ByteArrayInputStream(random), sm2.getId(), "file2", false); assertThat(result).isInstanceOf(Artifact.class); @@ -117,15 +117,15 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest { assertThat(result).isNotEqualTo(result2); assertThat(((JpaArtifact) result).getSha1Hash()).isEqualTo(((JpaArtifact) result2).getSha1Hash()); - assertThat(artifactManagement.findArtifactByFilename("file1").get().getSha1Hash()) + assertThat(artifactManagement.getByFilename("file1").get().getSha1Hash()) .isEqualTo(HashGeneratorUtils.generateSHA1(random)); - assertThat(artifactManagement.findArtifactByFilename("file1").get().getMd5Hash()) + assertThat(artifactManagement.getByFilename("file1").get().getMd5Hash()) .isEqualTo(HashGeneratorUtils.generateMD5(random)); assertThat(artifactRepository.findAll()).hasSize(4); assertThat(softwareModuleRepository.findAll()).hasSize(3); - assertThat(softwareModuleManagement.findSoftwareModuleById(sm.getId()).get().getArtifacts()).hasSize(3); + assertThat(softwareModuleManagement.get(sm.getId()).get().getArtifacts()).hasSize(3); } @Test @@ -136,7 +136,7 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest { final byte random[] = RandomStringUtils.random(5 * 1024).getBytes(); - artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", false); + artifactManagement.create(new ByteArrayInputStream(random), sm.getId(), "file1", false); assertThat(artifactRepository.findAll()).hasSize(1); softwareModuleRepository.deleteAll(); @@ -145,7 +145,7 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest { /** * Test method for - * {@link org.eclipse.hawkbit.repository.ArtifactManagement#deleteArtifact(java.lang.Long)} + * {@link org.eclipse.hawkbit.repository.ArtifactManagement#delete(java.lang.Long)} * . * * @throws IOException @@ -162,9 +162,9 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest { assertThat(artifactRepository.findAll()).isEmpty(); - final Artifact result = artifactManagement.createArtifact(new RandomGeneratedInputStream(5 * 1024), sm.getId(), + final Artifact result = artifactManagement.create(new RandomGeneratedInputStream(5 * 1024), sm.getId(), "file1", false); - final Artifact result2 = artifactManagement.createArtifact(new RandomGeneratedInputStream(5 * 1024), + final Artifact result2 = artifactManagement.create(new RandomGeneratedInputStream(5 * 1024), sm2.getId(), "file2", false); assertThat(artifactRepository.findAll()).hasSize(2); @@ -178,14 +178,14 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest { assertThat(binaryArtifactRepository.getArtifactBySha1(tenantAware.getCurrentTenant(), result2.getSha1Hash())) .isNotNull(); - artifactManagement.deleteArtifact(result.getId()); + artifactManagement.delete(result.getId()); assertThat(binaryArtifactRepository.getArtifactBySha1(tenantAware.getCurrentTenant(), result.getSha1Hash())) .isNull(); assertThat(binaryArtifactRepository.getArtifactBySha1(tenantAware.getCurrentTenant(), result2.getSha1Hash())) .isNotNull(); - artifactManagement.deleteArtifact(result2.getId()); + artifactManagement.delete(result2.getId()); assertThat(binaryArtifactRepository.getArtifactBySha1(tenantAware.getCurrentTenant(), result2.getSha1Hash())) .isNull(); @@ -204,9 +204,9 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest { final byte random[] = RandomStringUtils.random(5 * 1024).getBytes(); - final Artifact result = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", + final Artifact result = artifactManagement.create(new ByteArrayInputStream(random), sm.getId(), "file1", false); - final Artifact result2 = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm2.getId(), + final Artifact result2 = artifactManagement.create(new ByteArrayInputStream(random), sm2.getId(), "file2", false); assertThat(artifactRepository.findAll()).hasSize(2); @@ -216,11 +216,11 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest { assertThat(binaryArtifactRepository.getArtifactBySha1(tenantAware.getCurrentTenant(), result.getSha1Hash())) .isNotNull(); - artifactManagement.deleteArtifact(result.getId()); + artifactManagement.delete(result.getId()); assertThat(binaryArtifactRepository.getArtifactBySha1(tenantAware.getCurrentTenant(), result.getSha1Hash())) .isNotNull(); - artifactManagement.deleteArtifact(result2.getId()); + artifactManagement.delete(result2.getId()); assertThat(binaryArtifactRepository.getArtifactBySha1(tenantAware.getCurrentTenant(), result.getSha1Hash())) .isNull(); } @@ -228,10 +228,10 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Loads an local artifact based on given ID.") public void findArtifact() throws NoSuchAlgorithmException, IOException { - final Artifact result = artifactManagement.createArtifact(new RandomGeneratedInputStream(5 * 1024), + final Artifact result = artifactManagement.create(new RandomGeneratedInputStream(5 * 1024), testdataFactory.createSoftwareModuleOs().getId(), "file1", false); - assertThat(artifactManagement.findArtifact(result.getId()).get()).isEqualTo(result); + assertThat(artifactManagement.get(result.getId()).get()).isEqualTo(result); } @Test @@ -239,7 +239,7 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest { public void loadStreamOfArtifact() throws NoSuchAlgorithmException, IOException { final byte random[] = RandomStringUtils.random(5 * 1024).getBytes(); - final Artifact result = artifactManagement.createArtifact(new ByteArrayInputStream(random), + final Artifact result = artifactManagement.create(new ByteArrayInputStream(random), testdataFactory.createSoftwareModuleOs().getId(), "file1", false); try (InputStream fileInputStream = artifactManagement.loadArtifactBinary(result.getSha1Hash()).get() @@ -266,11 +266,11 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest { public void findArtifactBySoftwareModule() { final SoftwareModule sm = testdataFactory.createSoftwareModuleOs(); - assertThat(artifactManagement.findArtifactBySoftwareModule(PAGE, sm.getId())).isEmpty(); + assertThat(artifactManagement.findBySoftwareModule(PAGE, sm.getId())).isEmpty(); - artifactManagement.createArtifact(new RandomGeneratedInputStream(5 * 1024), sm.getId(), "file1", false); + artifactManagement.create(new RandomGeneratedInputStream(5 * 1024), sm.getId(), "file1", false); - assertThat(artifactManagement.findArtifactBySoftwareModule(PAGE, sm.getId())).hasSize(1); + assertThat(artifactManagement.findBySoftwareModule(PAGE, sm.getId())).hasSize(1); } @Test @@ -278,12 +278,12 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest { public void findByFilenameAndSoftwareModule() { final SoftwareModule sm = testdataFactory.createSoftwareModuleOs(); - assertThat(artifactManagement.findByFilenameAndSoftwareModule("file1", sm.getId())).isNotPresent(); + assertThat(artifactManagement.getByFilenameAndSoftwareModule("file1", sm.getId())).isNotPresent(); - artifactManagement.createArtifact(new RandomGeneratedInputStream(5 * 1024), sm.getId(), "file1", false); - artifactManagement.createArtifact(new RandomGeneratedInputStream(5 * 1024), sm.getId(), "file2", false); + artifactManagement.create(new RandomGeneratedInputStream(5 * 1024), sm.getId(), "file1", false); + artifactManagement.create(new RandomGeneratedInputStream(5 * 1024), sm.getId(), "file2", false); - assertThat(artifactManagement.findByFilenameAndSoftwareModule("file1", sm.getId())).isPresent(); + assertThat(artifactManagement.getByFilenameAndSoftwareModule("file1", sm.getId())).isPresent(); } } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ControllerManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ControllerManagementTest.java index 0ace0f03d..425452ec2 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ControllerManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ControllerManagementTest.java @@ -74,8 +74,8 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest { final SoftwareModule module = testdataFactory.createSoftwareModuleOs(); assertThat(controllerManagement.findActionWithDetails(NOT_EXIST_IDL)).isNotPresent(); - assertThat(controllerManagement.findByControllerId(NOT_EXIST_ID)).isNotPresent(); - assertThat(controllerManagement.findByTargetId(NOT_EXIST_IDL)).isNotPresent(); + assertThat(controllerManagement.getByControllerId(NOT_EXIST_ID)).isNotPresent(); + assertThat(controllerManagement.get(NOT_EXIST_IDL)).isNotPresent(); assertThat(controllerManagement.getActionForDownloadByTargetAndSoftwareModule(target.getControllerId(), module.getId())).isNotPresent(); @@ -308,8 +308,8 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest { final Long dsId = testdataFactory.createDistributionSet().getId(); testdataFactory.createTarget(); assignDistributionSet(dsId, TestdataFactory.DEFAULT_CONTROLLER_ID); - assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get() - .getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING); + assertThat(targetManagement.getByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get().getUpdateStatus()) + .isEqualTo(TargetUpdateStatus.PENDING); return deploymentManagement.findActiveActionsByTarget(PAGE, TestdataFactory.DEFAULT_CONTROLLER_ID).getContent() .get(0).getId(); @@ -364,7 +364,7 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest { private void assertActionStatus(final Long actionId, final String controllerId, final TargetUpdateStatus expectedTargetUpdateStatus, final Action.Status expectedActionActionStatus, final Action.Status expectedActionStatus, final boolean actionActive) { - final TargetUpdateStatus targetStatus = targetManagement.findTargetByControllerID(controllerId).get() + final TargetUpdateStatus targetStatus = targetManagement.getByControllerID(controllerId).get() .getUpdateStatus(); assertThat(targetStatus).isEqualTo(expectedTargetUpdateStatus); final Action action = deploymentManagement.findAction(actionId).get(); @@ -396,9 +396,9 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest { Target savedTarget = testdataFactory.createTarget(); // create two artifacts with identical SHA1 hash - final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random), + final Artifact artifact = artifactManagement.create(new ByteArrayInputStream(random), ds.findFirstModuleByType(osType).get().getId(), "file1", false); - final Artifact artifact2 = artifactManagement.createArtifact(new ByteArrayInputStream(random), + final Artifact artifact2 = artifactManagement.create(new ByteArrayInputStream(random), ds2.findFirstModuleByType(osType).get().getId(), "file1", false); assertThat(artifact.getSha1Hash()).isEqualTo(artifact2.getSha1Hash()); @@ -531,8 +531,8 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest { entityFactory.actionStatus().create(action.getId()).status(Action.Status.RUNNING)); // nothing changed as "feedback after close" is disabled - assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get() - .getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC); + assertThat(targetManagement.getByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get().getUpdateStatus()) + .isEqualTo(TargetUpdateStatus.IN_SYNC); assertThat(actionStatusRepository.count()).isEqualTo(3); assertThat(controllerManagement.findActionStatusByAction(PAGE, action.getId()).getNumberOfElements()) @@ -556,8 +556,8 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest { entityFactory.actionStatus().create(action.getId()).status(Action.Status.RUNNING)); // nothing changed as "feedback after close" is disabled - assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get() - .getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC); + assertThat(targetManagement.getByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get().getUpdateStatus()) + .isEqualTo(TargetUpdateStatus.IN_SYNC); // however, additional action status has been stored assertThat(actionStatusRepository.findAll(PAGE).getNumberOfElements()).isEqualTo(4); @@ -581,7 +581,7 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest { }); // verify that audit information has not changed - final Target targetVerify = targetManagement.findTargetByControllerID(controllerId).get(); + final Target targetVerify = targetManagement.getByControllerID(controllerId).get(); assertThat(targetVerify.getCreatedBy()).isEqualTo(target.getCreatedBy()); assertThat(targetVerify.getCreatedAt()).isEqualTo(target.getCreatedAt()); assertThat(targetVerify.getLastModifiedBy()).isEqualTo(target.getLastModifiedBy()); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DeploymentManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DeploymentManagementTest.java index ca798dec0..7c09b4d6b 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DeploymentManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DeploymentManagementTest.java @@ -40,6 +40,8 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaAction; import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; +import org.eclipse.hawkbit.repository.jpa.specifications.DistributionSetSpecification; +import org.eclipse.hawkbit.repository.jpa.specifications.SpecificationsBuilder; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.ActionType; import org.eclipse.hawkbit.repository.model.Action.Status; @@ -223,8 +225,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { // not exists assignDS.add(100L); - final DistributionSetTag tag = tagManagement - .createDistributionSetTag(entityFactory.tag().create().name("Tag1")); + final DistributionSetTag tag = distributionSetTagManagement.create(entityFactory.tag().create().name("Tag1")); assertThatExceptionOfType(EntityNotFoundException.class) .isThrownBy(() -> distributionSetManagement.assignTag(assignDS, tag.getId())) @@ -271,8 +272,8 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { final DistributionSet dsInstalled = action.getDistributionSet(); // check initial status - assertThat(targetManagement.findTargetByControllerID("4712").get().getUpdateStatus()) - .as("target has update status").isEqualTo(TargetUpdateStatus.IN_SYNC); + assertThat(targetManagement.getByControllerID("4712").get().getUpdateStatus()).as("target has update status") + .isEqualTo(TargetUpdateStatus.IN_SYNC); // assign the two sets in a row JpaAction firstAction = assignSet(target, dsFirst); @@ -289,7 +290,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { entityFactory.actionStatus().create(secondAction.getId()).status(Status.CANCELED)); assertThat(actionStatusRepository.findAll()).as("wrong size of actions status").hasSize(7); assertThat(deploymentManagement.getAssignedDistributionSet("4712").get()).as("wrong ds").isEqualTo(dsFirst); - assertThat(targetManagement.findTargetByControllerID("4712").get().getUpdateStatus()).as("wrong update status") + assertThat(targetManagement.getByControllerID("4712").get().getUpdateStatus()).as("wrong update status") .isEqualTo(TargetUpdateStatus.PENDING); // we cancel first -> back to installed @@ -301,7 +302,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { assertThat(actionStatusRepository.findAll()).as("wrong size of action status").hasSize(9); assertThat(deploymentManagement.getAssignedDistributionSet("4712").get()).as("wrong assigned ds") .isEqualTo(dsInstalled); - assertThat(targetManagement.findTargetByControllerID("4712").get().getUpdateStatus()).as("wrong update status") + assertThat(targetManagement.getByControllerID("4712").get().getUpdateStatus()).as("wrong update status") .isEqualTo(TargetUpdateStatus.IN_SYNC); } @@ -317,7 +318,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { final DistributionSet dsInstalled = action.getDistributionSet(); // check initial status - assertThat(targetManagement.findTargetByControllerID("4712").get().getUpdateStatus()).as("wrong update status") + assertThat(targetManagement.getByControllerID("4712").get().getUpdateStatus()).as("wrong update status") .isEqualTo(TargetUpdateStatus.IN_SYNC); // assign the two sets in a row @@ -336,8 +337,8 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { assertThat(actionStatusRepository.findAll()).as("wrong size of action status").hasSize(7); assertThat(deploymentManagement.getAssignedDistributionSet("4712").get()).as("wrong assigned ds") .isEqualTo(dsSecond); - assertThat(targetManagement.findTargetByControllerID("4712").get().getUpdateStatus()) - .as("wrong target update status").isEqualTo(TargetUpdateStatus.PENDING); + assertThat(targetManagement.getByControllerID("4712").get().getUpdateStatus()).as("wrong target update status") + .isEqualTo(TargetUpdateStatus.PENDING); // we cancel second -> remain assigned until finished cancellation deploymentManagement.cancelAction(secondAction.getId()); @@ -351,7 +352,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { // cancelled success -> back to dsInstalled assertThat(deploymentManagement.getAssignedDistributionSet("4712").get()).as("wrong installed ds") .isEqualTo(dsInstalled); - assertThat(targetManagement.findTargetByControllerID("4712").get().getUpdateStatus()) + assertThat(targetManagement.getByControllerID("4712").get().getUpdateStatus()) .as("wrong target info update status").isEqualTo(TargetUpdateStatus.IN_SYNC); } @@ -365,7 +366,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { final DistributionSet ds = testdataFactory.createDistributionSet("newDS", true); // verify initial status - assertThat(targetManagement.findTargetByControllerID("4712").get().getUpdateStatus()) + assertThat(targetManagement.getByControllerID("4712").get().getUpdateStatus()) .as("wrong target info update status").isEqualTo(TargetUpdateStatus.IN_SYNC); Action assigningAction = assignSet(target, ds); @@ -386,8 +387,8 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { assertThat(assigningAction.getStatus()).as("wrong size of status").isEqualTo(Status.CANCELED); assertThat(deploymentManagement.getAssignedDistributionSet("4712").get()).as("wrong assigned ds") .isEqualTo(dsInstalled); - assertThat(targetManagement.findTargetByControllerID("4712").get().getUpdateStatus()) - .as("wrong target update status").isEqualTo(TargetUpdateStatus.IN_SYNC); + assertThat(targetManagement.getByControllerID("4712").get().getUpdateStatus()).as("wrong target update status") + .isEqualTo(TargetUpdateStatus.IN_SYNC); } @Test @@ -399,7 +400,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { final DistributionSet ds = testdataFactory.createDistributionSet("newDS", true); // verify initial status - assertThat(targetManagement.findTargetByControllerID("4712").get().getUpdateStatus()).as("wrong update status") + assertThat(targetManagement.getByControllerID("4712").get().getUpdateStatus()).as("wrong update status") .isEqualTo(TargetUpdateStatus.IN_SYNC); final Action assigningAction = assignSet(target, ds); @@ -418,7 +419,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { private JpaAction assignSet(final Target target, final DistributionSet ds) { assignDistributionSet(ds.getId(), target.getControllerId()); - assertThat(targetManagement.findTargetByControllerID(target.getControllerId()).get().getUpdateStatus()) + assertThat(targetManagement.getByControllerID(target.getControllerId()).get().getUpdateStatus()) .as("wrong update status").isEqualTo(TargetUpdateStatus.PENDING); assertThat(deploymentManagement.getAssignedDistributionSet(target.getControllerId()).get()) .as("wrong assigned ds").isEqualTo(ds); @@ -450,9 +451,8 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { .getAssignedEntity(); assertThat(actionRepository.count()).isEqualTo(20); - assertThat(targetManagement.findTargetByInstalledDistributionSet(ds.getId(), PAGE).getContent()) - .containsAll(targets).hasSize(10) - .containsAll(targetManagement.findTargetByAssignedDistributionSet(ds.getId(), PAGE)) + assertThat(targetManagement.findByInstalledDistributionSet(PAGE, ds.getId()).getContent()).containsAll(targets) + .hasSize(10).containsAll(targetManagement.findByAssignedDistributionSet(PAGE, ds.getId())) .as("InstallationDate set").allMatch(target -> target.getInstallationDate() >= current) .as("TargetUpdateStatus IN_SYNC") .allMatch(target -> TargetUpdateStatus.IN_SYNC.equals(target.getUpdateStatus())) @@ -486,10 +486,10 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { // verify that one Action for each assignDistributionSet assertThat(actionRepository.findAll(PAGE).getNumberOfElements()).as("wrong size of actions").isEqualTo(20); - final Iterable allFoundTargets = targetManagement.findTargetsAll(PAGE).getContent(); + final Iterable allFoundTargets = targetManagement.findAll(PAGE).getContent(); // get final updated version of targets - savedDeployedTargets = targetManagement.findTargetsByControllerID( + savedDeployedTargets = targetManagement.getByControllerID( savedDeployedTargets.stream().map(target -> target.getControllerId()).collect(Collectors.toList())); assertThat(allFoundTargets).as("founded targets are wrong").containsAll(savedDeployedTargets) @@ -500,13 +500,13 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { .doesNotContain(Iterables.toArray(savedDeployedTargets, Target.class)); for (final Target myt : savedNakedTargets) { - final Target t = targetManagement.findTargetByControllerID(myt.getControllerId()).get(); + final Target t = targetManagement.getByControllerID(myt.getControllerId()).get(); assertThat(deploymentManagement.countActionsByTarget(t.getControllerId())).as("action should be empty") .isEqualTo(0L); } for (final Target myt : savedDeployedTargets) { - final Target t = targetManagement.findTargetByControllerID(myt.getControllerId()).get(); + final Target t = targetManagement.getByControllerID(myt.getControllerId()).get(); final List activeActionsByTarget = deploymentManagement .findActiveActionsByTarget(PAGE, t.getControllerId()).getContent(); assertThat(activeActionsByTarget).as("action should not be empty").isNotEmpty(); @@ -531,9 +531,8 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { final SoftwareModule ah = testdataFactory.createSoftwareModuleApp(); final SoftwareModule os = testdataFactory.createSoftwareModuleOs(); - final DistributionSet incomplete = distributionSetManagement - .createDistributionSet(entityFactory.distributionSet().create().name("incomplete").version("v1") - .type(standardDsType).modules(Arrays.asList(ah.getId()))); + final DistributionSet incomplete = distributionSetManagement.create(entityFactory.distributionSet().create() + .name("incomplete").version("v1").type(standardDsType).modules(Arrays.asList(ah.getId()))); try { assignDistributionSet(incomplete, targets); @@ -664,7 +663,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { .isEqualTo(dsC.getId()); assertThat(deploymentManagement.getInstalledDistributionSet(t.getControllerId())) .as("installed ds should not be null").isNotPresent(); - assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).get().getUpdateStatus()) + assertThat(targetManagement.getByControllerID(t.getControllerId()).get().getUpdateStatus()) .as("wrong target info update status").isEqualTo(TargetUpdateStatus.PENDING); } @@ -675,12 +674,12 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { // verify, that dsA is deployed correctly for (final Target t_ : updatedTsDsA) { - final Target t = targetManagement.findTargetByControllerID(t_.getControllerId()).get(); + final Target t = targetManagement.getByControllerID(t_.getControllerId()).get(); assertThat(deploymentManagement.getAssignedDistributionSet(t.getControllerId()).get()) .as("assigned ds is wrong").isEqualTo(dsA); assertThat(deploymentManagement.getInstalledDistributionSet(t.getControllerId()).get()) .as("installed ds is wrong").isEqualTo(dsA); - assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).get().getUpdateStatus()) + assertThat(targetManagement.getByControllerID(t.getControllerId()).get().getUpdateStatus()) .as("wrong target info update status").isEqualTo(TargetUpdateStatus.IN_SYNC); assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, t.getControllerId())) .as("no actions should be active").hasSize(0); @@ -695,19 +694,19 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { actionRepository.findByDistributionSetId(pageRequest, dsA.getId()).getContent().get(1); // get final updated version of targets - final List deployResWithDsBTargets = targetManagement.findTargetsByControllerID(deployResWithDsB + final List deployResWithDsBTargets = targetManagement.getByControllerID(deployResWithDsB .getDeployedTargets().stream().map(Target::getControllerId).collect(Collectors.toList())); assertThat(deployed2DS).as("deployed ds is wrong").containsAll(deployResWithDsBTargets); assertThat(deployed2DS).as("deployed ds is wrong").hasSameSizeAs(deployResWithDsBTargets); for (final Target t_ : deployed2DS) { - final Target t = targetManagement.findTargetByControllerID(t_.getControllerId()).get(); + final Target t = targetManagement.getByControllerID(t_.getControllerId()).get(); assertThat(deploymentManagement.getAssignedDistributionSet(t.getControllerId()).get()) .as("assigned ds is wrong").isEqualTo(dsA); assertThat(deploymentManagement.getInstalledDistributionSet(t.getControllerId())) .as("installed ds should be null").isNotPresent(); - assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).get().getUpdateStatus()) + assertThat(targetManagement.getByControllerID(t.getControllerId()).get().getUpdateStatus()) .as("wrong target info update status").isEqualTo(TargetUpdateStatus.PENDING); } @@ -739,42 +738,41 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { final DistributionSet dsA = testdataFactory.createDistributionSet(""); - distributionSetManagement.deleteDistributionSet(dsA.getId()); + distributionSetManagement.delete(dsA.getId()); - assertThat(distributionSetManagement.findDistributionSetById(dsA.getId())).isNotPresent(); + assertThat(distributionSetManagement.get(dsA.getId())).isNotPresent(); // // verify that the ds is not physically deleted for (final DistributionSet ds : deploymentResult.getDistributionSets()) { - distributionSetManagement.deleteDistributionSet(ds.getId()); - final DistributionSet foundDS = distributionSetManagement.findDistributionSetById(ds.getId()).get(); + distributionSetManagement.delete(ds.getId()); + final DistributionSet foundDS = distributionSetManagement.get(ds.getId()).get(); assertThat(foundDS).as("founded should not be null").isNotNull(); assertThat(foundDS.isDeleted()).as("found ds should be deleted").isTrue(); } // verify that deleted attribute is used correctly - List allFoundDS = distributionSetManagement - .findDistributionSetsByDeletedAndOrCompleted(PAGE, false, true).getContent(); + List allFoundDS = distributionSetManagement.findByCompleted(PAGE, true).getContent(); assertThat(allFoundDS.size()).as("no ds should be founded").isEqualTo(0); - allFoundDS = distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageRequest, true, true) - .getContent(); - assertThat(allFoundDS).as("wrong size of founded ds").hasSize(noOfDistributionSets); + + assertThat(distributionSetRepository.findAll(SpecificationsBuilder.combineWithAnd(Arrays + .asList(DistributionSetSpecification.isDeleted(true), DistributionSetSpecification.isCompleted(true))), + PAGE).getContent()).as("wrong size of founded ds").hasSize(noOfDistributionSets); for (final DistributionSet ds : deploymentResult.getDistributionSets()) { testdataFactory.sendUpdateActionStatusToTargets(deploymentResult.getDeployedTargets(), Status.FINISHED, Collections.singletonList("blabla alles gut")); } // try to delete again - distributionSetManagement.deleteDistributionSet(deploymentResult.getDistributionSetIDs()); + distributionSetManagement.delete(deploymentResult.getDistributionSetIDs()); // verify that the result is the same, even though distributionSet dsA // has been installed // successfully and no activeAction is referring to created distribution // sets - allFoundDS = distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageRequest, false, true) - .getContent(); + allFoundDS = distributionSetManagement.findByCompleted(pageRequest, true).getContent(); assertThat(allFoundDS.size()).as("no ds should be founded").isEqualTo(0); - allFoundDS = distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageRequest, true, true) - .getContent(); - assertThat(allFoundDS).as("size of founded ds is wrong").hasSize(noOfDistributionSets); + assertThat(distributionSetRepository.findAll(SpecificationsBuilder.combineWithAnd(Arrays + .asList(DistributionSetSpecification.isDeleted(true), DistributionSetSpecification.isCompleted(true))), + PAGE).getContent()).as("wrong size of founded ds").hasSize(noOfDistributionSets); } @@ -798,13 +796,13 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { Collections.singletonList("blabla alles gut")); } - assertThat(targetManagement.countTargetsAll()).as("size of targets is wrong").isNotZero(); + assertThat(targetManagement.count()).as("size of targets is wrong").isNotZero(); assertThat(actionStatusRepository.count()).as("size of action status is wrong").isNotZero(); - targetManagement.deleteTargets(deploymentResult.getUndeployedTargetIDs()); - targetManagement.deleteTargets(deploymentResult.getDeployedTargetIDs()); + targetManagement.delete(deploymentResult.getUndeployedTargetIDs()); + targetManagement.delete(deploymentResult.getDeployedTargetIDs()); - assertThat(targetManagement.countTargetsAll()).as("size of targets should be zero").isZero(); + assertThat(targetManagement.count()).as("size of targets should be zero").isZero(); assertThat(actionStatusRepository.count()).as("size of action status is wrong").isZero(); } @@ -818,13 +816,13 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { // doing the assignment targs = assignDistributionSet(dsA, targs).getAssignedEntity(); - Target targ = targetManagement.findTargetByControllerID(targs.iterator().next().getControllerId()).get(); + Target targ = targetManagement.getByControllerID(targs.iterator().next().getControllerId()).get(); // checking the revisions of the created entities // verifying that the revision of the object and the revision within the // DB has not changed - assertThat(dsA.getOptLockRevision()).as("lock revision is wrong").isEqualTo( - distributionSetManagement.findDistributionSetByIdWithDetails(dsA.getId()).get().getOptLockRevision()); + assertThat(dsA.getOptLockRevision()).as("lock revision is wrong") + .isEqualTo(distributionSetManagement.getWithDetails(dsA.getId()).get().getOptLockRevision()); // verifying that the assignment is correct assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, targ.getControllerId()).getTotalElements()) @@ -843,7 +841,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { controllerManagement.addUpdateActionStatus( entityFactory.actionStatus().create(updAct.getContent().get(0).getId()).status(Status.FINISHED)); - targ = targetManagement.findTargetByControllerID(targ.getControllerId()).get(); + targ = targetManagement.getByControllerID(targ.getControllerId()).get(); assertEquals("active target actions are wrong", 0, deploymentManagement.findActiveActionsByTarget(PAGE, targ.getControllerId()).getTotalElements()); @@ -863,7 +861,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { assertEquals("active actions are wrong", 1, deploymentManagement.findActiveActionsByTarget(PAGE, targ.getControllerId()).getTotalElements()); assertEquals("target status is wrong", TargetUpdateStatus.PENDING, - targetManagement.findTargetByControllerID(targ.getControllerId()).get().getUpdateStatus()); + targetManagement.getByControllerID(targ.getControllerId()).get().getUpdateStatus()); assertEquals("wrong assigned ds", dsB, deploymentManagement.getAssignedDistributionSet(targ.getControllerId()).get()); assertEquals("Installed ds is wrong", dsA.getId(), @@ -881,13 +879,13 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { testdataFactory.createDistributionSet("b"); final Target targ = testdataFactory.createTarget("target-id-A"); - assertThat(dsA.getOptLockRevision()).as("lock revision is wrong").isEqualTo( - distributionSetManagement.findDistributionSetByIdWithDetails(dsA.getId()).get().getOptLockRevision()); + assertThat(dsA.getOptLockRevision()).as("lock revision is wrong") + .isEqualTo(distributionSetManagement.getWithDetails(dsA.getId()).get().getOptLockRevision()); assignDistributionSet(dsA, Arrays.asList(targ)); - assertThat(dsA.getOptLockRevision()).as("lock revision is wrong").isEqualTo( - distributionSetManagement.findDistributionSetByIdWithDetails(dsA.getId()).get().getOptLockRevision()); + assertThat(dsA.getOptLockRevision()).as("lock revision is wrong") + .isEqualTo(distributionSetManagement.getWithDetails(dsA.getId()).get().getOptLockRevision()); } @Test @@ -1004,9 +1002,9 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { assertThat(event.getActionId()).as("Action id in database and event do not match") .isEqualTo(activeActionsByTarget.get(0).getId()); - assertThat(distributionSetManagement.findDistributionSetById(event.getDistributionSetId()).get() - .getModules()).as("softwaremodule size is not correct") - .containsOnly(ds.getModules().toArray(new SoftwareModule[ds.getModules().size()])); + assertThat(distributionSetManagement.get(event.getDistributionSetId()).get().getModules()) + .as("softwaremodule size is not correct") + .containsOnly(ds.getModules().toArray(new SoftwareModule[ds.getModules().size()])); } } assertThat(found).as("No event found for controller " + myt.getControllerId()).isTrue(); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DistributionSetManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DistributionSetManagementTest.java index 2c843061f..42d3192be 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DistributionSetManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DistributionSetManagementTest.java @@ -73,11 +73,10 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest { @Expect(type = SoftwareModuleCreatedEvent.class, count = 3) }) public void nonExistingEntityAccessReturnsNotPresent() { final DistributionSet set = testdataFactory.createDistributionSet(); - assertThat(distributionSetManagement.findDistributionSetById(NOT_EXIST_IDL)).isNotPresent(); - assertThat(distributionSetManagement.findDistributionSetByIdWithDetails(NOT_EXIST_IDL)).isNotPresent(); - assertThat(distributionSetManagement.findDistributionSetByNameAndVersion(NOT_EXIST_ID, NOT_EXIST_ID)) - .isNotPresent(); - assertThat(distributionSetManagement.findDistributionSetMetadata(set.getId(), NOT_EXIST_ID)).isNotPresent(); + assertThat(distributionSetManagement.get(NOT_EXIST_IDL)).isNotPresent(); + assertThat(distributionSetManagement.getWithDetails(NOT_EXIST_IDL)).isNotPresent(); + assertThat(distributionSetManagement.getByNameAndVersion(NOT_EXIST_ID, NOT_EXIST_ID)).isNotPresent(); + assertThat(distributionSetManagement.getMetaDataByDistributionSetId(set.getId(), NOT_EXIST_ID)).isNotPresent(); } @@ -99,6 +98,8 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest { () -> distributionSetManagement.assignSoftwareModules(set.getId(), Arrays.asList(NOT_EXIST_IDL)), "SoftwareModule"); + verifyThrownExceptionBy(() -> distributionSetManagement.countByTypeId(NOT_EXIST_IDL), "DistributionSet"); + verifyThrownExceptionBy(() -> distributionSetManagement.unassignSoftwareModule(NOT_EXIST_IDL, module.getId()), "DistributionSet"); verifyThrownExceptionBy(() -> distributionSetManagement.unassignSoftwareModule(set.getId(), NOT_EXIST_IDL), @@ -110,10 +111,8 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest { verifyThrownExceptionBy(() -> distributionSetManagement.assignTag(Arrays.asList(NOT_EXIST_IDL), dsTag.getId()), "DistributionSet"); - verifyThrownExceptionBy(() -> distributionSetManagement.findDistributionSetsByTag(PAGE, NOT_EXIST_IDL), - "DistributionSetTag"); - verifyThrownExceptionBy( - () -> distributionSetManagement.findDistributionSetsByTag(PAGE, "name==*", NOT_EXIST_IDL), + verifyThrownExceptionBy(() -> distributionSetManagement.findByTag(PAGE, NOT_EXIST_IDL), "DistributionSetTag"); + verifyThrownExceptionBy(() -> distributionSetManagement.findByRsqlAndTag(PAGE, "name==*", NOT_EXIST_IDL), "DistributionSetTag"); verifyThrownExceptionBy( @@ -131,47 +130,44 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest { verifyThrownExceptionBy( () -> distributionSetManagement - .createDistributionSet(entityFactory.distributionSet().create().name("xxx").type(NOT_EXIST_ID)), + .create(entityFactory.distributionSet().create().name("xxx").type(NOT_EXIST_ID)), "DistributionSetType"); - verifyThrownExceptionBy(() -> distributionSetManagement.createDistributionSetMetadata(NOT_EXIST_IDL, + verifyThrownExceptionBy(() -> distributionSetManagement.createMetaData(NOT_EXIST_IDL, Arrays.asList(entityFactory.generateMetadata("123", "123"))), "DistributionSet"); - verifyThrownExceptionBy(() -> distributionSetManagement.deleteDistributionSet(Arrays.asList(NOT_EXIST_IDL)), + verifyThrownExceptionBy(() -> distributionSetManagement.delete(Arrays.asList(NOT_EXIST_IDL)), "DistributionSet"); - verifyThrownExceptionBy(() -> distributionSetManagement.deleteDistributionSet(NOT_EXIST_IDL), + verifyThrownExceptionBy(() -> distributionSetManagement.delete(NOT_EXIST_IDL), "DistributionSet"); + verifyThrownExceptionBy(() -> distributionSetManagement.deleteMetaData(NOT_EXIST_IDL, "xxx"), "DistributionSet"); - verifyThrownExceptionBy(() -> distributionSetManagement.deleteDistributionSetMetadata(NOT_EXIST_IDL, "xxx"), - "DistributionSet"); - verifyThrownExceptionBy( - () -> distributionSetManagement.deleteDistributionSetMetadata(set.getId(), NOT_EXIST_ID), + verifyThrownExceptionBy(() -> distributionSetManagement.deleteMetaData(set.getId(), NOT_EXIST_ID), "DistributionSetMetadata"); - verifyThrownExceptionBy(() -> distributionSetManagement.findDistributionSetByAction(NOT_EXIST_IDL), "Action"); + verifyThrownExceptionBy(() -> distributionSetManagement.getByAction(NOT_EXIST_IDL), "Action"); - verifyThrownExceptionBy(() -> distributionSetManagement.findDistributionSetMetadata(NOT_EXIST_IDL, "xxx"), + verifyThrownExceptionBy(() -> distributionSetManagement.getMetaDataByDistributionSetId(NOT_EXIST_IDL, "xxx"), + "DistributionSet"); + + verifyThrownExceptionBy(() -> distributionSetManagement.findMetaDataByDistributionSetId(PAGE, NOT_EXIST_IDL), "DistributionSet"); verifyThrownExceptionBy( - () -> distributionSetManagement.findDistributionSetMetadataByDistributionSetId(NOT_EXIST_IDL, PAGE), + () -> distributionSetManagement.findMetaDataByDistributionSetIdAndRsql(PAGE, NOT_EXIST_IDL, "name==*"), "DistributionSet"); - verifyThrownExceptionBy(() -> distributionSetManagement - .findDistributionSetMetadataByDistributionSetId(NOT_EXIST_IDL, "name==*", PAGE), "DistributionSet"); - - assertThatThrownBy(() -> distributionSetManagement.isDistributionSetInUse(NOT_EXIST_IDL)) + assertThatThrownBy(() -> distributionSetManagement.isInUse(NOT_EXIST_IDL)) .isInstanceOf(EntityNotFoundException.class).hasMessageContaining(NOT_EXIST_ID) .hasMessageContaining("DistributionSet"); verifyThrownExceptionBy( - () -> distributionSetManagement - .updateDistributionSet(entityFactory.distributionSet().update(NOT_EXIST_IDL)), + () -> distributionSetManagement.update(entityFactory.distributionSet().update(NOT_EXIST_IDL)), "DistributionSet"); - verifyThrownExceptionBy(() -> distributionSetManagement.updateDistributionSetMetadata(NOT_EXIST_IDL, + verifyThrownExceptionBy(() -> distributionSetManagement.updateMetaData(NOT_EXIST_IDL, entityFactory.generateMetadata("xxx", "xxx")), "DistributionSet"); - verifyThrownExceptionBy(() -> distributionSetManagement.updateDistributionSetMetadata(set.getId(), + verifyThrownExceptionBy(() -> distributionSetManagement.updateMetaData(set.getId(), entityFactory.generateMetadata(NOT_EXIST_ID, "xxx")), "DistributionSetMetadata"); } @@ -192,13 +188,13 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest { private void createAndUpdateDistributionSetWithInvalidDescription(final DistributionSet set) { assertThatExceptionOfType(ConstraintViolationException.class) - .isThrownBy(() -> distributionSetManagement.createDistributionSet(entityFactory.distributionSet() - .create().name("a").version("a").description(RandomStringUtils.randomAlphanumeric(513)))) + .isThrownBy(() -> distributionSetManagement.create(entityFactory.distributionSet().create().name("a") + .version("a").description(RandomStringUtils.randomAlphanumeric(513)))) .as("entity with too long description should not be created"); assertThatExceptionOfType(ConstraintViolationException.class) - .isThrownBy(() -> distributionSetManagement.updateDistributionSet(entityFactory.distributionSet() - .update(set.getId()).description(RandomStringUtils.randomAlphanumeric(513)))) + .isThrownBy(() -> distributionSetManagement.update(entityFactory.distributionSet().update(set.getId()) + .description(RandomStringUtils.randomAlphanumeric(513)))) .as("entity with too long description should not be updated"); } @@ -207,23 +203,21 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest { private void createAndUpdateDistributionSetWithInvalidName(final DistributionSet set) { assertThatExceptionOfType(ConstraintViolationException.class) - .isThrownBy(() -> distributionSetManagement.createDistributionSet(entityFactory.distributionSet() - .create().version("a").name(RandomStringUtils.randomAlphanumeric(65)))) + .isThrownBy(() -> distributionSetManagement.create(entityFactory.distributionSet().create().version("a") + .name(RandomStringUtils.randomAlphanumeric(65)))) + .as("entity with too long name should not be created"); + + assertThatExceptionOfType(ConstraintViolationException.class).isThrownBy( + () -> distributionSetManagement.create(entityFactory.distributionSet().create().version("a").name(""))) .as("entity with too long name should not be created"); assertThatExceptionOfType(ConstraintViolationException.class) - .isThrownBy(() -> distributionSetManagement - .createDistributionSet(entityFactory.distributionSet().create().version("a").name(""))) - .as("entity with too long name should not be created"); - - assertThatExceptionOfType(ConstraintViolationException.class) - .isThrownBy(() -> distributionSetManagement.updateDistributionSet(entityFactory.distributionSet() - .update(set.getId()).name(RandomStringUtils.randomAlphanumeric(65)))) + .isThrownBy(() -> distributionSetManagement.update(entityFactory.distributionSet().update(set.getId()) + .name(RandomStringUtils.randomAlphanumeric(65)))) .as("entity with too long name should not be updated"); - assertThatExceptionOfType(ConstraintViolationException.class) - .isThrownBy(() -> distributionSetManagement - .updateDistributionSet(entityFactory.distributionSet().update(set.getId()).name(""))) + assertThatExceptionOfType(ConstraintViolationException.class).isThrownBy( + () -> distributionSetManagement.update(entityFactory.distributionSet().update(set.getId()).name(""))) .as("entity with too short name should not be updated"); } @@ -232,23 +226,21 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest { private void createAndUpdateDistributionSetWithInvalidVersion(final DistributionSet set) { assertThatExceptionOfType(ConstraintViolationException.class) - .isThrownBy(() -> distributionSetManagement.createDistributionSet(entityFactory.distributionSet() - .create().name("a").version(RandomStringUtils.randomAlphanumeric(65)))) + .isThrownBy(() -> distributionSetManagement.create(entityFactory.distributionSet().create().name("a") + .version(RandomStringUtils.randomAlphanumeric(65)))) + .as("entity with too long name should not be created"); + + assertThatExceptionOfType(ConstraintViolationException.class).isThrownBy( + () -> distributionSetManagement.create(entityFactory.distributionSet().create().name("a").version(""))) .as("entity with too long name should not be created"); assertThatExceptionOfType(ConstraintViolationException.class) - .isThrownBy(() -> distributionSetManagement - .createDistributionSet(entityFactory.distributionSet().create().name("a").version(""))) - .as("entity with too long name should not be created"); - - assertThatExceptionOfType(ConstraintViolationException.class) - .isThrownBy(() -> distributionSetManagement.updateDistributionSet(entityFactory.distributionSet() - .update(set.getId()).version(RandomStringUtils.randomAlphanumeric(65)))) + .isThrownBy(() -> distributionSetManagement.update(entityFactory.distributionSet().update(set.getId()) + .version(RandomStringUtils.randomAlphanumeric(65)))) .as("entity with too long name should not be updated"); - assertThatExceptionOfType(ConstraintViolationException.class) - .isThrownBy(() -> distributionSetManagement - .updateDistributionSet(entityFactory.distributionSet().update(set.getId()).version(""))) + assertThatExceptionOfType(ConstraintViolationException.class).isThrownBy( + () -> distributionSetManagement.update(entityFactory.distributionSet().update(set.getId()).version(""))) .as("entity with too short name should not be updated"); } @@ -266,7 +258,7 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest { @Description("Verifies that a DS is of default type if not specified explicitly at creation time.") public void createDistributionSetWithImplicitType() { final DistributionSet set = distributionSetManagement - .createDistributionSet(entityFactory.distributionSet().create().name("newtypesoft").version("1")); + .create(entityFactory.distributionSet().create().name("newtypesoft").version("1")); assertThat(set.getType()).as("Type should be equal to default type of tenant") .isEqualTo(systemManagement.getTenantMetadata().getDefaultDsType()); @@ -276,11 +268,10 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Verifies that a DS cannot be created if another DS with same name and version exists.") public void createDistributionSetWithDuplicateNameAndVersionFails() { - distributionSetManagement - .createDistributionSet(entityFactory.distributionSet().create().name("newtypesoft").version("1")); + distributionSetManagement.create(entityFactory.distributionSet().create().name("newtypesoft").version("1")); assertThatExceptionOfType(EntityAlreadyExistsException.class).isThrownBy(() -> distributionSetManagement - .createDistributionSet(entityFactory.distributionSet().create().name("newtypesoft").version("1"))); + .create(entityFactory.distributionSet().create().name("newtypesoft").version("1"))); } @@ -293,7 +284,7 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest { creates.add(entityFactory.distributionSet().create().name("newtypesoft" + i).version("1" + i)); } - final List sets = distributionSetManagement.createDistributionSets(creates); + final List sets = distributionSetManagement.create(creates); assertThat(sets).as("Type should be equal to default type of tenant").are(new Condition() { @Override @@ -330,33 +321,30 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest { assignDS.add(testdataFactory.createDistributionSet("DS" + i, "1.0", Collections.emptyList()).getId()); } - final DistributionSetTag tag = tagManagement - .createDistributionSetTag(entityFactory.tag().create().name("Tag1")); + final DistributionSetTag tag = distributionSetTagManagement.create(entityFactory.tag().create().name("Tag1")); final List assignedDS = distributionSetManagement.assignTag(assignDS, tag.getId()); assertThat(assignedDS.size()).as("assigned ds has wrong size").isEqualTo(4); assignedDS.stream().map(c -> (JpaDistributionSet) c) .forEach(ds -> assertThat(ds.getTags().size()).as("ds has wrong tag size").isEqualTo(1)); - DistributionSetTag findDistributionSetTag = tagManagement.findDistributionSetTag("Tag1").get(); + DistributionSetTag findDistributionSetTag = distributionSetTagManagement.getByName("Tag1").get(); - assertThat(assignedDS.size()).as("assigned ds has wrong size").isEqualTo( - distributionSetManagement.findDistributionSetsByTag(PAGE, tag.getId()).getNumberOfElements()); + assertThat(assignedDS.size()).as("assigned ds has wrong size") + .isEqualTo(distributionSetManagement.findByTag(PAGE, tag.getId()).getNumberOfElements()); final JpaDistributionSet unAssignDS = (JpaDistributionSet) distributionSetManagement .unAssignTag(assignDS.get(0), findDistributionSetTag.getId()); assertThat(unAssignDS.getId()).as("unassigned ds is wrong").isEqualTo(assignDS.get(0)); assertThat(unAssignDS.getTags().size()).as("unassigned ds has wrong tag size").isEqualTo(0); - findDistributionSetTag = tagManagement.findDistributionSetTag("Tag1").get(); - assertThat(distributionSetManagement.findDistributionSetsByTag(PAGE, tag.getId()).getNumberOfElements()) + findDistributionSetTag = distributionSetTagManagement.getByName("Tag1").get(); + assertThat(distributionSetManagement.findByTag(PAGE, tag.getId()).getNumberOfElements()) .as("ds tag ds has wrong ds size").isEqualTo(3); - assertThat(distributionSetManagement - .findDistributionSetsByTag(PAGE, "name==" + unAssignDS.getName(), tag.getId()).getNumberOfElements()) - .as("ds tag ds has wrong ds size").isEqualTo(0); - assertThat(distributionSetManagement - .findDistributionSetsByTag(PAGE, "name!=" + unAssignDS.getName(), tag.getId()).getNumberOfElements()) - .as("ds tag ds has wrong ds size").isEqualTo(3); + assertThat(distributionSetManagement.findByRsqlAndTag(PAGE, "name==" + unAssignDS.getName(), tag.getId()) + .getNumberOfElements()).as("ds tag ds has wrong ds size").isEqualTo(0); + assertThat(distributionSetManagement.findByRsqlAndTag(PAGE, "name!=" + unAssignDS.getName(), tag.getId()) + .getNumberOfElements()).as("ds tag ds has wrong ds size").isEqualTo(3); } @Test @@ -375,7 +363,7 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest { // assign target assignDistributionSet(ds.getId(), target.getControllerId()); - ds = distributionSetManagement.findDistributionSetByIdWithDetails(ds.getId()).get(); + ds = distributionSetManagement.getWithDetails(ds.getId()).get(); final Long dsId = ds.getId(); // not allowed as it is assigned now @@ -392,14 +380,13 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest { @Description("Ensures that it is not possible to add a software module that is not defined of the DS's type.") public void updateDistributionSetUnsupportedModuleFails() { final DistributionSet set = distributionSetManagement - .createDistributionSet( - entityFactory.distributionSet().create().name("agent-hub2").version("1.0.5") - .type(distributionSetTypeManagement - .createDistributionSetType(entityFactory.distributionSetType().create() - .key("test").name("test").mandatory(Arrays.asList(osType.getId()))) - .getKey())); + .create(entityFactory.distributionSet().create().name("agent-hub2") + .version( + "1.0.5") + .type(distributionSetTypeManagement.create(entityFactory.distributionSetType().create() + .key("test").name("test").mandatory(Arrays.asList(osType.getId()))).getKey())); - final SoftwareModule module = softwareModuleManagement.createSoftwareModule( + final SoftwareModule module = softwareModuleManagement.create( entityFactory.softwareModule().create().name("agent-hub2").version("1.0.5").type(appType.getKey())); // update data @@ -418,19 +405,18 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest { // update data // legal update of module addition distributionSetManagement.assignSoftwareModules(ds.getId(), Sets.newHashSet(os.getId())); - ds = distributionSetManagement.findDistributionSetByIdWithDetails(ds.getId()).get(); + ds = distributionSetManagement.getWithDetails(ds.getId()).get(); assertThat(ds.findFirstModuleByType(osType).get()).isEqualTo(os); // legal update of module removal distributionSetManagement.unassignSoftwareModule(ds.getId(), ds.findFirstModuleByType(appType).get().getId()); - ds = distributionSetManagement.findDistributionSetByIdWithDetails(ds.getId()).get(); + ds = distributionSetManagement.getWithDetails(ds.getId()).get(); assertThat(ds.findFirstModuleByType(appType).isPresent()).isFalse(); // Update description - distributionSetManagement - .updateDistributionSet(entityFactory.distributionSet().update(ds.getId()).name("a new name") - .description("a new description").version("a new version").requiredMigrationStep(true)); - ds = distributionSetManagement.findDistributionSetByIdWithDetails(ds.getId()).get(); + distributionSetManagement.update(entityFactory.distributionSet().update(ds.getId()).name("a new name") + .description("a new description").version("a new version").requiredMigrationStep(true)); + ds = distributionSetManagement.getWithDetails(ds.getId()).get(); assertThat(ds.getDescription()).isEqualTo("a new description"); assertThat(ds.getName()).isEqualTo("a new name"); assertThat(ds.getVersion()).isEqualTo("a new version"); @@ -453,18 +439,18 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest { // create an DS meta data entry createDistributionSetMetadata(ds.getId(), new JpaDistributionSetMetadata(knownKey, ds, knownValue)); - DistributionSet changedLockRevisionDS = distributionSetManagement.findDistributionSetById(ds.getId()).get(); + DistributionSet changedLockRevisionDS = distributionSetManagement.get(ds.getId()).get(); assertThat(changedLockRevisionDS.getOptLockRevision()).isEqualTo(2); Thread.sleep(100); // update the DS metadata final JpaDistributionSetMetadata updated = (JpaDistributionSetMetadata) distributionSetManagement - .updateDistributionSetMetadata(ds.getId(), entityFactory.generateMetadata(knownKey, knownUpdateValue)); + .updateMetaData(ds.getId(), entityFactory.generateMetadata(knownKey, knownUpdateValue)); // we are updating the sw meta data so also modifying the base software // module so opt lock // revision must be three - changedLockRevisionDS = distributionSetManagement.findDistributionSetById(ds.getId()).get(); + changedLockRevisionDS = distributionSetManagement.get(ds.getId()).get(); assertThat(changedLockRevisionDS.getOptLockRevision()).isEqualTo(3); assertThat(changedLockRevisionDS.getLastModifiedAt()).isGreaterThan(0L); @@ -505,15 +491,19 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest { .setIsDeleted(false).setIsComplete(true).setSelectDSWithNoTag(Boolean.FALSE); // target first only has an assigned DS-three so check order correct - final List tFirstPin = distributionSetManagement.findDistributionSetsAllOrderedByLinkTarget( - PAGE, distributionSetFilterBuilder, tFirst.getControllerId()).getContent(); + final List tFirstPin = distributionSetManagement + .findByFilterAndAssignedInstalledDsOrderedByLinkTarget(PAGE, distributionSetFilterBuilder, + tFirst.getControllerId()) + .getContent(); assertThat(tFirstPin.get(0)).isEqualTo(dsThree); assertThat(tFirstPin).hasSize(10); // target second has installed DS-2 and assigned DS-4 so check order // correct - final List tSecondPin = distributionSetManagement.findDistributionSetsAllOrderedByLinkTarget( - PAGE, distributionSetFilterBuilder, tSecond.getControllerId()).getContent(); + final List tSecondPin = distributionSetManagement + .findByFilterAndAssignedInstalledDsOrderedByLinkTarget(PAGE, distributionSetFilterBuilder, + tSecond.getControllerId()) + .getContent(); assertThat(tSecondPin.get(0)).isEqualTo(dsSecond); assertThat(tSecondPin.get(1)).isEqualTo(dsFour); assertThat(tFirstPin).hasSize(10); @@ -522,35 +512,35 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest { @Test @Description("searches for distribution sets based on the various filter options, e.g. name, version, desc., tags.") public void searchDistributionSetsOnFilters() { - DistributionSetTag dsTagA = tagManagement - .createDistributionSetTag(entityFactory.tag().create().name("DistributionSetTag-A")); - final DistributionSetTag dsTagB = tagManagement - .createDistributionSetTag(entityFactory.tag().create().name("DistributionSetTag-B")); - final DistributionSetTag dsTagC = tagManagement - .createDistributionSetTag(entityFactory.tag().create().name("DistributionSetTag-C")); - tagManagement.createDistributionSetTag(entityFactory.tag().create().name("DistributionSetTag-D")); + DistributionSetTag dsTagA = distributionSetTagManagement + .create(entityFactory.tag().create().name("DistributionSetTag-A")); + final DistributionSetTag dsTagB = distributionSetTagManagement + .create(entityFactory.tag().create().name("DistributionSetTag-B")); + final DistributionSetTag dsTagC = distributionSetTagManagement + .create(entityFactory.tag().create().name("DistributionSetTag-C")); + distributionSetTagManagement.create(entityFactory.tag().create().name("DistributionSetTag-D")); List ds5Group1 = testdataFactory.createDistributionSets("", 5); List dsGroup2 = testdataFactory.createDistributionSets("test2", 5); DistributionSet dsDeleted = testdataFactory.createDistributionSet("deleted"); - final DistributionSet dsInComplete = distributionSetManagement.createDistributionSet(entityFactory - .distributionSet().create().name("notcomplete").version("1").type(standardDsType.getKey())); + final DistributionSet dsInComplete = distributionSetManagement.create(entityFactory.distributionSet().create() + .name("notcomplete").version("1").type(standardDsType.getKey())); - DistributionSetType newType = distributionSetTypeManagement.createDistributionSetType( - entityFactory.distributionSetType().create().key("foo").name("bar").description("test")); + DistributionSetType newType = distributionSetTypeManagement + .create(entityFactory.distributionSetType().create().key("foo").name("bar").description("test")); distributionSetTypeManagement.assignMandatorySoftwareModuleTypes(newType.getId(), Arrays.asList(osType.getId())); newType = distributionSetTypeManagement.assignOptionalSoftwareModuleTypes(newType.getId(), Arrays.asList(appType.getId(), runtimeType.getId())); - final DistributionSet dsNewType = distributionSetManagement.createDistributionSet( + final DistributionSet dsNewType = distributionSetManagement.create( entityFactory.distributionSet().create().name("newtype").version("1").type(newType.getKey()).modules( dsDeleted.getModules().stream().map(SoftwareModule::getId).collect(Collectors.toList()))); assignDistributionSet(dsDeleted, testdataFactory.createTargets(5)); - distributionSetManagement.deleteDistributionSet(dsDeleted.getId()); - dsDeleted = distributionSetManagement.findDistributionSetById(dsDeleted.getId()).get(); + distributionSetManagement.delete(dsDeleted.getId()); + dsDeleted = distributionSetManagement.get(dsDeleted.getId()).get(); ds5Group1 = toggleTagAssignment(ds5Group1, dsTagA).getAssignedEntity(); dsTagA = distributionSetTagRepository.findByNameEquals(dsTagA.getName()).get(); @@ -571,18 +561,18 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest { expected.add(dsNewType); assertThat(distributionSetManagement - .findDistributionSetsByFilters(PAGE, getDistributionSetFilterBuilder().build()).getContent()) - .hasSize(13).containsOnly(expected.toArray(new DistributionSet[0])); + .findByDistributionSetFilter(PAGE, getDistributionSetFilterBuilder().build()).getContent()).hasSize(13) + .containsOnly(expected.toArray(new DistributionSet[0])); DistributionSetFilterBuilder distributionSetFilterBuilder; // search for not deleted distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsDeleted(Boolean.TRUE); - assertThat(distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()) + assertThat(distributionSetManagement.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build()) .getContent()).hasSize(1); distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsDeleted(false); - assertThat(distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()) + assertThat(distributionSetManagement.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build()) .getContent()).hasSize(12); // search for completed @@ -593,50 +583,50 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest { expected.add(dsNewType); distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(true); - assertThat(distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()) + assertThat(distributionSetManagement.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build()) .getContent()).hasSize(12).containsOnly(expected.toArray(new DistributionSet[0])); distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.FALSE); expected = new ArrayList<>(); expected.add(dsInComplete); - assertThat(distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()) + assertThat(distributionSetManagement.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build()) .getContent()).hasSize(1).containsOnly(expected.toArray(new DistributionSet[0])); // search for type distributionSetFilterBuilder = getDistributionSetFilterBuilder().setType(newType); - assertThat(distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()) + assertThat(distributionSetManagement.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build()) .getContent()).hasSize(1); distributionSetFilterBuilder = getDistributionSetFilterBuilder().setType(standardDsType); - assertThat(distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()) + assertThat(distributionSetManagement.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build()) .getContent()).hasSize(12); // search for text distributionSetFilterBuilder = getDistributionSetFilterBuilder().setSearchText("%test2"); - assertThat(distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()) + assertThat(distributionSetManagement.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build()) .getContent()).hasSize(5); // search for tags distributionSetFilterBuilder = getDistributionSetFilterBuilder().setTagNames(Arrays.asList(dsTagA.getName())); - assertThat(distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()) + assertThat(distributionSetManagement.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build()) .getContent()).hasSize(10); distributionSetFilterBuilder = getDistributionSetFilterBuilder().setTagNames(Arrays.asList(dsTagB.getName())); - assertThat(distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()) + assertThat(distributionSetManagement.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build()) .getContent()).hasSize(5); distributionSetFilterBuilder = getDistributionSetFilterBuilder() .setTagNames(Arrays.asList(dsTagA.getName(), dsTagB.getName())); - assertThat(distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()) + assertThat(distributionSetManagement.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build()) .getContent()).hasSize(10); distributionSetFilterBuilder = getDistributionSetFilterBuilder() .setTagNames(Arrays.asList(dsTagC.getName(), dsTagB.getName())); - assertThat(distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()) + assertThat(distributionSetManagement.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build()) .getContent()).hasSize(5); distributionSetFilterBuilder = getDistributionSetFilterBuilder().setTagNames(Arrays.asList(dsTagC.getName())); - assertThat(distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()) + assertThat(distributionSetManagement.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build()) .getContent()).hasSize(0); // combine deleted and complete @@ -647,23 +637,23 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest { distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE) .setIsDeleted(Boolean.FALSE); - assertThat(distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()) + assertThat(distributionSetManagement.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build()) .getContent()).hasSize(11).containsOnly(expected.toArray(new DistributionSet[0])); expected = Arrays.asList(dsInComplete); distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.FALSE); - assertThat(distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()) + assertThat(distributionSetManagement.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build()) .getContent()).hasSize(1).containsOnly(expected.toArray(new DistributionSet[0])); expected = Arrays.asList(dsDeleted); distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE) .setIsDeleted(Boolean.TRUE); - assertThat(distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()) + assertThat(distributionSetManagement.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build()) .getContent()).hasSize(1).containsOnly(expected.toArray(new DistributionSet[0])); distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsDeleted(Boolean.TRUE) .setIsComplete(Boolean.FALSE); - assertThat(distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()) + assertThat(distributionSetManagement.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build()) .getContent()).hasSize(0); // combine deleted and complete and type @@ -672,57 +662,57 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest { expected.addAll(dsGroup2); distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsDeleted(Boolean.FALSE) .setIsComplete(Boolean.TRUE).setType(standardDsType); - assertThat(distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()) + assertThat(distributionSetManagement.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build()) .getContent()).hasSize(10).containsOnly(expected.toArray(new DistributionSet[0])); expected = Arrays.asList(dsDeleted); distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE) .setType(standardDsType).setIsDeleted(Boolean.TRUE); - assertThat(distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()) + assertThat(distributionSetManagement.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build()) .getContent()).hasSize(1).containsOnly(expected.toArray(new DistributionSet[0])); distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsDeleted(Boolean.TRUE) .setIsComplete(Boolean.FALSE).setType(standardDsType); - assertThat(distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()) + assertThat(distributionSetManagement.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build()) .getContent()).hasSize(0); expected = Arrays.asList(dsNewType); distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE).setType(newType); - assertThat(distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()) + assertThat(distributionSetManagement.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build()) .getContent()).hasSize(1).containsOnly(expected.toArray(new DistributionSet[0])); // combine deleted and complete and type and text expected = dsGroup2; distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE) .setType(standardDsType).setSearchText("%test2"); - assertThat(distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()) + assertThat(distributionSetManagement.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build()) .getContent()).hasSize(5).containsOnly(expected.toArray(new DistributionSet[0])); distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE) .setIsDeleted(Boolean.TRUE).setType(standardDsType).setSearchText("%test2"); - assertThat(distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()) + assertThat(distributionSetManagement.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build()) .getContent()).hasSize(0); distributionSetFilterBuilder = getDistributionSetFilterBuilder().setType(standardDsType).setSearchText("%test2") .setIsComplete(false).setIsDeleted(false); - assertThat(distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()) + assertThat(distributionSetManagement.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build()) .getContent()).hasSize(0); distributionSetFilterBuilder = getDistributionSetFilterBuilder().setType(newType).setSearchText("%test2") .setIsComplete(Boolean.TRUE).setIsDeleted(false); - assertThat(distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()) + assertThat(distributionSetManagement.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build()) .getContent()).hasSize(0); // combine deleted and complete and type and text and tag expected = dsGroup2; distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(true).setType(standardDsType) .setSearchText("%test2").setTagNames(Arrays.asList(dsTagA.getName())); - assertThat(distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()) + assertThat(distributionSetManagement.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build()) .getContent()).hasSize(5).containsOnly(expected.toArray(new DistributionSet[0])); distributionSetFilterBuilder = getDistributionSetFilterBuilder().setType(standardDsType).setSearchText("%test2") .setTagNames(Arrays.asList(dsTagA.getName())).setIsComplete(Boolean.FALSE).setIsDeleted(Boolean.FALSE); - assertThat(distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()) + assertThat(distributionSetManagement.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build()) .getContent()).hasSize(0); } @@ -736,8 +726,7 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest { public void findDistributionSetsWithoutLazy() { testdataFactory.createDistributionSets(20); - assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(PAGE, false, true)) - .hasSize(20); + assertThat(distributionSetManagement.findByCompleted(PAGE, true)).hasSize(20); } @Test @@ -748,12 +737,10 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest { // delete a ds assertThat(distributionSetRepository.findAll()).hasSize(2); - distributionSetManagement.deleteDistributionSet(ds1.getId()); + distributionSetManagement.delete(ds1.getId()); // not assigned so not marked as deleted but fully deleted assertThat(distributionSetRepository.findAll()).hasSize(1); - assertThat(distributionSetManagement - .findDistributionSetsByDeletedAndOrCompleted(PAGE, Boolean.FALSE, Boolean.TRUE).getTotalElements()) - .isEqualTo(1); + assertThat(distributionSetManagement.findByCompleted(PAGE, true).getTotalElements()).isEqualTo(1); } @Test @@ -776,10 +763,10 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest { } final Page metadataOfDs1 = distributionSetManagement - .findDistributionSetMetadataByDistributionSetId(ds1.getId(), new PageRequest(0, 100)); + .findMetaDataByDistributionSetId(new PageRequest(0, 100), ds1.getId()); final Page metadataOfDs2 = distributionSetManagement - .findDistributionSetMetadataByDistributionSetId(ds2.getId(), new PageRequest(0, 100)); + .findMetaDataByDistributionSetId(new PageRequest(0, 100), ds2.getId()); assertThat(metadataOfDs1.getNumberOfElements()).isEqualTo(10); assertThat(metadataOfDs1.getTotalElements()).isEqualTo(10); @@ -806,14 +793,11 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest { // delete assigned ds assertThat(distributionSetRepository.findAll()).hasSize(4); - distributionSetManagement - .deleteDistributionSet(Arrays.asList(dsToTargetAssigned.getId(), dsToRolloutAssigned.getId())); + distributionSetManagement.delete(Arrays.asList(dsToTargetAssigned.getId(), dsToRolloutAssigned.getId())); // not assigned so not marked as deleted assertThat(distributionSetRepository.findAll()).hasSize(4); - assertThat(distributionSetManagement - .findDistributionSetsByDeletedAndOrCompleted(PAGE, Boolean.FALSE, Boolean.TRUE).getTotalElements()) - .isEqualTo(2); + assertThat(distributionSetManagement.findByCompleted(PAGE, true).getTotalElements()).isEqualTo(2); } @Test @@ -846,7 +830,7 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest { testdataFactory.createDistributionSet("test" + i); } - final List foundDs = distributionSetManagement.findDistributionSetsById(searchIds); + final List foundDs = distributionSetManagement.get(searchIds); assertThat(foundDs).hasSize(3); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TagManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DistributionSetTagManagementTest.java similarity index 50% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TagManagementTest.java rename to hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DistributionSetTagManagementTest.java index 0aa68a282..4763e69ec 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TagManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DistributionSetTagManagementTest.java @@ -18,20 +18,16 @@ import java.util.Collection; import java.util.List; import java.util.stream.Collectors; -import org.eclipse.hawkbit.repository.TagManagement; +import org.eclipse.hawkbit.repository.DistributionSetTagManagement; import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTagUpdatedEvent; import org.eclipse.hawkbit.repository.event.remote.entity.TargetCreatedEvent; import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagUpdatedEvent; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; -import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetFilter.DistributionSetFilterBuilder; import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult; import org.eclipse.hawkbit.repository.model.Tag; -import org.eclipse.hawkbit.repository.model.Target; -import org.eclipse.hawkbit.repository.model.TargetTag; -import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult; import org.eclipse.hawkbit.repository.test.matcher.Expect; import org.eclipse.hawkbit.repository.test.matcher.ExpectEvents; import org.junit.Test; @@ -41,22 +37,20 @@ import ru.yandex.qatools.allure.annotations.Features; import ru.yandex.qatools.allure.annotations.Stories; /** - * Test class for {@link TagManagement}. + * {@link DistributionSetTagManagement} tests. * */ @Features("Component Tests - Repository") -@Stories("Tag Management") -public class TagManagementTest extends AbstractJpaIntegrationTest { +@Stories("DistributionSet Tag Management") +public class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Verifies that management get access reacts as specfied on calls for non existing entities by means " + "of Optional not present.") @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) }) public void nonExistingEntityAccessReturnsNotPresent() { - assertThat(tagManagement.findDistributionSetTag(NOT_EXIST_ID)).isNotPresent(); - assertThat(tagManagement.findDistributionSetTagById(NOT_EXIST_IDL)).isNotPresent(); - assertThat(tagManagement.findTargetTag(NOT_EXIST_ID)).isNotPresent(); - assertThat(tagManagement.findTargetTagById(NOT_EXIST_IDL)).isNotPresent(); + assertThat(distributionSetTagManagement.getByName(NOT_EXIST_ID)).isNotPresent(); + assertThat(distributionSetTagManagement.get(NOT_EXIST_IDL)).isNotPresent(); } @Test @@ -65,18 +59,16 @@ public class TagManagementTest extends AbstractJpaIntegrationTest { @ExpectEvents({ @Expect(type = DistributionSetTagUpdatedEvent.class, count = 0), @Expect(type = TargetTagUpdatedEvent.class, count = 0) }) public void entityQueriesReferringToNotExistingEntitiesThrowsException() { - verifyThrownExceptionBy(() -> tagManagement.deleteDistributionSetTag(NOT_EXIST_ID), "DistributionSetTag"); - verifyThrownExceptionBy(() -> tagManagement.deleteTargetTag(NOT_EXIST_ID), "TargetTag"); + verifyThrownExceptionBy(() -> distributionSetTagManagement.delete(NOT_EXIST_ID), + "DistributionSetTag"); - verifyThrownExceptionBy(() -> tagManagement.findDistributionSetTagsByDistributionSet(PAGE, NOT_EXIST_IDL), + verifyThrownExceptionBy( + () -> distributionSetTagManagement.findByDistributionSet(PAGE, NOT_EXIST_IDL), "DistributionSet"); - verifyThrownExceptionBy(() -> tagManagement.updateDistributionSetTag(entityFactory.tag().update(NOT_EXIST_IDL)), + verifyThrownExceptionBy( + () -> distributionSetTagManagement.update(entityFactory.tag().update(NOT_EXIST_IDL)), "DistributionSetTag"); - verifyThrownExceptionBy(() -> tagManagement.updateTargetTag(entityFactory.tag().update(NOT_EXIST_IDL)), - "TargetTag"); - - verifyThrownExceptionBy(() -> tagManagement.findAllTargetTags(PAGE, NOT_EXIST_ID), "Target"); } @Test @@ -90,28 +82,33 @@ public class TagManagementTest extends AbstractJpaIntegrationTest { final Collection dsBCs = testdataFactory.createDistributionSets("DS-BC", 13); final Collection dsABCs = testdataFactory.createDistributionSets("DS-ABC", 9); - final DistributionSetTag tagA = tagManagement.createDistributionSetTag(entityFactory.tag().create().name("A")); - final DistributionSetTag tagB = tagManagement.createDistributionSetTag(entityFactory.tag().create().name("B")); - final DistributionSetTag tagC = tagManagement.createDistributionSetTag(entityFactory.tag().create().name("C")); - final DistributionSetTag tagX = tagManagement.createDistributionSetTag(entityFactory.tag().create().name("X")); - final DistributionSetTag tagY = tagManagement.createDistributionSetTag(entityFactory.tag().create().name("Y")); + final DistributionSetTag tagA = distributionSetTagManagement + .create(entityFactory.tag().create().name("A")); + final DistributionSetTag tagB = distributionSetTagManagement + .create(entityFactory.tag().create().name("B")); + final DistributionSetTag tagC = distributionSetTagManagement + .create(entityFactory.tag().create().name("C")); + final DistributionSetTag tagX = distributionSetTagManagement + .create(entityFactory.tag().create().name("X")); + final DistributionSetTag tagY = distributionSetTagManagement + .create(entityFactory.tag().create().name("Y")); toggleTagAssignment(dsAs, tagA); toggleTagAssignment(dsBs, tagB); toggleTagAssignment(dsCs, tagC); - toggleTagAssignment(dsABs, tagManagement.findDistributionSetTag(tagA.getName()).get()); - toggleTagAssignment(dsABs, tagManagement.findDistributionSetTag(tagB.getName()).get()); + toggleTagAssignment(dsABs, distributionSetTagManagement.getByName(tagA.getName()).get()); + toggleTagAssignment(dsABs, distributionSetTagManagement.getByName(tagB.getName()).get()); - toggleTagAssignment(dsACs, tagManagement.findDistributionSetTag(tagA.getName()).get()); - toggleTagAssignment(dsACs, tagManagement.findDistributionSetTag(tagC.getName()).get()); + toggleTagAssignment(dsACs, distributionSetTagManagement.getByName(tagA.getName()).get()); + toggleTagAssignment(dsACs, distributionSetTagManagement.getByName(tagC.getName()).get()); - toggleTagAssignment(dsBCs, tagManagement.findDistributionSetTag(tagB.getName()).get()); - toggleTagAssignment(dsBCs, tagManagement.findDistributionSetTag(tagC.getName()).get()); + toggleTagAssignment(dsBCs, distributionSetTagManagement.getByName(tagB.getName()).get()); + toggleTagAssignment(dsBCs, distributionSetTagManagement.getByName(tagC.getName()).get()); - toggleTagAssignment(dsABCs, tagManagement.findDistributionSetTag(tagA.getName()).get()); - toggleTagAssignment(dsABCs, tagManagement.findDistributionSetTag(tagB.getName()).get()); - toggleTagAssignment(dsABCs, tagManagement.findDistributionSetTag(tagC.getName()).get()); + toggleTagAssignment(dsABCs, distributionSetTagManagement.getByName(tagA.getName()).get()); + toggleTagAssignment(dsABCs, distributionSetTagManagement.getByName(tagB.getName()).get()); + toggleTagAssignment(dsABCs, distributionSetTagManagement.getByName(tagC.getName()).get()); DistributionSetFilterBuilder distributionSetFilterBuilder; @@ -121,7 +118,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest { assertEquals("filter works not correct", dsAs.spliterator().getExactSizeIfKnown() + dsABs.spliterator().getExactSizeIfKnown() + dsACs.spliterator().getExactSizeIfKnown() + dsABCs.spliterator().getExactSizeIfKnown(), - distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()) + distributionSetManagement.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build()) .getTotalElements()); distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(true) @@ -129,7 +126,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest { assertEquals("filter works not correct", dsBs.spliterator().getExactSizeIfKnown() + dsABs.spliterator().getExactSizeIfKnown() + dsBCs.spliterator().getExactSizeIfKnown() + dsABCs.spliterator().getExactSizeIfKnown(), - distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()) + distributionSetManagement.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build()) .getTotalElements()); distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(true) @@ -137,22 +134,22 @@ public class TagManagementTest extends AbstractJpaIntegrationTest { assertEquals("filter works not correct", dsCs.spliterator().getExactSizeIfKnown() + dsACs.spliterator().getExactSizeIfKnown() + dsBCs.spliterator().getExactSizeIfKnown() + dsABCs.spliterator().getExactSizeIfKnown(), - distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()) + distributionSetManagement.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build()) .getTotalElements()); distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(true) .setTagNames(Arrays.asList(tagX.getName())); assertEquals("filter works not correct", 0, distributionSetManagement - .findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getTotalElements()); + .findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build()).getTotalElements()); assertEquals("wrong tag size", 5, distributionSetTagRepository.findAll().spliterator().getExactSizeIfKnown()); - tagManagement.deleteDistributionSetTag(tagY.getName()); + distributionSetTagManagement.delete(tagY.getName()); assertEquals("wrong tag size", 4, distributionSetTagRepository.findAll().spliterator().getExactSizeIfKnown()); - tagManagement.deleteDistributionSetTag(tagX.getName()); + distributionSetTagManagement.delete(tagX.getName()); assertEquals("wrong tag size", 3, distributionSetTagRepository.findAll().spliterator().getExactSizeIfKnown()); - tagManagement.deleteDistributionSetTag(tagB.getName()); + distributionSetTagManagement.delete(tagB.getName()); assertEquals("wrong tag size", 2, distributionSetTagRepository.findAll().spliterator().getExactSizeIfKnown()); distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE) @@ -160,27 +157,23 @@ public class TagManagementTest extends AbstractJpaIntegrationTest { assertEquals("filter works not correct", dsAs.spliterator().getExactSizeIfKnown() + dsABs.spliterator().getExactSizeIfKnown() + dsACs.spliterator().getExactSizeIfKnown() + dsABCs.spliterator().getExactSizeIfKnown(), - distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()) + distributionSetManagement.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build()) .getTotalElements()); distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE) .setTagNames(Arrays.asList(tagB.getName())); assertEquals("filter works not correct", 0, distributionSetManagement - .findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getTotalElements()); + .findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build()).getTotalElements()); distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE) .setTagNames(Arrays.asList(tagC.getName())); assertEquals("filter works not correct", dsCs.spliterator().getExactSizeIfKnown() + dsACs.spliterator().getExactSizeIfKnown() + dsBCs.spliterator().getExactSizeIfKnown() + dsABCs.spliterator().getExactSizeIfKnown(), - distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()) + distributionSetManagement.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build()) .getTotalElements()); } - private DistributionSetFilterBuilder getDistributionSetFilterBuilder() { - return new DistributionSetFilterBuilder(); - } - @Test @Description("Verifies the toogle mechanism by means on assigning tag if at least on DS in the list does not have" + "the tag yet. Unassign if all of them have the tag already.") @@ -188,15 +181,15 @@ public class TagManagementTest extends AbstractJpaIntegrationTest { final Collection groupA = testdataFactory.createDistributionSets(20); final Collection groupB = testdataFactory.createDistributionSets("unassigned", 20); - final DistributionSetTag tag = tagManagement - .createDistributionSetTag(entityFactory.tag().create().name("tag1").description("tagdesc1")); + final DistributionSetTag tag = distributionSetTagManagement + .create(entityFactory.tag().create().name("tag1").description("tagdesc1")); // toggle A only -> A is now assigned DistributionSetTagAssignmentResult result = toggleTagAssignment(groupA, tag); assertThat(result.getAlreadyAssigned()).isEqualTo(0); assertThat(result.getAssigned()).isEqualTo(20); assertThat(result.getAssignedEntity()).containsAll(distributionSetManagement - .findDistributionSetsById(groupA.stream().map(DistributionSet::getId).collect(Collectors.toList()))); + .get(groupA.stream().map(DistributionSet::getId).collect(Collectors.toList()))); assertThat(result.getUnassigned()).isEqualTo(0); assertThat(result.getUnassignedEntity()).isEmpty(); assertThat(result.getDistributionSetTag()).isEqualTo(tag); @@ -206,7 +199,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest { assertThat(result.getAlreadyAssigned()).isEqualTo(20); assertThat(result.getAssigned()).isEqualTo(20); assertThat(result.getAssignedEntity()).containsAll(distributionSetManagement - .findDistributionSetsById(groupB.stream().map(DistributionSet::getId).collect(Collectors.toList()))); + .get(groupB.stream().map(DistributionSet::getId).collect(Collectors.toList()))); assertThat(result.getUnassigned()).isEqualTo(0); assertThat(result.getUnassignedEntity()).isEmpty(); assertThat(result.getDistributionSetTag()).isEqualTo(tag); @@ -217,147 +210,24 @@ public class TagManagementTest extends AbstractJpaIntegrationTest { assertThat(result.getAssigned()).isEqualTo(0); assertThat(result.getAssignedEntity()).isEmpty(); assertThat(result.getUnassigned()).isEqualTo(40); - assertThat(result.getUnassignedEntity()).containsAll(distributionSetManagement.findDistributionSetsById( + assertThat(result.getUnassignedEntity()).containsAll(distributionSetManagement.get( concat(groupB, groupA).stream().map(DistributionSet::getId).collect(Collectors.toList()))); assertThat(result.getDistributionSetTag()).isEqualTo(tag); } - @Test - @Description("Verifies the toogle mechanism by means on assigning tag if at least on target in the list does not have" - + "the tag yet. Unassign if all of them have the tag already.") - public void assignAndUnassignTargetTags() { - final List groupA = testdataFactory.createTargets(20); - final List groupB = testdataFactory.createTargets(20, "groupb", "groupb"); - - final TargetTag tag = tagManagement - .createTargetTag(entityFactory.tag().create().name("tag1").description("tagdesc1")); - - // toggle A only -> A is now assigned - TargetTagAssignmentResult result = toggleTagAssignment(groupA, tag); - assertThat(result.getAlreadyAssigned()).isEqualTo(0); - assertThat(result.getAssigned()).isEqualTo(20); - assertThat(result.getAssignedEntity()).containsAll(targetManagement.findTargetsByControllerID( - groupA.stream().map(target -> target.getControllerId()).collect(Collectors.toList()))); - assertThat(result.getUnassigned()).isEqualTo(0); - assertThat(result.getUnassignedEntity()).isEmpty(); - assertThat(result.getTargetTag()).isEqualTo(tag); - - // toggle A+B -> A is still assigned and B is assigned as well - result = toggleTagAssignment(concat(groupA, groupB), tag); - assertThat(result.getAlreadyAssigned()).isEqualTo(20); - assertThat(result.getAssigned()).isEqualTo(20); - assertThat(result.getAssignedEntity()).containsAll(targetManagement.findTargetsByControllerID( - groupB.stream().map(target -> target.getControllerId()).collect(Collectors.toList()))); - assertThat(result.getUnassigned()).isEqualTo(0); - assertThat(result.getUnassignedEntity()).isEmpty(); - assertThat(result.getTargetTag()).isEqualTo(tag); - - // toggle A+B -> both unassigned - result = toggleTagAssignment(concat(groupA, groupB), tag); - assertThat(result.getAlreadyAssigned()).isEqualTo(0); - assertThat(result.getAssigned()).isEqualTo(0); - assertThat(result.getAssignedEntity()).isEmpty(); - assertThat(result.getUnassigned()).isEqualTo(40); - assertThat(result.getUnassignedEntity()).containsAll(targetManagement.findTargetsByControllerID( - concat(groupB, groupA).stream().map(target -> target.getControllerId()).collect(Collectors.toList()))); - assertThat(result.getTargetTag()).isEqualTo(tag); - - } - - @SafeVarargs - private final Collection concat(final Collection... targets) { - final List result = new ArrayList<>(); - Arrays.asList(targets).forEach(result::addAll); - return result; - } - - @Test - @Description("Ensures that all tags are retrieved through repository.") - public void findAllTargetTags() { - final List tags = createTargetsWithTags(); - - assertThat(targetTagRepository.findAll()).isEqualTo(targetTagRepository.findAll()).isEqualTo(tags) - .as("Wrong tag size").hasSize(20); - } - - @Test - @Description("Ensures that a created tag is persisted in the repository as defined.") - public void createTargetTag() { - final Tag tag = tagManagement - .createTargetTag(entityFactory.tag().create().name("kai1").description("kai2").colour("colour")); - - assertThat(targetTagRepository.findByNameEquals("kai1").get().getDescription()).as("wrong tag ed") - .isEqualTo("kai2"); - assertThat(tagManagement.findTargetTag("kai1").get().getColour()).as("wrong tag found").isEqualTo("colour"); - assertThat(tagManagement.findTargetTagById(tag.getId()).get().getColour()).as("wrong tag found") - .isEqualTo("colour"); - } - - @Test - @Description("Ensures that a deleted tag is removed from the repository as defined.") - public void deleteTargetTags() { - - // create test data - final Iterable tags = createTargetsWithTags(); - final TargetTag toDelete = tags.iterator().next(); - - for (final Target target : targetRepository.findAll()) { - assertThat(tagManagement.findAllTargetTags(PAGE, target.getControllerId()).getContent()) - .contains(toDelete); - } - - // delete - tagManagement.deleteTargetTag(toDelete.getName()); - - // check - for (final Target target : targetRepository.findAll()) { - assertThat(tagManagement.findAllTargetTags(PAGE, target.getControllerId()).getContent()) - .doesNotContain(toDelete); - } - assertThat(targetTagRepository.findOne(toDelete.getId())).as("No tag should be found").isNull(); - assertThat(targetTagRepository.findAll()).as("Wrong target tag size").hasSize(19); - } - - @Test - @Description("Tests the name update of a target tag.") - public void updateTargetTag() { - final List tags = createTargetsWithTags(); - - // change data - final TargetTag savedAssigned = tags.iterator().next(); - - // persist - tagManagement.updateTargetTag(entityFactory.tag().update(savedAssigned.getId()).name("test123")); - - // check data - assertThat(targetTagRepository.findAll()).as("Wrong target tag size").hasSize(tags.size()); - assertThat(targetTagRepository.findOne(savedAssigned.getId()).getName()).as("wrong target tag is saved") - .isEqualTo("test123"); - assertThat(targetTagRepository.findOne(savedAssigned.getId()).getOptLockRevision()) - .as("wrong target tag is saved").isEqualTo(2); - } - @Test @Description("Ensures that a created tag is persisted in the repository as defined.") public void createDistributionSetTag() { - final Tag tag = tagManagement.createDistributionSetTag( + final Tag tag = distributionSetTagManagement.create( entityFactory.tag().create().name("kai1").description("kai2").colour("colour")); assertThat(distributionSetTagRepository.findByNameEquals("kai1").get().getDescription()).as("wrong tag found") .isEqualTo("kai2"); - assertThat(tagManagement.findDistributionSetTag("kai1").get().getColour()).as("wrong tag found") + assertThat(distributionSetTagManagement.getByName("kai1").get().getColour()).as("wrong tag found") .isEqualTo("colour"); - assertThat(tagManagement.findDistributionSetTagById(tag.getId()).get().getColour()).as("wrong tag found") - .isEqualTo("colour"); - } - - @Test - @Description("Ensures that a created tags are persisted in the repository as defined.") - public void createDistributionSetTags() { - final List tags = createDsSetsWithTags(); - - assertThat(distributionSetTagRepository.findAll()).as("Wrong size of tags created").hasSize(tags.size()); + assertThat(distributionSetTagManagement.get(tag.getId()).get().getColour()) + .as("wrong tag found").isEqualTo("colour"); } @Test @@ -373,11 +243,11 @@ public class TagManagementTest extends AbstractJpaIntegrationTest { } // delete - tagManagement.deleteDistributionSetTag(tags.iterator().next().getName()); + distributionSetTagManagement.delete(tags.iterator().next().getName()); // check assertThat(distributionSetTagRepository.findOne(toDelete.getId())).as("Deleted tag should be null").isNull(); - assertThat(tagManagement.findAllDistributionSetTags(PAGE).getContent()) + assertThat(distributionSetTagManagement.findAll(PAGE).getContent()) .as("Wrong size of tags after deletion").hasSize(19); for (final DistributionSet set : distributionSetRepository.findAll()) { @@ -386,39 +256,12 @@ public class TagManagementTest extends AbstractJpaIntegrationTest { } } - @Test - @Description("Ensures that a tag cannot be created if one exists already with that name (ecpects EntityAlreadyExistsException).") - public void failedDuplicateTargetTagNameException() { - tagManagement.createTargetTag(entityFactory.tag().create().name("A")); - - try { - tagManagement.createTargetTag(entityFactory.tag().create().name("A")); - fail("should not have worked as tag already exists"); - } catch (final EntityAlreadyExistsException e) { - - } - } - - @Test - @Description("Ensures that a tag cannot be updated to a name that already exists on another tag (ecpects EntityAlreadyExistsException).") - public void failedDuplicateTargetTagNameExceptionAfterUpdate() { - tagManagement.createTargetTag(entityFactory.tag().create().name("A")); - final TargetTag tag = tagManagement.createTargetTag(entityFactory.tag().create().name("B")); - - try { - tagManagement.updateTargetTag(entityFactory.tag().update(tag.getId()).name("A")); - fail("should not have worked as tag already exists"); - } catch (final EntityAlreadyExistsException e) { - - } - } - @Test @Description("Ensures that a tag cannot be created if one exists already with that name (ecpects EntityAlreadyExistsException).") public void failedDuplicateDsTagNameException() { - tagManagement.createDistributionSetTag(entityFactory.tag().create().name("A")); + distributionSetTagManagement.create(entityFactory.tag().create().name("A")); try { - tagManagement.createDistributionSetTag(entityFactory.tag().create().name("A")); + distributionSetTagManagement.create(entityFactory.tag().create().name("A")); fail("should not have worked as tag already exists"); } catch (final EntityAlreadyExistsException e) { @@ -428,11 +271,12 @@ public class TagManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Ensures that a tag cannot be updated to a name that already exists on another tag (ecpects EntityAlreadyExistsException).") public void failedDuplicateDsTagNameExceptionAfterUpdate() { - tagManagement.createDistributionSetTag(entityFactory.tag().create().name("A")); - final DistributionSetTag tag = tagManagement.createDistributionSetTag(entityFactory.tag().create().name("B")); + distributionSetTagManagement.create(entityFactory.tag().create().name("A")); + final DistributionSetTag tag = distributionSetTagManagement + .create(entityFactory.tag().create().name("B")); try { - tagManagement.updateDistributionSetTag(entityFactory.tag().update(tag.getId()).name("A")); + distributionSetTagManagement.update(entityFactory.tag().update(tag.getId()).name("A")); fail("should not have worked as tag already exists"); } catch (final EntityAlreadyExistsException e) { @@ -450,11 +294,12 @@ public class TagManagementTest extends AbstractJpaIntegrationTest { final DistributionSetTag savedAssigned = tags.iterator().next(); // persist - tagManagement.updateDistributionSetTag(entityFactory.tag().update(savedAssigned.getId()).name("test123")); + distributionSetTagManagement + .update(entityFactory.tag().update(savedAssigned.getId()).name("test123")); // check data - assertThat(tagManagement.findAllDistributionSetTags(PAGE).getContent()).as("Wrong size of ds tags") - .hasSize(tags.size()); + assertThat(distributionSetTagManagement.findAll(PAGE).getContent()) + .as("Wrong size of ds tags").hasSize(tags.size()); assertThat(distributionSetTagRepository.findOne(savedAssigned.getId()).getName()).as("Wrong ds tag found") .isEqualTo("test123"); } @@ -465,18 +310,17 @@ public class TagManagementTest extends AbstractJpaIntegrationTest { final List tags = createDsSetsWithTags(); // test - assertThat(tagManagement.findAllDistributionSetTags(PAGE).getContent()).as("Wrong size of tags") + assertThat(distributionSetTagManagement.findAll(PAGE).getContent()).as("Wrong size of tags") .hasSize(tags.size()); assertThat(distributionSetTagRepository.findAll()).as("Wrong size of tags").hasSize(20); } - private List createTargetsWithTags() { - final List targets = testdataFactory.createTargets(20); - final Iterable tags = testdataFactory.createTargetTags(20, ""); + @Test + @Description("Ensures that a created tags are persisted in the repository as defined.") + public void createDistributionSetTags() { + final List tags = createDsSetsWithTags(); - tags.forEach(tag -> toggleTagAssignment(targets, tag)); - - return targetTagRepository.findAll(); + assertThat(distributionSetTagRepository.findAll()).as("Wrong size of tags created").hasSize(tags.size()); } private List createDsSetsWithTags() { @@ -486,6 +330,18 @@ public class TagManagementTest extends AbstractJpaIntegrationTest { tags.forEach(tag -> toggleTagAssignment(sets, tag)); - return tagManagement.findAllDistributionSetTags(PAGE).getContent(); + return distributionSetTagManagement.findAll(PAGE).getContent(); } + + private DistributionSetFilterBuilder getDistributionSetFilterBuilder() { + return new DistributionSetFilterBuilder(); + } + + @SafeVarargs + private final Collection concat(final Collection... targets) { + final List result = new ArrayList<>(); + Arrays.asList(targets).forEach(result::addAll); + return result; + } + } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DistributionSetTypeManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DistributionSetTypeManagementTest.java index 8fefc8dcd..fa71642d2 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DistributionSetTypeManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DistributionSetTypeManagementTest.java @@ -48,9 +48,9 @@ public class DistributionSetTypeManagementTest extends AbstractJpaIntegrationTes + "of Optional not present.") @ExpectEvents({ @Expect(type = DistributionSetCreatedEvent.class, count = 0) }) public void nonExistingEntityAccessReturnsNotPresent() { - assertThat(distributionSetTypeManagement.findDistributionSetTypeById(NOT_EXIST_IDL)).isNotPresent(); - assertThat(distributionSetTypeManagement.findDistributionSetTypeByKey(NOT_EXIST_ID)).isNotPresent(); - assertThat(distributionSetTypeManagement.findDistributionSetTypeByName(NOT_EXIST_ID)).isNotPresent(); + assertThat(distributionSetTypeManagement.get(NOT_EXIST_IDL)).isNotPresent(); + assertThat(distributionSetTypeManagement.getByKey(NOT_EXIST_ID)).isNotPresent(); + assertThat(distributionSetTypeManagement.getByName(NOT_EXIST_ID)).isNotPresent(); } @Test @@ -71,15 +71,10 @@ public class DistributionSetTypeManagementTest extends AbstractJpaIntegrationTes testdataFactory.findOrCreateDistributionSetType("xxx", "xxx").getId(), Arrays.asList(NOT_EXIST_IDL)), "SoftwareModuleType"); - verifyThrownExceptionBy(() -> distributionSetTypeManagement.countDistributionSetsByType(NOT_EXIST_IDL), - "DistributionSet"); - - verifyThrownExceptionBy(() -> distributionSetTypeManagement.deleteDistributionSetType(NOT_EXIST_IDL), - "DistributionSetType"); + verifyThrownExceptionBy(() -> distributionSetTypeManagement.delete(NOT_EXIST_IDL), "DistributionSetType"); verifyThrownExceptionBy( - () -> distributionSetTypeManagement - .updateDistributionSetType(entityFactory.distributionSetType().update(NOT_EXIST_IDL)), + () -> distributionSetTypeManagement.update(entityFactory.distributionSetType().update(NOT_EXIST_IDL)), "DistributionSet"); } @@ -100,12 +95,12 @@ public class DistributionSetTypeManagementTest extends AbstractJpaIntegrationTes private void createAndUpdateDistributionSetWithInvalidDescription(final DistributionSet set) { assertThatExceptionOfType(ConstraintViolationException.class) - .isThrownBy(() -> distributionSetManagement.createDistributionSet(entityFactory.distributionSet() + .isThrownBy(() -> distributionSetManagement.create(entityFactory.distributionSet() .create().name("a").version("a").description(RandomStringUtils.randomAlphanumeric(513)))) .as("set with too long description should not be created"); assertThatExceptionOfType(ConstraintViolationException.class) - .isThrownBy(() -> distributionSetManagement.updateDistributionSet(entityFactory.distributionSet() + .isThrownBy(() -> distributionSetManagement.update(entityFactory.distributionSet() .update(set.getId()).description(RandomStringUtils.randomAlphanumeric(513)))) .as("set with too long description should not be updated"); @@ -115,28 +110,28 @@ public class DistributionSetTypeManagementTest extends AbstractJpaIntegrationTes private void createAndUpdateDistributionSetWithInvalidName(final DistributionSet set) { assertThatExceptionOfType(ConstraintViolationException.class) - .isThrownBy(() -> distributionSetManagement.createDistributionSet(entityFactory.distributionSet() + .isThrownBy(() -> distributionSetManagement.create(entityFactory.distributionSet() .create().version("a").name(RandomStringUtils.randomAlphanumeric(65)))) .as("set with too long name should not be created"); assertThatExceptionOfType(ConstraintViolationException.class) .isThrownBy(() -> distributionSetManagement - .createDistributionSet(entityFactory.distributionSet().create().version("a").name(""))) + .create(entityFactory.distributionSet().create().version("a").name(""))) .as("set with too short name should not be created"); assertThatExceptionOfType(ConstraintViolationException.class) .isThrownBy(() -> distributionSetManagement - .createDistributionSet(entityFactory.distributionSet().create().version("a").name(null))) + .create(entityFactory.distributionSet().create().version("a").name(null))) .as("set with null name should not be created"); assertThatExceptionOfType(ConstraintViolationException.class) - .isThrownBy(() -> distributionSetManagement.updateDistributionSet(entityFactory.distributionSet() + .isThrownBy(() -> distributionSetManagement.update(entityFactory.distributionSet() .update(set.getId()).name(RandomStringUtils.randomAlphanumeric(65)))) .as("set with too long name should not be updated"); assertThatExceptionOfType(ConstraintViolationException.class) .isThrownBy(() -> distributionSetManagement - .updateDistributionSet(entityFactory.distributionSet().update(set.getId()).name(""))) + .update(entityFactory.distributionSet().update(set.getId()).name(""))) .as("set with too short name should not be updated"); } @@ -144,85 +139,80 @@ public class DistributionSetTypeManagementTest extends AbstractJpaIntegrationTes private void createAndUpdateDistributionSetWithInvalidVersion(final DistributionSet set) { assertThatExceptionOfType(ConstraintViolationException.class) - .isThrownBy(() -> distributionSetManagement.createDistributionSet(entityFactory.distributionSet() + .isThrownBy(() -> distributionSetManagement.create(entityFactory.distributionSet() .create().name("a").version(RandomStringUtils.randomAlphanumeric(65)))) .as("set with too long name should not be created"); assertThatExceptionOfType(ConstraintViolationException.class) .isThrownBy(() -> distributionSetManagement - .createDistributionSet(entityFactory.distributionSet().create().name("a").version(""))) + .create(entityFactory.distributionSet().create().name("a").version(""))) .as("set with too short name should not be created"); assertThatExceptionOfType(ConstraintViolationException.class) .isThrownBy(() -> distributionSetManagement - .createDistributionSet(entityFactory.distributionSet().create().name("a").version(null))) + .create(entityFactory.distributionSet().create().name("a").version(null))) .as("set with null name should not be created"); assertThatExceptionOfType(ConstraintViolationException.class) - .isThrownBy(() -> distributionSetManagement.updateDistributionSet(entityFactory.distributionSet() + .isThrownBy(() -> distributionSetManagement.update(entityFactory.distributionSet() .update(set.getId()).version(RandomStringUtils.randomAlphanumeric(65)))) .as("set with too long name should not be updated"); assertThatExceptionOfType(ConstraintViolationException.class) .isThrownBy(() -> distributionSetManagement - .updateDistributionSet(entityFactory.distributionSet().update(set.getId()).version(""))) + .update(entityFactory.distributionSet().update(set.getId()).version(""))) .as("set with too short name should not be updated"); } @Test @Description("Tests the successfull module update of unused distribution set type which is in fact allowed.") public void updateUnassignedDistributionSetTypeModules() { - final DistributionSetType updatableType = distributionSetTypeManagement.createDistributionSetType( - entityFactory.distributionSetType().create().key("updatableType").name("to be deleted")); - assertThat(distributionSetTypeManagement.findDistributionSetTypeByKey("updatableType").get() - .getMandatoryModuleTypes()).isEmpty(); + final DistributionSetType updatableType = distributionSetTypeManagement + .create(entityFactory.distributionSetType().create().key("updatableType").name("to be deleted")); + assertThat(distributionSetTypeManagement.getByKey("updatableType").get().getMandatoryModuleTypes()).isEmpty(); // add OS distributionSetTypeManagement.assignMandatorySoftwareModuleTypes(updatableType.getId(), Sets.newHashSet(osType.getId())); - assertThat(distributionSetTypeManagement.findDistributionSetTypeByKey("updatableType").get() - .getMandatoryModuleTypes()).containsOnly(osType); + assertThat(distributionSetTypeManagement.getByKey("updatableType").get().getMandatoryModuleTypes()) + .containsOnly(osType); // add JVM distributionSetTypeManagement.assignMandatorySoftwareModuleTypes(updatableType.getId(), Sets.newHashSet(runtimeType.getId())); - assertThat(distributionSetTypeManagement.findDistributionSetTypeByKey("updatableType").get() - .getMandatoryModuleTypes()).containsOnly(osType, runtimeType); + assertThat(distributionSetTypeManagement.getByKey("updatableType").get().getMandatoryModuleTypes()) + .containsOnly(osType, runtimeType); // remove OS distributionSetTypeManagement.unassignSoftwareModuleType(updatableType.getId(), osType.getId()); - assertThat(distributionSetTypeManagement.findDistributionSetTypeByKey("updatableType").get() - .getMandatoryModuleTypes()).containsOnly(runtimeType); + assertThat(distributionSetTypeManagement.getByKey("updatableType").get().getMandatoryModuleTypes()) + .containsOnly(runtimeType); } @Test @Description("Tests the successfull update of used distribution set type meta data which is in fact allowed.") public void updateAssignedDistributionSetTypeMetaData() { - final DistributionSetType nonUpdatableType = distributionSetTypeManagement - .createDistributionSetType(entityFactory.distributionSetType().create().key("updatableType") - .name("to be deleted").colour("test123")); - assertThat(distributionSetTypeManagement.findDistributionSetTypeByKey("updatableType").get() - .getMandatoryModuleTypes()).isEmpty(); - distributionSetManagement.createDistributionSet(entityFactory.distributionSet().create().name("newtypesoft") + final DistributionSetType nonUpdatableType = distributionSetTypeManagement.create(entityFactory + .distributionSetType().create().key("updatableType").name("to be deleted").colour("test123")); + assertThat(distributionSetTypeManagement.getByKey("updatableType").get().getMandatoryModuleTypes()).isEmpty(); + distributionSetManagement.create(entityFactory.distributionSet().create().name("newtypesoft") .version("1").type(nonUpdatableType.getKey())); - distributionSetTypeManagement.updateDistributionSetType( + distributionSetTypeManagement.update( entityFactory.distributionSetType().update(nonUpdatableType.getId()).description("a new description")); - assertThat(distributionSetTypeManagement.findDistributionSetTypeByKey("updatableType").get().getDescription()) + assertThat(distributionSetTypeManagement.getByKey("updatableType").get().getDescription()) .isEqualTo("a new description"); - assertThat(distributionSetTypeManagement.findDistributionSetTypeByKey("updatableType").get().getColour()) - .isEqualTo("test123"); + assertThat(distributionSetTypeManagement.getByKey("updatableType").get().getColour()).isEqualTo("test123"); } @Test @Description("Tests the unsuccessfull update of used distribution set type (module addition).") public void addModuleToAssignedDistributionSetTypeFails() { - final DistributionSetType nonUpdatableType = distributionSetTypeManagement.createDistributionSetType( - entityFactory.distributionSetType().create().key("updatableType").name("to be deleted")); - assertThat(distributionSetTypeManagement.findDistributionSetTypeByKey("updatableType").get() - .getMandatoryModuleTypes()).isEmpty(); - distributionSetManagement.createDistributionSet(entityFactory.distributionSet().create().name("newtypesoft") + final DistributionSetType nonUpdatableType = distributionSetTypeManagement + .create(entityFactory.distributionSetType().create().key("updatableType").name("to be deleted")); + assertThat(distributionSetTypeManagement.getByKey("updatableType").get().getMandatoryModuleTypes()).isEmpty(); + distributionSetManagement.create(entityFactory.distributionSet().create().name("newtypesoft") .version("1").type(nonUpdatableType.getKey())); assertThatThrownBy(() -> distributionSetTypeManagement @@ -233,14 +223,13 @@ public class DistributionSetTypeManagementTest extends AbstractJpaIntegrationTes @Test @Description("Tests the unsuccessfull update of used distribution set type (module removal).") public void removeModuleToAssignedDistributionSetTypeFails() { - DistributionSetType nonUpdatableType = distributionSetTypeManagement.createDistributionSetType( - entityFactory.distributionSetType().create().key("updatableType").name("to be deleted")); - assertThat(distributionSetTypeManagement.findDistributionSetTypeByKey("updatableType").get() - .getMandatoryModuleTypes()).isEmpty(); + DistributionSetType nonUpdatableType = distributionSetTypeManagement + .create(entityFactory.distributionSetType().create().key("updatableType").name("to be deleted")); + assertThat(distributionSetTypeManagement.getByKey("updatableType").get().getMandatoryModuleTypes()).isEmpty(); nonUpdatableType = distributionSetTypeManagement.assignMandatorySoftwareModuleTypes(nonUpdatableType.getId(), Sets.newHashSet(osType.getId())); - distributionSetManagement.createDistributionSet(entityFactory.distributionSet().create().name("newtypesoft") + distributionSetManagement.create(entityFactory.distributionSet().create().name("newtypesoft") .version("1").type(nonUpdatableType.getKey())); final Long typeId = nonUpdatableType.getId(); @@ -252,11 +241,10 @@ public class DistributionSetTypeManagementTest extends AbstractJpaIntegrationTes @Description("Tests the successfull deletion of unused (hard delete) distribution set types.") public void deleteUnassignedDistributionSetType() { final JpaDistributionSetType hardDelete = (JpaDistributionSetType) distributionSetTypeManagement - .createDistributionSetType( - entityFactory.distributionSetType().create().key("delete").name("to be deleted")); + .create(entityFactory.distributionSetType().create().key("delete").name("to be deleted")); assertThat(distributionSetTypeRepository.findAll()).contains(hardDelete); - distributionSetTypeManagement.deleteDistributionSetType(hardDelete.getId()); + distributionSetTypeManagement.delete(hardDelete.getId()); assertThat(distributionSetTypeRepository.findAll()).doesNotContain(hardDelete); } @@ -265,16 +253,14 @@ public class DistributionSetTypeManagementTest extends AbstractJpaIntegrationTes @Description("Tests the successfull deletion of used (soft delete) distribution set types.") public void deleteAssignedDistributionSetType() { final JpaDistributionSetType softDelete = (JpaDistributionSetType) distributionSetTypeManagement - .createDistributionSetType( - entityFactory.distributionSetType().create().key("softdeleted").name("to be deleted")); + .create(entityFactory.distributionSetType().create().key("softdeleted").name("to be deleted")); assertThat(distributionSetTypeRepository.findAll()).contains(softDelete); - distributionSetManagement.createDistributionSet( + distributionSetManagement.create( entityFactory.distributionSet().create().name("softdeleted").version("1").type(softDelete.getKey())); - distributionSetTypeManagement.deleteDistributionSetType(softDelete.getId()); - assertThat(distributionSetTypeManagement.findDistributionSetTypeByKey("softdeleted").get().isDeleted()) - .isEqualTo(true); + distributionSetTypeManagement.delete(softDelete.getId()); + assertThat(distributionSetTypeManagement.getByKey("softdeleted").get().isDeleted()).isEqualTo(true); } } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/RolloutGroupManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/RolloutGroupManagementTest.java index a3e1c9db5..75ba66ec9 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/RolloutGroupManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/RolloutGroupManagementTest.java @@ -34,8 +34,8 @@ public class RolloutGroupManagementTest extends AbstractJpaIntegrationTest { + "of Optional not present.") @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) }) public void nonExistingEntityAccessReturnsNotPresent() { - assertThat(rolloutGroupManagement.findRolloutGroupById(NOT_EXIST_IDL)).isNotPresent(); - assertThat(rolloutGroupManagement.findRolloutGroupWithDetailedStatus(NOT_EXIST_IDL)).isNotPresent(); + assertThat(rolloutGroupManagement.get(NOT_EXIST_IDL)).isNotPresent(); + assertThat(rolloutGroupManagement.getWithDetailedStatus(NOT_EXIST_IDL)).isNotPresent(); } @@ -52,19 +52,19 @@ public class RolloutGroupManagementTest extends AbstractJpaIntegrationTest { public void entityQueriesReferringToNotExistingEntitiesThrowsException() { testdataFactory.createRollout("xxx"); - verifyThrownExceptionBy(() -> rolloutGroupManagement.countRolloutGroupsByRolloutId(NOT_EXIST_IDL), "Rollout"); + verifyThrownExceptionBy(() -> rolloutGroupManagement.countByRollout(NOT_EXIST_IDL), "Rollout"); verifyThrownExceptionBy(() -> rolloutGroupManagement.countTargetsOfRolloutsGroup(NOT_EXIST_IDL), "RolloutGroup"); verifyThrownExceptionBy( - () -> rolloutGroupManagement.findAllRolloutGroupsWithDetailedStatus(NOT_EXIST_IDL, PAGE), "Rollout"); - verifyThrownExceptionBy(() -> rolloutGroupManagement.findAllTargetsWithActionStatus(PAGE, NOT_EXIST_IDL), + () -> rolloutGroupManagement.findByRolloutWithDetailedStatus(PAGE, NOT_EXIST_IDL), "Rollout"); + verifyThrownExceptionBy(() -> rolloutGroupManagement.findAllTargetsOfRolloutGroupWithActionStatus(PAGE, NOT_EXIST_IDL), "RolloutGroup"); - verifyThrownExceptionBy(() -> rolloutGroupManagement.findRolloutGroupsAll(NOT_EXIST_IDL, "name==*", PAGE), + verifyThrownExceptionBy(() -> rolloutGroupManagement.findByRolloutAndRsql(PAGE, NOT_EXIST_IDL, "name==*"), "Rollout"); - verifyThrownExceptionBy(() -> rolloutGroupManagement.findRolloutGroupTargets(NOT_EXIST_IDL, PAGE), + verifyThrownExceptionBy(() -> rolloutGroupManagement.findTargetsOfRolloutGroup(PAGE, NOT_EXIST_IDL), "RolloutGroup"); - verifyThrownExceptionBy(() -> rolloutGroupManagement.findRolloutGroupTargets(NOT_EXIST_IDL, "name==*", PAGE), + verifyThrownExceptionBy(() -> rolloutGroupManagement.findTargetsOfRolloutGroupByRsql(PAGE, NOT_EXIST_IDL, "name==*"), "RolloutGroup"); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/RolloutManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/RolloutManagementTest.java index 15e3b2511..18032ddb9 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/RolloutManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/RolloutManagementTest.java @@ -99,7 +99,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { // start rollout final Rollout rollout = testdataFactory.createRolloutByVariables("rolloutNotCancelRunningAction", "description", 1, "name==*", knownDistributionSet, "50", "5"); - rolloutManagement.startRollout(rollout.getId()); + rolloutManagement.start(rollout.getId()); rolloutManagement.handleRollouts(); // verify that manually created action is still running and action @@ -124,9 +124,9 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { + "of Optional not present.") @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) }) public void nonExistingEntityAccessReturnsNotPresent() { - assertThat(rolloutManagement.findRolloutById(NOT_EXIST_IDL)).isNotPresent(); - assertThat(rolloutManagement.findRolloutByName(NOT_EXIST_ID)).isNotPresent(); - assertThat(rolloutManagement.findRolloutWithDetailedStatus(NOT_EXIST_IDL)).isNotPresent(); + assertThat(rolloutManagement.get(NOT_EXIST_IDL)).isNotPresent(); + assertThat(rolloutManagement.getByName(NOT_EXIST_ID)).isNotPresent(); + assertThat(rolloutManagement.getWithDetailedStatus(NOT_EXIST_IDL)).isNotPresent(); } @Test @@ -142,13 +142,13 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { public void entityQueriesReferringToNotExistingEntitiesThrowsException() { testdataFactory.createRollout("xxx"); - verifyThrownExceptionBy(() -> rolloutManagement.deleteRollout(NOT_EXIST_IDL), "Rollout"); + verifyThrownExceptionBy(() -> rolloutManagement.delete(NOT_EXIST_IDL), "Rollout"); verifyThrownExceptionBy(() -> rolloutManagement.pauseRollout(NOT_EXIST_IDL), "Rollout"); verifyThrownExceptionBy(() -> rolloutManagement.resumeRollout(NOT_EXIST_IDL), "Rollout"); - verifyThrownExceptionBy(() -> rolloutManagement.startRollout(NOT_EXIST_IDL), "Rollout"); + verifyThrownExceptionBy(() -> rolloutManagement.start(NOT_EXIST_IDL), "Rollout"); - verifyThrownExceptionBy(() -> rolloutManagement.updateRollout(entityFactory.rollout().update(NOT_EXIST_IDL)), + verifyThrownExceptionBy(() -> rolloutManagement.update(entityFactory.rollout().update(NOT_EXIST_IDL)), "Rollout"); } @@ -165,7 +165,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { // verify the split of the target and targetGroup final Page rolloutGroups = rolloutGroupManagement - .findRolloutGroupsByRolloutId(createdRollout.getId(), PAGE); + .findByRollout(PAGE, createdRollout.getId()); // we have total of #amountTargetsForRollout in rollouts splitted in // group size #groupSize assertThat(rolloutGroups).hasSize(amountGroups); @@ -183,13 +183,13 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { successCondition, errorCondition); // verify first group is running - final RolloutGroup firstGroup = rolloutGroupManagement.findRolloutGroupsByRolloutId(createdRollout.getId(), - new OffsetBasedPageRequest(0, 1, new Sort(Direction.ASC, "id"))).getContent().get(0); + final RolloutGroup firstGroup = rolloutGroupManagement.findByRollout(new OffsetBasedPageRequest(0, 1, new Sort(Direction.ASC, "id")), + createdRollout.getId()).getContent().get(0); assertThat(firstGroup.getStatus()).isEqualTo(RolloutGroupStatus.RUNNING); // verify other groups are scheduled - final List scheduledGroups = rolloutGroupManagement.findRolloutGroupsByRolloutId( - createdRollout.getId(), new OffsetBasedPageRequest(1, 100, new Sort(Direction.ASC, "id"))).getContent(); + final List scheduledGroups = rolloutGroupManagement.findByRollout( + new OffsetBasedPageRequest(1, 100, new Sort(Direction.ASC, "id")), createdRollout.getId()).getContent(); scheduledGroups.forEach(group -> assertThat(group.getStatus()).isEqualTo(RolloutGroupStatus.SCHEDULED) .as("group which should be in scheduled state is in " + group.getStatus() + " state")); // verify that the first group actions has been started and are in state @@ -224,15 +224,15 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { rolloutManagement.handleRollouts(); // verify that now the first and the second group are in running state - final List runningRolloutGroups = rolloutGroupManagement.findRolloutGroupsByRolloutId( - createdRollout.getId(), new OffsetBasedPageRequest(0, 2, new Sort(Direction.ASC, "id"))).getContent(); + final List runningRolloutGroups = rolloutGroupManagement.findByRollout( + new OffsetBasedPageRequest(0, 2, new Sort(Direction.ASC, "id")), createdRollout.getId()).getContent(); runningRolloutGroups.forEach(group -> assertThat(group.getStatus()).isEqualTo(RolloutGroupStatus.RUNNING) .as("group should be in running state because it should be started but it is in " + group.getStatus() + " state")); // verify that the other groups are still in schedule state - final List scheduledRolloutGroups = rolloutGroupManagement.findRolloutGroupsByRolloutId( - createdRollout.getId(), new OffsetBasedPageRequest(2, 10, new Sort(Direction.ASC, "id"))).getContent(); + final List scheduledRolloutGroups = rolloutGroupManagement.findByRollout( + new OffsetBasedPageRequest(2, 10, new Sort(Direction.ASC, "id")), createdRollout.getId()).getContent(); scheduledRolloutGroups.forEach(group -> assertThat(group.getStatus()).isEqualTo(RolloutGroupStatus.SCHEDULED) .as("group should be in scheduled state because it should not be started but it is in " + group.getStatus() + " state")); @@ -269,12 +269,12 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { final Rollout createdRollout = createSimpleTestRolloutWithTargetsAndDistributionSet(amountTargetsForRollout, amountOtherTargets, amountGroups, successCondition, errorCondition); - rolloutManagement.startRollout(createdRollout.getId()); + rolloutManagement.start(createdRollout.getId()); // Run here, because scheduler is disabled during tests rolloutManagement.handleRollouts(); - return rolloutManagement.findRolloutById(createdRollout.getId()).get(); + return rolloutManagement.get(createdRollout.getId()).get(); } @Step("Finish three actions of the rollout group and delete two targets") @@ -286,15 +286,15 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { finishAction(runningActions.get(0)); finishAction(runningActions.get(1)); finishAction(runningActions.get(2)); - targetManagement.deleteTargets( + targetManagement.delete( Arrays.asList(runningActions.get(3).getTarget().getId(), runningActions.get(4).getTarget().getId())); } @Step("Check the status of the rollout groups, second group should be in running status") private void checkSecondGroupStatusIsRunning(final Rollout createdRollout) { rolloutManagement.handleRollouts(); - final List runningRolloutGroups = rolloutGroupManagement.findRolloutGroupsByRolloutId( - createdRollout.getId(), new OffsetBasedPageRequest(0, 10, new Sort(Direction.ASC, "id"))).getContent(); + final List runningRolloutGroups = rolloutGroupManagement.findByRollout( + new OffsetBasedPageRequest(0, 10, new Sort(Direction.ASC, "id")), createdRollout.getId()).getContent(); assertThat(runningRolloutGroups.get(0).getStatus()).isEqualTo(RolloutGroupStatus.FINISHED); assertThat(runningRolloutGroups.get(1).getStatus()).isEqualTo(RolloutGroupStatus.RUNNING); assertThat(runningRolloutGroups.get(2).getStatus()).isEqualTo(RolloutGroupStatus.SCHEDULED); @@ -306,7 +306,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { createdRollout.getId(), Status.RUNNING); final List runningActions = runningActionsSlice.getContent(); finishAction(runningActions.get(0)); - targetManagement.deleteTargets( + targetManagement.delete( Arrays.asList(runningActions.get(1).getTarget().getId(), runningActions.get(2).getTarget().getId(), runningActions.get(3).getTarget().getId(), runningActions.get(4).getTarget().getId())); @@ -317,7 +317,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { final Slice runningActionsSlice = actionRepository.findByRolloutIdAndStatus(PAGE, createdRollout.getId(), Status.SCHEDULED); final List runningActions = runningActionsSlice.getContent(); - targetManagement.deleteTargets(Arrays.asList(runningActions.get(0).getTarget().getId(), + targetManagement.delete(Arrays.asList(runningActions.get(0).getTarget().getId(), runningActions.get(1).getTarget().getId(), runningActions.get(2).getTarget().getId(), runningActions.get(3).getTarget().getId(), runningActions.get(4).getTarget().getId())); } @@ -326,11 +326,11 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { private void verifyRolloutAndAllGroupsAreFinished(final Rollout createdRollout) { rolloutManagement.handleRollouts(); final List runningRolloutGroups = rolloutGroupManagement - .findRolloutGroupsByRolloutId(createdRollout.getId(), PAGE).getContent(); + .findByRollout(PAGE, createdRollout.getId()).getContent(); assertThat(runningRolloutGroups.get(0).getStatus()).isEqualTo(RolloutGroupStatus.FINISHED); assertThat(runningRolloutGroups.get(1).getStatus()).isEqualTo(RolloutGroupStatus.FINISHED); assertThat(runningRolloutGroups.get(2).getStatus()).isEqualTo(RolloutGroupStatus.FINISHED); - assertThat(rolloutManagement.findRolloutById(createdRollout.getId()).get().getStatus()) + assertThat(rolloutManagement.get(createdRollout.getId()).get().getStatus()) .isEqualTo(RolloutStatus.FINISHED); } @@ -365,19 +365,19 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { // and should execute the error action rolloutManagement.handleRollouts(); - final Rollout rollout = rolloutManagement.findRolloutById(createdRollout.getId()).get(); + final Rollout rollout = rolloutManagement.get(createdRollout.getId()).get(); // the rollout itself should be in paused based on the error action assertThat(rollout.getStatus()).isEqualTo(RolloutStatus.PAUSED); // the first rollout group should be in error state - final List errorGroup = rolloutGroupManagement.findRolloutGroupsByRolloutId( - createdRollout.getId(), new OffsetBasedPageRequest(0, 1, new Sort(Direction.ASC, "id"))).getContent(); + final List errorGroup = rolloutGroupManagement.findByRollout( + new OffsetBasedPageRequest(0, 1, new Sort(Direction.ASC, "id")), createdRollout.getId()).getContent(); assertThat(errorGroup).hasSize(1); assertThat(errorGroup.get(0).getStatus()).isEqualTo(RolloutGroupStatus.ERROR); // all other groups should still be in scheduled state - final List scheduleGroups = rolloutGroupManagement.findRolloutGroupsByRolloutId( - createdRollout.getId(), new OffsetBasedPageRequest(1, 100, new Sort(Direction.ASC, "id"))).getContent(); + final List scheduleGroups = rolloutGroupManagement.findByRollout( + new OffsetBasedPageRequest(1, 100, new Sort(Direction.ASC, "id")), createdRollout.getId()).getContent(); scheduleGroups.forEach(group -> assertThat(group.getStatus()).isEqualTo(RolloutGroupStatus.SCHEDULED)); } @@ -405,28 +405,28 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { // and should execute the error action rolloutManagement.handleRollouts(); - final Rollout rollout = rolloutManagement.findRolloutById(createdRollout.getId()).get(); + final Rollout rollout = rolloutManagement.get(createdRollout.getId()).get(); // the rollout itself should be in paused based on the error action assertThat(rollout.getStatus()).isEqualTo(RolloutStatus.PAUSED); // all other groups should still be in scheduled state - final List scheduleGroups = rolloutGroupManagement.findRolloutGroupsByRolloutId( - createdRollout.getId(), new OffsetBasedPageRequest(1, 100, new Sort(Direction.ASC, "id"))).getContent(); + final List scheduleGroups = rolloutGroupManagement.findByRollout( + new OffsetBasedPageRequest(1, 100, new Sort(Direction.ASC, "id")), createdRollout.getId()).getContent(); scheduleGroups.forEach(group -> assertThat(group.getStatus()).isEqualTo(RolloutGroupStatus.SCHEDULED)); // resume the rollout again after it gets paused by error action rolloutManagement.resumeRollout(createdRollout.getId()); // the rollout should be running again - assertThat(rolloutManagement.findRolloutById(createdRollout.getId()).get().getStatus()) + assertThat(rolloutManagement.get(createdRollout.getId()).get().getStatus()) .isEqualTo(RolloutStatus.RUNNING); // checking rollouts again rolloutManagement.handleRollouts(); // next group should be running again after resuming the rollout - final List resumedGroups = rolloutGroupManagement.findRolloutGroupsByRolloutId( - createdRollout.getId(), new OffsetBasedPageRequest(1, 1, new Sort(Direction.ASC, "id"))).getContent(); + final List resumedGroups = rolloutGroupManagement.findByRollout( + new OffsetBasedPageRequest(1, 1, new Sort(Direction.ASC, "id")), createdRollout.getId()).getContent(); assertThat(resumedGroups).hasSize(1); assertThat(resumedGroups.get(0).getStatus()).isEqualTo(RolloutGroupStatus.RUNNING); } @@ -451,7 +451,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { rolloutManagement.handleRollouts(); // finish running actions, 2 actions should be finished assertThat(changeStatusForAllRunningActions(createdRollout, Status.FINISHED)).isEqualTo(2); - assertThat(rolloutManagement.findRolloutById(createdRollout.getId()).get().getStatus()) + assertThat(rolloutManagement.get(createdRollout.getId()).get().getStatus()) .isEqualTo(RolloutStatus.RUNNING); } @@ -461,12 +461,12 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { // verify all groups are in finished state rolloutGroupManagement - .findRolloutGroupsByRolloutId(createdRollout.getId(), - new OffsetBasedPageRequest(0, 100, new Sort(Direction.ASC, "id"))) + .findByRollout(new OffsetBasedPageRequest(0, 100, new Sort(Direction.ASC, "id")), + createdRollout.getId()) .forEach(group -> assertThat(group.getStatus()).isEqualTo(RolloutGroupStatus.FINISHED)); // verify that rollout itself is in finished state - final Rollout findRolloutById = rolloutManagement.findRolloutById(createdRollout.getId()).get(); + final Rollout findRolloutById = rolloutManagement.get(createdRollout.getId()).get(); assertThat(findRolloutById.getStatus()).isEqualTo(RolloutStatus.FINISHED); } @@ -487,7 +487,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { validationMap.put(TotalTargetCountStatus.Status.NOTSTARTED, 8L); validateRolloutActionStatus(createdRollout.getId(), validationMap); - rolloutManagement.startRollout(createdRollout.getId()); + rolloutManagement.start(createdRollout.getId()); // Run here, because scheduler is disabled during tests rolloutManagement.handleRollouts(); @@ -550,7 +550,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { validationMap.put(TotalTargetCountStatus.Status.NOTSTARTED, 8L); validateRolloutActionStatus(createdRollout.getId(), validationMap); - rolloutManagement.startRollout(createdRollout.getId()); + rolloutManagement.start(createdRollout.getId()); // Run here, because scheduler is disabled during tests rolloutManagement.handleRollouts(); @@ -589,9 +589,9 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { // round(7/3)=2 targets running (Group 3) // round(5/2)=3 targets SCHEDULED (Group 3) // round(2/1)=2 targets SCHEDULED (Group 4) - createdRollout = rolloutManagement.findRolloutById(createdRollout.getId()).get(); + createdRollout = rolloutManagement.get(createdRollout.getId()).get(); final List rolloutGroups = rolloutGroupManagement - .findRolloutGroupsByRolloutId(createdRollout.getId(), PAGE).getContent(); + .findByRollout(PAGE, createdRollout.getId()).getContent(); Map expectedTargetCountStatus = createInitStatusMap(); expectedTargetCountStatus.put(TotalTargetCountStatus.Status.FINISHED, 2L); @@ -624,15 +624,15 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { successCondition, errorCondition); final DistributionSet ds = createdRollout.getDistributionSet(); - createdRollout = rolloutManagement.findRolloutById(createdRollout.getId()).get(); + createdRollout = rolloutManagement.get(createdRollout.getId()).get(); // 5 targets are running final List runningActions = findActionsByRolloutAndStatus(createdRollout, Status.RUNNING); assertThat(runningActions.size()).isEqualTo(5); // 5 targets are in the group and the DS has been assigned final List rolloutGroups = rolloutGroupManagement - .findRolloutGroupsByRolloutId(createdRollout.getId(), PAGE).getContent(); - final Page targets = rolloutGroupManagement.findRolloutGroupTargets(rolloutGroups.get(0).getId(), PAGE); + .findByRollout(PAGE, createdRollout.getId()).getContent(); + final Page targets = rolloutGroupManagement.findTargetsOfRolloutGroup(PAGE, rolloutGroups.get(0).getId()); final List targetList = targets.getContent(); assertThat(targetList.size()).isEqualTo(5); @@ -665,7 +665,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { Rollout rolloutOne = createAndStartRollout(amountTargetsForRollout, amountOtherTargets, amountGroups, successCondition, errorCondition); - rolloutOne = rolloutManagement.findRolloutById(rolloutOne.getId()).get(); + rolloutOne = rolloutManagement.get(rolloutOne.getId()).get(); final DistributionSet dsForRolloutTwo = testdataFactory.createDistributionSet("dsForRolloutTwo"); @@ -680,7 +680,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { expectedTargetCountStatus.put(TotalTargetCountStatus.Status.SCHEDULED, 5L); validateRolloutActionStatus(rolloutOne.getId(), expectedTargetCountStatus); - rolloutManagement.startRollout(rolloutTwo.getId()); + rolloutManagement.start(rolloutTwo.getId()); // Run here, because scheduler is disabled during tests rolloutManagement.handleRollouts(); @@ -707,7 +707,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { successCondition, errorCondition); final DistributionSet distributionSet = rolloutOne.getDistributionSet(); - rolloutOne = rolloutManagement.findRolloutById(rolloutOne.getId()).get(); + rolloutOne = rolloutManagement.get(rolloutOne.getId()).get(); changeStatusForRunningActions(rolloutOne, Status.ERROR, 2); changeStatusForRunningActions(rolloutOne, Status.FINISHED, 3); rolloutManagement.handleRollouts(); @@ -724,7 +724,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { expectedTargetCountStatus.put(TotalTargetCountStatus.Status.ERROR, 6L); validateRolloutActionStatus(rolloutOne.getId(), expectedTargetCountStatus); // rollout is finished - rolloutOne = rolloutManagement.findRolloutById(rolloutOne.getId()).get(); + rolloutOne = rolloutManagement.get(rolloutOne.getId()).get(); assertThat(rolloutOne.getStatus()).isEqualTo(RolloutStatus.FINISHED); final int amountGroupsForRolloutTwo = 1; @@ -732,19 +732,19 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { "This is the description for rollout two", amountGroupsForRolloutTwo, "controllerId==rollout-*", distributionSet, "50", "80"); - rolloutManagement.startRollout(rolloutTwo.getId()); + rolloutManagement.start(rolloutTwo.getId()); // Run here, because scheduler is disabled during tests rolloutManagement.handleRollouts(); - rolloutTwo = rolloutManagement.findRolloutById(rolloutTwo.getId()).get(); + rolloutTwo = rolloutManagement.get(rolloutTwo.getId()).get(); // 6 error targets are now running expectedTargetCountStatus = createInitStatusMap(); expectedTargetCountStatus.put(TotalTargetCountStatus.Status.RUNNING, 6L); expectedTargetCountStatus.put(TotalTargetCountStatus.Status.FINISHED, 9L); validateRolloutActionStatus(rolloutTwo.getId(), expectedTargetCountStatus); changeStatusForAllRunningActions(rolloutTwo, Status.FINISHED); - final Page targetPage = targetManagement.findTargetByUpdateStatus(PAGE, TargetUpdateStatus.IN_SYNC); + final Page targetPage = targetManagement.findByUpdateStatus(PAGE, TargetUpdateStatus.IN_SYNC); final List targetList = targetPage.getContent(); // 15 targets in finished/IN_SYNC status and same DS assigned assertThat(targetList.size()).isEqualTo(amountTargetsForRollout); @@ -764,13 +764,13 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { Rollout rolloutOne = createAndStartRollout(amountTargetsForRollout, amountOtherTargets, amountGroups, successCondition, errorCondition); - rolloutOne = rolloutManagement.findRolloutById(rolloutOne.getId()).get(); + rolloutOne = rolloutManagement.get(rolloutOne.getId()).get(); changeStatusForRunningActions(rolloutOne, Status.ERROR, 2); changeStatusForRunningActions(rolloutOne, Status.FINISHED, 3); rolloutManagement.handleRollouts(); // verify: 40% error but 60% finished -> should move to next group final List rolloutGruops = rolloutGroupManagement - .findRolloutGroupsByRolloutId(rolloutOne.getId(), PAGE).getContent(); + .findByRollout(PAGE, rolloutOne.getId()).getContent(); final Map expectedTargetCountStatus = createInitStatusMap(); expectedTargetCountStatus.put(TotalTargetCountStatus.Status.RUNNING, 5L); validateRolloutGroupActionStatus(rolloutGruops.get(1), expectedTargetCountStatus); @@ -789,14 +789,14 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { Rollout rolloutOne = createAndStartRollout(amountTargetsForRollout, amountOtherTargets, amountGroups, successCondition, errorCondition); - rolloutOne = rolloutManagement.findRolloutById(rolloutOne.getId()).get(); + rolloutOne = rolloutManagement.get(rolloutOne.getId()).get(); changeStatusForRunningActions(rolloutOne, Status.ERROR, 2); changeStatusForRunningActions(rolloutOne, Status.FINISHED, 3); rolloutManagement.handleRollouts(); // verify: 40% error and 60% finished -> should not move to next group // because successCondition 80% final List rolloutGruops = rolloutGroupManagement - .findRolloutGroupsByRolloutId(rolloutOne.getId(), PAGE).getContent(); + .findByRollout(PAGE, rolloutOne.getId()).getContent(); final Map expectedTargetCountStatus = createInitStatusMap(); expectedTargetCountStatus.put(TotalTargetCountStatus.Status.SCHEDULED, 5L); validateRolloutGroupActionStatus(rolloutGruops.get(1), expectedTargetCountStatus); @@ -814,12 +814,12 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { Rollout rolloutOne = createAndStartRollout(amountTargetsForRollout, amountOtherTargets, amountGroups, successCondition, errorCondition); - rolloutOne = rolloutManagement.findRolloutById(rolloutOne.getId()).get(); + rolloutOne = rolloutManagement.get(rolloutOne.getId()).get(); changeStatusForRunningActions(rolloutOne, Status.ERROR, 2); changeStatusForRunningActions(rolloutOne, Status.FINISHED, 3); rolloutManagement.handleRollouts(); // verify: 40% error -> should pause because errorCondition is 20% - rolloutOne = rolloutManagement.findRolloutById(rolloutOne.getId()).get(); + rolloutOne = rolloutManagement.get(rolloutOne.getId()).get(); assertThat(RolloutStatus.PAUSED).isEqualTo(rolloutOne.getStatus()); } @@ -833,14 +833,14 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { final String errorCondition = "20"; final Rollout rolloutA = createTestRolloutWithTargetsAndDistributionSet(amountTargetsForRollout, amountGroups, successCondition, errorCondition, "RolloutA", "RolloutA"); - rolloutManagement.startRollout(rolloutA.getId()); + rolloutManagement.start(rolloutA.getId()); rolloutManagement.handleRollouts(); final int amountTargetsForRollout2 = 10; final int amountGroups2 = 2; final Rollout rolloutB = createTestRolloutWithTargetsAndDistributionSet(amountTargetsForRollout2, amountGroups2, successCondition, errorCondition, "RolloutB", "RolloutB"); - rolloutManagement.startRollout(rolloutB.getId()); + rolloutManagement.start(rolloutB.getId()); rolloutManagement.handleRollouts(); changeStatusForAllRunningActions(rolloutB, Status.FINISHED); @@ -850,7 +850,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { final int amountGroups3 = 2; final Rollout rolloutC = createTestRolloutWithTargetsAndDistributionSet(amountTargetsForRollout3, amountGroups3, successCondition, errorCondition, "RolloutC", "RolloutC"); - rolloutManagement.startRollout(rolloutC.getId()); + rolloutManagement.start(rolloutC.getId()); rolloutManagement.handleRollouts(); changeStatusForAllRunningActions(rolloutC, Status.ERROR); @@ -860,7 +860,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { final int amountGroups4 = 3; final Rollout rolloutD = createTestRolloutWithTargetsAndDistributionSet(amountTargetsForRollout4, amountGroups4, successCondition, errorCondition, "RolloutD", "RolloutD"); - rolloutManagement.startRollout(rolloutD.getId()); + rolloutManagement.start(rolloutD.getId()); rolloutManagement.handleRollouts(); changeStatusForRunningActions(rolloutD, Status.ERROR, 1); @@ -868,7 +868,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { changeStatusForAllRunningActions(rolloutD, Status.FINISHED); rolloutManagement.handleRollouts(); - final Page rolloutPage = rolloutManagement.findAllRolloutsWithDetailedStatus( + final Page rolloutPage = rolloutManagement.findAllWithDetailedStatus( new OffsetBasedPageRequest(0, 100, new Sort(Direction.ASC, "name")), false); final List rolloutList = rolloutPage.getContent(); @@ -911,7 +911,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { createTestRolloutWithTargetsAndDistributionSet(amountTargetsForRollout, amountGroups, successCondition, errorCondition, "Rollout" + i, "Rollout" + i); } - final Long count = rolloutManagement.countRolloutsAll(); + final Long count = rolloutManagement.count(); assertThat(count).isEqualTo(10L); } @@ -932,7 +932,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { errorCondition, "SomethingElse" + i, "SomethingElse" + i); } - final Long count = rolloutManagement.countRolloutsAllByFilters("Rollout%"); + final Long count = rolloutManagement.countByFilters("Rollout%"); assertThat(count).isEqualTo(5L); } @@ -954,7 +954,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { errorCondition, "SomethingElse" + i, "SomethingElse" + i); } - final Slice rollout = rolloutManagement.findRolloutWithDetailedStatusByFilters( + final Slice rollout = rolloutManagement.findByFiltersWithDetailedStatus( new OffsetBasedPageRequest(0, 100, new Sort(Direction.ASC, "name")), "Rollout%", false); final List rolloutList = rollout.getContent(); assertThat(rolloutList.size()).isEqualTo(5); @@ -977,7 +977,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { final Rollout rolloutCreated = createTestRolloutWithTargetsAndDistributionSet(amountTargetsForRollout, amountGroups, successCondition, errorCondition, rolloutName, "RolloutA"); - final Rollout rolloutFound = rolloutManagement.findRolloutByName(rolloutName).get(); + final Rollout rolloutFound = rolloutManagement.getByName(rolloutName).get(); assertThat(rolloutCreated).isEqualTo(rolloutFound); } @@ -993,18 +993,18 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { final String rolloutName = "MyRollout"; Rollout myRollout = createTestRolloutWithTargetsAndDistributionSet(amountTargetsForRollout, amountGroups, successCondition, errorCondition, rolloutName, rolloutName); - rolloutManagement.startRollout(myRollout.getId()); + rolloutManagement.start(myRollout.getId()); // Run here, because scheduler is disabled during tests rolloutManagement.handleRollouts(); changeStatusForRunningActions(myRollout, Status.FINISHED, 2); rolloutManagement.handleRollouts(); - myRollout = rolloutManagement.findRolloutById(myRollout.getId()).get(); + myRollout = rolloutManagement.get(myRollout.getId()).get(); float percent = rolloutGroupManagement - .findRolloutGroupWithDetailedStatus(rolloutGroupManagement - .findRolloutGroupsByRolloutId(myRollout.getId(), PAGE).getContent().get(0).getId()) + .getWithDetailedStatus(rolloutGroupManagement + .findByRollout(PAGE, myRollout.getId()).getContent().get(0).getId()) .get().getTotalTargetCountStatus().getFinishedPercent(); assertThat(percent).isEqualTo(40); @@ -1012,8 +1012,8 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { rolloutManagement.handleRollouts(); percent = rolloutGroupManagement - .findRolloutGroupWithDetailedStatus(rolloutGroupManagement - .findRolloutGroupsByRolloutId(myRollout.getId(), PAGE).getContent().get(0).getId()) + .getWithDetailedStatus(rolloutGroupManagement + .findByRollout(PAGE, myRollout.getId()).getContent().get(0).getId()) .get().getTotalTargetCountStatus().getFinishedPercent(); assertThat(percent).isEqualTo(100); @@ -1022,8 +1022,8 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { rolloutManagement.handleRollouts(); percent = rolloutGroupManagement - .findRolloutGroupWithDetailedStatus(rolloutGroupManagement - .findRolloutGroupsByRolloutId(myRollout.getId(), PAGE).getContent().get(1).getId()) + .getWithDetailedStatus(rolloutGroupManagement + .findByRollout(PAGE, myRollout.getId()).getContent().get(1).getId()) .get().getTotalTargetCountStatus().getFinishedPercent(); assertThat(percent).isEqualTo(80); } @@ -1045,7 +1045,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { final String rsqlParam = "controllerId==*MyRoll*"; - rolloutManagement.startRollout(myRollout.getId()); + rolloutManagement.start(myRollout.getId()); // Run here, because scheduler is disabled during tests rolloutManagement.handleRollouts(); @@ -1053,26 +1053,26 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { final Condition targetBelongsInRollout = new Condition<>(s -> s.startsWith(rolloutName), "Target belongs into rollout"); - myRollout = rolloutManagement.findRolloutById(myRollout.getId()).get(); + myRollout = rolloutManagement.get(myRollout.getId()).get(); final List rolloutGroups = rolloutGroupManagement - .findRolloutGroupsByRolloutId(myRollout.getId(), PAGE).getContent(); + .findByRollout(PAGE, myRollout.getId()).getContent(); - Page targetPage = rolloutGroupManagement.findRolloutGroupTargets(rolloutGroups.get(0).getId(), - rsqlParam, new OffsetBasedPageRequest(0, 100)); + Page targetPage = rolloutGroupManagement.findTargetsOfRolloutGroupByRsql(new OffsetBasedPageRequest(0, 100), + rolloutGroups.get(0).getId(), rsqlParam); final List targetlistGroup1 = targetPage.getContent(); assertThat(targetlistGroup1.size()).isEqualTo(5); assertThat(targetlistGroup1.stream().map(Target::getControllerId).collect(Collectors.toList())) .are(targetBelongsInRollout); - targetPage = rolloutGroupManagement.findRolloutGroupTargets(rolloutGroups.get(1).getId(), rsqlParam, - new OffsetBasedPageRequest(0, 100)); + targetPage = rolloutGroupManagement.findTargetsOfRolloutGroupByRsql(new OffsetBasedPageRequest(0, 100), rolloutGroups.get(1).getId(), + rsqlParam); final List targetlistGroup2 = targetPage.getContent(); assertThat(targetlistGroup2.size()).isEqualTo(5); assertThat(targetlistGroup2.stream().map(Target::getControllerId).collect(Collectors.toList())) .are(targetBelongsInRollout); - targetPage = rolloutGroupManagement.findRolloutGroupTargets(rolloutGroups.get(2).getId(), rsqlParam, - new OffsetBasedPageRequest(0, 100)); + targetPage = rolloutGroupManagement.findTargetsOfRolloutGroupByRsql(new OffsetBasedPageRequest(0, 100), rolloutGroups.get(2).getId(), + rsqlParam); final List targetlistGroup3 = targetPage.getContent(); assertThat(targetlistGroup3.size()).isEqualTo(5); assertThat(targetlistGroup3.stream().map(Target::getControllerId).collect(Collectors.toList())) @@ -1135,7 +1135,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.READY); - final List groups = rolloutGroupManagement.findRolloutGroupsByRolloutId(myRollout.getId(), PAGE) + final List groups = rolloutGroupManagement.findByRollout(PAGE, myRollout.getId()) .getContent(); assertThat(groups.get(0).getStatus()).isEqualTo(RolloutGroupStatus.READY); @@ -1149,7 +1149,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { assertThat(groups.get(4).getStatus()).isEqualTo(RolloutGroupStatus.READY); assertThat(groups.get(4).getTotalTargets()).isEqualTo(0); - rolloutManagement.startRollout(myRollout.getId()); + rolloutManagement.start(myRollout.getId()); // Run here, because scheduler is disabled during tests rolloutManagement.handleRollouts(); @@ -1159,7 +1159,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { assertThat(MultipleInvokeHelper.doWithTimeout(new RolloutStatusCallable(myRollout.getId()), conditionRolloutStatus, 15000, 500)).as("Rollout status").isNotNull(); - myRollout = rolloutManagement.findRolloutById(myRollout.getId()).get(); + myRollout = rolloutManagement.get(myRollout.getId()).get(); assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.RUNNING); final Map expectedTargetCountStatus = createInitStatusMap(); expectedTargetCountStatus.put(TotalTargetCountStatus.Status.RUNNING, 1L); @@ -1188,10 +1188,10 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { rolloutManagement.handleRollouts(); - myRollout = rolloutManagement.findRolloutById(myRollout.getId()).get(); + myRollout = rolloutManagement.get(myRollout.getId()).get(); assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.READY); - rolloutManagement.startRollout(myRollout.getId()); + rolloutManagement.start(myRollout.getId()); // Run here, because scheduler is disabled during tests rolloutManagement.handleRollouts(); @@ -1201,7 +1201,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { assertThat(MultipleInvokeHelper.doWithTimeout(new RolloutStatusCallable(myRollout.getId()), conditionRolloutTargetCount, 15000, 500)).as("Rollout status").isNotNull(); - myRollout = rolloutManagement.findRolloutById(myRollout.getId()).get(); + myRollout = rolloutManagement.get(myRollout.getId()).get(); assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.RUNNING); final Map expectedTargetCountStatus = createInitStatusMap(); expectedTargetCountStatus.put(TotalTargetCountStatus.Status.RUNNING, 10L); @@ -1228,20 +1228,20 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.READY); // schedule rollout auto start into the future - rolloutManagement.updateRollout( + rolloutManagement.update( entityFactory.rollout().update(myRollout.getId()).startAt(System.currentTimeMillis() + 60000)); rolloutManagement.handleRollouts(); // rollout should not have been started - myRollout = rolloutManagement.findRolloutById(myRollout.getId()).get(); + myRollout = rolloutManagement.get(myRollout.getId()).get(); assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.READY); // schedule to now rolloutManagement - .updateRollout(entityFactory.rollout().update(myRollout.getId()).startAt(System.currentTimeMillis())); + .update(entityFactory.rollout().update(myRollout.getId()).startAt(System.currentTimeMillis())); rolloutManagement.handleRollouts(); - myRollout = rolloutManagement.findRolloutById(myRollout.getId()).get(); + myRollout = rolloutManagement.get(myRollout.getId()).get(); assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.STARTING); // Run here, because scheduler is disabled during tests @@ -1252,7 +1252,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { assertThat(MultipleInvokeHelper.doWithTimeout(new RolloutStatusCallable(myRollout.getId()), conditionRolloutTargetCount, 15000, 500)).as("Rollout status").isNotNull(); - myRollout = rolloutManagement.findRolloutById(myRollout.getId()).get(); + myRollout = rolloutManagement.get(myRollout.getId()).get(); assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.RUNNING); final Map expectedTargetCountStatus = createInitStatusMap(); expectedTargetCountStatus.put(TotalTargetCountStatus.Status.RUNNING, 10L); @@ -1288,11 +1288,11 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { rolloutGroups.add(generateRolloutGroup(1, percentTargetsInGroup2, null)); rolloutGroups.add(generateRolloutGroup(2, percentTargetsInGroup3, null)); - Rollout myRollout = rolloutManagement.createRollout(rolloutcreate, rolloutGroups, conditions); - myRollout = rolloutManagement.findRolloutById(myRollout.getId()).get(); + Rollout myRollout = rolloutManagement.create(rolloutcreate, rolloutGroups, conditions); + myRollout = rolloutManagement.get(myRollout.getId()).get(); assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.CREATING); - for (final RolloutGroup group : rolloutGroupManagement.findRolloutGroupsByRolloutId(myRollout.getId(), PAGE) + for (final RolloutGroup group : rolloutGroupManagement.findByRollout(PAGE, myRollout.getId()) .getContent()) { assertThat(group.getStatus()).isEqualTo(RolloutGroupStatus.CREATING); } @@ -1304,11 +1304,11 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { rolloutManagement.handleRollouts(); - myRollout = rolloutManagement.findRolloutById(myRollout.getId()).get(); + myRollout = rolloutManagement.get(myRollout.getId()).get(); assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.READY); assertThat(myRollout.getTotalTargets()).isEqualTo(amountTargetsInGroup1and2 + amountTargetsInGroup1); - final List groups = rolloutGroupManagement.findRolloutGroupsByRolloutId(myRollout.getId(), PAGE) + final List groups = rolloutGroupManagement.findByRollout(PAGE, myRollout.getId()) .getContent(); ; assertThat(groups.get(0).getStatus()).isEqualTo(RolloutGroupStatus.READY); @@ -1338,7 +1338,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { rolloutGroups.add(generateRolloutGroup(1, percentTargetsInGroup2, null)); assertThatExceptionOfType(ValidationException.class) - .isThrownBy(() -> rolloutManagement.createRollout(myRollout, rolloutGroups, conditions)) + .isThrownBy(() -> rolloutManagement.create(myRollout, rolloutGroups, conditions)) .withMessageContaining("groups don't match"); } @@ -1359,7 +1359,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { generateRolloutGroup(1, percentTargetsInGroup2, null)); assertThatExceptionOfType(ValidationException.class) - .isThrownBy(() -> rolloutManagement.createRollout(myRollout, rolloutGroups, conditions)) + .isThrownBy(() -> rolloutManagement.create(myRollout, rolloutGroups, conditions)) .withMessageContaining("percentage has to be between 1 and 100"); } @@ -1375,7 +1375,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { final RolloutCreate myRollout = generateTargetsAndRollout(rolloutName, amountTargetsForRollout); assertThatExceptionOfType(ValidationException.class) - .isThrownBy(() -> rolloutManagement.createRollout(myRollout, illegalGroupAmount, conditions)) + .isThrownBy(() -> rolloutManagement.create(myRollout, illegalGroupAmount, conditions)) .withMessageContaining("not be greater than " + quotaManagement.getMaxRolloutGroupsPerRollout()); } @@ -1400,14 +1400,14 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { .description("some description").targetFilterQuery("id==" + targetPrefixName + "-*") .set(distributionSet); - Rollout myRollout = rolloutManagement.createRollout(rolloutToCreate, amountGroups, conditions); - myRollout = rolloutManagement.findRolloutById(myRollout.getId()).get(); + Rollout myRollout = rolloutManagement.create(rolloutToCreate, amountGroups, conditions); + myRollout = rolloutManagement.get(myRollout.getId()).get(); assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.CREATING); final Long rolloutId = myRollout.getId(); assertThatExceptionOfType(RolloutIllegalStateException.class) - .isThrownBy(() -> rolloutManagement.startRollout(rolloutId)) + .isThrownBy(() -> rolloutManagement.start(rolloutId)) .withMessageContaining("can only be started in state ready"); } @@ -1430,7 +1430,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { amountOtherTargets, amountGroups, successCondition, errorCondition); // test - rolloutManagement.deleteRollout(createdRollout.getId()); + rolloutManagement.delete(createdRollout.getId()); rolloutManagement.handleRollouts(); // verify @@ -1462,7 +1462,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { // start the rollout, so it has active running actions and a group which // has been started - rolloutManagement.startRollout(createdRollout.getId()); + rolloutManagement.start(createdRollout.getId()); rolloutManagement.handleRollouts(); // verify we have running actions @@ -1470,7 +1470,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { .getNumberOfElements()).isEqualTo(2); // test - rolloutManagement.deleteRollout(createdRollout.getId()); + rolloutManagement.delete(createdRollout.getId()); rolloutManagement.handleRollouts(); // verify @@ -1480,12 +1480,12 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { assertThat(deletedRollout.getStatus()).isEqualTo(RolloutStatus.DELETED); assertThatExceptionOfType(EntityReadOnlyException.class) .isThrownBy(() -> rolloutManagement - .updateRollout(entityFactory.rollout().update(createdRollout.getId()).description("test"))) + .update(entityFactory.rollout().update(createdRollout.getId()).description("test"))) .withMessageContaining("" + createdRollout.getId()); assertThat(rolloutManagement.findAll(PAGE, true).getContent()).hasSize(1); assertThat(rolloutManagement.findAll(PAGE, false).getContent()).hasSize(0); - assertThat(rolloutGroupManagement.findAllRolloutGroupsWithDetailedStatus(createdRollout.getId(), PAGE) + assertThat(rolloutGroupManagement.findByRolloutWithDetailedStatus(PAGE, createdRollout.getId()) .getContent()).hasSize(amountGroups); // verify that all scheduled actions are deleted @@ -1517,13 +1517,13 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { private void validateRolloutGroupActionStatus(final RolloutGroup rolloutGroup, final Map expectedTargetCountStatus) { final RolloutGroup rolloutGroupWithDetail = rolloutGroupManagement - .findRolloutGroupWithDetailedStatus(rolloutGroup.getId()).get(); + .getWithDetailedStatus(rolloutGroup.getId()).get(); validateStatus(rolloutGroupWithDetail.getTotalTargetCountStatus(), expectedTargetCountStatus); } private void validateRolloutActionStatus(final Long rolloutId, final Map expectedTargetCountStatus) { - final Rollout rolloutWithDetail = rolloutManagement.findRolloutWithDetailedStatus(rolloutId).get(); + final Rollout rolloutWithDetail = rolloutManagement.getWithDetailedStatus(rolloutId).get(); validateStatus(rolloutWithDetail.getTotalTargetCountStatus(), expectedTargetCountStatus); } @@ -1608,7 +1608,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { @Override public RolloutStatus call() throws Exception { - final Rollout myRollout = rolloutManagement.findRolloutById(rolloutId).get(); + final Rollout myRollout = rolloutManagement.get(rolloutId).get(); return myRollout.getStatus(); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleManagementTest.java index f1a73d50a..2ebae177b 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleManagementTest.java @@ -60,13 +60,12 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest { public void nonExistingEntityAccessReturnsNotPresent() { final SoftwareModule module = testdataFactory.createSoftwareModuleApp(); - assertThat(softwareModuleManagement.findSoftwareModuleById(1234L)).isNotPresent(); + assertThat(softwareModuleManagement.get(1234L)).isNotPresent(); - assertThat( - softwareModuleManagement.findSoftwareModuleByNameAndVersion(NOT_EXIST_ID, NOT_EXIST_ID, osType.getId())) - .isNotPresent(); + assertThat(softwareModuleManagement.getByNameAndVersionAndType(NOT_EXIST_ID, NOT_EXIST_ID, osType.getId())) + .isNotPresent(); - assertThat(softwareModuleManagement.findSoftwareModuleMetadata(module.getId(), NOT_EXIST_ID)).isNotPresent(); + assertThat(softwareModuleManagement.getMetaDataBySoftwareModuleId(module.getId(), NOT_EXIST_ID)).isNotPresent(); } @Test @@ -77,53 +76,49 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest { final SoftwareModule module = testdataFactory.createSoftwareModuleApp(); verifyThrownExceptionBy( - () -> softwareModuleManagement.createSoftwareModule( - Arrays.asList(entityFactory.softwareModule().create().name("xxx").type(NOT_EXIST_ID))), + () -> softwareModuleManagement + .create(Arrays.asList(entityFactory.softwareModule().create().name("xxx").type(NOT_EXIST_ID))), "SoftwareModuleType"); verifyThrownExceptionBy( () -> softwareModuleManagement - .createSoftwareModule(entityFactory.softwareModule().create().name("xxx").type(NOT_EXIST_ID)), + .create(entityFactory.softwareModule().create().name("xxx").type(NOT_EXIST_ID)), "SoftwareModuleType"); - verifyThrownExceptionBy(() -> softwareModuleManagement.createSoftwareModuleMetadata(NOT_EXIST_IDL, + verifyThrownExceptionBy(() -> softwareModuleManagement.createMetaData(NOT_EXIST_IDL, entityFactory.generateMetadata("xxx", "xxx")), "SoftwareModule"); - verifyThrownExceptionBy(() -> softwareModuleManagement.createSoftwareModuleMetadata(NOT_EXIST_IDL, + verifyThrownExceptionBy(() -> softwareModuleManagement.createMetaData(NOT_EXIST_IDL, Arrays.asList(entityFactory.generateMetadata("xxx", "xxx"))), "SoftwareModule"); - verifyThrownExceptionBy(() -> softwareModuleManagement.deleteSoftwareModule(NOT_EXIST_IDL), "SoftwareModule"); - verifyThrownExceptionBy(() -> softwareModuleManagement.deleteSoftwareModules(Arrays.asList(NOT_EXIST_IDL)), - "SoftwareModule"); - verifyThrownExceptionBy(() -> softwareModuleManagement.deleteSoftwareModuleMetadata(NOT_EXIST_IDL, "xxx"), - "SoftwareModule"); - verifyThrownExceptionBy( - () -> softwareModuleManagement.deleteSoftwareModuleMetadata(module.getId(), NOT_EXIST_ID), + verifyThrownExceptionBy(() -> softwareModuleManagement.delete(NOT_EXIST_IDL), "SoftwareModule"); + verifyThrownExceptionBy(() -> softwareModuleManagement.delete(Arrays.asList(NOT_EXIST_IDL)), "SoftwareModule"); + verifyThrownExceptionBy(() -> softwareModuleManagement.deleteMetaData(NOT_EXIST_IDL, "xxx"), "SoftwareModule"); + verifyThrownExceptionBy(() -> softwareModuleManagement.deleteMetaData(module.getId(), NOT_EXIST_ID), "SoftwareModuleMetadata"); - verifyThrownExceptionBy(() -> softwareModuleManagement.updateSoftwareModuleMetadata(NOT_EXIST_IDL, + verifyThrownExceptionBy(() -> softwareModuleManagement.updateMetaData(NOT_EXIST_IDL, entityFactory.generateMetadata("xxx", "xxx")), "SoftwareModule"); - verifyThrownExceptionBy(() -> softwareModuleManagement.updateSoftwareModuleMetadata(module.getId(), + verifyThrownExceptionBy(() -> softwareModuleManagement.updateMetaData(module.getId(), entityFactory.generateMetadata(NOT_EXIST_ID, "xxx")), "SoftwareModuleMetadata"); - verifyThrownExceptionBy(() -> softwareModuleManagement.findSoftwareModuleByAssignedTo(PAGE, NOT_EXIST_IDL), + verifyThrownExceptionBy(() -> softwareModuleManagement.findByAssignedTo(PAGE, NOT_EXIST_IDL), "DistributionSet"); - verifyThrownExceptionBy( - () -> softwareModuleManagement.findSoftwareModuleByNameAndVersion("xxx", "xxx", NOT_EXIST_IDL), + verifyThrownExceptionBy(() -> softwareModuleManagement.getByNameAndVersionAndType("xxx", "xxx", NOT_EXIST_IDL), "SoftwareModuleType"); - verifyThrownExceptionBy(() -> softwareModuleManagement.findSoftwareModuleMetadata(NOT_EXIST_IDL, NOT_EXIST_ID), + verifyThrownExceptionBy( + () -> softwareModuleManagement.getMetaDataBySoftwareModuleId(NOT_EXIST_IDL, NOT_EXIST_ID), "SoftwareModule"); + verifyThrownExceptionBy(() -> softwareModuleManagement.findMetaDataBySoftwareModuleId(PAGE, NOT_EXIST_IDL), + "SoftwareModule"); + verifyThrownExceptionBy(() -> softwareModuleManagement.findMetaDataByRsql(PAGE, NOT_EXIST_IDL, "name==*"), + "SoftwareModule"); + verifyThrownExceptionBy(() -> softwareModuleManagement.findByType(PAGE, NOT_EXIST_IDL), "SoftwareModule"); + verifyThrownExceptionBy( - () -> softwareModuleManagement.findSoftwareModuleMetadataBySoftwareModuleId(PAGE, NOT_EXIST_IDL), + () -> softwareModuleManagement.update(entityFactory.softwareModule().update(NOT_EXIST_IDL)), "SoftwareModule"); - verifyThrownExceptionBy(() -> softwareModuleManagement - .findSoftwareModuleMetadataBySoftwareModuleId(NOT_EXIST_IDL, "name==*", PAGE), "SoftwareModule"); - verifyThrownExceptionBy(() -> softwareModuleManagement.findSoftwareModulesByType(PAGE, NOT_EXIST_IDL), - "SoftwareModule"); - - verifyThrownExceptionBy(() -> softwareModuleManagement - .updateSoftwareModule(entityFactory.softwareModule().update(NOT_EXIST_IDL)), "SoftwareModule"); } @Test @@ -132,7 +127,7 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest { final SoftwareModule ah = testdataFactory.createSoftwareModuleOs(); final SoftwareModule updated = softwareModuleManagement - .updateSoftwareModule(entityFactory.softwareModule().update(ah.getId())); + .update(entityFactory.softwareModule().update(ah.getId())); assertThat(updated.getOptLockRevision()) .as("Expected version number of updated entitity to be equal to created version") @@ -144,8 +139,8 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest { public void updateSoftareModuleFieldsToNewValue() { final SoftwareModule ah = testdataFactory.createSoftwareModuleOs(); - final SoftwareModule updated = softwareModuleManagement.updateSoftwareModule( - entityFactory.softwareModule().update(ah.getId()).description("changed").vendor("changed")); + final SoftwareModule updated = softwareModuleManagement + .update(entityFactory.softwareModule().update(ah.getId()).description("changed").vendor("changed")); assertThat(updated.getOptLockRevision()).as("Expected version number of updated entitity is") .isEqualTo(ah.getOptLockRevision() + 1); @@ -168,54 +163,47 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest { @Test @Description("searched for software modules based on the various filter options, e.g. name,desc,type, version.") public void findSoftwareModuleByFilters() { - final SoftwareModule ah = softwareModuleManagement.createSoftwareModule( - entityFactory.softwareModule().create().type(appType).name("agent-hub").version("1.0.1")); - final SoftwareModule jvm = softwareModuleManagement.createSoftwareModule( - entityFactory.softwareModule().create().type(runtimeType).name("oracle-jre").version("1.7.2")); - final SoftwareModule os = softwareModuleManagement.createSoftwareModule( - entityFactory.softwareModule().create().type(osType).name("poky").version("3.0.2")); + final SoftwareModule ah = softwareModuleManagement + .create(entityFactory.softwareModule().create().type(appType).name("agent-hub").version("1.0.1")); + final SoftwareModule jvm = softwareModuleManagement + .create(entityFactory.softwareModule().create().type(runtimeType).name("oracle-jre").version("1.7.2")); + final SoftwareModule os = softwareModuleManagement + .create(entityFactory.softwareModule().create().type(osType).name("poky").version("3.0.2")); - final SoftwareModule ah2 = softwareModuleManagement.createSoftwareModule( - entityFactory.softwareModule().create().type(appType).name("agent-hub").version("1.0.2")); + final SoftwareModule ah2 = softwareModuleManagement + .create(entityFactory.softwareModule().create().type(appType).name("agent-hub").version("1.0.2")); JpaDistributionSet ds = (JpaDistributionSet) distributionSetManagement - .createDistributionSet(entityFactory.distributionSet().create().name("ds-1").version("1.0.1") - .type(standardDsType).modules(Arrays.asList(os.getId(), jvm.getId(), ah2.getId()))); + .create(entityFactory.distributionSet().create().name("ds-1").version("1.0.1").type(standardDsType) + .modules(Arrays.asList(os.getId(), jvm.getId(), ah2.getId()))); final JpaTarget target = (JpaTarget) testdataFactory.createTarget(); ds = (JpaDistributionSet) assignSet(target, ds).getDistributionSet(); // standard searches - assertThat(softwareModuleManagement.findSoftwareModuleByFilters(PAGE, "poky", osType.getId()).getContent()) + assertThat(softwareModuleManagement.findByTextAndType(PAGE, "poky", osType.getId()).getContent()).hasSize(1); + assertThat(softwareModuleManagement.findByTextAndType(PAGE, "poky", osType.getId()).getContent().get(0)) + .isEqualTo(os); + assertThat(softwareModuleManagement.findByTextAndType(PAGE, "oracle%", runtimeType.getId()).getContent()) .hasSize(1); - assertThat( - softwareModuleManagement.findSoftwareModuleByFilters(PAGE, "poky", osType.getId()).getContent().get(0)) - .isEqualTo(os); - assertThat( - softwareModuleManagement.findSoftwareModuleByFilters(PAGE, "oracle%", runtimeType.getId()).getContent()) - .hasSize(1); - assertThat(softwareModuleManagement.findSoftwareModuleByFilters(PAGE, "oracle%", runtimeType.getId()) - .getContent().get(0)).isEqualTo(jvm); - assertThat(softwareModuleManagement.findSoftwareModuleByFilters(PAGE, "1.0.1", appType.getId()).getContent()) - .hasSize(1); - assertThat(softwareModuleManagement.findSoftwareModuleByFilters(PAGE, "1.0.1", appType.getId()).getContent() - .get(0)).isEqualTo(ah); - assertThat(softwareModuleManagement.findSoftwareModuleByFilters(PAGE, "1.0%", appType.getId()).getContent()) - .hasSize(2); + assertThat(softwareModuleManagement.findByTextAndType(PAGE, "oracle%", runtimeType.getId()).getContent().get(0)) + .isEqualTo(jvm); + assertThat(softwareModuleManagement.findByTextAndType(PAGE, "1.0.1", appType.getId()).getContent()).hasSize(1); + assertThat(softwareModuleManagement.findByTextAndType(PAGE, "1.0.1", appType.getId()).getContent().get(0)) + .isEqualTo(ah); + assertThat(softwareModuleManagement.findByTextAndType(PAGE, "1.0%", appType.getId()).getContent()).hasSize(2); // no we search with on entity marked as deleted - softwareModuleManagement.deleteSoftwareModule( + softwareModuleManagement.delete( softwareModuleRepository.findByAssignedToAndType(PAGE, ds, appType).getContent().get(0).getId()); - assertThat(softwareModuleManagement.findSoftwareModuleByFilters(PAGE, "1.0%", appType.getId()).getContent()) - .hasSize(1); - assertThat( - softwareModuleManagement.findSoftwareModuleByFilters(PAGE, "1.0%", appType.getId()).getContent().get(0)) - .isEqualTo(ah); + assertThat(softwareModuleManagement.findByTextAndType(PAGE, "1.0%", appType.getId()).getContent()).hasSize(1); + assertThat(softwareModuleManagement.findByTextAndType(PAGE, "1.0%", appType.getId()).getContent().get(0)) + .isEqualTo(ah); } private Action assignSet(final JpaTarget target, final JpaDistributionSet ds) { assignDistributionSet(ds.getId(), target.getControllerId()); - assertThat(targetManagement.findTargetByControllerID(target.getControllerId()).get().getUpdateStatus()) + assertThat(targetManagement.getByControllerID(target.getControllerId()).get().getUpdateStatus()) .isEqualTo(TargetUpdateStatus.PENDING); assertThat(deploymentManagement.getAssignedDistributionSet(target.getControllerId()).get()).isEqualTo(ds); final Action action = actionRepository.findByTargetAndDistributionSet(PAGE, target, ds).getContent().get(0); @@ -230,7 +218,7 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest { final List modules = Arrays.asList(testdataFactory.createSoftwareModuleOs().getId(), testdataFactory.createSoftwareModuleApp().getId(), 624355263L); - assertThat(softwareModuleManagement.findSoftwareModulesById(modules)).hasSize(2); + assertThat(softwareModuleManagement.get(modules)).hasSize(2); } @Test @@ -240,10 +228,10 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest { final SoftwareModule one = testdataFactory.createSoftwareModuleOs("one"); final SoftwareModule two = testdataFactory.createSoftwareModuleOs("two"); // ignored - softwareModuleManagement.deleteSoftwareModule(testdataFactory.createSoftwareModuleOs("deleted").getId()); + softwareModuleManagement.delete(testdataFactory.createSoftwareModuleOs("deleted").getId()); testdataFactory.createSoftwareModuleApp(); - assertThat(softwareModuleManagement.findSoftwareModulesByType(PAGE, osType.getId()).getContent()) + assertThat(softwareModuleManagement.findByType(PAGE, osType.getId()).getContent()) .as("Expected to find the following number of modules:").hasSize(2).as("with the following elements") .contains(two, one); } @@ -256,10 +244,10 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest { testdataFactory.createSoftwareModuleOs("two"); final SoftwareModule deleted = testdataFactory.createSoftwareModuleOs("deleted"); // ignored - softwareModuleManagement.deleteSoftwareModule(deleted.getId()); + softwareModuleManagement.delete(deleted.getId()); - assertThat(softwareModuleManagement.countSoftwareModulesAll()) - .as("Expected to find the following number of modules:").isEqualTo(2); + assertThat(softwareModuleManagement.count()).as("Expected to find the following number of modules:") + .isEqualTo(2); } @Test @@ -273,12 +261,12 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest { final Artifact artifact2 = artifactsIt.next(); // [STEP2]: Delete unassigned SoftwareModule - softwareModuleManagement.deleteSoftwareModule(unassignedModule.getId()); + softwareModuleManagement.delete(unassignedModule.getId()); // [VERIFY EXPECTED RESULT]: // verify: SoftwareModule is deleted assertThat(softwareModuleRepository.findAll()).hasSize(0); - assertThat(softwareModuleManagement.findSoftwareModuleById(unassignedModule.getId())).isNotPresent(); + assertThat(softwareModuleManagement.get(unassignedModule.getId())).isNotPresent(); // verify: binary data of artifact is deleted assertArtfiactNull(artifact1, artifact2); @@ -299,13 +287,13 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest { testdataFactory.createDistributionSet(Sets.newHashSet(assignedModule)); // [STEP3]: Delete the assigned SoftwareModule - softwareModuleManagement.deleteSoftwareModule(assignedModule.getId()); + softwareModuleManagement.delete(assignedModule.getId()); // [VERIFY EXPECTED RESULT]: // verify: assignedModule is marked as deleted - assignedModule = softwareModuleManagement.findSoftwareModuleById(assignedModule.getId()).get(); + assignedModule = softwareModuleManagement.get(assignedModule.getId()).get(); assertTrue("The module should be flagged as deleted", assignedModule.isDeleted()); - assertThat(softwareModuleManagement.findSoftwareModulesAll(PAGE)).hasSize(0); + assertThat(softwareModuleManagement.findAll(PAGE)).hasSize(0); assertThat(softwareModuleRepository.findAll()).hasSize(1); // verify: binary data is deleted @@ -336,16 +324,16 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest { assignDistributionSet(disSet, Arrays.asList(target)); // [STEP4]: Delete the DistributionSet - distributionSetManagement.deleteDistributionSet(disSet.getId()); + distributionSetManagement.delete(disSet.getId()); // [STEP5]: Delete the assigned SoftwareModule - softwareModuleManagement.deleteSoftwareModule(assignedModule.getId()); + softwareModuleManagement.delete(assignedModule.getId()); // [VERIFY EXPECTED RESULT]: // verify: assignedModule is marked as deleted - assignedModule = softwareModuleManagement.findSoftwareModuleById(assignedModule.getId()).get(); + assignedModule = softwareModuleManagement.get(assignedModule.getId()).get(); assertTrue("The found module should be flagged deleted", assignedModule.isDeleted()); - assertThat(softwareModuleManagement.findSoftwareModulesAll(PAGE)).hasSize(0); + assertThat(softwareModuleManagement.findAll(PAGE)).hasSize(0); assertThat(softwareModuleRepository.findAll()).hasSize(1); // verify: binary data is deleted @@ -370,26 +358,26 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest { SoftwareModule moduleX = createSoftwareModuleWithArtifacts(osType, "modulex", "v1.0", 0); // [STEP2]: Create newArtifactX and add it to SoftwareModuleX - artifactManagement.createArtifact(new ByteArrayInputStream(source), moduleX.getId(), "artifactx", false); - moduleX = softwareModuleManagement.findSoftwareModuleById(moduleX.getId()).get(); + artifactManagement.create(new ByteArrayInputStream(source), moduleX.getId(), "artifactx", false); + moduleX = softwareModuleManagement.get(moduleX.getId()).get(); final Artifact artifactX = moduleX.getArtifacts().iterator().next(); // [STEP3]: Create SoftwareModuleY and add the same ArtifactX SoftwareModule moduleY = createSoftwareModuleWithArtifacts(osType, "moduley", "v1.0", 0); // [STEP4]: Assign the same ArtifactX to SoftwareModuleY - artifactManagement.createArtifact(new ByteArrayInputStream(source), moduleY.getId(), "artifactx", false); - moduleY = softwareModuleManagement.findSoftwareModuleById(moduleY.getId()).get(); + artifactManagement.create(new ByteArrayInputStream(source), moduleY.getId(), "artifactx", false); + moduleY = softwareModuleManagement.get(moduleY.getId()).get(); final Artifact artifactY = moduleY.getArtifacts().iterator().next(); // [STEP5]: Delete SoftwareModuleX - softwareModuleManagement.deleteSoftwareModule(moduleX.getId()); + softwareModuleManagement.delete(moduleX.getId()); // [VERIFY EXPECTED RESULT]: // verify: SoftwareModuleX is deleted, and ModuelY still exists assertThat(softwareModuleRepository.findAll()).hasSize(1); - assertThat(softwareModuleManagement.findSoftwareModuleById(moduleX.getId())).isNotPresent(); - assertThat(softwareModuleManagement.findSoftwareModuleById(moduleY.getId())).isPresent(); + assertThat(softwareModuleManagement.get(moduleX.getId())).isNotPresent(); + assertThat(softwareModuleManagement.get(moduleY.getId())).isPresent(); // verify: binary data of artifact is not deleted assertArtfiactNotNull(artifactY); @@ -412,15 +400,15 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest { // [STEP1]: Create SoftwareModuleX and add a new ArtifactX SoftwareModule moduleX = createSoftwareModuleWithArtifacts(osType, "modulex", "v1.0", 0); - artifactManagement.createArtifact(new ByteArrayInputStream(source), moduleX.getId(), "artifactx", false); - moduleX = softwareModuleManagement.findSoftwareModuleById(moduleX.getId()).get(); + artifactManagement.create(new ByteArrayInputStream(source), moduleX.getId(), "artifactx", false); + moduleX = softwareModuleManagement.get(moduleX.getId()).get(); final Artifact artifactX = moduleX.getArtifacts().iterator().next(); // [STEP2]: Create SoftwareModuleY and add the same ArtifactX SoftwareModule moduleY = createSoftwareModuleWithArtifacts(osType, "moduley", "v1.0", 0); - artifactManagement.createArtifact(new ByteArrayInputStream(source), moduleY.getId(), "artifactx", false); - moduleY = softwareModuleManagement.findSoftwareModuleById(moduleY.getId()).get(); + artifactManagement.create(new ByteArrayInputStream(source), moduleY.getId(), "artifactx", false); + moduleY = softwareModuleManagement.get(moduleY.getId()).get(); final Artifact artifactY = moduleY.getArtifacts().iterator().next(); // [STEP3]: Assign SoftwareModuleX to DistributionSetX and to target @@ -432,21 +420,21 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest { assignDistributionSet(disSetY, Arrays.asList(target)); // [STEP5]: Delete SoftwareModuleX - softwareModuleManagement.deleteSoftwareModule(moduleX.getId()); + softwareModuleManagement.delete(moduleX.getId()); // [STEP6]: Delete SoftwareModuleY - softwareModuleManagement.deleteSoftwareModule(moduleY.getId()); + softwareModuleManagement.delete(moduleY.getId()); // [VERIFY EXPECTED RESULT]: - moduleX = softwareModuleManagement.findSoftwareModuleById(moduleX.getId()).get(); - moduleY = softwareModuleManagement.findSoftwareModuleById(moduleY.getId()).get(); + moduleX = softwareModuleManagement.get(moduleX.getId()).get(); + moduleY = softwareModuleManagement.get(moduleY.getId()).get(); // verify: SoftwareModuleX and SofwtareModule are marked as deleted assertThat(moduleX).isNotNull(); assertThat(moduleY).isNotNull(); assertTrue("The module should be flagged deleted", moduleX.isDeleted()); assertTrue("The module should be flagged deleted", moduleY.isDeleted()); - assertThat(softwareModuleManagement.findSoftwareModulesAll(PAGE)).hasSize(0); + assertThat(softwareModuleManagement.findAll(PAGE)).hasSize(0); assertThat(softwareModuleRepository.findAll()).hasSize(2); // verify: binary data of artifact is deleted @@ -462,16 +450,16 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest { final long countSoftwareModule = softwareModuleRepository.count(); // create SoftwareModule - SoftwareModule softwareModule = softwareModuleManagement.createSoftwareModule(entityFactory.softwareModule() - .create().type(type).name(name).version(version).description("description of artifact " + name)); + SoftwareModule softwareModule = softwareModuleManagement.create(entityFactory.softwareModule().create() + .type(type).name(name).version(version).description("description of artifact " + name)); for (int i = 0; i < numberArtifacts; i++) { - artifactManagement.createArtifact(new RandomGeneratedInputStream(5 * 1024), softwareModule.getId(), + artifactManagement.create(new RandomGeneratedInputStream(5 * 1024), softwareModule.getId(), "file" + (i + 1), false); } // Verify correct Creation of SoftwareModule and corresponding artifacts - softwareModule = softwareModuleManagement.findSoftwareModuleById(softwareModule.getId()).get(); + softwareModule = softwareModuleManagement.get(softwareModule.getId()).get(); assertThat(softwareModuleRepository.findAll()).hasSize((int) countSoftwareModule + 1); final List artifacts = softwareModule.getArtifacts(); @@ -505,10 +493,10 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest { @Description("Test verfies that results are returned based on given filter parameters and in the specified order.") public void findSoftwareModuleOrderByDistributionModuleNameAscModuleVersionAsc() { // test meta data - final SoftwareModuleType testType = softwareModuleTypeManagement.createSoftwareModuleType( - entityFactory.softwareModuleType().create().key("thetype").name("thename").maxAssignments(100)); + final SoftwareModuleType testType = softwareModuleTypeManagement + .create(entityFactory.softwareModuleType().create().key("thetype").name("thename").maxAssignments(100)); DistributionSetType testDsType = distributionSetTypeManagement - .createDistributionSetType(entityFactory.distributionSetType().create().key("key").name("name")); + .create(entityFactory.distributionSetType().create().key("key").name("name")); distributionSetTypeManagement.assignMandatorySoftwareModuleTypes(testDsType.getId(), Arrays.asList(osType.getId())); @@ -525,28 +513,28 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest { final SoftwareModule deleted = testdataFactory.createSoftwareModule("thetype", "deleted"); final SoftwareModule four = testdataFactory.createSoftwareModuleOs("e"); - final DistributionSet set = distributionSetManagement.createDistributionSet( - entityFactory.distributionSet().create().name("set").version("1").type(testDsType).modules(Lists + final DistributionSet set = distributionSetManagement + .create(entityFactory.distributionSet().create().name("set").version("1").type(testDsType).modules(Lists .newArrayList(one.getId(), two.getId(), deleted.getId(), four.getId(), differentName.getId()))); - softwareModuleManagement.deleteSoftwareModule(deleted.getId()); + softwareModuleManagement.delete(deleted.getId()); // with filter on name, version and module type - assertThat(softwareModuleManagement.findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(PAGE, + assertThat(softwareModuleManagement.findAllOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(PAGE, set.getId(), "%found%", testType.getId()).getContent()) .as("Found modules with given name, given module type and the assigned ones first") .containsExactly(new AssignedSoftwareModule(one, true), new AssignedSoftwareModule(two, true), new AssignedSoftwareModule(unassigned, false)); // with filter on module type only - assertThat(softwareModuleManagement.findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(PAGE, - set.getId(), null, testType.getId()).getContent()) - .as("Found modules with given module type and the assigned ones first").containsExactly( - new AssignedSoftwareModule(differentName, true), new AssignedSoftwareModule(one, true), - new AssignedSoftwareModule(two, true), new AssignedSoftwareModule(unassigned, false)); + assertThat(softwareModuleManagement + .findAllOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(PAGE, set.getId(), null, testType.getId()) + .getContent()).as("Found modules with given module type and the assigned ones first").containsExactly( + new AssignedSoftwareModule(differentName, true), new AssignedSoftwareModule(one, true), + new AssignedSoftwareModule(two, true), new AssignedSoftwareModule(unassigned, false)); // without any filter assertThat(softwareModuleManagement - .findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(PAGE, set.getId(), null, null) + .findAllOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(PAGE, set.getId(), null, null) .getContent()).as("Found modules with the assigned ones first").containsExactly( new AssignedSoftwareModule(differentName, true), new AssignedSoftwareModule(one, true), new AssignedSoftwareModule(two, true), new AssignedSoftwareModule(four, true), @@ -557,10 +545,10 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest { @Description("Checks that number of modules is returned as expected based on given filters.") public void countSoftwareModuleByFilters() { // test meta data - final SoftwareModuleType testType = softwareModuleTypeManagement.createSoftwareModuleType( - entityFactory.softwareModuleType().create().key("thetype").name("thename").maxAssignments(100)); + final SoftwareModuleType testType = softwareModuleTypeManagement + .create(entityFactory.softwareModuleType().create().key("thetype").name("thename").maxAssignments(100)); DistributionSetType testDsType = distributionSetTypeManagement - .createDistributionSetType(entityFactory.distributionSetType().create().key("key").name("name")); + .create(entityFactory.distributionSetType().create().key("key").name("name")); distributionSetTypeManagement.assignMandatorySoftwareModuleTypes(testDsType.getId(), Arrays.asList(osType.getId())); @@ -577,17 +565,17 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest { final SoftwareModule deleted = testdataFactory.createSoftwareModule("thetype", "deleted"); final SoftwareModule four = testdataFactory.createSoftwareModuleOs("e"); - distributionSetManagement.createDistributionSet( - entityFactory.distributionSet().create().name("set").version("1").type(testDsType).modules(Lists + distributionSetManagement + .create(entityFactory.distributionSet().create().name("set").version("1").type(testDsType).modules(Lists .newArrayList(one.getId(), two.getId(), deleted.getId(), four.getId(), differentName.getId()))); - softwareModuleManagement.deleteSoftwareModule(deleted.getId()); + softwareModuleManagement.delete(deleted.getId()); // test - assertThat(softwareModuleManagement.countSoftwareModuleByFilters("%found%", testType.getId())) + assertThat(softwareModuleManagement.countByTextAndType("%found%", testType.getId())) .as("Number of modules with given name or version and type").isEqualTo(3); - assertThat(softwareModuleManagement.countSoftwareModuleByFilters(null, testType.getId())) + assertThat(softwareModuleManagement.countByTextAndType(null, testType.getId())) .as("Number of modules with given type").isEqualTo(4); - assertThat(softwareModuleManagement.countSoftwareModuleByFilters(null, null)).as("Number of modules overall") + assertThat(softwareModuleManagement.countByTextAndType(null, null)).as("Number of modules overall") .isEqualTo(5); } @@ -599,9 +587,9 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest { // one soft deleted final SoftwareModule deleted = testdataFactory.createSoftwareModuleApp(); testdataFactory.createDistributionSet(Arrays.asList(deleted)); - softwareModuleManagement.deleteSoftwareModule(deleted.getId()); + softwareModuleManagement.delete(deleted.getId()); - assertThat(softwareModuleManagement.countSoftwareModulesAll()).as("Number of undeleted modules").isEqualTo(1); + assertThat(softwareModuleManagement.count()).as("Number of undeleted modules").isEqualTo(1); assertThat(softwareModuleRepository.count()).as("Number of all modules").isEqualTo(2); } @@ -614,11 +602,11 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest { // one soft deleted final SoftwareModule deleted = testdataFactory.createSoftwareModuleApp(); - final DistributionSet set = distributionSetManagement.createDistributionSet(entityFactory.distributionSet() - .create().name("set").version("1").modules(Arrays.asList(one.getId(), deleted.getId()))); - softwareModuleManagement.deleteSoftwareModule(deleted.getId()); + final DistributionSet set = distributionSetManagement.create(entityFactory.distributionSet().create() + .name("set").version("1").modules(Arrays.asList(one.getId(), deleted.getId()))); + softwareModuleManagement.delete(deleted.getId()); - assertThat(softwareModuleManagement.findSoftwareModuleByAssignedTo(PAGE, set.getId()).getContent()) + assertThat(softwareModuleManagement.findByAssignedTo(PAGE, set.getId()).getContent()) .as("Found this number of modules").hasSize(2); } @@ -640,11 +628,10 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest { final SoftwareModuleMetadata swMetadata2 = new JpaSoftwareModuleMetadata(knownKey2, ah, knownValue2); - final List softwareModuleMetadata = softwareModuleManagement - .createSoftwareModuleMetadata(ah.getId(), Arrays.asList(swMetadata1, swMetadata2)); + final List softwareModuleMetadata = softwareModuleManagement.createMetaData(ah.getId(), + Arrays.asList(swMetadata1, swMetadata2)); - final SoftwareModule changedLockRevisionModule = softwareModuleManagement.findSoftwareModuleById(ah.getId()) - .get(); + final SoftwareModule changedLockRevisionModule = softwareModuleManagement.get(ah.getId()).get(); assertThat(changedLockRevisionModule.getOptLockRevision()).isEqualTo(2); assertThat(softwareModuleMetadata).hasSize(2); @@ -664,12 +651,10 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest { final SoftwareModule ah = testdataFactory.createSoftwareModuleApp(); - softwareModuleManagement.createSoftwareModuleMetadata(ah.getId(), - entityFactory.generateMetadata(knownKey1, knownValue1)); + softwareModuleManagement.createMetaData(ah.getId(), entityFactory.generateMetadata(knownKey1, knownValue1)); try { - softwareModuleManagement.createSoftwareModuleMetadata(ah.getId(), - entityFactory.generateMetadata(knownKey1, knownValue2)); + softwareModuleManagement.createMetaData(ah.getId(), entityFactory.generateMetadata(knownKey1, knownValue2)); fail("should not have worked as module metadata already exists"); } catch (final EntityAlreadyExistsException e) { @@ -690,24 +675,23 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest { assertThat(ah.getOptLockRevision()).isEqualTo(1); // create an software module meta data entry - final List softwareModuleMetadata = softwareModuleManagement - .createSoftwareModuleMetadata(ah.getId(), - Collections.singleton(entityFactory.generateMetadata(knownKey, knownValue))); + final List softwareModuleMetadata = softwareModuleManagement.createMetaData(ah.getId(), + Collections.singleton(entityFactory.generateMetadata(knownKey, knownValue))); assertThat(softwareModuleMetadata).hasSize(1); // base software module should have now the opt lock revision one // because we are modifying the // base software module - SoftwareModule changedLockRevisionModule = softwareModuleManagement.findSoftwareModuleById(ah.getId()).get(); + SoftwareModule changedLockRevisionModule = softwareModuleManagement.get(ah.getId()).get(); assertThat(changedLockRevisionModule.getOptLockRevision()).isEqualTo(2); // update the software module metadata Thread.sleep(100); - final SoftwareModuleMetadata updated = softwareModuleManagement.updateSoftwareModuleMetadata(ah.getId(), + final SoftwareModuleMetadata updated = softwareModuleManagement.updateMetaData(ah.getId(), entityFactory.generateMetadata(knownKey, knownUpdateValue)); // we are updating the sw meta data so also modiying the base software // module so opt lock // revision must be two - changedLockRevisionModule = softwareModuleManagement.findSoftwareModuleById(ah.getId()).get(); + changedLockRevisionModule = softwareModuleManagement.get(ah.getId()).get(); assertThat(changedLockRevisionModule.getOptLockRevision()).isEqualTo(3); // verify updated meta data contains the updated value @@ -725,19 +709,16 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest { SoftwareModule ah = testdataFactory.createSoftwareModuleApp(); - ah = softwareModuleManagement - .createSoftwareModuleMetadata(ah.getId(), entityFactory.generateMetadata(knownKey1, knownValue1)) + ah = softwareModuleManagement.createMetaData(ah.getId(), entityFactory.generateMetadata(knownKey1, knownValue1)) .getSoftwareModule(); - assertThat(softwareModuleManagement - .findSoftwareModuleMetadataBySoftwareModuleId(new PageRequest(0, 100), ah.getId()).getContent()) - .as("Contains the created metadata element") + assertThat(softwareModuleManagement.findMetaDataBySoftwareModuleId(new PageRequest(0, 10), ah.getId()) + .getContent()).as("Contains the created metadata element") .containsExactly(new JpaSoftwareModuleMetadata(knownKey1, ah, knownValue1)); - softwareModuleManagement.deleteSoftwareModuleMetadata(ah.getId(), knownKey1); - assertThat(softwareModuleManagement - .findSoftwareModuleMetadataBySoftwareModuleId(new PageRequest(0, 100), ah.getId()).getContent()) - .as("Metadata elemenets are").isEmpty(); + softwareModuleManagement.deleteMetaData(ah.getId(), knownKey1); + assertThat(softwareModuleManagement.findMetaDataBySoftwareModuleId(new PageRequest(0, 10), ah.getId()) + .getContent()).as("Metadata elemenets are").isEmpty(); } @Test @@ -748,11 +729,10 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest { SoftwareModule ah = testdataFactory.createSoftwareModuleApp(); - ah = softwareModuleManagement - .createSoftwareModuleMetadata(ah.getId(), entityFactory.generateMetadata(knownKey1, knownValue1)) + ah = softwareModuleManagement.createMetaData(ah.getId(), entityFactory.generateMetadata(knownKey1, knownValue1)) .getSoftwareModule(); - assertThat(softwareModuleManagement.findSoftwareModuleMetadata(ah.getId(), "doesnotexist")).isNotPresent(); + assertThat(softwareModuleManagement.getMetaDataBySoftwareModuleId(ah.getId(), "doesnotexist")).isNotPresent(); } @Test @@ -764,20 +744,22 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest { SoftwareModule sw2 = testdataFactory.createSoftwareModuleOs(); for (int index = 0; index < 10; index++) { - sw1 = softwareModuleManagement.createSoftwareModuleMetadata(sw1.getId(), - entityFactory.generateMetadata("key" + index, "value" + index)).getSoftwareModule(); + sw1 = softwareModuleManagement + .createMetaData(sw1.getId(), entityFactory.generateMetadata("key" + index, "value" + index)) + .getSoftwareModule(); } for (int index = 0; index < 20; index++) { - sw2 = softwareModuleManagement.createSoftwareModuleMetadata(sw2.getId(), - new JpaSoftwareModuleMetadata("key" + index, sw2, "value" + index)).getSoftwareModule(); + sw2 = softwareModuleManagement + .createMetaData(sw2.getId(), new JpaSoftwareModuleMetadata("key" + index, sw2, "value" + index)) + .getSoftwareModule(); } final Page metadataOfSw1 = softwareModuleManagement - .findSoftwareModuleMetadataBySoftwareModuleId(sw1.getId(), new PageRequest(0, 100)); + .findMetaDataBySoftwareModuleId(new PageRequest(0, 100), sw1.getId()); final Page metadataOfSw2 = softwareModuleManagement - .findSoftwareModuleMetadataBySoftwareModuleId(sw2.getId(), new PageRequest(0, 100)); + .findMetaDataBySoftwareModuleId(new PageRequest(0, 100), sw2.getId()); assertThat(metadataOfSw1.getNumberOfElements()).isEqualTo(10); assertThat(metadataOfSw1.getTotalElements()).isEqualTo(10); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleTypeManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleTypeManagementTest.java index a058bf0f7..0dd0e16dd 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleTypeManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleTypeManagementTest.java @@ -39,9 +39,9 @@ public class SoftwareModuleTypeManagementTest extends AbstractJpaIntegrationTest @ExpectEvents({ @Expect(type = SoftwareModuleCreatedEvent.class, count = 0) }) public void nonExistingEntityAccessReturnsNotPresent() { - assertThat(softwareModuleTypeManagement.findSoftwareModuleTypeById(NOT_EXIST_IDL)).isNotPresent(); - assertThat(softwareModuleTypeManagement.findSoftwareModuleTypeByKey(NOT_EXIST_ID)).isNotPresent(); - assertThat(softwareModuleTypeManagement.findSoftwareModuleTypeByName(NOT_EXIST_ID)).isNotPresent(); + assertThat(softwareModuleTypeManagement.get(NOT_EXIST_IDL)).isNotPresent(); + assertThat(softwareModuleTypeManagement.getByKey(NOT_EXIST_ID)).isNotPresent(); + assertThat(softwareModuleTypeManagement.getByName(NOT_EXIST_ID)).isNotPresent(); } @Test @@ -49,23 +49,23 @@ public class SoftwareModuleTypeManagementTest extends AbstractJpaIntegrationTest + " by means of throwing EntityNotFoundException.") @ExpectEvents({ @Expect(type = SoftwareModuleCreatedEvent.class, count = 0) }) public void entityQueriesReferringToNotExistingEntitiesThrowsException() { - verifyThrownExceptionBy(() -> softwareModuleTypeManagement.deleteSoftwareModuleType(NOT_EXIST_IDL), + verifyThrownExceptionBy(() -> softwareModuleTypeManagement.delete(NOT_EXIST_IDL), "SoftwareModuleType"); verifyThrownExceptionBy( () -> softwareModuleTypeManagement - .updateSoftwareModuleType(entityFactory.softwareModuleType().update(1234L)), + .update(entityFactory.softwareModuleType().update(1234L)), "SoftwareModuleType"); } @Test @Description("Calling update without changing fields results in no recorded change in the repository including unchanged audit fields.") public void updateNothingResultsInUnchangedRepositoryForType() { - final SoftwareModuleType created = softwareModuleTypeManagement.createSoftwareModuleType( + final SoftwareModuleType created = softwareModuleTypeManagement.create( entityFactory.softwareModuleType().create().key("test-key").name("test-name")); final SoftwareModuleType updated = softwareModuleTypeManagement - .updateSoftwareModuleType(entityFactory.softwareModuleType().update(created.getId())); + .update(entityFactory.softwareModuleType().update(created.getId())); assertThat(updated.getOptLockRevision()) .as("Expected version number of updated entitity to be equal to created version") @@ -75,10 +75,10 @@ public class SoftwareModuleTypeManagementTest extends AbstractJpaIntegrationTest @Test @Description("Calling update for changed fields results in change in the repository.") public void updateSoftareModuleTypeFieldsToNewValue() { - final SoftwareModuleType created = softwareModuleTypeManagement.createSoftwareModuleType( + final SoftwareModuleType created = softwareModuleTypeManagement.create( entityFactory.softwareModuleType().create().key("test-key").name("test-name")); - final SoftwareModuleType updated = softwareModuleTypeManagement.updateSoftwareModuleType( + final SoftwareModuleType updated = softwareModuleTypeManagement.update( entityFactory.softwareModuleType().update(created.getId()).description("changed").colour("changed")); assertThat(updated.getOptLockRevision()).as("Expected version number of updated entitity is") @@ -94,9 +94,9 @@ public class SoftwareModuleTypeManagementTest extends AbstractJpaIntegrationTest entityFactory.softwareModuleType().create().key("test-key").name("test-name"), entityFactory.softwareModuleType().create().key("test-key2").name("test-name2")); - softwareModuleTypeManagement.createSoftwareModuleType(created); + softwareModuleTypeManagement.create(created); try { - softwareModuleTypeManagement.createSoftwareModuleType(created); + softwareModuleTypeManagement.create(created); fail("Should not have worked as module already exists."); } catch (final EntityAlreadyExistsException e) { @@ -106,34 +106,34 @@ public class SoftwareModuleTypeManagementTest extends AbstractJpaIntegrationTest @Test @Description("Tests the successfull deletion of software module types. Both unused (hard delete) and used ones (soft delete).") public void deleteAssignedAndUnassignedSoftwareModuleTypes() { - assertThat(softwareModuleTypeManagement.findSoftwareModuleTypesAll(PAGE)).hasSize(3).contains(osType, + assertThat(softwareModuleTypeManagement.findAll(PAGE)).hasSize(3).contains(osType, runtimeType, appType); - SoftwareModuleType type = softwareModuleTypeManagement.createSoftwareModuleType( + SoftwareModuleType type = softwareModuleTypeManagement.create( entityFactory.softwareModuleType().create().key("bundle").name("OSGi Bundle")); - assertThat(softwareModuleTypeManagement.findSoftwareModuleTypesAll(PAGE)).hasSize(4).contains(osType, + assertThat(softwareModuleTypeManagement.findAll(PAGE)).hasSize(4).contains(osType, runtimeType, appType, type); // delete unassigned - softwareModuleTypeManagement.deleteSoftwareModuleType(type.getId()); - assertThat(softwareModuleTypeManagement.findSoftwareModuleTypesAll(PAGE)).hasSize(3).contains(osType, + softwareModuleTypeManagement.delete(type.getId()); + assertThat(softwareModuleTypeManagement.findAll(PAGE)).hasSize(3).contains(osType, runtimeType, appType); assertThat(softwareModuleTypeRepository.findAll()).hasSize(3).contains((JpaSoftwareModuleType) osType, (JpaSoftwareModuleType) runtimeType, (JpaSoftwareModuleType) appType); - type = softwareModuleTypeManagement.createSoftwareModuleType( + type = softwareModuleTypeManagement.create( entityFactory.softwareModuleType().create().key("bundle2").name("OSGi Bundle2")); - assertThat(softwareModuleTypeManagement.findSoftwareModuleTypesAll(PAGE)).hasSize(4).contains(osType, + assertThat(softwareModuleTypeManagement.findAll(PAGE)).hasSize(4).contains(osType, runtimeType, appType, type); - softwareModuleManagement.createSoftwareModule( + softwareModuleManagement.create( entityFactory.softwareModule().create().type(type).name("Test SM").version("1.0")); // delete assigned - softwareModuleTypeManagement.deleteSoftwareModuleType(type.getId()); - assertThat(softwareModuleTypeManagement.findSoftwareModuleTypesAll(PAGE)).hasSize(3).contains(osType, + softwareModuleTypeManagement.delete(type.getId()); + assertThat(softwareModuleTypeManagement.findAll(PAGE)).hasSize(3).contains(osType, runtimeType, appType); assertThat(softwareModuleTypeRepository.findAll()).hasSize(4).contains((JpaSoftwareModuleType) osType, @@ -146,11 +146,11 @@ public class SoftwareModuleTypeManagementTest extends AbstractJpaIntegrationTest public void findSoftwareModuleTypeByName() { testdataFactory.createSoftwareModuleOs(); final SoftwareModuleType found = softwareModuleTypeManagement - .createSoftwareModuleType(entityFactory.softwareModuleType().create().key("thetype").name("thename")); - softwareModuleTypeManagement.createSoftwareModuleType( + .create(entityFactory.softwareModuleType().create().key("thetype").name("thename")); + softwareModuleTypeManagement.create( entityFactory.softwareModuleType().create().key("thetype2").name("anothername")); - assertThat(softwareModuleTypeManagement.findSoftwareModuleTypeByName("thename").get()) + assertThat(softwareModuleTypeManagement.getByName("thename").get()) .as("Type with given name").isEqualTo(found); } @@ -158,9 +158,9 @@ public class SoftwareModuleTypeManagementTest extends AbstractJpaIntegrationTest @Description("Verfies that it is not possible to create a type that alrady exists.") public void createSoftwareModuleTypeFailsWithExistingEntity() { softwareModuleTypeManagement - .createSoftwareModuleType(entityFactory.softwareModuleType().create().key("thetype").name("thename")); + .create(entityFactory.softwareModuleType().create().key("thetype").name("thename")); try { - softwareModuleTypeManagement.createSoftwareModuleType( + softwareModuleTypeManagement.create( entityFactory.softwareModuleType().create().key("thetype").name("thename")); fail("should not have worked as module type already exists"); } catch (final EntityAlreadyExistsException e) { @@ -173,9 +173,9 @@ public class SoftwareModuleTypeManagementTest extends AbstractJpaIntegrationTest @Description("Verfies that it is not possible to create a list of types where one already exists.") public void createSoftwareModuleTypesFailsWithExistingEntity() { softwareModuleTypeManagement - .createSoftwareModuleType(entityFactory.softwareModuleType().create().key("thetype").name("thename")); + .create(entityFactory.softwareModuleType().create().key("thetype").name("thename")); try { - softwareModuleTypeManagement.createSoftwareModuleType( + softwareModuleTypeManagement.create( Arrays.asList(entityFactory.softwareModuleType().create().key("thetype").name("thename"), entityFactory.softwareModuleType().create().key("anothertype").name("anothername"))); fail("should not have worked as module type already exists"); @@ -188,7 +188,7 @@ public class SoftwareModuleTypeManagementTest extends AbstractJpaIntegrationTest @Description("Verifies that the creation of a softwareModuleType is failing because of invalid max assignment") public void createSoftwareModuleTypesFailsWithInvalidMaxAssignment() { try { - softwareModuleTypeManagement.createSoftwareModuleType( + softwareModuleTypeManagement.create( entityFactory.softwareModuleType().create().key("type").name("name").maxAssignments(0)); fail("should not have worked as max assignment is invalid. Should be greater than 0."); } catch (final ConstraintViolationException e) { @@ -199,12 +199,12 @@ public class SoftwareModuleTypeManagementTest extends AbstractJpaIntegrationTest @Test @Description("Verfies that multiple types are created as requested.") public void createMultipleSoftwareModuleTypes() { - final List created = softwareModuleTypeManagement.createSoftwareModuleType( + final List created = softwareModuleTypeManagement.create( Arrays.asList(entityFactory.softwareModuleType().create().key("thetype").name("thename"), entityFactory.softwareModuleType().create().key("thetype2").name("thename2"))); assertThat(created.size()).as("Number of created types").isEqualTo(2); - assertThat(softwareModuleTypeManagement.countSoftwareModuleTypesAll()).as("Number of types in repository") + assertThat(softwareModuleTypeManagement.count()).as("Number of types in repository") .isEqualTo(5); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SystemManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SystemManagementTest.java index e65518392..09f004b6a 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SystemManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SystemManagementTest.java @@ -134,14 +134,14 @@ public class SystemManagementTest extends AbstractJpaIntegrationTest { private void createTestArtifact(final byte[] random) { final SoftwareModule sm = testdataFactory.createSoftwareModuleOs(); - artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", false); + artifactManagement.create(new ByteArrayInputStream(random), sm.getId(), "file1", false); } private void createDeletedTestArtifact(final byte[] random) { final DistributionSet ds = testdataFactory.createDistributionSet("deleted garbage", true); ds.getModules().stream().forEach(module -> { - artifactManagement.createArtifact(new ByteArrayInputStream(random), module.getId(), "file1", false); - softwareModuleManagement.deleteSoftwareModule(module.getId()); + artifactManagement.create(new ByteArrayInputStream(random), module.getId(), "file1", false); + softwareModuleManagement.delete(module.getId()); }); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetFilterQueryManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetFilterQueryManagementTest.java index 60c363242..904453436 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetFilterQueryManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetFilterQueryManagementTest.java @@ -51,8 +51,8 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest + "of Optional not present.") @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) }) public void nonExistingEntityAccessReturnsNotPresent() { - assertThat(targetFilterQueryManagement.findTargetFilterQueryById(NOT_EXIST_IDL)).isNotPresent(); - assertThat(targetFilterQueryManagement.findTargetFilterQueryByName(NOT_EXIST_ID)).isNotPresent(); + assertThat(targetFilterQueryManagement.get(NOT_EXIST_IDL)).isNotPresent(); + assertThat(targetFilterQueryManagement.getByName(NOT_EXIST_ID)).isNotPresent(); } @Test @@ -62,50 +62,51 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest @Expect(type = SoftwareModuleCreatedEvent.class, count = 3) }) public void entityQueriesReferringToNotExistingEntitiesThrowsException() { final DistributionSet set = testdataFactory.createDistributionSet(); - final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement.createTargetFilterQuery( + final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement.create( entityFactory.targetFilterQuery().create().name("test filter").query("name==PendingTargets001")); - verifyThrownExceptionBy(() -> targetFilterQueryManagement.deleteTargetFilterQuery(NOT_EXIST_IDL), + verifyThrownExceptionBy(() -> targetFilterQueryManagement.delete(NOT_EXIST_IDL), "TargetFilterQuery"); - verifyThrownExceptionBy(() -> targetFilterQueryManagement.findTargetFilterQueryByAutoAssignDS(PAGE, - NOT_EXIST_IDL, "name==*"), "DistributionSet"); + verifyThrownExceptionBy( + () -> targetFilterQueryManagement.findByAutoAssignDSAndRsql(PAGE, NOT_EXIST_IDL, "name==*"), + "DistributionSet"); verifyThrownExceptionBy( () -> targetFilterQueryManagement - .updateTargetFilterQuery(entityFactory.targetFilterQuery().update(NOT_EXIST_IDL)), + .update(entityFactory.targetFilterQuery().update(NOT_EXIST_IDL)), "TargetFilterQuery"); verifyThrownExceptionBy(() -> targetFilterQueryManagement - .updateTargetFilterQueryAutoAssignDS(targetFilterQuery.getId(), NOT_EXIST_IDL), "DistributionSet"); + .updateAutoAssignDS(targetFilterQuery.getId(), NOT_EXIST_IDL), "DistributionSet"); verifyThrownExceptionBy( - () -> targetFilterQueryManagement.updateTargetFilterQueryAutoAssignDS(1234L, set.getId()), + () -> targetFilterQueryManagement.updateAutoAssignDS(1234L, set.getId()), "TargetFilterQuery"); verifyThrownExceptionBy(() -> targetFilterQueryManagement - .updateTargetFilterQueryAutoAssignDS(targetFilterQuery.getId(), NOT_EXIST_IDL), "DistributionSet"); + .updateAutoAssignDS(targetFilterQuery.getId(), NOT_EXIST_IDL), "DistributionSet"); } @Test @Description("Test creation of target filter query.") public void createTargetFilterQuery() { final String filterName = "new target filter"; - final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement.createTargetFilterQuery( + final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement.create( entityFactory.targetFilterQuery().create().name(filterName).query("name==PendingTargets001")); assertEquals("Retrieved newly created custom target filter", targetFilterQuery, - targetFilterQueryManagement.findTargetFilterQueryByName(filterName).get()); + targetFilterQueryManagement.getByName(filterName).get()); } @Test @Description("Test searching a target filter query.") public void searchTargetFilterQuery() { final String filterName = "targetFilterQueryName"; - final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement.createTargetFilterQuery( + final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement.create( entityFactory.targetFilterQuery().create().name(filterName).query("name==PendingTargets001")); - targetFilterQueryManagement.createTargetFilterQuery( + targetFilterQueryManagement.create( entityFactory.targetFilterQuery().create().name("someOtherFilter").query("name==PendingTargets002")); final List results = targetFilterQueryManagement - .findTargetFilterQueryByFilter(new PageRequest(0, 10), "name==" + filterName).getContent(); + .findByRsql(new PageRequest(0, 10), "name==" + filterName).getContent(); assertEquals("Search result should have 1 result", 1, results.size()); assertEquals("Retrieved newly created custom target filter", targetFilterQuery, results.get(0)); } @@ -114,7 +115,7 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest @Description("Test searching a target filter query with an invalid filter.") public void searchTargetFilterQueryInvalidField() { // Should throw an exception - targetFilterQueryManagement.findTargetFilterQueryByFilter(new PageRequest(0, 10), "unknownField==testValue") + targetFilterQueryManagement.findByRsql(new PageRequest(0, 10), "unknownField==testValue") .getContent(); } @@ -123,11 +124,11 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest @Description("Checks if the EntityAlreadyExistsException is thrown if a targetfilterquery with the same name are created more than once.") public void createDuplicateTargetFilterQuery() { final String filterName = "new target filter duplicate"; - targetFilterQueryManagement.createTargetFilterQuery( + targetFilterQueryManagement.create( entityFactory.targetFilterQuery().create().name(filterName).query("name==PendingTargets001")); try { - targetFilterQueryManagement.createTargetFilterQuery( + targetFilterQueryManagement.create( entityFactory.targetFilterQuery().create().name(filterName).query("name==PendingTargets001")); fail("should not have worked as query already exists"); } catch (final EntityAlreadyExistsException e) { @@ -139,11 +140,11 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest @Description("Test deletion of target filter query.") public void deleteTargetFilterQuery() { final String filterName = "delete_target_filter_query"; - final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement.createTargetFilterQuery( + final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement.create( entityFactory.targetFilterQuery().create().name(filterName).query("name==PendingTargets001")); - targetFilterQueryManagement.deleteTargetFilterQuery(targetFilterQuery.getId()); + targetFilterQueryManagement.delete(targetFilterQuery.getId()); assertFalse("Returns null as the target filter is deleted", - targetFilterQueryManagement.findTargetFilterQueryById(targetFilterQuery.getId()).isPresent()); + targetFilterQueryManagement.get(targetFilterQuery.getId()).isPresent()); } @@ -151,14 +152,14 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest @Description("Test updation of target filter query.") public void updateTargetFilterQuery() { final String filterName = "target_filter_01"; - final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement.createTargetFilterQuery( + final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement.create( entityFactory.targetFilterQuery().create().name(filterName).query("name==PendingTargets001")); final String newQuery = "status==UNKNOWN"; - targetFilterQueryManagement.updateTargetFilterQuery( + targetFilterQueryManagement.update( entityFactory.targetFilterQuery().update(targetFilterQuery.getId()).query(newQuery)); assertEquals("Returns updated target filter query", newQuery, - targetFilterQueryManagement.findTargetFilterQueryByName(filterName).get().getQuery()); + targetFilterQueryManagement.getByName(filterName).get().getQuery()); } @@ -166,15 +167,15 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest @Description("Test assigning a distribution set") public void assignDistributionSet() { final String filterName = "target_filter_02"; - final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement.createTargetFilterQuery( + final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement.create( entityFactory.targetFilterQuery().create().name(filterName).query("name==PendingTargets001")); final DistributionSet distributionSet = testdataFactory.createDistributionSet(); - targetFilterQueryManagement.updateTargetFilterQueryAutoAssignDS(targetFilterQuery.getId(), + targetFilterQueryManagement.updateAutoAssignDS(targetFilterQuery.getId(), distributionSet.getId()); - final TargetFilterQuery tfq = targetFilterQueryManagement.findTargetFilterQueryByName(filterName).get(); + final TargetFilterQuery tfq = targetFilterQueryManagement.getByName(filterName).get(); assertEquals("Returns correct distribution set", distributionSet, tfq.getAutoAssignDistributionSet()); @@ -184,22 +185,22 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest @Description("Test removing distribution set while it has a relation to a target filter query") public void removeAssignDistributionSet() { final String filterName = "target_filter_03"; - final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement.createTargetFilterQuery( + final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement.create( entityFactory.targetFilterQuery().create().name(filterName).query("name==PendingTargets001")); final DistributionSet distributionSet = testdataFactory.createDistributionSet(); - targetFilterQueryManagement.updateTargetFilterQueryAutoAssignDS(targetFilterQuery.getId(), + targetFilterQueryManagement.updateAutoAssignDS(targetFilterQuery.getId(), distributionSet.getId()); // Check if target filter query is there - TargetFilterQuery tfq = targetFilterQueryManagement.findTargetFilterQueryByName(filterName).get(); + TargetFilterQuery tfq = targetFilterQueryManagement.getByName(filterName).get(); assertEquals("Returns correct distribution set", distributionSet, tfq.getAutoAssignDistributionSet()); - distributionSetManagement.deleteDistributionSet(distributionSet.getId()); + distributionSetManagement.delete(distributionSet.getId()); // Check if auto assign distribution set is null - tfq = targetFilterQueryManagement.findTargetFilterQueryByName(filterName).get(); + tfq = targetFilterQueryManagement.getByName(filterName).get(); assertNotNull("Returns target filter query", tfq); assertNull("Returns distribution set as null", tfq.getAutoAssignDistributionSet()); @@ -216,23 +217,23 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest // later step assignDistributionSet(distributionSet.getId(), target.getControllerId()); - targetFilterQueryManagement.updateTargetFilterQueryAutoAssignDS(targetFilterQueryManagement - .createTargetFilterQuery( + targetFilterQueryManagement.updateAutoAssignDS(targetFilterQueryManagement + .create( entityFactory.targetFilterQuery().create().name(filterName).query("name==PendingTargets001")) .getId(), distributionSet.getId()); // Check if target filter query is there with the distribution set - TargetFilterQuery tfq = targetFilterQueryManagement.findTargetFilterQueryByName(filterName).get(); + TargetFilterQuery tfq = targetFilterQueryManagement.getByName(filterName).get(); assertEquals("Returns correct distribution set", distributionSet, tfq.getAutoAssignDistributionSet()); - distributionSetManagement.deleteDistributionSet(distributionSet.getId()); + distributionSetManagement.delete(distributionSet.getId()); // Check if distribution set is still in the database with deleted flag assertTrue("Distribution set should be deleted", - distributionSetManagement.findDistributionSetById(distributionSet.getId()).get().isDeleted()); + distributionSetManagement.get(distributionSet.getId()).get().isDeleted()); // Check if auto assign distribution set is null - tfq = targetFilterQueryManagement.findTargetFilterQueryByName(filterName).get(); + tfq = targetFilterQueryManagement.getByName(filterName).get(); assertNotNull("Returns target filter query", tfq); assertNull("Returns distribution set as null", tfq.getAutoAssignDistributionSet()); @@ -244,40 +245,40 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest final String filterName = "d"; - assertEquals(0L, targetFilterQueryManagement.countAllTargetFilterQuery().longValue()); + assertEquals(0L, targetFilterQueryManagement.count()); targetFilterQueryManagement - .createTargetFilterQuery(entityFactory.targetFilterQuery().create().name("a").query("name==*")); + .create(entityFactory.targetFilterQuery().create().name("a").query("name==*")); targetFilterQueryManagement - .createTargetFilterQuery(entityFactory.targetFilterQuery().create().name("b").query("name==*")); + .create(entityFactory.targetFilterQuery().create().name("b").query("name==*")); final DistributionSet distributionSet = testdataFactory.createDistributionSet(); final DistributionSet distributionSet2 = testdataFactory.createDistributionSet("2"); final TargetFilterQuery tfq = targetFilterQueryManagement - .updateTargetFilterQueryAutoAssignDS( - targetFilterQueryManagement.createTargetFilterQuery( + .updateAutoAssignDS( + targetFilterQueryManagement.create( entityFactory.targetFilterQuery().create().name("c").query("name==x")).getId(), distributionSet.getId()); - final TargetFilterQuery tfq2 = targetFilterQueryManagement.updateTargetFilterQueryAutoAssignDS( - targetFilterQueryManagement.createTargetFilterQuery( + final TargetFilterQuery tfq2 = targetFilterQueryManagement.updateAutoAssignDS( + targetFilterQueryManagement.create( entityFactory.targetFilterQuery().create().name(filterName).query("name==z*")).getId(), distributionSet2.getId()); - assertEquals(4L, targetFilterQueryManagement.countAllTargetFilterQuery().longValue()); + assertEquals(4L, targetFilterQueryManagement.count()); // check if find works Page tfqList = targetFilterQueryManagement - .findTargetFilterQueryByAutoAssignDS(new PageRequest(0, 500), distributionSet.getId(), null); + .findByAutoAssignDSAndRsql(new PageRequest(0, 500), distributionSet.getId(), null); assertThat(1L).as("Target filter query").isEqualTo(tfqList.getTotalElements()); assertEquals("Returns correct target filter query", tfq.getId(), tfqList.iterator().next().getId()); - targetFilterQueryManagement.updateTargetFilterQueryAutoAssignDS(tfq2.getId(), distributionSet.getId()); + targetFilterQueryManagement.updateAutoAssignDS(tfq2.getId(), distributionSet.getId()); // check if find works for two - tfqList = targetFilterQueryManagement.findTargetFilterQueryByAutoAssignDS(new PageRequest(0, 500), + tfqList = targetFilterQueryManagement.findByAutoAssignDSAndRsql(new PageRequest(0, 500), distributionSet.getId(), null); assertThat(2L).as("Target filter query count").isEqualTo(tfqList.getTotalElements()); Iterator iterator = tfqList.iterator(); @@ -285,14 +286,14 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest assertEquals("Returns correct target filter query 2", tfq2.getId(), iterator.next().getId()); // check if find works with name filter - tfqList = targetFilterQueryManagement.findTargetFilterQueryByAutoAssignDS(new PageRequest(0, 500), + tfqList = targetFilterQueryManagement.findByAutoAssignDSAndRsql(new PageRequest(0, 500), distributionSet.getId(), "name==" + filterName); assertThat(1L).as("Target filter query count").isEqualTo(tfqList.getTotalElements()); assertEquals("Returns correct target filter query", tfq2.getId(), tfqList.iterator().next().getId()); // check if find works for all with auto assign DS - tfqList = targetFilterQueryManagement.findTargetFilterQueryWithAutoAssignDS(new PageRequest(0, 500)); + tfqList = targetFilterQueryManagement.findWithAutoAssignDS(new PageRequest(0, 500)); assertThat(2L).as("Target filter query count").isEqualTo(tfqList.getTotalElements()); iterator = tfqList.iterator(); assertEquals("Returns correct target filter query 1", tfq.getId(), iterator.next().getId()); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetManagementSearchTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetManagementSearchTest.java index 537e28d29..754608eab 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetManagementSearchTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetManagementSearchTest.java @@ -47,10 +47,10 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { + "That includes both the test itself, as a count operation with the same filters " + "and query definitions by RSQL (named and un-named).") public void targetSearchWithVariousFilterCombinations() { - final TargetTag targTagX = tagManagement.createTargetTag(entityFactory.tag().create().name("TargTag-X")); - final TargetTag targTagY = tagManagement.createTargetTag(entityFactory.tag().create().name("TargTag-Y")); - final TargetTag targTagZ = tagManagement.createTargetTag(entityFactory.tag().create().name("TargTag-Z")); - final TargetTag targTagW = tagManagement.createTargetTag(entityFactory.tag().create().name("TargTag-W")); + final TargetTag targTagX = targetTagManagement.create(entityFactory.tag().create().name("TargTag-X")); + final TargetTag targTagY = targetTagManagement.create(entityFactory.tag().create().name("TargTag-Y")); + final TargetTag targTagZ = targetTagManagement.create(entityFactory.tag().create().name("TargTag-Z")); + final TargetTag targTagW = targetTagManagement.create(entityFactory.tag().create().name("TargTag-W")); final DistributionSet setA = testdataFactory.createDistributionSet(""); @@ -66,7 +66,7 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { targAs = toggleTagAssignment(targAs, targTagX).getAssignedEntity(); final Target targSpecialName = targetManagement - .updateTarget(entityFactory.target().update(targAs.get(0).getControllerId()).name("targ-A-special")); + .update(entityFactory.target().update(targAs.get(0).getControllerId()).name("targ-A-special")); final String targetDsBIdPref = "targ-B"; List targBs = testdataFactory.createTargets(100, targetDsBIdPref, @@ -102,61 +102,58 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { final List unknown = Arrays.asList(TargetUpdateStatus.UNKNOWN); final List pending = Arrays.asList(TargetUpdateStatus.PENDING); - final List both = Arrays.asList(TargetUpdateStatus.UNKNOWN, - TargetUpdateStatus.PENDING); + final List both = Arrays.asList(TargetUpdateStatus.UNKNOWN, TargetUpdateStatus.PENDING); // get final updated version of targets targAs = targetManagement - .findTargetsByControllerID(targAs.stream().map(Target::getControllerId).collect(Collectors.toList())); + .getByControllerID(targAs.stream().map(Target::getControllerId).collect(Collectors.toList())); targBs = targetManagement - .findTargetsByControllerID(targBs.stream().map(Target::getControllerId).collect(Collectors.toList())); + .getByControllerID(targBs.stream().map(Target::getControllerId).collect(Collectors.toList())); targCs = targetManagement - .findTargetsByControllerID(targCs.stream().map(Target::getControllerId).collect(Collectors.toList())); + .getByControllerID(targCs.stream().map(Target::getControllerId).collect(Collectors.toList())); // try to find several targets with different filter settings verifyThat1TargetHasNameAndId("targ-A-special", targSpecialName.getControllerId()); verifyThatRepositoryContains400Targets(); verifyThat200TargetsHaveTagD(targTagW, concat(targBs, targCs)); verifyThat100TargetsContainsGivenTextAndHaveTagAssigned(targTagY, targTagW, targBs); - verifyThat1TargetHasTagHasDescOrNameAndDs(targTagW, setA, - targetManagement.findTargetByControllerID(assignedC).get()); + verifyThat1TargetHasTagHasDescOrNameAndDs(targTagW, setA, targetManagement.getByControllerID(assignedC).get()); verifyThat0TargetsWithTagAndDescOrNameHasDS(targTagW, setA); verifyThat0TargetsWithNameOrdescAndDSHaveTag(targTagX, setA); verifyThat3TargetsHaveDSAssigned(setA, - targetManagement.findTargetsByControllerID(Arrays.asList(assignedA, assignedB, assignedC))); - verifyThat1TargetWithDescOrNameHasDS(setA, targetManagement.findTargetByControllerID(assignedA).get()); + targetManagement.getByControllerID(Arrays.asList(assignedA, assignedB, assignedC))); + verifyThat1TargetWithDescOrNameHasDS(setA, targetManagement.getByControllerID(assignedA).get()); List expected = concat(targAs, targBs, targCs, targDs); - expected.removeAll( - targetManagement.findTargetsByControllerID(Arrays.asList(assignedA, assignedB, assignedC))); + expected.removeAll(targetManagement.getByControllerID(Arrays.asList(assignedA, assignedB, assignedC))); verifyThat397TargetsAreInStatusUnknown(unknown, expected); expected = concat(targBs, targCs); - expected.removeAll(targetManagement.findTargetsByControllerID(Arrays.asList(assignedB, assignedC))); + expected.removeAll(targetManagement.getByControllerID(Arrays.asList(assignedB, assignedC))); verifyThat198TargetsAreInStatusUnknownAndHaveGivenTags(targTagY, targTagW, unknown, expected); verfyThat0TargetsAreInStatusUnknownAndHaveDSAssigned(setA, unknown); expected = concat(targAs); - expected.remove(targetManagement.findTargetByControllerID(assignedA).get()); + expected.remove(targetManagement.getByControllerID(assignedA).get()); verifyThat99TargetsWithNameOrDescriptionAreInGivenStatus(unknown, expected); expected = concat(targBs); - expected.remove(targetManagement.findTargetByControllerID(assignedB).get()); + expected.remove(targetManagement.getByControllerID(assignedB).get()); verifyThat99TargetsWithGivenNameOrDescAndTagAreInStatusUnknown(targTagW, unknown, expected); verifyThat3TargetsAreInStatusPending(pending, - targetManagement.findTargetsByControllerID(Arrays.asList(assignedA, assignedB, assignedC))); + targetManagement.getByControllerID(Arrays.asList(assignedA, assignedB, assignedC))); verifyThat3TargetsWithGivenDSAreInPending(setA, pending, - targetManagement.findTargetsByControllerID(Arrays.asList(assignedA, assignedB, assignedC))); + targetManagement.getByControllerID(Arrays.asList(assignedA, assignedB, assignedC))); verifyThat1TargetWithGivenNameOrDescAndDSIsInPending(setA, pending, - targetManagement.findTargetByControllerID(assignedA).get()); + targetManagement.getByControllerID(assignedA).get()); verifyThat1TargetWithGivenNameOrDescAndTagAndDSIsInPending(targTagW, setA, pending, - targetManagement.findTargetByControllerID(assignedB).get()); + targetManagement.getByControllerID(assignedB).get()); verifyThat2TargetsWithGivenTagAndDSIsInPending(targTagW, setA, pending, - targetManagement.findTargetsByControllerID(Arrays.asList(assignedB, assignedC))); + targetManagement.getByControllerID(Arrays.asList(assignedB, assignedC))); verifyThat2TargetsWithGivenTagAreInPending(targTagW, pending, - targetManagement.findTargetsByControllerID(Arrays.asList(assignedB, assignedC))); + targetManagement.getByControllerID(Arrays.asList(assignedB, assignedC))); verifyThat200targetsWithGivenTagAreInStatusPendingorUnknown(targTagW, both, concat(targBs, targCs)); verfiyThat1TargetAIsInStatusPendingAndHasDSInstalled(installedSet, pending, - targetManagement.findTargetByControllerID(installedC).get()); + targetManagement.getByControllerID(installedC).get()); expected = concat(targBs, targCs); - expected.removeAll(targetManagement.findTargetsByControllerID(Arrays.asList(assignedB, assignedC))); + expected.removeAll(targetManagement.getByControllerID(Arrays.asList(assignedB, assignedC))); verifyThat198TargetsAreInStatusUnknownAndOverdue(unknown, expected); } @@ -165,14 +162,15 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { final List pending, final Target expected) { final String query = "updatestatus==pending and installedds.name==" + installedSet.getName(); assertThat(targetManagement - .findTargetByFilters(PAGE, pending, null, null, installedSet.getId(), Boolean.FALSE, new String[0]) + .findByFilters(PAGE, + new FilterParams(pending, null, null, installedSet.getId(), Boolean.FALSE, new String[0])) .getContent()).as("has number of elements").hasSize(1) .as("that number is also returned by count query") - .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(pending, null, null, + .hasSize(Ints.saturatedCast(targetManagement.countByFilters(pending, null, null, installedSet.getId(), Boolean.FALSE, new String[0]))) .as("and contains the following elements").containsExactly(expected) .as("and filter query returns the same result") - .containsAll(targetManagement.findTargetsAll(query, PAGE).getContent()); + .containsAll(targetManagement.findByRsql(PAGE, query).getContent()); } @@ -182,13 +180,14 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { final String query = "(updatestatus==pending or updatestatus==unknown) and tag==" + targTagW.getName(); assertThat(targetManagement - .findTargetByFilters(PAGE, both, null, null, null, Boolean.FALSE, targTagW.getName()).getContent()) - .as("has number of elements").hasSize(200).as("that number is also returned by count query") - .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(both, null, null, null, + .findByFilters(PAGE, new FilterParams(both, null, null, null, Boolean.FALSE, targTagW.getName())) + .getContent()).as("has number of elements").hasSize(200) + .as("that number is also returned by count query") + .hasSize(Ints.saturatedCast(targetManagement.countByFilters(both, null, null, null, Boolean.FALSE, targTagW.getName()))) .as("and contains the following elements").containsAll(expected) .as("and filter query returns the same result") - .containsAll(targetManagement.findTargetsAll(query, PAGE).getContent()); + .containsAll(targetManagement.findByRsql(PAGE, query).getContent()); } @Step @@ -197,14 +196,14 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { final String query = "updatestatus==pending and tag==" + targTagW.getName(); assertThat(targetManagement - .findTargetByFilters(PAGE, pending, null, null, null, Boolean.FALSE, targTagW.getName()) + .findByFilters(PAGE, new FilterParams(pending, null, null, null, Boolean.FALSE, targTagW.getName())) .getContent()).as("has number of elements").hasSize(2) .as("that number is also returned by count query") - .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(pending, null, null, null, + .hasSize(Ints.saturatedCast(targetManagement.countByFilters(pending, null, null, null, Boolean.FALSE, targTagW.getName()))) .as("and contains the following elements").containsAll(expected) .as("and filter query returns the same result") - .containsAll(targetManagement.findTargetsAll(query, PAGE).getContent()); + .containsAll(targetManagement.findByRsql(PAGE, query).getContent()); } @Step @@ -214,14 +213,15 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { + setA.getName() + ") and tag==" + targTagW.getName(); assertThat(targetManagement - .findTargetByFilters(PAGE, pending, null, null, setA.getId(), Boolean.FALSE, targTagW.getName()) + .findByFilters(PAGE, + new FilterParams(pending, null, null, setA.getId(), Boolean.FALSE, targTagW.getName())) .getContent()).as("has number of elements").hasSize(2) .as("that number is also returned by count query") - .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(pending, null, null, - setA.getId(), Boolean.FALSE, targTagW.getName()))) + .hasSize(Ints.saturatedCast(targetManagement.countByFilters(pending, null, null, setA.getId(), + Boolean.FALSE, targTagW.getName()))) .as("and contains the following elements").containsAll(expected) .as("and filter query returns the same result") - .containsAll(targetManagement.findTargetsAll(query, PAGE).getContent()); + .containsAll(targetManagement.findByRsql(PAGE, query).getContent()); } @Step @@ -230,14 +230,16 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { final String query = "updatestatus==pending and (assignedds.name==" + setA.getName() + " or installedds.name==" + setA.getName() + ") and (name==*targ-B* or description==*targ-B*) and tag==" + targTagW.getName(); - assertThat(targetManagement.findTargetByFilters(PAGE, pending, null, "%targ-B%", setA.getId(), Boolean.FALSE, - targTagW.getName()).getContent()).as("has number of elements").hasSize(1) + assertThat(targetManagement + .findByFilters(PAGE, + new FilterParams(pending, null, "%targ-B%", setA.getId(), Boolean.FALSE, targTagW.getName())) + .getContent()).as("has number of elements").hasSize(1) .as("that number is also returned by count query") - .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(pending, null, "%targ-B%", + .hasSize(Ints.saturatedCast(targetManagement.countByFilters(pending, null, "%targ-B%", setA.getId(), Boolean.FALSE, targTagW.getName()))) .as("and contains the following elements").containsExactly(expected) .as("and filter query returns the same result") - .containsAll(targetManagement.findTargetsAll(query, PAGE).getContent()); + .containsAll(targetManagement.findByRsql(PAGE, query).getContent()); } @Step @@ -247,14 +249,15 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { + setA.getName() + ") and (name==*targ-A* or description==*targ-A*)"; assertThat(targetManagement - .findTargetByFilters(PAGE, pending, null, "%targ-A%", setA.getId(), Boolean.FALSE, new String[0]) + .findByFilters(PAGE, + new FilterParams(pending, null, "%targ-A%", setA.getId(), Boolean.FALSE, new String[0])) .getContent()).as("has number of elements").hasSize(1) .as("that number is also returned by count query") - .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(pending, null, "%targ-A%", + .hasSize(Ints.saturatedCast(targetManagement.countByFilters(pending, null, "%targ-A%", setA.getId(), Boolean.FALSE, new String[0]))) .as("and contains the following elements").containsExactly(expected) .as("and filter query returns the same result") - .containsAll(targetManagement.findTargetsAll(query, PAGE).getContent()); + .containsAll(targetManagement.findByRsql(PAGE, query).getContent()); } @Step @@ -264,14 +267,14 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { + setA.getName() + ")"; assertThat(targetManagement - .findTargetByFilters(PAGE, pending, null, null, setA.getId(), Boolean.FALSE, new String[0]) + .findByFilters(PAGE, new FilterParams(pending, null, null, setA.getId(), Boolean.FALSE, new String[0])) .getContent()).as("has number of elements").hasSize(3) .as("that number is also returned by count query") - .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(pending, null, null, - setA.getId(), Boolean.FALSE, new String[0]))) + .hasSize(Ints.saturatedCast(targetManagement.countByFilters(pending, null, null, setA.getId(), + Boolean.FALSE, new String[0]))) .as("and contains the following elements").containsAll(expected) .as("and filter query returns the same result") - .containsAll(targetManagement.findTargetsAll(query, PAGE).getContent()); + .containsAll(targetManagement.findByRsql(PAGE, query).getContent()); } @Step @@ -280,13 +283,14 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { final String query = "updatestatus==pending"; assertThat(targetManagement - .findTargetByFilters(PAGE, pending, null, null, null, Boolean.FALSE, new String[0]).getContent()) - .as("has number of elements").hasSize(3).as("that number is also returned by count query") - .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(pending, null, null, null, + .findByFilters(PAGE, new FilterParams(pending, null, null, null, Boolean.FALSE, new String[0])) + .getContent()).as("has number of elements").hasSize(3) + .as("that number is also returned by count query") + .hasSize(Ints.saturatedCast(targetManagement.countByFilters(pending, null, null, null, Boolean.FALSE, new String[0]))) .as("and contains the following elements").containsAll(expected) .as("and filter query returns the same result") - .containsAll(targetManagement.findTargetsAll(query, PAGE).getContent()); + .containsAll(targetManagement.findByRsql(PAGE, query).getContent()); } @Step @@ -296,14 +300,15 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { + targTagW.getName(); assertThat(targetManagement - .findTargetByFilters(PAGE, unknown, null, "%targ-B%", null, Boolean.FALSE, targTagW.getName()) + .findByFilters(PAGE, + new FilterParams(unknown, null, "%targ-B%", null, Boolean.FALSE, targTagW.getName())) .getContent()).as("has number of elements").hasSize(99) .as("that number is also returned by count query") - .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(unknown, null, "%targ-B%", - null, Boolean.FALSE, targTagW.getName()))) + .hasSize(Ints.saturatedCast(targetManagement.countByFilters(unknown, null, "%targ-B%", null, + Boolean.FALSE, targTagW.getName()))) .as("and contains the following elements").containsAll(expected) .as("and filter query returns the same result") - .containsAll(targetManagement.findTargetsAll(query, PAGE).getContent()); + .containsAll(targetManagement.findByRsql(PAGE, query).getContent()); } @Step @@ -312,14 +317,14 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { final String query = "updatestatus==unknown and (name==*targ-A* or description==*targ-A*)"; assertThat(targetManagement - .findTargetByFilters(PAGE, unknown, null, "%targ-A%", null, Boolean.FALSE, new String[0]) + .findByFilters(PAGE, new FilterParams(unknown, null, "%targ-A%", null, Boolean.FALSE, new String[0])) .getContent()).as("has number of elements").hasSize(99) .as("that number is also returned by count query") - .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(unknown, null, "%targ-A%", - null, Boolean.FALSE, new String[0]))) + .hasSize(Ints.saturatedCast(targetManagement.countByFilters(unknown, null, "%targ-A%", null, + Boolean.FALSE, new String[0]))) .as("and contains the following elements").containsAll(expected) .as("and filter query returns the same result") - .containsAll(targetManagement.findTargetsAll(query, PAGE).getContent()); + .containsAll(targetManagement.findByRsql(PAGE, query).getContent()); } @@ -330,13 +335,13 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { + setA.getName() + ")"; assertThat(targetManagement - .findTargetByFilters(PAGE, unknown, null, null, setA.getId(), Boolean.FALSE, new String[0]) + .findByFilters(PAGE, new FilterParams(unknown, null, null, setA.getId(), Boolean.FALSE, new String[0])) .getContent()).as("has number of elements").hasSize(0) .as("that number is also returned by count query") - .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(unknown, null, null, - setA.getId(), Boolean.FALSE, new String[0]))) + .hasSize(Ints.saturatedCast(targetManagement.countByFilters(unknown, null, null, setA.getId(), + Boolean.FALSE, new String[0]))) .as("and filter query returns the same result") - .hasSize(targetManagement.findTargetsAll(query, PAGE).getContent().size()); + .hasSize(targetManagement.findByRsql(PAGE, query).getContent().size()); } @Step @@ -345,14 +350,15 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { final String query = "updatestatus==unknown and (tag==" + targTagY.getName() + " or tag==" + targTagW.getName() + ")"; - assertThat(targetManagement.findTargetByFilters(PAGE, unknown, null, null, null, Boolean.FALSE, - targTagY.getName(), targTagW.getName()).getContent()).as("has number of elements").hasSize(198) + assertThat(targetManagement.findByFilters(PAGE, + new FilterParams(unknown, null, null, null, Boolean.FALSE, targTagY.getName(), targTagW.getName())) + .getContent()).as("has number of elements").hasSize(198) .as("that number is also returned by count query") - .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(unknown, null, null, null, + .hasSize(Ints.saturatedCast(targetManagement.countByFilters(unknown, null, null, null, Boolean.FALSE, targTagY.getName(), targTagW.getName()))) .as("and contains the following elements").containsAll(expected) .as("and filter query returns the same result") - .containsAll(targetManagement.findTargetsAll(query, PAGE).getContent()); + .containsAll(targetManagement.findByRsql(PAGE, query).getContent()); } @Step @@ -361,13 +367,14 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { final String query = "updatestatus==unknown"; assertThat(targetManagement - .findTargetByFilters(PAGE, unknown, null, null, null, Boolean.FALSE, new String[0]).getContent()) - .as("has number of elements").hasSize(397).as("that number is also returned by count query") - .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(unknown, null, null, null, + .findByFilters(PAGE, new FilterParams(unknown, null, null, null, Boolean.FALSE, new String[0])) + .getContent()).as("has number of elements").hasSize(397) + .as("that number is also returned by count query") + .hasSize(Ints.saturatedCast(targetManagement.countByFilters(unknown, null, null, null, Boolean.FALSE, new String[0]))) .as("and contains the following elements").containsAll(expected) .as("and filter query returns the same result") - .containsAll(targetManagement.findTargetsAll(query, PAGE).getContent()); + .containsAll(targetManagement.findByRsql(PAGE, query).getContent()); } @@ -378,14 +385,14 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { final String query = "lastcontrollerrequestat=le=${overdue_ts};updatestatus==UNKNOWN"; assertThat(targetManagement - .findTargetByFilters(PAGE, unknown, Boolean.TRUE, null, null, Boolean.FALSE, new String[0]) + .findByFilters(PAGE, new FilterParams(unknown, Boolean.TRUE, null, null, Boolean.FALSE, new String[0])) .getContent()).as("has number of elements").hasSize(198) .as("that number is also returned by count query") - .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(unknown, Boolean.TRUE, null, - null, Boolean.FALSE, new String[0]))) + .hasSize(Ints.saturatedCast(targetManagement.countByFilters(unknown, Boolean.TRUE, null, null, + Boolean.FALSE, new String[0]))) .as("and contains the following elements").containsAll(expected) .as("and filter query returns the same result") - .containsAll(targetManagement.findTargetsAll(query, PAGE).getContent()); + .containsAll(targetManagement.findByRsql(PAGE, query).getContent()); } @Step @@ -394,14 +401,15 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { + " or installedds.name==" + setA.getName() + ")"; assertThat(targetManagement - .findTargetByFilters(PAGE, null, null, "%targ-A%", setA.getId(), Boolean.FALSE, new String[0]) + .findByFilters(PAGE, + new FilterParams(null, null, "%targ-A%", setA.getId(), Boolean.FALSE, new String[0])) .getContent()).as("has number of elements").hasSize(1) .as("that number is also returned by count query") - .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(null, null, "%targ-A%", + .hasSize(Ints.saturatedCast(targetManagement.countByFilters(null, null, "%targ-A%", setA.getId(), Boolean.FALSE, new String[0]))) .as("and contains the following elements").containsExactly(expected) .as("and filter query returns the same result") - .containsAll(targetManagement.findTargetsAll(query, PAGE).getContent()); + .containsAll(targetManagement.findByRsql(PAGE, query).getContent()); } @@ -410,14 +418,14 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { final String query = "assignedds.name==" + setA.getName() + " or installedds.name==" + setA.getName(); assertThat(targetManagement - .findTargetByFilters(PAGE, null, null, null, setA.getId(), Boolean.FALSE, new String[0]) + .findByFilters(PAGE, new FilterParams(null, null, null, setA.getId(), Boolean.FALSE, new String[0])) .getContent()).as("has number of elements").hasSize(3) .as("that number is also returned by count query") - .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(null, null, null, - setA.getId(), Boolean.FALSE, new String[0]))) + .hasSize(Ints.saturatedCast(targetManagement.countByFilters(null, null, null, setA.getId(), + Boolean.FALSE, new String[0]))) .as("and contains the following elements").containsAll(expected) .as("and filter query returns the same result") - .containsAll(targetManagement.findTargetsAll(query, PAGE).getContent()); + .containsAll(targetManagement.findByRsql(PAGE, query).getContent()); } @@ -426,13 +434,14 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { final String query = "(name==*targ-C* or description==*targ-C*) and tag==" + targTagX.getName() + " and (assignedds.name==" + setA.getName() + " or installedds.name==" + setA.getName() + ")"; assertThat(targetManagement - .findTargetByFilters(PAGE, null, null, "%targ-C%", setA.getId(), Boolean.FALSE, targTagX.getName()) + .findByFilters(PAGE, + new FilterParams(null, null, "%targ-C%", setA.getId(), Boolean.FALSE, targTagX.getName())) .getContent()).as("has number of elements").hasSize(0) .as("that number is also returned by count query") - .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(null, null, "%targ-C%", + .hasSize(Ints.saturatedCast(targetManagement.countByFilters(null, null, "%targ-C%", setA.getId(), Boolean.FALSE, targTagX.getName()))) .as("and filter query returns the same result") - .hasSize(targetManagement.findTargetsAll(query, PAGE).getContent().size()); + .hasSize(targetManagement.findByRsql(PAGE, query).getContent().size()); } @@ -441,13 +450,14 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { final String query = "(name==*targ-A* or description==*targ-A*) and tag==" + targTagW.getName() + " and (assignedds.name==" + setA.getName() + " or installedds.name==" + setA.getName() + ")"; assertThat(targetManagement - .findTargetByFilters(PAGE, null, null, "%targ-A%", setA.getId(), Boolean.FALSE, targTagW.getName()) + .findByFilters(PAGE, + new FilterParams(null, null, "%targ-A%", setA.getId(), Boolean.FALSE, targTagW.getName())) .getContent()).as("has number of elements").hasSize(0) .as("that number is also returned by count query") - .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(null, null, "%targ-A%", + .hasSize(Ints.saturatedCast(targetManagement.countByFilters(null, null, "%targ-A%", setA.getId(), Boolean.FALSE, targTagW.getName()))) .as("and filter query returns the same result") - .hasSize(targetManagement.findTargetsAll(query, PAGE).getContent().size()); + .hasSize(targetManagement.findByRsql(PAGE, query).getContent().size()); } @@ -457,27 +467,29 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { final String query = "(name==*targ-c* or description==*targ-C*) and tag==" + targTagW.getName() + " and (assignedds.name==" + setA.getName() + " or installedds.name==" + setA.getName() + ")"; assertThat(targetManagement - .findTargetByFilters(PAGE, null, null, "%targ-C%", setA.getId(), Boolean.FALSE, targTagW.getName()) + .findByFilters(PAGE, + new FilterParams(null, null, "%targ-C%", setA.getId(), Boolean.FALSE, targTagW.getName())) .getContent()).as("has number of elements").hasSize(1) .as("that number is also returned by count query") - .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(null, null, "%targ-C%", + .hasSize(Ints.saturatedCast(targetManagement.countByFilters(null, null, "%targ-C%", setA.getId(), Boolean.FALSE, targTagW.getName()))) .as("and contains the following elements").containsExactly(expected) .as("and filter query returns the same result") - .containsAll(targetManagement.findTargetsAll(query, PAGE).getContent()); + .containsAll(targetManagement.findByRsql(PAGE, query).getContent()); } @Step private void verifyThat1TargetHasNameAndId(final String name, final String controllerId) { - assertThat(targetManagement.findTargetByFilters(PAGE, null, null, name, null, Boolean.FALSE).getContent()) - .as("has number of elements").hasSize(1).as("that number is also returned by count query").hasSize(Ints - .saturatedCast(targetManagement.countTargetByFilters(null, null, name, null, Boolean.FALSE))); + assertThat(targetManagement.findByFilters(PAGE, new FilterParams(null, null, name, null, Boolean.FALSE)) + .getContent()).as("has number of elements").hasSize(1).as("that number is also returned by count query") + .hasSize(Ints + .saturatedCast(targetManagement.countByFilters(null, null, name, null, Boolean.FALSE))); - assertThat(targetManagement.findTargetByFilters(PAGE, null, null, controllerId, null, Boolean.FALSE) + assertThat(targetManagement.findByFilters(PAGE, new FilterParams(null, null, controllerId, null, Boolean.FALSE)) .getContent()).as("has number of elements").hasSize(1).as("that number is also returned by count query") .hasSize(Ints.saturatedCast( - targetManagement.countTargetByFilters(null, null, controllerId, null, Boolean.FALSE))); + targetManagement.countByFilters(null, null, controllerId, null, Boolean.FALSE))); } @Step @@ -485,14 +497,15 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { final TargetTag targTagW, final List expected) { final String query = "(name==*targ-B* or description==*targ-B*) and (tag==" + targTagY.getName() + " or tag==" + targTagW.getName() + ")"; - assertThat(targetManagement.findTargetByFilters(PAGE, null, null, "%targ-B%", null, Boolean.FALSE, - targTagY.getName(), targTagW.getName()).getContent()).as("has number of elements").hasSize(100) + assertThat(targetManagement.findByFilters(PAGE, + new FilterParams(null, null, "%targ-B%", null, Boolean.FALSE, targTagY.getName(), targTagW.getName())) + .getContent()).as("has number of elements").hasSize(100) .as("that number is also returned by count query") - .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(null, null, "%targ-B%", null, + .hasSize(Ints.saturatedCast(targetManagement.countByFilters(null, null, "%targ-B%", null, Boolean.FALSE, targTagY.getName(), targTagW.getName()))) .as("and contains the following elements").containsAll(expected) .as("and filter query returns the same result") - .containsAll(targetManagement.findTargetsAll(query, PAGE).getContent()); + .containsAll(targetManagement.findByRsql(PAGE, query).getContent()); } @@ -507,26 +520,25 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { private void verifyThat200TargetsHaveTagD(final TargetTag targTagD, final List expected) { final String query = "tag==" + targTagD.getName(); assertThat(targetManagement - .findTargetByFilters(PAGE, null, null, null, null, Boolean.FALSE, targTagD.getName()).getContent()) - .as("Expected number of results is").hasSize(200) + .findByFilters(PAGE, new FilterParams(null, null, null, null, Boolean.FALSE, targTagD.getName())) + .getContent()).as("Expected number of results is").hasSize(200) .as("and is expected number of results is equal to ") - .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(null, null, null, null, + .hasSize(Ints.saturatedCast(targetManagement.countByFilters(null, null, null, null, Boolean.FALSE, targTagD.getName()))) .as("and contains the following elements").containsAll(expected) .as("and filter query returns the same result") - .containsAll(targetManagement.findTargetsAll(query, PAGE).getContent()); + .containsAll(targetManagement.findByRsql(PAGE, query).getContent()); } @Step private void verifyThatRepositoryContains400Targets() { - assertThat( - targetManagement.findTargetByFilters(PAGE, null, null, null, null, null, new String[0]).getContent()) - .as("Overall we expect that many targets in the repository").hasSize(400) + assertThat(targetManagement.findByFilters(PAGE, new FilterParams(null, null, null, null, null, new String[0])) + .getContent()).as("Overall we expect that many targets in the repository").hasSize(400) .as("which is also reflected by repository count") - .hasSize(Ints.saturatedCast(targetManagement.countTargetsAll())) + .hasSize(Ints.saturatedCast(targetManagement.count())) .as("which is also reflected by call without specification") - .containsAll(targetManagement.findTargetsAll(PAGE).getContent()); + .containsAll(targetManagement.findAll(PAGE).getContent()); } @@ -546,7 +558,7 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { .sendUpdateActionStatusToTargets(targInstalled, Status.FINISHED, Collections.singletonList("installed")) .stream().map(Action::getTarget).collect(Collectors.toList()); - final Slice result = targetManagement.findTargetsAllOrderByLinkedDistributionSet(PAGE, ds.getId(), + final Slice result = targetManagement.findByFilterOrderByLinkedDistributionSet(PAGE, ds.getId(), new FilterParams(null, null, null, null, Boolean.FALSE, new String[0])); final Comparator byId = (e1, e2) -> Long.compare(e2.getId(), e1.getId()); @@ -580,11 +592,11 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { List targInstalled = Lists.newArrayListWithExpectedSize(overdueMix.length); for (int i = 0; i < overdueMix.length; i++) { - notAssigned.add(targetManagement.createTarget( - entityFactory.target().create().controllerId("not" + i).lastTargetQuery(overdueMix[i]))); - targAssigned.add(targetManagement.createTarget( + notAssigned.add(targetManagement + .create(entityFactory.target().create().controllerId("not" + i).lastTargetQuery(overdueMix[i]))); + targAssigned.add(targetManagement.create( entityFactory.target().create().controllerId("assigned" + i).lastTargetQuery(overdueMix[i]))); - targInstalled.add(targetManagement.createTarget( + targInstalled.add(targetManagement.create( entityFactory.target().create().controllerId("installed" + i).lastTargetQuery(overdueMix[i]))); } @@ -596,8 +608,8 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { .sendUpdateActionStatusToTargets(targInstalled, Status.FINISHED, Collections.singletonList("installed")) .stream().map(Action::getTarget).collect(Collectors.toList()); - final Slice result = targetManagement.findTargetsAllOrderByLinkedDistributionSet(PAGE, ds.getId(), - new FilterParams(null, null, Boolean.TRUE, null, Boolean.FALSE, new String[0])); + final Slice result = targetManagement.findByFilterOrderByLinkedDistributionSet(PAGE, ds.getId(), + new FilterParams(null, Boolean.TRUE, null, null, Boolean.FALSE, new String[0])); final Comparator byId = (e1, e2) -> Long.compare(e2.getId(), e1.getId()); @@ -627,10 +639,10 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { assignDistributionSet(assignedSet, assignedtargets); // get final updated version of targets - assignedtargets = targetManagement.findTargetsByControllerID( + assignedtargets = targetManagement.getByControllerID( assignedtargets.stream().map(target -> target.getControllerId()).collect(Collectors.toList())); - assertThat(targetManagement.findTargetByAssignedDistributionSet(assignedSet.getId(), PAGE)) + assertThat(targetManagement.findByAssignedDistributionSet(PAGE, assignedSet.getId())) .as("Contains the assigned targets").containsAll(assignedtargets) .as("and that means the following expected amount").hasSize(10); @@ -641,14 +653,14 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { public void findTargetWithoutAssignedDistributionSet() { final DistributionSet assignedSet = testdataFactory.createDistributionSet(""); final TargetFilterQuery tfq = targetFilterQueryManagement - .createTargetFilterQuery(entityFactory.targetFilterQuery().create().name("tfq").query("name==*")); + .create(entityFactory.targetFilterQuery().create().name("tfq").query("name==*")); final List unassignedTargets = testdataFactory.createTargets(12, "unassigned", "unassigned"); final List assignedTargets = testdataFactory.createTargets(10, "assigned", "assigned"); assignDistributionSet(assignedSet, assignedTargets); final List result = targetManagement - .findAllTargetsByTargetFilterQueryAndNonDS(PAGE, assignedSet.getId(), tfq.getQuery()).getContent(); + .findByTargetFilterQueryAndNonDS(PAGE, assignedSet.getId(), tfq.getQuery()).getContent(); assertThat(result).as("count of targets").hasSize(unassignedTargets.size()).as("contains all targets") .containsAll(unassignedTargets); @@ -668,10 +680,10 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { assignDistributionSet(assignedSet, installedtargets); // get final updated version of targets - installedtargets = targetManagement.findTargetsByControllerID( - installedtargets.stream().map(target -> target.getControllerId()).collect(Collectors.toList())); + installedtargets = targetManagement + .getByControllerID(installedtargets.stream().map(Target::getControllerId).collect(Collectors.toList())); - assertThat(targetManagement.findTargetByInstalledDistributionSet(installedSet.getId(), PAGE)) + assertThat(targetManagement.findByInstalledDistributionSet(PAGE, installedSet.getId())) .as("Contains the assigned targets").containsAll(installedtargets) .as("and that means the following expected amount").hasSize(10); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetManagementTest.java index 4a4222ace..8e5cd21c0 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetManagementTest.java @@ -26,6 +26,7 @@ import javax.validation.ConstraintViolationException; import org.apache.commons.lang3.RandomStringUtils; import org.eclipse.hawkbit.im.authentication.SpPermission; +import org.eclipse.hawkbit.repository.FilterParams; import org.eclipse.hawkbit.repository.event.remote.TargetAssignDistributionSetEvent; import org.eclipse.hawkbit.repository.event.remote.TargetDeletedEvent; import org.eclipse.hawkbit.repository.event.remote.TargetPollEvent; @@ -71,8 +72,8 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest { + "of Optional not present.") @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) }) public void nonExistingEntityAccessReturnsNotPresent() { - assertThat(targetManagement.findTargetByControllerID(NOT_EXIST_ID)).isNotPresent(); - assertThat(targetManagement.findTargetById(NOT_EXIST_IDL)).isNotPresent(); + assertThat(targetManagement.getByControllerID(NOT_EXIST_ID)).isNotPresent(); + assertThat(targetManagement.get(NOT_EXIST_IDL)).isNotPresent(); } @Test @@ -81,45 +82,42 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest { @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = TargetTagCreatedEvent.class, count = 1) }) public void entityQueriesReferringToNotExistingEntitiesThrowsException() { - final TargetTag tag = tagManagement.createTargetTag(entityFactory.tag().create().name("A")); + final TargetTag tag = targetTagManagement.create(entityFactory.tag().create().name("A")); final Target target = testdataFactory.createTarget(); verifyThrownExceptionBy( () -> targetManagement.assignTag(Arrays.asList(target.getControllerId()), NOT_EXIST_IDL), "TargetTag"); verifyThrownExceptionBy(() -> targetManagement.assignTag(Arrays.asList(NOT_EXIST_ID), tag.getId()), "Target"); - verifyThrownExceptionBy(() -> targetManagement.findTargetsByTag(PAGE, NOT_EXIST_IDL), "TargetTag"); - verifyThrownExceptionBy(() -> targetManagement.findTargetsByTag(PAGE, "name==*", NOT_EXIST_IDL), "TargetTag"); + verifyThrownExceptionBy(() -> targetManagement.findByTag(PAGE, NOT_EXIST_IDL), "TargetTag"); + verifyThrownExceptionBy(() -> targetManagement.findByRsqlAndTag(PAGE, "name==*", NOT_EXIST_IDL), "TargetTag"); - verifyThrownExceptionBy(() -> targetManagement.countTargetByAssignedDistributionSet(NOT_EXIST_IDL), + verifyThrownExceptionBy(() -> targetManagement.countByAssignedDistributionSet(NOT_EXIST_IDL), "DistributionSet"); - verifyThrownExceptionBy(() -> targetManagement.countTargetByInstalledDistributionSet(NOT_EXIST_IDL), + verifyThrownExceptionBy(() -> targetManagement.countByInstalledDistributionSet(NOT_EXIST_IDL), "DistributionSet"); - verifyThrownExceptionBy(() -> targetManagement.countTargetByTargetFilterQuery(NOT_EXIST_IDL), - "TargetFilterQuery"); - verifyThrownExceptionBy( - () -> targetManagement.countTargetsByTargetFilterQueryAndNonDS(NOT_EXIST_IDL, "name==*"), + verifyThrownExceptionBy(() -> targetManagement.countByTargetFilterQuery(NOT_EXIST_IDL), "TargetFilterQuery"); + verifyThrownExceptionBy(() -> targetManagement.countByRsqlAndNonDS(NOT_EXIST_IDL, "name==*"), "DistributionSet"); - verifyThrownExceptionBy(() -> targetManagement.deleteTarget(NOT_EXIST_ID), "Target"); - verifyThrownExceptionBy(() -> targetManagement.deleteTargets(Arrays.asList(NOT_EXIST_IDL)), "Target"); + verifyThrownExceptionBy(() -> targetManagement.deleteByControllerID(NOT_EXIST_ID), "Target"); + verifyThrownExceptionBy(() -> targetManagement.delete(Arrays.asList(NOT_EXIST_IDL)), "Target"); - verifyThrownExceptionBy( - () -> targetManagement.findAllTargetsByTargetFilterQueryAndNonDS(PAGE, NOT_EXIST_IDL, "name==*"), + verifyThrownExceptionBy(() -> targetManagement.findByTargetFilterQueryAndNonDS(PAGE, NOT_EXIST_IDL, "name==*"), "DistributionSet"); - verifyThrownExceptionBy(() -> targetManagement.findAllTargetsInRolloutGroupWithoutAction(PAGE, NOT_EXIST_IDL), + verifyThrownExceptionBy(() -> targetManagement.findByInRolloutGroupWithoutAction(PAGE, NOT_EXIST_IDL), "RolloutGroup"); - verifyThrownExceptionBy(() -> targetManagement.findTargetByAssignedDistributionSet(NOT_EXIST_IDL, PAGE), + verifyThrownExceptionBy(() -> targetManagement.findByAssignedDistributionSet(PAGE, NOT_EXIST_IDL), "DistributionSet"); verifyThrownExceptionBy( - () -> targetManagement.findTargetByAssignedDistributionSet(NOT_EXIST_IDL, "name==*", PAGE), + () -> targetManagement.findByAssignedDistributionSetAndRsql(PAGE, NOT_EXIST_IDL, "name==*"), "DistributionSet"); - verifyThrownExceptionBy(() -> targetManagement.findTargetByInstalledDistributionSet(NOT_EXIST_IDL, PAGE), + verifyThrownExceptionBy(() -> targetManagement.findByInstalledDistributionSet(PAGE, NOT_EXIST_IDL), "DistributionSet"); verifyThrownExceptionBy( - () -> targetManagement.findTargetByInstalledDistributionSet(NOT_EXIST_IDL, "name==*", PAGE), + () -> targetManagement.findByInstalledDistributionSetAndRsql(PAGE, NOT_EXIST_IDL, "name==*"), "DistributionSet"); verifyThrownExceptionBy( @@ -131,16 +129,15 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest { verifyThrownExceptionBy(() -> targetManagement.unAssignTag(NOT_EXIST_ID, tag.getId()), "Target"); verifyThrownExceptionBy(() -> targetManagement.unAssignTag(target.getControllerId(), NOT_EXIST_IDL), "TargetTag"); - verifyThrownExceptionBy(() -> targetManagement.updateTarget(entityFactory.target().update(NOT_EXIST_ID)), - "Target"); + verifyThrownExceptionBy(() -> targetManagement.update(entityFactory.target().update(NOT_EXIST_ID)), "Target"); } @Test @Description("Ensures that retrieving the target security is only permitted with the necessary permissions.") @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1) }) public void getTargetSecurityTokenOnlyWithCorrectPermission() throws Exception { - final Target createdTarget = targetManagement.createTarget( - entityFactory.target().create().controllerId("targetWithSecurityToken").securityToken("token")); + final Target createdTarget = targetManagement + .create(entityFactory.target().create().controllerId("targetWithSecurityToken").securityToken("token")); // retrieve security token only with READ_TARGET_SEC_TOKEN permission final String securityTokenWithReadPermission = securityRule.runAs(WithSpringAuthorityRule @@ -172,7 +169,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest { @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) }) public void createTargetForTenantWhichDoesNotExistThrowsTenantNotExistException() { try { - targetManagement.createTarget(entityFactory.target().create().controllerId("targetId123")); + targetManagement.create(entityFactory.target().create().controllerId("targetId123")); fail("should not be possible as the tenant does not exist"); } catch (final TenantNotExistException e) { // ok @@ -183,10 +180,10 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest { @Description("Verify that a target with same controller ID than another device cannot be created.") @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1) }) public void createTargetThatViolatesUniqueConstraintFails() { - targetManagement.createTarget(entityFactory.target().create().controllerId("123")); + targetManagement.create(entityFactory.target().create().controllerId("123")); assertThatExceptionOfType(EntityAlreadyExistsException.class) - .isThrownBy(() -> targetManagement.createTarget(entityFactory.target().create().controllerId("123"))); + .isThrownBy(() -> targetManagement.create(entityFactory.target().create().controllerId("123"))); } @Test @@ -207,12 +204,12 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest { private void createAndUpdateTargetWithInvalidDescription(final Target target) { assertThatExceptionOfType(ConstraintViolationException.class) - .isThrownBy(() -> targetManagement.createTarget(entityFactory.target().create().controllerId("a") + .isThrownBy(() -> targetManagement.create(entityFactory.target().create().controllerId("a") .description(RandomStringUtils.randomAlphanumeric(513)))) .as("target with too long description should not be created"); assertThatExceptionOfType(ConstraintViolationException.class) - .isThrownBy(() -> targetManagement.updateTarget(entityFactory.target().update(target.getControllerId()) + .isThrownBy(() -> targetManagement.update(entityFactory.target().update(target.getControllerId()) .description(RandomStringUtils.randomAlphanumeric(513)))) .as("target with too long description should not be updated"); @@ -222,17 +219,18 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest { private void createAndUpdateTargetWithInvalidName(final Target target) { assertThatExceptionOfType(ConstraintViolationException.class) - .isThrownBy(() -> targetManagement.createTarget(entityFactory.target().create().controllerId("a") + .isThrownBy(() -> targetManagement.create(entityFactory.target().create().controllerId("a") .name(RandomStringUtils.randomAlphanumeric(65)))) .as("target with too long name should not be created"); assertThatExceptionOfType(ConstraintViolationException.class) - .isThrownBy(() -> targetManagement.updateTarget(entityFactory.target().update(target.getControllerId()) + .isThrownBy(() -> targetManagement.update(entityFactory.target().update(target.getControllerId()) .name(RandomStringUtils.randomAlphanumeric(65)))) .as("target with too long name should not be updated"); - assertThatExceptionOfType(ConstraintViolationException.class).isThrownBy( - () -> targetManagement.updateTarget(entityFactory.target().update(target.getControllerId()).name(""))) + assertThatExceptionOfType(ConstraintViolationException.class) + .isThrownBy( + () -> targetManagement.update(entityFactory.target().update(target.getControllerId()).name(""))) .as("target with too short name should not be updated"); } @@ -241,18 +239,18 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest { private void createAndUpdateTargetWithInvalidSecurityToken(final Target target) { assertThatExceptionOfType(ConstraintViolationException.class) - .isThrownBy(() -> targetManagement.createTarget(entityFactory.target().create().controllerId("a") + .isThrownBy(() -> targetManagement.create(entityFactory.target().create().controllerId("a") .securityToken(RandomStringUtils.randomAlphanumeric(129)))) .as("target with too long token should not be created"); assertThatExceptionOfType(ConstraintViolationException.class) - .isThrownBy(() -> targetManagement.updateTarget(entityFactory.target().update(target.getControllerId()) + .isThrownBy(() -> targetManagement.update(entityFactory.target().update(target.getControllerId()) .securityToken(RandomStringUtils.randomAlphanumeric(129)))) .as("target with too long token should not be updated"); assertThatExceptionOfType(ConstraintViolationException.class) .isThrownBy(() -> targetManagement - .updateTarget(entityFactory.target().update(target.getControllerId()).securityToken(""))) + .update(entityFactory.target().update(target.getControllerId()).securityToken(""))) .as("target with too short token should not be updated"); } @@ -260,12 +258,12 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest { private void createAndUpdateTargetWithInvalidAddress(final Target target) { assertThatExceptionOfType(ConstraintViolationException.class) - .isThrownBy(() -> targetManagement.createTarget(entityFactory.target().create().controllerId("a") + .isThrownBy(() -> targetManagement.create(entityFactory.target().create().controllerId("a") .address(RandomStringUtils.randomAlphanumeric(513)))) .as("target with too long address should not be created"); assertThatExceptionOfType(ConstraintViolationException.class) - .isThrownBy(() -> targetManagement.updateTarget(entityFactory.target().update(target.getControllerId()) + .isThrownBy(() -> targetManagement.update(entityFactory.target().update(target.getControllerId()) .address(RandomStringUtils.randomAlphanumeric(513)))) .as("target with too long address should not be updated"); } @@ -273,41 +271,40 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest { @Step private void createTargetWithInvalidControllerId() { assertThatExceptionOfType(ConstraintViolationException.class) - .isThrownBy(() -> targetManagement.createTarget(entityFactory.target().create().controllerId(""))) + .isThrownBy(() -> targetManagement.create(entityFactory.target().create().controllerId(""))) .as("target with empty controller id should not be created"); assertThatExceptionOfType(ConstraintViolationException.class) - .isThrownBy(() -> targetManagement.createTarget(entityFactory.target().create().controllerId(null))) + .isThrownBy(() -> targetManagement.create(entityFactory.target().create().controllerId(null))) .as("target with null controller id should not be created"); assertThatExceptionOfType(ConstraintViolationException.class) - .isThrownBy(() -> targetManagement.createTarget( - entityFactory.target().create().controllerId(RandomStringUtils.randomAlphanumeric(65)))) + .isThrownBy(() -> targetManagement + .create(entityFactory.target().create().controllerId(RandomStringUtils.randomAlphanumeric(65)))) .as("target with too long controller id should not be created"); assertThatExceptionOfType(ConstraintViolationException.class) - .isThrownBy(() -> targetManagement.createTarget(entityFactory.target().create().controllerId(" "))) + .isThrownBy(() -> targetManagement.create(entityFactory.target().create().controllerId(" "))) .as(WHITESPACE_ERROR); assertThatExceptionOfType(ConstraintViolationException.class) - .isThrownBy(() -> targetManagement.createTarget(entityFactory.target().create().controllerId(" a"))) + .isThrownBy(() -> targetManagement.create(entityFactory.target().create().controllerId(" a"))) .as(WHITESPACE_ERROR); assertThatExceptionOfType(ConstraintViolationException.class) - .isThrownBy(() -> targetManagement.createTarget(entityFactory.target().create().controllerId("a "))) + .isThrownBy(() -> targetManagement.create(entityFactory.target().create().controllerId("a "))) .as(WHITESPACE_ERROR); assertThatExceptionOfType(ConstraintViolationException.class) - .isThrownBy(() -> targetManagement.createTarget(entityFactory.target().create().controllerId("a b"))) + .isThrownBy(() -> targetManagement.create(entityFactory.target().create().controllerId("a b"))) .as(WHITESPACE_ERROR); assertThatExceptionOfType(ConstraintViolationException.class) - .isThrownBy(() -> targetManagement.createTarget(entityFactory.target().create().controllerId(" "))) + .isThrownBy(() -> targetManagement.create(entityFactory.target().create().controllerId(" "))) .as(WHITESPACE_ERROR); assertThatExceptionOfType(ConstraintViolationException.class) - .isThrownBy( - () -> targetManagement.createTarget(entityFactory.target().create().controllerId("aaa bbb"))) + .isThrownBy(() -> targetManagement.create(entityFactory.target().create().controllerId("aaa bbb"))) .as(WHITESPACE_ERROR); } @@ -319,36 +316,36 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest { @Expect(type = TargetUpdatedEvent.class, count = 5) }) public void assignAndUnassignTargetsToTag() { final List assignTarget = new ArrayList<>(); - assignTarget.add(targetManagement.createTarget(entityFactory.target().create().controllerId("targetId123")) + assignTarget.add( + targetManagement.create(entityFactory.target().create().controllerId("targetId123")).getControllerId()); + assignTarget.add(targetManagement.create(entityFactory.target().create().controllerId("targetId1234")) .getControllerId()); - assignTarget.add(targetManagement.createTarget(entityFactory.target().create().controllerId("targetId1234")) + assignTarget.add(targetManagement.create(entityFactory.target().create().controllerId("targetId1235")) .getControllerId()); - assignTarget.add(targetManagement.createTarget(entityFactory.target().create().controllerId("targetId1235")) - .getControllerId()); - assignTarget.add(targetManagement.createTarget(entityFactory.target().create().controllerId("targetId1236")) + assignTarget.add(targetManagement.create(entityFactory.target().create().controllerId("targetId1236")) .getControllerId()); - final TargetTag targetTag = tagManagement.createTargetTag(entityFactory.tag().create().name("Tag1")); + final TargetTag targetTag = targetTagManagement.create(entityFactory.tag().create().name("Tag1")); final List assignedTargets = targetManagement.assignTag(assignTarget, targetTag.getId()); assertThat(assignedTargets.size()).as("Assigned targets are wrong").isEqualTo(4); assignedTargets.forEach(target -> assertThat( - tagManagement.findAllTargetTags(PAGE, target.getControllerId()).getNumberOfElements()).isEqualTo(1)); + targetTagManagement.findByTarget(PAGE, target.getControllerId()).getNumberOfElements()) + .isEqualTo(1)); - TargetTag findTargetTag = tagManagement.findTargetTag("Tag1").get(); + TargetTag findTargetTag = targetTagManagement.getByName("Tag1").get(); assertThat(assignedTargets.size()).as("Assigned targets are wrong") - .isEqualTo(targetManagement.findTargetsByTag(PAGE, targetTag.getId()).getNumberOfElements()); + .isEqualTo(targetManagement.findByTag(PAGE, targetTag.getId()).getNumberOfElements()); final Target unAssignTarget = targetManagement.unAssignTag("targetId123", findTargetTag.getId()); assertThat(unAssignTarget.getControllerId()).as("Controller id is wrong").isEqualTo("targetId123"); - assertThat(tagManagement.findAllTargetTags(PAGE, unAssignTarget.getControllerId())).as("Tag size is wrong") - .isEmpty(); - findTargetTag = tagManagement.findTargetTag("Tag1").get(); - assertThat(targetManagement.findTargetsByTag(PAGE, targetTag.getId())).as("Assigned targets are wrong") - .hasSize(3); - assertThat(targetManagement.findTargetsByTag(PAGE, "controllerId==targetId123", targetTag.getId())) + assertThat(targetTagManagement.findByTarget(PAGE, unAssignTarget.getControllerId())) + .as("Tag size is wrong").isEmpty(); + findTargetTag = targetTagManagement.getByName("Tag1").get(); + assertThat(targetManagement.findByTag(PAGE, targetTag.getId())).as("Assigned targets are wrong").hasSize(3); + assertThat(targetManagement.findByRsqlAndTag(PAGE, "controllerId==targetId123", targetTag.getId())) .as("Assigned targets are wrong").isEmpty(); - assertThat(targetManagement.findTargetsByTag(PAGE, "controllerId==targetId1234", targetTag.getId())) + assertThat(targetManagement.findByRsqlAndTag(PAGE, "controllerId==targetId1234", targetTag.getId())) .as("Assigned targets are wrong").hasSize(1); } @@ -358,32 +355,32 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest { @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 12), @Expect(type = TargetDeletedEvent.class, count = 12), @Expect(type = TargetUpdatedEvent.class, count = 6) }) public void deleteAndCreateTargets() { - Target target = targetManagement.createTarget(entityFactory.target().create().controllerId("targetId123")); - assertThat(targetManagement.countTargetsAll()).as("target count is wrong").isEqualTo(1); - targetManagement.deleteTargets(Arrays.asList(target.getId())); - assertThat(targetManagement.countTargetsAll()).as("target count is wrong").isEqualTo(0); + Target target = targetManagement.create(entityFactory.target().create().controllerId("targetId123")); + assertThat(targetManagement.count()).as("target count is wrong").isEqualTo(1); + targetManagement.delete(Arrays.asList(target.getId())); + assertThat(targetManagement.count()).as("target count is wrong").isEqualTo(0); target = createTargetWithAttributes("4711"); - assertThat(targetManagement.countTargetsAll()).as("target count is wrong").isEqualTo(1); - targetManagement.deleteTargets(Arrays.asList(target.getId())); - assertThat(targetManagement.countTargetsAll()).as("target count is wrong").isEqualTo(0); + assertThat(targetManagement.count()).as("target count is wrong").isEqualTo(1); + targetManagement.delete(Arrays.asList(target.getId())); + assertThat(targetManagement.count()).as("target count is wrong").isEqualTo(0); final List targets = new ArrayList<>(); for (int i = 0; i < 5; i++) { - target = targetManagement.createTarget(entityFactory.target().create().controllerId("" + i)); + target = targetManagement.create(entityFactory.target().create().controllerId("" + i)); targets.add(target.getId()); targets.add(createTargetWithAttributes("" + (i * i + 1000)).getId()); } - assertThat(targetManagement.countTargetsAll()).as("target count is wrong").isEqualTo(10); - targetManagement.deleteTargets(targets); - assertThat(targetManagement.countTargetsAll()).as("target count is wrong").isEqualTo(0); + assertThat(targetManagement.count()).as("target count is wrong").isEqualTo(10); + targetManagement.delete(targets); + assertThat(targetManagement.count()).as("target count is wrong").isEqualTo(0); } private Target createTargetWithAttributes(final String controllerId) { final Map testData = new HashMap<>(); testData.put("test1", "testdata1"); - targetManagement.createTarget(entityFactory.target().create().controllerId(controllerId)); + targetManagement.create(entityFactory.target().create().controllerId(controllerId)); final Target target = controllerManagement.updateControllerAttributes(controllerId, testData); assertThat(targetManagement.getControllerAttributes(controllerId)).as("Controller Attributes are wrong") @@ -403,13 +400,13 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest { final DistributionSet set = testdataFactory.createDistributionSet("test"); final DistributionSet set2 = testdataFactory.createDistributionSet("test2"); - assertThat(targetManagement.countTargetByAssignedDistributionSet(set.getId())).as("Target count is wrong") + assertThat(targetManagement.countByAssignedDistributionSet(set.getId())).as("Target count is wrong") .isEqualTo(0); - assertThat(targetManagement.countTargetByInstalledDistributionSet(set.getId())).as("Target count is wrong") + assertThat(targetManagement.countByInstalledDistributionSet(set.getId())).as("Target count is wrong") .isEqualTo(0); - assertThat(targetManagement.countTargetByAssignedDistributionSet(set2.getId())).as("Target count is wrong") + assertThat(targetManagement.countByAssignedDistributionSet(set2.getId())).as("Target count is wrong") .isEqualTo(0); - assertThat(targetManagement.countTargetByInstalledDistributionSet(set2.getId())).as("Target count is wrong") + assertThat(targetManagement.countByInstalledDistributionSet(set2.getId())).as("Target count is wrong") .isEqualTo(0); Target target = createTargetWithAttributes("4711"); @@ -423,16 +420,16 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest { entityFactory.actionStatus().create(result.getActions().get(0)).status(Status.FINISHED)); assignDistributionSet(set2.getId(), "4711"); - target = targetManagement.findTargetByControllerID("4711").get(); + target = targetManagement.getByControllerID("4711").get(); // read data - assertThat(targetManagement.countTargetByAssignedDistributionSet(set.getId())).as("Target count is wrong") + assertThat(targetManagement.countByAssignedDistributionSet(set.getId())).as("Target count is wrong") .isEqualTo(0); - assertThat(targetManagement.countTargetByInstalledDistributionSet(set.getId())).as("Target count is wrong") + assertThat(targetManagement.countByInstalledDistributionSet(set.getId())).as("Target count is wrong") .isEqualTo(1); - assertThat(targetManagement.countTargetByAssignedDistributionSet(set2.getId())).as("Target count is wrong") + assertThat(targetManagement.countByAssignedDistributionSet(set2.getId())).as("Target count is wrong") .isEqualTo(1); - assertThat(targetManagement.countTargetByInstalledDistributionSet(set2.getId())).as("Target count is wrong") + assertThat(targetManagement.countByInstalledDistributionSet(set2.getId())).as("Target count is wrong") .isEqualTo(0); assertThat(target.getLastTargetQuery()).as("Target query is not work").isGreaterThanOrEqualTo(current); assertThat(deploymentManagement.getAssignedDistributionSet("4711").get()).as("Assigned ds size is wrong") @@ -458,9 +455,9 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest { @Description("Checks if the EntityAlreadyExistsException is thrown if a single target with the same controller ID are created twice.") @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1) }) public void createTargetDuplicate() { - targetManagement.createTarget(entityFactory.target().create().controllerId("4711")); + targetManagement.create(entityFactory.target().create().controllerId("4711")); try { - targetManagement.createTarget(entityFactory.target().create().controllerId("4711")); + targetManagement.create(entityFactory.target().create().controllerId("4711")); fail("Target already exists"); } catch (final EntityAlreadyExistsException e) { } @@ -484,7 +481,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest { */ private void checkTargetHasTags(final boolean strict, final Iterable targets, final TargetTag... tags) { _target: for (final Target tl : targets) { - for (final Tag tt : tagManagement.findAllTargetTags(PAGE, tl.getControllerId())) { + for (final Tag tt : targetTagManagement.findByTarget(PAGE, tl.getControllerId())) { for (final Tag tag : tags) { if (tag.getName().equals(tt.getName())) { continue _target; @@ -500,10 +497,10 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest { private void checkTargetHasNotTags(final Iterable targets, final TargetTag... tags) { for (final Target tl : targets) { - targetManagement.findTargetByControllerID(tl.getControllerId()).get(); + targetManagement.getByControllerID(tl.getControllerId()).get(); for (final Tag tag : tags) { - for (final Tag tt : tagManagement.findAllTargetTags(PAGE, tl.getControllerId())) { + for (final Tag tt : targetTagManagement.findByTarget(PAGE, tl.getControllerId())) { if (tag.getName().equals(tt.getName())) { fail("Target should have no tags"); } @@ -531,7 +528,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest { assertNotNull("The lastModifiedAt attribut of the target should no be null", savedTarget.getLastModifiedAt()); Thread.sleep(1); - savedTarget = targetManagement.updateTarget( + savedTarget = targetManagement.update( entityFactory.target().update(savedTarget.getControllerId()).description("changed description")); assertNotNull("The lastModifiedAt attribute of the target should not be null", savedTarget.getLastModifiedAt()); assertThat(createdAt).as("CreatedAt compared with saved modifiedAt") @@ -540,7 +537,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest { .isNotEqualTo(savedTarget.getLastModifiedAt()); modifiedAt = savedTarget.getLastModifiedAt(); - final Target foundTarget = targetManagement.findTargetByControllerID(savedTarget.getControllerId()).get(); + final Target foundTarget = targetManagement.getByControllerID(savedTarget.getControllerId()).get(); assertNotNull("The target should not be null", foundTarget); assertThat(myCtrlID).as("ControllerId compared with saved controllerId") .isEqualTo(foundTarget.getControllerId()); @@ -572,7 +569,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest { // change the objects and save to again to trigger a change on // lastModifiedAt firstList = firstList.stream() - .map(t -> targetManagement.updateTarget( + .map(t -> targetManagement.update( entityFactory.target().update(t.getControllerId()).name(t.getName().concat("\tchanged")))) .collect(Collectors.toList()); @@ -600,16 +597,16 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest { } } - targetManagement.deleteTarget(extra.getControllerId()); + targetManagement.deleteByControllerID(extra.getControllerId()); final int numberToDelete = 50; final Collection targetsToDelete = firstList.subList(0, numberToDelete); final Target[] deletedTargets = Iterables.toArray(targetsToDelete, Target.class); final List targetsIdsToDelete = targetsToDelete.stream().map(Target::getId).collect(Collectors.toList()); - targetManagement.deleteTargets(targetsIdsToDelete); + targetManagement.delete(targetsIdsToDelete); - final List targetsLeft = targetManagement.findTargetsAll(new PageRequest(0, 200)).getContent(); + final List targetsLeft = targetManagement.findAll(new PageRequest(0, 200)).getContent(); assertThat(firstList.spliterator().getExactSizeIfKnown() - numberToDelete).as("Size of splited list") .isEqualTo(targetsLeft.spliterator().getExactSizeIfKnown()); @@ -633,17 +630,17 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest { final List t2Tags = testdataFactory.createTargetTags(noT2Tags, "tag2"); t2Tags.forEach(tag -> targetManagement.assignTag(Arrays.asList(t2.getControllerId()), tag.getId())); - final Target t11 = targetManagement.findTargetByControllerID(t1.getControllerId()).get(); - assertThat(tagManagement.findAllTargetTags(PAGE, t11.getControllerId()).getContent()).as("Tag size is wrong") - .hasSize(noT1Tags).containsAll(t1Tags); - assertThat(tagManagement.findAllTargetTags(PAGE, t11.getControllerId()).getContent()).as("Tag size is wrong") - .hasSize(noT1Tags).doesNotContain(Iterables.toArray(t2Tags, TargetTag.class)); + final Target t11 = targetManagement.getByControllerID(t1.getControllerId()).get(); + assertThat(targetTagManagement.findByTarget(PAGE, t11.getControllerId()).getContent()) + .as("Tag size is wrong").hasSize(noT1Tags).containsAll(t1Tags); + assertThat(targetTagManagement.findByTarget(PAGE, t11.getControllerId()).getContent()) + .as("Tag size is wrong").hasSize(noT1Tags).doesNotContain(Iterables.toArray(t2Tags, TargetTag.class)); - final Target t21 = targetManagement.findTargetByControllerID(t2.getControllerId()).get(); - assertThat(tagManagement.findAllTargetTags(PAGE, t21.getControllerId()).getContent()).as("Tag size is wrong") - .hasSize(noT2Tags).containsAll(t2Tags); - assertThat(tagManagement.findAllTargetTags(PAGE, t21.getControllerId()).getContent()).as("Tag size is wrong") - .hasSize(noT2Tags).doesNotContain(Iterables.toArray(t1Tags, TargetTag.class)); + final Target t21 = targetManagement.getByControllerID(t2.getControllerId()).get(); + assertThat(targetTagManagement.findByTarget(PAGE, t21.getControllerId()).getContent()) + .as("Tag size is wrong").hasSize(noT2Tags).containsAll(t2Tags); + assertThat(targetTagManagement.findByTarget(PAGE, t21.getControllerId()).getContent()) + .as("Tag size is wrong").hasSize(noT2Tags).doesNotContain(Iterables.toArray(t1Tags, TargetTag.class)); } @Test @@ -660,10 +657,10 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest { final List tagABCTargets = testdataFactory.createTargets(10, "tagABCTargets", "first description"); - final TargetTag tagA = tagManagement.createTargetTag(entityFactory.tag().create().name("A")); - final TargetTag tagB = tagManagement.createTargetTag(entityFactory.tag().create().name("B")); - final TargetTag tagC = tagManagement.createTargetTag(entityFactory.tag().create().name("C")); - tagManagement.createTargetTag(entityFactory.tag().create().name("X")); + final TargetTag tagA = targetTagManagement.create(entityFactory.tag().create().name("A")); + final TargetTag tagB = targetTagManagement.create(entityFactory.tag().create().name("B")); + final TargetTag tagC = targetTagManagement.create(entityFactory.tag().create().name("C")); + targetTagManagement.create(entityFactory.tag().create().name("X")); // doing different assignments toggleTagAssignment(tagATargets, tagA); @@ -677,7 +674,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest { toggleTagAssignment(tagABCTargets, tagB); toggleTagAssignment(tagABCTargets, tagC); - assertThat(targetManagement.countTargetByFilters(null, null, null, null, Boolean.FALSE, "X")) + assertThat(targetManagement.countByFilters(null, null, null, null, Boolean.FALSE, "X")) .as("Target count is wrong").isEqualTo(0); // search for targets with tag tagA @@ -707,11 +704,11 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest { checkTargetHasNotTags(tagCTargets, tagA, tagB); // check again target lists refreshed from DB - assertThat(targetManagement.countTargetByFilters(null, null, null, null, Boolean.FALSE, "A")) + assertThat(targetManagement.countByFilters(null, null, null, null, Boolean.FALSE, "A")) .as("Target count is wrong").isEqualTo(targetWithTagA.size()); - assertThat(targetManagement.countTargetByFilters(null, null, null, null, Boolean.FALSE, "B")) + assertThat(targetManagement.countByFilters(null, null, null, null, Boolean.FALSE, "B")) .as("Target count is wrong").isEqualTo(targetWithTagB.size()); - assertThat(targetManagement.countTargetByFilters(null, null, null, null, Boolean.FALSE, "C")) + assertThat(targetManagement.countByFilters(null, null, null, null, Boolean.FALSE, "C")) .as("Target count is wrong").isEqualTo(targetWithTagC.size()); } @@ -721,9 +718,9 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest { @Expect(type = TargetCreatedEvent.class, count = 109), @Expect(type = TargetUpdatedEvent.class, count = 227) }) public void targetTagBulkUnassignments() { - final TargetTag targTagA = tagManagement.createTargetTag(entityFactory.tag().create().name("Targ-A-Tag")); - final TargetTag targTagB = tagManagement.createTargetTag(entityFactory.tag().create().name("Targ-B-Tag")); - final TargetTag targTagC = tagManagement.createTargetTag(entityFactory.tag().create().name("Targ-C-Tag")); + final TargetTag targTagA = targetTagManagement.create(entityFactory.tag().create().name("Targ-A-Tag")); + final TargetTag targTagB = targetTagManagement.create(entityFactory.tag().create().name("Targ-B-Tag")); + final TargetTag targTagC = targetTagManagement.create(entityFactory.tag().create().name("Targ-C-Tag")); final List targAs = testdataFactory.createTargets(25, "target-id-A", "first description"); final List targBs = testdataFactory.createTargets(20, "target-id-B", "first description"); @@ -780,7 +777,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest { @Expect(type = TargetUpdatedEvent.class, count = 25) }) public void findTargetsWithNoTag() { - final TargetTag targTagA = tagManagement.createTargetTag(entityFactory.tag().create().name("Targ-A-Tag")); + final TargetTag targTagA = targetTagManagement.create(entityFactory.tag().create().name("Targ-A-Tag")); final List targAs = testdataFactory.createTargets(25, "target-id-A", "first description"); toggleTagAssignment(targAs, targTagA); @@ -788,9 +785,9 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest { final String[] tagNames = null; final List targetsListWithNoTag = targetManagement - .findTargetByFilters(PAGE, null, null, null, null, Boolean.TRUE, tagNames).getContent(); + .findByFilters(PAGE, new FilterParams(null, null, null, null, Boolean.TRUE, tagNames)).getContent(); - assertThat(50L).as("Total targets").isEqualTo(targetManagement.countTargetsAll()); + assertThat(50L).as("Total targets").isEqualTo(targetManagement.count()); assertThat(25).as("Targets with no tag").isEqualTo(targetsListWithNoTag.size()); } @@ -804,8 +801,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest { controllerManagement.findOrRegisterTargetIfItDoesNotexist(knownTargetControllerId, new URI("http://127.0.0.1")); securityRule.runAs(WithSpringAuthorityRule.withUser("bumlux", "READ_TARGET"), () -> { - final Target findTargetByControllerID = targetManagement.findTargetByControllerID(knownTargetControllerId) - .get(); + final Target findTargetByControllerID = targetManagement.getByControllerID(knownTargetControllerId).get(); assertThat(findTargetByControllerID).isNotNull(); assertThat(findTargetByControllerID.getPollStatus()).isNotNull(); return null; @@ -817,16 +813,16 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest { @Description("Test that RSQL filter finds targets with tags or specific ids.") public void findTargetsWithTagOrId() { final String rsqlFilter = "tag==Targ-A-Tag,id==target-id-B-00001,id==target-id-B-00008"; - final TargetTag targTagA = tagManagement.createTargetTag(entityFactory.tag().create().name("Targ-A-Tag")); + final TargetTag targTagA = targetTagManagement.create(entityFactory.tag().create().name("Targ-A-Tag")); final List targAs = testdataFactory.createTargets(25, "target-id-A", "first description").stream() .map(Target::getControllerId).collect(Collectors.toList()); targetManagement.toggleTagAssignment(targAs, targTagA.getName()); testdataFactory.createTargets(25, "target-id-B", "first description"); - final Page foundTargets = targetManagement.findTargetsAll(rsqlFilter, PAGE); + final Page foundTargets = targetManagement.findByRsql(PAGE, rsqlFilter); - assertThat(targetManagement.countTargetsAll()).as("Total targets").isEqualTo(50L); + assertThat(targetManagement.count()).as("Total targets").isEqualTo(50L); assertThat(foundTargets.getTotalElements()).as("Targets in RSQL filter").isEqualTo(27L); } @@ -840,7 +836,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest { testdataFactory.createTarget("test" + i); } - final List foundDs = targetManagement.findTargetsById(searchIds); + final List foundDs = targetManagement.get(searchIds); assertThat(foundDs).hasSize(3); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetTagManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetTagManagementTest.java new file mode 100644 index 000000000..5f72a8d9e --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetTagManagementTest.java @@ -0,0 +1,220 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.jpa; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.fail; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import java.util.stream.Collectors; + +import org.eclipse.hawkbit.repository.TargetTagManagement; +import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTagUpdatedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.TargetCreatedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagUpdatedEvent; +import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; +import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag; +import org.eclipse.hawkbit.repository.model.Tag; +import org.eclipse.hawkbit.repository.model.Target; +import org.eclipse.hawkbit.repository.model.TargetTag; +import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult; +import org.eclipse.hawkbit.repository.test.matcher.Expect; +import org.eclipse.hawkbit.repository.test.matcher.ExpectEvents; +import org.junit.Test; + +import ru.yandex.qatools.allure.annotations.Description; +import ru.yandex.qatools.allure.annotations.Features; +import ru.yandex.qatools.allure.annotations.Stories; + +/** + * Test class for {@link TargetTagManagement}. + * + */ +@Features("Component Tests - Repository") +@Stories("Target Tag Management") +public class TargetTagManagementTest extends AbstractJpaIntegrationTest { + + @Test + @Description("Verifies that management get access reacts as specfied on calls for non existing entities by means " + + "of Optional not present.") + @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) }) + public void nonExistingEntityAccessReturnsNotPresent() { + assertThat(targetTagManagement.getByName(NOT_EXIST_ID)).isNotPresent(); + assertThat(targetTagManagement.get(NOT_EXIST_IDL)).isNotPresent(); + } + + @Test + @Description("Verifies that management queries react as specfied on calls for non existing entities " + + " by means of throwing EntityNotFoundException.") + @ExpectEvents({ @Expect(type = DistributionSetTagUpdatedEvent.class, count = 0), + @Expect(type = TargetTagUpdatedEvent.class, count = 0) }) + public void entityQueriesReferringToNotExistingEntitiesThrowsException() { + verifyThrownExceptionBy(() -> targetTagManagement.delete(NOT_EXIST_ID), "TargetTag"); + + verifyThrownExceptionBy(() -> targetTagManagement.update(entityFactory.tag().update(NOT_EXIST_IDL)), + "TargetTag"); + + verifyThrownExceptionBy(() -> targetTagManagement.findByTarget(PAGE, NOT_EXIST_ID), "Target"); + } + + @Test + @Description("Verifies the toogle mechanism by means on assigning tag if at least on target in the list does not have" + + "the tag yet. Unassign if all of them have the tag already.") + public void assignAndUnassignTargetTags() { + final List groupA = testdataFactory.createTargets(20); + final List groupB = testdataFactory.createTargets(20, "groupb", "groupb"); + + final TargetTag tag = targetTagManagement + .create(entityFactory.tag().create().name("tag1").description("tagdesc1")); + + // toggle A only -> A is now assigned + TargetTagAssignmentResult result = toggleTagAssignment(groupA, tag); + assertThat(result.getAlreadyAssigned()).isEqualTo(0); + assertThat(result.getAssigned()).isEqualTo(20); + assertThat(result.getAssignedEntity()).containsAll(targetManagement.getByControllerID( + groupA.stream().map(target -> target.getControllerId()).collect(Collectors.toList()))); + assertThat(result.getUnassigned()).isEqualTo(0); + assertThat(result.getUnassignedEntity()).isEmpty(); + assertThat(result.getTargetTag()).isEqualTo(tag); + + // toggle A+B -> A is still assigned and B is assigned as well + result = toggleTagAssignment(concat(groupA, groupB), tag); + assertThat(result.getAlreadyAssigned()).isEqualTo(20); + assertThat(result.getAssigned()).isEqualTo(20); + assertThat(result.getAssignedEntity()).containsAll(targetManagement.getByControllerID( + groupB.stream().map(target -> target.getControllerId()).collect(Collectors.toList()))); + assertThat(result.getUnassigned()).isEqualTo(0); + assertThat(result.getUnassignedEntity()).isEmpty(); + assertThat(result.getTargetTag()).isEqualTo(tag); + + // toggle A+B -> both unassigned + result = toggleTagAssignment(concat(groupA, groupB), tag); + assertThat(result.getAlreadyAssigned()).isEqualTo(0); + assertThat(result.getAssigned()).isEqualTo(0); + assertThat(result.getAssignedEntity()).isEmpty(); + assertThat(result.getUnassigned()).isEqualTo(40); + assertThat(result.getUnassignedEntity()).containsAll(targetManagement.getByControllerID( + concat(groupB, groupA).stream().map(Target::getControllerId).collect(Collectors.toList()))); + assertThat(result.getTargetTag()).isEqualTo(tag); + + } + + @SafeVarargs + private final Collection concat(final Collection... targets) { + final List result = new ArrayList<>(); + Arrays.asList(targets).forEach(result::addAll); + return result; + } + + @Test + @Description("Ensures that all tags are retrieved through repository.") + public void findAllTargetTags() { + final List tags = createTargetsWithTags(); + + assertThat(targetTagRepository.findAll()).isEqualTo(targetTagRepository.findAll()).isEqualTo(tags) + .as("Wrong tag size").hasSize(20); + } + + @Test + @Description("Ensures that a created tag is persisted in the repository as defined.") + public void createTargetTag() { + final Tag tag = targetTagManagement + .create(entityFactory.tag().create().name("kai1").description("kai2").colour("colour")); + + assertThat(targetTagRepository.findByNameEquals("kai1").get().getDescription()).as("wrong tag ed") + .isEqualTo("kai2"); + assertThat(targetTagManagement.getByName("kai1").get().getColour()).as("wrong tag found") + .isEqualTo("colour"); + assertThat(targetTagManagement.get(tag.getId()).get().getColour()).as("wrong tag found") + .isEqualTo("colour"); + } + + @Test + @Description("Ensures that a deleted tag is removed from the repository as defined.") + public void deleteTargetTags() { + + // create test data + final Iterable tags = createTargetsWithTags(); + final TargetTag toDelete = tags.iterator().next(); + + for (final Target target : targetRepository.findAll()) { + assertThat(targetTagManagement.findByTarget(PAGE, target.getControllerId()).getContent()) + .contains(toDelete); + } + + // delete + targetTagManagement.delete(toDelete.getName()); + + // check + for (final Target target : targetRepository.findAll()) { + assertThat(targetTagManagement.findByTarget(PAGE, target.getControllerId()).getContent()) + .doesNotContain(toDelete); + } + assertThat(targetTagRepository.findOne(toDelete.getId())).as("No tag should be found").isNull(); + assertThat(targetTagRepository.findAll()).as("Wrong target tag size").hasSize(19); + } + + @Test + @Description("Tests the name update of a target tag.") + public void updateTargetTag() { + final List tags = createTargetsWithTags(); + + // change data + final TargetTag savedAssigned = tags.iterator().next(); + + // persist + targetTagManagement.update(entityFactory.tag().update(savedAssigned.getId()).name("test123")); + + // check data + assertThat(targetTagRepository.findAll()).as("Wrong target tag size").hasSize(tags.size()); + assertThat(targetTagRepository.findOne(savedAssigned.getId()).getName()).as("wrong target tag is saved") + .isEqualTo("test123"); + assertThat(targetTagRepository.findOne(savedAssigned.getId()).getOptLockRevision()) + .as("wrong target tag is saved").isEqualTo(2); + } + + @Test + @Description("Ensures that a tag cannot be created if one exists already with that name (ecpects EntityAlreadyExistsException).") + public void failedDuplicateTargetTagNameException() { + targetTagManagement.create(entityFactory.tag().create().name("A")); + + try { + targetTagManagement.create(entityFactory.tag().create().name("A")); + fail("should not have worked as tag already exists"); + } catch (final EntityAlreadyExistsException e) { + + } + } + + @Test + @Description("Ensures that a tag cannot be updated to a name that already exists on another tag (ecpects EntityAlreadyExistsException).") + public void failedDuplicateTargetTagNameExceptionAfterUpdate() { + targetTagManagement.create(entityFactory.tag().create().name("A")); + final TargetTag tag = targetTagManagement.create(entityFactory.tag().create().name("B")); + + try { + targetTagManagement.update(entityFactory.tag().update(tag.getId()).name("A")); + fail("should not have worked as tag already exists"); + } catch (final EntityAlreadyExistsException e) { + + } + } + + private List createTargetsWithTags() { + final List targets = testdataFactory.createTargets(20); + final Iterable tags = testdataFactory.createTargetTags(20, ""); + + tags.forEach(tag -> toggleTagAssignment(targets, tag)); + + return targetTagRepository.findAll(); + } +} diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/autoassign/AutoAssignCheckerTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/autoassign/AutoAssignCheckerTest.java index 4bb041c8c..bce2ff35b 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/autoassign/AutoAssignCheckerTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/autoassign/AutoAssignCheckerTest.java @@ -49,8 +49,8 @@ public class AutoAssignCheckerTest extends AbstractJpaIntegrationTest { // target filter query that matches all targets final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement - .createTargetFilterQuery(entityFactory.targetFilterQuery().create().name("filterA").query("name==*")); - targetFilterQueryManagement.updateTargetFilterQueryAutoAssignDS(targetFilterQuery.getId(), setA.getId()); + .create(entityFactory.targetFilterQuery().create().name("filterA").query("name==*")); + targetFilterQueryManagement.updateAutoAssignDS(targetFilterQuery.getId(), setA.getId()); final String targetDsAIdPref = "targ"; final List targets = testdataFactory.createTargets(100, targetDsAIdPref, @@ -72,7 +72,7 @@ public class AutoAssignCheckerTest extends AbstractJpaIntegrationTest { verifyThatTargetsHaveDistributionSetAssignment(setB, targets.subList(10, 20), targetsCount); // Count the number of targets that will be assigned with setA - assertThat(targetManagement.countTargetsByTargetFilterQueryAndNonDS(setA.getId(), targetFilterQuery.getQuery())) + assertThat(targetManagement.countByRsqlAndNonDS(setA.getId(), targetFilterQuery.getQuery())) .isEqualTo(90); // Run the check @@ -90,7 +90,7 @@ public class AutoAssignCheckerTest extends AbstractJpaIntegrationTest { public void checkAutoAssignWithFailures() { // incomplete distribution set that will be assigned - final DistributionSet setF = distributionSetManagement.createDistributionSet(entityFactory.distributionSet() + final DistributionSet setF = distributionSetManagement.create(entityFactory.distributionSet() .create().name("dsA").version("1").type(testdataFactory.findOrCreateDefaultTestDsType())); final DistributionSet setA = testdataFactory.createDistributionSet("dsA"); final DistributionSet setB = testdataFactory.createDistributionSet("dsB"); @@ -100,14 +100,14 @@ public class AutoAssignCheckerTest extends AbstractJpaIntegrationTest { // target filter query that matches first bunch of targets, that should // fail - targetFilterQueryManagement.updateTargetFilterQueryAutoAssignDS( - targetFilterQueryManagement.createTargetFilterQuery(entityFactory.targetFilterQuery().create() + targetFilterQueryManagement.updateAutoAssignDS( + targetFilterQueryManagement.create(entityFactory.targetFilterQuery().create() .name("filterA").query("id==" + targetDsFIdPref + "*")).getId(), setF.getId()); // target filter query that matches failed bunch of targets - targetFilterQueryManagement.updateTargetFilterQueryAutoAssignDS( - targetFilterQueryManagement.createTargetFilterQuery(entityFactory.targetFilterQuery().create() + targetFilterQueryManagement.updateAutoAssignDS( + targetFilterQueryManagement.create(entityFactory.targetFilterQuery().create() .name("filterB").query("id==" + targetDsAIdPref + "*")).getId(), setA.getId()); @@ -145,7 +145,7 @@ public class AutoAssignCheckerTest extends AbstractJpaIntegrationTest { final int count) { final List targetIds = targets.stream().map(Target::getId).collect(Collectors.toList()); - final Slice targetsAll = targetManagement.findTargetsAll(PAGE); + final Slice targetsAll = targetManagement.findAll(PAGE); assertThat(targetsAll).as("Count of targets").hasSize(count); for (final Target target : targetsAll) { diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/event/RepositoryEntityEventTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/event/RepositoryEntityEventTest.java index a90f05ef0..ce4bd7198 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/event/RepositoryEntityEventTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/event/RepositoryEntityEventTest.java @@ -69,8 +69,7 @@ public class RepositoryEntityEventTest extends AbstractJpaIntegrationTest { @Description("Verifies that the target update event is published when a target has been updated") public void targetUpdateEventIsPublished() throws InterruptedException { final Target createdTarget = testdataFactory.createTarget("12345"); - targetManagement - .updateTarget(entityFactory.target().update(createdTarget.getControllerId()).name("updateName")); + targetManagement.update(entityFactory.target().update(createdTarget.getControllerId()).name("updateName")); final TargetUpdatedEvent targetUpdatedEvent = eventListener.waitForEvent(TargetUpdatedEvent.class); assertThat(targetUpdatedEvent).isNotNull(); @@ -82,7 +81,7 @@ public class RepositoryEntityEventTest extends AbstractJpaIntegrationTest { public void targetDeletedEventIsPublished() throws InterruptedException { final Target createdTarget = testdataFactory.createTarget("12345"); - targetManagement.deleteTarget("12345"); + targetManagement.deleteByControllerID("12345"); final TargetDeletedEvent targetDeletedEvent = eventListener.waitForEvent(TargetDeletedEvent.class); assertThat(targetDeletedEvent).isNotNull(); @@ -104,7 +103,7 @@ public class RepositoryEntityEventTest extends AbstractJpaIntegrationTest { final Rollout createdRollout = testdataFactory.createRolloutByVariables(rolloutName, "desc", amountGroups, "controllerId==" + targetPrefixName + "-*", distributionSet, successCondition, errorCondition); - rolloutManagement.deleteRollout(createdRollout.getId()); + rolloutManagement.delete(createdRollout.getId()); rolloutManagement.handleRollouts(); final RolloutDeletedEvent rolloutDeletedEvent = eventListener.waitForEvent(RolloutDeletedEvent.class); @@ -128,7 +127,7 @@ public class RepositoryEntityEventTest extends AbstractJpaIntegrationTest { public void distributionSetDeletedEventIsPublished() throws InterruptedException { final DistributionSet createDistributionSet = testdataFactory.createDistributionSet(); - distributionSetManagement.deleteDistributionSet(createDistributionSet.getId()); + distributionSetManagement.delete(createDistributionSet.getId()); final DistributionSetDeletedEvent dsDeletedEvent = eventListener .waitForEvent(DistributionSetDeletedEvent.class); @@ -152,7 +151,7 @@ public class RepositoryEntityEventTest extends AbstractJpaIntegrationTest { public void softwareModuleUpdateEventIsPublished() throws InterruptedException { final SoftwareModule softwareModule = testdataFactory.createSoftwareModuleApp(); softwareModuleManagement - .updateSoftwareModule(entityFactory.softwareModule().update(softwareModule.getId()).description("New")); + .update(entityFactory.softwareModule().update(softwareModule.getId()).description("New")); final SoftwareModuleUpdatedEvent softwareModuleUpdatedEvent = eventListener .waitForEvent(SoftwareModuleUpdatedEvent.class); @@ -164,7 +163,7 @@ public class RepositoryEntityEventTest extends AbstractJpaIntegrationTest { @Description("Verifies that the software module deleted event is published when a software module has been deleted") public void softwareModuleDeletedEventIsPublished() throws InterruptedException { final SoftwareModule softwareModule = testdataFactory.createSoftwareModuleApp(); - softwareModuleManagement.deleteSoftwareModule(softwareModule.getId()); + softwareModuleManagement.delete(softwareModule.getId()); final SoftwareModuleDeletedEvent softwareModuleDeletedEvent = eventListener .waitForEvent(SoftwareModuleDeletedEvent.class); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/model/EntityInterceptorListenerTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/model/EntityInterceptorListenerTest.java index e27bd3a85..0fc1f28e7 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/model/EntityInterceptorListenerTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/model/EntityInterceptorListenerTest.java @@ -54,8 +54,7 @@ public class EntityInterceptorListenerTest extends AbstractJpaIntegrationTest { final Target targetToBeCreated = testdataFactory.createTarget("targetToBeCreated"); - final Target loadedTarget = targetManagement.findTargetByControllerID(targetToBeCreated.getControllerId()) - .get(); + final Target loadedTarget = targetManagement.getByControllerID(targetToBeCreated.getControllerId()).get(); assertThat(postLoadEntityListener.getEntity()).isNotNull(); assertThat(postLoadEntityListener.getEntity()).isEqualTo(loadedTarget); } @@ -95,7 +94,7 @@ public class EntityInterceptorListenerTest extends AbstractJpaIntegrationTest { Target updateTarget = addListenerAndCreateTarget(entityInterceptor, "targetToBeCreated"); updateTarget = targetManagement - .updateTarget(entityFactory.target().update(updateTarget.getControllerId()).name("New")); + .update(entityFactory.target().update(updateTarget.getControllerId()).name("New")); assertThat(entityInterceptor.getEntity()).isNotNull(); assertThat(entityInterceptor.getEntity()).isEqualTo(updateTarget); @@ -104,9 +103,9 @@ public class EntityInterceptorListenerTest extends AbstractJpaIntegrationTest { private void executeDeleteAndAssertCallbackResult(final AbstractEntityListener entityInterceptor) { EntityInterceptorHolder.getInstance().getEntityInterceptors().add(entityInterceptor); final SoftwareModuleType type = softwareModuleTypeManagement - .createSoftwareModuleType(entityFactory.softwareModuleType().create().name("test").key("test")); + .create(entityFactory.softwareModuleType().create().name("test").key("test")); - softwareModuleTypeManagement.deleteSoftwareModuleType(type.getId()); + softwareModuleTypeManagement.delete(type.getId()); assertThat(entityInterceptor.getEntity()).isNotNull(); assertThat(entityInterceptor.getEntity()).isEqualTo(type); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/model/ModelEqualsHashcodeTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/model/ModelEqualsHashcodeTest.java index 538b69ca2..1c336f2f7 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/model/ModelEqualsHashcodeTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/model/ModelEqualsHashcodeTest.java @@ -56,11 +56,11 @@ public class ModelEqualsHashcodeTest extends AbstractJpaIntegrationTest { @Description("Verfies that updated entities are not equal.") public void changedEntitiesAreNotEqual() { final SoftwareModuleType type = softwareModuleTypeManagement - .createSoftwareModuleType(entityFactory.softwareModuleType().create().key("test").name("test")); + .create(entityFactory.softwareModuleType().create().key("test").name("test")); assertThat(type).as("persited entity is not equal to regular object") .isNotEqualTo(entityFactory.softwareModuleType().create().key("test").name("test").build()); - final SoftwareModuleType updated = softwareModuleTypeManagement.updateSoftwareModuleType( + final SoftwareModuleType updated = softwareModuleTypeManagement.update( entityFactory.softwareModuleType().update(type.getId()).description("another")); assertThat(type).as("Changed entity is not equal to the previous version").isNotEqualTo(updated); } @@ -68,7 +68,7 @@ public class ModelEqualsHashcodeTest extends AbstractJpaIntegrationTest { @Test @Description("Verify that no proxy of the entity manager has an influence on the equals or hashcode result.") public void managedEntityIsEqualToUnamangedObjectWithSameKey() { - final SoftwareModuleType type = softwareModuleTypeManagement.createSoftwareModuleType( + final SoftwareModuleType type = softwareModuleTypeManagement.create( entityFactory.softwareModuleType().create().key("test").name("test").description("test")); final JpaSoftwareModuleType mock = new JpaSoftwareModuleType("test", "test", "test", 1); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLActionFieldsTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLActionFieldsTest.java index 0b32a854a..52238eaba 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLActionFieldsTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLActionFieldsTest.java @@ -40,7 +40,7 @@ public class RSQLActionFieldsTest extends AbstractJpaIntegrationTest { public void setupBeforeTest() { final DistributionSet dsA = testdataFactory.createDistributionSet("daA"); target = (JpaTarget) targetManagement - .createTarget(entityFactory.target().create().controllerId("targetId123").description("targetId123")); + .create(entityFactory.target().create().controllerId("targetId123").description("targetId123")); action = new JpaAction(); action.setActionType(ActionType.SOFT); action.setDistributionSet(dsA); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLDistributionSetFieldTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLDistributionSetFieldTest.java index aab2ce6ac..d247f1212 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLDistributionSetFieldTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLDistributionSetFieldTest.java @@ -36,21 +36,19 @@ public class RSQLDistributionSetFieldTest extends AbstractJpaIntegrationTest { public void seuptBeforeTest() { DistributionSet ds = testdataFactory.createDistributionSet("DS"); - ds = distributionSetManagement - .updateDistributionSet(entityFactory.distributionSet().update(ds.getId()).description("DS")); + ds = distributionSetManagement.update(entityFactory.distributionSet().update(ds.getId()).description("DS")); createDistributionSetMetadata(ds.getId(), entityFactory.generateMetadata("metaKey", "metaValue")); DistributionSet ds2 = testdataFactory.createDistributionSets("NewDS", 3).get(0); - ds2 = distributionSetManagement - .updateDistributionSet(entityFactory.distributionSet().update(ds2.getId()).description("DS%")); + ds2 = distributionSetManagement.update(entityFactory.distributionSet().update(ds2.getId()).description("DS%")); createDistributionSetMetadata(ds2.getId(), entityFactory.generateMetadata("metaKey", "value")); - final DistributionSetTag targetTag = tagManagement - .createDistributionSetTag(entityFactory.tag().create().name("Tag1")); - tagManagement.createDistributionSetTag(entityFactory.tag().create().name("Tag2")); - tagManagement.createDistributionSetTag(entityFactory.tag().create().name("Tag3")); - tagManagement.createDistributionSetTag(entityFactory.tag().create().name("Tag4")); + final DistributionSetTag targetTag = distributionSetTagManagement + .create(entityFactory.tag().create().name("Tag1")); + distributionSetTagManagement.create(entityFactory.tag().create().name("Tag2")); + distributionSetTagManagement.create(entityFactory.tag().create().name("Tag3")); + distributionSetTagManagement.create(entityFactory.tag().create().name("Tag4")); distributionSetManagement.assignTag(Arrays.asList(ds.getId(), ds2.getId()), targetTag.getId()); } @@ -138,8 +136,7 @@ public class RSQLDistributionSetFieldTest extends AbstractJpaIntegrationTest { } private void assertRSQLQuery(final String rsqlParam, final long excpectedEntity) { - final Page find = distributionSetManagement.findDistributionSetsAll(rsqlParam, - new PageRequest(0, 100), false); + final Page find = distributionSetManagement.findByRsql(new PageRequest(0, 100), rsqlParam); final long countAll = find.getTotalElements(); assertThat(find).as("Founded entity is should not be null").isNotNull(); assertThat(countAll).as("Founded entity size is wrong").isEqualTo(excpectedEntity); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLDistributionSetMetadataFieldsTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLDistributionSetMetadataFieldsTest.java index 446ca0379..d3b20ae4f 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLDistributionSetMetadataFieldsTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLDistributionSetMetadataFieldsTest.java @@ -43,7 +43,7 @@ public class RSQLDistributionSetMetadataFieldsTest extends AbstractJpaIntegratio metadata.add(entityFactory.generateMetadata("" + i, "" + i)); } - distributionSetManagement.createDistributionSetMetadata(distributionSetId, metadata); + distributionSetManagement.createMetaData(distributionSetId, metadata); } @Test @@ -67,7 +67,7 @@ public class RSQLDistributionSetMetadataFieldsTest extends AbstractJpaIntegratio private void assertRSQLQuery(final String rsqlParam, final long expectedEntities) { final Page findEnitity = distributionSetManagement - .findDistributionSetMetadataByDistributionSetId(distributionSetId, rsqlParam, new PageRequest(0, 100)); + .findMetaDataByDistributionSetIdAndRsql(new PageRequest(0, 100), distributionSetId, rsqlParam); final long countAllEntities = findEnitity.getTotalElements(); assertThat(findEnitity).isNotNull(); assertThat(countAllEntities).isEqualTo(expectedEntities); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLRolloutGroupFields.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLRolloutGroupFields.java index 8a3f052e5..9be11d4b1 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLRolloutGroupFields.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLRolloutGroupFields.java @@ -39,9 +39,9 @@ public class RSQLRolloutGroupFields extends AbstractJpaIntegrationTest { testdataFactory.createTargets(amountTargets, "rollout", "rollout"); final DistributionSet dsA = testdataFactory.createDistributionSet(""); rollout = createRollout("rollout1", 4, dsA.getId(), "controllerId==rollout*"); - rollout = rolloutManagement.findRolloutById(rollout.getId()).get(); + rollout = rolloutManagement.get(rollout.getId()).get(); - this.rolloutGroupId = rolloutGroupManagement.findRolloutGroupsByRolloutId(rollout.getId(), PAGE).getContent() + this.rolloutGroupId = rolloutGroupManagement.findByRollout(PAGE, rollout.getId()).getContent() .get(0).getId(); } @@ -75,8 +75,8 @@ public class RSQLRolloutGroupFields extends AbstractJpaIntegrationTest { } private void assertRSQLQuery(final String rsqlParam, final long expcetedTargets) { - final Page findTargetPage = rolloutGroupManagement.findRolloutGroupsAll(rollout.getId(), - rsqlParam, new PageRequest(0, 100)); + final Page findTargetPage = rolloutGroupManagement.findByRolloutAndRsql(new PageRequest(0, 100), + rollout.getId(), rsqlParam); final long countTargetsAll = findTargetPage.getTotalElements(); assertThat(findTargetPage).isNotNull(); assertThat(countTargetsAll).isEqualTo(expcetedTargets); @@ -84,9 +84,9 @@ public class RSQLRolloutGroupFields extends AbstractJpaIntegrationTest { private Rollout createRollout(final String name, final int amountGroups, final long distributionSetId, final String targetFilterQuery) { - return rolloutManagement.createRollout( + return rolloutManagement.create( entityFactory.rollout().create() - .set(distributionSetManagement.findDistributionSetById(distributionSetId).get()).name(name) + .set(distributionSetManagement.get(distributionSetId).get()).name(name) .targetFilterQuery(targetFilterQuery), amountGroups, new RolloutGroupConditionBuilder().withDefaults() .successCondition(RolloutGroupSuccessCondition.THRESHOLD, "100").build()); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleFieldTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleFieldTest.java index e0825b885..0460ece39 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleFieldTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleFieldTest.java @@ -31,21 +31,21 @@ public class RSQLSoftwareModuleFieldTest extends AbstractJpaIntegrationTest { @Before public void setupBeforeTest() { - final SoftwareModule ah = softwareModuleManagement.createSoftwareModule(entityFactory.softwareModule().create() + final SoftwareModule ah = softwareModuleManagement.create(entityFactory.softwareModule().create() .type(appType).name("agent-hub").version("1.0.1").description("agent-hub")); - softwareModuleManagement.createSoftwareModule(entityFactory.softwareModule().create().type(runtimeType) + softwareModuleManagement.create(entityFactory.softwareModule().create().type(runtimeType) .name("oracle-jre").version("1.7.2").description("aa")); - softwareModuleManagement.createSoftwareModule( + softwareModuleManagement.create( entityFactory.softwareModule().create().type(osType).name("poky").version("3.0.2").description("aa")); - final JpaSoftwareModule ah2 = (JpaSoftwareModule) softwareModuleManagement.createSoftwareModule(entityFactory + final JpaSoftwareModule ah2 = (JpaSoftwareModule) softwareModuleManagement.create(entityFactory .softwareModule().create().type(appType).name("agent-hub2").version("1.0.1").description("agent-hub2")); final MetaData softwareModuleMetadata = entityFactory.generateMetadata("metaKey", "metaValue"); - softwareModuleManagement.createSoftwareModuleMetadata(ah.getId(), softwareModuleMetadata); + softwareModuleManagement.createMetaData(ah.getId(), softwareModuleMetadata); final MetaData softwareModuleMetadata2 = entityFactory.generateMetadata("metaKey", "value"); - softwareModuleManagement.createSoftwareModuleMetadata(ah2.getId(), softwareModuleMetadata2); + softwareModuleManagement.createMetaData(ah2.getId(), softwareModuleMetadata2); } @Test @@ -105,8 +105,8 @@ public class RSQLSoftwareModuleFieldTest extends AbstractJpaIntegrationTest { } private void assertRSQLQuery(final String rsqlParam, final long excpectedEntity) { - final Page find = softwareModuleManagement.findSoftwareModulesByPredicate(rsqlParam, - new PageRequest(0, 100)); + final Page find = softwareModuleManagement.findByRsql(new PageRequest(0, 100), + rsqlParam); final long countAll = find.getTotalElements(); assertThat(find).isNotNull(); assertThat(countAll).isEqualTo(excpectedEntity); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleMetadataFieldsTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleMetadataFieldsTest.java index d035bc207..73829d29e 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleMetadataFieldsTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleMetadataFieldsTest.java @@ -45,7 +45,7 @@ public class RSQLSoftwareModuleMetadataFieldsTest extends AbstractJpaIntegration metadata.add(entityFactory.generateMetadata("" + i, "" + i)); } - softwareModuleManagement.createSoftwareModuleMetadata(softwareModule.getId(), metadata); + softwareModuleManagement.createMetaData(softwareModule.getId(), metadata); } @@ -70,7 +70,7 @@ public class RSQLSoftwareModuleMetadataFieldsTest extends AbstractJpaIntegration private void assertRSQLQuery(final String rsqlParam, final long expectedEntities) { final Page findEnitity = softwareModuleManagement - .findSoftwareModuleMetadataBySoftwareModuleId(softwareModuleId, rsqlParam, new PageRequest(0, 100)); + .findMetaDataByRsql(new PageRequest(0, 100), softwareModuleId, rsqlParam); final long countAllEntities = findEnitity.getTotalElements(); assertThat(findEnitity).isNotNull(); assertThat(countAllEntities).isEqualTo(expectedEntities); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleTypeFieldsTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleTypeFieldsTest.java index 4e684d56f..77eaa81f6 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleTypeFieldsTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleTypeFieldsTest.java @@ -60,8 +60,8 @@ public class RSQLSoftwareModuleTypeFieldsTest extends AbstractJpaIntegrationTest } private void assertRSQLQuery(final String rsqlParam, final long excpectedEntity) { - final Page find = softwareModuleTypeManagement.findSoftwareModuleTypesAll(rsqlParam, - new PageRequest(0, 100)); + final Page find = softwareModuleTypeManagement.findByRsql(new PageRequest(0, 100), + rsqlParam); final long countAll = find.getTotalElements(); assertThat(find).isNotNull(); assertThat(countAll).isEqualTo(excpectedEntity); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLTagFieldsTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLTagFieldsTest.java index 239556aae..620c9dd6e 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLTagFieldsTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLTagFieldsTest.java @@ -34,8 +34,8 @@ public class RSQLTagFieldsTest extends AbstractJpaIntegrationTest { for (int i = 0; i < 5; i++) { final TagCreate targetTag = entityFactory.tag().create().name(Integer.toString(i)) .description(Integer.toString(i)).colour(i % 2 == 0 ? "red" : "blue"); - tagManagement.createTargetTag(targetTag); - tagManagement.createDistributionSetTag(targetTag); + targetTagManagement.create(targetTag); + distributionSetTagManagement.create(targetTag); } } @@ -101,8 +101,8 @@ public class RSQLTagFieldsTest extends AbstractJpaIntegrationTest { private void assertRSQLQueryDistributionSet(final String rsqlParam, final long expectedEntities) { - final Page findEnitity = tagManagement.findAllDistributionSetTags(rsqlParam, - new PageRequest(0, 100)); + final Page findEnitity = distributionSetTagManagement.findByRsql(new PageRequest(0, 100), + rsqlParam); final long countAllEntities = findEnitity.getTotalElements(); assertThat(findEnitity).isNotNull(); assertThat(countAllEntities).isEqualTo(expectedEntities); @@ -110,7 +110,7 @@ public class RSQLTagFieldsTest extends AbstractJpaIntegrationTest { private void assertRSQLQueryTarget(final String rsqlParam, final long expectedEntities) { - final Page findEnitity = tagManagement.findAllTargetTags(rsqlParam, new PageRequest(0, 100)); + final Page findEnitity = targetTagManagement.findByRsql(new PageRequest(0, 100), rsqlParam); final long countAllEntities = findEnitity.getTotalElements(); assertThat(findEnitity).isNotNull(); assertThat(countAllEntities).isEqualTo(expectedEntities); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLTargetFieldTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLTargetFieldTest.java index dbde2bd09..fe15ae2d1 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLTargetFieldTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLTargetFieldTest.java @@ -44,14 +44,14 @@ public class RSQLTargetFieldTest extends AbstractJpaIntegrationTest { final Map attributes = new HashMap<>(); - target = targetManagement.createTarget(entityFactory.target().create().controllerId("targetId123") + target = targetManagement.create(entityFactory.target().create().controllerId("targetId123") .name("targetName123").description("targetDesc123")); attributes.put("revision", "1.1"); target = controllerManagement.updateControllerAttributes(target.getControllerId(), attributes); target = controllerManagement.findOrRegisterTargetIfItDoesNotexist(target.getControllerId(), LOCALHOST); target2 = targetManagement - .createTarget(entityFactory.target().create().controllerId("targetId1234").description("targetId1234")); + .create(entityFactory.target().create().controllerId("targetId1234").description("targetId1234")); attributes.put("revision", "1.2"); Thread.sleep(1); target2 = controllerManagement.updateControllerAttributes(target2.getControllerId(), attributes); @@ -60,10 +60,10 @@ public class RSQLTargetFieldTest extends AbstractJpaIntegrationTest { testdataFactory.createTarget("targetId1235"); testdataFactory.createTarget("targetId1236"); - final TargetTag targetTag = tagManagement.createTargetTag(entityFactory.tag().create().name("Tag1")); - tagManagement.createTargetTag(entityFactory.tag().create().name("Tag2")); - tagManagement.createTargetTag(entityFactory.tag().create().name("Tag3")); - tagManagement.createTargetTag(entityFactory.tag().create().name("Tag4")); + final TargetTag targetTag = targetTagManagement.create(entityFactory.tag().create().name("Tag1")); + targetTagManagement.create(entityFactory.tag().create().name("Tag2")); + targetTagManagement.create(entityFactory.tag().create().name("Tag3")); + targetTagManagement.create(entityFactory.tag().create().name("Tag4")); targetManagement.assignTag(Arrays.asList(target.getControllerId(), target2.getControllerId()), targetTag.getId()); @@ -182,7 +182,7 @@ public class RSQLTargetFieldTest extends AbstractJpaIntegrationTest { } private void assertRSQLQuery(final String rsqlParam, final long expcetedTargets) { - final Page findTargetPage = targetManagement.findTargetsAll(rsqlParam, PAGE); + final Page findTargetPage = targetManagement.findByRsql(PAGE, rsqlParam); final long countTargetsAll = findTargetPage.getTotalElements(); assertThat(findTargetPage).isNotNull(); assertThat(countTargetsAll).isEqualTo(expcetedTargets); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/tenancy/MultiTenancyEntityTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/tenancy/MultiTenancyEntityTest.java index 63b095c1c..d0dbd0001 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/tenancy/MultiTenancyEntityTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/tenancy/MultiTenancyEntityTest.java @@ -72,7 +72,7 @@ public class MultiTenancyEntityTest extends AbstractJpaIntegrationTest { createTargetForTenant(controllerAnotherTenant, anotherTenant); // find all targets for current tenant "mytenant" - final Slice findTargetsAll = targetManagement.findTargetsAll(PAGE); + final Slice findTargetsAll = targetManagement.findAll(PAGE); // no target has been created for "mytenant" assertThat(findTargetsAll).hasSize(0); @@ -105,9 +105,9 @@ public class MultiTenancyEntityTest extends AbstractJpaIntegrationTest { // logged in tenant mytenant - check if tenant default data is // autogenerated - assertThat(distributionSetTypeManagement.findDistributionSetTypesAll(PAGE)).isEmpty(); + assertThat(distributionSetTypeManagement.findAll(PAGE)).isEmpty(); assertThat(systemManagement.getTenantMetadata().getTenant().toUpperCase()).isEqualTo("mytenant".toUpperCase()); - assertThat(distributionSetTypeManagement.findDistributionSetTypesAll(PAGE)).isNotEmpty(); + assertThat(distributionSetTypeManagement.findAll(PAGE)).isNotEmpty(); // check that the cache is not getting in the way, i.e. "bumlux" results // in bumlux and not @@ -128,7 +128,7 @@ public class MultiTenancyEntityTest extends AbstractJpaIntegrationTest { // ensure target cannot be deleted by 'mytenant' try { - targetManagement.deleteTargets(Arrays.asList(createTargetForTenant.getId())); + targetManagement.delete(Arrays.asList(createTargetForTenant.getId())); fail("mytenant should not have been able to delete target of anotherTenant"); } catch (final EntityNotFoundException ex) { // ok @@ -173,12 +173,12 @@ public class MultiTenancyEntityTest extends AbstractJpaIntegrationTest { private Slice findTargetsForTenant(final String tenant) throws Exception { return securityRule.runAs(WithSpringAuthorityRule.withUserAndTenant("user", tenant), - () -> targetManagement.findTargetsAll(PAGE)); + () -> targetManagement.findAll(PAGE)); } private void deleteTargetsForTenant(final String tenant, final Collection targetIds) throws Exception { securityRule.runAs(WithSpringAuthorityRule.withUserAndTenant("user", tenant), () -> { - targetManagement.deleteTargets(targetIds); + targetManagement.delete(targetIds); return null; }); } @@ -190,7 +190,7 @@ public class MultiTenancyEntityTest extends AbstractJpaIntegrationTest { private Page findDistributionSetForTenant(final String tenant) throws Exception { return securityRule.runAs(WithSpringAuthorityRule.withUserAndTenant("user", tenant), - () -> distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(PAGE, false, true)); + () -> distributionSetManagement.findByCompleted(PAGE, true)); } } diff --git a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTest.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTest.java index 321e22511..66b71d70e 100644 --- a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTest.java +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTest.java @@ -28,6 +28,7 @@ import org.eclipse.hawkbit.repository.ArtifactManagement; import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.DistributionSetManagement; +import org.eclipse.hawkbit.repository.DistributionSetTagManagement; import org.eclipse.hawkbit.repository.DistributionSetTypeManagement; import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.QuotaManagement; @@ -37,9 +38,9 @@ import org.eclipse.hawkbit.repository.RolloutManagement; import org.eclipse.hawkbit.repository.SoftwareModuleManagement; import org.eclipse.hawkbit.repository.SoftwareModuleTypeManagement; import org.eclipse.hawkbit.repository.SystemManagement; -import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.TargetFilterQueryManagement; import org.eclipse.hawkbit.repository.TargetManagement; +import org.eclipse.hawkbit.repository.TargetTagManagement; import org.eclipse.hawkbit.repository.TenantConfigurationManagement; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.ActionType; @@ -143,7 +144,10 @@ public abstract class AbstractIntegrationTest { protected TargetFilterQueryManagement targetFilterQueryManagement; @Autowired - protected TagManagement tagManagement; + protected TargetTagManagement targetTagManagement; + + @Autowired + protected DistributionSetTagManagement distributionSetTagManagement; @Autowired protected DeploymentManagement deploymentManagement; @@ -234,7 +238,7 @@ public abstract class AbstractIntegrationTest { } protected DistributionSetMetadata createDistributionSetMetadata(final Long dsId, final MetaData md) { - return distributionSetManagement.createDistributionSetMetadata(dsId, Collections.singletonList(md)).get(0); + return distributionSetManagement.createMetaData(dsId, Collections.singletonList(md)).get(0); } protected Long getOsModule(final DistributionSet ds) { @@ -267,17 +271,17 @@ public abstract class AbstractIntegrationTest { osType = securityRule .runAsPrivileged(() -> testdataFactory.findOrCreateSoftwareModuleType(TestdataFactory.SM_TYPE_OS)); - osType = securityRule.runAsPrivileged(() -> softwareModuleTypeManagement.updateSoftwareModuleType( + osType = securityRule.runAsPrivileged(() -> softwareModuleTypeManagement.update( entityFactory.softwareModuleType().update(osType.getId()).description(description))); appType = securityRule.runAsPrivileged( () -> testdataFactory.findOrCreateSoftwareModuleType(TestdataFactory.SM_TYPE_APP, Integer.MAX_VALUE)); - appType = securityRule.runAsPrivileged(() -> softwareModuleTypeManagement.updateSoftwareModuleType( + appType = securityRule.runAsPrivileged(() -> softwareModuleTypeManagement.update( entityFactory.softwareModuleType().update(appType.getId()).description(description))); runtimeType = securityRule .runAsPrivileged(() -> testdataFactory.findOrCreateSoftwareModuleType(TestdataFactory.SM_TYPE_RT)); - runtimeType = securityRule.runAsPrivileged(() -> softwareModuleTypeManagement.updateSoftwareModuleType( + runtimeType = securityRule.runAsPrivileged(() -> softwareModuleTypeManagement.update( entityFactory.softwareModuleType().update(runtimeType.getId()).description(description))); standardDsType = securityRule.runAsPrivileged(() -> testdataFactory.findOrCreateDefaultTestDsType()); diff --git a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/TestdataFactory.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/TestdataFactory.java index f114aa539..375861a1f 100644 --- a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/TestdataFactory.java +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/TestdataFactory.java @@ -27,13 +27,14 @@ import org.eclipse.hawkbit.repository.Constants; import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.DistributionSetManagement; +import org.eclipse.hawkbit.repository.DistributionSetTagManagement; import org.eclipse.hawkbit.repository.DistributionSetTypeManagement; import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.RolloutManagement; import org.eclipse.hawkbit.repository.SoftwareModuleManagement; import org.eclipse.hawkbit.repository.SoftwareModuleTypeManagement; -import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.TargetManagement; +import org.eclipse.hawkbit.repository.TargetTagManagement; import org.eclipse.hawkbit.repository.builder.TagCreate; import org.eclipse.hawkbit.repository.builder.TargetCreate; import org.eclipse.hawkbit.repository.model.Action; @@ -135,7 +136,10 @@ public class TestdataFactory { private DeploymentManagement deploymentManagement; @Autowired - private TagManagement tagManagement; + private TargetTagManagement targetTagManagement; + + @Autowired + private DistributionSetTagManagement distributionSetTagManagement; @Autowired private EntityFactory entityFactory; @@ -262,20 +266,20 @@ public class TestdataFactory { public DistributionSet createDistributionSet(final String prefix, final String version, final boolean isRequiredMigrationStep) { - final SoftwareModule appMod = softwareModuleManagement.createSoftwareModule(entityFactory.softwareModule() + final SoftwareModule appMod = softwareModuleManagement.create(entityFactory.softwareModule() .create().type(findOrCreateSoftwareModuleType(SM_TYPE_APP, Integer.MAX_VALUE)) .name(prefix + SM_TYPE_APP).version(version + "." + new SecureRandom().nextInt(100)) .description(LOREM.words(20)).vendor(prefix + " vendor Limited, California")); - final SoftwareModule runtimeMod = softwareModuleManagement.createSoftwareModule( + final SoftwareModule runtimeMod = softwareModuleManagement.create( entityFactory.softwareModule().create().type(findOrCreateSoftwareModuleType(SM_TYPE_RT)) .name(prefix + "app runtime").version(version + "." + new SecureRandom().nextInt(100)) .description(LOREM.words(20)).vendor(prefix + " vendor GmbH, Stuttgart, Germany")); - final SoftwareModule osMod = softwareModuleManagement.createSoftwareModule( + final SoftwareModule osMod = softwareModuleManagement.create( entityFactory.softwareModule().create().type(findOrCreateSoftwareModuleType(SM_TYPE_OS)) .name(prefix + " Firmware").version(version + "." + new SecureRandom().nextInt(100)) .description(LOREM.words(20)).vendor(prefix + " vendor Limited Inc, California")); - return distributionSetManagement.createDistributionSet( + return distributionSetManagement.create( entityFactory.distributionSet().create().name(prefix != null && prefix.length() > 0 ? prefix : "DS") .version(version).description(LOREM.words(10)).type(findOrCreateDefaultTestDsType()) .modules(Arrays.asList(osMod.getId(), runtimeMod.getId(), appMod.getId())) @@ -302,7 +306,7 @@ public class TestdataFactory { public DistributionSet createDistributionSet(final String prefix, final String version, final boolean isRequiredMigrationStep, final Collection modules) { - return distributionSetManagement.createDistributionSet( + return distributionSetManagement.create( entityFactory.distributionSet().create().name(prefix != null && prefix.length() > 0 ? prefix : "DS") .version(version).description(LOREM.words(10)).type(findOrCreateDefaultTestDsType()) .modules(modules.stream().map(SoftwareModule::getId).collect(Collectors.toList())) @@ -333,7 +337,7 @@ public class TestdataFactory { tags.forEach(tag -> distributionSetManagement.toggleTagAssignment(Arrays.asList(set.getId()), tag.getName())); - return distributionSetManagement.findDistributionSetById(set.getId()).get(); + return distributionSetManagement.get(set.getId()).get(); } @@ -366,7 +370,7 @@ public class TestdataFactory { final List sets = Lists.newArrayListWithExpectedSize(number); for (int i = 0; i < number; i++) { - sets.add(distributionSetManagement.createDistributionSet( + sets.add(distributionSetManagement.create( entityFactory.distributionSet().create().name("DS" + i).version(DEFAULT_VERSION + "." + i) .description(LOREM.words(10)).type(findOrCreateDefaultTestDsType()))); } @@ -413,7 +417,7 @@ public class TestdataFactory { */ public DistributionSet createDistributionSetWithNoSoftwareModules(final String name, final String version) { - return distributionSetManagement.createDistributionSet(entityFactory.distributionSet().create().name(name) + return distributionSetManagement.create(entityFactory.distributionSet().create().name(name) .version(version).description(DEFAULT_DESCRIPTION).type(findOrCreateDefaultTestDsType())); } @@ -430,7 +434,7 @@ public class TestdataFactory { final List artifacts = new ArrayList<>(); for (int i = 0; i < 3; i++) { final InputStream stubInputStream = IOUtils.toInputStream("some test data" + i, Charset.forName("UTF-8")); - artifacts.add(artifactManagement.createArtifact(stubInputStream, moduleId, "filename" + i, false)); + artifacts.add(artifactManagement.create(stubInputStream, moduleId, "filename" + i, false)); } @@ -522,7 +526,7 @@ public class TestdataFactory { * @return persisted {@link SoftwareModule}. */ public SoftwareModule createSoftwareModule(final String typeKey, final String prefix) { - return softwareModuleManagement.createSoftwareModule(entityFactory.softwareModule().create() + return softwareModuleManagement.create(entityFactory.softwareModule().create() .type(findOrCreateSoftwareModuleType(typeKey)).name(prefix + typeKey).version(prefix + DEFAULT_VERSION) .description(LOREM.words(10)).vendor(DEFAULT_VENDOR)); } @@ -540,7 +544,7 @@ public class TestdataFactory { * @return persisted {@link Target} */ public Target createTarget(final String controllerId) { - final Target target = targetManagement.createTarget(entityFactory.target().create().controllerId(controllerId)); + final Target target = targetManagement.create(entityFactory.target().create().controllerId(controllerId)); assertThat(target.getCreatedBy()).isNotNull(); assertThat(target.getCreatedAt()).isNotNull(); assertThat(target.getLastModifiedBy()).isNotNull(); @@ -566,14 +570,14 @@ public class TestdataFactory { */ public DistributionSet createUpdatedDistributionSet() { DistributionSet set = createDistributionSet(""); - set = distributionSetManagement.updateDistributionSet( + set = distributionSetManagement.update( entityFactory.distributionSet().update(set.getId()).description("Updated " + DEFAULT_DESCRIPTION)); - set.getModules().forEach(module -> softwareModuleManagement.updateSoftwareModule( + set.getModules().forEach(module -> softwareModuleManagement.update( entityFactory.softwareModule().update(module.getId()).description("Updated " + DEFAULT_DESCRIPTION))); // load also lazy stuff - return distributionSetManagement.findDistributionSetByIdWithDetails(set.getId()).get(); + return distributionSetManagement.getWithDetails(set.getId()).get(); } /** @@ -604,8 +608,8 @@ public class TestdataFactory { * @return persisted {@link DistributionSetType} */ public DistributionSetType findOrCreateDistributionSetType(final String dsTypeKey, final String dsTypeName) { - return distributionSetTypeManagement.findDistributionSetTypeByKey(dsTypeKey).orElseGet( - () -> distributionSetTypeManagement.createDistributionSetType(entityFactory.distributionSetType() + return distributionSetTypeManagement.getByKey(dsTypeKey).orElseGet( + () -> distributionSetTypeManagement.create(entityFactory.distributionSetType() .create().key(dsTypeKey).name(dsTypeName).description(LOREM.words(10)).colour("black"))); } @@ -626,8 +630,8 @@ public class TestdataFactory { */ public DistributionSetType findOrCreateDistributionSetType(final String dsTypeKey, final String dsTypeName, final Collection mandatory, final Collection optional) { - return distributionSetTypeManagement.findDistributionSetTypeByKey(dsTypeKey) - .orElseGet(() -> distributionSetTypeManagement.createDistributionSetType(entityFactory + return distributionSetTypeManagement.getByKey(dsTypeKey) + .orElseGet(() -> distributionSetTypeManagement.create(entityFactory .distributionSetType().create().key(dsTypeKey).name(dsTypeName).description(LOREM.words(10)) .colour("black") .optional(optional.stream().map(SoftwareModuleType::getId).collect(Collectors.toList())) @@ -660,8 +664,8 @@ public class TestdataFactory { * @return persisted {@link SoftwareModuleType} */ public SoftwareModuleType findOrCreateSoftwareModuleType(final String key, final int maxAssignments) { - return softwareModuleTypeManagement.findSoftwareModuleTypeByKey(key).orElseGet( - () -> softwareModuleTypeManagement.createSoftwareModuleType(entityFactory.softwareModuleType().create() + return softwareModuleTypeManagement.getByKey(key).orElseGet( + () -> softwareModuleTypeManagement.create(entityFactory.softwareModuleType().create() .key(key).name(key).description(LOREM.words(10)).maxAssignments(maxAssignments))); } @@ -681,7 +685,7 @@ public class TestdataFactory { */ public DistributionSet createDistributionSet(final String name, final String version, final DistributionSetType type, final Collection modules) { - return distributionSetManagement.createDistributionSet( + return distributionSetManagement.create( entityFactory.distributionSet().create().name(name).version(version).description(LOREM.words(10)) .type(type).modules(modules.stream().map(SoftwareModule::getId).collect(Collectors.toList()))); } @@ -759,7 +763,7 @@ public class TestdataFactory { targets.add(entityFactory.target().create().controllerId(DEFAULT_CONTROLLER_ID + i)); } - return targetManagement.createTargets(targets); + return targetManagement.create(targets); } /** @@ -825,7 +829,7 @@ public class TestdataFactory { public List createTargets(final int numberOfTargets, final String controllerIdPrefix, final String descriptionPrefix) { - return targetManagement.createTargets(IntStream.range(0, numberOfTargets) + return targetManagement.create(IntStream.range(0, numberOfTargets) .mapToObj(i -> entityFactory.target().create() .controllerId(String.format("%s-%05d", controllerIdPrefix, i)) .description(descriptionPrefix + i)) @@ -848,7 +852,7 @@ public class TestdataFactory { public List createTargets(final int numberOfTargets, final String controllerIdPrefix, final String descriptionPrefix, final Long lastTargetQuery) { - return targetManagement.createTargets(IntStream.range(0, numberOfTargets) + return targetManagement.create(IntStream.range(0, numberOfTargets) .mapToObj(i -> entityFactory.target().create().controllerId(controllerIdPrefix + i) .description(descriptionPrefix + i).lastTargetQuery(lastTargetQuery)) .collect(Collectors.toList())); @@ -871,7 +875,7 @@ public class TestdataFactory { .colour(String.valueOf(i))); } - return tagManagement.createTargetTags(result); + return targetTagManagement.create(result); } /** @@ -890,7 +894,7 @@ public class TestdataFactory { entityFactory.tag().create().name("tag" + i).description("tagdesc" + i).colour(String.valueOf(i))); } - return tagManagement.createDistributionSetTags(result); + return distributionSetTagManagement.create(result); } private Action sendUpdateActionStatusToTarget(final Status status, final Action updActA, @@ -971,14 +975,14 @@ public class TestdataFactory { .errorCondition(RolloutGroupErrorCondition.THRESHOLD, errorCondition) .errorAction(RolloutGroupErrorAction.PAUSE, null).build(); - final Rollout rollout = rolloutManagement.createRollout(entityFactory.rollout().create().name(rolloutName) + final Rollout rollout = rolloutManagement.create(entityFactory.rollout().create().name(rolloutName) .description(rolloutDescription).targetFilterQuery(filterQuery).set(distributionSet), groupSize, conditions); // Run here, because Scheduler is disabled during tests rolloutManagement.handleRollouts(); - return rolloutManagement.findRolloutById(rollout.getId()).get(); + return rolloutManagement.get(rollout.getId()).get(); } /** diff --git a/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/ControllerPreAuthenticateSecurityTokenFilter.java b/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/ControllerPreAuthenticateSecurityTokenFilter.java index 646ffd3be..9fab33fd1 100644 --- a/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/ControllerPreAuthenticateSecurityTokenFilter.java +++ b/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/ControllerPreAuthenticateSecurityTokenFilter.java @@ -80,9 +80,9 @@ public class ControllerPreAuthenticateSecurityTokenFilter extends AbstractContro public HeaderAuthentication getPreAuthenticatedCredentials(final DmfTenantSecurityToken securityToken) { final Optional target = systemSecurityContext.runAsSystemAsTenant(() -> { if (securityToken.getTargetId() != null) { - return controllerManagement.findByTargetId(securityToken.getTargetId()); + return controllerManagement.get(securityToken.getTargetId()); } - return controllerManagement.findByControllerId(securityToken.getControllerId()); + return controllerManagement.getByControllerId(securityToken.getControllerId()); }, securityToken.getTenant()); return target.map(t -> new HeaderAuthentication(t.getControllerId(), @@ -95,7 +95,7 @@ public class ControllerPreAuthenticateSecurityTokenFilter extends AbstractContro return securityToken.getControllerId(); } final Optional foundTarget = systemSecurityContext.runAsSystemAsTenant( - () -> controllerManagement.findByTargetId(securityToken.getTargetId()), securityToken.getTenant()); + () -> controllerManagement.get(securityToken.getTargetId()), securityToken.getTenant()); if (!foundTarget.isPresent()) { return null; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/UploadArtifactView.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/UploadArtifactView.java index 92c752c80..b0f97a456 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/UploadArtifactView.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/UploadArtifactView.java @@ -16,7 +16,6 @@ import org.eclipse.hawkbit.repository.ArtifactManagement; import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.SoftwareModuleManagement; import org.eclipse.hawkbit.repository.SoftwareModuleTypeManagement; -import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.ui.HawkbitUI; import org.eclipse.hawkbit.ui.SpPermissionChecker; import org.eclipse.hawkbit.ui.artifacts.details.ArtifactDetailsLayout; @@ -93,8 +92,7 @@ public class UploadArtifactView extends VerticalLayout implements View, BrowserW @Autowired UploadArtifactView(final UIEventBus eventBus, final SpPermissionChecker permChecker, final VaadinMessageSource i18n, final UINotification uiNotification, final ArtifactUploadState artifactUploadState, - final TagManagement tagManagement, final EntityFactory entityFactory, - final SoftwareModuleManagement softwareModuleManagement, + final EntityFactory entityFactory, final SoftwareModuleManagement softwareModuleManagement, final SoftwareModuleTypeManagement softwareModuleTypeManagement, final UploadViewClientCriterion uploadViewClientCriterion, final MultipartConfigElement multipartConfigElement, final ArtifactManagement artifactManagement) { @@ -104,9 +102,10 @@ public class UploadArtifactView extends VerticalLayout implements View, BrowserW this.uiNotification = uiNotification; this.artifactUploadState = artifactUploadState; this.filterByTypeLayout = new SMTypeFilterLayout(artifactUploadState, i18n, permChecker, eventBus, - tagManagement, entityFactory, uiNotification, softwareModuleTypeManagement, uploadViewClientCriterion); + entityFactory, uiNotification, softwareModuleTypeManagement, uploadViewClientCriterion); this.smTableLayout = new SoftwareModuleTableLayout(i18n, permChecker, artifactUploadState, uiNotification, - eventBus, softwareModuleManagement, softwareModuleTypeManagement, entityFactory, uploadViewClientCriterion); + eventBus, softwareModuleManagement, softwareModuleTypeManagement, entityFactory, + uploadViewClientCriterion); this.artifactDetailsLayout = new ArtifactDetailsLayout(i18n, eventBus, artifactUploadState, uiNotification, artifactManagement, softwareModuleManagement); this.uploadLayout = new UploadLayout(i18n, uiNotification, eventBus, artifactUploadState, diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/details/ArtifactBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/details/ArtifactBeanQuery.java index e0b1159f0..4d050f289 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/details/ArtifactBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/details/ArtifactBeanQuery.java @@ -78,7 +78,7 @@ public class ArtifactBeanQuery extends AbstractBeanQuery { artifactBeans = firstPagetArtifacts; } else { artifactBeans = getArtifactManagement() - .findArtifactBySoftwareModule(new OffsetBasedPageRequest(startIndex, count, sort), baseSwModuleId); + .findBySoftwareModule(new OffsetBasedPageRequest(startIndex, count, sort), baseSwModuleId); } return artifactBeans.getContent(); @@ -95,7 +95,7 @@ public class ArtifactBeanQuery extends AbstractBeanQuery { long size = 0; if (baseSwModuleId != null) { firstPagetArtifacts = getArtifactManagement() - .findArtifactBySoftwareModule(new PageRequest(0, SPUIDefinitions.PAGE_SIZE, sort), baseSwModuleId); + .findBySoftwareModule(new PageRequest(0, SPUIDefinitions.PAGE_SIZE, sort), baseSwModuleId); size = firstPagetArtifacts.getTotalElements(); } if (size > Integer.MAX_VALUE) { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/details/ArtifactDetailsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/details/ArtifactDetailsLayout.java index 2b9afbeb6..7a9f3d733 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/details/ArtifactDetailsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/details/ArtifactDetailsLayout.java @@ -155,7 +155,7 @@ public class ArtifactDetailsLayout extends VerticalLayout { private Optional findSelectedSoftwareModule() { final Optional selectedBaseSwModuleId = artifactUploadState.getSelectedBaseSwModuleId(); if (selectedBaseSwModuleId.isPresent()) { - return softwareModuleManagement.findSoftwareModuleById(selectedBaseSwModuleId.get()); + return softwareModuleManagement.get(selectedBaseSwModuleId.get()); } return Optional.empty(); } @@ -282,7 +282,7 @@ public class ArtifactDetailsLayout extends VerticalLayout { i18n.getMessage("message.delete.artifact", new Object[] { fileName }), i18n.getMessage("button.ok"), i18n.getMessage("button.cancel"), ok -> { if (ok) { - artifactManagement.deleteArtifact(id); + artifactManagement.delete(id); uINotification.displaySuccess(i18n.getMessage("message.artifact.deleted", fileName)); final Optional softwareModule = findSelectedSoftwareModule(); if (softwareModule.isPresent()) { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/footer/UploadViewConfirmationWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/footer/UploadViewConfirmationWindowLayout.java index 4680e08f9..86b9431fb 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/footer/UploadViewConfirmationWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/footer/UploadViewConfirmationWindowLayout.java @@ -152,7 +152,7 @@ public class UploadViewConfirmationWindowLayout extends AbstractConfirmationWind private void deleteSMAll(final ConfirmationTab tab) { final Set swmoduleIds = artifactUploadState.getDeleteSofwareModules().keySet(); - softwareModuleManagement.deleteSoftwareModules(swmoduleIds); + softwareModuleManagement.delete(swmoduleIds); eventBus.publish(this, new SoftwareModuleEvent(BaseEntityEventType.REMOVE_ENTITY, swmoduleIds)); addToConsolitatedMsg(FontAwesome.TRASH_O.getHtml() + SPUILabelDefinitions.HTML_SPACE @@ -250,8 +250,8 @@ public class UploadViewConfirmationWindowLayout extends AbstractConfirmationWind private void deleteSMtypeAll(final ConfirmationTab tab) { final int deleteSWModuleTypeCount = artifactUploadState.getSelectedDeleteSWModuleTypes().size(); for (final String swModuleTypeName : artifactUploadState.getSelectedDeleteSWModuleTypes()) { - softwareModuleTypeManagement.findSoftwareModuleTypeByName(swModuleTypeName).map(SoftwareModuleType::getId) - .ifPresent(softwareModuleTypeManagement::deleteSoftwareModuleType); + softwareModuleTypeManagement.getByName(swModuleTypeName).map(SoftwareModuleType::getId) + .ifPresent(softwareModuleTypeManagement::delete); } addToConsolitatedMsg(FontAwesome.TASKS.getHtml() + SPUILabelDefinitions.HTML_SPACE + i18n.getMessage("message.sw.module.type.delete", new Object[] { deleteSWModuleTypeCount })); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/BaseSwModuleBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/BaseSwModuleBeanQuery.java index 4d78cbc69..e6adcc928 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/BaseSwModuleBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/BaseSwModuleBeanQuery.java @@ -77,11 +77,11 @@ public class BaseSwModuleBeanQuery extends AbstractBeanQuery Integer.MAX_VALUE) { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleAddUpdateWindow.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleAddUpdateWindow.java index caa17712c..f576b6d72 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleAddUpdateWindow.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleAddUpdateWindow.java @@ -140,12 +140,12 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent { final String type = typeComboBox.getValue() != null ? typeComboBox.getValue().toString() : null; final SoftwareModuleType softwareModuleTypeByName = softwareModuleTypeManagement - .findSoftwareModuleTypeByName(type) + .getByName(type) .orElseThrow(() -> new EntityNotFoundException(SoftwareModuleType.class, type)); final SoftwareModuleCreate softwareModule = entityFactory.softwareModule().create() .type(softwareModuleTypeByName).name(name).version(version).description(description).vendor(vendor); - final SoftwareModule newSoftwareModule = softwareModuleManagement.createSoftwareModule(softwareModule); + final SoftwareModule newSoftwareModule = softwareModuleManagement.create(softwareModule); eventBus.publish(this, new SoftwareModuleEvent(BaseEntityEventType.ADD_ENTITY, newSoftwareModule)); uiNotifcation.displaySuccess(i18n.getMessage("message.save.success", new Object[] { newSoftwareModule.getName() + ":" + newSoftwareModule.getVersion() })); @@ -157,10 +157,10 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent { final String version = versionTextField.getValue(); final String type = typeComboBox.getValue() != null ? typeComboBox.getValue().toString() : null; - final Optional moduleType = softwareModuleTypeManagement.findSoftwareModuleTypeByName(type) + final Optional moduleType = softwareModuleTypeManagement.getByName(type) .map(SoftwareModuleType::getId); if (moduleType.isPresent() && softwareModuleManagement - .findSoftwareModuleByNameAndVersion(name, version, moduleType.get()).isPresent()) { + .getByNameAndVersionAndType(name, version, moduleType.get()).isPresent()) { uiNotifcation.displayValidationError( i18n.getMessage("message.duplicate.softwaremodule", new Object[] { name, version })); return true; @@ -173,7 +173,7 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent { */ private void updateSwModule() { final SoftwareModule newSWModule = softwareModuleManagement - .updateSoftwareModule(entityFactory.softwareModule().update(baseSwModuleId) + .update(entityFactory.softwareModule().update(baseSwModuleId) .description(descTextArea.getValue()).vendor(vendorTextField.getValue())); if (newSWModule != null) { uiNotifcation.displaySuccess(i18n.getMessage("message.save.success", @@ -289,7 +289,7 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent { return; } editSwModule = Boolean.TRUE; - softwareModuleManagement.findSoftwareModuleById(baseSwModuleId).ifPresent(swModule -> { + softwareModuleManagement.get(baseSwModuleId).ifPresent(swModule -> { nameTextField.setValue(swModule.getName()); versionTextField.setValue(swModule.getVersion()); vendorTextField.setValue(HawkbitCommonUtil.trimAndNullIfEmpty(swModule.getVendor())); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java index 923455e66..67e8e22d5 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java @@ -146,7 +146,7 @@ public class SoftwareModuleTable extends AbstractNamedVersionTable findEntityByTableValue(final Long entityTableId) { - return softwareModuleManagement.findSoftwareModuleById(entityTableId); + return softwareModuleManagement.get(entityTableId); } @Override @@ -255,7 +255,7 @@ public class SoftwareModuleTable extends AbstractNamedVersionTable UI.getCurrent().addWindow(swMetadataPopupLayout.getWindow(swmodule, null))); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/CreateUpdateSoftwareTypeLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/CreateUpdateSoftwareTypeLayout.java index 46d327b46..3bc4a9f3c 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/CreateUpdateSoftwareTypeLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/CreateUpdateSoftwareTypeLayout.java @@ -14,7 +14,6 @@ import java.util.Optional; import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.SoftwareModuleTypeManagement; -import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.ui.SpPermissionChecker; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleTypeEvent; @@ -66,8 +65,6 @@ public class CreateUpdateSoftwareTypeLayout extends CreateUpdateTypeLayout typeSelected = softwareModuleTypeManagement - .findSoftwareModuleTypeByName(tagNameComboBox.getValue().toString()); + .getByName(tagNameComboBox.getValue().toString()); if (typeSelected.isPresent()) { return typeSelected.get().getColour() != null ? ColorPickerHelper.rgbToColorConverter(typeSelected.get().getColour()) @@ -197,7 +194,7 @@ public class CreateUpdateSoftwareTypeLayout extends CreateUpdateTypeLayout { + softwareModuleTypeManagement.getByName(targetTagSelected).ifPresent(selectedTypeTag -> { tagDesc.setValue(selectedTypeTag.getDescription()); typeKey.setValue(selectedTypeTag.getKey()); if (selectedTypeTag.getMaxAssignments() == 1) { @@ -237,12 +234,12 @@ public class CreateUpdateSoftwareTypeLayout extends CreateUpdateTypeLayout findEntityByKey() { - return softwareModuleTypeManagement.findSoftwareModuleTypeByKey(typeKey.getValue()); + return softwareModuleTypeManagement.getByKey(typeKey.getValue()); } @Override protected Optional findEntityByName() { - return softwareModuleTypeManagement.findSoftwareModuleTypeByName(tagName.getValue()); + return softwareModuleTypeManagement.getByName(tagName.getValue()); } @Override @@ -264,7 +261,7 @@ public class CreateUpdateSoftwareTypeLayout extends CreateUpdateTypeLayout { artifactUploadState.getSoftwareModuleFilters().setSoftwareModuleType(softwareModuleType); eventBus.publish(this, new RefreshSoftwareModuleByFilterEvent()); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/SMTypeFilterHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/SMTypeFilterHeader.java index ff632714d..7c75f68fc 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/SMTypeFilterHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/SMTypeFilterHeader.java @@ -10,7 +10,6 @@ package org.eclipse.hawkbit.ui.artifacts.smtype; import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.SoftwareModuleTypeManagement; -import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.ui.SpPermissionChecker; import org.eclipse.hawkbit.ui.artifacts.event.UploadArtifactUIEvent; import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState; @@ -37,13 +36,12 @@ public class SMTypeFilterHeader extends AbstractFilterHeader { private final CreateUpdateSoftwareTypeLayout createUpdateSWTypeLayout; SMTypeFilterHeader(final VaadinMessageSource i18n, final SpPermissionChecker permChecker, final UIEventBus eventBus, - final ArtifactUploadState artifactUploadState, final TagManagement tagManagement, - final EntityFactory entityFactory, final UINotification uiNotification, - final SoftwareModuleTypeManagement softwareModuletypeManagement) { + final ArtifactUploadState artifactUploadState, final EntityFactory entityFactory, + final UINotification uiNotification, final SoftwareModuleTypeManagement softwareModuletypeManagement) { super(permChecker, eventBus, i18n); this.artifactUploadState = artifactUploadState; - this.createUpdateSWTypeLayout = new CreateUpdateSoftwareTypeLayout(i18n, tagManagement, entityFactory, eventBus, - permChecker, uiNotification, softwareModuletypeManagement); + this.createUpdateSWTypeLayout = new CreateUpdateSoftwareTypeLayout(i18n, entityFactory, eventBus, permChecker, + uiNotification, softwareModuletypeManagement); if (permChecker.hasCreateDistributionPermission() || permChecker.hasUpdateDistributionPermission()) { createUpdateSWTypeLayout.init(); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/SMTypeFilterLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/SMTypeFilterLayout.java index 13fc226cc..ec871ca31 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/SMTypeFilterLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/SMTypeFilterLayout.java @@ -10,7 +10,6 @@ package org.eclipse.hawkbit.ui.artifacts.smtype; import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.SoftwareModuleTypeManagement; -import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.ui.SpPermissionChecker; import org.eclipse.hawkbit.ui.artifacts.event.UploadArtifactUIEvent; import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState; @@ -32,12 +31,11 @@ public class SMTypeFilterLayout extends AbstractFilterLayout { private final ArtifactUploadState artifactUploadState; public SMTypeFilterLayout(final ArtifactUploadState artifactUploadState, final VaadinMessageSource i18n, - final SpPermissionChecker permChecker, final UIEventBus eventBus, final TagManagement tagManagement, - final EntityFactory entityFactory, final UINotification uiNotification, - final SoftwareModuleTypeManagement softwareModuleTypeManagement, + final SpPermissionChecker permChecker, final UIEventBus eventBus, final EntityFactory entityFactory, + final UINotification uiNotification, final SoftwareModuleTypeManagement softwareModuleTypeManagement, final UploadViewClientCriterion uploadViewClientCriterion) { - super(new SMTypeFilterHeader(i18n, permChecker, eventBus, artifactUploadState, tagManagement, entityFactory, - uiNotification, softwareModuleTypeManagement), + super(new SMTypeFilterHeader(i18n, permChecker, eventBus, artifactUploadState, entityFactory, uiNotification, + softwareModuleTypeManagement), new SMTypeFilterButtons(eventBus, artifactUploadState, uploadViewClientCriterion, softwareModuleTypeManagement)); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadConfirmationWindow.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadConfirmationWindow.java index b77f203a3..6aede5bb5 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadConfirmationWindow.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadConfirmationWindow.java @@ -191,7 +191,7 @@ public class UploadConfirmationWindow implements Button.ClickListener { final Item item = uploadDetailsTable.getItem(itemId); if (HawkbitCommonUtil.trimAndNullIfEmpty(fileName) != null) { final Long baseSwId = (Long) item.getItemProperty(BASE_SOFTWARE_ID).getValue(); - final Optional artifact = artifactManagement.findByFilenameAndSoftwareModule(fileName, baseSwId); + final Optional artifact = artifactManagement.getByFilenameAndSoftwareModule(fileName, baseSwId); if (artifact.isPresent()) { warningIconLabel.setVisible(true); if (isErrorIcon(warningIconLabel)) { @@ -431,7 +431,7 @@ public class UploadConfirmationWindow implements Button.ClickListener { final Label errorLabel, final String oldFileName, final Long currentSwId) { if (warningLabel == null && (errorLabelCount > 1 || (duplicateCount == 1 && errorLabelCount == 1))) { - final Optional artifactList = artifactManagement.findByFilenameAndSoftwareModule(oldFileName, + final Optional artifactList = artifactManagement.getByFilenameAndSoftwareModule(oldFileName, currentSwId); if (errorLabel == null) { return; @@ -629,7 +629,7 @@ public class UploadConfirmationWindow implements Button.ClickListener { try (FileInputStream fis = new FileInputStream(newFile)) { - artifactManagement.createArtifact(fis, baseSw.getId(), providedFileName, + artifactManagement.create(fis, baseSw.getId(), providedFileName, HawkbitCommonUtil.trimAndNullIfEmpty(md5Checksum), HawkbitCommonUtil.trimAndNullIfEmpty(sha1Checksum), true, customFile.getMimeType()); saveUploadStatus(providedFileName, swModuleNameVersion, SPUILabelDefinitions.SUCCESS, ""); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java index 93b6cd17c..3a7c6d1fa 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java @@ -217,7 +217,7 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene final Optional selectedBaseSwModuleId = artifactUploadState.getSelectedBaseSwModuleId(); if (selectedBaseSwModuleId.isPresent()) { - selectedSwForUpload = softwareModuleManagement.findSoftwareModuleById(selectedBaseSwModuleId.get()).orElse(null); + selectedSwForUpload = softwareModuleManagement.get(selectedBaseSwModuleId.get()).orElse(null); } if (selectedSwForUpload != null && view.checkIfSoftwareModuleIsSelected() diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java index 4e549bc35..b750af715 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java @@ -251,7 +251,7 @@ public class UploadLayout extends VerticalLayout { artifactUploadState.getSelectedBaseSwModuleId().ifPresent(selectedSwId -> { // reset the flag hasDirectory = false; - final SoftwareModule softwareModule = softwareModuleManagement.findSoftwareModuleById(selectedSwId) + final SoftwareModule softwareModule = softwareModuleManagement.get(selectedSwId) .orElse(null); for (final Html5File file : files) { processFile(file, softwareModule); @@ -730,7 +730,7 @@ public class UploadLayout extends VerticalLayout { } void refreshArtifactDetailsLayout(final Long selectedBaseSoftwareModuleId) { - final SoftwareModule softwareModule = softwareModuleManagement.findSoftwareModuleById(selectedBaseSoftwareModuleId) + final SoftwareModule softwareModule = softwareModuleManagement.get(selectedBaseSoftwareModuleId) .orElse(null); eventBus.publish(this, new SoftwareModuleEvent(SoftwareModuleEventType.ARTIFACTS_CHANGED, softwareModule)); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/DistributionSetTypeBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/DistributionSetTypeBeanQuery.java index 25cb25fe0..ea3a7057c 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/DistributionSetTypeBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/DistributionSetTypeBeanQuery.java @@ -14,11 +14,9 @@ import java.util.Map; import org.eclipse.hawkbit.repository.DistributionSetTypeManagement; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.model.DistributionSetType; -import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SpringContextHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.data.domain.Page; import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort.Direction; import org.vaadin.addons.lazyquerycontainer.AbstractBeanQuery; @@ -38,7 +36,6 @@ public class DistributionSetTypeBeanQuery extends AbstractBeanQuery firstPageDistSetType; private transient DistributionSetTypeManagement distributionSetTypeManagement; /** @@ -62,9 +59,7 @@ public class DistributionSetTypeBeanQuery extends AbstractBeanQuery Integer.MAX_VALUE) { size = Integer.MAX_VALUE; } @@ -80,15 +75,7 @@ public class DistributionSetTypeBeanQuery extends AbstractBeanQuery loadBeans(final int startIndex, final int count) { - Page typeBeans; - if (startIndex == 0 && firstPageDistSetType != null) { - typeBeans = firstPageDistSetType; - } else { - typeBeans = getDistributionSetManagement() - .findDistributionSetTypesAll(new OffsetBasedPageRequest(startIndex, count, sort)); - } - - return typeBeans.getContent(); + return getDistributionSetManagement().findAll(new OffsetBasedPageRequest(startIndex, count, sort)).getContent(); } @Override diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/SoftwareModuleTypeBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/SoftwareModuleTypeBeanQuery.java index 0376ae252..44a61361d 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/SoftwareModuleTypeBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/SoftwareModuleTypeBeanQuery.java @@ -14,9 +14,7 @@ import java.util.Map; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.SoftwareModuleTypeManagement; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; -import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SpringContextHelper; -import org.springframework.data.domain.Page; import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort.Direction; import org.vaadin.addons.lazyquerycontainer.AbstractBeanQuery; @@ -28,8 +26,8 @@ import org.vaadin.addons.lazyquerycontainer.QueryDefinition; */ public class SoftwareModuleTypeBeanQuery extends AbstractBeanQuery { private static final long serialVersionUID = 7824925429198339644L; + private final Sort sort = new Sort(Direction.ASC, "name"); - private transient Page firstPageSwModuleType; private transient SoftwareModuleTypeManagement softwareModuleTypeManagement; /** @@ -47,9 +45,7 @@ public class SoftwareModuleTypeBeanQuery extends AbstractBeanQuery Integer.MAX_VALUE) { size = Integer.MAX_VALUE; } @@ -65,14 +61,9 @@ public class SoftwareModuleTypeBeanQuery extends AbstractBeanQuery loadBeans(final int startIndex, final int count) { - Page swModuleTypeBeans; - if (startIndex == 0 && firstPageSwModuleType != null) { - swModuleTypeBeans = firstPageSwModuleType; - } else { - swModuleTypeBeans = getSoftwareModuleTypeManagement() - .findSoftwareModuleTypesAll(new OffsetBasedPageRequest(startIndex, count, sort)); - } - return swModuleTypeBeans.getContent(); + + return getSoftwareModuleTypeManagement().findAll(new OffsetBasedPageRequest(startIndex, count, sort)) + .getContent(); } @Override diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractDistributionSetDetails.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractDistributionSetDetails.java index e1a67b708..307e43e40 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractDistributionSetDetails.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractDistributionSetDetails.java @@ -11,8 +11,8 @@ package org.eclipse.hawkbit.ui.common.detailslayout; import java.util.Optional; import org.eclipse.hawkbit.repository.DistributionSetManagement; +import org.eclipse.hawkbit.repository.DistributionSetTagManagement; import org.eclipse.hawkbit.repository.EntityFactory; -import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.ui.SpPermissionChecker; import org.eclipse.hawkbit.ui.common.tagdetails.DistributionTagToken; @@ -64,7 +64,7 @@ public abstract class AbstractDistributionSetDetails final DistributionAddUpdateWindowLayout distributionAddUpdateWindowLayout, final DistributionSetManagement distributionSetManagement, final DsMetadataPopupLayout dsMetadataPopupLayout, final EntityFactory entityFactory, - final UINotification uiNotification, final TagManagement tagManagement, + final UINotification uiNotification, final DistributionSetTagManagement distributionSetTagManagement, final SoftwareModuleDetailsTable softwareModuleDetailsTable) { super(i18n, eventBus, permissionChecker, managementUIState); this.distributionAddUpdateWindowLayout = distributionAddUpdateWindowLayout; @@ -72,7 +72,7 @@ public abstract class AbstractDistributionSetDetails this.distributionSetManagement = distributionSetManagement; this.dsMetadataPopupLayout = dsMetadataPopupLayout; this.distributionTagToken = new DistributionTagToken(permissionChecker, i18n, uiNotification, eventBus, - managementUIState, tagManagement, distributionSetManagement); + managementUIState, distributionSetTagManagement, distributionSetManagement); this.softwareModuleDetailsTable = softwareModuleDetailsTable; dsMetadataTable = new DistributionSetMetadatadetailsLayout(i18n, permissionChecker, distributionSetManagement, @@ -132,7 +132,7 @@ public abstract class AbstractDistributionSetDetails @Override protected void showMetadata(final ClickEvent event) { final Optional ds = distributionSetManagement - .findDistributionSetById(getSelectedBaseEntityId()); + .get(getSelectedBaseEntityId()); if (!ds.isPresent()) { uiNotification.displayWarning(getI18n().getMessage("distributionset.not.exists")); return; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractSoftwareModuleDetails.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractSoftwareModuleDetails.java index c4cc5084d..dd66cef65 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractSoftwareModuleDetails.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractSoftwareModuleDetails.java @@ -139,7 +139,7 @@ public abstract class AbstractSoftwareModuleDetails @Override protected void showMetadata(final ClickEvent event) { - softwareModuleManagement.findSoftwareModuleById(getSelectedBaseEntityId()) + softwareModuleManagement.get(getSelectedBaseEntityId()) .ifPresent(swmodule -> UI.getCurrent().addWindow(swMetadataPopupLayout.getWindow(swmodule, null))); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/DistributionSetMetadatadetailsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/DistributionSetMetadatadetailsLayout.java index e66dc1291..d47231d08 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/DistributionSetMetadatadetailsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/DistributionSetMetadatadetailsLayout.java @@ -85,7 +85,7 @@ public class DistributionSetMetadatadetailsLayout extends Table { } selectedDistSetId = distributionSet.getId(); final List dsMetadataList = distributionSetManagement - .findDistributionSetMetadataByDistributionSetId(selectedDistSetId, new PageRequest(0, 500)) + .findMetaDataByDistributionSetId(new PageRequest(0, 500), selectedDistSetId) .getContent(); if (null != dsMetadataList && !dsMetadataList.isEmpty()) { dsMetadataList.forEach(dsMetadata -> setDSMetadataProperties(dsMetadata)); @@ -151,7 +151,7 @@ public class DistributionSetMetadatadetailsLayout extends Table { } private void showMetadataDetails(final Long selectedDistSetId, final String metadataKey) { - final Optional distSet = distributionSetManagement.findDistributionSetById(selectedDistSetId); + final Optional distSet = distributionSetManagement.get(selectedDistSetId); if (!distSet.isPresent()) { notification.displayWarning(i18n.getMessage("distributionset.not.exists")); return; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/SoftwareModuleDetailsTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/SoftwareModuleDetailsTable.java index 27891a2b1..db2281f34 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/SoftwareModuleDetailsTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/SoftwareModuleDetailsTable.java @@ -185,7 +185,7 @@ public class SoftwareModuleDetailsTable extends Table { private void unassignSW(final ClickEvent event, final DistributionSet distributionSet, final Set alreadyAssignedSwModules) { final SoftwareModule unAssignedSw = getSoftwareModule(event.getButton().getId(), alreadyAssignedSwModules); - if (distributionSetManagement.isDistributionSetInUse(distributionSet.getId())) { + if (distributionSetManagement.isInUse(distributionSet.getId())) { uiNotification.displayValidationError(i18n.getMessage("message.error.notification.ds.target.assigned", distributionSet.getName(), distributionSet.getVersion())); } else { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/SoftwareModuleMetadatadetailslayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/SoftwareModuleMetadatadetailslayout.java index 8e8b32579..196e210da 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/SoftwareModuleMetadatadetailslayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/SoftwareModuleMetadatadetailslayout.java @@ -97,8 +97,8 @@ public class SoftwareModuleMetadatadetailslayout extends Table { } selectedSWModuleId = swModule.getId(); final List swMetadataList = softwareModuleManagement - .findSoftwareModuleMetadataBySoftwareModuleId(selectedSWModuleId, - new PageRequest(0, MAX_METADATA_QUERY)) + .findMetaDataBySoftwareModuleId(new PageRequest(0, MAX_METADATA_QUERY), + selectedSWModuleId) .getContent(); if (!CollectionUtils.isEmpty(swMetadataList)) { swMetadataList.forEach(this::setSWMetadataProperties); @@ -178,7 +178,7 @@ public class SoftwareModuleMetadatadetailslayout extends Table { } private void showMetadataDetails(final Long selectedSWModuleId, final String metadataKey) { - softwareModuleManagement.findSoftwareModuleById(selectedSWModuleId).ifPresent(swmodule -> UI.getCurrent() + softwareModuleManagement.get(selectedSWModuleId).ifPresent(swmodule -> UI.getCurrent() .addWindow(swMetadataPopupLayout.getWindow(swmodule, entityFactory.generateMetadata(metadataKey, "")))); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTargetTagToken.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTargetTagToken.java index 68d958fbe..d3ecf0974 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTargetTagToken.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTargetTagToken.java @@ -11,7 +11,7 @@ package org.eclipse.hawkbit.ui.common.tagdetails; import java.util.List; import java.util.Objects; -import org.eclipse.hawkbit.repository.TagManagement; +import org.eclipse.hawkbit.repository.TargetTagManagement; import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagCreatedEvent; import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagUpdatedEvent; import org.eclipse.hawkbit.repository.model.BaseEntity; @@ -37,11 +37,11 @@ public abstract class AbstractTargetTagToken extends Abstr private static final long serialVersionUID = 7772876588903171201L; - protected final transient TagManagement tagManagement; + protected final transient TargetTagManagement tagManagement; protected AbstractTargetTagToken(final SpPermissionChecker checker, final VaadinMessageSource i18n, final UINotification uinotification, final UIEventBus eventBus, final ManagementUIState managementUIState, - final TagManagement tagManagement) { + final TargetTagManagement tagManagement) { super(checker, i18n, uinotification, eventBus, managementUIState); this.tagManagement = tagManagement; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/DistributionTagToken.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/DistributionTagToken.java index e8e169653..3fe949d9c 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/DistributionTagToken.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/DistributionTagToken.java @@ -13,7 +13,7 @@ import java.util.Objects; import java.util.stream.Collectors; import org.eclipse.hawkbit.repository.DistributionSetManagement; -import org.eclipse.hawkbit.repository.TagManagement; +import org.eclipse.hawkbit.repository.DistributionSetTagManagement; import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTagCreatedEvent; import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTagUpdatedEvent; import org.eclipse.hawkbit.repository.model.DistributionSet; @@ -45,7 +45,7 @@ public class DistributionTagToken extends AbstractTagToken { private static final long serialVersionUID = -8022738301736043396L; - private final transient TagManagement tagManagement; + private final transient DistributionSetTagManagement distributionSetTagManagement; private final transient DistributionSetManagement distributionSetManagement; @@ -54,9 +54,10 @@ public class DistributionTagToken extends AbstractTagToken { public DistributionTagToken(final SpPermissionChecker checker, final VaadinMessageSource i18n, final UINotification uinotification, final UIEventBus eventBus, final ManagementUIState managementUIState, - final TagManagement tagManagement, final DistributionSetManagement distributionSetManagement) { + final DistributionSetTagManagement distributionSetTagManagement, + final DistributionSetManagement distributionSetManagement) { super(checker, i18n, uinotification, eventBus, managementUIState); - this.tagManagement = tagManagement; + this.distributionSetTagManagement = distributionSetTagManagement; this.distributionSetManagement = distributionSetManagement; } @@ -107,8 +108,8 @@ public class DistributionTagToken extends AbstractTagToken { public void displayAlreadyAssignedTags() { removePreviouslyAddedTokens(); if (selectedEntity != null) { - tagManagement - .findDistributionSetTagsByDistributionSet(new PageRequest(0, MAX_TAG_QUERY), selectedEntity.getId()) + distributionSetTagManagement + .findByDistributionSet(new PageRequest(0, MAX_TAG_QUERY), selectedEntity.getId()) .getContent().stream().forEach(tag -> addNewToken(tag.getId())); } } @@ -117,7 +118,7 @@ public class DistributionTagToken extends AbstractTagToken { protected void populateContainer() { container.removeAllItems(); tagDetails.clear(); - tagManagement.findAllDistributionSetTags(new PageRequest(0, MAX_TAG_QUERY)).getContent().stream() + distributionSetTagManagement.findAll(new PageRequest(0, MAX_TAG_QUERY)).getContent().stream() .forEach(tag -> setContainerPropertValues(tag.getId(), tag.getName(), tag.getColour())); } @@ -129,8 +130,7 @@ public class DistributionTagToken extends AbstractTagToken { @EventBusListenerMethod(scope = EventScope.UI) void onDistributionSetTagCreatedBulkEvent(final DistributionSetTagCreatedEventContainer eventContainer) { - eventContainer.getEvents().stream().filter(Objects::nonNull) - .map(DistributionSetTagCreatedEvent::getEntity) + eventContainer.getEvents().stream().filter(Objects::nonNull).map(DistributionSetTagCreatedEvent::getEntity) .forEach(distributionSetTag -> setContainerPropertValues(distributionSetTag.getId(), distributionSetTag.getName(), distributionSetTag.getColour())); } @@ -143,8 +143,8 @@ public class DistributionTagToken extends AbstractTagToken { @EventBusListenerMethod(scope = EventScope.UI) void onDistributionSetTagUpdateEvent(final DistributionSetTagUpdatedEventContainer eventContainer) { - eventContainer.getEvents().stream().filter(Objects::nonNull) - .map(DistributionSetTagUpdatedEvent::getEntity).forEach(entity -> { + eventContainer.getEvents().stream().filter(Objects::nonNull).map(DistributionSetTagUpdatedEvent::getEntity) + .forEach(entity -> { final Item item = container.getItem(entity.getId()); if (item != null) { updateItem(entity.getName(), entity.getColour(), item); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/TargetTagToken.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/TargetTagToken.java index a803c7359..836876ad4 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/TargetTagToken.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/TargetTagToken.java @@ -11,7 +11,7 @@ package org.eclipse.hawkbit.ui.common.tagdetails; import java.util.Arrays; import java.util.Optional; -import org.eclipse.hawkbit.repository.TagManagement; +import org.eclipse.hawkbit.repository.TargetTagManagement; import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetTag; @@ -46,7 +46,7 @@ public class TargetTagToken extends AbstractTargetTagToken { public TargetTagToken(final SpPermissionChecker checker, final VaadinMessageSource i18n, final UINotification uinotification, final UIEventBus eventBus, final ManagementUIState managementUIState, - final TagManagement tagManagement, final TargetManagement targetManagement) { + final TargetTagManagement tagManagement, final TargetManagement targetManagement) { super(checker, i18n, uinotification, eventBus, managementUIState, tagManagement); this.targetManagement = targetManagement; } @@ -98,7 +98,7 @@ public class TargetTagToken extends AbstractTargetTagToken { protected void displayAlreadyAssignedTags() { removePreviouslyAddedTokens(); if (selectedEntity != null) { - for (final TargetTag tag : tagManagement.findAllTargetTags(new PageRequest(0, MAX_TAGS), + for (final TargetTag tag : tagManagement.findByTarget(new PageRequest(0, MAX_TAGS), selectedEntity.getControllerId())) { addNewToken(tag.getId()); } @@ -109,7 +109,7 @@ public class TargetTagToken extends AbstractTargetTagToken { protected void populateContainer() { container.removeAllItems(); tagDetails.clear(); - for (final TargetTag tag : tagManagement.findAllTargetTags(new PageRequest(0, MAX_TAGS))) { + for (final TargetTag tag : tagManagement.findAll(new PageRequest(0, MAX_TAGS))) { setContainerPropertValues(tag.getId(), tag.getName(), tag.getColour()); } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/DistributionsView.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/DistributionsView.java index 758793dac..5c8d63354 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/DistributionsView.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/DistributionsView.java @@ -14,12 +14,12 @@ import javax.annotation.PostConstruct; import org.eclipse.hawkbit.repository.ArtifactManagement; import org.eclipse.hawkbit.repository.DistributionSetManagement; +import org.eclipse.hawkbit.repository.DistributionSetTagManagement; import org.eclipse.hawkbit.repository.DistributionSetTypeManagement; import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.SoftwareModuleManagement; import org.eclipse.hawkbit.repository.SoftwareModuleTypeManagement; import org.eclipse.hawkbit.repository.SystemManagement; -import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.ui.HawkbitUI; import org.eclipse.hawkbit.ui.SpPermissionChecker; @@ -100,7 +100,7 @@ public class DistributionsView extends AbstractNotificationView implements Brows final SoftwareModuleTypeManagement softwareModuleTypeManagement, final DistributionSetManagement distributionSetManagement, final DistributionSetTypeManagement distributionSetTypeManagement, final TargetManagement targetManagement, - final EntityFactory entityFactory, final TagManagement tagManagement, + final EntityFactory entityFactory, final DistributionSetTagManagement distributionSetTagManagement, final DistributionsViewClientCriterion distributionsViewClientCriterion, final ArtifactUploadState artifactUploadState, final SystemManagement systemManagement, final ArtifactManagement artifactManagement, final NotificationUnreadButton notificationUnreadButton, @@ -110,17 +110,17 @@ public class DistributionsView extends AbstractNotificationView implements Brows this.i18n = i18n; this.uiNotification = uiNotification; this.filterByDSTypeLayout = new DSTypeFilterLayout(manageDistUIState, i18n, permChecker, eventBus, - tagManagement, entityFactory, uiNotification, softwareModuleTypeManagement, - distributionSetTypeManagement, distributionsViewClientCriterion); + entityFactory, uiNotification, softwareModuleTypeManagement, distributionSetTypeManagement, + distributionSetManagement, distributionsViewClientCriterion); this.distributionTableLayout = new DistributionSetTableLayout(i18n, eventBus, permChecker, manageDistUIState, softwareModuleManagement, distributionSetManagement, distributionSetTypeManagement, targetManagement, - entityFactory, uiNotification, tagManagement, distributionsViewClientCriterion, systemManagement); + entityFactory, uiNotification, distributionSetTagManagement, distributionsViewClientCriterion, + systemManagement); this.softwareModuleTableLayout = new SwModuleTableLayout(i18n, uiNotification, eventBus, softwareModuleManagement, softwareModuleTypeManagement, entityFactory, manageDistUIState, permChecker, distributionsViewClientCriterion, artifactUploadState, artifactManagement); this.filterBySMTypeLayout = new DistSMTypeFilterLayout(eventBus, i18n, permChecker, manageDistUIState, - tagManagement, entityFactory, uiNotification, softwareModuleTypeManagement, - distributionsViewClientCriterion); + entityFactory, uiNotification, softwareModuleTypeManagement, distributionsViewClientCriterion); this.deleteActionsLayout = new DSDeleteActionsLayout(i18n, permChecker, eventBus, uiNotification, systemManagement, manageDistUIState, distributionsViewClientCriterion, distributionSetManagement, distributionSetTypeManagement, softwareModuleManagement, softwareModuleTypeManagement); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/CreateUpdateDistSetTypeLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/CreateUpdateDistSetTypeLayout.java index 990b366a3..940874fff 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/CreateUpdateDistSetTypeLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/CreateUpdateDistSetTypeLayout.java @@ -13,10 +13,10 @@ import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; +import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.DistributionSetTypeManagement; import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.SoftwareModuleTypeManagement; -import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.builder.DistributionSetTypeUpdate; import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; @@ -74,6 +74,8 @@ public class CreateUpdateDistSetTypeLayout extends CreateUpdateTypeLayout existedDistType = distributionSetTypeManagement - .findDistributionSetTypeByName(tagNameComboBox.getValue().toString()); + .getByName(tagNameComboBox.getValue().toString()); if (existedDistType.isPresent()) { return existedDistType.get().getColour() != null ? ColorPickerHelper.rgbToColorConverter(existedDistType.get().getColour()) @@ -194,7 +198,7 @@ public class CreateUpdateDistSetTypeLayout extends CreateUpdateTypeLayout moduleTypeBeans = softwareModuleTypeManagement - .findSoftwareModuleTypesAll(new PageRequest(0, 1_000)); + .findAll(new PageRequest(0, 1_000)); Item saveTblitem; for (final SoftwareModuleType swTypeTag : moduleTypeBeans) { saveTblitem = sourceTableContainer.addItem(swTypeTag.getId()); @@ -398,11 +402,10 @@ public class CreateUpdateDistSetTypeLayout extends CreateUpdateTypeLayout optional = itemIds.stream() .filter(itemId -> isOptionalModuleType(selectedTable.getItem(itemId))).collect(Collectors.toList()); - final DistributionSetType newDistType = distributionSetTypeManagement.createDistributionSetType( - entityFactory.distributionSetType().create().key(typeKeyValue).name(typeNameValue) + final DistributionSetType newDistType = distributionSetTypeManagement + .create(entityFactory.distributionSetType().create().key(typeKeyValue).name(typeNameValue) .description(typeDescValue).colour(colorPicked).mandatory(mandatory).optional(optional)); - uiNotification - .displaySuccess(i18n.getMessage("message.save.success", new Object[] { newDistType.getName() })); + uiNotification.displaySuccess(i18n.getMessage("message.save.success", newDistType.getName())); eventBus.publish(this, new DistributionSetTypeEvent(DistributionSetTypeEnum.ADD_DIST_SET_TYPE, newDistType)); } else { @@ -430,8 +433,7 @@ public class CreateUpdateDistSetTypeLayout extends CreateUpdateTypeLayout isMandatoryModuleType(selectedTable.getItem(itemId))) .collect(Collectors.toList())) @@ -439,10 +441,9 @@ public class CreateUpdateDistSetTypeLayout extends CreateUpdateTypeLayout { + distributionSetTypeManagement.getByName(distSetTypeSelected).ifPresent(selectedTypeTag -> { tagDesc.setValue(selectedTypeTag.getDescription()); typeKey.setValue(selectedTypeTag.getKey()); - if (distributionSetTypeManagement.countDistributionSetsByType(selectedTypeTag.getId()) <= 0) { + if (distributionSetManagement.countByTypeId(selectedTypeTag.getId()) <= 0) { distTypeSelectLayout.setEnabled(true); selectedTable.setEnabled(true); } else { @@ -585,17 +586,17 @@ public class CreateUpdateDistSetTypeLayout extends CreateUpdateTypeLayout findEntityByKey() { - return distributionSetTypeManagement.findDistributionSetTypeByKey(typeKey.getValue()); + return distributionSetTypeManagement.getByKey(typeKey.getValue()); } @Override protected Optional findEntityByName() { - return distributionSetTypeManagement.findDistributionSetTypeByName(tagName.getValue()); + return distributionSetTypeManagement.getByName(tagName.getValue()); } @Override protected String getDuplicateKeyErrorMessage(final DistributionSetType existingType) { - return i18n.getMessage("message.type.key.duplicate.check", new Object[] { existingType.getKey() }); + return i18n.getMessage("message.type.key.duplicate.check", existingType.getKey()); } @Override diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/DSTypeFilterButtonClick.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/DSTypeFilterButtonClick.java index 76681d523..48268c587 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/DSTypeFilterButtonClick.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/DSTypeFilterButtonClick.java @@ -47,7 +47,7 @@ public class DSTypeFilterButtonClick extends AbstractFilterSingleButtonClick imp @Override protected void filterClicked(final Button clickedButton) { - distributionSetTypeManagement.findDistributionSetTypeByName(clickedButton.getData().toString()) + distributionSetTypeManagement.getByName(clickedButton.getData().toString()) .ifPresent(manageDistUIState.getManageDistFilters()::setClickedDistSetType); eventBus.publish(this, new RefreshDistributionTableByFilterEvent()); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/DSTypeFilterHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/DSTypeFilterHeader.java index 3bd0a8453..87a604112 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/DSTypeFilterHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/DSTypeFilterHeader.java @@ -8,10 +8,10 @@ */ package org.eclipse.hawkbit.ui.distributions.disttype; +import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.DistributionSetTypeManagement; import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.SoftwareModuleTypeManagement; -import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.ui.SpPermissionChecker; import org.eclipse.hawkbit.ui.common.CommonDialogWindow; import org.eclipse.hawkbit.ui.common.filterlayout.AbstractFilterHeader; @@ -38,14 +38,15 @@ public class DSTypeFilterHeader extends AbstractFilterHeader { private final CreateUpdateDistSetTypeLayout createUpdateDistSetTypeLayout; DSTypeFilterHeader(final VaadinMessageSource i18n, final SpPermissionChecker permChecker, final UIEventBus eventBus, - final ManageDistUIState manageDistUIState, final TagManagement tagManagement, - final EntityFactory entityFactory, final UINotification uiNotification, - final SoftwareModuleTypeManagement softwareModuleTypeManagement, - final DistributionSetTypeManagement distributionSetTypeManagement) { + final ManageDistUIState manageDistUIState, final EntityFactory entityFactory, + final UINotification uiNotification, final SoftwareModuleTypeManagement softwareModuleTypeManagement, + final DistributionSetTypeManagement distributionSetTypeManagement, + final DistributionSetManagement distributionSetManagement) { super(permChecker, eventBus, i18n); this.manageDistUIState = manageDistUIState; - this.createUpdateDistSetTypeLayout = new CreateUpdateDistSetTypeLayout(i18n, tagManagement, entityFactory, - eventBus, permChecker, uiNotification, softwareModuleTypeManagement, distributionSetTypeManagement); + this.createUpdateDistSetTypeLayout = new CreateUpdateDistSetTypeLayout(i18n, entityFactory, eventBus, + permChecker, uiNotification, softwareModuleTypeManagement, distributionSetTypeManagement, + distributionSetManagement); if (hasCreateUpdatePermission()) { createUpdateDistSetTypeLayout.init(); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/DSTypeFilterLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/DSTypeFilterLayout.java index 014f4f59d..bbf712a65 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/DSTypeFilterLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/DSTypeFilterLayout.java @@ -8,10 +8,10 @@ */ package org.eclipse.hawkbit.ui.distributions.disttype; +import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.DistributionSetTypeManagement; import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.SoftwareModuleTypeManagement; -import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.ui.SpPermissionChecker; import org.eclipse.hawkbit.ui.common.filterlayout.AbstractFilterLayout; import org.eclipse.hawkbit.ui.dd.criteria.DistributionsViewClientCriterion; @@ -33,13 +33,13 @@ public class DSTypeFilterLayout extends AbstractFilterLayout { private final ManageDistUIState manageDistUIState; public DSTypeFilterLayout(final ManageDistUIState manageDistUIState, final VaadinMessageSource i18n, - final SpPermissionChecker permChecker, final UIEventBus eventBus, final TagManagement tagManagement, - final EntityFactory entityFactory, final UINotification uiNotification, - final SoftwareModuleTypeManagement softwareModuleTypeManagement, + final SpPermissionChecker permChecker, final UIEventBus eventBus, final EntityFactory entityFactory, + final UINotification uiNotification, final SoftwareModuleTypeManagement softwareModuleTypeManagement, final DistributionSetTypeManagement distributionSetTypeManagement, + final DistributionSetManagement distributionSetManagement, final DistributionsViewClientCriterion distributionsViewClientCriterion) { - super(new DSTypeFilterHeader(i18n, permChecker, eventBus, manageDistUIState, tagManagement, entityFactory, - uiNotification, softwareModuleTypeManagement, distributionSetTypeManagement), + super(new DSTypeFilterHeader(i18n, permChecker, eventBus, manageDistUIState, entityFactory, uiNotification, + softwareModuleTypeManagement, distributionSetTypeManagement, distributionSetManagement), new DSTypeFilterButtons(eventBus, manageDistUIState, distributionsViewClientCriterion, distributionSetTypeManagement)); this.manageDistUIState = manageDistUIState; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetDetails.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetDetails.java index 3df09736b..0bc723b59 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetDetails.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetDetails.java @@ -13,9 +13,9 @@ import java.util.Map; import java.util.Set; import org.eclipse.hawkbit.repository.DistributionSetManagement; +import org.eclipse.hawkbit.repository.DistributionSetTagManagement; import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.SoftwareModuleManagement; -import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.ui.SpPermissionChecker; @@ -69,14 +69,15 @@ public class DistributionSetDetails extends AbstractDistributionSetDetails { final SpPermissionChecker permissionChecker, final ManageDistUIState manageDistUIState, final ManagementUIState managementUIState, final DistributionAddUpdateWindowLayout distributionAddUpdateWindowLayout, - final SoftwareModuleManagement softwareManagement, final DistributionSetManagement distributionSetManagement, - final TargetManagement targetManagement, final EntityFactory entityFactory, - final UINotification uiNotification, final TagManagement tagManagement, + final SoftwareModuleManagement softwareManagement, + final DistributionSetManagement distributionSetManagement, final TargetManagement targetManagement, + final EntityFactory entityFactory, final UINotification uiNotification, + final DistributionSetTagManagement distributionSetTagManagement, final DsMetadataPopupLayout dsMetadataPopupLayout) { super(i18n, eventBus, permissionChecker, managementUIState, distributionAddUpdateWindowLayout, - distributionSetManagement, dsMetadataPopupLayout, entityFactory, uiNotification, tagManagement, - createSoftwareModuleDetailsTable(i18n, permissionChecker, distributionSetManagement, eventBus, - manageDistUIState, uiNotification)); + distributionSetManagement, dsMetadataPopupLayout, entityFactory, uiNotification, + distributionSetTagManagement, createSoftwareModuleDetailsTable(i18n, permissionChecker, + distributionSetManagement, eventBus, manageDistUIState, uiNotification)); this.manageDistUIState = manageDistUIState; this.softwareModuleManagement = softwareManagement; this.targetManagement = targetManagement; @@ -127,7 +128,7 @@ public class DistributionSetDetails extends AbstractDistributionSetDetails { } softwareModuleIdNameList.stream().map(SoftwareModuleIdName::getId) - .map(softwareModuleManagement::findSoftwareModuleById) + .map(softwareModuleManagement::get) .forEach(found -> found.ifPresent(softwareModule -> { if (assignedSWModule.containsKey(softwareModule.getType().getName())) { @@ -157,7 +158,7 @@ public class DistributionSetDetails extends AbstractDistributionSetDetails { private Button assignSoftModuleButton(final String softwareModuleName) { if (getPermissionChecker().hasUpdateDistributionPermission() && manageDistUIState.getLastSelectedDistribution() - .map(selected -> targetManagement.countTargetByAssignedDistributionSet(selected) <= 0).orElse(false)) { + .map(selected -> targetManagement.countByAssignedDistributionSet(selected) <= 0).orElse(false)) { final Button reassignSoftModule = SPUIComponentProvider.getButton(softwareModuleName, "", "", "", true, FontAwesome.TIMES, SPUIButtonStyleSmallNoBorder.class); @@ -254,7 +255,7 @@ public class DistributionSetDetails extends AbstractDistributionSetDetails { assignedSWModule.clear(); } - getDistributionSetManagement().findDistributionSetByIdWithDetails(getSelectedBaseEntityId()) + getDistributionSetManagement().getWithDetails(getSelectedBaseEntityId()) .ifPresent(set -> { setSelectedBaseEntity(set); UI.getCurrent().access(this::populateModule); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java index 774f1f967..5ff6a766b 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java @@ -182,7 +182,7 @@ public class DistributionSetTable extends AbstractNamedVersionTable findEntityByTableValue(final Long entityTableId) { - return distributionSetManagement.findDistributionSetByIdWithDetails(entityTableId); + return distributionSetManagement.getWithDetails(entityTableId); } @Override @@ -239,7 +239,7 @@ public class DistributionSetTable extends AbstractNamedVersionTable softwareModulesIdList, final Object distId) { final Optional distributionSet = distributionSetManagement - .findDistributionSetById((Long) distId); + .get((Long) distId); if (!distributionSet.isPresent()) { notification.displayWarning(i18n.getMessage("distributionset.not.exists")); @@ -262,7 +262,7 @@ public class DistributionSetTable extends AbstractNamedVersionTable softwareModule = softwareModuleManagement - .findSoftwareModuleById(softwareModuleId); + .get(softwareModuleId); if (softwareModule.isPresent() && validSoftwareModule((Long) distId, softwareModule.get())) { final SoftwareModuleIdName softwareModuleIdName = new SoftwareModuleIdName(softwareModuleId, @@ -321,12 +321,12 @@ public class DistributionSetTable extends AbstractNamedVersionTable ds = distributionSetManagement.findDistributionSetByIdWithDetails(distId); + final Optional ds = distributionSetManagement.getWithDetails(distId); if (!ds.isPresent() || !validateSoftwareModule(sm, ds.get())) { return false; } - if (distributionSetManagement.isDistributionSetInUse(ds.get().getId())) { + if (distributionSetManagement.isInUse(ds.get().getId())) { notification.displayValidationError(i18n.getMessage("message.error.notification.ds.target.assigned", ds.get().getName(), ds.get().getVersion())); return false; @@ -335,7 +335,7 @@ public class DistributionSetTable extends AbstractNamedVersionTable 0) { + if (targetManagement.countByFilters(null, null, null, ds.getId(), Boolean.FALSE, new String[] {}) > 0) { /* Distribution is already assigned */ notification.displayValidationError(i18n.getMessage("message.dist.inuse", HawkbitCommonUtil.concatStrings(":", ds.getName(), ds.getVersion()))); @@ -479,7 +479,7 @@ public class DistributionSetTable extends AbstractNamedVersionTable UI.getCurrent().addWindow(dsMetadataPopupLayout.getWindow(ds, null))); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTableLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTableLayout.java index 03ca85f5d..7c3b57d86 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTableLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTableLayout.java @@ -9,11 +9,11 @@ package org.eclipse.hawkbit.ui.distributions.dstable; import org.eclipse.hawkbit.repository.DistributionSetManagement; +import org.eclipse.hawkbit.repository.DistributionSetTagManagement; import org.eclipse.hawkbit.repository.DistributionSetTypeManagement; import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.SoftwareModuleManagement; import org.eclipse.hawkbit.repository.SystemManagement; -import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.ui.SpPermissionChecker; import org.eclipse.hawkbit.ui.common.table.AbstractTableLayout; @@ -35,9 +35,11 @@ public class DistributionSetTableLayout extends AbstractTableLayout getMetadataList() { return Collections.unmodifiableList(distributionSetManagement - .findDistributionSetMetadataByDistributionSetId(getSelectedEntity().getId(), new PageRequest(0, 500)) + .findMetaDataByDistributionSetId(new PageRequest(0, 500), getSelectedEntity().getId()) .getContent()); } @Override protected void deleteMetadata(final DistributionSet entity, final String key, final String value) { - distributionSetManagement.deleteDistributionSetMetadata(entity.getId(), key); + distributionSetManagement.deleteMetaData(entity.getId(), key); } @Override diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/ManageDistBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/ManageDistBeanQuery.java index 26d40a170..c2b53b689 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/ManageDistBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/ManageDistBeanQuery.java @@ -72,7 +72,7 @@ public class ManageDistBeanQuery extends AbstractBeanQuery { } } - if (sortStates!= null && sortStates.length > 0) { + if (sortStates != null && sortStates.length > 0) { // Initialize sort sort = new Sort(sortStates[0] ? Direction.ASC : Direction.DESC, (String) sortPropertyIds[0]); // Add sort @@ -96,13 +96,13 @@ public class ManageDistBeanQuery extends AbstractBeanQuery { distBeans = firstPageDistributionSets; } else if (StringUtils.isEmpty(searchText)) { // if no search filters available - distBeans = getDistributionSetManagement().findDistributionSetsByDeletedAndOrCompleted( - new OffsetBasedPageRequest(startIndex, count, sort), false, dsComplete); + distBeans = getDistributionSetManagement() + .findByCompleted(new OffsetBasedPageRequest(startIndex, count, sort), dsComplete); } else { final DistributionSetFilter distributionSetFilter = new DistributionSetFilterBuilder().setIsDeleted(false) .setIsComplete(dsComplete).setSearchText(searchText).setSelectDSWithNoTag(Boolean.FALSE) .setType(distributionSetType).build(); - distBeans = getDistributionSetManagement().findDistributionSetsByFilters( + distBeans = getDistributionSetManagement().findByDistributionSetFilter( new PageRequest(startIndex / count, count, sort), distributionSetFilter); } @@ -122,13 +122,13 @@ public class ManageDistBeanQuery extends AbstractBeanQuery { public int size() { if (StringUtils.isEmpty(searchText) && null == distributionSetType) { // if no search filters available - firstPageDistributionSets = getDistributionSetManagement().findDistributionSetsByDeletedAndOrCompleted( - new PageRequest(0, SPUIDefinitions.PAGE_SIZE, sort), false, dsComplete); + firstPageDistributionSets = getDistributionSetManagement() + .findByCompleted(new PageRequest(0, SPUIDefinitions.PAGE_SIZE, sort), dsComplete); } else { final DistributionSetFilter distributionSetFilter = new DistributionSetFilterBuilder().setIsDeleted(false) .setIsComplete(dsComplete).setSearchText(searchText).setSelectDSWithNoTag(Boolean.FALSE) .setType(distributionSetType).build(); - firstPageDistributionSets = getDistributionSetManagement().findDistributionSetsByFilters( + firstPageDistributionSets = getDistributionSetManagement().findByDistributionSetFilter( new PageRequest(0, SPUIDefinitions.PAGE_SIZE, sort), distributionSetFilter); } final long size = firstPageDistributionSets.getTotalElements(); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DSDeleteActionsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DSDeleteActionsLayout.java index a5422e002..225e68fdc 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DSDeleteActionsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DSDeleteActionsLayout.java @@ -191,7 +191,7 @@ public class DSDeleteActionsLayout extends AbstractDeleteActionsLayout { final AbstractTable table = (AbstractTable) sourceTable; final Set ids = table.getDeletedEntityByTransferable(transferable); final List findDistributionSetAllById = distributionSetManagement - .findDistributionSetsById(ids); + .get(ids); if (findDistributionSetAllById.isEmpty()) { notification.displayWarning(i18n.getMessage("distributionsets.not.exists")); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DistributionsConfirmationWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DistributionsConfirmationWindowLayout.java index 4fd7c69df..9a782ede4 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DistributionsConfirmationWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DistributionsConfirmationWindowLayout.java @@ -176,7 +176,7 @@ public class DistributionsConfirmationWindowLayout extends AbstractConfirmationW removeAssignedSoftwareModules(); } - softwareModuleManagement.deleteSoftwareModules(swmoduleIds); + softwareModuleManagement.delete(swmoduleIds); eventBus.publish(this, new SoftwareModuleEvent(BaseEntityEventType.REMOVE_ENTITY, swmoduleIds)); addToConsolitatedMsg(FontAwesome.TRASH_O.getHtml() + SPUILabelDefinitions.HTML_SPACE @@ -292,8 +292,8 @@ public class DistributionsConfirmationWindowLayout extends AbstractConfirmationW final int deleteSWModuleTypeCount = manageDistUIState.getSelectedDeleteSWModuleTypes().size(); for (final String swModuleTypeName : manageDistUIState.getSelectedDeleteSWModuleTypes()) { - softwareModuleTypeManagement.findSoftwareModuleTypeByName(swModuleTypeName).map(SoftwareModuleType::getId) - .ifPresent(softwareModuleTypeManagement::deleteSoftwareModuleType); + softwareModuleTypeManagement.getByName(swModuleTypeName).map(SoftwareModuleType::getId) + .ifPresent(softwareModuleTypeManagement::delete); } addToConsolitatedMsg(FontAwesome.TASKS.getHtml() + SPUILabelDefinitions.HTML_SPACE + i18n.getMessage("message.sw.module.type.delete", new Object[] { deleteSWModuleTypeCount })); @@ -383,7 +383,7 @@ public class DistributionsConfirmationWindowLayout extends AbstractConfirmationW }); } - distributionSetManagement.deleteDistributionSet(Arrays.asList(deletedIds)); + distributionSetManagement.delete(Arrays.asList(deletedIds)); eventBus.publish(this, new DistributionTableEvent(BaseEntityEventType.REMOVE_ENTITY, Arrays.asList(deletedIds))); @@ -474,8 +474,8 @@ public class DistributionsConfirmationWindowLayout extends AbstractConfirmationW final int deleteDistTypeCount = manageDistUIState.getSelectedDeleteDistSetTypes().size(); manageDistUIState.getSelectedDeleteDistSetTypes().stream() .map(deleteDistTypeName -> distributionSetTypeManagement - .findDistributionSetTypeByName(deleteDistTypeName).get().getId()) - .forEach(distributionSetTypeManagement::deleteDistributionSetType); + .getByName(deleteDistTypeName).get().getId()) + .forEach(distributionSetTypeManagement::delete); addToConsolitatedMsg(FontAwesome.TASKS.getHtml() + SPUILabelDefinitions.HTML_SPACE + i18n.getMessage("message.dist.type.delete", new Object[] { deleteDistTypeCount })); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwMetadataPopupLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwMetadataPopupLayout.java index 2719c4fd1..de806a493 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwMetadataPopupLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwMetadataPopupLayout.java @@ -37,8 +37,8 @@ public class SwMetadataPopupLayout extends AbstractMetadataPopupLayout getMetadataList() { - return Collections.unmodifiableList(softwareModuleManagement.findSoftwareModuleMetadataBySoftwareModuleId( - new PageRequest(0, MAX_METADATA_QUERY), getSelectedEntity().getId()).getContent()); + return Collections.unmodifiableList(softwareModuleManagement + .findMetaDataBySoftwareModuleId(new PageRequest(0, MAX_METADATA_QUERY), getSelectedEntity().getId()).getContent()); } /** @@ -83,7 +83,7 @@ public class SwMetadataPopupLayout extends AbstractMetadataPopupLayout @Override protected List loadBeans(final int startIndex, final int count) { return getSoftwareModuleManagement() - .findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc( + .findAllOrderBySetAssignmentAndModuleNameAscModuleVersionAsc( new OffsetBasedPageRequest(startIndex, count), orderByDistId, searchText, type) .getContent().stream().map(SwModuleBeanQuery::getProxyBean).collect(Collectors.toList()); } @@ -110,9 +110,9 @@ public class SwModuleBeanQuery extends AbstractBeanQuery public int size() { long size; if (type == null && StringUtils.isEmpty(searchText)) { - size = getSoftwareModuleManagement().countSoftwareModulesAll(); + size = getSoftwareModuleManagement().count(); } else { - size = getSoftwareModuleManagement().countSoftwareModuleByFilters(searchText, type); + size = getSoftwareModuleManagement().countByTextAndType(searchText, type); } if (size > Integer.MAX_VALUE) { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleTable.java index 2efa2ca7b..10a8c34a9 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleTable.java @@ -255,7 +255,7 @@ public class SwModuleTable extends AbstractNamedVersionTable { @Override protected Optional findEntityByTableValue(final Long lastSelectedId) { - return softwareModuleManagement.findSoftwareModuleById(lastSelectedId); + return softwareModuleManagement.get(lastSelectedId); } @Override @@ -417,7 +417,7 @@ public class SwModuleTable extends AbstractNamedVersionTable { } private void showMetadataDetails(final Long itemId) { - softwareModuleManagement.findSoftwareModuleById(itemId) + softwareModuleManagement.get(itemId) .ifPresent(swmodule -> UI.getCurrent().addWindow(swMetadataPopupLayout.getWindow(swmodule, null))); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtype/DistSMTypeFilterButtonClick.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtype/DistSMTypeFilterButtonClick.java index 18203d1da..ce47cd735 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtype/DistSMTypeFilterButtonClick.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtype/DistSMTypeFilterButtonClick.java @@ -45,7 +45,7 @@ public class DistSMTypeFilterButtonClick extends AbstractFilterSingleButtonClick @Override protected void filterClicked(final Button clickedButton) { - softwareModuleTypeManagement.findSoftwareModuleTypeByName(clickedButton.getData().toString()) + softwareModuleTypeManagement.getByName(clickedButton.getData().toString()) .ifPresent(smType -> { manageDistUIState.getSoftwareModuleFilters().setSoftwareModuleType(smType); eventBus.publish(this, new RefreshSoftwareModuleByFilterEvent()); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtype/DistSMTypeFilterHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtype/DistSMTypeFilterHeader.java index 199f4de63..408d7cb4f 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtype/DistSMTypeFilterHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtype/DistSMTypeFilterHeader.java @@ -10,7 +10,6 @@ package org.eclipse.hawkbit.ui.distributions.smtype; import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.SoftwareModuleTypeManagement; -import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.ui.SpPermissionChecker; import org.eclipse.hawkbit.ui.artifacts.smtype.CreateUpdateSoftwareTypeLayout; import org.eclipse.hawkbit.ui.common.filterlayout.AbstractFilterHeader; @@ -37,13 +36,12 @@ public class DistSMTypeFilterHeader extends AbstractFilterHeader { private final CreateUpdateSoftwareTypeLayout createUpdateSWTypeLayout; DistSMTypeFilterHeader(final VaadinMessageSource i18n, final SpPermissionChecker permChecker, - final UIEventBus eventBus, final ManageDistUIState manageDistUIState, final TagManagement tagManagement, - final EntityFactory entityFactory, final UINotification uiNotification, - final SoftwareModuleTypeManagement softwareModuleTypeManagement) { + final UIEventBus eventBus, final ManageDistUIState manageDistUIState, final EntityFactory entityFactory, + final UINotification uiNotification, final SoftwareModuleTypeManagement softwareModuleTypeManagement) { super(permChecker, eventBus, i18n); this.manageDistUIState = manageDistUIState; - this.createUpdateSWTypeLayout = new CreateUpdateSoftwareTypeLayout(i18n, tagManagement, entityFactory, eventBus, - permChecker, uiNotification, softwareModuleTypeManagement); + this.createUpdateSWTypeLayout = new CreateUpdateSoftwareTypeLayout(i18n, entityFactory, eventBus, permChecker, + uiNotification, softwareModuleTypeManagement); if (hasCreateUpdatePermission()) { createUpdateSWTypeLayout.init(); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtype/DistSMTypeFilterLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtype/DistSMTypeFilterLayout.java index a422ae72c..e5d24c7dd 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtype/DistSMTypeFilterLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtype/DistSMTypeFilterLayout.java @@ -10,7 +10,6 @@ package org.eclipse.hawkbit.ui.distributions.smtype; import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.SoftwareModuleTypeManagement; -import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.ui.SpPermissionChecker; import org.eclipse.hawkbit.ui.common.filterlayout.AbstractFilterLayout; import org.eclipse.hawkbit.ui.dd.criteria.DistributionsViewClientCriterion; @@ -33,11 +32,11 @@ public class DistSMTypeFilterLayout extends AbstractFilterLayout { public DistSMTypeFilterLayout(final UIEventBus eventBus, final VaadinMessageSource i18n, final SpPermissionChecker permChecker, final ManageDistUIState manageDistUIState, - final TagManagement tagManagement, final EntityFactory entityFactory, final UINotification uiNotification, + final EntityFactory entityFactory, final UINotification uiNotification, final SoftwareModuleTypeManagement softwareModuleTypeManagement, final DistributionsViewClientCriterion distributionsViewClientCriterion) { - super(new DistSMTypeFilterHeader(i18n, permChecker, eventBus, manageDistUIState, tagManagement, entityFactory, - uiNotification, softwareModuleTypeManagement), + super(new DistSMTypeFilterHeader(i18n, permChecker, eventBus, manageDistUIState, entityFactory, uiNotification, + softwareModuleTypeManagement), new DistSMTypeFilterButtons(eventBus, manageDistUIState, distributionsViewClientCriterion, softwareModuleTypeManagement)); this.manageDistUIState = manageDistUIState; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterHeader.java index ae9d3dbd6..6a88f3156 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterHeader.java @@ -368,7 +368,7 @@ public class CreateOrUpdateFilterHeader extends VerticalLayout implements Button } private void createTargetFilterQuery() { - final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement.createTargetFilterQuery(entityFactory + final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement.create(entityFactory .targetFilterQuery().create().name(nameTextField.getValue()).query(queryTextField.getValue())); notification.displaySuccess( i18n.getMessage("message.create.filter.success", new Object[] { targetFilterQuery.getName() })); @@ -382,7 +382,7 @@ public class CreateOrUpdateFilterHeader extends VerticalLayout implements Button } final TargetFilterQuery targetFilterQuery = tfQuery.get(); final TargetFilterQuery updatedTargetFilter = targetFilterQueryManagement - .updateTargetFilterQuery(entityFactory.targetFilterQuery().update(targetFilterQuery.getId()) + .update(entityFactory.targetFilterQuery().update(targetFilterQuery.getId()) .name(nameTextField.getValue()).query(queryTextField.getValue())); filterManagementUIState.setTfQuery(updatedTargetFilter); oldFilterName = nameTextField.getValue(); @@ -400,7 +400,7 @@ public class CreateOrUpdateFilterHeader extends VerticalLayout implements Button } private boolean doesAlreadyExists() { - if (targetFilterQueryManagement.findTargetFilterQueryByName(nameTextField.getValue()).isPresent()) { + if (targetFilterQueryManagement.getByName(nameTextField.getValue()).isPresent()) { notification.displayValidationError( i18n.getMessage("message.target.filter.duplicate", nameTextField.getValue())); return true; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CustomTargetBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CustomTargetBeanQuery.java index c5972ef14..a2126979f 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CustomTargetBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CustomTargetBeanQuery.java @@ -89,10 +89,10 @@ public class CustomTargetBeanQuery extends AbstractBeanQuery { Slice targetBeans; final List proxyTargetBeans = new ArrayList<>(); if (!StringUtils.isEmpty(filterQuery)) { - targetBeans = targetManagement.findTargetsAll(filterQuery, - new PageRequest(startIndex / SPUIDefinitions.PAGE_SIZE, SPUIDefinitions.PAGE_SIZE, sort)); + targetBeans = targetManagement.findByRsql(new PageRequest(startIndex / SPUIDefinitions.PAGE_SIZE, SPUIDefinitions.PAGE_SIZE, sort), + filterQuery); } else { - targetBeans = targetManagement.findTargetsAll( + targetBeans = targetManagement.findAll( new PageRequest(startIndex / SPUIDefinitions.PAGE_SIZE, SPUIDefinitions.PAGE_SIZE, sort)); } @@ -129,7 +129,7 @@ public class CustomTargetBeanQuery extends AbstractBeanQuery { public int size() { long size = 0; if (!StringUtils.isEmpty(filterQuery)) { - size = getTargetManagement().countTargetByTargetFilterQuery(filterQuery); + size = getTargetManagement().countByRsql(filterQuery); } getFilterManagementUIState().setTargetsCountAll(size); if (size > SPUIDefinitions.MAX_TABLE_ENTRIES) { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/DistributionSetSelectWindow.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/DistributionSetSelectWindow.java index 9fd4ac81e..4734d0463 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/DistributionSetSelectWindow.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/DistributionSetSelectWindow.java @@ -105,7 +105,7 @@ public class DistributionSetSelectWindow */ public void showForTargetFilter(final Long tfqId) { this.tfqId = tfqId; - final TargetFilterQuery tfq = targetFilterQueryManagement.findTargetFilterQueryById(tfqId) + final TargetFilterQuery tfq = targetFilterQueryManagement.get(tfqId) .orElseThrow(() -> new EntityNotFoundException(TargetFilterQuery.class, tfqId)); initLocal(); @@ -164,13 +164,13 @@ public class DistributionSetSelectWindow } private void updateTargetFilterQueryDS(final Long targetFilterQueryId, final Long dsId) { - final TargetFilterQuery tfq = targetFilterQueryManagement.findTargetFilterQueryById(targetFilterQueryId) + final TargetFilterQuery tfq = targetFilterQueryManagement.get(targetFilterQueryId) .orElseThrow(() -> new EntityNotFoundException(TargetFilterQuery.class, targetFilterQueryId)); if (dsId != null) { confirmWithConsequencesDialog(tfq, dsId); } else { - targetFilterQueryManagement.updateTargetFilterQueryAutoAssignDS(targetFilterQueryId, null); + targetFilterQueryManagement.updateAutoAssignDS(targetFilterQueryId, null); eventBus.publish(this, CustomFilterUIEvent.UPDATED_TARGET_FILTER_QUERY); } @@ -182,7 +182,7 @@ public class DistributionSetSelectWindow @Override public void onConfirmResult(final boolean accepted) { if (accepted) { - targetFilterQueryManagement.updateTargetFilterQueryAutoAssignDS(tfq.getId(), dsId); + targetFilterQueryManagement.updateAutoAssignDS(tfq.getId(), dsId); eventBus.publish(this, CustomFilterUIEvent.UPDATED_TARGET_FILTER_QUERY); } } @@ -232,7 +232,7 @@ public class DistributionSetSelectWindow layout.setMargin(true); setContent(layout); - final Long targetsCount = targetManagement.countTargetsByTargetFilterQueryAndNonDS(distributionSetId, + final Long targetsCount = targetManagement.countByRsqlAndNonDS(distributionSetId, targetFilterQuery.getQuery()); Label mainTextLabel; if (targetsCount == 0) { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/TargetFilterBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/TargetFilterBeanQuery.java index 8fcb87eb4..caa3b0cc8 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/TargetFilterBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/TargetFilterBeanQuery.java @@ -84,10 +84,10 @@ public class TargetFilterBeanQuery extends AbstractBeanQuery targetFilterQuery = firstPageTargetFilter; } else if (StringUtils.isEmpty(searchText)) { // if no search filters available - targetFilterQuery = getTargetFilterQueryManagement().findAllTargetFilterQuery( + targetFilterQuery = getTargetFilterQueryManagement().findAll( new PageRequest(startIndex / SPUIDefinitions.PAGE_SIZE, SPUIDefinitions.PAGE_SIZE, sort)); } else { - targetFilterQuery = getTargetFilterQueryManagement().findTargetFilterQueryByName( + targetFilterQuery = getTargetFilterQueryManagement().findByName( new PageRequest(startIndex / SPUIDefinitions.PAGE_SIZE, SPUIDefinitions.PAGE_SIZE, sort), searchText); } @@ -121,10 +121,10 @@ public class TargetFilterBeanQuery extends AbstractBeanQuery public int size() { if (StringUtils.isEmpty(searchText)) { firstPageTargetFilter = getTargetFilterQueryManagement() - .findAllTargetFilterQuery(new PageRequest(0, SPUIDefinitions.PAGE_SIZE, sort)); + .findAll(new PageRequest(0, SPUIDefinitions.PAGE_SIZE, sort)); } else { firstPageTargetFilter = getTargetFilterQueryManagement() - .findTargetFilterQueryByName(new PageRequest(0, SPUIDefinitions.PAGE_SIZE, sort), searchText); + .findByName(new PageRequest(0, SPUIDefinitions.PAGE_SIZE, sort), searchText); } final long size = firstPageTargetFilter.getTotalElements(); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/TargetFilterTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/TargetFilterTable.java index 10a5921ae..de8c813e2 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/TargetFilterTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/TargetFilterTable.java @@ -179,9 +179,9 @@ public class TargetFilterTable extends Table { i18n.getMessage("message.delete.filter.confirm"), i18n.getMessage("button.ok"), i18n.getMessage("button.cancel"), ok -> { if (ok) { final Long rowId = (Long) ((Button) event.getComponent()).getData(); - final String deletedFilterName = targetFilterQueryManagement.findTargetFilterQueryById(rowId) + final String deletedFilterName = targetFilterQueryManagement.get(rowId) .get().getName(); - targetFilterQueryManagement.deleteTargetFilterQuery(rowId); + targetFilterQueryManagement.delete(rowId); /* * Refresh the custom filter table to show latest change @@ -252,7 +252,7 @@ public class TargetFilterTable extends Table { private void onClickOfDetailButton(final ClickEvent event) { final String targetFilterName = (String) ((Button) event.getComponent()).getData(); - targetFilterQueryManagement.findTargetFilterQueryByName(targetFilterName).ifPresent(targetFilterQuery -> { + targetFilterQueryManagement.getByName(targetFilterName).ifPresent(targetFilterQuery -> { filterManagementUIState.setFilterQueryValue(targetFilterQuery.getQuery()); filterManagementUIState.setTfQuery(targetFilterQuery); filterManagementUIState.setEditViewDisplayed(true); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/layouts/AbstractCreateUpdateTagLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/layouts/AbstractCreateUpdateTagLayout.java index cdb5f2bca..3df443e3b 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/layouts/AbstractCreateUpdateTagLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/layouts/AbstractCreateUpdateTagLayout.java @@ -8,16 +8,10 @@ */ package org.eclipse.hawkbit.ui.layouts; -import java.util.Objects; import java.util.Optional; import org.eclipse.hawkbit.repository.EntityFactory; -import org.eclipse.hawkbit.repository.TagManagement; -import org.eclipse.hawkbit.repository.builder.TagUpdate; -import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.NamedEntity; -import org.eclipse.hawkbit.repository.model.Tag; -import org.eclipse.hawkbit.repository.model.TargetTag; import org.eclipse.hawkbit.ui.SpPermissionChecker; import org.eclipse.hawkbit.ui.colorpicker.ColorPickerConstants; import org.eclipse.hawkbit.ui.colorpicker.ColorPickerHelper; @@ -28,10 +22,7 @@ import org.eclipse.hawkbit.ui.common.builder.LabelBuilder; import org.eclipse.hawkbit.ui.common.builder.TextAreaBuilder; import org.eclipse.hawkbit.ui.common.builder.TextFieldBuilder; import org.eclipse.hawkbit.ui.common.builder.WindowBuilder; -import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; -import org.eclipse.hawkbit.ui.management.event.DistributionSetTagTableEvent; -import org.eclipse.hawkbit.ui.management.event.TargetTagTableEvent; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider; @@ -80,8 +71,6 @@ public abstract class AbstractCreateUpdateTagLayout exten protected VaadinMessageSource i18n; - protected transient TagManagement tagManagement; - protected transient EntityFactory entityFactory; protected transient EventBus.UIEventBus eventBus; @@ -131,11 +120,9 @@ public abstract class AbstractCreateUpdateTagLayout exten * @param uiNotification * UINotification */ - public AbstractCreateUpdateTagLayout(final VaadinMessageSource i18n, final TagManagement tagManagement, - final EntityFactory entityFactory, final UIEventBus eventBus, final SpPermissionChecker permChecker, - final UINotification uiNotification) { + public AbstractCreateUpdateTagLayout(final VaadinMessageSource i18n, final EntityFactory entityFactory, + final UIEventBus eventBus, final SpPermissionChecker permChecker, final UINotification uiNotification) { this.i18n = i18n; - this.tagManagement = tagManagement; this.entityFactory = entityFactory; this.eventBus = eventBus; this.permChecker = permChecker; @@ -295,22 +282,7 @@ public abstract class AbstractCreateUpdateTagLayout exten colorPickerLayout.setVisible(tagPreviewBtnClicked); } - /** - * @return the color which should be selected in the color-picker component. - */ - protected Color getColorForColorPicker() { - final Optional targetTagSelected = tagManagement - .findTargetTag(tagNameComboBox.getValue().toString()); - if (targetTagSelected.isPresent()) { - return ColorPickerHelper.rgbToColorConverter(targetTagSelected.map(TargetTag::getColour) - .filter(Objects::nonNull).orElse(ColorPickerConstants.DEFAULT_COLOR)); - } - - return ColorPickerHelper.rgbToColorConverter(tagManagement - .findDistributionSetTag(tagNameComboBox.getValue().toString()).map(DistributionSetTag::getColour) - .filter(Objects::nonNull).orElse(ColorPickerConstants.DEFAULT_COLOR)); - - } + protected abstract Color getColorForColorPicker(); private void tagNameChosen(final ValueChangeEvent event) { final String tagSelected = (String) event.getProperty().getValue(); @@ -573,25 +545,6 @@ public abstract class AbstractCreateUpdateTagLayout exten tagDescValue = HawkbitCommonUtil.trimAndNullIfEmpty(tagDesc.getValue()); } - /** - * update tag. - */ - protected void updateExistingTag(final Tag targetObj) { - final TagUpdate update = entityFactory.tag().update(targetObj.getId()).name(tagName.getValue()) - .description(tagDesc.getValue()) - .colour(ColorPickerHelper.getColorPickedString(colorPickerLayout.getSelPreview())); - if (targetObj instanceof TargetTag) { - tagManagement.updateTargetTag(update); - eventBus.publish(this, new TargetTagTableEvent(BaseEntityEventType.UPDATED_ENTITY, (TargetTag) targetObj)); - } else if (targetObj instanceof DistributionSetTag) { - tagManagement.updateDistributionSetTag(update); - eventBus.publish(this, new DistributionSetTagTableEvent(BaseEntityEventType.UPDATED_ENTITY, - (DistributionSetTag) targetObj)); - } - uiNotification.displaySuccess(i18n.getMessage("message.update.success", new Object[] { targetObj.getName() })); - - } - protected void displaySuccess(final String tagName) { uiNotification.displaySuccess(i18n.getMessage("message.save.success", new Object[] { tagName })); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/layouts/CreateUpdateTypeLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/layouts/CreateUpdateTypeLayout.java index 39a07ede2..64c65d364 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/layouts/CreateUpdateTypeLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/layouts/CreateUpdateTypeLayout.java @@ -11,7 +11,6 @@ package org.eclipse.hawkbit.ui.layouts; import java.util.Optional; import org.eclipse.hawkbit.repository.EntityFactory; -import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.model.NamedEntity; import org.eclipse.hawkbit.ui.SpPermissionChecker; import org.eclipse.hawkbit.ui.colorpicker.ColorPickerConstants; @@ -47,9 +46,9 @@ public abstract class CreateUpdateTypeLayout extends Abst private static final String TYPE_NAME_DYNAMIC_STYLE = "new-tag-name"; private static final String TYPE_DESC_DYNAMIC_STYLE = "new-tag-desc"; - public CreateUpdateTypeLayout(final VaadinMessageSource i18n, final TagManagement tagManagement, final EntityFactory entityFactory, + public CreateUpdateTypeLayout(final VaadinMessageSource i18n, final EntityFactory entityFactory, final UIEventBus eventBus, final SpPermissionChecker permChecker, final UINotification uiNotification) { - super(i18n, tagManagement, entityFactory, eventBus, permChecker, uiNotification); + super(i18n, entityFactory, eventBus, permChecker, uiNotification); } @Override @@ -67,8 +66,8 @@ public abstract class CreateUpdateTypeLayout extends Abst colorLabel = new LabelBuilder().name(i18n.getMessage("label.choose.type.color")).buildLabel(); colorLabel.addStyleName(SPUIDefinitions.COLOR_LABEL_STYLE); - tagNameComboBox = SPUIComponentProvider.getComboBox(i18n.getMessage("label.combobox.type"), "", null, null, false, "", - i18n.getMessage("label.combobox.type")); + tagNameComboBox = SPUIComponentProvider.getComboBox(i18n.getMessage("label.combobox.type"), "", null, null, + false, "", i18n.getMessage("label.combobox.type")); tagNameComboBox.setId(SPUIDefinitions.NEW_DISTRIBUTION_SET_TYPE_NAME_COMBO); tagNameComboBox.addStyleName(SPUIDefinitions.FILTER_TYPE_COMBO_STYLE); tagNameComboBox.setImmediate(true); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/DeploymentView.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/DeploymentView.java index 8ffabb288..82de22d3b 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/DeploymentView.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/DeploymentView.java @@ -15,12 +15,13 @@ import javax.annotation.PostConstruct; import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.DistributionSetManagement; +import org.eclipse.hawkbit.repository.DistributionSetTagManagement; import org.eclipse.hawkbit.repository.DistributionSetTypeManagement; import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.SystemManagement; -import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.TargetFilterQueryManagement; import org.eclipse.hawkbit.repository.TargetManagement; +import org.eclipse.hawkbit.repository.TargetTagManagement; import org.eclipse.hawkbit.ui.HawkbitUI; import org.eclipse.hawkbit.ui.SpPermissionChecker; import org.eclipse.hawkbit.ui.UiProperties; @@ -124,7 +125,9 @@ public class DeploymentView extends AbstractNotificationView implements BrowserW final DistributionSetManagement distributionSetManagement, final DistributionSetTypeManagement distributionSetTypeManagement, final TargetManagement targetManagement, final EntityFactory entityFactory, final UiProperties uiproperties, - final ManagementViewClientCriterion managementViewClientCriterion, final TagManagement tagManagement, + final ManagementViewClientCriterion managementViewClientCriterion, + final TargetTagManagement targetTagManagement, + final DistributionSetTagManagement distributionSetTagManagement, final TargetFilterQueryManagement targetFilterQueryManagement, final SystemManagement systemManagement, final NotificationUnreadButton notificationUnreadButton, final DeploymentViewMenuItem deploymentViewMenuItem, @Qualifier("uiExecutor") final Executor uiExecutor) { @@ -138,27 +141,28 @@ public class DeploymentView extends AbstractNotificationView implements BrowserW this.actionStatusLayout = new ActionStatusLayout(i18n, eventBus, managementUIState); this.actionStatusMsgLayout = new ActionStatusMsgLayout(i18n, eventBus, managementUIState); final CreateUpdateTargetTagLayoutWindow createUpdateTargetTagLayout = new CreateUpdateTargetTagLayoutWindow( - i18n, tagManagement, entityFactory, eventBus, permChecker, uiNotification); + i18n, targetTagManagement, entityFactory, eventBus, permChecker, uiNotification); this.targetTagFilterLayout = new TargetTagFilterLayout(i18n, createUpdateTargetTagLayout, managementUIState, managementViewClientCriterion, permChecker, eventBus, uiNotification, entityFactory, targetFilterQueryManagement); final TargetTable targetTable = new TargetTable(eventBus, i18n, uiNotification, targetManagement, managementUIState, permChecker, managementViewClientCriterion, distributionSetManagement, - tagManagement); + targetTagManagement); this.targetTableLayout = new TargetTableLayout(eventbus, targetTable, targetManagement, entityFactory, i18n, eventBus, uiNotification, managementUIState, managementViewClientCriterion, deploymentManagement, - uiproperties, permChecker, uiNotification, tagManagement, distributionSetManagement, uiExecutor); + uiproperties, permChecker, uiNotification, targetTagManagement, distributionSetManagement, uiExecutor); this.distributionTagLayout = new DistributionTagLayout(eventbus, managementUIState, i18n, permChecker, eventBus, - tagManagement, entityFactory, uiNotification, distFilterParameters, distributionSetManagement, - managementViewClientCriterion); + distributionSetTagManagement, entityFactory, uiNotification, distFilterParameters, + distributionSetManagement, managementViewClientCriterion); this.distributionTableLayout = new DistributionTableLayout(i18n, eventBus, permChecker, managementUIState, distributionSetManagement, distributionSetTypeManagement, managementViewClientCriterion, entityFactory, - uiNotification, tagManagement, systemManagement, targetManagement, deploymentManagement); + uiNotification, distributionSetTagManagement, targetTagManagement, systemManagement, targetManagement, + deploymentManagement); this.deleteAndActionsLayout = new DeleteActionsLayout(i18n, permChecker, eventBus, uiNotification, - tagManagement, managementViewClientCriterion, managementUIState, targetManagement, targetTable, - deploymentManagement, distributionSetManagement); + targetTagManagement, distributionSetTagManagement, managementViewClientCriterion, managementUIState, + targetManagement, targetTable, deploymentManagement, distributionSetManagement); this.deploymentViewMenuItem = deploymentViewMenuItem; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionAddUpdateWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionAddUpdateWindowLayout.java index 7eab01a23..8d2ea9ff8 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionAddUpdateWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionAddUpdateWindowLayout.java @@ -141,8 +141,8 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent { final boolean isMigStepReq = reqMigStepCheckbox.getValue(); final Long distSetTypeId = (Long) distsetTypeNameComboBox.getValue(); - distributionSetTypeManagement.findDistributionSetTypeById(distSetTypeId).ifPresent(type -> { - final DistributionSet currentDS = distributionSetManagement.updateDistributionSet( + distributionSetTypeManagement.get(distSetTypeId).ifPresent(type -> { + final DistributionSet currentDS = distributionSetManagement.update( entityFactory.distributionSet().update(editDistId).name(distNameTextField.getValue()) .description(descTextArea.getValue()).version(distVersionTextField.getValue()) .requiredMigrationStep(isMigStepReq).type(type)); @@ -166,10 +166,10 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent { final boolean isMigStepReq = reqMigStepCheckbox.getValue(); final DistributionSetType distributionSetType = distributionSetTypeManagement - .findDistributionSetTypeById(distSetTypeId) + .get(distSetTypeId) .orElseThrow(() -> new EntityNotFoundException(DistributionSetType.class, distSetTypeId)); final DistributionSet newDist = distributionSetManagement - .createDistributionSet(entityFactory.distributionSet().create().name(name).version(version) + .create(entityFactory.distributionSet().create().name(name).version(version) .description(desc).type(distributionSetType).requiredMigrationStep(isMigStepReq)); eventBus.publish(this, new DistributionTableEvent(BaseEntityEventType.ADD_ENTITY, newDist)); @@ -183,7 +183,7 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent { final String version = distVersionTextField.getValue(); final Optional existingDs = distributionSetManagement - .findDistributionSetByNameAndVersion(name, version); + .getByNameAndVersion(name, version); /* * Distribution should not exists with the same name & version. * Display error message, when the "existingDs" is not null and it @@ -297,7 +297,7 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent { } final Optional distSet = distributionSetManagement - .findDistributionSetByIdWithDetails(editDistId); + .getWithDetails(editDistId); if (!distSet.isPresent()) { return; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionBeanQuery.java index a5486f49a..aa3a3bf2f 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionBeanQuery.java @@ -75,7 +75,7 @@ public class DistributionBeanQuery extends AbstractBeanQuery } } - if (sortStates!= null && sortStates.length > 0) { + if (sortStates != null && sortStates.length > 0) { // Initalize sort sort = new Sort(sortStates[0] ? Direction.ASC : Direction.DESC, (String) sortPropertyIds[0]); // Add sort @@ -105,18 +105,18 @@ public class DistributionBeanQuery extends AbstractBeanQuery .setIsDeleted(false).setIsComplete(true).setSearchText(searchText) .setSelectDSWithNoTag(noTagClicked).setTagNames(distributionTags); - distBeans = getDistributionSetManagement().findDistributionSetsAllOrderedByLinkTarget( + distBeans = getDistributionSetManagement().findByFilterAndAssignedInstalledDsOrderedByLinkTarget( new OffsetBasedPageRequest(startIndex, count, sort), distributionSetFilterBuilder, pinnedTarget.getControllerId()); } else if (distributionTags.isEmpty() && StringUtils.isEmpty(searchText) && !noTagClicked) { // if no search filters available - distBeans = getDistributionSetManagement().findDistributionSetsByDeletedAndOrCompleted( - new OffsetBasedPageRequest(startIndex, count, sort), false, true); + distBeans = getDistributionSetManagement() + .findByCompleted(new OffsetBasedPageRequest(startIndex, count, sort), true); } else { final DistributionSetFilter distributionSetFilter = new DistributionSetFilterBuilder().setIsDeleted(false) .setIsComplete(true).setSearchText(searchText).setSelectDSWithNoTag(noTagClicked) .setTagNames(distributionTags).build(); - distBeans = getDistributionSetManagement().findDistributionSetsByFilters( + distBeans = getDistributionSetManagement().findByDistributionSetFilter( new OffsetBasedPageRequest(startIndex, count, sort), distributionSetFilter); } @@ -146,19 +146,20 @@ public class DistributionBeanQuery extends AbstractBeanQuery .setIsDeleted(false).setIsComplete(true).setSearchText(searchText) .setSelectDSWithNoTag(noTagClicked).setTagNames(distributionTags); - firstPageDistributionSets = getDistributionSetManagement().findDistributionSetsAllOrderedByLinkTarget( - new PageRequest(0, SPUIDefinitions.PAGE_SIZE, sort), distributionSetFilterBuilder, - pinnedTarget.getControllerId()); + firstPageDistributionSets = getDistributionSetManagement() + .findByFilterAndAssignedInstalledDsOrderedByLinkTarget( + new PageRequest(0, SPUIDefinitions.PAGE_SIZE, sort), distributionSetFilterBuilder, + pinnedTarget.getControllerId()); } else if (distributionTags.isEmpty() && StringUtils.isEmpty(searchText) && !noTagClicked) { // if no search filters available - firstPageDistributionSets = getDistributionSetManagement().findDistributionSetsByDeletedAndOrCompleted( - new PageRequest(0, SPUIDefinitions.PAGE_SIZE, sort), false, true); + firstPageDistributionSets = getDistributionSetManagement() + .findByCompleted(new PageRequest(0, SPUIDefinitions.PAGE_SIZE, sort), true); } else { final DistributionSetFilter distributionSetFilter = new DistributionSetFilterBuilder().setIsDeleted(false) .setIsComplete(true).setSearchText(searchText).setSelectDSWithNoTag(noTagClicked) .setTagNames(distributionTags).build(); - firstPageDistributionSets = getDistributionSetManagement().findDistributionSetsByFilters( + firstPageDistributionSets = getDistributionSetManagement().findByDistributionSetFilter( new PageRequest(0, SPUIDefinitions.PAGE_SIZE, sort), distributionSetFilter); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionDetails.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionDetails.java index 06b1b3e64..21aed433c 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionDetails.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionDetails.java @@ -9,8 +9,8 @@ package org.eclipse.hawkbit.ui.management.dstable; import org.eclipse.hawkbit.repository.DistributionSetManagement; +import org.eclipse.hawkbit.repository.DistributionSetTagManagement; import org.eclipse.hawkbit.repository.EntityFactory; -import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.ui.SpPermissionChecker; import org.eclipse.hawkbit.ui.common.detailslayout.AbstractDistributionSetDetails; import org.eclipse.hawkbit.ui.common.detailslayout.SoftwareModuleDetailsTable; @@ -31,10 +31,11 @@ public class DistributionDetails extends AbstractDistributionSetDetails { final SpPermissionChecker permissionChecker, final ManagementUIState managementUIState, final DistributionSetManagement distributionSetManagement, final DsMetadataPopupLayout dsMetadataPopupLayout, final EntityFactory entityFactory, - final UINotification uiNotification, final TagManagement tagManagement, + final UINotification uiNotification, final DistributionSetTagManagement distributionSetTagManagement, final DistributionAddUpdateWindowLayout distributionAddUpdateWindowLayout) { super(i18n, eventBus, permissionChecker, managementUIState, distributionAddUpdateWindowLayout, - distributionSetManagement, dsMetadataPopupLayout, entityFactory, uiNotification, tagManagement, + distributionSetManagement, dsMetadataPopupLayout, entityFactory, uiNotification, + distributionSetTagManagement, createSoftwareModuleDetailsTable(i18n, permissionChecker, uiNotification)); restoreState(); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java index 7a984c221..90e204f4e 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java @@ -20,8 +20,8 @@ import java.util.stream.Collectors; import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.DistributionSetManagement; -import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.TargetManagement; +import org.eclipse.hawkbit.repository.TargetTagManagement; import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetUpdatedEvent; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult; @@ -89,7 +89,7 @@ public class DistributionTable extends AbstractNamedVersionTable findEntityByTableValue(final Long lastSelectedId) { - return distributionSetManagement.findDistributionSetByIdWithDetails(lastSelectedId); + return distributionSetManagement.getWithDetails(lastSelectedId); } @Override @@ -394,12 +394,12 @@ public class DistributionTable extends AbstractNamedVersionTable { + targetTagManagement.getByName(targetTagName).ifPresent(tag -> { Pageable query = new PageRequest(0, 500); Page assignedTargets; boolean assigned = false; do { - assignedTargets = targetManagement.findTargetsByTag(query, tag.getId()); + assignedTargets = targetManagement.findByTag(query, tag.getId()); if (assignedTargets.hasContent()) { assignTargetToDs(getItem(distItemId), assignedTargets.getContent()); @@ -422,7 +422,7 @@ public class DistributionTable extends AbstractNamedVersionTable findDistributionSetById = distributionSetManagement - .findDistributionSetById(distId); + final Optional findDistributionSetById = distributionSetManagement.get(distId); if (!findDistributionSetById.isPresent()) { notification.displayWarning(i18n.getMessage("distributionset.not.exists")); return; @@ -721,7 +720,7 @@ public class DistributionTable extends AbstractNamedVersionTable ds = distributionSetManagement.findDistributionSetById((Long) itemId); + final Optional ds = distributionSetManagement.get((Long) itemId); if (!ds.isPresent()) { notification.displayWarning(i18n.getMessage("distributionset.not.exists")); return; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTableLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTableLayout.java index 36d96585b..9eb598234 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTableLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTableLayout.java @@ -10,11 +10,12 @@ package org.eclipse.hawkbit.ui.management.dstable; import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.DistributionSetManagement; +import org.eclipse.hawkbit.repository.DistributionSetTagManagement; import org.eclipse.hawkbit.repository.DistributionSetTypeManagement; import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.SystemManagement; -import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.TargetManagement; +import org.eclipse.hawkbit.repository.TargetTagManagement; import org.eclipse.hawkbit.ui.SpPermissionChecker; import org.eclipse.hawkbit.ui.common.table.AbstractTableLayout; import org.eclipse.hawkbit.ui.dd.criteria.ManagementViewClientCriterion; @@ -38,9 +39,9 @@ public class DistributionTableLayout extends AbstractTableLayout implements RefreshableContainer { - private static final long serialVersionUID = 444276149954167545L; + private static final long serialVersionUID = 1L; private static final String TARGET_TAG_NAME_DYNAMIC_STYLE = "new-target-tag-name"; private static final String MSG_TEXTFIELD_NAME = "textfield.name"; - CreateUpdateDistributionTagLayoutWindow(final VaadinMessageSource i18n, final TagManagement tagManagement, - final EntityFactory entityFactory, final UIEventBus eventBus, final SpPermissionChecker permChecker, - final UINotification uiNotification) { - super(i18n, tagManagement, entityFactory, eventBus, permChecker, uiNotification); + private final transient DistributionSetTagManagement distributionSetTagManagement; + + CreateUpdateDistributionTagLayoutWindow(final VaadinMessageSource i18n, + final DistributionSetTagManagement distributionSetTagManagement, final EntityFactory entityFactory, + final UIEventBus eventBus, final SpPermissionChecker permChecker, final UINotification uiNotification) { + super(i18n, entityFactory, eventBus, permChecker, uiNotification); + this.distributionSetTagManagement = distributionSetTagManagement; + } + + /** + * @return the color which should be selected in the color-picker component. + */ + @Override + protected Color getColorForColorPicker() { + return ColorPickerHelper.rgbToColorConverter(distributionSetTagManagement + .getByName(tagNameComboBox.getValue().toString()).map(DistributionSetTag::getColour) + .filter(Objects::nonNull).orElse(ColorPickerConstants.DEFAULT_COLOR)); + + } + + /** + * update tag. + */ + protected void updateExistingTag(final Tag targetObj) { + final TagUpdate update = entityFactory.tag().update(targetObj.getId()).name(tagName.getValue()) + .description(tagDesc.getValue()); + + distributionSetTagManagement.update(update); + eventBus.publish(this, + new DistributionSetTagTableEvent(BaseEntityEventType.UPDATED_ENTITY, (DistributionSetTag) targetObj)); + uiNotification.displaySuccess(i18n.getMessage("message.update.success", new Object[] { targetObj.getName() })); + } @Override @@ -57,8 +89,8 @@ public class CreateUpdateDistributionTagLayoutWindow extends AbstractCreateUpdat } tagNameComboBox.removeAllItems(); - final List distTagNameList = tagManagement - .findAllDistributionSetTags(new PageRequest(0, MAX_TAGS)).getContent(); + final List distTagNameList = distributionSetTagManagement + .findAll(new PageRequest(0, MAX_TAGS)).getContent(); distTagNameList.forEach(value -> tagNameComboBox.addItem(value.getName())); } @@ -82,7 +114,7 @@ public class CreateUpdateDistributionTagLayoutWindow extends AbstractCreateUpdat @Override protected Optional findEntityByName() { - return tagManagement.findDistributionSetTag(tagName.getValue()); + return distributionSetTagManagement.getByName(tagName.getValue()); } /** @@ -100,8 +132,8 @@ public class CreateUpdateDistributionTagLayoutWindow extends AbstractCreateUpdat colour = getColorPicked(); } - final DistributionSetTag newDistTag = tagManagement.createDistributionSetTag(entityFactory.tag().create() - .name(tagNameValueTrimmed).description(tagDescriptionTrimmed).colour(colour)); + final DistributionSetTag newDistTag = distributionSetTagManagement.create(entityFactory + .tag().create().name(tagNameValueTrimmed).description(tagDescriptionTrimmed).colour(colour)); eventBus.publish(this, new DistributionSetTagTableEvent(BaseEntityEventType.ADD_ENTITY, newDistTag)); displaySuccess(newDistTag.getName()); resetDistTagValues(); @@ -143,7 +175,8 @@ public class CreateUpdateDistributionTagLayoutWindow extends AbstractCreateUpdat @Override public void setTagDetails(final String distTagSelected) { tagName.setValue(distTagSelected); - final Optional selectedDistTag = tagManagement.findDistributionSetTag(distTagSelected); + final Optional selectedDistTag = distributionSetTagManagement + .getByName(distTagSelected); if (selectedDistTag.isPresent()) { tagDesc.setValue(selectedDistTag.get().getDescription()); if (null == selectedDistTag.get().getColour()) { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagBeanQuery.java index 8be9548f7..edf3e032e 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagBeanQuery.java @@ -8,18 +8,17 @@ */ package org.eclipse.hawkbit.ui.management.dstag; -import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; +import org.eclipse.hawkbit.repository.DistributionSetTagManagement; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; -import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.ui.management.tag.ProxyTag; import org.eclipse.hawkbit.ui.management.tag.TagIdName; -import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SpringContextHelper; -import org.springframework.data.domain.Page; +import org.springframework.data.domain.Slice; import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort.Direction; import org.vaadin.addons.lazyquerycontainer.AbstractBeanQuery; @@ -33,8 +32,8 @@ public class DistributionTagBeanQuery extends AbstractBeanQuery { private static final long serialVersionUID = -4791426170440663033L; private final Sort sort = new Sort(Direction.ASC, "name"); - private transient Page firstPageDsTag = null; - private transient TagManagement tagManagementService; + + private transient DistributionSetTagManagement distributionSetTagManagement; /** * Parametric Constructor. @@ -56,33 +55,26 @@ public class DistributionTagBeanQuery extends AbstractBeanQuery { @Override public int size() { - firstPageDsTag = getTagManagement() - .findAllDistributionSetTags(new OffsetBasedPageRequest(0, SPUIDefinitions.PAGE_SIZE, sort)); - long size = firstPageDsTag.getTotalElements(); + long size = getTagManagement().count(); if (size > Integer.MAX_VALUE) { size = Integer.MAX_VALUE; } return (int) size; } - private TagManagement getTagManagement() { - if (tagManagementService == null) { - tagManagementService = SpringContextHelper.getBean(TagManagement.class); + private DistributionSetTagManagement getTagManagement() { + if (distributionSetTagManagement == null) { + distributionSetTagManagement = SpringContextHelper.getBean(DistributionSetTagManagement.class); } - return tagManagementService; + return distributionSetTagManagement; } @Override protected List loadBeans(final int startIndex, final int count) { - Page dsTagBeans; - final List tagList = new ArrayList<>(); - if (startIndex == 0 && firstPageDsTag != null) { - dsTagBeans = firstPageDsTag; - } else { - dsTagBeans = getTagManagement() - .findAllDistributionSetTags(new OffsetBasedPageRequest(startIndex, count, sort)); - } - for (final DistributionSetTag tag : dsTagBeans) { + final Slice dsTagBeans = getTagManagement() + .findAll(new OffsetBasedPageRequest(startIndex, count, sort)); + + return dsTagBeans.getContent().stream().map(tag -> { final ProxyTag proxyTargetTag = new ProxyTag(); proxyTargetTag.setColour(tag.getColour()); proxyTargetTag.setDescription(tag.getDescription()); @@ -90,9 +82,10 @@ public class DistributionTagBeanQuery extends AbstractBeanQuery { proxyTargetTag.setId(tag.getId()); final TagIdName tagIdName = new TagIdName(tag.getName(), tag.getId()); proxyTargetTag.setTagIdName(tagIdName); - tagList.add(proxyTargetTag); - } - return tagList; + + return proxyTargetTag; + + }).collect(Collectors.toList()); } @Override diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagHeader.java index 313a1f279..a5a8b2b5d 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagHeader.java @@ -8,8 +8,8 @@ */ package org.eclipse.hawkbit.ui.management.dstag; +import org.eclipse.hawkbit.repository.DistributionSetTagManagement; import org.eclipse.hawkbit.repository.EntityFactory; -import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.ui.SpPermissionChecker; import org.eclipse.hawkbit.ui.common.filterlayout.AbstractFilterHeader; import org.eclipse.hawkbit.ui.components.RefreshableContainer; @@ -36,12 +36,13 @@ public class DistributionTagHeader extends AbstractFilterHeader implements Refre private final CreateUpdateDistributionTagLayoutWindow createORUpdateDistributionTagLayout; DistributionTagHeader(final VaadinMessageSource i18n, final ManagementUIState managementUIState, - final SpPermissionChecker permChecker, final UIEventBus eventBus, final TagManagement tagManagement, - final EntityFactory entityFactory, final UINotification uiNotification) { + final SpPermissionChecker permChecker, final UIEventBus eventBus, + final DistributionSetTagManagement distributionSetTagManagement, final EntityFactory entityFactory, + final UINotification uiNotification) { super(permChecker, eventBus, i18n); this.managementUIState = managementUIState; - this.createORUpdateDistributionTagLayout = new CreateUpdateDistributionTagLayoutWindow(i18n, tagManagement, - entityFactory, eventBus, permChecker, uiNotification); + this.createORUpdateDistributionTagLayout = new CreateUpdateDistributionTagLayoutWindow(i18n, + distributionSetTagManagement, entityFactory, eventBus, permChecker, uiNotification); if (hasCreateUpdatePermission()) { createORUpdateDistributionTagLayout.init(); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagLayout.java index de25ac940..fc28b4c95 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagLayout.java @@ -9,8 +9,8 @@ package org.eclipse.hawkbit.ui.management.dstag; import org.eclipse.hawkbit.repository.DistributionSetManagement; +import org.eclipse.hawkbit.repository.DistributionSetTagManagement; import org.eclipse.hawkbit.repository.EntityFactory; -import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.ui.SpPermissionChecker; import org.eclipse.hawkbit.ui.common.filterlayout.AbstractFilterButtons; import org.eclipse.hawkbit.ui.common.filterlayout.AbstractFilterHeader; @@ -38,15 +38,15 @@ public class DistributionTagLayout extends AbstractFilterLayout implements Refre private final ManagementUIState managementUIState; - public DistributionTagLayout(final UIEventBus eventbus, final ManagementUIState managementUIState, final VaadinMessageSource i18n, - final SpPermissionChecker permChecker, final UIEventBus eventBus, final TagManagement tagManagement, - final EntityFactory entityFactory, final UINotification uiNotification, - final DistributionTableFilters distFilterParameters, + public DistributionTagLayout(final UIEventBus eventbus, final ManagementUIState managementUIState, + final VaadinMessageSource i18n, final SpPermissionChecker permChecker, final UIEventBus eventBus, + final DistributionSetTagManagement distributionSetTagManagement, final EntityFactory entityFactory, + final UINotification uiNotification, final DistributionTableFilters distFilterParameters, final DistributionSetManagement distributionSetManagement, final ManagementViewClientCriterion managementViewClientCriterion) { - super(new DistributionTagHeader(i18n, managementUIState, permChecker, eventBus, tagManagement, entityFactory, - uiNotification), + super(new DistributionTagHeader(i18n, managementUIState, permChecker, eventBus, distributionSetTagManagement, + entityFactory, uiNotification), new DistributionTagButtons(eventBus, managementUIState, entityFactory, i18n, uiNotification, permChecker, distFilterParameters, distributionSetManagement, managementViewClientCriterion)); this.managementUIState = managementUIState; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/CountMessageLabel.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/CountMessageLabel.java index 5a562dbcb..2e8148594 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/CountMessageLabel.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/CountMessageLabel.java @@ -193,8 +193,8 @@ public class CountMessageLabel extends Label { * as dist ID */ private void displayCountLabel(final Long distId) { - final Long targetsWithAssigedDsCount = targetManagement.countTargetByAssignedDistributionSet(distId); - final Long targetsWithInstalledDsCount = targetManagement.countTargetByInstalledDistributionSet(distId); + final Long targetsWithAssigedDsCount = targetManagement.countByAssignedDistributionSet(distId); + final Long targetsWithInstalledDsCount = targetManagement.countByInstalledDistributionSet(distId); final StringBuilder message = new StringBuilder(i18n.getMessage("label.target.count")); message.append(""); message.append(i18n.getMessage("label.assigned.count", new Object[] { targetsWithAssigedDsCount })); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java index c59f37cf6..3fcea2ea2 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java @@ -17,8 +17,9 @@ import java.util.stream.Collectors; import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.DistributionSetManagement; -import org.eclipse.hawkbit.repository.TagManagement; +import org.eclipse.hawkbit.repository.DistributionSetTagManagement; import org.eclipse.hawkbit.repository.TargetManagement; +import org.eclipse.hawkbit.repository.TargetTagManagement; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.ui.SpPermissionChecker; @@ -62,7 +63,9 @@ public class DeleteActionsLayout extends AbstractDeleteActionsLayout { private static final long serialVersionUID = 1L; - private final transient TagManagement tagManagementService; + private final transient DistributionSetTagManagement distributionSetTagManagement; + + private final transient TargetTagManagement targetTagManagement; private final ManagementViewClientCriterion managementViewClientCriterion; @@ -77,13 +80,15 @@ public class DeleteActionsLayout extends AbstractDeleteActionsLayout { private final transient DistributionSetManagement distributionSetManagement; public DeleteActionsLayout(final VaadinMessageSource i18n, final SpPermissionChecker permChecker, - final UIEventBus eventBus, final UINotification notification, final TagManagement tagManagementService, + final UIEventBus eventBus, final UINotification notification, final TargetTagManagement targetTagManagement, + final DistributionSetTagManagement distributionSetTagManagement, final ManagementViewClientCriterion managementViewClientCriterion, final ManagementUIState managementUIState, final TargetManagement targetManagement, final TargetTable targetTable, final DeploymentManagement deploymentManagement, final DistributionSetManagement distributionSetManagement) { super(i18n, permChecker, eventBus, notification); - this.tagManagementService = tagManagementService; + this.distributionSetTagManagement = distributionSetTagManagement; + this.targetTagManagement = targetTagManagement; this.managementViewClientCriterion = managementViewClientCriterion; this.managementUIState = managementUIState; this.manangementConfirmationWindowLayout = new ManangementConfirmationWindowLayout(i18n, eventBus, @@ -244,7 +249,7 @@ public class DeleteActionsLayout extends AbstractDeleteActionsLayout { if (managementUIState.getDistributionTableFilters().getDistSetTags().contains(tagName)) { notification.displayValidationError(i18n.getMessage("message.tag.delete", new Object[] { tagName })); } else { - tagManagementService.deleteDistributionSetTag(tagName); + distributionSetTagManagement.delete(tagName); if (source instanceof DragAndDropWrapper) { final Long id = DeleteActionsLayoutHelper.getDistributionTagId((DragAndDropWrapper) source); @@ -261,7 +266,7 @@ public class DeleteActionsLayout extends AbstractDeleteActionsLayout { if (managementUIState.getTargetTableFilters().getClickedTargetTags().contains(tagName)) { notification.displayValidationError(i18n.getMessage("message.tag.delete", new Object[] { tagName })); } else { - tagManagementService.deleteTargetTag(tagName); + targetTagManagement.delete(tagName); if (source instanceof DragAndDropWrapper) { final Long id = DeleteActionsLayoutHelper.getTargetTagId((DragAndDropWrapper) source); @@ -285,8 +290,7 @@ public class DeleteActionsLayout extends AbstractDeleteActionsLayout { return; } - final List findDistributionSetAllById = distributionSetManagement - .findDistributionSetsById(ids); + final List findDistributionSetAllById = distributionSetManagement.get(ids); if (findDistributionSetAllById.isEmpty()) { notification.displayWarning(i18n.getMessage("distributionsets.not.exists")); @@ -329,8 +333,7 @@ public class DeleteActionsLayout extends AbstractDeleteActionsLayout { private boolean isDsInUseInBulkUpload(final Set distributionIdNameSet, final Long dsInBulkUpload) { if (distributionIdNameSet.contains(dsInBulkUpload)) { - final Optional distributionSet = distributionSetManagement - .findDistributionSetById(dsInBulkUpload); + final Optional distributionSet = distributionSetManagement.get(dsInBulkUpload); if (!distributionSet.isPresent()) { notification.displayWarning(i18n.getMessage("distributionset.not.exists")); return true; @@ -345,7 +348,7 @@ public class DeleteActionsLayout extends AbstractDeleteActionsLayout { private void addInDeleteTargetList(final Table sourceTable, final TableTransferable transferable) { final TargetTable targetTable = (TargetTable) sourceTable; final Set targetIdSet = targetTable.getDeletedEntityByTransferable(transferable); - final Collection findTargetAllById = targetManagement.findTargetsById(targetIdSet); + final Collection findTargetAllById = targetManagement.get(targetIdSet); if (findTargetAllById.isEmpty()) { notification.displayWarning(i18n.getMessage("targets.not.exists")); return; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/ManangementConfirmationWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/ManangementConfirmationWindowLayout.java index 0fccd0095..78708ce49 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/ManangementConfirmationWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/ManangementConfirmationWindowLayout.java @@ -373,7 +373,7 @@ public class ManangementConfirmationWindowLayout extends AbstractConfirmationWin final Collection deletedIds = managementUIState.getDeletedDistributionList().stream() .map(DistributionSetIdName::getId).collect(Collectors.toList()); - distributionSetManagement.deleteDistributionSet(deletedIds); + distributionSetManagement.delete(deletedIds); eventBus.publish(this, new DistributionTableEvent(BaseEntityEventType.REMOVE_ENTITY, deletedIds)); addToConsolitatedMsg(FontAwesome.TRASH_O.getHtml() + SPUILabelDefinitions.HTML_SPACE @@ -463,7 +463,7 @@ public class ManangementConfirmationWindowLayout extends AbstractConfirmationWin final Set targetIds = targetIdNames.stream().map(TargetIdName::getTargetId).collect(Collectors.toSet()); - targetManagement.deleteTargets(targetIds); + targetManagement.delete(targetIds); eventBus.publish(this, new TargetTableEvent(BaseEntityEventType.REMOVE_ENTITY, targetIds)); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/BulkUploadHandler.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/BulkUploadHandler.java index 8701200d0..6edd2705f 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/BulkUploadHandler.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/BulkUploadHandler.java @@ -29,7 +29,7 @@ import java.util.concurrent.Executor; import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.EntityFactory; -import org.eclipse.hawkbit.repository.TagManagement; +import org.eclipse.hawkbit.repository.TargetTagManagement; import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; import org.eclipse.hawkbit.repository.model.Action.ActionType; @@ -81,7 +81,7 @@ public class BulkUploadHandler extends CustomComponent private static final Splitter SPLITTER = Splitter.on(',').omitEmptyStrings().trimResults(); private final transient TargetManagement targetManagement; - private final transient TagManagement tagManagement; + private final transient TargetTagManagement tagManagement; private final ComboBox comboBox; private final TextArea descTextArea; @@ -106,7 +106,7 @@ public class BulkUploadHandler extends CustomComponent private final UI uiInstance; BulkUploadHandler(final TargetBulkUpdateWindowLayout targetBulkUpdateWindowLayout, - final TargetManagement targetManagement, final TagManagement tagManagement, + final TargetManagement targetManagement, final TargetTagManagement tagManagement, final EntityFactory entityFactory, final DistributionSetManagement distributionSetManagement, final ManagementUIState managementUIState, final DeploymentManagement deploymentManagement, final VaadinMessageSource i18n, final UI uiInstance, final Executor uiExecutor) { @@ -304,7 +304,7 @@ public class BulkUploadHandler extends CustomComponent final TargetBulkUpload targetBulkUpload = managementUIState.getTargetTableFilters().getBulkUpload(); final List targetsList = targetBulkUpload.getTargetsCreated(); final Long dsSelected = (Long) comboBox.getValue(); - if (!distributionSetManagement.findDistributionSetById(dsSelected).isPresent()) { + if (!distributionSetManagement.get(dsSelected).isPresent()) { return i18n.getMessage("message.bulk.upload.assignment.failed"); } deploymentManagement.assignDistributionSet(targetBulkUpload.getDsNameAndVersion(), actionType, @@ -316,7 +316,7 @@ public class BulkUploadHandler extends CustomComponent final Map tokensSelected = targetBulkTokenTags.getTokensAdded(); final List deletedTags = new ArrayList<>(); for (final TagData tagData : tokensSelected.values()) { - if (!tagManagement.findTargetTagById(tagData.getId()).isPresent()) { + if (!tagManagement.get(tagData.getId()).isPresent()) { deletedTags.add(tagData.getName()); } else { targetManagement.toggleTagAssignment( @@ -368,7 +368,7 @@ public class BulkUploadHandler extends CustomComponent final String description = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue()); try { - targetManagement.createTarget(entityFactory.target().create().controllerId(newControllerId).name(name) + targetManagement.create(entityFactory.target().create().controllerId(newControllerId).name(name) .description(description)); managementUIState.getTargetTableFilters().getBulkUpload().getTargetsCreated().add(newControllerId); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetAddUpdateWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetAddUpdateWindowLayout.java index c52438a1b..8564b8455 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetAddUpdateWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetAddUpdateWindowLayout.java @@ -131,7 +131,7 @@ public class TargetAddUpdateWindowLayout extends CustomComponent { */ public void updateTarget() { /* save updated entity */ - final Target target = targetManagement.updateTarget(entityFactory.target().update(controllerId) + final Target target = targetManagement.update(entityFactory.target().update(controllerId) .name(nameTextField.getValue()).description(descTextArea.getValue())); /* display success msg */ uINotification.displaySuccess(i18n.getMessage("message.update.success", new Object[] { target.getName() })); @@ -144,7 +144,7 @@ public class TargetAddUpdateWindowLayout extends CustomComponent { final String newName = HawkbitCommonUtil.trimAndNullIfEmpty(nameTextField.getValue()); final String newDesc = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue()); - final Target newTarget = targetManagement.createTarget( + final Target newTarget = targetManagement.create( entityFactory.target().create().controllerId(newControllerId).name(newName).description(newDesc)); eventBus.publish(this, new TargetTableEvent(BaseEntityEventType.ADD_ENTITY, newTarget)); @@ -169,9 +169,9 @@ public class TargetAddUpdateWindowLayout extends CustomComponent { * @return window or {@code null} if target is not exists. */ public Window getWindow(final String controllerId) { - final Optional target = targetManagement.findTargetByControllerID(controllerId); + final Optional target = targetManagement.getByControllerID(controllerId); if (!target.isPresent()) { - uINotification.displayWarning(i18n.getMessage("target.not.exists", new Object[] { controllerId })); + uINotification.displayWarning(i18n.getMessage("target.not.exists", controllerId)); return null; } populateValuesOfTarget(target.get()); @@ -195,10 +195,9 @@ public class TargetAddUpdateWindowLayout extends CustomComponent { private boolean isDuplicate() { final String newControlllerId = controllerIDTextField.getValue(); - final Optional existingTarget = targetManagement.findTargetByControllerID(newControlllerId.trim()); + final Optional existingTarget = targetManagement.getByControllerID(newControlllerId.trim()); if (existingTarget.isPresent()) { - uINotification.displayValidationError( - i18n.getMessage("message.target.duplicate.check", new Object[] { newControlllerId })); + uINotification.displayValidationError(i18n.getMessage("message.target.duplicate.check", newControlllerId)); return true; } else { return false; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetBeanQuery.java index f9f3b229f..5d94c60aa 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetBeanQuery.java @@ -109,19 +109,20 @@ public class TargetBeanQuery extends AbstractBeanQuery { Slice targetBeans; final List proxyTargetBeans = new ArrayList<>(); if (pinnedDistId != null) { - targetBeans = getTargetManagement().findTargetsAllOrderByLinkedDistributionSet( + targetBeans = getTargetManagement().findByFilterOrderByLinkedDistributionSet( new OffsetBasedPageRequest(startIndex, SPUIDefinitions.PAGE_SIZE, sort), pinnedDistId, - new FilterParams(distributionId, status, overdueState, searchText, noTagClicked, targetTags)); + new FilterParams(status, overdueState, searchText, distributionId, noTagClicked, targetTags)); } else if (null != targetFilterQueryId) { - targetBeans = getTargetManagement().findTargetsByTargetFilterQuery(targetFilterQueryId, - new PageRequest(startIndex / SPUIDefinitions.PAGE_SIZE, SPUIDefinitions.PAGE_SIZE, sort)); + targetBeans = getTargetManagement().findByTargetFilterQuery( + new PageRequest(startIndex / SPUIDefinitions.PAGE_SIZE, SPUIDefinitions.PAGE_SIZE, sort), + targetFilterQueryId); } else if (!isAnyFilterSelected()) { - targetBeans = getTargetManagement().findTargetsAll( - new PageRequest(startIndex / SPUIDefinitions.PAGE_SIZE, SPUIDefinitions.PAGE_SIZE, sort)); + targetBeans = getTargetManagement() + .findAll(new PageRequest(startIndex / SPUIDefinitions.PAGE_SIZE, SPUIDefinitions.PAGE_SIZE, sort)); } else { - targetBeans = getTargetManagement().findTargetByFilters( - new PageRequest(startIndex / SPUIDefinitions.PAGE_SIZE, SPUIDefinitions.PAGE_SIZE, sort), status, - overdueState, searchText, distributionId, noTagClicked, targetTags); + targetBeans = getTargetManagement().findByFilters( + new PageRequest(startIndex / SPUIDefinitions.PAGE_SIZE, SPUIDefinitions.PAGE_SIZE, sort), + new FilterParams(status, overdueState, searchText, distributionId, noTagClicked, targetTags)); } for (final Target targ : targetBeans) { final ProxyTarget prxyTarget = new ProxyTarget(); @@ -176,15 +177,15 @@ public class TargetBeanQuery extends AbstractBeanQuery { @Override public int size() { - final long totSize = getTargetManagement().countTargetsAll(); + final long totSize = getTargetManagement().count(); long size; if (null != targetFilterQueryId) { - size = getTargetManagement().countTargetByTargetFilterQuery(targetFilterQueryId); + size = getTargetManagement().countByTargetFilterQuery(targetFilterQueryId); } else if (!isAnyFilterSelected()) { size = totSize; } else { - size = getTargetManagement().countTargetByFilters(status, overdueState, searchText, distributionId, - noTagClicked, targetTags); + size = getTargetManagement().countByFilters(status, overdueState, searchText, distributionId, noTagClicked, + targetTags); } final ManagementUIState tmpManagementUIState = getManagementUIState(); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetBulkTokenTags.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetBulkTokenTags.java index 93cb91fc1..d2082cf27 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetBulkTokenTags.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetBulkTokenTags.java @@ -10,7 +10,7 @@ package org.eclipse.hawkbit.ui.management.targettable; import java.util.Map; -import org.eclipse.hawkbit.repository.TagManagement; +import org.eclipse.hawkbit.repository.TargetTagManagement; import org.eclipse.hawkbit.repository.model.TargetTag; import org.eclipse.hawkbit.ui.SpPermissionChecker; import org.eclipse.hawkbit.ui.common.tagdetails.AbstractTargetTagToken; @@ -30,7 +30,7 @@ public class TargetBulkTokenTags extends AbstractTargetTagToken { private static final int MAX_TAGS = 500; TargetBulkTokenTags(final SpPermissionChecker checker, final VaadinMessageSource i18n, final UINotification uinotification, - final UIEventBus eventBus, final ManagementUIState managementUIState, final TagManagement tagManagement) { + final UIEventBus eventBus, final ManagementUIState managementUIState, final TargetTagManagement tagManagement) { super(checker, i18n, uinotification, eventBus, managementUIState, tagManagement); } @@ -68,7 +68,7 @@ public class TargetBulkTokenTags extends AbstractTargetTagToken { protected void addAlreadySelectedTags() { for (final String tagName : managementUIState.getTargetTableFilters().getBulkUpload().getAssignedTagNames()) { - tagManagement.findTargetTag(tagName).map(TargetTag::getId).ifPresent(this::addNewToken); + tagManagement.getByName(tagName).map(TargetTag::getId).ifPresent(this::addNewToken); } } @@ -76,7 +76,7 @@ public class TargetBulkTokenTags extends AbstractTargetTagToken { protected void populateContainer() { container.removeAllItems(); tagDetails.clear(); - for (final TargetTag tag : tagManagement.findAllTargetTags(new PageRequest(0, MAX_TAGS))) { + for (final TargetTag tag : tagManagement.findAll(new PageRequest(0, MAX_TAGS))) { setContainerPropertValues(tag.getId(), tag.getName(), tag.getColour()); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetBulkUpdateWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetBulkUpdateWindowLayout.java index 69ee6de4c..dd909b7f2 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetBulkUpdateWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetBulkUpdateWindowLayout.java @@ -14,7 +14,7 @@ import java.util.concurrent.Executor; import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.EntityFactory; -import org.eclipse.hawkbit.repository.TagManagement; +import org.eclipse.hawkbit.repository.TargetTagManagement; import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.ui.SpPermissionChecker; import org.eclipse.hawkbit.ui.UiProperties; @@ -65,7 +65,7 @@ public class TargetBulkUpdateWindowLayout extends CustomComponent { private final transient TargetManagement targetManagement; private final transient DistributionSetManagement distributionSetManagement; - private final transient TagManagement tagManagement; + private final transient TargetTagManagement tagManagement; private final transient EntityFactory entityFactory; @@ -98,7 +98,7 @@ public class TargetBulkUpdateWindowLayout extends CustomComponent { TargetBulkUpdateWindowLayout(final VaadinMessageSource i18n, final TargetManagement targetManagement, final UIEventBus eventBus, final ManagementUIState managementUIState, final DeploymentManagement deploymentManagement, final UiProperties uiproperties, - final SpPermissionChecker checker, final UINotification uinotification, final TagManagement tagManagement, + final SpPermissionChecker checker, final UINotification uinotification, final TargetTagManagement tagManagement, final DistributionSetManagement distributionSetManagement, final EntityFactory entityFactory, final Executor uiExecutor) { this.i18n = i18n; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetDetails.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetDetails.java index 30d55c98b..8ee4b034d 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetDetails.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetDetails.java @@ -12,7 +12,7 @@ import java.net.URI; import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.EntityFactory; -import org.eclipse.hawkbit.repository.TagManagement; +import org.eclipse.hawkbit.repository.TargetTagManagement; import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.SoftwareModule; @@ -65,7 +65,7 @@ public class TargetDetails extends AbstractTableDetailsLayout { TargetDetails(final VaadinMessageSource i18n, final UIEventBus eventBus, final SpPermissionChecker permissionChecker, final ManagementUIState managementUIState, - final UINotification uiNotification, final TagManagement tagManagement, + final UINotification uiNotification, final TargetTagManagement tagManagement, final TargetManagement targetManagement, final DeploymentManagement deploymentManagement, final EntityFactory entityFactory, final TargetTable targetTable) { super(i18n, eventBus, permissionChecker, managementUIState); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java index 3bd7c91f7..a7b48df39 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java @@ -21,8 +21,8 @@ import java.util.stream.Stream; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.FilterParams; -import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.TargetManagement; +import org.eclipse.hawkbit.repository.TargetTagManagement; import org.eclipse.hawkbit.repository.event.remote.entity.RemoteEntityEvent; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.Tag; @@ -104,7 +104,7 @@ public class TargetTable extends AbstractTable { private final transient DistributionSetManagement distributionSetManagement; - private final transient TagManagement tagManagement; + private final transient TargetTagManagement tagManagement; private final SpPermissionChecker permChecker; @@ -119,7 +119,7 @@ public class TargetTable extends AbstractTable { public TargetTable(final UIEventBus eventBus, final VaadinMessageSource i18n, final UINotification notification, final TargetManagement targetManagement, final ManagementUIState managementUIState, final SpPermissionChecker permChecker, final ManagementViewClientCriterion managementViewClientCriterion, - final DistributionSetManagement distributionSetManagement, final TagManagement tagManagement) { + final DistributionSetManagement distributionSetManagement, final TargetTagManagement tagManagement) { super(eventBus, i18n, notification); this.targetManagement = targetManagement; this.permChecker = permChecker; @@ -152,16 +152,15 @@ public class TargetTable extends AbstractTable { refreshTargets(); } else { eventContainer.getEvents().stream().filter(event -> visibleItemIds.contains(event.getEntityId())) - .filter(Objects::nonNull) - .forEach(event -> updateVisibleItemOnEvent(event.getEntity())); + .filter(Objects::nonNull).forEach(event -> updateVisibleItemOnEvent(event.getEntity())); } publishTargetSelectedEntityForRefresh(eventContainer.getEvents().stream()); } private void publishTargetSelectedEntityForRefresh( final Stream> targetEntityEventStream) { - targetEntityEventStream.filter(event -> isLastSelectedTarget(event.getEntityId())) - .filter(Objects::nonNull).findAny().ifPresent(event -> eventBus.publish(this, + targetEntityEventStream.filter(event -> isLastSelectedTarget(event.getEntityId())).filter(Objects::nonNull) + .findAny().ifPresent(event -> eventBus.publish(this, new TargetTableEvent(BaseEntityEventType.SELECTED_ENTITY, event.getEntity()))); } @@ -299,7 +298,7 @@ public class TargetTable extends AbstractTable { @Override protected Optional findEntityByTableValue(final Long lastSelectedId) { - return targetManagement.findTargetById(lastSelectedId); + return targetManagement.get(lastSelectedId); } @Override @@ -519,15 +518,15 @@ public class TargetTable extends AbstractTable { * @return TagAssigmentResult with all meta data of the assignment outcome. */ public TargetTagAssignmentResult toggleTagAssignment(final Collection targetIds, final String targTagName) { - final List controllerIds = targetManagement.findTargetsById(targetIds).stream() - .map(Target::getControllerId).collect(Collectors.toList()); + final List controllerIds = targetManagement.get(targetIds).stream().map(Target::getControllerId) + .collect(Collectors.toList()); if (controllerIds.isEmpty()) { notification.displayWarning(i18n.getMessage("targets.not.exists")); return new TargetTagAssignmentResult(0, 0, 0, Lists.newArrayListWithCapacity(0), Lists.newArrayListWithCapacity(0), null); } - final Optional tag = tagManagement.findTargetTag(targTagName); + final Optional tag = tagManagement.getByName(targTagName); if (!tag.isPresent()) { notification.displayWarning(i18n.getMessage("targettag.not.exists", new Object[] { targTagName })); return new TargetTagAssignmentResult(0, 0, 0, Lists.newArrayListWithCapacity(0), @@ -580,15 +579,14 @@ public class TargetTable extends AbstractTable { return; } final Long targetId = (Long) targetItemId; - final Optional target = targetManagement.findTargetById(targetId); + final Optional target = targetManagement.get(targetId); if (!target.isPresent()) { getNotification().displayWarning(i18n.getMessage("target.not.exists", new Object[] { "" })); return; } final TargetIdName createTargetIdName = new TargetIdName(target.get()); - final List findDistributionSetAllById = distributionSetManagement - .findDistributionSetsById(ids); + final List findDistributionSetAllById = distributionSetManagement.get(ids); if (findDistributionSetAllById.isEmpty()) { notification.displayWarning(i18n.getMessage("distributionsets.not.exists")); @@ -848,7 +846,7 @@ public class TargetTable extends AbstractTable { } final long size = getTargetsCountWithFilter(totalTargetsCount, pinnedDistId, - new FilterParams(distributionId, status, overdueState, searchText, noTagClicked, targetTags)); + new FilterParams(status, overdueState, searchText, distributionId, noTagClicked, targetTags)); if (size > SPUIDefinitions.MAX_TABLE_ENTRIES) { managementUIState.setTargetsTruncated(size - SPUIDefinitions.MAX_TABLE_ENTRIES); @@ -861,16 +859,15 @@ public class TargetTable extends AbstractTable { final long size; if (query.isPresent()) { - size = targetManagement.countTargetByTargetFilterQuery(query.get()); + size = targetManagement.countByTargetFilterQuery(query.get()); } else if (noFilterSelected(filterParams.getFilterByStatus(), pinnedDistId, filterParams.getSelectTargetWithNoTag(), filterParams.getFilterByTagNames(), filterParams.getFilterBySearchText())) { size = totalTargetsCount; } else { - size = targetManagement.countTargetByFilters(filterParams.getFilterByStatus(), - filterParams.getOverdueState(), filterParams.getFilterBySearchText(), - filterParams.getFilterByDistributionId(), filterParams.getSelectTargetWithNoTag(), - filterParams.getFilterByTagNames()); + size = targetManagement.countByFilters(filterParams.getFilterByStatus(), filterParams.getOverdueState(), + filterParams.getFilterBySearchText(), filterParams.getFilterByDistributionId(), + filterParams.getSelectTargetWithNoTag(), filterParams.getFilterByTagNames()); } return size; } @@ -886,7 +883,7 @@ public class TargetTable extends AbstractTable { } private long getTotalTargetsCount() { - return targetManagement.countTargetsAll(); + return targetManagement.count(); } private boolean isFilteredByStatus() { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTableHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTableHeader.java index bcf0300ce..a2fdf0735 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTableHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTableHeader.java @@ -15,7 +15,7 @@ import java.util.concurrent.Executor; import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.EntityFactory; -import org.eclipse.hawkbit.repository.TagManagement; +import org.eclipse.hawkbit.repository.TargetTagManagement; import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.ui.SpPermissionChecker; @@ -81,7 +81,7 @@ public class TargetTableHeader extends AbstractTableHeader { final UINotification notification, final ManagementUIState managementUIState, final ManagementViewClientCriterion managementViewClientCriterion, final TargetManagement targetManagement, final DeploymentManagement deploymentManagement, final UiProperties uiproperties, final UIEventBus eventBus, - final EntityFactory entityFactory, final UINotification uinotification, final TagManagement tagManagement, + final EntityFactory entityFactory, final UINotification uinotification, final TargetTagManagement tagManagement, final DistributionSetManagement distributionSetManagement, final Executor uiExecutor, final TargetTable targetTable) { super(i18n, permChecker, eventbus, managementUIState, null, null); @@ -336,7 +336,7 @@ public class TargetTableHeader extends AbstractTableHeader { } final Long distributionSetId = distributionIdSet.iterator().next(); final Optional distributionSet = distributionSetManagement - .findDistributionSetById(distributionSetId); + .get(distributionSetId); if (!distributionSet.isPresent()) { notification.displayWarning(i18n.getMessage("distributionset.not.exists")); return; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTableLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTableLayout.java index c51cf0065..4cc056633 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTableLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTableLayout.java @@ -13,7 +13,7 @@ import java.util.concurrent.Executor; import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.EntityFactory; -import org.eclipse.hawkbit.repository.TagManagement; +import org.eclipse.hawkbit.repository.TargetTagManagement; import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.ui.SpPermissionChecker; import org.eclipse.hawkbit.ui.UiProperties; @@ -46,7 +46,7 @@ public class TargetTableLayout extends AbstractTableLayout { final ManagementViewClientCriterion managementViewClientCriterion, final DeploymentManagement deploymentManagement, final UiProperties uiproperties, final SpPermissionChecker permissionChecker, final UINotification uinotification, - final TagManagement tagManagement, final DistributionSetManagement distributionSetManagement, + final TargetTagManagement tagManagement, final DistributionSetManagement distributionSetManagement, final Executor uiExecutor) { this.eventBus = eventBus; this.targetDetails = new TargetDetails(i18n, eventbus, permissionChecker, managementUIState, uinotification, diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/CreateUpdateTargetTagLayoutWindow.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/CreateUpdateTargetTagLayoutWindow.java index 5b197247f..2c0fbcecb 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/CreateUpdateTargetTagLayoutWindow.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/CreateUpdateTargetTagLayoutWindow.java @@ -8,10 +8,13 @@ */ package org.eclipse.hawkbit.ui.management.targettag; +import java.util.Objects; import java.util.Optional; import org.eclipse.hawkbit.repository.EntityFactory; -import org.eclipse.hawkbit.repository.TagManagement; +import org.eclipse.hawkbit.repository.TargetTagManagement; +import org.eclipse.hawkbit.repository.builder.TagUpdate; +import org.eclipse.hawkbit.repository.model.Tag; import org.eclipse.hawkbit.repository.model.TargetTag; import org.eclipse.hawkbit.ui.SpPermissionChecker; import org.eclipse.hawkbit.ui.colorpicker.ColorPickerConstants; @@ -27,21 +30,25 @@ import org.springframework.data.domain.PageRequest; import org.springframework.util.StringUtils; import org.vaadin.spring.events.EventBus.UIEventBus; +import com.vaadin.shared.ui.colorpicker.Color; + /** * Class for Create / Update Tag Layout of target */ public class CreateUpdateTargetTagLayoutWindow extends AbstractCreateUpdateTagLayout implements RefreshableContainer { - private static final long serialVersionUID = 2446682350481560235L; + private static final long serialVersionUID = 1L; + + private final transient TargetTagManagement targetTagManagement; /** * Constructor for CreateUpdateTargetTagLayoutWindow * * @param i18n * I18N - * @param tagManagement - * TagManagement + * @param targetTagManagement + * TargetTagManagement * @param entityFactory * EntityFactory * @param eventBus @@ -51,10 +58,11 @@ public class CreateUpdateTargetTagLayoutWindow extends AbstractCreateUpdateTagLa * @param uiNotification * UINotification */ - public CreateUpdateTargetTagLayoutWindow(final VaadinMessageSource i18n, final TagManagement tagManagement, - final EntityFactory entityFactory, final UIEventBus eventBus, final SpPermissionChecker permChecker, - final UINotification uiNotification) { - super(i18n, tagManagement, entityFactory, eventBus, permChecker, uiNotification); + public CreateUpdateTargetTagLayoutWindow(final VaadinMessageSource i18n, + final TargetTagManagement targetTagManagement, final EntityFactory entityFactory, final UIEventBus eventBus, + final SpPermissionChecker permChecker, final UINotification uiNotification) { + super(i18n, entityFactory, eventBus, permChecker, uiNotification); + this.targetTagManagement = targetTagManagement; } @Override @@ -69,10 +77,20 @@ public class CreateUpdateTargetTagLayoutWindow extends AbstractCreateUpdateTagLa @Override public void populateTagNameCombo() { tagNameComboBox.removeAllItems(); - tagManagement.findAllTargetTags(new PageRequest(0, MAX_TAGS)) + targetTagManagement.findAll(new PageRequest(0, MAX_TAGS)) .forEach(value -> tagNameComboBox.addItem(value.getName())); } + /** + * @return the color which should be selected in the color-picker component. + */ + @Override + protected Color getColorForColorPicker() { + return ColorPickerHelper + .rgbToColorConverter(targetTagManagement.getByName(tagNameComboBox.getValue().toString()) + .map(TargetTag::getColour).filter(Objects::nonNull).orElse(ColorPickerConstants.DEFAULT_COLOR)); + } + /** * Select tag & set tag name & tag desc values corresponding to selected * tag. @@ -83,7 +101,7 @@ public class CreateUpdateTargetTagLayoutWindow extends AbstractCreateUpdateTagLa @Override public void setTagDetails(final String targetTagSelected) { tagName.setValue(targetTagSelected); - final Optional selectedTargetTag = tagManagement.findTargetTag(targetTagSelected); + final Optional selectedTargetTag = targetTagManagement.getByName(targetTagSelected); if (selectedTargetTag.isPresent()) { tagDesc.setValue(selectedTargetTag.get().getDescription()); if (null == selectedTargetTag.get().getColour()) { @@ -107,7 +125,7 @@ public class CreateUpdateTargetTagLayoutWindow extends AbstractCreateUpdateTagLa @Override protected Optional findEntityByName() { - return tagManagement.findTargetTag(tagName.getValue()); + return targetTagManagement.getByName(tagName.getValue()); } /** @@ -124,7 +142,7 @@ public class CreateUpdateTargetTagLayoutWindow extends AbstractCreateUpdateTagLa colour = getColorPicked(); } - final TargetTag newTargetTag = tagManagement.createTargetTag(entityFactory.tag().create() + final TargetTag newTargetTag = targetTagManagement.create(entityFactory.tag().create() .name(tagNameTrimmed).description(tagDescriptionTrimmed).colour(colour)); eventBus.publish(this, new TargetTagTableEvent(BaseEntityEventType.ADD_ENTITY, newTargetTag)); displaySuccess(newTargetTag.getName()); @@ -133,6 +151,21 @@ public class CreateUpdateTargetTagLayoutWindow extends AbstractCreateUpdateTagLa } } + /** + * update tag. + */ + protected void updateExistingTag(final Tag targetObj) { + final TagUpdate update = entityFactory.tag().update(targetObj.getId()).name(tagName.getValue()) + .description(tagDesc.getValue()) + .colour(ColorPickerHelper.getColorPickedString(colorPickerLayout.getSelPreview())); + + targetTagManagement.update(update); + eventBus.publish(this, new TargetTagTableEvent(BaseEntityEventType.UPDATED_ENTITY, (TargetTag) targetObj)); + + uiNotification.displaySuccess(i18n.getMessage("message.update.success", new Object[] { targetObj.getName() })); + + } + @Override protected void createRequiredComponents() { super.createRequiredComponents(); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/CustomTargetTagFilterButtonClick.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/CustomTargetTagFilterButtonClick.java index f6559671d..ca0da4ef3 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/CustomTargetTagFilterButtonClick.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/CustomTargetTagFilterButtonClick.java @@ -50,7 +50,7 @@ public class CustomTargetTagFilterButtonClick extends AbstractFilterSingleButton @Override protected void filterClicked(final Button clickedButton) { - targetFilterQueryManagement.findTargetFilterQueryById((Long) clickedButton.getData()) + targetFilterQueryManagement.get((Long) clickedButton.getData()) .ifPresent(targetFilterQuery -> { this.managementUIState.getTargetTableFilters().setTargetFilterQuery(targetFilterQuery.getId()); this.eventBus.publish(this, TargetFilterEvent.FILTER_BY_TARGET_FILTER_QUERY); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagBeanQuery.java index 5164a409a..9611ce233 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagBeanQuery.java @@ -13,7 +13,7 @@ import java.util.List; import java.util.Map; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; -import org.eclipse.hawkbit.repository.TagManagement; +import org.eclipse.hawkbit.repository.TargetTagManagement; import org.eclipse.hawkbit.repository.model.TargetTag; import org.eclipse.hawkbit.ui.management.tag.ProxyTag; import org.eclipse.hawkbit.ui.management.tag.TagIdName; @@ -34,7 +34,7 @@ public class TargetTagBeanQuery extends AbstractBeanQuery { private static final long serialVersionUID = -4791426170440663033L; private final Sort sort = new Sort(Direction.ASC, "name"); private transient Page firstPageTargetTag = null; - private transient TagManagement tagManagementService; + private transient TargetTagManagement tagManagementService; /** * Parametric constructor. @@ -57,7 +57,7 @@ public class TargetTagBeanQuery extends AbstractBeanQuery { @Override public int size() { firstPageTargetTag = getTagManagement() - .findAllTargetTags(new OffsetBasedPageRequest(0, SPUIDefinitions.PAGE_SIZE, sort)); + .findAll(new OffsetBasedPageRequest(0, SPUIDefinitions.PAGE_SIZE, sort)); long size = firstPageTargetTag.getTotalElements(); if (size > Integer.MAX_VALUE) { size = Integer.MAX_VALUE; @@ -65,9 +65,9 @@ public class TargetTagBeanQuery extends AbstractBeanQuery { return (int) size; } - private TagManagement getTagManagement() { + private TargetTagManagement getTagManagement() { if (tagManagementService == null) { - tagManagementService = SpringContextHelper.getBean(TagManagement.class); + tagManagementService = SpringContextHelper.getBean(TargetTagManagement.class); } return tagManagementService; } @@ -79,7 +79,7 @@ public class TargetTagBeanQuery extends AbstractBeanQuery { if (startIndex == 0 && firstPageTargetTag != null) { targetTagBeans = firstPageTargetTag; } else { - targetTagBeans = getTagManagement().findAllTargetTags(new OffsetBasedPageRequest(startIndex, count, sort)); + targetTagBeans = getTagManagement().findAll(new OffsetBasedPageRequest(startIndex, count, sort)); } for (final TargetTag tag : targetTagBeans.getContent()) { final ProxyTag proxyTargetTag = new ProxyTag(); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutView.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutView.java index 07a03c565..1c79e7eb5 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutView.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutView.java @@ -172,7 +172,7 @@ public class RolloutView extends VerticalLayout implements View { return true; } - final Optional rollout = rolloutManagement.findRolloutById(rolloutIdInState.get()); + final Optional rollout = rolloutManagement.get(rolloutIdInState.get()); return !rollout.isPresent() || rollout.get().isDeleted(); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java index 265060d0b..6eef9c18c 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java @@ -224,7 +224,7 @@ public class AddUpdateRolloutWindowLayout extends GridLayout { } private boolean duplicateCheck() { - if (rolloutManagement.findRolloutByName(getRolloutName()).isPresent()) { + if (rolloutManagement.getByName(getRolloutName()).isPresent()) { uiNotification .displayValidationError(i18n.getMessage("message.rollout.duplicate.check", getRolloutName())); return false; @@ -252,7 +252,7 @@ public class AddUpdateRolloutWindowLayout extends GridLayout { Rollout updatedRollout; try { - updatedRollout = rolloutManagement.updateRollout(rolloutUpdate); + updatedRollout = rolloutManagement.update(rolloutUpdate); } catch (final EntityNotFoundException | EntityReadOnlyException e) { LOGGER.warn("Rollout was deleted. Redirect to Rollouts overview.", e); uiNotification.displayWarning( @@ -268,7 +268,7 @@ public class AddUpdateRolloutWindowLayout extends GridLayout { private boolean duplicateCheckForEdit() { final String rolloutNameVal = getRolloutName(); if (!rollout.getName().equals(rolloutNameVal) - && rolloutManagement.findRolloutByName(rolloutNameVal).isPresent()) { + && rolloutManagement.getByName(rolloutNameVal).isPresent()) { uiNotification .displayValidationError(i18n.getMessage("message.rollout.duplicate.check", rolloutNameVal)); return false; @@ -304,10 +304,10 @@ public class AddUpdateRolloutWindowLayout extends GridLayout { } if (isNumberOfGroups()) { - return rolloutManagement.createRollout(rolloutCreate, amountGroup, conditions); + return rolloutManagement.create(rolloutCreate, amountGroup, conditions); } else if (isGroupsDefinition()) { final List groups = defineGroupsLayout.getSavedRolloutGroups(); - return rolloutManagement.createRollout(rolloutCreate, groups, conditions); + return rolloutManagement.create(rolloutCreate, groups, conditions); } throw new IllegalStateException("Either of the Tabs must be selected"); @@ -717,7 +717,7 @@ public class AddUpdateRolloutWindowLayout extends GridLayout { groupsLegendLayout.populateTotalTargets(null); defineGroupsLayout.setTargetFilter(null); } else { - totalTargetsCount = targetManagement.countTargetByTargetFilterQuery(filterQueryString); + totalTargetsCount = targetManagement.countByRsql(filterQueryString); groupsLegendLayout.populateTotalTargets(totalTargetsCount); defineGroupsLayout.setTargetFilter(filterQueryString); } @@ -735,7 +735,7 @@ public class AddUpdateRolloutWindowLayout extends GridLayout { private void populateTargetFilterQuery(final Rollout rollout) { final Page filterQueries = targetFilterQueryManagement - .findTargetFilterQueryByQuery(new PageRequest(0, 1), rollout.getTargetFilterQuery()); + .findByQuery(new PageRequest(0, 1), rollout.getTargetFilterQuery()); if (filterQueries.getTotalElements() > 0) { final TargetFilterQuery filterQuery = filterQueries.getContent().get(0); targetFilterQueryCombo.setValue(filterQuery.getName()); @@ -897,7 +897,7 @@ public class AddUpdateRolloutWindowLayout extends GridLayout { return; } - final Optional rolloutFound = rolloutManagement.findRolloutById(rolloutId); + final Optional rolloutFound = rolloutManagement.get(rolloutId); if (!rolloutFound.isPresent()) { return; } @@ -937,12 +937,12 @@ public class AddUpdateRolloutWindowLayout extends GridLayout { window.setOrginaleValues(); updateGroupsChart( - rolloutGroupManagement.findRolloutGroupsByRolloutId(rollout.getId(), - new PageRequest(0, quotaManagement.getMaxRolloutGroupsPerRollout())).getContent(), + rolloutGroupManagement.findByRollout(new PageRequest(0, quotaManagement.getMaxRolloutGroupsPerRollout()), + rollout.getId()).getContent(), rollout.getTotalTargets()); } - totalTargetsCount = targetManagement.countTargetByTargetFilterQuery(rollout.getTargetFilterQuery()); + totalTargetsCount = targetManagement.countByRsql(rollout.getTargetFilterQuery()); groupsLegendLayout.populateTotalTargets(totalTargetsCount); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/DefineGroupsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/DefineGroupsLayout.java index 2ca759840..39fa980e0 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/DefineGroupsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/DefineGroupsLayout.java @@ -238,8 +238,8 @@ public class DefineGroupsLayout extends GridLayout { removeAllRows(); - final List groups = rolloutGroupManagement.findRolloutGroupsByRolloutId(rollout.getId(), - new PageRequest(0, quotaManagement.getMaxRolloutGroupsPerRollout())).getContent(); + final List groups = rolloutGroupManagement.findByRollout(new PageRequest(0, quotaManagement.getMaxRolloutGroupsPerRollout()), + rollout.getId()).getContent(); for (final RolloutGroup group : groups) { final GroupRow groupRow = addGroupRow(); groupRow.populateByGroup(group); @@ -493,7 +493,7 @@ public class DefineGroupsLayout extends GridLayout { targetFilterQueryCombo.setValue(null); } else { final Page filterQueries = targetFilterQueryManagement - .findTargetFilterQueryByQuery(new PageRequest(0, 1), group.getTargetFilterQuery()); + .findByQuery(new PageRequest(0, 1), group.getTargetFilterQuery()); if (filterQueries.getTotalElements() > 0) { final TargetFilterQuery filterQuery = filterQueries.getContent().get(0); targetFilterQueryCombo.setValue(filterQuery.getName()); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/DistributionBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/DistributionBeanQuery.java index d1b67cccb..0cb44e4f2 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/DistributionBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/DistributionBeanQuery.java @@ -82,7 +82,7 @@ public class DistributionBeanQuery extends AbstractBeanQuery if (startIndex == 0 && firstPageDistributionSets != null) { distBeans = firstPageDistributionSets; } else { - distBeans = getDistributionSetManagement().findDistributionSetsByFilters( + distBeans = getDistributionSetManagement().findByDistributionSetFilter( new PageRequest(startIndex / count, count, sort), distributionSetFilter); } return createProxyDistributions(distBeans); @@ -119,7 +119,7 @@ public class DistributionBeanQuery extends AbstractBeanQuery final DistributionSetFilter distributionSetFilter = new DistributionSetFilterBuilder().setIsDeleted(false) .setIsComplete(true).build(); - firstPageDistributionSets = getDistributionSetManagement().findDistributionSetsByFilters( + firstPageDistributionSets = getDistributionSetManagement().findByDistributionSetFilter( new PageRequest(0, SPUIDefinitions.PAGE_SIZE, sort), distributionSetFilter); final long size = firstPageDistributionSets.getTotalElements(); if (size > Integer.MAX_VALUE) { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java index 3d7a74909..647d168f2 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java @@ -92,9 +92,9 @@ public class RolloutBeanQuery extends AbstractBeanQuery { final PageRequest pageRequest = new PageRequest(startIndex / SPUIDefinitions.PAGE_SIZE, SPUIDefinitions.PAGE_SIZE, sort); if (StringUtils.isEmpty(searchText)) { - rolloutBeans = getRolloutManagement().findAllRolloutsWithDetailedStatus(pageRequest, false); + rolloutBeans = getRolloutManagement().findAllWithDetailedStatus(pageRequest, false); } else { - rolloutBeans = getRolloutManagement().findRolloutWithDetailedStatusByFilters(pageRequest, searchText, + rolloutBeans = getRolloutManagement().findByFiltersWithDetailedStatus(pageRequest, searchText, false); } return getProxyRolloutList(rolloutBeans); @@ -137,11 +137,11 @@ public class RolloutBeanQuery extends AbstractBeanQuery { @Override public int size() { - int size = getRolloutManagement().countRolloutsAll().intValue(); + long size = getRolloutManagement().count(); if (!StringUtils.isEmpty(searchText)) { - size = getRolloutManagement().countRolloutsAllByFilters(searchText).intValue(); + size = getRolloutManagement().countByFilters(searchText); } - return size; + return (int) size; } private RolloutManagement getRolloutManagement() { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java index 43062b73c..37593d8be 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java @@ -183,7 +183,7 @@ public class RolloutListGrid extends AbstractGrid { return; } final Optional rollout = rolloutManagement - .findRolloutWithDetailedStatus(rolloutChangeEvent.getRolloutId()); + .getWithDetailedStatus(rolloutChangeEvent.getRolloutId()); if (!rollout.isPresent()) { return; @@ -472,7 +472,7 @@ public class RolloutListGrid extends AbstractGrid { final String rolloutName = (String) row.getItemProperty(SPUILabelDefinitions.VAR_NAME).getValue(); if (RolloutStatus.READY.equals(rolloutStatus)) { - rolloutManagement.startRollout(rolloutId); + rolloutManagement.start(rolloutId); uiNotification.displaySuccess(i18n.getMessage("message.rollout.started", rolloutName)); return; } @@ -499,7 +499,7 @@ public class RolloutListGrid extends AbstractGrid { } private void deleteRollout(final Long rolloutId) { - final Optional rollout = rolloutManagement.findRolloutWithDetailedStatus(rolloutId); + final Optional rollout = rolloutManagement.getWithDetailedStatus(rolloutId); if (!rollout.isPresent()) { return; @@ -514,7 +514,7 @@ public class RolloutListGrid extends AbstractGrid { } final Item row = getContainerDataSource().getItem(rolloutId); final String rolloutName = (String) row.getItemProperty(SPUILabelDefinitions.VAR_NAME).getValue(); - rolloutManagement.deleteRollout(rolloutId); + rolloutManagement.delete(rolloutId); uiNotification.displaySuccess(i18n.getMessage("message.rollout.deleted", rolloutName)); }, UIComponentIdProvider.ROLLOUT_DELETE_CONFIRMATION_DIALOG); UI.getCurrent().addWindow(confirmationDialog.getWindow()); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupBeanQuery.java index a1c8d5263..a57ba9b58 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupBeanQuery.java @@ -105,7 +105,7 @@ public class RolloutGroupBeanQuery extends AbstractBeanQuery proxyRolloutGroupsList = firstPageRolloutGroupSets.getContent(); } else { proxyRolloutGroupsList = getRolloutGroupManagement() - .findAllRolloutGroupsWithDetailedStatus(rolloutId, new PageRequest(startIndex / count, count)) + .findByRolloutWithDetailedStatus(new PageRequest(startIndex / count, count), rolloutId) .getContent(); } } @@ -156,8 +156,8 @@ public class RolloutGroupBeanQuery extends AbstractBeanQuery long size = 0; if (rolloutId != null) { try { - firstPageRolloutGroupSets = getRolloutGroupManagement().findAllRolloutGroupsWithDetailedStatus( - rolloutId, new PageRequest(0, SPUIDefinitions.PAGE_SIZE, sort)); + firstPageRolloutGroupSets = getRolloutGroupManagement().findByRolloutWithDetailedStatus( + new PageRequest(0, SPUIDefinitions.PAGE_SIZE, sort), rolloutId); size = firstPageRolloutGroupSets.getTotalElements(); } catch (final EntityNotFoundException e) { LOG.error("Rollout does not exists. Redirect to Rollouts overview", e); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java index f6d5e1322..fafdefa8d 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java @@ -306,7 +306,7 @@ public class RolloutGroupListGrid extends AbstractGrid { @Override public void click(final RendererClickEvent event) { final Optional group = rolloutGroupManagement - .findRolloutGroupWithDetailedStatus((Long) event.getItemId()); + .getWithDetailedStatus((Long) event.getItemId()); if (!group.isPresent()) { eventBus.publish(this, RolloutEvent.SHOW_ROLLOUTS); return; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsBeanQuery.java index 43b303413..acd3fb76b 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsBeanQuery.java @@ -88,7 +88,7 @@ public class RolloutGroupTargetsBeanQuery extends AbstractBeanQuery } return rolloutGroup.map(group -> getProxyRolloutGroupTargetsList(getRolloutGroupManagement() - .findAllTargetsWithActionStatus(new PageRequest(startIndex / count, count), group.getId()) + .findAllTargetsOfRolloutGroupWithActionStatus(new PageRequest(startIndex / count, count), group.getId()) .getContent())).orElse(Collections.emptyList()); } @@ -134,7 +134,7 @@ public class RolloutGroupTargetsBeanQuery extends AbstractBeanQuery try { firstPageTargetSets = rolloutGroup.map(group -> getRolloutGroupManagement() - .findAllTargetsWithActionStatus(new PageRequest(0, SPUIDefinitions.PAGE_SIZE, sort), group.getId())) + .findAllTargetsOfRolloutGroupWithActionStatus(new PageRequest(0, SPUIDefinitions.PAGE_SIZE, sort), group.getId())) .orElse(null); size = firstPageTargetSets == null ? 0 : firstPageTargetSets.getTotalElements(); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/DefaultDistributionSetTypeLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/DefaultDistributionSetTypeLayout.java index 35808cfd2..7f2255d8f 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/DefaultDistributionSetTypeLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/DefaultDistributionSetTypeLayout.java @@ -80,7 +80,7 @@ public class DefaultDistributionSetTypeLayout extends BaseConfigurationView { hlayout.setComponentAlignment(configurationLabel, Alignment.MIDDLE_LEFT); final Iterable distributionSetTypeCollection = distributionSetTypeManagement - .findDistributionSetTypesAll(new PageRequest(0, 100)); + .findAll(new PageRequest(0, 100)); combobox.setId(UIComponentIdProvider.SYSTEM_CONFIGURATION_DEFAULTDIS_COMBOBOX); combobox.setNullSelectionAllowed(false);