committed by
GitHub
335 changed files with 12480 additions and 2412 deletions
@ -1,49 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2017 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; |
|||
|
|||
import org.junit.Test; |
|||
import org.junit.runner.RunWith; |
|||
import org.springframework.test.context.web.WebAppConfiguration; |
|||
import org.springframework.boot.test.IntegrationTest; |
|||
import org.springframework.boot.test.SpringApplicationConfiguration; |
|||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
|||
|
|||
@RunWith(SpringJUnit4ClassRunner.class) |
|||
@SpringApplicationConfiguration(classes = ThingsboardServerApplication.class) |
|||
@WebAppConfiguration |
|||
@IntegrationTest("server.port:0") |
|||
public class ThingsboardApplicationTests { |
|||
|
|||
@Test |
|||
public void contextLoads() { |
|||
String test = "[ \n" + |
|||
" {\n" + |
|||
" \"key\": \"name\",\n" + |
|||
"\t\"type\": \"text\" \n" + |
|||
" },\n" + |
|||
" {\n" + |
|||
"\t\"key\": \"name2\",\n" + |
|||
"\t\"type\": \"color\"\n" + |
|||
" },\n" + |
|||
" {\n" + |
|||
"\t\"key\": \"name3\",\n" + |
|||
"\t\"type\": \"javascript\"\n" + |
|||
" } \n" + |
|||
"]"; |
|||
} |
|||
|
|||
} |
|||
@ -1,73 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2017 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.mqtt; |
|||
|
|||
import org.junit.runner.RunWith; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; |
|||
import org.springframework.boot.test.IntegrationTest; |
|||
import org.springframework.boot.test.SpringApplicationContextLoader; |
|||
import org.springframework.context.annotation.ComponentScan; |
|||
import org.springframework.context.annotation.Configuration; |
|||
import org.springframework.http.converter.HttpMessageConverter; |
|||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; |
|||
import org.springframework.test.annotation.DirtiesContext; |
|||
import org.springframework.test.context.ActiveProfiles; |
|||
import org.springframework.test.context.ContextConfiguration; |
|||
import org.springframework.test.context.TestPropertySource; |
|||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
|||
import org.springframework.test.context.web.WebAppConfiguration; |
|||
import org.springframework.web.context.WebApplicationContext; |
|||
import org.thingsboard.server.mqtt.telemetry.MqttTelemetryIntergrationTest; |
|||
|
|||
import java.util.Arrays; |
|||
|
|||
import static org.junit.Assert.assertNotNull; |
|||
|
|||
/** |
|||
* @author Valerii Sosliuk |
|||
*/ |
|||
@ActiveProfiles("default") |
|||
@RunWith(SpringJUnit4ClassRunner.class) |
|||
@ContextConfiguration(classes= MqttTelemetryIntergrationTest.class, loader=SpringApplicationContextLoader.class) |
|||
@TestPropertySource(locations = {"classpath:cassandra-test.properties", "classpath:thingsboard-test.properties"}) |
|||
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) |
|||
@Configuration |
|||
@EnableAutoConfiguration |
|||
@ComponentScan({"org.thingsboard.server"}) |
|||
@WebAppConfiguration |
|||
@IntegrationTest("server.port:8080") |
|||
public class AbstractFeatureIntegrationTest { |
|||
|
|||
@SuppressWarnings("rawtypes") |
|||
private HttpMessageConverter mappingJackson2HttpMessageConverter; |
|||
|
|||
@Autowired |
|||
private WebApplicationContext webApplicationContext; |
|||
|
|||
@Autowired |
|||
void setConverters(HttpMessageConverter<?>[] converters) { |
|||
|
|||
this.mappingJackson2HttpMessageConverter = Arrays.stream(converters) |
|||
.filter(hmc -> hmc instanceof MappingJackson2HttpMessageConverter) |
|||
.findAny() |
|||
.get(); |
|||
|
|||
assertNotNull("the JSON message converter must not be null", |
|||
this.mappingJackson2HttpMessageConverter); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,38 @@ |
|||
/** |
|||
* Copyright © 2016-2017 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.junit.ClassRule; |
|||
import org.junit.extensions.cpsuite.ClasspathSuite; |
|||
import org.junit.runner.RunWith; |
|||
import org.thingsboard.server.dao.CustomPostgresUnit; |
|||
|
|||
import java.util.Arrays; |
|||
|
|||
/** |
|||
* Created by Valerii Sosliuk on 6/27/2017. |
|||
*/ |
|||
@RunWith(ClasspathSuite.class) |
|||
@ClasspathSuite.ClassnameFilters({"org.thingsboard.server.system.sql.*SqlTest"}) |
|||
public class SystemSqlTestSuite { |
|||
|
|||
@ClassRule |
|||
public static CustomPostgresUnit postgresUnit = new CustomPostgresUnit( |
|||
Arrays.asList("postgres/schema.sql", "postgres/system-data.sql"), |
|||
"postgres-embedded-test.properties"); |
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,27 @@ |
|||
/** |
|||
* Copyright © 2016-2017 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 { |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
/** |
|||
* Copyright © 2016-2017 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.sql; |
|||
|
|||
import org.thingsboard.server.dao.service.DaoSqlTest; |
|||
import org.thingsboard.server.system.BaseHttpDeviceApiTest; |
|||
|
|||
/** |
|||
* Created by Valerii Sosliuk on 6/27/2017. |
|||
*/ |
|||
@DaoSqlTest |
|||
public class DeviceApiSqlTest extends BaseHttpDeviceApiTest{ |
|||
} |
|||
@ -1 +0,0 @@ |
|||
updates.enabled=false |
|||
@ -0,0 +1,38 @@ |
|||
/** |
|||
* Copyright © 2016-2017 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; |
|||
|
|||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; |
|||
import org.springframework.boot.autoconfigure.domain.EntityScan; |
|||
import org.springframework.context.annotation.ComponentScan; |
|||
import org.springframework.context.annotation.Configuration; |
|||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories; |
|||
import org.springframework.transaction.annotation.EnableTransactionManagement; |
|||
import org.thingsboard.server.dao.util.SqlDao; |
|||
|
|||
/** |
|||
* @author Valerii Sosliuk |
|||
*/ |
|||
@Configuration |
|||
@EnableAutoConfiguration |
|||
@ComponentScan("org.thingsboard.server.dao.sql") |
|||
@EnableJpaRepositories("org.thingsboard.server.dao.sql") |
|||
@EntityScan("org.thingsboard.server.dao.model.sql") |
|||
@EnableTransactionManagement |
|||
@SqlDao |
|||
public class JpaDaoConfig { |
|||
|
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
/** |
|||
* Copyright © 2016-2017 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; |
|||
|
|||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; |
|||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; |
|||
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration; |
|||
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; |
|||
import org.springframework.context.annotation.Configuration; |
|||
import org.thingsboard.server.dao.util.NoSqlDao; |
|||
|
|||
@Configuration |
|||
@EnableAutoConfiguration( |
|||
exclude = { |
|||
DataSourceAutoConfiguration.class, |
|||
DataSourceTransactionManagerAutoConfiguration.class, |
|||
HibernateJpaAutoConfiguration.class}) |
|||
@NoSqlDao |
|||
public class NoSqlDaoConfig { |
|||
} |
|||
@ -0,0 +1,39 @@ |
|||
/** |
|||
* Copyright © 2016-2017 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.nosql.CassandraAbstractSearchTextDao; |
|||
import org.thingsboard.server.dao.util.NoSqlDao; |
|||
import org.thingsboard.server.dao.model.nosql.DashboardEntity; |
|||
|
|||
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,60 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2017 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 static com.datastax.driver.core.querybuilder.QueryBuilder.eq; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.DASHBOARD_BY_CUSTOMER_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME; |
|||
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_CUSTOMER_ID_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.DASHBOARD_TENANT_ID_PROPERTY; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID; |
|||
|
|||
import java.util.Arrays; |
|||
import java.util.List; |
|||
import java.util.UUID; |
|||
|
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.common.data.Dashboard; |
|||
import org.thingsboard.server.common.data.page.TextPageLink; |
|||
import org.thingsboard.server.dao.AbstractSearchTextDao; |
|||
import org.thingsboard.server.dao.model.DashboardEntity; |
|||
import org.slf4j.Logger; |
|||
import org.slf4j.LoggerFactory; |
|||
import org.thingsboard.server.dao.model.DashboardInfoEntity; |
|||
|
|||
@Component |
|||
@Slf4j |
|||
public class DashboardDaoImpl extends AbstractSearchTextDao<DashboardEntity> implements DashboardDao { |
|||
|
|||
@Override |
|||
protected Class<DashboardEntity> getColumnFamilyClass() { |
|||
return DashboardEntity.class; |
|||
} |
|||
|
|||
@Override |
|||
protected String getColumnFamilyName() { |
|||
return DASHBOARD_COLUMN_FAMILY_NAME; |
|||
} |
|||
|
|||
@Override |
|||
public DashboardEntity save(Dashboard dashboard) { |
|||
log.debug("Save dashboard [{}] ", dashboard); |
|||
return save(new DashboardEntity(dashboard)); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,84 @@ |
|||
/** |
|||
* Copyright © 2016-2017 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.sql; |
|||
|
|||
import com.datastax.driver.core.utils.UUIDs; |
|||
import com.fasterxml.jackson.databind.JsonNode; |
|||
import lombok.Data; |
|||
import org.hibernate.annotations.Type; |
|||
import org.hibernate.annotations.TypeDef; |
|||
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.util.mapping.JsonStringType; |
|||
|
|||
import javax.persistence.*; |
|||
import java.util.UUID; |
|||
|
|||
import static org.thingsboard.server.dao.model.ModelConstants.*; |
|||
|
|||
@Data |
|||
@Entity |
|||
@TypeDef(name = "json", typeClass = JsonStringType.class) |
|||
@Table(name = ADMIN_SETTINGS_COLUMN_FAMILY_NAME) |
|||
public final class AdminSettingsEntity implements BaseEntity<AdminSettings> { |
|||
|
|||
@Transient |
|||
private static final long serialVersionUID = 842759712850362147L; |
|||
|
|||
@Id |
|||
@Column(name = ID_PROPERTY) |
|||
private UUID id; |
|||
|
|||
@Column(name = ADMIN_SETTINGS_KEY_PROPERTY) |
|||
private String key; |
|||
|
|||
@Type(type = "json") |
|||
@Column(name = ADMIN_SETTINGS_JSON_VALUE_PROPERTY) |
|||
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(); |
|||
} |
|||
|
|||
@Override |
|||
public UUID getId() { |
|||
return id; |
|||
} |
|||
|
|||
@Override |
|||
public void setId(UUID id) { |
|||
this.id = id; |
|||
} |
|||
|
|||
@Override |
|||
public AdminSettings toData() { |
|||
AdminSettings adminSettings = new AdminSettings(new AdminSettingsId(id)); |
|||
adminSettings.setCreatedTime(UUIDs.unixTimestamp(id)); |
|||
adminSettings.setKey(key); |
|||
adminSettings.setJsonValue(jsonValue); |
|||
return adminSettings; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,136 @@ |
|||
/** |
|||
* Copyright © 2016-2017 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.sql; |
|||
|
|||
import com.datastax.driver.core.utils.UUIDs; |
|||
import com.fasterxml.jackson.databind.JsonNode; |
|||
import lombok.Data; |
|||
import org.hibernate.annotations.Type; |
|||
import org.hibernate.annotations.TypeDef; |
|||
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.ModelConstants; |
|||
import org.thingsboard.server.dao.util.mapping.JsonStringType; |
|||
|
|||
import javax.persistence.*; |
|||
import java.util.UUID; |
|||
|
|||
import static org.thingsboard.server.dao.model.ModelConstants.*; |
|||
|
|||
@Data |
|||
@Entity |
|||
@TypeDef(name = "json", typeClass = JsonStringType.class) |
|||
@Table(name = ALARM_COLUMN_FAMILY_NAME) |
|||
public final class AlarmEntity implements BaseEntity<Alarm> { |
|||
|
|||
@Transient |
|||
private static final long serialVersionUID = -339979717281685984L; |
|||
|
|||
@Id |
|||
@Column(name = ID_PROPERTY) |
|||
private UUID id; |
|||
|
|||
@Column(name = ALARM_TENANT_ID_PROPERTY) |
|||
private UUID tenantId; |
|||
|
|||
@Column(name = ALARM_ORIGINATOR_ID_PROPERTY) |
|||
private UUID originatorId; |
|||
|
|||
@Column(name = ALARM_ORIGINATOR_TYPE_PROPERTY) |
|||
private EntityType originatorType; |
|||
|
|||
@Column(name = ALARM_TYPE_PROPERTY) |
|||
private String type; |
|||
|
|||
@Enumerated(EnumType.STRING) |
|||
@Column(name = ALARM_SEVERITY_PROPERTY) |
|||
private AlarmSeverity severity; |
|||
|
|||
@Enumerated(EnumType.STRING) |
|||
@Column(name = ALARM_STATUS_PROPERTY) |
|||
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; |
|||
|
|||
@Type(type = "json") |
|||
@Column(name = ModelConstants.ASSET_ADDITIONAL_INFO_PROPERTY) |
|||
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(); |
|||
} |
|||
|
|||
@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; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,117 @@ |
|||
/** |
|||
* Copyright © 2016-2017 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.sql; |
|||
|
|||
import com.datastax.driver.core.utils.UUIDs; |
|||
import com.fasterxml.jackson.databind.JsonNode; |
|||
import lombok.Data; |
|||
import org.hibernate.annotations.Type; |
|||
import org.hibernate.annotations.TypeDef; |
|||
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.ModelConstants; |
|||
import org.thingsboard.server.dao.model.SearchTextEntity; |
|||
import org.thingsboard.server.dao.util.mapping.JsonStringType; |
|||
|
|||
import javax.persistence.*; |
|||
import java.util.UUID; |
|||
|
|||
import static org.thingsboard.server.dao.model.ModelConstants.*; |
|||
|
|||
@Data |
|||
@Entity |
|||
@TypeDef(name = "json", typeClass = JsonStringType.class) |
|||
@Table(name = ASSET_COLUMN_FAMILY_NAME) |
|||
public final class AssetEntity implements SearchTextEntity<Asset> { |
|||
|
|||
@Transient |
|||
private static final long serialVersionUID = -4089175869616037592L; |
|||
|
|||
@Id |
|||
@Column(name = ID_PROPERTY) |
|||
private UUID id; |
|||
|
|||
@Column(name = ASSET_TENANT_ID_PROPERTY) |
|||
private UUID tenantId; |
|||
|
|||
@Column(name = ASSET_CUSTOMER_ID_PROPERTY) |
|||
private UUID customerId; |
|||
|
|||
@Column(name = ASSET_NAME_PROPERTY) |
|||
private String name; |
|||
|
|||
@Column(name = ASSET_TYPE_PROPERTY) |
|||
private String type; |
|||
|
|||
@Column(name = SEARCH_TEXT_PROPERTY) |
|||
private String searchText; |
|||
|
|||
@Type(type = "json") |
|||
@Column(name = ModelConstants.ASSET_ADDITIONAL_INFO_PROPERTY) |
|||
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(); |
|||
} |
|||
|
|||
@Override |
|||
public String getSearchTextSource() { |
|||
return name; |
|||
} |
|||
|
|||
@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; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,34 @@ |
|||
/** |
|||
* Copyright © 2016-2017 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.sql; |
|||
|
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Data; |
|||
import lombok.NoArgsConstructor; |
|||
import org.thingsboard.server.common.data.EntityType; |
|||
|
|||
import java.io.Serializable; |
|||
import java.util.UUID; |
|||
|
|||
@Data |
|||
@AllArgsConstructor |
|||
@NoArgsConstructor |
|||
public class AttributeKvCompositeKey implements Serializable { |
|||
private EntityType entityType; |
|||
private UUID entityId; |
|||
private String attributeType; |
|||
private String attributeKey; |
|||
} |
|||
@ -0,0 +1,81 @@ |
|||
/** |
|||
* Copyright © 2016-2017 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.sql; |
|||
|
|||
import lombok.Data; |
|||
import org.thingsboard.server.common.data.EntityType; |
|||
import org.thingsboard.server.common.data.kv.*; |
|||
import org.thingsboard.server.dao.model.ToData; |
|||
|
|||
import javax.persistence.*; |
|||
import java.io.Serializable; |
|||
import java.util.UUID; |
|||
|
|||
import static org.thingsboard.server.dao.model.ModelConstants.*; |
|||
|
|||
@Data |
|||
@Entity |
|||
@Table(name = "attribute_kv") |
|||
@IdClass(AttributeKvCompositeKey.class) |
|||
public class AttributeKvEntity implements ToData<AttributeKvEntry>, Serializable { |
|||
|
|||
@Id |
|||
@Enumerated(EnumType.STRING) |
|||
@Column(name = ENTITY_TYPE_COLUMN) |
|||
private EntityType entityType; |
|||
|
|||
@Id |
|||
@Column(name = ENTITY_ID_COLUMN) |
|||
private UUID entityId; |
|||
|
|||
@Id |
|||
@Column(name = ATTRIBUTE_TYPE_COLUMN) |
|||
private String attributeType; |
|||
|
|||
@Id |
|||
@Column(name = ATTRIBUTE_KEY_COLUMN) |
|||
private String attributeKey; |
|||
|
|||
@Column(name = BOOLEAN_VALUE_COLUMN) |
|||
private Boolean booleanValue; |
|||
|
|||
@Column(name = STRING_VALUE_COLUMN) |
|||
private String strValue; |
|||
|
|||
@Column(name = LONG_VALUE_COLUMN) |
|||
private Long longValue; |
|||
|
|||
@Column(name = DOUBLE_VALUE_COLUMN) |
|||
private Double doubleValue; |
|||
|
|||
@Column(name = LAST_UPDATE_TS_COLUMN) |
|||
private Long lastUpdateTs; |
|||
|
|||
@Override |
|||
public AttributeKvEntry toData() { |
|||
KvEntry kvEntry = null; |
|||
if (strValue != null) { |
|||
kvEntry = new StringDataEntry(attributeKey, strValue); |
|||
} else if (booleanValue != null) { |
|||
kvEntry = new BooleanDataEntry(attributeKey, booleanValue); |
|||
} else if (doubleValue != null) { |
|||
kvEntry = new DoubleDataEntry(attributeKey, doubleValue); |
|||
} else if (longValue != null) { |
|||
kvEntry = new LongDataEntry(attributeKey, longValue); |
|||
} |
|||
return new BaseAttributeKvEntry(kvEntry, lastUpdateTs); |
|||
} |
|||
} |
|||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue