Skip to content

Commit

Permalink
More Sonar code smells removed, i.e. #161.
Browse files Browse the repository at this point in the history
  • Loading branch information
fkoehne committed Feb 27, 2019
1 parent 8195e46 commit ae13c34
Show file tree
Hide file tree
Showing 7 changed files with 197 additions and 198 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class Level {
private Long id;

@Column(name = "sqlevel")
private int level;
private int levelNumber;

@Column(name = "min_xp")
private Long minXp;
Expand All @@ -40,19 +40,19 @@ public Level() {
}

public Level(final Long min, final Long max) {
this.minXp = min;
this.maxXp = max;
minXp = min;
maxXp = max;
}

public Level(final Long min, final Long max, final List<User> users, final List<Artefact> artefacts) {
this.minXp = min;
this.maxXp = max;
minXp = min;
maxXp = max;
this.users = users;
this.artefacts = artefacts;
}

public Level(final Long minLevel) {
this.minXp = minLevel;
minXp = minLevel;
}

public Long getId() {
Expand All @@ -68,15 +68,15 @@ public Long getMinXp() {
}

public void setMinXp(final Long min) {
this.minXp = min;
minXp = min;
}

public Long getMaxXp() {
return maxXp;
}

public void setMaxXp(final Long max) {
this.maxXp = max;
maxXp = max;
}

public List<User> getUsers() {
Expand All @@ -95,11 +95,11 @@ public void setArtefacts(final List<Artefact> artefacts) {
this.artefacts = artefacts;
}

public int getLevel() {
return level;
public int getLevelNumber() {
return levelNumber;
}

public void setLevel(int level) {
this.level = level;
public void setLevelNumber(int level) {
levelNumber = level;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,53 +21,53 @@
@Table(name = "Permission")
public class Permission {

@JsonIgnore
@Id
@GeneratedValue
private Long id;

@Enumerated(EnumType.STRING)
@Column(name = "type", nullable = false)
private PermissionType type;

@Column(name = "permission", nullable = false)
private String permission;

@JsonIgnore
@ManyToMany(cascade = CascadeType.ALL)
@JoinTable(name = "Role_To_Permission", joinColumns = @JoinColumn(name = "permission_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "role_id", referencedColumnName = "id"))
private List<Role> roles;

public Long getId() {
return id;
}

public void setId(final Long id) {
this.id = id;
}

public PermissionType getType() {
return type;
}

public void setType(final PermissionType type) {
this.type = type;
}

public String getPermission() {
return permission;
}

public void setPermission(final String permission) {
this.permission = permission;
}

public List<Role> getRoles() {
return roles;
}

public void setRoles(final List<Role> roles) {
this.roles = roles;
}
@JsonIgnore
@Id
@GeneratedValue
private Long id;

@Enumerated(EnumType.STRING)
@Column(name = "type", nullable = false)
private PermissionType type;

@Column(name = "permission", nullable = false)
private String permissionDescription;

@JsonIgnore
@ManyToMany(cascade = CascadeType.ALL)
@JoinTable(name = "Role_To_Permission", joinColumns = @JoinColumn(name = "permission_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "role_id", referencedColumnName = "id"))
private List<Role> roles;

public Long getId() {
return id;
}

public void setId(final Long id) {
this.id = id;
}

public PermissionType getType() {
return type;
}

public void setType(final PermissionType type) {
this.type = type;
}

public String getPermissionDescription() {
return permissionDescription;
}

public void setPermissionDescription(final String permission) {
permissionDescription = permission;
}

public List<Role> getRoles() {
return roles;
}

public void setRoles(final List<Role> roles) {
this.roles = roles;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

public interface LevelRepository extends JpaRepository<Level, Long> {

Level findById(Long id);
Level findById(Long id);

Level findFirstByMinXpIsLessThanEqualOrderByLevelDesc(Long xp);
Level findFirstByMinXpIsLessThanEqualOrderByLevelNumberDesc(Long xp);

Level findFirstByLevelOrderByLevelDesc(int level);
Level findFirstByLevelNumberOrderByLevelNumberDesc(int levelNumber);
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ public Artefact getArtefact(final long id) {
public Artefact createArtefact(final Artefact artefact) {
LOGGER.info("Creating new artefact " + artefact.getName());
Level minLevel = artefact.getMinLevel();
Level existingLevel = levelService.findByLevel(minLevel.getLevel());
Level existingLevel = levelService.findByLevel(minLevel.getLevelNumber());
if (existingLevel != null) {
artefact.setMinLevel(existingLevel);
} else {
LOGGER.info("Artefact Level " + minLevel.getLevel() + " does not exist yet - creating it...");
LOGGER.info("Artefact Level " + minLevel.getLevelNumber() + " does not exist yet - creating it...");
levelService.createLevel(minLevel);
artefact.setMinLevel(minLevel);
}
Expand All @@ -65,7 +65,7 @@ public Artefact updateArtefact(final Long id, final Artefact artefactDto) {
artefact.setDescription(artefactDto.getDescription());
artefact.setQuantity(artefactDto.getQuantity());
artefact.setSkills(artefactDto.getSkills());
int minLevel = artefactDto.getMinLevel().getLevel();
int minLevel = artefactDto.getMinLevel().getLevelNumber();
Level newLevel = levelService.findByLevel(minLevel);
artefact.setMinLevel(newLevel);
return artefactRepository.save(artefact);
Expand Down Expand Up @@ -97,7 +97,7 @@ public synchronized Artefact buyArtefact(Artefact artefact, final User user) {
final Level minLevel = artefact.getMinLevel();
final Level devLevel = user.getLevel();

if (minLevel.getLevel() > devLevel.getLevel()) {
if (minLevel.getLevelNumber() > devLevel.getLevelNumber()) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@
@Service
public class LevelService {

@Autowired
private LevelRepository levelRepository;
@Autowired
private LevelRepository levelRepository;

public Level getLevelByUserXp(final Long xp) {
// find highest level within users xp
return levelRepository.findFirstByMinXpIsLessThanEqualOrderByLevelDesc(xp);
}
public Level getLevelByUserXp(final Long xp) {
// find highest level within users xp
return levelRepository.findFirstByMinXpIsLessThanEqualOrderByLevelNumberDesc(xp);
}

public Level findById(final Long id) {
return levelRepository.findById(id);
}
public Level findById(final Long id) {
return levelRepository.findById(id);
}

public void createLevel(Level newLevel) {
levelRepository.save(newLevel);
}
public void createLevel(Level newLevel) {
levelRepository.save(newLevel);
}

public Level findByLevel(int level) {
return levelRepository.findFirstByLevelOrderByLevelDesc(level);
}
public Level findByLevel(int levelNumber) {
return levelRepository.findFirstByLevelNumberOrderByLevelNumberDesc(levelNumber);
}
}
Loading

0 comments on commit ae13c34

Please sign in to comment.