Refactor inlineImages
This commit is contained in:
		
							parent
							
								
									468fab3340
								
							
						
					
					
						commit
						993abb142e
					
				@ -27,20 +27,18 @@ import org.springframework.stereotype.Service;
 | 
			
		||||
import org.springframework.util.Base64Utils;
 | 
			
		||||
import org.thingsboard.server.cluster.TbClusterService;
 | 
			
		||||
import org.thingsboard.server.common.data.Dashboard;
 | 
			
		||||
import org.thingsboard.server.common.data.DeviceProfile;
 | 
			
		||||
import org.thingsboard.server.common.data.EntityType;
 | 
			
		||||
import org.thingsboard.server.common.data.HasImage;
 | 
			
		||||
import org.thingsboard.server.common.data.ImageDescriptor;
 | 
			
		||||
import org.thingsboard.server.common.data.StringUtils;
 | 
			
		||||
import org.thingsboard.server.common.data.TbImageDeleteResult;
 | 
			
		||||
import org.thingsboard.server.common.data.TbResource;
 | 
			
		||||
import org.thingsboard.server.common.data.TbResourceInfo;
 | 
			
		||||
import org.thingsboard.server.common.data.User;
 | 
			
		||||
import org.thingsboard.server.common.data.asset.AssetProfile;
 | 
			
		||||
import org.thingsboard.server.common.data.audit.ActionType;
 | 
			
		||||
import org.thingsboard.server.common.data.id.TbResourceId;
 | 
			
		||||
import org.thingsboard.server.common.data.id.TenantId;
 | 
			
		||||
import org.thingsboard.server.common.data.widget.WidgetTypeDetails;
 | 
			
		||||
import org.thingsboard.server.common.data.widget.WidgetsBundle;
 | 
			
		||||
import org.thingsboard.server.dao.resource.ImageService;
 | 
			
		||||
import org.thingsboard.server.gen.transport.TransportProtos;
 | 
			
		||||
import org.thingsboard.server.queue.util.TbCoreComponent;
 | 
			
		||||
@ -48,11 +46,9 @@ import org.thingsboard.server.service.entitiy.AbstractTbEntityService;
 | 
			
		||||
 | 
			
		||||
import java.util.Iterator;
 | 
			
		||||
import java.util.LinkedList;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
import java.util.Optional;
 | 
			
		||||
import java.util.Queue;
 | 
			
		||||
import java.util.concurrent.TimeUnit;
 | 
			
		||||
import java.util.function.Consumer;
 | 
			
		||||
 | 
			
		||||
@Service
 | 
			
		||||
@Slf4j
 | 
			
		||||
@ -167,32 +163,20 @@ public class DefaultTbImageService extends AbstractTbEntityService implements Tb
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void inlineImages(Dashboard entity) {
 | 
			
		||||
        var tenantId = entity.getTenantId();
 | 
			
		||||
        entity.setImage(inlineImage(tenantId, "image", entity.getImage()));
 | 
			
		||||
        inlineIntoJson(tenantId, entity.getConfiguration());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void inlineImages(WidgetTypeDetails entity) {
 | 
			
		||||
        var tenantId = entity.getTenantId();
 | 
			
		||||
        entity.setImage(inlineImage(tenantId, "image", entity.getImage()));
 | 
			
		||||
        inlineIntoJson(tenantId, entity.getDescriptor());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void inlineImages(WidgetsBundle entity) {
 | 
			
		||||
    public void inlineImages(HasImage entity) {
 | 
			
		||||
        entity.setImage(inlineImage(entity.getTenantId(), "image", entity.getImage()));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void inlineImages(AssetProfile entity) {
 | 
			
		||||
        entity.setImage(inlineImage(entity.getTenantId(), "image", entity.getImage()));
 | 
			
		||||
    public void inlineImages(Dashboard dashboard) {
 | 
			
		||||
        inlineImages((HasImage) dashboard);
 | 
			
		||||
        inlineIntoJson(dashboard.getTenantId(), dashboard.getConfiguration());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void inlineImages(DeviceProfile entity) {
 | 
			
		||||
        entity.setImage(inlineImage(entity.getTenantId(), "image", entity.getImage()));
 | 
			
		||||
    public void inlineImages(WidgetTypeDetails widgetTypeDetails) {
 | 
			
		||||
        inlineImages((HasImage) widgetTypeDetails);
 | 
			
		||||
        inlineIntoJson(widgetTypeDetails.getTenantId(), widgetTypeDetails.getDescriptor());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void inlineIntoJson(TenantId tenantId, JsonNode root) {
 | 
			
		||||
 | 
			
		||||
@ -16,15 +16,12 @@
 | 
			
		||||
package org.thingsboard.server.service.resource;
 | 
			
		||||
 | 
			
		||||
import org.thingsboard.server.common.data.Dashboard;
 | 
			
		||||
import org.thingsboard.server.common.data.DeviceProfile;
 | 
			
		||||
import org.thingsboard.server.common.data.HasImage;
 | 
			
		||||
import org.thingsboard.server.common.data.TbImageDeleteResult;
 | 
			
		||||
import org.thingsboard.server.common.data.TbResource;
 | 
			
		||||
import org.thingsboard.server.common.data.TbResourceInfo;
 | 
			
		||||
import org.thingsboard.server.common.data.User;
 | 
			
		||||
import org.thingsboard.server.common.data.asset.AssetProfile;
 | 
			
		||||
import org.thingsboard.server.common.data.id.TenantId;
 | 
			
		||||
import org.thingsboard.server.common.data.widget.WidgetTypeDetails;
 | 
			
		||||
import org.thingsboard.server.common.data.widget.WidgetsBundle;
 | 
			
		||||
 | 
			
		||||
public interface TbImageService {
 | 
			
		||||
 | 
			
		||||
@ -40,13 +37,10 @@ public interface TbImageService {
 | 
			
		||||
 | 
			
		||||
    void evictETag(ImageCacheKey imageCacheKey);
 | 
			
		||||
 | 
			
		||||
    void inlineImages(Dashboard entity);
 | 
			
		||||
    void inlineImages(HasImage entity);
 | 
			
		||||
 | 
			
		||||
    void inlineImages(WidgetTypeDetails entity);
 | 
			
		||||
    void inlineImages(Dashboard dashboard);
 | 
			
		||||
 | 
			
		||||
    void inlineImages(WidgetsBundle entity);
 | 
			
		||||
    void inlineImages(WidgetTypeDetails widgetTypeDetails);
 | 
			
		||||
 | 
			
		||||
    void inlineImages(AssetProfile entity);
 | 
			
		||||
 | 
			
		||||
    void inlineImages(DeviceProfile entity);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -41,7 +41,7 @@ import java.io.IOException;
 | 
			
		||||
@ToString(exclude = {"image", "profileDataBytes"})
 | 
			
		||||
@EqualsAndHashCode(callSuper = true)
 | 
			
		||||
@Slf4j
 | 
			
		||||
public class DeviceProfile extends BaseData<DeviceProfileId> implements HasName, HasTenantId, HasOtaPackage, HasRuleEngineProfile, ExportableEntity<DeviceProfileId> {
 | 
			
		||||
public class DeviceProfile extends BaseData<DeviceProfileId> implements HasName, HasTenantId, HasOtaPackage, HasRuleEngineProfile, ExportableEntity<DeviceProfileId>, HasImage {
 | 
			
		||||
 | 
			
		||||
    private static final long serialVersionUID = 6998485460273302018L;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,24 @@
 | 
			
		||||
/**
 | 
			
		||||
 * 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.common.data;
 | 
			
		||||
 | 
			
		||||
public interface HasImage extends HasTenantId {
 | 
			
		||||
 | 
			
		||||
    String getImage();
 | 
			
		||||
 | 
			
		||||
    void setImage(String image);
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@ -22,8 +22,8 @@ import lombok.EqualsAndHashCode;
 | 
			
		||||
import lombok.ToString;
 | 
			
		||||
import lombok.extern.slf4j.Slf4j;
 | 
			
		||||
import org.thingsboard.server.common.data.BaseData;
 | 
			
		||||
import org.thingsboard.server.common.data.BaseDataWithAdditionalInfo;
 | 
			
		||||
import org.thingsboard.server.common.data.ExportableEntity;
 | 
			
		||||
import org.thingsboard.server.common.data.HasImage;
 | 
			
		||||
import org.thingsboard.server.common.data.HasName;
 | 
			
		||||
import org.thingsboard.server.common.data.HasRuleEngineProfile;
 | 
			
		||||
import org.thingsboard.server.common.data.HasTenantId;
 | 
			
		||||
@ -39,7 +39,7 @@ import org.thingsboard.server.common.data.validation.NoXss;
 | 
			
		||||
@ToString(exclude = {"image"})
 | 
			
		||||
@EqualsAndHashCode(callSuper = true)
 | 
			
		||||
@Slf4j
 | 
			
		||||
public class AssetProfile extends BaseData<AssetProfileId> implements HasName, HasTenantId, HasRuleEngineProfile, ExportableEntity<AssetProfileId> {
 | 
			
		||||
public class AssetProfile extends BaseData<AssetProfileId> implements HasName, HasTenantId, HasRuleEngineProfile, ExportableEntity<AssetProfileId>, HasImage {
 | 
			
		||||
 | 
			
		||||
    private static final long serialVersionUID = 6998485460273302018L;
 | 
			
		||||
 | 
			
		||||
@ -114,7 +114,7 @@ public class AssetProfile extends BaseData<AssetProfileId> implements HasName, H
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @ApiModelProperty(position = 5, value = "Used to mark the default profile. Default profile is used when the asset profile is not specified during asset creation.")
 | 
			
		||||
    public boolean isDefault(){
 | 
			
		||||
    public boolean isDefault() {
 | 
			
		||||
        return isDefault;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -22,8 +22,8 @@ import lombok.EqualsAndHashCode;
 | 
			
		||||
import lombok.Getter;
 | 
			
		||||
import lombok.Setter;
 | 
			
		||||
import org.thingsboard.server.common.data.BaseData;
 | 
			
		||||
import org.thingsboard.server.common.data.BaseDataWithAdditionalInfo;
 | 
			
		||||
import org.thingsboard.server.common.data.ExportableEntity;
 | 
			
		||||
import org.thingsboard.server.common.data.HasImage;
 | 
			
		||||
import org.thingsboard.server.common.data.HasName;
 | 
			
		||||
import org.thingsboard.server.common.data.HasTenantId;
 | 
			
		||||
import org.thingsboard.server.common.data.HasTitle;
 | 
			
		||||
@ -34,7 +34,7 @@ import org.thingsboard.server.common.data.validation.NoXss;
 | 
			
		||||
 | 
			
		||||
@ApiModel
 | 
			
		||||
@EqualsAndHashCode(callSuper = true)
 | 
			
		||||
public class WidgetsBundle extends BaseData<WidgetsBundleId> implements HasName, HasTenantId, ExportableEntity<WidgetsBundleId>, HasTitle {
 | 
			
		||||
public class WidgetsBundle extends BaseData<WidgetsBundleId> implements HasName, HasTenantId, ExportableEntity<WidgetsBundleId>, HasTitle, HasImage {
 | 
			
		||||
 | 
			
		||||
    private static final long serialVersionUID = -7627368878362410489L;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user