Fixed import and sonar issues

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
kaizimmerm
2016-09-20 18:30:31 +02:00
parent ca23b6e1b8
commit 1000ca3d19
12 changed files with 56 additions and 43 deletions

View File

@@ -8,8 +8,8 @@
*/
package org.eclipse.hawkbit.repository.jpa.model;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import javax.persistence.CollectionTable;
@@ -136,11 +136,10 @@ public class JpaActionStatus extends AbstractJpaTenantAwareBaseEntity implements
@Override
public final void addMessage(final String message) {
if (messages == null) {
messages = new LinkedList<>();
}
if (message != null) {
if (messages == null) {
messages = new ArrayList<>((message.length() / 512) + 1);
}
Splitter.fixedLength(512).split(message).forEach(messages::add);
}
}

View File

@@ -119,7 +119,7 @@ public class JpaDistributionSet extends AbstractJpaNamedVersionedEntity implemen
* Default constructor.
*/
public JpaDistributionSet() {
super();
// Default constructor for JPA
}
/**
@@ -252,15 +252,7 @@ public class JpaDistributionSet extends AbstractJpaNamedVersionedEntity implemen
modules = new HashSet<>();
}
// we cannot allow that modules are added without a type defined
if (type == null) {
throw new DistributionSetTypeUndefinedException();
}
// check if it is allowed to such a module to this DS type
if (!type.containsModuleType(softwareModule.getType())) {
throw new UnsupportedSoftwareModuleForThisDistributionSetException();
}
checkTypeCompatability(softwareModule);
final Optional<SoftwareModule> found = modules.stream()
.filter(module -> module.getId().equals(softwareModule.getId())).findFirst();
@@ -286,6 +278,18 @@ public class JpaDistributionSet extends AbstractJpaNamedVersionedEntity implemen
return false;
}
private void checkTypeCompatability(final SoftwareModule softwareModule) {
// we cannot allow that modules are added without a type defined
if (type == null) {
throw new DistributionSetTypeUndefinedException();
}
// check if it is allowed to such a module to this DS type
if (!type.containsModuleType(softwareModule.getType())) {
throw new UnsupportedSoftwareModuleForThisDistributionSetException();
}
}
@Override
public boolean removeModule(final SoftwareModule softwareModule) {
if (modules == null) {

View File

@@ -130,18 +130,26 @@ public class JpaDistributionSetType extends AbstractJpaNamedEntity implements Di
@Override
public boolean areModuleEntriesIdentical(final DistributionSetType dsType) {
if (!(dsType instanceof JpaDistributionSetType)) {
if (!(dsType instanceof JpaDistributionSetType) || isOneModuleListEmpty(dsType)) {
return false;
} else if (CollectionUtils.isEmpty(elements)
&& CollectionUtils.isEmpty(((JpaDistributionSetType) dsType).elements)) {
} else if (areBothModuleListsEmpty(dsType)) {
return true;
} else if (CollectionUtils.isEmpty(elements)) {
return false;
}
return new HashSet<DistributionSetTypeElement>(((JpaDistributionSetType) dsType).elements).equals(elements);
}
private boolean isOneModuleListEmpty(final DistributionSetType dsType) {
return (!CollectionUtils.isEmpty(((JpaDistributionSetType) dsType).elements)
&& CollectionUtils.isEmpty(elements))
|| (CollectionUtils.isEmpty(((JpaDistributionSetType) dsType).elements)
&& !CollectionUtils.isEmpty(elements));
}
private boolean areBothModuleListsEmpty(final DistributionSetType dsType) {
return CollectionUtils.isEmpty(((JpaDistributionSetType) dsType).elements) && CollectionUtils.isEmpty(elements);
}
@Override
public DistributionSetType addOptionalModuleType(final SoftwareModuleType smType) {
if (elements == null) {

View File

@@ -8,6 +8,7 @@
*/
package org.eclipse.hawkbit.repository.jpa.model;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
@@ -90,7 +91,7 @@ public class JpaSoftwareModule extends AbstractJpaNamedVersionedEntity implement
* Default constructor.
*/
public JpaSoftwareModule() {
// Default constructor for JPA
}
/**
@@ -121,7 +122,7 @@ public class JpaSoftwareModule extends AbstractJpaNamedVersionedEntity implement
@Override
public void addArtifact(final LocalArtifact artifact) {
if (null == artifacts) {
artifacts = new LinkedList<>();
artifacts = new ArrayList<>(4);
artifacts.add(artifact);
return;
}

View File

@@ -11,7 +11,6 @@ package org.eclipse.hawkbit.repository.jpa.model;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
@@ -116,7 +115,7 @@ public class JpaTarget extends AbstractJpaNamedEntity implements Persistable<Lon
@CascadeOnDelete
@OneToMany(fetch = FetchType.LAZY, cascade = { CascadeType.REMOVE, CascadeType.PERSIST })
@JoinColumn(name = "target_Id", insertable = false, updatable = false)
private final List<RolloutTargetGroup> rolloutTargetGroup = new ArrayList<>();
private List<RolloutTargetGroup> rolloutTargetGroup;
/**
* Constructor.
@@ -166,6 +165,14 @@ public class JpaTarget extends AbstractJpaNamedEntity implements Persistable<Lon
return tags;
}
public List<RolloutTargetGroup> getRolloutTargetGroup() {
if (rolloutTargetGroup == null) {
return Collections.emptyList();
}
return Collections.unmodifiableList(rolloutTargetGroup);
}
public boolean addTag(final TargetTag tag) {
if (tags == null) {
tags = new HashSet<>();
@@ -201,7 +208,7 @@ public class JpaTarget extends AbstractJpaNamedEntity implements Persistable<Lon
public boolean addAction(final Action action) {
if (actions == null) {
actions = new LinkedList<>();
actions = new ArrayList<>(4);
}
return actions.add(action);