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

refactor and sonar fixes related changes #434

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
29 changes: 25 additions & 4 deletions src/main/java/io/github/jhipster/online/domain/Jdl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

public Long getId() {
return id;
}
Expand Down Expand Up @@ -80,16 +81,36 @@ public void setJdlMetadata(JdlMetadata jdlMetadata) {

@Override
public boolean equals(Object o) {
if (this == o) {
if (isSameObject(o)) {
Copy link
Member

Choose a reason for hiding this comment

The 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 equals method

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());
}

Expand Down
45 changes: 25 additions & 20 deletions src/main/java/io/github/jhipster/online/domain/YoRC.java
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ public int hashCode() {

@Override
public String toString() {
return (
String basicInfo =
"YoRC{" +
"id=" +
getId() +
Expand Down Expand Up @@ -781,17 +781,12 @@ public String toString() {
"'" +
", userLanguage='" +
getUserLanguage() +
"'" +
", year=" +
getYear() +
", month=" +
getMonth() +
", week=" +
getWeek() +
", day=" +
getDay() +
", hour=" +
getHour() +
"'";

String dateTimeInfo =
", year=" + getYear() + ", month=" + getMonth() + ", week=" + getWeek() + ", day=" + getDay() + ", hour=" + getHour();

String serverInfo =
", serverPort='" +
getServerPort() +
"'" +
Expand All @@ -806,7 +801,9 @@ public String toString() {
"'" +
", websocket='" +
isWebsocket() +
"'" +
"'";

String databaseInfo =
", databaseType='" +
getDatabaseType() +
"'" +
Expand All @@ -815,7 +812,9 @@ public String toString() {
"'" +
", prodDatabaseType='" +
getProdDatabaseType() +
"'" +
"'";

String serviceInfo =
", searchEngine='" +
isSearchEngine() +
"'" +
Expand All @@ -830,7 +829,9 @@ public String toString() {
"'" +
", enableSwaggerCodegen='" +
isEnableSwaggerCodegen() +
"'" +
"'";

String clientInfo =
", clientFramework='" +
getClientFramework() +
"'" +
Expand All @@ -842,7 +843,9 @@ public String toString() {
"'" +
", clientPackageManager='" +
getClientPackageManager() +
"'" +
"'";

String applicationInfo =
", applicationType='" +
getApplicationType() +
"'" +
Expand All @@ -854,7 +857,9 @@ public String toString() {
"'" +
", nativeLanguage='" +
getNativeLanguage() +
"'" +
"'";

String testingInfo =
", hasProtractor='" +
isHasProtractor() +
"'" +
Expand All @@ -863,8 +868,8 @@ public String toString() {
"'" +
", hasCucumber='" +
isHasCucumber() +
"'" +
"}"
);
"'}";

return basicInfo + dateTimeInfo + serverInfo + databaseInfo + serviceInfo + clientInfo + applicationInfo + testingInfo;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public class EntityStatsService {

private final EntityStatsMapper entityStatsMapper;

private final CriteriaBuilder builder;

public EntityStatsService(
EntityStatsRepository entityStatsRepository,
EntityManager entityManager,
Expand All @@ -64,6 +66,7 @@ public EntityStatsService(
this.entityStatsRepository = entityStatsRepository;
this.entityManager = entityManager;
this.entityStatsMapper = entityStatsMapper;
this.builder = entityManager.getCriteriaBuilder();
}

/**
Expand Down Expand Up @@ -118,7 +121,6 @@ public void deleteByOwner(GeneratorIdentity owner) {
}

public List<TemporalCountDTO> getCount(Instant after, TemporalValueType dbTemporalFunction) {
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<RawSQL> query = builder.createQuery(RawSQL.class);
Root<EntityStats> root = query.from(EntityStats.class);
ParameterExpression<Instant> parameter = builder.parameter(Instant.class, QueryUtil.DATE);
Expand All @@ -132,7 +134,6 @@ public List<TemporalCountDTO> getCount(Instant after, TemporalValueType dbTempor
}

public List<TemporalDistributionDTO> getFieldCount(Instant after, EntityStatColumn field, TemporalValueType dbTemporalFunction) {
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<RawSQLField> query = builder.createQuery(RawSQLField.class);
Root<EntityStats> root = query.from(EntityStats.class);
ParameterExpression<Instant> parameter = builder.parameter(Instant.class, QueryUtil.DATE);
Expand Down
17 changes: 9 additions & 8 deletions src/main/java/io/github/jhipster/online/service/GitService.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,18 @@ public void pushNewApplicationToGit(User user, File workingDir, String organizat
commit(git, workingDir, "Initial application generation by JHipster");

log.debug("Adding remote repository {} / {}", organization, applicationName);
URIish urIish = null;

RemoteAddCommand remoteAddCommand = git.remoteAdd();
remoteAddCommand.setName("origin");

if (gitProvider.equals(GitProvider.GITHUB)) {
urIish = new URIish(applicationProperties.getGithub().getHost() + "/" + organization + "/" + applicationName + ".git");
URIish urIish = new URIish(applicationProperties.getGithub().getHost() + "/" + organization + "/" + applicationName + ".git");
remoteAddCommand.setUri(urIish);
} else if (gitProvider.equals(GitProvider.GITLAB)) {
urIish =
new URIish(applicationProperties.getGitlab().getHost() + "/" + organization + "/" + applicationName + ".git")
.setPass(user.getGitlabOAuthToken());
URIish urIish = new URIish(applicationProperties.getGitlab().getHost() + "/" + organization + "/" + applicationName + ".git")
.setPass(user.getGitlabOAuthToken());
remoteAddCommand.setUri(urIish);
}
RemoteAddCommand remoteAddCommand = git.remoteAdd();
remoteAddCommand.setName("origin");
remoteAddCommand.setUri(urIish);
remoteAddCommand.call();

String currentBranch = git.getRepository().getFullBranch();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Copy link
Member

Choose a reason for hiding this comment

The 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;
}

/**
Expand Down Expand Up @@ -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);
Copy link
Member

Choose a reason for hiding this comment

The 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);
}
}
Loading