Extended tests for tag toggle and fixed a typo on the assigment result

classes.

Signed-off-by: Kai Zimmermann <kai.zimmermann@bosch-si.com>
This commit is contained in:
Kai Zimmermann
2016-03-27 10:39:29 +02:00
parent c9566e61ce
commit 8a26ded4c4
22 changed files with 232 additions and 183 deletions

View File

@@ -8,14 +8,14 @@
*/ */
package org.eclipse.hawkbit.eventbus.event; package org.eclipse.hawkbit.eventbus.event;
import org.eclipse.hawkbit.repository.model.DistributionSetTagAssigmentResult; import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult;
/** /**
* A event for assignment target tag. * A event for assignment target tag.
*/ */
public class DistributionSetTagAssigmentResultEvent { public class DistributionSetTagAssigmentResultEvent {
private final DistributionSetTagAssigmentResult assigmentResult; private final DistributionSetTagAssignmentResult assigmentResult;
/** /**
* Constructor. * Constructor.
@@ -23,11 +23,11 @@ public class DistributionSetTagAssigmentResultEvent {
* @param assigmentResult * @param assigmentResult
* the assignment result- * the assignment result-
*/ */
public DistributionSetTagAssigmentResultEvent(final DistributionSetTagAssigmentResult assigmentResult) { public DistributionSetTagAssigmentResultEvent(final DistributionSetTagAssignmentResult assigmentResult) {
this.assigmentResult = assigmentResult; this.assigmentResult = assigmentResult;
} }
public DistributionSetTagAssigmentResult getAssigmentResult() { public DistributionSetTagAssignmentResult getAssigmentResult() {
return assigmentResult; return assigmentResult;
} }

View File

@@ -8,14 +8,14 @@
*/ */
package org.eclipse.hawkbit.eventbus.event; package org.eclipse.hawkbit.eventbus.event;
import org.eclipse.hawkbit.repository.model.TargetTagAssigmentResult; import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult;
/** /**
* A event for assignment target tag. * A event for assignment target tag.
*/ */
public class TargetTagAssigmentResultEvent { public class TargetTagAssigmentResultEvent {
private final TargetTagAssigmentResult assigmentResult; private final TargetTagAssignmentResult assigmentResult;
/** /**
* Constructor. * Constructor.
@@ -23,11 +23,11 @@ public class TargetTagAssigmentResultEvent {
* @param assigmentResult * @param assigmentResult
* the assignment result- * the assignment result-
*/ */
public TargetTagAssigmentResultEvent(final TargetTagAssigmentResult assigmentResult) { public TargetTagAssigmentResultEvent(final TargetTagAssignmentResult assigmentResult) {
this.assigmentResult = assigmentResult; this.assigmentResult = assigmentResult;
} }
public TargetTagAssigmentResult getAssigmentResult() { public TargetTagAssignmentResult getAssigmentResult() {
return assigmentResult; return assigmentResult;
} }

View File

@@ -38,7 +38,7 @@ import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetMetadata; import org.eclipse.hawkbit.repository.model.DistributionSetMetadata;
import org.eclipse.hawkbit.repository.model.DistributionSetMetadata_; import org.eclipse.hawkbit.repository.model.DistributionSetMetadata_;
import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.DistributionSetTag;
import org.eclipse.hawkbit.repository.model.DistributionSetTagAssigmentResult; import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult;
import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.DistributionSetType;
import org.eclipse.hawkbit.repository.model.DistributionSetTypeElement; import org.eclipse.hawkbit.repository.model.DistributionSetTypeElement;
import org.eclipse.hawkbit.repository.model.DistributionSet_; import org.eclipse.hawkbit.repository.model.DistributionSet_;
@@ -68,9 +68,6 @@ import com.google.common.eventbus.EventBus;
/** /**
* Business facade for managing the {@link DistributionSet}s. * Business facade for managing the {@link DistributionSet}s.
* *
*
*
*
*/ */
@Transactional(readOnly = true) @Transactional(readOnly = true)
@Validated @Validated
@@ -140,15 +137,15 @@ public class DistributionSetManagement {
* @param sets * @param sets
* to toggle for * to toggle for
* @param tag * @param tag
* to toogle * to toggle
* @return {@link DistributionSetTagAssigmentResult} with all metadata of * @return {@link DistributionSetTagAssignmentResult} with all meta data of
* the assignment outcome. * the assignment outcome.
*/ */
@Modifying @Modifying
@Transactional @Transactional
@NotNull @NotNull
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
public DistributionSetTagAssigmentResult toggleTagAssignment(@NotEmpty final List<DistributionSet> sets, public DistributionSetTagAssignmentResult toggleTagAssignment(@NotEmpty final List<DistributionSet> sets,
@NotNull final DistributionSetTag tag) { @NotNull final DistributionSetTag tag) {
return toggleTagAssignment(sets.stream().map(ds -> ds.getId()).collect(Collectors.toList()), tag.getName()); return toggleTagAssignment(sets.stream().map(ds -> ds.getId()).collect(Collectors.toList()), tag.getName());
} }
@@ -163,42 +160,42 @@ public class DistributionSetManagement {
* to toggle for * to toggle for
* @param tagName * @param tagName
* to toggle * to toggle
* @return {@link DistributionSetTagAssigmentResult} with all metadata of * @return {@link DistributionSetTagAssignmentResult} with all meta data of
* the assignment outcome. * the assignment outcome.
*/ */
@Modifying @Modifying
@Transactional @Transactional
@NotNull @NotNull
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
public DistributionSetTagAssigmentResult toggleTagAssignment(@NotEmpty final Collection<Long> dsIds, public DistributionSetTagAssignmentResult toggleTagAssignment(@NotEmpty final Collection<Long> dsIds,
@NotNull final String tagName) { @NotNull final String tagName) {
final Iterable<DistributionSet> sets = findDistributionSetListWithDetails(dsIds); final Iterable<DistributionSet> sets = findDistributionSetListWithDetails(dsIds);
final DistributionSetTag myTag = tagManagement.findDistributionSetTag(tagName); final DistributionSetTag myTag = tagManagement.findDistributionSetTag(tagName);
DistributionSetTagAssigmentResult result; DistributionSetTagAssignmentResult result;
final List<DistributionSet> allDSs = new ArrayList<>(); final List<DistributionSet> toBeChangedDSs = new ArrayList<>();
for (final DistributionSet set : sets) { for (final DistributionSet set : sets) {
if (set.getTags().add(myTag)) { if (set.getTags().add(myTag)) {
allDSs.add(set); toBeChangedDSs.add(set);
} }
} }
// unassigment case // un-assignment case
if (allDSs.isEmpty()) { if (toBeChangedDSs.isEmpty()) {
for (final DistributionSet set : sets) { for (final DistributionSet set : sets) {
if (set.getTags().remove(myTag)) { if (set.getTags().remove(myTag)) {
allDSs.add(set); toBeChangedDSs.add(set);
} }
} }
result = new DistributionSetTagAssigmentResult(dsIds.size() - allDSs.size(), 0, allDSs.size(), result = new DistributionSetTagAssignmentResult(dsIds.size() - toBeChangedDSs.size(), 0, toBeChangedDSs.size(),
Collections.emptyList(), distributionSetRepository.save(allDSs), myTag); Collections.emptyList(), distributionSetRepository.save(toBeChangedDSs), myTag);
} else { } else {
result = new DistributionSetTagAssigmentResult(dsIds.size() - allDSs.size(), allDSs.size(), 0, result = new DistributionSetTagAssignmentResult(dsIds.size() - toBeChangedDSs.size(), toBeChangedDSs.size(), 0,
distributionSetRepository.save(allDSs), Collections.emptyList(), myTag); distributionSetRepository.save(toBeChangedDSs), Collections.emptyList(), myTag);
} }
final DistributionSetTagAssigmentResult resultAssignment = result; final DistributionSetTagAssignmentResult resultAssignment = result;
afterCommit.afterCommit(() -> eventBus.post(new DistributionSetTagAssigmentResultEvent(resultAssignment))); afterCommit.afterCommit(() -> eventBus.post(new DistributionSetTagAssigmentResultEvent(resultAssignment)));
// no reason to persist the tag // no reason to persist the tag
@@ -436,7 +433,7 @@ public class DistributionSetManagement {
* @param spec * @param spec
* of the search * of the search
* @param pageable * @param pageable
* parametsr for paging * parameter for paging
* *
* @return the found {@link SoftwareModuleType}s * @return the found {@link SoftwareModuleType}s
*/ */
@@ -1059,7 +1056,7 @@ public class DistributionSetManagement {
afterCommit.afterCommit(() -> { afterCommit.afterCommit(() -> {
final DistributionSetTagAssigmentResult result = new DistributionSetTagAssigmentResult(0, save.size(), 0, final DistributionSetTagAssignmentResult result = new DistributionSetTagAssignmentResult(0, save.size(), 0,
save, Collections.emptyList(), tag); save, Collections.emptyList(), tag);
eventBus.post(new DistributionSetTagAssigmentResultEvent(result)); eventBus.post(new DistributionSetTagAssigmentResultEvent(result));
}); });

View File

@@ -258,10 +258,6 @@ public class SoftwareManagement {
return artifactManagement.findSoftwareModuleById(id); return artifactManagement.findSoftwareModuleById(id);
} }
// TODO: discuss this method, does not seem to make sense to search by name
// and version without type. It also makes no sense to return collection
// here. It should be a single result based on ytpe,name,version (like the
// constraint).
/** /**
* retrieves {@link SoftwareModule}s by their name AND version. * retrieves {@link SoftwareModule}s by their name AND version.
* *
@@ -269,13 +265,15 @@ public class SoftwareManagement {
* of the {@link SoftwareModule} * of the {@link SoftwareModule}
* @param version * @param version
* of the {@link SoftwareModule} * of the {@link SoftwareModule}
* @return the found {@link SoftwareModule}s * @param type
* of the {@link SoftwareModule}
* @return the found {@link SoftwareModule} or <code>null</code>
*/ */
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
public List<SoftwareModule> findSoftwareModuleByNameAndVersion(@NotEmpty final String name, public SoftwareModule findSoftwareModuleByNameAndVersion(@NotEmpty final String name,
@NotEmpty final String version) { @NotEmpty final String version, @NotNull final SoftwareModuleType type) {
return softwareModuleRepository.findByNameAndVersion(name, version); return softwareModuleRepository.findOneByNameAndVersionAndType(name, version, type);
} }
/** /**

View File

@@ -43,15 +43,19 @@ public interface SoftwareModuleRepository
Long countByType(SoftwareModuleType type); Long countByType(SoftwareModuleType type);
/** /**
* Retrieves {@link SoftwareModule}s by filtering on name AND version. * Retrieves {@link SoftwareModule} by filtering on name AND version AND
* type (which is unique per tenant.
* *
* @param name * @param name
* to be filtered on * to be filtered on
* @param version * @param version
* to be filtered on * to be filtered on
* @return the found {@link SoftwareModule}s with the given name AND verion * @param type
* to be filtered on
* @return the found {@link SoftwareModule} with the given name AND version
* AND type
*/ */
List<SoftwareModule> findByNameAndVersion(String name, String version); SoftwareModule findOneByNameAndVersionAndType(String name, String version, SoftwareModuleType type);
/** /**
* deletes the {@link SoftwareModule}s with the given IDs. * deletes the {@link SoftwareModule}s with the given IDs.

View File

@@ -11,10 +11,10 @@ package org.eclipse.hawkbit.repository.model;
import java.util.List; import java.util.List;
/** /**
* Result object for {@link DistributionSetTag} assigments. * Result object for {@link DistributionSetTag} assignments.
* *
*/ */
public class DistributionSetTagAssigmentResult extends AssignmentResult { public class DistributionSetTagAssignmentResult extends AssignmentResult {
private final int unassigned; private final int unassigned;
private final List<DistributionSet> assignedDs; private final List<DistributionSet> assignedDs;
@@ -37,7 +37,7 @@ public class DistributionSetTagAssigmentResult extends AssignmentResult {
* @param distributionSetTag * @param distributionSetTag
* the assigned or unassigned tag * the assigned or unassigned tag
*/ */
public DistributionSetTagAssigmentResult(final int alreadyAssigned, final int assigned, final int unassigned, public DistributionSetTagAssignmentResult(final int alreadyAssigned, final int assigned, final int unassigned,
final List<DistributionSet> assignedDs, final List<DistributionSet> unassignedDs, final List<DistributionSet> assignedDs, final List<DistributionSet> unassignedDs,
final DistributionSetTag distributionSetTag) { final DistributionSetTag distributionSetTag) {
super(assigned, alreadyAssigned); super(assigned, alreadyAssigned);
@@ -47,30 +47,18 @@ public class DistributionSetTagAssigmentResult extends AssignmentResult {
this.distributionSetTag = distributionSetTag; this.distributionSetTag = distributionSetTag;
} }
/**
* @return the unassigned
*/
public int getUnassigned() { public int getUnassigned() {
return unassigned; return unassigned;
} }
/**
* @return the distributionSetTag
*/
public DistributionSetTag getDistributionSetTag() { public DistributionSetTag getDistributionSetTag() {
return distributionSetTag; return distributionSetTag;
} }
/**
* @return the assignedDs
*/
public List<DistributionSet> getAssignedDs() { public List<DistributionSet> getAssignedDs() {
return assignedDs; return assignedDs;
} }
/**
* @return the unassignedDs
*/
public List<DistributionSet> getUnassignedDs() { public List<DistributionSet> getUnassignedDs() {
return unassignedDs; return unassignedDs;
} }

View File

@@ -11,13 +11,10 @@ package org.eclipse.hawkbit.repository.model;
import java.util.List; import java.util.List;
/** /**
* Result object for {@link TargetTag} assigments. * Result object for {@link TargetTag} assignments.
*
*
*
* *
*/ */
public class TargetTagAssigmentResult extends AssignmentResult { public class TargetTagAssignmentResult extends AssignmentResult {
private final int unassigned; private final int unassigned;
private final List<Target> assignedTargets; private final List<Target> assignedTargets;
@@ -40,7 +37,7 @@ public class TargetTagAssigmentResult extends AssignmentResult {
* @param targetTag * @param targetTag
* the assigned or unassigned tag * the assigned or unassigned tag
*/ */
public TargetTagAssigmentResult(final int alreadyAssigned, final int assigned, final int unassigned, public TargetTagAssignmentResult(final int alreadyAssigned, final int assigned, final int unassigned,
final List<Target> assignedTargets, final List<Target> unassignedTargets, final TargetTag targetTag) { final List<Target> assignedTargets, final List<Target> unassignedTargets, final TargetTag targetTag) {
super(assigned, alreadyAssigned); super(assigned, alreadyAssigned);
this.unassigned = unassigned; this.unassigned = unassigned;
@@ -49,23 +46,14 @@ public class TargetTagAssigmentResult extends AssignmentResult {
this.targetTag = targetTag; this.targetTag = targetTag;
} }
/**
* @return the unassigned
*/
public int getUnassigned() { public int getUnassigned() {
return unassigned; return unassigned;
} }
/**
* @return the assignedTargets
*/
public List<Target> getAssignedTargets() { public List<Target> getAssignedTargets() {
return assignedTargets; return assignedTargets;
} }
/**
* @return the unassignedTargets
*/
public List<Target> getUnassignedTargets() { public List<Target> getUnassignedTargets() {
return unassignedTargets; return unassignedTargets;
} }

View File

@@ -143,7 +143,7 @@ public class TestDataUtil {
} }
public static List<DistributionSetTag> generateDistributionSetTags(final int number) { public static List<DistributionSetTag> generateDistributionSetTags(final int number) {
final List<DistributionSetTag> result = new ArrayList<DistributionSetTag>(); final List<DistributionSetTag> result = new ArrayList<>();
for (int i = 0; i < number; i++) { for (int i = 0; i < number; i++) {
result.add(new DistributionSetTag("tag" + i, "tagdesc" + i, "" + i)); result.add(new DistributionSetTag("tag" + i, "tagdesc" + i, "" + i));

View File

@@ -9,7 +9,6 @@
package org.eclipse.hawkbit.repository; package org.eclipse.hawkbit.repository;
import static org.fest.assertions.api.Assertions.assertThat; import static org.fest.assertions.api.Assertions.assertThat;
import static org.junit.Assert.fail;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@@ -43,7 +42,7 @@ public class ControllerManagementTest extends AbstractIntegrationTest {
distributionSetManagement); distributionSetManagement);
Target savedTarget = targetManagement.createTarget(target); Target savedTarget = targetManagement.createTarget(target);
final List<Target> toAssign = new ArrayList<Target>(); final List<Target> toAssign = new ArrayList<>();
toAssign.add(savedTarget); toAssign.add(savedTarget);
assertThat(savedTarget.getTargetInfo().getUpdateStatus()).isEqualTo(TargetUpdateStatus.UNKNOWN); assertThat(savedTarget.getTargetInfo().getUpdateStatus()).isEqualTo(TargetUpdateStatus.UNKNOWN);
@@ -74,8 +73,8 @@ public class ControllerManagementTest extends AbstractIntegrationTest {
.isEqualTo(3); .isEqualTo(3);
} }
@Test @Test(expected = ConstraintViolationException.class)
@Description("Register a controller which not exist") @Description("Register a controller which does not exist")
public void testfindOrRegisterTargetIfItDoesNotexist() { public void testfindOrRegisterTargetIfItDoesNotexist() {
final Target target = controllerManagament.findOrRegisterTargetIfItDoesNotexist("AA", null); final Target target = controllerManagament.findOrRegisterTargetIfItDoesNotexist("AA", null);
assertThat(target).as("target should not be null").isNotNull(); assertThat(target).as("target should not be null").isNotNull();
@@ -84,12 +83,8 @@ public class ControllerManagementTest extends AbstractIntegrationTest {
assertThat(target).as("Target should be the equals").isEqualTo(sameTarget); assertThat(target).as("Target should be the equals").isEqualTo(sameTarget);
assertThat(targetRepository.count()).as("Only 1 target should be registred").isEqualTo(1L); assertThat(targetRepository.count()).as("Only 1 target should be registred").isEqualTo(1L);
try { // throws exception
controllerManagament.findOrRegisterTargetIfItDoesNotexist("", null); controllerManagament.findOrRegisterTargetIfItDoesNotexist("", null);
fail("target with empty controller id should not be registred");
} catch (final ConstraintViolationException e) {
// ok
}
} }
@Test @Test
@@ -101,7 +96,7 @@ public class ControllerManagementTest extends AbstractIntegrationTest {
final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement, final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement,
distributionSetManagement); distributionSetManagement);
Target savedTarget = targetManagement.createTarget(target); Target savedTarget = targetManagement.createTarget(target);
final List<Target> toAssign = new ArrayList<Target>(); final List<Target> toAssign = new ArrayList<>();
toAssign.add(savedTarget); toAssign.add(savedTarget);
savedTarget = deploymentManagement.assignDistributionSet(ds, toAssign).getAssignedTargets().iterator().next(); savedTarget = deploymentManagement.assignDistributionSet(ds, toAssign).getAssignedTargets().iterator().next();
Action savedAction = deploymentManagement.findActiveActionsByTarget(savedTarget).get(0); Action savedAction = deploymentManagement.findActiveActionsByTarget(savedTarget).get(0);
@@ -124,7 +119,7 @@ public class ControllerManagementTest extends AbstractIntegrationTest {
final ActionStatus actionStatusMessage3 = new ActionStatus(savedAction, Action.Status.FINISHED, final ActionStatus actionStatusMessage3 = new ActionStatus(savedAction, Action.Status.FINISHED,
System.currentTimeMillis()); System.currentTimeMillis());
actionStatusMessage3.addMessage("finish"); actionStatusMessage3.addMessage("finish");
savedAction = controllerManagament.addUpdateActionStatus(actionStatusMessage3, savedAction); controllerManagament.addUpdateActionStatus(actionStatusMessage3, savedAction);
targetManagement.findTargetByControllerID("Rabbit").getTargetInfo().getUpdateStatus(); targetManagement.findTargetByControllerID("Rabbit").getTargetInfo().getUpdateStatus();

View File

@@ -44,15 +44,12 @@ import ru.yandex.qatools.allure.annotations.Features;
import ru.yandex.qatools.allure.annotations.Stories; import ru.yandex.qatools.allure.annotations.Stories;
/** /**
* {@link SoftwareManagement} test focused on {@link DistributionSet} and * {@link DistributionSetManagement} tests.
* {@link DistributionSetType} related stuff.
*
*
* *
*/ */
@Features("Component Tests - Repository") @Features("Component Tests - Repository")
@Stories("Software Management") @Stories("DistributionSet Management")
public class SoftwareManagementForDSTest extends AbstractIntegrationTest { public class DistributionSetManagementTest extends AbstractIntegrationTest {
@Test @Test
@Description("Tests the successfull module update of unused distribution set type which is in fact allowed.") @Description("Tests the successfull module update of unused distribution set type which is in fact allowed.")
@@ -159,8 +156,6 @@ public class SoftwareManagementForDSTest extends AbstractIntegrationTest {
assertThat(distributionSetManagement.findDistributionSetTypeByKey("softdeleted").isDeleted()).isEqualTo(true); assertThat(distributionSetManagement.findDistributionSetTypeByKey("softdeleted").isDeleted()).isEqualTo(true);
} }
// TODO: kzimmerm: test N+1
@Test(expected = EntityAlreadyExistsException.class) @Test(expected = EntityAlreadyExistsException.class)
@Description("Ensures that it is not possible to create a DS that already exists (unique constraint is on name,version for DS).") @Description("Ensures that it is not possible to create a DS that already exists (unique constraint is on name,version for DS).")
public void createDuplicateDistributionSetsFailsWithException() { public void createDuplicateDistributionSetsFailsWithException() {

View File

@@ -10,9 +10,11 @@ package org.eclipse.hawkbit.repository;
import static org.fest.assertions.api.Assertions.assertThat; import static org.fest.assertions.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import org.eclipse.hawkbit.AbstractIntegrationTest; import org.eclipse.hawkbit.AbstractIntegrationTest;
import org.eclipse.hawkbit.TestDataUtil; import org.eclipse.hawkbit.TestDataUtil;
@@ -20,9 +22,11 @@ import org.eclipse.hawkbit.repository.DistributionSetFilter.DistributionSetFilte
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetTag; 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.Tag;
import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetTag; import org.eclipse.hawkbit.repository.model.TargetTag;
import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -158,6 +162,98 @@ public class TagManagementTest extends AbstractIntegrationTest {
return new DistributionSetFilterBuilder(); 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.")
public void assignAndUnassignDistributionSetTags() {
final List<DistributionSet> groupA = TestDataUtil.generateDistributionSets(20, softwareManagement,
distributionSetManagement);
final List<DistributionSet> groupB = TestDataUtil.generateDistributionSets("unassigned", 20, softwareManagement,
distributionSetManagement);
final DistributionSetTag tag = tagManagement
.createDistributionSetTag(new DistributionSetTag("tag1", "tagdesc1", ""));
// toggle A only -> A is now assigned
DistributionSetTagAssignmentResult result = distributionSetManagement.toggleTagAssignment(groupA, tag);
assertThat(result.getAlreadyAssigned()).isEqualTo(0);
assertThat(result.getAssigned()).isEqualTo(20);
assertThat(result.getAssignedDs()).containsAll(distributionSetManagement.findDistributionSetListWithDetails(
groupA.stream().map(set -> set.getId()).collect(Collectors.toList())));
assertThat(result.getUnassigned()).isEqualTo(0);
assertThat(result.getUnassignedDs()).isEmpty();
assertThat(result.getDistributionSetTag()).isEqualTo(tag);
// toggle A+B -> A is still assigned and B is assigned as well
result = distributionSetManagement.toggleTagAssignment(concat(groupA, groupB), tag);
assertThat(result.getAlreadyAssigned()).isEqualTo(20);
assertThat(result.getAssigned()).isEqualTo(20);
assertThat(result.getAssignedDs()).containsAll(distributionSetManagement.findDistributionSetListWithDetails(
groupB.stream().map(set -> set.getId()).collect(Collectors.toList())));
assertThat(result.getUnassigned()).isEqualTo(0);
assertThat(result.getUnassignedDs()).isEmpty();
assertThat(result.getDistributionSetTag()).isEqualTo(tag);
// toggle A+B -> both unassigned
result = distributionSetManagement.toggleTagAssignment(concat(groupA, groupB), tag);
assertThat(result.getAlreadyAssigned()).isEqualTo(0);
assertThat(result.getAssigned()).isEqualTo(0);
assertThat(result.getAssignedDs()).isEmpty();
assertThat(result.getUnassigned()).isEqualTo(40);
assertThat(result.getUnassignedDs()).containsAll(distributionSetManagement.findDistributionSetListWithDetails(
concat(groupB, groupA).stream().map(set -> set.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<Target> groupA = targetManagement.createTargets(TestDataUtil.generateTargets(20, ""));
final List<Target> groupB = targetManagement.createTargets(TestDataUtil.generateTargets(20, "groupb"));
final TargetTag tag = tagManagement.createTargetTag(new TargetTag("tag1", "tagdesc1", ""));
// toggle A only -> A is now assigned
TargetTagAssignmentResult result = targetManagement.toggleTagAssignment(groupA, tag);
assertThat(result.getAlreadyAssigned()).isEqualTo(0);
assertThat(result.getAssigned()).isEqualTo(20);
assertThat(result.getAssignedTargets()).containsAll(targetManagement.findTargetsByControllerIDsWithTags(
groupA.stream().map(target -> target.getControllerId()).collect(Collectors.toList())));
assertThat(result.getUnassigned()).isEqualTo(0);
assertThat(result.getUnassignedTargets()).isEmpty();
assertThat(result.getTargetTag()).isEqualTo(tag);
// toggle A+B -> A is still assigned and B is assigned as well
result = targetManagement.toggleTagAssignment(concat(groupA, groupB), tag);
assertThat(result.getAlreadyAssigned()).isEqualTo(20);
assertThat(result.getAssigned()).isEqualTo(20);
assertThat(result.getAssignedTargets()).containsAll(targetManagement.findTargetsByControllerIDsWithTags(
groupB.stream().map(target -> target.getControllerId()).collect(Collectors.toList())));
assertThat(result.getUnassigned()).isEqualTo(0);
assertThat(result.getUnassignedTargets()).isEmpty();
assertThat(result.getTargetTag()).isEqualTo(tag);
// toggle A+B -> both unassigned
result = targetManagement.toggleTagAssignment(concat(groupA, groupB), tag);
assertThat(result.getAlreadyAssigned()).isEqualTo(0);
assertThat(result.getAssigned()).isEqualTo(0);
assertThat(result.getAssignedTargets()).isEmpty();
assertThat(result.getUnassigned()).isEqualTo(40);
assertThat(result.getUnassignedTargets()).containsAll(targetManagement.findTargetsByControllerIDsWithTags(
concat(groupB, groupA).stream().map(target -> target.getControllerId()).collect(Collectors.toList())));
assertThat(result.getTargetTag()).isEqualTo(tag);
}
@SafeVarargs
private final <T> List<T> concat(final List<T>... targets) {
final List<T> result = new ArrayList<>();
Arrays.asList(targets).forEach(result::addAll);
return result;
}
@Test @Test
@Description("Ensures that all tags are retrieved through repository.") @Description("Ensures that all tags are retrieved through repository.")
public void findAllTargetTags() { public void findAllTargetTags() {
@@ -266,48 +362,38 @@ public class TagManagementTest extends AbstractIntegrationTest {
} }
} }
@Test(expected = EntityAlreadyExistsException.class)
@Description("Ensures that a tag cannot be created if one exists already with that name (ecpects EntityAlreadyExistsException).") @Description("Ensures that a tag cannot be created if one exists already with that name (ecpects EntityAlreadyExistsException).")
public void failedDuplicateTargetTagNameException() { public void failedDuplicateTargetTagNameException() {
tagManagement.createTargetTag(new TargetTag("A")); tagManagement.createTargetTag(new TargetTag("A"));
try {
tagManagement.createTargetTag(new TargetTag("A")); tagManagement.createTargetTag(new TargetTag("A"));
fail("Expected EntityAlreadyExistsException");
} catch (final EntityAlreadyExistsException e) {
}
} }
@Test(expected = EntityAlreadyExistsException.class)
@Description("Ensures that a tag cannot be updated to a name that already exists on another tag (ecpects EntityAlreadyExistsException).") @Description("Ensures that a tag cannot be updated to a name that already exists on another tag (ecpects EntityAlreadyExistsException).")
public void failedDuplicateTargetTagNameExceptionAfterUpdate() { public void failedDuplicateTargetTagNameExceptionAfterUpdate() {
tagManagement.createTargetTag(new TargetTag("A")); tagManagement.createTargetTag(new TargetTag("A"));
final TargetTag tag = tagManagement.createTargetTag(new TargetTag("B")); final TargetTag tag = tagManagement.createTargetTag(new TargetTag("B"));
tag.setName("A"); tag.setName("A");
try {
tagManagement.updateTargetTag(tag); tagManagement.updateTargetTag(tag);
fail("Expected EntityAlreadyExistsException");
} catch (final EntityAlreadyExistsException e) {
}
} }
@Test(expected = EntityAlreadyExistsException.class)
@Description("Ensures that a tag cannot be created if one exists already with that name (ecpects EntityAlreadyExistsException).") @Description("Ensures that a tag cannot be created if one exists already with that name (ecpects EntityAlreadyExistsException).")
public void failedDuplicateDsTagNameException() { public void failedDuplicateDsTagNameException() {
tagManagement.createDistributionSetTag(new DistributionSetTag("A")); tagManagement.createDistributionSetTag(new DistributionSetTag("A"));
try {
tagManagement.createDistributionSetTag(new DistributionSetTag("A")); tagManagement.createDistributionSetTag(new DistributionSetTag("A"));
fail("Expected EntityAlreadyExistsException");
} catch (final EntityAlreadyExistsException e) {
}
} }
@Test(expected = EntityAlreadyExistsException.class)
@Description("Ensures that a tag cannot be updated to a name that already exists on another tag (ecpects EntityAlreadyExistsException).") @Description("Ensures that a tag cannot be updated to a name that already exists on another tag (ecpects EntityAlreadyExistsException).")
public void failedDuplicateDsTagNameExceptionAfterUpdate() { public void failedDuplicateDsTagNameExceptionAfterUpdate() {
tagManagement.createDistributionSetTag(new DistributionSetTag("A")); tagManagement.createDistributionSetTag(new DistributionSetTag("A"));
final DistributionSetTag tag = tagManagement.createDistributionSetTag(new DistributionSetTag("B")); final DistributionSetTag tag = tagManagement.createDistributionSetTag(new DistributionSetTag("B"));
tag.setName("A"); tag.setName("A");
try {
tagManagement.updateDistributionSetTag(tag); tagManagement.updateDistributionSetTag(tag);
fail("Expected EntityAlreadyExistsException");
} catch (final EntityAlreadyExistsException e) {
}
} }
@Test @Test

View File

@@ -17,7 +17,7 @@ import org.eclipse.hawkbit.repository.TagManagement;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.DistributionSetTag;
import org.eclipse.hawkbit.repository.model.DistributionSetTagAssigmentResult; import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult;
import org.eclipse.hawkbit.repository.rsql.RSQLUtility; import org.eclipse.hawkbit.repository.rsql.RSQLUtility;
import org.eclipse.hawkbit.rest.resource.api.DistributionSetTagRestApi; import org.eclipse.hawkbit.rest.resource.api.DistributionSetTagRestApi;
import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetRest; import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetRest;
@@ -135,7 +135,7 @@ public class DistributionSetTagResource implements DistributionSetTagRestApi {
final DistributionSetTag tag = findDistributionTagById(distributionsetTagId); final DistributionSetTag tag = findDistributionTagById(distributionsetTagId);
final DistributionSetTagAssigmentResult assigmentResult = this.distributionSetManagement final DistributionSetTagAssignmentResult assigmentResult = this.distributionSetManagement
.toggleTagAssignment(findDistributionSetIds(assignedDSRequestBodies), tag.getName()); .toggleTagAssignment(findDistributionSetIds(assignedDSRequestBodies), tag.getName());
final DistributionSetTagAssigmentResultRest tagAssigmentResultRest = new DistributionSetTagAssigmentResultRest(); final DistributionSetTagAssigmentResultRest tagAssigmentResultRest = new DistributionSetTagAssigmentResultRest();

View File

@@ -17,7 +17,7 @@ import org.eclipse.hawkbit.repository.TargetManagement;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetTag; import org.eclipse.hawkbit.repository.model.TargetTag;
import org.eclipse.hawkbit.repository.model.TargetTagAssigmentResult; import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult;
import org.eclipse.hawkbit.repository.rsql.RSQLUtility; import org.eclipse.hawkbit.repository.rsql.RSQLUtility;
import org.eclipse.hawkbit.rest.resource.api.TargetTagRestApi; import org.eclipse.hawkbit.rest.resource.api.TargetTagRestApi;
import org.eclipse.hawkbit.rest.resource.model.tag.AssignedTargetRequestBody; import org.eclipse.hawkbit.rest.resource.model.tag.AssignedTargetRequestBody;
@@ -130,7 +130,7 @@ public class TargetTagResource implements TargetTagRestApi {
LOG.debug("Toggle Target assignment {} for target tag {}", assignedTargetRequestBodies.size(), targetTagId); LOG.debug("Toggle Target assignment {} for target tag {}", assignedTargetRequestBodies.size(), targetTagId);
final TargetTag targetTag = findTargetTagById(targetTagId); final TargetTag targetTag = findTargetTagById(targetTagId);
final TargetTagAssigmentResult assigmentResult = this.targetManagement final TargetTagAssignmentResult assigmentResult = this.targetManagement
.toggleTagAssignment(findTargetControllerIds(assignedTargetRequestBodies), targetTag.getName()); .toggleTagAssignment(findTargetControllerIds(assignedTargetRequestBodies), targetTag.getName());
final TargetTagAssigmentResultRest tagAssigmentResultRest = new TargetTagAssigmentResultRest(); final TargetTagAssigmentResultRest tagAssigmentResultRest = new TargetTagAssigmentResultRest();

View File

@@ -773,12 +773,12 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
.andExpect(jsonPath("[2].createdBy", equalTo("uploadTester"))) .andExpect(jsonPath("[2].createdBy", equalTo("uploadTester")))
.andExpect(jsonPath("[2].createdAt", not(equalTo(0)))).andReturn(); .andExpect(jsonPath("[2].createdAt", not(equalTo(0)))).andReturn();
final SoftwareModule osCreated = softwareManagement.findSoftwareModuleByNameAndVersion("name1", "version1") final SoftwareModule osCreated = softwareManagement.findSoftwareModuleByNameAndVersion("name1", "version1",
.get(0); osType);
final SoftwareModule jvmCreated = softwareManagement.findSoftwareModuleByNameAndVersion("name2", "version1") final SoftwareModule jvmCreated = softwareManagement.findSoftwareModuleByNameAndVersion("name2", "version1",
.get(0); runtimeType);
final SoftwareModule ahCreated = softwareManagement.findSoftwareModuleByNameAndVersion("name3", "version1") final SoftwareModule ahCreated = softwareManagement.findSoftwareModuleByNameAndVersion("name3", "version1",
.get(0); appType);
assertThat( assertThat(
JsonPath.compile("[0]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString()) JsonPath.compile("[0]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString())
@@ -930,8 +930,10 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
.andExpect(jsonPath("[1]key", equalTo(knownKey2))) .andExpect(jsonPath("[1]key", equalTo(knownKey2)))
.andExpect(jsonPath("[1]value", equalTo(knownValue2))); .andExpect(jsonPath("[1]value", equalTo(knownValue2)));
final SoftwareModuleMetadata metaKey1 = softwareManagement.findSoftwareModuleMetadata(new SwMetadataCompositeKey(sm, knownKey1)); final SoftwareModuleMetadata metaKey1 = softwareManagement
final SoftwareModuleMetadata metaKey2 = softwareManagement.findSoftwareModuleMetadata(new SwMetadataCompositeKey(sm, knownKey2)); .findSoftwareModuleMetadata(new SwMetadataCompositeKey(sm, knownKey1));
final SoftwareModuleMetadata metaKey2 = softwareManagement
.findSoftwareModuleMetadata(new SwMetadataCompositeKey(sm, knownKey2));
assertThat(metaKey1.getValue()).as("Metadata key is wrong").isEqualTo(knownValue1); assertThat(metaKey1.getValue()).as("Metadata key is wrong").isEqualTo(knownValue1);
assertThat(metaKey2.getValue()).as("Metadata key is wrong").isEqualTo(knownValue2); assertThat(metaKey2.getValue()).as("Metadata key is wrong").isEqualTo(knownValue2);
@@ -957,7 +959,8 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
.andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("key", equalTo(knownKey))).andExpect(jsonPath("value", equalTo(updateValue))); .andExpect(jsonPath("key", equalTo(knownKey))).andExpect(jsonPath("value", equalTo(updateValue)));
final SoftwareModuleMetadata assertDS = softwareManagement.findSoftwareModuleMetadata(new SwMetadataCompositeKey(sm, knownKey)); final SoftwareModuleMetadata assertDS = softwareManagement
.findSoftwareModuleMetadata(new SwMetadataCompositeKey(sm, knownKey));
assertThat(assertDS.getValue()).as("Metadata is wrong").isEqualTo(updateValue); assertThat(assertDS.getValue()).as("Metadata is wrong").isEqualTo(updateValue);
} }

View File

@@ -28,8 +28,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory; import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory;
import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventBus;
import com.vaadin.event.FieldEvents.TextChangeEvent;
import com.vaadin.event.FieldEvents.TextChangeListener;
import com.vaadin.server.FontAwesome; import com.vaadin.server.FontAwesome;
import com.vaadin.spring.annotation.SpringComponent; import com.vaadin.spring.annotation.SpringComponent;
import com.vaadin.spring.annotation.ViewScope; import com.vaadin.spring.annotation.ViewScope;
@@ -245,28 +243,22 @@ public class SoftwareModuleAddUpdateWindow implements Serializable {
} }
private void addDescriptionTextChangeListener() { private void addDescriptionTextChangeListener() {
descTextArea.addTextChangeListener(new TextChangeListener() { descTextArea.addTextChangeListener(event -> {
@Override
public void textChange(final TextChangeEvent event) {
if (event.getText().equals(oldDescriptionValue) && vendorTextField.getValue().equals(oldVendorValue)) { if (event.getText().equals(oldDescriptionValue) && vendorTextField.getValue().equals(oldVendorValue)) {
saveSoftware.setEnabled(false); saveSoftware.setEnabled(false);
} else { } else {
saveSoftware.setEnabled(true); saveSoftware.setEnabled(true);
} }
}
}); });
} }
private void addVendorTextChangeListener() { private void addVendorTextChangeListener() {
vendorTextField.addTextChangeListener(new TextChangeListener() { vendorTextField.addTextChangeListener(event -> {
@Override
public void textChange(final TextChangeEvent event) {
if (event.getText().equals(oldVendorValue) && descTextArea.getValue().equals(oldDescriptionValue)) { if (event.getText().equals(oldVendorValue) && descTextArea.getValue().equals(oldDescriptionValue)) {
saveSoftware.setEnabled(false); saveSoftware.setEnabled(false);
} else { } else {
saveSoftware.setEnabled(true); saveSoftware.setEnabled(true);
} }
}
}); });
} }
@@ -280,7 +272,7 @@ public class SoftwareModuleAddUpdateWindow implements Serializable {
final String description = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue()); final String description = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue());
final String type = typeComboBox.getValue() != null ? typeComboBox.getValue().toString() : null; final String type = typeComboBox.getValue() != null ? typeComboBox.getValue().toString() : null;
if (mandatoryCheck(name, version, type)) { if (mandatoryCheck(name, version, type)) {
if (HawkbitCommonUtil.isDuplicate(name, version)) { if (HawkbitCommonUtil.isDuplicate(name, version, type)) {
uiNotifcation.displayValidationError( uiNotifcation.displayValidationError(
i18n.get("message.duplicate.softwaremodule", new Object[] { name, version })); i18n.get("message.duplicate.softwaremodule", new Object[] { name, version }));
} else { } else {

View File

@@ -26,7 +26,7 @@ import org.eclipse.hawkbit.repository.SpPermissionChecker;
import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.TagManagement;
import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.DistributionSetTag;
import org.eclipse.hawkbit.repository.model.DistributionSetTagAssigmentResult; import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult;
import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent; import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent;
import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent.DistributionComponentEvent; import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent.DistributionComponentEvent;
import org.eclipse.hawkbit.ui.management.event.ManagementUIEvent; import org.eclipse.hawkbit.ui.management.event.ManagementUIEvent;
@@ -100,7 +100,7 @@ public class DistributionTagToken extends AbstractTagToken {
@Override @Override
protected void assignTag(final String tagNameSelected) { protected void assignTag(final String tagNameSelected) {
if (tagNameSelected != null) { if (tagNameSelected != null) {
final DistributionSetTagAssigmentResult result = toggleAssignment(tagNameSelected); final DistributionSetTagAssignmentResult result = toggleAssignment(tagNameSelected);
if (result.getAssigned() >= 1 && NOTAGS_SELECTED) { if (result.getAssigned() >= 1 && NOTAGS_SELECTED) {
eventBus.publish(this, ManagementUIEvent.ASSIGN_DISTRIBUTION_TAG); eventBus.publish(this, ManagementUIEvent.ASSIGN_DISTRIBUTION_TAG);
} }
@@ -109,10 +109,10 @@ public class DistributionTagToken extends AbstractTagToken {
} }
} }
private DistributionSetTagAssigmentResult toggleAssignment(final String tagNameSelected) { private DistributionSetTagAssignmentResult toggleAssignment(final String tagNameSelected) {
final Set<Long> distributionList = new HashSet<>(); final Set<Long> distributionList = new HashSet<>();
distributionList.add(selectedDS.getId()); distributionList.add(selectedDS.getId());
final DistributionSetTagAssigmentResult result = distributionSetManagement.toggleTagAssignment(distributionList, final DistributionSetTagAssignmentResult result = distributionSetManagement.toggleTagAssignment(distributionList,
tagNameSelected); tagNameSelected);
uinotification.displaySuccess(HawkbitCommonUtil.getDistributionTagAssignmentMsg(tagNameSelected, result, i18n)); uinotification.displaySuccess(HawkbitCommonUtil.getDistributionTagAssignmentMsg(tagNameSelected, result, i18n));
return result; return result;
@@ -120,7 +120,7 @@ public class DistributionTagToken extends AbstractTagToken {
@Override @Override
protected void unassignTag(final String tagName) { protected void unassignTag(final String tagName) {
final DistributionSetTagAssigmentResult result = toggleAssignment(tagName); final DistributionSetTagAssignmentResult result = toggleAssignment(tagName);
if (result.getUnassigned() >= 1 && (isClickedTagListEmpty() || getClickedTagList().contains(tagName))) { if (result.getUnassigned() >= 1 && (isClickedTagListEmpty() || getClickedTagList().contains(tagName))) {
eventBus.publish(this, ManagementUIEvent.UNASSIGN_DISTRIBUTION_TAG); eventBus.publish(this, ManagementUIEvent.UNASSIGN_DISTRIBUTION_TAG);
} }
@@ -202,7 +202,7 @@ public class DistributionTagToken extends AbstractTagToken {
@EventBusListenerMethod(scope = EventScope.SESSION) @EventBusListenerMethod(scope = EventScope.SESSION)
void onTargetTagAssigmentResultEvent(final DistributionSetTagAssigmentResultEvent event) { void onTargetTagAssigmentResultEvent(final DistributionSetTagAssigmentResultEvent event) {
final DistributionSetTagAssigmentResult assignmentResult = event.getAssigmentResult(); final DistributionSetTagAssignmentResult assignmentResult = event.getAssigmentResult();
final DistributionSetTag tag = assignmentResult.getDistributionSetTag(); final DistributionSetTag tag = assignmentResult.getDistributionSetTag();
if (isAssign(assignmentResult)) { if (isAssign(assignmentResult)) {
addNewToken(tag.getId()); addNewToken(tag.getId());
@@ -212,7 +212,7 @@ public class DistributionTagToken extends AbstractTagToken {
} }
protected boolean isAssign(final DistributionSetTagAssigmentResult assignmentResult) { protected boolean isAssign(final DistributionSetTagAssignmentResult assignmentResult) {
if (assignmentResult.getAssigned() > 0) { if (assignmentResult.getAssigned() > 0) {
final List<Long> assignedDsNames = assignmentResult.getAssignedDs().stream().map(t -> t.getId()) final List<Long> assignedDsNames = assignmentResult.getAssignedDs().stream().map(t -> t.getId())
.collect(Collectors.toList()); .collect(Collectors.toList());
@@ -223,7 +223,7 @@ public class DistributionTagToken extends AbstractTagToken {
return false; return false;
} }
protected boolean isUnassign(final DistributionSetTagAssigmentResult assignmentResult) { protected boolean isUnassign(final DistributionSetTagAssignmentResult assignmentResult) {
if (assignmentResult.getUnassigned() > 0) { if (assignmentResult.getUnassigned() > 0) {
final List<Long> assignedDsNames = assignmentResult.getUnassignedDs().stream().map(t -> t.getId()) final List<Long> assignedDsNames = assignmentResult.getUnassignedDs().stream().map(t -> t.getId())
.collect(Collectors.toList()); .collect(Collectors.toList());

View File

@@ -19,7 +19,7 @@ import org.eclipse.hawkbit.eventbus.event.TargetTagUpdateEvent;
import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.TargetManagement;
import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetTag; import org.eclipse.hawkbit.repository.model.TargetTag;
import org.eclipse.hawkbit.repository.model.TargetTagAssigmentResult; import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult;
import org.eclipse.hawkbit.ui.management.event.ManagementUIEvent; import org.eclipse.hawkbit.ui.management.event.ManagementUIEvent;
import org.eclipse.hawkbit.ui.management.event.TargetTableEvent; import org.eclipse.hawkbit.ui.management.event.TargetTableEvent;
import org.eclipse.hawkbit.ui.management.event.TargetTableEvent.TargetComponentEvent; import org.eclipse.hawkbit.ui.management.event.TargetTableEvent.TargetComponentEvent;
@@ -68,7 +68,7 @@ public class TargetTagToken extends AbstractTargetTagToken {
@Override @Override
protected void assignTag(final String tagNameSelected) { protected void assignTag(final String tagNameSelected) {
if (tagNameSelected != null) { if (tagNameSelected != null) {
final TargetTagAssigmentResult result = toggleAssignment(tagNameSelected); final TargetTagAssignmentResult result = toggleAssignment(tagNameSelected);
if (result.getAssigned() >= 1 && NOTAGS_SELECTED) { if (result.getAssigned() >= 1 && NOTAGS_SELECTED) {
eventBus.publish(this, ManagementUIEvent.ASSIGN_TARGET_TAG); eventBus.publish(this, ManagementUIEvent.ASSIGN_TARGET_TAG);
} }
@@ -77,17 +77,17 @@ public class TargetTagToken extends AbstractTargetTagToken {
} }
} }
private TargetTagAssigmentResult toggleAssignment(final String tagNameSelected) { private TargetTagAssignmentResult toggleAssignment(final String tagNameSelected) {
final Set<String> targetList = new HashSet<>(); final Set<String> targetList = new HashSet<>();
targetList.add(selectedTarget.getControllerId()); targetList.add(selectedTarget.getControllerId());
final TargetTagAssigmentResult result = targetManagement.toggleTagAssignment(targetList, tagNameSelected); final TargetTagAssignmentResult result = targetManagement.toggleTagAssignment(targetList, tagNameSelected);
uinotification.displaySuccess(HawkbitCommonUtil.getTargetTagAssigmentMsg(tagNameSelected, result, i18n)); uinotification.displaySuccess(HawkbitCommonUtil.getTargetTagAssigmentMsg(tagNameSelected, result, i18n));
return result; return result;
} }
@Override @Override
protected void unassignTag(final String tagName) { protected void unassignTag(final String tagName) {
final TargetTagAssigmentResult result = toggleAssignment(tagName); final TargetTagAssignmentResult result = toggleAssignment(tagName);
if (result.getUnassigned() >= 1 && (isClickedTagListEmpty() || getClickedTagList().contains(tagName))) { if (result.getUnassigned() >= 1 && (isClickedTagListEmpty() || getClickedTagList().contains(tagName))) {
eventBus.publish(this, ManagementUIEvent.UNASSIGN_TARGET_TAG); eventBus.publish(this, ManagementUIEvent.UNASSIGN_TARGET_TAG);
} }
@@ -139,7 +139,7 @@ public class TargetTagToken extends AbstractTargetTagToken {
@EventBusListenerMethod(scope = EventScope.SESSION) @EventBusListenerMethod(scope = EventScope.SESSION)
void onTargetTagAssigmentResultEvent(final TargetTagAssigmentResultEvent event) { void onTargetTagAssigmentResultEvent(final TargetTagAssigmentResultEvent event) {
final TargetTagAssigmentResult assignmentResult = event.getAssigmentResult(); final TargetTagAssignmentResult assignmentResult = event.getAssigmentResult();
final TargetTag targetTag = assignmentResult.getTargetTag(); final TargetTag targetTag = assignmentResult.getTargetTag();
if (isAssign(assignmentResult)) { if (isAssign(assignmentResult)) {
addNewToken(targetTag.getId()); addNewToken(targetTag.getId());
@@ -149,7 +149,7 @@ public class TargetTagToken extends AbstractTargetTagToken {
} }
protected boolean isAssign(final TargetTagAssigmentResult assignmentResult) { protected boolean isAssign(final TargetTagAssignmentResult assignmentResult) {
if (assignmentResult.getAssigned() > 0) { if (assignmentResult.getAssigned() > 0) {
final List<String> assignedTargetNames = assignmentResult.getAssignedTargets().stream() final List<String> assignedTargetNames = assignmentResult.getAssignedTargets().stream()
.map(t -> t.getControllerId()).collect(Collectors.toList()); .map(t -> t.getControllerId()).collect(Collectors.toList());
@@ -160,7 +160,7 @@ public class TargetTagToken extends AbstractTargetTagToken {
return false; return false;
} }
protected boolean isUnassign(final TargetTagAssigmentResult assignmentResult) { protected boolean isUnassign(final TargetTagAssignmentResult assignmentResult) {
if (assignmentResult.getUnassigned() > 0) { if (assignmentResult.getUnassigned() > 0) {
final List<String> unassignedTargetNamesList = assignmentResult.getUnassignedTargets().stream() final List<String> unassignedTargetNamesList = assignmentResult.getUnassignedTargets().stream()
.map(t -> t.getControllerId()).collect(Collectors.toList()); .map(t -> t.getControllerId()).collect(Collectors.toList());

View File

@@ -25,7 +25,7 @@ import org.eclipse.hawkbit.repository.SpPermissionChecker;
import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.TargetManagement;
import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetIdName; import org.eclipse.hawkbit.repository.model.DistributionSetIdName;
import org.eclipse.hawkbit.repository.model.DistributionSetTagAssigmentResult; import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult;
import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetIdName; import org.eclipse.hawkbit.repository.model.TargetIdName;
import org.eclipse.hawkbit.ui.common.table.AbstractTable; import org.eclipse.hawkbit.ui.common.table.AbstractTable;
@@ -360,7 +360,7 @@ public class DistributionTable extends AbstractTable {
final String distTagName = HawkbitCommonUtil.removePrefix(event.getTransferable().getSourceComponent().getId(), final String distTagName = HawkbitCommonUtil.removePrefix(event.getTransferable().getSourceComponent().getId(),
SPUIDefinitions.DISTRIBUTION_TAG_ID_PREFIXS); SPUIDefinitions.DISTRIBUTION_TAG_ID_PREFIXS);
final DistributionSetTagAssigmentResult result = distributionSetManagement.toggleTagAssignment(distList, final DistributionSetTagAssignmentResult result = distributionSetManagement.toggleTagAssignment(distList,
distTagName); distTagName);
notification.displaySuccess(HawkbitCommonUtil.getDistributionTagAssignmentMsg(distTagName, result, i18n)); notification.displaySuccess(HawkbitCommonUtil.getDistributionTagAssignmentMsg(distTagName, result, i18n));
@@ -564,7 +564,7 @@ public class DistributionTable extends AbstractTable {
.getItemProperty(SPUILabelDefinitions.VAR_DIST_ID_NAME).getValue(); .getItemProperty(SPUILabelDefinitions.VAR_DIST_ID_NAME).getValue();
final Button pinBtn = getPinBtn(itemId, dist.getName(), dist.getVersion()); final Button pinBtn = getPinBtn(itemId, dist.getName(), dist.getVersion());
saveDistributionPinnedBtn(pinBtn); saveDistributionPinnedBtn(pinBtn);
pinBtn.addClickListener(event -> addPinClickListener(event)); pinBtn.addClickListener(this::addPinClickListener);
rePinDistribution(pinBtn, dist.getId()); rePinDistribution(pinBtn, dist.getId());
return pinBtn; return pinBtn;
} }

View File

@@ -16,7 +16,7 @@ import java.util.stream.Collectors;
import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.DistributionSetManagement;
import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.repository.SpPermissionChecker;
import org.eclipse.hawkbit.repository.model.DistributionSetIdName; import org.eclipse.hawkbit.repository.model.DistributionSetIdName;
import org.eclipse.hawkbit.repository.model.DistributionSetTagAssigmentResult; import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult;
import org.eclipse.hawkbit.ui.management.state.DistributionTableFilters; import org.eclipse.hawkbit.ui.management.state.DistributionTableFilters;
import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil;
import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.I18N;
@@ -147,7 +147,7 @@ public class DistributionTagDropEvent implements DropHandler {
SPUIDefinitions.DISTRIBUTION_TAG_ID_PREFIXS); SPUIDefinitions.DISTRIBUTION_TAG_ID_PREFIXS);
final List<String> tagsClickedList = distFilterParameters.getDistSetTags(); final List<String> tagsClickedList = distFilterParameters.getDistSetTags();
final DistributionSetTagAssigmentResult result = distributionSetManagement.toggleTagAssignment(distributionList, final DistributionSetTagAssignmentResult result = distributionSetManagement.toggleTagAssignment(distributionList,
distTagName); distTagName);
notification.displaySuccess(HawkbitCommonUtil.getDistributionTagAssignmentMsg(distTagName, result, i18n)); notification.displaySuccess(HawkbitCommonUtil.getDistributionTagAssignmentMsg(distTagName, result, i18n));

View File

@@ -32,7 +32,7 @@ import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetFilterQuery; import org.eclipse.hawkbit.repository.model.TargetFilterQuery;
import org.eclipse.hawkbit.repository.model.TargetIdName; import org.eclipse.hawkbit.repository.model.TargetIdName;
import org.eclipse.hawkbit.repository.model.TargetInfo; import org.eclipse.hawkbit.repository.model.TargetInfo;
import org.eclipse.hawkbit.repository.model.TargetTagAssigmentResult; import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult;
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
import org.eclipse.hawkbit.ui.common.table.AbstractTable; import org.eclipse.hawkbit.ui.common.table.AbstractTable;
import org.eclipse.hawkbit.ui.filter.FilterExpression; import org.eclipse.hawkbit.ui.filter.FilterExpression;
@@ -656,7 +656,7 @@ public class TargetTable extends AbstractTable implements Handler {
} }
final String targTagName = HawkbitCommonUtil.removePrefix(event.getTransferable().getSourceComponent().getId(), final String targTagName = HawkbitCommonUtil.removePrefix(event.getTransferable().getSourceComponent().getId(),
SPUIDefinitions.TARGET_TAG_ID_PREFIXS); SPUIDefinitions.TARGET_TAG_ID_PREFIXS);
final TargetTagAssigmentResult result = targetManagement.toggleTagAssignment(targetList, targTagName); final TargetTagAssignmentResult result = targetManagement.toggleTagAssignment(targetList, targTagName);
final List<String> tagsClickedList = managementUIState.getTargetTableFilters().getClickedTargetTags(); final List<String> tagsClickedList = managementUIState.getTargetTableFilters().getClickedTargetTags();
notification.displaySuccess(HawkbitCommonUtil.getTargetTagAssigmentMsg(targTagName, result, i18n)); notification.displaySuccess(HawkbitCommonUtil.getTargetTagAssigmentMsg(targTagName, result, i18n));

View File

@@ -23,7 +23,7 @@ import org.eclipse.hawkbit.repository.TagManagement;
import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.TargetManagement;
import org.eclipse.hawkbit.repository.model.TargetIdName; import org.eclipse.hawkbit.repository.model.TargetIdName;
import org.eclipse.hawkbit.repository.model.TargetTag; import org.eclipse.hawkbit.repository.model.TargetTag;
import org.eclipse.hawkbit.repository.model.TargetTagAssigmentResult; import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult;
import org.eclipse.hawkbit.ui.common.filterlayout.AbstractFilterButtons; import org.eclipse.hawkbit.ui.common.filterlayout.AbstractFilterButtons;
import org.eclipse.hawkbit.ui.management.event.DragEvent; import org.eclipse.hawkbit.ui.management.event.DragEvent;
import org.eclipse.hawkbit.ui.management.event.ManagementUIEvent; import org.eclipse.hawkbit.ui.management.event.ManagementUIEvent;
@@ -248,7 +248,7 @@ public class TargetTagFilterButtons extends AbstractFilterButtons {
final List<String> tagsClickedList = managementUIState.getTargetTableFilters().getClickedTargetTags(); final List<String> tagsClickedList = managementUIState.getTargetTableFilters().getClickedTargetTags();
final TargetTagAssigmentResult result = targetManagement.toggleTagAssignment(targetList, targTagName); final TargetTagAssignmentResult result = targetManagement.toggleTagAssignment(targetList, targTagName);
notification.displaySuccess(HawkbitCommonUtil.getTargetTagAssigmentMsg(targTagName, result, i18n)); notification.displaySuccess(HawkbitCommonUtil.getTargetTagAssigmentMsg(targTagName, result, i18n));
if (result.getAssigned() >= 1 && managementUIState.getTargetTableFilters().isNoTagSelected()) { if (result.getAssigned() >= 1 && managementUIState.getTargetTableFilters().isNoTagSelected()) {

View File

@@ -25,13 +25,13 @@ import org.apache.commons.lang3.StringUtils;
import org.eclipse.hawkbit.im.authentication.UserPrincipal; import org.eclipse.hawkbit.im.authentication.UserPrincipal;
import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.SoftwareManagement;
import org.eclipse.hawkbit.repository.model.DistributionSetIdName; import org.eclipse.hawkbit.repository.model.DistributionSetIdName;
import org.eclipse.hawkbit.repository.model.DistributionSetTagAssigmentResult; import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult;
import org.eclipse.hawkbit.repository.model.RolloutGroup; import org.eclipse.hawkbit.repository.model.RolloutGroup;
import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
import org.eclipse.hawkbit.repository.model.TargetIdName; import org.eclipse.hawkbit.repository.model.TargetIdName;
import org.eclipse.hawkbit.repository.model.TargetInfo.PollStatus; import org.eclipse.hawkbit.repository.model.TargetInfo.PollStatus;
import org.eclipse.hawkbit.repository.model.TargetTagAssigmentResult; import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult;
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus;
import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus.Status; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus.Status;
@@ -802,13 +802,16 @@ public final class HawkbitCommonUtil {
* as string * as string
* @param version * @param version
* as string * as string
* @param type
* key as string
* @return boolean as flag * @return boolean as flag
*/ */
public static boolean isDuplicate(final String name, final String version) { public static boolean isDuplicate(final String name, final String version, final String type) {
final SoftwareManagement swMgmtService = SpringContextHelper.getBean(SoftwareManagement.class); final SoftwareManagement swMgmtService = SpringContextHelper.getBean(SoftwareManagement.class);
final List<SoftwareModule> swModulesList = swMgmtService.findSoftwareModuleByNameAndVersion(name, version); final SoftwareModule swModule = swMgmtService.findSoftwareModuleByNameAndVersion(name, version,
swMgmtService.findSoftwareModuleTypeByKey(type));
boolean duplicate = false; boolean duplicate = false;
if (swModulesList != null && !swModulesList.isEmpty()) { if (swModule != null) {
duplicate = true; duplicate = true;
} }
return duplicate; return duplicate;
@@ -875,7 +878,7 @@ public final class HawkbitCommonUtil {
* I18N * I18N
* @return message * @return message
*/ */
public static String getTargetTagAssigmentMsg(final String targTagName, final TargetTagAssigmentResult result, public static String getTargetTagAssigmentMsg(final String targTagName, final TargetTagAssignmentResult result,
final I18N i18n) { final I18N i18n) {
final StringBuilder formMsg = new StringBuilder(); final StringBuilder formMsg = new StringBuilder();
final int assignedCount = result.getAssigned(); final int assignedCount = result.getAssigned();
@@ -922,7 +925,7 @@ public final class HawkbitCommonUtil {
* @return message * @return message
*/ */
public static String getDistributionTagAssignmentMsg(final String targTagName, public static String getDistributionTagAssignmentMsg(final String targTagName,
final DistributionSetTagAssigmentResult result, final I18N i18n) { final DistributionSetTagAssignmentResult result, final I18N i18n) {
final StringBuilder formMsg = new StringBuilder(); final StringBuilder formMsg = new StringBuilder();
final int assignedCount = result.getAssigned(); final int assignedCount = result.getAssigned();
final int alreadyAssignedCount = result.getAlreadyAssigned(); final int alreadyAssignedCount = result.getAlreadyAssigned();
@@ -1359,12 +1362,12 @@ public final class HawkbitCommonUtil {
* details of status and count * details of status and count
* @return String * @return String
*/ */
public static String getFormattedString(Map<Status, Long> details) { public static String getFormattedString(final Map<Status, Long> details) {
StringBuilder val = new StringBuilder(); final StringBuilder val = new StringBuilder();
if (details == null || details.isEmpty()) { if (details == null || details.isEmpty()) {
return null; return null;
} }
for (Entry<Status, Long> entry : details.entrySet()) { for (final Entry<Status, Long> entry : details.entrySet()) {
val.append(entry.getKey()).append(":").append(entry.getValue()).append(","); val.append(entry.getKey()).append(":").append(entry.getValue()).append(",");
} }
return val.substring(0, val.length() - 1); return val.substring(0, val.length() - 1);
@@ -1382,8 +1385,8 @@ public final class HawkbitCommonUtil {
* label id * label id
* @return * @return
*/ */
public static String getStatusLabelDetailsInString(String value, String style, String id) { public static String getStatusLabelDetailsInString(final String value, final String style, final String id) {
StringBuilder val = new StringBuilder(); final StringBuilder val = new StringBuilder();
if (!Strings.isNullOrEmpty(value)) { if (!Strings.isNullOrEmpty(value)) {
val.append("value:").append(value).append(","); val.append("value:").append(value).append(",");
} }