-
-
Notifications
You must be signed in to change notification settings - Fork 143
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
refactor and sonar fixes related changes #434
base: main
Are you sure you want to change the base?
Changes from all commits
0524464
6b074be
7a08e91
7006e1e
07b81d2
cae435b
7c8e54b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,7 +48,8 @@ public class Jdl implements Serializable { | |
@JsonIgnore | ||
private JdlMetadata jdlMetadata; | ||
|
||
// jhipster-needle-entity-add-field - Jhipster will add fields here, do not remove | ||
// jhipster-needle-entity-add-field - Jhipster will add fields here, do not | ||
// remove | ||
public Long getId() { | ||
return id; | ||
} | ||
|
@@ -80,16 +81,36 @@ public void setJdlMetadata(JdlMetadata jdlMetadata) { | |
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
if (isSameObject(o)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are unnecessary changes IMO, just makes code more verbose and the methods are not even reused. Same for other methods added. Please revert back to original |
||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
|
||
if (isNotSameType(o)) { | ||
return false; | ||
} | ||
|
||
Jdl jdlMetadataObject = (Jdl) o; | ||
if (jdlMetadataObject.getId() == null || getId() == null) { | ||
|
||
if (areIdsNull(jdlMetadataObject)) { | ||
return false; | ||
} | ||
|
||
return isSameId(jdlMetadataObject); | ||
} | ||
|
||
private boolean isSameObject(Object o) { | ||
return this == o; | ||
} | ||
|
||
private boolean isNotSameType(Object o) { | ||
return o == null || getClass() != o.getClass(); | ||
} | ||
|
||
private boolean areIdsNull(Jdl jdlMetadataObject) { | ||
return jdlMetadataObject.getId() == null || getId() == null; | ||
} | ||
|
||
private boolean isSameId(Jdl jdlMetadataObject) { | ||
return Objects.equals(getId(), jdlMetadataObject.getId()); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,24 +21,16 @@ | |
|
||
import io.github.jhipster.online.domain.GeneratorIdentity; | ||
import io.github.jhipster.online.domain.SubGenEvent; | ||
import io.github.jhipster.online.domain.SubGenEvent_; | ||
import io.github.jhipster.online.domain.enums.SubGenEventType; | ||
import io.github.jhipster.online.repository.SubGenEventRepository; | ||
import io.github.jhipster.online.service.dto.RawSQLField; | ||
import io.github.jhipster.online.service.dto.SubGenEventDTO; | ||
import io.github.jhipster.online.service.dto.TemporalCountDTO; | ||
import io.github.jhipster.online.service.dto.TemporalDistributionDTO; | ||
import io.github.jhipster.online.service.enums.TemporalValueType; | ||
import io.github.jhipster.online.service.mapper.SubGenEventMapper; | ||
import io.github.jhipster.online.service.util.QueryUtil; | ||
import io.github.jhipster.online.service.util.SubGenEventStatisticsService; | ||
import java.time.Instant; | ||
import java.util.*; | ||
import java.util.stream.Collectors; | ||
import javax.persistence.EntityManager; | ||
import javax.persistence.criteria.CriteriaBuilder; | ||
import javax.persistence.criteria.CriteriaQuery; | ||
import javax.persistence.criteria.ParameterExpression; | ||
import javax.persistence.criteria.Root; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.stereotype.Service; | ||
|
@@ -55,18 +47,18 @@ public class SubGenEventService { | |
|
||
private final SubGenEventRepository subGenEventRepository; | ||
|
||
private final EntityManager entityManager; | ||
|
||
private final SubGenEventMapper subGenEventMapper; | ||
|
||
private final SubGenEventStatisticsService subGenEventStatisticsService; | ||
|
||
public SubGenEventService( | ||
SubGenEventRepository subGenEventRepository, | ||
EntityManager entityManager, | ||
SubGenEventMapper subGenEventMapper | ||
SubGenEventMapper subGenEventMapper, | ||
SubGenEventStatisticsService subGenEventStatisticsService | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i dont see the need to create another service here |
||
) { | ||
this.subGenEventRepository = subGenEventRepository; | ||
this.entityManager = entityManager; | ||
this.subGenEventMapper = subGenEventMapper; | ||
this.subGenEventStatisticsService = subGenEventStatisticsService; | ||
} | ||
|
||
/** | ||
|
@@ -121,68 +113,10 @@ public void deleteByOwner(GeneratorIdentity owner) { | |
} | ||
|
||
public List<TemporalCountDTO> getFieldCount(Instant after, SubGenEventType field, TemporalValueType dbTemporalFunction) { | ||
CriteriaBuilder builder = entityManager.getCriteriaBuilder(); | ||
CriteriaQuery<RawSQLField> query = builder.createQuery(RawSQLField.class); | ||
Root<SubGenEvent> root = query.from(SubGenEvent.class); | ||
ParameterExpression<Instant> dateParameter = builder.parameter(Instant.class, QueryUtil.DATE); | ||
ParameterExpression<String> typeParameter = builder.parameter(String.class, QueryUtil.TYPE); | ||
|
||
query | ||
.select( | ||
builder.construct( | ||
RawSQLField.class, | ||
root.get(dbTemporalFunction.getFieldName()), | ||
root.get(SubGenEvent_.type), | ||
builder.count(root) | ||
) | ||
) | ||
.where( | ||
builder.greaterThan(root.get(SubGenEvent_.date).as(Instant.class), dateParameter), | ||
builder.equal(root.get(SubGenEvent_.type), typeParameter) | ||
) | ||
.groupBy(root.get(SubGenEvent_.type), root.get(dbTemporalFunction.getFieldName())); | ||
|
||
return entityManager | ||
.createQuery(query) | ||
.setParameter(QueryUtil.DATE, after) | ||
.setParameter(QueryUtil.TYPE, field.getDatabaseValue()) | ||
.getResultList() | ||
.stream() | ||
.map( | ||
entry -> | ||
new TemporalCountDTO( | ||
TemporalValueType.absoluteMomentToInstant(entry.getMoment().longValue(), dbTemporalFunction), | ||
entry.getCount() | ||
) | ||
) | ||
.collect(Collectors.toList()); | ||
return subGenEventStatisticsService.getFieldCount(after, field, dbTemporalFunction); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if a seperate service is created better to call it directly from the controller instead of indirection here |
||
} | ||
|
||
public List<TemporalDistributionDTO> getDeploymentToolDistribution(Instant after, TemporalValueType dbTemporalFunction) { | ||
Map<SubGenEventType, List<TemporalCountDTO>> entries = Arrays | ||
.stream(SubGenEventType.getDeploymentTools()) | ||
.map(deploymentTool -> new AbstractMap.SimpleEntry<>(deploymentTool, getFieldCount(after, deploymentTool, dbTemporalFunction))) | ||
.collect(Collectors.toMap(AbstractMap.SimpleEntry::getKey, AbstractMap.SimpleEntry::getValue)); | ||
|
||
List<TemporalDistributionDTO> result = new ArrayList<>(); | ||
for (Map.Entry<SubGenEventType, List<TemporalCountDTO>> entry : entries.entrySet()) { | ||
for (TemporalCountDTO count : entry.getValue()) { | ||
Optional<TemporalDistributionDTO> maybeDistribution = result | ||
.stream() | ||
.filter(td -> td.getDate().equals(count.getDate())) | ||
.findFirst(); | ||
TemporalDistributionDTO distributionDTO; | ||
if (maybeDistribution.isPresent()) { | ||
distributionDTO = maybeDistribution.get(); | ||
} else { | ||
distributionDTO = new TemporalDistributionDTO(count.getDate()); | ||
result.add(distributionDTO); | ||
} | ||
|
||
distributionDTO.getValues().put(entry.getKey().getDatabaseValue(), count.getCount()); | ||
} | ||
} | ||
|
||
return result; | ||
return subGenEventStatisticsService.getDeploymentToolDistribution(after, dbTemporalFunction); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why?