103 changed files with 214 additions and 8423 deletions
@ -1,30 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.NoSqlDao; |
|||
|
|||
@Service |
|||
@NoSqlDao |
|||
@Profile("install") |
|||
public class CassandraEntityDatabaseSchemaService extends CassandraAbstractDatabaseSchemaService |
|||
implements EntityDatabaseSchemaService { |
|||
public CassandraEntityDatabaseSchemaService() { |
|||
super("schema-entities.cql"); |
|||
} |
|||
} |
|||
@ -1,40 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.controller; |
|||
|
|||
import org.cassandraunit.dataset.cql.ClassPathCQLDataSet; |
|||
import org.junit.ClassRule; |
|||
import org.junit.extensions.cpsuite.ClasspathSuite; |
|||
import org.junit.runner.RunWith; |
|||
import org.thingsboard.server.dao.CustomCassandraCQLUnit; |
|||
|
|||
import java.util.Arrays; |
|||
|
|||
@RunWith(ClasspathSuite.class) |
|||
@ClasspathSuite.ClassnameFilters({ |
|||
"org.thingsboard.server.controller.nosql.*Test"}) |
|||
public class ControllerNoSqlTestSuite { |
|||
|
|||
@ClassRule |
|||
public static CustomCassandraCQLUnit cassandraUnit = |
|||
new CustomCassandraCQLUnit( |
|||
Arrays.asList( |
|||
new ClassPathCQLDataSet("cassandra/schema-ts.cql", false, false), |
|||
new ClassPathCQLDataSet("cassandra/schema-entities.cql", false, false), |
|||
new ClassPathCQLDataSet("cassandra/system-data.cql", false, false), |
|||
new ClassPathCQLDataSet("cassandra/system-test.cql", false, false)), |
|||
"cassandra-test.yaml", 30000l); |
|||
} |
|||
@ -1,26 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.controller.nosql; |
|||
|
|||
import org.thingsboard.server.controller.BaseAdminControllerTest; |
|||
import org.thingsboard.server.dao.service.DaoNoSqlTest; |
|||
|
|||
/** |
|||
* Created by Valerii Sosliuk on 6/28/2017. |
|||
*/ |
|||
@DaoNoSqlTest |
|||
public class AdminControllerNoSqlTest extends BaseAdminControllerTest { |
|||
} |
|||
@ -1,27 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.controller.nosql; |
|||
|
|||
import org.thingsboard.server.controller.BaseAssetControllerTest; |
|||
import org.thingsboard.server.dao.service.DaoNoSqlTest; |
|||
import org.thingsboard.server.dao.util.NoSqlDao; |
|||
|
|||
/** |
|||
* Created by Valerii Sosliuk on 6/28/2017. |
|||
*/ |
|||
@DaoNoSqlTest |
|||
public class AssetControllerNoSqlTest extends BaseAssetControllerTest { |
|||
} |
|||
@ -1,23 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.controller.nosql; |
|||
|
|||
import org.thingsboard.server.controller.BaseAuditLogControllerTest; |
|||
import org.thingsboard.server.dao.service.DaoNoSqlTest; |
|||
|
|||
@DaoNoSqlTest |
|||
public class AuditLogControllerNoSqlTest extends BaseAuditLogControllerTest { |
|||
} |
|||
@ -1,26 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.controller.nosql; |
|||
|
|||
import org.thingsboard.server.controller.BaseAuthControllerTest; |
|||
import org.thingsboard.server.dao.service.DaoNoSqlTest; |
|||
|
|||
/** |
|||
* Created by Valerii Sosliuk on 6/28/2017. |
|||
*/ |
|||
@DaoNoSqlTest |
|||
public class AuthControllerNoSqlTest extends BaseAuthControllerTest { |
|||
} |
|||
@ -1,26 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.controller.nosql; |
|||
|
|||
import org.thingsboard.server.controller.BaseComponentDescriptorControllerTest; |
|||
import org.thingsboard.server.dao.service.DaoNoSqlTest; |
|||
|
|||
/** |
|||
* Created by Valerii Sosliuk on 6/28/2017. |
|||
*/ |
|||
@DaoNoSqlTest |
|||
public class ComponentDescriptorControllerNoSqlTest extends BaseComponentDescriptorControllerTest { |
|||
} |
|||
@ -1,26 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.controller.nosql; |
|||
|
|||
import org.thingsboard.server.controller.BaseCustomerControllerTest; |
|||
import org.thingsboard.server.dao.service.DaoNoSqlTest; |
|||
|
|||
/** |
|||
* Created by Valerii Sosliuk on 6/28/2017. |
|||
*/ |
|||
@DaoNoSqlTest |
|||
public class CustomerControllerNoSqlTest extends BaseCustomerControllerTest { |
|||
} |
|||
@ -1,26 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.controller.nosql; |
|||
|
|||
import org.thingsboard.server.controller.BaseDashboardControllerTest; |
|||
import org.thingsboard.server.dao.service.DaoNoSqlTest; |
|||
|
|||
/** |
|||
* Created by Valerii Sosliuk on 6/28/2017. |
|||
*/ |
|||
@DaoNoSqlTest |
|||
public class DashboardControllerNoSqlTest extends BaseDashboardControllerTest { |
|||
} |
|||
@ -1,26 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.controller.nosql; |
|||
|
|||
import org.thingsboard.server.controller.BaseDeviceControllerTest; |
|||
import org.thingsboard.server.dao.service.DaoNoSqlTest; |
|||
|
|||
/** |
|||
* Created by Valerii Sosliuk on 6/28/2017. |
|||
*/ |
|||
@DaoNoSqlTest |
|||
public class DeviceControllerNoSqlTest extends BaseDeviceControllerTest { |
|||
} |
|||
@ -1,26 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.controller.nosql; |
|||
|
|||
import org.thingsboard.server.controller.BaseEntityViewControllerTest; |
|||
import org.thingsboard.server.dao.service.DaoNoSqlTest; |
|||
|
|||
/** |
|||
* Created by Victor Basanets on 8/27/2017. |
|||
*/ |
|||
@DaoNoSqlTest |
|||
public class EntityViewControllerNoSqlTest extends BaseEntityViewControllerTest { |
|||
} |
|||
@ -1,26 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.controller.nosql; |
|||
|
|||
import org.thingsboard.server.controller.BaseTenantControllerTest; |
|||
import org.thingsboard.server.dao.service.DaoNoSqlTest; |
|||
|
|||
/** |
|||
* Created by Valerii Sosliuk on 6/28/2017. |
|||
*/ |
|||
@DaoNoSqlTest |
|||
public class TenantControllerNoSqlTest extends BaseTenantControllerTest { |
|||
} |
|||
@ -1,26 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.controller.nosql; |
|||
|
|||
import org.thingsboard.server.controller.BaseUserControllerTest; |
|||
import org.thingsboard.server.dao.service.DaoNoSqlTest; |
|||
|
|||
/** |
|||
* Created by Valerii Sosliuk on 6/28/2017. |
|||
*/ |
|||
@DaoNoSqlTest |
|||
public class UserControllerNoSqlTest extends BaseUserControllerTest { |
|||
} |
|||
@ -1,26 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.controller.nosql; |
|||
|
|||
import org.thingsboard.server.controller.BaseWidgetTypeControllerTest; |
|||
import org.thingsboard.server.dao.service.DaoNoSqlTest; |
|||
|
|||
/** |
|||
* Created by Valerii Sosliuk on 6/28/2017. |
|||
*/ |
|||
@DaoNoSqlTest |
|||
public class WidgetTypeControllerNoSqlTest extends BaseWidgetTypeControllerTest { |
|||
} |
|||
@ -1,26 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.controller.nosql; |
|||
|
|||
import org.thingsboard.server.controller.BaseWidgetsBundleControllerTest; |
|||
import org.thingsboard.server.dao.service.DaoNoSqlTest; |
|||
|
|||
/** |
|||
* Created by Valerii Sosliuk on 6/28/2017. |
|||
*/ |
|||
@DaoNoSqlTest |
|||
public class WidgetsBundleControllerNoSqlTest extends BaseWidgetsBundleControllerTest { |
|||
} |
|||
@ -1,43 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.rules; |
|||
|
|||
import org.cassandraunit.dataset.cql.ClassPathCQLDataSet; |
|||
import org.junit.ClassRule; |
|||
import org.junit.extensions.cpsuite.ClasspathSuite; |
|||
import org.junit.runner.RunWith; |
|||
import org.thingsboard.server.dao.CustomCassandraCQLUnit; |
|||
import org.thingsboard.server.dao.CustomSqlUnit; |
|||
|
|||
import java.util.Arrays; |
|||
|
|||
@RunWith(ClasspathSuite.class) |
|||
@ClasspathSuite.ClassnameFilters({ |
|||
"org.thingsboard.server.rules.flow.nosql.*Test", |
|||
"org.thingsboard.server.rules.lifecycle.nosql.*Test" |
|||
}) |
|||
public class RuleEngineNoSqlTestSuite { |
|||
|
|||
@ClassRule |
|||
public static CustomCassandraCQLUnit cassandraUnit = |
|||
new CustomCassandraCQLUnit( |
|||
Arrays.asList( |
|||
new ClassPathCQLDataSet("cassandra/schema-ts.cql", false, false), |
|||
new ClassPathCQLDataSet("cassandra/schema-entities.cql", false, false), |
|||
new ClassPathCQLDataSet("cassandra/system-data.cql", false, false)), |
|||
"cassandra-test.yaml", 30000l); |
|||
|
|||
} |
|||
@ -1,26 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.rules.flow.nosql; |
|||
|
|||
import org.thingsboard.server.dao.service.DaoNoSqlTest; |
|||
import org.thingsboard.server.rules.flow.AbstractRuleEngineFlowIntegrationTest; |
|||
|
|||
/** |
|||
* Created by Valerii Sosliuk on 8/22/2017. |
|||
*/ |
|||
@DaoNoSqlTest |
|||
public class RuleEngineFlowNoSqlIntegrationTest extends AbstractRuleEngineFlowIntegrationTest { |
|||
} |
|||
@ -1,26 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.rules.lifecycle.nosql; |
|||
|
|||
import org.thingsboard.server.dao.service.DaoNoSqlTest; |
|||
import org.thingsboard.server.rules.lifecycle.AbstractRuleEngineLifecycleIntegrationTest; |
|||
|
|||
/** |
|||
* Created by Valerii Sosliuk on 8/22/2017. |
|||
*/ |
|||
@DaoNoSqlTest |
|||
public class RuleEngineLifecycleNoSqlIntegrationTest extends AbstractRuleEngineLifecycleIntegrationTest { |
|||
} |
|||
@ -1,41 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.system; |
|||
|
|||
import org.cassandraunit.dataset.cql.ClassPathCQLDataSet; |
|||
import org.junit.ClassRule; |
|||
import org.junit.extensions.cpsuite.ClasspathSuite; |
|||
import org.junit.runner.RunWith; |
|||
import org.thingsboard.server.dao.CustomCassandraCQLUnit; |
|||
|
|||
import java.util.Arrays; |
|||
|
|||
/** |
|||
* @author Andrew Shvayka |
|||
*/ |
|||
@RunWith(ClasspathSuite.class) |
|||
@ClasspathSuite.ClassnameFilters({"org.thingsboard.server.system.*NoSqlTest"}) |
|||
public class SystemNoSqlTestSuite { |
|||
|
|||
@ClassRule |
|||
public static CustomCassandraCQLUnit cassandraUnit = |
|||
new CustomCassandraCQLUnit( |
|||
Arrays.asList( |
|||
new ClassPathCQLDataSet("cassandra/schema-ts.cql", false, false), |
|||
new ClassPathCQLDataSet("cassandra/schema-entities.cql", false, false), |
|||
new ClassPathCQLDataSet("cassandra/system-data.cql", false, false)), |
|||
"cassandra-test.yaml", 30000l); |
|||
} |
|||
@ -1,27 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.system.nosql; |
|||
|
|||
import org.thingsboard.server.dao.service.DaoNoSqlTest; |
|||
import org.thingsboard.server.dao.util.NoSqlDao; |
|||
import org.thingsboard.server.system.BaseHttpDeviceApiTest; |
|||
|
|||
/** |
|||
* Created by Valerii Sosliuk on 6/27/2017. |
|||
*/ |
|||
@DaoNoSqlTest |
|||
public class DeviceApiNoSqlTest extends BaseHttpDeviceApiTest { |
|||
} |
|||
@ -1,139 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.alarm; |
|||
|
|||
import com.datastax.driver.core.Statement; |
|||
import com.datastax.driver.core.querybuilder.QueryBuilder; |
|||
import com.datastax.driver.core.querybuilder.Select; |
|||
import com.google.common.util.concurrent.Futures; |
|||
import com.google.common.util.concurrent.ListenableFuture; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.common.data.EntityType; |
|||
import org.thingsboard.server.common.data.alarm.Alarm; |
|||
import org.thingsboard.server.common.data.alarm.AlarmInfo; |
|||
import org.thingsboard.server.common.data.alarm.AlarmQuery; |
|||
import org.thingsboard.server.common.data.alarm.AlarmSearchStatus; |
|||
import org.thingsboard.server.common.data.id.EntityId; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.relation.EntityRelation; |
|||
import org.thingsboard.server.common.data.relation.RelationTypeGroup; |
|||
import org.thingsboard.server.dao.model.ModelConstants; |
|||
import org.thingsboard.server.dao.model.nosql.AlarmEntity; |
|||
import org.thingsboard.server.dao.nosql.CassandraAbstractModelDao; |
|||
import org.thingsboard.server.dao.relation.RelationDao; |
|||
import org.thingsboard.server.dao.util.NoSqlDao; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
import java.util.UUID; |
|||
|
|||
import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; |
|||
import static com.datastax.driver.core.querybuilder.QueryBuilder.select; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ALARM_BY_ID_VIEW_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ALARM_COLUMN_FAMILY_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ALARM_ORIGINATOR_ID_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ALARM_ORIGINATOR_TYPE_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ALARM_TENANT_ID_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ALARM_TYPE_PROPERTY; |
|||
|
|||
@Component |
|||
@Slf4j |
|||
@NoSqlDao |
|||
public class CassandraAlarmDao extends CassandraAbstractModelDao<AlarmEntity, Alarm> implements AlarmDao { |
|||
|
|||
@Autowired |
|||
private RelationDao relationDao; |
|||
|
|||
@Override |
|||
protected Class<AlarmEntity> getColumnFamilyClass() { |
|||
return AlarmEntity.class; |
|||
} |
|||
|
|||
@Override |
|||
protected String getColumnFamilyName() { |
|||
return ALARM_COLUMN_FAMILY_NAME; |
|||
} |
|||
|
|||
protected boolean isDeleteOnSave() { |
|||
return false; |
|||
} |
|||
|
|||
@Override |
|||
public Alarm save(TenantId tenantId, Alarm alarm) { |
|||
log.debug("Save asset [{}] ", alarm); |
|||
return super.save(tenantId, alarm); |
|||
} |
|||
|
|||
@Override |
|||
public Boolean deleteAlarm(TenantId tenantId, Alarm alarm) { |
|||
Statement delete = QueryBuilder.delete().all().from(getColumnFamilyName()).where(eq(ModelConstants.ID_PROPERTY, alarm.getId().getId())) |
|||
.and(eq(ALARM_TENANT_ID_PROPERTY, tenantId.getId())) |
|||
.and(eq(ALARM_ORIGINATOR_ID_PROPERTY, alarm.getOriginator().getId())) |
|||
.and(eq(ALARM_ORIGINATOR_TYPE_PROPERTY, alarm.getOriginator().getEntityType())) |
|||
.and(eq(ALARM_TYPE_PROPERTY, alarm.getType())); |
|||
log.debug("Remove request: {}", delete.toString()); |
|||
return executeWrite(tenantId, delete).wasApplied(); |
|||
} |
|||
|
|||
@Override |
|||
public ListenableFuture<Alarm> findLatestByOriginatorAndType(TenantId tenantId, EntityId originator, String type) { |
|||
Select select = select().from(ALARM_COLUMN_FAMILY_NAME); |
|||
Select.Where query = select.where(); |
|||
query.and(eq(ALARM_TENANT_ID_PROPERTY, tenantId.getId())); |
|||
query.and(eq(ALARM_ORIGINATOR_ID_PROPERTY, originator.getId())); |
|||
query.and(eq(ALARM_ORIGINATOR_TYPE_PROPERTY, originator.getEntityType())); |
|||
query.and(eq(ALARM_TYPE_PROPERTY, type)); |
|||
query.limit(1); |
|||
query.orderBy(QueryBuilder.asc(ModelConstants.ALARM_TYPE_PROPERTY), QueryBuilder.desc(ModelConstants.ID_PROPERTY)); |
|||
return findOneByStatementAsync(tenantId, query); |
|||
} |
|||
|
|||
@Override |
|||
public ListenableFuture<List<AlarmInfo>> findAlarms(TenantId tenantId, AlarmQuery query) { |
|||
log.trace("Try to find alarms by entity [{}], searchStatus [{}], status [{}] and pageLink [{}]", query.getAffectedEntityId(), query.getSearchStatus(), query.getStatus(), query.getPageLink()); |
|||
EntityId affectedEntity = query.getAffectedEntityId(); |
|||
String searchStatusName; |
|||
if (query.getSearchStatus() == null && query.getStatus() == null) { |
|||
searchStatusName = AlarmSearchStatus.ANY.name(); |
|||
} else if (query.getSearchStatus() != null) { |
|||
searchStatusName = query.getSearchStatus().name(); |
|||
} else { |
|||
searchStatusName = query.getStatus().name(); |
|||
} |
|||
String relationType = BaseAlarmService.ALARM_RELATION_PREFIX + searchStatusName; |
|||
ListenableFuture<List<EntityRelation>> relations = relationDao.findRelations(tenantId, affectedEntity, relationType, RelationTypeGroup.ALARM, EntityType.ALARM, query.getPageLink()); |
|||
return Futures.transformAsync(relations, input -> { |
|||
List<ListenableFuture<AlarmInfo>> alarmFutures = new ArrayList<>(input.size()); |
|||
for (EntityRelation relation : input) { |
|||
alarmFutures.add(Futures.transform( |
|||
findAlarmByIdAsync(tenantId, relation.getTo().getId()), |
|||
AlarmInfo::new)); |
|||
} |
|||
return Futures.successfulAsList(alarmFutures); |
|||
}); |
|||
} |
|||
|
|||
@Override |
|||
public ListenableFuture<Alarm> findAlarmByIdAsync(TenantId tenantId, UUID key) { |
|||
log.debug("Get alarm by id {}", key); |
|||
Select.Where query = select().from(ALARM_BY_ID_VIEW_NAME).where(eq(ModelConstants.ID_PROPERTY, key)); |
|||
query.limit(1); |
|||
log.trace("Execute query {}", query); |
|||
return findOneByStatementAsync(tenantId, query); |
|||
} |
|||
} |
|||
@ -1,191 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.asset; |
|||
|
|||
import com.datastax.driver.core.ResultSet; |
|||
import com.datastax.driver.core.ResultSetFuture; |
|||
import com.datastax.driver.core.Statement; |
|||
import com.datastax.driver.core.querybuilder.Select; |
|||
import com.datastax.driver.mapping.Result; |
|||
import com.google.common.base.Function; |
|||
import com.google.common.util.concurrent.Futures; |
|||
import com.google.common.util.concurrent.ListenableFuture; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.common.data.EntitySubtype; |
|||
import org.thingsboard.server.common.data.EntityType; |
|||
import org.thingsboard.server.common.data.asset.Asset; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.page.TextPageLink; |
|||
import org.thingsboard.server.dao.DaoUtil; |
|||
import org.thingsboard.server.dao.model.EntitySubtypeEntity; |
|||
import org.thingsboard.server.dao.model.nosql.AssetEntity; |
|||
import org.thingsboard.server.dao.nosql.CassandraAbstractSearchTextDao; |
|||
import org.thingsboard.server.dao.util.NoSqlDao; |
|||
|
|||
import javax.annotation.Nullable; |
|||
import java.util.ArrayList; |
|||
import java.util.Arrays; |
|||
import java.util.Collections; |
|||
import java.util.List; |
|||
import java.util.Optional; |
|||
import java.util.UUID; |
|||
|
|||
import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; |
|||
import static com.datastax.driver.core.querybuilder.QueryBuilder.in; |
|||
import static com.datastax.driver.core.querybuilder.QueryBuilder.select; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ASSET_BY_CUSTOMER_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ASSET_BY_CUSTOMER_BY_TYPE_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ASSET_BY_TENANT_AND_NAME_VIEW_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ASSET_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ASSET_BY_TENANT_BY_TYPE_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ASSET_COLUMN_FAMILY_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ASSET_CUSTOMER_ID_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ASSET_NAME_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ASSET_TENANT_ID_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ASSET_TYPE_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ENTITY_SUBTYPE_COLUMN_FAMILY_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ENTITY_SUBTYPE_ENTITY_TYPE_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ENTITY_SUBTYPE_TENANT_ID_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ID_PROPERTY; |
|||
|
|||
@Component |
|||
@Slf4j |
|||
@NoSqlDao |
|||
public class CassandraAssetDao extends CassandraAbstractSearchTextDao<AssetEntity, Asset> implements AssetDao { |
|||
|
|||
@Override |
|||
protected Class<AssetEntity> getColumnFamilyClass() { |
|||
return AssetEntity.class; |
|||
} |
|||
|
|||
@Override |
|||
protected String getColumnFamilyName() { |
|||
return ASSET_COLUMN_FAMILY_NAME; |
|||
} |
|||
|
|||
@Override |
|||
public Asset save(TenantId tenantId, Asset domain) { |
|||
Asset savedAsset = super.save(tenantId, domain); |
|||
EntitySubtype entitySubtype = new EntitySubtype(savedAsset.getTenantId(), EntityType.ASSET, savedAsset.getType()); |
|||
EntitySubtypeEntity entitySubtypeEntity = new EntitySubtypeEntity(entitySubtype); |
|||
Statement saveStatement = cluster.getMapper(EntitySubtypeEntity.class).saveQuery(entitySubtypeEntity); |
|||
executeWrite(tenantId, saveStatement); |
|||
return savedAsset; |
|||
} |
|||
|
|||
@Override |
|||
public List<Asset> findAssetsByTenantId(UUID tenantId, TextPageLink pageLink) { |
|||
log.debug("Try to find assets by tenantId [{}] and pageLink [{}]", tenantId, pageLink); |
|||
List<AssetEntity> assetEntities = findPageWithTextSearch(new TenantId(tenantId), ASSET_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, |
|||
Collections.singletonList(eq(ASSET_TENANT_ID_PROPERTY, tenantId)), pageLink); |
|||
|
|||
log.trace("Found assets [{}] by tenantId [{}] and pageLink [{}]", assetEntities, tenantId, pageLink); |
|||
return DaoUtil.convertDataList(assetEntities); |
|||
} |
|||
|
|||
@Override |
|||
public List<Asset> findAssetsByTenantIdAndType(UUID tenantId, String type, TextPageLink pageLink) { |
|||
log.debug("Try to find assets by tenantId [{}], type [{}] and pageLink [{}]", tenantId, type, pageLink); |
|||
List<AssetEntity> assetEntities = findPageWithTextSearch(new TenantId(tenantId), ASSET_BY_TENANT_BY_TYPE_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, |
|||
Arrays.asList(eq(ASSET_TYPE_PROPERTY, type), |
|||
eq(ASSET_TENANT_ID_PROPERTY, tenantId)), pageLink); |
|||
log.trace("Found assets [{}] by tenantId [{}], type [{}] and pageLink [{}]", assetEntities, tenantId, type, pageLink); |
|||
return DaoUtil.convertDataList(assetEntities); |
|||
} |
|||
|
|||
public ListenableFuture<List<Asset>> findAssetsByTenantIdAndIdsAsync(UUID tenantId, List<UUID> assetIds) { |
|||
log.debug("Try to find assets by tenantId [{}] and asset Ids [{}]", tenantId, assetIds); |
|||
Select select = select().from(getColumnFamilyName()); |
|||
Select.Where query = select.where(); |
|||
query.and(eq(ASSET_TENANT_ID_PROPERTY, tenantId)); |
|||
query.and(in(ID_PROPERTY, assetIds)); |
|||
return findListByStatementAsync(new TenantId(tenantId), query); |
|||
} |
|||
|
|||
@Override |
|||
public List<Asset> findAssetsByTenantIdAndCustomerId(UUID tenantId, UUID customerId, TextPageLink pageLink) { |
|||
log.debug("Try to find assets by tenantId [{}], customerId[{}] and pageLink [{}]", tenantId, customerId, pageLink); |
|||
List<AssetEntity> assetEntities = findPageWithTextSearch(new TenantId(tenantId), ASSET_BY_CUSTOMER_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, |
|||
Arrays.asList(eq(ASSET_CUSTOMER_ID_PROPERTY, customerId), |
|||
eq(ASSET_TENANT_ID_PROPERTY, tenantId)), |
|||
pageLink); |
|||
|
|||
log.trace("Found assets [{}] by tenantId [{}], customerId [{}] and pageLink [{}]", assetEntities, tenantId, customerId, pageLink); |
|||
return DaoUtil.convertDataList(assetEntities); |
|||
} |
|||
|
|||
@Override |
|||
public List<Asset> findAssetsByTenantIdAndCustomerIdAndType(UUID tenantId, UUID customerId, String type, TextPageLink pageLink) { |
|||
log.debug("Try to find assets by tenantId [{}], customerId [{}], type [{}] and pageLink [{}]", tenantId, customerId, type, pageLink); |
|||
List<AssetEntity> assetEntities = findPageWithTextSearch(new TenantId(tenantId), ASSET_BY_CUSTOMER_BY_TYPE_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, |
|||
Arrays.asList(eq(ASSET_TYPE_PROPERTY, type), |
|||
eq(ASSET_CUSTOMER_ID_PROPERTY, customerId), |
|||
eq(ASSET_TENANT_ID_PROPERTY, tenantId)), |
|||
pageLink); |
|||
|
|||
log.trace("Found assets [{}] by tenantId [{}], customerId [{}], type [{}] and pageLink [{}]", assetEntities, tenantId, customerId, type, pageLink); |
|||
return DaoUtil.convertDataList(assetEntities); |
|||
} |
|||
|
|||
@Override |
|||
public ListenableFuture<List<Asset>> findAssetsByTenantIdAndCustomerIdAndIdsAsync(UUID tenantId, UUID customerId, List<UUID> assetIds) { |
|||
log.debug("Try to find assets by tenantId [{}], customerId [{}] and asset Ids [{}]", tenantId, customerId, assetIds); |
|||
Select select = select().from(getColumnFamilyName()); |
|||
Select.Where query = select.where(); |
|||
query.and(eq(ASSET_TENANT_ID_PROPERTY, tenantId)); |
|||
query.and(eq(ASSET_CUSTOMER_ID_PROPERTY, customerId)); |
|||
query.and(in(ID_PROPERTY, assetIds)); |
|||
return findListByStatementAsync(new TenantId(tenantId), query); |
|||
} |
|||
|
|||
@Override |
|||
public Optional<Asset> findAssetsByTenantIdAndName(UUID tenantId, String assetName) { |
|||
Select select = select().from(ASSET_BY_TENANT_AND_NAME_VIEW_NAME); |
|||
Select.Where query = select.where(); |
|||
query.and(eq(ASSET_TENANT_ID_PROPERTY, tenantId)); |
|||
query.and(eq(ASSET_NAME_PROPERTY, assetName)); |
|||
AssetEntity assetEntity = (AssetEntity) findOneByStatement(new TenantId(tenantId), query); |
|||
return Optional.ofNullable(DaoUtil.getData(assetEntity)); |
|||
} |
|||
|
|||
@Override |
|||
public ListenableFuture<List<EntitySubtype>> findTenantAssetTypesAsync(UUID tenantId) { |
|||
Select select = select().from(ENTITY_SUBTYPE_COLUMN_FAMILY_NAME); |
|||
Select.Where query = select.where(); |
|||
query.and(eq(ENTITY_SUBTYPE_TENANT_ID_PROPERTY, tenantId)); |
|||
query.and(eq(ENTITY_SUBTYPE_ENTITY_TYPE_PROPERTY, EntityType.ASSET)); |
|||
query.setConsistencyLevel(cluster.getDefaultReadConsistencyLevel()); |
|||
ResultSetFuture resultSetFuture = executeAsyncRead(new TenantId(tenantId), query); |
|||
return Futures.transform(resultSetFuture, new Function<ResultSet, List<EntitySubtype>>() { |
|||
@Nullable |
|||
@Override |
|||
public List<EntitySubtype> apply(@Nullable ResultSet resultSet) { |
|||
Result<EntitySubtypeEntity> result = cluster.getMapper(EntitySubtypeEntity.class).map(resultSet); |
|||
if (result != null) { |
|||
List<EntitySubtype> entitySubtypes = new ArrayList<>(); |
|||
result.all().forEach((entitySubtypeEntity) -> |
|||
entitySubtypes.add(entitySubtypeEntity.toEntitySubtype()) |
|||
); |
|||
return entitySubtypes; |
|||
} else { |
|||
return Collections.emptyList(); |
|||
} |
|||
} |
|||
}); |
|||
} |
|||
|
|||
} |
|||
@ -1,204 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.attributes; |
|||
|
|||
import com.datastax.driver.core.BoundStatement; |
|||
import com.datastax.driver.core.PreparedStatement; |
|||
import com.datastax.driver.core.ResultSet; |
|||
import com.datastax.driver.core.Row; |
|||
import com.datastax.driver.core.Statement; |
|||
import com.datastax.driver.core.querybuilder.QueryBuilder; |
|||
import com.datastax.driver.core.querybuilder.Select; |
|||
import com.google.common.base.Function; |
|||
import com.google.common.util.concurrent.Futures; |
|||
import com.google.common.util.concurrent.ListenableFuture; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.common.data.id.EntityId; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.kv.AttributeKvEntry; |
|||
import org.thingsboard.server.common.data.kv.BaseAttributeKvEntry; |
|||
import org.thingsboard.server.dao.model.ModelConstants; |
|||
import org.thingsboard.server.dao.nosql.CassandraAbstractAsyncDao; |
|||
import org.thingsboard.server.dao.timeseries.CassandraBaseTimeseriesDao; |
|||
import org.thingsboard.server.dao.util.NoSqlDao; |
|||
|
|||
import javax.annotation.PostConstruct; |
|||
import javax.annotation.PreDestroy; |
|||
import java.util.ArrayList; |
|||
import java.util.Collection; |
|||
import java.util.List; |
|||
import java.util.Optional; |
|||
import java.util.stream.Collectors; |
|||
|
|||
import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; |
|||
import static com.datastax.driver.core.querybuilder.QueryBuilder.select; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ATTRIBUTES_KV_CF; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ATTRIBUTE_KEY_COLUMN; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ATTRIBUTE_TYPE_COLUMN; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ENTITY_ID_COLUMN; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ENTITY_TYPE_COLUMN; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.LAST_UPDATE_TS_COLUMN; |
|||
|
|||
/** |
|||
* @author Andrew Shvayka |
|||
*/ |
|||
@Component |
|||
@Slf4j |
|||
@NoSqlDao |
|||
public class CassandraBaseAttributesDao extends CassandraAbstractAsyncDao implements AttributesDao { |
|||
|
|||
private PreparedStatement saveStmt; |
|||
|
|||
@PostConstruct |
|||
public void init() { |
|||
super.startExecutor(); |
|||
} |
|||
|
|||
@PreDestroy |
|||
public void stop() { |
|||
super.stopExecutor(); |
|||
} |
|||
|
|||
@Override |
|||
public ListenableFuture<Optional<AttributeKvEntry>> find(TenantId tenantId, EntityId entityId, String attributeType, String attributeKey) { |
|||
Select.Where select = select().from(ATTRIBUTES_KV_CF) |
|||
.where(eq(ENTITY_TYPE_COLUMN, entityId.getEntityType())) |
|||
.and(eq(ENTITY_ID_COLUMN, entityId.getId())) |
|||
.and(eq(ATTRIBUTE_TYPE_COLUMN, attributeType)) |
|||
.and(eq(ATTRIBUTE_KEY_COLUMN, attributeKey)); |
|||
log.trace("Generated query [{}] for entityId {} and key {}", select, entityId, attributeKey); |
|||
return Futures.transform(executeAsyncRead(tenantId, select), (Function<? super ResultSet, ? extends Optional<AttributeKvEntry>>) input -> |
|||
Optional.ofNullable(convertResultToAttributesKvEntry(attributeKey, input.one())) |
|||
, readResultsProcessingExecutor); |
|||
} |
|||
|
|||
@Override |
|||
public ListenableFuture<List<AttributeKvEntry>> find(TenantId tenantId, EntityId entityId, String attributeType, Collection<String> attributeKeys) { |
|||
List<ListenableFuture<Optional<AttributeKvEntry>>> entries = new ArrayList<>(); |
|||
attributeKeys.forEach(attributeKey -> entries.add(find(tenantId, entityId, attributeType, attributeKey))); |
|||
return Futures.transform(Futures.allAsList(entries), (Function<List<Optional<AttributeKvEntry>>, ? extends List<AttributeKvEntry>>) input -> { |
|||
List<AttributeKvEntry> result = new ArrayList<>(); |
|||
input.stream().filter(opt -> opt.isPresent()).forEach(opt -> result.add(opt.get())); |
|||
return result; |
|||
}, readResultsProcessingExecutor); |
|||
} |
|||
|
|||
|
|||
@Override |
|||
public ListenableFuture<List<AttributeKvEntry>> findAll(TenantId tenantId, EntityId entityId, String attributeType) { |
|||
Select.Where select = select().from(ATTRIBUTES_KV_CF) |
|||
.where(eq(ENTITY_TYPE_COLUMN, entityId.getEntityType())) |
|||
.and(eq(ENTITY_ID_COLUMN, entityId.getId())) |
|||
.and(eq(ATTRIBUTE_TYPE_COLUMN, attributeType)); |
|||
log.trace("Generated query [{}] for entityId {} and attributeType {}", select, entityId, attributeType); |
|||
return Futures.transform(executeAsyncRead(tenantId, select), (Function<? super ResultSet, ? extends List<AttributeKvEntry>>) input -> |
|||
convertResultToAttributesKvEntryList(input) |
|||
, readResultsProcessingExecutor); |
|||
} |
|||
|
|||
@Override |
|||
public ListenableFuture<Void> save(TenantId tenantId, EntityId entityId, String attributeType, AttributeKvEntry attribute) { |
|||
BoundStatement stmt = getSaveStmt().bind(); |
|||
stmt.setString(0, entityId.getEntityType().name()); |
|||
stmt.setUUID(1, entityId.getId()); |
|||
stmt.setString(2, attributeType); |
|||
stmt.setString(3, attribute.getKey()); |
|||
stmt.setLong(4, attribute.getLastUpdateTs()); |
|||
stmt.setString(5, attribute.getStrValue().orElse(null)); |
|||
Optional<Boolean> booleanValue = attribute.getBooleanValue(); |
|||
if (booleanValue.isPresent()) { |
|||
stmt.setBool(6, booleanValue.get()); |
|||
} else { |
|||
stmt.setToNull(6); |
|||
} |
|||
Optional<Long> longValue = attribute.getLongValue(); |
|||
if (longValue.isPresent()) { |
|||
stmt.setLong(7, longValue.get()); |
|||
} else { |
|||
stmt.setToNull(7); |
|||
} |
|||
Optional<Double> doubleValue = attribute.getDoubleValue(); |
|||
if (doubleValue.isPresent()) { |
|||
stmt.setDouble(8, doubleValue.get()); |
|||
} else { |
|||
stmt.setToNull(8); |
|||
} |
|||
log.trace("Generated save stmt [{}] for entityId {} and attributeType {} and attribute", stmt, entityId, attributeType, attribute); |
|||
return getFuture(executeAsyncWrite(tenantId, stmt), rs -> null); |
|||
} |
|||
|
|||
@Override |
|||
public ListenableFuture<List<Void>> removeAll(TenantId tenantId, EntityId entityId, String attributeType, List<String> keys) { |
|||
List<ListenableFuture<Void>> futures = keys |
|||
.stream() |
|||
.map(key -> delete(tenantId, entityId, attributeType, key)) |
|||
.collect(Collectors.toList()); |
|||
return Futures.allAsList(futures); |
|||
} |
|||
|
|||
private ListenableFuture<Void> delete(TenantId tenantId, EntityId entityId, String attributeType, String key) { |
|||
Statement delete = QueryBuilder.delete().all().from(ModelConstants.ATTRIBUTES_KV_CF) |
|||
.where(eq(ENTITY_TYPE_COLUMN, entityId.getEntityType())) |
|||
.and(eq(ENTITY_ID_COLUMN, entityId.getId())) |
|||
.and(eq(ATTRIBUTE_TYPE_COLUMN, attributeType)) |
|||
.and(eq(ATTRIBUTE_KEY_COLUMN, key)); |
|||
log.debug("Remove request: {}", delete.toString()); |
|||
return getFuture(executeAsyncWrite(tenantId, delete), rs -> null); |
|||
} |
|||
|
|||
private PreparedStatement getSaveStmt() { |
|||
if (saveStmt == null) { |
|||
saveStmt = prepare("INSERT INTO " + ModelConstants.ATTRIBUTES_KV_CF + |
|||
"(" + ENTITY_TYPE_COLUMN + |
|||
"," + ENTITY_ID_COLUMN + |
|||
"," + ATTRIBUTE_TYPE_COLUMN + |
|||
"," + ATTRIBUTE_KEY_COLUMN + |
|||
"," + LAST_UPDATE_TS_COLUMN + |
|||
"," + ModelConstants.STRING_VALUE_COLUMN + |
|||
"," + ModelConstants.BOOLEAN_VALUE_COLUMN + |
|||
"," + ModelConstants.LONG_VALUE_COLUMN + |
|||
"," + ModelConstants.DOUBLE_VALUE_COLUMN + |
|||
")" + |
|||
" VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)"); |
|||
} |
|||
return saveStmt; |
|||
} |
|||
|
|||
private AttributeKvEntry convertResultToAttributesKvEntry(String key, Row row) { |
|||
AttributeKvEntry attributeEntry = null; |
|||
if (row != null) { |
|||
long lastUpdateTs = row.get(LAST_UPDATE_TS_COLUMN, Long.class); |
|||
attributeEntry = new BaseAttributeKvEntry(CassandraBaseTimeseriesDao.toKvEntry(row, key), lastUpdateTs); |
|||
} |
|||
return attributeEntry; |
|||
} |
|||
|
|||
private List<AttributeKvEntry> convertResultToAttributesKvEntryList(ResultSet resultSet) { |
|||
List<Row> rows = resultSet.all(); |
|||
List<AttributeKvEntry> entries = new ArrayList<>(rows.size()); |
|||
if (!rows.isEmpty()) { |
|||
rows.forEach(row -> { |
|||
String key = row.getString(ModelConstants.ATTRIBUTE_KEY_COLUMN); |
|||
AttributeKvEntry kvEntry = convertResultToAttributesKvEntry(key, row); |
|||
if (kvEntry != null) { |
|||
entries.add(kvEntry); |
|||
} |
|||
}); |
|||
} |
|||
return entries; |
|||
} |
|||
} |
|||
@ -1,70 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.audit; |
|||
|
|||
import lombok.Getter; |
|||
import org.thingsboard.server.common.data.page.TimePageLink; |
|||
import org.thingsboard.server.dao.model.nosql.AuditLogEntity; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
import java.util.UUID; |
|||
|
|||
public class AuditLogQueryCursor { |
|||
@Getter |
|||
private final UUID tenantId; |
|||
@Getter |
|||
private final List<AuditLogEntity> data; |
|||
@Getter |
|||
private final TimePageLink pageLink; |
|||
|
|||
private final List<Long> partitions; |
|||
|
|||
private int partitionIndex; |
|||
private int currentLimit; |
|||
|
|||
public AuditLogQueryCursor(UUID tenantId, TimePageLink pageLink, List<Long> partitions) { |
|||
this.tenantId = tenantId; |
|||
this.partitions = partitions; |
|||
this.partitionIndex = partitions.size() - 1; |
|||
this.data = new ArrayList<>(); |
|||
this.currentLimit = pageLink.getLimit(); |
|||
this.pageLink = pageLink; |
|||
} |
|||
|
|||
public boolean hasNextPartition() { |
|||
return partitionIndex >= 0; |
|||
} |
|||
|
|||
public boolean isFull() { |
|||
return currentLimit <= 0; |
|||
} |
|||
|
|||
public long getNextPartition() { |
|||
long partition = partitions.get(partitionIndex); |
|||
partitionIndex--; |
|||
return partition; |
|||
} |
|||
|
|||
public int getCurrentLimit() { |
|||
return currentLimit; |
|||
} |
|||
|
|||
public void addData(List<AuditLogEntity> newData) { |
|||
currentLimit -= newData.size(); |
|||
data.addAll(newData); |
|||
} |
|||
} |
|||
@ -1,359 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.audit; |
|||
|
|||
import com.datastax.driver.core.BoundStatement; |
|||
import com.datastax.driver.core.PreparedStatement; |
|||
import com.datastax.driver.core.ResultSet; |
|||
import com.datastax.driver.core.ResultSetFuture; |
|||
import com.datastax.driver.core.querybuilder.QueryBuilder; |
|||
import com.datastax.driver.core.querybuilder.Select; |
|||
import com.google.common.base.Function; |
|||
import com.google.common.util.concurrent.Futures; |
|||
import com.google.common.util.concurrent.ListenableFuture; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.beans.factory.annotation.Value; |
|||
import org.springframework.core.env.Environment; |
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.common.data.audit.AuditLog; |
|||
import org.thingsboard.server.common.data.id.CustomerId; |
|||
import org.thingsboard.server.common.data.id.EntityId; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.id.UserId; |
|||
import org.thingsboard.server.common.data.page.TimePageLink; |
|||
import org.thingsboard.server.dao.DaoUtil; |
|||
import org.thingsboard.server.dao.model.ModelConstants; |
|||
import org.thingsboard.server.dao.model.nosql.AuditLogEntity; |
|||
import org.thingsboard.server.dao.nosql.CassandraAbstractSearchTimeDao; |
|||
import org.thingsboard.server.dao.timeseries.TsPartitionDate; |
|||
import org.thingsboard.server.dao.util.NoSqlDao; |
|||
|
|||
import javax.annotation.Nullable; |
|||
import javax.annotation.PostConstruct; |
|||
import javax.annotation.PreDestroy; |
|||
import java.time.Instant; |
|||
import java.time.LocalDate; |
|||
import java.time.LocalDateTime; |
|||
import java.time.ZoneOffset; |
|||
import java.util.ArrayList; |
|||
import java.util.Arrays; |
|||
import java.util.List; |
|||
import java.util.Optional; |
|||
import java.util.StringJoiner; |
|||
import java.util.UUID; |
|||
import java.util.concurrent.ExecutorService; |
|||
import java.util.concurrent.Executors; |
|||
import java.util.stream.Collectors; |
|||
|
|||
import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.AUDIT_LOG_BY_CUSTOMER_ID_CF; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.AUDIT_LOG_BY_ENTITY_ID_CF; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.AUDIT_LOG_BY_TENANT_ID_CF; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.AUDIT_LOG_BY_USER_ID_CF; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.AUDIT_LOG_COLUMN_FAMILY_NAME; |
|||
|
|||
@Component |
|||
@Slf4j |
|||
@NoSqlDao |
|||
public class CassandraAuditLogDao extends CassandraAbstractSearchTimeDao<AuditLogEntity, AuditLog> implements AuditLogDao { |
|||
|
|||
private static final String INSERT_INTO = "INSERT INTO "; |
|||
|
|||
@Autowired |
|||
private Environment environment; |
|||
|
|||
@Override |
|||
protected Class<AuditLogEntity> getColumnFamilyClass() { |
|||
return AuditLogEntity.class; |
|||
} |
|||
|
|||
@Override |
|||
protected String getColumnFamilyName() { |
|||
return AUDIT_LOG_COLUMN_FAMILY_NAME; |
|||
} |
|||
|
|||
protected ExecutorService readResultsProcessingExecutor; |
|||
|
|||
@Value("${audit-log.by_tenant_partitioning}") |
|||
private String partitioning; |
|||
private TsPartitionDate tsFormat; |
|||
|
|||
@Value("${audit-log.default_query_period}") |
|||
private Integer defaultQueryPeriodInDays; |
|||
|
|||
private PreparedStatement partitionInsertStmt; |
|||
private PreparedStatement saveByTenantStmt; |
|||
private PreparedStatement saveByTenantIdAndUserIdStmt; |
|||
private PreparedStatement saveByTenantIdAndEntityIdStmt; |
|||
private PreparedStatement saveByTenantIdAndCustomerIdStmt; |
|||
|
|||
private boolean isInstall() { |
|||
return environment.acceptsProfiles("install"); |
|||
} |
|||
|
|||
@PostConstruct |
|||
public void init() { |
|||
if (!isInstall()) { |
|||
Optional<TsPartitionDate> partition = TsPartitionDate.parse(partitioning); |
|||
if (partition.isPresent()) { |
|||
tsFormat = partition.get(); |
|||
} else { |
|||
log.warn("Incorrect configuration of partitioning {}", partitioning); |
|||
throw new RuntimeException("Failed to parse partitioning property: " + partitioning + "!"); |
|||
} |
|||
} |
|||
readResultsProcessingExecutor = Executors.newCachedThreadPool(); |
|||
} |
|||
|
|||
@PreDestroy |
|||
public void stopExecutor() { |
|||
if (readResultsProcessingExecutor != null) { |
|||
readResultsProcessingExecutor.shutdownNow(); |
|||
} |
|||
} |
|||
|
|||
private <T> ListenableFuture<T> getFuture(ResultSetFuture future, java.util.function.Function<ResultSet, T> transformer) { |
|||
return Futures.transform(future, new Function<ResultSet, T>() { |
|||
@Nullable |
|||
@Override |
|||
public T apply(@Nullable ResultSet input) { |
|||
return transformer.apply(input); |
|||
} |
|||
}, readResultsProcessingExecutor); |
|||
} |
|||
|
|||
@Override |
|||
public ListenableFuture<Void> saveByTenantId(AuditLog auditLog) { |
|||
log.debug("Save saveByTenantId [{}] ", auditLog); |
|||
|
|||
long partition = toPartitionTs(LocalDate.now().atStartOfDay().toInstant(ZoneOffset.UTC).toEpochMilli()); |
|||
BoundStatement stmt = getSaveByTenantStmt().bind(); |
|||
stmt = setSaveStmtVariables(stmt, auditLog, partition); |
|||
return getFuture(executeAsyncWrite(auditLog.getTenantId(), stmt), rs -> null); |
|||
} |
|||
|
|||
@Override |
|||
public ListenableFuture<Void> saveByTenantIdAndEntityId(AuditLog auditLog) { |
|||
log.debug("Save saveByTenantIdAndEntityId [{}] ", auditLog); |
|||
|
|||
BoundStatement stmt = getSaveByTenantIdAndEntityIdStmt().bind(); |
|||
stmt = setSaveStmtVariables(stmt, auditLog, -1); |
|||
return getFuture(executeAsyncWrite(auditLog.getTenantId(), stmt), rs -> null); |
|||
} |
|||
|
|||
@Override |
|||
public ListenableFuture<Void> saveByTenantIdAndCustomerId(AuditLog auditLog) { |
|||
log.debug("Save saveByTenantIdAndCustomerId [{}] ", auditLog); |
|||
|
|||
BoundStatement stmt = getSaveByTenantIdAndCustomerIdStmt().bind(); |
|||
stmt = setSaveStmtVariables(stmt, auditLog, -1); |
|||
return getFuture(executeAsyncWrite(auditLog.getTenantId(), stmt), rs -> null); |
|||
} |
|||
|
|||
@Override |
|||
public ListenableFuture<Void> saveByTenantIdAndUserId(AuditLog auditLog) { |
|||
log.debug("Save saveByTenantIdAndUserId [{}] ", auditLog); |
|||
|
|||
BoundStatement stmt = getSaveByTenantIdAndUserIdStmt().bind(); |
|||
stmt = setSaveStmtVariables(stmt, auditLog, -1); |
|||
return getFuture(executeAsyncWrite(auditLog.getTenantId(), stmt), rs -> null); |
|||
} |
|||
|
|||
private BoundStatement setSaveStmtVariables(BoundStatement stmt, AuditLog auditLog, long partition) { |
|||
stmt.setUUID(0, auditLog.getId().getId()) |
|||
.setUUID(1, auditLog.getTenantId().getId()) |
|||
.setUUID(2, auditLog.getCustomerId().getId()) |
|||
.setUUID(3, auditLog.getEntityId().getId()) |
|||
.setString(4, auditLog.getEntityId().getEntityType().name()) |
|||
.setString(5, auditLog.getEntityName()) |
|||
.setUUID(6, auditLog.getUserId().getId()) |
|||
.setString(7, auditLog.getUserName()) |
|||
.setString(8, auditLog.getActionType().name()) |
|||
.setString(9, auditLog.getActionData() != null ? auditLog.getActionData().toString() : null) |
|||
.setString(10, auditLog.getActionStatus().name()) |
|||
.setString(11, auditLog.getActionFailureDetails()); |
|||
if (partition > -1) { |
|||
stmt.setLong(12, partition); |
|||
} |
|||
return stmt; |
|||
} |
|||
|
|||
@Override |
|||
public ListenableFuture<Void> savePartitionsByTenantId(AuditLog auditLog) { |
|||
log.debug("Save savePartitionsByTenantId [{}] ", auditLog); |
|||
|
|||
long partition = toPartitionTs(LocalDate.now().atStartOfDay().toInstant(ZoneOffset.UTC).toEpochMilli()); |
|||
|
|||
BoundStatement stmt = getPartitionInsertStmt().bind(); |
|||
stmt = stmt.setUUID(0, auditLog.getTenantId().getId()) |
|||
.setLong(1, partition); |
|||
return getFuture(executeAsyncWrite(auditLog.getTenantId(), stmt), rs -> null); |
|||
} |
|||
|
|||
private PreparedStatement getSaveByTenantStmt() { |
|||
if (saveByTenantStmt == null) { |
|||
saveByTenantStmt = getSaveByTenantIdAndCFName(ModelConstants.AUDIT_LOG_BY_TENANT_ID_CF, true); |
|||
} |
|||
return saveByTenantStmt; |
|||
} |
|||
|
|||
private PreparedStatement getSaveByTenantIdAndEntityIdStmt() { |
|||
if (saveByTenantIdAndEntityIdStmt == null) { |
|||
saveByTenantIdAndEntityIdStmt = getSaveByTenantIdAndCFName(ModelConstants.AUDIT_LOG_BY_ENTITY_ID_CF, false); |
|||
} |
|||
return saveByTenantIdAndEntityIdStmt; |
|||
} |
|||
|
|||
private PreparedStatement getSaveByTenantIdAndCustomerIdStmt() { |
|||
if (saveByTenantIdAndCustomerIdStmt == null) { |
|||
saveByTenantIdAndCustomerIdStmt = getSaveByTenantIdAndCFName(ModelConstants.AUDIT_LOG_BY_CUSTOMER_ID_CF, false); |
|||
} |
|||
return saveByTenantIdAndCustomerIdStmt; |
|||
} |
|||
|
|||
private PreparedStatement getSaveByTenantIdAndUserIdStmt() { |
|||
if (saveByTenantIdAndUserIdStmt == null) { |
|||
saveByTenantIdAndUserIdStmt = getSaveByTenantIdAndCFName(ModelConstants.AUDIT_LOG_BY_USER_ID_CF, false); |
|||
} |
|||
return saveByTenantIdAndUserIdStmt; |
|||
} |
|||
|
|||
private PreparedStatement getSaveByTenantIdAndCFName(String cfName, boolean hasPartition) { |
|||
List columnsList = new ArrayList(); |
|||
columnsList.add(ModelConstants.AUDIT_LOG_ID_PROPERTY); |
|||
columnsList.add(ModelConstants.AUDIT_LOG_TENANT_ID_PROPERTY); |
|||
columnsList.add(ModelConstants.AUDIT_LOG_CUSTOMER_ID_PROPERTY); |
|||
columnsList.add(ModelConstants.AUDIT_LOG_ENTITY_ID_PROPERTY); |
|||
columnsList.add(ModelConstants.AUDIT_LOG_ENTITY_TYPE_PROPERTY); |
|||
columnsList.add(ModelConstants.AUDIT_LOG_ENTITY_NAME_PROPERTY); |
|||
columnsList.add(ModelConstants.AUDIT_LOG_USER_ID_PROPERTY); |
|||
columnsList.add(ModelConstants.AUDIT_LOG_USER_NAME_PROPERTY); |
|||
columnsList.add(ModelConstants.AUDIT_LOG_ACTION_TYPE_PROPERTY); |
|||
columnsList.add(ModelConstants.AUDIT_LOG_ACTION_DATA_PROPERTY); |
|||
columnsList.add(ModelConstants.AUDIT_LOG_ACTION_STATUS_PROPERTY); |
|||
columnsList.add(ModelConstants.AUDIT_LOG_ACTION_FAILURE_DETAILS_PROPERTY); |
|||
if (hasPartition) { |
|||
columnsList.add(ModelConstants.AUDIT_LOG_PARTITION_PROPERTY); |
|||
} |
|||
StringJoiner values = new StringJoiner(","); |
|||
for (int i = 0; i < columnsList.size(); i++) { |
|||
values.add("?"); |
|||
} |
|||
String statementString = INSERT_INTO + cfName + " (" + String.join(",", columnsList) + ") VALUES (" + values.toString() + ")"; |
|||
return prepare(statementString); |
|||
} |
|||
|
|||
private PreparedStatement getPartitionInsertStmt() { |
|||
if (partitionInsertStmt == null) { |
|||
partitionInsertStmt = prepare(INSERT_INTO + ModelConstants.AUDIT_LOG_BY_TENANT_ID_PARTITIONS_CF + |
|||
"(" + ModelConstants.AUDIT_LOG_TENANT_ID_PROPERTY + |
|||
"," + ModelConstants.AUDIT_LOG_PARTITION_PROPERTY + ")" + |
|||
" VALUES(?, ?)"); |
|||
} |
|||
return partitionInsertStmt; |
|||
} |
|||
|
|||
private long toPartitionTs(long ts) { |
|||
LocalDateTime time = LocalDateTime.ofInstant(Instant.ofEpochMilli(ts), ZoneOffset.UTC); |
|||
return tsFormat.truncatedTo(time).toInstant(ZoneOffset.UTC).toEpochMilli(); |
|||
} |
|||
|
|||
@Override |
|||
public List<AuditLog> findAuditLogsByTenantIdAndEntityId(UUID tenantId, EntityId entityId, TimePageLink pageLink) { |
|||
log.trace("Try to find audit logs by tenant [{}], entity [{}] and pageLink [{}]", tenantId, entityId, pageLink); |
|||
List<AuditLogEntity> entities = findPageWithTimeSearch(new TenantId(tenantId), AUDIT_LOG_BY_ENTITY_ID_CF, |
|||
Arrays.asList(eq(ModelConstants.AUDIT_LOG_TENANT_ID_PROPERTY, tenantId), |
|||
eq(ModelConstants.AUDIT_LOG_ENTITY_TYPE_PROPERTY, entityId.getEntityType()), |
|||
eq(ModelConstants.AUDIT_LOG_ENTITY_ID_PROPERTY, entityId.getId())), |
|||
pageLink); |
|||
log.trace("Found audit logs by tenant [{}], entity [{}] and pageLink [{}]", tenantId, entityId, pageLink); |
|||
return DaoUtil.convertDataList(entities); |
|||
} |
|||
|
|||
@Override |
|||
public List<AuditLog> findAuditLogsByTenantIdAndCustomerId(UUID tenantId, CustomerId customerId, TimePageLink pageLink) { |
|||
log.trace("Try to find audit logs by tenant [{}], customer [{}] and pageLink [{}]", tenantId, customerId, pageLink); |
|||
List<AuditLogEntity> entities = findPageWithTimeSearch(new TenantId(tenantId), AUDIT_LOG_BY_CUSTOMER_ID_CF, |
|||
Arrays.asList(eq(ModelConstants.AUDIT_LOG_TENANT_ID_PROPERTY, tenantId), |
|||
eq(ModelConstants.AUDIT_LOG_CUSTOMER_ID_PROPERTY, customerId.getId())), |
|||
pageLink); |
|||
log.trace("Found audit logs by tenant [{}], customer [{}] and pageLink [{}]", tenantId, customerId, pageLink); |
|||
return DaoUtil.convertDataList(entities); |
|||
} |
|||
|
|||
@Override |
|||
public List<AuditLog> findAuditLogsByTenantIdAndUserId(UUID tenantId, UserId userId, TimePageLink pageLink) { |
|||
log.trace("Try to find audit logs by tenant [{}], user [{}] and pageLink [{}]", tenantId, userId, pageLink); |
|||
List<AuditLogEntity> entities = findPageWithTimeSearch(new TenantId(tenantId), AUDIT_LOG_BY_USER_ID_CF, |
|||
Arrays.asList(eq(ModelConstants.AUDIT_LOG_TENANT_ID_PROPERTY, tenantId), |
|||
eq(ModelConstants.AUDIT_LOG_USER_ID_PROPERTY, userId.getId())), |
|||
pageLink); |
|||
log.trace("Found audit logs by tenant [{}], user [{}] and pageLink [{}]", tenantId, userId, pageLink); |
|||
return DaoUtil.convertDataList(entities); |
|||
} |
|||
|
|||
@Override |
|||
public List<AuditLog> findAuditLogsByTenantId(UUID tenantId, TimePageLink pageLink) { |
|||
log.trace("Try to find audit logs by tenant [{}] and pageLink [{}]", tenantId, pageLink); |
|||
|
|||
long minPartition; |
|||
if (pageLink.getStartTime() != null && pageLink.getStartTime() != 0) { |
|||
minPartition = toPartitionTs(pageLink.getStartTime()); |
|||
} else { |
|||
minPartition = toPartitionTs(LocalDate.now().minusDays(defaultQueryPeriodInDays).atStartOfDay().toInstant(ZoneOffset.UTC).toEpochMilli()); |
|||
} |
|||
|
|||
long maxPartition; |
|||
if (pageLink.getEndTime() != null && pageLink.getEndTime() != 0) { |
|||
maxPartition = toPartitionTs(pageLink.getEndTime()); |
|||
} else { |
|||
maxPartition = toPartitionTs(LocalDate.now().atStartOfDay().toInstant(ZoneOffset.UTC).toEpochMilli()); |
|||
} |
|||
|
|||
List<Long> partitions = fetchPartitions(tenantId, minPartition, maxPartition) |
|||
.all() |
|||
.stream() |
|||
.map(row -> row.getLong(ModelConstants.PARTITION_COLUMN)) |
|||
.collect(Collectors.toList()); |
|||
|
|||
AuditLogQueryCursor cursor = new AuditLogQueryCursor(tenantId, pageLink, partitions); |
|||
List<AuditLogEntity> entities = fetchSequentiallyWithLimit(cursor); |
|||
log.trace("Found audit logs by tenant [{}] and pageLink [{}]", tenantId, pageLink); |
|||
return DaoUtil.convertDataList(entities); |
|||
} |
|||
|
|||
private List<AuditLogEntity> fetchSequentiallyWithLimit(AuditLogQueryCursor cursor) { |
|||
if (cursor.isFull() || !cursor.hasNextPartition()) { |
|||
return cursor.getData(); |
|||
} else { |
|||
cursor.addData(findPageWithTimeSearch(new TenantId(cursor.getTenantId()), AUDIT_LOG_BY_TENANT_ID_CF, |
|||
Arrays.asList(eq(ModelConstants.AUDIT_LOG_TENANT_ID_PROPERTY, cursor.getTenantId()), |
|||
eq(ModelConstants.AUDIT_LOG_PARTITION_PROPERTY, cursor.getNextPartition())), |
|||
cursor.getPageLink())); |
|||
return fetchSequentiallyWithLimit(cursor); |
|||
} |
|||
} |
|||
|
|||
private ResultSet fetchPartitions(UUID tenantId, long minPartition, long maxPartition) { |
|||
Select.Where select = QueryBuilder.select(ModelConstants.AUDIT_LOG_PARTITION_PROPERTY).from(ModelConstants.AUDIT_LOG_BY_TENANT_ID_PARTITIONS_CF) |
|||
.where(eq(ModelConstants.AUDIT_LOG_TENANT_ID_PROPERTY, tenantId)); |
|||
select.and(QueryBuilder.gte(ModelConstants.PARTITION_COLUMN, minPartition)); |
|||
select.and(QueryBuilder.lte(ModelConstants.PARTITION_COLUMN, maxPartition)); |
|||
return executeRead(new TenantId(tenantId), select); |
|||
} |
|||
|
|||
} |
|||
@ -1,175 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.component; |
|||
|
|||
import com.datastax.driver.core.ResultSet; |
|||
import com.datastax.driver.core.Statement; |
|||
import com.datastax.driver.core.querybuilder.QueryBuilder; |
|||
import com.datastax.driver.core.querybuilder.Select; |
|||
import com.datastax.driver.core.utils.UUIDs; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.common.data.id.ComponentDescriptorId; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.page.TextPageLink; |
|||
import org.thingsboard.server.common.data.plugin.ComponentDescriptor; |
|||
import org.thingsboard.server.common.data.plugin.ComponentScope; |
|||
import org.thingsboard.server.common.data.plugin.ComponentType; |
|||
import org.thingsboard.server.dao.DaoUtil; |
|||
import org.thingsboard.server.dao.model.ModelConstants; |
|||
import org.thingsboard.server.dao.model.nosql.ComponentDescriptorEntity; |
|||
import org.thingsboard.server.dao.nosql.CassandraAbstractSearchTextDao; |
|||
import org.thingsboard.server.dao.util.NoSqlDao; |
|||
|
|||
import java.util.Arrays; |
|||
import java.util.List; |
|||
import java.util.Optional; |
|||
import java.util.UUID; |
|||
|
|||
import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; |
|||
import static com.datastax.driver.core.querybuilder.QueryBuilder.select; |
|||
|
|||
/** |
|||
* @author Andrew Shvayka |
|||
*/ |
|||
@Component |
|||
@Slf4j |
|||
@NoSqlDao |
|||
public class CassandraBaseComponentDescriptorDao extends CassandraAbstractSearchTextDao<ComponentDescriptorEntity, ComponentDescriptor> implements ComponentDescriptorDao { |
|||
|
|||
public static final String SEARCH_RESULT = "Search result: [{}]"; |
|||
|
|||
@Override |
|||
protected Class<ComponentDescriptorEntity> getColumnFamilyClass() { |
|||
return ComponentDescriptorEntity.class; |
|||
} |
|||
|
|||
@Override |
|||
protected String getColumnFamilyName() { |
|||
return ModelConstants.COMPONENT_DESCRIPTOR_COLUMN_FAMILY_NAME; |
|||
} |
|||
|
|||
@Override |
|||
public Optional<ComponentDescriptor> saveIfNotExist(TenantId tenantId, ComponentDescriptor component) { |
|||
ComponentDescriptorEntity entity = new ComponentDescriptorEntity(component); |
|||
log.debug("Save component entity [{}]", entity); |
|||
Optional<ComponentDescriptor> result = saveIfNotExist(tenantId, entity); |
|||
if (log.isTraceEnabled()) { |
|||
log.trace("Saved result: [{}] for component entity [{}]", result.isPresent(), result.orElse(null)); |
|||
} else { |
|||
log.debug("Saved result: [{}]", result.isPresent()); |
|||
} |
|||
return result; |
|||
} |
|||
|
|||
@Override |
|||
public ComponentDescriptor findById(TenantId tenantId, ComponentDescriptorId componentId) { |
|||
log.debug("Search component entity by id [{}]", componentId); |
|||
ComponentDescriptor componentDescriptor = super.findById(tenantId, componentId.getId()); |
|||
if (log.isTraceEnabled()) { |
|||
log.trace("Search result: [{}] for component entity [{}]", componentDescriptor != null, componentDescriptor); |
|||
} else { |
|||
log.debug(SEARCH_RESULT, componentDescriptor != null); |
|||
} |
|||
return componentDescriptor; |
|||
} |
|||
|
|||
@Override |
|||
public ComponentDescriptor findByClazz(TenantId tenantId, String clazz) { |
|||
log.debug("Search component entity by clazz [{}]", clazz); |
|||
Select.Where query = select().from(getColumnFamilyName()).where(eq(ModelConstants.COMPONENT_DESCRIPTOR_CLASS_PROPERTY, clazz)); |
|||
log.trace("Execute query [{}]", query); |
|||
ComponentDescriptorEntity entity = findOneByStatement(tenantId, query); |
|||
if (log.isTraceEnabled()) { |
|||
log.trace("Search result: [{}] for component entity [{}]", entity != null, entity); |
|||
} else { |
|||
log.debug(SEARCH_RESULT, entity != null); |
|||
} |
|||
return DaoUtil.getData(entity); |
|||
} |
|||
|
|||
@Override |
|||
public List<ComponentDescriptor> findByTypeAndPageLink(TenantId tenantId, ComponentType type, TextPageLink pageLink) { |
|||
log.debug("Try to find component by type [{}] and pageLink [{}]", type, pageLink); |
|||
List<ComponentDescriptorEntity> entities = findPageWithTextSearch(tenantId, ModelConstants.COMPONENT_DESCRIPTOR_BY_TYPE_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, |
|||
Arrays.asList(eq(ModelConstants.COMPONENT_DESCRIPTOR_TYPE_PROPERTY, type)), pageLink); |
|||
if (log.isTraceEnabled()) { |
|||
log.trace(SEARCH_RESULT, Arrays.toString(entities.toArray())); |
|||
} else { |
|||
log.debug(SEARCH_RESULT, entities.size()); |
|||
} |
|||
return DaoUtil.convertDataList(entities); |
|||
} |
|||
|
|||
@Override |
|||
public List<ComponentDescriptor> findByScopeAndTypeAndPageLink(TenantId tenantId, ComponentScope scope, ComponentType type, TextPageLink pageLink) { |
|||
log.debug("Try to find component by scope [{}] and type [{}] and pageLink [{}]", scope, type, pageLink); |
|||
List<ComponentDescriptorEntity> entities = findPageWithTextSearch(tenantId, ModelConstants.COMPONENT_DESCRIPTOR_BY_SCOPE_TYPE_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, |
|||
Arrays.asList(eq(ModelConstants.COMPONENT_DESCRIPTOR_TYPE_PROPERTY, type), |
|||
eq(ModelConstants.COMPONENT_DESCRIPTOR_SCOPE_PROPERTY, scope.name())), pageLink); |
|||
if (log.isTraceEnabled()) { |
|||
log.trace(SEARCH_RESULT, Arrays.toString(entities.toArray())); |
|||
} else { |
|||
log.debug(SEARCH_RESULT, entities.size()); |
|||
} |
|||
return DaoUtil.convertDataList(entities); |
|||
} |
|||
|
|||
public boolean removeById(TenantId tenantId, UUID key) { |
|||
Statement delete = QueryBuilder.delete().all().from(ModelConstants.COMPONENT_DESCRIPTOR_BY_ID).where(eq(ModelConstants.ID_PROPERTY, key)); |
|||
log.debug("Remove request: {}", delete.toString()); |
|||
return executeWrite(tenantId, delete).wasApplied(); |
|||
} |
|||
|
|||
@Override |
|||
public void deleteById(TenantId tenantId, ComponentDescriptorId id) { |
|||
log.debug("Delete plugin meta-data entity by id [{}]", id); |
|||
boolean result = removeById(tenantId, id.getId()); |
|||
log.debug("Delete result: [{}]", result); |
|||
} |
|||
|
|||
@Override |
|||
public void deleteByClazz(TenantId tenantId, String clazz) { |
|||
log.debug("Delete plugin meta-data entity by id [{}]", clazz); |
|||
Statement delete = QueryBuilder.delete().all().from(getColumnFamilyName()).where(eq(ModelConstants.COMPONENT_DESCRIPTOR_CLASS_PROPERTY, clazz)); |
|||
log.debug("Remove request: {}", delete.toString()); |
|||
ResultSet resultSet = executeWrite(tenantId, delete); |
|||
log.debug("Delete result: [{}]", resultSet.wasApplied()); |
|||
} |
|||
|
|||
private Optional<ComponentDescriptor> saveIfNotExist(TenantId tenantId, ComponentDescriptorEntity entity) { |
|||
if (entity.getId() == null) { |
|||
entity.setId(UUIDs.timeBased()); |
|||
} |
|||
|
|||
ResultSet rs = executeRead(tenantId, QueryBuilder.insertInto(getColumnFamilyName()) |
|||
.value(ModelConstants.ID_PROPERTY, entity.getId()) |
|||
.value(ModelConstants.COMPONENT_DESCRIPTOR_NAME_PROPERTY, entity.getName()) |
|||
.value(ModelConstants.COMPONENT_DESCRIPTOR_CLASS_PROPERTY, entity.getClazz()) |
|||
.value(ModelConstants.COMPONENT_DESCRIPTOR_TYPE_PROPERTY, entity.getType()) |
|||
.value(ModelConstants.COMPONENT_DESCRIPTOR_SCOPE_PROPERTY, entity.getScope()) |
|||
.value(ModelConstants.COMPONENT_DESCRIPTOR_CONFIGURATION_DESCRIPTOR_PROPERTY, entity.getConfigurationDescriptor()) |
|||
.value(ModelConstants.COMPONENT_DESCRIPTOR_ACTIONS_PROPERTY, entity.getActions()) |
|||
.value(ModelConstants.SEARCH_TEXT_PROPERTY, entity.getSearchText()) |
|||
.ifNotExists() |
|||
); |
|||
if (rs.wasApplied()) { |
|||
return Optional.of(DaoUtil.getData(entity)); |
|||
} else { |
|||
return Optional.empty(); |
|||
} |
|||
} |
|||
} |
|||
@ -1,77 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.customer; |
|||
|
|||
import com.datastax.driver.core.querybuilder.Select; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.common.data.Customer; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.page.TextPageLink; |
|||
import org.thingsboard.server.dao.DaoUtil; |
|||
import org.thingsboard.server.dao.model.ModelConstants; |
|||
import org.thingsboard.server.dao.model.nosql.CustomerEntity; |
|||
import org.thingsboard.server.dao.nosql.CassandraAbstractSearchTextDao; |
|||
import org.thingsboard.server.dao.util.NoSqlDao; |
|||
|
|||
import java.util.Arrays; |
|||
import java.util.List; |
|||
import java.util.Optional; |
|||
import java.util.UUID; |
|||
|
|||
import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; |
|||
import static com.datastax.driver.core.querybuilder.QueryBuilder.select; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.CUSTOMER_BY_TENANT_AND_TITLE_VIEW_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.CUSTOMER_TENANT_ID_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.CUSTOMER_TITLE_PROPERTY; |
|||
|
|||
@Component |
|||
@Slf4j |
|||
@NoSqlDao |
|||
public class CassandraCustomerDao extends CassandraAbstractSearchTextDao<CustomerEntity, Customer> implements CustomerDao { |
|||
|
|||
@Override |
|||
protected Class<CustomerEntity> getColumnFamilyClass() { |
|||
return CustomerEntity.class; |
|||
} |
|||
|
|||
@Override |
|||
protected String getColumnFamilyName() { |
|||
return ModelConstants.CUSTOMER_COLUMN_FAMILY_NAME; |
|||
} |
|||
|
|||
@Override |
|||
public List<Customer> findCustomersByTenantId(UUID tenantId, TextPageLink pageLink) { |
|||
log.debug("Try to find customers by tenantId [{}] and pageLink [{}]", tenantId, pageLink); |
|||
List<CustomerEntity> customerEntities = findPageWithTextSearch(new TenantId(tenantId), ModelConstants.CUSTOMER_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, |
|||
Arrays.asList(eq(ModelConstants.CUSTOMER_TENANT_ID_PROPERTY, tenantId)), |
|||
pageLink); |
|||
log.trace("Found customers [{}] by tenantId [{}] and pageLink [{}]", customerEntities, tenantId, pageLink); |
|||
return DaoUtil.convertDataList(customerEntities); |
|||
} |
|||
|
|||
@Override |
|||
public Optional<Customer> findCustomersByTenantIdAndTitle(UUID tenantId, String title) { |
|||
Select select = select().from(CUSTOMER_BY_TENANT_AND_TITLE_VIEW_NAME); |
|||
Select.Where query = select.where(); |
|||
query.and(eq(CUSTOMER_TENANT_ID_PROPERTY, tenantId)); |
|||
query.and(eq(CUSTOMER_TITLE_PROPERTY, title)); |
|||
CustomerEntity customerEntity = findOneByStatement(new TenantId(tenantId), query); |
|||
Customer customer = DaoUtil.getData(customerEntity); |
|||
return Optional.ofNullable(customer); |
|||
} |
|||
|
|||
} |
|||
@ -1,39 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.dashboard; |
|||
|
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.common.data.Dashboard; |
|||
import org.thingsboard.server.dao.model.nosql.DashboardEntity; |
|||
import org.thingsboard.server.dao.nosql.CassandraAbstractSearchTextDao; |
|||
import org.thingsboard.server.dao.util.NoSqlDao; |
|||
|
|||
import static org.thingsboard.server.dao.model.ModelConstants.DASHBOARD_COLUMN_FAMILY_NAME; |
|||
|
|||
@Component |
|||
@NoSqlDao |
|||
public class CassandraDashboardDao extends CassandraAbstractSearchTextDao<DashboardEntity, Dashboard> implements DashboardDao { |
|||
|
|||
@Override |
|||
protected Class<DashboardEntity> getColumnFamilyClass() { |
|||
return DashboardEntity.class; |
|||
} |
|||
|
|||
@Override |
|||
protected String getColumnFamilyName() { |
|||
return DASHBOARD_COLUMN_FAMILY_NAME; |
|||
} |
|||
} |
|||
@ -1,91 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.dashboard; |
|||
|
|||
import com.google.common.util.concurrent.Futures; |
|||
import com.google.common.util.concurrent.ListenableFuture; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.common.data.DashboardInfo; |
|||
import org.thingsboard.server.common.data.EntityType; |
|||
import org.thingsboard.server.common.data.id.CustomerId; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.page.TextPageLink; |
|||
import org.thingsboard.server.common.data.page.TimePageLink; |
|||
import org.thingsboard.server.common.data.relation.EntityRelation; |
|||
import org.thingsboard.server.common.data.relation.RelationTypeGroup; |
|||
import org.thingsboard.server.dao.DaoUtil; |
|||
import org.thingsboard.server.dao.model.nosql.DashboardInfoEntity; |
|||
import org.thingsboard.server.dao.nosql.CassandraAbstractSearchTextDao; |
|||
import org.thingsboard.server.dao.relation.RelationDao; |
|||
import org.thingsboard.server.dao.util.NoSqlDao; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.Collections; |
|||
import java.util.List; |
|||
import java.util.UUID; |
|||
|
|||
import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.DASHBOARD_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.DASHBOARD_COLUMN_FAMILY_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.DASHBOARD_TENANT_ID_PROPERTY; |
|||
|
|||
@Component |
|||
@Slf4j |
|||
@NoSqlDao |
|||
public class CassandraDashboardInfoDao extends CassandraAbstractSearchTextDao<DashboardInfoEntity, DashboardInfo> implements DashboardInfoDao { |
|||
|
|||
@Autowired |
|||
private RelationDao relationDao; |
|||
|
|||
@Override |
|||
protected Class<DashboardInfoEntity> getColumnFamilyClass() { |
|||
return DashboardInfoEntity.class; |
|||
} |
|||
|
|||
@Override |
|||
protected String getColumnFamilyName() { |
|||
return DASHBOARD_COLUMN_FAMILY_NAME; |
|||
} |
|||
|
|||
@Override |
|||
public List<DashboardInfo> findDashboardsByTenantId(UUID tenantId, TextPageLink pageLink) { |
|||
log.debug("Try to find dashboards by tenantId [{}] and pageLink [{}]", tenantId, pageLink); |
|||
List<DashboardInfoEntity> dashboardEntities = findPageWithTextSearch(new TenantId(tenantId), DASHBOARD_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, |
|||
Collections.singletonList(eq(DASHBOARD_TENANT_ID_PROPERTY, tenantId)), |
|||
pageLink); |
|||
|
|||
log.trace("Found dashboards [{}] by tenantId [{}] and pageLink [{}]", dashboardEntities, tenantId, pageLink); |
|||
return DaoUtil.convertDataList(dashboardEntities); |
|||
} |
|||
|
|||
@Override |
|||
public ListenableFuture<List<DashboardInfo>> findDashboardsByTenantIdAndCustomerId(UUID tenantId, UUID customerId, TimePageLink pageLink) { |
|||
log.debug("Try to find dashboards by tenantId [{}], customerId[{}] and pageLink [{}]", tenantId, customerId, pageLink); |
|||
|
|||
ListenableFuture<List<EntityRelation>> relations = relationDao.findRelations(new TenantId(tenantId), new CustomerId(customerId), EntityRelation.CONTAINS_TYPE, RelationTypeGroup.DASHBOARD, EntityType.DASHBOARD, pageLink); |
|||
|
|||
return Futures.transformAsync(relations, input -> { |
|||
List<ListenableFuture<DashboardInfo>> dashboardFutures = new ArrayList<>(input.size()); |
|||
for (EntityRelation relation : input) { |
|||
dashboardFutures.add(findByIdAsync(new TenantId(tenantId), relation.getTo().getId())); |
|||
} |
|||
return Futures.successfulAsList(dashboardFutures); |
|||
}); |
|||
} |
|||
|
|||
} |
|||
@ -1,70 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.device; |
|||
|
|||
import com.datastax.driver.core.querybuilder.Select.Where; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.security.DeviceCredentials; |
|||
import org.thingsboard.server.dao.DaoUtil; |
|||
import org.thingsboard.server.dao.model.ModelConstants; |
|||
import org.thingsboard.server.dao.model.nosql.DeviceCredentialsEntity; |
|||
import org.thingsboard.server.dao.nosql.CassandraAbstractModelDao; |
|||
import org.thingsboard.server.dao.util.NoSqlDao; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; |
|||
import static com.datastax.driver.core.querybuilder.QueryBuilder.select; |
|||
|
|||
@Component |
|||
@Slf4j |
|||
@NoSqlDao |
|||
public class CassandraDeviceCredentialsDao extends CassandraAbstractModelDao<DeviceCredentialsEntity, DeviceCredentials> implements DeviceCredentialsDao { |
|||
|
|||
@Override |
|||
protected Class<DeviceCredentialsEntity> getColumnFamilyClass() { |
|||
return DeviceCredentialsEntity.class; |
|||
} |
|||
|
|||
@Override |
|||
protected String getColumnFamilyName() { |
|||
return ModelConstants.DEVICE_CREDENTIALS_COLUMN_FAMILY_NAME; |
|||
} |
|||
|
|||
@Override |
|||
public DeviceCredentials findByDeviceId(TenantId tenantId, UUID deviceId) { |
|||
log.debug("Try to find device credentials by deviceId [{}] ", deviceId); |
|||
Where query = select().from(ModelConstants.DEVICE_CREDENTIALS_BY_DEVICE_COLUMN_FAMILY_NAME) |
|||
.where(eq(ModelConstants.DEVICE_CREDENTIALS_DEVICE_ID_PROPERTY, deviceId)); |
|||
log.trace("Execute query {}", query); |
|||
DeviceCredentialsEntity deviceCredentialsEntity = findOneByStatement(tenantId, query); |
|||
log.trace("Found device credentials [{}] by deviceId [{}]", deviceCredentialsEntity, deviceId); |
|||
return DaoUtil.getData(deviceCredentialsEntity); |
|||
} |
|||
|
|||
@Override |
|||
public DeviceCredentials findByCredentialsId(TenantId tenantId, String credentialsId) { |
|||
log.debug("Try to find device credentials by credentialsId [{}] ", credentialsId); |
|||
Where query = select().from(ModelConstants.DEVICE_CREDENTIALS_BY_CREDENTIALS_ID_COLUMN_FAMILY_NAME) |
|||
.where(eq(ModelConstants.DEVICE_CREDENTIALS_CREDENTIALS_ID_PROPERTY, credentialsId)); |
|||
log.trace("Execute query {}", query); |
|||
DeviceCredentialsEntity deviceCredentialsEntity = findOneByStatement(tenantId, query); |
|||
log.trace("Found device credentials [{}] by credentialsId [{}]", deviceCredentialsEntity, credentialsId); |
|||
return DaoUtil.getData(deviceCredentialsEntity); |
|||
} |
|||
} |
|||
@ -1,191 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.device; |
|||
|
|||
import com.datastax.driver.core.ResultSet; |
|||
import com.datastax.driver.core.ResultSetFuture; |
|||
import com.datastax.driver.core.Statement; |
|||
import com.datastax.driver.core.querybuilder.Select; |
|||
import com.datastax.driver.mapping.Result; |
|||
import com.google.common.base.Function; |
|||
import com.google.common.util.concurrent.Futures; |
|||
import com.google.common.util.concurrent.ListenableFuture; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.common.data.Device; |
|||
import org.thingsboard.server.common.data.EntitySubtype; |
|||
import org.thingsboard.server.common.data.EntityType; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.page.TextPageLink; |
|||
import org.thingsboard.server.dao.DaoUtil; |
|||
import org.thingsboard.server.dao.model.EntitySubtypeEntity; |
|||
import org.thingsboard.server.dao.model.nosql.DeviceEntity; |
|||
import org.thingsboard.server.dao.nosql.CassandraAbstractSearchTextDao; |
|||
import org.thingsboard.server.dao.util.NoSqlDao; |
|||
|
|||
import javax.annotation.Nullable; |
|||
import java.util.ArrayList; |
|||
import java.util.Arrays; |
|||
import java.util.Collections; |
|||
import java.util.List; |
|||
import java.util.Optional; |
|||
import java.util.UUID; |
|||
|
|||
import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; |
|||
import static com.datastax.driver.core.querybuilder.QueryBuilder.in; |
|||
import static com.datastax.driver.core.querybuilder.QueryBuilder.select; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.DEVICE_BY_CUSTOMER_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.DEVICE_BY_CUSTOMER_BY_TYPE_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.DEVICE_BY_TENANT_AND_NAME_VIEW_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.DEVICE_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.DEVICE_BY_TENANT_BY_TYPE_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.DEVICE_COLUMN_FAMILY_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.DEVICE_CUSTOMER_ID_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.DEVICE_NAME_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.DEVICE_TENANT_ID_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.DEVICE_TYPE_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ENTITY_SUBTYPE_COLUMN_FAMILY_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ENTITY_SUBTYPE_ENTITY_TYPE_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ENTITY_SUBTYPE_TENANT_ID_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ID_PROPERTY; |
|||
|
|||
@Component |
|||
@Slf4j |
|||
@NoSqlDao |
|||
public class CassandraDeviceDao extends CassandraAbstractSearchTextDao<DeviceEntity, Device> implements DeviceDao { |
|||
|
|||
@Override |
|||
protected Class<DeviceEntity> getColumnFamilyClass() { |
|||
return DeviceEntity.class; |
|||
} |
|||
|
|||
@Override |
|||
protected String getColumnFamilyName() { |
|||
return DEVICE_COLUMN_FAMILY_NAME; |
|||
} |
|||
|
|||
@Override |
|||
public Device save(TenantId tenantId, Device domain) { |
|||
Device savedDevice = super.save(tenantId, domain); |
|||
EntitySubtype entitySubtype = new EntitySubtype(savedDevice.getTenantId(), EntityType.DEVICE, savedDevice.getType()); |
|||
EntitySubtypeEntity entitySubtypeEntity = new EntitySubtypeEntity(entitySubtype); |
|||
Statement saveStatement = cluster.getMapper(EntitySubtypeEntity.class).saveQuery(entitySubtypeEntity); |
|||
executeWrite(tenantId, saveStatement); |
|||
return savedDevice; |
|||
} |
|||
|
|||
@Override |
|||
public List<Device> findDevicesByTenantId(UUID tenantId, TextPageLink pageLink) { |
|||
log.debug("Try to find devices by tenantId [{}] and pageLink [{}]", tenantId, pageLink); |
|||
List<DeviceEntity> deviceEntities = findPageWithTextSearch(new TenantId(tenantId), DEVICE_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, |
|||
Collections.singletonList(eq(DEVICE_TENANT_ID_PROPERTY, tenantId)), pageLink); |
|||
|
|||
log.trace("Found devices [{}] by tenantId [{}] and pageLink [{}]", deviceEntities, tenantId, pageLink); |
|||
return DaoUtil.convertDataList(deviceEntities); |
|||
} |
|||
|
|||
@Override |
|||
public List<Device> findDevicesByTenantIdAndType(UUID tenantId, String type, TextPageLink pageLink) { |
|||
log.debug("Try to find devices by tenantId [{}], type [{}] and pageLink [{}]", tenantId, type, pageLink); |
|||
List<DeviceEntity> deviceEntities = findPageWithTextSearch(new TenantId(tenantId), DEVICE_BY_TENANT_BY_TYPE_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, |
|||
Arrays.asList(eq(DEVICE_TYPE_PROPERTY, type), |
|||
eq(DEVICE_TENANT_ID_PROPERTY, tenantId)), pageLink); |
|||
log.trace("Found devices [{}] by tenantId [{}], type [{}] and pageLink [{}]", deviceEntities, tenantId, type, pageLink); |
|||
return DaoUtil.convertDataList(deviceEntities); |
|||
} |
|||
|
|||
@Override |
|||
public ListenableFuture<List<Device>> findDevicesByTenantIdAndIdsAsync(UUID tenantId, List<UUID> deviceIds) { |
|||
log.debug("Try to find devices by tenantId [{}] and device Ids [{}]", tenantId, deviceIds); |
|||
Select select = select().from(getColumnFamilyName()); |
|||
Select.Where query = select.where(); |
|||
query.and(eq(DEVICE_TENANT_ID_PROPERTY, tenantId)); |
|||
query.and(in(ID_PROPERTY, deviceIds)); |
|||
return findListByStatementAsync(new TenantId(tenantId), query); |
|||
} |
|||
|
|||
@Override |
|||
public List<Device> findDevicesByTenantIdAndCustomerId(UUID tenantId, UUID customerId, TextPageLink pageLink) { |
|||
log.debug("Try to find devices by tenantId [{}], customerId[{}] and pageLink [{}]", tenantId, customerId, pageLink); |
|||
List<DeviceEntity> deviceEntities = findPageWithTextSearch(new TenantId(tenantId), DEVICE_BY_CUSTOMER_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, |
|||
Arrays.asList(eq(DEVICE_CUSTOMER_ID_PROPERTY, customerId), |
|||
eq(DEVICE_TENANT_ID_PROPERTY, tenantId)), |
|||
pageLink); |
|||
|
|||
log.trace("Found devices [{}] by tenantId [{}], customerId [{}] and pageLink [{}]", deviceEntities, tenantId, customerId, pageLink); |
|||
return DaoUtil.convertDataList(deviceEntities); |
|||
} |
|||
|
|||
@Override |
|||
public List<Device> findDevicesByTenantIdAndCustomerIdAndType(UUID tenantId, UUID customerId, String type, TextPageLink pageLink) { |
|||
log.debug("Try to find devices by tenantId [{}], customerId [{}], type [{}] and pageLink [{}]", tenantId, customerId, type, pageLink); |
|||
List<DeviceEntity> deviceEntities = findPageWithTextSearch(new TenantId(tenantId), DEVICE_BY_CUSTOMER_BY_TYPE_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, |
|||
Arrays.asList(eq(DEVICE_TYPE_PROPERTY, type), |
|||
eq(DEVICE_CUSTOMER_ID_PROPERTY, customerId), |
|||
eq(DEVICE_TENANT_ID_PROPERTY, tenantId)), |
|||
pageLink); |
|||
|
|||
log.trace("Found devices [{}] by tenantId [{}], customerId [{}], type [{}] and pageLink [{}]", deviceEntities, tenantId, customerId, type, pageLink); |
|||
return DaoUtil.convertDataList(deviceEntities); |
|||
} |
|||
|
|||
@Override |
|||
public ListenableFuture<List<Device>> findDevicesByTenantIdCustomerIdAndIdsAsync(UUID tenantId, UUID customerId, List<UUID> deviceIds) { |
|||
log.debug("Try to find devices by tenantId [{}], customerId [{}] and device Ids [{}]", tenantId, customerId, deviceIds); |
|||
Select select = select().from(getColumnFamilyName()); |
|||
Select.Where query = select.where(); |
|||
query.and(eq(DEVICE_TENANT_ID_PROPERTY, tenantId)); |
|||
query.and(eq(DEVICE_CUSTOMER_ID_PROPERTY, customerId)); |
|||
query.and(in(ID_PROPERTY, deviceIds)); |
|||
return findListByStatementAsync(new TenantId(tenantId), query); |
|||
} |
|||
|
|||
@Override |
|||
public Optional<Device> findDeviceByTenantIdAndName(UUID tenantId, String deviceName) { |
|||
Select select = select().from(DEVICE_BY_TENANT_AND_NAME_VIEW_NAME); |
|||
Select.Where query = select.where(); |
|||
query.and(eq(DEVICE_TENANT_ID_PROPERTY, tenantId)); |
|||
query.and(eq(DEVICE_NAME_PROPERTY, deviceName)); |
|||
return Optional.ofNullable(DaoUtil.getData(findOneByStatement(new TenantId(tenantId), query))); |
|||
} |
|||
|
|||
@Override |
|||
public ListenableFuture<List<EntitySubtype>> findTenantDeviceTypesAsync(UUID tenantId) { |
|||
Select select = select().from(ENTITY_SUBTYPE_COLUMN_FAMILY_NAME); |
|||
Select.Where query = select.where(); |
|||
query.and(eq(ENTITY_SUBTYPE_TENANT_ID_PROPERTY, tenantId)); |
|||
query.and(eq(ENTITY_SUBTYPE_ENTITY_TYPE_PROPERTY, EntityType.DEVICE)); |
|||
query.setConsistencyLevel(cluster.getDefaultReadConsistencyLevel()); |
|||
ResultSetFuture resultSetFuture = executeAsyncRead(new TenantId(tenantId), query); |
|||
return Futures.transform(resultSetFuture, new Function<ResultSet, List<EntitySubtype>>() { |
|||
@Nullable |
|||
@Override |
|||
public List<EntitySubtype> apply(@Nullable ResultSet resultSet) { |
|||
Result<EntitySubtypeEntity> result = cluster.getMapper(EntitySubtypeEntity.class).map(resultSet); |
|||
if (result != null) { |
|||
List<EntitySubtype> entitySubtypes = new ArrayList<>(); |
|||
result.all().forEach((entitySubtypeEntity) -> |
|||
entitySubtypes.add(entitySubtypeEntity.toEntitySubtype()) |
|||
); |
|||
return entitySubtypes; |
|||
} else { |
|||
return Collections.emptyList(); |
|||
} |
|||
} |
|||
}); |
|||
} |
|||
|
|||
} |
|||
@ -1,186 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.entityview; |
|||
|
|||
import com.datastax.driver.core.ResultSet; |
|||
import com.datastax.driver.core.ResultSetFuture; |
|||
import com.datastax.driver.core.Statement; |
|||
import com.datastax.driver.core.querybuilder.Select; |
|||
import com.datastax.driver.mapping.Result; |
|||
import com.google.common.base.Function; |
|||
import com.google.common.util.concurrent.Futures; |
|||
import com.google.common.util.concurrent.ListenableFuture; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.common.data.EntitySubtype; |
|||
import org.thingsboard.server.common.data.EntityType; |
|||
import org.thingsboard.server.common.data.EntityView; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.page.TextPageLink; |
|||
import org.thingsboard.server.dao.DaoUtil; |
|||
import org.thingsboard.server.dao.model.EntitySubtypeEntity; |
|||
import org.thingsboard.server.dao.model.nosql.EntityViewEntity; |
|||
import org.thingsboard.server.dao.nosql.CassandraAbstractSearchTextDao; |
|||
import org.thingsboard.server.dao.util.NoSqlDao; |
|||
|
|||
import javax.annotation.Nullable; |
|||
import java.util.ArrayList; |
|||
import java.util.Arrays; |
|||
import java.util.Collections; |
|||
import java.util.List; |
|||
import java.util.Optional; |
|||
import java.util.UUID; |
|||
|
|||
import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; |
|||
import static com.datastax.driver.core.querybuilder.QueryBuilder.select; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.CUSTOMER_ID_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.DEVICE_TYPE_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ENTITY_ID_COLUMN; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ENTITY_SUBTYPE_COLUMN_FAMILY_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ENTITY_SUBTYPE_ENTITY_TYPE_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ENTITY_SUBTYPE_TENANT_ID_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ENTITY_VIEW_BY_TENANT_AND_CUSTOMER_AND_TYPE_CF; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ENTITY_VIEW_BY_TENANT_AND_CUSTOMER_CF; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ENTITY_VIEW_BY_TENANT_AND_ENTITY_ID_CF; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ENTITY_VIEW_BY_TENANT_AND_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ENTITY_VIEW_BY_TENANT_AND_SEARCH_TEXT_CF; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ENTITY_VIEW_BY_TENANT_BY_TYPE_AND_SEARCH_TEXT_CF; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ENTITY_VIEW_NAME_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ENTITY_VIEW_TABLE_FAMILY_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ENTITY_VIEW_TENANT_ID_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ENTITY_VIEW_TYPE_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.TENANT_ID_PROPERTY; |
|||
|
|||
/** |
|||
* Created by Victor Basanets on 9/06/2017. |
|||
*/ |
|||
@Component |
|||
@Slf4j |
|||
@NoSqlDao |
|||
public class CassandraEntityViewDao extends CassandraAbstractSearchTextDao<EntityViewEntity, EntityView> implements EntityViewDao { |
|||
|
|||
@Override |
|||
protected Class<EntityViewEntity> getColumnFamilyClass() { |
|||
return EntityViewEntity.class; |
|||
} |
|||
|
|||
@Override |
|||
protected String getColumnFamilyName() { |
|||
return ENTITY_VIEW_TABLE_FAMILY_NAME; |
|||
} |
|||
|
|||
@Override |
|||
public EntityView save(TenantId tenantId, EntityView domain) { |
|||
EntityView savedEntityView = super.save(domain.getTenantId(), domain); |
|||
EntitySubtype entitySubtype = new EntitySubtype(savedEntityView.getTenantId(), EntityType.ENTITY_VIEW, savedEntityView.getType()); |
|||
EntitySubtypeEntity entitySubtypeEntity = new EntitySubtypeEntity(entitySubtype); |
|||
Statement saveStatement = cluster.getMapper(EntitySubtypeEntity.class).saveQuery(entitySubtypeEntity); |
|||
executeWrite(tenantId, saveStatement); |
|||
return savedEntityView; |
|||
} |
|||
|
|||
@Override |
|||
public List<EntityView> findEntityViewsByTenantId(UUID tenantId, TextPageLink pageLink) { |
|||
log.debug("Try to find entity views by tenantId [{}] and pageLink [{}]", tenantId, pageLink); |
|||
List<EntityViewEntity> entityViewEntities = |
|||
findPageWithTextSearch(new TenantId(tenantId), ENTITY_VIEW_BY_TENANT_AND_SEARCH_TEXT_CF, |
|||
Collections.singletonList(eq(TENANT_ID_PROPERTY, tenantId)), pageLink); |
|||
log.trace("Found entity views [{}] by tenantId [{}] and pageLink [{}]", |
|||
entityViewEntities, tenantId, pageLink); |
|||
return DaoUtil.convertDataList(entityViewEntities); |
|||
} |
|||
|
|||
@Override |
|||
public List<EntityView> findEntityViewsByTenantIdAndType(UUID tenantId, String type, TextPageLink pageLink) { |
|||
log.debug("Try to find entity views by tenantId [{}], type [{}] and pageLink [{}]", tenantId, type, pageLink); |
|||
List<EntityViewEntity> entityViewEntities = |
|||
findPageWithTextSearch(new TenantId(tenantId), ENTITY_VIEW_BY_TENANT_BY_TYPE_AND_SEARCH_TEXT_CF, |
|||
Arrays.asList(eq(ENTITY_VIEW_TYPE_PROPERTY, type), |
|||
eq(TENANT_ID_PROPERTY, tenantId)), pageLink); |
|||
log.trace("Found entity views [{}] by tenantId [{}], type [{}] and pageLink [{}]", |
|||
entityViewEntities, tenantId, type, pageLink); |
|||
return DaoUtil.convertDataList(entityViewEntities); |
|||
} |
|||
|
|||
@Override |
|||
public Optional<EntityView> findEntityViewByTenantIdAndName(UUID tenantId, String name) { |
|||
Select.Where query = select().from(ENTITY_VIEW_BY_TENANT_AND_NAME).where(); |
|||
query.and(eq(ENTITY_VIEW_TENANT_ID_PROPERTY, tenantId)); |
|||
query.and(eq(ENTITY_VIEW_NAME_PROPERTY, name)); |
|||
return Optional.ofNullable(DaoUtil.getData(findOneByStatement(new TenantId(tenantId), query))); |
|||
} |
|||
|
|||
@Override |
|||
public List<EntityView> findEntityViewsByTenantIdAndCustomerId(UUID tenantId, UUID customerId, TextPageLink pageLink) { |
|||
log.debug("Try to find entity views by tenantId [{}], customerId[{}] and pageLink [{}]", |
|||
tenantId, customerId, pageLink); |
|||
List<EntityViewEntity> entityViewEntities = findPageWithTextSearch(new TenantId(tenantId), |
|||
ENTITY_VIEW_BY_TENANT_AND_CUSTOMER_CF, |
|||
Arrays.asList(eq(CUSTOMER_ID_PROPERTY, customerId), eq(TENANT_ID_PROPERTY, tenantId)), |
|||
pageLink); |
|||
log.trace("Found find entity views [{}] by tenantId [{}], customerId [{}] and pageLink [{}]", |
|||
entityViewEntities, tenantId, customerId, pageLink); |
|||
return DaoUtil.convertDataList(entityViewEntities); |
|||
} |
|||
|
|||
@Override |
|||
public List<EntityView> findEntityViewsByTenantIdAndCustomerIdAndType(UUID tenantId, UUID customerId, String type, TextPageLink pageLink) { |
|||
log.debug("Try to find entity views by tenantId [{}], customerId[{}], type [{}] and pageLink [{}]", |
|||
tenantId, customerId, type, pageLink); |
|||
List<EntityViewEntity> entityViewEntities = findPageWithTextSearch(new TenantId(tenantId), |
|||
ENTITY_VIEW_BY_TENANT_AND_CUSTOMER_AND_TYPE_CF, |
|||
Arrays.asList(eq(DEVICE_TYPE_PROPERTY, type), eq(CUSTOMER_ID_PROPERTY, customerId), eq(TENANT_ID_PROPERTY, tenantId)), |
|||
pageLink); |
|||
log.trace("Found find entity views [{}] by tenantId [{}], customerId [{}], type [{}] and pageLink [{}]", |
|||
entityViewEntities, tenantId, customerId, type, pageLink); |
|||
return DaoUtil.convertDataList(entityViewEntities); |
|||
} |
|||
|
|||
@Override |
|||
public ListenableFuture<List<EntityView>> findEntityViewsByTenantIdAndEntityIdAsync(UUID tenantId, UUID entityId) { |
|||
log.debug("Try to find entity views by tenantId [{}] and entityId [{}]", tenantId, entityId); |
|||
Select.Where query = select().from(ENTITY_VIEW_BY_TENANT_AND_ENTITY_ID_CF).where(); |
|||
query.and(eq(TENANT_ID_PROPERTY, tenantId)); |
|||
query.and(eq(ENTITY_ID_COLUMN, entityId)); |
|||
return findListByStatementAsync(new TenantId(tenantId), query); |
|||
} |
|||
|
|||
@Override |
|||
public ListenableFuture<List<EntitySubtype>> findTenantEntityViewTypesAsync(UUID tenantId) { |
|||
Select select = select().from(ENTITY_SUBTYPE_COLUMN_FAMILY_NAME); |
|||
Select.Where query = select.where(); |
|||
query.and(eq(ENTITY_SUBTYPE_TENANT_ID_PROPERTY, tenantId)); |
|||
query.and(eq(ENTITY_SUBTYPE_ENTITY_TYPE_PROPERTY, EntityType.ENTITY_VIEW)); |
|||
query.setConsistencyLevel(cluster.getDefaultReadConsistencyLevel()); |
|||
ResultSetFuture resultSetFuture = executeAsyncRead(new TenantId(tenantId), query); |
|||
return Futures.transform(resultSetFuture, new Function<ResultSet, List<EntitySubtype>>() { |
|||
@Nullable |
|||
@Override |
|||
public List<EntitySubtype> apply(@Nullable ResultSet resultSet) { |
|||
Result<EntitySubtypeEntity> result = cluster.getMapper(EntitySubtypeEntity.class).map(resultSet); |
|||
if (result != null) { |
|||
List<EntitySubtype> entitySubtypes = new ArrayList<>(); |
|||
result.all().forEach((entitySubtypeEntity) -> |
|||
entitySubtypes.add(entitySubtypeEntity.toEntitySubtype()) |
|||
); |
|||
return entitySubtypes; |
|||
} else { |
|||
return Collections.emptyList(); |
|||
} |
|||
} |
|||
}); |
|||
} |
|||
} |
|||
@ -1,215 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.event; |
|||
|
|||
import com.datastax.driver.core.ResultSetFuture; |
|||
import com.datastax.driver.core.querybuilder.Insert; |
|||
import com.datastax.driver.core.querybuilder.QueryBuilder; |
|||
import com.datastax.driver.core.querybuilder.Select; |
|||
import com.datastax.driver.core.utils.UUIDs; |
|||
import com.google.common.util.concurrent.Futures; |
|||
import com.google.common.util.concurrent.ListenableFuture; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
import org.springframework.beans.factory.annotation.Value; |
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.common.data.DataConstants; |
|||
import org.thingsboard.server.common.data.Event; |
|||
import org.thingsboard.server.common.data.id.EntityId; |
|||
import org.thingsboard.server.common.data.id.EventId; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.page.TimePageLink; |
|||
import org.thingsboard.server.dao.DaoUtil; |
|||
import org.thingsboard.server.dao.model.ModelConstants; |
|||
import org.thingsboard.server.dao.model.nosql.EventEntity; |
|||
import org.thingsboard.server.dao.nosql.CassandraAbstractSearchTimeDao; |
|||
import org.thingsboard.server.dao.util.NoSqlDao; |
|||
|
|||
import java.util.Arrays; |
|||
import java.util.List; |
|||
import java.util.Optional; |
|||
import java.util.UUID; |
|||
import java.util.concurrent.ExecutionException; |
|||
|
|||
import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; |
|||
import static com.datastax.driver.core.querybuilder.QueryBuilder.in; |
|||
import static com.datastax.driver.core.querybuilder.QueryBuilder.select; |
|||
import static com.datastax.driver.core.querybuilder.QueryBuilder.ttl; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.*; |
|||
|
|||
@Component |
|||
@Slf4j |
|||
@NoSqlDao |
|||
public class CassandraBaseEventDao extends CassandraAbstractSearchTimeDao<EventEntity, Event> implements EventDao { |
|||
|
|||
private final TenantId systemTenantId = new TenantId(NULL_UUID); |
|||
|
|||
@Override |
|||
protected Class<EventEntity> getColumnFamilyClass() { |
|||
return EventEntity.class; |
|||
} |
|||
|
|||
@Override |
|||
protected String getColumnFamilyName() { |
|||
return EVENT_COLUMN_FAMILY_NAME; |
|||
} |
|||
|
|||
@Value("${cassandra.query.events_ttl:0}") |
|||
private int eventsTtl; |
|||
|
|||
@Value("${cassandra.query.debug_events_ttl:0}") |
|||
private int debugEventsTtl; |
|||
|
|||
@Override |
|||
public Event save(TenantId tenantId, Event event) { |
|||
try { |
|||
return saveAsync(event).get(); |
|||
} catch (InterruptedException | ExecutionException e) { |
|||
throw new IllegalStateException("Could not save EventEntity", e); |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public ListenableFuture<Event> saveAsync(Event event) { |
|||
log.debug("Save event [{}] ", event); |
|||
if (event.getTenantId() == null) { |
|||
log.trace("Save system event with predefined id {}", systemTenantId); |
|||
event.setTenantId(systemTenantId); |
|||
} |
|||
if (event.getId() == null) { |
|||
event.setId(new EventId(UUIDs.timeBased())); |
|||
} |
|||
if (StringUtils.isEmpty(event.getUid())) { |
|||
event.setUid(event.getId().toString()); |
|||
} |
|||
ListenableFuture<Optional<Event>> optionalSave = saveAsync(event.getTenantId(), new EventEntity(event), false, eventsTtl); |
|||
return Futures.transform(optionalSave, opt -> opt.orElse(null)); |
|||
} |
|||
|
|||
@Override |
|||
public Optional<Event> saveIfNotExists(Event event) { |
|||
if (event.getTenantId() == null) { |
|||
log.trace("Save system event with predefined id {}", systemTenantId); |
|||
event.setTenantId(systemTenantId); |
|||
} |
|||
if (event.getId() == null) { |
|||
event.setId(new EventId(UUIDs.timeBased())); |
|||
} |
|||
return save(event.getTenantId(), new EventEntity(event), true, eventsTtl); |
|||
} |
|||
|
|||
@Override |
|||
public Event findEvent(UUID tenantId, EntityId entityId, String eventType, String eventUid) { |
|||
log.debug("Search event entity by [{}][{}][{}][{}]", tenantId, entityId, eventType, eventUid); |
|||
Select.Where query = select().from(getColumnFamilyName()).where( |
|||
eq(ModelConstants.EVENT_TENANT_ID_PROPERTY, tenantId)) |
|||
.and(eq(ModelConstants.EVENT_ENTITY_TYPE_PROPERTY, entityId.getEntityType())) |
|||
.and(eq(ModelConstants.EVENT_ENTITY_ID_PROPERTY, entityId.getId())) |
|||
.and(eq(ModelConstants.EVENT_TYPE_PROPERTY, eventType)) |
|||
.and(eq(ModelConstants.EVENT_UID_PROPERTY, eventUid)); |
|||
log.trace("Execute query [{}]", query); |
|||
EventEntity entity = findOneByStatement(new TenantId(tenantId), query); |
|||
if (log.isTraceEnabled()) { |
|||
log.trace("Search result: [{}] for event entity [{}]", entity != null, entity); |
|||
} else { |
|||
log.debug("Search result: [{}]", entity != null); |
|||
} |
|||
return DaoUtil.getData(entity); |
|||
} |
|||
|
|||
@Override |
|||
public List<Event> findEvents(UUID tenantId, EntityId entityId, TimePageLink pageLink) { |
|||
log.trace("Try to find events by tenant [{}], entity [{}]and pageLink [{}]", tenantId, entityId, pageLink); |
|||
List<EventEntity> entities = findPageWithTimeSearch(new TenantId(tenantId), EVENT_BY_ID_VIEW_NAME, |
|||
Arrays.asList(eq(ModelConstants.EVENT_TENANT_ID_PROPERTY, tenantId), |
|||
eq(ModelConstants.EVENT_ENTITY_TYPE_PROPERTY, entityId.getEntityType()), |
|||
eq(ModelConstants.EVENT_ENTITY_ID_PROPERTY, entityId.getId())), |
|||
pageLink); |
|||
log.trace("Found events by tenant [{}], entity [{}] and pageLink [{}]", tenantId, entityId, pageLink); |
|||
return DaoUtil.convertDataList(entities); |
|||
} |
|||
|
|||
@Override |
|||
public List<Event> findEvents(UUID tenantId, EntityId entityId, String eventType, TimePageLink pageLink) { |
|||
log.trace("Try to find events by tenant [{}], entity [{}], type [{}] and pageLink [{}]", tenantId, entityId, eventType, pageLink); |
|||
List<EventEntity> entities = findPageWithTimeSearch(new TenantId(tenantId), EVENT_BY_TYPE_AND_ID_VIEW_NAME, |
|||
Arrays.asList(eq(ModelConstants.EVENT_TENANT_ID_PROPERTY, tenantId), |
|||
eq(ModelConstants.EVENT_ENTITY_TYPE_PROPERTY, entityId.getEntityType()), |
|||
eq(ModelConstants.EVENT_ENTITY_ID_PROPERTY, entityId.getId()), |
|||
eq(ModelConstants.EVENT_TYPE_PROPERTY, eventType)), |
|||
pageLink.isAscOrder() ? QueryBuilder.asc(ModelConstants.EVENT_TYPE_PROPERTY) : |
|||
QueryBuilder.desc(ModelConstants.EVENT_TYPE_PROPERTY), |
|||
pageLink); |
|||
log.trace("Found events by tenant [{}], entity [{}], type [{}] and pageLink [{}]", tenantId, entityId, eventType, pageLink); |
|||
return DaoUtil.convertDataList(entities); |
|||
} |
|||
|
|||
@Override |
|||
public List<Event> findLatestEvents(UUID tenantId, EntityId entityId, String eventType, int limit) { |
|||
log.trace("Try to find latest events by tenant [{}], entity [{}], type [{}] and limit [{}]", tenantId, entityId, eventType, limit); |
|||
Select select = select().from(EVENT_BY_TYPE_AND_ID_VIEW_NAME); |
|||
Select.Where query = select.where(); |
|||
query.and(eq(ModelConstants.EVENT_TENANT_ID_PROPERTY, tenantId)); |
|||
query.and(eq(ModelConstants.EVENT_ENTITY_TYPE_PROPERTY, entityId.getEntityType())); |
|||
query.and(eq(ModelConstants.EVENT_ENTITY_ID_PROPERTY, entityId.getId())); |
|||
query.and(eq(ModelConstants.EVENT_TYPE_PROPERTY, eventType)); |
|||
query.limit(limit); |
|||
query.orderBy(QueryBuilder.desc(ModelConstants.EVENT_TYPE_PROPERTY), QueryBuilder.desc(ModelConstants.ID_PROPERTY)); |
|||
List<EventEntity> entities = findListByStatement(new TenantId(tenantId), query); |
|||
return DaoUtil.convertDataList(entities); |
|||
} |
|||
|
|||
private Optional<Event> save(TenantId tenantId, EventEntity entity, boolean ifNotExists, int ttl) { |
|||
try { |
|||
return saveAsync(tenantId, entity, ifNotExists, ttl).get(); |
|||
} catch (InterruptedException | ExecutionException e) { |
|||
throw new IllegalStateException("Could not save EventEntity", e); |
|||
} |
|||
} |
|||
|
|||
private ListenableFuture<Optional<Event>> saveAsync(TenantId tenantId, EventEntity entity, boolean ifNotExists, int ttl) { |
|||
if (entity.getId() == null) { |
|||
entity.setId(UUIDs.timeBased()); |
|||
} |
|||
Insert insert = QueryBuilder.insertInto(getColumnFamilyName()) |
|||
.value(ModelConstants.ID_PROPERTY, entity.getId()) |
|||
.value(ModelConstants.EVENT_TENANT_ID_PROPERTY, entity.getTenantId()) |
|||
.value(ModelConstants.EVENT_ENTITY_TYPE_PROPERTY, entity.getEntityType()) |
|||
.value(ModelConstants.EVENT_ENTITY_ID_PROPERTY, entity.getEntityId()) |
|||
.value(ModelConstants.EVENT_TYPE_PROPERTY, entity.getEventType()) |
|||
.value(ModelConstants.EVENT_UID_PROPERTY, entity.getEventUid()) |
|||
.value(ModelConstants.EVENT_BODY_PROPERTY, entity.getBody()); |
|||
|
|||
if (ifNotExists) { |
|||
insert = insert.ifNotExists(); |
|||
} |
|||
|
|||
int selectedTtl = (entity.getEventType().equals(DataConstants.DEBUG_RULE_NODE) || |
|||
entity.getEventType().equals(DataConstants.DEBUG_RULE_CHAIN)) ? debugEventsTtl : ttl; |
|||
|
|||
if (selectedTtl > 0) { |
|||
insert.using(ttl(selectedTtl)); |
|||
} |
|||
ResultSetFuture resultSetFuture = executeAsyncWrite(tenantId, insert); |
|||
return Futures.transform(resultSetFuture, rs -> { |
|||
if (rs.wasApplied()) { |
|||
return Optional.of(DaoUtil.getData(entity)); |
|||
} else { |
|||
return Optional.empty(); |
|||
} |
|||
}); |
|||
} |
|||
} |
|||
@ -1,97 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.model.nosql; |
|||
|
|||
import com.datastax.driver.core.utils.UUIDs; |
|||
import com.datastax.driver.mapping.annotations.Column; |
|||
import com.datastax.driver.mapping.annotations.PartitionKey; |
|||
import com.datastax.driver.mapping.annotations.Table; |
|||
import com.fasterxml.jackson.databind.JsonNode; |
|||
import lombok.EqualsAndHashCode; |
|||
import lombok.ToString; |
|||
import org.thingsboard.server.common.data.AdminSettings; |
|||
import org.thingsboard.server.common.data.id.AdminSettingsId; |
|||
import org.thingsboard.server.dao.model.BaseEntity; |
|||
import org.thingsboard.server.dao.model.type.JsonCodec; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
import static org.thingsboard.server.dao.model.ModelConstants.ADMIN_SETTINGS_COLUMN_FAMILY_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ADMIN_SETTINGS_JSON_VALUE_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ADMIN_SETTINGS_KEY_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ID_PROPERTY; |
|||
|
|||
@Table(name = ADMIN_SETTINGS_COLUMN_FAMILY_NAME) |
|||
@EqualsAndHashCode |
|||
@ToString |
|||
public final class AdminSettingsEntity implements BaseEntity<AdminSettings> { |
|||
|
|||
@PartitionKey(value = 0) |
|||
@Column(name = ID_PROPERTY) |
|||
private UUID id; |
|||
|
|||
@Column(name = ADMIN_SETTINGS_KEY_PROPERTY) |
|||
private String key; |
|||
|
|||
@Column(name = ADMIN_SETTINGS_JSON_VALUE_PROPERTY, codec = JsonCodec.class) |
|||
private JsonNode jsonValue; |
|||
|
|||
public AdminSettingsEntity() { |
|||
super(); |
|||
} |
|||
|
|||
public AdminSettingsEntity(AdminSettings adminSettings) { |
|||
if (adminSettings.getId() != null) { |
|||
this.id = adminSettings.getId().getId(); |
|||
} |
|||
this.key = adminSettings.getKey(); |
|||
this.jsonValue = adminSettings.getJsonValue(); |
|||
} |
|||
|
|||
public UUID getId() { |
|||
return id; |
|||
} |
|||
|
|||
public void setId(UUID id) { |
|||
this.id = id; |
|||
} |
|||
|
|||
public String getKey() { |
|||
return key; |
|||
} |
|||
|
|||
public void setKey(String key) { |
|||
this.key = key; |
|||
} |
|||
|
|||
public JsonNode getJsonValue() { |
|||
return jsonValue; |
|||
} |
|||
|
|||
public void setJsonValue(JsonNode jsonValue) { |
|||
this.jsonValue = jsonValue; |
|||
} |
|||
|
|||
@Override |
|||
public AdminSettings toData() { |
|||
AdminSettings adminSettings = new AdminSettings(new AdminSettingsId(id)); |
|||
adminSettings.setCreatedTime(UUIDs.unixTimestamp(id)); |
|||
adminSettings.setKey(key); |
|||
adminSettings.setJsonValue(jsonValue); |
|||
return adminSettings; |
|||
} |
|||
|
|||
} |
|||
@ -1,254 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.model.nosql; |
|||
|
|||
import com.datastax.driver.core.utils.UUIDs; |
|||
import com.datastax.driver.mapping.annotations.ClusteringColumn; |
|||
import com.datastax.driver.mapping.annotations.Column; |
|||
import com.datastax.driver.mapping.annotations.PartitionKey; |
|||
import com.datastax.driver.mapping.annotations.Table; |
|||
import com.fasterxml.jackson.databind.JsonNode; |
|||
import lombok.EqualsAndHashCode; |
|||
import lombok.ToString; |
|||
import org.thingsboard.server.common.data.EntityType; |
|||
import org.thingsboard.server.common.data.alarm.Alarm; |
|||
import org.thingsboard.server.common.data.alarm.AlarmId; |
|||
import org.thingsboard.server.common.data.alarm.AlarmSeverity; |
|||
import org.thingsboard.server.common.data.alarm.AlarmStatus; |
|||
import org.thingsboard.server.common.data.id.EntityIdFactory; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.dao.model.BaseEntity; |
|||
import org.thingsboard.server.dao.model.type.AlarmSeverityCodec; |
|||
import org.thingsboard.server.dao.model.type.AlarmStatusCodec; |
|||
import org.thingsboard.server.dao.model.type.EntityTypeCodec; |
|||
import org.thingsboard.server.dao.model.type.JsonCodec; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
import static org.thingsboard.server.dao.model.ModelConstants.ALARM_ACK_TS_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ALARM_CLEAR_TS_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ALARM_COLUMN_FAMILY_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ALARM_DETAILS_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ALARM_END_TS_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ALARM_ORIGINATOR_ID_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ALARM_ORIGINATOR_TYPE_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ALARM_PROPAGATE_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ALARM_SEVERITY_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ALARM_START_TS_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ALARM_STATUS_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ALARM_TENANT_ID_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ALARM_TYPE_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ID_PROPERTY; |
|||
|
|||
@Table(name = ALARM_COLUMN_FAMILY_NAME) |
|||
@EqualsAndHashCode |
|||
@ToString |
|||
public final class AlarmEntity implements BaseEntity<Alarm> { |
|||
|
|||
@ClusteringColumn(value = 1) |
|||
@Column(name = ID_PROPERTY) |
|||
private UUID id; |
|||
|
|||
@PartitionKey(value = 0) |
|||
@Column(name = ALARM_TENANT_ID_PROPERTY) |
|||
private UUID tenantId; |
|||
|
|||
@PartitionKey(value = 1) |
|||
@Column(name = ALARM_ORIGINATOR_ID_PROPERTY) |
|||
private UUID originatorId; |
|||
|
|||
@PartitionKey(value = 2) |
|||
@Column(name = ALARM_ORIGINATOR_TYPE_PROPERTY, codec = EntityTypeCodec.class) |
|||
private EntityType originatorType; |
|||
|
|||
@ClusteringColumn(value = 0) |
|||
@Column(name = ALARM_TYPE_PROPERTY) |
|||
private String type; |
|||
|
|||
@Column(name = ALARM_SEVERITY_PROPERTY, codec = AlarmSeverityCodec.class) |
|||
private AlarmSeverity severity; |
|||
|
|||
@Column(name = ALARM_STATUS_PROPERTY, codec = AlarmStatusCodec.class) |
|||
private AlarmStatus status; |
|||
|
|||
@Column(name = ALARM_START_TS_PROPERTY) |
|||
private Long startTs; |
|||
|
|||
@Column(name = ALARM_END_TS_PROPERTY) |
|||
private Long endTs; |
|||
|
|||
@Column(name = ALARM_ACK_TS_PROPERTY) |
|||
private Long ackTs; |
|||
|
|||
@Column(name = ALARM_CLEAR_TS_PROPERTY) |
|||
private Long clearTs; |
|||
|
|||
@Column(name = ALARM_DETAILS_PROPERTY, codec = JsonCodec.class) |
|||
private JsonNode details; |
|||
|
|||
@Column(name = ALARM_PROPAGATE_PROPERTY) |
|||
private Boolean propagate; |
|||
|
|||
public AlarmEntity() { |
|||
super(); |
|||
} |
|||
|
|||
public AlarmEntity(Alarm alarm) { |
|||
if (alarm.getId() != null) { |
|||
this.id = alarm.getId().getId(); |
|||
} |
|||
if (alarm.getTenantId() != null) { |
|||
this.tenantId = alarm.getTenantId().getId(); |
|||
} |
|||
this.type = alarm.getType(); |
|||
this.originatorId = alarm.getOriginator().getId(); |
|||
this.originatorType = alarm.getOriginator().getEntityType(); |
|||
this.type = alarm.getType(); |
|||
this.severity = alarm.getSeverity(); |
|||
this.status = alarm.getStatus(); |
|||
this.propagate = alarm.isPropagate(); |
|||
this.startTs = alarm.getStartTs(); |
|||
this.endTs = alarm.getEndTs(); |
|||
this.ackTs = alarm.getAckTs(); |
|||
this.clearTs = alarm.getClearTs(); |
|||
this.details = alarm.getDetails(); |
|||
} |
|||
|
|||
public UUID getId() { |
|||
return id; |
|||
} |
|||
|
|||
public void setId(UUID id) { |
|||
this.id = id; |
|||
} |
|||
|
|||
public UUID getTenantId() { |
|||
return tenantId; |
|||
} |
|||
|
|||
public void setTenantId(UUID tenantId) { |
|||
this.tenantId = tenantId; |
|||
} |
|||
|
|||
public UUID getOriginatorId() { |
|||
return originatorId; |
|||
} |
|||
|
|||
public void setOriginatorId(UUID originatorId) { |
|||
this.originatorId = originatorId; |
|||
} |
|||
|
|||
public EntityType getOriginatorType() { |
|||
return originatorType; |
|||
} |
|||
|
|||
public void setOriginatorType(EntityType originatorType) { |
|||
this.originatorType = originatorType; |
|||
} |
|||
|
|||
public String getType() { |
|||
return type; |
|||
} |
|||
|
|||
public void setType(String type) { |
|||
this.type = type; |
|||
} |
|||
|
|||
public AlarmSeverity getSeverity() { |
|||
return severity; |
|||
} |
|||
|
|||
public void setSeverity(AlarmSeverity severity) { |
|||
this.severity = severity; |
|||
} |
|||
|
|||
public AlarmStatus getStatus() { |
|||
return status; |
|||
} |
|||
|
|||
public void setStatus(AlarmStatus status) { |
|||
this.status = status; |
|||
} |
|||
|
|||
public Long getStartTs() { |
|||
return startTs; |
|||
} |
|||
|
|||
public void setStartTs(Long startTs) { |
|||
this.startTs = startTs; |
|||
} |
|||
|
|||
public Long getEndTs() { |
|||
return endTs; |
|||
} |
|||
|
|||
public void setEndTs(Long endTs) { |
|||
this.endTs = endTs; |
|||
} |
|||
|
|||
public Long getAckTs() { |
|||
return ackTs; |
|||
} |
|||
|
|||
public void setAckTs(Long ackTs) { |
|||
this.ackTs = ackTs; |
|||
} |
|||
|
|||
public Long getClearTs() { |
|||
return clearTs; |
|||
} |
|||
|
|||
public void setClearTs(Long clearTs) { |
|||
this.clearTs = clearTs; |
|||
} |
|||
|
|||
public JsonNode getDetails() { |
|||
return details; |
|||
} |
|||
|
|||
public void setDetails(JsonNode details) { |
|||
this.details = details; |
|||
} |
|||
|
|||
public Boolean getPropagate() { |
|||
return propagate; |
|||
} |
|||
|
|||
public void setPropagate(Boolean propagate) { |
|||
this.propagate = propagate; |
|||
} |
|||
|
|||
@Override |
|||
public Alarm toData() { |
|||
Alarm alarm = new Alarm(new AlarmId(id)); |
|||
alarm.setCreatedTime(UUIDs.unixTimestamp(id)); |
|||
if (tenantId != null) { |
|||
alarm.setTenantId(new TenantId(tenantId)); |
|||
} |
|||
alarm.setOriginator(EntityIdFactory.getByTypeAndUuid(originatorType, originatorId)); |
|||
alarm.setType(type); |
|||
alarm.setSeverity(severity); |
|||
alarm.setStatus(status); |
|||
alarm.setPropagate(propagate); |
|||
alarm.setStartTs(startTs); |
|||
alarm.setEndTs(endTs); |
|||
alarm.setAckTs(ackTs); |
|||
alarm.setClearTs(clearTs); |
|||
alarm.setDetails(details); |
|||
return alarm; |
|||
} |
|||
|
|||
} |
|||
@ -1,170 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.model.nosql; |
|||
|
|||
import com.datastax.driver.core.utils.UUIDs; |
|||
import com.datastax.driver.mapping.annotations.Column; |
|||
import com.datastax.driver.mapping.annotations.PartitionKey; |
|||
import com.datastax.driver.mapping.annotations.Table; |
|||
import com.fasterxml.jackson.databind.JsonNode; |
|||
import lombok.EqualsAndHashCode; |
|||
import lombok.ToString; |
|||
import org.thingsboard.server.common.data.asset.Asset; |
|||
import org.thingsboard.server.common.data.id.AssetId; |
|||
import org.thingsboard.server.common.data.id.CustomerId; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.dao.model.SearchTextEntity; |
|||
import org.thingsboard.server.dao.model.type.JsonCodec; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
import static org.thingsboard.server.dao.model.ModelConstants.ASSET_ADDITIONAL_INFO_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ASSET_COLUMN_FAMILY_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ASSET_CUSTOMER_ID_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ASSET_NAME_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ASSET_TENANT_ID_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ASSET_TYPE_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ID_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.SEARCH_TEXT_PROPERTY; |
|||
|
|||
@Table(name = ASSET_COLUMN_FAMILY_NAME) |
|||
@EqualsAndHashCode |
|||
@ToString |
|||
public final class AssetEntity implements SearchTextEntity<Asset> { |
|||
|
|||
@PartitionKey(value = 0) |
|||
@Column(name = ID_PROPERTY) |
|||
private UUID id; |
|||
|
|||
@PartitionKey(value = 1) |
|||
@Column(name = ASSET_TENANT_ID_PROPERTY) |
|||
private UUID tenantId; |
|||
|
|||
@PartitionKey(value = 2) |
|||
@Column(name = ASSET_CUSTOMER_ID_PROPERTY) |
|||
private UUID customerId; |
|||
|
|||
@PartitionKey(value = 3) |
|||
@Column(name = ASSET_TYPE_PROPERTY) |
|||
private String type; |
|||
|
|||
@Column(name = ASSET_NAME_PROPERTY) |
|||
private String name; |
|||
|
|||
@Column(name = SEARCH_TEXT_PROPERTY) |
|||
private String searchText; |
|||
|
|||
@Column(name = ASSET_ADDITIONAL_INFO_PROPERTY, codec = JsonCodec.class) |
|||
private JsonNode additionalInfo; |
|||
|
|||
public AssetEntity() { |
|||
super(); |
|||
} |
|||
|
|||
public AssetEntity(Asset asset) { |
|||
if (asset.getId() != null) { |
|||
this.id = asset.getId().getId(); |
|||
} |
|||
if (asset.getTenantId() != null) { |
|||
this.tenantId = asset.getTenantId().getId(); |
|||
} |
|||
if (asset.getCustomerId() != null) { |
|||
this.customerId = asset.getCustomerId().getId(); |
|||
} |
|||
this.name = asset.getName(); |
|||
this.type = asset.getType(); |
|||
this.additionalInfo = asset.getAdditionalInfo(); |
|||
} |
|||
|
|||
public UUID getId() { |
|||
return id; |
|||
} |
|||
|
|||
public void setId(UUID id) { |
|||
this.id = id; |
|||
} |
|||
|
|||
public UUID getTenantId() { |
|||
return tenantId; |
|||
} |
|||
|
|||
public void setTenantId(UUID tenantId) { |
|||
this.tenantId = tenantId; |
|||
} |
|||
|
|||
public UUID getCustomerId() { |
|||
return customerId; |
|||
} |
|||
|
|||
public void setCustomerId(UUID customerId) { |
|||
this.customerId = customerId; |
|||
} |
|||
|
|||
public String getName() { |
|||
return name; |
|||
} |
|||
|
|||
public void setName(String name) { |
|||
this.name = name; |
|||
} |
|||
|
|||
public String getType() { |
|||
return type; |
|||
} |
|||
|
|||
public void setType(String type) { |
|||
this.type = type; |
|||
} |
|||
|
|||
public JsonNode getAdditionalInfo() { |
|||
return additionalInfo; |
|||
} |
|||
|
|||
public void setAdditionalInfo(JsonNode additionalInfo) { |
|||
this.additionalInfo = additionalInfo; |
|||
} |
|||
|
|||
@Override |
|||
public String getSearchTextSource() { |
|||
return getName(); |
|||
} |
|||
|
|||
@Override |
|||
public void setSearchText(String searchText) { |
|||
this.searchText = searchText; |
|||
} |
|||
|
|||
public String getSearchText() { |
|||
return searchText; |
|||
} |
|||
|
|||
@Override |
|||
public Asset toData() { |
|||
Asset asset = new Asset(new AssetId(id)); |
|||
asset.setCreatedTime(UUIDs.unixTimestamp(id)); |
|||
if (tenantId != null) { |
|||
asset.setTenantId(new TenantId(tenantId)); |
|||
} |
|||
if (customerId != null) { |
|||
asset.setCustomerId(new CustomerId(customerId)); |
|||
} |
|||
asset.setName(name); |
|||
asset.setType(type); |
|||
asset.setAdditionalInfo(additionalInfo); |
|||
return asset; |
|||
} |
|||
|
|||
} |
|||
@ -1,155 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.model.nosql; |
|||
|
|||
import com.datastax.driver.core.utils.UUIDs; |
|||
import com.datastax.driver.mapping.annotations.Column; |
|||
import com.datastax.driver.mapping.annotations.Table; |
|||
import com.fasterxml.jackson.databind.JsonNode; |
|||
import lombok.Data; |
|||
import lombok.NoArgsConstructor; |
|||
import org.thingsboard.server.common.data.EntityType; |
|||
import org.thingsboard.server.common.data.audit.ActionStatus; |
|||
import org.thingsboard.server.common.data.audit.ActionType; |
|||
import org.thingsboard.server.common.data.audit.AuditLog; |
|||
import org.thingsboard.server.common.data.id.AuditLogId; |
|||
import org.thingsboard.server.common.data.id.CustomerId; |
|||
import org.thingsboard.server.common.data.id.EntityIdFactory; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.id.UserId; |
|||
import org.thingsboard.server.dao.model.BaseEntity; |
|||
import org.thingsboard.server.dao.model.type.ActionStatusCodec; |
|||
import org.thingsboard.server.dao.model.type.ActionTypeCodec; |
|||
import org.thingsboard.server.dao.model.type.EntityTypeCodec; |
|||
import org.thingsboard.server.dao.model.type.JsonCodec; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
import static org.thingsboard.server.dao.model.ModelConstants.AUDIT_LOG_ACTION_DATA_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.AUDIT_LOG_ACTION_FAILURE_DETAILS_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.AUDIT_LOG_ACTION_STATUS_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.AUDIT_LOG_ACTION_TYPE_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.AUDIT_LOG_BY_ENTITY_ID_CF; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.AUDIT_LOG_CUSTOMER_ID_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.AUDIT_LOG_ENTITY_ID_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.AUDIT_LOG_ENTITY_NAME_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.AUDIT_LOG_ENTITY_TYPE_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.AUDIT_LOG_TENANT_ID_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.AUDIT_LOG_USER_ID_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.AUDIT_LOG_USER_NAME_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ID_PROPERTY; |
|||
|
|||
@Table(name = AUDIT_LOG_BY_ENTITY_ID_CF) |
|||
@Data |
|||
@NoArgsConstructor |
|||
public class AuditLogEntity implements BaseEntity<AuditLog> { |
|||
|
|||
@Column(name = ID_PROPERTY) |
|||
private UUID id; |
|||
|
|||
@Column(name = AUDIT_LOG_TENANT_ID_PROPERTY) |
|||
private UUID tenantId; |
|||
|
|||
@Column(name = AUDIT_LOG_CUSTOMER_ID_PROPERTY) |
|||
private UUID customerId; |
|||
|
|||
@Column(name = AUDIT_LOG_ENTITY_TYPE_PROPERTY, codec = EntityTypeCodec.class) |
|||
private EntityType entityType; |
|||
|
|||
@Column(name = AUDIT_LOG_ENTITY_ID_PROPERTY) |
|||
private UUID entityId; |
|||
|
|||
@Column(name = AUDIT_LOG_ENTITY_NAME_PROPERTY) |
|||
private String entityName; |
|||
|
|||
@Column(name = AUDIT_LOG_USER_ID_PROPERTY) |
|||
private UUID userId; |
|||
|
|||
@Column(name = AUDIT_LOG_USER_NAME_PROPERTY) |
|||
private String userName; |
|||
|
|||
@Column(name = AUDIT_LOG_ACTION_TYPE_PROPERTY, codec = ActionTypeCodec.class) |
|||
private ActionType actionType; |
|||
|
|||
@Column(name = AUDIT_LOG_ACTION_DATA_PROPERTY, codec = JsonCodec.class) |
|||
private JsonNode actionData; |
|||
|
|||
@Column(name = AUDIT_LOG_ACTION_STATUS_PROPERTY, codec = ActionStatusCodec.class) |
|||
private ActionStatus actionStatus; |
|||
|
|||
@Column(name = AUDIT_LOG_ACTION_FAILURE_DETAILS_PROPERTY) |
|||
private String actionFailureDetails; |
|||
|
|||
@Override |
|||
public UUID getId() { |
|||
return id; |
|||
} |
|||
|
|||
@Override |
|||
public void setId(UUID id) { |
|||
this.id = id; |
|||
} |
|||
|
|||
public AuditLogEntity(AuditLog auditLog) { |
|||
if (auditLog.getId() != null) { |
|||
this.id = auditLog.getId().getId(); |
|||
} |
|||
if (auditLog.getTenantId() != null) { |
|||
this.tenantId = auditLog.getTenantId().getId(); |
|||
} |
|||
if (auditLog.getEntityId() != null) { |
|||
this.entityType = auditLog.getEntityId().getEntityType(); |
|||
this.entityId = auditLog.getEntityId().getId(); |
|||
} |
|||
if (auditLog.getCustomerId() != null) { |
|||
this.customerId = auditLog.getCustomerId().getId(); |
|||
} |
|||
if (auditLog.getUserId() != null) { |
|||
this.userId = auditLog.getUserId().getId(); |
|||
} |
|||
this.entityName = auditLog.getEntityName(); |
|||
this.userName = auditLog.getUserName(); |
|||
this.actionType = auditLog.getActionType(); |
|||
this.actionData = auditLog.getActionData(); |
|||
this.actionStatus = auditLog.getActionStatus(); |
|||
this.actionFailureDetails = auditLog.getActionFailureDetails(); |
|||
} |
|||
|
|||
@Override |
|||
public AuditLog toData() { |
|||
AuditLog auditLog = new AuditLog(new AuditLogId(id)); |
|||
auditLog.setCreatedTime(UUIDs.unixTimestamp(id)); |
|||
if (tenantId != null) { |
|||
auditLog.setTenantId(new TenantId(tenantId)); |
|||
} |
|||
if (entityId != null && entityType != null) { |
|||
auditLog.setEntityId(EntityIdFactory.getByTypeAndUuid(entityType, entityId)); |
|||
} |
|||
if (customerId != null) { |
|||
auditLog.setCustomerId(new CustomerId(customerId)); |
|||
} |
|||
if (userId != null) { |
|||
auditLog.setUserId(new UserId(userId)); |
|||
} |
|||
auditLog.setEntityName(this.entityName); |
|||
auditLog.setUserName(this.userName); |
|||
auditLog.setActionType(this.actionType); |
|||
auditLog.setActionData(this.actionData); |
|||
auditLog.setActionStatus(this.actionStatus); |
|||
auditLog.setActionFailureDetails(this.actionFailureDetails); |
|||
return auditLog; |
|||
} |
|||
} |
|||
@ -1,171 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.model.nosql; |
|||
|
|||
import com.datastax.driver.mapping.annotations.Column; |
|||
import com.datastax.driver.mapping.annotations.PartitionKey; |
|||
import com.datastax.driver.mapping.annotations.Table; |
|||
import com.fasterxml.jackson.databind.JsonNode; |
|||
import org.thingsboard.server.common.data.id.ComponentDescriptorId; |
|||
import org.thingsboard.server.common.data.plugin.ComponentDescriptor; |
|||
import org.thingsboard.server.common.data.plugin.ComponentScope; |
|||
import org.thingsboard.server.common.data.plugin.ComponentType; |
|||
import org.thingsboard.server.dao.model.SearchTextEntity; |
|||
import org.thingsboard.server.dao.model.type.JsonCodec; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
import static org.thingsboard.server.dao.model.ModelConstants.COMPONENT_DESCRIPTOR_ACTIONS_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.COMPONENT_DESCRIPTOR_CLASS_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.COMPONENT_DESCRIPTOR_COLUMN_FAMILY_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.COMPONENT_DESCRIPTOR_CONFIGURATION_DESCRIPTOR_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.COMPONENT_DESCRIPTOR_NAME_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.COMPONENT_DESCRIPTOR_SCOPE_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.COMPONENT_DESCRIPTOR_TYPE_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ID_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.SEARCH_TEXT_PROPERTY; |
|||
|
|||
/** |
|||
* @author Andrew Shvayka |
|||
*/ |
|||
@Table(name = COMPONENT_DESCRIPTOR_COLUMN_FAMILY_NAME) |
|||
public class ComponentDescriptorEntity implements SearchTextEntity<ComponentDescriptor> { |
|||
|
|||
@PartitionKey |
|||
@Column(name = ID_PROPERTY) |
|||
private UUID id; |
|||
|
|||
@Column(name = COMPONENT_DESCRIPTOR_TYPE_PROPERTY) |
|||
private ComponentType type; |
|||
|
|||
@Column(name = COMPONENT_DESCRIPTOR_SCOPE_PROPERTY) |
|||
private ComponentScope scope; |
|||
|
|||
@Column(name = COMPONENT_DESCRIPTOR_NAME_PROPERTY) |
|||
private String name; |
|||
|
|||
@Column(name = COMPONENT_DESCRIPTOR_CLASS_PROPERTY) |
|||
private String clazz; |
|||
|
|||
@Column(name = COMPONENT_DESCRIPTOR_CONFIGURATION_DESCRIPTOR_PROPERTY, codec = JsonCodec.class) |
|||
private JsonNode configurationDescriptor; |
|||
|
|||
@Column(name = COMPONENT_DESCRIPTOR_ACTIONS_PROPERTY) |
|||
private String actions; |
|||
|
|||
@Column(name = SEARCH_TEXT_PROPERTY) |
|||
private String searchText; |
|||
|
|||
public ComponentDescriptorEntity() { |
|||
} |
|||
|
|||
public ComponentDescriptorEntity(ComponentDescriptor component) { |
|||
if (component.getId() != null) { |
|||
this.id = component.getId().getId(); |
|||
} |
|||
this.actions = component.getActions(); |
|||
this.type = component.getType(); |
|||
this.scope = component.getScope(); |
|||
this.name = component.getName(); |
|||
this.clazz = component.getClazz(); |
|||
this.configurationDescriptor = component.getConfigurationDescriptor(); |
|||
this.searchText = component.getName(); |
|||
} |
|||
|
|||
@Override |
|||
public ComponentDescriptor toData() { |
|||
ComponentDescriptor data = new ComponentDescriptor(new ComponentDescriptorId(id)); |
|||
data.setType(type); |
|||
data.setScope(scope); |
|||
data.setName(this.getName()); |
|||
data.setClazz(this.getClazz()); |
|||
data.setActions(this.getActions()); |
|||
data.setConfigurationDescriptor(this.getConfigurationDescriptor()); |
|||
return data; |
|||
} |
|||
|
|||
@Override |
|||
public UUID getId() { |
|||
return id; |
|||
} |
|||
|
|||
@Override |
|||
public void setId(UUID id) { |
|||
this.id = id; |
|||
} |
|||
|
|||
public String getActions() { |
|||
return actions; |
|||
} |
|||
|
|||
public void setActions(String actions) { |
|||
this.actions = actions; |
|||
} |
|||
|
|||
public ComponentType getType() { |
|||
return type; |
|||
} |
|||
|
|||
public void setType(ComponentType type) { |
|||
this.type = type; |
|||
} |
|||
|
|||
public ComponentScope getScope() { |
|||
return scope; |
|||
} |
|||
|
|||
public void setScope(ComponentScope scope) { |
|||
this.scope = scope; |
|||
} |
|||
|
|||
public String getName() { |
|||
return name; |
|||
} |
|||
|
|||
public void setName(String name) { |
|||
this.name = name; |
|||
} |
|||
|
|||
public String getClazz() { |
|||
return clazz; |
|||
} |
|||
|
|||
public void setClazz(String clazz) { |
|||
this.clazz = clazz; |
|||
} |
|||
|
|||
public JsonNode getConfigurationDescriptor() { |
|||
return configurationDescriptor; |
|||
} |
|||
|
|||
public void setConfigurationDescriptor(JsonNode configurationDescriptor) { |
|||
this.configurationDescriptor = configurationDescriptor; |
|||
} |
|||
|
|||
public String getSearchText() { |
|||
return searchText; |
|||
} |
|||
|
|||
@Override |
|||
public void setSearchText(String searchText) { |
|||
this.searchText = searchText; |
|||
} |
|||
|
|||
@Override |
|||
public String getSearchTextSource() { |
|||
return getSearchText(); |
|||
} |
|||
} |
|||
@ -1,243 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.model.nosql; |
|||
|
|||
import com.datastax.driver.core.utils.UUIDs; |
|||
import com.datastax.driver.mapping.annotations.Column; |
|||
import com.datastax.driver.mapping.annotations.PartitionKey; |
|||
import com.datastax.driver.mapping.annotations.Table; |
|||
import com.fasterxml.jackson.databind.JsonNode; |
|||
import lombok.EqualsAndHashCode; |
|||
import lombok.ToString; |
|||
import org.thingsboard.server.common.data.Customer; |
|||
import org.thingsboard.server.common.data.id.CustomerId; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.dao.model.SearchTextEntity; |
|||
import org.thingsboard.server.dao.model.type.JsonCodec; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
import static org.thingsboard.server.dao.model.ModelConstants.ADDRESS2_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ADDRESS_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.CITY_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.COUNTRY_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.CUSTOMER_ADDITIONAL_INFO_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.CUSTOMER_COLUMN_FAMILY_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.CUSTOMER_TENANT_ID_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.CUSTOMER_TITLE_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.EMAIL_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ID_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.PHONE_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.SEARCH_TEXT_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.STATE_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ZIP_PROPERTY; |
|||
|
|||
@Table(name = CUSTOMER_COLUMN_FAMILY_NAME) |
|||
@EqualsAndHashCode |
|||
@ToString |
|||
public final class CustomerEntity implements SearchTextEntity<Customer> { |
|||
|
|||
@PartitionKey(value = 0) |
|||
@Column(name = ID_PROPERTY) |
|||
private UUID id; |
|||
|
|||
@PartitionKey(value = 1) |
|||
@Column(name = CUSTOMER_TENANT_ID_PROPERTY) |
|||
private UUID tenantId; |
|||
|
|||
@Column(name = CUSTOMER_TITLE_PROPERTY) |
|||
private String title; |
|||
|
|||
@Column(name = SEARCH_TEXT_PROPERTY) |
|||
private String searchText; |
|||
|
|||
@Column(name = COUNTRY_PROPERTY) |
|||
private String country; |
|||
|
|||
@Column(name = STATE_PROPERTY) |
|||
private String state; |
|||
|
|||
@Column(name = CITY_PROPERTY) |
|||
private String city; |
|||
|
|||
@Column(name = ADDRESS_PROPERTY) |
|||
private String address; |
|||
|
|||
@Column(name = ADDRESS2_PROPERTY) |
|||
private String address2; |
|||
|
|||
@Column(name = ZIP_PROPERTY) |
|||
private String zip; |
|||
|
|||
@Column(name = PHONE_PROPERTY) |
|||
private String phone; |
|||
|
|||
@Column(name = EMAIL_PROPERTY) |
|||
private String email; |
|||
|
|||
@Column(name = CUSTOMER_ADDITIONAL_INFO_PROPERTY, codec = JsonCodec.class) |
|||
private JsonNode additionalInfo; |
|||
|
|||
public CustomerEntity() { |
|||
super(); |
|||
} |
|||
|
|||
public CustomerEntity(Customer customer) { |
|||
if (customer.getId() != null) { |
|||
this.id = customer.getId().getId(); |
|||
} |
|||
this.tenantId = customer.getTenantId().getId(); |
|||
this.title = customer.getTitle(); |
|||
this.country = customer.getCountry(); |
|||
this.state = customer.getState(); |
|||
this.city = customer.getCity(); |
|||
this.address = customer.getAddress(); |
|||
this.address2 = customer.getAddress2(); |
|||
this.zip = customer.getZip(); |
|||
this.phone = customer.getPhone(); |
|||
this.email = customer.getEmail(); |
|||
this.additionalInfo = customer.getAdditionalInfo(); |
|||
} |
|||
|
|||
public UUID getId() { |
|||
return id; |
|||
} |
|||
|
|||
public void setId(UUID id) { |
|||
this.id = id; |
|||
} |
|||
|
|||
public UUID getTenantId() { |
|||
return tenantId; |
|||
} |
|||
|
|||
public void setTenantId(UUID tenantId) { |
|||
this.tenantId = tenantId; |
|||
} |
|||
|
|||
public String getTitle() { |
|||
return title; |
|||
} |
|||
|
|||
public void setTitle(String title) { |
|||
this.title = title; |
|||
} |
|||
|
|||
public String getCountry() { |
|||
return country; |
|||
} |
|||
|
|||
public void setCountry(String country) { |
|||
this.country = country; |
|||
} |
|||
|
|||
public String getState() { |
|||
return state; |
|||
} |
|||
|
|||
public void setState(String state) { |
|||
this.state = state; |
|||
} |
|||
|
|||
public String getCity() { |
|||
return city; |
|||
} |
|||
|
|||
public void setCity(String city) { |
|||
this.city = city; |
|||
} |
|||
|
|||
public String getAddress() { |
|||
return address; |
|||
} |
|||
|
|||
public void setAddress(String address) { |
|||
this.address = address; |
|||
} |
|||
|
|||
public String getAddress2() { |
|||
return address2; |
|||
} |
|||
|
|||
public void setAddress2(String address2) { |
|||
this.address2 = address2; |
|||
} |
|||
|
|||
public String getZip() { |
|||
return zip; |
|||
} |
|||
|
|||
public void setZip(String zip) { |
|||
this.zip = zip; |
|||
} |
|||
|
|||
public String getPhone() { |
|||
return phone; |
|||
} |
|||
|
|||
public void setPhone(String phone) { |
|||
this.phone = phone; |
|||
} |
|||
|
|||
public String getEmail() { |
|||
return email; |
|||
} |
|||
|
|||
public void setEmail(String email) { |
|||
this.email = email; |
|||
} |
|||
|
|||
public JsonNode getAdditionalInfo() { |
|||
return additionalInfo; |
|||
} |
|||
|
|||
public void setAdditionalInfo(JsonNode additionalInfo) { |
|||
this.additionalInfo = additionalInfo; |
|||
} |
|||
|
|||
@Override |
|||
public String getSearchTextSource() { |
|||
return getTitle(); |
|||
} |
|||
|
|||
@Override |
|||
public void setSearchText(String searchText) { |
|||
this.searchText = searchText; |
|||
} |
|||
|
|||
public String getSearchText() { |
|||
return searchText; |
|||
} |
|||
|
|||
@Override |
|||
public Customer toData() { |
|||
Customer customer = new Customer(new CustomerId(id)); |
|||
customer.setCreatedTime(UUIDs.unixTimestamp(id)); |
|||
customer.setTenantId(new TenantId(tenantId)); |
|||
customer.setTitle(title); |
|||
customer.setCountry(country); |
|||
customer.setState(state); |
|||
customer.setCity(city); |
|||
customer.setAddress(address); |
|||
customer.setAddress2(address2); |
|||
customer.setZip(zip); |
|||
customer.setPhone(phone); |
|||
customer.setEmail(email); |
|||
customer.setAdditionalInfo(additionalInfo); |
|||
return customer; |
|||
} |
|||
|
|||
} |
|||
@ -1,174 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.model.nosql; |
|||
|
|||
import com.datastax.driver.core.utils.UUIDs; |
|||
import com.datastax.driver.mapping.annotations.Column; |
|||
import com.datastax.driver.mapping.annotations.PartitionKey; |
|||
import com.datastax.driver.mapping.annotations.Table; |
|||
import com.fasterxml.jackson.core.JsonProcessingException; |
|||
import com.fasterxml.jackson.databind.JavaType; |
|||
import com.fasterxml.jackson.databind.JsonNode; |
|||
import com.fasterxml.jackson.databind.ObjectMapper; |
|||
import lombok.EqualsAndHashCode; |
|||
import lombok.ToString; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.util.StringUtils; |
|||
import org.thingsboard.server.common.data.Dashboard; |
|||
import org.thingsboard.server.common.data.ShortCustomerInfo; |
|||
import org.thingsboard.server.common.data.id.DashboardId; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.dao.model.SearchTextEntity; |
|||
import org.thingsboard.server.dao.model.type.JsonCodec; |
|||
|
|||
import java.io.IOException; |
|||
import java.util.HashSet; |
|||
import java.util.UUID; |
|||
|
|||
import static org.thingsboard.server.dao.model.ModelConstants.DASHBOARD_ASSIGNED_CUSTOMERS_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.DASHBOARD_COLUMN_FAMILY_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.DASHBOARD_CONFIGURATION_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.DASHBOARD_TENANT_ID_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.DASHBOARD_TITLE_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ID_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.SEARCH_TEXT_PROPERTY; |
|||
|
|||
@Table(name = DASHBOARD_COLUMN_FAMILY_NAME) |
|||
@EqualsAndHashCode |
|||
@ToString |
|||
@Slf4j |
|||
public final class DashboardEntity implements SearchTextEntity<Dashboard> { |
|||
|
|||
private static final ObjectMapper objectMapper = new ObjectMapper(); |
|||
private static final JavaType assignedCustomersType = |
|||
objectMapper.getTypeFactory().constructCollectionType(HashSet.class, ShortCustomerInfo.class); |
|||
|
|||
@PartitionKey(value = 0) |
|||
@Column(name = ID_PROPERTY) |
|||
private UUID id; |
|||
|
|||
@PartitionKey(value = 1) |
|||
@Column(name = DASHBOARD_TENANT_ID_PROPERTY) |
|||
private UUID tenantId; |
|||
|
|||
@Column(name = DASHBOARD_TITLE_PROPERTY) |
|||
private String title; |
|||
|
|||
@Column(name = SEARCH_TEXT_PROPERTY) |
|||
private String searchText; |
|||
|
|||
@Column(name = DASHBOARD_ASSIGNED_CUSTOMERS_PROPERTY) |
|||
private String assignedCustomers; |
|||
|
|||
@Column(name = DASHBOARD_CONFIGURATION_PROPERTY, codec = JsonCodec.class) |
|||
private JsonNode configuration; |
|||
|
|||
public DashboardEntity() { |
|||
super(); |
|||
} |
|||
|
|||
public DashboardEntity(Dashboard dashboard) { |
|||
if (dashboard.getId() != null) { |
|||
this.id = dashboard.getId().getId(); |
|||
} |
|||
if (dashboard.getTenantId() != null) { |
|||
this.tenantId = dashboard.getTenantId().getId(); |
|||
} |
|||
this.title = dashboard.getTitle(); |
|||
if (dashboard.getAssignedCustomers() != null) { |
|||
try { |
|||
this.assignedCustomers = objectMapper.writeValueAsString(dashboard.getAssignedCustomers()); |
|||
} catch (JsonProcessingException e) { |
|||
log.error("Unable to serialize assigned customers to string!", e); |
|||
} |
|||
} |
|||
this.configuration = dashboard.getConfiguration(); |
|||
} |
|||
|
|||
public UUID getId() { |
|||
return id; |
|||
} |
|||
|
|||
public void setId(UUID id) { |
|||
this.id = id; |
|||
} |
|||
|
|||
public UUID getTenantId() { |
|||
return tenantId; |
|||
} |
|||
|
|||
public void setTenantId(UUID tenantId) { |
|||
this.tenantId = tenantId; |
|||
} |
|||
|
|||
public String getTitle() { |
|||
return title; |
|||
} |
|||
|
|||
public void setTitle(String title) { |
|||
this.title = title; |
|||
} |
|||
|
|||
public String getAssignedCustomers() { |
|||
return assignedCustomers; |
|||
} |
|||
|
|||
public void setAssignedCustomers(String assignedCustomers) { |
|||
this.assignedCustomers = assignedCustomers; |
|||
} |
|||
|
|||
public JsonNode getConfiguration() { |
|||
return configuration; |
|||
} |
|||
|
|||
public void setConfiguration(JsonNode configuration) { |
|||
this.configuration = configuration; |
|||
} |
|||
|
|||
@Override |
|||
public String getSearchTextSource() { |
|||
return getTitle(); |
|||
} |
|||
|
|||
@Override |
|||
public void setSearchText(String searchText) { |
|||
this.searchText = searchText; |
|||
} |
|||
|
|||
public String getSearchText() { |
|||
return searchText; |
|||
} |
|||
|
|||
@Override |
|||
public Dashboard toData() { |
|||
Dashboard dashboard = new Dashboard(new DashboardId(id)); |
|||
dashboard.setCreatedTime(UUIDs.unixTimestamp(id)); |
|||
if (tenantId != null) { |
|||
dashboard.setTenantId(new TenantId(tenantId)); |
|||
} |
|||
dashboard.setTitle(title); |
|||
if (!StringUtils.isEmpty(assignedCustomers)) { |
|||
try { |
|||
dashboard.setAssignedCustomers(objectMapper.readValue(assignedCustomers, assignedCustomersType)); |
|||
} catch (IOException e) { |
|||
log.warn("Unable to parse assigned customers!", e); |
|||
} |
|||
} |
|||
dashboard.setConfiguration(configuration); |
|||
return dashboard; |
|||
} |
|||
|
|||
} |
|||
@ -1,158 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.model.nosql; |
|||
|
|||
import com.datastax.driver.core.utils.UUIDs; |
|||
import com.datastax.driver.mapping.annotations.Column; |
|||
import com.datastax.driver.mapping.annotations.PartitionKey; |
|||
import com.datastax.driver.mapping.annotations.Table; |
|||
import com.fasterxml.jackson.core.JsonProcessingException; |
|||
import com.fasterxml.jackson.databind.JavaType; |
|||
import com.fasterxml.jackson.databind.ObjectMapper; |
|||
import lombok.EqualsAndHashCode; |
|||
import lombok.ToString; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.util.StringUtils; |
|||
import org.thingsboard.server.common.data.DashboardInfo; |
|||
import org.thingsboard.server.common.data.ShortCustomerInfo; |
|||
import org.thingsboard.server.common.data.id.DashboardId; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.dao.model.SearchTextEntity; |
|||
|
|||
import java.io.IOException; |
|||
import java.util.HashSet; |
|||
import java.util.UUID; |
|||
|
|||
import static org.thingsboard.server.dao.model.ModelConstants.DASHBOARD_ASSIGNED_CUSTOMERS_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.DASHBOARD_COLUMN_FAMILY_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.DASHBOARD_TENANT_ID_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.DASHBOARD_TITLE_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ID_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.SEARCH_TEXT_PROPERTY; |
|||
|
|||
@Table(name = DASHBOARD_COLUMN_FAMILY_NAME) |
|||
@EqualsAndHashCode |
|||
@ToString |
|||
@Slf4j |
|||
public class DashboardInfoEntity implements SearchTextEntity<DashboardInfo> { |
|||
|
|||
private static final ObjectMapper objectMapper = new ObjectMapper(); |
|||
private static final JavaType assignedCustomersType = |
|||
objectMapper.getTypeFactory().constructCollectionType(HashSet.class, ShortCustomerInfo.class); |
|||
|
|||
@PartitionKey(value = 0) |
|||
@Column(name = ID_PROPERTY) |
|||
private UUID id; |
|||
|
|||
@PartitionKey(value = 1) |
|||
@Column(name = DASHBOARD_TENANT_ID_PROPERTY) |
|||
private UUID tenantId; |
|||
|
|||
@Column(name = DASHBOARD_TITLE_PROPERTY) |
|||
private String title; |
|||
|
|||
@Column(name = SEARCH_TEXT_PROPERTY) |
|||
private String searchText; |
|||
|
|||
@Column(name = DASHBOARD_ASSIGNED_CUSTOMERS_PROPERTY) |
|||
private String assignedCustomers; |
|||
|
|||
public DashboardInfoEntity() { |
|||
super(); |
|||
} |
|||
|
|||
public DashboardInfoEntity(DashboardInfo dashboardInfo) { |
|||
if (dashboardInfo.getId() != null) { |
|||
this.id = dashboardInfo.getId().getId(); |
|||
} |
|||
if (dashboardInfo.getTenantId() != null) { |
|||
this.tenantId = dashboardInfo.getTenantId().getId(); |
|||
} |
|||
this.title = dashboardInfo.getTitle(); |
|||
if (dashboardInfo.getAssignedCustomers() != null) { |
|||
try { |
|||
this.assignedCustomers = objectMapper.writeValueAsString(dashboardInfo.getAssignedCustomers()); |
|||
} catch (JsonProcessingException e) { |
|||
log.error("Unable to serialize assigned customers to string!", e); |
|||
} |
|||
} |
|||
} |
|||
|
|||
public UUID getId() { |
|||
return id; |
|||
} |
|||
|
|||
public void setId(UUID id) { |
|||
this.id = id; |
|||
} |
|||
|
|||
public UUID getTenantId() { |
|||
return tenantId; |
|||
} |
|||
|
|||
public void setTenantId(UUID tenantId) { |
|||
this.tenantId = tenantId; |
|||
} |
|||
|
|||
public String getTitle() { |
|||
return title; |
|||
} |
|||
|
|||
public void setTitle(String title) { |
|||
this.title = title; |
|||
} |
|||
|
|||
public String getAssignedCustomers() { |
|||
return assignedCustomers; |
|||
} |
|||
|
|||
public void setAssignedCustomers(String assignedCustomers) { |
|||
this.assignedCustomers = assignedCustomers; |
|||
} |
|||
|
|||
@Override |
|||
public String getSearchTextSource() { |
|||
return getTitle(); |
|||
} |
|||
|
|||
@Override |
|||
public void setSearchText(String searchText) { |
|||
this.searchText = searchText; |
|||
} |
|||
|
|||
public String getSearchText() { |
|||
return searchText; |
|||
} |
|||
|
|||
@Override |
|||
public DashboardInfo toData() { |
|||
DashboardInfo dashboardInfo = new DashboardInfo(new DashboardId(id)); |
|||
dashboardInfo.setCreatedTime(UUIDs.unixTimestamp(id)); |
|||
if (tenantId != null) { |
|||
dashboardInfo.setTenantId(new TenantId(tenantId)); |
|||
} |
|||
dashboardInfo.setTitle(title); |
|||
if (!StringUtils.isEmpty(assignedCustomers)) { |
|||
try { |
|||
dashboardInfo.setAssignedCustomers(objectMapper.readValue(assignedCustomers, assignedCustomersType)); |
|||
} catch (IOException e) { |
|||
log.warn("Unable to parse assigned customers!", e); |
|||
} |
|||
} |
|||
return dashboardInfo; |
|||
} |
|||
|
|||
} |
|||
@ -1,130 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.model.nosql; |
|||
|
|||
import com.datastax.driver.core.utils.UUIDs; |
|||
import com.datastax.driver.mapping.annotations.Column; |
|||
import com.datastax.driver.mapping.annotations.PartitionKey; |
|||
import com.datastax.driver.mapping.annotations.Table; |
|||
import lombok.EqualsAndHashCode; |
|||
import lombok.ToString; |
|||
import org.thingsboard.server.common.data.id.DeviceCredentialsId; |
|||
import org.thingsboard.server.common.data.id.DeviceId; |
|||
import org.thingsboard.server.common.data.security.DeviceCredentials; |
|||
import org.thingsboard.server.common.data.security.DeviceCredentialsType; |
|||
import org.thingsboard.server.dao.model.BaseEntity; |
|||
import org.thingsboard.server.dao.model.type.DeviceCredentialsTypeCodec; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
import static org.thingsboard.server.dao.model.ModelConstants.DEVICE_CREDENTIALS_COLUMN_FAMILY_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.DEVICE_CREDENTIALS_CREDENTIALS_ID_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.DEVICE_CREDENTIALS_CREDENTIALS_TYPE_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.DEVICE_CREDENTIALS_CREDENTIALS_VALUE_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.DEVICE_CREDENTIALS_DEVICE_ID_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ID_PROPERTY; |
|||
|
|||
@Table(name = DEVICE_CREDENTIALS_COLUMN_FAMILY_NAME) |
|||
@EqualsAndHashCode |
|||
@ToString |
|||
public final class DeviceCredentialsEntity implements BaseEntity<DeviceCredentials> { |
|||
|
|||
@PartitionKey(value = 0) |
|||
@Column(name = ID_PROPERTY) |
|||
private UUID id; |
|||
|
|||
@Column(name = DEVICE_CREDENTIALS_DEVICE_ID_PROPERTY) |
|||
private UUID deviceId; |
|||
|
|||
@Column(name = DEVICE_CREDENTIALS_CREDENTIALS_TYPE_PROPERTY, codec = DeviceCredentialsTypeCodec.class) |
|||
private DeviceCredentialsType credentialsType; |
|||
|
|||
@Column(name = DEVICE_CREDENTIALS_CREDENTIALS_ID_PROPERTY) |
|||
private String credentialsId; |
|||
|
|||
@Column(name = DEVICE_CREDENTIALS_CREDENTIALS_VALUE_PROPERTY) |
|||
private String credentialsValue; |
|||
|
|||
public DeviceCredentialsEntity() { |
|||
super(); |
|||
} |
|||
|
|||
public DeviceCredentialsEntity(DeviceCredentials deviceCredentials) { |
|||
if (deviceCredentials.getId() != null) { |
|||
this.id = deviceCredentials.getId().getId(); |
|||
} |
|||
if (deviceCredentials.getDeviceId() != null) { |
|||
this.deviceId = deviceCredentials.getDeviceId().getId(); |
|||
} |
|||
this.credentialsType = deviceCredentials.getCredentialsType(); |
|||
this.credentialsId = deviceCredentials.getCredentialsId(); |
|||
this.credentialsValue = deviceCredentials.getCredentialsValue(); |
|||
} |
|||
|
|||
public UUID getId() { |
|||
return id; |
|||
} |
|||
|
|||
public void setId(UUID id) { |
|||
this.id = id; |
|||
} |
|||
|
|||
public UUID getDeviceId() { |
|||
return deviceId; |
|||
} |
|||
|
|||
public void setDeviceId(UUID deviceId) { |
|||
this.deviceId = deviceId; |
|||
} |
|||
|
|||
public DeviceCredentialsType getCredentialsType() { |
|||
return credentialsType; |
|||
} |
|||
|
|||
public void setCredentialsType(DeviceCredentialsType credentialsType) { |
|||
this.credentialsType = credentialsType; |
|||
} |
|||
|
|||
public String getCredentialsId() { |
|||
return credentialsId; |
|||
} |
|||
|
|||
public void setCredentialsId(String credentialsId) { |
|||
this.credentialsId = credentialsId; |
|||
} |
|||
|
|||
public String getCredentialsValue() { |
|||
return credentialsValue; |
|||
} |
|||
|
|||
public void setCredentialsValue(String credentialsValue) { |
|||
this.credentialsValue = credentialsValue; |
|||
} |
|||
|
|||
@Override |
|||
public DeviceCredentials toData() { |
|||
DeviceCredentials deviceCredentials = new DeviceCredentials(new DeviceCredentialsId(id)); |
|||
deviceCredentials.setCreatedTime(UUIDs.unixTimestamp(id)); |
|||
if (deviceId != null) { |
|||
deviceCredentials.setDeviceId(new DeviceId(deviceId)); |
|||
} |
|||
deviceCredentials.setCredentialsType(credentialsType); |
|||
deviceCredentials.setCredentialsId(credentialsId); |
|||
deviceCredentials.setCredentialsValue(credentialsValue); |
|||
return deviceCredentials; |
|||
} |
|||
|
|||
} |
|||
@ -1,168 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.model.nosql; |
|||
|
|||
import com.datastax.driver.core.utils.UUIDs; |
|||
import com.datastax.driver.mapping.annotations.Column; |
|||
import com.datastax.driver.mapping.annotations.PartitionKey; |
|||
import com.datastax.driver.mapping.annotations.Table; |
|||
import com.fasterxml.jackson.databind.JsonNode; |
|||
import lombok.EqualsAndHashCode; |
|||
import lombok.ToString; |
|||
import org.thingsboard.server.common.data.Device; |
|||
import org.thingsboard.server.common.data.id.CustomerId; |
|||
import org.thingsboard.server.common.data.id.DeviceId; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.dao.model.SearchTextEntity; |
|||
import org.thingsboard.server.dao.model.type.JsonCodec; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
import static org.thingsboard.server.dao.model.ModelConstants.*; |
|||
|
|||
@Table(name = DEVICE_COLUMN_FAMILY_NAME) |
|||
@EqualsAndHashCode |
|||
@ToString |
|||
public final class DeviceEntity implements SearchTextEntity<Device> { |
|||
|
|||
@PartitionKey(value = 0) |
|||
@Column(name = ID_PROPERTY) |
|||
private UUID id; |
|||
|
|||
@PartitionKey(value = 1) |
|||
@Column(name = DEVICE_TENANT_ID_PROPERTY) |
|||
private UUID tenantId; |
|||
|
|||
@PartitionKey(value = 2) |
|||
@Column(name = DEVICE_CUSTOMER_ID_PROPERTY) |
|||
private UUID customerId; |
|||
|
|||
@PartitionKey(value = 3) |
|||
@Column(name = DEVICE_TYPE_PROPERTY) |
|||
private String type; |
|||
|
|||
@Column(name = DEVICE_NAME_PROPERTY) |
|||
private String name; |
|||
|
|||
@Column(name = DEVICE_LABEL_PROPERTY) |
|||
private String label; |
|||
|
|||
@Column(name = SEARCH_TEXT_PROPERTY) |
|||
private String searchText; |
|||
|
|||
@Column(name = DEVICE_ADDITIONAL_INFO_PROPERTY, codec = JsonCodec.class) |
|||
private JsonNode additionalInfo; |
|||
|
|||
public DeviceEntity() { |
|||
super(); |
|||
} |
|||
|
|||
public DeviceEntity(Device device) { |
|||
if (device.getId() != null) { |
|||
this.id = device.getId().getId(); |
|||
} |
|||
if (device.getTenantId() != null) { |
|||
this.tenantId = device.getTenantId().getId(); |
|||
} |
|||
if (device.getCustomerId() != null) { |
|||
this.customerId = device.getCustomerId().getId(); |
|||
} |
|||
this.name = device.getName(); |
|||
this.type = device.getType(); |
|||
this.label = device.getLabel(); |
|||
this.additionalInfo = device.getAdditionalInfo(); |
|||
} |
|||
|
|||
public UUID getId() { |
|||
return id; |
|||
} |
|||
|
|||
public void setId(UUID id) { |
|||
this.id = id; |
|||
} |
|||
|
|||
public UUID getTenantId() { |
|||
return tenantId; |
|||
} |
|||
|
|||
public void setTenantId(UUID tenantId) { |
|||
this.tenantId = tenantId; |
|||
} |
|||
|
|||
public UUID getCustomerId() { |
|||
return customerId; |
|||
} |
|||
|
|||
public void setCustomerId(UUID customerId) { |
|||
this.customerId = customerId; |
|||
} |
|||
|
|||
public String getName() { |
|||
return name; |
|||
} |
|||
|
|||
public void setName(String name) { |
|||
this.name = name; |
|||
} |
|||
|
|||
public String getType() { |
|||
return type; |
|||
} |
|||
|
|||
public void setType(String type) { |
|||
this.type = type; |
|||
} |
|||
|
|||
public JsonNode getAdditionalInfo() { |
|||
return additionalInfo; |
|||
} |
|||
|
|||
public void setAdditionalInfo(JsonNode additionalInfo) { |
|||
this.additionalInfo = additionalInfo; |
|||
} |
|||
|
|||
@Override |
|||
public String getSearchTextSource() { |
|||
return getName(); |
|||
} |
|||
|
|||
@Override |
|||
public void setSearchText(String searchText) { |
|||
this.searchText = searchText; |
|||
} |
|||
|
|||
public String getSearchText() { |
|||
return searchText; |
|||
} |
|||
|
|||
@Override |
|||
public Device toData() { |
|||
Device device = new Device(new DeviceId(id)); |
|||
device.setCreatedTime(UUIDs.unixTimestamp(id)); |
|||
if (tenantId != null) { |
|||
device.setTenantId(new TenantId(tenantId)); |
|||
} |
|||
if (customerId != null) { |
|||
device.setCustomerId(new CustomerId(customerId)); |
|||
} |
|||
device.setName(name); |
|||
device.setType(type); |
|||
device.setLabel(label); |
|||
device.setAdditionalInfo(additionalInfo); |
|||
return device; |
|||
} |
|||
|
|||
} |
|||
@ -1,164 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.model.nosql; |
|||
|
|||
import com.datastax.driver.core.utils.UUIDs; |
|||
import com.datastax.driver.mapping.annotations.Column; |
|||
import com.datastax.driver.mapping.annotations.PartitionKey; |
|||
import com.datastax.driver.mapping.annotations.Table; |
|||
import com.fasterxml.jackson.databind.JsonNode; |
|||
import com.fasterxml.jackson.databind.ObjectMapper; |
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
import lombok.ToString; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.hibernate.annotations.Type; |
|||
import org.thingsboard.server.common.data.EntityType; |
|||
import org.thingsboard.server.common.data.EntityView; |
|||
import org.thingsboard.server.common.data.id.CustomerId; |
|||
import org.thingsboard.server.common.data.id.EntityIdFactory; |
|||
import org.thingsboard.server.common.data.id.EntityViewId; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.objects.TelemetryEntityView; |
|||
import org.thingsboard.server.dao.model.ModelConstants; |
|||
import org.thingsboard.server.dao.model.SearchTextEntity; |
|||
|
|||
import javax.persistence.EnumType; |
|||
import javax.persistence.Enumerated; |
|||
import java.io.IOException; |
|||
import java.util.UUID; |
|||
|
|||
import static org.thingsboard.server.dao.model.ModelConstants.DEVICE_TYPE_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ENTITY_TYPE_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ENTITY_VIEW_TABLE_FAMILY_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ID_PROPERTY; |
|||
|
|||
/** |
|||
* Created by Victor Basanets on 8/31/2017. |
|||
*/ |
|||
@Data |
|||
@Table(name = ENTITY_VIEW_TABLE_FAMILY_NAME) |
|||
@EqualsAndHashCode |
|||
@ToString |
|||
@Slf4j |
|||
public class EntityViewEntity implements SearchTextEntity<EntityView> { |
|||
|
|||
@PartitionKey(value = 0) |
|||
@Column(name = ID_PROPERTY) |
|||
private UUID id; |
|||
|
|||
@PartitionKey(value = 1) |
|||
@Column(name = ModelConstants.ENTITY_VIEW_TENANT_ID_PROPERTY) |
|||
private UUID tenantId; |
|||
|
|||
@PartitionKey(value = 2) |
|||
@Column(name = ModelConstants.ENTITY_VIEW_CUSTOMER_ID_PROPERTY) |
|||
private UUID customerId; |
|||
|
|||
@PartitionKey(value = 3) |
|||
@Column(name = DEVICE_TYPE_PROPERTY) |
|||
private String type; |
|||
|
|||
@Enumerated(EnumType.STRING) |
|||
@Column(name = ENTITY_TYPE_PROPERTY) |
|||
private EntityType entityType; |
|||
|
|||
@Column(name = ModelConstants.ENTITY_VIEW_ENTITY_ID_PROPERTY) |
|||
private UUID entityId; |
|||
|
|||
@Column(name = ModelConstants.ENTITY_VIEW_NAME_PROPERTY) |
|||
private String name; |
|||
|
|||
@Column(name = ModelConstants.ENTITY_VIEW_KEYS_PROPERTY) |
|||
private String keys; |
|||
|
|||
@Column(name = ModelConstants.ENTITY_VIEW_START_TS_PROPERTY) |
|||
private long startTs; |
|||
|
|||
@Column(name = ModelConstants.ENTITY_VIEW_END_TS_PROPERTY) |
|||
private long endTs; |
|||
|
|||
@Column(name = ModelConstants.SEARCH_TEXT_PROPERTY) |
|||
private String searchText; |
|||
|
|||
@Type(type = "json") |
|||
@Column(name = ModelConstants.ENTITY_VIEW_ADDITIONAL_INFO_PROPERTY) |
|||
private JsonNode additionalInfo; |
|||
|
|||
private static final ObjectMapper mapper = new ObjectMapper(); |
|||
|
|||
public EntityViewEntity() { |
|||
super(); |
|||
} |
|||
|
|||
public EntityViewEntity(EntityView entityView) { |
|||
if (entityView.getId() != null) { |
|||
this.id = entityView.getId().getId(); |
|||
} |
|||
if (entityView.getEntityId() != null) { |
|||
this.entityId = entityView.getEntityId().getId(); |
|||
this.entityType = entityView.getEntityId().getEntityType(); |
|||
} |
|||
if (entityView.getTenantId() != null) { |
|||
this.tenantId = entityView.getTenantId().getId(); |
|||
} |
|||
if (entityView.getCustomerId() != null) { |
|||
this.customerId = entityView.getCustomerId().getId(); |
|||
} |
|||
this.type = entityView.getType(); |
|||
this.name = entityView.getName(); |
|||
try { |
|||
this.keys = mapper.writeValueAsString(entityView.getKeys()); |
|||
} catch (IOException e) { |
|||
log.error("Unable to serialize entity view keys!", e); |
|||
} |
|||
this.startTs = entityView.getStartTimeMs(); |
|||
this.endTs = entityView.getEndTimeMs(); |
|||
this.searchText = entityView.getSearchText(); |
|||
this.additionalInfo = entityView.getAdditionalInfo(); |
|||
} |
|||
|
|||
@Override |
|||
public String getSearchTextSource() { |
|||
return name; |
|||
} |
|||
|
|||
@Override |
|||
public EntityView toData() { |
|||
EntityView entityView = new EntityView(new EntityViewId(id)); |
|||
entityView.setCreatedTime(UUIDs.unixTimestamp(id)); |
|||
if (entityId != null) { |
|||
entityView.setEntityId(EntityIdFactory.getByTypeAndId(entityType.name(), entityId.toString())); |
|||
} |
|||
if (tenantId != null) { |
|||
entityView.setTenantId(new TenantId(tenantId)); |
|||
} |
|||
if (customerId != null) { |
|||
entityView.setCustomerId(new CustomerId(customerId)); |
|||
} |
|||
entityView.setType(type); |
|||
entityView.setName(name); |
|||
try { |
|||
entityView.setKeys(mapper.readValue(keys, TelemetryEntityView.class)); |
|||
} catch (IOException e) { |
|||
log.error("Unable to read entity view keys!", e); |
|||
} |
|||
entityView.setStartTimeMs(startTs); |
|||
entityView.setEndTimeMs(endTs); |
|||
entityView.setAdditionalInfo(additionalInfo); |
|||
return entityView; |
|||
} |
|||
} |
|||
@ -1,117 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.model.nosql; |
|||
|
|||
import com.datastax.driver.core.utils.UUIDs; |
|||
import com.datastax.driver.mapping.annotations.ClusteringColumn; |
|||
import com.datastax.driver.mapping.annotations.Column; |
|||
import com.datastax.driver.mapping.annotations.PartitionKey; |
|||
import com.datastax.driver.mapping.annotations.Table; |
|||
import com.fasterxml.jackson.databind.JsonNode; |
|||
import lombok.Data; |
|||
import lombok.NoArgsConstructor; |
|||
import org.thingsboard.server.common.data.EntityType; |
|||
import org.thingsboard.server.common.data.Event; |
|||
import org.thingsboard.server.common.data.id.EntityIdFactory; |
|||
import org.thingsboard.server.common.data.id.EventId; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.dao.model.BaseEntity; |
|||
import org.thingsboard.server.dao.model.type.EntityTypeCodec; |
|||
import org.thingsboard.server.dao.model.type.JsonCodec; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
import static org.thingsboard.server.dao.model.ModelConstants.EVENT_BODY_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.EVENT_COLUMN_FAMILY_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.EVENT_ENTITY_ID_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.EVENT_ENTITY_TYPE_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.EVENT_TENANT_ID_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.EVENT_TYPE_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.EVENT_UID_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ID_PROPERTY; |
|||
|
|||
/** |
|||
* @author Andrew Shvayka |
|||
*/ |
|||
@Data |
|||
@NoArgsConstructor |
|||
@Table(name = EVENT_COLUMN_FAMILY_NAME) |
|||
public class EventEntity implements BaseEntity<Event> { |
|||
|
|||
@Column(name = ID_PROPERTY) |
|||
private UUID id; |
|||
|
|||
@PartitionKey() |
|||
@Column(name = EVENT_TENANT_ID_PROPERTY) |
|||
private UUID tenantId; |
|||
|
|||
@PartitionKey(value = 1) |
|||
@Column(name = EVENT_ENTITY_TYPE_PROPERTY, codec = EntityTypeCodec.class) |
|||
private EntityType entityType; |
|||
|
|||
@PartitionKey(value = 2) |
|||
@Column(name = EVENT_ENTITY_ID_PROPERTY) |
|||
private UUID entityId; |
|||
|
|||
@ClusteringColumn() |
|||
@Column(name = EVENT_TYPE_PROPERTY) |
|||
private String eventType; |
|||
|
|||
@ClusteringColumn(value = 1) |
|||
@Column(name = EVENT_UID_PROPERTY) |
|||
private String eventUid; |
|||
|
|||
@Column(name = EVENT_BODY_PROPERTY, codec = JsonCodec.class) |
|||
private JsonNode body; |
|||
|
|||
public EventEntity(Event event) { |
|||
if (event.getId() != null) { |
|||
this.id = event.getId().getId(); |
|||
} |
|||
if (event.getTenantId() != null) { |
|||
this.tenantId = event.getTenantId().getId(); |
|||
} |
|||
if (event.getEntityId() != null) { |
|||
this.entityType = event.getEntityId().getEntityType(); |
|||
this.entityId = event.getEntityId().getId(); |
|||
} |
|||
this.eventType = event.getType(); |
|||
this.eventUid = event.getUid(); |
|||
this.body = event.getBody(); |
|||
} |
|||
|
|||
@Override |
|||
public UUID getId() { |
|||
return id; |
|||
} |
|||
|
|||
@Override |
|||
public void setId(UUID id) { |
|||
this.id = id; |
|||
} |
|||
|
|||
@Override |
|||
public Event toData() { |
|||
Event event = new Event(new EventId(id)); |
|||
event.setCreatedTime(UUIDs.unixTimestamp(id)); |
|||
event.setTenantId(new TenantId(tenantId)); |
|||
event.setEntityId(EntityIdFactory.getByTypeAndUuid(entityType, entityId)); |
|||
event.setBody(body); |
|||
event.setType(eventType); |
|||
event.setUid(eventUid); |
|||
return event; |
|||
} |
|||
} |
|||
@ -1,182 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.model.nosql; |
|||
|
|||
import com.datastax.driver.core.utils.UUIDs; |
|||
import com.datastax.driver.mapping.annotations.ClusteringColumn; |
|||
import com.datastax.driver.mapping.annotations.Column; |
|||
import com.datastax.driver.mapping.annotations.PartitionKey; |
|||
import com.datastax.driver.mapping.annotations.Table; |
|||
import com.fasterxml.jackson.databind.JsonNode; |
|||
import lombok.EqualsAndHashCode; |
|||
import lombok.Getter; |
|||
import lombok.Setter; |
|||
import lombok.ToString; |
|||
import org.thingsboard.server.common.data.id.RuleChainId; |
|||
import org.thingsboard.server.common.data.id.RuleNodeId; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.rule.RuleChain; |
|||
import org.thingsboard.server.dao.DaoUtil; |
|||
import org.thingsboard.server.dao.model.SearchTextEntity; |
|||
import org.thingsboard.server.dao.model.type.JsonCodec; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
import static org.thingsboard.server.dao.model.ModelConstants.ADDITIONAL_INFO_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.DEBUG_MODE; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ID_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.RULE_CHAIN_COLUMN_FAMILY_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.RULE_CHAIN_CONFIGURATION_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.RULE_CHAIN_FIRST_RULE_NODE_ID_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.RULE_CHAIN_NAME_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.RULE_CHAIN_ROOT_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.RULE_CHAIN_TENANT_ID_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.SEARCH_TEXT_PROPERTY; |
|||
|
|||
@Table(name = RULE_CHAIN_COLUMN_FAMILY_NAME) |
|||
@EqualsAndHashCode |
|||
@ToString |
|||
public class RuleChainEntity implements SearchTextEntity<RuleChain> { |
|||
|
|||
@PartitionKey |
|||
@Column(name = ID_PROPERTY) |
|||
private UUID id; |
|||
@ClusteringColumn |
|||
@Column(name = RULE_CHAIN_TENANT_ID_PROPERTY) |
|||
private UUID tenantId; |
|||
@Column(name = RULE_CHAIN_NAME_PROPERTY) |
|||
private String name; |
|||
@Column(name = SEARCH_TEXT_PROPERTY) |
|||
private String searchText; |
|||
@Column(name = RULE_CHAIN_FIRST_RULE_NODE_ID_PROPERTY) |
|||
private UUID firstRuleNodeId; |
|||
@Column(name = RULE_CHAIN_ROOT_PROPERTY) |
|||
private boolean root; |
|||
@Getter |
|||
@Setter |
|||
@Column(name = DEBUG_MODE) |
|||
private boolean debugMode; |
|||
@Column(name = RULE_CHAIN_CONFIGURATION_PROPERTY, codec = JsonCodec.class) |
|||
private JsonNode configuration; |
|||
@Column(name = ADDITIONAL_INFO_PROPERTY, codec = JsonCodec.class) |
|||
private JsonNode additionalInfo; |
|||
|
|||
public RuleChainEntity() { |
|||
} |
|||
|
|||
public RuleChainEntity(RuleChain ruleChain) { |
|||
if (ruleChain.getId() != null) { |
|||
this.id = ruleChain.getUuidId(); |
|||
} |
|||
this.tenantId = DaoUtil.getId(ruleChain.getTenantId()); |
|||
this.name = ruleChain.getName(); |
|||
this.searchText = ruleChain.getName(); |
|||
this.firstRuleNodeId = DaoUtil.getId(ruleChain.getFirstRuleNodeId()); |
|||
this.root = ruleChain.isRoot(); |
|||
this.debugMode = ruleChain.isDebugMode(); |
|||
this.configuration = ruleChain.getConfiguration(); |
|||
this.additionalInfo = ruleChain.getAdditionalInfo(); |
|||
} |
|||
|
|||
@Override |
|||
public String getSearchTextSource() { |
|||
return getSearchText(); |
|||
} |
|||
|
|||
@Override |
|||
public void setSearchText(String searchText) { |
|||
this.searchText = searchText; |
|||
} |
|||
|
|||
@Override |
|||
public UUID getId() { |
|||
return id; |
|||
} |
|||
|
|||
@Override |
|||
public void setId(UUID id) { |
|||
this.id = id; |
|||
} |
|||
|
|||
public UUID getTenantId() { |
|||
return tenantId; |
|||
} |
|||
|
|||
public void setTenantId(UUID tenantId) { |
|||
this.tenantId = tenantId; |
|||
} |
|||
|
|||
public String getName() { |
|||
return name; |
|||
} |
|||
|
|||
public void setName(String name) { |
|||
this.name = name; |
|||
} |
|||
|
|||
public UUID getFirstRuleNodeId() { |
|||
return firstRuleNodeId; |
|||
} |
|||
|
|||
public void setFirstRuleNodeId(UUID firstRuleNodeId) { |
|||
this.firstRuleNodeId = firstRuleNodeId; |
|||
} |
|||
|
|||
public boolean isRoot() { |
|||
return root; |
|||
} |
|||
|
|||
public void setRoot(boolean root) { |
|||
this.root = root; |
|||
} |
|||
|
|||
public String getSearchText() { |
|||
return searchText; |
|||
} |
|||
|
|||
public JsonNode getConfiguration() { |
|||
return configuration; |
|||
} |
|||
|
|||
public void setConfiguration(JsonNode configuration) { |
|||
this.configuration = configuration; |
|||
} |
|||
|
|||
public JsonNode getAdditionalInfo() { |
|||
return additionalInfo; |
|||
} |
|||
|
|||
public void setAdditionalInfo(JsonNode additionalInfo) { |
|||
this.additionalInfo = additionalInfo; |
|||
} |
|||
|
|||
@Override |
|||
public RuleChain toData() { |
|||
RuleChain ruleChain = new RuleChain(new RuleChainId(id)); |
|||
ruleChain.setCreatedTime(UUIDs.unixTimestamp(id)); |
|||
ruleChain.setTenantId(new TenantId(tenantId)); |
|||
ruleChain.setName(name); |
|||
if (this.firstRuleNodeId != null) { |
|||
ruleChain.setFirstRuleNodeId(new RuleNodeId(this.firstRuleNodeId)); |
|||
} |
|||
ruleChain.setRoot(this.root); |
|||
ruleChain.setDebugMode(this.debugMode); |
|||
ruleChain.setConfiguration(this.configuration); |
|||
ruleChain.setAdditionalInfo(this.additionalInfo); |
|||
return ruleChain; |
|||
} |
|||
|
|||
} |
|||
@ -1,167 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.model.nosql; |
|||
|
|||
import com.datastax.driver.core.utils.UUIDs; |
|||
import com.datastax.driver.mapping.annotations.Column; |
|||
import com.datastax.driver.mapping.annotations.PartitionKey; |
|||
import com.datastax.driver.mapping.annotations.Table; |
|||
import com.fasterxml.jackson.databind.JsonNode; |
|||
import lombok.EqualsAndHashCode; |
|||
import lombok.Getter; |
|||
import lombok.Setter; |
|||
import lombok.ToString; |
|||
import org.thingsboard.server.common.data.id.RuleChainId; |
|||
import org.thingsboard.server.common.data.id.RuleNodeId; |
|||
import org.thingsboard.server.common.data.rule.RuleNode; |
|||
import org.thingsboard.server.dao.model.SearchTextEntity; |
|||
import org.thingsboard.server.dao.model.type.JsonCodec; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
import static org.thingsboard.server.dao.model.ModelConstants.ADDITIONAL_INFO_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.DEBUG_MODE; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ID_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.RULE_NODE_CHAIN_ID_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.RULE_NODE_COLUMN_FAMILY_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.RULE_NODE_CONFIGURATION_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.RULE_NODE_NAME_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.RULE_NODE_TYPE_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.SEARCH_TEXT_PROPERTY; |
|||
|
|||
@Table(name = RULE_NODE_COLUMN_FAMILY_NAME) |
|||
@EqualsAndHashCode |
|||
@ToString |
|||
public class RuleNodeEntity implements SearchTextEntity<RuleNode> { |
|||
|
|||
@PartitionKey |
|||
@Column(name = ID_PROPERTY) |
|||
private UUID id; |
|||
@Column(name = RULE_NODE_CHAIN_ID_PROPERTY) |
|||
private UUID ruleChainId; |
|||
@Column(name = RULE_NODE_TYPE_PROPERTY) |
|||
private String type; |
|||
@Column(name = RULE_NODE_NAME_PROPERTY) |
|||
private String name; |
|||
@Column(name = SEARCH_TEXT_PROPERTY) |
|||
private String searchText; |
|||
@Column(name = RULE_NODE_CONFIGURATION_PROPERTY, codec = JsonCodec.class) |
|||
private JsonNode configuration; |
|||
@Column(name = ADDITIONAL_INFO_PROPERTY, codec = JsonCodec.class) |
|||
private JsonNode additionalInfo; |
|||
@Getter |
|||
@Setter |
|||
@Column(name = DEBUG_MODE) |
|||
private boolean debugMode; |
|||
|
|||
public RuleNodeEntity() { |
|||
} |
|||
|
|||
public RuleNodeEntity(RuleNode ruleNode) { |
|||
if (ruleNode.getId() != null) { |
|||
this.id = ruleNode.getUuidId(); |
|||
} |
|||
if (ruleNode.getRuleChainId() != null) { |
|||
this.ruleChainId = ruleNode.getRuleChainId().getId(); |
|||
} |
|||
this.type = ruleNode.getType(); |
|||
this.name = ruleNode.getName(); |
|||
this.debugMode = ruleNode.isDebugMode(); |
|||
this.searchText = ruleNode.getName(); |
|||
this.configuration = ruleNode.getConfiguration(); |
|||
this.additionalInfo = ruleNode.getAdditionalInfo(); |
|||
} |
|||
|
|||
@Override |
|||
public String getSearchTextSource() { |
|||
return getSearchText(); |
|||
} |
|||
|
|||
@Override |
|||
public void setSearchText(String searchText) { |
|||
this.searchText = searchText; |
|||
} |
|||
|
|||
@Override |
|||
public UUID getId() { |
|||
return id; |
|||
} |
|||
|
|||
@Override |
|||
public void setId(UUID id) { |
|||
this.id = id; |
|||
} |
|||
|
|||
public UUID getRuleChainId() { |
|||
return ruleChainId; |
|||
} |
|||
|
|||
public void setRuleChainId(UUID ruleChainId) { |
|||
this.ruleChainId = ruleChainId; |
|||
} |
|||
|
|||
public String getType() { |
|||
return type; |
|||
} |
|||
|
|||
public void setType(String type) { |
|||
this.type = type; |
|||
} |
|||
|
|||
public String getName() { |
|||
return name; |
|||
} |
|||
|
|||
public void setName(String name) { |
|||
this.name = name; |
|||
} |
|||
|
|||
public String getSearchText() { |
|||
return searchText; |
|||
} |
|||
|
|||
public JsonNode getConfiguration() { |
|||
return configuration; |
|||
} |
|||
|
|||
public void setConfiguration(JsonNode configuration) { |
|||
this.configuration = configuration; |
|||
} |
|||
|
|||
public JsonNode getAdditionalInfo() { |
|||
return additionalInfo; |
|||
} |
|||
|
|||
public void setAdditionalInfo(JsonNode additionalInfo) { |
|||
this.additionalInfo = additionalInfo; |
|||
} |
|||
|
|||
@Override |
|||
public RuleNode toData() { |
|||
RuleNode ruleNode = new RuleNode(new RuleNodeId(id)); |
|||
ruleNode.setCreatedTime(UUIDs.unixTimestamp(id)); |
|||
if (this.ruleChainId != null) { |
|||
ruleNode.setRuleChainId(new RuleChainId(this.ruleChainId)); |
|||
} |
|||
ruleNode.setType(this.type); |
|||
ruleNode.setName(this.name); |
|||
ruleNode.setDebugMode(this.debugMode); |
|||
ruleNode.setConfiguration(this.configuration); |
|||
ruleNode.setAdditionalInfo(this.additionalInfo); |
|||
return ruleNode; |
|||
} |
|||
|
|||
} |
|||
@ -1,242 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.model.nosql; |
|||
|
|||
import com.datastax.driver.core.utils.UUIDs; |
|||
import com.datastax.driver.mapping.annotations.Column; |
|||
import com.datastax.driver.mapping.annotations.PartitionKey; |
|||
import com.datastax.driver.mapping.annotations.Table; |
|||
import com.fasterxml.jackson.databind.JsonNode; |
|||
import lombok.EqualsAndHashCode; |
|||
import lombok.ToString; |
|||
import org.thingsboard.server.common.data.Tenant; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.dao.model.SearchTextEntity; |
|||
import org.thingsboard.server.dao.model.type.JsonCodec; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
import static org.thingsboard.server.dao.model.ModelConstants.ADDRESS2_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ADDRESS_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.CITY_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.COUNTRY_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.EMAIL_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ID_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.PHONE_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.SEARCH_TEXT_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.STATE_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.TENANT_ADDITIONAL_INFO_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.TENANT_COLUMN_FAMILY_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.TENANT_REGION_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.TENANT_TITLE_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ZIP_PROPERTY; |
|||
|
|||
@Table(name = TENANT_COLUMN_FAMILY_NAME) |
|||
@EqualsAndHashCode |
|||
@ToString |
|||
public final class TenantEntity implements SearchTextEntity<Tenant> { |
|||
|
|||
@PartitionKey(value = 0) |
|||
@Column(name = ID_PROPERTY) |
|||
private UUID id; |
|||
|
|||
@Column(name = TENANT_TITLE_PROPERTY) |
|||
private String title; |
|||
|
|||
@Column(name = SEARCH_TEXT_PROPERTY) |
|||
private String searchText; |
|||
|
|||
@Column(name = TENANT_REGION_PROPERTY) |
|||
private String region; |
|||
|
|||
@Column(name = COUNTRY_PROPERTY) |
|||
private String country; |
|||
|
|||
@Column(name = STATE_PROPERTY) |
|||
private String state; |
|||
|
|||
@Column(name = CITY_PROPERTY) |
|||
private String city; |
|||
|
|||
@Column(name = ADDRESS_PROPERTY) |
|||
private String address; |
|||
|
|||
@Column(name = ADDRESS2_PROPERTY) |
|||
private String address2; |
|||
|
|||
@Column(name = ZIP_PROPERTY) |
|||
private String zip; |
|||
|
|||
@Column(name = PHONE_PROPERTY) |
|||
private String phone; |
|||
|
|||
@Column(name = EMAIL_PROPERTY) |
|||
private String email; |
|||
|
|||
@Column(name = TENANT_ADDITIONAL_INFO_PROPERTY, codec = JsonCodec.class) |
|||
private JsonNode additionalInfo; |
|||
|
|||
public TenantEntity() { |
|||
super(); |
|||
} |
|||
|
|||
public TenantEntity(Tenant tenant) { |
|||
if (tenant.getId() != null) { |
|||
this.id = tenant.getId().getId(); |
|||
} |
|||
this.title = tenant.getTitle(); |
|||
this.region = tenant.getRegion(); |
|||
this.country = tenant.getCountry(); |
|||
this.state = tenant.getState(); |
|||
this.city = tenant.getCity(); |
|||
this.address = tenant.getAddress(); |
|||
this.address2 = tenant.getAddress2(); |
|||
this.zip = tenant.getZip(); |
|||
this.phone = tenant.getPhone(); |
|||
this.email = tenant.getEmail(); |
|||
this.additionalInfo = tenant.getAdditionalInfo(); |
|||
} |
|||
|
|||
public UUID getId() { |
|||
return id; |
|||
} |
|||
|
|||
public void setId(UUID id) { |
|||
this.id = id; |
|||
} |
|||
|
|||
public String getTitle() { |
|||
return title; |
|||
} |
|||
|
|||
public void setTitle(String title) { |
|||
this.title = title; |
|||
} |
|||
|
|||
public String getRegion() { |
|||
return region; |
|||
} |
|||
|
|||
public void setRegion(String region) { |
|||
this.region = region; |
|||
} |
|||
|
|||
public String getCountry() { |
|||
return country; |
|||
} |
|||
|
|||
public void setCountry(String country) { |
|||
this.country = country; |
|||
} |
|||
|
|||
public String getState() { |
|||
return state; |
|||
} |
|||
|
|||
public void setState(String state) { |
|||
this.state = state; |
|||
} |
|||
|
|||
public String getCity() { |
|||
return city; |
|||
} |
|||
|
|||
public void setCity(String city) { |
|||
this.city = city; |
|||
} |
|||
|
|||
public String getAddress() { |
|||
return address; |
|||
} |
|||
|
|||
public void setAddress(String address) { |
|||
this.address = address; |
|||
} |
|||
|
|||
public String getAddress2() { |
|||
return address2; |
|||
} |
|||
|
|||
public void setAddress2(String address2) { |
|||
this.address2 = address2; |
|||
} |
|||
|
|||
public String getZip() { |
|||
return zip; |
|||
} |
|||
|
|||
public void setZip(String zip) { |
|||
this.zip = zip; |
|||
} |
|||
|
|||
public String getPhone() { |
|||
return phone; |
|||
} |
|||
|
|||
public void setPhone(String phone) { |
|||
this.phone = phone; |
|||
} |
|||
|
|||
public String getEmail() { |
|||
return email; |
|||
} |
|||
|
|||
public void setEmail(String email) { |
|||
this.email = email; |
|||
} |
|||
|
|||
public JsonNode getAdditionalInfo() { |
|||
return additionalInfo; |
|||
} |
|||
|
|||
public void setAdditionalInfo(JsonNode additionalInfo) { |
|||
this.additionalInfo = additionalInfo; |
|||
} |
|||
|
|||
@Override |
|||
public String getSearchTextSource() { |
|||
return getTitle(); |
|||
} |
|||
|
|||
@Override |
|||
public void setSearchText(String searchText) { |
|||
this.searchText = searchText; |
|||
} |
|||
|
|||
public String getSearchText() { |
|||
return searchText; |
|||
} |
|||
|
|||
@Override |
|||
public Tenant toData() { |
|||
Tenant tenant = new Tenant(new TenantId(id)); |
|||
tenant.setCreatedTime(UUIDs.unixTimestamp(id)); |
|||
tenant.setTitle(title); |
|||
tenant.setRegion(region); |
|||
tenant.setCountry(country); |
|||
tenant.setState(state); |
|||
tenant.setCity(city); |
|||
tenant.setAddress(address); |
|||
tenant.setAddress2(address2); |
|||
tenant.setZip(zip); |
|||
tenant.setPhone(phone); |
|||
tenant.setEmail(email); |
|||
tenant.setAdditionalInfo(additionalInfo); |
|||
return tenant; |
|||
} |
|||
|
|||
|
|||
} |
|||
@ -1,140 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.model.nosql; |
|||
|
|||
import com.datastax.driver.core.utils.UUIDs; |
|||
import com.datastax.driver.mapping.annotations.Column; |
|||
import com.datastax.driver.mapping.annotations.PartitionKey; |
|||
import com.datastax.driver.mapping.annotations.Table; |
|||
import lombok.EqualsAndHashCode; |
|||
import org.thingsboard.server.common.data.id.UserCredentialsId; |
|||
import org.thingsboard.server.common.data.id.UserId; |
|||
import org.thingsboard.server.common.data.security.UserCredentials; |
|||
import org.thingsboard.server.dao.model.BaseEntity; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
import static org.thingsboard.server.dao.model.ModelConstants.ID_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.USER_CREDENTIALS_ACTIVATE_TOKEN_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.USER_CREDENTIALS_COLUMN_FAMILY_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.USER_CREDENTIALS_ENABLED_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.USER_CREDENTIALS_PASSWORD_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.USER_CREDENTIALS_RESET_TOKEN_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.USER_CREDENTIALS_USER_ID_PROPERTY; |
|||
|
|||
@Table(name = USER_CREDENTIALS_COLUMN_FAMILY_NAME) |
|||
@EqualsAndHashCode |
|||
public final class UserCredentialsEntity implements BaseEntity<UserCredentials> { |
|||
|
|||
@PartitionKey(value = 0) |
|||
@Column(name = ID_PROPERTY) |
|||
private UUID id; |
|||
|
|||
@Column(name = USER_CREDENTIALS_USER_ID_PROPERTY) |
|||
private UUID userId; |
|||
|
|||
@Column(name = USER_CREDENTIALS_ENABLED_PROPERTY) |
|||
private boolean enabled; |
|||
|
|||
@Column(name = USER_CREDENTIALS_PASSWORD_PROPERTY) |
|||
private String password; |
|||
|
|||
@Column(name = USER_CREDENTIALS_ACTIVATE_TOKEN_PROPERTY) |
|||
private String activateToken; |
|||
|
|||
@Column(name = USER_CREDENTIALS_RESET_TOKEN_PROPERTY) |
|||
private String resetToken; |
|||
|
|||
public UserCredentialsEntity() { |
|||
super(); |
|||
} |
|||
|
|||
public UserCredentialsEntity(UserCredentials userCredentials) { |
|||
if (userCredentials.getId() != null) { |
|||
this.id = userCredentials.getId().getId(); |
|||
} |
|||
if (userCredentials.getUserId() != null) { |
|||
this.userId = userCredentials.getUserId().getId(); |
|||
} |
|||
this.enabled = userCredentials.isEnabled(); |
|||
this.password = userCredentials.getPassword(); |
|||
this.activateToken = userCredentials.getActivateToken(); |
|||
this.resetToken = userCredentials.getResetToken(); |
|||
} |
|||
|
|||
public UUID getId() { |
|||
return id; |
|||
} |
|||
|
|||
public void setId(UUID id) { |
|||
this.id = id; |
|||
} |
|||
|
|||
public UUID getUserId() { |
|||
return userId; |
|||
} |
|||
|
|||
public void setUserId(UUID userId) { |
|||
this.userId = userId; |
|||
} |
|||
|
|||
public boolean isEnabled() { |
|||
return enabled; |
|||
} |
|||
|
|||
public void setEnabled(boolean enabled) { |
|||
this.enabled = enabled; |
|||
} |
|||
|
|||
public String getPassword() { |
|||
return password; |
|||
} |
|||
|
|||
public void setPassword(String password) { |
|||
this.password = password; |
|||
} |
|||
|
|||
public String getActivateToken() { |
|||
return activateToken; |
|||
} |
|||
|
|||
public void setActivateToken(String activateToken) { |
|||
this.activateToken = activateToken; |
|||
} |
|||
|
|||
public String getResetToken() { |
|||
return resetToken; |
|||
} |
|||
|
|||
public void setResetToken(String resetToken) { |
|||
this.resetToken = resetToken; |
|||
} |
|||
|
|||
@Override |
|||
public UserCredentials toData() { |
|||
UserCredentials userCredentials = new UserCredentials(new UserCredentialsId(id)); |
|||
userCredentials.setCreatedTime(UUIDs.unixTimestamp(id)); |
|||
if (userId != null) { |
|||
userCredentials.setUserId(new UserId(userId)); |
|||
} |
|||
userCredentials.setEnabled(enabled); |
|||
userCredentials.setPassword(password); |
|||
userCredentials.setActivateToken(activateToken); |
|||
userCredentials.setResetToken(resetToken); |
|||
return userCredentials; |
|||
} |
|||
|
|||
} |
|||
@ -1,200 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.model.nosql; |
|||
|
|||
import com.datastax.driver.core.utils.UUIDs; |
|||
import com.datastax.driver.mapping.annotations.Column; |
|||
import com.datastax.driver.mapping.annotations.PartitionKey; |
|||
import com.datastax.driver.mapping.annotations.Table; |
|||
import com.fasterxml.jackson.databind.JsonNode; |
|||
import lombok.EqualsAndHashCode; |
|||
import lombok.ToString; |
|||
import org.thingsboard.server.common.data.User; |
|||
import org.thingsboard.server.common.data.id.CustomerId; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.id.UserId; |
|||
import org.thingsboard.server.common.data.security.Authority; |
|||
import org.thingsboard.server.dao.model.SearchTextEntity; |
|||
import org.thingsboard.server.dao.model.type.AuthorityCodec; |
|||
import org.thingsboard.server.dao.model.type.JsonCodec; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
import static org.thingsboard.server.dao.model.ModelConstants.ID_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.SEARCH_TEXT_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.USER_ADDITIONAL_INFO_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.USER_AUTHORITY_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.USER_COLUMN_FAMILY_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.USER_CUSTOMER_ID_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.USER_EMAIL_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.USER_FIRST_NAME_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.USER_LAST_NAME_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.USER_TENANT_ID_PROPERTY; |
|||
|
|||
@Table(name = USER_COLUMN_FAMILY_NAME) |
|||
@EqualsAndHashCode |
|||
@ToString |
|||
public final class UserEntity implements SearchTextEntity<User> { |
|||
|
|||
@PartitionKey(value = 0) |
|||
@Column(name = ID_PROPERTY) |
|||
private UUID id; |
|||
|
|||
@PartitionKey(value = 1) |
|||
@Column(name = USER_TENANT_ID_PROPERTY) |
|||
private UUID tenantId; |
|||
|
|||
@PartitionKey(value = 2) |
|||
@Column(name = USER_CUSTOMER_ID_PROPERTY) |
|||
private UUID customerId; |
|||
|
|||
@PartitionKey(value = 3) |
|||
@Column(name = USER_AUTHORITY_PROPERTY, codec = AuthorityCodec.class) |
|||
private Authority authority; |
|||
|
|||
@Column(name = USER_EMAIL_PROPERTY) |
|||
private String email; |
|||
|
|||
@Column(name = SEARCH_TEXT_PROPERTY) |
|||
private String searchText; |
|||
|
|||
@Column(name = USER_FIRST_NAME_PROPERTY) |
|||
private String firstName; |
|||
|
|||
@Column(name = USER_LAST_NAME_PROPERTY) |
|||
private String lastName; |
|||
|
|||
@Column(name = USER_ADDITIONAL_INFO_PROPERTY, codec = JsonCodec.class) |
|||
private JsonNode additionalInfo; |
|||
|
|||
public UserEntity() { |
|||
super(); |
|||
} |
|||
|
|||
public UserEntity(User user) { |
|||
if (user.getId() != null) { |
|||
this.id = user.getId().getId(); |
|||
} |
|||
this.authority = user.getAuthority(); |
|||
if (user.getTenantId() != null) { |
|||
this.tenantId = user.getTenantId().getId(); |
|||
} |
|||
if (user.getCustomerId() != null) { |
|||
this.customerId = user.getCustomerId().getId(); |
|||
} |
|||
this.email = user.getEmail(); |
|||
this.firstName = user.getFirstName(); |
|||
this.lastName = user.getLastName(); |
|||
this.additionalInfo = user.getAdditionalInfo(); |
|||
} |
|||
|
|||
public UUID getId() { |
|||
return id; |
|||
} |
|||
|
|||
public void setId(UUID id) { |
|||
this.id = id; |
|||
} |
|||
|
|||
public Authority getAuthority() { |
|||
return authority; |
|||
} |
|||
|
|||
public void setAuthority(Authority authority) { |
|||
this.authority = authority; |
|||
} |
|||
|
|||
public UUID getTenantId() { |
|||
return tenantId; |
|||
} |
|||
|
|||
public void setTenantId(UUID tenantId) { |
|||
this.tenantId = tenantId; |
|||
} |
|||
|
|||
public UUID getCustomerId() { |
|||
return customerId; |
|||
} |
|||
|
|||
public void setCustomerId(UUID customerId) { |
|||
this.customerId = customerId; |
|||
} |
|||
|
|||
public String getEmail() { |
|||
return email; |
|||
} |
|||
|
|||
public void setEmail(String email) { |
|||
this.email = email; |
|||
} |
|||
|
|||
public String getFirstName() { |
|||
return firstName; |
|||
} |
|||
|
|||
public void setFirstName(String firstName) { |
|||
this.firstName = firstName; |
|||
} |
|||
|
|||
public String getLastName() { |
|||
return lastName; |
|||
} |
|||
|
|||
public void setLastName(String lastName) { |
|||
this.lastName = lastName; |
|||
} |
|||
|
|||
public JsonNode getAdditionalInfo() { |
|||
return additionalInfo; |
|||
} |
|||
|
|||
public void setAdditionalInfo(JsonNode additionalInfo) { |
|||
this.additionalInfo = additionalInfo; |
|||
} |
|||
|
|||
@Override |
|||
public String getSearchTextSource() { |
|||
return getEmail(); |
|||
} |
|||
|
|||
@Override |
|||
public void setSearchText(String searchText) { |
|||
this.searchText = searchText; |
|||
} |
|||
|
|||
public String getSearchText() { |
|||
return searchText; |
|||
} |
|||
|
|||
@Override |
|||
public User toData() { |
|||
User user = new User(new UserId(id)); |
|||
user.setCreatedTime(UUIDs.unixTimestamp(id)); |
|||
user.setAuthority(authority); |
|||
if (tenantId != null) { |
|||
user.setTenantId(new TenantId(tenantId)); |
|||
} |
|||
if (customerId != null) { |
|||
user.setCustomerId(new CustomerId(customerId)); |
|||
} |
|||
user.setEmail(email); |
|||
user.setFirstName(firstName); |
|||
user.setLastName(lastName); |
|||
user.setAdditionalInfo(additionalInfo); |
|||
return user; |
|||
} |
|||
|
|||
} |
|||
@ -1,148 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.model.nosql; |
|||
|
|||
import com.datastax.driver.core.utils.UUIDs; |
|||
import com.datastax.driver.mapping.annotations.Column; |
|||
import com.datastax.driver.mapping.annotations.PartitionKey; |
|||
import com.datastax.driver.mapping.annotations.Table; |
|||
import com.fasterxml.jackson.databind.JsonNode; |
|||
import lombok.EqualsAndHashCode; |
|||
import lombok.ToString; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.id.WidgetTypeId; |
|||
import org.thingsboard.server.common.data.widget.WidgetType; |
|||
import org.thingsboard.server.dao.model.BaseEntity; |
|||
import org.thingsboard.server.dao.model.type.JsonCodec; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
import static org.thingsboard.server.dao.model.ModelConstants.ID_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.WIDGET_TYPE_ALIAS_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.WIDGET_TYPE_BUNDLE_ALIAS_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.WIDGET_TYPE_COLUMN_FAMILY_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.WIDGET_TYPE_DESCRIPTOR_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.WIDGET_TYPE_NAME_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.WIDGET_TYPE_TENANT_ID_PROPERTY; |
|||
|
|||
@Table(name = WIDGET_TYPE_COLUMN_FAMILY_NAME) |
|||
@EqualsAndHashCode |
|||
@ToString |
|||
public final class WidgetTypeEntity implements BaseEntity<WidgetType> { |
|||
|
|||
@PartitionKey(value = 0) |
|||
@Column(name = ID_PROPERTY) |
|||
private UUID id; |
|||
|
|||
@PartitionKey(value = 1) |
|||
@Column(name = WIDGET_TYPE_TENANT_ID_PROPERTY) |
|||
private UUID tenantId; |
|||
|
|||
@PartitionKey(value = 2) |
|||
@Column(name = WIDGET_TYPE_BUNDLE_ALIAS_PROPERTY) |
|||
private String bundleAlias; |
|||
|
|||
@Column(name = WIDGET_TYPE_ALIAS_PROPERTY) |
|||
private String alias; |
|||
|
|||
@Column(name = WIDGET_TYPE_NAME_PROPERTY) |
|||
private String name; |
|||
|
|||
@Column(name = WIDGET_TYPE_DESCRIPTOR_PROPERTY, codec = JsonCodec.class) |
|||
private JsonNode descriptor; |
|||
|
|||
public WidgetTypeEntity() { |
|||
super(); |
|||
} |
|||
|
|||
public WidgetTypeEntity(WidgetType widgetType) { |
|||
if (widgetType.getId() != null) { |
|||
this.id = widgetType.getId().getId(); |
|||
} |
|||
if (widgetType.getTenantId() != null) { |
|||
this.tenantId = widgetType.getTenantId().getId(); |
|||
} |
|||
this.bundleAlias = widgetType.getBundleAlias(); |
|||
this.alias = widgetType.getAlias(); |
|||
this.name = widgetType.getName(); |
|||
this.descriptor = widgetType.getDescriptor(); |
|||
} |
|||
|
|||
@Override |
|||
public UUID getId() { |
|||
return id; |
|||
} |
|||
|
|||
@Override |
|||
public void setId(UUID id) { |
|||
this.id = id; |
|||
} |
|||
|
|||
public UUID getTenantId() { |
|||
return tenantId; |
|||
} |
|||
|
|||
public void setTenantId(UUID tenantId) { |
|||
this.tenantId = tenantId; |
|||
} |
|||
|
|||
public String getBundleAlias() { |
|||
return bundleAlias; |
|||
} |
|||
|
|||
public void setBundleAlias(String bundleAlias) { |
|||
this.bundleAlias = bundleAlias; |
|||
} |
|||
|
|||
public String getAlias() { |
|||
return alias; |
|||
} |
|||
|
|||
public void setAlias(String alias) { |
|||
this.alias = alias; |
|||
} |
|||
|
|||
public String getName() { |
|||
return name; |
|||
} |
|||
|
|||
public void setName(String name) { |
|||
this.name = name; |
|||
} |
|||
|
|||
public JsonNode getDescriptor() { |
|||
return descriptor; |
|||
} |
|||
|
|||
public void setDescriptor(JsonNode descriptor) { |
|||
this.descriptor = descriptor; |
|||
} |
|||
|
|||
@Override |
|||
public WidgetType toData() { |
|||
WidgetType widgetType = new WidgetType(new WidgetTypeId(id)); |
|||
widgetType.setCreatedTime(UUIDs.unixTimestamp(id)); |
|||
if (tenantId != null) { |
|||
widgetType.setTenantId(new TenantId(tenantId)); |
|||
} |
|||
widgetType.setBundleAlias(bundleAlias); |
|||
widgetType.setAlias(alias); |
|||
widgetType.setName(name); |
|||
widgetType.setDescriptor(descriptor); |
|||
return widgetType; |
|||
} |
|||
|
|||
} |
|||
@ -1,156 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.model.nosql; |
|||
|
|||
|
|||
import com.datastax.driver.core.utils.UUIDs; |
|||
import com.datastax.driver.mapping.annotations.Column; |
|||
import com.datastax.driver.mapping.annotations.PartitionKey; |
|||
import com.datastax.driver.mapping.annotations.Table; |
|||
import lombok.EqualsAndHashCode; |
|||
import lombok.ToString; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.id.WidgetsBundleId; |
|||
import org.thingsboard.server.common.data.widget.WidgetsBundle; |
|||
import org.thingsboard.server.dao.model.SearchTextEntity; |
|||
|
|||
import java.nio.ByteBuffer; |
|||
import java.util.UUID; |
|||
|
|||
import static org.thingsboard.server.dao.model.ModelConstants.ID_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.SEARCH_TEXT_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.WIDGETS_BUNDLE_ALIAS_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.WIDGETS_BUNDLE_COLUMN_FAMILY_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.WIDGETS_BUNDLE_IMAGE_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.WIDGETS_BUNDLE_TENANT_ID_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.WIDGETS_BUNDLE_TITLE_PROPERTY; |
|||
|
|||
@Table(name = WIDGETS_BUNDLE_COLUMN_FAMILY_NAME) |
|||
@EqualsAndHashCode |
|||
@ToString |
|||
public final class WidgetsBundleEntity implements SearchTextEntity<WidgetsBundle> { |
|||
|
|||
@PartitionKey(value = 0) |
|||
@Column(name = ID_PROPERTY) |
|||
private UUID id; |
|||
|
|||
@PartitionKey(value = 1) |
|||
@Column(name = WIDGETS_BUNDLE_TENANT_ID_PROPERTY) |
|||
private UUID tenantId; |
|||
|
|||
@Column(name = WIDGETS_BUNDLE_ALIAS_PROPERTY) |
|||
private String alias; |
|||
|
|||
@Column(name = WIDGETS_BUNDLE_TITLE_PROPERTY) |
|||
private String title; |
|||
|
|||
@Column(name = SEARCH_TEXT_PROPERTY) |
|||
private String searchText; |
|||
|
|||
@Column(name = WIDGETS_BUNDLE_IMAGE_PROPERTY) |
|||
private ByteBuffer image; |
|||
|
|||
public WidgetsBundleEntity() { |
|||
super(); |
|||
} |
|||
|
|||
public WidgetsBundleEntity(WidgetsBundle widgetsBundle) { |
|||
if (widgetsBundle.getId() != null) { |
|||
this.id = widgetsBundle.getId().getId(); |
|||
} |
|||
if (widgetsBundle.getTenantId() != null) { |
|||
this.tenantId = widgetsBundle.getTenantId().getId(); |
|||
} |
|||
this.alias = widgetsBundle.getAlias(); |
|||
this.title = widgetsBundle.getTitle(); |
|||
if (widgetsBundle.getImage() != null) { |
|||
this.image = ByteBuffer.wrap(widgetsBundle.getImage()); |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public UUID getId() { |
|||
return id; |
|||
} |
|||
|
|||
@Override |
|||
public void setId(UUID id) { |
|||
this.id = id; |
|||
} |
|||
|
|||
public UUID getTenantId() { |
|||
return tenantId; |
|||
} |
|||
|
|||
public void setTenantId(UUID tenantId) { |
|||
this.tenantId = tenantId; |
|||
} |
|||
|
|||
public String getAlias() { |
|||
return alias; |
|||
} |
|||
|
|||
public void setAlias(String alias) { |
|||
this.alias = alias; |
|||
} |
|||
|
|||
public String getTitle() { |
|||
return title; |
|||
} |
|||
|
|||
public void setTitle(String title) { |
|||
this.title = title; |
|||
} |
|||
|
|||
public ByteBuffer getImage() { |
|||
return image; |
|||
} |
|||
|
|||
public void setImage(ByteBuffer image) { |
|||
this.image = image; |
|||
} |
|||
|
|||
@Override |
|||
public String getSearchTextSource() { |
|||
return getTitle(); |
|||
} |
|||
|
|||
@Override |
|||
public void setSearchText(String searchText) { |
|||
this.searchText = searchText; |
|||
} |
|||
|
|||
public String getSearchText() { |
|||
return searchText; |
|||
} |
|||
|
|||
@Override |
|||
public WidgetsBundle toData() { |
|||
WidgetsBundle widgetsBundle = new WidgetsBundle(new WidgetsBundleId(id)); |
|||
widgetsBundle.setCreatedTime(UUIDs.unixTimestamp(id)); |
|||
if (tenantId != null) { |
|||
widgetsBundle.setTenantId(new TenantId(tenantId)); |
|||
} |
|||
widgetsBundle.setAlias(alias); |
|||
widgetsBundle.setTitle(title); |
|||
if (image != null) { |
|||
byte[] imageByteArray = new byte[image.remaining()]; |
|||
image.get(imageByteArray); |
|||
widgetsBundle.setImage(imageByteArray); |
|||
} |
|||
return widgetsBundle; |
|||
} |
|||
} |
|||
@ -1,26 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.model.type; |
|||
|
|||
import com.datastax.driver.extras.codecs.enums.EnumNameCodec; |
|||
import org.thingsboard.server.common.data.audit.ActionStatus; |
|||
|
|||
public class ActionStatusCodec extends EnumNameCodec<ActionStatus> { |
|||
|
|||
public ActionStatusCodec() { |
|||
super(ActionStatus.class); |
|||
} |
|||
} |
|||
@ -1,26 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.model.type; |
|||
|
|||
import com.datastax.driver.extras.codecs.enums.EnumNameCodec; |
|||
import org.thingsboard.server.common.data.audit.ActionType; |
|||
|
|||
public class ActionTypeCodec extends EnumNameCodec<ActionType> { |
|||
|
|||
public ActionTypeCodec() { |
|||
super(ActionType.class); |
|||
} |
|||
} |
|||
@ -1,27 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.model.type; |
|||
|
|||
import com.datastax.driver.extras.codecs.enums.EnumNameCodec; |
|||
import org.thingsboard.server.common.data.alarm.AlarmSeverity; |
|||
|
|||
public class AlarmSeverityCodec extends EnumNameCodec<AlarmSeverity> { |
|||
|
|||
public AlarmSeverityCodec() { |
|||
super(AlarmSeverity.class); |
|||
} |
|||
|
|||
} |
|||
@ -1,27 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.model.type; |
|||
|
|||
import com.datastax.driver.extras.codecs.enums.EnumNameCodec; |
|||
import org.thingsboard.server.common.data.alarm.AlarmStatus; |
|||
|
|||
public class AlarmStatusCodec extends EnumNameCodec<AlarmStatus> { |
|||
|
|||
public AlarmStatusCodec() { |
|||
super(AlarmStatus.class); |
|||
} |
|||
|
|||
} |
|||
@ -1,27 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.model.type; |
|||
|
|||
import com.datastax.driver.extras.codecs.enums.EnumNameCodec; |
|||
import org.thingsboard.server.common.data.security.Authority; |
|||
|
|||
public class AuthorityCodec extends EnumNameCodec<Authority> { |
|||
|
|||
public AuthorityCodec() { |
|||
super(Authority.class); |
|||
} |
|||
|
|||
} |
|||
@ -1,27 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.model.type; |
|||
|
|||
import com.datastax.driver.extras.codecs.enums.EnumNameCodec; |
|||
import org.thingsboard.server.common.data.plugin.ComponentScope; |
|||
|
|||
public class ComponentScopeCodec extends EnumNameCodec<ComponentScope> { |
|||
|
|||
public ComponentScopeCodec() { |
|||
super(ComponentScope.class); |
|||
} |
|||
|
|||
} |
|||
@ -1,27 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.model.type; |
|||
|
|||
import com.datastax.driver.extras.codecs.enums.EnumNameCodec; |
|||
import org.thingsboard.server.common.data.plugin.ComponentType; |
|||
|
|||
public class ComponentTypeCodec extends EnumNameCodec<ComponentType> { |
|||
|
|||
public ComponentTypeCodec() { |
|||
super(ComponentType.class); |
|||
} |
|||
|
|||
} |
|||
@ -1,27 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.model.type; |
|||
|
|||
import com.datastax.driver.extras.codecs.enums.EnumNameCodec; |
|||
import org.thingsboard.server.common.data.security.DeviceCredentialsType; |
|||
|
|||
public class DeviceCredentialsTypeCodec extends EnumNameCodec<DeviceCredentialsType> { |
|||
|
|||
public DeviceCredentialsTypeCodec() { |
|||
super(DeviceCredentialsType.class); |
|||
} |
|||
|
|||
} |
|||
@ -1,27 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.model.type; |
|||
|
|||
import com.datastax.driver.extras.codecs.enums.EnumNameCodec; |
|||
import org.thingsboard.server.common.data.relation.RelationTypeGroup; |
|||
|
|||
public class RelationTypeGroupCodec extends EnumNameCodec<RelationTypeGroup> { |
|||
|
|||
public RelationTypeGroupCodec() { |
|||
super(RelationTypeGroup.class); |
|||
} |
|||
|
|||
} |
|||
@ -1,381 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.relation; |
|||
|
|||
import com.datastax.driver.core.BoundStatement; |
|||
import com.datastax.driver.core.PreparedStatement; |
|||
import com.datastax.driver.core.ResultSet; |
|||
import com.datastax.driver.core.ResultSetFuture; |
|||
import com.datastax.driver.core.Row; |
|||
import com.datastax.driver.core.querybuilder.QueryBuilder; |
|||
import com.datastax.driver.core.querybuilder.Select; |
|||
import com.fasterxml.jackson.databind.JsonNode; |
|||
import com.google.common.util.concurrent.ListenableFuture; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.common.data.EntityType; |
|||
import org.thingsboard.server.common.data.id.EntityId; |
|||
import org.thingsboard.server.common.data.id.EntityIdFactory; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.page.TimePageLink; |
|||
import org.thingsboard.server.common.data.relation.EntityRelation; |
|||
import org.thingsboard.server.common.data.relation.RelationTypeGroup; |
|||
import org.thingsboard.server.dao.model.ModelConstants; |
|||
import org.thingsboard.server.dao.model.type.RelationTypeGroupCodec; |
|||
import org.thingsboard.server.dao.nosql.CassandraAbstractAsyncDao; |
|||
import org.thingsboard.server.dao.nosql.CassandraAbstractSearchTimeDao; |
|||
import org.thingsboard.server.dao.util.NoSqlDao; |
|||
|
|||
import javax.annotation.PostConstruct; |
|||
import java.util.ArrayList; |
|||
import java.util.Arrays; |
|||
import java.util.List; |
|||
|
|||
import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; |
|||
|
|||
/** |
|||
* Created by ashvayka on 25.04.17. |
|||
*/ |
|||
@Component |
|||
@Slf4j |
|||
@NoSqlDao |
|||
public class BaseRelationDao extends CassandraAbstractAsyncDao implements RelationDao { |
|||
|
|||
private static final String SELECT_COLUMNS = "SELECT " + |
|||
ModelConstants.RELATION_FROM_ID_PROPERTY + "," + |
|||
ModelConstants.RELATION_FROM_TYPE_PROPERTY + "," + |
|||
ModelConstants.RELATION_TO_ID_PROPERTY + "," + |
|||
ModelConstants.RELATION_TO_TYPE_PROPERTY + "," + |
|||
ModelConstants.RELATION_TYPE_GROUP_PROPERTY + "," + |
|||
ModelConstants.RELATION_TYPE_PROPERTY + "," + |
|||
ModelConstants.ADDITIONAL_INFO_PROPERTY; |
|||
public static final String FROM = " FROM "; |
|||
public static final String WHERE = " WHERE "; |
|||
public static final String AND = " AND "; |
|||
|
|||
private static final RelationTypeGroupCodec relationTypeGroupCodec = new RelationTypeGroupCodec(); |
|||
public static final String EQUAL_TO_PARAM = " = ? "; |
|||
|
|||
private PreparedStatement saveStmt; |
|||
private PreparedStatement findAllByFromStmt; |
|||
private PreparedStatement findAllByFromAndTypeStmt; |
|||
private PreparedStatement findAllByToStmt; |
|||
private PreparedStatement findAllByToAndTypeStmt; |
|||
private PreparedStatement checkRelationStmt; |
|||
private PreparedStatement deleteStmt; |
|||
private PreparedStatement deleteAllByEntityStmt; |
|||
|
|||
@PostConstruct |
|||
public void init() { |
|||
super.startExecutor(); |
|||
} |
|||
|
|||
@Override |
|||
public ListenableFuture<List<EntityRelation>> findAllByFrom(TenantId tenantId, EntityId from, RelationTypeGroup typeGroup) { |
|||
BoundStatement stmt = getFindAllByFromStmt().bind() |
|||
.setUUID(0, from.getId()) |
|||
.setString(1, from.getEntityType().name()) |
|||
.set(2, typeGroup, relationTypeGroupCodec); |
|||
return executeAsyncRead(tenantId, from, stmt); |
|||
} |
|||
|
|||
@Override |
|||
public ListenableFuture<List<EntityRelation>> findAllByFromAndType(TenantId tenantId, EntityId from, String relationType, RelationTypeGroup typeGroup) { |
|||
BoundStatement stmt = getFindAllByFromAndTypeStmt().bind() |
|||
.setUUID(0, from.getId()) |
|||
.setString(1, from.getEntityType().name()) |
|||
.set(2, typeGroup, relationTypeGroupCodec) |
|||
.setString(3, relationType); |
|||
return executeAsyncRead(tenantId, from, stmt); |
|||
} |
|||
|
|||
@Override |
|||
public ListenableFuture<List<EntityRelation>> findAllByTo(TenantId tenantId, EntityId to, RelationTypeGroup typeGroup) { |
|||
BoundStatement stmt = getFindAllByToStmt().bind() |
|||
.setUUID(0, to.getId()) |
|||
.setString(1, to.getEntityType().name()) |
|||
.set(2, typeGroup, relationTypeGroupCodec); |
|||
return executeAsyncRead(tenantId, to, stmt); |
|||
} |
|||
|
|||
@Override |
|||
public ListenableFuture<List<EntityRelation>> findAllByToAndType(TenantId tenantId, EntityId to, String relationType, RelationTypeGroup typeGroup) { |
|||
BoundStatement stmt = getFindAllByToAndTypeStmt().bind() |
|||
.setUUID(0, to.getId()) |
|||
.setString(1, to.getEntityType().name()) |
|||
.set(2, typeGroup, relationTypeGroupCodec) |
|||
.setString(3, relationType); |
|||
return executeAsyncRead(tenantId, to, stmt); |
|||
} |
|||
|
|||
@Override |
|||
public ListenableFuture<Boolean> checkRelation(TenantId tenantId, EntityId from, EntityId to, String relationType, RelationTypeGroup typeGroup) { |
|||
BoundStatement stmt = getCheckRelationStmt().bind() |
|||
.setUUID(0, from.getId()) |
|||
.setString(1, from.getEntityType().name()) |
|||
.setUUID(2, to.getId()) |
|||
.setString(3, to.getEntityType().name()) |
|||
.set(4, typeGroup, relationTypeGroupCodec) |
|||
.setString(5, relationType); |
|||
return getFuture(executeAsyncRead(tenantId, stmt), rs -> rs != null ? rs.one() != null : false); |
|||
} |
|||
|
|||
@Override |
|||
public ListenableFuture<EntityRelation> getRelation(TenantId tenantId, EntityId from, EntityId to, String relationType, RelationTypeGroup typeGroup) { |
|||
BoundStatement stmt = getCheckRelationStmt().bind() |
|||
.setUUID(0, from.getId()) |
|||
.setString(1, from.getEntityType().name()) |
|||
.setUUID(2, to.getId()) |
|||
.setString(3, to.getEntityType().name()) |
|||
.set(4, typeGroup, relationTypeGroupCodec) |
|||
.setString(5, relationType); |
|||
return getFuture(executeAsyncRead(tenantId, stmt), rs -> rs != null ? getEntityRelation(rs.one()) : null); |
|||
} |
|||
|
|||
@Override |
|||
public boolean saveRelation(TenantId tenantId, EntityRelation relation) { |
|||
BoundStatement stmt = getSaveRelationStatement(tenantId, relation); |
|||
ResultSet rs = executeWrite(tenantId, stmt); |
|||
return rs.wasApplied(); |
|||
} |
|||
|
|||
@Override |
|||
public ListenableFuture<Boolean> saveRelationAsync(TenantId tenantId, EntityRelation relation) { |
|||
BoundStatement stmt = getSaveRelationStatement(tenantId, relation); |
|||
ResultSetFuture future = executeAsyncWrite(tenantId, stmt); |
|||
return getBooleanListenableFuture(future); |
|||
} |
|||
|
|||
private BoundStatement getSaveRelationStatement(TenantId tenantId, EntityRelation relation) { |
|||
BoundStatement stmt = getSaveStmt().bind() |
|||
.setUUID(0, relation.getFrom().getId()) |
|||
.setString(1, relation.getFrom().getEntityType().name()) |
|||
.setUUID(2, relation.getTo().getId()) |
|||
.setString(3, relation.getTo().getEntityType().name()) |
|||
.set(4, relation.getTypeGroup(), relationTypeGroupCodec) |
|||
.setString(5, relation.getType()) |
|||
.set(6, relation.getAdditionalInfo(), JsonNode.class); |
|||
return stmt; |
|||
} |
|||
|
|||
@Override |
|||
public boolean deleteRelation(TenantId tenantId, EntityRelation relation) { |
|||
return deleteRelation(tenantId, relation.getFrom(), relation.getTo(), relation.getType(), relation.getTypeGroup()); |
|||
} |
|||
|
|||
@Override |
|||
public ListenableFuture<Boolean> deleteRelationAsync(TenantId tenantId, EntityRelation relation) { |
|||
return deleteRelationAsync(tenantId, relation.getFrom(), relation.getTo(), relation.getType(), relation.getTypeGroup()); |
|||
} |
|||
|
|||
@Override |
|||
public boolean deleteRelation(TenantId tenantId, EntityId from, EntityId to, String relationType, RelationTypeGroup typeGroup) { |
|||
BoundStatement stmt = getDeleteRelationStatement(tenantId, from, to, relationType, typeGroup); |
|||
ResultSet rs = executeWrite(tenantId, stmt); |
|||
return rs.wasApplied(); |
|||
} |
|||
|
|||
@Override |
|||
public ListenableFuture<Boolean> deleteRelationAsync(TenantId tenantId, EntityId from, EntityId to, String relationType, RelationTypeGroup typeGroup) { |
|||
BoundStatement stmt = getDeleteRelationStatement(tenantId, from, to, relationType, typeGroup); |
|||
ResultSetFuture future = executeAsyncWrite(tenantId, stmt); |
|||
return getBooleanListenableFuture(future); |
|||
} |
|||
|
|||
private BoundStatement getDeleteRelationStatement(TenantId tenantId, EntityId from, EntityId to, String relationType, RelationTypeGroup typeGroup) { |
|||
BoundStatement stmt = getDeleteStmt().bind() |
|||
.setUUID(0, from.getId()) |
|||
.setString(1, from.getEntityType().name()) |
|||
.setUUID(2, to.getId()) |
|||
.setString(3, to.getEntityType().name()) |
|||
.set(4, typeGroup, relationTypeGroupCodec) |
|||
.setString(5, relationType); |
|||
return stmt; |
|||
} |
|||
|
|||
@Override |
|||
public boolean deleteOutboundRelations(TenantId tenantId, EntityId entity) { |
|||
BoundStatement stmt = getDeleteAllByEntityStmt().bind() |
|||
.setUUID(0, entity.getId()) |
|||
.setString(1, entity.getEntityType().name()); |
|||
ResultSet rs = executeWrite(tenantId, stmt); |
|||
return rs.wasApplied(); |
|||
} |
|||
|
|||
|
|||
@Override |
|||
public ListenableFuture<Boolean> deleteOutboundRelationsAsync(TenantId tenantId, EntityId entity) { |
|||
BoundStatement stmt = getDeleteAllByEntityStmt().bind() |
|||
.setUUID(0, entity.getId()) |
|||
.setString(1, entity.getEntityType().name()); |
|||
ResultSetFuture future = executeAsyncWrite(tenantId, stmt); |
|||
return getBooleanListenableFuture(future); |
|||
} |
|||
|
|||
@Override |
|||
public ListenableFuture<List<EntityRelation>> findRelations(TenantId tenantId, EntityId from, String relationType, RelationTypeGroup typeGroup, EntityType childType, TimePageLink pageLink) { |
|||
Select.Where query = CassandraAbstractSearchTimeDao.buildQuery(ModelConstants.RELATION_BY_TYPE_AND_CHILD_TYPE_VIEW_NAME, |
|||
Arrays.asList(eq(ModelConstants.RELATION_FROM_ID_PROPERTY, from.getId()), |
|||
eq(ModelConstants.RELATION_FROM_TYPE_PROPERTY, from.getEntityType().name()), |
|||
eq(ModelConstants.RELATION_TYPE_GROUP_PROPERTY, typeGroup.name()), |
|||
eq(ModelConstants.RELATION_TYPE_PROPERTY, relationType), |
|||
eq(ModelConstants.RELATION_TO_TYPE_PROPERTY, childType.name())), |
|||
Arrays.asList( |
|||
pageLink.isAscOrder() ? QueryBuilder.desc(ModelConstants.RELATION_TYPE_GROUP_PROPERTY) : |
|||
QueryBuilder.asc(ModelConstants.RELATION_TYPE_GROUP_PROPERTY), |
|||
pageLink.isAscOrder() ? QueryBuilder.desc(ModelConstants.RELATION_TYPE_PROPERTY) : |
|||
QueryBuilder.asc(ModelConstants.RELATION_TYPE_PROPERTY), |
|||
pageLink.isAscOrder() ? QueryBuilder.desc(ModelConstants.RELATION_TO_TYPE_PROPERTY) : |
|||
QueryBuilder.asc(ModelConstants.RELATION_TO_TYPE_PROPERTY) |
|||
), |
|||
pageLink, ModelConstants.RELATION_TO_ID_PROPERTY); |
|||
return getFuture(executeAsyncRead(tenantId, query), this::getEntityRelations); |
|||
} |
|||
|
|||
private PreparedStatement getSaveStmt() { |
|||
if (saveStmt == null) { |
|||
saveStmt = prepare("INSERT INTO " + ModelConstants.RELATION_COLUMN_FAMILY_NAME + " " + |
|||
"(" + ModelConstants.RELATION_FROM_ID_PROPERTY + |
|||
"," + ModelConstants.RELATION_FROM_TYPE_PROPERTY + |
|||
"," + ModelConstants.RELATION_TO_ID_PROPERTY + |
|||
"," + ModelConstants.RELATION_TO_TYPE_PROPERTY + |
|||
"," + ModelConstants.RELATION_TYPE_GROUP_PROPERTY + |
|||
"," + ModelConstants.RELATION_TYPE_PROPERTY + |
|||
"," + ModelConstants.ADDITIONAL_INFO_PROPERTY + ")" + |
|||
" VALUES(?, ?, ?, ?, ?, ?, ?)"); |
|||
} |
|||
return saveStmt; |
|||
} |
|||
|
|||
private PreparedStatement getDeleteStmt() { |
|||
if (deleteStmt == null) { |
|||
deleteStmt = prepare("DELETE FROM " + ModelConstants.RELATION_COLUMN_FAMILY_NAME + |
|||
WHERE + ModelConstants.RELATION_FROM_ID_PROPERTY + " = ?" + |
|||
AND + ModelConstants.RELATION_FROM_TYPE_PROPERTY + " = ?" + |
|||
AND + ModelConstants.RELATION_TO_ID_PROPERTY + " = ?" + |
|||
AND + ModelConstants.RELATION_TO_TYPE_PROPERTY + " = ?" + |
|||
AND + ModelConstants.RELATION_TYPE_GROUP_PROPERTY + " = ?" + |
|||
AND + ModelConstants.RELATION_TYPE_PROPERTY + " = ?"); |
|||
} |
|||
return deleteStmt; |
|||
} |
|||
|
|||
private PreparedStatement getDeleteAllByEntityStmt() { |
|||
if (deleteAllByEntityStmt == null) { |
|||
deleteAllByEntityStmt = prepare("DELETE FROM " + ModelConstants.RELATION_COLUMN_FAMILY_NAME + |
|||
WHERE + ModelConstants.RELATION_FROM_ID_PROPERTY + " = ?" + |
|||
AND + ModelConstants.RELATION_FROM_TYPE_PROPERTY + " = ?"); |
|||
} |
|||
return deleteAllByEntityStmt; |
|||
} |
|||
|
|||
private PreparedStatement getFindAllByFromStmt() { |
|||
if (findAllByFromStmt == null) { |
|||
findAllByFromStmt = prepare(SELECT_COLUMNS + " " + |
|||
FROM + ModelConstants.RELATION_COLUMN_FAMILY_NAME + " " + |
|||
WHERE + ModelConstants.RELATION_FROM_ID_PROPERTY + EQUAL_TO_PARAM + |
|||
AND + ModelConstants.RELATION_FROM_TYPE_PROPERTY + EQUAL_TO_PARAM + |
|||
AND + ModelConstants.RELATION_TYPE_GROUP_PROPERTY + EQUAL_TO_PARAM); |
|||
} |
|||
return findAllByFromStmt; |
|||
} |
|||
|
|||
private PreparedStatement getFindAllByFromAndTypeStmt() { |
|||
if (findAllByFromAndTypeStmt == null) { |
|||
findAllByFromAndTypeStmt = prepare(SELECT_COLUMNS + " " + |
|||
FROM + ModelConstants.RELATION_COLUMN_FAMILY_NAME + " " + |
|||
WHERE + ModelConstants.RELATION_FROM_ID_PROPERTY + EQUAL_TO_PARAM + |
|||
AND + ModelConstants.RELATION_FROM_TYPE_PROPERTY + EQUAL_TO_PARAM + |
|||
AND + ModelConstants.RELATION_TYPE_GROUP_PROPERTY + EQUAL_TO_PARAM + |
|||
AND + ModelConstants.RELATION_TYPE_PROPERTY + EQUAL_TO_PARAM); |
|||
} |
|||
return findAllByFromAndTypeStmt; |
|||
} |
|||
|
|||
|
|||
private PreparedStatement getFindAllByToStmt() { |
|||
if (findAllByToStmt == null) { |
|||
findAllByToStmt = prepare(SELECT_COLUMNS + " " + |
|||
FROM + ModelConstants.RELATION_REVERSE_VIEW_NAME + " " + |
|||
WHERE + ModelConstants.RELATION_TO_ID_PROPERTY + EQUAL_TO_PARAM + |
|||
AND + ModelConstants.RELATION_TO_TYPE_PROPERTY + EQUAL_TO_PARAM + |
|||
AND + ModelConstants.RELATION_TYPE_GROUP_PROPERTY + EQUAL_TO_PARAM); |
|||
} |
|||
return findAllByToStmt; |
|||
} |
|||
|
|||
private PreparedStatement getFindAllByToAndTypeStmt() { |
|||
if (findAllByToAndTypeStmt == null) { |
|||
findAllByToAndTypeStmt = prepare(SELECT_COLUMNS + " " + |
|||
FROM + ModelConstants.RELATION_REVERSE_VIEW_NAME + " " + |
|||
WHERE + ModelConstants.RELATION_TO_ID_PROPERTY + EQUAL_TO_PARAM + |
|||
AND + ModelConstants.RELATION_TO_TYPE_PROPERTY + EQUAL_TO_PARAM + |
|||
AND + ModelConstants.RELATION_TYPE_GROUP_PROPERTY + EQUAL_TO_PARAM + |
|||
AND + ModelConstants.RELATION_TYPE_PROPERTY + EQUAL_TO_PARAM); |
|||
} |
|||
return findAllByToAndTypeStmt; |
|||
} |
|||
|
|||
|
|||
private PreparedStatement getCheckRelationStmt() { |
|||
if (checkRelationStmt == null) { |
|||
checkRelationStmt = prepare(SELECT_COLUMNS + " " + |
|||
FROM + ModelConstants.RELATION_COLUMN_FAMILY_NAME + " " + |
|||
WHERE + ModelConstants.RELATION_FROM_ID_PROPERTY + EQUAL_TO_PARAM + |
|||
AND + ModelConstants.RELATION_FROM_TYPE_PROPERTY + EQUAL_TO_PARAM + |
|||
AND + ModelConstants.RELATION_TO_ID_PROPERTY + EQUAL_TO_PARAM + |
|||
AND + ModelConstants.RELATION_TO_TYPE_PROPERTY + EQUAL_TO_PARAM + |
|||
AND + ModelConstants.RELATION_TYPE_GROUP_PROPERTY + EQUAL_TO_PARAM + |
|||
AND + ModelConstants.RELATION_TYPE_PROPERTY + EQUAL_TO_PARAM); |
|||
} |
|||
return checkRelationStmt; |
|||
} |
|||
|
|||
private EntityId toEntity(Row row, String uuidColumn, String typeColumn) { |
|||
return EntityIdFactory.getByTypeAndUuid(row.getString(typeColumn), row.getUUID(uuidColumn)); |
|||
} |
|||
|
|||
private ListenableFuture<List<EntityRelation>> executeAsyncRead(TenantId tenantId, EntityId from, BoundStatement stmt) { |
|||
log.debug("Generated query [{}] for entity {}", stmt, from); |
|||
return getFuture(executeAsyncRead(tenantId, stmt), rs -> getEntityRelations(rs)); |
|||
} |
|||
|
|||
private ListenableFuture<Boolean> getBooleanListenableFuture(ResultSetFuture rsFuture) { |
|||
return getFuture(rsFuture, rs -> rs != null ? rs.wasApplied() : false); |
|||
} |
|||
|
|||
private List<EntityRelation> getEntityRelations(ResultSet rs) { |
|||
List<Row> rows = rs.all(); |
|||
List<EntityRelation> entries = new ArrayList<>(rows.size()); |
|||
if (!rows.isEmpty()) { |
|||
rows.forEach(row -> { |
|||
entries.add(getEntityRelation(row)); |
|||
}); |
|||
} |
|||
return entries; |
|||
} |
|||
|
|||
private EntityRelation getEntityRelation(Row row) { |
|||
EntityRelation relation = new EntityRelation(); |
|||
relation.setTypeGroup(row.get(ModelConstants.RELATION_TYPE_GROUP_PROPERTY, relationTypeGroupCodec)); |
|||
relation.setType(row.getString(ModelConstants.RELATION_TYPE_PROPERTY)); |
|||
relation.setAdditionalInfo(row.get(ModelConstants.ADDITIONAL_INFO_PROPERTY, JsonNode.class)); |
|||
relation.setFrom(toEntity(row, ModelConstants.RELATION_FROM_ID_PROPERTY, ModelConstants.RELATION_FROM_TYPE_PROPERTY)); |
|||
relation.setTo(toEntity(row, ModelConstants.RELATION_TO_ID_PROPERTY, ModelConstants.RELATION_TO_TYPE_PROPERTY)); |
|||
return relation; |
|||
} |
|||
|
|||
} |
|||
@ -1,63 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.rule; |
|||
|
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.page.TextPageLink; |
|||
import org.thingsboard.server.common.data.rule.RuleChain; |
|||
import org.thingsboard.server.dao.DaoUtil; |
|||
import org.thingsboard.server.dao.model.nosql.RuleChainEntity; |
|||
import org.thingsboard.server.dao.nosql.CassandraAbstractSearchTextDao; |
|||
import org.thingsboard.server.dao.util.NoSqlDao; |
|||
|
|||
import java.util.Collections; |
|||
import java.util.List; |
|||
import java.util.UUID; |
|||
|
|||
import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.RULE_CHAIN_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.RULE_CHAIN_COLUMN_FAMILY_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.RULE_CHAIN_TENANT_ID_PROPERTY; |
|||
|
|||
@Component |
|||
@Slf4j |
|||
@NoSqlDao |
|||
public class CassandraRuleChainDao extends CassandraAbstractSearchTextDao<RuleChainEntity, RuleChain> implements RuleChainDao { |
|||
|
|||
@Override |
|||
protected Class<RuleChainEntity> getColumnFamilyClass() { |
|||
return RuleChainEntity.class; |
|||
} |
|||
|
|||
@Override |
|||
protected String getColumnFamilyName() { |
|||
return RULE_CHAIN_COLUMN_FAMILY_NAME; |
|||
} |
|||
|
|||
@Override |
|||
public List<RuleChain> findRuleChainsByTenantId(UUID tenantId, TextPageLink pageLink) { |
|||
log.debug("Try to find rule chains by tenantId [{}] and pageLink [{}]", tenantId, pageLink); |
|||
List<RuleChainEntity> ruleChainEntities = findPageWithTextSearch(new TenantId(tenantId), RULE_CHAIN_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, |
|||
Collections.singletonList(eq(RULE_CHAIN_TENANT_ID_PROPERTY, tenantId)), |
|||
pageLink); |
|||
|
|||
log.trace("Found rule chains [{}] by tenantId [{}] and pageLink [{}]", ruleChainEntities, tenantId, pageLink); |
|||
return DaoUtil.convertDataList(ruleChainEntities); |
|||
} |
|||
|
|||
} |
|||
@ -1,42 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.rule; |
|||
|
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.common.data.rule.RuleNode; |
|||
import org.thingsboard.server.dao.model.nosql.RuleNodeEntity; |
|||
import org.thingsboard.server.dao.nosql.CassandraAbstractSearchTextDao; |
|||
import org.thingsboard.server.dao.util.NoSqlDao; |
|||
|
|||
import static org.thingsboard.server.dao.model.ModelConstants.RULE_NODE_COLUMN_FAMILY_NAME; |
|||
|
|||
@Component |
|||
@Slf4j |
|||
@NoSqlDao |
|||
public class CassandraRuleNodeDao extends CassandraAbstractSearchTextDao<RuleNodeEntity, RuleNode> implements RuleNodeDao { |
|||
|
|||
@Override |
|||
protected Class<RuleNodeEntity> getColumnFamilyClass() { |
|||
return RuleNodeEntity.class; |
|||
} |
|||
|
|||
@Override |
|||
protected String getColumnFamilyName() { |
|||
return RULE_NODE_COLUMN_FAMILY_NAME; |
|||
} |
|||
|
|||
} |
|||
@ -1,59 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.settings; |
|||
|
|||
import com.datastax.driver.core.querybuilder.Select.Where; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.common.data.AdminSettings; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.dao.DaoUtil; |
|||
import org.thingsboard.server.dao.model.nosql.AdminSettingsEntity; |
|||
import org.thingsboard.server.dao.nosql.CassandraAbstractModelDao; |
|||
import org.thingsboard.server.dao.util.NoSqlDao; |
|||
|
|||
import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; |
|||
import static com.datastax.driver.core.querybuilder.QueryBuilder.select; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ADMIN_SETTINGS_BY_KEY_COLUMN_FAMILY_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ADMIN_SETTINGS_COLUMN_FAMILY_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.ADMIN_SETTINGS_KEY_PROPERTY; |
|||
|
|||
@Component |
|||
@Slf4j |
|||
@NoSqlDao |
|||
public class CassandraAdminSettingsDao extends CassandraAbstractModelDao<AdminSettingsEntity, AdminSettings> implements AdminSettingsDao { |
|||
|
|||
@Override |
|||
protected Class<AdminSettingsEntity> getColumnFamilyClass() { |
|||
return AdminSettingsEntity.class; |
|||
} |
|||
|
|||
@Override |
|||
protected String getColumnFamilyName() { |
|||
return ADMIN_SETTINGS_COLUMN_FAMILY_NAME; |
|||
} |
|||
|
|||
@Override |
|||
public AdminSettings findByKey(TenantId tenantId, String key) { |
|||
log.debug("Try to find admin settings by key [{}] ", key); |
|||
Where query = select().from(ADMIN_SETTINGS_BY_KEY_COLUMN_FAMILY_NAME).where(eq(ADMIN_SETTINGS_KEY_PROPERTY, key)); |
|||
log.trace("Execute query {}", query); |
|||
AdminSettingsEntity adminSettingsEntity = findOneByStatement(tenantId, query); |
|||
log.trace("Found admin settings [{}] by key [{}]", adminSettingsEntity, key); |
|||
return DaoUtil.getData(adminSettingsEntity); |
|||
} |
|||
|
|||
} |
|||
@ -1,61 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.tenant; |
|||
|
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.common.data.Tenant; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.page.TextPageLink; |
|||
import org.thingsboard.server.dao.DaoUtil; |
|||
import org.thingsboard.server.dao.model.nosql.TenantEntity; |
|||
import org.thingsboard.server.dao.nosql.CassandraAbstractSearchTextDao; |
|||
import org.thingsboard.server.dao.util.NoSqlDao; |
|||
|
|||
import java.util.Arrays; |
|||
import java.util.List; |
|||
|
|||
import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.TENANT_BY_REGION_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.TENANT_COLUMN_FAMILY_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.TENANT_REGION_PROPERTY; |
|||
|
|||
@Component |
|||
@Slf4j |
|||
@NoSqlDao |
|||
public class CassandraTenantDao extends CassandraAbstractSearchTextDao<TenantEntity, Tenant> implements TenantDao { |
|||
|
|||
@Override |
|||
protected Class<TenantEntity> getColumnFamilyClass() { |
|||
return TenantEntity.class; |
|||
} |
|||
|
|||
@Override |
|||
protected String getColumnFamilyName() { |
|||
return TENANT_COLUMN_FAMILY_NAME; |
|||
} |
|||
|
|||
@Override |
|||
public List<Tenant> findTenantsByRegion(TenantId tenantId, String region, TextPageLink pageLink) { |
|||
log.debug("Try to find tenants by region [{}] and pageLink [{}]", region, pageLink); |
|||
List<TenantEntity> tenantEntities = findPageWithTextSearch(tenantId, TENANT_BY_REGION_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, |
|||
Arrays.asList(eq(TENANT_REGION_PROPERTY, region)), |
|||
pageLink); |
|||
log.trace("Found tenants [{}] by region [{}] and pageLink [{}]", tenantEntities, region, pageLink); |
|||
return DaoUtil.convertDataList(tenantEntities); |
|||
} |
|||
|
|||
} |
|||
@ -1,83 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.user; |
|||
|
|||
import com.datastax.driver.core.querybuilder.Select.Where; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.security.UserCredentials; |
|||
import org.thingsboard.server.dao.DaoUtil; |
|||
import org.thingsboard.server.dao.model.ModelConstants; |
|||
import org.thingsboard.server.dao.model.nosql.UserCredentialsEntity; |
|||
import org.thingsboard.server.dao.nosql.CassandraAbstractModelDao; |
|||
import org.thingsboard.server.dao.util.NoSqlDao; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; |
|||
import static com.datastax.driver.core.querybuilder.QueryBuilder.select; |
|||
|
|||
@Component |
|||
@Slf4j |
|||
@NoSqlDao |
|||
public class CassandraUserCredentialsDao extends CassandraAbstractModelDao<UserCredentialsEntity, UserCredentials> implements UserCredentialsDao { |
|||
|
|||
public static final String EXECUTE_QUERY = "Execute query {}"; |
|||
|
|||
@Override |
|||
protected Class<UserCredentialsEntity> getColumnFamilyClass() { |
|||
return UserCredentialsEntity.class; |
|||
} |
|||
|
|||
@Override |
|||
protected String getColumnFamilyName() { |
|||
return ModelConstants.USER_CREDENTIALS_COLUMN_FAMILY_NAME; |
|||
} |
|||
|
|||
@Override |
|||
public UserCredentials findByUserId(TenantId tenantId, UUID userId) { |
|||
log.debug("Try to find user credentials by userId [{}] ", userId); |
|||
Where query = select().from(ModelConstants.USER_CREDENTIALS_BY_USER_COLUMN_FAMILY_NAME).where(eq(ModelConstants.USER_CREDENTIALS_USER_ID_PROPERTY, userId)); |
|||
log.trace(EXECUTE_QUERY, query); |
|||
UserCredentialsEntity userCredentialsEntity = findOneByStatement(tenantId, query); |
|||
log.trace("Found user credentials [{}] by userId [{}]", userCredentialsEntity, userId); |
|||
return DaoUtil.getData(userCredentialsEntity); |
|||
} |
|||
|
|||
@Override |
|||
public UserCredentials findByActivateToken(TenantId tenantId, String activateToken) { |
|||
log.debug("Try to find user credentials by activateToken [{}] ", activateToken); |
|||
Where query = select().from(ModelConstants.USER_CREDENTIALS_BY_ACTIVATE_TOKEN_COLUMN_FAMILY_NAME) |
|||
.where(eq(ModelConstants.USER_CREDENTIALS_ACTIVATE_TOKEN_PROPERTY, activateToken)); |
|||
log.trace(EXECUTE_QUERY, query); |
|||
UserCredentialsEntity userCredentialsEntity = findOneByStatement(tenantId, query); |
|||
log.trace("Found user credentials [{}] by activateToken [{}]", userCredentialsEntity, activateToken); |
|||
return DaoUtil.getData(userCredentialsEntity); |
|||
} |
|||
|
|||
@Override |
|||
public UserCredentials findByResetToken(TenantId tenantId, String resetToken) { |
|||
log.debug("Try to find user credentials by resetToken [{}] ", resetToken); |
|||
Where query = select().from(ModelConstants.USER_CREDENTIALS_BY_RESET_TOKEN_COLUMN_FAMILY_NAME) |
|||
.where(eq(ModelConstants.USER_CREDENTIALS_RESET_TOKEN_PROPERTY, resetToken)); |
|||
log.trace(EXECUTE_QUERY, query); |
|||
UserCredentialsEntity userCredentialsEntity = findOneByStatement(tenantId, query); |
|||
log.trace("Found user credentials [{}] by resetToken [{}]", userCredentialsEntity, resetToken); |
|||
return DaoUtil.getData(userCredentialsEntity); |
|||
} |
|||
|
|||
} |
|||
@ -1,89 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.user; |
|||
|
|||
import com.datastax.driver.core.querybuilder.Select.Where; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.common.data.User; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.page.TextPageLink; |
|||
import org.thingsboard.server.common.data.security.Authority; |
|||
import org.thingsboard.server.dao.DaoUtil; |
|||
import org.thingsboard.server.dao.model.ModelConstants; |
|||
import org.thingsboard.server.dao.model.nosql.UserEntity; |
|||
import org.thingsboard.server.dao.nosql.CassandraAbstractSearchTextDao; |
|||
import org.thingsboard.server.dao.util.NoSqlDao; |
|||
|
|||
import java.util.Arrays; |
|||
import java.util.List; |
|||
import java.util.UUID; |
|||
|
|||
import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; |
|||
import static com.datastax.driver.core.querybuilder.QueryBuilder.select; |
|||
|
|||
@Component |
|||
@Slf4j |
|||
@NoSqlDao |
|||
public class CassandraUserDao extends CassandraAbstractSearchTextDao<UserEntity, User> implements UserDao { |
|||
|
|||
@Override |
|||
protected Class<UserEntity> getColumnFamilyClass() { |
|||
return UserEntity.class; |
|||
} |
|||
|
|||
@Override |
|||
protected String getColumnFamilyName() { |
|||
return ModelConstants.USER_COLUMN_FAMILY_NAME; |
|||
} |
|||
|
|||
@Override |
|||
public User findByEmail(TenantId tenantId, String email) { |
|||
log.debug("Try to find user by email [{}] ", email); |
|||
Where query = select().from(ModelConstants.USER_BY_EMAIL_COLUMN_FAMILY_NAME).where(eq(ModelConstants.USER_EMAIL_PROPERTY, email)); |
|||
log.trace("Execute query {}", query); |
|||
UserEntity userEntity = findOneByStatement(tenantId, query); |
|||
log.trace("Found user [{}] by email [{}]", userEntity, email); |
|||
return DaoUtil.getData(userEntity); |
|||
} |
|||
|
|||
@Override |
|||
public List<User> findTenantAdmins(UUID tenantId, TextPageLink pageLink) { |
|||
log.debug("Try to find tenant admin users by tenantId [{}] and pageLink [{}]", tenantId, pageLink); |
|||
List<UserEntity> userEntities = findPageWithTextSearch(new TenantId(tenantId), |
|||
ModelConstants.USER_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, |
|||
Arrays.asList(eq(ModelConstants.USER_TENANT_ID_PROPERTY, tenantId), |
|||
eq(ModelConstants.USER_CUSTOMER_ID_PROPERTY, ModelConstants.NULL_UUID), |
|||
eq(ModelConstants.USER_AUTHORITY_PROPERTY, Authority.TENANT_ADMIN.name())), |
|||
pageLink); |
|||
log.trace("Found tenant admin users [{}] by tenantId [{}] and pageLink [{}]", userEntities, tenantId, pageLink); |
|||
return DaoUtil.convertDataList(userEntities); |
|||
} |
|||
|
|||
@Override |
|||
public List<User> findCustomerUsers(UUID tenantId, UUID customerId, TextPageLink pageLink) { |
|||
log.debug("Try to find customer users by tenantId [{}], customerId [{}] and pageLink [{}]", tenantId, customerId, pageLink); |
|||
List<UserEntity> userEntities = findPageWithTextSearch(new TenantId(tenantId), |
|||
ModelConstants.USER_BY_CUSTOMER_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, |
|||
Arrays.asList(eq(ModelConstants.USER_TENANT_ID_PROPERTY, tenantId), |
|||
eq(ModelConstants.USER_CUSTOMER_ID_PROPERTY, customerId), |
|||
eq(ModelConstants.USER_AUTHORITY_PROPERTY, Authority.CUSTOMER_USER.name())), |
|||
pageLink); |
|||
log.trace("Found customer users [{}] by tenantId [{}], customerId [{}] and pageLink [{}]", userEntities, tenantId, customerId, pageLink); |
|||
return DaoUtil.convertDataList(userEntities); |
|||
} |
|||
|
|||
} |
|||
@ -1,81 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.widget; |
|||
|
|||
import com.datastax.driver.core.querybuilder.Select.Where; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.widget.WidgetType; |
|||
import org.thingsboard.server.dao.DaoUtil; |
|||
import org.thingsboard.server.dao.model.nosql.WidgetTypeEntity; |
|||
import org.thingsboard.server.dao.nosql.CassandraAbstractModelDao; |
|||
import org.thingsboard.server.dao.util.NoSqlDao; |
|||
|
|||
import java.util.List; |
|||
import java.util.UUID; |
|||
|
|||
import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; |
|||
import static com.datastax.driver.core.querybuilder.QueryBuilder.select; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.WIDGET_TYPE_ALIAS_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.WIDGET_TYPE_BUNDLE_ALIAS_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.WIDGET_TYPE_BY_TENANT_AND_ALIASES_COLUMN_FAMILY_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.WIDGET_TYPE_COLUMN_FAMILY_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.WIDGET_TYPE_TENANT_ID_PROPERTY; |
|||
|
|||
@Component |
|||
@Slf4j |
|||
@NoSqlDao |
|||
public class CassandraWidgetTypeDao extends CassandraAbstractModelDao<WidgetTypeEntity, WidgetType> implements WidgetTypeDao { |
|||
|
|||
@Override |
|||
protected Class<WidgetTypeEntity> getColumnFamilyClass() { |
|||
return WidgetTypeEntity.class; |
|||
} |
|||
|
|||
@Override |
|||
protected String getColumnFamilyName() { |
|||
return WIDGET_TYPE_COLUMN_FAMILY_NAME; |
|||
} |
|||
|
|||
@Override |
|||
public List<WidgetType> findWidgetTypesByTenantIdAndBundleAlias(UUID tenantId, String bundleAlias) { |
|||
log.debug("Try to find widget types by tenantId [{}] and bundleAlias [{}]", tenantId, bundleAlias); |
|||
Where query = select().from(WIDGET_TYPE_BY_TENANT_AND_ALIASES_COLUMN_FAMILY_NAME) |
|||
.where() |
|||
.and(eq(WIDGET_TYPE_TENANT_ID_PROPERTY, tenantId)) |
|||
.and(eq(WIDGET_TYPE_BUNDLE_ALIAS_PROPERTY, bundleAlias)); |
|||
List<WidgetTypeEntity> widgetTypesEntities = findListByStatement(new TenantId(tenantId), query); |
|||
log.trace("Found widget types [{}] by tenantId [{}] and bundleAlias [{}]", widgetTypesEntities, tenantId, bundleAlias); |
|||
return DaoUtil.convertDataList(widgetTypesEntities); |
|||
} |
|||
|
|||
@Override |
|||
public WidgetType findByTenantIdBundleAliasAndAlias(UUID tenantId, String bundleAlias, String alias) { |
|||
log.debug("Try to find widget type by tenantId [{}], bundleAlias [{}] and alias [{}]", tenantId, bundleAlias, alias); |
|||
Where query = select().from(WIDGET_TYPE_BY_TENANT_AND_ALIASES_COLUMN_FAMILY_NAME) |
|||
.where() |
|||
.and(eq(WIDGET_TYPE_TENANT_ID_PROPERTY, tenantId)) |
|||
.and(eq(WIDGET_TYPE_BUNDLE_ALIAS_PROPERTY, bundleAlias)) |
|||
.and(eq(WIDGET_TYPE_ALIAS_PROPERTY, alias)); |
|||
log.trace("Execute query {}", query); |
|||
WidgetTypeEntity widgetTypeEntity = findOneByStatement(new TenantId(tenantId), query); |
|||
log.trace("Found widget type [{}] by tenantId [{}], bundleAlias [{}] and alias [{}]", |
|||
widgetTypeEntity, tenantId, bundleAlias, alias); |
|||
return DaoUtil.getData(widgetTypeEntity); |
|||
} |
|||
|
|||
} |
|||
@ -1,103 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.widget; |
|||
|
|||
import com.datastax.driver.core.querybuilder.Select; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.common.data.Tenant; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.page.TextPageLink; |
|||
import org.thingsboard.server.common.data.widget.WidgetsBundle; |
|||
import org.thingsboard.server.dao.DaoUtil; |
|||
import org.thingsboard.server.dao.model.nosql.WidgetsBundleEntity; |
|||
import org.thingsboard.server.dao.nosql.CassandraAbstractSearchTextDao; |
|||
import org.thingsboard.server.dao.util.NoSqlDao; |
|||
|
|||
import java.util.Arrays; |
|||
import java.util.List; |
|||
import java.util.UUID; |
|||
|
|||
import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; |
|||
import static com.datastax.driver.core.querybuilder.QueryBuilder.in; |
|||
import static com.datastax.driver.core.querybuilder.QueryBuilder.select; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.WIDGETS_BUNDLE_ALIAS_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.WIDGETS_BUNDLE_BY_TENANT_AND_ALIAS_COLUMN_FAMILY_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.WIDGETS_BUNDLE_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.WIDGETS_BUNDLE_COLUMN_FAMILY_NAME; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.WIDGETS_BUNDLE_TENANT_ID_PROPERTY; |
|||
|
|||
@Component |
|||
@Slf4j |
|||
@NoSqlDao |
|||
public class CassandraWidgetsBundleDao extends CassandraAbstractSearchTextDao<WidgetsBundleEntity, WidgetsBundle> implements WidgetsBundleDao { |
|||
|
|||
@Override |
|||
protected Class<WidgetsBundleEntity> getColumnFamilyClass() { |
|||
return WidgetsBundleEntity.class; |
|||
} |
|||
|
|||
@Override |
|||
protected String getColumnFamilyName() { |
|||
return WIDGETS_BUNDLE_COLUMN_FAMILY_NAME; |
|||
} |
|||
|
|||
@Override |
|||
public WidgetsBundle findWidgetsBundleByTenantIdAndAlias(UUID tenantId, String alias) { |
|||
log.debug("Try to find widgets bundle by tenantId [{}] and alias [{}]", tenantId, alias); |
|||
Select.Where query = select().from(WIDGETS_BUNDLE_BY_TENANT_AND_ALIAS_COLUMN_FAMILY_NAME) |
|||
.where() |
|||
.and(eq(WIDGETS_BUNDLE_TENANT_ID_PROPERTY, tenantId)) |
|||
.and(eq(WIDGETS_BUNDLE_ALIAS_PROPERTY, alias)); |
|||
log.trace("Execute query {}", query); |
|||
WidgetsBundleEntity widgetsBundleEntity = findOneByStatement(new TenantId(tenantId), query); |
|||
log.trace("Found widgets bundle [{}] by tenantId [{}] and alias [{}]", |
|||
widgetsBundleEntity, tenantId, alias); |
|||
return DaoUtil.getData(widgetsBundleEntity); |
|||
} |
|||
|
|||
@Override |
|||
public List<WidgetsBundle> findSystemWidgetsBundles(TenantId tenantId, TextPageLink pageLink) { |
|||
log.debug("Try to find system widgets bundles by pageLink [{}]", pageLink); |
|||
List<WidgetsBundleEntity> widgetsBundlesEntities = findPageWithTextSearch(tenantId, WIDGETS_BUNDLE_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, |
|||
Arrays.asList(eq(WIDGETS_BUNDLE_TENANT_ID_PROPERTY, NULL_UUID)), |
|||
pageLink); |
|||
log.trace("Found system widgets bundles [{}] by pageLink [{}]", widgetsBundlesEntities, pageLink); |
|||
return DaoUtil.convertDataList(widgetsBundlesEntities); |
|||
} |
|||
|
|||
@Override |
|||
public List<WidgetsBundle> findTenantWidgetsBundlesByTenantId(UUID tenantId, TextPageLink pageLink) { |
|||
log.debug("Try to find tenant widgets bundles by tenantId [{}] and pageLink [{}]", tenantId, pageLink); |
|||
List<WidgetsBundleEntity> widgetsBundlesEntities = findPageWithTextSearch(new TenantId(tenantId), WIDGETS_BUNDLE_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, |
|||
Arrays.asList(eq(WIDGETS_BUNDLE_TENANT_ID_PROPERTY, tenantId)), |
|||
pageLink); |
|||
log.trace("Found tenant widgets bundles [{}] by tenantId [{}] and pageLink [{}]", widgetsBundlesEntities, tenantId, pageLink); |
|||
return DaoUtil.convertDataList(widgetsBundlesEntities); |
|||
} |
|||
|
|||
@Override |
|||
public List<WidgetsBundle> findAllTenantWidgetsBundlesByTenantId(UUID tenantId, TextPageLink pageLink) { |
|||
log.debug("Try to find all tenant widgets bundles by tenantId [{}] and pageLink [{}]", tenantId, pageLink); |
|||
List<WidgetsBundleEntity> widgetsBundlesEntities = findPageWithTextSearch(new TenantId(tenantId), WIDGETS_BUNDLE_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, |
|||
Arrays.asList(in(WIDGETS_BUNDLE_TENANT_ID_PROPERTY, Arrays.asList(NULL_UUID, tenantId))), |
|||
pageLink); |
|||
log.trace("Found all tenant widgets bundles [{}] by tenantId [{}] and pageLink [{}]", widgetsBundlesEntities, tenantId, pageLink); |
|||
return DaoUtil.convertDataList(widgetsBundlesEntities); |
|||
} |
|||
|
|||
} |
|||
@ -1,714 +0,0 @@ |
|||
-- |
|||
-- Copyright © 2016-2019 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. |
|||
-- |
|||
|
|||
CREATE KEYSPACE IF NOT EXISTS thingsboard |
|||
WITH replication = { |
|||
'class' : 'SimpleStrategy', |
|||
'replication_factor' : 1 |
|||
}; |
|||
|
|||
CREATE TABLE IF NOT EXISTS thingsboard.user ( |
|||
id timeuuid, |
|||
tenant_id timeuuid, |
|||
customer_id timeuuid, |
|||
email text, |
|||
search_text text, |
|||
authority text, |
|||
first_name text, |
|||
last_name text, |
|||
additional_info text, |
|||
PRIMARY KEY (id, tenant_id, customer_id, authority) |
|||
); |
|||
|
|||
CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.user_by_email AS |
|||
SELECT * |
|||
from thingsboard.user |
|||
WHERE email IS NOT NULL AND tenant_id IS NOT NULL AND customer_id IS NOT NULL AND id IS NOT NULL AND authority IS NOT |
|||
NULL |
|||
PRIMARY KEY ( email, tenant_id, customer_id, id, authority ); |
|||
|
|||
CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.user_by_tenant_and_search_text AS |
|||
SELECT * |
|||
from thingsboard.user |
|||
WHERE tenant_id IS NOT NULL AND customer_id IS NOT NULL AND authority IS NOT NULL AND search_text IS NOT NULL AND id |
|||
IS NOT NULL |
|||
PRIMARY KEY ( tenant_id, customer_id, authority, search_text, id ) |
|||
WITH CLUSTERING ORDER BY ( customer_id DESC, authority DESC, search_text ASC, id DESC ); |
|||
|
|||
CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.user_by_customer_and_search_text AS |
|||
SELECT * |
|||
from thingsboard.user |
|||
WHERE tenant_id IS NOT NULL AND customer_id IS NOT NULL AND authority IS NOT NULL AND search_text IS NOT NULL AND id |
|||
IS NOT NULL |
|||
PRIMARY KEY ( customer_id, tenant_id, authority, search_text, id ) |
|||
WITH CLUSTERING ORDER BY ( tenant_id DESC, authority DESC, search_text ASC, id DESC ); |
|||
|
|||
CREATE TABLE IF NOT EXISTS thingsboard.user_credentials ( |
|||
id timeuuid PRIMARY KEY, |
|||
user_id timeuuid, |
|||
enabled boolean, |
|||
password text, |
|||
activate_token text, |
|||
reset_token text |
|||
); |
|||
|
|||
CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.user_credentials_by_user AS |
|||
SELECT * |
|||
from thingsboard.user_credentials |
|||
WHERE user_id IS NOT NULL AND id IS NOT NULL |
|||
PRIMARY KEY ( user_id, id ); |
|||
|
|||
CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.user_credentials_by_activate_token AS |
|||
SELECT * |
|||
from thingsboard.user_credentials |
|||
WHERE activate_token IS NOT NULL AND id IS NOT NULL |
|||
PRIMARY KEY ( activate_token, id ); |
|||
|
|||
CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.user_credentials_by_reset_token AS |
|||
SELECT * |
|||
from thingsboard.user_credentials |
|||
WHERE reset_token IS NOT NULL AND id IS NOT NULL |
|||
PRIMARY KEY ( reset_token, id ); |
|||
|
|||
CREATE TABLE IF NOT EXISTS thingsboard.admin_settings ( |
|||
id timeuuid PRIMARY KEY, |
|||
key text, |
|||
json_value text |
|||
); |
|||
|
|||
CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.admin_settings_by_key AS |
|||
SELECT * |
|||
from thingsboard.admin_settings |
|||
WHERE key IS NOT NULL AND id IS NOT NULL |
|||
PRIMARY KEY ( key, id ) |
|||
WITH CLUSTERING ORDER BY ( id DESC ); |
|||
|
|||
CREATE TABLE IF NOT EXISTS thingsboard.tenant ( |
|||
id timeuuid, |
|||
title text, |
|||
search_text text, |
|||
region text, |
|||
country text, |
|||
state text, |
|||
city text, |
|||
address text, |
|||
address2 text, |
|||
zip text, |
|||
phone text, |
|||
email text, |
|||
additional_info text, |
|||
PRIMARY KEY (id, region) |
|||
); |
|||
|
|||
CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.tenant_by_region_and_search_text AS |
|||
SELECT * |
|||
from thingsboard.tenant |
|||
WHERE region IS NOT NULL AND search_text IS NOT NULL AND id IS NOT NULL |
|||
PRIMARY KEY ( region, search_text, id ) |
|||
WITH CLUSTERING ORDER BY ( search_text ASC, id DESC ); |
|||
|
|||
CREATE TABLE IF NOT EXISTS thingsboard.customer ( |
|||
id timeuuid, |
|||
tenant_id timeuuid, |
|||
title text, |
|||
search_text text, |
|||
country text, |
|||
state text, |
|||
city text, |
|||
address text, |
|||
address2 text, |
|||
zip text, |
|||
phone text, |
|||
email text, |
|||
additional_info text, |
|||
PRIMARY KEY (id, tenant_id) |
|||
); |
|||
|
|||
CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.customer_by_tenant_and_title AS |
|||
SELECT * |
|||
from thingsboard.customer |
|||
WHERE tenant_id IS NOT NULL AND title IS NOT NULL AND id IS NOT NULL |
|||
PRIMARY KEY ( tenant_id, title, id ) |
|||
WITH CLUSTERING ORDER BY ( title ASC, id DESC ); |
|||
|
|||
CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.customer_by_tenant_and_search_text AS |
|||
SELECT * |
|||
from thingsboard.customer |
|||
WHERE tenant_id IS NOT NULL AND search_text IS NOT NULL AND id IS NOT NULL |
|||
PRIMARY KEY ( tenant_id, search_text, id ) |
|||
WITH CLUSTERING ORDER BY ( search_text ASC, id DESC ); |
|||
|
|||
CREATE TABLE IF NOT EXISTS thingsboard.device ( |
|||
id timeuuid, |
|||
tenant_id timeuuid, |
|||
customer_id timeuuid, |
|||
name text, |
|||
type text, |
|||
label text, |
|||
search_text text, |
|||
additional_info text, |
|||
PRIMARY KEY (id, tenant_id, customer_id, type) |
|||
); |
|||
|
|||
CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.device_by_tenant_and_name AS |
|||
SELECT * |
|||
from thingsboard.device |
|||
WHERE tenant_id IS NOT NULL |
|||
AND customer_id IS NOT NULL |
|||
AND type IS NOT NULL |
|||
AND name IS NOT NULL |
|||
AND id IS NOT NULL |
|||
PRIMARY KEY ( tenant_id, name, id, customer_id, type) |
|||
WITH CLUSTERING ORDER BY ( name ASC, id DESC, customer_id DESC); |
|||
|
|||
CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.device_by_tenant_and_search_text AS |
|||
SELECT * |
|||
from thingsboard.device |
|||
WHERE tenant_id IS NOT NULL |
|||
AND customer_id IS NOT NULL |
|||
AND type IS NOT NULL |
|||
AND search_text IS NOT NULL |
|||
AND id IS NOT NULL |
|||
PRIMARY KEY ( tenant_id, search_text, id, customer_id, type) |
|||
WITH CLUSTERING ORDER BY ( search_text ASC, id DESC, customer_id DESC); |
|||
|
|||
CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.device_by_tenant_by_type_and_search_text AS |
|||
SELECT * |
|||
from thingsboard.device |
|||
WHERE tenant_id IS NOT NULL |
|||
AND customer_id IS NOT NULL |
|||
AND type IS NOT NULL |
|||
AND search_text IS NOT NULL |
|||
AND id IS NOT NULL |
|||
PRIMARY KEY ( tenant_id, type, search_text, id, customer_id) |
|||
WITH CLUSTERING ORDER BY ( type ASC, search_text ASC, id DESC, customer_id DESC); |
|||
|
|||
CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.device_by_customer_and_search_text AS |
|||
SELECT * |
|||
from thingsboard.device |
|||
WHERE tenant_id IS NOT NULL |
|||
AND customer_id IS NOT NULL |
|||
AND type IS NOT NULL |
|||
AND search_text IS NOT NULL |
|||
AND id IS NOT NULL |
|||
PRIMARY KEY ( customer_id, tenant_id, search_text, id, type ) |
|||
WITH CLUSTERING ORDER BY ( tenant_id DESC, search_text ASC, id DESC ); |
|||
|
|||
CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.device_by_customer_by_type_and_search_text AS |
|||
SELECT * |
|||
from thingsboard.device |
|||
WHERE tenant_id IS NOT NULL |
|||
AND customer_id IS NOT NULL |
|||
AND type IS NOT NULL |
|||
AND search_text IS NOT NULL |
|||
AND id IS NOT NULL |
|||
PRIMARY KEY ( customer_id, tenant_id, type, search_text, id ) |
|||
WITH CLUSTERING ORDER BY ( tenant_id DESC, type ASC, search_text ASC, id DESC ); |
|||
|
|||
CREATE TABLE IF NOT EXISTS thingsboard.device_credentials ( |
|||
id timeuuid PRIMARY KEY, |
|||
device_id timeuuid, |
|||
credentials_type text, |
|||
credentials_id text, |
|||
credentials_value text |
|||
); |
|||
|
|||
CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.device_credentials_by_device AS |
|||
SELECT * |
|||
from thingsboard.device_credentials |
|||
WHERE device_id IS NOT NULL AND id IS NOT NULL |
|||
PRIMARY KEY ( device_id, id ); |
|||
|
|||
CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.device_credentials_by_credentials_id AS |
|||
SELECT * |
|||
from thingsboard.device_credentials |
|||
WHERE credentials_id IS NOT NULL AND id IS NOT NULL |
|||
PRIMARY KEY ( credentials_id, id ); |
|||
|
|||
CREATE TABLE IF NOT EXISTS thingsboard.asset ( |
|||
id timeuuid, |
|||
tenant_id timeuuid, |
|||
customer_id timeuuid, |
|||
name text, |
|||
type text, |
|||
search_text text, |
|||
additional_info text, |
|||
PRIMARY KEY (id, tenant_id, customer_id, type) |
|||
); |
|||
|
|||
CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.asset_by_tenant_and_name AS |
|||
SELECT * |
|||
from thingsboard.asset |
|||
WHERE tenant_id IS NOT NULL AND customer_id IS NOT NULL AND type IS NOT NULL AND name IS NOT NULL AND id IS NOT NULL |
|||
PRIMARY KEY ( tenant_id, name, id, customer_id, type) |
|||
WITH CLUSTERING ORDER BY ( name ASC, id DESC, customer_id DESC); |
|||
|
|||
CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.asset_by_tenant_and_search_text AS |
|||
SELECT * |
|||
from thingsboard.asset |
|||
WHERE tenant_id IS NOT NULL AND customer_id IS NOT NULL AND type IS NOT NULL AND search_text IS NOT NULL AND id IS NOT NULL |
|||
PRIMARY KEY ( tenant_id, search_text, id, customer_id, type) |
|||
WITH CLUSTERING ORDER BY ( search_text ASC, id DESC, customer_id DESC); |
|||
|
|||
CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.asset_by_tenant_by_type_and_search_text AS |
|||
SELECT * |
|||
from thingsboard.asset |
|||
WHERE tenant_id IS NOT NULL AND customer_id IS NOT NULL AND type IS NOT NULL AND search_text IS NOT NULL AND id IS NOT NULL |
|||
PRIMARY KEY ( tenant_id, type, search_text, id, customer_id) |
|||
WITH CLUSTERING ORDER BY ( type ASC, search_text ASC, id DESC, customer_id DESC); |
|||
|
|||
CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.asset_by_customer_and_search_text AS |
|||
SELECT * |
|||
from thingsboard.asset |
|||
WHERE tenant_id IS NOT NULL AND customer_id IS NOT NULL AND type IS NOT NULL AND search_text IS NOT NULL AND id IS NOT NULL |
|||
PRIMARY KEY ( customer_id, tenant_id, search_text, id, type ) |
|||
WITH CLUSTERING ORDER BY ( tenant_id DESC, search_text ASC, id DESC ); |
|||
|
|||
CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.asset_by_customer_by_type_and_search_text AS |
|||
SELECT * |
|||
from thingsboard.asset |
|||
WHERE tenant_id IS NOT NULL AND customer_id IS NOT NULL AND type IS NOT NULL AND search_text IS NOT NULL AND id IS NOT NULL |
|||
PRIMARY KEY ( customer_id, tenant_id, type, search_text, id ) |
|||
WITH CLUSTERING ORDER BY ( tenant_id DESC, type ASC, search_text ASC, id DESC ); |
|||
|
|||
CREATE TABLE IF NOT EXISTS thingsboard.entity_subtype ( |
|||
tenant_id timeuuid, |
|||
entity_type text, // (DEVICE, ASSET) |
|||
type text, |
|||
PRIMARY KEY (tenant_id, entity_type, type) |
|||
); |
|||
|
|||
CREATE TABLE IF NOT EXISTS thingsboard.alarm ( |
|||
id timeuuid, |
|||
tenant_id timeuuid, |
|||
type text, |
|||
originator_id timeuuid, |
|||
originator_type text, |
|||
severity text, |
|||
status text, |
|||
start_ts bigint, |
|||
end_ts bigint, |
|||
ack_ts bigint, |
|||
clear_ts bigint, |
|||
details text, |
|||
propagate boolean, |
|||
PRIMARY KEY ((tenant_id, originator_id, originator_type), type, id) |
|||
) WITH CLUSTERING ORDER BY ( type ASC, id DESC); |
|||
|
|||
CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.alarm_by_id AS |
|||
SELECT * |
|||
from thingsboard.alarm |
|||
WHERE tenant_id IS NOT NULL AND originator_id IS NOT NULL AND originator_type IS NOT NULL AND type IS NOT NULL |
|||
AND type IS NOT NULL AND id IS NOT NULL |
|||
PRIMARY KEY (id, tenant_id, originator_id, originator_type, type) |
|||
WITH CLUSTERING ORDER BY ( tenant_id ASC, originator_id ASC, originator_type ASC, type ASC); |
|||
|
|||
CREATE TABLE IF NOT EXISTS thingsboard.relation ( |
|||
from_id timeuuid, |
|||
from_type text, |
|||
to_id timeuuid, |
|||
to_type text, |
|||
relation_type_group text, |
|||
relation_type text, |
|||
additional_info text, |
|||
PRIMARY KEY ((from_id, from_type), relation_type_group, relation_type, to_id, to_type) |
|||
) WITH CLUSTERING ORDER BY ( relation_type_group ASC, relation_type ASC, to_id ASC, to_type ASC); |
|||
|
|||
CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.relation_by_type_and_child_type AS |
|||
SELECT * |
|||
from thingsboard.relation |
|||
WHERE from_id IS NOT NULL AND from_type IS NOT NULL AND relation_type_group IS NOT NULL AND relation_type IS NOT NULL AND to_id IS NOT NULL AND to_type IS NOT NULL |
|||
PRIMARY KEY ((from_id, from_type), relation_type_group, relation_type, to_type, to_id) |
|||
WITH CLUSTERING ORDER BY ( relation_type_group ASC, relation_type ASC, to_type ASC, to_id DESC); |
|||
|
|||
CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.reverse_relation AS |
|||
SELECT * |
|||
from thingsboard.relation |
|||
WHERE from_id IS NOT NULL AND from_type IS NOT NULL AND relation_type_group IS NOT NULL AND relation_type IS NOT NULL AND to_id IS NOT NULL AND to_type IS NOT NULL |
|||
PRIMARY KEY ((to_id, to_type), relation_type_group, relation_type, from_id, from_type) |
|||
WITH CLUSTERING ORDER BY ( relation_type_group ASC, relation_type ASC, from_id ASC, from_type ASC); |
|||
|
|||
CREATE TABLE IF NOT EXISTS thingsboard.widgets_bundle ( |
|||
id timeuuid, |
|||
tenant_id timeuuid, |
|||
alias text, |
|||
title text, |
|||
search_text text, |
|||
image blob, |
|||
PRIMARY KEY (id, tenant_id) |
|||
); |
|||
|
|||
CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.widgets_bundle_by_tenant_and_search_text AS |
|||
SELECT * |
|||
from thingsboard.widgets_bundle |
|||
WHERE tenant_id IS NOT NULL AND search_text IS NOT NULL AND id IS NOT NULL |
|||
PRIMARY KEY ( tenant_id, search_text, id ) |
|||
WITH CLUSTERING ORDER BY ( search_text ASC, id DESC ); |
|||
|
|||
CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.widgets_bundle_by_tenant_and_alias AS |
|||
SELECT * |
|||
from thingsboard.widgets_bundle |
|||
WHERE tenant_id IS NOT NULL AND alias IS NOT NULL AND id IS NOT NULL |
|||
PRIMARY KEY ( tenant_id, alias, id ) |
|||
WITH CLUSTERING ORDER BY ( alias ASC, id DESC ); |
|||
|
|||
CREATE TABLE IF NOT EXISTS thingsboard.widget_type ( |
|||
id timeuuid, |
|||
tenant_id timeuuid, |
|||
bundle_alias text, |
|||
alias text, |
|||
name text, |
|||
descriptor text, |
|||
PRIMARY KEY (id, tenant_id, bundle_alias) |
|||
); |
|||
|
|||
CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.widget_type_by_tenant_and_aliases AS |
|||
SELECT * |
|||
from thingsboard.widget_type |
|||
WHERE tenant_id IS NOT NULL AND bundle_alias IS NOT NULL AND alias IS NOT NULL AND id IS NOT NULL |
|||
PRIMARY KEY ( tenant_id, bundle_alias, alias, id ) |
|||
WITH CLUSTERING ORDER BY ( bundle_alias ASC, alias ASC, id DESC ); |
|||
|
|||
CREATE TABLE IF NOT EXISTS thingsboard.dashboard ( |
|||
id timeuuid, |
|||
tenant_id timeuuid, |
|||
title text, |
|||
search_text text, |
|||
assigned_customers text, |
|||
configuration text, |
|||
PRIMARY KEY (id, tenant_id) |
|||
); |
|||
|
|||
CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.dashboard_by_tenant_and_search_text AS |
|||
SELECT * |
|||
from thingsboard.dashboard |
|||
WHERE tenant_id IS NOT NULL AND search_text IS NOT NULL AND id IS NOT NULL |
|||
PRIMARY KEY ( tenant_id, search_text, id ) |
|||
WITH CLUSTERING ORDER BY ( search_text ASC, id DESC ); |
|||
|
|||
CREATE TABLE IF NOT EXISTS thingsboard.attributes_kv_cf ( |
|||
entity_type text, // (DEVICE, CUSTOMER, TENANT) |
|||
entity_id timeuuid, |
|||
attribute_type text, // (CLIENT_SIDE, SHARED, SERVER_SIDE) |
|||
attribute_key text, |
|||
bool_v boolean, |
|||
str_v text, |
|||
long_v bigint, |
|||
dbl_v double, |
|||
last_update_ts bigint, |
|||
PRIMARY KEY ((entity_type, entity_id, attribute_type), attribute_key) |
|||
) WITH compaction = { 'class' : 'LeveledCompactionStrategy' }; |
|||
|
|||
CREATE TABLE IF NOT EXISTS thingsboard.component_descriptor ( |
|||
id timeuuid, |
|||
type text, |
|||
scope text, |
|||
name text, |
|||
search_text text, |
|||
clazz text, |
|||
configuration_descriptor text, |
|||
actions text, |
|||
PRIMARY KEY (clazz, id, type, scope) |
|||
); |
|||
|
|||
CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.component_desc_by_type_search_text AS |
|||
SELECT * |
|||
from thingsboard.component_descriptor |
|||
WHERE type IS NOT NULL AND scope IS NOT NULL AND search_text IS NOT NULL AND id IS NOT NULL AND clazz IS NOT NULL |
|||
PRIMARY KEY ( type, search_text, id, clazz, scope) |
|||
WITH CLUSTERING ORDER BY ( search_text DESC); |
|||
|
|||
CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.component_desc_by_scope_type_search_text AS |
|||
SELECT * |
|||
from thingsboard.component_descriptor |
|||
WHERE type IS NOT NULL AND scope IS NOT NULL AND search_text IS NOT NULL AND id IS NOT NULL AND clazz IS NOT NULL |
|||
PRIMARY KEY ( (scope, type), search_text, id, clazz) |
|||
WITH CLUSTERING ORDER BY ( search_text DESC); |
|||
|
|||
CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.component_desc_by_id AS |
|||
SELECT * |
|||
from thingsboard.component_descriptor |
|||
WHERE type IS NOT NULL AND scope IS NOT NULL AND id IS NOT NULL AND clazz IS NOT NULL |
|||
PRIMARY KEY ( id, clazz, scope, type ) |
|||
WITH CLUSTERING ORDER BY ( clazz ASC, scope ASC, type DESC); |
|||
|
|||
CREATE TABLE IF NOT EXISTS thingsboard.event ( |
|||
tenant_id timeuuid, // tenant or system |
|||
id timeuuid, |
|||
event_type text, |
|||
event_uid text, |
|||
entity_type text, |
|||
entity_id timeuuid, |
|||
body text, |
|||
PRIMARY KEY ((tenant_id, entity_type, entity_id), event_type, event_uid) |
|||
); |
|||
|
|||
CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.event_by_type_and_id AS |
|||
SELECT * |
|||
FROM thingsboard.event |
|||
WHERE tenant_id IS NOT NULL AND entity_type IS NOT NULL AND entity_id IS NOT NULL AND id IS NOT NULL |
|||
AND event_type IS NOT NULL AND event_uid IS NOT NULL |
|||
PRIMARY KEY ((tenant_id, entity_type, entity_id), event_type, id, event_uid) |
|||
WITH CLUSTERING ORDER BY (event_type ASC, id ASC, event_uid ASC); |
|||
|
|||
|
|||
CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.event_by_id AS |
|||
SELECT * |
|||
FROM thingsboard.event |
|||
WHERE tenant_id IS NOT NULL AND entity_type IS NOT NULL AND entity_id IS NOT NULL AND id IS NOT NULL |
|||
AND event_type IS NOT NULL AND event_uid IS NOT NULL |
|||
PRIMARY KEY ((tenant_id, entity_type, entity_id), id, event_type, event_uid) |
|||
WITH CLUSTERING ORDER BY (id ASC, event_type ASC, event_uid ASC); |
|||
|
|||
CREATE TABLE IF NOT EXISTS thingsboard.audit_log_by_entity_id ( |
|||
tenant_id timeuuid, |
|||
id timeuuid, |
|||
customer_id timeuuid, |
|||
entity_id timeuuid, |
|||
entity_type text, |
|||
entity_name text, |
|||
user_id timeuuid, |
|||
user_name text, |
|||
action_type text, |
|||
action_data text, |
|||
action_status text, |
|||
action_failure_details text, |
|||
PRIMARY KEY ((tenant_id, entity_id, entity_type), id) |
|||
); |
|||
|
|||
CREATE TABLE IF NOT EXISTS thingsboard.audit_log_by_customer_id ( |
|||
tenant_id timeuuid, |
|||
id timeuuid, |
|||
customer_id timeuuid, |
|||
entity_id timeuuid, |
|||
entity_type text, |
|||
entity_name text, |
|||
user_id timeuuid, |
|||
user_name text, |
|||
action_type text, |
|||
action_data text, |
|||
action_status text, |
|||
action_failure_details text, |
|||
PRIMARY KEY ((tenant_id, customer_id), id) |
|||
); |
|||
|
|||
CREATE TABLE IF NOT EXISTS thingsboard.audit_log_by_user_id ( |
|||
tenant_id timeuuid, |
|||
id timeuuid, |
|||
customer_id timeuuid, |
|||
entity_id timeuuid, |
|||
entity_type text, |
|||
entity_name text, |
|||
user_id timeuuid, |
|||
user_name text, |
|||
action_type text, |
|||
action_data text, |
|||
action_status text, |
|||
action_failure_details text, |
|||
PRIMARY KEY ((tenant_id, user_id), id) |
|||
); |
|||
|
|||
CREATE TABLE IF NOT EXISTS thingsboard.audit_log_by_tenant_id ( |
|||
tenant_id timeuuid, |
|||
id timeuuid, |
|||
partition bigint, |
|||
customer_id timeuuid, |
|||
entity_id timeuuid, |
|||
entity_type text, |
|||
entity_name text, |
|||
user_id timeuuid, |
|||
user_name text, |
|||
action_type text, |
|||
action_data text, |
|||
action_status text, |
|||
action_failure_details text, |
|||
PRIMARY KEY ((tenant_id, partition), id) |
|||
); |
|||
|
|||
CREATE TABLE IF NOT EXISTS thingsboard.audit_log_by_tenant_id_partitions ( |
|||
tenant_id timeuuid, |
|||
partition bigint, |
|||
PRIMARY KEY (( tenant_id ), partition) |
|||
) WITH CLUSTERING ORDER BY ( partition ASC ) |
|||
AND compaction = { 'class' : 'LeveledCompactionStrategy' }; |
|||
|
|||
CREATE TABLE IF NOT EXISTS thingsboard.msg_queue ( |
|||
node_id timeuuid, |
|||
cluster_partition bigint, |
|||
ts_partition bigint, |
|||
ts bigint, |
|||
msg blob, |
|||
PRIMARY KEY ((node_id, cluster_partition, ts_partition), ts)) |
|||
WITH CLUSTERING ORDER BY (ts DESC) |
|||
AND compaction = { |
|||
'class': 'org.apache.cassandra.db.compaction.DateTieredCompactionStrategy', |
|||
'min_threshold': '5', |
|||
'base_time_seconds': '43200', |
|||
'max_window_size_seconds': '43200', |
|||
'tombstone_threshold': '0.9', |
|||
'unchecked_tombstone_compaction': 'true' |
|||
}; |
|||
|
|||
CREATE TABLE IF NOT EXISTS thingsboard.msg_ack_queue ( |
|||
node_id timeuuid, |
|||
cluster_partition bigint, |
|||
ts_partition bigint, |
|||
msg_id timeuuid, |
|||
PRIMARY KEY ((node_id, cluster_partition, ts_partition), msg_id)) |
|||
WITH CLUSTERING ORDER BY (msg_id DESC) |
|||
AND compaction = { |
|||
'class': 'org.apache.cassandra.db.compaction.DateTieredCompactionStrategy', |
|||
'min_threshold': '5', |
|||
'base_time_seconds': '43200', |
|||
'max_window_size_seconds': '43200', |
|||
'tombstone_threshold': '0.9', |
|||
'unchecked_tombstone_compaction': 'true' |
|||
}; |
|||
|
|||
CREATE TABLE IF NOT EXISTS thingsboard.processed_msg_partitions ( |
|||
node_id timeuuid, |
|||
cluster_partition bigint, |
|||
ts_partition bigint, |
|||
PRIMARY KEY ((node_id, cluster_partition), ts_partition)) |
|||
WITH CLUSTERING ORDER BY (ts_partition DESC) |
|||
AND compaction = { |
|||
'class': 'org.apache.cassandra.db.compaction.DateTieredCompactionStrategy', |
|||
'min_threshold': '5', |
|||
'base_time_seconds': '43200', |
|||
'max_window_size_seconds': '43200', |
|||
'tombstone_threshold': '0.9', |
|||
'unchecked_tombstone_compaction': 'true' |
|||
}; |
|||
|
|||
CREATE TABLE IF NOT EXISTS thingsboard.rule_chain ( |
|||
id uuid, |
|||
tenant_id uuid, |
|||
name text, |
|||
search_text text, |
|||
first_rule_node_id uuid, |
|||
root boolean, |
|||
debug_mode boolean, |
|||
configuration text, |
|||
additional_info text, |
|||
PRIMARY KEY (id, tenant_id) |
|||
); |
|||
|
|||
CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.rule_chain_by_tenant_and_search_text AS |
|||
SELECT * |
|||
from thingsboard.rule_chain |
|||
WHERE tenant_id IS NOT NULL AND search_text IS NOT NULL AND id IS NOT NULL |
|||
PRIMARY KEY ( tenant_id, search_text, id ) |
|||
WITH CLUSTERING ORDER BY ( search_text ASC, id DESC ); |
|||
|
|||
CREATE TABLE IF NOT EXISTS thingsboard.rule_node ( |
|||
id uuid, |
|||
rule_chain_id uuid, |
|||
type text, |
|||
name text, |
|||
debug_mode boolean, |
|||
search_text text, |
|||
configuration text, |
|||
additional_info text, |
|||
PRIMARY KEY (id) |
|||
); |
|||
|
|||
CREATE TABLE IF NOT EXISTS thingsboard.entity_view ( |
|||
id timeuuid, |
|||
entity_id timeuuid, |
|||
entity_type text, |
|||
tenant_id timeuuid, |
|||
customer_id timeuuid, |
|||
name text, |
|||
type text, |
|||
keys text, |
|||
start_ts bigint, |
|||
end_ts bigint, |
|||
search_text text, |
|||
additional_info text, |
|||
PRIMARY KEY (id, entity_id, tenant_id, customer_id, type) |
|||
); |
|||
|
|||
CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_view_by_tenant_and_name AS |
|||
SELECT * |
|||
from thingsboard.entity_view |
|||
WHERE tenant_id IS NOT NULL |
|||
AND entity_id IS NOT NULL |
|||
AND customer_id IS NOT NULL |
|||
AND type IS NOT NULL |
|||
AND name IS NOT NULL |
|||
AND id IS NOT NULL |
|||
PRIMARY KEY (tenant_id, name, id, customer_id, entity_id, type) |
|||
WITH CLUSTERING ORDER BY (name ASC, id DESC, customer_id DESC); |
|||
|
|||
CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_view_by_tenant_and_search_text AS |
|||
SELECT * |
|||
from thingsboard.entity_view |
|||
WHERE tenant_id IS NOT NULL |
|||
AND entity_id IS NOT NULL |
|||
AND customer_id IS NOT NULL |
|||
AND type IS NOT NULL |
|||
AND search_text IS NOT NULL |
|||
AND id IS NOT NULL |
|||
PRIMARY KEY (tenant_id, search_text, id, customer_id, entity_id, type) |
|||
WITH CLUSTERING ORDER BY (search_text ASC, id DESC, customer_id DESC); |
|||
|
|||
CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_view_by_tenant_by_type_and_search_text AS |
|||
SELECT * |
|||
from thingsboard.entity_view |
|||
WHERE tenant_id IS NOT NULL |
|||
AND entity_id IS NOT NULL |
|||
AND customer_id IS NOT NULL |
|||
AND type IS NOT NULL |
|||
AND search_text IS NOT NULL |
|||
AND id IS NOT NULL |
|||
PRIMARY KEY (tenant_id, type, search_text, id, customer_id, entity_id) |
|||
WITH CLUSTERING ORDER BY (type ASC, search_text ASC, id DESC, customer_id DESC); |
|||
|
|||
CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_view_by_tenant_and_customer AS |
|||
SELECT * |
|||
from thingsboard.entity_view |
|||
WHERE tenant_id IS NOT NULL |
|||
AND customer_id IS NOT NULL |
|||
AND entity_id IS NOT NULL |
|||
AND type IS NOT NULL |
|||
AND search_text IS NOT NULL |
|||
AND id IS NOT NULL |
|||
PRIMARY KEY (tenant_id, customer_id, search_text, id, entity_id, type) |
|||
WITH CLUSTERING ORDER BY (customer_id DESC, search_text ASC, id DESC); |
|||
|
|||
CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_view_by_tenant_and_customer_and_type AS |
|||
SELECT * |
|||
from thingsboard.entity_view |
|||
WHERE tenant_id IS NOT NULL |
|||
AND customer_id IS NOT NULL |
|||
AND entity_id IS NOT NULL |
|||
AND type IS NOT NULL |
|||
AND search_text IS NOT NULL |
|||
AND id IS NOT NULL |
|||
PRIMARY KEY (tenant_id, type, customer_id, search_text, id, entity_id) |
|||
WITH CLUSTERING ORDER BY (type ASC, customer_id DESC, search_text ASC, id DESC); |
|||
|
|||
CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_view_by_tenant_and_entity_id AS |
|||
SELECT * |
|||
from thingsboard.entity_view |
|||
WHERE tenant_id IS NOT NULL |
|||
AND customer_id IS NOT NULL |
|||
AND entity_id IS NOT NULL |
|||
AND type IS NOT NULL |
|||
AND search_text IS NOT NULL |
|||
AND id IS NOT NULL |
|||
PRIMARY KEY (tenant_id, entity_id, customer_id, search_text, id, type) |
|||
WITH CLUSTERING ORDER BY (entity_id DESC, customer_id DESC, search_text ASC, id DESC); |
|||
@ -1,44 +0,0 @@ |
|||
-- |
|||
-- Copyright © 2016-2019 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. |
|||
-- |
|||
|
|||
/** SYSTEM **/ |
|||
|
|||
/** System admin **/ |
|||
INSERT INTO thingsboard.user ( id, tenant_id, customer_id, email, search_text, authority ) |
|||
VALUES ( minTimeuuid ( '2016-11-01 01:01:01+0000' ), minTimeuuid ( 0 ), minTimeuuid ( 0 ), 'sysadmin@thingsboard.org', |
|||
'sysadmin@thingsboard.org', 'SYS_ADMIN' ); |
|||
|
|||
INSERT INTO thingsboard.user_credentials ( id, user_id, enabled, password ) |
|||
VALUES ( now ( ), minTimeuuid ( '2016-11-01 01:01:01+0000' ), true, |
|||
'$2a$10$5JTB8/hxWc9WAy62nCGSxeefl3KWmipA9nFpVdDa0/xfIseeBB4Bu' ); |
|||
|
|||
/** System settings **/ |
|||
INSERT INTO thingsboard.admin_settings ( id, key, json_value ) |
|||
VALUES ( now ( ), 'general', '{ |
|||
"baseUrl": "http://localhost:8080" |
|||
}' ); |
|||
|
|||
INSERT INTO thingsboard.admin_settings ( id, key, json_value ) |
|||
VALUES ( now ( ), 'mail', '{ |
|||
"mailFrom": "Thingsboard <sysadmin@localhost.localdomain>", |
|||
"smtpProtocol": "smtp", |
|||
"smtpHost": "localhost", |
|||
"smtpPort": "25", |
|||
"timeout": "10000", |
|||
"enableTls": "false", |
|||
"username": "", |
|||
"password": "" |
|||
}' ); |
|||
@ -1,23 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.service.attributes.nosql; |
|||
|
|||
import org.thingsboard.server.dao.service.DaoNoSqlTest; |
|||
import org.thingsboard.server.dao.service.attributes.BaseAttributesServiceTest; |
|||
|
|||
@DaoNoSqlTest |
|||
public class AttributesServiceNoSqlTest extends BaseAttributesServiceTest { |
|||
} |
|||
@ -1,23 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.service.event.nosql; |
|||
|
|||
import org.thingsboard.server.dao.service.DaoNoSqlTest; |
|||
import org.thingsboard.server.dao.service.event.BaseEventServiceTest; |
|||
|
|||
@DaoNoSqlTest |
|||
public class EventServiceNoSqlTest extends BaseEventServiceTest { |
|||
} |
|||
@ -1,23 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.service.nosql; |
|||
|
|||
import org.thingsboard.server.dao.service.BaseAdminSettingsServiceTest; |
|||
import org.thingsboard.server.dao.service.DaoNoSqlTest; |
|||
|
|||
@DaoNoSqlTest |
|||
public class AdminSettingsServiceNoSqlTest extends BaseAdminSettingsServiceTest { |
|||
} |
|||
@ -1,23 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.service.nosql; |
|||
|
|||
import org.thingsboard.server.dao.service.BaseAlarmServiceTest; |
|||
import org.thingsboard.server.dao.service.DaoNoSqlTest; |
|||
|
|||
@DaoNoSqlTest |
|||
public class AlarmServiceNoSqlTest extends BaseAlarmServiceTest { |
|||
} |
|||
@ -1,23 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.service.nosql; |
|||
|
|||
import org.thingsboard.server.dao.service.BaseAssetServiceTest; |
|||
import org.thingsboard.server.dao.service.DaoNoSqlTest; |
|||
|
|||
@DaoNoSqlTest |
|||
public class AssetServiceNoSqlTest extends BaseAssetServiceTest { |
|||
} |
|||
@ -1,23 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.service.nosql; |
|||
|
|||
import org.thingsboard.server.dao.service.BaseCustomerServiceTest; |
|||
import org.thingsboard.server.dao.service.DaoNoSqlTest; |
|||
|
|||
@DaoNoSqlTest |
|||
public class CustomerServiceNoSqlTest extends BaseCustomerServiceTest { |
|||
} |
|||
@ -1,23 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.service.nosql; |
|||
|
|||
import org.thingsboard.server.dao.service.BaseDashboardServiceTest; |
|||
import org.thingsboard.server.dao.service.DaoNoSqlTest; |
|||
|
|||
@DaoNoSqlTest |
|||
public class DashboardServiceNoSqlTest extends BaseDashboardServiceTest { |
|||
} |
|||
@ -1,23 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.service.nosql; |
|||
|
|||
import org.thingsboard.server.dao.service.BaseDeviceCredentialsCacheTest; |
|||
import org.thingsboard.server.dao.service.DaoNoSqlTest; |
|||
|
|||
@DaoNoSqlTest |
|||
public class DeviceCredentialCacheServiceNoSqlTest extends BaseDeviceCredentialsCacheTest { |
|||
} |
|||
@ -1,23 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.service.nosql; |
|||
|
|||
import org.thingsboard.server.dao.service.BaseDeviceCredentialsServiceTest; |
|||
import org.thingsboard.server.dao.service.DaoNoSqlTest; |
|||
|
|||
@DaoNoSqlTest |
|||
public class DeviceCredentialServiceNoSqlTest extends BaseDeviceCredentialsServiceTest { |
|||
} |
|||
@ -1,23 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.service.nosql; |
|||
|
|||
import org.thingsboard.server.dao.service.BaseDeviceServiceTest; |
|||
import org.thingsboard.server.dao.service.DaoNoSqlTest; |
|||
|
|||
@DaoNoSqlTest |
|||
public class DeviceServiceNoSqlTest extends BaseDeviceServiceTest { |
|||
} |
|||
@ -1,23 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.service.nosql; |
|||
|
|||
import org.thingsboard.server.dao.service.BaseRelationCacheTest; |
|||
import org.thingsboard.server.dao.service.DaoNoSqlTest; |
|||
|
|||
@DaoNoSqlTest |
|||
public class RelationCacheNoSqlTest extends BaseRelationCacheTest { |
|||
} |
|||
@ -1,23 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.service.nosql; |
|||
|
|||
import org.thingsboard.server.dao.service.BaseRelationServiceTest; |
|||
import org.thingsboard.server.dao.service.DaoNoSqlTest; |
|||
|
|||
@DaoNoSqlTest |
|||
public class RelationServiceNoSqlTest extends BaseRelationServiceTest { |
|||
} |
|||
@ -1,23 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.service.nosql; |
|||
|
|||
import org.thingsboard.server.dao.service.BaseRuleChainServiceTest; |
|||
import org.thingsboard.server.dao.service.DaoNoSqlTest; |
|||
|
|||
@DaoNoSqlTest |
|||
public class RuleChainServiceNoSqlTest extends BaseRuleChainServiceTest { |
|||
} |
|||
@ -1,23 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.service.nosql; |
|||
|
|||
import org.thingsboard.server.dao.service.BaseTenantServiceTest; |
|||
import org.thingsboard.server.dao.service.DaoNoSqlTest; |
|||
|
|||
@DaoNoSqlTest |
|||
public class TenantServiceNoSqlTest extends BaseTenantServiceTest { |
|||
} |
|||
@ -1,23 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.service.nosql; |
|||
|
|||
import org.thingsboard.server.dao.service.BaseUserServiceTest; |
|||
import org.thingsboard.server.dao.service.DaoNoSqlTest; |
|||
|
|||
@DaoNoSqlTest |
|||
public class UserServiceNoSqlTest extends BaseUserServiceTest { |
|||
} |
|||
@ -1,23 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.service.nosql; |
|||
|
|||
import org.thingsboard.server.dao.service.BaseWidgetTypeServiceTest; |
|||
import org.thingsboard.server.dao.service.DaoNoSqlTest; |
|||
|
|||
@DaoNoSqlTest |
|||
public class WidgetTypeServiceNoSqlTest extends BaseWidgetTypeServiceTest { |
|||
} |
|||
@ -1,23 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2019 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.dao.service.nosql; |
|||
|
|||
import org.thingsboard.server.dao.service.BaseWidgetsBundleServiceTest; |
|||
import org.thingsboard.server.dao.service.DaoNoSqlTest; |
|||
|
|||
@DaoNoSqlTest |
|||
public class WidgetsBundleServiceNoSqlTest extends BaseWidgetsBundleServiceTest { |
|||
} |
|||
@ -1,27 +0,0 @@ |
|||
TRUNCATE thingsboard.rule_chain; |
|||
TRUNCATE thingsboard.rule_node; |
|||
|
|||
-- msg_queue dataset |
|||
|
|||
INSERT INTO thingsboard.msg_queue (node_id, cluster_partition, ts_partition, ts, msg) |
|||
VALUES (055eee50-1883-11e8-b380-65b5d5335ba9, 101, 200, 201, null); |
|||
INSERT INTO thingsboard.msg_queue (node_id, cluster_partition, ts_partition, ts, msg) |
|||
VALUES (055eee50-1883-11e8-b380-65b5d5335ba9, 101, 200, 202, null); |
|||
INSERT INTO thingsboard.msg_queue (node_id, cluster_partition, ts_partition, ts, msg) |
|||
VALUES (055eee50-1883-11e8-b380-65b5d5335ba9, 101, 300, 301, null); |
|||
|
|||
-- ack_queue dataset |
|||
INSERT INTO thingsboard.msg_ack_queue (node_id, cluster_partition, ts_partition, msg_id) |
|||
VALUES (055eee50-1883-11e8-b380-65b5d5335ba9, 101, 300, bebaeb60-1888-11e8-bf21-65b5d5335ba9); |
|||
INSERT INTO thingsboard.msg_ack_queue (node_id, cluster_partition, ts_partition, msg_id) |
|||
VALUES (055eee50-1883-11e8-b380-65b5d5335ba9, 101, 300, 12baeb60-1888-11e8-bf21-65b5d5335ba9); |
|||
INSERT INTO thingsboard.msg_ack_queue (node_id, cluster_partition, ts_partition, msg_id) |
|||
VALUES (055eee50-1883-11e8-b380-65b5d5335ba9, 101, 200, 32baeb60-1888-11e8-bf21-65b5d5335ba9); |
|||
|
|||
-- processed partition dataset |
|||
INSERT INTO thingsboard.processed_msg_partitions (node_id, cluster_partition, ts_partition) |
|||
VALUES (055eee50-1883-11e8-b380-65b5d5335ba9, 101, 100); |
|||
INSERT INTO thingsboard.processed_msg_partitions (node_id, cluster_partition, ts_partition) |
|||
VALUES (055eee50-1883-11e8-b380-65b5d5335ba9, 101, 777); |
|||
INSERT INTO thingsboard.processed_msg_partitions (node_id, cluster_partition, ts_partition) |
|||
VALUES (055eee50-1883-11e8-b380-65b5d5335ba9, 202, 200); |
|||
@ -1,2 +1,14 @@ |
|||
database.entities.type=cassandra |
|||
database.ts.type=cassandra |
|||
|
|||
sql.ts_inserts_executor_type=fixed |
|||
sql.ts_inserts_fixed_thread_pool_size=10 |
|||
|
|||
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true |
|||
spring.jpa.show-sql=false |
|||
spring.jpa.hibernate.ddl-auto=none |
|||
spring.jpa.database-platform=org.hibernate.dialect.HSQLDialect |
|||
|
|||
spring.datasource.username=sa |
|||
spring.datasource.password= |
|||
spring.datasource.url=jdbc:hsqldb:file:/tmp/testDb;sql.enforce_size=false |
|||
spring.datasource.driverClassName=org.hsqldb.jdbc.JDBCDriver |
|||
|
|||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue