Skip to content

Commit

Permalink
Merge pull request #6073 from deutschebank/db-contrib/waltz-6070-read…
Browse files Browse the repository at this point in the history
…only-phys-flows

Db contrib/waltz 6070 readonly phys flows
  • Loading branch information
davidwatkins73 authored May 26, 2022
2 parents e0add81 + bbcec42 commit 2aadfcf
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.finos.waltz.common.exception;

import static java.lang.String.format;

public class ModifyingReadOnlyRecordException extends RuntimeException {

private final String code;
Expand All @@ -10,6 +12,11 @@ public ModifyingReadOnlyRecordException(String code, String message) {
this.code = code;
}

public ModifyingReadOnlyRecordException(String code, String messageFormat, Object... args) {
super(format(messageFormat, args));
this.code = code;
}


public String getCode() {
return code;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.finos.waltz.common.exception;

import static java.lang.String.format;

public class NotFoundException extends RuntimeException {

private final String code;
Expand All @@ -11,8 +13,8 @@ public NotFoundException(String code, String message) {
}


public NotFoundException(String code, String message, Throwable cause) {
super(message, cause);
public NotFoundException(String code, String messageFormat, Object... args) {
super(format(messageFormat, args));
this.code = code;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<waltz-editable-enum initial-val="$ctrl.physicalFlow.criticality"
enum-kind="physicalFlowCriticality"
on-save="$ctrl.onSaveCriticality"
read-only="$ctrl.physicalFlow.isReadOnly"
edit-role="LOGICAL_DATA_FLOW_EDITOR">
</waltz-editable-enum>
</td>
Expand All @@ -43,6 +44,7 @@
<waltz-editable-enum initial-val="$ctrl.physicalFlow.transport"
enum-kind="TransportKind"
on-save="$ctrl.onSaveTransport"
read-only="$ctrl.physicalFlow.isReadOnly"
edit-role="LOGICAL_DATA_FLOW_EDITOR">
</waltz-editable-enum>
</td>
Expand All @@ -55,6 +57,7 @@
<waltz-editable-enum initial-val="$ctrl.physicalFlow.frequency"
enum-kind="frequencyKind"
on-save="$ctrl.onSaveFrequency"
read-only="$ctrl.physicalFlow.isReadOnly"
edit-role="LOGICAL_DATA_FLOW_EDITOR">
</waltz-editable-enum>
</td>
Expand All @@ -66,6 +69,7 @@
<td>
<waltz-editable-field on-save="$ctrl.onSaveBasisOffset"
field-type="text"
read-only="$ctrl.physicalFlow.isReadOnly"
initial-val="$ctrl.physicalFlow.basisOffset">
</waltz-editable-field>
</td>
Expand Down Expand Up @@ -112,6 +116,7 @@
<waltz-editable-field on-save="$ctrl.onSaveDescription"
field-type="textarea"
empty-label="Not provided"
read-only="$ctrl.physicalFlow.isReadOnly"
initial-val="$ctrl.physicalFlow.description">
</waltz-editable-field>
</td>
Expand Down
6 changes: 5 additions & 1 deletion waltz-ng/client/physical-flows/physical-flow-view.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<waltz-section-actions ng-if="ctrl.physicalFlow.entityLifecycleStatus !== 'REMOVED'">
<div waltz-has-role="LOGICAL_DATA_FLOW_EDITOR">
<button class="btn btn-xs btn-danger"
ng-disabled="! (ctrl.mentions | isEmpty)"
ng-disabled="! (ctrl.mentions | isEmpty) || ctrl.physicalFlow.isReadOnly"
ng-click="(ctrl.mentions | isEmpty) && ctrl.deleteFlow()">
Delete
</button>
Expand Down Expand Up @@ -297,6 +297,10 @@
<a ng-click="ctrl.visibility.overviewEditor = true"
ng-if="! ctrl.visibility.overviewEditor"
class="clickable">
<span ng-if="ctrl.physicalFlow.isReadOnly"
title="The flow is locked, only limited fields will be editable">
<waltz-icon name="unlock-alt"></waltz-icon>
</span>
Edit
</a>

Expand Down
37 changes: 24 additions & 13 deletions waltz-ng/client/widgets/editable-enum/editable-enum.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,30 @@

<span ng-bind="$ctrl.currentVal | toDisplayName:$ctrl.enumKind"></span>

<a ng-click="$ctrl.onEdit()"
ng-if="$ctrl.editRole"
waltz-has-role="{{ $ctrl.editRole }}"
class="btn btn-xs waltz-visibility-child-30">
<waltz-icon name="pencil"></waltz-icon>
Edit
</a>
<a ng-click="$ctrl.onEdit()"
ng-if="! $ctrl.editRole"
class="btn btn-xs waltz-visibility-child-30">
<waltz-icon name="pencil"></waltz-icon>
Edit
</a>
<span class="btn btn-xs waltz-visibility-child-30">
<span ng-if="$ctrl.readOnly"
title="Cannot edit as marked as read-only">
<waltz-icon name="lock"></waltz-icon>
Edit
</span>

<span ng-if="!$ctrl.readOnly">
<a ng-if="$ctrl.editRole"
ng-click="$ctrl.onEdit()"
waltz-has-role="{{ $ctrl.editRole }}"
class="btn btn-xs waltz-visibility-child-30">
<waltz-icon name="pencil"></waltz-icon>
Edit
</a>
<a ng-if="! $ctrl.editRole"
ng-click="$ctrl.onEdit()"
class="btn btn-xs waltz-visibility-child-30">
<waltz-icon name="pencil"></waltz-icon>
Edit
</a>
</span>
</span>

</span>

<!-- EDIT -->
Expand Down
4 changes: 3 additions & 1 deletion waltz-ng/client/widgets/editable-enum/editable-enum.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ const bindings = {
enumKind: "@",
onSave: "<",
editRole: "@",
ctx: "<?"
ctx: "<?",
readOnly: "<?"
};


const initialState = {
currentVal: null,
readOnly: false,
visibility: {
editor: false
}
Expand Down
42 changes: 25 additions & 17 deletions waltz-ng/client/widgets/editable-field.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,31 @@
ng-if="$ctrl.newVal == null">
</span>

<a ng-click="$ctrl.edit()"
ng-if="$ctrl.editRole"
waltz-has-role="{{ $ctrl.editRole }}"
style="position: relative; top: -1px"
class="btn btn-xs waltz-visibility-child-30">
<waltz-icon name="pencil">
</waltz-icon>
<span ng-bind="$ctrl.buttonLabel"></span>
</a>
<a ng-click="$ctrl.edit()"
ng-if="! $ctrl.editRole"
style="position: relative; top: -1px"
class="btn btn-xs waltz-visibility-child-30">
<waltz-icon name="pencil">
</waltz-icon>
<span ng-bind="$ctrl.buttonLabel"></span>
</a>
<span class="btn btn-xs waltz-visibility-child-30">
<span ng-if="$ctrl.readOnly"
title="Cannot edit as marked as read-only">
<waltz-icon name="lock"></waltz-icon>
Edit
</span>
<span ng-if="!$ctrl.readOnly">
<a ng-click="$ctrl.edit()"
ng-if="$ctrl.editRole"
waltz-has-role="{{ $ctrl.editRole }}"
style="position: relative; top: -1px">
<waltz-icon name="pencil">
</waltz-icon>
<span ng-bind="$ctrl.buttonLabel"></span>
</a>
<a ng-click="$ctrl.edit()"
ng-if="! $ctrl.editRole"
style="position: relative; top: -1px">
<waltz-icon name="pencil">
</waltz-icon>
<span ng-bind="$ctrl.buttonLabel"></span>
</a>
</span>
</span>

</div>

<div ng-if="$ctrl.editing" style="border-radius: 3px; border: 1px solid #eee; background-color: #fafafa; padding: 10px">
Expand Down
6 changes: 4 additions & 2 deletions waltz-ng/client/widgets/editable-field.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ const bindings = {
onCancel: "<?",
maxDate: "<?", // only for date fields
minDate: "<?", // only for date fields
inlineHelp: "@?"
inlineHelp: "@?",
readOnly: "<?"
};


Expand All @@ -52,7 +53,8 @@ const initialState = {
saveLabel: "Save",
startInEditMode: false,
onCancel: null,
onSave: () => console.log("WEF: No on-save method provided")
onSave: () => console.log("WEF: No on-save method provided"),
readOnly: false
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

package org.finos.waltz.service.physical_flow;

import org.finos.waltz.common.exception.ModifyingReadOnlyRecordException;
import org.finos.waltz.common.exception.NotFoundException;
import org.finos.waltz.service.changelog.ChangeLogService;
import org.finos.waltz.service.external_identifier.ExternalIdentifierService;
import org.finos.waltz.service.logical_flow.LogicalFlowService;
Expand Down Expand Up @@ -300,6 +302,7 @@ private void ensureLogicalDataFlowExistsAndIsNotRemoved(long logicalFlowId, Stri

public int updateAttribute(String username, SetAttributeCommand command) {


int rc = doUpdateAttribute(command);

if (rc != 0) {
Expand All @@ -319,6 +322,7 @@ public int updateAttribute(String username, SetAttributeCommand command) {

private int doUpdateAttribute(SetAttributeCommand command) {
long flowId = command.entityReference().id();
ensureFlowExistsAndIsNotReadOnly(flowId);
switch(command.name()) {
case "criticality":
return physicalFlowDao.updateCriticality(flowId, Criticality.valueOf(command.value()));
Expand All @@ -340,6 +344,27 @@ private int doUpdateAttribute(SetAttributeCommand command) {
}
}

/**
* Verifies that a flow exists and is not read only.
* If it is then the corresponding exception is thrown, namely one of:
*
* <ul>
* <li>NotFoundException</li>
* <li>ModifyingReadOnlyRecordException</li>
* </ul>
*
* @param flowId identifier of the flow being checked
*/
private void ensureFlowExistsAndIsNotReadOnly(long flowId) {
PhysicalFlow flow = getById(flowId);
if (flow == null) {
throw new NotFoundException("PF_NOTFOUND", "Physical Flow: %d not found", flowId);
}
if (flow.isReadOnly()) {
throw new ModifyingReadOnlyRecordException("PF_READONLY", "Physical Flow: %d is read only", flowId);
}
}


private void copyExternalIdFromFlowAndSpecification(String username,
EntityReference toRef,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ private int updateSpecDefinitionId(Request request, Response response) throws IO

private int updateAttribute(Request request, Response response) throws IOException {
WebUtilities.requireRole(userRoleService, request, SystemRole.LOGICAL_DATA_FLOW_EDITOR);

String username = WebUtilities.getUsername(request);
SetAttributeCommand command
= WebUtilities.readBody(request, SetAttributeCommand.class);
Expand Down

0 comments on commit 2aadfcf

Please sign in to comment.