29 changed files with 1119 additions and 246 deletions
@ -0,0 +1,40 @@ |
|||||
|
/** |
||||
|
* 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.common.data; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
import org.thingsboard.server.common.data.id.EntityViewId; |
||||
|
|
||||
|
@Data |
||||
|
public class EntityViewInfo extends EntityView { |
||||
|
|
||||
|
private String customerTitle; |
||||
|
private boolean customerIsPublic; |
||||
|
|
||||
|
public EntityViewInfo() { |
||||
|
super(); |
||||
|
} |
||||
|
|
||||
|
public EntityViewInfo(EntityViewId entityViewId) { |
||||
|
super(entityViewId); |
||||
|
} |
||||
|
|
||||
|
public EntityViewInfo(EntityView entityView, String customerTitle, boolean customerIsPublic) { |
||||
|
super(entityView); |
||||
|
this.customerTitle = customerTitle; |
||||
|
this.customerIsPublic = customerIsPublic; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,40 @@ |
|||||
|
/** |
||||
|
* 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.common.data.asset; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
import org.thingsboard.server.common.data.id.AssetId; |
||||
|
|
||||
|
@Data |
||||
|
public class AssetInfo extends Asset { |
||||
|
|
||||
|
private String customerTitle; |
||||
|
private boolean customerIsPublic; |
||||
|
|
||||
|
public AssetInfo() { |
||||
|
super(); |
||||
|
} |
||||
|
|
||||
|
public AssetInfo(AssetId assetId) { |
||||
|
super(assetId); |
||||
|
} |
||||
|
|
||||
|
public AssetInfo(Asset asset, String customerTitle, boolean customerIsPublic) { |
||||
|
super(asset); |
||||
|
this.customerTitle = customerTitle; |
||||
|
this.customerIsPublic = customerIsPublic; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,129 @@ |
|||||
|
/** |
||||
|
* 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.sql; |
||||
|
|
||||
|
import com.datastax.driver.core.utils.UUIDs; |
||||
|
import com.fasterxml.jackson.databind.JsonNode; |
||||
|
import lombok.Data; |
||||
|
import lombok.EqualsAndHashCode; |
||||
|
import org.hibernate.annotations.Type; |
||||
|
import org.hibernate.annotations.TypeDef; |
||||
|
import org.thingsboard.server.common.data.UUIDConverter; |
||||
|
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.BaseSqlEntity; |
||||
|
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.Column; |
||||
|
import javax.persistence.Entity; |
||||
|
import javax.persistence.MappedSuperclass; |
||||
|
import javax.persistence.Table; |
||||
|
|
||||
|
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.SEARCH_TEXT_PROPERTY; |
||||
|
|
||||
|
@Data |
||||
|
@EqualsAndHashCode(callSuper = true) |
||||
|
@TypeDef(name = "json", typeClass = JsonStringType.class) |
||||
|
@MappedSuperclass |
||||
|
public abstract class AbstractAssetEntity<T extends Asset> extends BaseSqlEntity<T> implements SearchTextEntity<T> { |
||||
|
|
||||
|
@Column(name = ASSET_TENANT_ID_PROPERTY) |
||||
|
private String tenantId; |
||||
|
|
||||
|
@Column(name = ASSET_CUSTOMER_ID_PROPERTY) |
||||
|
private String 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 AbstractAssetEntity() { |
||||
|
super(); |
||||
|
} |
||||
|
|
||||
|
public AbstractAssetEntity(Asset asset) { |
||||
|
if (asset.getId() != null) { |
||||
|
this.setId(asset.getId().getId()); |
||||
|
} |
||||
|
if (asset.getTenantId() != null) { |
||||
|
this.tenantId = UUIDConverter.fromTimeUUID(asset.getTenantId().getId()); |
||||
|
} |
||||
|
if (asset.getCustomerId() != null) { |
||||
|
this.customerId = UUIDConverter.fromTimeUUID(asset.getCustomerId().getId()); |
||||
|
} |
||||
|
this.name = asset.getName(); |
||||
|
this.type = asset.getType(); |
||||
|
this.additionalInfo = asset.getAdditionalInfo(); |
||||
|
} |
||||
|
|
||||
|
public AbstractAssetEntity(AssetEntity assetEntity) { |
||||
|
this.setId(assetEntity.getId()); |
||||
|
this.tenantId = assetEntity.getTenantId(); |
||||
|
this.customerId = assetEntity.getCustomerId(); |
||||
|
this.type = assetEntity.getType(); |
||||
|
this.name = assetEntity.getName(); |
||||
|
this.searchText = assetEntity.getSearchText(); |
||||
|
this.additionalInfo = assetEntity.getAdditionalInfo(); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public String getSearchTextSource() { |
||||
|
return name; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void setSearchText(String searchText) { |
||||
|
this.searchText = searchText; |
||||
|
} |
||||
|
|
||||
|
public String getSearchText() { |
||||
|
return searchText; |
||||
|
} |
||||
|
|
||||
|
protected Asset toAsset() { |
||||
|
Asset asset = new Asset(new AssetId(UUIDConverter.fromString(id))); |
||||
|
asset.setCreatedTime(UUIDs.unixTimestamp(UUIDConverter.fromString(id))); |
||||
|
if (tenantId != null) { |
||||
|
asset.setTenantId(new TenantId(UUIDConverter.fromString(tenantId))); |
||||
|
} |
||||
|
if (customerId != null) { |
||||
|
asset.setCustomerId(new CustomerId(UUIDConverter.fromString(customerId))); |
||||
|
} |
||||
|
asset.setName(name); |
||||
|
asset.setType(type); |
||||
|
asset.setAdditionalInfo(additionalInfo); |
||||
|
return asset; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,172 @@ |
|||||
|
/** |
||||
|
* 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.sql; |
||||
|
|
||||
|
import com.datastax.driver.core.utils.UUIDs; |
||||
|
import com.fasterxml.jackson.databind.JsonNode; |
||||
|
import com.fasterxml.jackson.databind.ObjectMapper; |
||||
|
import lombok.Data; |
||||
|
import lombok.EqualsAndHashCode; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.hibernate.annotations.Type; |
||||
|
import org.hibernate.annotations.TypeDef; |
||||
|
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.BaseSqlEntity; |
||||
|
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.io.IOException; |
||||
|
|
||||
|
import static org.thingsboard.server.dao.model.ModelConstants.ENTITY_TYPE_PROPERTY; |
||||
|
|
||||
|
/** |
||||
|
* Created by Victor Basanets on 8/30/2017. |
||||
|
*/ |
||||
|
|
||||
|
@Data |
||||
|
@EqualsAndHashCode(callSuper = true) |
||||
|
@TypeDef(name = "json", typeClass = JsonStringType.class) |
||||
|
@MappedSuperclass |
||||
|
@Slf4j |
||||
|
public abstract class AbstractEntityViewEntity<T extends EntityView> extends BaseSqlEntity<T> implements SearchTextEntity<T> { |
||||
|
|
||||
|
@Column(name = ModelConstants.ENTITY_VIEW_ENTITY_ID_PROPERTY) |
||||
|
private String entityId; |
||||
|
|
||||
|
@Enumerated(EnumType.STRING) |
||||
|
@Column(name = ENTITY_TYPE_PROPERTY) |
||||
|
private EntityType entityType; |
||||
|
|
||||
|
@Column(name = ModelConstants.ENTITY_VIEW_TENANT_ID_PROPERTY) |
||||
|
private String tenantId; |
||||
|
|
||||
|
@Column(name = ModelConstants.ENTITY_VIEW_CUSTOMER_ID_PROPERTY) |
||||
|
private String customerId; |
||||
|
|
||||
|
@Column(name = ModelConstants.DEVICE_TYPE_PROPERTY) |
||||
|
private String type; |
||||
|
|
||||
|
@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 AbstractEntityViewEntity() { |
||||
|
super(); |
||||
|
} |
||||
|
|
||||
|
public AbstractEntityViewEntity(EntityView entityView) { |
||||
|
if (entityView.getId() != null) { |
||||
|
this.setId(entityView.getId().getId()); |
||||
|
} |
||||
|
if (entityView.getEntityId() != null) { |
||||
|
this.entityId = toString(entityView.getEntityId().getId()); |
||||
|
this.entityType = entityView.getEntityId().getEntityType(); |
||||
|
} |
||||
|
if (entityView.getTenantId() != null) { |
||||
|
this.tenantId = toString(entityView.getTenantId().getId()); |
||||
|
} |
||||
|
if (entityView.getCustomerId() != null) { |
||||
|
this.customerId = toString(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(); |
||||
|
} |
||||
|
|
||||
|
public AbstractEntityViewEntity(EntityViewEntity entityViewEntity) { |
||||
|
this.setId(entityViewEntity.getId()); |
||||
|
this.entityId = entityViewEntity.getEntityId(); |
||||
|
this.entityType = entityViewEntity.getEntityType(); |
||||
|
this.tenantId = entityViewEntity.getTenantId(); |
||||
|
this.customerId = entityViewEntity.getCustomerId(); |
||||
|
this.type = entityViewEntity.getType(); |
||||
|
this.name = entityViewEntity.getName(); |
||||
|
this.keys = entityViewEntity.getKeys(); |
||||
|
this.startTs = entityViewEntity.getStartTs(); |
||||
|
this.endTs = entityViewEntity.getEndTs(); |
||||
|
this.searchText = entityViewEntity.getSearchText(); |
||||
|
this.additionalInfo = entityViewEntity.getAdditionalInfo(); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public String getSearchTextSource() { |
||||
|
return name; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void setSearchText(String searchText) { |
||||
|
this.searchText = searchText; |
||||
|
} |
||||
|
|
||||
|
protected EntityView toEntityView() { |
||||
|
EntityView entityView = new EntityView(new EntityViewId(getId())); |
||||
|
entityView.setCreatedTime(UUIDs.unixTimestamp(getId())); |
||||
|
|
||||
|
if (entityId != null) { |
||||
|
entityView.setEntityId(EntityIdFactory.getByTypeAndId(entityType.name(), toUUID(entityId).toString())); |
||||
|
} |
||||
|
if (tenantId != null) { |
||||
|
entityView.setTenantId(new TenantId(toUUID(tenantId))); |
||||
|
} |
||||
|
if (customerId != null) { |
||||
|
entityView.setCustomerId(new CustomerId(toUUID(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; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,58 @@ |
|||||
|
/** |
||||
|
* 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.sql; |
||||
|
|
||||
|
import com.fasterxml.jackson.databind.JsonNode; |
||||
|
import lombok.Data; |
||||
|
import lombok.EqualsAndHashCode; |
||||
|
import org.thingsboard.server.common.data.asset.AssetInfo; |
||||
|
|
||||
|
import java.util.HashMap; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
@Data |
||||
|
@EqualsAndHashCode(callSuper = true) |
||||
|
public class AssetInfoEntity extends AbstractAssetEntity<AssetInfo> { |
||||
|
|
||||
|
public static final Map<String,String> assetInfoColumnMap = new HashMap<>(); |
||||
|
static { |
||||
|
assetInfoColumnMap.put("customerTitle", "c.title"); |
||||
|
} |
||||
|
|
||||
|
private String customerTitle; |
||||
|
private boolean customerIsPublic; |
||||
|
|
||||
|
public AssetInfoEntity() { |
||||
|
super(); |
||||
|
} |
||||
|
|
||||
|
public AssetInfoEntity(AssetEntity assetEntity, |
||||
|
String customerTitle, |
||||
|
Object customerAdditionalInfo) { |
||||
|
super(assetEntity); |
||||
|
this.customerTitle = customerTitle; |
||||
|
if (customerAdditionalInfo != null && ((JsonNode)customerAdditionalInfo).has("isPublic")) { |
||||
|
this.customerIsPublic = ((JsonNode)customerAdditionalInfo).get("isPublic").asBoolean(); |
||||
|
} else { |
||||
|
this.customerIsPublic = false; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public AssetInfo toData() { |
||||
|
return new AssetInfo(super.toAsset(), customerTitle, customerIsPublic); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,58 @@ |
|||||
|
/** |
||||
|
* 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.sql; |
||||
|
|
||||
|
import com.fasterxml.jackson.databind.JsonNode; |
||||
|
import lombok.Data; |
||||
|
import lombok.EqualsAndHashCode; |
||||
|
import org.thingsboard.server.common.data.EntityViewInfo; |
||||
|
|
||||
|
import java.util.HashMap; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
@Data |
||||
|
@EqualsAndHashCode(callSuper = true) |
||||
|
public class EntityViewInfoEntity extends AbstractEntityViewEntity<EntityViewInfo> { |
||||
|
|
||||
|
public static final Map<String,String> entityViewInfoColumnMap = new HashMap<>(); |
||||
|
static { |
||||
|
entityViewInfoColumnMap.put("customerTitle", "c.title"); |
||||
|
} |
||||
|
|
||||
|
private String customerTitle; |
||||
|
private boolean customerIsPublic; |
||||
|
|
||||
|
public EntityViewInfoEntity() { |
||||
|
super(); |
||||
|
} |
||||
|
|
||||
|
public EntityViewInfoEntity(EntityViewEntity entityViewEntity, |
||||
|
String customerTitle, |
||||
|
Object customerAdditionalInfo) { |
||||
|
super(entityViewEntity); |
||||
|
this.customerTitle = customerTitle; |
||||
|
if (customerAdditionalInfo != null && ((JsonNode)customerAdditionalInfo).has("isPublic")) { |
||||
|
this.customerIsPublic = ((JsonNode)customerAdditionalInfo).get("isPublic").asBoolean(); |
||||
|
} else { |
||||
|
this.customerIsPublic = false; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public EntityViewInfo toData() { |
||||
|
return new EntityViewInfo(super.toEntityView(), customerTitle, customerIsPublic); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue