Skip to content

Commit

Permalink
Merge pull request #7127 from deutschebank/db-contrib/waltz-7023-m-ca…
Browse files Browse the repository at this point in the history
…t-create

Measurable category create
  • Loading branch information
davidwatkins73 authored Aug 22, 2024
2 parents b2130be + 27e4e09 commit c9bce35
Show file tree
Hide file tree
Showing 19 changed files with 718 additions and 308 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,19 +266,23 @@ public int deleteByGenericSelector(GenericSelector genericSelector) {
public boolean store(SaveAssessmentRatingCommand command) {
checkNotNull(command, "command cannot be null");
AssessmentRatingRecord record = COMMAND_TO_RECORD_MAPPER.apply(command);

return isUpdate(command)
? dsl.executeUpdate(record) == 1
: dsl.executeInsert(record) == 1;
}


public boolean isUpdate(SaveAssessmentRatingCommand command) {
EntityReference ref = command.entityReference();

boolean isUpdate = dsl.fetchExists(dsl
return dsl.fetchExists(dsl
.select(ar.ID)
.from(ar)
.where(ar.ENTITY_KIND.eq(ref.kind().name()))
.and(ar.ENTITY_ID.eq(ref.id()))
.and(ar.ASSESSMENT_DEFINITION_ID.eq(command.assessmentDefinitionId()))
.and(ar.RATING_ID.eq(command.ratingId())));

return isUpdate
? dsl.executeUpdate(record) == 1
: dsl.executeInsert(record) == 1;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public Collection<MeasurableCategory> findCategoriesByDirectOrgUnit(long id) {
.fetch(TO_DOMAIN_MAPPER);
}

public boolean save(MeasurableCategory measurableCategory, String username) {
public Long save(MeasurableCategory measurableCategory, String username) {


MeasurableCategoryRecord record = dsl.newRecord(MEASURABLE_CATEGORY);
Expand All @@ -146,9 +146,9 @@ public boolean save(MeasurableCategory measurableCategory, String username) {

record.changed(MEASURABLE_CATEGORY.ID, false);

int update = record.store();
record.store();

return update == 1;
return record.getId();
}

public Map<Long, Long> findRatingCountsByCategoryId(EntityReference ref) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/*
* 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 org.finos.waltz.integration_test.inmem.service;

import org.finos.waltz.common.SetUtilities;
import org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest;
import org.finos.waltz.model.EntityKind;
import org.finos.waltz.model.EntityReference;
import org.finos.waltz.model.Operation;
import org.finos.waltz.model.exceptions.NotAuthorizedException;
import org.finos.waltz.model.measurable_category.ImmutableMeasurableCategory;
import org.finos.waltz.model.measurable_category.MeasurableCategory;
import org.finos.waltz.model.user.SystemRole;
import org.finos.waltz.service.measurable_category.MeasurableCategoryService;
import org.finos.waltz.test_common.helpers.ChangeLogHelper;
import org.finos.waltz.test_common.helpers.RatingSchemeHelper;
import org.finos.waltz.test_common.helpers.UserHelper;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

import static org.finos.waltz.model.EntityReference.mkRef;
import static org.finos.waltz.test_common.helpers.NameHelper.mkName;
import static org.junit.Assert.*;

public class MeasurableCategoryServiceTest extends BaseInMemoryIntegrationTest {

@Autowired
private MeasurableCategoryService mcSvc;

@Autowired
private UserHelper userHelper;

@Autowired
private RatingSchemeHelper ratingSchemeHelper;

@Autowired
private ChangeLogHelper changeLogHelper;


@Test
public void needToBeAnAdminOrTaxonomyEditorToSaveCategories() {
String admin = mkName("mc_admin");
String taxonomyEditor = mkName("mc_tax");
String unauthorised = mkName("unauthorised");
userHelper.createUserWithSystemRoles(admin, SetUtilities.asSet(SystemRole.ADMIN));
userHelper.createUserWithSystemRoles(taxonomyEditor, SetUtilities.asSet(SystemRole.TAXONOMY_EDITOR));
userHelper.createUserWithRoles(unauthorised, "WIBBLE");

ImmutableMeasurableCategory mc1 = mkMeasurableCategory("mc1");
assertTrue("Should work as has ADMIN role", mcSvc.save(mc1, admin) > 0L);

ImmutableMeasurableCategory mc2 = mkMeasurableCategory("mc2");
assertTrue("Should work as has TAXONOMY_EDITOR role", mcSvc.save(mc2, taxonomyEditor) > 0L);

ImmutableMeasurableCategory mc3 = mkMeasurableCategory("mc3");
assertThrows("Should not work as incorrect roles", NotAuthorizedException.class, () -> mcSvc.save(mc3, unauthorised));
}


@Test
public void categoriesCanBeUpdatedByRepeatedCallsToSave() {
String user = mkName("mc_tax");
userHelper.createUserWithSystemRoles(user, SetUtilities.asSet(SystemRole.TAXONOMY_EDITOR));

ImmutableMeasurableCategory v1Pre = mkMeasurableCategory("mc");
String v1Name = v1Pre.name();
Long mcId = mcSvc.save(v1Pre, user);
MeasurableCategory v1Post = mcSvc.getById(mcId);
assertEquals("Expected initially saved name to match", v1Name, v1Post.name());

EntityReference mcRef = mkRef(EntityKind.MEASURABLE_CATEGORY, mcId);
changeLogHelper.assertChangeLogContainsAtLeastOneMatchingOperation(mcRef, Operation.ADD);

ImmutableMeasurableCategory v2Pre = ImmutableMeasurableCategory.copyOf(v1Post)
.withName(mkName("updated_mc"))
.withDescription("updated desc")
.withAllowPrimaryRatings(false)
.withIcon("fire");

mcSvc.save(v2Pre, user);
MeasurableCategory v2Post = mcSvc.getById(mcId);
assertEquals("Expected updated name to match", v2Pre.name(), v2Post.name());
assertEquals("Expected updated desc to match", v2Pre.description(), v2Post.description());
assertEquals("Expected updated primary ratings to match", v2Pre.allowPrimaryRatings(), v2Post.allowPrimaryRatings());
assertEquals("Expected updated icon to match", v2Pre.icon(), v2Post.icon());

changeLogHelper.assertChangeLogContainsAtLeastOneMatchingOperation(mcRef, Operation.UPDATE);
}


// --- util

private ImmutableMeasurableCategory mkMeasurableCategory(String stem) {
return ImmutableMeasurableCategory
.builder()
.name(mkName(stem))
.externalId(mkName(stem.toUpperCase()))
.description(stem + " desc")
.icon("cog")
.allowPrimaryRatings(true)
.editable(true)
.lastUpdatedBy("mctest")
.ratingSchemeId(ratingSchemeHelper.createEmptyRatingScheme(stem + "_rs"))
.build();
}


}
16 changes: 16 additions & 0 deletions waltz-ng/client/common/svelte/ViewLink.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,26 @@
path: ctx => `logical-flow/${ctx.id}`,
title: "Logical Flow View"
},
"main.system.measurable-category.edit": {
path: ctx => `system/measurable-category/id/${ctx.id}/edit`,
title: "Measurable Category Edit"
},
"main.system.measurable-category.create": {
path: () => `system/measurable-category/create`,
title: "Measurable Category Create"
},
"main.system.measurable-category.list": {
path: () => `system/measurable-category/list`,
title: "Measurable Categories"
},
"main.measurable.view": {
path: ctx => `measurable/${ctx.id}`,
title: "Measurable View"
},
"main.measurable-category.list": {
path: ctx => `measurable-category/${ctx.id}`,
title: "Measurable View"
},
"main.org-unit.view": {
path: ctx => `org-units/${ctx.id}`,
title: "Org Unit View"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ function controller($q,
// -- boot

vm.$onInit = () => {
serviceBroker
.loadAppData(CORE_API.MeasurableStore.findAll)
.then(r => vm.measurables = _.filter(r.data, m => m.categoryId === categoryId));
reloadMeasurables();

serviceBroker
.loadAppData(CORE_API.MeasurableCategoryStore.findAll)
Expand Down
3 changes: 3 additions & 0 deletions waltz-ng/client/svelte-stores/page-navigation-store.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import {writable} from "svelte/store";

/**
* If you push an item into this store the browser will navigate to the
* corresponding page.
*
* Expects object looking like:
* {
* state: ''
Expand Down
42 changes: 42 additions & 0 deletions waltz-ng/client/system/measurable-category-create-view.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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
*
*/
import MeasurableCategoryEditView from "./svelte/measurable-categories/MeasurableCategoryEditView.svelte";
import {initialiseData} from "../common";


const initialState = {
MeasurableCategoryEditView
};


function controller($stateParams) {
const vm = initialiseData(this, initialState);

vm.id = $stateParams.id;
}


controller.$inject = ["$stateParams"];


export default {
template: `<waltz-svelte-component component="$ctrl.MeasurableCategoryEditView" mode="'CREATE'"></waltz-svelte-component>`,
controller,
controllerAs: "$ctrl",
bindToController: true,
};
42 changes: 42 additions & 0 deletions waltz-ng/client/system/measurable-category-edit-view.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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
*
*/
import MeasurableCategoryEditView from "./svelte/measurable-categories/MeasurableCategoryEditView.svelte";
import {initialiseData} from "../common";


const initialState = {
MeasurableCategoryEditView
};


function controller($stateParams) {
const vm = initialiseData(this, initialState);

vm.id = $stateParams.id;
}


controller.$inject = ["$stateParams"];


export default {
template: `<waltz-svelte-component component="$ctrl.MeasurableCategoryEditView" mode="'EDIT'" id="$ctrl.id"></waltz-svelte-component>`,
controller,
controllerAs: "$ctrl",
bindToController: true,
};
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
* See the License for the specific
*
*/
import MeasurableCategoriesAdminView from "./svelte/measurable-categories/MeasurableCategoriesAdminView.svelte";
import MeasurableCategoryListView from "./svelte/measurable-categories/MeasurableCategoryListView.svelte";
import {initialiseData} from "../common";


const initialState = {
MeasurableCategoriesAdminView
MeasurableCategoryListView
};


Expand All @@ -34,7 +34,7 @@ controller.$inject = [];


export default {
template: `<waltz-svelte-component component="$ctrl.MeasurableCategoriesAdminView"></waltz-svelte-component>`,
template: `<waltz-svelte-component component="$ctrl.MeasurableCategoryListView"></waltz-svelte-component>`,
controller,
controllerAs: "$ctrl",
bindToController: true,
Expand Down
33 changes: 28 additions & 5 deletions waltz-ng/client/system/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ import PermissionsView from "./permissions-view";
import NavAidBuilderView from "./nav-aid-builder-view";
import VersionInfoView from "./version-info-view";
import LicencesAdminView from "./licences-view";
import MeasurableCategoriesView from "./measurable-categories-view";
import MeasurableCategoryListView from "./measurable-category-list-view";
import MeasurableCategoryEditView from "./measurable-category-edit-view";
import MeasurableCategoryCreateView from "./measurable-category-create-view";
import DiagramBuilderView from "./diagram-builder-view";
import NavAidAdminView from "./nav-aids-view";

Expand Down Expand Up @@ -119,9 +121,27 @@ const licencesState = {
};


const measurableCategoriesState = {
url: "/measurable-categories",
views: { "content@": MeasurableCategoriesView }


const measurableCategoryState = {
url: "/measurable-category",
};

const measurableCategoryListState = {
url: "/list",
views: { "content@": MeasurableCategoryListView }
};


const measurableCategoryCreateState = {
url: "/create",
views: { "content@": MeasurableCategoryCreateView }
};


const measurableCategoryEditState = {
url: "/id/{id:int}/edit",
views: { "content@": MeasurableCategoryEditView }
};


Expand Down Expand Up @@ -181,7 +201,10 @@ function setupRoutes($stateProvider) {
.state("main.system.euda-list", eudaListState)
.state("main.system.hierarchies", hierarchiesState)
.state("main.system.licences", licencesState)
.state("main.system.measurable-categories", measurableCategoriesState)
.state("main.system.measurable-category", measurableCategoryState)
.state("main.system.measurable-category.list", measurableCategoryListState)
.state("main.system.measurable-category.edit", measurableCategoryEditState)
.state("main.system.measurable-category.create", measurableCategoryCreateState)
.state("main.system.nav-aids", navAidAdminState)
.state("main.system.nav-aid-builder", navAidBuilderState)
.state("main.system.orphans", orphansState)
Expand Down
Loading

0 comments on commit c9bce35

Please sign in to comment.