From d70ce27253a1c5a996095cae4ea44b28c6b6bebd Mon Sep 17 00:00:00 2001 From: ViacheslavKlimov Date: Tue, 14 Nov 2023 12:08:59 +0200 Subject: [PATCH] Fix build --- .../service/install/update/ImagesUpdater.java | 32 +++++++++---------- .../resource/DefaultTbImageService.java | 15 +++++++++ .../service/resource/TbImageService.java | 15 +++++++++ .../server/dao/resource/ImageService.java | 17 +++++++++- .../server/dao/resource/BaseImageService.java | 18 +++++++++-- 5 files changed, 78 insertions(+), 19 deletions(-) diff --git a/application/src/main/java/org/thingsboard/server/service/install/update/ImagesUpdater.java b/application/src/main/java/org/thingsboard/server/service/install/update/ImagesUpdater.java index 74ee36ce34..9894ed5360 100644 --- a/application/src/main/java/org/thingsboard/server/service/install/update/ImagesUpdater.java +++ b/application/src/main/java/org/thingsboard/server/service/install/update/ImagesUpdater.java @@ -33,7 +33,7 @@ import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.common.data.util.ImageUtils; import org.thingsboard.server.common.data.widget.WidgetTypeDetails; import org.thingsboard.server.common.data.widget.WidgetsBundle; -import org.thingsboard.server.dao.resource.ResourceService; +import org.thingsboard.server.dao.resource.ImageService; import java.nio.file.Files; import java.nio.file.Path; @@ -47,7 +47,7 @@ import java.util.Optional; @RequiredArgsConstructor public class ImagesUpdater { - private final ResourceService resourceService; + private final ImageService imageService; private static final String IMAGE_NAME_SUFFIX = " - image"; private static final String BACKGROUND_IMAGE_NAME_SUFFIX = " - background image"; @@ -201,19 +201,19 @@ public class ImagesUpdater { private String saveImage(TenantId tenantId, String name, String key, byte[] imageData, String mediaType, String existingImageQuery) { - TbResourceInfo resourceInfo = resourceService.findResourceInfoByTenantIdAndKey(tenantId, ResourceType.IMAGE, key); + TbResourceInfo resourceInfo = imageService.getImageInfoByTenantIdAndKey(tenantId, key); if (resourceInfo == null && !tenantId.isSysTenantId() && existingImageQuery != null) { // TODO: need to search among tenant images too (custom widgets) - List existingSystemImages = resourceService.findByTenantIdAndDataAndKeyStartingWith(TenantId.SYS_TENANT_ID, imageData, existingImageQuery); - if (!existingSystemImages.isEmpty()) { - resourceInfo = existingSystemImages.get(0); - if (existingSystemImages.size() > 1) { - log.warn("Found more than one system image resources for key {}", existingImageQuery); - } - String link = resourceService.getResourceLink(resourceInfo); - log.info("Using system image {} for {}", link, key); - return link; - } +// List existingSystemImages = imageService.findByTenantIdAndDataAndKeyStartingWith(TenantId.SYS_TENANT_ID, imageData, existingImageQuery); +// if (!existingSystemImages.isEmpty()) { +// resourceInfo = existingSystemImages.get(0); +// if (existingSystemImages.size() > 1) { +// log.warn("Found more than one system image resources for key {}", existingImageQuery); +// } +// String link = imageService.getImageLink(resourceInfo); +// log.info("Using system image {} for {}", link, key); +// return link; +// } } TbResource resource; if (resourceInfo == null) { @@ -224,16 +224,16 @@ public class ImagesUpdater { } else if (tenantId.isSysTenantId()) { resource = new TbResource(resourceInfo); } else { - return resourceService.getResourceLink(resourceInfo); + return imageService.getImageLink(resourceInfo); } resource.setTitle(name); resource.setFileName(key); resource.setMediaType(mediaType); resource.setData(imageData); - resource = resourceService.saveResource(resource); + resource = imageService.saveImage(resource); log.info("[{}] {} image '{}' ({})", tenantId, resourceInfo == null ? "Created" : "Updated", resource.getTitle(), resource.getResourceKey()); - return resourceService.getResourceLink(resourceInfo); + return imageService.getImageLink(resourceInfo); } private String getText(JsonNode jsonNode, String field) { diff --git a/application/src/main/java/org/thingsboard/server/service/resource/DefaultTbImageService.java b/application/src/main/java/org/thingsboard/server/service/resource/DefaultTbImageService.java index d367bb2aa2..0c58f6a10a 100644 --- a/application/src/main/java/org/thingsboard/server/service/resource/DefaultTbImageService.java +++ b/application/src/main/java/org/thingsboard/server/service/resource/DefaultTbImageService.java @@ -1,3 +1,18 @@ +/** + * Copyright © 2016-2023 The Thingsboard Authors + * + * 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 language governing permissions and + * limitations under the License. + */ package org.thingsboard.server.service.resource; import lombok.RequiredArgsConstructor; diff --git a/application/src/main/java/org/thingsboard/server/service/resource/TbImageService.java b/application/src/main/java/org/thingsboard/server/service/resource/TbImageService.java index 5acb1b4180..7039d0edaa 100644 --- a/application/src/main/java/org/thingsboard/server/service/resource/TbImageService.java +++ b/application/src/main/java/org/thingsboard/server/service/resource/TbImageService.java @@ -1,3 +1,18 @@ +/** + * Copyright © 2016-2023 The Thingsboard Authors + * + * 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 language governing permissions and + * limitations under the License. + */ package org.thingsboard.server.service.resource; import org.springframework.web.multipart.MultipartFile; diff --git a/common/dao-api/src/main/java/org/thingsboard/server/dao/resource/ImageService.java b/common/dao-api/src/main/java/org/thingsboard/server/dao/resource/ImageService.java index b31befa36b..a09a00296f 100644 --- a/common/dao-api/src/main/java/org/thingsboard/server/dao/resource/ImageService.java +++ b/common/dao-api/src/main/java/org/thingsboard/server/dao/resource/ImageService.java @@ -1,3 +1,18 @@ +/** + * Copyright © 2016-2023 The Thingsboard Authors + * + * 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 language governing permissions and + * limitations under the License. + */ package org.thingsboard.server.dao.resource; import org.thingsboard.server.common.data.TbResource; @@ -9,7 +24,7 @@ import org.thingsboard.server.common.data.page.PageLink; public interface ImageService { - TbResourceInfo saveImage(TbResource image); + TbResource saveImage(TbResource image); TbResourceInfo saveImageInfo(TbResourceInfo imageInfo); diff --git a/dao/src/main/java/org/thingsboard/server/dao/resource/BaseImageService.java b/dao/src/main/java/org/thingsboard/server/dao/resource/BaseImageService.java index 19959baf54..29a6f98409 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/resource/BaseImageService.java +++ b/dao/src/main/java/org/thingsboard/server/dao/resource/BaseImageService.java @@ -1,6 +1,20 @@ +/** + * Copyright © 2016-2023 The Thingsboard Authors + * + * 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 language governing permissions and + * limitations under the License. + */ package org.thingsboard.server.dao.resource; -import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.thingsboard.server.common.data.ResourceType; import org.thingsboard.server.common.data.TbResource; @@ -22,7 +36,7 @@ public class BaseImageService extends BaseResourceService implements ImageServic } @Override - public TbResourceInfo saveImage(TbResource image) { + public TbResource saveImage(TbResource image) { resourceValidator.validate(image, TbResourceInfo::getTenantId); if (image.getData() != null) {