Showing
100 changed files
with
1107 additions
and
219 deletions
Too many changes to show.
To preserve performance only 100 of 120 files are displayed.
... | ... | @@ -476,11 +476,6 @@ class DefaultTbContext implements TbContext { |
476 | 476 | } |
477 | 477 | |
478 | 478 | @Override |
479 | - public RedisTemplate<String, Object> getRedisTemplate() { | |
480 | - return mainCtx.getRedisTemplate(); | |
481 | - } | |
482 | - | |
483 | - @Override | |
484 | 479 | public PageData<RuleNodeState> findRuleNodeStates(PageLink pageLink) { |
485 | 480 | if (log.isDebugEnabled()) { |
486 | 481 | log.debug("[{}][{}] Fetch Rule Node States.", getTenantId(), getSelfId()); | ... | ... |
application/src/main/java/org/thingsboard/server/actors/ruleChain/RuleNodeActorMessageProcessor.java
... | ... | @@ -147,7 +147,7 @@ public class RuleNodeActorMessageProcessor extends ComponentMsgProcessor<RuleNod |
147 | 147 | TbNode tbNode = null; |
148 | 148 | if (ruleNode != null) { |
149 | 149 | Class<?> componentClazz = Class.forName(ruleNode.getType()); |
150 | - tbNode = (TbNode) (componentClazz.newInstance()); | |
150 | + tbNode = (TbNode) (componentClazz.getDeclaredConstructor().newInstance()); | |
151 | 151 | tbNode.init(defaultCtx, new TbNodeConfiguration(ruleNode.getConfiguration())); |
152 | 152 | } |
153 | 153 | return tbNode; | ... | ... |
... | ... | @@ -91,6 +91,7 @@ public class CustomOAuth2AuthorizationRequestResolver implements OAuth2Authoriza |
91 | 91 | return action; |
92 | 92 | } |
93 | 93 | |
94 | + @SuppressWarnings("deprecation") | |
94 | 95 | private OAuth2AuthorizationRequest resolve(HttpServletRequest request, String registrationId, String redirectUriAction) { |
95 | 96 | if (registrationId == null) { |
96 | 97 | return null; | ... | ... |
... | ... | @@ -127,7 +127,7 @@ public class ThingsboardSecurityConfiguration extends WebSecurityConfigurerAdapt |
127 | 127 | } |
128 | 128 | |
129 | 129 | protected JwtTokenAuthenticationProcessingFilter buildJwtTokenAuthenticationProcessingFilter() throws Exception { |
130 | - List<String> pathsToSkip = new ArrayList(Arrays.asList(NON_TOKEN_BASED_AUTH_ENTRY_POINTS)); | |
130 | + List<String> pathsToSkip = new ArrayList<>(Arrays.asList(NON_TOKEN_BASED_AUTH_ENTRY_POINTS)); | |
131 | 131 | pathsToSkip.addAll(Arrays.asList(WS_TOKEN_BASED_AUTH_ENTRY_POINT, TOKEN_REFRESH_ENTRY_POINT, FORM_BASED_LOGIN_ENTRY_POINT, |
132 | 132 | PUBLIC_LOGIN_ENTRY_POINT, DEVICE_API_ENTRY_POINT, WEBJARS_ENTRY_POINT)); |
133 | 133 | SkipPathRequestMatcher matcher = new SkipPathRequestMatcher(pathsToSkip, TOKEN_BASED_AUTH_ENTRY_POINT); | ... | ... |
... | ... | @@ -645,6 +645,7 @@ public abstract class BaseController { |
645 | 645 | return ruleNode; |
646 | 646 | } |
647 | 647 | |
648 | + @SuppressWarnings("unchecked") | |
648 | 649 | protected <I extends EntityId> I emptyId(EntityType entityType) { |
649 | 650 | return (I) EntityIdFactory.getByTypeAndUuid(entityType, ModelConstants.NULL_UUID); |
650 | 651 | } |
... | ... | @@ -759,6 +760,7 @@ public abstract class BaseController { |
759 | 760 | entityNode = json.createObjectNode(); |
760 | 761 | if (actionType == ActionType.ATTRIBUTES_UPDATED) { |
761 | 762 | String scope = extractParameter(String.class, 0, additionalInfo); |
763 | + @SuppressWarnings("unchecked") | |
762 | 764 | List<AttributeKvEntry> attributes = extractParameter(List.class, 1, additionalInfo); |
763 | 765 | metaData.putValue("scope", scope); |
764 | 766 | if (attributes != null) { |
... | ... | @@ -768,6 +770,7 @@ public abstract class BaseController { |
768 | 770 | } |
769 | 771 | } else if (actionType == ActionType.ATTRIBUTES_DELETED) { |
770 | 772 | String scope = extractParameter(String.class, 0, additionalInfo); |
773 | + @SuppressWarnings("unchecked") | |
771 | 774 | List<String> keys = extractParameter(List.class, 1, additionalInfo); |
772 | 775 | metaData.putValue("scope", scope); |
773 | 776 | ArrayNode attrsArrayNode = entityNode.putArray("attributes"); |
... | ... | @@ -775,9 +778,11 @@ public abstract class BaseController { |
775 | 778 | keys.forEach(attrsArrayNode::add); |
776 | 779 | } |
777 | 780 | } else if (actionType == ActionType.TIMESERIES_UPDATED) { |
781 | + @SuppressWarnings("unchecked") | |
778 | 782 | List<TsKvEntry> timeseries = extractParameter(List.class, 0, additionalInfo); |
779 | 783 | addTimeseries(entityNode, timeseries); |
780 | 784 | } else if (actionType == ActionType.TIMESERIES_DELETED) { |
785 | + @SuppressWarnings("unchecked") | |
781 | 786 | List<String> keys = extractParameter(List.class, 0, additionalInfo); |
782 | 787 | if (keys != null) { |
783 | 788 | ArrayNode timeseriesArrayNode = entityNode.putArray("timeseries"); | ... | ... |
... | ... | @@ -63,7 +63,7 @@ import java.util.List; |
63 | 63 | import java.util.concurrent.ExecutionException; |
64 | 64 | import java.util.stream.Collectors; |
65 | 65 | |
66 | -import static org.apache.commons.lang.StringUtils.isBlank; | |
66 | +import static org.apache.commons.lang3.StringUtils.isBlank; | |
67 | 67 | import static org.thingsboard.server.controller.CustomerController.CUSTOMER_ID; |
68 | 68 | |
69 | 69 | /** | ... | ... |
... | ... | @@ -24,6 +24,7 @@ import org.springframework.beans.factory.annotation.Value; |
24 | 24 | import org.springframework.beans.factory.config.BeanDefinition; |
25 | 25 | import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; |
26 | 26 | import org.springframework.core.env.Environment; |
27 | +import org.springframework.core.env.Profiles; | |
27 | 28 | import org.springframework.core.type.filter.AnnotationTypeFilter; |
28 | 29 | import org.springframework.stereotype.Service; |
29 | 30 | import org.thingsboard.rule.engine.api.NodeConfiguration; |
... | ... | @@ -69,7 +70,7 @@ public class AnnotationComponentDiscoveryService implements ComponentDiscoverySe |
69 | 70 | private ObjectMapper mapper = new ObjectMapper(); |
70 | 71 | |
71 | 72 | private boolean isInstall() { |
72 | - return environment.acceptsProfiles("install"); | |
73 | + return environment.acceptsProfiles(Profiles.of("install")); | |
73 | 74 | } |
74 | 75 | |
75 | 76 | @PostConstruct |
... | ... | @@ -185,7 +186,7 @@ public class AnnotationComponentDiscoveryService implements ComponentDiscoverySe |
185 | 186 | nodeDefinition.setRelationTypes(getRelationTypesWithFailureRelation(nodeAnnotation)); |
186 | 187 | nodeDefinition.setCustomRelations(nodeAnnotation.customRelations()); |
187 | 188 | Class<? extends NodeConfiguration> configClazz = nodeAnnotation.configClazz(); |
188 | - NodeConfiguration config = configClazz.newInstance(); | |
189 | + NodeConfiguration config = configClazz.getDeclaredConstructor().newInstance(); | |
189 | 190 | NodeConfiguration defaultConfiguration = config.defaultConfiguration(); |
190 | 191 | nodeDefinition.setDefaultConfiguration(mapper.valueToTree(defaultConfiguration)); |
191 | 192 | nodeDefinition.setUiResources(nodeAnnotation.uiResources()); | ... | ... |
... | ... | @@ -20,7 +20,7 @@ import com.fasterxml.jackson.databind.JsonNode; |
20 | 20 | import com.fasterxml.jackson.databind.node.ObjectNode; |
21 | 21 | import com.google.common.util.concurrent.ListenableFuture; |
22 | 22 | import lombok.extern.slf4j.Slf4j; |
23 | -import org.apache.commons.lang.RandomStringUtils; | |
23 | +import org.apache.commons.lang3.RandomStringUtils; | |
24 | 24 | import org.springframework.beans.factory.annotation.Autowired; |
25 | 25 | import org.springframework.stereotype.Service; |
26 | 26 | import org.springframework.util.StringUtils; | ... | ... |
... | ... | @@ -146,17 +146,17 @@ public class CassandraDbHelper { |
146 | 146 | if (row.isNull(index)) { |
147 | 147 | return null; |
148 | 148 | } else if (type.getProtocolCode() == ProtocolConstants.DataType.DOUBLE) { |
149 | - str = new Double(row.getDouble(index)).toString(); | |
149 | + str = Double.valueOf(row.getDouble(index)).toString(); | |
150 | 150 | } else if (type.getProtocolCode() == ProtocolConstants.DataType.INT) { |
151 | - str = new Integer(row.getInt(index)).toString(); | |
151 | + str = Integer.valueOf(row.getInt(index)).toString(); | |
152 | 152 | } else if (type.getProtocolCode() == ProtocolConstants.DataType.BIGINT) { |
153 | - str = new Long(row.getLong(index)).toString(); | |
153 | + str = Long.valueOf(row.getLong(index)).toString(); | |
154 | 154 | } else if (type.getProtocolCode() == ProtocolConstants.DataType.UUID) { |
155 | 155 | str = row.getUuid(index).toString(); |
156 | 156 | } else if (type.getProtocolCode() == ProtocolConstants.DataType.TIMEUUID) { |
157 | 157 | str = row.getUuid(index).toString(); |
158 | 158 | } else if (type.getProtocolCode() == ProtocolConstants.DataType.FLOAT) { |
159 | - str = new Float(row.getFloat(index)).toString(); | |
159 | + str = Float.valueOf(row.getFloat(index)).toString(); | |
160 | 160 | } else if (type.getProtocolCode() == ProtocolConstants.DataType.TIMESTAMP) { |
161 | 161 | str = ""+row.getInstant(index).toEpochMilli(); |
162 | 162 | } else { | ... | ... |
... | ... | @@ -153,7 +153,8 @@ public class CassandraToSqlColumn { |
153 | 153 | sqlInsertStatement.setBoolean(this.sqlIndex, Boolean.parseBoolean(value)); |
154 | 154 | break; |
155 | 155 | case ENUM_TO_INT: |
156 | - Enum enumVal = Enum.valueOf(this.enumClass, value); | |
156 | + @SuppressWarnings("unchecked") | |
157 | + Enum<?> enumVal = Enum.valueOf(this.enumClass, value); | |
157 | 158 | int intValue = enumVal.ordinal(); |
158 | 159 | sqlInsertStatement.setInt(this.sqlIndex, intValue); |
159 | 160 | break; | ... | ... |
... | ... | @@ -57,7 +57,7 @@ import java.util.List; |
57 | 57 | import java.util.concurrent.ExecutionException; |
58 | 58 | import java.util.stream.Collectors; |
59 | 59 | |
60 | -import static org.apache.commons.lang.StringUtils.isBlank; | |
60 | +import static org.apache.commons.lang3.StringUtils.isBlank; | |
61 | 61 | import static org.thingsboard.server.service.install.DatabaseHelper.objectMapper; |
62 | 62 | |
63 | 63 | @Service | ... | ... |
... | ... | @@ -206,7 +206,7 @@ public class DefaultEntityQueryService implements EntityQueryService { |
206 | 206 | addItemsToArrayNode(json.putArray("entityTypes"), types); |
207 | 207 | addItemsToArrayNode(json.putArray("timeseries"), timeseriesKeys); |
208 | 208 | addItemsToArrayNode(json.putArray("attribute"), attributesKeys); |
209 | - response.setResult(new ResponseEntity(json, HttpStatus.OK)); | |
209 | + response.setResult(new ResponseEntity<>(json, HttpStatus.OK)); | |
210 | 210 | } |
211 | 211 | |
212 | 212 | private void replyWithEmptyResponse(DeferredResult<ResponseEntity> response) { | ... | ... |
... | ... | @@ -21,7 +21,6 @@ import com.google.common.util.concurrent.ListenableFuture; |
21 | 21 | import com.google.common.util.concurrent.MoreExecutors; |
22 | 22 | import delight.nashornsandbox.NashornSandbox; |
23 | 23 | import delight.nashornsandbox.NashornSandboxes; |
24 | -import jdk.nashorn.api.scripting.NashornScriptEngineFactory; | |
25 | 24 | import lombok.Getter; |
26 | 25 | import lombok.extern.slf4j.Slf4j; |
27 | 26 | import org.springframework.beans.factory.annotation.Value; |
... | ... | @@ -33,6 +32,7 @@ import javax.annotation.PostConstruct; |
33 | 32 | import javax.annotation.PreDestroy; |
34 | 33 | import javax.script.Invocable; |
35 | 34 | import javax.script.ScriptEngine; |
35 | +import javax.script.ScriptEngineManager; | |
36 | 36 | import javax.script.ScriptException; |
37 | 37 | import java.util.UUID; |
38 | 38 | import java.util.concurrent.ExecutionException; |
... | ... | @@ -97,8 +97,8 @@ public abstract class AbstractNashornJsInvokeService extends AbstractJsInvokeSer |
97 | 97 | sandbox.allowLoadFunctions(true); |
98 | 98 | sandbox.setMaxPreparedStatements(30); |
99 | 99 | } else { |
100 | - NashornScriptEngineFactory factory = new NashornScriptEngineFactory(); | |
101 | - engine = factory.getScriptEngine(new String[]{"--no-java"}); | |
100 | + ScriptEngineManager factory = new ScriptEngineManager(); | |
101 | + engine = factory.getEngineByName("nashorn"); | |
102 | 102 | } |
103 | 103 | } |
104 | 104 | ... | ... |
... | ... | @@ -29,7 +29,7 @@ public class SkipPathRequestMatcher implements RequestMatcher { |
29 | 29 | private RequestMatcher processingMatcher; |
30 | 30 | |
31 | 31 | public SkipPathRequestMatcher(List<String> pathsToSkip, String processingPath) { |
32 | - Assert.notNull(pathsToSkip); | |
32 | + Assert.notNull(pathsToSkip, "List of paths to skip is required."); | |
33 | 33 | List<RequestMatcher> m = pathsToSkip.stream().map(path -> new AntPathRequestMatcher(path)).collect(Collectors.toList()); |
34 | 34 | matchers = new OrRequestMatcher(m); |
35 | 35 | processingMatcher = new AntPathRequestMatcher(processingPath); | ... | ... |
... | ... | @@ -100,6 +100,7 @@ public class JwtTokenFactory { |
100 | 100 | Jws<Claims> jwsClaims = rawAccessToken.parseClaims(settings.getTokenSigningKey()); |
101 | 101 | Claims claims = jwsClaims.getBody(); |
102 | 102 | String subject = claims.getSubject(); |
103 | + @SuppressWarnings("unchecked") | |
103 | 104 | List<String> scopes = claims.get(SCOPES, List.class); |
104 | 105 | if (scopes == null || scopes.isEmpty()) { |
105 | 106 | throw new IllegalArgumentException("JWT Token doesn't have any scopes"); |
... | ... | @@ -155,6 +156,7 @@ public class JwtTokenFactory { |
155 | 156 | Jws<Claims> jwsClaims = rawAccessToken.parseClaims(settings.getTokenSigningKey()); |
156 | 157 | Claims claims = jwsClaims.getBody(); |
157 | 158 | String subject = claims.getSubject(); |
159 | + @SuppressWarnings("unchecked") | |
158 | 160 | List<String> scopes = claims.get(SCOPES, List.class); |
159 | 161 | if (scopes == null || scopes.isEmpty()) { |
160 | 162 | throw new IllegalArgumentException("Refresh Token doesn't have any scopes"); | ... | ... |
... | ... | @@ -47,6 +47,7 @@ public class CustomerUserPermissions extends AbstractPermissions { |
47 | 47 | Operation.READ_ATTRIBUTES, Operation.READ_TELEMETRY, Operation.RPC_CALL, Operation.CLAIM_DEVICES) { |
48 | 48 | |
49 | 49 | @Override |
50 | + @SuppressWarnings("unchecked") | |
50 | 51 | public boolean hasPermission(SecurityUser user, Operation operation, EntityId entityId, HasTenantId entity) { |
51 | 52 | |
52 | 53 | if (!super.hasPermission(user, operation, entityId, entity)) { |
... | ... | @@ -69,6 +70,7 @@ public class CustomerUserPermissions extends AbstractPermissions { |
69 | 70 | new PermissionChecker.GenericPermissionChecker(Operation.READ, Operation.READ_ATTRIBUTES, Operation.READ_TELEMETRY) { |
70 | 71 | |
71 | 72 | @Override |
73 | + @SuppressWarnings("unchecked") | |
72 | 74 | public boolean hasPermission(SecurityUser user, Operation operation, EntityId entityId, HasTenantId entity) { |
73 | 75 | if (!super.hasPermission(user, operation, entityId, entity)) { |
74 | 76 | return false; |
... | ... | @@ -119,6 +121,7 @@ public class CustomerUserPermissions extends AbstractPermissions { |
119 | 121 | private static final PermissionChecker widgetsPermissionChecker = new PermissionChecker.GenericPermissionChecker(Operation.READ) { |
120 | 122 | |
121 | 123 | @Override |
124 | + @SuppressWarnings("unchecked") | |
122 | 125 | public boolean hasPermission(SecurityUser user, Operation operation, EntityId entityId, HasTenantId entity) { |
123 | 126 | if (!super.hasPermission(user, operation, entityId, entity)) { |
124 | 127 | return false; | ... | ... |
... | ... | @@ -56,6 +56,7 @@ public class DefaultAccessControlService implements AccessControlService { |
56 | 56 | } |
57 | 57 | |
58 | 58 | @Override |
59 | + @SuppressWarnings("unchecked") | |
59 | 60 | public <I extends EntityId, T extends HasTenantId> void checkPermission(SecurityUser user, Resource resource, |
60 | 61 | Operation operation, I entityId, T entity) throws ThingsboardException { |
61 | 62 | PermissionChecker permissionChecker = getPermissionChecker(user.getAuthority(), resource); | ... | ... |
... | ... | @@ -59,6 +59,7 @@ public class TenantAdminPermissions extends AbstractPermissions { |
59 | 59 | new PermissionChecker.GenericPermissionChecker(Operation.READ, Operation.READ_ATTRIBUTES, Operation.READ_TELEMETRY) { |
60 | 60 | |
61 | 61 | @Override |
62 | + @SuppressWarnings("unchecked") | |
62 | 63 | public boolean hasPermission(SecurityUser user, Operation operation, EntityId entityId, HasTenantId entity) { |
63 | 64 | if (!super.hasPermission(user, operation, entityId, entity)) { |
64 | 65 | return false; | ... | ... |
... | ... | @@ -15,8 +15,8 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.service.security.system; |
17 | 17 | |
18 | +import com.fasterxml.jackson.core.type.TypeReference; | |
18 | 19 | import com.fasterxml.jackson.databind.JsonNode; |
19 | -import com.fasterxml.jackson.databind.ObjectMapper; | |
20 | 20 | import com.fasterxml.jackson.databind.node.ObjectNode; |
21 | 21 | import lombok.extern.slf4j.Slf4j; |
22 | 22 | import org.apache.commons.lang3.StringUtils; |
... | ... | @@ -49,6 +49,7 @@ import org.thingsboard.server.dao.exception.DataValidationException; |
49 | 49 | import org.thingsboard.server.dao.settings.AdminSettingsService; |
50 | 50 | import org.thingsboard.server.dao.user.UserService; |
51 | 51 | import org.thingsboard.server.dao.user.UserServiceImpl; |
52 | +import org.thingsboard.server.dao.util.mapping.JacksonUtil; | |
52 | 53 | import org.thingsboard.server.service.security.exception.UserPasswordExpiredException; |
53 | 54 | import org.thingsboard.server.utils.MiscUtils; |
54 | 55 | |
... | ... | @@ -65,8 +66,6 @@ import static org.thingsboard.server.common.data.CacheConstants.SECURITY_SETTING |
65 | 66 | @Slf4j |
66 | 67 | public class DefaultSystemSecurityService implements SystemSecurityService { |
67 | 68 | |
68 | - private static final ObjectMapper objectMapper = new ObjectMapper(); | |
69 | - | |
70 | 69 | @Autowired |
71 | 70 | private AdminSettingsService adminSettingsService; |
72 | 71 | |
... | ... | @@ -89,7 +88,7 @@ public class DefaultSystemSecurityService implements SystemSecurityService { |
89 | 88 | AdminSettings adminSettings = adminSettingsService.findAdminSettingsByKey(tenantId, "securitySettings"); |
90 | 89 | if (adminSettings != null) { |
91 | 90 | try { |
92 | - securitySettings = objectMapper.treeToValue(adminSettings.getJsonValue(), SecuritySettings.class); | |
91 | + securitySettings = JacksonUtil.convertValue(adminSettings.getJsonValue(), SecuritySettings.class); | |
93 | 92 | } catch (Exception e) { |
94 | 93 | throw new RuntimeException("Failed to load security settings!", e); |
95 | 94 | } |
... | ... | @@ -109,10 +108,10 @@ public class DefaultSystemSecurityService implements SystemSecurityService { |
109 | 108 | adminSettings = new AdminSettings(); |
110 | 109 | adminSettings.setKey("securitySettings"); |
111 | 110 | } |
112 | - adminSettings.setJsonValue(objectMapper.valueToTree(securitySettings)); | |
111 | + adminSettings.setJsonValue(JacksonUtil.valueToTree(securitySettings)); | |
113 | 112 | AdminSettings savedAdminSettings = adminSettingsService.saveAdminSettings(tenantId, adminSettings); |
114 | 113 | try { |
115 | - return objectMapper.treeToValue(savedAdminSettings.getJsonValue(), SecuritySettings.class); | |
114 | + return JacksonUtil.convertValue(savedAdminSettings.getJsonValue(), SecuritySettings.class); | |
116 | 115 | } catch (Exception e) { |
117 | 116 | throw new RuntimeException("Failed to load security settings!", e); |
118 | 117 | } |
... | ... | @@ -189,7 +188,7 @@ public class DefaultSystemSecurityService implements SystemSecurityService { |
189 | 188 | JsonNode additionalInfo = user.getAdditionalInfo(); |
190 | 189 | if (additionalInfo instanceof ObjectNode && additionalInfo.has(UserServiceImpl.USER_PASSWORD_HISTORY)) { |
191 | 190 | JsonNode userPasswordHistoryJson = additionalInfo.get(UserServiceImpl.USER_PASSWORD_HISTORY); |
192 | - Map<String, String> userPasswordHistoryMap = objectMapper.convertValue(userPasswordHistoryJson, Map.class); | |
191 | + Map<String, String> userPasswordHistoryMap = JacksonUtil.convertValue(userPasswordHistoryJson, new TypeReference<>() {}); | |
193 | 192 | for (Map.Entry<String, String> entry : userPasswordHistoryMap.entrySet()) { |
194 | 193 | if (encoder.matches(password, entry.getValue()) && Long.parseLong(entry.getKey()) > passwordReuseFrequencyTs) { |
195 | 194 | throw new DataValidationException("Password was already used for the last " + passwordPolicy.getPasswordReuseFrequencyDays() + " days"); | ... | ... |
... | ... | @@ -318,6 +318,7 @@ public class DefaultTbEntityDataSubscriptionService implements TbEntityDataSubsc |
318 | 318 | return ctx; |
319 | 319 | } |
320 | 320 | |
321 | + @SuppressWarnings("unchecked") | |
321 | 322 | private <T extends TbAbstractDataSubCtx> T getSubCtx(String sessionId, int cmdId) { |
322 | 323 | Map<Integer, TbAbstractDataSubCtx> sessionSubs = subscriptionsBySessionId.get(sessionId); |
323 | 324 | if (sessionSubs != null) { | ... | ... |
... | ... | @@ -123,6 +123,7 @@ public class DefaultTbLocalSubscriptionService implements TbLocalSubscriptionSer |
123 | 123 | } |
124 | 124 | |
125 | 125 | @Override |
126 | + @SuppressWarnings("unchecked") | |
126 | 127 | public void onSubscriptionUpdate(String sessionId, TelemetrySubscriptionUpdate update, TbCallback callback) { |
127 | 128 | TbSubscription subscription = subscriptionsBySessionId |
128 | 129 | .getOrDefault(sessionId, Collections.emptyMap()).get(update.getSubscriptionId()); |
... | ... | @@ -143,6 +144,7 @@ public class DefaultTbLocalSubscriptionService implements TbLocalSubscriptionSer |
143 | 144 | } |
144 | 145 | |
145 | 146 | @Override |
147 | + @SuppressWarnings("unchecked") | |
146 | 148 | public void onSubscriptionUpdate(String sessionId, AlarmSubscriptionUpdate update, TbCallback callback) { |
147 | 149 | TbSubscription subscription = subscriptionsBySessionId |
148 | 150 | .getOrDefault(sessionId, Collections.emptyMap()).get(update.getSubscriptionId()); | ... | ... |
... | ... | @@ -264,6 +264,7 @@ public abstract class TbAbstractDataSubCtx<T extends AbstractDataQuery<? extends |
264 | 264 | }, MoreExecutors.directExecutor()); |
265 | 265 | } |
266 | 266 | |
267 | + @SuppressWarnings("unchecked") | |
267 | 268 | private void updateDynamicValuesByKey(DynamicValueKeySub sub, TsValue tsValue) { |
268 | 269 | DynamicValueKey dvk = sub.getKey(); |
269 | 270 | switch (dvk.getPredicateType()) { |
... | ... | @@ -285,6 +286,7 @@ public abstract class TbAbstractDataSubCtx<T extends AbstractDataQuery<? extends |
285 | 286 | } |
286 | 287 | } |
287 | 288 | |
289 | + @SuppressWarnings("unchecked") | |
288 | 290 | private void registerDynamicValues(KeyFilterPredicate predicate) { |
289 | 291 | switch (predicate.getType()) { |
290 | 292 | case STRING: | ... | ... |
... | ... | @@ -15,9 +15,13 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.service.telemetry.cmd.v2; |
17 | 17 | |
18 | +import lombok.AllArgsConstructor; | |
18 | 19 | import lombok.Data; |
20 | +import lombok.NoArgsConstructor; | |
19 | 21 | |
20 | 22 | @Data |
23 | +@AllArgsConstructor | |
24 | +@NoArgsConstructor(force = true) | |
21 | 25 | public class AlarmDataUnsubscribeCmd implements UnsubscribeCmd { |
22 | 26 | |
23 | 27 | private final int cmdId; | ... | ... |
... | ... | @@ -15,9 +15,13 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.service.telemetry.cmd.v2; |
17 | 17 | |
18 | +import lombok.AllArgsConstructor; | |
18 | 19 | import lombok.Data; |
20 | +import lombok.NoArgsConstructor; | |
19 | 21 | |
20 | 22 | @Data |
23 | +@AllArgsConstructor | |
24 | +@NoArgsConstructor(force = true) | |
21 | 25 | public class EntityDataUnsubscribeCmd implements UnsubscribeCmd { |
22 | 26 | |
23 | 27 | private final int cmdId; | ... | ... |
... | ... | @@ -375,6 +375,10 @@ public abstract class AbstractWebTest { |
375 | 375 | return readResponse(doGetAsync(urlTemplate, urlVariables).andExpect(status().isOk()), responseClass); |
376 | 376 | } |
377 | 377 | |
378 | + protected <T> T doGetAsyncTyped(String urlTemplate, TypeReference<T> responseType, Object... urlVariables) throws Exception { | |
379 | + return readResponse(doGetAsync(urlTemplate, urlVariables).andExpect(status().isOk()), responseType); | |
380 | + } | |
381 | + | |
378 | 382 | protected ResultActions doGetAsync(String urlTemplate, Object... urlVariables) throws Exception { |
379 | 383 | MockHttpServletRequestBuilder getRequest; |
380 | 384 | getRequest = get(urlTemplate, urlVariables); | ... | ... |
... | ... | @@ -347,8 +347,8 @@ public abstract class BaseEntityViewControllerTest extends AbstractControllerTes |
347 | 347 | |
348 | 348 | Thread.sleep(1000); |
349 | 349 | |
350 | - List<Map<String, Object>> values = doGetAsync("/api/plugins/telemetry/ENTITY_VIEW/" + savedView.getId().getId().toString() + | |
351 | - "/values/attributes?keys=" + String.join(",", actualAttributesSet), List.class); | |
350 | + List<Map<String, Object>> values = doGetAsyncTyped("/api/plugins/telemetry/ENTITY_VIEW/" + savedView.getId().getId().toString() + | |
351 | + "/values/attributes?keys=" + String.join(",", actualAttributesSet), new TypeReference<>() {}); | |
352 | 352 | |
353 | 353 | assertEquals("value1", getValue(values, "caKey1")); |
354 | 354 | assertEquals(true, getValue(values, "caKey2")); |
... | ... | @@ -364,8 +364,8 @@ public abstract class BaseEntityViewControllerTest extends AbstractControllerTes |
364 | 364 | Set<String> expectedActualAttributesSet = new HashSet<>(Arrays.asList("caKey1", "caKey2", "caKey3", "caKey4")); |
365 | 365 | assertTrue(actualAttributesSet.containsAll(expectedActualAttributesSet)); |
366 | 366 | |
367 | - List<Map<String, Object>> valueTelemetryOfDevices = doGetAsync("/api/plugins/telemetry/DEVICE/" + testDevice.getId().getId().toString() + | |
368 | - "/values/attributes?keys=" + String.join(",", actualAttributesSet), List.class); | |
367 | + List<Map<String, Object>> valueTelemetryOfDevices = doGetAsyncTyped("/api/plugins/telemetry/DEVICE/" + testDevice.getId().getId().toString() + | |
368 | + "/values/attributes?keys=" + String.join(",", actualAttributesSet), new TypeReference<>() {}); | |
369 | 369 | |
370 | 370 | EntityView view = new EntityView(); |
371 | 371 | view.setEntityId(testDevice.getId()); |
... | ... | @@ -379,8 +379,8 @@ public abstract class BaseEntityViewControllerTest extends AbstractControllerTes |
379 | 379 | |
380 | 380 | Thread.sleep(1000); |
381 | 381 | |
382 | - List<Map<String, Object>> values = doGetAsync("/api/plugins/telemetry/ENTITY_VIEW/" + savedView.getId().getId().toString() + | |
383 | - "/values/attributes?keys=" + String.join(",", actualAttributesSet), List.class); | |
382 | + List<Map<String, Object>> values = doGetAsyncTyped("/api/plugins/telemetry/ENTITY_VIEW/" + savedView.getId().getId().toString() + | |
383 | + "/values/attributes?keys=" + String.join(",", actualAttributesSet), new TypeReference<>() {}); | |
384 | 384 | assertEquals(0, values.size()); |
385 | 385 | } |
386 | 386 | |
... | ... | @@ -449,12 +449,12 @@ public abstract class BaseEntityViewControllerTest extends AbstractControllerTes |
449 | 449 | } |
450 | 450 | |
451 | 451 | private Set<String> getTelemetryKeys(String type, String id) throws Exception { |
452 | - return new HashSet<>(doGetAsync("/api/plugins/telemetry/" + type + "/" + id + "/keys/timeseries", List.class)); | |
452 | + return new HashSet<>(doGetAsyncTyped("/api/plugins/telemetry/" + type + "/" + id + "/keys/timeseries", new TypeReference<>() {})); | |
453 | 453 | } |
454 | 454 | |
455 | 455 | private Map<String, List<Map<String, String>>> getTelemetryValues(String type, String id, Set<String> keys, Long startTs, Long endTs) throws Exception { |
456 | - return doGetAsync("/api/plugins/telemetry/" + type + "/" + id + | |
457 | - "/values/timeseries?keys=" + String.join(",", keys) + "&startTs=" + startTs + "&endTs=" + endTs, Map.class); | |
456 | + return doGetAsyncTyped("/api/plugins/telemetry/" + type + "/" + id + | |
457 | + "/values/timeseries?keys=" + String.join(",", keys) + "&startTs=" + startTs + "&endTs=" + endTs, new TypeReference<>() {}); | |
458 | 458 | } |
459 | 459 | |
460 | 460 | private Set<String> getAttributesByKeys(String stringKV) throws Exception { |
... | ... | @@ -479,7 +479,7 @@ public abstract class BaseEntityViewControllerTest extends AbstractControllerTes |
479 | 479 | client.publish("v1/devices/me/attributes", message); |
480 | 480 | Thread.sleep(1000); |
481 | 481 | client.disconnect(); |
482 | - return new HashSet<>(doGetAsync("/api/plugins/telemetry/DEVICE/" + viewDeviceId + "/keys/attributes", List.class)); | |
482 | + return new HashSet<>(doGetAsyncTyped("/api/plugins/telemetry/DEVICE/" + viewDeviceId + "/keys/attributes", new TypeReference<>() {})); | |
483 | 483 | } |
484 | 484 | |
485 | 485 | private Object getValue(List<Map<String, Object>> values, String stringValue) { | ... | ... |
... | ... | @@ -16,6 +16,7 @@ |
16 | 16 | package org.thingsboard.server.mqtt.telemetry.attributes; |
17 | 17 | |
18 | 18 | import com.fasterxml.jackson.core.JsonProcessingException; |
19 | +import com.fasterxml.jackson.core.type.TypeReference; | |
19 | 20 | import lombok.extern.slf4j.Slf4j; |
20 | 21 | import org.eclipse.paho.client.mqttv3.MqttAsyncClient; |
21 | 22 | import org.junit.After; |
... | ... | @@ -80,7 +81,7 @@ public abstract class AbstractMqttAttributesIntegrationTest extends AbstractMqtt |
80 | 81 | |
81 | 82 | List<String> actualKeys = null; |
82 | 83 | while (start <= end) { |
83 | - actualKeys = doGetAsync("/api/plugins/telemetry/DEVICE/" + deviceId + "/keys/attributes/CLIENT_SCOPE", List.class); | |
84 | + actualKeys = doGetAsyncTyped("/api/plugins/telemetry/DEVICE/" + deviceId + "/keys/attributes/CLIENT_SCOPE", new TypeReference<>() {}); | |
84 | 85 | if (actualKeys.size() == expectedKeys.size()) { |
85 | 86 | break; |
86 | 87 | } |
... | ... | @@ -96,7 +97,7 @@ public abstract class AbstractMqttAttributesIntegrationTest extends AbstractMqtt |
96 | 97 | assertEquals(expectedKeySet, actualKeySet); |
97 | 98 | |
98 | 99 | String getAttributesValuesUrl = getAttributesValuesUrl(deviceId, actualKeySet); |
99 | - List<Map<String, Object>> values = doGetAsync(getAttributesValuesUrl, List.class); | |
100 | + List<Map<String, Object>> values = doGetAsyncTyped(getAttributesValuesUrl, new TypeReference<>() {}); | |
100 | 101 | assertAttributesValues(values, expectedKeySet); |
101 | 102 | String deleteAttributesUrl = "/api/plugins/telemetry/DEVICE/" + deviceId + "/CLIENT_SCOPE?keys=" + String.join(",", actualKeySet); |
102 | 103 | doDelete(deleteAttributesUrl); |
... | ... | @@ -121,10 +122,10 @@ public abstract class AbstractMqttAttributesIntegrationTest extends AbstractMqtt |
121 | 122 | |
122 | 123 | Thread.sleep(2000); |
123 | 124 | |
124 | - List<String> firstDeviceActualKeys = doGetAsync("/api/plugins/telemetry/DEVICE/" + firstDevice.getId() + "/keys/attributes/CLIENT_SCOPE", List.class); | |
125 | + List<String> firstDeviceActualKeys = doGetAsyncTyped("/api/plugins/telemetry/DEVICE/" + firstDevice.getId() + "/keys/attributes/CLIENT_SCOPE", new TypeReference<>() {}); | |
125 | 126 | Set<String> firstDeviceActualKeySet = new HashSet<>(firstDeviceActualKeys); |
126 | 127 | |
127 | - List<String> secondDeviceActualKeys = doGetAsync("/api/plugins/telemetry/DEVICE/" + secondDevice.getId() + "/keys/attributes/CLIENT_SCOPE", List.class); | |
128 | + List<String> secondDeviceActualKeys = doGetAsyncTyped("/api/plugins/telemetry/DEVICE/" + secondDevice.getId() + "/keys/attributes/CLIENT_SCOPE", new TypeReference<>() {}); | |
128 | 129 | Set<String> secondDeviceActualKeySet = new HashSet<>(secondDeviceActualKeys); |
129 | 130 | |
130 | 131 | Set<String> expectedKeySet = new HashSet<>(expectedKeys); |
... | ... | @@ -135,14 +136,15 @@ public abstract class AbstractMqttAttributesIntegrationTest extends AbstractMqtt |
135 | 136 | String getAttributesValuesUrlFirstDevice = getAttributesValuesUrl(firstDevice.getId(), firstDeviceActualKeySet); |
136 | 137 | String getAttributesValuesUrlSecondDevice = getAttributesValuesUrl(firstDevice.getId(), secondDeviceActualKeySet); |
137 | 138 | |
138 | - List<Map<String, Object>> firstDeviceValues = doGetAsync(getAttributesValuesUrlFirstDevice, List.class); | |
139 | - List<Map<String, Object>> secondDeviceValues = doGetAsync(getAttributesValuesUrlSecondDevice, List.class); | |
139 | + List<Map<String, Object>> firstDeviceValues = doGetAsyncTyped(getAttributesValuesUrlFirstDevice, new TypeReference<>() {}); | |
140 | + List<Map<String, Object>> secondDeviceValues = doGetAsyncTyped(getAttributesValuesUrlSecondDevice, new TypeReference<>() {}); | |
140 | 141 | |
141 | 142 | assertAttributesValues(firstDeviceValues, expectedKeySet); |
142 | 143 | assertAttributesValues(secondDeviceValues, expectedKeySet); |
143 | 144 | |
144 | 145 | } |
145 | 146 | |
147 | + @SuppressWarnings("unchecked") | |
146 | 148 | protected void assertAttributesValues(List<Map<String, Object>> deviceValues, Set<String> expectedKeySet) throws JsonProcessingException { |
147 | 149 | for (Map<String, Object> map : deviceValues) { |
148 | 150 | String key = (String) map.get("key"); | ... | ... |
... | ... | @@ -15,6 +15,7 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.mqtt.telemetry.timeseries; |
17 | 17 | |
18 | +import com.fasterxml.jackson.core.type.TypeReference; | |
18 | 19 | import io.netty.handler.codec.mqtt.MqttQoS; |
19 | 20 | import lombok.extern.slf4j.Slf4j; |
20 | 21 | import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken; |
... | ... | @@ -25,6 +26,7 @@ import org.eclipse.paho.client.mqttv3.MqttMessage; |
25 | 26 | import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence; |
26 | 27 | import org.junit.After; |
27 | 28 | import org.junit.Before; |
29 | +import org.junit.Ignore; | |
28 | 30 | import org.junit.Test; |
29 | 31 | import org.thingsboard.server.common.data.Device; |
30 | 32 | import org.thingsboard.server.common.data.device.profile.MqttTopics; |
... | ... | @@ -107,7 +109,7 @@ public abstract class AbstractMqttTimeseriesIntegrationTest extends AbstractMqtt |
107 | 109 | |
108 | 110 | List<String> actualKeys = null; |
109 | 111 | while (start <= end) { |
110 | - actualKeys = doGetAsync("/api/plugins/telemetry/DEVICE/" + deviceId + "/keys/timeseries", List.class); | |
112 | + actualKeys = doGetAsyncTyped("/api/plugins/telemetry/DEVICE/" + deviceId + "/keys/timeseries", new TypeReference<>() {}); | |
111 | 113 | if (actualKeys.size() == expectedKeys.size()) { |
112 | 114 | break; |
113 | 115 | } |
... | ... | @@ -129,13 +131,13 @@ public abstract class AbstractMqttTimeseriesIntegrationTest extends AbstractMqtt |
129 | 131 | } |
130 | 132 | start = System.currentTimeMillis(); |
131 | 133 | end = System.currentTimeMillis() + 5000; |
132 | - Map<String, List<Map<String, String>>> values = null; | |
134 | + Map<String, List<Map<String, Object>>> values = null; | |
133 | 135 | while (start <= end) { |
134 | - values = doGetAsync(getTelemetryValuesUrl, Map.class); | |
136 | + values = doGetAsyncTyped(getTelemetryValuesUrl, new TypeReference<>() {}); | |
135 | 137 | boolean valid = values.size() == expectedKeys.size(); |
136 | 138 | if (valid) { |
137 | 139 | for (String key : expectedKeys) { |
138 | - List<Map<String, String>> tsValues = values.get(key); | |
140 | + List<Map<String, Object>> tsValues = values.get(key); | |
139 | 141 | if (tsValues != null && tsValues.size() > 0) { |
140 | 142 | Object ts = tsValues.get(0).get("ts"); |
141 | 143 | if (ts == null) { |
... | ... | @@ -181,10 +183,10 @@ public abstract class AbstractMqttTimeseriesIntegrationTest extends AbstractMqtt |
181 | 183 | |
182 | 184 | Thread.sleep(2000); |
183 | 185 | |
184 | - List<String> firstDeviceActualKeys = doGetAsync("/api/plugins/telemetry/DEVICE/" + firstDevice.getId() + "/keys/timeseries", List.class); | |
186 | + List<String> firstDeviceActualKeys = doGetAsyncTyped("/api/plugins/telemetry/DEVICE/" + firstDevice.getId() + "/keys/timeseries", new TypeReference<>() {}); | |
185 | 187 | Set<String> firstDeviceActualKeySet = new HashSet<>(firstDeviceActualKeys); |
186 | 188 | |
187 | - List<String> secondDeviceActualKeys = doGetAsync("/api/plugins/telemetry/DEVICE/" + secondDevice.getId() + "/keys/timeseries", List.class); | |
189 | + List<String> secondDeviceActualKeys = doGetAsyncTyped("/api/plugins/telemetry/DEVICE/" + secondDevice.getId() + "/keys/timeseries", new TypeReference<>() {}); | |
188 | 190 | Set<String> secondDeviceActualKeySet = new HashSet<>(secondDeviceActualKeys); |
189 | 191 | |
190 | 192 | Set<String> expectedKeySet = new HashSet<>(expectedKeys); |
... | ... | @@ -195,8 +197,8 @@ public abstract class AbstractMqttTimeseriesIntegrationTest extends AbstractMqtt |
195 | 197 | String getTelemetryValuesUrlFirstDevice = getTelemetryValuesUrl(firstDevice.getId(), firstDeviceActualKeySet); |
196 | 198 | String getTelemetryValuesUrlSecondDevice = getTelemetryValuesUrl(firstDevice.getId(), secondDeviceActualKeySet); |
197 | 199 | |
198 | - Map<String, List<Map<String, String>>> firstDeviceValues = doGetAsync(getTelemetryValuesUrlFirstDevice, Map.class); | |
199 | - Map<String, List<Map<String, String>>> secondDeviceValues = doGetAsync(getTelemetryValuesUrlSecondDevice, Map.class); | |
200 | + Map<String, List<Map<String, Object>>> firstDeviceValues = doGetAsyncTyped(getTelemetryValuesUrlFirstDevice, new TypeReference<>() {}); | |
201 | + Map<String, List<Map<String, Object>>> secondDeviceValues = doGetAsyncTyped(getTelemetryValuesUrlSecondDevice, new TypeReference<>() {}); | |
200 | 202 | |
201 | 203 | assertGatewayDeviceData(firstDeviceValues, expectedKeys); |
202 | 204 | assertGatewayDeviceData(secondDeviceValues, expectedKeys); |
... | ... | @@ -212,7 +214,7 @@ public abstract class AbstractMqttTimeseriesIntegrationTest extends AbstractMqtt |
212 | 214 | return "/api/plugins/telemetry/DEVICE/" + deviceId + "/values/timeseries?startTs=0&endTs=25000&keys=" + String.join(",", actualKeySet); |
213 | 215 | } |
214 | 216 | |
215 | - private void assertGatewayDeviceData(Map<String, List<Map<String, String>>> deviceValues, List<String> expectedKeys) { | |
217 | + private void assertGatewayDeviceData(Map<String, List<Map<String, Object>>> deviceValues, List<String> expectedKeys) { | |
216 | 218 | |
217 | 219 | assertEquals(2, deviceValues.get(expectedKeys.get(0)).size()); |
218 | 220 | assertEquals(2, deviceValues.get(expectedKeys.get(1)).size()); |
... | ... | @@ -228,11 +230,11 @@ public abstract class AbstractMqttTimeseriesIntegrationTest extends AbstractMqtt |
228 | 230 | |
229 | 231 | } |
230 | 232 | |
231 | - private void assertValues(Map<String, List<Map<String, String>>> deviceValues, int arrayIndex) { | |
232 | - for (Map.Entry<String, List<Map<String, String>>> entry : deviceValues.entrySet()) { | |
233 | + private void assertValues(Map<String, List<Map<String, Object>>> deviceValues, int arrayIndex) { | |
234 | + for (Map.Entry<String, List<Map<String, Object>>> entry : deviceValues.entrySet()) { | |
233 | 235 | String key = entry.getKey(); |
234 | - List<Map<String, String>> tsKv = entry.getValue(); | |
235 | - String value = tsKv.get(arrayIndex).get("value"); | |
236 | + List<Map<String, Object>> tsKv = entry.getValue(); | |
237 | + String value = (String) tsKv.get(arrayIndex).get("value"); | |
236 | 238 | switch (key) { |
237 | 239 | case "key1": |
238 | 240 | assertEquals("value1", value); |
... | ... | @@ -253,7 +255,7 @@ public abstract class AbstractMqttTimeseriesIntegrationTest extends AbstractMqtt |
253 | 255 | } |
254 | 256 | } |
255 | 257 | |
256 | - private void assertTs(Map<String, List<Map<String, String>>> deviceValues, List<String> expectedKeys, int ts, int arrayIndex) { | |
258 | + private void assertTs(Map<String, List<Map<String, Object>>> deviceValues, List<String> expectedKeys, int ts, int arrayIndex) { | |
257 | 259 | assertEquals(ts, deviceValues.get(expectedKeys.get(0)).get(arrayIndex).get("ts")); |
258 | 260 | assertEquals(ts, deviceValues.get(expectedKeys.get(1)).get(arrayIndex).get("ts")); |
259 | 261 | assertEquals(ts, deviceValues.get(expectedKeys.get(2)).get(arrayIndex).get("ts")); | ... | ... |
... | ... | @@ -21,12 +21,11 @@ import org.junit.Assert; |
21 | 21 | import org.junit.Before; |
22 | 22 | import org.junit.Test; |
23 | 23 | import org.junit.runner.RunWith; |
24 | -import org.mockito.runners.MockitoJUnitRunner; | |
24 | +import org.mockito.junit.MockitoJUnitRunner; | |
25 | 25 | import org.springframework.context.ApplicationEventPublisher; |
26 | 26 | import org.springframework.test.util.ReflectionTestUtils; |
27 | 27 | import org.thingsboard.server.common.data.id.DeviceId; |
28 | 28 | import org.thingsboard.server.common.data.id.TenantId; |
29 | -import org.thingsboard.server.common.msg.queue.ServiceQueue; | |
30 | 29 | import org.thingsboard.server.queue.discovery.HashPartitionService; |
31 | 30 | import org.thingsboard.server.common.msg.queue.ServiceType; |
32 | 31 | import org.thingsboard.server.queue.discovery.TbServiceInfoProvider; | ... | ... |
... | ... | @@ -20,7 +20,7 @@ import org.junit.Assert; |
20 | 20 | import org.junit.Test; |
21 | 21 | import org.junit.runner.RunWith; |
22 | 22 | import org.mockito.Mockito; |
23 | -import org.mockito.runners.MockitoJUnitRunner; | |
23 | +import org.mockito.junit.MockitoJUnitRunner; | |
24 | 24 | import org.thingsboard.server.gen.transport.TransportProtos; |
25 | 25 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; |
26 | 26 | import org.thingsboard.server.service.queue.processing.TbRuleEngineSubmitStrategy; | ... | ... |
... | ... | @@ -20,7 +20,7 @@ import lombok.extern.slf4j.Slf4j; |
20 | 20 | import org.junit.Test; |
21 | 21 | import org.junit.runner.RunWith; |
22 | 22 | import org.mockito.Mockito; |
23 | -import org.mockito.runners.MockitoJUnitRunner; | |
23 | +import org.mockito.junit.MockitoJUnitRunner; | |
24 | 24 | import org.thingsboard.server.utils.EventDeduplicationExecutor; |
25 | 25 | |
26 | 26 | import java.util.concurrent.ExecutorService; | ... | ... |
... | ... | @@ -21,7 +21,7 @@ import org.junit.Assert; |
21 | 21 | import org.junit.Before; |
22 | 22 | import org.junit.Test; |
23 | 23 | import org.junit.runner.RunWith; |
24 | -import org.mockito.runners.MockitoJUnitRunner; | |
24 | +import org.mockito.junit.MockitoJUnitRunner; | |
25 | 25 | import org.thingsboard.server.common.data.id.DeviceId; |
26 | 26 | |
27 | 27 | import java.util.ArrayList; | ... | ... |
... | ... | @@ -49,6 +49,10 @@ |
49 | 49 | <artifactId>guava</artifactId> |
50 | 50 | </dependency> |
51 | 51 | <dependency> |
52 | + <groupId>javax.annotation</groupId> | |
53 | + <artifactId>javax.annotation-api</artifactId> | |
54 | + </dependency> | |
55 | + <dependency> | |
52 | 56 | <groupId>com.github.fge</groupId> |
53 | 57 | <artifactId>json-schema-validator</artifactId> |
54 | 58 | </dependency> |
... | ... | @@ -99,7 +103,7 @@ |
99 | 103 | </dependency> |
100 | 104 | <dependency> |
101 | 105 | <groupId>org.mockito</groupId> |
102 | - <artifactId>mockito-all</artifactId> | |
106 | + <artifactId>mockito-core</artifactId> | |
103 | 107 | <scope>test</scope> |
104 | 108 | </dependency> |
105 | 109 | </dependencies> | ... | ... |
... | ... | @@ -23,6 +23,7 @@ import lombok.extern.slf4j.Slf4j; |
23 | 23 | import org.springframework.beans.factory.annotation.Autowired; |
24 | 24 | import org.springframework.beans.factory.annotation.Value; |
25 | 25 | import org.springframework.core.env.Environment; |
26 | +import org.springframework.core.env.Profiles; | |
26 | 27 | import org.thingsboard.server.dao.cassandra.guava.GuavaSession; |
27 | 28 | import org.thingsboard.server.dao.cassandra.guava.GuavaSessionBuilder; |
28 | 29 | import org.thingsboard.server.dao.cassandra.guava.GuavaSessionUtils; |
... | ... | @@ -77,7 +78,7 @@ public abstract class AbstractCassandraCluster { |
77 | 78 | } |
78 | 79 | |
79 | 80 | private boolean isInstall() { |
80 | - return environment.acceptsProfiles("install"); | |
81 | + return environment.acceptsProfiles(Profiles.of("install")); | |
81 | 82 | } |
82 | 83 | |
83 | 84 | private void initSession() { | ... | ... |
... | ... | @@ -18,38 +18,25 @@ package org.thingsboard.server.dao.cassandra.guava; |
18 | 18 | import com.datastax.oss.driver.api.core.CqlSession; |
19 | 19 | import com.datastax.oss.driver.api.core.config.DriverConfigLoader; |
20 | 20 | import com.datastax.oss.driver.api.core.context.DriverContext; |
21 | -import com.datastax.oss.driver.api.core.metadata.Node; | |
22 | -import com.datastax.oss.driver.api.core.metadata.NodeStateListener; | |
23 | -import com.datastax.oss.driver.api.core.metadata.schema.SchemaChangeListener; | |
21 | +import com.datastax.oss.driver.api.core.session.ProgrammaticArguments; | |
24 | 22 | import com.datastax.oss.driver.api.core.session.SessionBuilder; |
25 | -import com.datastax.oss.driver.api.core.tracker.RequestTracker; | |
26 | -import com.datastax.oss.driver.api.core.type.codec.TypeCodec; | |
27 | 23 | import edu.umd.cs.findbugs.annotations.NonNull; |
28 | -import java.util.List; | |
29 | -import java.util.Map; | |
30 | -import java.util.function.Predicate; | |
31 | 24 | |
32 | 25 | public class GuavaSessionBuilder extends SessionBuilder<GuavaSessionBuilder, GuavaSession> { |
33 | 26 | |
34 | 27 | @Override |
35 | 28 | protected DriverContext buildContext( |
36 | 29 | DriverConfigLoader configLoader, |
37 | - List<TypeCodec<?>> typeCodecs, | |
38 | - NodeStateListener nodeStateListener, | |
39 | - SchemaChangeListener schemaChangeListener, | |
40 | - RequestTracker requestTracker, | |
41 | - Map<String, String> localDatacenters, | |
42 | - Map<String, Predicate<Node>> nodeFilters, | |
43 | - ClassLoader classLoader) { | |
30 | + ProgrammaticArguments programmaticArguments) { | |
44 | 31 | return new GuavaDriverContext( |
45 | 32 | configLoader, |
46 | - typeCodecs, | |
47 | - nodeStateListener, | |
48 | - schemaChangeListener, | |
49 | - requestTracker, | |
50 | - localDatacenters, | |
51 | - nodeFilters, | |
52 | - classLoader); | |
33 | + programmaticArguments.getTypeCodecs(), | |
34 | + programmaticArguments.getNodeStateListener(), | |
35 | + programmaticArguments.getSchemaChangeListener(), | |
36 | + programmaticArguments.getRequestTracker(), | |
37 | + programmaticArguments.getLocalDatacenters(), | |
38 | + programmaticArguments.getNodeFilters(), | |
39 | + programmaticArguments.getClassLoader()); | |
53 | 40 | } |
54 | 41 | |
55 | 42 | @Override | ... | ... |
... | ... | @@ -18,9 +18,11 @@ package org.thingsboard.server.dao.device.claim; |
18 | 18 | |
19 | 19 | import lombok.AllArgsConstructor; |
20 | 20 | import lombok.Data; |
21 | +import lombok.NoArgsConstructor; | |
21 | 22 | import org.thingsboard.server.common.data.Device; |
22 | 23 | |
23 | 24 | @AllArgsConstructor |
25 | +@NoArgsConstructor | |
24 | 26 | @Data |
25 | 27 | public class ClaimResult { |
26 | 28 | ... | ... |
... | ... | @@ -15,9 +15,13 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.common.data; |
17 | 17 | |
18 | +import lombok.AllArgsConstructor; | |
18 | 19 | import lombok.Data; |
20 | +import lombok.NoArgsConstructor; | |
19 | 21 | |
20 | 22 | @Data |
23 | +@AllArgsConstructor | |
24 | +@NoArgsConstructor(force = true) | |
21 | 25 | public class ClaimRequest { |
22 | 26 | |
23 | 27 | private final String secretKey; | ... | ... |
... | ... | @@ -17,10 +17,12 @@ package org.thingsboard.server.common.data; |
17 | 17 | |
18 | 18 | import lombok.AllArgsConstructor; |
19 | 19 | import lombok.Data; |
20 | +import lombok.NoArgsConstructor; | |
20 | 21 | import org.thingsboard.server.common.data.id.DashboardId; |
21 | 22 | |
22 | 23 | @Data |
23 | 24 | @AllArgsConstructor |
25 | +@NoArgsConstructor | |
24 | 26 | public class HomeDashboardInfo { |
25 | 27 | private DashboardId dashboardId; |
26 | 28 | private boolean hideDashboardToolbar; | ... | ... |
... | ... | @@ -17,6 +17,7 @@ package org.thingsboard.server.common.data; |
17 | 17 | |
18 | 18 | import lombok.AllArgsConstructor; |
19 | 19 | import lombok.Getter; |
20 | +import lombok.NoArgsConstructor; | |
20 | 21 | import lombok.Setter; |
21 | 22 | import org.thingsboard.server.common.data.id.CustomerId; |
22 | 23 | |
... | ... | @@ -25,6 +26,7 @@ import org.thingsboard.server.common.data.id.CustomerId; |
25 | 26 | */ |
26 | 27 | |
27 | 28 | @AllArgsConstructor |
29 | +@NoArgsConstructor | |
28 | 30 | public class ShortCustomerInfo { |
29 | 31 | |
30 | 32 | @Getter @Setter | ... | ... |
... | ... | @@ -15,10 +15,14 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.common.data.device.profile; |
17 | 17 | |
18 | +import lombok.AllArgsConstructor; | |
18 | 19 | import lombok.Data; |
20 | +import lombok.NoArgsConstructor; | |
19 | 21 | import org.thingsboard.server.common.data.DeviceProfileProvisionType; |
20 | 22 | |
21 | 23 | @Data |
24 | +@AllArgsConstructor | |
25 | +@NoArgsConstructor(force = true) | |
22 | 26 | public class AllowCreateNewDevicesDeviceProfileProvisionConfiguration implements DeviceProfileProvisionConfiguration { |
23 | 27 | |
24 | 28 | private final String provisionDeviceSecret; | ... | ... |
... | ... | @@ -15,10 +15,14 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.common.data.device.profile; |
17 | 17 | |
18 | +import lombok.AllArgsConstructor; | |
18 | 19 | import lombok.Data; |
20 | +import lombok.NoArgsConstructor; | |
19 | 21 | import org.thingsboard.server.common.data.DeviceProfileProvisionType; |
20 | 22 | |
21 | 23 | @Data |
24 | +@AllArgsConstructor | |
25 | +@NoArgsConstructor(force = true) | |
22 | 26 | public class CheckPreProvisionedDevicesDeviceProfileProvisionConfiguration implements DeviceProfileProvisionConfiguration { |
23 | 27 | |
24 | 28 | private final String provisionDeviceSecret; | ... | ... |
... | ... | @@ -15,10 +15,14 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.common.data.device.profile; |
17 | 17 | |
18 | +import lombok.AllArgsConstructor; | |
18 | 19 | import lombok.Data; |
20 | +import lombok.NoArgsConstructor; | |
19 | 21 | import org.thingsboard.server.common.data.DeviceProfileProvisionType; |
20 | 22 | |
21 | 23 | @Data |
24 | +@AllArgsConstructor | |
25 | +@NoArgsConstructor(force = true) | |
22 | 26 | public class DisabledDeviceProfileProvisionConfiguration implements DeviceProfileProvisionConfiguration { |
23 | 27 | |
24 | 28 | private final String provisionDeviceSecret; | ... | ... |
... | ... | @@ -15,7 +15,9 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.common.data.query; |
17 | 17 | |
18 | +import com.fasterxml.jackson.annotation.JsonCreator; | |
18 | 19 | import com.fasterxml.jackson.annotation.JsonIgnore; |
20 | +import com.fasterxml.jackson.annotation.JsonProperty; | |
19 | 21 | import lombok.Data; |
20 | 22 | import lombok.Getter; |
21 | 23 | |
... | ... | @@ -30,4 +32,11 @@ public class DynamicValue<T> { |
30 | 32 | @Getter |
31 | 33 | private final String sourceAttribute; |
32 | 34 | |
35 | + @JsonCreator | |
36 | + public DynamicValue(@JsonProperty("sourceType") DynamicValueSourceType sourceType, | |
37 | + @JsonProperty("sourceAttribute") String sourceAttribute) { | |
38 | + this.sourceType = sourceType; | |
39 | + this.sourceAttribute = sourceAttribute; | |
40 | + } | |
41 | + | |
33 | 42 | } | ... | ... |
... | ... | @@ -15,12 +15,16 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.common.data.query; |
17 | 17 | |
18 | +import lombok.AllArgsConstructor; | |
18 | 19 | import lombok.Data; |
20 | +import lombok.NoArgsConstructor; | |
19 | 21 | import org.thingsboard.server.common.data.id.EntityId; |
20 | 22 | |
21 | 23 | import java.util.Map; |
22 | 24 | |
23 | 25 | @Data |
26 | +@AllArgsConstructor | |
27 | +@NoArgsConstructor(force = true) | |
24 | 28 | public class EntityData { |
25 | 29 | |
26 | 30 | private final EntityId entityId; | ... | ... |
... | ... | @@ -15,9 +15,13 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.common.data.query; |
17 | 17 | |
18 | +import lombok.AllArgsConstructor; | |
18 | 19 | import lombok.Data; |
20 | +import lombok.NoArgsConstructor; | |
19 | 21 | |
20 | 22 | @Data |
23 | +@AllArgsConstructor | |
24 | +@NoArgsConstructor(force = true) | |
21 | 25 | public class EntityKey { |
22 | 26 | private final EntityKeyType type; |
23 | 27 | private final String key; | ... | ... |
... | ... | @@ -15,9 +15,13 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.common.data.query; |
17 | 17 | |
18 | +import lombok.AllArgsConstructor; | |
18 | 19 | import lombok.Data; |
20 | +import lombok.NoArgsConstructor; | |
19 | 21 | |
20 | 22 | @Data |
23 | +@AllArgsConstructor | |
24 | +@NoArgsConstructor(force = true) | |
21 | 25 | public class TsValue { |
22 | 26 | |
23 | 27 | private final long ts; | ... | ... |
... | ... | @@ -17,6 +17,7 @@ package org.thingsboard.server.common.data.relation; |
17 | 17 | |
18 | 18 | import lombok.AllArgsConstructor; |
19 | 19 | import lombok.Data; |
20 | +import lombok.NoArgsConstructor; | |
20 | 21 | import org.thingsboard.server.common.data.EntityType; |
21 | 22 | |
22 | 23 | import java.util.List; |
... | ... | @@ -26,6 +27,7 @@ import java.util.List; |
26 | 27 | */ |
27 | 28 | @Data |
28 | 29 | @AllArgsConstructor |
30 | +@NoArgsConstructor | |
29 | 31 | public class EntityTypeFilter { |
30 | 32 | |
31 | 33 | private String relationType; | ... | ... |
common/data/src/main/java/org/thingsboard/server/common/data/relation/RelationsSearchParameters.java
... | ... | @@ -17,6 +17,7 @@ package org.thingsboard.server.common.data.relation; |
17 | 17 | |
18 | 18 | import lombok.AllArgsConstructor; |
19 | 19 | import lombok.Data; |
20 | +import lombok.NoArgsConstructor; | |
20 | 21 | import org.thingsboard.server.common.data.EntityType; |
21 | 22 | import org.thingsboard.server.common.data.id.EntityId; |
22 | 23 | import org.thingsboard.server.common.data.id.EntityIdFactory; |
... | ... | @@ -28,6 +29,7 @@ import java.util.UUID; |
28 | 29 | */ |
29 | 30 | @Data |
30 | 31 | @AllArgsConstructor |
32 | +@NoArgsConstructor | |
31 | 33 | public class RelationsSearchParameters { |
32 | 34 | |
33 | 35 | private UUID rootId; | ... | ... |
... | ... | @@ -19,7 +19,7 @@ import com.datastax.oss.driver.api.core.uuid.Uuids; |
19 | 19 | import org.junit.Assert; |
20 | 20 | import org.junit.Test; |
21 | 21 | import org.junit.runner.RunWith; |
22 | -import org.mockito.runners.MockitoJUnitRunner; | |
22 | +import org.mockito.junit.MockitoJUnitRunner; | |
23 | 23 | |
24 | 24 | import java.util.ArrayList; |
25 | 25 | import java.util.Arrays; | ... | ... |
... | ... | @@ -154,6 +154,7 @@ public class TbServiceBusConsumerTemplate<T extends TbQueueMsg> extends Abstract |
154 | 154 | } |
155 | 155 | |
156 | 156 | private <V> CompletableFuture<List<V>> fromList(List<CompletableFuture<V>> futures) { |
157 | + @SuppressWarnings("unchecked") | |
157 | 158 | CompletableFuture<Collection<V>>[] arrayFuture = new CompletableFuture[futures.size()]; |
158 | 159 | futures.toArray(arrayFuture); |
159 | 160 | ... | ... |
... | ... | @@ -60,6 +60,7 @@ public final class InMemoryStorage { |
60 | 60 | public <T extends TbQueueMsg> List<T> get(String topic) throws InterruptedException { |
61 | 61 | if (storage.containsKey(topic)) { |
62 | 62 | List<T> entities; |
63 | + @SuppressWarnings("unchecked") | |
63 | 64 | T first = (T) storage.get(topic).poll(); |
64 | 65 | if (first != null) { |
65 | 66 | entities = new ArrayList<>(); |
... | ... | @@ -67,7 +68,9 @@ public final class InMemoryStorage { |
67 | 68 | List<TbQueueMsg> otherList = new ArrayList<>(); |
68 | 69 | storage.get(topic).drainTo(otherList, 999); |
69 | 70 | for (TbQueueMsg other : otherList) { |
70 | - entities.add((T) other); | |
71 | + @SuppressWarnings("unchecked") | |
72 | + T entity = (T) other; | |
73 | + entities.add(entity); | |
71 | 74 | } |
72 | 75 | } else { |
73 | 76 | entities = Collections.emptyList(); | ... | ... |
... | ... | @@ -64,6 +64,7 @@ public class InMemoryTbQueueConsumer<T extends TbQueueMsg> implements TbQueueCon |
64 | 64 | @Override |
65 | 65 | public List<T> poll(long durationInMillis) { |
66 | 66 | if (subscribed) { |
67 | + @SuppressWarnings("unchecked") | |
67 | 68 | List<T> messages = partitions |
68 | 69 | .stream() |
69 | 70 | .map(tpi -> { | ... | ... |
... | ... | @@ -47,6 +47,7 @@ public class DefaultTbApiUsageClient implements TbApiUsageClient { |
47 | 47 | @Value("${usage.stats.report.interval:10}") |
48 | 48 | private int interval; |
49 | 49 | |
50 | + @SuppressWarnings("unchecked") | |
50 | 51 | private final ConcurrentMap<TenantId, AtomicLong>[] values = new ConcurrentMap[ApiUsageRecordKey.values().length]; |
51 | 52 | private final PartitionService partitionService; |
52 | 53 | private final SchedulerComponent scheduler; | ... | ... |
... | ... | @@ -79,7 +79,7 @@ |
79 | 79 | </dependency> |
80 | 80 | <dependency> |
81 | 81 | <groupId>org.mockito</groupId> |
82 | - <artifactId>mockito-all</artifactId> | |
82 | + <artifactId>mockito-core</artifactId> | |
83 | 83 | <scope>test</scope> |
84 | 84 | </dependency> |
85 | 85 | </dependencies> |
... | ... | @@ -89,4 +89,4 @@ |
89 | 89 | </plugins> |
90 | 90 | </build> |
91 | 91 | |
92 | -</project> | |
\ No newline at end of file | ||
92 | +</project> | ... | ... |
... | ... | @@ -45,6 +45,7 @@ import java.io.IOException; |
45 | 45 | import java.io.InputStream; |
46 | 46 | import java.net.URL; |
47 | 47 | import java.security.KeyStore; |
48 | +import java.security.cert.CertificateEncodingException; | |
48 | 49 | import java.security.cert.CertificateException; |
49 | 50 | import java.security.cert.X509Certificate; |
50 | 51 | import java.util.concurrent.CountDownLatch; |
... | ... | @@ -154,7 +155,7 @@ public class MqttSslHandlerProvider { |
154 | 155 | String credentialsBody = null; |
155 | 156 | for (X509Certificate cert : chain) { |
156 | 157 | try { |
157 | - String strCert = SslUtil.getX509CertificateString(cert); | |
158 | + String strCert = SslUtil.getCertificateString(cert); | |
158 | 159 | String sha3Hash = EncryptionUtil.getSha3Hash(strCert); |
159 | 160 | final String[] credentialsBodyHolder = new String[1]; |
160 | 161 | CountDownLatch latch = new CountDownLatch(1); |
... | ... | @@ -179,7 +180,7 @@ public class MqttSslHandlerProvider { |
179 | 180 | credentialsBody = credentialsBodyHolder[0]; |
180 | 181 | break; |
181 | 182 | } |
182 | - } catch (InterruptedException | IOException e) { | |
183 | + } catch (InterruptedException | CertificateEncodingException e) { | |
183 | 184 | log.error(e.getMessage(), e); |
184 | 185 | } |
185 | 186 | } | ... | ... |
... | ... | @@ -35,6 +35,7 @@ import io.netty.handler.codec.mqtt.MqttSubscribeMessage; |
35 | 35 | import io.netty.handler.codec.mqtt.MqttTopicSubscription; |
36 | 36 | import io.netty.handler.codec.mqtt.MqttUnsubscribeMessage; |
37 | 37 | import io.netty.handler.ssl.SslHandler; |
38 | +import io.netty.util.CharsetUtil; | |
38 | 39 | import io.netty.util.ReferenceCountUtil; |
39 | 40 | import io.netty.util.concurrent.Future; |
40 | 41 | import io.netty.util.concurrent.GenericFutureListener; |
... | ... | @@ -68,7 +69,8 @@ import org.thingsboard.server.transport.mqtt.session.MqttTopicMatcher; |
68 | 69 | import org.thingsboard.server.transport.mqtt.util.SslUtil; |
69 | 70 | |
70 | 71 | import javax.net.ssl.SSLPeerUnverifiedException; |
71 | -import javax.security.cert.X509Certificate; | |
72 | +import java.security.cert.Certificate; | |
73 | +import java.security.cert.X509Certificate; | |
72 | 74 | import java.io.IOException; |
73 | 75 | import java.net.InetSocketAddress; |
74 | 76 | import java.util.ArrayList; |
... | ... | @@ -315,7 +317,7 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement |
315 | 317 | } |
316 | 318 | |
317 | 319 | private <T> TransportServiceCallback<Void> getPubAckCallback(final ChannelHandlerContext ctx, final int msgId, final T msg) { |
318 | - return new TransportServiceCallback<Void>() { | |
320 | + return new TransportServiceCallback<>() { | |
319 | 321 | @Override |
320 | 322 | public void onSuccess(Void dummy) { |
321 | 323 | log.trace("[{}] Published msg: {}", sessionId, msg); |
... | ... | @@ -482,12 +484,13 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement |
482 | 484 | if (userName != null) { |
483 | 485 | request.setUserName(userName); |
484 | 486 | } |
485 | - String password = connectMessage.payload().password(); | |
486 | - if (password != null) { | |
487 | + byte[] passwordBytes = connectMessage.payload().passwordInBytes(); | |
488 | + if (passwordBytes != null) { | |
489 | + String password = new String(passwordBytes, CharsetUtil.UTF_8); | |
487 | 490 | request.setPassword(password); |
488 | 491 | } |
489 | 492 | transportService.process(DeviceTransportType.MQTT, request.build(), |
490 | - new TransportServiceCallback<ValidateDeviceCredentialsResponse>() { | |
493 | + new TransportServiceCallback<>() { | |
491 | 494 | @Override |
492 | 495 | public void onSuccess(ValidateDeviceCredentialsResponse msg) { |
493 | 496 | onValidateDeviceResponse(msg, ctx, connectMessage); |
... | ... | @@ -507,10 +510,10 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement |
507 | 510 | if (!context.isSkipValidityCheckForClientCert()) { |
508 | 511 | cert.checkValidity(); |
509 | 512 | } |
510 | - String strCert = SslUtil.getX509CertificateString(cert); | |
513 | + String strCert = SslUtil.getCertificateString(cert); | |
511 | 514 | String sha3Hash = EncryptionUtil.getSha3Hash(strCert); |
512 | 515 | transportService.process(DeviceTransportType.MQTT, ValidateDeviceX509CertRequestMsg.newBuilder().setHash(sha3Hash).build(), |
513 | - new TransportServiceCallback<ValidateDeviceCredentialsResponse>() { | |
516 | + new TransportServiceCallback<>() { | |
514 | 517 | @Override |
515 | 518 | public void onSuccess(ValidateDeviceCredentialsResponse msg) { |
516 | 519 | onValidateDeviceResponse(msg, ctx, connectMessage); |
... | ... | @@ -531,9 +534,9 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement |
531 | 534 | |
532 | 535 | private X509Certificate getX509Certificate() { |
533 | 536 | try { |
534 | - X509Certificate[] certChain = sslHandler.engine().getSession().getPeerCertificateChain(); | |
537 | + Certificate[] certChain = sslHandler.engine().getSession().getPeerCertificates(); | |
535 | 538 | if (certChain.length > 0) { |
536 | - return certChain[0]; | |
539 | + return (X509Certificate) certChain[0]; | |
537 | 540 | } |
538 | 541 | } catch (SSLPeerUnverifiedException e) { |
539 | 542 | log.warn(e.getMessage()); | ... | ... |
... | ... | @@ -20,8 +20,8 @@ import org.springframework.util.Base64Utils; |
20 | 20 | import org.thingsboard.server.common.msg.EncryptionUtil; |
21 | 21 | |
22 | 22 | import java.io.IOException; |
23 | +import java.security.cert.Certificate; | |
23 | 24 | import java.security.cert.CertificateEncodingException; |
24 | -import java.security.cert.X509Certificate; | |
25 | 25 | |
26 | 26 | /** |
27 | 27 | * @author Valerii Sosliuk |
... | ... | @@ -32,15 +32,8 @@ public class SslUtil { |
32 | 32 | private SslUtil() { |
33 | 33 | } |
34 | 34 | |
35 | - public static String getX509CertificateString(X509Certificate cert) | |
36 | - throws CertificateEncodingException, IOException { | |
37 | - Base64Utils.encodeToString(cert.getEncoded()); | |
38 | - return EncryptionUtil.trimNewLines(Base64Utils.encodeToString(cert.getEncoded())); | |
39 | - } | |
40 | - | |
41 | - public static String getX509CertificateString(javax.security.cert.X509Certificate cert) | |
42 | - throws javax.security.cert.CertificateEncodingException, IOException { | |
43 | - Base64Utils.encodeToString(cert.getEncoded()); | |
35 | + public static String getCertificateString(Certificate cert) | |
36 | + throws CertificateEncodingException { | |
44 | 37 | return EncryptionUtil.trimNewLines(Base64Utils.encodeToString(cert.getEncoded())); |
45 | 38 | } |
46 | 39 | } | ... | ... |
... | ... | @@ -17,7 +17,7 @@ package org.thingsboard.server.transport.mqtt.util; |
17 | 17 | |
18 | 18 | import org.junit.Test; |
19 | 19 | import org.junit.runner.RunWith; |
20 | -import org.mockito.runners.MockitoJUnitRunner; | |
20 | +import org.mockito.junit.MockitoJUnitRunner; | |
21 | 21 | |
22 | 22 | import javax.script.ScriptException; |
23 | 23 | ... | ... |
... | ... | @@ -32,6 +32,7 @@ public class ProtoWithFSTService implements DataDecodingEncodingService { |
32 | 32 | @Override |
33 | 33 | public <T> Optional<T> decode(byte[] byteArray) { |
34 | 34 | try { |
35 | + @SuppressWarnings("unchecked") | |
35 | 36 | T msg = (T) config.asObject(byteArray); |
36 | 37 | return Optional.of(msg); |
37 | 38 | } catch (IllegalArgumentException e) { | ... | ... |
... | ... | @@ -42,6 +42,10 @@ |
42 | 42 | <scope>provided</scope> |
43 | 43 | </dependency> |
44 | 44 | <dependency> |
45 | + <groupId>javax.annotation</groupId> | |
46 | + <artifactId>javax.annotation-api</artifactId> | |
47 | + </dependency> | |
48 | + <dependency> | |
45 | 49 | <groupId>org.slf4j</groupId> |
46 | 50 | <artifactId>slf4j-api</artifactId> |
47 | 51 | </dependency> |
... | ... | @@ -64,7 +68,7 @@ |
64 | 68 | </dependency> |
65 | 69 | <dependency> |
66 | 70 | <groupId>org.mockito</groupId> |
67 | - <artifactId>mockito-all</artifactId> | |
71 | + <artifactId>mockito-core</artifactId> | |
68 | 72 | <scope>test</scope> |
69 | 73 | </dependency> |
70 | 74 | </dependencies> | ... | ... |
... | ... | @@ -40,11 +40,11 @@ public abstract class DaoUtil { |
40 | 40 | |
41 | 41 | public static <T> PageData<T> toPageData(Page<? extends ToData<T>> page) { |
42 | 42 | List<T> data = convertDataList(page.getContent()); |
43 | - return new PageData(data, page.getTotalPages(), page.getTotalElements(), page.hasNext()); | |
43 | + return new PageData<>(data, page.getTotalPages(), page.getTotalElements(), page.hasNext()); | |
44 | 44 | } |
45 | 45 | |
46 | 46 | public static <T> PageData<T> pageToPageData(Page<T> page) { |
47 | - return new PageData(page.getContent(), page.getTotalPages(), page.getTotalElements(), page.hasNext()); | |
47 | + return new PageData<>(page.getContent(), page.getTotalPages(), page.getTotalElements(), page.hasNext()); | |
48 | 48 | } |
49 | 49 | |
50 | 50 | public static Pageable toPageable(PageLink pageLink) { | ... | ... |
... | ... | @@ -306,7 +306,7 @@ public class BaseAlarmService extends AbstractEntityService implements AlarmServ |
306 | 306 | )); |
307 | 307 | } |
308 | 308 | return Futures.transform(Futures.successfulAsList(alarmFutures), |
309 | - alarmInfos -> new PageData(alarmInfos, alarms.getTotalPages(), alarms.getTotalElements(), | |
309 | + alarmInfos -> new PageData<>(alarmInfos, alarms.getTotalPages(), alarms.getTotalElements(), | |
310 | 310 | alarms.hasNext()), MoreExecutors.directExecutor()); |
311 | 311 | } |
312 | 312 | return Futures.immediateFuture(alarms); | ... | ... |
... | ... | @@ -190,6 +190,7 @@ public class AuditLogServiceImpl implements AuditLogService { |
190 | 190 | case ATTRIBUTES_UPDATED: |
191 | 191 | actionData.put("entityId", entityId.toString()); |
192 | 192 | String scope = extractParameter(String.class, 0, additionalInfo); |
193 | + @SuppressWarnings("unchecked") | |
193 | 194 | List<AttributeKvEntry> attributes = extractParameter(List.class, 1, additionalInfo); |
194 | 195 | actionData.put("scope", scope); |
195 | 196 | ObjectNode attrsNode = JacksonUtil.newObjectNode(); |
... | ... | @@ -205,6 +206,7 @@ public class AuditLogServiceImpl implements AuditLogService { |
205 | 206 | actionData.put("entityId", entityId.toString()); |
206 | 207 | scope = extractParameter(String.class, 0, additionalInfo); |
207 | 208 | actionData.put("scope", scope); |
209 | + @SuppressWarnings("unchecked") | |
208 | 210 | List<String> keys = extractParameter(List.class, 1, additionalInfo); |
209 | 211 | ArrayNode attrsArrayNode = actionData.putArray("attributes"); |
210 | 212 | if (keys != null) { |
... | ... | @@ -267,6 +269,7 @@ public class AuditLogServiceImpl implements AuditLogService { |
267 | 269 | break; |
268 | 270 | case TIMESERIES_UPDATED: |
269 | 271 | actionData.put("entityId", entityId.toString()); |
272 | + @SuppressWarnings("unchecked") | |
270 | 273 | List<TsKvEntry> updatedTimeseries = extractParameter(List.class, 0, additionalInfo); |
271 | 274 | if (updatedTimeseries != null) { |
272 | 275 | ArrayNode result = actionData.putArray("timeseries"); |
... | ... | @@ -283,6 +286,7 @@ public class AuditLogServiceImpl implements AuditLogService { |
283 | 286 | break; |
284 | 287 | case TIMESERIES_DELETED: |
285 | 288 | actionData.put("entityId", entityId.toString()); |
289 | + @SuppressWarnings("unchecked") | |
286 | 290 | List<String> timeseriesKeys = extractParameter(List.class, 0, additionalInfo); |
287 | 291 | if (timeseriesKeys != null) { |
288 | 292 | ArrayNode timeseriesArrayNode = actionData.putArray("timeseries"); | ... | ... |
... | ... | @@ -36,22 +36,22 @@ public class DummyAuditLogServiceImpl implements AuditLogService { |
36 | 36 | |
37 | 37 | @Override |
38 | 38 | public PageData<AuditLog> findAuditLogsByTenantIdAndCustomerId(TenantId tenantId, CustomerId customerId, List<ActionType> actionTypes, TimePageLink pageLink) { |
39 | - return new PageData(); | |
39 | + return new PageData<>(); | |
40 | 40 | } |
41 | 41 | |
42 | 42 | @Override |
43 | 43 | public PageData<AuditLog> findAuditLogsByTenantIdAndUserId(TenantId tenantId, UserId userId, List<ActionType> actionTypes, TimePageLink pageLink) { |
44 | - return new PageData(); | |
44 | + return new PageData<>(); | |
45 | 45 | } |
46 | 46 | |
47 | 47 | @Override |
48 | 48 | public PageData<AuditLog> findAuditLogsByTenantIdAndEntityId(TenantId tenantId, EntityId entityId, List<ActionType> actionTypes, TimePageLink pageLink) { |
49 | - return new PageData(); | |
49 | + return new PageData<>(); | |
50 | 50 | } |
51 | 51 | |
52 | 52 | @Override |
53 | 53 | public PageData<AuditLog> findAuditLogsByTenantId(TenantId tenantId, List<ActionType> actionTypes, TimePageLink pageLink) { |
54 | - return new PageData(); | |
54 | + return new PageData<>(); | |
55 | 55 | } |
56 | 56 | |
57 | 57 | @Override | ... | ... |
... | ... | @@ -275,6 +275,7 @@ public class EntityViewServiceImpl extends AbstractEntityService implements Enti |
275 | 275 | tenantIdAndEntityId.add(entityId); |
276 | 276 | |
277 | 277 | Cache cache = cacheManager.getCache(ENTITY_VIEW_CACHE); |
278 | + @SuppressWarnings("unchecked") | |
278 | 279 | List<EntityView> fromCache = cache.get(tenantIdAndEntityId, List.class); |
279 | 280 | if (fromCache != null) { |
280 | 281 | return Futures.immediateFuture(fromCache); | ... | ... |
... | ... | @@ -53,7 +53,7 @@ public class HybridClientRegistrationRepository implements ClientRegistrationRep |
53 | 53 | .userNameAttributeName(localClientRegistration.getUserNameAttributeName()) |
54 | 54 | .jwkSetUri(localClientRegistration.getJwkSetUri()) |
55 | 55 | .clientAuthenticationMethod(new ClientAuthenticationMethod(localClientRegistration.getClientAuthenticationMethod())) |
56 | - .redirectUriTemplate(defaultRedirectUriTemplate) | |
56 | + .redirectUri(defaultRedirectUriTemplate) | |
57 | 57 | .build(); |
58 | 58 | } |
59 | 59 | } | ... | ... |
... | ... | @@ -301,6 +301,7 @@ public class BaseRelationService implements RelationService { |
301 | 301 | fromAndTypeGroup.add(EntitySearchDirection.FROM.name()); |
302 | 302 | |
303 | 303 | Cache cache = cacheManager.getCache(RELATIONS_CACHE); |
304 | + @SuppressWarnings("unchecked") | |
304 | 305 | List<EntityRelation> fromCache = cache.get(fromAndTypeGroup, List.class); |
305 | 306 | if (fromCache != null) { |
306 | 307 | return Futures.immediateFuture(fromCache); |
... | ... | @@ -382,6 +383,7 @@ public class BaseRelationService implements RelationService { |
382 | 383 | toAndTypeGroup.add(EntitySearchDirection.TO.name()); |
383 | 384 | |
384 | 385 | Cache cache = cacheManager.getCache(RELATIONS_CACHE); |
386 | + @SuppressWarnings("unchecked") | |
385 | 387 | List<EntityRelation> fromCache = cache.get(toAndTypeGroup, List.class); |
386 | 388 | if (fromCache != null) { |
387 | 389 | return Futures.immediateFuture(fromCache); | ... | ... |
... | ... | @@ -45,12 +45,12 @@ public class JpaDashboardInfoDao extends JpaAbstractSearchTextDao<DashboardInfoE |
45 | 45 | private DashboardInfoRepository dashboardInfoRepository; |
46 | 46 | |
47 | 47 | @Override |
48 | - protected Class getEntityClass() { | |
48 | + protected Class<DashboardInfoEntity> getEntityClass() { | |
49 | 49 | return DashboardInfoEntity.class; |
50 | 50 | } |
51 | 51 | |
52 | 52 | @Override |
53 | - protected CrudRepository getCrudRepository() { | |
53 | + protected CrudRepository<DashboardInfoEntity, UUID> getCrudRepository() { | |
54 | 54 | return dashboardInfoRepository; |
55 | 55 | } |
56 | 56 | ... | ... |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.sql.device; |
17 | 17 | |
18 | -import org.apache.commons.lang.StringUtils; | |
18 | +import org.apache.commons.lang3.StringUtils; | |
19 | 19 | import org.springframework.beans.factory.annotation.Autowired; |
20 | 20 | import org.springframework.data.repository.CrudRepository; |
21 | 21 | import org.springframework.stereotype.Component; | ... | ... |
... | ... | @@ -39,12 +39,12 @@ public class JpaRuleChainDao extends JpaAbstractSearchTextDao<RuleChainEntity, R |
39 | 39 | private RuleChainRepository ruleChainRepository; |
40 | 40 | |
41 | 41 | @Override |
42 | - protected Class getEntityClass() { | |
42 | + protected Class<RuleChainEntity> getEntityClass() { | |
43 | 43 | return RuleChainEntity.class; |
44 | 44 | } |
45 | 45 | |
46 | 46 | @Override |
47 | - protected CrudRepository getCrudRepository() { | |
47 | + protected CrudRepository<RuleChainEntity, UUID> getCrudRepository() { | |
48 | 48 | return ruleChainRepository; |
49 | 49 | } |
50 | 50 | ... | ... |
... | ... | @@ -24,6 +24,8 @@ import org.thingsboard.server.dao.model.sql.RuleNodeEntity; |
24 | 24 | import org.thingsboard.server.dao.rule.RuleNodeDao; |
25 | 25 | import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao; |
26 | 26 | |
27 | +import java.util.UUID; | |
28 | + | |
27 | 29 | @Slf4j |
28 | 30 | @Component |
29 | 31 | public class JpaRuleNodeDao extends JpaAbstractSearchTextDao<RuleNodeEntity, RuleNode> implements RuleNodeDao { |
... | ... | @@ -32,12 +34,12 @@ public class JpaRuleNodeDao extends JpaAbstractSearchTextDao<RuleNodeEntity, Rul |
32 | 34 | private RuleNodeRepository ruleNodeRepository; |
33 | 35 | |
34 | 36 | @Override |
35 | - protected Class getEntityClass() { | |
37 | + protected Class<RuleNodeEntity> getEntityClass() { | |
36 | 38 | return RuleNodeEntity.class; |
37 | 39 | } |
38 | 40 | |
39 | 41 | @Override |
40 | - protected CrudRepository getCrudRepository() { | |
42 | + protected CrudRepository<RuleNodeEntity, UUID> getCrudRepository() { | |
41 | 43 | return ruleNodeRepository; |
42 | 44 | } |
43 | 45 | ... | ... |
... | ... | @@ -39,12 +39,12 @@ public class JpaRuleNodeStateDao extends JpaAbstractDao<RuleNodeStateEntity, Rul |
39 | 39 | private RuleNodeStateRepository ruleNodeStateRepository; |
40 | 40 | |
41 | 41 | @Override |
42 | - protected Class getEntityClass() { | |
42 | + protected Class<RuleNodeStateEntity> getEntityClass() { | |
43 | 43 | return RuleNodeStateEntity.class; |
44 | 44 | } |
45 | 45 | |
46 | 46 | @Override |
47 | - protected CrudRepository getCrudRepository() { | |
47 | + protected CrudRepository<RuleNodeStateEntity, UUID> getCrudRepository() { | |
48 | 48 | return ruleNodeStateRepository; |
49 | 49 | } |
50 | 50 | ... | ... |
... | ... | @@ -18,6 +18,8 @@ package org.thingsboard.server.dao.sql.rule; |
18 | 18 | import org.springframework.data.repository.CrudRepository; |
19 | 19 | import org.thingsboard.server.dao.model.sql.RuleNodeEntity; |
20 | 20 | |
21 | -public interface RuleNodeRepository extends CrudRepository<RuleNodeEntity, String> { | |
21 | +import java.util.UUID; | |
22 | + | |
23 | +public interface RuleNodeRepository extends CrudRepository<RuleNodeEntity, UUID> { | |
22 | 24 | |
23 | 25 | } | ... | ... |
... | ... | @@ -32,6 +32,7 @@ import lombok.extern.slf4j.Slf4j; |
32 | 32 | import org.springframework.beans.factory.annotation.Autowired; |
33 | 33 | import org.springframework.beans.factory.annotation.Value; |
34 | 34 | import org.springframework.core.env.Environment; |
35 | +import org.springframework.core.env.Profiles; | |
35 | 36 | import org.springframework.stereotype.Component; |
36 | 37 | import org.thingsboard.server.common.data.id.EntityId; |
37 | 38 | import org.thingsboard.server.common.data.id.TenantId; |
... | ... | @@ -108,7 +109,7 @@ public class CassandraBaseTimeseriesDao extends AbstractCassandraBaseTimeseriesD |
108 | 109 | private PreparedStatement deletePartitionStmt; |
109 | 110 | |
110 | 111 | private boolean isInstall() { |
111 | - return environment.acceptsProfiles("install"); | |
112 | + return environment.acceptsProfiles(Profiles.of("install")); | |
112 | 113 | } |
113 | 114 | |
114 | 115 | @PostConstruct | ... | ... |
... | ... | @@ -15,8 +15,8 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.user; |
17 | 17 | |
18 | +import com.fasterxml.jackson.core.type.TypeReference; | |
18 | 19 | import com.fasterxml.jackson.databind.JsonNode; |
19 | -import com.fasterxml.jackson.databind.ObjectMapper; | |
20 | 20 | import com.fasterxml.jackson.databind.node.ObjectNode; |
21 | 21 | import com.google.common.util.concurrent.ListenableFuture; |
22 | 22 | import lombok.extern.slf4j.Slf4j; |
... | ... | @@ -48,6 +48,7 @@ import org.thingsboard.server.dao.service.DataValidator; |
48 | 48 | import org.thingsboard.server.dao.service.PaginatedRemover; |
49 | 49 | import org.thingsboard.server.dao.tenant.TbTenantProfileCache; |
50 | 50 | import org.thingsboard.server.dao.tenant.TenantDao; |
51 | +import org.thingsboard.server.dao.util.mapping.JacksonUtil; | |
51 | 52 | |
52 | 53 | import java.util.HashMap; |
53 | 54 | import java.util.Map; |
... | ... | @@ -71,8 +72,6 @@ public class UserServiceImpl extends AbstractEntityService implements UserServic |
71 | 72 | |
72 | 73 | private static final String USER_CREDENTIALS_ENABLED = "userCredentialsEnabled"; |
73 | 74 | |
74 | - private static final ObjectMapper objectMapper = new ObjectMapper(); | |
75 | - | |
76 | 75 | @Value("${security.user_login_case_sensitive:true}") |
77 | 76 | private boolean userLoginCaseSensitive; |
78 | 77 | |
... | ... | @@ -279,7 +278,7 @@ public class UserServiceImpl extends AbstractEntityService implements UserServic |
279 | 278 | User user = findUserById(tenantId, userId); |
280 | 279 | JsonNode additionalInfo = user.getAdditionalInfo(); |
281 | 280 | if (!(additionalInfo instanceof ObjectNode)) { |
282 | - additionalInfo = objectMapper.createObjectNode(); | |
281 | + additionalInfo = JacksonUtil.newObjectNode(); | |
283 | 282 | } |
284 | 283 | ((ObjectNode) additionalInfo).put(USER_CREDENTIALS_ENABLED, enabled); |
285 | 284 | user.setAdditionalInfo(additionalInfo); |
... | ... | @@ -302,7 +301,7 @@ public class UserServiceImpl extends AbstractEntityService implements UserServic |
302 | 301 | private void setLastLoginTs(User user) { |
303 | 302 | JsonNode additionalInfo = user.getAdditionalInfo(); |
304 | 303 | if (!(additionalInfo instanceof ObjectNode)) { |
305 | - additionalInfo = objectMapper.createObjectNode(); | |
304 | + additionalInfo = JacksonUtil.newObjectNode(); | |
306 | 305 | } |
307 | 306 | ((ObjectNode) additionalInfo).put(LAST_LOGIN_TS, System.currentTimeMillis()); |
308 | 307 | user.setAdditionalInfo(additionalInfo); |
... | ... | @@ -311,7 +310,7 @@ public class UserServiceImpl extends AbstractEntityService implements UserServic |
311 | 310 | private void resetFailedLoginAttempts(User user) { |
312 | 311 | JsonNode additionalInfo = user.getAdditionalInfo(); |
313 | 312 | if (!(additionalInfo instanceof ObjectNode)) { |
314 | - additionalInfo = objectMapper.createObjectNode(); | |
313 | + additionalInfo = JacksonUtil.newObjectNode(); | |
315 | 314 | } |
316 | 315 | ((ObjectNode) additionalInfo).put(FAILED_LOGIN_ATTEMPTS, 0); |
317 | 316 | user.setAdditionalInfo(additionalInfo); |
... | ... | @@ -329,7 +328,7 @@ public class UserServiceImpl extends AbstractEntityService implements UserServic |
329 | 328 | private int increaseFailedLoginAttempts(User user) { |
330 | 329 | JsonNode additionalInfo = user.getAdditionalInfo(); |
331 | 330 | if (!(additionalInfo instanceof ObjectNode)) { |
332 | - additionalInfo = objectMapper.createObjectNode(); | |
331 | + additionalInfo = JacksonUtil.newObjectNode(); | |
333 | 332 | } |
334 | 333 | int failedLoginAttempts = 0; |
335 | 334 | if (additionalInfo.has(FAILED_LOGIN_ATTEMPTS)) { |
... | ... | @@ -353,26 +352,30 @@ public class UserServiceImpl extends AbstractEntityService implements UserServic |
353 | 352 | private void updatePasswordHistory(User user, UserCredentials userCredentials) { |
354 | 353 | JsonNode additionalInfo = user.getAdditionalInfo(); |
355 | 354 | if (!(additionalInfo instanceof ObjectNode)) { |
356 | - additionalInfo = objectMapper.createObjectNode(); | |
355 | + additionalInfo = JacksonUtil.newObjectNode(); | |
357 | 356 | } |
357 | + Map<String, String> userPasswordHistoryMap = null; | |
358 | + JsonNode userPasswordHistoryJson; | |
358 | 359 | if (additionalInfo.has(USER_PASSWORD_HISTORY)) { |
359 | - JsonNode userPasswordHistoryJson = additionalInfo.get(USER_PASSWORD_HISTORY); | |
360 | - Map<String, String> userPasswordHistoryMap = objectMapper.convertValue(userPasswordHistoryJson, Map.class); | |
360 | + userPasswordHistoryJson = additionalInfo.get(USER_PASSWORD_HISTORY); | |
361 | + userPasswordHistoryMap = JacksonUtil.convertValue(userPasswordHistoryJson, new TypeReference<>(){}); | |
362 | + } | |
363 | + if (userPasswordHistoryMap != null) { | |
361 | 364 | userPasswordHistoryMap.put(Long.toString(System.currentTimeMillis()), userCredentials.getPassword()); |
362 | - userPasswordHistoryJson = objectMapper.valueToTree(userPasswordHistoryMap); | |
365 | + userPasswordHistoryJson = JacksonUtil.valueToTree(userPasswordHistoryMap); | |
363 | 366 | ((ObjectNode) additionalInfo).replace(USER_PASSWORD_HISTORY, userPasswordHistoryJson); |
364 | 367 | } else { |
365 | - Map<String, String> userPasswordHistoryMap = new HashMap<>(); | |
368 | + userPasswordHistoryMap = new HashMap<>(); | |
366 | 369 | userPasswordHistoryMap.put(Long.toString(System.currentTimeMillis()), userCredentials.getPassword()); |
367 | - JsonNode userPasswordHistoryJson = objectMapper.valueToTree(userPasswordHistoryMap); | |
370 | + userPasswordHistoryJson = JacksonUtil.valueToTree(userPasswordHistoryMap); | |
368 | 371 | ((ObjectNode) additionalInfo).set(USER_PASSWORD_HISTORY, userPasswordHistoryJson); |
369 | 372 | } |
370 | 373 | user.setAdditionalInfo(additionalInfo); |
371 | 374 | saveUser(user); |
372 | 375 | } |
373 | 376 | |
374 | - private DataValidator<User> userValidator = | |
375 | - new DataValidator<User>() { | |
377 | + private final DataValidator<User> userValidator = | |
378 | + new DataValidator<>() { | |
376 | 379 | @Override |
377 | 380 | protected void validateCreate(TenantId tenantId, User user) { |
378 | 381 | if (!user.getTenantId().getId().equals(ModelConstants.NULL_UUID)) { |
... | ... | @@ -452,8 +455,8 @@ public class UserServiceImpl extends AbstractEntityService implements UserServic |
452 | 455 | } |
453 | 456 | }; |
454 | 457 | |
455 | - private DataValidator<UserCredentials> userCredentialsValidator = | |
456 | - new DataValidator<UserCredentials>() { | |
458 | + private final DataValidator<UserCredentials> userCredentialsValidator = | |
459 | + new DataValidator<>() { | |
457 | 460 | |
458 | 461 | @Override |
459 | 462 | protected void validateCreate(TenantId tenantId, UserCredentials userCredentials) { |
... | ... | @@ -484,7 +487,7 @@ public class UserServiceImpl extends AbstractEntityService implements UserServic |
484 | 487 | } |
485 | 488 | }; |
486 | 489 | |
487 | - private PaginatedRemover<TenantId, User> tenantAdminsRemover = new PaginatedRemover<TenantId, User>() { | |
490 | + private final PaginatedRemover<TenantId, User> tenantAdminsRemover = new PaginatedRemover<>() { | |
488 | 491 | @Override |
489 | 492 | protected PageData<User> findEntities(TenantId tenantId, TenantId id, PageLink pageLink) { |
490 | 493 | return userDao.findTenantAdmins(id.getId(), pageLink); |
... | ... | @@ -496,7 +499,7 @@ public class UserServiceImpl extends AbstractEntityService implements UserServic |
496 | 499 | } |
497 | 500 | }; |
498 | 501 | |
499 | - private PaginatedRemover<CustomerId, User> customerUsersRemover = new PaginatedRemover<CustomerId, User>() { | |
502 | + private final PaginatedRemover<CustomerId, User> customerUsersRemover = new PaginatedRemover<>() { | |
500 | 503 | @Override |
501 | 504 | protected PageData<User> findEntities(TenantId tenantId, CustomerId id, PageLink pageLink) { |
502 | 505 | return userDao.findCustomerUsers(tenantId.getId(), id.getId(), pageLink); | ... | ... |
... | ... | @@ -16,6 +16,7 @@ |
16 | 16 | package org.thingsboard.server.dao.util.mapping; |
17 | 17 | |
18 | 18 | import com.fasterxml.jackson.core.JsonProcessingException; |
19 | +import com.fasterxml.jackson.core.type.TypeReference; | |
19 | 20 | import com.fasterxml.jackson.databind.JsonNode; |
20 | 21 | import com.fasterxml.jackson.databind.ObjectMapper; |
21 | 22 | import com.fasterxml.jackson.databind.node.ObjectNode; |
... | ... | @@ -38,6 +39,15 @@ public class JacksonUtil { |
38 | 39 | } |
39 | 40 | } |
40 | 41 | |
42 | + public static <T> T convertValue(Object fromValue, TypeReference<T> toValueTypeRef) { | |
43 | + try { | |
44 | + return fromValue != null ? OBJECT_MAPPER.convertValue(fromValue, toValueTypeRef) : null; | |
45 | + } catch (IllegalArgumentException e) { | |
46 | + throw new IllegalArgumentException("The given object value: " | |
47 | + + fromValue + " cannot be converted to " + toValueTypeRef, e); | |
48 | + } | |
49 | + } | |
50 | + | |
41 | 51 | public static <T> T fromString(String string, Class<T> clazz) { |
42 | 52 | try { |
43 | 53 | return string != null ? OBJECT_MAPPER.readValue(string, clazz) : null; |
... | ... | @@ -72,7 +82,9 @@ public class JacksonUtil { |
72 | 82 | } |
73 | 83 | |
74 | 84 | public static <T> T clone(T value) { |
75 | - return fromString(toString(value), (Class<T>) value.getClass()); | |
85 | + @SuppressWarnings("unchecked") | |
86 | + Class<T> valueClass = (Class<T>) value.getClass(); | |
87 | + return fromString(toString(value), valueClass); | |
76 | 88 | } |
77 | 89 | |
78 | 90 | public static <T> JsonNode valueToTree(T value) { | ... | ... |
... | ... | @@ -244,6 +244,7 @@ public class Descriptor |
244 | 244 | * |
245 | 245 | * @return A Descriptor for the SSTable, and the Component remainder. |
246 | 246 | */ |
247 | + @SuppressWarnings("deprecation") | |
247 | 248 | public static Pair<Descriptor, String> fromFilename(File directory, String name, boolean skipComponent) |
248 | 249 | { |
249 | 250 | File parentDirectory = directory != null ? directory : new File("."); |
... | ... | @@ -319,6 +320,7 @@ public class Descriptor |
319 | 320 | component); |
320 | 321 | } |
321 | 322 | |
323 | + @SuppressWarnings("deprecation") | |
322 | 324 | public IMetadataSerializer getMetadataSerializer() |
323 | 325 | { |
324 | 326 | if (version.hasNewStatsFile()) | ... | ... |
1 | +/* | |
2 | + * Licensed to the Apache Software Foundation (ASF) under one | |
3 | + * or more contributor license agreements. See the NOTICE file | |
4 | + * distributed with this work for additional information | |
5 | + * regarding copyright ownership. The ASF licenses this file | |
6 | + * to you under the Apache License, Version 2.0 (the | |
7 | + * "License"); you may not use this file except in compliance | |
8 | + * with the License. You may obtain a copy of the License at | |
9 | + * | |
10 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
11 | + * | |
12 | + * Unless required by applicable law or agreed to in writing, software | |
13 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
15 | + * See the License for the specific language governing permissions and | |
16 | + * limitations under the License. | |
17 | + */ | |
18 | +package org.apache.cassandra.io.util; | |
19 | + | |
20 | +import java.io.*; | |
21 | +import java.nio.ByteBuffer; | |
22 | +import java.nio.channels.FileChannel; | |
23 | +import java.nio.charset.Charset; | |
24 | +import java.nio.charset.StandardCharsets; | |
25 | +import java.nio.file.*; | |
26 | +import java.nio.file.attribute.BasicFileAttributes; | |
27 | +import java.nio.file.attribute.FileAttributeView; | |
28 | +import java.nio.file.attribute.FileStoreAttributeView; | |
29 | +import java.text.DecimalFormat; | |
30 | +import java.util.Arrays; | |
31 | +import java.util.Collections; | |
32 | +import java.util.List; | |
33 | +import java.util.Optional; | |
34 | +import java.util.concurrent.atomic.AtomicReference; | |
35 | +import java.util.function.Consumer; | |
36 | +import java.util.function.Predicate; | |
37 | +import java.util.stream.StreamSupport; | |
38 | + | |
39 | +import org.slf4j.Logger; | |
40 | +import org.slf4j.LoggerFactory; | |
41 | + | |
42 | +import org.apache.cassandra.concurrent.ScheduledExecutors; | |
43 | +import org.apache.cassandra.io.FSError; | |
44 | +import org.apache.cassandra.io.FSErrorHandler; | |
45 | +import org.apache.cassandra.io.FSReadError; | |
46 | +import org.apache.cassandra.io.FSWriteError; | |
47 | +import org.apache.cassandra.io.sstable.CorruptSSTableException; | |
48 | +import org.apache.cassandra.utils.JVMStabilityInspector; | |
49 | + | |
50 | +import static com.google.common.base.Throwables.throwIfUnchecked; | |
51 | +import static org.apache.cassandra.utils.Throwables.maybeFail; | |
52 | +import static org.apache.cassandra.utils.Throwables.merge; | |
53 | + | |
54 | +public final class FileUtils | |
55 | +{ | |
56 | + public static final Charset CHARSET = StandardCharsets.UTF_8; | |
57 | + | |
58 | + private static final Logger logger = LoggerFactory.getLogger(FileUtils.class); | |
59 | + public static final long ONE_KB = 1024; | |
60 | + public static final long ONE_MB = 1024 * ONE_KB; | |
61 | + public static final long ONE_GB = 1024 * ONE_MB; | |
62 | + public static final long ONE_TB = 1024 * ONE_GB; | |
63 | + | |
64 | + private static final DecimalFormat df = new DecimalFormat("#.##"); | |
65 | + public static final boolean isCleanerAvailable = false; | |
66 | + private static final AtomicReference<Optional<FSErrorHandler>> fsErrorHandler = new AtomicReference<>(Optional.empty()); | |
67 | + | |
68 | + public static void createHardLink(String from, String to) | |
69 | + { | |
70 | + createHardLink(new File(from), new File(to)); | |
71 | + } | |
72 | + | |
73 | + public static void createHardLink(File from, File to) | |
74 | + { | |
75 | + if (to.exists()) | |
76 | + throw new RuntimeException("Tried to create duplicate hard link to " + to); | |
77 | + if (!from.exists()) | |
78 | + throw new RuntimeException("Tried to hard link to file that does not exist " + from); | |
79 | + | |
80 | + try | |
81 | + { | |
82 | + Files.createLink(to.toPath(), from.toPath()); | |
83 | + } | |
84 | + catch (IOException e) | |
85 | + { | |
86 | + throw new FSWriteError(e, to); | |
87 | + } | |
88 | + } | |
89 | + | |
90 | + public static File createTempFile(String prefix, String suffix, File directory) | |
91 | + { | |
92 | + try | |
93 | + { | |
94 | + return File.createTempFile(prefix, suffix, directory); | |
95 | + } | |
96 | + catch (IOException e) | |
97 | + { | |
98 | + throw new FSWriteError(e, directory); | |
99 | + } | |
100 | + } | |
101 | + | |
102 | + public static File createTempFile(String prefix, String suffix) | |
103 | + { | |
104 | + return createTempFile(prefix, suffix, new File(System.getProperty("java.io.tmpdir"))); | |
105 | + } | |
106 | + | |
107 | + public static Throwable deleteWithConfirm(String filePath, boolean expect, Throwable accumulate) | |
108 | + { | |
109 | + return deleteWithConfirm(new File(filePath), expect, accumulate); | |
110 | + } | |
111 | + | |
112 | + public static Throwable deleteWithConfirm(File file, boolean expect, Throwable accumulate) | |
113 | + { | |
114 | + boolean exists = file.exists(); | |
115 | + assert exists || !expect : "attempted to delete non-existing file " + file.getName(); | |
116 | + try | |
117 | + { | |
118 | + if (exists) | |
119 | + Files.delete(file.toPath()); | |
120 | + } | |
121 | + catch (Throwable t) | |
122 | + { | |
123 | + try | |
124 | + { | |
125 | + throw new FSWriteError(t, file); | |
126 | + } | |
127 | + catch (Throwable t2) | |
128 | + { | |
129 | + accumulate = merge(accumulate, t2); | |
130 | + } | |
131 | + } | |
132 | + return accumulate; | |
133 | + } | |
134 | + | |
135 | + public static void deleteWithConfirm(String file) | |
136 | + { | |
137 | + deleteWithConfirm(new File(file)); | |
138 | + } | |
139 | + | |
140 | + public static void deleteWithConfirm(File file) | |
141 | + { | |
142 | + maybeFail(deleteWithConfirm(file, true, null)); | |
143 | + } | |
144 | + | |
145 | + public static void renameWithOutConfirm(String from, String to) | |
146 | + { | |
147 | + try | |
148 | + { | |
149 | + atomicMoveWithFallback(new File(from).toPath(), new File(to).toPath()); | |
150 | + } | |
151 | + catch (IOException e) | |
152 | + { | |
153 | + if (logger.isTraceEnabled()) | |
154 | + logger.trace("Could not move file "+from+" to "+to, e); | |
155 | + } | |
156 | + } | |
157 | + | |
158 | + public static void renameWithConfirm(String from, String to) | |
159 | + { | |
160 | + renameWithConfirm(new File(from), new File(to)); | |
161 | + } | |
162 | + | |
163 | + public static void renameWithConfirm(File from, File to) | |
164 | + { | |
165 | + assert from.exists(); | |
166 | + if (logger.isTraceEnabled()) | |
167 | + logger.trace("Renaming {} to {}", from.getPath(), to.getPath()); | |
168 | + // this is not FSWE because usually when we see it it's because we didn't close the file before renaming it, | |
169 | + // and Windows is picky about that. | |
170 | + try | |
171 | + { | |
172 | + atomicMoveWithFallback(from.toPath(), to.toPath()); | |
173 | + } | |
174 | + catch (IOException e) | |
175 | + { | |
176 | + throw new RuntimeException(String.format("Failed to rename %s to %s", from.getPath(), to.getPath()), e); | |
177 | + } | |
178 | + } | |
179 | + | |
180 | + /** | |
181 | + * Move a file atomically, if it fails, it falls back to a non-atomic operation | |
182 | + * @param from | |
183 | + * @param to | |
184 | + * @throws IOException | |
185 | + */ | |
186 | + private static void atomicMoveWithFallback(Path from, Path to) throws IOException | |
187 | + { | |
188 | + try | |
189 | + { | |
190 | + Files.move(from, to, StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.ATOMIC_MOVE); | |
191 | + } | |
192 | + catch (AtomicMoveNotSupportedException e) | |
193 | + { | |
194 | + logger.trace("Could not do an atomic move", e); | |
195 | + Files.move(from, to, StandardCopyOption.REPLACE_EXISTING); | |
196 | + } | |
197 | + | |
198 | + } | |
199 | + public static void truncate(String path, long size) | |
200 | + { | |
201 | + try(FileChannel channel = FileChannel.open(Paths.get(path), StandardOpenOption.READ, StandardOpenOption.WRITE)) | |
202 | + { | |
203 | + channel.truncate(size); | |
204 | + } | |
205 | + catch (IOException e) | |
206 | + { | |
207 | + throw new RuntimeException(e); | |
208 | + } | |
209 | + } | |
210 | + | |
211 | + public static void closeQuietly(Closeable c) | |
212 | + { | |
213 | + try | |
214 | + { | |
215 | + if (c != null) | |
216 | + c.close(); | |
217 | + } | |
218 | + catch (Exception e) | |
219 | + { | |
220 | + logger.warn("Failed closing {}", c, e); | |
221 | + } | |
222 | + } | |
223 | + | |
224 | + public static void closeQuietly(AutoCloseable c) | |
225 | + { | |
226 | + try | |
227 | + { | |
228 | + if (c != null) | |
229 | + c.close(); | |
230 | + } | |
231 | + catch (Exception e) | |
232 | + { | |
233 | + logger.warn("Failed closing {}", c, e); | |
234 | + } | |
235 | + } | |
236 | + | |
237 | + public static void close(Closeable... cs) throws IOException | |
238 | + { | |
239 | + close(Arrays.asList(cs)); | |
240 | + } | |
241 | + | |
242 | + public static void close(Iterable<? extends Closeable> cs) throws IOException | |
243 | + { | |
244 | + Throwable e = null; | |
245 | + for (Closeable c : cs) | |
246 | + { | |
247 | + try | |
248 | + { | |
249 | + if (c != null) | |
250 | + c.close(); | |
251 | + } | |
252 | + catch (Throwable ex) | |
253 | + { | |
254 | + if (e == null) e = ex; | |
255 | + else e.addSuppressed(ex); | |
256 | + logger.warn("Failed closing stream {}", c, ex); | |
257 | + } | |
258 | + } | |
259 | + maybeFail(e, IOException.class); | |
260 | + } | |
261 | + | |
262 | + public static void closeQuietly(Iterable<? extends AutoCloseable> cs) | |
263 | + { | |
264 | + for (AutoCloseable c : cs) | |
265 | + { | |
266 | + try | |
267 | + { | |
268 | + if (c != null) | |
269 | + c.close(); | |
270 | + } | |
271 | + catch (Exception ex) | |
272 | + { | |
273 | + logger.warn("Failed closing {}", c, ex); | |
274 | + } | |
275 | + } | |
276 | + } | |
277 | + | |
278 | + public static String getCanonicalPath(String filename) | |
279 | + { | |
280 | + try | |
281 | + { | |
282 | + return new File(filename).getCanonicalPath(); | |
283 | + } | |
284 | + catch (IOException e) | |
285 | + { | |
286 | + throw new FSReadError(e, filename); | |
287 | + } | |
288 | + } | |
289 | + | |
290 | + public static String getCanonicalPath(File file) | |
291 | + { | |
292 | + try | |
293 | + { | |
294 | + return file.getCanonicalPath(); | |
295 | + } | |
296 | + catch (IOException e) | |
297 | + { | |
298 | + throw new FSReadError(e, file); | |
299 | + } | |
300 | + } | |
301 | + | |
302 | + /** Return true if file is contained in folder */ | |
303 | + public static boolean isContained(File folder, File file) | |
304 | + { | |
305 | + Path folderPath = Paths.get(getCanonicalPath(folder)); | |
306 | + Path filePath = Paths.get(getCanonicalPath(file)); | |
307 | + | |
308 | + return filePath.startsWith(folderPath); | |
309 | + } | |
310 | + | |
311 | + /** Convert absolute path into a path relative to the base path */ | |
312 | + public static String getRelativePath(String basePath, String path) | |
313 | + { | |
314 | + try | |
315 | + { | |
316 | + return Paths.get(basePath).relativize(Paths.get(path)).toString(); | |
317 | + } | |
318 | + catch(Exception ex) | |
319 | + { | |
320 | + String absDataPath = FileUtils.getCanonicalPath(basePath); | |
321 | + return Paths.get(absDataPath).relativize(Paths.get(path)).toString(); | |
322 | + } | |
323 | + } | |
324 | + | |
325 | + public static void clean(ByteBuffer buffer) | |
326 | + { | |
327 | + if (buffer == null) | |
328 | + return; | |
329 | + } | |
330 | + | |
331 | + public static void createDirectory(String directory) | |
332 | + { | |
333 | + createDirectory(new File(directory)); | |
334 | + } | |
335 | + | |
336 | + public static void createDirectory(File directory) | |
337 | + { | |
338 | + if (!directory.exists()) | |
339 | + { | |
340 | + if (!directory.mkdirs()) | |
341 | + throw new FSWriteError(new IOException("Failed to mkdirs " + directory), directory); | |
342 | + } | |
343 | + } | |
344 | + | |
345 | + public static boolean delete(String file) | |
346 | + { | |
347 | + File f = new File(file); | |
348 | + return f.delete(); | |
349 | + } | |
350 | + | |
351 | + public static void delete(File... files) | |
352 | + { | |
353 | + if (files == null) | |
354 | + { | |
355 | + // CASSANDRA-13389: some callers use Files.listFiles() which, on error, silently returns null | |
356 | + logger.debug("Received null list of files to delete"); | |
357 | + return; | |
358 | + } | |
359 | + | |
360 | + for ( File file : files ) | |
361 | + { | |
362 | + file.delete(); | |
363 | + } | |
364 | + } | |
365 | + | |
366 | + public static void deleteAsync(final String file) | |
367 | + { | |
368 | + Runnable runnable = new Runnable() | |
369 | + { | |
370 | + public void run() | |
371 | + { | |
372 | + deleteWithConfirm(new File(file)); | |
373 | + } | |
374 | + }; | |
375 | + ScheduledExecutors.nonPeriodicTasks.execute(runnable); | |
376 | + } | |
377 | + | |
378 | + public static void visitDirectory(Path dir, Predicate<? super File> filter, Consumer<? super File> consumer) | |
379 | + { | |
380 | + try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) | |
381 | + { | |
382 | + StreamSupport.stream(stream.spliterator(), false) | |
383 | + .map(Path::toFile) | |
384 | + // stream directories are weakly consistent so we always check if the file still exists | |
385 | + .filter(f -> f.exists() && (filter == null || filter.test(f))) | |
386 | + .forEach(consumer); | |
387 | + } | |
388 | + catch (IOException|DirectoryIteratorException ex) | |
389 | + { | |
390 | + logger.error("Failed to list files in {} with exception: {}", dir, ex.getMessage(), ex); | |
391 | + } | |
392 | + } | |
393 | + | |
394 | + public static String stringifyFileSize(double value) | |
395 | + { | |
396 | + double d; | |
397 | + if ( value >= ONE_TB ) | |
398 | + { | |
399 | + d = value / ONE_TB; | |
400 | + String val = df.format(d); | |
401 | + return val + " TiB"; | |
402 | + } | |
403 | + else if ( value >= ONE_GB ) | |
404 | + { | |
405 | + d = value / ONE_GB; | |
406 | + String val = df.format(d); | |
407 | + return val + " GiB"; | |
408 | + } | |
409 | + else if ( value >= ONE_MB ) | |
410 | + { | |
411 | + d = value / ONE_MB; | |
412 | + String val = df.format(d); | |
413 | + return val + " MiB"; | |
414 | + } | |
415 | + else if ( value >= ONE_KB ) | |
416 | + { | |
417 | + d = value / ONE_KB; | |
418 | + String val = df.format(d); | |
419 | + return val + " KiB"; | |
420 | + } | |
421 | + else | |
422 | + { | |
423 | + String val = df.format(value); | |
424 | + return val + " bytes"; | |
425 | + } | |
426 | + } | |
427 | + | |
428 | + /** | |
429 | + * Deletes all files and subdirectories under "dir". | |
430 | + * @param dir Directory to be deleted | |
431 | + * @throws FSWriteError if any part of the tree cannot be deleted | |
432 | + */ | |
433 | + public static void deleteRecursive(File dir) | |
434 | + { | |
435 | + if (dir.isDirectory()) | |
436 | + { | |
437 | + String[] children = dir.list(); | |
438 | + for (String child : children) | |
439 | + deleteRecursive(new File(dir, child)); | |
440 | + } | |
441 | + | |
442 | + // The directory is now empty so now it can be smoked | |
443 | + deleteWithConfirm(dir); | |
444 | + } | |
445 | + | |
446 | + /** | |
447 | + * Schedules deletion of all file and subdirectories under "dir" on JVM shutdown. | |
448 | + * @param dir Directory to be deleted | |
449 | + */ | |
450 | + public static void deleteRecursiveOnExit(File dir) | |
451 | + { | |
452 | + if (dir.isDirectory()) | |
453 | + { | |
454 | + String[] children = dir.list(); | |
455 | + for (String child : children) | |
456 | + deleteRecursiveOnExit(new File(dir, child)); | |
457 | + } | |
458 | + | |
459 | + logger.trace("Scheduling deferred deletion of file: {}", dir); | |
460 | + dir.deleteOnExit(); | |
461 | + } | |
462 | + | |
463 | + public static void handleCorruptSSTable(CorruptSSTableException e) | |
464 | + { | |
465 | + fsErrorHandler.get().ifPresent(handler -> handler.handleCorruptSSTable(e)); | |
466 | + } | |
467 | + | |
468 | + public static void handleFSError(FSError e) | |
469 | + { | |
470 | + fsErrorHandler.get().ifPresent(handler -> handler.handleFSError(e)); | |
471 | + } | |
472 | + | |
473 | + /** | |
474 | + * handleFSErrorAndPropagate will invoke the disk failure policy error handler, | |
475 | + * which may or may not stop the daemon or transports. However, if we don't exit, | |
476 | + * we still want to propagate the exception to the caller in case they have custom | |
477 | + * exception handling | |
478 | + * | |
479 | + * @param e A filesystem error | |
480 | + */ | |
481 | + public static void handleFSErrorAndPropagate(FSError e) | |
482 | + { | |
483 | + JVMStabilityInspector.inspectThrowable(e); | |
484 | + throwIfUnchecked(e); | |
485 | + throw new RuntimeException(e); | |
486 | + } | |
487 | + | |
488 | + /** | |
489 | + * Get the size of a directory in bytes | |
490 | + * @param folder The directory for which we need size. | |
491 | + * @return The size of the directory | |
492 | + */ | |
493 | + public static long folderSize(File folder) | |
494 | + { | |
495 | + final long [] sizeArr = {0L}; | |
496 | + try | |
497 | + { | |
498 | + Files.walkFileTree(folder.toPath(), new SimpleFileVisitor<Path>() | |
499 | + { | |
500 | + @Override | |
501 | + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) | |
502 | + { | |
503 | + sizeArr[0] += attrs.size(); | |
504 | + return FileVisitResult.CONTINUE; | |
505 | + } | |
506 | + }); | |
507 | + } | |
508 | + catch (IOException e) | |
509 | + { | |
510 | + logger.error("Error while getting {} folder size. {}", folder, e); | |
511 | + } | |
512 | + return sizeArr[0]; | |
513 | + } | |
514 | + | |
515 | + public static void copyTo(DataInput in, OutputStream out, int length) throws IOException | |
516 | + { | |
517 | + byte[] buffer = new byte[64 * 1024]; | |
518 | + int copiedBytes = 0; | |
519 | + | |
520 | + while (copiedBytes + buffer.length < length) | |
521 | + { | |
522 | + in.readFully(buffer); | |
523 | + out.write(buffer); | |
524 | + copiedBytes += buffer.length; | |
525 | + } | |
526 | + | |
527 | + if (copiedBytes < length) | |
528 | + { | |
529 | + int left = length - copiedBytes; | |
530 | + in.readFully(buffer, 0, left); | |
531 | + out.write(buffer, 0, left); | |
532 | + } | |
533 | + } | |
534 | + | |
535 | + public static boolean isSubDirectory(File parent, File child) throws IOException | |
536 | + { | |
537 | + parent = parent.getCanonicalFile(); | |
538 | + child = child.getCanonicalFile(); | |
539 | + | |
540 | + File toCheck = child; | |
541 | + while (toCheck != null) | |
542 | + { | |
543 | + if (parent.equals(toCheck)) | |
544 | + return true; | |
545 | + toCheck = toCheck.getParentFile(); | |
546 | + } | |
547 | + return false; | |
548 | + } | |
549 | + | |
550 | + public static void append(File file, String ... lines) | |
551 | + { | |
552 | + if (file.exists()) | |
553 | + write(file, Arrays.asList(lines), StandardOpenOption.APPEND); | |
554 | + else | |
555 | + write(file, Arrays.asList(lines), StandardOpenOption.CREATE); | |
556 | + } | |
557 | + | |
558 | + public static void appendAndSync(File file, String ... lines) | |
559 | + { | |
560 | + if (file.exists()) | |
561 | + write(file, Arrays.asList(lines), StandardOpenOption.APPEND, StandardOpenOption.SYNC); | |
562 | + else | |
563 | + write(file, Arrays.asList(lines), StandardOpenOption.CREATE, StandardOpenOption.SYNC); | |
564 | + } | |
565 | + | |
566 | + public static void replace(File file, String ... lines) | |
567 | + { | |
568 | + write(file, Arrays.asList(lines), StandardOpenOption.TRUNCATE_EXISTING); | |
569 | + } | |
570 | + | |
571 | + public static void write(File file, List<String> lines, StandardOpenOption ... options) | |
572 | + { | |
573 | + try | |
574 | + { | |
575 | + Files.write(file.toPath(), | |
576 | + lines, | |
577 | + CHARSET, | |
578 | + options); | |
579 | + } | |
580 | + catch (IOException ex) | |
581 | + { | |
582 | + throw new RuntimeException(ex); | |
583 | + } | |
584 | + } | |
585 | + | |
586 | + public static List<String> readLines(File file) | |
587 | + { | |
588 | + try | |
589 | + { | |
590 | + return Files.readAllLines(file.toPath(), CHARSET); | |
591 | + } | |
592 | + catch (IOException ex) | |
593 | + { | |
594 | + if (ex instanceof NoSuchFileException) | |
595 | + return Collections.emptyList(); | |
596 | + | |
597 | + throw new RuntimeException(ex); | |
598 | + } | |
599 | + } | |
600 | + | |
601 | + public static void setFSErrorHandler(FSErrorHandler handler) | |
602 | + { | |
603 | + fsErrorHandler.getAndSet(Optional.ofNullable(handler)); | |
604 | + } | |
605 | + | |
606 | + /** | |
607 | + * Returns the size of the specified partition. | |
608 | + * <p>This method handles large file system by returning {@code Long.MAX_VALUE} if the size overflow. | |
609 | + * See <a href='https://bugs.openjdk.java.net/browse/JDK-8179320'>JDK-8179320</a> for more information.</p> | |
610 | + * | |
611 | + * @param file the partition | |
612 | + * @return the size, in bytes, of the partition or {@code 0L} if the abstract pathname does not name a partition | |
613 | + */ | |
614 | + public static long getTotalSpace(File file) | |
615 | + { | |
616 | + return handleLargeFileSystem(file.getTotalSpace()); | |
617 | + } | |
618 | + | |
619 | + /** | |
620 | + * Returns the number of unallocated bytes on the specified partition. | |
621 | + * <p>This method handles large file system by returning {@code Long.MAX_VALUE} if the number of unallocated bytes | |
622 | + * overflow. See <a href='https://bugs.openjdk.java.net/browse/JDK-8179320'>JDK-8179320</a> for more information</p> | |
623 | + * | |
624 | + * @param file the partition | |
625 | + * @return the number of unallocated bytes on the partition or {@code 0L} | |
626 | + * if the abstract pathname does not name a partition. | |
627 | + */ | |
628 | + public static long getFreeSpace(File file) | |
629 | + { | |
630 | + return handleLargeFileSystem(file.getFreeSpace()); | |
631 | + } | |
632 | + | |
633 | + /** | |
634 | + * Returns the number of available bytes on the specified partition. | |
635 | + * <p>This method handles large file system by returning {@code Long.MAX_VALUE} if the number of available bytes | |
636 | + * overflow. See <a href='https://bugs.openjdk.java.net/browse/JDK-8179320'>JDK-8179320</a> for more information</p> | |
637 | + * | |
638 | + * @param file the partition | |
639 | + * @return the number of available bytes on the partition or {@code 0L} | |
640 | + * if the abstract pathname does not name a partition. | |
641 | + */ | |
642 | + public static long getUsableSpace(File file) | |
643 | + { | |
644 | + return handleLargeFileSystem(file.getUsableSpace()); | |
645 | + } | |
646 | + | |
647 | + /** | |
648 | + * Returns the {@link FileStore} representing the file store where a file | |
649 | + * is located. This {@link FileStore} handles large file system by returning {@code Long.MAX_VALUE} | |
650 | + * from {@code FileStore#getTotalSpace()}, {@code FileStore#getUnallocatedSpace()} and {@code FileStore#getUsableSpace()} | |
651 | + * it the value is bigger than {@code Long.MAX_VALUE}. See <a href='https://bugs.openjdk.java.net/browse/JDK-8162520'>JDK-8162520</a> | |
652 | + * for more information. | |
653 | + * | |
654 | + * @param path the path to the file | |
655 | + * @return the file store where the file is stored | |
656 | + */ | |
657 | + public static FileStore getFileStore(Path path) throws IOException | |
658 | + { | |
659 | + return new SafeFileStore(Files.getFileStore(path)); | |
660 | + } | |
661 | + | |
662 | + /** | |
663 | + * Handle large file system by returning {@code Long.MAX_VALUE} when the size overflows. | |
664 | + * @param size returned by the Java's FileStore methods | |
665 | + * @return the size or {@code Long.MAX_VALUE} if the size was bigger than {@code Long.MAX_VALUE} | |
666 | + */ | |
667 | + private static long handleLargeFileSystem(long size) | |
668 | + { | |
669 | + return size < 0 ? Long.MAX_VALUE : size; | |
670 | + } | |
671 | + | |
672 | + /** | |
673 | + * Private constructor as the class contains only static methods. | |
674 | + */ | |
675 | + private FileUtils() | |
676 | + { | |
677 | + } | |
678 | + | |
679 | + /** | |
680 | + * FileStore decorator used to safely handle large file system. | |
681 | + * | |
682 | + * <p>Java's FileStore methods (getTotalSpace/getUnallocatedSpace/getUsableSpace) are limited to reporting bytes as | |
683 | + * signed long (2^63-1), if the filesystem is any bigger, then the size overflows. {@code SafeFileStore} will | |
684 | + * return {@code Long.MAX_VALUE} if the size overflow.</p> | |
685 | + * | |
686 | + * @see https://bugs.openjdk.java.net/browse/JDK-8162520. | |
687 | + */ | |
688 | + private static final class SafeFileStore extends FileStore | |
689 | + { | |
690 | + /** | |
691 | + * The decorated {@code FileStore} | |
692 | + */ | |
693 | + private final FileStore fileStore; | |
694 | + | |
695 | + public SafeFileStore(FileStore fileStore) | |
696 | + { | |
697 | + this.fileStore = fileStore; | |
698 | + } | |
699 | + | |
700 | + @Override | |
701 | + public String name() | |
702 | + { | |
703 | + return fileStore.name(); | |
704 | + } | |
705 | + | |
706 | + @Override | |
707 | + public String type() | |
708 | + { | |
709 | + return fileStore.type(); | |
710 | + } | |
711 | + | |
712 | + @Override | |
713 | + public boolean isReadOnly() | |
714 | + { | |
715 | + return fileStore.isReadOnly(); | |
716 | + } | |
717 | + | |
718 | + @Override | |
719 | + public long getTotalSpace() throws IOException | |
720 | + { | |
721 | + return handleLargeFileSystem(fileStore.getTotalSpace()); | |
722 | + } | |
723 | + | |
724 | + @Override | |
725 | + public long getUsableSpace() throws IOException | |
726 | + { | |
727 | + return handleLargeFileSystem(fileStore.getUsableSpace()); | |
728 | + } | |
729 | + | |
730 | + @Override | |
731 | + public long getUnallocatedSpace() throws IOException | |
732 | + { | |
733 | + return handleLargeFileSystem(fileStore.getUnallocatedSpace()); | |
734 | + } | |
735 | + | |
736 | + @Override | |
737 | + public boolean supportsFileAttributeView(Class<? extends FileAttributeView> type) | |
738 | + { | |
739 | + return fileStore.supportsFileAttributeView(type); | |
740 | + } | |
741 | + | |
742 | + @Override | |
743 | + public boolean supportsFileAttributeView(String name) | |
744 | + { | |
745 | + return fileStore.supportsFileAttributeView(name); | |
746 | + } | |
747 | + | |
748 | + @Override | |
749 | + public <V extends FileStoreAttributeView> V getFileStoreAttributeView(Class<V> type) | |
750 | + { | |
751 | + return fileStore.getFileStoreAttributeView(type); | |
752 | + } | |
753 | + | |
754 | + @Override | |
755 | + public Object getAttribute(String attribute) throws IOException | |
756 | + { | |
757 | + return fileStore.getAttribute(attribute); | |
758 | + } | |
759 | + } | |
760 | +} | ... | ... |
... | ... | @@ -25,7 +25,7 @@ import org.junit.Test; |
25 | 25 | import org.junit.runner.RunWith; |
26 | 26 | import org.mockito.Mock; |
27 | 27 | import org.mockito.Spy; |
28 | -import org.mockito.runners.MockitoJUnitRunner; | |
28 | +import org.mockito.junit.MockitoJUnitRunner; | |
29 | 29 | import org.springframework.core.env.Environment; |
30 | 30 | import org.springframework.test.util.ReflectionTestUtils; |
31 | 31 | import org.thingsboard.server.common.data.id.TenantId; |
... | ... | @@ -35,9 +35,9 @@ import org.thingsboard.server.dao.timeseries.CassandraBaseTimeseriesDao; |
35 | 35 | |
36 | 36 | import java.util.UUID; |
37 | 37 | |
38 | -import static org.mockito.Matchers.any; | |
39 | -import static org.mockito.Matchers.anyInt; | |
40 | -import static org.mockito.Matchers.anyString; | |
38 | +import static org.mockito.ArgumentMatchers.any; | |
39 | +import static org.mockito.ArgumentMatchers.anyInt; | |
40 | +import static org.mockito.ArgumentMatchers.anyString; | |
41 | 41 | import static org.mockito.Mockito.doReturn; |
42 | 42 | import static org.mockito.Mockito.times; |
43 | 43 | import static org.mockito.Mockito.verify; | ... | ... |
... | ... | @@ -347,7 +347,7 @@ public abstract class BaseAlarmServiceTest extends AbstractServiceTest { |
347 | 347 | } |
348 | 348 | |
349 | 349 | private AlarmDataQuery toQuery(AlarmDataPageLink pageLink){ |
350 | - return toQuery(pageLink, Collections.EMPTY_LIST); | |
350 | + return toQuery(pageLink, Collections.emptyList()); | |
351 | 351 | } |
352 | 352 | |
353 | 353 | private AlarmDataQuery toQuery(AlarmDataPageLink pageLink, List<EntityKey> alarmFields){ | ... | ... |
... | ... | @@ -1193,7 +1193,7 @@ public abstract class BaseEntityServiceTest extends AbstractServiceTest { |
1193 | 1193 | |
1194 | 1194 | EntityDataPageLink pageLink = new EntityDataPageLink(100, 0, null, sortOrder); |
1195 | 1195 | EntityDataQuery query = new EntityDataQuery(filter, pageLink, entityFields, null, deviceTypeFilters); |
1196 | - PageData data = entityService.findEntityDataByQuery(tenantId, new CustomerId(CustomerId.NULL_UUID), query); | |
1196 | + PageData<EntityData> data = entityService.findEntityDataByQuery(tenantId, new CustomerId(CustomerId.NULL_UUID), query); | |
1197 | 1197 | List<EntityData> loadedEntities = getLoadedEntities(data, query); |
1198 | 1198 | Assert.assertEquals(devices.size(), loadedEntities.size()); |
1199 | 1199 | |
... | ... | @@ -1220,7 +1220,7 @@ public abstract class BaseEntityServiceTest extends AbstractServiceTest { |
1220 | 1220 | return A.containsAll(B) && B.containsAll(A); |
1221 | 1221 | } |
1222 | 1222 | |
1223 | - private List<EntityData> getLoadedEntities(PageData data, EntityDataQuery query) { | |
1223 | + private List<EntityData> getLoadedEntities(PageData<EntityData> data, EntityDataQuery query) { | |
1224 | 1224 | List<EntityData> loadedEntities = new ArrayList<>(data.getData()); |
1225 | 1225 | |
1226 | 1226 | while (data.hasNext()) { | ... | ... |
... | ... | @@ -51,6 +51,7 @@ import org.thingsboard.server.common.data.security.DeviceCredentials; |
51 | 51 | import org.thingsboard.server.msa.mapper.WsTelemetryResponse; |
52 | 52 | |
53 | 53 | |
54 | +import javax.net.ssl.HostnameVerifier; | |
54 | 55 | import javax.net.ssl.SSLContext; |
55 | 56 | import javax.net.ssl.SSLSession; |
56 | 57 | import javax.net.ssl.SSLSocket; |
... | ... | @@ -114,14 +115,17 @@ public abstract class AbstractContainerTest { |
114 | 115 | } |
115 | 116 | |
116 | 117 | protected Device createDevice(String name) { |
117 | - return restClient.createDevice(name + RandomStringUtils.randomAlphanumeric(7), "DEFAULT"); | |
118 | + Device device = new Device(); | |
119 | + device.setName(name + RandomStringUtils.randomAlphanumeric(7)); | |
120 | + device.setType("DEFAULT"); | |
121 | + return restClient.saveDevice(device); | |
118 | 122 | } |
119 | 123 | |
120 | 124 | protected WsClient subscribeToWebSocket(DeviceId deviceId, String scope, CmdsType property) throws Exception { |
121 | 125 | WsClient wsClient = new WsClient(new URI(WSS_URL + "/api/ws/plugins/telemetry?token=" + restClient.getToken())); |
122 | 126 | SSLContextBuilder builder = SSLContexts.custom(); |
123 | 127 | builder.loadTrustMaterial(null, (TrustStrategy) (chain, authType) -> true); |
124 | - wsClient.setSocket(builder.build().getSocketFactory().createSocket()); | |
128 | + wsClient.setSocketFactory(builder.build().getSocketFactory()); | |
125 | 129 | wsClient.connectBlocking(); |
126 | 130 | |
127 | 131 | JsonObject cmdsObject = new JsonObject(); |
... | ... | @@ -218,24 +222,7 @@ public abstract class AbstractContainerTest { |
218 | 222 | SSLContextBuilder builder = SSLContexts.custom(); |
219 | 223 | builder.loadTrustMaterial(null, (TrustStrategy) (chain, authType) -> true); |
220 | 224 | SSLContext sslContext = builder.build(); |
221 | - SSLConnectionSocketFactory sslSelfSigned = new SSLConnectionSocketFactory(sslContext, new X509HostnameVerifier() { | |
222 | - @Override | |
223 | - public void verify(String host, SSLSocket ssl) { | |
224 | - } | |
225 | - | |
226 | - @Override | |
227 | - public void verify(String host, X509Certificate cert) { | |
228 | - } | |
229 | - | |
230 | - @Override | |
231 | - public void verify(String host, String[] cns, String[] subjectAlts) { | |
232 | - } | |
233 | - | |
234 | - @Override | |
235 | - public boolean verify(String s, SSLSession sslSession) { | |
236 | - return true; | |
237 | - } | |
238 | - }); | |
225 | + SSLConnectionSocketFactory sslSelfSigned = new SSLConnectionSocketFactory(sslContext, (s, sslSession) -> true); | |
239 | 226 | |
240 | 227 | Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder |
241 | 228 | .<ConnectionSocketFactory>create() | ... | ... |
... | ... | @@ -34,7 +34,7 @@ import java.util.Map; |
34 | 34 | @ClasspathSuite.ClassnameFilters({"org.thingsboard.server.msa.*Test"}) |
35 | 35 | public class ContainerTestSuite { |
36 | 36 | |
37 | - private static DockerComposeContainer testContainer; | |
37 | + private static DockerComposeContainer<?> testContainer; | |
38 | 38 | |
39 | 39 | @ClassRule |
40 | 40 | public static ThingsBoardDbInstaller installTb = new ThingsBoardDbInstaller(); |
... | ... | @@ -43,7 +43,7 @@ public class ContainerTestSuite { |
43 | 43 | public static DockerComposeContainer getTestContainer() { |
44 | 44 | if (testContainer == null) { |
45 | 45 | boolean skipTailChildContainers = Boolean.valueOf(System.getProperty("blackBoxTests.skipTailChildContainers")); |
46 | - testContainer = new DockerComposeContainer( | |
46 | + testContainer = new DockerComposeContainer<>( | |
47 | 47 | new File("./../../docker/docker-compose.yml"), |
48 | 48 | new File("./../../docker/docker-compose.postgres.yml"), |
49 | 49 | new File("./../../docker/docker-compose.postgres.volumes.yml"), | ... | ... |
... | ... | @@ -44,7 +44,7 @@ public class HttpClientTest extends AbstractContainerTest { |
44 | 44 | restClient.login("tenant@thingsboard.org", "tenant"); |
45 | 45 | |
46 | 46 | Device device = createDevice("http_"); |
47 | - DeviceCredentials deviceCredentials = restClient.getCredentials(device.getId()); | |
47 | + DeviceCredentials deviceCredentials = restClient.getDeviceCredentialsByDeviceId(device.getId()).get(); | |
48 | 48 | |
49 | 49 | WsClient wsClient = subscribeToWebSocket(device.getId(), "LATEST_TELEMETRY", CmdsType.TS_SUB_CMDS); |
50 | 50 | ResponseEntity deviceTelemetryResponse = restClient.getRestTemplate() |
... | ... | @@ -73,7 +73,7 @@ public class HttpClientTest extends AbstractContainerTest { |
73 | 73 | TB_TOKEN = restClient.getToken(); |
74 | 74 | |
75 | 75 | Device device = createDevice("test"); |
76 | - String accessToken = restClient.getCredentials(device.getId()).getCredentialsId(); | |
76 | + String accessToken = restClient.getDeviceCredentialsByDeviceId(device.getId()).get().getCredentialsId(); | |
77 | 77 | assertNotNull(accessToken); |
78 | 78 | |
79 | 79 | ResponseEntity deviceSharedAttributes = restClient.getRestTemplate() |
... | ... | @@ -92,6 +92,7 @@ public class HttpClientTest extends AbstractContainerTest { |
92 | 92 | |
93 | 93 | TimeUnit.SECONDS.sleep(3); |
94 | 94 | |
95 | + @SuppressWarnings("deprecation") | |
95 | 96 | Optional<JsonNode> allOptional = restClient.getAttributes(accessToken, null, null); |
96 | 97 | assertTrue(allOptional.isPresent()); |
97 | 98 | |
... | ... | @@ -101,6 +102,7 @@ public class HttpClientTest extends AbstractContainerTest { |
101 | 102 | assertEquals(mapper.readTree(createPayload().toString()), all.get("shared")); |
102 | 103 | assertEquals(mapper.readTree(createPayload().toString()), all.get("client")); |
103 | 104 | |
105 | + @SuppressWarnings("deprecation") | |
104 | 106 | Optional<JsonNode> sharedOptional = restClient.getAttributes(accessToken, null, "stringKey"); |
105 | 107 | assertTrue(sharedOptional.isPresent()); |
106 | 108 | |
... | ... | @@ -108,6 +110,7 @@ public class HttpClientTest extends AbstractContainerTest { |
108 | 110 | assertEquals(shared.get("shared").get("stringKey"), mapper.readTree(createPayload().get("stringKey").toString())); |
109 | 111 | assertFalse(shared.has("client")); |
110 | 112 | |
113 | + @SuppressWarnings("deprecation") | |
111 | 114 | Optional<JsonNode> clientOptional = restClient.getAttributes(accessToken, "longKey,stringKey", null); |
112 | 115 | assertTrue(clientOptional.isPresent()); |
113 | 116 | ... | ... |
... | ... | @@ -62,7 +62,7 @@ public class MqttClientTest extends AbstractContainerTest { |
62 | 62 | public void telemetryUpload() throws Exception { |
63 | 63 | restClient.login("tenant@thingsboard.org", "tenant"); |
64 | 64 | Device device = createDevice("mqtt_"); |
65 | - DeviceCredentials deviceCredentials = restClient.getCredentials(device.getId()); | |
65 | + DeviceCredentials deviceCredentials = restClient.getDeviceCredentialsByDeviceId(device.getId()).get(); | |
66 | 66 | |
67 | 67 | WsClient wsClient = subscribeToWebSocket(device.getId(), "LATEST_TELEMETRY", CmdsType.TS_SUB_CMDS); |
68 | 68 | MqttClient mqttClient = getMqttClient(deviceCredentials, null); |
... | ... | @@ -89,7 +89,7 @@ public class MqttClientTest extends AbstractContainerTest { |
89 | 89 | |
90 | 90 | restClient.login("tenant@thingsboard.org", "tenant"); |
91 | 91 | Device device = createDevice("mqtt_"); |
92 | - DeviceCredentials deviceCredentials = restClient.getCredentials(device.getId()); | |
92 | + DeviceCredentials deviceCredentials = restClient.getDeviceCredentialsByDeviceId(device.getId()).get(); | |
93 | 93 | |
94 | 94 | WsClient wsClient = subscribeToWebSocket(device.getId(), "LATEST_TELEMETRY", CmdsType.TS_SUB_CMDS); |
95 | 95 | MqttClient mqttClient = getMqttClient(deviceCredentials, null); |
... | ... | @@ -113,7 +113,7 @@ public class MqttClientTest extends AbstractContainerTest { |
113 | 113 | public void publishAttributeUpdateToServer() throws Exception { |
114 | 114 | restClient.login("tenant@thingsboard.org", "tenant"); |
115 | 115 | Device device = createDevice("mqtt_"); |
116 | - DeviceCredentials deviceCredentials = restClient.getCredentials(device.getId()); | |
116 | + DeviceCredentials deviceCredentials = restClient.getDeviceCredentialsByDeviceId(device.getId()).get(); | |
117 | 117 | |
118 | 118 | WsClient wsClient = subscribeToWebSocket(device.getId(), "CLIENT_SCOPE", CmdsType.ATTR_SUB_CMDS); |
119 | 119 | MqttMessageListener listener = new MqttMessageListener(); |
... | ... | @@ -144,7 +144,7 @@ public class MqttClientTest extends AbstractContainerTest { |
144 | 144 | public void requestAttributeValuesFromServer() throws Exception { |
145 | 145 | restClient.login("tenant@thingsboard.org", "tenant"); |
146 | 146 | Device device = createDevice("mqtt_"); |
147 | - DeviceCredentials deviceCredentials = restClient.getCredentials(device.getId()); | |
147 | + DeviceCredentials deviceCredentials = restClient.getDeviceCredentialsByDeviceId(device.getId()).get(); | |
148 | 148 | |
149 | 149 | WsClient wsClient = subscribeToWebSocket(device.getId(), "CLIENT_SCOPE", CmdsType.ATTR_SUB_CMDS); |
150 | 150 | MqttMessageListener listener = new MqttMessageListener(); |
... | ... | @@ -204,7 +204,7 @@ public class MqttClientTest extends AbstractContainerTest { |
204 | 204 | public void subscribeToAttributeUpdatesFromServer() throws Exception { |
205 | 205 | restClient.login("tenant@thingsboard.org", "tenant"); |
206 | 206 | Device device = createDevice("mqtt_"); |
207 | - DeviceCredentials deviceCredentials = restClient.getCredentials(device.getId()); | |
207 | + DeviceCredentials deviceCredentials = restClient.getDeviceCredentialsByDeviceId(device.getId()).get(); | |
208 | 208 | |
209 | 209 | MqttMessageListener listener = new MqttMessageListener(); |
210 | 210 | MqttClient mqttClient = getMqttClient(deviceCredentials, listener); |
... | ... | @@ -250,7 +250,7 @@ public class MqttClientTest extends AbstractContainerTest { |
250 | 250 | public void serverSideRpc() throws Exception { |
251 | 251 | restClient.login("tenant@thingsboard.org", "tenant"); |
252 | 252 | Device device = createDevice("mqtt_"); |
253 | - DeviceCredentials deviceCredentials = restClient.getCredentials(device.getId()); | |
253 | + DeviceCredentials deviceCredentials = restClient.getDeviceCredentialsByDeviceId(device.getId()).get(); | |
254 | 254 | |
255 | 255 | MqttMessageListener listener = new MqttMessageListener(); |
256 | 256 | MqttClient mqttClient = getMqttClient(deviceCredentials, listener); |
... | ... | @@ -297,7 +297,7 @@ public class MqttClientTest extends AbstractContainerTest { |
297 | 297 | public void clientSideRpc() throws Exception { |
298 | 298 | restClient.login("tenant@thingsboard.org", "tenant"); |
299 | 299 | Device device = createDevice("mqtt_"); |
300 | - DeviceCredentials deviceCredentials = restClient.getCredentials(device.getId()); | |
300 | + DeviceCredentials deviceCredentials = restClient.getDeviceCredentialsByDeviceId(device.getId()).get(); | |
301 | 301 | |
302 | 302 | MqttMessageListener listener = new MqttMessageListener(); |
303 | 303 | MqttClient mqttClient = getMqttClient(deviceCredentials, listener); | ... | ... |
... | ... | @@ -67,16 +67,15 @@ |
67 | 67 | <plugin> |
68 | 68 | <groupId>org.apache.maven.plugins</groupId> |
69 | 69 | <artifactId>maven-compiler-plugin</artifactId> |
70 | - <version>3.1</version> | |
70 | + <version>3.8.1</version> | |
71 | 71 | <configuration> |
72 | - <source>1.8</source> | |
73 | - <target>1.8</target> | |
72 | + <release>11</release> | |
74 | 73 | </configuration> |
75 | 74 | </plugin> |
76 | 75 | <plugin> |
77 | 76 | <groupId>org.apache.maven.plugins</groupId> |
78 | 77 | <artifactId>maven-jar-plugin</artifactId> |
79 | - <version>2.4</version> | |
78 | + <version>3.1.1</version> | |
80 | 79 | <configuration> |
81 | 80 | <archive> |
82 | 81 | <manifest> |
... | ... | @@ -87,4 +86,4 @@ |
87 | 86 | </plugin> |
88 | 87 | </plugins> |
89 | 88 | </build> |
90 | -</project> | |
\ No newline at end of file | ||
89 | +</project> | ... | ... |
... | ... | @@ -36,6 +36,9 @@ |
36 | 36 | <pkg.implementationTitle>${project.name}</pkg.implementationTitle> |
37 | 37 | <pkg.unixLogFolder>/var/log/${pkg.name}</pkg.unixLogFolder> |
38 | 38 | <pkg.installFolder>/usr/share/${pkg.name}</pkg.installFolder> |
39 | + <javax-annotation.version>1.3.2</javax-annotation.version> | |
40 | + <jakarta.xml.bind-api.version>2.3.2</jakarta.xml.bind-api.version> | |
41 | + <jaxb-runtime.version>2.3.2</jaxb-runtime.version> | |
39 | 42 | <spring-boot.version>2.3.5.RELEASE</spring-boot.version> |
40 | 43 | <spring.version>5.2.10.RELEASE</spring.version> |
41 | 44 | <spring-security.version>5.4.1</spring-security.version> |
... | ... | @@ -46,9 +49,9 @@ |
46 | 49 | <junit.version>4.12</junit.version> |
47 | 50 | <slf4j.version>1.7.7</slf4j.version> |
48 | 51 | <logback.version>1.2.3</logback.version> |
49 | - <mockito.version>1.9.5</mockito.version> | |
52 | + <mockito.version>3.3.3</mockito.version> | |
50 | 53 | <rat.version>0.10</rat.version> |
51 | - <cassandra.version>4.6.0</cassandra.version> | |
54 | + <cassandra.version>4.10.0</cassandra.version> | |
52 | 55 | <metrics.version>4.0.5</metrics.version> |
53 | 56 | <cassandra-unit.version>4.3.1.0</cassandra-unit.version> |
54 | 57 | <cassandra-all.version>3.11.9</cassandra-all.version> |
... | ... | @@ -70,7 +73,7 @@ |
70 | 73 | <zookeeper.version>3.5.5</zookeeper.version> |
71 | 74 | <protobuf.version>3.11.4</protobuf.version> |
72 | 75 | <grpc.version>1.22.1</grpc.version> |
73 | - <lombok.version>1.16.18</lombok.version> | |
76 | + <lombok.version>1.18.18</lombok.version> | |
74 | 77 | <paho.client.version>1.2.4</paho.client.version> |
75 | 78 | <netty.version>4.1.53.Final</netty.version> |
76 | 79 | <os-maven-plugin.version>1.5.0</os-maven-plugin.version> |
... | ... | @@ -86,12 +89,12 @@ |
86 | 89 | <hsqldb.version>2.5.0</hsqldb.version> |
87 | 90 | <dbunit.version>2.5.3</dbunit.version> |
88 | 91 | <spring-test-dbunit.version>1.2.1</spring-test-dbunit.version> |
89 | - <postgresql.driver.version>9.4.1212</postgresql.driver.version> | |
92 | + <postgresql.driver.version>42.2.16</postgresql.driver.version> | |
90 | 93 | <sonar.exclusions>org/thingsboard/server/gen/**/*, |
91 | 94 | org/thingsboard/server/extensions/core/plugin/telemetry/gen/**/* |
92 | 95 | </sonar.exclusions> |
93 | 96 | <elasticsearch.version>5.0.2</elasticsearch.version> |
94 | - <delight-nashorn-sandbox.version>0.1.14</delight-nashorn-sandbox.version> | |
97 | + <delight-nashorn-sandbox.version>0.1.31</delight-nashorn-sandbox.version> | |
95 | 98 | <kafka.version>2.6.0</kafka.version> |
96 | 99 | <bucket4j.version>4.1.1</bucket4j.version> |
97 | 100 | <fst.version>2.57</fst.version> |
... | ... | @@ -543,10 +546,14 @@ |
543 | 546 | <plugin> |
544 | 547 | <groupId>org.apache.maven.plugins</groupId> |
545 | 548 | <artifactId>maven-compiler-plugin</artifactId> |
546 | - <version>2.5.1</version> | |
549 | + <version>3.8.1</version> | |
547 | 550 | <configuration> |
548 | - <source>1.8</source> | |
549 | - <target>1.8</target> | |
551 | + <release>11</release> | |
552 | + <compilerArgs> | |
553 | + <arg>-Xlint:deprecation</arg> | |
554 | + <arg>-Xlint:removal</arg> | |
555 | + <arg>-Xlint:unchecked</arg> | |
556 | + </compilerArgs> | |
550 | 557 | </configuration> |
551 | 558 | </plugin> |
552 | 559 | <plugin> |
... | ... | @@ -557,12 +564,12 @@ |
557 | 564 | <plugin> |
558 | 565 | <groupId>org.apache.maven.plugins</groupId> |
559 | 566 | <artifactId>maven-source-plugin</artifactId> |
560 | - <version>2.2.1</version> | |
567 | + <version>3.2.1</version> | |
561 | 568 | </plugin> |
562 | 569 | <plugin> |
563 | 570 | <groupId>org.apache.maven.plugins</groupId> |
564 | 571 | <artifactId>maven-jar-plugin</artifactId> |
565 | - <version>3.0.2</version> | |
572 | + <version>3.1.1</version> | |
566 | 573 | </plugin> |
567 | 574 | <plugin> |
568 | 575 | <groupId>org.apache.maven.plugins</groupId> |
... | ... | @@ -570,6 +577,11 @@ |
570 | 577 | <version>3.0.0</version> |
571 | 578 | </plugin> |
572 | 579 | <plugin> |
580 | + <groupId>org.apache.maven.plugins</groupId> | |
581 | + <artifactId>maven-deploy-plugin</artifactId> | |
582 | + <version>2.8.2</version> | |
583 | + </plugin> | |
584 | + <plugin> | |
573 | 585 | <groupId>org.springframework.boot</groupId> |
574 | 586 | <artifactId>spring-boot-maven-plugin</artifactId> |
575 | 587 | <version>${spring-boot.version}</version> |
... | ... | @@ -583,6 +595,11 @@ |
583 | 595 | <groupId>org.apache.maven.plugins</groupId> |
584 | 596 | <artifactId>maven-surefire-plugin</artifactId> |
585 | 597 | <version>3.0.0-M1</version> |
598 | + <configuration> | |
599 | + <argLine> | |
600 | + --illegal-access=permit | |
601 | + </argLine> | |
602 | + </configuration> | |
586 | 603 | </plugin> |
587 | 604 | <plugin> |
588 | 605 | <groupId>org.apache.maven.plugins</groupId> |
... | ... | @@ -873,6 +890,21 @@ |
873 | 890 | <scope>test</scope> |
874 | 891 | </dependency> |
875 | 892 | <dependency> |
893 | + <groupId>javax.annotation</groupId> | |
894 | + <artifactId>javax.annotation-api</artifactId> | |
895 | + <version>${javax-annotation.version}</version> | |
896 | + </dependency> | |
897 | + <dependency> | |
898 | + <groupId>jakarta.xml.bind</groupId> | |
899 | + <artifactId>jakarta.xml.bind-api</artifactId> | |
900 | + <version>${jakarta.xml.bind-api.version}</version> | |
901 | + </dependency> | |
902 | + <dependency> | |
903 | + <groupId>org.glassfish.jaxb</groupId> | |
904 | + <artifactId>jaxb-runtime</artifactId> | |
905 | + <version>${jaxb-runtime.version}</version> | |
906 | + </dependency> | |
907 | + <dependency> | |
876 | 908 | <groupId>org.springframework.boot</groupId> |
877 | 909 | <artifactId>spring-boot-starter-security</artifactId> |
878 | 910 | <version>${spring-boot.version}</version> |
... | ... | @@ -1219,7 +1251,7 @@ |
1219 | 1251 | </dependency> |
1220 | 1252 | <dependency> |
1221 | 1253 | <groupId>org.mockito</groupId> |
1222 | - <artifactId>mockito-all</artifactId> | |
1254 | + <artifactId>mockito-core</artifactId> | |
1223 | 1255 | <version>${mockito.version}</version> |
1224 | 1256 | <scope>test</scope> |
1225 | 1257 | </dependency> | ... | ... |