forked from finos/waltz
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request finos#4984 from deutschebank/db-contrib/waltz-4876…
…-dao-for-summerise-change-log Db contrib/waltz 4876 dao for summerise change log
- Loading branch information
Showing
3 changed files
with
190 additions
and
0 deletions.
There are no files selected for viewing
115 changes: 115 additions & 0 deletions
115
waltz-data/src/main/java/com/khartec/waltz/data/changelog/ChangeLogSummariesDao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
* Waltz - Enterprise Architecture | ||
* Copyright (C) 2016, 2017, 2018, 2019 Waltz open source project | ||
* See README.md for more information | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific | ||
* | ||
*/ | ||
|
||
package com.khartec.waltz.data.changelog; | ||
|
||
import com.khartec.waltz.model.EntityKind; | ||
import com.khartec.waltz.model.EntityReference; | ||
import com.khartec.waltz.model.tally.ChangeLogTally; | ||
import com.khartec.waltz.model.tally.DateTally; | ||
import com.khartec.waltz.model.tally.ImmutableChangeLogTally; | ||
import com.khartec.waltz.model.tally.ImmutableDateTally; | ||
import org.jooq.*; | ||
import org.jooq.impl.DSL; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.sql.Date; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import static com.khartec.waltz.common.Checks.checkNotNull; | ||
import static com.khartec.waltz.schema.tables.ChangeLog.CHANGE_LOG; | ||
|
||
|
||
@Repository | ||
public class ChangeLogSummariesDao { | ||
|
||
private final DSLContext dsl; | ||
|
||
|
||
private static final RecordMapper<Record2<Date,Integer>, DateTally> TO_DATE_TALLY_MAPPER = record -> { | ||
Date date = record.value1(); | ||
Integer count = record.value2(); | ||
|
||
return ImmutableDateTally.builder() | ||
.date(date) | ||
.count(count) | ||
.build(); | ||
}; | ||
|
||
|
||
private static final RecordMapper<Record4<Long, String, String, Integer>, ChangeLogTally> TO_CHANGE_LOG_TALLY_MAPPER = record -> { | ||
|
||
EntityKind parentKind = EntityKind.valueOf(record.value2()); | ||
EntityKind childKind = (record.value3() != null) ? EntityKind.valueOf(record.value3()) : null; | ||
Integer count = record.value4(); | ||
|
||
return ImmutableChangeLogTally.builder() | ||
.ref(EntityReference.mkRef(parentKind, record.value1())) | ||
.childKind(childKind) | ||
.count(count) | ||
.build(); | ||
}; | ||
|
||
|
||
@Autowired | ||
public ChangeLogSummariesDao(DSLContext dsl) { | ||
checkNotNull(dsl, "dsl must not be null"); | ||
this.dsl = dsl; | ||
} | ||
|
||
|
||
public List<DateTally> findCountByDateForParentKindBySelector(EntityKind parentKind, | ||
Select<Record1<Long>> selector, | ||
Optional<Integer> limit) { | ||
checkNotNull(parentKind, "parentKind must not be null"); | ||
|
||
Field<Date> date = DSL.date(CHANGE_LOG.CREATED_AT); | ||
|
||
return dsl.select(date, DSL.count(CHANGE_LOG.ID)) | ||
.from(CHANGE_LOG) | ||
.where(CHANGE_LOG.PARENT_ID.in(selector) | ||
.and(CHANGE_LOG.PARENT_KIND.eq(parentKind.name()))) | ||
.groupBy(date) | ||
.orderBy(date.desc()) | ||
.limit(limit.orElse(Integer.MAX_VALUE)) | ||
.fetch(TO_DATE_TALLY_MAPPER); | ||
} | ||
|
||
|
||
public List<ChangeLogTally> findCountByParentAndChildKindForDateBySelector(EntityKind parentKind, | ||
Select<Record1<Long>> selector, | ||
Date date, | ||
Optional<Integer> limit) { | ||
checkNotNull(parentKind, "parentKind must not be null"); | ||
|
||
AggregateFunction<Integer> count = DSL.count(CHANGE_LOG.ID); | ||
Field<Date> changelogDate = DSL.date(CHANGE_LOG.CREATED_AT); | ||
|
||
return dsl.select(CHANGE_LOG.PARENT_ID, CHANGE_LOG.PARENT_KIND, CHANGE_LOG.CHILD_KIND, count) | ||
.from(CHANGE_LOG) | ||
.where(CHANGE_LOG.PARENT_ID.in(selector) | ||
.and(CHANGE_LOG.PARENT_KIND.eq(parentKind.name())) | ||
.and(changelogDate.eq(date))) | ||
.groupBy(CHANGE_LOG.PARENT_ID, CHANGE_LOG.PARENT_KIND, CHANGE_LOG.CHILD_KIND) | ||
.orderBy(count.desc()) | ||
.limit(limit.orElse(Integer.MAX_VALUE)) | ||
.fetch(TO_CHANGE_LOG_TALLY_MAPPER); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
waltz-model/src/main/java/com/khartec/waltz/model/tally/ChangeLogTally.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Waltz - Enterprise Architecture | ||
* Copyright (C) 2016, 2017, 2018, 2019 Waltz open source project | ||
* See README.md for more information | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific | ||
* | ||
*/ | ||
|
||
package com.khartec.waltz.model.tally; | ||
|
||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
import com.khartec.waltz.model.EntityKind; | ||
import com.khartec.waltz.model.EntityReference; | ||
import com.khartec.waltz.model.Nullable; | ||
import org.immutables.value.Value; | ||
|
||
@Value.Immutable | ||
@JsonSerialize(as = ImmutableChangeLogTally.class) | ||
@JsonDeserialize(as = ImmutableChangeLogTally.class) | ||
public abstract class ChangeLogTally { | ||
|
||
public abstract EntityReference ref(); | ||
|
||
@Nullable | ||
public abstract EntityKind childKind(); | ||
|
||
public abstract long count(); | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
waltz-model/src/main/java/com/khartec/waltz/model/tally/DateTally.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Waltz - Enterprise Architecture | ||
* Copyright (C) 2016, 2017, 2018, 2019 Waltz open source project | ||
* See README.md for more information | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific | ||
* | ||
*/ | ||
|
||
package com.khartec.waltz.model.tally; | ||
|
||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
import org.immutables.value.Value; | ||
|
||
import java.sql.Date; | ||
|
||
@Value.Immutable | ||
@JsonSerialize(as = ImmutableDateTally.class) | ||
@JsonDeserialize(as = ImmutableDateTally.class) | ||
public abstract class DateTally { | ||
|
||
public abstract Date date(); | ||
public abstract long count(); | ||
|
||
} |