Fix build

This commit is contained in:
ViacheslavKlimov 2023-11-14 12:08:59 +02:00
parent 7d4729451a
commit d70ce27253
5 changed files with 78 additions and 19 deletions

View File

@ -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.util.ImageUtils;
import org.thingsboard.server.common.data.widget.WidgetTypeDetails; import org.thingsboard.server.common.data.widget.WidgetTypeDetails;
import org.thingsboard.server.common.data.widget.WidgetsBundle; 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.Files;
import java.nio.file.Path; import java.nio.file.Path;
@ -47,7 +47,7 @@ import java.util.Optional;
@RequiredArgsConstructor @RequiredArgsConstructor
public class ImagesUpdater { public class ImagesUpdater {
private final ResourceService resourceService; private final ImageService imageService;
private static final String IMAGE_NAME_SUFFIX = " - image"; private static final String IMAGE_NAME_SUFFIX = " - image";
private static final String BACKGROUND_IMAGE_NAME_SUFFIX = " - background 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, private String saveImage(TenantId tenantId, String name, String key, byte[] imageData, String mediaType,
String existingImageQuery) { String existingImageQuery) {
TbResourceInfo resourceInfo = resourceService.findResourceInfoByTenantIdAndKey(tenantId, ResourceType.IMAGE, key); TbResourceInfo resourceInfo = imageService.getImageInfoByTenantIdAndKey(tenantId, key);
if (resourceInfo == null && !tenantId.isSysTenantId() && existingImageQuery != null) { if (resourceInfo == null && !tenantId.isSysTenantId() && existingImageQuery != null) {
// TODO: need to search among tenant images too (custom widgets) // TODO: need to search among tenant images too (custom widgets)
List<TbResourceInfo> existingSystemImages = resourceService.findByTenantIdAndDataAndKeyStartingWith(TenantId.SYS_TENANT_ID, imageData, existingImageQuery); // List<TbResourceInfo> existingSystemImages = imageService.findByTenantIdAndDataAndKeyStartingWith(TenantId.SYS_TENANT_ID, imageData, existingImageQuery);
if (!existingSystemImages.isEmpty()) { // if (!existingSystemImages.isEmpty()) {
resourceInfo = existingSystemImages.get(0); // resourceInfo = existingSystemImages.get(0);
if (existingSystemImages.size() > 1) { // if (existingSystemImages.size() > 1) {
log.warn("Found more than one system image resources for key {}", existingImageQuery); // log.warn("Found more than one system image resources for key {}", existingImageQuery);
} // }
String link = resourceService.getResourceLink(resourceInfo); // String link = imageService.getImageLink(resourceInfo);
log.info("Using system image {} for {}", link, key); // log.info("Using system image {} for {}", link, key);
return link; // return link;
} // }
} }
TbResource resource; TbResource resource;
if (resourceInfo == null) { if (resourceInfo == null) {
@ -224,16 +224,16 @@ public class ImagesUpdater {
} else if (tenantId.isSysTenantId()) { } else if (tenantId.isSysTenantId()) {
resource = new TbResource(resourceInfo); resource = new TbResource(resourceInfo);
} else { } else {
return resourceService.getResourceLink(resourceInfo); return imageService.getImageLink(resourceInfo);
} }
resource.setTitle(name); resource.setTitle(name);
resource.setFileName(key); resource.setFileName(key);
resource.setMediaType(mediaType); resource.setMediaType(mediaType);
resource.setData(imageData); resource.setData(imageData);
resource = resourceService.saveResource(resource); resource = imageService.saveImage(resource);
log.info("[{}] {} image '{}' ({})", tenantId, resourceInfo == null ? "Created" : "Updated", log.info("[{}] {} image '{}' ({})", tenantId, resourceInfo == null ? "Created" : "Updated",
resource.getTitle(), resource.getResourceKey()); resource.getTitle(), resource.getResourceKey());
return resourceService.getResourceLink(resourceInfo); return imageService.getImageLink(resourceInfo);
} }
private String getText(JsonNode jsonNode, String field) { private String getText(JsonNode jsonNode, String field) {

View File

@ -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; package org.thingsboard.server.service.resource;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;

View File

@ -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; package org.thingsboard.server.service.resource;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;

View File

@ -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; package org.thingsboard.server.dao.resource;
import org.thingsboard.server.common.data.TbResource; import org.thingsboard.server.common.data.TbResource;
@ -9,7 +24,7 @@ import org.thingsboard.server.common.data.page.PageLink;
public interface ImageService { public interface ImageService {
TbResourceInfo saveImage(TbResource image); TbResource saveImage(TbResource image);
TbResourceInfo saveImageInfo(TbResourceInfo imageInfo); TbResourceInfo saveImageInfo(TbResourceInfo imageInfo);

View File

@ -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; package org.thingsboard.server.dao.resource;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.thingsboard.server.common.data.ResourceType; import org.thingsboard.server.common.data.ResourceType;
import org.thingsboard.server.common.data.TbResource; import org.thingsboard.server.common.data.TbResource;
@ -22,7 +36,7 @@ public class BaseImageService extends BaseResourceService implements ImageServic
} }
@Override @Override
public TbResourceInfo saveImage(TbResource image) { public TbResource saveImage(TbResource image) {
resourceValidator.validate(image, TbResourceInfo::getTenantId); resourceValidator.validate(image, TbResourceInfo::getTenantId);
if (image.getData() != null) { if (image.getData() != null) {