Improve OtaPackageExportData
This commit is contained in:
		
							parent
							
								
									27473619db
								
							
						
					
					
						commit
						7ffd468d06
					
				@ -20,7 +20,7 @@ import org.springframework.stereotype.Service;
 | 
			
		||||
import org.thingsboard.server.common.data.EntityType;
 | 
			
		||||
import org.thingsboard.server.common.data.OtaPackage;
 | 
			
		||||
import org.thingsboard.server.common.data.id.OtaPackageId;
 | 
			
		||||
import org.thingsboard.server.common.data.sync.ie.EntityExportData;
 | 
			
		||||
import org.thingsboard.server.common.data.sync.ie.OtaPackageExportData;
 | 
			
		||||
import org.thingsboard.server.queue.util.TbCoreComponent;
 | 
			
		||||
import org.thingsboard.server.service.sync.vc.data.EntitiesExportCtx;
 | 
			
		||||
 | 
			
		||||
@ -29,13 +29,18 @@ import java.util.Set;
 | 
			
		||||
@Service
 | 
			
		||||
@TbCoreComponent
 | 
			
		||||
@RequiredArgsConstructor
 | 
			
		||||
public class OtaPackageExportService extends BaseEntityExportService<OtaPackageId, OtaPackage, EntityExportData<OtaPackage>> {
 | 
			
		||||
public class OtaPackageExportService extends BaseEntityExportService<OtaPackageId, OtaPackage, OtaPackageExportData> {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    protected void setRelatedEntities(EntitiesExportCtx<?> ctx, OtaPackage otaPackage, EntityExportData<OtaPackage> exportData) {
 | 
			
		||||
    protected void setRelatedEntities(EntitiesExportCtx<?> ctx, OtaPackage otaPackage, OtaPackageExportData exportData) {
 | 
			
		||||
        otaPackage.setDeviceProfileId(getExternalIdOrElseInternal(ctx, otaPackage.getDeviceProfileId()));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    protected OtaPackageExportData newExportData() {
 | 
			
		||||
        return new OtaPackageExportData();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Set<EntityType> getSupportedEntityTypes() {
 | 
			
		||||
        return Set.of(EntityType.OTA_PACKAGE);
 | 
			
		||||
 | 
			
		||||
@ -19,11 +19,9 @@ import lombok.RequiredArgsConstructor;
 | 
			
		||||
import org.springframework.stereotype.Service;
 | 
			
		||||
import org.thingsboard.server.common.data.EntityType;
 | 
			
		||||
import org.thingsboard.server.common.data.OtaPackage;
 | 
			
		||||
import org.thingsboard.server.common.data.User;
 | 
			
		||||
import org.thingsboard.server.common.data.exception.ThingsboardException;
 | 
			
		||||
import org.thingsboard.server.common.data.id.OtaPackageId;
 | 
			
		||||
import org.thingsboard.server.common.data.id.TenantId;
 | 
			
		||||
import org.thingsboard.server.common.data.sync.ie.EntityExportData;
 | 
			
		||||
import org.thingsboard.server.common.data.sync.ie.OtaPackageExportData;
 | 
			
		||||
import org.thingsboard.server.dao.ota.OtaPackageService;
 | 
			
		||||
import org.thingsboard.server.queue.util.TbCoreComponent;
 | 
			
		||||
import org.thingsboard.server.service.sync.vc.data.EntitiesImportCtx;
 | 
			
		||||
@ -31,7 +29,7 @@ import org.thingsboard.server.service.sync.vc.data.EntitiesImportCtx;
 | 
			
		||||
@Service
 | 
			
		||||
@TbCoreComponent
 | 
			
		||||
@RequiredArgsConstructor
 | 
			
		||||
public class OtaPackageImportService extends BaseEntityImportService<OtaPackageId, OtaPackage, EntityExportData<OtaPackage>> {
 | 
			
		||||
public class OtaPackageImportService extends BaseEntityImportService<OtaPackageId, OtaPackage, OtaPackageExportData> {
 | 
			
		||||
 | 
			
		||||
    private final OtaPackageService otaPackageService;
 | 
			
		||||
 | 
			
		||||
@ -41,7 +39,7 @@ public class OtaPackageImportService extends BaseEntityImportService<OtaPackageI
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    protected OtaPackage prepare(EntitiesImportCtx ctx, OtaPackage otaPackage, OtaPackage oldOtaPackage, EntityExportData<OtaPackage> exportData, IdProvider idProvider) {
 | 
			
		||||
    protected OtaPackage prepare(EntitiesImportCtx ctx, OtaPackage otaPackage, OtaPackage oldOtaPackage, OtaPackageExportData exportData, IdProvider idProvider) {
 | 
			
		||||
        otaPackage.setDeviceProfileId(idProvider.getInternalId(otaPackage.getDeviceProfileId()));
 | 
			
		||||
        return otaPackage;
 | 
			
		||||
    }
 | 
			
		||||
@ -66,15 +64,10 @@ public class OtaPackageImportService extends BaseEntityImportService<OtaPackageI
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    protected OtaPackage saveOrUpdate(EntitiesImportCtx ctx, OtaPackage otaPackage, EntityExportData<OtaPackage> exportData, IdProvider idProvider, CompareResult compareResult) {
 | 
			
		||||
    protected OtaPackage saveOrUpdate(EntitiesImportCtx ctx, OtaPackage otaPackage, OtaPackageExportData exportData, IdProvider idProvider, CompareResult compareResult) {
 | 
			
		||||
        return otaPackageService.saveOtaPackage(otaPackage);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    protected void onEntitySaved(User user, OtaPackage savedOtaPackage, OtaPackage oldOtaPackage) throws ThingsboardException {
 | 
			
		||||
        super.onEntitySaved(user, savedOtaPackage, oldOtaPackage);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public EntityType getEntityType() {
 | 
			
		||||
        return EntityType.OTA_PACKAGE;
 | 
			
		||||
 | 
			
		||||
@ -15,9 +15,7 @@
 | 
			
		||||
 */
 | 
			
		||||
package org.thingsboard.server.common.data;
 | 
			
		||||
 | 
			
		||||
import com.fasterxml.jackson.annotation.JsonAlias;
 | 
			
		||||
import com.fasterxml.jackson.annotation.JsonIgnore;
 | 
			
		||||
import com.fasterxml.jackson.annotation.JsonProperty;
 | 
			
		||||
import com.fasterxml.jackson.databind.JsonNode;
 | 
			
		||||
import io.swagger.v3.oas.annotations.media.Schema;
 | 
			
		||||
import lombok.Data;
 | 
			
		||||
@ -136,17 +134,6 @@ public class OtaPackageInfo extends BaseDataWithAdditionalInfo<OtaPackageId> imp
 | 
			
		||||
        return StringUtils.isNotEmpty(url);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @JsonProperty("otaVersion")
 | 
			
		||||
    @JsonAlias("version")
 | 
			
		||||
    public void setVersion(String version) {
 | 
			
		||||
        this.version = version;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @JsonProperty("otaVersion")
 | 
			
		||||
    public String getVersion() {
 | 
			
		||||
        return version;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Schema(description = "OTA Package description.", example = "Description for the OTA Package fw_1.0")
 | 
			
		||||
    @Override
 | 
			
		||||
    public JsonNode getAdditionalInfo() {
 | 
			
		||||
 | 
			
		||||
@ -41,7 +41,8 @@ import java.util.Map;
 | 
			
		||||
        @Type(name = "DEVICE", value = DeviceExportData.class),
 | 
			
		||||
        @Type(name = "RULE_CHAIN", value = RuleChainExportData.class),
 | 
			
		||||
        @Type(name = "WIDGET_TYPE", value = WidgetTypeExportData.class),
 | 
			
		||||
        @Type(name = "WIDGETS_BUNDLE", value = WidgetsBundleExportData.class)
 | 
			
		||||
        @Type(name = "WIDGETS_BUNDLE", value = WidgetsBundleExportData.class),
 | 
			
		||||
        @Type(name = "OTA_PACKAGE", value = OtaPackageExportData.class)
 | 
			
		||||
})
 | 
			
		||||
@JsonInclude(JsonInclude.Include.NON_NULL)
 | 
			
		||||
@Data
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,37 @@
 | 
			
		||||
/**
 | 
			
		||||
 * Copyright © 2016-2025 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.sync.ie;
 | 
			
		||||
 | 
			
		||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
 | 
			
		||||
import lombok.EqualsAndHashCode;
 | 
			
		||||
import org.thingsboard.server.common.data.OtaPackage;
 | 
			
		||||
 | 
			
		||||
@EqualsAndHashCode(callSuper = true)
 | 
			
		||||
public class OtaPackageExportData extends EntityExportData<OtaPackage> {
 | 
			
		||||
 | 
			
		||||
    @JsonIgnoreProperties(value = {"tenantId", "createdTime"}, ignoreUnknown = true)
 | 
			
		||||
    @Override
 | 
			
		||||
    public OtaPackage getEntity() {
 | 
			
		||||
        return super.getEntity();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @JsonIgnoreProperties(value = {"tenantId", "createdTime"}, ignoreUnknown = true)
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setEntity(OtaPackage entity) {
 | 
			
		||||
        super.setEntity(entity);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@ -62,9 +62,6 @@ import java.util.function.BiFunction;
 | 
			
		||||
import java.util.function.UnaryOperator;
 | 
			
		||||
import java.util.regex.Pattern;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Created by Valerii Sosliuk on 5/12/2017.
 | 
			
		||||
 */
 | 
			
		||||
@Slf4j
 | 
			
		||||
public class JacksonUtil {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -40,9 +40,6 @@ import java.util.List;
 | 
			
		||||
import java.util.Optional;
 | 
			
		||||
import java.util.UUID;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author Valerii Sosliuk
 | 
			
		||||
 */
 | 
			
		||||
@Slf4j
 | 
			
		||||
@SqlDao
 | 
			
		||||
public abstract class JpaAbstractDao<E extends BaseEntity<D>, D>
 | 
			
		||||
 | 
			
		||||
@ -48,9 +48,6 @@ import java.util.UUID;
 | 
			
		||||
 | 
			
		||||
import static org.thingsboard.server.dao.DaoUtil.convertTenantEntityInfosToDto;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Created by Valerii Sosliuk on 5/19/2017.
 | 
			
		||||
 */
 | 
			
		||||
@Component
 | 
			
		||||
@SqlDao
 | 
			
		||||
@Slf4j
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user