diff --git a/application/src/main/java/org/thingsboard/server/controller/TbResourceController.java b/application/src/main/java/org/thingsboard/server/controller/TbResourceController.java index 21d7eadb69..120449c137 100644 --- a/application/src/main/java/org/thingsboard/server/controller/TbResourceController.java +++ b/application/src/main/java/org/thingsboard/server/controller/TbResourceController.java @@ -40,7 +40,7 @@ import org.thingsboard.server.common.data.page.PageData; import org.thingsboard.server.common.data.page.PageLink; import org.thingsboard.server.common.data.security.Authority; import org.thingsboard.server.queue.util.TbCoreComponent; -import org.thingsboard.server.service.entitiy.resource.TbResourceNotifyService; +import org.thingsboard.server.service.resource.TbResourceService; import org.thingsboard.server.service.security.permission.Operation; import org.thingsboard.server.service.security.permission.Resource; @@ -71,7 +71,7 @@ import static org.thingsboard.server.controller.ControllerConstants.UUID_WIKI_LI @RequiredArgsConstructor public class TbResourceController extends BaseController { - private final TbResourceNotifyService tbResourceService; + private final TbResourceService tbResourceService; public static final String RESOURCE_ID = "resourceId"; diff --git a/application/src/main/java/org/thingsboard/server/service/entitiy/resource/DefaultTbResourceNotifyService.java b/application/src/main/java/org/thingsboard/server/service/entitiy/resource/DefaultTbResourceNotifyService.java deleted file mode 100644 index beb1707214..0000000000 --- a/application/src/main/java/org/thingsboard/server/service/entitiy/resource/DefaultTbResourceNotifyService.java +++ /dev/null @@ -1,71 +0,0 @@ -/** - * Copyright © 2016-2022 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.entitiy.resource; - - -import lombok.AllArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; -import org.thingsboard.server.common.data.EntityType; -import org.thingsboard.server.common.data.TbResource; -import org.thingsboard.server.common.data.audit.ActionType; -import org.thingsboard.server.common.data.exception.ThingsboardException; -import org.thingsboard.server.common.data.id.TbResourceId; -import org.thingsboard.server.common.data.id.TenantId; -import org.thingsboard.server.queue.util.TbCoreComponent; -import org.thingsboard.server.service.entitiy.AbstractTbEntityService; -import org.thingsboard.server.service.security.model.SecurityUser; - -@Service -@TbCoreComponent -@AllArgsConstructor -@Slf4j -public class DefaultTbResourceNotifyService extends AbstractTbEntityService implements TbResourceNotifyService { - - @Override - public TbResource save(TbResource tbResource, SecurityUser user) throws ThingsboardException { - ActionType actionType = tbResource.getId() == null ? ActionType.ADDED : ActionType.UPDATED; - TenantId tenantId = tbResource.getTenantId(); - try { - - TbResource savedResource = checkNotNull(resourceService.saveResource(tbResource)); - tbClusterService.onResourceChange(savedResource, null); - notificationEntityService.notifyCreateOrUpdateOrDelete(tenantId, null, savedResource.getId(), - savedResource, user, actionType, false, null); - return savedResource; - } catch (Exception e) { - notificationEntityService.notifyCreateOrUpdateOrDelete(tenantId, null, emptyId(EntityType.TB_RESOURCE), - tbResource, user, actionType, false, e); - throw handleException(e); - } - } - - @Override - public void delete(TbResource tbResource, SecurityUser user) throws ThingsboardException { - TbResourceId resourceId = tbResource.getId(); - TenantId tenantId = tbResource.getTenantId(); - try { - resourceService.deleteResource(tenantId, resourceId); - tbClusterService.onResourceDeleted(tbResource, null); - notificationEntityService.notifyCreateOrUpdateOrDelete(tenantId, null, resourceId, tbResource, user, ActionType.DELETED, - false, null, resourceId.toString()); - } catch (Exception e) { - notificationEntityService.notifyCreateOrUpdateOrDelete(tenantId, null, emptyId(EntityType.TB_RESOURCE), null, user, ActionType.DELETED, - false, e, resourceId.toString()); - throw handleException(e); - } - } -} diff --git a/application/src/main/java/org/thingsboard/server/service/entitiy/resource/TbResourceNotifyService.java b/application/src/main/java/org/thingsboard/server/service/entitiy/resource/TbResourceNotifyService.java deleted file mode 100644 index 1605d745c2..0000000000 --- a/application/src/main/java/org/thingsboard/server/service/entitiy/resource/TbResourceNotifyService.java +++ /dev/null @@ -1,22 +0,0 @@ -/** - * Copyright © 2016-2022 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.entitiy.resource; - -import org.thingsboard.server.common.data.TbResource; -import org.thingsboard.server.service.entitiy.SimpleTbEntityService; - -public interface TbResourceNotifyService extends SimpleTbEntityService { -} diff --git a/application/src/main/java/org/thingsboard/server/service/resource/DefaultTbResourceService.java b/application/src/main/java/org/thingsboard/server/service/resource/DefaultTbResourceService.java index fab78afc70..c91ff91152 100644 --- a/application/src/main/java/org/thingsboard/server/service/resource/DefaultTbResourceService.java +++ b/application/src/main/java/org/thingsboard/server/service/resource/DefaultTbResourceService.java @@ -22,9 +22,11 @@ import org.eclipse.leshan.core.model.DefaultDDFFileValidator; import org.eclipse.leshan.core.model.InvalidDDFFileException; import org.eclipse.leshan.core.model.ObjectModel; import org.springframework.stereotype.Service; +import org.thingsboard.server.common.data.EntityType; import org.thingsboard.server.common.data.ResourceType; import org.thingsboard.server.common.data.TbResource; import org.thingsboard.server.common.data.TbResourceInfo; +import org.thingsboard.server.common.data.audit.ActionType; import org.thingsboard.server.common.data.exception.ThingsboardErrorCode; import org.thingsboard.server.common.data.exception.ThingsboardException; import org.thingsboard.server.common.data.id.TbResourceId; @@ -36,6 +38,8 @@ import org.thingsboard.server.common.data.page.PageData; import org.thingsboard.server.common.data.page.PageLink; import org.thingsboard.server.dao.exception.DataValidationException; import org.thingsboard.server.dao.resource.ResourceService; +import org.thingsboard.server.service.entitiy.AbstractTbEntityService; +import org.thingsboard.server.service.security.model.SecurityUser; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -53,7 +57,7 @@ import static org.thingsboard.server.dao.service.Validator.validateId; @Slf4j @Service -public class DefaultTbResourceService implements TbResourceService { +public class DefaultTbResourceService extends AbstractTbEntityService implements TbResourceService { private final ResourceService resourceService; private final DDFFileParser ddfFileParser; @@ -64,7 +68,7 @@ public class DefaultTbResourceService implements TbResourceService { } @Override - public TbResource saveResource(TbResource resource) throws ThingsboardException { + public TbResource saveResourceInternal(TbResource resource) throws ThingsboardException { log.trace("Executing saveResource [{}]", resource); if (StringUtils.isEmpty(resource.getData())) { throw new DataValidationException("Resource data should be specified!"); @@ -150,11 +154,6 @@ public class DefaultTbResourceService implements TbResourceService { .collect(Collectors.toList()); } - @Override - public void deleteResource(TenantId tenantId, TbResourceId resourceId) { - resourceService.deleteResource(tenantId, resourceId); - } - @Override public void deleteResourcesByTenantId(TenantId tenantId) { resourceService.deleteResourcesByTenantId(tenantId); @@ -215,4 +214,37 @@ public class DefaultTbResourceService implements TbResourceService { return null; } } -} + + @Override + public TbResource save(TbResource tbResource, SecurityUser user) throws ThingsboardException { + ActionType actionType = tbResource.getId() == null ? ActionType.ADDED : ActionType.UPDATED; + TenantId tenantId = tbResource.getTenantId(); + try { + + TbResource savedResource = checkNotNull(saveResourceInternal(tbResource)); + tbClusterService.onResourceChange(savedResource, null); + notificationEntityService.notifyCreateOrUpdateOrDelete(tenantId, null, savedResource.getId(), + savedResource, user, actionType, false, null); + return savedResource; + } catch (Exception e) { + notificationEntityService.notifyCreateOrUpdateOrDelete(tenantId, null, emptyId(EntityType.TB_RESOURCE), + tbResource, user, actionType, false, e); + throw handleException(e); + } + } + + @Override + public void delete(TbResource tbResource, SecurityUser user) throws ThingsboardException { + TbResourceId resourceId = tbResource.getId(); + TenantId tenantId = tbResource.getTenantId(); + try { + resourceService.deleteResource(tenantId, resourceId); + tbClusterService.onResourceDeleted(tbResource, null); + notificationEntityService.notifyCreateOrUpdateOrDelete(tenantId, null, resourceId, tbResource, user, ActionType.DELETED, + false, null, resourceId.toString()); + } catch (Exception e) { + notificationEntityService.notifyCreateOrUpdateOrDelete(tenantId, null, emptyId(EntityType.TB_RESOURCE), null, user, ActionType.DELETED, + false, e, resourceId.toString()); + throw handleException(e); + } + }} diff --git a/application/src/main/java/org/thingsboard/server/service/resource/TbResourceService.java b/application/src/main/java/org/thingsboard/server/service/resource/TbResourceService.java index bfa04d4cd6..3bcb7f0722 100644 --- a/application/src/main/java/org/thingsboard/server/service/resource/TbResourceService.java +++ b/application/src/main/java/org/thingsboard/server/service/resource/TbResourceService.java @@ -24,12 +24,13 @@ import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.common.data.lwm2m.LwM2mObject; import org.thingsboard.server.common.data.page.PageData; import org.thingsboard.server.common.data.page.PageLink; +import org.thingsboard.server.service.entitiy.SimpleTbEntityService; import java.util.List; -public interface TbResourceService { +public interface TbResourceService extends SimpleTbEntityService { - TbResource saveResource(TbResource resource) throws ThingsboardException; + TbResource saveResourceInternal(TbResource resource) throws ThingsboardException; TbResource getResource(TenantId tenantId, ResourceType resourceType, String resourceKey); @@ -51,8 +52,6 @@ public interface TbResourceService { String sortOrder, PageLink pageLink); - void deleteResource(TenantId tenantId, TbResourceId resourceId); - void deleteResourcesByTenantId(TenantId tenantId); long sumDataSizeByTenantId(TenantId tenantId);