Browse Source
# Conflicts: # common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/bootstrap/LwM2MTransportBootstrapService.java # common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/secure/TbLwM2MDtlsCertificateVerifier.javapull/5930/head
94 changed files with 1140 additions and 1194 deletions
@ -1,56 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2022 The Thingsboard Authors |
|
||||
* |
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
||||
* you may not use this file except in compliance with the License. |
|
||||
* You may obtain a copy of the License at |
|
||||
* |
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||
* |
|
||||
* Unless required by applicable law or agreed to in writing, software |
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
||||
* See the License for the specific language governing permissions and |
|
||||
* limitations under the License. |
|
||||
*/ |
|
||||
package org.thingsboard.server.service.install; |
|
||||
|
|
||||
import lombok.extern.slf4j.Slf4j; |
|
||||
import org.springframework.context.annotation.Profile; |
|
||||
import org.springframework.stereotype.Service; |
|
||||
import org.thingsboard.server.dao.util.HsqlDao; |
|
||||
|
|
||||
import java.nio.charset.Charset; |
|
||||
import java.nio.file.Files; |
|
||||
import java.nio.file.Path; |
|
||||
import java.nio.file.Paths; |
|
||||
import java.sql.Connection; |
|
||||
import java.sql.DriverManager; |
|
||||
|
|
||||
@Service |
|
||||
@Slf4j |
|
||||
@HsqlDao |
|
||||
@Profile("install") |
|
||||
public class HsqlEntityDatabaseSchemaService extends SqlAbstractDatabaseSchemaService |
|
||||
implements EntityDatabaseSchemaService { |
|
||||
protected HsqlEntityDatabaseSchemaService() { |
|
||||
super("schema-entities-hsql.sql", "schema-entities-idx.sql"); |
|
||||
} |
|
||||
|
|
||||
private final String schemaTypesSql = "schema-types-hsql.sql"; |
|
||||
|
|
||||
@Override |
|
||||
public void createDatabaseSchema(boolean createIndexes) throws Exception { |
|
||||
|
|
||||
log.info("Installing SQL DataBase types part: " + schemaTypesSql); |
|
||||
|
|
||||
Path schemaFile = Paths.get(installScripts.getDataDir(), SQL_DIR, schemaTypesSql); |
|
||||
try (Connection conn = DriverManager.getConnection(dbUrl, dbUserName, dbPassword)) { |
|
||||
String sql = new String(Files.readAllBytes(schemaFile), Charset.forName("UTF-8")); |
|
||||
conn.createStatement().execute(sql); //NOSONAR, ignoring because method used to load initial thingsboard database schema
|
|
||||
} |
|
||||
|
|
||||
super.createDatabaseSchema(createIndexes); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
@ -1,32 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2022 The Thingsboard Authors |
|
||||
* |
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
||||
* you may not use this file except in compliance with the License. |
|
||||
* You may obtain a copy of the License at |
|
||||
* |
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||
* |
|
||||
* Unless required by applicable law or agreed to in writing, software |
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
||||
* See the License for the specific language governing permissions and |
|
||||
* limitations under the License. |
|
||||
*/ |
|
||||
package org.thingsboard.server.service.install; |
|
||||
|
|
||||
import org.springframework.context.annotation.Profile; |
|
||||
import org.springframework.stereotype.Service; |
|
||||
import org.thingsboard.server.dao.util.HsqlDao; |
|
||||
import org.thingsboard.server.dao.util.SqlTsDao; |
|
||||
|
|
||||
@Service |
|
||||
@SqlTsDao |
|
||||
@HsqlDao |
|
||||
@Profile("install") |
|
||||
public class HsqlTsDatabaseSchemaService extends SqlAbstractDatabaseSchemaService |
|
||||
implements TsDatabaseSchemaService { |
|
||||
public HsqlTsDatabaseSchemaService() { |
|
||||
super("schema-ts-hsql.sql", null); |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,162 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2022 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.transport.lwm2m.bootstrap.secure; |
||||
|
|
||||
|
import lombok.RequiredArgsConstructor; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.eclipse.californium.elements.auth.RawPublicKeyIdentity; |
||||
|
import org.eclipse.californium.elements.util.CertPathUtil; |
||||
|
import org.eclipse.californium.scandium.dtls.AlertMessage; |
||||
|
import org.eclipse.californium.scandium.dtls.CertificateMessage; |
||||
|
import org.eclipse.californium.scandium.dtls.CertificateType; |
||||
|
import org.eclipse.californium.scandium.dtls.CertificateVerificationResult; |
||||
|
import org.eclipse.californium.scandium.dtls.ConnectionId; |
||||
|
import org.eclipse.californium.scandium.dtls.HandshakeException; |
||||
|
import org.eclipse.californium.scandium.dtls.HandshakeResultHandler; |
||||
|
import org.eclipse.californium.scandium.dtls.x509.NewAdvancedCertificateVerifier; |
||||
|
import org.eclipse.californium.scandium.dtls.x509.StaticNewAdvancedCertificateVerifier; |
||||
|
import org.eclipse.californium.scandium.util.ServerNames; |
||||
|
import org.springframework.beans.factory.annotation.Value; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
import org.thingsboard.server.common.data.StringUtils; |
||||
|
import org.thingsboard.server.common.msg.EncryptionUtil; |
||||
|
import org.thingsboard.server.common.transport.auth.ValidateDeviceCredentialsResponse; |
||||
|
import org.thingsboard.server.common.transport.util.SslUtil; |
||||
|
import org.thingsboard.server.queue.util.TbLwM2mBootstrapTransportComponent; |
||||
|
import org.thingsboard.server.transport.lwm2m.bootstrap.store.LwM2MBootstrapSecurityStore; |
||||
|
import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportServerConfig; |
||||
|
import org.thingsboard.server.transport.lwm2m.secure.TbLwM2MSecurityInfo; |
||||
|
import org.thingsboard.server.transport.lwm2m.server.client.LwM2MAuthException; |
||||
|
|
||||
|
import javax.annotation.PostConstruct; |
||||
|
import javax.security.auth.x500.X500Principal; |
||||
|
import java.net.InetSocketAddress; |
||||
|
import java.security.PublicKey; |
||||
|
import java.security.cert.CertPath; |
||||
|
import java.security.cert.CertificateEncodingException; |
||||
|
import java.security.cert.CertificateExpiredException; |
||||
|
import java.security.cert.CertificateNotYetValidException; |
||||
|
import java.security.cert.X509Certificate; |
||||
|
import java.util.Arrays; |
||||
|
import java.util.List; |
||||
|
|
||||
|
@Slf4j |
||||
|
@Component |
||||
|
@TbLwM2mBootstrapTransportComponent |
||||
|
@RequiredArgsConstructor |
||||
|
public class TbLwM2MDtlsBootstrapCertificateVerifier implements NewAdvancedCertificateVerifier { |
||||
|
|
||||
|
private final LwM2MTransportServerConfig config; |
||||
|
private final LwM2MBootstrapSecurityStore bsSecurityStore; |
||||
|
|
||||
|
private StaticNewAdvancedCertificateVerifier staticCertificateVerifier; |
||||
|
|
||||
|
@Value("${transport.lwm2m.server.security.skip_validity_check_for_client_cert:false}") |
||||
|
private boolean skipValidityCheckForClientCert; |
||||
|
|
||||
|
@Override |
||||
|
public List<CertificateType> getSupportedCertificateTypes() { |
||||
|
return Arrays.asList(CertificateType.X_509, CertificateType.RAW_PUBLIC_KEY); |
||||
|
} |
||||
|
|
||||
|
@SuppressWarnings("deprecation") |
||||
|
@PostConstruct |
||||
|
public void init() { |
||||
|
try { |
||||
|
/* by default trust all */ |
||||
|
if (config.getTrustSslCredentials() != null) { |
||||
|
X509Certificate[] trustedCertificates = config.getTrustSslCredentials().getTrustedCertificates(); |
||||
|
staticCertificateVerifier = new StaticNewAdvancedCertificateVerifier(trustedCertificates, new RawPublicKeyIdentity[0], null); |
||||
|
} |
||||
|
} catch (Exception e) { |
||||
|
log.warn("ailed to initialize the LwM2M certificate verifier", e); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public CertificateVerificationResult verifyCertificate(ConnectionId cid, ServerNames serverName, InetSocketAddress remotePeer, |
||||
|
boolean clientUsage, boolean verifySubject, boolean truncateCertificatePath, |
||||
|
CertificateMessage message) { |
||||
|
CertPath certChain = message.getCertificateChain(); |
||||
|
if (certChain == null) { |
||||
|
//We trust all RPK on this layer, and use TbLwM2MAuthorizer
|
||||
|
PublicKey publicKey = message.getPublicKey(); |
||||
|
return new CertificateVerificationResult(cid, publicKey, null); |
||||
|
} else { |
||||
|
try { |
||||
|
boolean x509CredentialsFound = false; |
||||
|
X509Certificate[] chain = certChain.getCertificates().toArray(new X509Certificate[0]); |
||||
|
for (X509Certificate cert : chain) { |
||||
|
try { |
||||
|
if (!skipValidityCheckForClientCert) { |
||||
|
cert.checkValidity(); |
||||
|
} |
||||
|
TbLwM2MSecurityInfo securityInfo = null; |
||||
|
// verify if trust
|
||||
|
if (staticCertificateVerifier != null) { |
||||
|
HandshakeException exception = staticCertificateVerifier.verifyCertificate(cid, serverName, remotePeer, clientUsage, verifySubject, truncateCertificatePath, message).getException(); |
||||
|
if (exception == null) { |
||||
|
String endpoint = config.getTrustSslCredentials().getValueFromSubjectNameByKey(cert.getSubjectX500Principal().getName(), "CN"); |
||||
|
if (StringUtils.isNotEmpty(endpoint)) { |
||||
|
securityInfo = bsSecurityStore.getX509ByEndpoint(endpoint); |
||||
|
} |
||||
|
} else { |
||||
|
log.trace("Certificate validation failed.", exception); |
||||
|
} |
||||
|
} |
||||
|
// if not trust or cert trust securityInfo == null
|
||||
|
if (securityInfo == null || securityInfo.getMsg() == null) { |
||||
|
String strCert = SslUtil.getCertificateString(cert); |
||||
|
String sha3Hash = EncryptionUtil.getSha3Hash(strCert); |
||||
|
try { |
||||
|
securityInfo = bsSecurityStore.getX509ByEndpoint(sha3Hash); |
||||
|
} catch (LwM2MAuthException e) { |
||||
|
log.trace("Failed to find security info: [{}]", sha3Hash, e); |
||||
|
} |
||||
|
} |
||||
|
ValidateDeviceCredentialsResponse msg = securityInfo != null ? securityInfo.getMsg() : null; |
||||
|
if (msg != null && StringUtils.isNotEmpty(msg.getCredentials())) { |
||||
|
x509CredentialsFound = true; |
||||
|
break; |
||||
|
} |
||||
|
} catch (CertificateEncodingException | |
||||
|
CertificateExpiredException | |
||||
|
CertificateNotYetValidException e) { |
||||
|
log.trace("Failed to find security info: [{}]", cert.getSubjectX500Principal().getName(), e); |
||||
|
} |
||||
|
} |
||||
|
if (!x509CredentialsFound) { |
||||
|
AlertMessage alert = new AlertMessage(AlertMessage.AlertLevel.FATAL, AlertMessage.AlertDescription.INTERNAL_ERROR); |
||||
|
throw new HandshakeException("x509 verification not enabled!", alert); |
||||
|
} |
||||
|
return new CertificateVerificationResult(cid, certChain, null); |
||||
|
} catch (HandshakeException e) { |
||||
|
log.trace("Certificate validation failed!", e); |
||||
|
return new CertificateVerificationResult(cid, e, null); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public List<X500Principal> getAcceptedIssuers() { |
||||
|
return CertPathUtil.toSubjects(null); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void setResultHandler(HandshakeResultHandler resultHandler) { |
||||
|
|
||||
|
} |
||||
|
} |
||||
@ -1,599 +0,0 @@ |
|||||
-- |
|
||||
-- Copyright © 2016-2022 The Thingsboard Authors |
|
||||
-- |
|
||||
-- Licensed under the Apache License, Version 2.0 (the "License"); |
|
||||
-- you may not use this file except in compliance with the License. |
|
||||
-- You may obtain a copy of the License at |
|
||||
-- |
|
||||
-- http://www.apache.org/licenses/LICENSE-2.0 |
|
||||
-- |
|
||||
-- Unless required by applicable law or agreed to in writing, software |
|
||||
-- distributed under the License is distributed on an "AS IS" BASIS, |
|
||||
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
||||
-- See the License for the specific language governing permissions and |
|
||||
-- limitations under the License. |
|
||||
-- |
|
||||
|
|
||||
SET DATABASE SQL SYNTAX PGS TRUE; |
|
||||
SET DATABASE TRANSACTION CONTROL MVCC; |
|
||||
|
|
||||
CREATE TABLE IF NOT EXISTS admin_settings ( |
|
||||
id uuid NOT NULL CONSTRAINT admin_settings_pkey PRIMARY KEY, |
|
||||
created_time bigint NOT NULL, |
|
||||
json_value varchar, |
|
||||
key varchar(255) |
|
||||
); |
|
||||
|
|
||||
CREATE TABLE IF NOT EXISTS alarm ( |
|
||||
id uuid NOT NULL CONSTRAINT alarm_pkey PRIMARY KEY, |
|
||||
created_time bigint NOT NULL, |
|
||||
ack_ts bigint, |
|
||||
clear_ts bigint, |
|
||||
additional_info varchar, |
|
||||
end_ts bigint, |
|
||||
originator_id uuid, |
|
||||
originator_type integer, |
|
||||
propagate boolean, |
|
||||
severity varchar(255), |
|
||||
start_ts bigint, |
|
||||
status varchar(255), |
|
||||
tenant_id uuid, |
|
||||
customer_id uuid, |
|
||||
propagate_relation_types varchar, |
|
||||
type varchar(255) |
|
||||
); |
|
||||
|
|
||||
CREATE TABLE IF NOT EXISTS entity_alarm ( |
|
||||
tenant_id uuid NOT NULL, |
|
||||
entity_type varchar(32), |
|
||||
entity_id uuid NOT NULL, |
|
||||
created_time bigint NOT NULL, |
|
||||
alarm_type varchar(255) NOT NULL, |
|
||||
customer_id uuid, |
|
||||
alarm_id uuid, |
|
||||
CONSTRAINT entity_alarm_pkey PRIMARY KEY(entity_id, alarm_id), |
|
||||
CONSTRAINT fk_entity_alarm_id FOREIGN KEY (alarm_id) REFERENCES alarm(id) ON DELETE CASCADE |
|
||||
); |
|
||||
|
|
||||
CREATE TABLE IF NOT EXISTS asset ( |
|
||||
id uuid NOT NULL CONSTRAINT asset_pkey PRIMARY KEY, |
|
||||
created_time bigint NOT NULL, |
|
||||
additional_info varchar, |
|
||||
customer_id uuid, |
|
||||
name varchar(255), |
|
||||
label varchar(255), |
|
||||
search_text varchar(255), |
|
||||
tenant_id uuid, |
|
||||
type varchar(255), |
|
||||
CONSTRAINT asset_name_unq_key UNIQUE (tenant_id, name) |
|
||||
); |
|
||||
|
|
||||
CREATE TABLE IF NOT EXISTS audit_log ( |
|
||||
id uuid NOT NULL CONSTRAINT audit_log_pkey PRIMARY KEY, |
|
||||
created_time bigint NOT NULL, |
|
||||
tenant_id uuid, |
|
||||
customer_id uuid, |
|
||||
entity_id uuid, |
|
||||
entity_type varchar(255), |
|
||||
entity_name varchar(255), |
|
||||
user_id uuid, |
|
||||
user_name varchar(255), |
|
||||
action_type varchar(255), |
|
||||
action_data varchar(1000000), |
|
||||
action_status varchar(255), |
|
||||
action_failure_details varchar(1000000) |
|
||||
); |
|
||||
|
|
||||
CREATE TABLE IF NOT EXISTS attribute_kv ( |
|
||||
entity_type varchar(255), |
|
||||
entity_id uuid, |
|
||||
attribute_type varchar(255), |
|
||||
attribute_key varchar(255), |
|
||||
bool_v boolean, |
|
||||
str_v varchar(10000000), |
|
||||
long_v bigint, |
|
||||
dbl_v double precision, |
|
||||
json_v varchar(10000000), |
|
||||
last_update_ts bigint, |
|
||||
CONSTRAINT attribute_kv_pkey PRIMARY KEY (entity_type, entity_id, attribute_type, attribute_key) |
|
||||
); |
|
||||
|
|
||||
CREATE TABLE IF NOT EXISTS component_descriptor ( |
|
||||
id uuid NOT NULL CONSTRAINT component_descriptor_pkey PRIMARY KEY, |
|
||||
created_time bigint NOT NULL, |
|
||||
actions varchar(255), |
|
||||
clazz varchar UNIQUE, |
|
||||
configuration_descriptor varchar, |
|
||||
name varchar(255), |
|
||||
scope varchar(255), |
|
||||
search_text varchar(255), |
|
||||
type varchar(255) |
|
||||
); |
|
||||
|
|
||||
CREATE TABLE IF NOT EXISTS customer ( |
|
||||
id uuid NOT NULL CONSTRAINT customer_pkey PRIMARY KEY, |
|
||||
created_time bigint NOT NULL, |
|
||||
additional_info varchar, |
|
||||
address varchar, |
|
||||
address2 varchar, |
|
||||
city varchar(255), |
|
||||
country varchar(255), |
|
||||
email varchar(255), |
|
||||
phone varchar(255), |
|
||||
search_text varchar(255), |
|
||||
state varchar(255), |
|
||||
tenant_id uuid, |
|
||||
title varchar(255), |
|
||||
zip varchar(255) |
|
||||
); |
|
||||
|
|
||||
CREATE TABLE IF NOT EXISTS dashboard ( |
|
||||
id uuid NOT NULL CONSTRAINT dashboard_pkey PRIMARY KEY, |
|
||||
created_time bigint NOT NULL, |
|
||||
configuration varchar(10000000), |
|
||||
assigned_customers varchar(1000000), |
|
||||
search_text varchar(255), |
|
||||
tenant_id uuid, |
|
||||
title varchar(255), |
|
||||
mobile_hide boolean DEFAULT false, |
|
||||
mobile_order int, |
|
||||
image varchar(1000000) |
|
||||
); |
|
||||
|
|
||||
CREATE TABLE IF NOT EXISTS rule_chain ( |
|
||||
id uuid NOT NULL CONSTRAINT rule_chain_pkey PRIMARY KEY, |
|
||||
created_time bigint NOT NULL, |
|
||||
additional_info varchar, |
|
||||
configuration varchar(10000000), |
|
||||
name varchar(255), |
|
||||
type varchar(255), |
|
||||
first_rule_node_id uuid, |
|
||||
root boolean, |
|
||||
debug_mode boolean, |
|
||||
search_text varchar(255), |
|
||||
tenant_id uuid |
|
||||
); |
|
||||
|
|
||||
CREATE TABLE IF NOT EXISTS rule_node ( |
|
||||
id uuid NOT NULL CONSTRAINT rule_node_pkey PRIMARY KEY, |
|
||||
created_time bigint NOT NULL, |
|
||||
rule_chain_id uuid, |
|
||||
additional_info varchar, |
|
||||
configuration varchar(10000000), |
|
||||
type varchar(255), |
|
||||
name varchar(255), |
|
||||
debug_mode boolean, |
|
||||
search_text varchar(255) |
|
||||
); |
|
||||
|
|
||||
CREATE TABLE IF NOT EXISTS rule_node_state ( |
|
||||
id uuid NOT NULL CONSTRAINT rule_node_state_pkey PRIMARY KEY, |
|
||||
created_time bigint NOT NULL, |
|
||||
rule_node_id uuid NOT NULL, |
|
||||
entity_type varchar(32) NOT NULL, |
|
||||
entity_id uuid NOT NULL, |
|
||||
state_data varchar(16384) NOT NULL, |
|
||||
CONSTRAINT rule_node_state_unq_key UNIQUE (rule_node_id, entity_id), |
|
||||
CONSTRAINT fk_rule_node_state_node_id FOREIGN KEY (rule_node_id) REFERENCES rule_node(id) ON DELETE CASCADE |
|
||||
); |
|
||||
|
|
||||
CREATE TABLE IF NOT EXISTS ota_package ( |
|
||||
id uuid NOT NULL CONSTRAINT ota_package_pkey PRIMARY KEY, |
|
||||
created_time bigint NOT NULL, |
|
||||
tenant_id uuid NOT NULL, |
|
||||
device_profile_id uuid , |
|
||||
type varchar(32) NOT NULL, |
|
||||
title varchar(255) NOT NULL, |
|
||||
version varchar(255) NOT NULL, |
|
||||
tag varchar(255), |
|
||||
url varchar(255), |
|
||||
file_name varchar(255), |
|
||||
content_type varchar(255), |
|
||||
checksum_algorithm varchar(32), |
|
||||
checksum varchar(1020), |
|
||||
data binary, |
|
||||
data_size bigint, |
|
||||
additional_info varchar, |
|
||||
search_text varchar(255), |
|
||||
CONSTRAINT ota_package_tenant_title_version_unq_key UNIQUE (tenant_id, title, version) |
|
||||
); |
|
||||
|
|
||||
CREATE TABLE IF NOT EXISTS device_profile ( |
|
||||
id uuid NOT NULL CONSTRAINT device_profile_pkey PRIMARY KEY, |
|
||||
created_time bigint NOT NULL, |
|
||||
name varchar(255), |
|
||||
type varchar(255), |
|
||||
image varchar(1000000), |
|
||||
transport_type varchar(255), |
|
||||
provision_type varchar(255), |
|
||||
profile_data jsonb, |
|
||||
description varchar, |
|
||||
search_text varchar(255), |
|
||||
is_default boolean, |
|
||||
tenant_id uuid, |
|
||||
firmware_id uuid, |
|
||||
software_id uuid, |
|
||||
default_rule_chain_id uuid, |
|
||||
default_dashboard_id uuid, |
|
||||
default_queue_name varchar(255), |
|
||||
provision_device_key varchar, |
|
||||
CONSTRAINT device_profile_name_unq_key UNIQUE (tenant_id, name), |
|
||||
CONSTRAINT device_provision_key_unq_key UNIQUE (provision_device_key), |
|
||||
CONSTRAINT fk_default_rule_chain_device_profile FOREIGN KEY (default_rule_chain_id) REFERENCES rule_chain(id), |
|
||||
CONSTRAINT fk_default_dashboard_device_profile FOREIGN KEY (default_dashboard_id) REFERENCES dashboard(id), |
|
||||
CONSTRAINT fk_firmware_device_profile FOREIGN KEY (firmware_id) REFERENCES ota_package(id), |
|
||||
CONSTRAINT fk_software_device_profile FOREIGN KEY (software_id) REFERENCES ota_package(id) |
|
||||
); |
|
||||
|
|
||||
CREATE TABLE IF NOT EXISTS device ( |
|
||||
id uuid NOT NULL CONSTRAINT device_pkey PRIMARY KEY, |
|
||||
created_time bigint NOT NULL, |
|
||||
additional_info varchar, |
|
||||
customer_id uuid, |
|
||||
device_profile_id uuid NOT NULL, |
|
||||
device_data jsonb, |
|
||||
type varchar(255), |
|
||||
name varchar(255), |
|
||||
label varchar(255), |
|
||||
search_text varchar(255), |
|
||||
tenant_id uuid, |
|
||||
firmware_id uuid, |
|
||||
software_id uuid, |
|
||||
CONSTRAINT device_name_unq_key UNIQUE (tenant_id, name), |
|
||||
CONSTRAINT fk_device_profile FOREIGN KEY (device_profile_id) REFERENCES device_profile(id), |
|
||||
CONSTRAINT fk_firmware_device FOREIGN KEY (firmware_id) REFERENCES ota_package(id), |
|
||||
CONSTRAINT fk_software_device FOREIGN KEY (software_id) REFERENCES ota_package(id) |
|
||||
); |
|
||||
|
|
||||
CREATE TABLE IF NOT EXISTS device_credentials ( |
|
||||
id uuid NOT NULL CONSTRAINT device_credentials_pkey PRIMARY KEY, |
|
||||
created_time bigint NOT NULL, |
|
||||
credentials_id varchar, |
|
||||
credentials_type varchar(255), |
|
||||
credentials_value varchar, |
|
||||
device_id uuid, |
|
||||
CONSTRAINT device_credentials_id_unq_key UNIQUE (credentials_id), |
|
||||
CONSTRAINT device_credentials_device_id_unq_key UNIQUE (device_id) |
|
||||
); |
|
||||
|
|
||||
CREATE TABLE IF NOT EXISTS event ( |
|
||||
id uuid NOT NULL CONSTRAINT event_pkey PRIMARY KEY, |
|
||||
created_time bigint NOT NULL, |
|
||||
body varchar(10000000), |
|
||||
entity_id uuid, |
|
||||
entity_type varchar(255), |
|
||||
event_type varchar(255), |
|
||||
event_uid varchar(255), |
|
||||
tenant_id uuid, |
|
||||
ts bigint NOT NULL, |
|
||||
CONSTRAINT event_unq_key UNIQUE (tenant_id, entity_type, entity_id, event_type, event_uid) |
|
||||
); |
|
||||
|
|
||||
CREATE TABLE IF NOT EXISTS relation ( |
|
||||
from_id uuid, |
|
||||
from_type varchar(255), |
|
||||
to_id uuid, |
|
||||
to_type varchar(255), |
|
||||
relation_type_group varchar(255), |
|
||||
relation_type varchar(255), |
|
||||
additional_info varchar, |
|
||||
CONSTRAINT relation_pkey PRIMARY KEY (from_id, from_type, relation_type_group, relation_type, to_id, to_type) |
|
||||
); |
|
||||
|
|
||||
CREATE TABLE IF NOT EXISTS tb_user ( |
|
||||
id uuid NOT NULL CONSTRAINT tb_user_pkey PRIMARY KEY, |
|
||||
created_time bigint NOT NULL, |
|
||||
additional_info varchar, |
|
||||
authority varchar(255), |
|
||||
customer_id uuid, |
|
||||
email varchar(255) UNIQUE, |
|
||||
first_name varchar(255), |
|
||||
last_name varchar(255), |
|
||||
search_text varchar(255), |
|
||||
tenant_id uuid |
|
||||
); |
|
||||
|
|
||||
CREATE TABLE IF NOT EXISTS tenant_profile ( |
|
||||
id uuid NOT NULL CONSTRAINT tenant_profile_pkey PRIMARY KEY, |
|
||||
created_time bigint NOT NULL, |
|
||||
name varchar(255), |
|
||||
profile_data jsonb, |
|
||||
description varchar, |
|
||||
search_text varchar(255), |
|
||||
is_default boolean, |
|
||||
isolated_tb_core boolean, |
|
||||
isolated_tb_rule_engine boolean, |
|
||||
CONSTRAINT tenant_profile_name_unq_key UNIQUE (name) |
|
||||
); |
|
||||
|
|
||||
CREATE TABLE IF NOT EXISTS tenant ( |
|
||||
id uuid NOT NULL CONSTRAINT tenant_pkey PRIMARY KEY, |
|
||||
created_time bigint NOT NULL, |
|
||||
additional_info varchar, |
|
||||
tenant_profile_id uuid NOT NULL, |
|
||||
address varchar, |
|
||||
address2 varchar, |
|
||||
city varchar(255), |
|
||||
country varchar(255), |
|
||||
email varchar(255), |
|
||||
phone varchar(255), |
|
||||
region varchar(255), |
|
||||
search_text varchar(255), |
|
||||
state varchar(255), |
|
||||
title varchar(255), |
|
||||
zip varchar(255), |
|
||||
CONSTRAINT fk_tenant_profile FOREIGN KEY (tenant_profile_id) REFERENCES tenant_profile(id) |
|
||||
); |
|
||||
|
|
||||
CREATE TABLE IF NOT EXISTS user_credentials ( |
|
||||
id uuid NOT NULL CONSTRAINT user_credentials_pkey PRIMARY KEY, |
|
||||
created_time bigint NOT NULL, |
|
||||
activate_token varchar(255) UNIQUE, |
|
||||
enabled boolean, |
|
||||
password varchar(255), |
|
||||
reset_token varchar(255) UNIQUE, |
|
||||
user_id uuid UNIQUE |
|
||||
); |
|
||||
|
|
||||
CREATE TABLE IF NOT EXISTS widget_type ( |
|
||||
id uuid NOT NULL CONSTRAINT widget_type_pkey PRIMARY KEY, |
|
||||
created_time bigint NOT NULL, |
|
||||
alias varchar(255), |
|
||||
bundle_alias varchar(255), |
|
||||
descriptor varchar(1000000), |
|
||||
name varchar(255), |
|
||||
tenant_id uuid, |
|
||||
image varchar(1000000), |
|
||||
description varchar(255) |
|
||||
); |
|
||||
|
|
||||
CREATE TABLE IF NOT EXISTS widgets_bundle ( |
|
||||
id uuid NOT NULL CONSTRAINT widgets_bundle_pkey PRIMARY KEY, |
|
||||
created_time bigint NOT NULL, |
|
||||
alias varchar(255), |
|
||||
search_text varchar(255), |
|
||||
tenant_id uuid, |
|
||||
title varchar(255), |
|
||||
image varchar(1000000), |
|
||||
description varchar(255) |
|
||||
); |
|
||||
|
|
||||
CREATE TABLE IF NOT EXISTS entity_view ( |
|
||||
id uuid NOT NULL CONSTRAINT entity_view_pkey PRIMARY KEY, |
|
||||
created_time bigint NOT NULL, |
|
||||
entity_id uuid, |
|
||||
entity_type varchar(255), |
|
||||
tenant_id uuid, |
|
||||
customer_id uuid, |
|
||||
type varchar(255), |
|
||||
name varchar(255), |
|
||||
keys varchar(10000000), |
|
||||
start_ts bigint, |
|
||||
end_ts bigint, |
|
||||
search_text varchar(255), |
|
||||
additional_info varchar |
|
||||
); |
|
||||
|
|
||||
CREATE TABLE IF NOT EXISTS ts_kv_latest ( |
|
||||
entity_id uuid NOT NULL, |
|
||||
key int NOT NULL, |
|
||||
ts bigint NOT NULL, |
|
||||
bool_v boolean, |
|
||||
str_v varchar(10000000), |
|
||||
long_v bigint, |
|
||||
dbl_v double precision, |
|
||||
json_v varchar(10000000), |
|
||||
CONSTRAINT ts_kv_latest_pkey PRIMARY KEY (entity_id, key) |
|
||||
); |
|
||||
|
|
||||
CREATE TABLE IF NOT EXISTS ts_kv_dictionary ( |
|
||||
key varchar(255) NOT NULL, |
|
||||
key_id int GENERATED BY DEFAULT AS IDENTITY(start with 0 increment by 1) UNIQUE, |
|
||||
CONSTRAINT ts_key_id_pkey PRIMARY KEY (key) |
|
||||
); |
|
||||
|
|
||||
CREATE TABLE IF NOT EXISTS oauth2_params ( |
|
||||
id uuid NOT NULL CONSTRAINT oauth2_params_pkey PRIMARY KEY, |
|
||||
enabled boolean, |
|
||||
tenant_id uuid, |
|
||||
created_time bigint NOT NULL |
|
||||
); |
|
||||
|
|
||||
CREATE TABLE IF NOT EXISTS oauth2_registration ( |
|
||||
id uuid NOT NULL CONSTRAINT oauth2_registration_pkey PRIMARY KEY, |
|
||||
oauth2_params_id uuid NOT NULL, |
|
||||
created_time bigint NOT NULL, |
|
||||
additional_info varchar, |
|
||||
client_id varchar(255), |
|
||||
client_secret varchar(2048), |
|
||||
authorization_uri varchar(255), |
|
||||
token_uri varchar(255), |
|
||||
scope varchar(255), |
|
||||
platforms varchar(255), |
|
||||
user_info_uri varchar(255), |
|
||||
user_name_attribute_name varchar(255), |
|
||||
jwk_set_uri varchar(255), |
|
||||
client_authentication_method varchar(255), |
|
||||
login_button_label varchar(255), |
|
||||
login_button_icon varchar(255), |
|
||||
allow_user_creation boolean, |
|
||||
activate_user boolean, |
|
||||
type varchar(31), |
|
||||
basic_email_attribute_key varchar(31), |
|
||||
basic_first_name_attribute_key varchar(31), |
|
||||
basic_last_name_attribute_key varchar(31), |
|
||||
basic_tenant_name_strategy varchar(31), |
|
||||
basic_tenant_name_pattern varchar(255), |
|
||||
basic_customer_name_pattern varchar(255), |
|
||||
basic_default_dashboard_name varchar(255), |
|
||||
basic_always_full_screen boolean, |
|
||||
custom_url varchar(255), |
|
||||
custom_username varchar(255), |
|
||||
custom_password varchar(255), |
|
||||
custom_send_token boolean, |
|
||||
CONSTRAINT fk_registration_oauth2_params FOREIGN KEY (oauth2_params_id) REFERENCES oauth2_params(id) ON DELETE CASCADE |
|
||||
); |
|
||||
|
|
||||
CREATE TABLE IF NOT EXISTS oauth2_domain ( |
|
||||
id uuid NOT NULL CONSTRAINT oauth2_domain_pkey PRIMARY KEY, |
|
||||
oauth2_params_id uuid NOT NULL, |
|
||||
created_time bigint NOT NULL, |
|
||||
domain_name varchar(255), |
|
||||
domain_scheme varchar(31), |
|
||||
CONSTRAINT fk_domain_oauth2_params FOREIGN KEY (oauth2_params_id) REFERENCES oauth2_params(id) ON DELETE CASCADE, |
|
||||
CONSTRAINT oauth2_domain_unq_key UNIQUE (oauth2_params_id, domain_name, domain_scheme) |
|
||||
); |
|
||||
|
|
||||
CREATE TABLE IF NOT EXISTS oauth2_mobile ( |
|
||||
id uuid NOT NULL CONSTRAINT oauth2_mobile_pkey PRIMARY KEY, |
|
||||
oauth2_params_id uuid NOT NULL, |
|
||||
created_time bigint NOT NULL, |
|
||||
pkg_name varchar(255), |
|
||||
app_secret varchar(2048), |
|
||||
CONSTRAINT fk_mobile_oauth2_params FOREIGN KEY (oauth2_params_id) REFERENCES oauth2_params(id) ON DELETE CASCADE, |
|
||||
CONSTRAINT oauth2_mobile_unq_key UNIQUE (oauth2_params_id, pkg_name) |
|
||||
); |
|
||||
|
|
||||
CREATE TABLE IF NOT EXISTS oauth2_client_registration_template ( |
|
||||
id uuid NOT NULL CONSTRAINT oauth2_client_registration_template_pkey PRIMARY KEY, |
|
||||
created_time bigint NOT NULL, |
|
||||
additional_info varchar, |
|
||||
provider_id varchar(255), |
|
||||
authorization_uri varchar(255), |
|
||||
token_uri varchar(255), |
|
||||
scope varchar(255), |
|
||||
user_info_uri varchar(255), |
|
||||
user_name_attribute_name varchar(255), |
|
||||
jwk_set_uri varchar(255), |
|
||||
client_authentication_method varchar(255), |
|
||||
type varchar(31), |
|
||||
basic_email_attribute_key varchar(31), |
|
||||
basic_first_name_attribute_key varchar(31), |
|
||||
basic_last_name_attribute_key varchar(31), |
|
||||
basic_tenant_name_strategy varchar(31), |
|
||||
basic_tenant_name_pattern varchar(255), |
|
||||
basic_customer_name_pattern varchar(255), |
|
||||
basic_default_dashboard_name varchar(255), |
|
||||
basic_always_full_screen boolean, |
|
||||
comment varchar, |
|
||||
login_button_icon varchar(255), |
|
||||
login_button_label varchar(255), |
|
||||
help_link varchar(255), |
|
||||
CONSTRAINT oauth2_template_provider_id_unq_key UNIQUE (provider_id) |
|
||||
); |
|
||||
|
|
||||
-- Deprecated |
|
||||
CREATE TABLE IF NOT EXISTS oauth2_client_registration_info ( |
|
||||
id uuid NOT NULL CONSTRAINT oauth2_client_registration_info_pkey PRIMARY KEY, |
|
||||
enabled boolean, |
|
||||
created_time bigint NOT NULL, |
|
||||
additional_info varchar, |
|
||||
client_id varchar(255), |
|
||||
client_secret varchar(255), |
|
||||
authorization_uri varchar(255), |
|
||||
token_uri varchar(255), |
|
||||
scope varchar(255), |
|
||||
user_info_uri varchar(255), |
|
||||
user_name_attribute_name varchar(255), |
|
||||
jwk_set_uri varchar(255), |
|
||||
client_authentication_method varchar(255), |
|
||||
login_button_label varchar(255), |
|
||||
login_button_icon varchar(255), |
|
||||
allow_user_creation boolean, |
|
||||
activate_user boolean, |
|
||||
type varchar(31), |
|
||||
basic_email_attribute_key varchar(31), |
|
||||
basic_first_name_attribute_key varchar(31), |
|
||||
basic_last_name_attribute_key varchar(31), |
|
||||
basic_tenant_name_strategy varchar(31), |
|
||||
basic_tenant_name_pattern varchar(255), |
|
||||
basic_customer_name_pattern varchar(255), |
|
||||
basic_default_dashboard_name varchar(255), |
|
||||
basic_always_full_screen boolean, |
|
||||
custom_url varchar(255), |
|
||||
custom_username varchar(255), |
|
||||
custom_password varchar(255), |
|
||||
custom_send_token boolean |
|
||||
); |
|
||||
|
|
||||
-- Deprecated |
|
||||
CREATE TABLE IF NOT EXISTS oauth2_client_registration ( |
|
||||
id uuid NOT NULL CONSTRAINT oauth2_client_registration_pkey PRIMARY KEY, |
|
||||
created_time bigint NOT NULL, |
|
||||
domain_name varchar(255), |
|
||||
domain_scheme varchar(31), |
|
||||
client_registration_info_id uuid |
|
||||
); |
|
||||
|
|
||||
CREATE TABLE IF NOT EXISTS api_usage_state ( |
|
||||
id uuid NOT NULL CONSTRAINT usage_record_pkey PRIMARY KEY, |
|
||||
created_time bigint NOT NULL, |
|
||||
tenant_id uuid, |
|
||||
entity_type varchar(32), |
|
||||
entity_id uuid, |
|
||||
transport varchar(32), |
|
||||
db_storage varchar(32), |
|
||||
re_exec varchar(32), |
|
||||
js_exec varchar(32), |
|
||||
email_exec varchar(32), |
|
||||
sms_exec varchar(32), |
|
||||
alarm_exec varchar(32), |
|
||||
CONSTRAINT api_usage_state_unq_key UNIQUE (tenant_id, entity_id) |
|
||||
); |
|
||||
|
|
||||
CREATE TABLE IF NOT EXISTS resource ( |
|
||||
id uuid NOT NULL CONSTRAINT resource_pkey PRIMARY KEY, |
|
||||
created_time bigint NOT NULL, |
|
||||
tenant_id uuid NOT NULL, |
|
||||
title varchar(255) NOT NULL, |
|
||||
resource_type varchar(32) NOT NULL, |
|
||||
resource_key varchar(255) NOT NULL, |
|
||||
search_text varchar(255), |
|
||||
file_name varchar(255) NOT NULL, |
|
||||
data varchar, |
|
||||
CONSTRAINT resource_unq_key UNIQUE (tenant_id, resource_type, resource_key) |
|
||||
); |
|
||||
|
|
||||
CREATE TABLE IF NOT EXISTS edge ( |
|
||||
id uuid NOT NULL CONSTRAINT edge_pkey PRIMARY KEY, |
|
||||
created_time bigint NOT NULL, |
|
||||
additional_info varchar, |
|
||||
customer_id uuid, |
|
||||
root_rule_chain_id uuid, |
|
||||
type varchar(255), |
|
||||
name varchar(255), |
|
||||
label varchar(255), |
|
||||
routing_key varchar(255), |
|
||||
secret varchar(255), |
|
||||
edge_license_key varchar(30), |
|
||||
cloud_endpoint varchar(255), |
|
||||
search_text varchar(255), |
|
||||
tenant_id uuid, |
|
||||
CONSTRAINT edge_name_unq_key UNIQUE (tenant_id, name), |
|
||||
CONSTRAINT edge_routing_key_unq_key UNIQUE (routing_key) |
|
||||
); |
|
||||
|
|
||||
CREATE TABLE IF NOT EXISTS edge_event ( |
|
||||
id uuid NOT NULL CONSTRAINT edge_event_pkey PRIMARY KEY, |
|
||||
created_time bigint NOT NULL, |
|
||||
edge_id uuid, |
|
||||
edge_event_type varchar(255), |
|
||||
edge_event_uid varchar(255), |
|
||||
entity_id uuid, |
|
||||
edge_event_action varchar(255), |
|
||||
body varchar(10000000), |
|
||||
tenant_id uuid, |
|
||||
ts bigint NOT NULL |
|
||||
); |
|
||||
|
|
||||
CREATE TABLE IF NOT EXISTS rpc ( |
|
||||
id uuid NOT NULL CONSTRAINT rpc_pkey PRIMARY KEY, |
|
||||
created_time bigint NOT NULL, |
|
||||
tenant_id uuid NOT NULL, |
|
||||
device_id uuid NOT NULL, |
|
||||
expiration_time bigint NOT NULL, |
|
||||
request varchar(10000000) NOT NULL, |
|
||||
response varchar(10000000), |
|
||||
additional_info varchar(10000000), |
|
||||
status varchar(255) NOT NULL |
|
||||
); |
|
||||
@ -1,41 +0,0 @@ |
|||||
-- |
|
||||
-- Copyright © 2016-2022 The Thingsboard Authors |
|
||||
-- |
|
||||
-- Licensed under the Apache License, Version 2.0 (the "License"); |
|
||||
-- you may not use this file except in compliance with the License. |
|
||||
-- You may obtain a copy of the License at |
|
||||
-- |
|
||||
-- http://www.apache.org/licenses/LICENSE-2.0 |
|
||||
-- |
|
||||
-- Unless required by applicable law or agreed to in writing, software |
|
||||
-- distributed under the License is distributed on an "AS IS" BASIS, |
|
||||
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
||||
-- See the License for the specific language governing permissions and |
|
||||
-- limitations under the License. |
|
||||
-- |
|
||||
|
|
||||
SET DATABASE SQL SYNTAX PGS TRUE; |
|
||||
SET DATABASE TRANSACTION CONTROL MVCC; |
|
||||
|
|
||||
CREATE TABLE IF NOT EXISTS ts_kv ( |
|
||||
entity_id uuid NOT NULL, |
|
||||
key int NOT NULL, |
|
||||
ts bigint NOT NULL, |
|
||||
bool_v boolean, |
|
||||
str_v varchar(10000000), |
|
||||
long_v bigint, |
|
||||
dbl_v double precision, |
|
||||
json_v varchar(10000000), |
|
||||
CONSTRAINT ts_kv_pkey PRIMARY KEY (entity_id, key, ts) |
|
||||
); |
|
||||
|
|
||||
CREATE TABLE IF NOT EXISTS ts_kv_dictionary ( |
|
||||
key varchar(255) NOT NULL, |
|
||||
key_id int GENERATED BY DEFAULT AS IDENTITY(start with 0 increment by 1) UNIQUE, |
|
||||
CONSTRAINT ts_key_id_pkey PRIMARY KEY (key) |
|
||||
); |
|
||||
|
|
||||
CREATE FUNCTION to_uuid(IN entity_id varchar) |
|
||||
RETURNS UUID |
|
||||
RETURN UUID(substring(entity_id, 8, 8) || '-' || substring(entity_id, 4, 4) || '-1' || substring(entity_id, 1, 3) || |
|
||||
'-' || substring(entity_id, 16, 4) || '-' || substring(entity_id, 20, 12)); |
|
||||
@ -1,20 +0,0 @@ |
|||||
-- |
|
||||
-- Copyright © 2016-2022 The Thingsboard Authors |
|
||||
-- |
|
||||
-- Licensed under the Apache License, Version 2.0 (the "License"); |
|
||||
-- you may not use this file except in compliance with the License. |
|
||||
-- You may obtain a copy of the License at |
|
||||
-- |
|
||||
-- http://www.apache.org/licenses/LICENSE-2.0 |
|
||||
-- |
|
||||
-- Unless required by applicable law or agreed to in writing, software |
|
||||
-- distributed under the License is distributed on an "AS IS" BASIS, |
|
||||
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
||||
-- See the License for the specific language governing permissions and |
|
||||
-- limitations under the License. |
|
||||
-- |
|
||||
|
|
||||
DROP TYPE json IF EXISTS; |
|
||||
CREATE TYPE json AS varchar; |
|
||||
DROP TYPE jsonb IF EXISTS; |
|
||||
CREATE TYPE jsonb AS other; |
|
||||
File diff suppressed because one or more lines are too long
@ -0,0 +1,163 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2022 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.rule.engine.geo; |
||||
|
|
||||
|
import org.junit.Assert; |
||||
|
import org.junit.Test; |
||||
|
import org.junit.runner.RunWith; |
||||
|
import org.mockito.junit.MockitoJUnitRunner; |
||||
|
|
||||
|
@RunWith(MockitoJUnitRunner.class) |
||||
|
public class TbGeoUtilTest { |
||||
|
|
||||
|
public static final String SIMPLE_RECT = "[[51.903762928405555,23.642220786948297],[44.669801219635644,41.83345155830211]]"; |
||||
|
public static final String SIMPLE_RECT_WITH_HOLE_IN_CENTER = "[[[44.66980121963565,23.642220786948297],[44.66980121963565,41.83345155830211],[51.903762928405555,41.83345155830211],[51.903762928405555,23.642220786948297]],[[46.10464044504632,26.234282119122227],[50.8755868028522,26.25625220459488],[51.04164771375101,38.5595000692786],[45.99790855491869,38.75723083853248]]]"; |
||||
|
public static final String SAND_CLOCK = "[[47.45865912532852,25.531200822337155],[49.76760268310416,29.353995694578202],[51.42691963936519,25.355440138555966],[51.413219087617655,39.41629484105169],[49.78179072754938,33.37452133607305],[47.81395478511215,38.867042704235466]]"; |
||||
|
public static final String SAND_CLOCK_WITH_HOLE_IN_CENTER = "[[[51.426919639365195,25.355440138555966],[49.76760268310416,29.353995694578202],[47.45865912532852,25.531200822337155],[47.81395478511215,38.867042704235466],[49.78179072754938,33.37452133607305],[51.413219087617655,39.41629484105169]],[[49.8243299406579,30.210829028011513],[50.34591034217041,31.04569227597222],[49.56853374046142,32.53965808811239],[49.02409241675058,31.57297432731579]]]"; |
||||
|
public static final String SELF_INTERSECTING = "[[47.42893833699058,27.178954662008522],[51.71367987390804,37.46095466320854],[51.659197648757306,27.947907653551276],[47.41407351681856,37.46095466320854]]"; |
||||
|
public static final String SELF_INTERSECTING_WITH_HOLES = "[[[[47.42893833699058,27.17895466200852],[47.41407351681856,37.46095466320853],[49.63741575793274,32.47858934221699]],[[47.84342032696093,29.20045703244998],[49.124803688667576,32.38611942598416],[47.858163521459254,34.714948486085035]]],[[[51.659197648757306,27.947907653551276],[49.63741575793274,32.47858934221699],[51.71367987390804,37.46095466320853]],[[51.20718653775245,30.738363015535448],[51.317169097567344,34.58312797324915],[50.1351109330126,32.51793993882006]]]]"; |
||||
|
|
||||
|
public static final Coordinates POINT_INSIDE_SIMPLE_RECT_CENTER = new Coordinates(48.37082198780869, 32.673342414527355); |
||||
|
public static final Coordinates POINT_INSIDE_SIMPLE_RECT_NEAR_BORDER = new Coordinates(48.42916753187315,40.956064637716224); |
||||
|
public static final Coordinates POINT_OUTSIDE_SIMPLE_RECT = new Coordinates(52.94806646045028,32.91501335472649); |
||||
|
public static final Coordinates POINT_INSIDE_SAND_CLOCK_CENTER = new Coordinates(49.993588800145105,31.289062500000004); |
||||
|
public static final Coordinates POINT_INSIDE_SAND_CLOCK_NEAR_BORDER = new Coordinates(47.798651123976306,26.895045405470082); |
||||
|
public static final Coordinates POINT_OUTSIDE_SAND_CLOCK_1 = new Coordinates(49.553754212665936,28.03748985004787); |
||||
|
public static final Coordinates POINT_OUTSIDE_SAND_CLOCK_2 = new Coordinates(46.9802466961145,32.321728498980335); |
||||
|
public static final Coordinates POINT_INSIDE_SELF_INTERSECTING_UPPER_CENTER = new Coordinates(50.750366308834884,32.51952867922265); |
||||
|
public static final Coordinates POINT_INSIDE_SELF_INTERSECTING_LOWER_CENTER = new Coordinates(48.1371117277312,32.40967825185941); |
||||
|
public static final Coordinates POINT_INSIDE_SELF_INTERSECTING_NEAR_BORDER = new Coordinates(51.16552151942722,35.66125090181154); |
||||
|
public static final Coordinates POINT_OUTSIDE_SELF_INTERSECTING_1= new Coordinates(49.66777277299077,33.26651158529272); |
||||
|
public static final Coordinates POINT_OUTSIDE_SELF_INTERSECTING_2 = new Coordinates(47.10052840114779,32.16800731166027); |
||||
|
public static final Coordinates POINT_OUTSIDE_SELF_INTERSECTING_3 = new Coordinates(78.76578380252519,15.646485040786361); |
||||
|
|
||||
|
|
||||
|
@Test |
||||
|
public void testPointsInSimplePolygons() { |
||||
|
Assert.assertTrue("Polygon " + SIMPLE_RECT + " must contain the dot " + POINT_INSIDE_SIMPLE_RECT_CENTER, |
||||
|
GeoUtil.contains(SIMPLE_RECT, POINT_INSIDE_SIMPLE_RECT_CENTER) |
||||
|
); |
||||
|
Assert.assertTrue("Polygon " + SIMPLE_RECT + " must contain the dot " + POINT_INSIDE_SIMPLE_RECT_NEAR_BORDER, |
||||
|
GeoUtil.contains(SIMPLE_RECT, POINT_INSIDE_SIMPLE_RECT_NEAR_BORDER) |
||||
|
); |
||||
|
Assert.assertTrue("Polygon " + SIMPLE_RECT_WITH_HOLE_IN_CENTER + " must contain the dot " |
||||
|
+ POINT_INSIDE_SIMPLE_RECT_NEAR_BORDER, |
||||
|
GeoUtil.contains(SIMPLE_RECT_WITH_HOLE_IN_CENTER, POINT_INSIDE_SIMPLE_RECT_NEAR_BORDER) |
||||
|
); |
||||
|
|
||||
|
Assert.assertFalse("Polygon " + SIMPLE_RECT + " must not contain the dot " |
||||
|
+ POINT_OUTSIDE_SIMPLE_RECT, |
||||
|
GeoUtil.contains(SIMPLE_RECT, POINT_OUTSIDE_SIMPLE_RECT) |
||||
|
); |
||||
|
Assert.assertFalse("Polygon " + SIMPLE_RECT_WITH_HOLE_IN_CENTER + " must not contain the dot " |
||||
|
+ POINT_OUTSIDE_SIMPLE_RECT, |
||||
|
GeoUtil.contains(SIMPLE_RECT_WITH_HOLE_IN_CENTER, POINT_OUTSIDE_SIMPLE_RECT) |
||||
|
); |
||||
|
Assert.assertFalse("Polygon " + SIMPLE_RECT_WITH_HOLE_IN_CENTER + " must not contain the dot " |
||||
|
+ POINT_INSIDE_SIMPLE_RECT_CENTER, |
||||
|
GeoUtil.contains(SIMPLE_RECT_WITH_HOLE_IN_CENTER, POINT_INSIDE_SIMPLE_RECT_CENTER) |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
@Test |
||||
|
public void testPointsInComplexPolygons() { |
||||
|
Assert.assertTrue("Polygon " + SAND_CLOCK + " must contain the dot " + POINT_INSIDE_SAND_CLOCK_CENTER, |
||||
|
GeoUtil.contains(SAND_CLOCK, POINT_INSIDE_SAND_CLOCK_CENTER) |
||||
|
); |
||||
|
Assert.assertTrue("Polygon " + SAND_CLOCK + " must contain the dot " + POINT_INSIDE_SAND_CLOCK_NEAR_BORDER, |
||||
|
GeoUtil.contains(SAND_CLOCK, POINT_INSIDE_SAND_CLOCK_NEAR_BORDER) |
||||
|
); |
||||
|
Assert.assertTrue("Polygon " + SAND_CLOCK_WITH_HOLE_IN_CENTER + " must contain the dot " |
||||
|
+ POINT_INSIDE_SAND_CLOCK_NEAR_BORDER, |
||||
|
GeoUtil.contains(SAND_CLOCK_WITH_HOLE_IN_CENTER, POINT_INSIDE_SAND_CLOCK_NEAR_BORDER) |
||||
|
); |
||||
|
|
||||
|
Assert.assertFalse("Polygon " + SAND_CLOCK + " must not contain the dot " |
||||
|
+ POINT_OUTSIDE_SAND_CLOCK_1, |
||||
|
GeoUtil.contains(SAND_CLOCK, POINT_OUTSIDE_SAND_CLOCK_1) |
||||
|
); |
||||
|
Assert.assertFalse("Polygon " + SAND_CLOCK + " must not contain the dot " |
||||
|
+ POINT_OUTSIDE_SAND_CLOCK_2, |
||||
|
GeoUtil.contains(SAND_CLOCK, POINT_OUTSIDE_SAND_CLOCK_2) |
||||
|
); |
||||
|
Assert.assertFalse("Polygon " + SAND_CLOCK_WITH_HOLE_IN_CENTER + " must not contain the dot " |
||||
|
+ POINT_INSIDE_SAND_CLOCK_CENTER, |
||||
|
GeoUtil.contains(SAND_CLOCK_WITH_HOLE_IN_CENTER, POINT_INSIDE_SAND_CLOCK_CENTER) |
||||
|
); |
||||
|
Assert.assertFalse("Polygon " + SAND_CLOCK_WITH_HOLE_IN_CENTER + " must not contain the dot " |
||||
|
+ POINT_OUTSIDE_SAND_CLOCK_1, |
||||
|
GeoUtil.contains(SAND_CLOCK_WITH_HOLE_IN_CENTER, POINT_OUTSIDE_SAND_CLOCK_1) |
||||
|
); |
||||
|
Assert.assertFalse("Polygon " + SAND_CLOCK_WITH_HOLE_IN_CENTER + " must not contain the dot " |
||||
|
+ POINT_OUTSIDE_SAND_CLOCK_2, |
||||
|
GeoUtil.contains(SAND_CLOCK_WITH_HOLE_IN_CENTER, POINT_OUTSIDE_SAND_CLOCK_2) |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
@Test |
||||
|
public void testPointsInSelfIntersectingPolygons() { |
||||
|
Assert.assertTrue("Polygon " + SELF_INTERSECTING + " must contain the dot " |
||||
|
+ POINT_INSIDE_SELF_INTERSECTING_UPPER_CENTER, |
||||
|
GeoUtil.contains(SELF_INTERSECTING, POINT_INSIDE_SELF_INTERSECTING_UPPER_CENTER) |
||||
|
); |
||||
|
Assert.assertTrue("Polygon " + SELF_INTERSECTING + " must contain the dot " |
||||
|
+ POINT_INSIDE_SELF_INTERSECTING_LOWER_CENTER, |
||||
|
GeoUtil.contains(SELF_INTERSECTING, POINT_INSIDE_SELF_INTERSECTING_LOWER_CENTER) |
||||
|
); |
||||
|
Assert.assertTrue("Polygon " + SELF_INTERSECTING + " must contain the dot " |
||||
|
+ POINT_INSIDE_SELF_INTERSECTING_NEAR_BORDER, |
||||
|
GeoUtil.contains(SELF_INTERSECTING, POINT_INSIDE_SELF_INTERSECTING_NEAR_BORDER) |
||||
|
); |
||||
|
Assert.assertTrue("Polygon " + SELF_INTERSECTING_WITH_HOLES + " must contain the dot " |
||||
|
+ POINT_INSIDE_SAND_CLOCK_NEAR_BORDER, |
||||
|
GeoUtil.contains(SELF_INTERSECTING_WITH_HOLES, POINT_INSIDE_SELF_INTERSECTING_NEAR_BORDER) |
||||
|
); |
||||
|
|
||||
|
Assert.assertFalse("Polygon " + SELF_INTERSECTING + " must not contain the dot " |
||||
|
+ POINT_OUTSIDE_SELF_INTERSECTING_1, |
||||
|
GeoUtil.contains(SELF_INTERSECTING, POINT_OUTSIDE_SELF_INTERSECTING_1) |
||||
|
); |
||||
|
Assert.assertFalse("Polygon " + SELF_INTERSECTING + " must not contain the dot " |
||||
|
+ POINT_OUTSIDE_SELF_INTERSECTING_2, |
||||
|
GeoUtil.contains(SELF_INTERSECTING, POINT_OUTSIDE_SELF_INTERSECTING_2) |
||||
|
); |
||||
|
Assert.assertFalse("Polygon " + SELF_INTERSECTING + " must not contain the dot " |
||||
|
+ POINT_OUTSIDE_SELF_INTERSECTING_3, |
||||
|
GeoUtil.contains(SELF_INTERSECTING, POINT_OUTSIDE_SELF_INTERSECTING_3) |
||||
|
); |
||||
|
Assert.assertFalse("Polygon " + SELF_INTERSECTING_WITH_HOLES + " must not contain the dot " |
||||
|
+ POINT_OUTSIDE_SELF_INTERSECTING_1, |
||||
|
GeoUtil.contains(SELF_INTERSECTING_WITH_HOLES, POINT_OUTSIDE_SELF_INTERSECTING_1) |
||||
|
); |
||||
|
Assert.assertFalse("Polygon " + SELF_INTERSECTING_WITH_HOLES + " must not contain the dot " |
||||
|
+ POINT_OUTSIDE_SELF_INTERSECTING_2, |
||||
|
GeoUtil.contains(SELF_INTERSECTING_WITH_HOLES, POINT_OUTSIDE_SELF_INTERSECTING_2) |
||||
|
); |
||||
|
Assert.assertFalse("Polygon " + SELF_INTERSECTING_WITH_HOLES + " must not contain the dot " |
||||
|
+ POINT_OUTSIDE_SELF_INTERSECTING_3, |
||||
|
GeoUtil.contains(SELF_INTERSECTING_WITH_HOLES, POINT_OUTSIDE_SELF_INTERSECTING_3) |
||||
|
); |
||||
|
Assert.assertFalse("Polygon " + SELF_INTERSECTING_WITH_HOLES + " must not contain the dot " |
||||
|
+ POINT_INSIDE_SELF_INTERSECTING_UPPER_CENTER, |
||||
|
GeoUtil.contains(SELF_INTERSECTING_WITH_HOLES, POINT_INSIDE_SELF_INTERSECTING_UPPER_CENTER) |
||||
|
); |
||||
|
Assert.assertFalse("Polygon " + SELF_INTERSECTING_WITH_HOLES + " must not contain the dot " |
||||
|
+ POINT_INSIDE_SELF_INTERSECTING_LOWER_CENTER, |
||||
|
GeoUtil.contains(SELF_INTERSECTING_WITH_HOLES, POINT_INSIDE_SELF_INTERSECTING_LOWER_CENTER) |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,19 @@ |
|||||
|
///
|
||||
|
/// Copyright © 2016-2022 The Thingsboard Authors
|
||||
|
///
|
||||
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
/// you may not use this file except in compliance with the License.
|
||||
|
/// You may obtain a copy of the License at
|
||||
|
///
|
||||
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
///
|
||||
|
/// Unless required by applicable law or agreed to in writing, software
|
||||
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
/// See the License for the specific language governing permissions and
|
||||
|
/// limitations under the License.
|
||||
|
///
|
||||
|
|
||||
|
export interface IEntityDetailsPageComponent { |
||||
|
reload(): void; |
||||
|
} |
||||
@ -0,0 +1,37 @@ |
|||||
|
///
|
||||
|
/// Copyright © 2016-2022 The Thingsboard Authors
|
||||
|
///
|
||||
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
/// you may not use this file except in compliance with the License.
|
||||
|
/// You may obtain a copy of the License at
|
||||
|
///
|
||||
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
///
|
||||
|
/// Unless required by applicable law or agreed to in writing, software
|
||||
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
/// See the License for the specific language governing permissions and
|
||||
|
/// limitations under the License.
|
||||
|
///
|
||||
|
|
||||
|
import { Pipe, PipeTransform } from '@angular/core'; |
||||
|
import { DomSanitizer, SafeHtml, SafeStyle, SafeScript, SafeUrl, SafeResourceUrl } from '@angular/platform-browser'; |
||||
|
|
||||
|
@Pipe({ |
||||
|
name: 'safe' |
||||
|
}) |
||||
|
export class SafePipe implements PipeTransform { |
||||
|
|
||||
|
constructor(protected sanitizer: DomSanitizer) {} |
||||
|
|
||||
|
public transform(value: any, type: string): SafeHtml | SafeStyle | SafeScript | SafeUrl | SafeResourceUrl { |
||||
|
switch (type) { |
||||
|
case 'html': return this.sanitizer.bypassSecurityTrustHtml(value); |
||||
|
case 'style': return this.sanitizer.bypassSecurityTrustStyle(value); |
||||
|
case 'script': return this.sanitizer.bypassSecurityTrustScript(value); |
||||
|
case 'url': return this.sanitizer.bypassSecurityTrustUrl(value); |
||||
|
case 'resourceUrl': return this.sanitizer.bypassSecurityTrustResourceUrl(value); |
||||
|
default: throw new Error(`Invalid safe type specified: ${type}`); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue