From 41ee0bfc07148010e6f2ed0b5d02feb8e3195378 Mon Sep 17 00:00:00 2001 From: "david.watkins@db.com" Date: Sun, 24 Sep 2023 18:45:41 +0100 Subject: [PATCH] Resurrect flow - restore flows (and remove them) from the view page #CTCTOWALTZ-2882 #6737 --- .../waltz/data/EntityAliasPopulator.java | 13 ++- .../waltz/data/app_group/AppGroupDao.java | 13 +-- .../finos/waltz/data/svg/SvgDiagramDao.java | 12 +- .../pages/view/logical-flow-view.html | 28 ++++- .../pages/view/logical-flow-view.js | 103 ++++++++++-------- .../services/logical-flow-store.js | 10 ++ ...ngExceptionTranslationExecuteListener.java | 15 ++- .../service/changelog/ChangeLogService.java | 28 ++++- .../finos/waltz/service/cost/CostService.java | 28 ++--- .../end_user_app/EndUserAppService.java | 7 +- .../involvement/InvolvementService.java | 16 ++- .../InvolvementKindService.java | 10 +- .../logical_flow/LogicalFlowService.java | 32 ++++-- .../orgunit/OrganisationalUnitService.java | 3 +- .../waltz/service/person/PersonService.java | 7 +- ...UploadLegalEntityRelationshipEndpoint.java | 9 +- .../endpoints/api/LogicalFlowEndpoint.java | 14 +++ .../DirectQueryBasedDataExtractor.java | 56 +++++----- 18 files changed, 248 insertions(+), 156 deletions(-) diff --git a/waltz-data/src/main/java/org/finos/waltz/data/EntityAliasPopulator.java b/waltz-data/src/main/java/org/finos/waltz/data/EntityAliasPopulator.java index 1187101a78..ae12fb5b32 100644 --- a/waltz-data/src/main/java/org/finos/waltz/data/EntityAliasPopulator.java +++ b/waltz-data/src/main/java/org/finos/waltz/data/EntityAliasPopulator.java @@ -18,7 +18,6 @@ package org.finos.waltz.data; -import org.finos.waltz.common.FunctionUtilities; import org.finos.waltz.model.EntityKind; import org.finos.waltz.model.EntityReference; import org.finos.waltz.schema.Tables; @@ -38,8 +37,12 @@ import static java.lang.String.format; import static java.util.stream.Collectors.toMap; import static org.finos.waltz.common.Checks.checkNotNull; -import static org.finos.waltz.schema.Tables.*; import static org.finos.waltz.model.EntityReference.mkRef; +import static org.finos.waltz.schema.Tables.APPLICATION; +import static org.finos.waltz.schema.Tables.CHANGE_INITIATIVE; +import static org.finos.waltz.schema.Tables.LEGAL_ENTITY; +import static org.finos.waltz.schema.Tables.ORGANISATIONAL_UNIT; +import static org.finos.waltz.schema.Tables.PERSON; import static org.jooq.lambda.tuple.Tuple.tuple; /** @@ -66,11 +69,11 @@ public Map fetchEntityIdLookupMap(EntityKind entityKind, Set fetchPersonAliasToIdMap(identifiers)); + return fetchPersonAliasToIdMap(identifiers); case CHANGE_INITIATIVE: - return FunctionUtilities.time("fetch alias map change initiatives", () -> fetchChangeInitiativeAliasToIdMap(identifiers)); + return fetchChangeInitiativeAliasToIdMap(identifiers); case ORG_UNIT: - return FunctionUtilities.time("fetch alias map org units", () -> fetchOrgUnitAliasToIdMap(identifiers)); + return fetchOrgUnitAliasToIdMap(identifiers); default: throw new IllegalArgumentException(format("Cannot find lookup map for id for entity kind: %s", entityKind)); } diff --git a/waltz-data/src/main/java/org/finos/waltz/data/app_group/AppGroupDao.java b/waltz-data/src/main/java/org/finos/waltz/data/app_group/AppGroupDao.java index d946fce1c2..abb0956638 100644 --- a/waltz-data/src/main/java/org/finos/waltz/data/app_group/AppGroupDao.java +++ b/waltz-data/src/main/java/org/finos/waltz/data/app_group/AppGroupDao.java @@ -20,14 +20,12 @@ import org.finos.waltz.data.JooqUtilities; import org.finos.waltz.data.SearchDao; -import org.finos.waltz.data.application.ApplicationDao; import org.finos.waltz.model.EntityKind; import org.finos.waltz.model.EntityReference; import org.finos.waltz.model.app_group.AppGroup; import org.finos.waltz.model.app_group.AppGroupKind; import org.finos.waltz.model.app_group.AppGroupMemberRole; import org.finos.waltz.model.app_group.ImmutableAppGroup; -import org.finos.waltz.model.application.Application; import org.finos.waltz.model.entity_search.EntitySearchOptions; import org.finos.waltz.schema.tables.records.ApplicationGroupRecord; import org.jooq.Condition; @@ -47,7 +45,6 @@ import java.util.List; import java.util.Optional; import java.util.Set; -import java.util.concurrent.Future; import java.util.stream.Collectors; import static org.finos.waltz.common.StringUtilities.mkSafe; @@ -243,7 +240,7 @@ public List search(EntitySearchOptions options) { .and(nameCondition)); SelectConditionStep publicGroupsViaAlias = dsl - .selectDistinct(APPLICATION_GROUP.fields()) + .select(APPLICATION_GROUP.fields()) .from(APPLICATION_GROUP) .innerJoin(ENTITY_ALIAS) .on(ENTITY_ALIAS.ID.eq(APPLICATION_GROUP.ID)) @@ -251,17 +248,19 @@ public List search(EntitySearchOptions options) { .and(aliasCondition); SelectConditionStep privateGroupsViaAlias = dsl - .selectDistinct(APPLICATION_GROUP.fields()) + .select(APPLICATION_GROUP.fields()) .from(APPLICATION_GROUP) .innerJoin(ENTITY_ALIAS) .on(ENTITY_ALIAS.ID.eq(APPLICATION_GROUP.ID)) .where(privateGroupCondition) .and(aliasCondition); - return privateGroups + Select searchQry = privateGroups .unionAll(publicGroups) .unionAll(privateGroupsViaAlias) - .unionAll(publicGroupsViaAlias) + .unionAll(publicGroupsViaAlias); + + return searchQry .fetch(TO_DOMAIN) .stream() .limit(options.limit()) diff --git a/waltz-data/src/main/java/org/finos/waltz/data/svg/SvgDiagramDao.java b/waltz-data/src/main/java/org/finos/waltz/data/svg/SvgDiagramDao.java index 4482e22385..4a0e7a9b4b 100644 --- a/waltz-data/src/main/java/org/finos/waltz/data/svg/SvgDiagramDao.java +++ b/waltz-data/src/main/java/org/finos/waltz/data/svg/SvgDiagramDao.java @@ -18,7 +18,6 @@ package org.finos.waltz.data.svg; -import org.finos.waltz.common.FunctionUtilities; import org.finos.waltz.model.svg.ImmutableSvgDiagram; import org.finos.waltz.model.svg.SvgDiagram; import org.finos.waltz.schema.tables.records.SvgDiagramRecord; @@ -40,7 +39,7 @@ public class SvgDiagramDao { private final DSLContext dsl; - private static RecordMapper svgMapper = r -> { + private static final RecordMapper SVG_MAPPER = r -> { SvgDiagramRecord record = r.into(SVG_DIAGRAM); return ImmutableSvgDiagram.builder() .id(record.getId()) @@ -67,16 +66,17 @@ public SvgDiagram getById(long id) { return dsl.select() .from(SVG_DIAGRAM) .where(SVG_DIAGRAM.ID.eq(id)) - .fetchOne(svgMapper); + .fetchOne(SVG_MAPPER); } public List findByGroups(String[] groups) { - return FunctionUtilities.time("SDD.findByGroups", () -> dsl.select() + return dsl + .select() .from(SVG_DIAGRAM) .where(SVG_DIAGRAM.GROUP.in(groups)) .orderBy(SVG_DIAGRAM.PRIORITY.asc()) - .fetch(svgMapper)); + .fetch(SVG_MAPPER); } @@ -84,7 +84,7 @@ public Set findAll() { return dsl .select(SVG_DIAGRAM.fields()) .from(SVG_DIAGRAM) - .fetchSet(svgMapper); + .fetchSet(SVG_MAPPER); } diff --git a/waltz-ng/client/logical-flow/pages/view/logical-flow-view.html b/waltz-ng/client/logical-flow/pages/view/logical-flow-view.html index 565033fe57..e016e16171 100644 --- a/waltz-ng/client/logical-flow/pages/view/logical-flow-view.html +++ b/waltz-ng/client/logical-flow/pages/view/logical-flow-view.html @@ -43,10 +43,32 @@
+ + + +
@@ -93,8 +115,8 @@ No information for this logical flow -
+

diff --git a/waltz-ng/client/logical-flow/pages/view/logical-flow-view.js b/waltz-ng/client/logical-flow/pages/view/logical-flow-view.js index b3c738868d..be9c451295 100644 --- a/waltz-ng/client/logical-flow/pages/view/logical-flow-view.js +++ b/waltz-ng/client/logical-flow/pages/view/logical-flow-view.js @@ -22,49 +22,23 @@ import {initialiseData} from "../../../common/index"; import template from "./logical-flow-view.html"; import {CORE_API} from "../../../common/services/core-api-utils"; import toasts from "../../../svelte-stores/toast-store"; +import _ from "lodash"; const initialState = { logicalFlow: null, + isDraft: false, + isRemoved: false, + canEdit: false, + canRestore: false, + canRemove: false }; -function mkHistoryObj(flow) { - return { - name: `${flow.source.name} to ${flow.target.name}`, - kind: "LOGICAL_DATA_FLOW", - state: "main.logical-flow.view", - stateParams: { id: flow.id } - }; -} - - -function removeFromHistory(historyStore, flow) { - if (! flow) { return; } - - const historyObj = mkHistoryObj(flow); - - historyStore.remove( - historyObj.name, - historyObj.kind, - historyObj.state, - historyObj.stateParams); -} - - -function navigateToLastView($state, historyStore) { - const lastHistoryItem = historyStore.getAll()[0]; - if (lastHistoryItem) { - $state.go(lastHistoryItem.state, lastHistoryItem.stateParams); - } else { - $state.go("main.home"); - } -} - - -function controller($state, +function controller($q, + $state, $stateParams, - historyStore, + $window, serviceBroker) { const vm = initialiseData(this, initialState); @@ -78,49 +52,84 @@ function controller($state, // -- LOAD --- - serviceBroker + const flowPromise = serviceBroker .loadViewData( CORE_API.LogicalFlowStore.getById, [ flowId ]) .then(r => vm.logicalFlow = r.data); + const permissionPromise = serviceBroker + .loadViewData( + CORE_API.LogicalFlowStore.findPermissionsForParentRef, + [vm.entityReference]) + .then(r => { + vm.canEdit = _.some(r.data, d => _.includes(["ADD", "UPDATE", "REMOVE"], d)); + }); + + $q.all([flowPromise, permissionPromise]).then(() => { + vm.isDraft = vm.logicalFlow.entityLifecycleStatus === "PENDING"; + vm.isRemoved = vm.logicalFlow.entityLifecycleStatus === "REMOVED" || vm.logicalFlow.isRemoved; + vm.canRemove = vm.canEdit && !vm.isRemoved; + vm.canRestore = vm.canEdit && vm.isRemoved; + }); + }; - const deleteLogicalFlow = () => { + const removeLogicalFlow = () => { return serviceBroker .execute(CORE_API.LogicalFlowStore.removeFlow, [vm.logicalFlow.id]) .then(r => { if (r.data > 0) { - toasts.success(`Logical Flow between ${vm.logicalFlow.source.name} and ${vm.logicalFlow.target.name} deleted`); + toasts.success(`Logical Flow between ${vm.logicalFlow.source.name} and ${vm.logicalFlow.target.name} removed`); + } else { + toasts.error(r.message); + } + $window.location.reload(); + }); + }; + + const restoreLogicalFlow = () => { + return serviceBroker + .execute(CORE_API.LogicalFlowStore.restoreFlow, [vm.logicalFlow.id]) + .then(r => { + if (r.data > 0) { + toasts.success(`Logical Flow between ${vm.logicalFlow.source.name} and ${vm.logicalFlow.target.name} has been restored`); } else { toasts.error(r.message); } - navigateToLastView($state, historyStore); + $window.location.reload(); }); }; - const handleDeleteFlowResponse = (response) => { + const handleRemoveFlowResponse = (response) => { if (response > 0) { - toasts.success("Logical flow deleted"); - removeFromHistory(historyStore, vm.logicalFlow); + toasts.success("Logical flow removed"); } else { toasts.error(response.message); } }; - vm.deleteFlow = () => { - if (confirm("Are you sure you want to delete this flow ?")) { - deleteLogicalFlow() - .then(r => handleDeleteFlowResponse(r.data)); + vm.removeFlow = () => { + if (confirm("Are you sure you want to remove this flow ?")) { + removeLogicalFlow() + .then(r => handleRemoveFlowResponse(r.data)); + } + }; + + vm.restoreFlow = () => { + if (confirm("Are you sure you want to restore this flow ?")) { + console.log("restoring", vm.logicalFlow); + restoreLogicalFlow(); } }; } controller.$inject = [ + "$q", "$state", "$stateParams", - "HistoryStore", + "$window", "ServiceBroker" ]; diff --git a/waltz-ng/client/logical-flow/services/logical-flow-store.js b/waltz-ng/client/logical-flow/services/logical-flow-store.js index d5dca0e8ac..80967b8fab 100644 --- a/waltz-ng/client/logical-flow/services/logical-flow-store.js +++ b/waltz-ng/client/logical-flow/services/logical-flow-store.js @@ -86,6 +86,10 @@ export function store($http, BaseApiUrl) { .delete(`${BASE}/${id}`) .then(r => r.data); + const restoreFlow = (id) => $http + .put(`${BASE}/${id}/restore`) + .then(r => r.data); + const addFlow = (addFlowCmd) => $http .post(`${BASE}`, addFlowCmd) .then(r => r.data); @@ -119,6 +123,7 @@ export function store($http, BaseApiUrl) { calculateStats, countByDataType, removeFlow, + restoreFlow, getById, addFlow, addFlows, @@ -183,6 +188,11 @@ export const LogicalFlowStore_API = { serviceFnName: "removeFlow", description: "removes a single logical flow" }, + restoreFlow: { + serviceName, + serviceFnName: "restoreFlow", + description: "restore a single logical flow" + }, getById: { serviceName, serviceFnName: "getById", diff --git a/waltz-service/src/main/java/org/finos/waltz/service/SpringExceptionTranslationExecuteListener.java b/waltz-service/src/main/java/org/finos/waltz/service/SpringExceptionTranslationExecuteListener.java index 6467c6cefa..a8c984a227 100644 --- a/waltz-service/src/main/java/org/finos/waltz/service/SpringExceptionTranslationExecuteListener.java +++ b/waltz-service/src/main/java/org/finos/waltz/service/SpringExceptionTranslationExecuteListener.java @@ -2,13 +2,18 @@ import org.jooq.ExecuteContext; import org.jooq.impl.DefaultExecuteListener; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.dao.DataAccessException; import org.springframework.jdbc.support.SQLStateSQLExceptionTranslator; import java.sql.SQLException; +import static java.lang.String.format; + public class SpringExceptionTranslationExecuteListener extends DefaultExecuteListener { + private static final Logger LOG = LoggerFactory.getLogger(SpringExceptionTranslationExecuteListener.class); private final SQLStateSQLExceptionTranslator translator; public SpringExceptionTranslationExecuteListener(SQLStateSQLExceptionTranslator translator) { @@ -18,8 +23,14 @@ public SpringExceptionTranslationExecuteListener(SQLStateSQLExceptionTranslator @Override public void exception(ExecuteContext ctx) { SQLException ex = ctx.sqlException(); - DataAccessException translatedEx = translator.translate("jooq", ctx.sql(), ex); - ctx.exception(translatedEx); + if (ex == null) { + LOG.error(format( + "The Spring SQL Exception translator is being passed a context with no SQLException. Context - runtime exception?: %s", + ctx.exception())); + } else { + DataAccessException translatedEx = translator.translate("jooq", ctx.sql(), ex); + ctx.exception(translatedEx); + } } } \ No newline at end of file diff --git a/waltz-service/src/main/java/org/finos/waltz/service/changelog/ChangeLogService.java b/waltz-service/src/main/java/org/finos/waltz/service/changelog/ChangeLogService.java index 7aacb99745..43183c5d3e 100644 --- a/waltz-service/src/main/java/org/finos/waltz/service/changelog/ChangeLogService.java +++ b/waltz-service/src/main/java/org/finos/waltz/service/changelog/ChangeLogService.java @@ -206,7 +206,7 @@ public void writeChangeLogEntries(LogicalFlow logicalFlow, Operation operation) { Tuple2> t = preparePreambleAndEntitiesForChangeLogs(logicalFlow); String message = format("%s: %s", t.v1, postamble); - writeChangeLogEntries(t.v2, message, operation, LOGICAL_DATA_FLOW, userId); + writeChangeLogEntries(t.v2, message, operation, logicalFlow.entityReference(), userId); } @@ -216,7 +216,7 @@ public void writeChangeLogEntries(PhysicalFlow physicalFlow, Operation operation) { Tuple2> t = preparePreambleAndEntitiesForChangeLogs(physicalFlow); String message = format("%s: %s", t.v1, postamble); - writeChangeLogEntries(t.v2, message, operation, PHYSICAL_FLOW, userId); + writeChangeLogEntries(t.v2, message, operation, physicalFlow.entityReference(), userId); } @@ -226,7 +226,7 @@ public void writeChangeLogEntries(PhysicalSpecification physicalSpec, Operation operation) { Tuple2> t = preparePreambleAndEntitiesForChangeLogs(physicalSpec); String message = format("%s: %s", t.v1, postamble); - writeChangeLogEntries(t.v2, message, operation, PHYSICAL_FLOW, userId); + writeChangeLogEntries(t.v2, message, operation, physicalSpec.entityReference(), userId); } public void writeChangeLogEntries(MeasurableRatingReplacement measurableRatingReplacement, @@ -278,6 +278,28 @@ private void writeChangeLogEntries(Set refs, } + private void writeChangeLogEntries(Set refs, + String message, + Operation operation, + EntityReference childRef, + String userId) { + Set changeLogEntries = map( + refs, + r -> ImmutableChangeLog + .builder() + .parentReference(r) + .message(message) + .severity(Severity.INFORMATION) + .userId(userId) + .childKind(childRef.kind()) + .childId(childRef.id()) + .operation(operation) + .build()); + + changeLogDao.write(changeLogEntries); + } + + private Tuple2> preparePreambleAndEntitiesForChangeLogs(PhysicalSpecification physicalSpec) { List physicalFlows = physicalFlowDao.findBySpecificationId(physicalSpec.id().get()); diff --git a/waltz-service/src/main/java/org/finos/waltz/service/cost/CostService.java b/waltz-service/src/main/java/org/finos/waltz/service/cost/CostService.java index 2ea5df9547..9fd02c6a1b 100644 --- a/waltz-service/src/main/java/org/finos/waltz/service/cost/CostService.java +++ b/waltz-service/src/main/java/org/finos/waltz/service/cost/CostService.java @@ -18,10 +18,7 @@ package org.finos.waltz.service.cost; -import org.finos.waltz.common.ArrayUtilities; import org.finos.waltz.common.DateTimeUtilities; -import org.finos.waltz.common.ListUtilities; -import org.finos.waltz.common.MapUtilities; import org.finos.waltz.data.GenericSelector; import org.finos.waltz.data.GenericSelectorFactory; import org.finos.waltz.data.cost.AllocatedCostDefinitionDao; @@ -42,17 +39,13 @@ import org.springframework.stereotype.Service; import java.math.BigDecimal; -import java.util.Comparator; import java.util.Map; -import java.util.Optional; import java.util.Set; -import java.util.stream.Collectors; import static java.lang.String.format; import static java.util.Comparator.comparingInt; import static java.util.Optional.ofNullable; import static org.finos.waltz.common.Checks.checkNotNull; -import static org.finos.waltz.common.FunctionUtilities.time; import static org.finos.waltz.common.MapUtilities.indexBy; @Service @@ -103,28 +96,25 @@ public EntityCostsSummary summariseByCostKindAndSelector(Long costKindId, GenericSelector genericSelector = genericSelectorFactory.applyForKind(targetKind, selectionOptions); - Set topCosts = time( - "topCosts: "+selectionOptions.entityReference(), - () -> costDao.findTopCostsForCostKindAndSelector( + Set topCosts = costDao + .findTopCostsForCostKindAndSelector( costKindId, year, genericSelector, - limit)); + limit); - BigDecimal totalCost = time( - "totalCosts: "+selectionOptions.entityReference(), - () -> costDao.getTotalForKindAndYearBySelector( + BigDecimal totalCost = costDao + .getTotalForKindAndYearBySelector( costKindId, year, - genericSelector)); + genericSelector); - Tuple2 mappedAndMissingCounts = time( - "missingCosts: "+selectionOptions.entityReference(), - () -> costDao.getMappedAndMissingCountsForKindAndYearBySelector( + Tuple2 mappedAndMissingCounts = costDao + .getMappedAndMissingCountsForKindAndYearBySelector( costKindId, year, - genericSelector)); + genericSelector); return ImmutableEntityCostsSummary .builder() diff --git a/waltz-service/src/main/java/org/finos/waltz/service/end_user_app/EndUserAppService.java b/waltz-service/src/main/java/org/finos/waltz/service/end_user_app/EndUserAppService.java index a5e30db345..40688ca702 100644 --- a/waltz-service/src/main/java/org/finos/waltz/service/end_user_app/EndUserAppService.java +++ b/waltz-service/src/main/java/org/finos/waltz/service/end_user_app/EndUserAppService.java @@ -52,7 +52,6 @@ import static java.lang.String.format; import static org.finos.waltz.common.Checks.checkNotNull; -import static org.finos.waltz.common.FunctionUtilities.time; import static org.finos.waltz.common.ListUtilities.map; import static org.finos.waltz.model.EntityKind.APPLICATION; import static org.finos.waltz.model.EntityReference.mkRef; @@ -88,19 +87,19 @@ public EndUserAppService(EndUserAppDao endUserAppDao, public List findByOrganisationalUnitSelector(IdSelectionOptions options) { checkNotNull(options, "options cannot be null"); Select> selector = orgUnitIdSelectorFactory.apply(options); - return time("EUAS.findByOrganisationalUnitSelector", () -> endUserAppDao.findByOrganisationalUnitSelector(selector)); + return endUserAppDao.findByOrganisationalUnitSelector(selector); } public Collection> countByOrgUnitId() { - return time("EUAS.countByOrgUnitId", endUserAppDao::countByOrganisationalUnit); + return endUserAppDao.countByOrganisationalUnit(); } public List findBySelector(IdSelectionOptions options) { checkNotNull(options, "options cannot be null"); Select> selector = endUserAppIdSelectorFactory.apply(options); - return time("EUAS.findBySelector", () -> endUserAppDao.findBySelector(selector)); + return endUserAppDao.findBySelector(selector); } public EndUserApplication getById(Long id) { diff --git a/waltz-service/src/main/java/org/finos/waltz/service/involvement/InvolvementService.java b/waltz-service/src/main/java/org/finos/waltz/service/involvement/InvolvementService.java index 4b362d0295..ee9e0b5f8c 100644 --- a/waltz-service/src/main/java/org/finos/waltz/service/involvement/InvolvementService.java +++ b/waltz-service/src/main/java/org/finos/waltz/service/involvement/InvolvementService.java @@ -25,7 +25,12 @@ import org.finos.waltz.data.GenericSelectorFactory; import org.finos.waltz.data.involvement.InvolvementDao; import org.finos.waltz.data.person.PersonDao; -import org.finos.waltz.model.*; +import org.finos.waltz.model.EntityKind; +import org.finos.waltz.model.EntityReference; +import org.finos.waltz.model.EntityReferenceUtilities; +import org.finos.waltz.model.IdSelectionOptions; +import org.finos.waltz.model.NameProvider; +import org.finos.waltz.model.Operation; import org.finos.waltz.model.changelog.ChangeLog; import org.finos.waltz.model.changelog.ImmutableChangeLog; import org.finos.waltz.model.involvement.EntityInvolvementChangeCommand; @@ -46,8 +51,9 @@ import java.util.stream.Collectors; import static java.lang.String.format; -import static org.finos.waltz.common.Checks.*; -import static org.finos.waltz.common.FunctionUtilities.time; +import static org.finos.waltz.common.Checks.checkNotEmpty; +import static org.finos.waltz.common.Checks.checkNotNull; +import static org.finos.waltz.common.Checks.checkTrue; import static org.finos.waltz.common.ListUtilities.applyToFirst; import static org.finos.waltz.common.ListUtilities.newArrayList; import static org.finos.waltz.common.SetUtilities.map; @@ -94,7 +100,7 @@ public InvolvementService(ChangeLogService changeLogService, public List findByEntityReference(EntityReference ref) { checkNotNull(ref, "ref cannot be null"); - return time("IS.findByEntityReference", () -> involvementDao.findByEntityReference(ref)); + return involvementDao.findByEntityReference(ref); } @@ -123,7 +129,7 @@ public Set findInvolvementsByKindAndEntityKind(Long invKindId, Enti public List findPeopleByEntityReference(EntityReference ref) { checkNotNull(ref, "ref cannot be null"); - return time("IS.findPeopleByEntityReference", () -> involvementDao.findPeopleByEntityReference(ref)); + return involvementDao.findPeopleByEntityReference(ref); } diff --git a/waltz-service/src/main/java/org/finos/waltz/service/involvement_kind/InvolvementKindService.java b/waltz-service/src/main/java/org/finos/waltz/service/involvement_kind/InvolvementKindService.java index 14fbf66897..27faee77b5 100644 --- a/waltz-service/src/main/java/org/finos/waltz/service/involvement_kind/InvolvementKindService.java +++ b/waltz-service/src/main/java/org/finos/waltz/service/involvement_kind/InvolvementKindService.java @@ -25,7 +25,11 @@ import org.finos.waltz.model.command.CommandOutcome; import org.finos.waltz.model.command.CommandResponse; import org.finos.waltz.model.command.ImmutableCommandResponse; -import org.finos.waltz.model.involvement_kind.*; +import org.finos.waltz.model.involvement_kind.ImmutableInvolvementKindChangeCommand; +import org.finos.waltz.model.involvement_kind.InvolvementKind; +import org.finos.waltz.model.involvement_kind.InvolvementKindChangeCommand; +import org.finos.waltz.model.involvement_kind.InvolvementKindCreateCommand; +import org.finos.waltz.model.involvement_kind.InvolvementKindUsageStat; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -33,7 +37,6 @@ import java.util.Set; import static org.finos.waltz.common.Checks.checkNotNull; -import static org.finos.waltz.common.FunctionUtilities.time; @Service public class InvolvementKindService { @@ -61,8 +64,7 @@ public InvolvementKind getById(long id) { public List findKeyInvolvementKindsByEntityKind(EntityKind entityKind) { checkNotNull(entityKind, "entityKind cannot be null"); - return time("IKS.findKeyInvolvementKindsByEntityKind", - () -> involvementKindDao.findKeyInvolvementKindsByEntityKind(entityKind)); + return involvementKindDao.findKeyInvolvementKindsByEntityKind(entityKind); } diff --git a/waltz-service/src/main/java/org/finos/waltz/service/logical_flow/LogicalFlowService.java b/waltz-service/src/main/java/org/finos/waltz/service/logical_flow/LogicalFlowService.java index 2ec88e8012..6dcd5ca106 100644 --- a/waltz-service/src/main/java/org/finos/waltz/service/logical_flow/LogicalFlowService.java +++ b/waltz-service/src/main/java/org/finos/waltz/service/logical_flow/LogicalFlowService.java @@ -18,7 +18,6 @@ package org.finos.waltz.service.logical_flow; -import org.finos.waltz.common.FunctionUtilities; import org.finos.waltz.common.SetUtilities; import org.finos.waltz.data.DBExecutorPoolInterface; import org.finos.waltz.data.application.ApplicationIdSelectorFactory; @@ -27,12 +26,25 @@ import org.finos.waltz.data.logical_flow.LogicalFlowDao; import org.finos.waltz.data.logical_flow.LogicalFlowIdSelectorFactory; import org.finos.waltz.data.logical_flow.LogicalFlowStatsDao; -import org.finos.waltz.model.*; +import org.finos.waltz.model.EntityReference; +import org.finos.waltz.model.HierarchyQueryScope; +import org.finos.waltz.model.IdProvider; +import org.finos.waltz.model.IdSelectionOptions; +import org.finos.waltz.model.Operation; +import org.finos.waltz.model.Severity; +import org.finos.waltz.model.UserTimestamp; import org.finos.waltz.model.changelog.ChangeLog; import org.finos.waltz.model.changelog.ImmutableChangeLog; import org.finos.waltz.model.datatype.DataType; import org.finos.waltz.model.datatype.ImmutableDataTypeDecorator; -import org.finos.waltz.model.logical_flow.*; +import org.finos.waltz.model.logical_flow.AddLogicalFlowCommand; +import org.finos.waltz.model.logical_flow.ImmutableLogicalFlow; +import org.finos.waltz.model.logical_flow.ImmutableLogicalFlowGraphSummary; +import org.finos.waltz.model.logical_flow.ImmutableLogicalFlowStatistics; +import org.finos.waltz.model.logical_flow.LogicalFlow; +import org.finos.waltz.model.logical_flow.LogicalFlowGraphSummary; +import org.finos.waltz.model.logical_flow.LogicalFlowMeasures; +import org.finos.waltz.model.logical_flow.LogicalFlowStatistics; import org.finos.waltz.model.rating.AuthoritativenessRatingValue; import org.finos.waltz.model.tally.TallyPack; import org.finos.waltz.service.changelog.ChangeLogService; @@ -67,7 +79,10 @@ import static org.finos.waltz.common.CollectionUtilities.isEmpty; import static org.finos.waltz.common.DateTimeUtilities.nowUtc; import static org.finos.waltz.common.ListUtilities.newArrayList; -import static org.finos.waltz.common.SetUtilities.*; +import static org.finos.waltz.common.SetUtilities.asSet; +import static org.finos.waltz.common.SetUtilities.fromCollection; +import static org.finos.waltz.common.SetUtilities.hasIntersection; +import static org.finos.waltz.common.SetUtilities.map; import static org.finos.waltz.model.EntityKind.DATA_TYPE; import static org.finos.waltz.model.EntityKind.LOGICAL_DATA_FLOW; import static org.finos.waltz.model.EntityReference.mkRef; @@ -321,16 +336,13 @@ private LogicalFlowStatistics calculateStatsForAppIdSelector(IdSelectionOptions Select> appIdSelector = appIdSelectorFactory.apply(options); Future>> dataTypeCounts = dbExecutorPool.submit(() -> - FunctionUtilities.time("DFS.dataTypes", - () -> logicalFlowStatsDao.tallyDataTypesByAppIdSelector(appIdSelector))); + logicalFlowStatsDao.tallyDataTypesByAppIdSelector(appIdSelector)); Future appCounts = dbExecutorPool.submit(() -> - FunctionUtilities.time("DFS.appCounts", - () -> logicalFlowStatsDao.countDistinctAppInvolvementByAppIdSelector(appIdSelector))); + logicalFlowStatsDao.countDistinctAppInvolvementByAppIdSelector(appIdSelector)); Future flowCounts = dbExecutorPool.submit(() -> - FunctionUtilities.time("DFS.flowCounts", - () -> logicalFlowStatsDao.countDistinctFlowInvolvementByAppIdSelector(appIdSelector))); + logicalFlowStatsDao.countDistinctFlowInvolvementByAppIdSelector(appIdSelector)); Supplier statSupplier = Unchecked.supplier(() -> ImmutableLogicalFlowStatistics.builder() .dataTypeCounts(dataTypeCounts.get()) diff --git a/waltz-service/src/main/java/org/finos/waltz/service/orgunit/OrganisationalUnitService.java b/waltz-service/src/main/java/org/finos/waltz/service/orgunit/OrganisationalUnitService.java index 786dfd3538..b79c0b3230 100644 --- a/waltz-service/src/main/java/org/finos/waltz/service/orgunit/OrganisationalUnitService.java +++ b/waltz-service/src/main/java/org/finos/waltz/service/orgunit/OrganisationalUnitService.java @@ -35,7 +35,6 @@ import static java.util.Collections.emptyList; import static org.finos.waltz.common.Checks.checkNotNull; -import static org.finos.waltz.common.FunctionUtilities.time; import static org.finos.waltz.common.StringUtilities.isEmpty; import static org.finos.waltz.model.EntityReference.mkRef; import static org.finos.waltz.model.IdSelectionOptions.mkOpts; @@ -81,7 +80,7 @@ public Integer updateDescription(long id, String description) { public List findByIds(Long... ids) { - return time("OUS.findActiveByFlowIds", () -> dao.findByIds(ids)); + return dao.findByIds(ids); } diff --git a/waltz-service/src/main/java/org/finos/waltz/service/person/PersonService.java b/waltz-service/src/main/java/org/finos/waltz/service/person/PersonService.java index 6182044abf..88ed8dc094 100644 --- a/waltz-service/src/main/java/org/finos/waltz/service/person/PersonService.java +++ b/waltz-service/src/main/java/org/finos/waltz/service/person/PersonService.java @@ -37,7 +37,6 @@ import static java.util.Collections.emptyList; import static org.finos.waltz.common.Checks.checkNotEmpty; import static org.finos.waltz.common.Checks.checkNotNull; -import static org.finos.waltz.common.FunctionUtilities.time; import static org.finos.waltz.common.StringUtilities.isEmpty; @Service @@ -70,7 +69,7 @@ public Person getById(long id) { public List findDirectsByEmployeeId(String employeeId) { checkNotEmpty(employeeId, "Cannot find directs without an employeeId"); - return time("PS.findDirectsByEmployeeId", () -> personDao.findDirectsByEmployeeId(employeeId)); + return personDao.findDirectsByEmployeeId(employeeId); } @@ -78,7 +77,7 @@ public List findDirectsForPersonIds(List personIds) { if (CollectionUtilities.isEmpty(personIds)) { return Collections.emptyList(); } - return time("PS.findDirectsByPersonIds", () -> personDao.findDirectsForPersonIds(personIds)); + return personDao.findDirectsForPersonIds(personIds); } @@ -87,7 +86,7 @@ public List findDirectsForPersonIds(List personIds) { **/ public List findAllManagersByEmployeeId(String employeeId) { checkNotEmpty(employeeId, "Cannot find directs without an employeeId"); - return time("PS.findAllManagersByEmployeeId", () -> personDao.findAllManagersByEmployeeId(employeeId)); + return personDao.findAllManagersByEmployeeId(employeeId); } diff --git a/waltz-web/src/main/java/org/finos/waltz/web/endpoints/api/BulkUploadLegalEntityRelationshipEndpoint.java b/waltz-web/src/main/java/org/finos/waltz/web/endpoints/api/BulkUploadLegalEntityRelationshipEndpoint.java index 9c0cf1ca09..b018155346 100644 --- a/waltz-web/src/main/java/org/finos/waltz/web/endpoints/api/BulkUploadLegalEntityRelationshipEndpoint.java +++ b/waltz-web/src/main/java/org/finos/waltz/web/endpoints/api/BulkUploadLegalEntityRelationshipEndpoint.java @@ -19,8 +19,6 @@ package org.finos.waltz.web.endpoints.api; import org.finos.waltz.common.Checks; -import org.finos.waltz.common.FunctionUtilities; -import org.finos.waltz.model.Operation; import org.finos.waltz.model.bulk_upload.legal_entity_relationship.BulkUploadLegalEntityRelationshipCommand; import org.finos.waltz.model.bulk_upload.legal_entity_relationship.ResolveBulkUploadLegalEntityRelationshipResponse; import org.finos.waltz.model.bulk_upload.legal_entity_relationship.SaveBulkUploadLegalEntityRelationshipResponse; @@ -38,10 +36,11 @@ import spark.Response; import java.io.IOException; -import java.util.Set; import static org.finos.waltz.common.Checks.checkNotNull; -import static org.finos.waltz.web.WebUtilities.*; +import static org.finos.waltz.web.WebUtilities.getUsername; +import static org.finos.waltz.web.WebUtilities.mkPath; +import static org.finos.waltz.web.WebUtilities.readBody; import static org.finos.waltz.web.endpoints.EndpointUtilities.postForDatum; @Service @@ -82,7 +81,7 @@ private ResolveBulkUploadLegalEntityRelationshipResponse resolveRoute(Request re String username = getUsername(request); LOG.info("User: {} resolving bulk upload: {}", username, uploadCmd); - return FunctionUtilities.time("resolve", () -> service.resolve(uploadCmd)); + return service.resolve(uploadCmd); } diff --git a/waltz-web/src/main/java/org/finos/waltz/web/endpoints/api/LogicalFlowEndpoint.java b/waltz-web/src/main/java/org/finos/waltz/web/endpoints/api/LogicalFlowEndpoint.java index e68b78fe7e..0e657bca60 100644 --- a/waltz-web/src/main/java/org/finos/waltz/web/endpoints/api/LogicalFlowEndpoint.java +++ b/waltz-web/src/main/java/org/finos/waltz/web/endpoints/api/LogicalFlowEndpoint.java @@ -98,6 +98,7 @@ public void register() { String findUpstreamFlowsForEntityReferencesPath = mkPath(BASE_URL, "find-upstream-flows"); String getByIdPath = mkPath(BASE_URL, ":id"); String removeFlowPath = mkPath(BASE_URL, ":id"); + String restoreFlowPath = mkPath(BASE_URL, ":id", "restore"); String cleanupOrphansPath = mkPath(BASE_URL, "cleanup-orphans"); String cleanupSelfReferencesPath = mkPath(BASE_URL, "cleanup-self-references"); String addFlowPath = mkPath(BASE_URL); @@ -161,6 +162,7 @@ public void register() { deleteForDatum(removeFlowPath, this::removeFlowRoute); postForDatum(addFlowPath, this::addFlowRoute); postForList(addFlowsPath, this::addFlowsRoute); + putForDatum(restoreFlowPath, this::restoreFlowRoute); } @@ -239,6 +241,18 @@ private int removeFlowRoute(Request request, Response response) { } + private boolean restoreFlowRoute(Request request, Response response) { + + long flowId = getId(request); + String username = getUsername(request); + ensureUserHasEditRights(flowId, username); + + LOG.info("User: {} restoring logical flow: {}", username, flowId); + + return logicalFlowService.restoreFlow(flowId, username); + } + + private void ensureUserHasEditRights(Long id, String username) { Set permissionsForFlow = flowPermissionChecker.findPermissionsForFlow(id, username); Set editPermissions = intersection(permissionsForFlow, asSet(Operation.ADD, Operation.UPDATE, Operation.REMOVE)); diff --git a/waltz-web/src/main/java/org/finos/waltz/web/endpoints/extracts/DirectQueryBasedDataExtractor.java b/waltz-web/src/main/java/org/finos/waltz/web/endpoints/extracts/DirectQueryBasedDataExtractor.java index 58a334061c..c1c471ee82 100644 --- a/waltz-web/src/main/java/org/finos/waltz/web/endpoints/extracts/DirectQueryBasedDataExtractor.java +++ b/waltz-web/src/main/java/org/finos/waltz/web/endpoints/extracts/DirectQueryBasedDataExtractor.java @@ -40,7 +40,6 @@ import java.util.concurrent.atomic.AtomicInteger; import static org.finos.waltz.common.Checks.checkNotNull; -import static org.finos.waltz.common.FunctionUtilities.time; public abstract class DirectQueryBasedDataExtractor implements DataExtractor { @@ -97,7 +96,7 @@ private String writeAsJson(Select qry, private Result query(DSLContext dslContext, Select qry){ return dslContext == null ? qry.fetch() - : time("fetch", () -> dslContext.fetch(dslContext.renderInlined(qry))); + : dslContext.fetch(dslContext.renderInlined(qry)); } @@ -109,24 +108,22 @@ public static Object writeAsMultiSheetExcel(DSLContext dsl, SXSSFWorkbook workbook = new SXSSFWorkbook(2000); for (Tuple2> sheetDef : sheetDefinitions) { - time("preparing excel sheet: " + sheetDef.v1, () -> { - SXSSFSheet sheet = workbook.createSheet(ExtractorUtilities.sanitizeSheetName(sheetDef.v1)); - writeExcelHeader(sheetDef.v2, sheet); - time("writing body", () -> writeExcelBody(sheetDef.v2, sheet, dsl)); - - int endFilterColumnIndex = sheetDef.v2.fields().length == 0 - ? 0 - : sheetDef.v2.fields().length - 1; - - sheet.setAutoFilter(new CellRangeAddress(0, 0, 0, endFilterColumnIndex)); - sheet.createFreezePane(0, 1); - }); + SXSSFSheet sheet = workbook.createSheet(ExtractorUtilities.sanitizeSheetName(sheetDef.v1)); + writeExcelHeader(sheetDef.v2, sheet); + writeExcelBody(sheetDef.v2, sheet, dsl); + + int endFilterColumnIndex = sheetDef.v2.fields().length == 0 + ? 0 + : sheetDef.v2.fields().length - 1; + + sheet.setAutoFilter(new CellRangeAddress(0, 0, 0, endFilterColumnIndex)); + sheet.createFreezePane(0, 1); } - return time("writing excel", Unchecked.supplier(() -> writeExcelToResponse( + return Unchecked.supplier(() -> writeExcelToResponse( suggestedFilenameStem, response, - workbook))); + workbook)); } @@ -184,23 +181,22 @@ private static void writeExcelBody(Select qry, SXSSFSheet sheet, DSLContext dsl) { AtomicInteger rowCounter = new AtomicInteger(1); + Result records = dsl == null ? qry.fetch() - : time("fetch", () -> dsl.fetch(dsl.renderInlined(qry))); - - time("record chomper", () -> { - int colCount = qry.fields().length; - records.forEach(r -> { - int rowNum = rowCounter.getAndIncrement(); - Row row = sheet.createRow(rowNum); - for (int col = 0; col < colCount; col++) { - Cell cell = row.createCell(col); - Object val = r.get(col); - if (val != null) { - cell.setCellValue(val.toString()); - } + : dsl.fetch(dsl.renderInlined(qry)); + + int colCount = qry.fields().length; + records.forEach(r -> { + int rowNum = rowCounter.getAndIncrement(); + Row row = sheet.createRow(rowNum); + for (int col = 0; col < colCount; col++) { + Cell cell = row.createCell(col); + Object val = r.get(col); + if (val != null) { + cell.setCellValue(val.toString()); } - }); + } }); }