Merge pull request #9286 from YevhenBondarenko/fix/widgets-bundle

fixed delete all types from widgets bundle
This commit is contained in:
Andrew Shvayka 2023-09-20 12:53:06 +03:00 committed by GitHub
commit 60453d9510
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 1 deletions

View File

@ -157,4 +157,10 @@ public class Validator {
return StringUtils.isEmpty(key) || RegexUtils.matches(key, PROPERTY_PATTERN);
}
public static void checkNotNull(Object reference, String errorMessage) {
if (reference == null) {
throw new IncorrectParameterException(errorMessage);
}
}
}

View File

@ -178,7 +178,10 @@ public class WidgetTypeServiceImpl implements WidgetTypeService {
log.trace("Executing updateWidgetsBundleWidgetTypes, tenantId [{}], widgetsBundleId [{}], widgetTypeIds [{}]", tenantId, widgetsBundleId, widgetTypeIds);
Validator.validateId(tenantId, INCORRECT_TENANT_ID + tenantId);
Validator.validateId(widgetsBundleId, INCORRECT_WIDGETS_BUNDLE_ID + widgetsBundleId);
validateIds(widgetTypeIds, "Incorrect widgetTypeIds " + widgetTypeIds);
Validator.checkNotNull(widgetTypeIds, "Incorrect widgetTypeIds " + widgetTypeIds);
if (!widgetTypeIds.isEmpty()) {
validateIds(widgetTypeIds, "Incorrect widgetTypeIds " + widgetTypeIds);
}
List<WidgetsBundleWidget> bundleWidgets = new ArrayList<>();
for (int index = 0; index < widgetTypeIds.size(); index++) {
bundleWidgets.add(new WidgetsBundleWidget(widgetsBundleId, widgetTypeIds.get(index), index));

View File

@ -218,4 +218,33 @@ public class WidgetTypeServiceTest extends AbstractServiceTest {
widgetsBundleService.deleteWidgetsBundle(tenantId, savedWidgetsBundle.getId());
}
@Test
public void testDeleteAllTypesFromWidgetsBundle() {
WidgetsBundle widgetsBundle = new WidgetsBundle();
widgetsBundle.setTenantId(tenantId);
widgetsBundle.setTitle("Widgets bundle");
WidgetsBundle savedWidgetsBundle = widgetsBundleService.saveWidgetsBundle(widgetsBundle);
List<WidgetType> widgetTypes = new ArrayList<>();
for (int i = 0; i < 5; i++) {
WidgetTypeDetails widgetType = new WidgetTypeDetails();
widgetType.setTenantId(tenantId);
widgetType.setName("Widget Type " + i);
widgetType.setDescriptor(JacksonUtil.fromString("{ \"someKey\": \"someValue\" }", JsonNode.class));
widgetTypes.add(new WidgetType(widgetTypeService.saveWidgetType(widgetType)));
}
List<WidgetTypeId> widgetTypeIds = widgetTypes.stream().map(WidgetType::getId).collect(Collectors.toList());
widgetTypeService.updateWidgetsBundleWidgetTypes(tenantId, savedWidgetsBundle.getId(), widgetTypeIds);
List<WidgetType> loadedWidgetTypes = widgetTypeService.findWidgetTypesByWidgetsBundleId(tenantId, savedWidgetsBundle.getId());
Assert.assertEquals(widgetTypes.size(), loadedWidgetTypes.size());
widgetTypeService.updateWidgetsBundleWidgetTypes(tenantId, savedWidgetsBundle.getId(), Collections.emptyList());
loadedWidgetTypes = widgetTypeService.findWidgetTypesByWidgetsBundleId(tenantId, savedWidgetsBundle.getId());
Assert.assertEquals(0, loadedWidgetTypes.size());
}
}