Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SonarQube code smell resolution #2123

Merged
merged 2 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
package gov.cdc.nbs.questionbank.entity;

import java.util.LinkedHashSet;
import java.util.Set;
import gov.cdc.nbs.questionbank.valueset.command.ValueSetCommand.Update;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import gov.cdc.nbs.questionbank.valueset.command.ValueSetCommand.Update;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@Entity
Expand Down Expand Up @@ -42,12 +35,7 @@ public class CodeSetGroupMetadatum {
@Column(name = "phin_std_val_ind")
private Character phinStdValInd;

@SuppressWarnings(
// Bidirectional mappings require knowledge of each other
"javaarchitecture:S7027"
)
@OneToMany(mappedBy = "codeSetGroup")
private Set<Codeset> codesets = new LinkedHashSet<>();
protected CodeSetGroupMetadatum() {}

public CodeSetGroupMetadatum(Long id, String codeSetDescTxt, String codeSetShortDescTxt, String codeSetName) {
this.id = id;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package gov.cdc.nbs.questionbank.entity;

import java.time.Instant;
import gov.cdc.nbs.questionbank.valueset.command.ValueSetCommand;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.EmbeddedId;
Expand All @@ -9,13 +9,14 @@
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import gov.cdc.nbs.questionbank.valueset.command.ValueSetCommand;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.time.Instant;

@AllArgsConstructor
@NoArgsConstructor
@Getter
Expand Down Expand Up @@ -61,8 +62,9 @@ public class Codeset {
private Instant statusToTime;

@SuppressWarnings(
// Bidirectional mappings require knowledge of each other
"javaarchitecture:S7027")
// Bidirectional mappings require knowledge of each other
"javaarchitecture:S7027"
)
@ManyToOne(fetch = FetchType.LAZY, cascade = {
CascadeType.MERGE,
CascadeType.REMOVE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ public interface CriteriaResolver {
Stream<BooleanExpression> resolve(final Filter filter, final Expression<?> expression);
}

@SuppressWarnings("javaarchitecture:S7027") // static method uses default implementation
public static Stream<BooleanExpression> apply(
final ExpressionResolver expressionResolver,
final Collection<Filter> filters) {
return apply(expressionResolver, new DefaultQueryDSLCriteriaResolver(), filters);
}

public static Stream<BooleanExpression> apply(
final ExpressionResolver expressionResolver,
final CriteriaResolver criteriaResolver,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@
import gov.cdc.nbs.questionbank.page.content.reorder.ReorderException;

public class ReorderablePage {
private List<Tab> tabs = new ArrayList<>();
private Long id;

public static final int PAGE_TYPE = 1002;
public static final int TAB = 1010;
public static final int SECTION = 1015;
public static final int SUBSECTION = 1016;

private final List<Tab> tabs = new ArrayList<>();
private final Long id;

public ReorderablePage(Long id) {
this.id = id;
Expand Down Expand Up @@ -37,13 +43,13 @@ public void move(long toMove, long afterId) {
public List<PageEntry> toPageEntries() {
List<PageEntry> entries = new ArrayList<>();
int orderNumber = 1;
entries.add(new PageEntry(id, SimplePageMapper.PAGE_TYPE, orderNumber++));
entries.add(new PageEntry(id, PAGE_TYPE, orderNumber++));
for (Tab t : tabs) {
entries.add(new PageEntry(t.getId(), SimplePageMapper.TAB, orderNumber++));
entries.add(new PageEntry(t.getId(), TAB, orderNumber++));
for (Section s : t.getSections()) {
entries.add(new PageEntry(s.getId(), SimplePageMapper.SECTION, orderNumber++));
entries.add(new PageEntry(s.getId(), SECTION, orderNumber++));
for (Subsection ss : s.getSubsections()) {
entries.add(new PageEntry(ss.getId(), SimplePageMapper.SUBSECTION, orderNumber++));
entries.add(new PageEntry(ss.getId(), SUBSECTION, orderNumber++));
for (Element e : ss.getElements()) {
entries.add(new PageEntry(e.getId(), e.getType(), orderNumber++));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
import gov.cdc.nbs.questionbank.page.content.reorder.models.ReorderablePage.Tab;

public class SimplePageMapper {
public static final int PAGE_TYPE = 1002;
public static final int TAB = 1010;
public static final int SECTION = 1015;
public static final int SUBSECTION = 1016;

private List<Tab> tabs = new ArrayList<>();
private Tab currentTab = null;
Expand All @@ -23,20 +19,20 @@ public ReorderablePage toPage(List<PageEntry> entries) {
ReorderablePage page = null;
for (PageEntry e : entries) {
switch (e.component()) {
case PAGE_TYPE:
case ReorderablePage.PAGE_TYPE:
page = new ReorderablePage(e.id());
break;
case TAB: {
case ReorderablePage.TAB: {
rollUpTab();
currentTab = new Tab(e.id());
break;
}
case SECTION: {
case ReorderablePage.SECTION: {
rollUpSection();
currentSection = new Section(e.id());
break;
}
case SUBSECTION: {
case ReorderablePage.SUBSECTION: {
rollUpSubsection();
currentSubsection = new Subsection(e.id());
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,14 @@ public class ConditionMother {
@Autowired
private LdfPageSetRepository ldfPageSetRepository;

private List<ConditionCode> allConditions = new ArrayList<>();
private final List<ConditionCode> allConditions = new ArrayList<>();

public void clean() {
conditionCodeRepository.deleteAll();
ldfPageSetRepository.deleteAll();
allConditions.clear();
}

public ConditionCode conditionCode() {
return allConditions.stream()
.filter(c -> c instanceof ConditionCode).findFirst()
.orElseGet(this::createCondition);
}

public ConditionCode one() {
return allConditions.stream().findFirst()
.orElseThrow(() -> new IllegalStateException("No conditions are available"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,13 @@ private Codeset valueSetWithConcepts() {
}

public Codeset createMetadataEntry(Codeset valueset) {
CodeSetGroupMetadatum codeGrp = new CodeSetGroupMetadatum();
codeGrp.setId(getCodeSetGroupID());
codeGrp.setCodeSetDescTxt(valueset.getCodeSetDescTxt());
codeGrp.setCodeSetNm(valueset.getValueSetNm());
codeGrp.setCodeSetShortDescTxt(valueset.getValueSetNm());
CodeSetGroupMetadatum codeGrp = new CodeSetGroupMetadatum(
getCodeSetGroupID(),
valueset.getCodeSetDescTxt(),
valueset.getValueSetNm(),
valueset.getValueSetNm()
);

codeGrp.setLdfPicklistIndCd(valueset.getLdfPicklistIndCd());
codeGrp = codeSetGrpMetaRepository.save(codeGrp);
valueset.setCodeSetGroup(codeGrp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public class AuthBusObjRt {
@JoinColumn(name = "auth_bus_obj_type_uid", nullable = false)
private AuthBusObjType authBusObjTypeUid;

@SuppressWarnings(
// Bidirectional mappings require knowledge of each other
"javaarchitecture:S7027"
)
@OneToOne(
mappedBy = "authBusObjRtUid",
cascade = {
Expand All @@ -45,7 +49,7 @@ public class AuthBusObjRt {
@Embedded
private AuthAudit audit;

AuthBusObjRt() {
protected AuthBusObjRt() {

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToOne;
import jakarta.persistence.Table;

@Entity
Expand All @@ -25,8 +26,12 @@ public class AuthBusOpRt {
@JoinColumn(name = "auth_bus_op_type_uid", nullable = false)
private AuthBusOpType authBusOpTypeUid;

@SuppressWarnings(
// Bidirectional mappings require knowledge of each other
"javaarchitecture:S7027"
)
@JsonIgnore
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@OneToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "auth_bus_obj_rt_uid", nullable = false)
private AuthBusObjRt authBusObjRtUid;

Expand All @@ -39,7 +44,7 @@ public class AuthBusOpRt {
@Embedded
private AuthAudit audit;

AuthBusOpRt() {
protected AuthBusOpRt() {

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
@Table(name = "Entity_id")
@SuppressWarnings(
// The PatientIdentificationHistoryListener is an entity listener specifically for instances of this class
"javaarchitecture:S7027"
{"javaarchitecture:S7027", "javaarchitecture:S7091"}
)
@EntityListeners(PatientIdentificationHistoryListener.class)
public class EntityId {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
@Table(name = "Entity_locator_participation")
@SuppressWarnings(
// The PatientEntityLocatorHistoryListener is an entity listener specifically for instances of this class
"javaarchitecture:S7027"
{"javaarchitecture:S7027", "javaarchitecture:S7091"}
)
@EntityListeners(PatientEntityLocatorHistoryListener.class)
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
@Setter
@Entity
@Table(name = "Person_ethnic_group")
@SuppressWarnings(
// The PatientEthnicityHistoryListener is an entity listener specifically for instances of this class
{"javaarchitecture:S7027","javaarchitecture:S7091"}
)
@EntityListeners(PatientEthnicityHistoryListener.class)
@SuppressWarnings("javaarchitecture:S7027") // Bidirectional mappings require knowledge of each other
public class PersonEthnicGroup {
@EmbeddedId
private PersonEthnicGroupId id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
@Table(name = "Person_name")
@SuppressWarnings(
// The PatientNameHistoryListener is an entity listener specifically for instances of this class
"javaarchitecture:S7027"
{"javaarchitecture:S7027","javaarchitecture:S7091"}
)
@EntityListeners(PatientNameHistoryListener.class)
public class PersonName {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
@IdClass(PersonRaceId.class)
@SuppressWarnings(
// The PatientRaceHistoryListener is an entity listener specifically for instances of this class
"javaarchitecture:S7027"
{"javaarchitecture:S7027","javaarchitecture:S7091"}
)
@EntityListeners(PatientRaceHistoryListener.class)
public class PersonRace {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@

@Entity
@DiscriminatorValue(PostalEntityLocatorParticipation.POSTAL_CLASS_CODE)
@SuppressWarnings(
// The PatientPostalLocatorHistoryListener is an entity listener specifically for instances of this class
{"javaarchitecture:S7027","javaarchitecture:S7091"}
)
@EntityListeners(PatientPostalLocatorHistoryListener.class)
@SuppressWarnings("javaarchitecture:S7027") // Bidirectional mappings require knowledge of each other
public class PostalEntityLocatorParticipation extends EntityLocatorParticipation {

static final String POSTAL_CLASS_CODE = "PST";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

@Entity
@DiscriminatorValue(TeleEntityLocatorParticipation.TELECOM_CLASS_CODE)
@SuppressWarnings(
// The PatientPhoneLocatorHistoryListener is an entity listener specifically for instances of this class
{"javaarchitecture:S7027","javaarchitecture:S7091"}
)
@EntityListeners(PatientPhoneLocatorHistoryListener.class)
public class TeleEntityLocatorParticipation extends EntityLocatorParticipation {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ public PatientEntityLocatorHistoryListener(PatientEntityLocatorHistoryCreator en
}

@PreUpdate
@SuppressWarnings("javaarchitecture:S7027")
@SuppressWarnings(
// The PatientEntityLocatorHistoryListener is an entity listener specifically for instances of EntityLocatorParticipation
{"javaarchitecture:S7027", "javaarchitecture:S7091"}
)
void preUpdate(final EntityLocatorParticipation entityLocatorParticipation) {
int version = entityLocatorParticipation.getVersionCtrlNbr() - 1;
this.creator.createEntityLocatorHistory(entityLocatorParticipation.getId().getEntityUid(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@

@Component
public class PatientEthnicityHistoryListener {

private static final String QUERY =
"SELECT MAX(version_ctrl_nbr) FROM Person_ethnic_group_hist WHERE person_uid = ? and ethnic_group_cd = ?";
private static final int IDENTIFIER_PARAMETER = 1;
private static final int GROUP_PARAMETER = 2;

private final PatientEthnicityHistoryCreator creator;
private final JdbcTemplate template;

Expand All @@ -17,7 +23,10 @@ public PatientEthnicityHistoryListener(PatientEthnicityHistoryCreator creator, J
}

@PreRemove
@SuppressWarnings("javaarchitecture:S7027")
@SuppressWarnings(
// The PatientEthnicityHistoryListener is an entity listener specifically for instances of PersonEthnicGroup
{"javaarchitecture:S7027","javaarchitecture:S7091"}
)
void preRemove(final PersonEthnicGroup personEthnicGroup) {
long personUid = personEthnicGroup.getPersonUid().getId();
String personEthnicityGroupCd = personEthnicGroup.getId().getEthnicGroupCd();
Expand All @@ -26,9 +35,15 @@ void preRemove(final PersonEthnicGroup personEthnicGroup) {

}

private int getCurrentVersionNumber(long personUid, String ethnicityGroupCd) {
String query = "SELECT MAX(version_ctrl_nbr) FROM Person_ethnic_group_hist WHERE person_uid = ? and ethnic_group_cd = ?";
Integer maxVersionControlNumber = template.queryForObject(query, Integer.class, personUid, ethnicityGroupCd);
return maxVersionControlNumber != null ? maxVersionControlNumber : 0;
private int getCurrentVersionNumber(final long identifier, final String group) {
return template.query(
QUERY, statement -> {
statement.setLong(IDENTIFIER_PARAMETER, identifier);
statement.setString(GROUP_PARAMETER, group);
},
(resultSet, row) -> resultSet.getInt(1))
.stream()
.findFirst()
.orElse(0);
}
}
Loading
Loading