|
|
@ -20,14 +20,21 @@ import org.springframework.context.annotation.Lazy; |
|
|
import org.springframework.stereotype.Component; |
|
|
import org.springframework.stereotype.Component; |
|
|
import org.thingsboard.server.common.data.StringUtils; |
|
|
import org.thingsboard.server.common.data.StringUtils; |
|
|
import org.thingsboard.server.common.data.TbResource; |
|
|
import org.thingsboard.server.common.data.TbResource; |
|
|
|
|
|
import org.thingsboard.server.common.data.id.EntityId; |
|
|
import org.thingsboard.server.common.data.id.TenantId; |
|
|
import org.thingsboard.server.common.data.id.TenantId; |
|
|
import org.thingsboard.server.common.data.tenant.profile.DefaultTenantProfileConfiguration; |
|
|
import org.thingsboard.server.common.data.tenant.profile.DefaultTenantProfileConfiguration; |
|
|
|
|
|
import org.thingsboard.server.common.data.widget.BaseWidgetType; |
|
|
|
|
|
import org.thingsboard.server.common.data.widget.WidgetTypeDetails; |
|
|
import org.thingsboard.server.dao.exception.DataValidationException; |
|
|
import org.thingsboard.server.dao.exception.DataValidationException; |
|
|
import org.thingsboard.server.dao.model.ModelConstants; |
|
|
import org.thingsboard.server.dao.model.ModelConstants; |
|
|
import org.thingsboard.server.dao.resource.TbResourceDao; |
|
|
import org.thingsboard.server.dao.resource.TbResourceDao; |
|
|
import org.thingsboard.server.dao.service.DataValidator; |
|
|
import org.thingsboard.server.dao.service.DataValidator; |
|
|
import org.thingsboard.server.dao.tenant.TbTenantProfileCache; |
|
|
import org.thingsboard.server.dao.tenant.TbTenantProfileCache; |
|
|
import org.thingsboard.server.dao.tenant.TenantService; |
|
|
import org.thingsboard.server.dao.tenant.TenantService; |
|
|
|
|
|
import org.thingsboard.server.dao.widget.WidgetTypeDao; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
import static org.thingsboard.server.common.data.EntityType.TB_RESOURCE; |
|
|
import static org.thingsboard.server.common.data.EntityType.TB_RESOURCE; |
|
|
|
|
|
|
|
|
@ -37,6 +44,9 @@ public class ResourceDataValidator extends DataValidator<TbResource> { |
|
|
@Autowired |
|
|
@Autowired |
|
|
private TbResourceDao resourceDao; |
|
|
private TbResourceDao resourceDao; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private WidgetTypeDao widgetTypeDao; |
|
|
|
|
|
|
|
|
@Autowired |
|
|
@Autowired |
|
|
private TenantService tenantService; |
|
|
private TenantService tenantService; |
|
|
|
|
|
|
|
|
@ -77,4 +87,15 @@ public class ResourceDataValidator extends DataValidator<TbResource> { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public void validateDelete(TenantId tenantId, EntityId resourceId) { |
|
|
|
|
|
List<WidgetTypeDetails> widgets = widgetTypeDao.findWidgetTypesInfosByTenantIdAndResourceId(tenantId.getId(), |
|
|
|
|
|
resourceId.getId()); |
|
|
|
|
|
if (!widgets.isEmpty()) { |
|
|
|
|
|
List<String> widgetNames = widgets.stream().map(BaseWidgetType::getName).collect(Collectors.toList()); |
|
|
|
|
|
throw new DataValidationException(String.format("Following widget types uses current resource: %s", widgetNames)); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|