Skip to content

Commit

Permalink
Adding change logs to SurveyActionQueueService
Browse files Browse the repository at this point in the history
- Used to inform if an action has been applied via scheduled queue, useful as prints the reason if the action failed.

#CTCTOWALTZ-2680
finos#6860
jessica-woodland-scott-db committed Nov 22, 2023
1 parent 52800ac commit ecea9c5
Showing 5 changed files with 30 additions and 51 deletions.
26 changes: 0 additions & 26 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -310,24 +310,6 @@


<!-- test -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>1.7.2</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
@@ -342,14 +324,6 @@
<scope>test</scope>
</dependency>

<!--intellij required as workaround https://youtrack.jetbrains.com/issue/IDEA-231927 -->
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.tngtech.archunit</groupId>
<artifactId>archunit</artifactId>
Original file line number Diff line number Diff line change
@@ -74,14 +74,14 @@ public class DataTypeDecoratorServiceTest extends BaseInMemoryIntegrationTest {
@Test
public void findByFlowIds() {

Collection<DataTypeDecorator> lfDecs = dtdSvc.findByFlowIds(emptyList(), EntityKind.LOGICAL_DATA_FLOW);
Collection<DataTypeDecorator> psDecs = dtdSvc.findByFlowIds(emptyList(), EntityKind.PHYSICAL_SPECIFICATION);
Set<DataTypeDecorator> lfDecs = dtdSvc.findByFlowIds(emptyList(), EntityKind.LOGICAL_DATA_FLOW);
Set<DataTypeDecorator> psDecs = dtdSvc.findByFlowIds(emptyList(), EntityKind.PHYSICAL_SPECIFICATION);

assertEquals(emptyList(), lfDecs, "If empty id list provided returns empty list");
assertEquals(emptyList(), psDecs, "If empty id list provided returns empty list");
assertEquals(emptySet(), lfDecs, "If empty id list provided returns empty set");
assertEquals(emptySet(), psDecs, "If empty id list provided returns empty set");

Collection<DataTypeDecorator> invalidId = dtdSvc.findByFlowIds(asList(-1L), EntityKind.LOGICAL_DATA_FLOW);
assertEquals(emptyList(), invalidId, "If flow id doesn't exist returns empty list");
assertEquals(emptySet(), invalidId, "If flow id doesn't exist returns empty set");

assertThrows(IllegalArgumentException.class,
() -> dtdSvc.findByFlowIds(asList(-1L), EntityKind.APPLICATION),
@@ -92,16 +92,16 @@ public void findByFlowIds() {

LogicalFlow flow = lfHelper.createLogicalFlow(a, b);

Collection<DataTypeDecorator> withNoDecorators = dtdSvc.findByFlowIds(asList(flow.entityReference().id()), EntityKind.LOGICAL_DATA_FLOW);
assertEquals(emptyList(), withNoDecorators,
Set<DataTypeDecorator> withNoDecorators = dtdSvc.findByFlowIds(asList(flow.entityReference().id()), EntityKind.LOGICAL_DATA_FLOW);
assertEquals(emptySet(), withNoDecorators,
"flow has no decorators");

Long dtId = dataTypeHelper.createDataType("findByFlowIds");
String username = mkName("findByFlowIds");

dtdSvc.updateDecorators(username, flow.entityReference(), asSet(dtId), emptySet());

Collection<DataTypeDecorator> flowDecorators = dtdSvc.findByFlowIds(asList(flow.entityReference().id()), EntityKind.LOGICAL_DATA_FLOW);
Set<DataTypeDecorator> flowDecorators = dtdSvc.findByFlowIds(asList(flow.entityReference().id()), EntityKind.LOGICAL_DATA_FLOW);
assertEquals(1, flowDecorators.size(), "Flow with one datatype associated returns a set with one decorator");
assertEquals(dtId, Long.valueOf(first(flowDecorators).dataTypeId()),
"Returns the correct datatype id on the decorator");
@@ -110,7 +110,7 @@ public void findByFlowIds() {
Long dtId3 = dataTypeHelper.createDataType("findByFlowIds3");
dtdSvc.updateDecorators(username, flow.entityReference(), asSet(dtId2, dtId3), emptySet());

Collection<DataTypeDecorator> multipleDecorators = dtdSvc.findByFlowIds(asList(flow.entityReference().id()), EntityKind.LOGICAL_DATA_FLOW);
Set<DataTypeDecorator> multipleDecorators = dtdSvc.findByFlowIds(asList(flow.entityReference().id()), EntityKind.LOGICAL_DATA_FLOW);
assertEquals(3, multipleDecorators.size());
assertEquals(asSet(dtId, dtId2, dtId3), map(multipleDecorators, DataTypeDecorator::dataTypeId),
"Returns all decorators for the flow");
Original file line number Diff line number Diff line change
@@ -296,9 +296,9 @@ private Collection<DataTypeDecorator> getSelectorForLogicalFlow(DataTypeDecorato
}


public Collection<DataTypeDecorator> findByFlowIds(Collection<Long> ids, EntityKind entityKind) {
public Set<DataTypeDecorator> findByFlowIds(Collection<Long> ids, EntityKind entityKind) {
if (isEmpty(ids)) {
return Collections.emptyList();
return Collections.emptySet();
}
return dataTypeDecoratorDaoSelectorFactory
.getDao(entityKind)
Original file line number Diff line number Diff line change
@@ -93,7 +93,7 @@ public void performActions() {

} else if (instance.status() != action.initialState()) {

String msg = format("Failed to apply queued action: %s. Initial state of survey instance with id: %d is not as expected: %s and is actually %s",
String msg = format("Failed to apply queued action: %s to survey: %d. Initial state of survey is not as expected: %s and is actually %s",
action.action().name(),
action.surveyInstanceId(),
action.initialState().name(),
@@ -138,8 +138,9 @@ public void performActions() {
action.surveyInstanceId(),
updateCmd);

String msg = format("Successfully applied queued action: %s. New status is: %s",
String msg = format("Successfully applied queued action: %s to survey: %d. New status is: %s",
action.action().name(),
action.surveyInstanceId(),
surveyInstanceStatus.name());

LOG.info(msg);
@@ -156,7 +157,7 @@ public void performActions() {

} catch (Exception e) {

String msg = format("Failed to apply queued action: %s. Error when updating survey instance id: %d, %s",
String msg = format("Failed to apply queued action: %s to survey: %d. Error when updating: %s",
action.action().name(),
action.surveyInstanceId(),
e.getMessage());
Original file line number Diff line number Diff line change
@@ -18,17 +18,17 @@

package org.finos.waltz.web.endpoints.api;

import org.finos.waltz.service.data_flow_decorator.LogicalFlowDecoratorService;
import org.finos.waltz.service.data_type.DataTypeDecoratorService;
import org.finos.waltz.service.user.UserRoleService;
import org.finos.waltz.web.ListRoute;
import org.finos.waltz.web.endpoints.Endpoint;
import org.finos.waltz.model.IdSelectionOptions;
import org.finos.waltz.model.data_flow_decorator.DecoratorRatingSummary;
import org.finos.waltz.model.data_flow_decorator.LogicalFlowDecoratorStat;
import org.finos.waltz.model.data_flow_decorator.UpdateDataFlowDecoratorsAction;
import org.finos.waltz.model.datatype.DataTypeDecorator;
import org.finos.waltz.model.user.SystemRole;
import org.finos.waltz.service.data_flow_decorator.LogicalFlowDecoratorService;
import org.finos.waltz.service.data_type.DataTypeDecoratorService;
import org.finos.waltz.service.user.UserRoleService;
import org.finos.waltz.web.ListRoute;
import org.finos.waltz.web.endpoints.Endpoint;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -38,15 +38,19 @@

import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Set;

import static org.finos.waltz.web.WebUtilities.*;
import static org.finos.waltz.web.endpoints.EndpointUtilities.getForList;
import static org.finos.waltz.web.endpoints.EndpointUtilities.postForList;
import static org.finos.waltz.common.Checks.checkNotNull;
import static org.finos.waltz.common.CollectionUtilities.map;
import static org.finos.waltz.model.EntityKind.LOGICAL_DATA_FLOW;
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.WebUtilities.readIdSelectionOptionsFromBody;
import static org.finos.waltz.web.WebUtilities.requireRole;
import static org.finos.waltz.web.endpoints.EndpointUtilities.getForList;
import static org.finos.waltz.web.endpoints.EndpointUtilities.postForList;


@Service
@@ -118,14 +122,14 @@ public void register() {
}


private Collection<DataTypeDecorator> updateDecoratorsBatchRoute(Request request, Response response) throws IOException {
private Set<DataTypeDecorator> updateDecoratorsBatchRoute(Request request, Response response) throws IOException {
requireRole(userRoleService, request, SystemRole.BULK_FLOW_EDITOR);

String user = getUsername(request);
List<UpdateDataFlowDecoratorsAction> actions = Arrays.asList(readBody(request, UpdateDataFlowDecoratorsAction[].class));

logicalFlowDecoratorService.addDecoratorsBatch(actions, user);
return dataTypeDecoratorService.findByFlowIds(map(actions, a -> a.flowId()), LOGICAL_DATA_FLOW);
return dataTypeDecoratorService.findByFlowIds(map(actions, UpdateDataFlowDecoratorsAction::flowId), LOGICAL_DATA_FLOW);
}

}

0 comments on commit ecea9c5

Please sign in to comment.