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;
import org.eclipse.hawkbit.repository.model.DistributionSetTagAssigmentResult;
import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult;
/**
* A event for assignment target tag.
*/
public class DistributionSetTagAssigmentResultEvent {
private final DistributionSetTagAssigmentResult assigmentResult;
private final DistributionSetTagAssignmentResult assigmentResult;
/**
* Constructor.
@@ -23,11 +23,11 @@ public class DistributionSetTagAssigmentResultEvent {
* @param assigmentResult
* the assignment result-
*/
public DistributionSetTagAssigmentResultEvent(final DistributionSetTagAssigmentResult assigmentResult) {
public DistributionSetTagAssigmentResultEvent(final DistributionSetTagAssignmentResult assigmentResult) {
this.assigmentResult = assigmentResult;
}
public DistributionSetTagAssigmentResult getAssigmentResult() {
public DistributionSetTagAssignmentResult getAssigmentResult() {
return assigmentResult;
}

View File

@@ -8,14 +8,14 @@
*/
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.
*/
public class TargetTagAssigmentResultEvent {
private final TargetTagAssigmentResult assigmentResult;
private final TargetTagAssignmentResult assigmentResult;
/**
* Constructor.
@@ -23,11 +23,11 @@ public class TargetTagAssigmentResultEvent {
* @param assigmentResult
* the assignment result-
*/
public TargetTagAssigmentResultEvent(final TargetTagAssigmentResult assigmentResult) {
public TargetTagAssigmentResultEvent(final TargetTagAssignmentResult assigmentResult) {
this.assigmentResult = assigmentResult;
}
public TargetTagAssigmentResult getAssigmentResult() {
public TargetTagAssignmentResult getAssigmentResult() {
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.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.DistributionSetTypeElement;
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.
*
*
*
*
*/
@Transactional(readOnly = true)
@Validated
@@ -140,15 +137,15 @@ public class DistributionSetManagement {
* @param sets
* to toggle for
* @param tag
* to toogle
* @return {@link DistributionSetTagAssigmentResult} with all metadata of
* to toggle
* @return {@link DistributionSetTagAssignmentResult} with all meta data of
* the assignment outcome.
*/
@Modifying
@Transactional
@NotNull
@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) {
return toggleTagAssignment(sets.stream().map(ds -> ds.getId()).collect(Collectors.toList()), tag.getName());
}
@@ -163,42 +160,42 @@ public class DistributionSetManagement {
* to toggle for
* @param tagName
* to toggle
* @return {@link DistributionSetTagAssigmentResult} with all metadata of
* @return {@link DistributionSetTagAssignmentResult} with all meta data of
* the assignment outcome.
*/
@Modifying
@Transactional
@NotNull
@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) {
final Iterable<DistributionSet> sets = findDistributionSetListWithDetails(dsIds);
final DistributionSetTag myTag = tagManagement.findDistributionSetTag(tagName);
DistributionSetTagAssigmentResult result;
final List<DistributionSet> allDSs = new ArrayList<>();
DistributionSetTagAssignmentResult result;
final List<DistributionSet> toBeChangedDSs = new ArrayList<>();
for (final DistributionSet set : sets) {
if (set.getTags().add(myTag)) {
allDSs.add(set);
toBeChangedDSs.add(set);
}
}
// unassigment case
if (allDSs.isEmpty()) {
// un-assignment case
if (toBeChangedDSs.isEmpty()) {
for (final DistributionSet set : sets) {
if (set.getTags().remove(myTag)) {
allDSs.add(set);
toBeChangedDSs.add(set);
}
}
result = new DistributionSetTagAssigmentResult(dsIds.size() - allDSs.size(), 0, allDSs.size(),
Collections.emptyList(), distributionSetRepository.save(allDSs), myTag);
result = new DistributionSetTagAssignmentResult(dsIds.size() - toBeChangedDSs.size(), 0, toBeChangedDSs.size(),
Collections.emptyList(), distributionSetRepository.save(toBeChangedDSs), myTag);
} else {
result = new DistributionSetTagAssigmentResult(dsIds.size() - allDSs.size(), allDSs.size(), 0,
distributionSetRepository.save(allDSs), Collections.emptyList(), myTag);
result = new DistributionSetTagAssignmentResult(dsIds.size() - toBeChangedDSs.size(), toBeChangedDSs.size(), 0,
distributionSetRepository.save(toBeChangedDSs), Collections.emptyList(), myTag);
}
final DistributionSetTagAssigmentResult resultAssignment = result;
final DistributionSetTagAssignmentResult resultAssignment = result;
afterCommit.afterCommit(() -> eventBus.post(new DistributionSetTagAssigmentResultEvent(resultAssignment)));
// no reason to persist the tag
@@ -436,7 +433,7 @@ public class DistributionSetManagement {
* @param spec
* of the search
* @param pageable
* parametsr for paging
* parameter for paging
*
* @return the found {@link SoftwareModuleType}s
*/
@@ -1059,7 +1056,7 @@ public class DistributionSetManagement {
afterCommit.afterCommit(() -> {
final DistributionSetTagAssigmentResult result = new DistributionSetTagAssigmentResult(0, save.size(), 0,
final DistributionSetTagAssignmentResult result = new DistributionSetTagAssignmentResult(0, save.size(), 0,
save, Collections.emptyList(), tag);
eventBus.post(new DistributionSetTagAssigmentResultEvent(result));
});

View File

@@ -258,10 +258,6 @@ public class SoftwareManagement {
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.
*
@@ -269,13 +265,15 @@ public class SoftwareManagement {
* of the {@link SoftwareModule}
* @param version
* 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)
public List<SoftwareModule> findSoftwareModuleByNameAndVersion(@NotEmpty final String name,
@NotEmpty final String version) {
public SoftwareModule findSoftwareModuleByNameAndVersion(@NotEmpty final String name,
@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);
/**
* 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
* to be filtered on
* @param version
* 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.

View File

@@ -11,10 +11,10 @@ package org.eclipse.hawkbit.repository.model;
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 List<DistributionSet> assignedDs;
@@ -37,7 +37,7 @@ public class DistributionSetTagAssigmentResult extends AssignmentResult {
* @param distributionSetTag
* 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 DistributionSetTag distributionSetTag) {
super(assigned, alreadyAssigned);
@@ -47,30 +47,18 @@ public class DistributionSetTagAssigmentResult extends AssignmentResult {
this.distributionSetTag = distributionSetTag;
}
/**
* @return the unassigned
*/
public int getUnassigned() {
return unassigned;
}
/**
* @return the distributionSetTag
*/
public DistributionSetTag getDistributionSetTag() {
return distributionSetTag;
}
/**
* @return the assignedDs
*/
public List<DistributionSet> getAssignedDs() {
return assignedDs;
}
/**
* @return the unassignedDs
*/
public List<DistributionSet> getUnassignedDs() {
return unassignedDs;
}

View File

@@ -11,13 +11,10 @@ package org.eclipse.hawkbit.repository.model;
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 List<Target> assignedTargets;
@@ -40,7 +37,7 @@ public class TargetTagAssigmentResult extends AssignmentResult {
* @param targetTag
* 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) {
super(assigned, alreadyAssigned);
this.unassigned = unassigned;
@@ -49,23 +46,14 @@ public class TargetTagAssigmentResult extends AssignmentResult {
this.targetTag = targetTag;
}
/**
* @return the unassigned
*/
public int getUnassigned() {
return unassigned;
}
/**
* @return the assignedTargets
*/
public List<Target> getAssignedTargets() {
return assignedTargets;
}
/**
* @return the unassignedTargets
*/
public List<Target> getUnassignedTargets() {
return unassignedTargets;
}