Skip to content

Commit

Permalink
Pull request finos#311: CTCTOWALTZ-2882 flow resurrection2 6737
Browse files Browse the repository at this point in the history
Merge in WALTZ/waltz from WALTZ/waltz-dw:CTCTOWALTZ-2882-flow-resurrection2-6737 to db-feature/waltz-6737-flow-resurrection

* commit '41ee0bfc07148010e6f2ed0b5d02feb8e3195378':
  Resurrect flow
  Resurrect flow
  • Loading branch information
db-waltz committed Sep 25, 2023
2 parents 01176d1 + 41ee0bf commit b752d20
Show file tree
Hide file tree
Showing 18 changed files with 248 additions and 156 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

/**
Expand All @@ -66,11 +69,11 @@ public Map<String, Long> fetchEntityIdLookupMap(EntityKind entityKind, Set<Strin
case LEGAL_ENTITY:
return fetchLegalEntityAliasToIdMap(identifiers);
case PERSON:
return FunctionUtilities.time("fetch alias map people", () -> 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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -243,25 +240,27 @@ public List<AppGroup> search(EntitySearchOptions options) {
.and(nameCondition));

SelectConditionStep<Record> publicGroupsViaAlias = dsl
.selectDistinct(APPLICATION_GROUP.fields())
.select(APPLICATION_GROUP.fields())
.from(APPLICATION_GROUP)
.innerJoin(ENTITY_ALIAS)
.on(ENTITY_ALIAS.ID.eq(APPLICATION_GROUP.ID))
.where(publicGroupCondition)
.and(aliasCondition);

SelectConditionStep<Record> 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<Record> searchQry = privateGroups
.unionAll(publicGroups)
.unionAll(privateGroupsViaAlias)
.unionAll(publicGroupsViaAlias)
.unionAll(publicGroupsViaAlias);

return searchQry
.fetch(TO_DOMAIN)
.stream()
.limit(options.limit())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -40,7 +39,7 @@ public class SvgDiagramDao {
private final DSLContext dsl;


private static RecordMapper<Record, SvgDiagram> svgMapper = r -> {
private static final RecordMapper<Record, SvgDiagram> SVG_MAPPER = r -> {
SvgDiagramRecord record = r.into(SVG_DIAGRAM);
return ImmutableSvgDiagram.builder()
.id(record.getId())
Expand All @@ -67,24 +66,25 @@ public SvgDiagram getById(long id) {
return dsl.select()
.from(SVG_DIAGRAM)
.where(SVG_DIAGRAM.ID.eq(id))
.fetchOne(svgMapper);
.fetchOne(SVG_MAPPER);
}


public List<SvgDiagram> 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);
}


public Set<SvgDiagram> findAll() {
return dsl
.select(SVG_DIAGRAM.fields())
.from(SVG_DIAGRAM)
.fetchSet(svgMapper);
.fetchSet(SVG_MAPPER);
}


Expand Down
28 changes: 25 additions & 3 deletions waltz-ng/client/logical-flow/pages/view/logical-flow-view.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,32 @@


<div class="waltz-page-summary waltz-page-summary-attach">
<waltz-section-actions>
<button ng-if="ctrl.canRestore"
class="btn btn-xs btn-primary"
uib-popover="Restore this flow, any physical flows that were active when this logical flow was removed will also be restored"
popover-append-to-body="true"
popover-popup-delay="300"
popover-placement="bottom"
popover-trigger="mouseenter"
ng-click="ctrl.restoreFlow()">
Restore
</button>
<button ng-if="ctrl.canRemove"
class="btn btn-xs btn-danger"
uib-popover="Remove this flow, any physical flows that are attached to the flow will also be removed"
popover-append-to-body="true"
popover-popup-delay="300"
popover-placement="bottom"
popover-trigger="mouseenter"
ng-click="ctrl.removeFlow()">
Remove
</button>
</waltz-section-actions>
<div ng-if="ctrl.logicalFlow"
ng-class="{
'ws-inactive': ctrl.logicalFlow.entityLifecycleStatus ==='REMOVED',
'ws-draft': ctrl.logicalFlow.entityLifecycleStatus ==='PENDING',
'ws-inactive': ctrl.isRemoved,
'ws-draft': ctrl.isDraft
}">
<div class="row">
<div class="col-md-6">
Expand Down Expand Up @@ -93,8 +115,8 @@
<waltz-no-data ng-if="!ctrl.logicalFlow">
<message>No information for this logical flow</message>
</waltz-no-data>

</div>

<div ng-if="ctrl.logicalFlow">
<br>

Expand Down
103 changes: 56 additions & 47 deletions waltz-ng/client/logical-flow/pages/view/logical-flow-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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"
];

Expand Down
10 changes: 10 additions & 0 deletions waltz-ng/client/logical-flow/services/logical-flow-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -119,6 +123,7 @@ export function store($http, BaseApiUrl) {
calculateStats,
countByDataType,
removeFlow,
restoreFlow,
getById,
addFlow,
addFlows,
Expand Down Expand Up @@ -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",
Expand Down
Loading

0 comments on commit b752d20

Please sign in to comment.