29 changed files with 451 additions and 157 deletions
@ -0,0 +1,45 @@ |
|||
/** |
|||
* 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.bean; |
|||
|
|||
import org.springframework.beans.factory.annotation.Value; |
|||
import org.springframework.beans.factory.config.BeanDefinition; |
|||
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; |
|||
import org.springframework.core.type.filter.AnnotationTypeFilter; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import java.lang.annotation.Annotation; |
|||
import java.util.HashSet; |
|||
import java.util.Set; |
|||
|
|||
@Service |
|||
public class AnnotationBeanDiscoveryService implements BeanDiscoveryService { |
|||
|
|||
@Value("${plugins.scan_packages}") |
|||
private String[] scanPackages; |
|||
|
|||
@Override |
|||
public Set<BeanDefinition> discoverBeansByAnnotationType(Class<? extends Annotation> annotationType) { |
|||
ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false); |
|||
scanner.addIncludeFilter(new AnnotationTypeFilter(annotationType)); |
|||
Set<BeanDefinition> defs = new HashSet<>(); |
|||
for (String scanPackage : scanPackages) { |
|||
defs.addAll(scanner.findCandidateComponents(scanPackage)); |
|||
} |
|||
return defs; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,27 @@ |
|||
/** |
|||
* 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.bean; |
|||
|
|||
import org.springframework.beans.factory.config.BeanDefinition; |
|||
|
|||
import java.lang.annotation.Annotation; |
|||
import java.util.Set; |
|||
|
|||
public interface BeanDiscoveryService { |
|||
|
|||
Set<BeanDefinition> discoverBeansByAnnotationType(Class<? extends Annotation> annotationType); |
|||
|
|||
} |
|||
@ -0,0 +1,45 @@ |
|||
/** |
|||
* 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.rule.engine.metadata; |
|||
|
|||
import com.fasterxml.jackson.databind.JsonNode; |
|||
import org.junit.Test; |
|||
import org.junit.jupiter.api.Assertions; |
|||
import org.thingsboard.common.util.JacksonUtil; |
|||
import org.thingsboard.server.common.data.util.TbPair; |
|||
|
|||
public class TbGetDeviceAttrNodeTest { |
|||
|
|||
@Test |
|||
public void givenOldConfig_whenUpgrade_thenShouldReturnSuccessResult() throws Exception { |
|||
var defaultConfig = new TbGetDeviceAttrNodeConfiguration().defaultConfiguration(); |
|||
var node = new TbGetDeviceAttrNode(); |
|||
String oldConfig = "{\"fetchToData\":false," + |
|||
"\"clientAttributeNames\":[]," + |
|||
"\"sharedAttributeNames\":[]," + |
|||
"\"serverAttributeNames\":[]," + |
|||
"\"latestTsKeyNames\":[]," + |
|||
"\"tellFailureIfAbsent\":true," + |
|||
"\"getLatestValueWithTs\":false," + |
|||
"\"deviceRelationsQuery\":{\"direction\":\"FROM\",\"maxLevel\":1,\"relationType\":\"Contains\",\"deviceTypes\":[\"default\"]," + |
|||
"\"fetchLastLevelOnly\":false}}"; |
|||
JsonNode configJson = JacksonUtil.toJsonNode(oldConfig); |
|||
TbPair<Boolean, JsonNode> upgrade = node.upgrade(0, configJson); |
|||
Assertions.assertTrue(upgrade.getFirst()); |
|||
Assertions.assertEquals(JacksonUtil.valueToTree(defaultConfig), upgrade.getSecond()); |
|||
} |
|||
|
|||
} |
|||
Loading…
Reference in new issue