|
|
@ -1,12 +1,12 @@ |
|
|
/** |
|
|
/** |
|
|
* Copyright © 2016-2022 The Thingsboard Authors |
|
|
* Copyright © 2016-2022 The Thingsboard Authors |
|
|
* |
|
|
* <p> |
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
* you may not use this file except in compliance with the License. |
|
|
* you may not use this file except in compliance with the License. |
|
|
* You may obtain a copy of the License at |
|
|
* You may obtain a copy of the License at |
|
|
* |
|
|
* <p> |
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
* |
|
|
* <p> |
|
|
* Unless required by applicable law or agreed to in writing, software |
|
|
* Unless required by applicable law or agreed to in writing, software |
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
|
@ -18,22 +18,19 @@ package org.thingsboard.server.service.entitiy.ota; |
|
|
import lombok.AllArgsConstructor; |
|
|
import lombok.AllArgsConstructor; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.thingsboard.server.common.data.EntityType; |
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
import org.thingsboard.server.common.data.OtaPackage; |
|
|
import org.thingsboard.server.common.data.*; |
|
|
import org.thingsboard.server.common.data.OtaPackageInfo; |
|
|
|
|
|
import org.thingsboard.server.common.data.SaveOtaPackageInfoRequest; |
|
|
|
|
|
import org.thingsboard.server.common.data.StringUtils; |
|
|
|
|
|
import org.thingsboard.server.common.data.User; |
|
|
|
|
|
import org.thingsboard.server.common.data.audit.ActionType; |
|
|
import org.thingsboard.server.common.data.audit.ActionType; |
|
|
import org.thingsboard.server.common.data.exception.ThingsboardException; |
|
|
import org.thingsboard.server.common.data.exception.ThingsboardException; |
|
|
import org.thingsboard.server.common.data.id.OtaPackageId; |
|
|
import org.thingsboard.server.common.data.id.OtaPackageId; |
|
|
import org.thingsboard.server.common.data.id.TenantId; |
|
|
import org.thingsboard.server.common.data.id.TenantId; |
|
|
import org.thingsboard.server.common.data.ota.ChecksumAlgorithm; |
|
|
import org.thingsboard.server.common.data.ota.ChecksumAlgorithm; |
|
|
import org.thingsboard.server.dao.ota.OtaPackageService; |
|
|
import org.thingsboard.server.dao.ota.OtaPackageService; |
|
|
|
|
|
import org.thingsboard.server.dao.ota.util.ChecksumUtil; |
|
|
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
|
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
|
import org.thingsboard.server.service.entitiy.AbstractTbEntityService; |
|
|
import org.thingsboard.server.service.entitiy.AbstractTbEntityService; |
|
|
|
|
|
|
|
|
import java.nio.ByteBuffer; |
|
|
import java.io.IOException; |
|
|
|
|
|
|
|
|
@Service |
|
|
@Service |
|
|
@TbCoreComponent |
|
|
@TbCoreComponent |
|
|
@ -64,12 +61,12 @@ public class DefaultTbOtaPackageService extends AbstractTbEntityService implemen |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public OtaPackageInfo saveOtaPackageData(OtaPackageInfo otaPackageInfo, String checksum, ChecksumAlgorithm checksumAlgorithm, |
|
|
public OtaPackageInfo saveOtaPackageData(OtaPackageInfo otaPackageInfo, String checksum, ChecksumAlgorithm checksumAlgorithm, |
|
|
byte[] data, String filename, String contentType, User user) throws ThingsboardException { |
|
|
MultipartFile file, User user) throws ThingsboardException { |
|
|
TenantId tenantId = otaPackageInfo.getTenantId(); |
|
|
TenantId tenantId = otaPackageInfo.getTenantId(); |
|
|
OtaPackageId otaPackageId = otaPackageInfo.getId(); |
|
|
OtaPackageId otaPackageId = otaPackageInfo.getId(); |
|
|
try { |
|
|
try { |
|
|
if (StringUtils.isEmpty(checksum)) { |
|
|
if (StringUtils.isEmpty(checksum)) { |
|
|
checksum = otaPackageService.generateChecksum(checksumAlgorithm, ByteBuffer.wrap(data)); |
|
|
checksum = ChecksumUtil.generateChecksum(checksumAlgorithm, file.getInputStream()); |
|
|
} |
|
|
} |
|
|
OtaPackage otaPackage = new OtaPackage(otaPackageId); |
|
|
OtaPackage otaPackage = new OtaPackage(otaPackageId); |
|
|
otaPackage.setCreatedTime(otaPackageInfo.getCreatedTime()); |
|
|
otaPackage.setCreatedTime(otaPackageInfo.getCreatedTime()); |
|
|
@ -82,14 +79,18 @@ public class DefaultTbOtaPackageService extends AbstractTbEntityService implemen |
|
|
otaPackage.setAdditionalInfo(otaPackageInfo.getAdditionalInfo()); |
|
|
otaPackage.setAdditionalInfo(otaPackageInfo.getAdditionalInfo()); |
|
|
otaPackage.setChecksumAlgorithm(checksumAlgorithm); |
|
|
otaPackage.setChecksumAlgorithm(checksumAlgorithm); |
|
|
otaPackage.setChecksum(checksum); |
|
|
otaPackage.setChecksum(checksum); |
|
|
otaPackage.setFileName(filename); |
|
|
otaPackage.setFileName(file.getOriginalFilename()); |
|
|
otaPackage.setContentType(contentType); |
|
|
otaPackage.setContentType(file.getContentType()); |
|
|
otaPackage.setData(ByteBuffer.wrap(data)); |
|
|
otaPackage.setData(file.getInputStream()); |
|
|
otaPackage.setDataSize((long) data.length); |
|
|
otaPackage.setDataSize(file.getSize()); |
|
|
OtaPackageInfo savedOtaPackage = otaPackageService.saveOtaPackage(otaPackage); |
|
|
OtaPackageInfo savedOtaPackage = otaPackageService.saveOtaPackage(otaPackage); |
|
|
notificationEntityService.notifyCreateOrUpdateOrDelete(tenantId, null, savedOtaPackage.getId(), |
|
|
notificationEntityService.notifyCreateOrUpdateOrDelete(tenantId, null, savedOtaPackage.getId(), |
|
|
savedOtaPackage, user, ActionType.UPDATED, true, null); |
|
|
savedOtaPackage, user, ActionType.UPDATED, true, null); |
|
|
return savedOtaPackage; |
|
|
return savedOtaPackage; |
|
|
|
|
|
} catch (IOException e){ |
|
|
|
|
|
notificationEntityService.logEntityAction(tenantId, emptyId(EntityType.OTA_PACKAGE), ActionType.UPDATED, |
|
|
|
|
|
user, e, otaPackageId.toString()); |
|
|
|
|
|
throw new RuntimeException(e); |
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
notificationEntityService.logEntityAction(tenantId, emptyId(EntityType.OTA_PACKAGE), ActionType.UPDATED, |
|
|
notificationEntityService.logEntityAction(tenantId, emptyId(EntityType.OTA_PACKAGE), ActionType.UPDATED, |
|
|
user, e, otaPackageId.toString()); |
|
|
user, e, otaPackageId.toString()); |
|
|
|