Merge pull request #9286 from YevhenBondarenko/fix/widgets-bundle
fixed delete all types from widgets bundle
This commit is contained in:
commit
60453d9510
@ -157,4 +157,10 @@ public class Validator {
|
|||||||
return StringUtils.isEmpty(key) || RegexUtils.matches(key, PROPERTY_PATTERN);
|
return StringUtils.isEmpty(key) || RegexUtils.matches(key, PROPERTY_PATTERN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void checkNotNull(Object reference, String errorMessage) {
|
||||||
|
if (reference == null) {
|
||||||
|
throw new IncorrectParameterException(errorMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -178,7 +178,10 @@ public class WidgetTypeServiceImpl implements WidgetTypeService {
|
|||||||
log.trace("Executing updateWidgetsBundleWidgetTypes, tenantId [{}], widgetsBundleId [{}], widgetTypeIds [{}]", tenantId, widgetsBundleId, widgetTypeIds);
|
log.trace("Executing updateWidgetsBundleWidgetTypes, tenantId [{}], widgetsBundleId [{}], widgetTypeIds [{}]", tenantId, widgetsBundleId, widgetTypeIds);
|
||||||
Validator.validateId(tenantId, INCORRECT_TENANT_ID + tenantId);
|
Validator.validateId(tenantId, INCORRECT_TENANT_ID + tenantId);
|
||||||
Validator.validateId(widgetsBundleId, INCORRECT_WIDGETS_BUNDLE_ID + widgetsBundleId);
|
Validator.validateId(widgetsBundleId, INCORRECT_WIDGETS_BUNDLE_ID + widgetsBundleId);
|
||||||
|
Validator.checkNotNull(widgetTypeIds, "Incorrect widgetTypeIds " + widgetTypeIds);
|
||||||
|
if (!widgetTypeIds.isEmpty()) {
|
||||||
validateIds(widgetTypeIds, "Incorrect widgetTypeIds " + widgetTypeIds);
|
validateIds(widgetTypeIds, "Incorrect widgetTypeIds " + widgetTypeIds);
|
||||||
|
}
|
||||||
List<WidgetsBundleWidget> bundleWidgets = new ArrayList<>();
|
List<WidgetsBundleWidget> bundleWidgets = new ArrayList<>();
|
||||||
for (int index = 0; index < widgetTypeIds.size(); index++) {
|
for (int index = 0; index < widgetTypeIds.size(); index++) {
|
||||||
bundleWidgets.add(new WidgetsBundleWidget(widgetsBundleId, widgetTypeIds.get(index), index));
|
bundleWidgets.add(new WidgetsBundleWidget(widgetsBundleId, widgetTypeIds.get(index), index));
|
||||||
|
|||||||
@ -218,4 +218,33 @@ public class WidgetTypeServiceTest extends AbstractServiceTest {
|
|||||||
widgetsBundleService.deleteWidgetsBundle(tenantId, savedWidgetsBundle.getId());
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user