52 changed files with 2242 additions and 50 deletions
@ -0,0 +1,42 @@ |
|||
-- |
|||
-- Copyright © 2016-2020 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. |
|||
-- |
|||
|
|||
ALTER TABLE device ADD COLUMN device_profile_id uuid; |
|||
ALTER TABLE tenant ADD COLUMN tenant_profile_id uuid; |
|||
|
|||
CREATE TABLE IF NOT EXISTS device_profile ( |
|||
id uuid NOT NULL CONSTRAINT device_profile_pkey PRIMARY KEY, |
|||
created_time bigint NOT NULL, |
|||
name varchar(255), |
|||
profile_data varchar, |
|||
description varchar, |
|||
search_text varchar(255), |
|||
default boolean, |
|||
tenant_id uuid, |
|||
default_rule_chain_id uuid |
|||
); |
|||
|
|||
CREATE TABLE IF NOT EXISTS tenant_profile ( |
|||
id uuid NOT NULL CONSTRAINT tenant_profile_pkey PRIMARY KEY, |
|||
created_time bigint NOT NULL, |
|||
name varchar(255), |
|||
profile_data varchar, |
|||
description varchar, |
|||
search_text varchar(255), |
|||
default boolean, |
|||
isolated_tb_core boolean, |
|||
isolated_tb_rule_engine boolean |
|||
); |
|||
@ -0,0 +1,49 @@ |
|||
/** |
|||
* Copyright © 2016-2020 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 org.thingsboard.server.common.data.DeviceProfile; |
|||
import org.thingsboard.server.common.data.EntityInfo; |
|||
import org.thingsboard.server.common.data.id.DeviceProfileId; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.page.PageData; |
|||
import org.thingsboard.server.common.data.page.PageLink; |
|||
|
|||
public interface DeviceProfileService { |
|||
|
|||
DeviceProfile findDeviceProfileById(TenantId tenantId, DeviceProfileId deviceProfileId); |
|||
|
|||
EntityInfo findDeviceProfileInfoById(TenantId tenantId, DeviceProfileId deviceProfileId); |
|||
|
|||
DeviceProfile saveDeviceProfile(DeviceProfile deviceProfile); |
|||
|
|||
void deleteDeviceProfile(TenantId tenantId, DeviceProfileId deviceProfileId); |
|||
|
|||
PageData<DeviceProfile> findDeviceProfiles(TenantId tenantId, PageLink pageLink); |
|||
|
|||
PageData<EntityInfo> findDeviceProfileInfos(TenantId tenantId, PageLink pageLink); |
|||
|
|||
DeviceProfile createDefaultDeviceProfile(TenantId tenantId); |
|||
|
|||
DeviceProfile findDefaultDeviceProfile(TenantId tenantId); |
|||
|
|||
EntityInfo findDefaultDeviceProfileInfo(TenantId tenantId); |
|||
|
|||
boolean setDefaultDeviceProfile(TenantId tenantId, DeviceProfileId deviceProfileId); |
|||
|
|||
void deleteDeviceProfilesByTenantId(TenantId tenantId); |
|||
|
|||
} |
|||
@ -0,0 +1,49 @@ |
|||
/** |
|||
* Copyright © 2016-2020 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 org.thingsboard.server.common.data.EntityInfo; |
|||
import org.thingsboard.server.common.data.TenantProfile; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.id.TenantProfileId; |
|||
import org.thingsboard.server.common.data.page.PageData; |
|||
import org.thingsboard.server.common.data.page.PageLink; |
|||
|
|||
public interface TenantProfileService { |
|||
|
|||
TenantProfile findTenantProfileById(TenantId tenantId, TenantProfileId tenantProfileId); |
|||
|
|||
EntityInfo findTenantProfileInfoById(TenantId tenantId, TenantProfileId tenantProfileId); |
|||
|
|||
TenantProfile saveTenantProfile(TenantId tenantId, TenantProfile tenantProfile); |
|||
|
|||
void deleteTenantProfile(TenantId tenantId, TenantProfileId tenantProfileId); |
|||
|
|||
PageData<TenantProfile> findTenantProfiles(TenantId tenantId, PageLink pageLink); |
|||
|
|||
PageData<EntityInfo> findTenantProfileInfos(TenantId tenantId, PageLink pageLink); |
|||
|
|||
TenantProfile findOrCreateDefaultTenantProfile(TenantId tenantId); |
|||
|
|||
TenantProfile findDefaultTenantProfile(TenantId tenantId); |
|||
|
|||
EntityInfo findDefaultTenantProfileInfo(TenantId tenantId); |
|||
|
|||
boolean setDefaultTenantProfile(TenantId tenantId, TenantProfileId tenantProfileId); |
|||
|
|||
void deleteTenantProfiles(TenantId tenantId); |
|||
|
|||
} |
|||
@ -0,0 +1,78 @@ |
|||
/** |
|||
* Copyright © 2016-2020 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 com.fasterxml.jackson.annotation.JsonIgnore; |
|||
import com.fasterxml.jackson.databind.JsonNode; |
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
import org.thingsboard.server.common.data.id.DeviceProfileId; |
|||
import org.thingsboard.server.common.data.id.RuleChainId; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
|
|||
import static org.thingsboard.server.common.data.SearchTextBasedWithAdditionalInfo.getJson; |
|||
import static org.thingsboard.server.common.data.SearchTextBasedWithAdditionalInfo.setJson; |
|||
|
|||
@Data |
|||
@EqualsAndHashCode(callSuper = true) |
|||
public class DeviceProfile extends SearchTextBased<DeviceProfileId> implements HasName { |
|||
|
|||
private TenantId tenantId; |
|||
private String name; |
|||
private String description; |
|||
private boolean isDefault; |
|||
private RuleChainId defaultRuleChainId; |
|||
private transient JsonNode profileData; |
|||
@JsonIgnore |
|||
private byte[] profileDataBytes; |
|||
|
|||
public DeviceProfile() { |
|||
super(); |
|||
} |
|||
|
|||
public DeviceProfile(DeviceProfileId deviceProfileId) { |
|||
super(deviceProfileId); |
|||
} |
|||
|
|||
public DeviceProfile(DeviceProfile deviceProfile) { |
|||
super(deviceProfile); |
|||
this.tenantId = deviceProfile.getTenantId(); |
|||
this.name = deviceProfile.getName(); |
|||
this.description = deviceProfile.getDescription(); |
|||
this.isDefault = deviceProfile.isDefault(); |
|||
this.defaultRuleChainId = deviceProfile.getDefaultRuleChainId(); |
|||
this.setProfileData(deviceProfile.getProfileData()); |
|||
} |
|||
|
|||
@Override |
|||
public String getSearchText() { |
|||
return getName(); |
|||
} |
|||
|
|||
@Override |
|||
public String getName() { |
|||
return name; |
|||
} |
|||
|
|||
public JsonNode getProfileData() { |
|||
return getJson(() -> profileData, () -> profileDataBytes); |
|||
} |
|||
|
|||
public void setProfileData(JsonNode data) { |
|||
setJson(data, json -> this.profileData = json, bytes -> this.profileDataBytes = bytes); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,41 @@ |
|||
/** |
|||
* Copyright © 2016-2020 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.EntityId; |
|||
import org.thingsboard.server.common.data.id.EntityIdFactory; |
|||
import org.thingsboard.server.common.data.id.HasId; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
@Data |
|||
public class EntityInfo implements HasId<EntityId>, HasName { |
|||
|
|||
private final EntityId id; |
|||
private final String name; |
|||
|
|||
public EntityInfo(EntityId id, String name) { |
|||
this.id = id; |
|||
this.name = name; |
|||
} |
|||
|
|||
public EntityInfo(UUID uuid, String type, String name) { |
|||
this.id = EntityIdFactory.getByTypeAndUuid(type, uuid); |
|||
this.name = name; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,76 @@ |
|||
/** |
|||
* Copyright © 2016-2020 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 com.fasterxml.jackson.annotation.JsonIgnore; |
|||
import com.fasterxml.jackson.databind.JsonNode; |
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
import org.thingsboard.server.common.data.id.TenantProfileId; |
|||
|
|||
import static org.thingsboard.server.common.data.SearchTextBasedWithAdditionalInfo.getJson; |
|||
import static org.thingsboard.server.common.data.SearchTextBasedWithAdditionalInfo.setJson; |
|||
|
|||
@Data |
|||
@EqualsAndHashCode(callSuper = true) |
|||
public class TenantProfile extends SearchTextBased<TenantProfileId> implements HasName { |
|||
|
|||
private String name; |
|||
private String description; |
|||
private boolean isDefault; |
|||
private boolean isolatedTbCore; |
|||
private boolean isolatedTbRuleEngine; |
|||
private transient JsonNode profileData; |
|||
@JsonIgnore |
|||
private byte[] profileDataBytes; |
|||
|
|||
public TenantProfile() { |
|||
super(); |
|||
} |
|||
|
|||
public TenantProfile(TenantProfileId tenantProfileId) { |
|||
super(tenantProfileId); |
|||
} |
|||
|
|||
public TenantProfile(TenantProfile tenantProfile) { |
|||
super(tenantProfile); |
|||
this.name = tenantProfile.getName(); |
|||
this.description = tenantProfile.getDescription(); |
|||
this.isDefault = tenantProfile.isDefault(); |
|||
this.isolatedTbCore = tenantProfile.isIsolatedTbCore(); |
|||
this.isolatedTbRuleEngine = tenantProfile.isIsolatedTbRuleEngine(); |
|||
this.setProfileData(tenantProfile.getProfileData()); |
|||
} |
|||
|
|||
@Override |
|||
public String getSearchText() { |
|||
return getName(); |
|||
} |
|||
|
|||
@Override |
|||
public String getName() { |
|||
return name; |
|||
} |
|||
|
|||
public JsonNode getProfileData() { |
|||
return getJson(() -> profileData, () -> profileDataBytes); |
|||
} |
|||
|
|||
public void setProfileData(JsonNode data) { |
|||
setJson(data, json -> this.profileData = json, bytes -> this.profileDataBytes = bytes); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,43 @@ |
|||
/** |
|||
* Copyright © 2016-2020 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.id; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonCreator; |
|||
import com.fasterxml.jackson.annotation.JsonIgnore; |
|||
import com.fasterxml.jackson.annotation.JsonProperty; |
|||
import org.thingsboard.server.common.data.EntityType; |
|||
|
|||
public class DeviceProfileId extends UUIDBased implements EntityId { |
|||
|
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
@JsonCreator |
|||
public DeviceProfileId(@JsonProperty("id") UUID id) { |
|||
super(id); |
|||
} |
|||
|
|||
public static DeviceProfileId fromString(String deviceProfileId) { |
|||
return new DeviceProfileId(UUID.fromString(deviceProfileId)); |
|||
} |
|||
|
|||
@JsonIgnore |
|||
@Override |
|||
public EntityType getEntityType() { |
|||
return EntityType.DEVICE_PROFILE; |
|||
} |
|||
} |
|||
@ -0,0 +1,24 @@ |
|||
/** |
|||
* Copyright © 2016-2020 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.id; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
public interface HasId<I extends HasUUID> extends Serializable { |
|||
|
|||
I getId(); |
|||
|
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
/** |
|||
* Copyright © 2016-2020 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.id; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
public interface HasUUID { |
|||
|
|||
UUID getId(); |
|||
|
|||
} |
|||
@ -0,0 +1,43 @@ |
|||
/** |
|||
* Copyright © 2016-2020 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.id; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonCreator; |
|||
import com.fasterxml.jackson.annotation.JsonIgnore; |
|||
import com.fasterxml.jackson.annotation.JsonProperty; |
|||
import org.thingsboard.server.common.data.EntityType; |
|||
|
|||
public class TenantProfileId extends UUIDBased implements EntityId { |
|||
|
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
@JsonCreator |
|||
public TenantProfileId(@JsonProperty("id") UUID id) { |
|||
super(id); |
|||
} |
|||
|
|||
public static TenantProfileId fromString(String tenantProfileId) { |
|||
return new TenantProfileId(UUID.fromString(tenantProfileId)); |
|||
} |
|||
|
|||
@JsonIgnore |
|||
@Override |
|||
public EntityType getEntityType() { |
|||
return EntityType.TENANT_PROFILE; |
|||
} |
|||
} |
|||
@ -0,0 +1,40 @@ |
|||
/** |
|||
* Copyright © 2016-2020 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 org.thingsboard.server.common.data.DeviceProfile; |
|||
import org.thingsboard.server.common.data.EntityInfo; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.page.PageData; |
|||
import org.thingsboard.server.common.data.page.PageLink; |
|||
import org.thingsboard.server.dao.Dao; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
public interface DeviceProfileDao extends Dao<DeviceProfile> { |
|||
|
|||
EntityInfo findDeviceProfileInfoById(TenantId tenantId, UUID deviceProfileId); |
|||
|
|||
DeviceProfile save(TenantId tenantId, DeviceProfile deviceProfile); |
|||
|
|||
PageData<DeviceProfile> findDeviceProfiles(TenantId tenantId, PageLink pageLink); |
|||
|
|||
PageData<EntityInfo> findDeviceProfileInfos(TenantId tenantId, PageLink pageLink); |
|||
|
|||
DeviceProfile findDefaultDeviceProfile(TenantId tenantId); |
|||
|
|||
EntityInfo findDefaultDeviceProfileInfo(TenantId tenantId); |
|||
} |
|||
@ -0,0 +1,202 @@ |
|||
/** |
|||
* Copyright © 2016-2020 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 lombok.extern.slf4j.Slf4j; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
import org.hibernate.exception.ConstraintViolationException; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
import org.thingsboard.server.common.data.DeviceProfile; |
|||
import org.thingsboard.server.common.data.EntityInfo; |
|||
import org.thingsboard.server.common.data.Tenant; |
|||
import org.thingsboard.server.common.data.id.DeviceProfileId; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.page.PageData; |
|||
import org.thingsboard.server.common.data.page.PageLink; |
|||
import org.thingsboard.server.dao.entity.AbstractEntityService; |
|||
import org.thingsboard.server.dao.exception.DataValidationException; |
|||
import org.thingsboard.server.dao.service.DataValidator; |
|||
import org.thingsboard.server.dao.service.PaginatedRemover; |
|||
import org.thingsboard.server.dao.service.Validator; |
|||
import org.thingsboard.server.dao.tenant.TenantDao; |
|||
import org.thingsboard.server.dao.util.mapping.JacksonUtil; |
|||
|
|||
import static org.thingsboard.server.dao.service.Validator.validateId; |
|||
|
|||
@Service |
|||
@Slf4j |
|||
public class DeviceProfileServiceImpl extends AbstractEntityService implements DeviceProfileService { |
|||
|
|||
private static final String INCORRECT_TENANT_ID = "Incorrect tenantId "; |
|||
private static final String INCORRECT_DEVICE_PROFILE_ID = "Incorrect deviceProfileId "; |
|||
|
|||
@Autowired |
|||
private DeviceProfileDao deviceProfileDao; |
|||
|
|||
@Autowired |
|||
private TenantDao tenantDao; |
|||
|
|||
@Override |
|||
public DeviceProfile findDeviceProfileById(TenantId tenantId, DeviceProfileId deviceProfileId) { |
|||
log.trace("Executing findDeviceProfileById [{}]", deviceProfileId); |
|||
Validator.validateId(deviceProfileId, INCORRECT_DEVICE_PROFILE_ID + deviceProfileId); |
|||
return deviceProfileDao.findById(tenantId, deviceProfileId.getId()); |
|||
} |
|||
|
|||
@Override |
|||
public EntityInfo findDeviceProfileInfoById(TenantId tenantId, DeviceProfileId deviceProfileId) { |
|||
log.trace("Executing findDeviceProfileById [{}]", deviceProfileId); |
|||
Validator.validateId(deviceProfileId, INCORRECT_DEVICE_PROFILE_ID + deviceProfileId); |
|||
return deviceProfileDao.findDeviceProfileInfoById(tenantId, deviceProfileId.getId()); |
|||
} |
|||
|
|||
@Override |
|||
public DeviceProfile saveDeviceProfile(DeviceProfile deviceProfile) { |
|||
log.trace("Executing saveDeviceProfile [{}]", deviceProfile); |
|||
deviceProfileValidator.validate(deviceProfile, DeviceProfile::getTenantId); |
|||
DeviceProfile savedDeviceProfile; |
|||
try { |
|||
savedDeviceProfile = deviceProfileDao.save(deviceProfile.getTenantId(), deviceProfile); |
|||
} catch (Exception t) { |
|||
ConstraintViolationException e = extractConstraintViolationException(t).orElse(null); |
|||
if (e != null && e.getConstraintName() != null && e.getConstraintName().equalsIgnoreCase("device_profile_name_unq_key")) { |
|||
throw new DataValidationException("Device profile with such name already exists!"); |
|||
} else { |
|||
throw t; |
|||
} |
|||
} |
|||
return savedDeviceProfile; |
|||
} |
|||
|
|||
@Override |
|||
public void deleteDeviceProfile(TenantId tenantId, DeviceProfileId deviceProfileId) { |
|||
log.trace("Executing deleteDeviceProfile [{}]", deviceProfileId); |
|||
Validator.validateId(deviceProfileId, INCORRECT_DEVICE_PROFILE_ID + deviceProfileId); |
|||
deleteEntityRelations(tenantId, deviceProfileId); |
|||
deviceProfileDao.removeById(tenantId, deviceProfileId.getId()); |
|||
} |
|||
|
|||
@Override |
|||
public PageData<DeviceProfile> findDeviceProfiles(TenantId tenantId, PageLink pageLink) { |
|||
log.trace("Executing findDeviceProfiles tenantId [{}], pageLink [{}]", tenantId, pageLink); |
|||
validateId(tenantId, INCORRECT_TENANT_ID + tenantId); |
|||
Validator.validatePageLink(pageLink); |
|||
return deviceProfileDao.findDeviceProfiles(tenantId, pageLink); |
|||
} |
|||
|
|||
@Override |
|||
public PageData<EntityInfo> findDeviceProfileInfos(TenantId tenantId, PageLink pageLink) { |
|||
log.trace("Executing findDeviceProfileInfos tenantId [{}], pageLink [{}]", tenantId, pageLink); |
|||
validateId(tenantId, INCORRECT_TENANT_ID + tenantId); |
|||
Validator.validatePageLink(pageLink); |
|||
return deviceProfileDao.findDeviceProfileInfos(tenantId, pageLink); |
|||
} |
|||
|
|||
@Override |
|||
public DeviceProfile createDefaultDeviceProfile(TenantId tenantId) { |
|||
log.trace("Executing createDefaultDeviceProfile tenantId [{}]", tenantId); |
|||
validateId(tenantId, INCORRECT_TENANT_ID + tenantId); |
|||
DeviceProfile deviceProfile = new DeviceProfile(); |
|||
deviceProfile.setTenantId(tenantId); |
|||
deviceProfile.setDefault(true); |
|||
deviceProfile.setName("Default"); |
|||
deviceProfile.setDescription("Default device profile"); |
|||
deviceProfile.setProfileData(JacksonUtil.OBJECT_MAPPER.createObjectNode()); |
|||
return deviceProfileDao.save(tenantId, deviceProfile); |
|||
} |
|||
|
|||
@Override |
|||
public DeviceProfile findDefaultDeviceProfile(TenantId tenantId) { |
|||
log.trace("Executing findDefaultDeviceProfile tenantId [{}]", tenantId); |
|||
validateId(tenantId, INCORRECT_TENANT_ID + tenantId); |
|||
return deviceProfileDao.findDefaultDeviceProfile(tenantId); |
|||
} |
|||
|
|||
@Override |
|||
public EntityInfo findDefaultDeviceProfileInfo(TenantId tenantId) { |
|||
log.trace("Executing findDefaultDeviceProfileInfo tenantId [{}]", tenantId); |
|||
validateId(tenantId, INCORRECT_TENANT_ID + tenantId); |
|||
return deviceProfileDao.findDefaultDeviceProfileInfo(tenantId); |
|||
} |
|||
|
|||
@Override |
|||
public boolean setDefaultDeviceProfile(TenantId tenantId, DeviceProfileId deviceProfileId) { |
|||
log.trace("Executing setDefaultDeviceProfile [{}]", deviceProfileId); |
|||
Validator.validateId(deviceProfileId, INCORRECT_DEVICE_PROFILE_ID + deviceProfileId); |
|||
DeviceProfile deviceProfile = deviceProfileDao.findById(tenantId, deviceProfileId.getId()); |
|||
if (!deviceProfile.isDefault()) { |
|||
deviceProfile.setDefault(true); |
|||
DeviceProfile previousDefaultDeviceProfile = findDefaultDeviceProfile(tenantId); |
|||
if (previousDefaultDeviceProfile == null) { |
|||
deviceProfileDao.save(tenantId, deviceProfile); |
|||
return true; |
|||
} else if (!previousDefaultDeviceProfile.getId().equals(deviceProfile.getId())) { |
|||
previousDefaultDeviceProfile.setDefault(false); |
|||
deviceProfileDao.save(tenantId, previousDefaultDeviceProfile); |
|||
deviceProfileDao.save(tenantId, deviceProfile); |
|||
return true; |
|||
} |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
@Override |
|||
public void deleteDeviceProfilesByTenantId(TenantId tenantId) { |
|||
log.trace("Executing deleteDeviceProfilesByTenantId, tenantId [{}]", tenantId); |
|||
validateId(tenantId, INCORRECT_TENANT_ID + tenantId); |
|||
tenantDeviceProfilesRemover.removeEntities(tenantId, tenantId); |
|||
} |
|||
|
|||
private DataValidator<DeviceProfile> deviceProfileValidator = |
|||
new DataValidator<DeviceProfile>() { |
|||
@Override |
|||
protected void validateDataImpl(TenantId tenantId, DeviceProfile deviceProfile) { |
|||
if (StringUtils.isEmpty(deviceProfile.getName())) { |
|||
throw new DataValidationException("Device profile name should be specified!"); |
|||
} |
|||
if (deviceProfile.getTenantId() == null) { |
|||
throw new DataValidationException("Device profile should be assigned to tenant!"); |
|||
} else { |
|||
Tenant tenant = tenantDao.findById(deviceProfile.getTenantId(), deviceProfile.getTenantId().getId()); |
|||
if (tenant == null) { |
|||
throw new DataValidationException("Device profile is referencing to non-existent tenant!"); |
|||
} |
|||
} |
|||
if (deviceProfile.isDefault()) { |
|||
DeviceProfile defaultDeviceProfile = findDefaultDeviceProfile(tenantId); |
|||
if (defaultDeviceProfile != null && !defaultDeviceProfile.getId().equals(deviceProfile.getId())) { |
|||
throw new DataValidationException("Another default device profile is present in scope of current tenant!"); |
|||
} |
|||
} |
|||
} |
|||
}; |
|||
|
|||
private PaginatedRemover<TenantId, DeviceProfile> tenantDeviceProfilesRemover = |
|||
new PaginatedRemover<TenantId, DeviceProfile>() { |
|||
|
|||
@Override |
|||
protected PageData<DeviceProfile> findEntities(TenantId tenantId, TenantId id, PageLink pageLink) { |
|||
return deviceProfileDao.findDeviceProfiles(id, pageLink); |
|||
} |
|||
|
|||
@Override |
|||
protected void removeEntity(TenantId tenantId, DeviceProfile entity) { |
|||
deleteDeviceProfile(tenantId, new DeviceProfileId(entity.getUuidId())); |
|||
} |
|||
}; |
|||
|
|||
} |
|||
@ -0,0 +1,117 @@ |
|||
/** |
|||
* Copyright © 2016-2020 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.hibernate.annotations.Type; |
|||
import org.hibernate.annotations.TypeDef; |
|||
import org.thingsboard.server.common.data.DeviceProfile; |
|||
import org.thingsboard.server.common.data.id.DeviceProfileId; |
|||
import org.thingsboard.server.common.data.id.RuleChainId; |
|||
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.Table; |
|||
import java.util.UUID; |
|||
|
|||
@Data |
|||
@EqualsAndHashCode(callSuper = true) |
|||
@Entity |
|||
@TypeDef(name = "json", typeClass = JsonStringType.class) |
|||
@Table(name = ModelConstants.DEVICE_PROFILE_COLUMN_FAMILY_NAME) |
|||
public final class DeviceProfileEntity extends BaseSqlEntity<DeviceProfile> implements SearchTextEntity<DeviceProfile> { |
|||
|
|||
@Column(name = ModelConstants.DEVICE_PROFILE_TENANT_ID_PROPERTY) |
|||
private UUID tenantId; |
|||
|
|||
@Column(name = ModelConstants.DEVICE_PROFILE_NAME_PROPERTY) |
|||
private String name; |
|||
|
|||
@Column(name = ModelConstants.DEVICE_PROFILE_DESCRIPTION_PROPERTY) |
|||
private String description; |
|||
|
|||
@Column(name = ModelConstants.SEARCH_TEXT_PROPERTY) |
|||
private String searchText; |
|||
|
|||
@Column(name = ModelConstants.DEVICE_PROFILE_IS_DEFAULT_PROPERTY) |
|||
private boolean isDefault; |
|||
|
|||
@Column(name = ModelConstants.DEVICE_PROFILE_DEFAULT_RULE_CHAIN_ID_PROPERTY, columnDefinition = "uuid") |
|||
private UUID defaultRuleChainId; |
|||
|
|||
@Type(type = "json") |
|||
@Column(name = ModelConstants.DEVICE_PROFILE_PROFILE_DATA_PROPERTY) |
|||
private JsonNode profileData; |
|||
|
|||
public DeviceProfileEntity() { |
|||
super(); |
|||
} |
|||
|
|||
public DeviceProfileEntity(DeviceProfile deviceProfile) { |
|||
if (deviceProfile.getId() != null) { |
|||
this.setUuid(deviceProfile.getId().getId()); |
|||
} |
|||
if (deviceProfile.getTenantId() != null) { |
|||
this.tenantId = deviceProfile.getTenantId().getId(); |
|||
} |
|||
this.setCreatedTime(deviceProfile.getCreatedTime()); |
|||
this.name = deviceProfile.getName(); |
|||
this.description = deviceProfile.getDescription(); |
|||
this.isDefault = deviceProfile.isDefault(); |
|||
this.profileData = deviceProfile.getProfileData(); |
|||
if (deviceProfile.getDefaultRuleChainId() != null) { |
|||
this.defaultRuleChainId = deviceProfile.getDefaultRuleChainId().getId(); |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public String getSearchTextSource() { |
|||
return name; |
|||
} |
|||
|
|||
@Override |
|||
public void setSearchText(String searchText) { |
|||
this.searchText = searchText; |
|||
} |
|||
|
|||
public String getSearchText() { |
|||
return searchText; |
|||
} |
|||
|
|||
@Override |
|||
public DeviceProfile toData() { |
|||
DeviceProfile deviceProfile = new DeviceProfile(new DeviceProfileId(this.getUuid())); |
|||
deviceProfile.setCreatedTime(createdTime); |
|||
if (tenantId != null) { |
|||
deviceProfile.setTenantId(new TenantId(tenantId)); |
|||
} |
|||
deviceProfile.setName(name); |
|||
deviceProfile.setDescription(description); |
|||
deviceProfile.setDefault(isDefault); |
|||
deviceProfile.setProfileData(profileData); |
|||
if (defaultRuleChainId != null) { |
|||
deviceProfile.setDefaultRuleChainId(new RuleChainId(defaultRuleChainId)); |
|||
} |
|||
return deviceProfile; |
|||
} |
|||
} |
|||
@ -0,0 +1,108 @@ |
|||
/** |
|||
* Copyright © 2016-2020 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.hibernate.annotations.Type; |
|||
import org.hibernate.annotations.TypeDef; |
|||
import org.thingsboard.server.common.data.TenantProfile; |
|||
import org.thingsboard.server.common.data.id.TenantProfileId; |
|||
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.Table; |
|||
|
|||
@Data |
|||
@EqualsAndHashCode(callSuper = true) |
|||
@Entity |
|||
@TypeDef(name = "json", typeClass = JsonStringType.class) |
|||
@Table(name = ModelConstants.TENANT_PROFILE_COLUMN_FAMILY_NAME) |
|||
public final class TenantProfileEntity extends BaseSqlEntity<TenantProfile> implements SearchTextEntity<TenantProfile> { |
|||
|
|||
@Column(name = ModelConstants.TENANT_PROFILE_NAME_PROPERTY) |
|||
private String name; |
|||
|
|||
@Column(name = ModelConstants.TENANT_PROFILE_DESCRIPTION_PROPERTY) |
|||
private String description; |
|||
|
|||
@Column(name = ModelConstants.SEARCH_TEXT_PROPERTY) |
|||
private String searchText; |
|||
|
|||
@Column(name = ModelConstants.TENANT_PROFILE_IS_DEFAULT_PROPERTY) |
|||
private boolean isDefault; |
|||
|
|||
@Column(name = ModelConstants.TENANT_PROFILE_ISOLATED_TB_CORE) |
|||
private boolean isolatedTbCore; |
|||
|
|||
@Column(name = ModelConstants.TENANT_PROFILE_ISOLATED_TB_RULE_ENGINE) |
|||
private boolean isolatedTbRuleEngine; |
|||
|
|||
@Type(type = "json") |
|||
@Column(name = ModelConstants.TENANT_PROFILE_PROFILE_DATA_PROPERTY) |
|||
private JsonNode profileData; |
|||
|
|||
public TenantProfileEntity() { |
|||
super(); |
|||
} |
|||
|
|||
public TenantProfileEntity(TenantProfile tenantProfile) { |
|||
if (tenantProfile.getId() != null) { |
|||
this.setUuid(tenantProfile.getId().getId()); |
|||
} |
|||
this.setCreatedTime(tenantProfile.getCreatedTime()); |
|||
this.name = tenantProfile.getName(); |
|||
this.description = tenantProfile.getDescription(); |
|||
this.isDefault = tenantProfile.isDefault(); |
|||
this.isolatedTbCore = tenantProfile.isIsolatedTbCore(); |
|||
this.isolatedTbRuleEngine = tenantProfile.isIsolatedTbRuleEngine(); |
|||
this.profileData = tenantProfile.getProfileData(); |
|||
} |
|||
|
|||
@Override |
|||
public String getSearchTextSource() { |
|||
return name; |
|||
} |
|||
|
|||
@Override |
|||
public void setSearchText(String searchText) { |
|||
this.searchText = searchText; |
|||
} |
|||
|
|||
public String getSearchText() { |
|||
return searchText; |
|||
} |
|||
|
|||
@Override |
|||
public TenantProfile toData() { |
|||
TenantProfile tenantProfile = new TenantProfile(new TenantProfileId(this.getUuid())); |
|||
tenantProfile.setCreatedTime(createdTime); |
|||
tenantProfile.setName(name); |
|||
tenantProfile.setDescription(description); |
|||
tenantProfile.setDefault(isDefault); |
|||
tenantProfile.setIsolatedTbCore(isolatedTbCore); |
|||
tenantProfile.setIsolatedTbRuleEngine(isolatedTbRuleEngine); |
|||
tenantProfile.setProfileData(profileData); |
|||
return tenantProfile; |
|||
} |
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,56 @@ |
|||
/** |
|||
* Copyright © 2016-2020 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.sql.device; |
|||
|
|||
import org.springframework.data.domain.Page; |
|||
import org.springframework.data.domain.Pageable; |
|||
import org.springframework.data.jpa.repository.Query; |
|||
import org.springframework.data.repository.PagingAndSortingRepository; |
|||
import org.springframework.data.repository.query.Param; |
|||
import org.thingsboard.server.common.data.EntityInfo; |
|||
import org.thingsboard.server.dao.model.sql.DeviceProfileEntity; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
public interface DeviceProfileRepository extends PagingAndSortingRepository<DeviceProfileEntity, UUID> { |
|||
|
|||
@Query("SELECT new org.thingsboard.server.common.data.EntityInfo(d.id, 'DEVICE_PROFILE', d.name) " + |
|||
"FROM DeviceProfileEntity d " + |
|||
"WHERE d.id = :deviceProfileId") |
|||
EntityInfo findDeviceProfileInfoById(@Param("deviceProfileId") UUID deviceProfileId); |
|||
|
|||
@Query("SELECT d FROM DeviceProfileEntity d WHERE " + |
|||
"d.tenantId = :tenantId AND LOWER(d.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))") |
|||
Page<DeviceProfileEntity> findDeviceProfiles(@Param("tenantId") UUID tenantId, |
|||
@Param("textSearch") String textSearch, |
|||
Pageable pageable); |
|||
|
|||
@Query("SELECT new org.thingsboard.server.common.data.EntityInfo(d.id, 'DEVICE_PROFILE', d.name) " + |
|||
"FROM DeviceProfileEntity d WHERE " + |
|||
"d.tenantId = :tenantId AND LOWER(d.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))") |
|||
Page<EntityInfo> findDeviceProfileInfos(@Param("tenantId") UUID tenantId, |
|||
@Param("textSearch") String textSearch, |
|||
Pageable pageable); |
|||
|
|||
@Query("SELECT d FROM DeviceProfileEntity d " + |
|||
"WHERE d.tenantId = :tenantId AND d.isDefault = true") |
|||
DeviceProfileEntity findByDefaultTrueAndTenantId(@Param("tenantId") UUID tenantId); |
|||
|
|||
@Query("SELECT new org.thingsboard.server.common.data.EntityInfo(d.id, 'DEVICE_PROFILE', d.name) " + |
|||
"FROM DeviceProfileEntity d " + |
|||
"WHERE d.tenantId = :tenantId AND d.isDefault = true") |
|||
EntityInfo findDefaultDeviceProfileInfo(@Param("tenantId") UUID tenantId); |
|||
} |
|||
@ -0,0 +1,83 @@ |
|||
/** |
|||
* Copyright © 2016-2020 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.sql.device; |
|||
|
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.data.repository.CrudRepository; |
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.common.data.DeviceProfile; |
|||
import org.thingsboard.server.common.data.EntityInfo; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.page.PageData; |
|||
import org.thingsboard.server.common.data.page.PageLink; |
|||
import org.thingsboard.server.dao.DaoUtil; |
|||
import org.thingsboard.server.dao.device.DeviceProfileDao; |
|||
import org.thingsboard.server.dao.model.sql.DeviceProfileEntity; |
|||
import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao; |
|||
|
|||
import java.util.Objects; |
|||
import java.util.UUID; |
|||
|
|||
@Component |
|||
public class JpaDeviceProfileDao extends JpaAbstractSearchTextDao<DeviceProfileEntity, DeviceProfile> implements DeviceProfileDao { |
|||
|
|||
@Autowired |
|||
private DeviceProfileRepository deviceProfileRepository; |
|||
|
|||
@Override |
|||
protected Class<DeviceProfileEntity> getEntityClass() { |
|||
return DeviceProfileEntity.class; |
|||
} |
|||
|
|||
@Override |
|||
protected CrudRepository<DeviceProfileEntity, UUID> getCrudRepository() { |
|||
return deviceProfileRepository; |
|||
} |
|||
|
|||
@Override |
|||
public EntityInfo findDeviceProfileInfoById(TenantId tenantId, UUID deviceProfileId) { |
|||
return deviceProfileRepository.findDeviceProfileInfoById(deviceProfileId); |
|||
} |
|||
|
|||
@Override |
|||
public PageData<DeviceProfile> findDeviceProfiles(TenantId tenantId, PageLink pageLink) { |
|||
return DaoUtil.toPageData( |
|||
deviceProfileRepository.findDeviceProfiles( |
|||
tenantId.getId(), |
|||
Objects.toString(pageLink.getTextSearch(), ""), |
|||
DaoUtil.toPageable(pageLink))); |
|||
} |
|||
|
|||
@Override |
|||
public PageData<EntityInfo> findDeviceProfileInfos(TenantId tenantId, PageLink pageLink) { |
|||
return DaoUtil.pageToPageData( |
|||
deviceProfileRepository.findDeviceProfileInfos( |
|||
tenantId.getId(), |
|||
Objects.toString(pageLink.getTextSearch(), ""), |
|||
DaoUtil.toPageable(pageLink))); |
|||
} |
|||
|
|||
@Override |
|||
public DeviceProfile findDefaultDeviceProfile(TenantId tenantId) { |
|||
return DaoUtil.getData(deviceProfileRepository.findByDefaultTrueAndTenantId(tenantId.getId())); |
|||
} |
|||
|
|||
@Override |
|||
public EntityInfo findDefaultDeviceProfileInfo(TenantId tenantId) { |
|||
return deviceProfileRepository.findDefaultDeviceProfileInfo(tenantId.getId()); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,80 @@ |
|||
/** |
|||
* Copyright © 2016-2020 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.sql.tenant; |
|||
|
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.data.repository.CrudRepository; |
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.common.data.EntityInfo; |
|||
import org.thingsboard.server.common.data.TenantProfile; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.page.PageData; |
|||
import org.thingsboard.server.common.data.page.PageLink; |
|||
import org.thingsboard.server.dao.DaoUtil; |
|||
import org.thingsboard.server.dao.model.sql.TenantProfileEntity; |
|||
import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao; |
|||
import org.thingsboard.server.dao.tenant.TenantProfileDao; |
|||
|
|||
import java.util.Objects; |
|||
import java.util.UUID; |
|||
|
|||
@Component |
|||
public class JpaTenantProfileDao extends JpaAbstractSearchTextDao<TenantProfileEntity, TenantProfile> implements TenantProfileDao { |
|||
|
|||
@Autowired |
|||
private TenantProfileRepository tenantProfileRepository; |
|||
|
|||
@Override |
|||
protected Class<TenantProfileEntity> getEntityClass() { |
|||
return TenantProfileEntity.class; |
|||
} |
|||
|
|||
@Override |
|||
protected CrudRepository<TenantProfileEntity, UUID> getCrudRepository() { |
|||
return tenantProfileRepository; |
|||
} |
|||
|
|||
@Override |
|||
public EntityInfo findTenantProfileInfoById(TenantId tenantId, UUID tenantProfileId) { |
|||
return tenantProfileRepository.findTenantProfileInfoById(tenantProfileId); |
|||
} |
|||
|
|||
@Override |
|||
public PageData<TenantProfile> findTenantProfiles(TenantId tenantId, PageLink pageLink) { |
|||
return DaoUtil.toPageData( |
|||
tenantProfileRepository.findTenantProfiles( |
|||
Objects.toString(pageLink.getTextSearch(), ""), |
|||
DaoUtil.toPageable(pageLink))); |
|||
} |
|||
|
|||
@Override |
|||
public PageData<EntityInfo> findTenantProfileInfos(TenantId tenantId, PageLink pageLink) { |
|||
return DaoUtil.pageToPageData( |
|||
tenantProfileRepository.findTenantProfileInfos( |
|||
Objects.toString(pageLink.getTextSearch(), ""), |
|||
DaoUtil.toPageable(pageLink))); |
|||
} |
|||
|
|||
@Override |
|||
public TenantProfile findDefaultTenantProfile(TenantId tenantId) { |
|||
return DaoUtil.getData(tenantProfileRepository.findByDefaultTrue()); |
|||
} |
|||
|
|||
@Override |
|||
public EntityInfo findDefaultTenantProfileInfo(TenantId tenantId) { |
|||
return tenantProfileRepository.findDefaultTenantProfileInfo(); |
|||
} |
|||
} |
|||
@ -0,0 +1,54 @@ |
|||
/** |
|||
* Copyright © 2016-2020 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.sql.tenant; |
|||
|
|||
import org.springframework.data.domain.Page; |
|||
import org.springframework.data.domain.Pageable; |
|||
import org.springframework.data.jpa.repository.Query; |
|||
import org.springframework.data.repository.PagingAndSortingRepository; |
|||
import org.springframework.data.repository.query.Param; |
|||
import org.thingsboard.server.common.data.EntityInfo; |
|||
import org.thingsboard.server.dao.model.sql.TenantProfileEntity; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
public interface TenantProfileRepository extends PagingAndSortingRepository<TenantProfileEntity, UUID> { |
|||
|
|||
@Query("SELECT new org.thingsboard.server.common.data.EntityInfo(t.id, 'TENANT_PROFILE', t.name) " + |
|||
"FROM TenantProfileEntity t " + |
|||
"WHERE t.id = :tenantProfileId") |
|||
EntityInfo findTenantProfileInfoById(@Param("tenantProfileId") UUID tenantProfileId); |
|||
|
|||
@Query("SELECT t FROM TenantProfileEntity t WHERE " + |
|||
"LOWER(t.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))") |
|||
Page<TenantProfileEntity> findTenantProfiles(@Param("textSearch") String textSearch, |
|||
Pageable pageable); |
|||
|
|||
@Query("SELECT new org.thingsboard.server.common.data.EntityInfo(t.id, 'TENANT_PROFILE', t.name) " + |
|||
"FROM TenantProfileEntity t " + |
|||
"WHERE LOWER(t.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))") |
|||
Page<EntityInfo> findTenantProfileInfos(@Param("textSearch") String textSearch, |
|||
Pageable pageable); |
|||
|
|||
@Query("SELECT t FROM TenantProfileEntity t " + |
|||
"WHERE t.isDefault = true") |
|||
TenantProfileEntity findByDefaultTrue(); |
|||
|
|||
@Query("SELECT new org.thingsboard.server.common.data.EntityInfo(t.id, 'TENANT_PROFILE', t.name) " + |
|||
"FROM TenantProfileEntity t " + |
|||
"WHERE t.isDefault = true") |
|||
EntityInfo findDefaultTenantProfileInfo(); |
|||
} |
|||
@ -0,0 +1,40 @@ |
|||
/** |
|||
* Copyright © 2016-2020 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 org.thingsboard.server.common.data.EntityInfo; |
|||
import org.thingsboard.server.common.data.TenantProfile; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.page.PageData; |
|||
import org.thingsboard.server.common.data.page.PageLink; |
|||
import org.thingsboard.server.dao.Dao; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
public interface TenantProfileDao extends Dao<TenantProfile> { |
|||
|
|||
EntityInfo findTenantProfileInfoById(TenantId tenantId, UUID tenantProfileId); |
|||
|
|||
TenantProfile save(TenantId tenantId, TenantProfile tenantProfile); |
|||
|
|||
PageData<TenantProfile> findTenantProfiles(TenantId tenantId, PageLink pageLink); |
|||
|
|||
PageData<EntityInfo> findTenantProfileInfos(TenantId tenantId, PageLink pageLink); |
|||
|
|||
TenantProfile findDefaultTenantProfile(TenantId tenantId); |
|||
|
|||
EntityInfo findDefaultTenantProfileInfo(TenantId tenantId); |
|||
} |
|||
@ -0,0 +1,187 @@ |
|||
/** |
|||
* Copyright © 2016-2020 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.apache.commons.lang3.StringUtils; |
|||
import org.hibernate.exception.ConstraintViolationException; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
import org.thingsboard.server.common.data.EntityInfo; |
|||
import org.thingsboard.server.common.data.TenantProfile; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.id.TenantProfileId; |
|||
import org.thingsboard.server.common.data.page.PageData; |
|||
import org.thingsboard.server.common.data.page.PageLink; |
|||
import org.thingsboard.server.dao.entity.AbstractEntityService; |
|||
import org.thingsboard.server.dao.exception.DataValidationException; |
|||
import org.thingsboard.server.dao.service.DataValidator; |
|||
import org.thingsboard.server.dao.service.PaginatedRemover; |
|||
import org.thingsboard.server.dao.service.Validator; |
|||
import org.thingsboard.server.dao.util.mapping.JacksonUtil; |
|||
|
|||
import static org.thingsboard.server.dao.service.Validator.validateId; |
|||
|
|||
@Service |
|||
@Slf4j |
|||
public class TenantProfileServiceImpl extends AbstractEntityService implements TenantProfileService { |
|||
|
|||
private static final String INCORRECT_TENANT_PROFILE_ID = "Incorrect tenantProfileId "; |
|||
|
|||
@Autowired |
|||
private TenantProfileDao tenantProfileDao; |
|||
|
|||
@Override |
|||
public TenantProfile findTenantProfileById(TenantId tenantId, TenantProfileId tenantProfileId) { |
|||
log.trace("Executing findTenantProfileById [{}]", tenantProfileId); |
|||
Validator.validateId(tenantProfileId, INCORRECT_TENANT_PROFILE_ID + tenantProfileId); |
|||
return tenantProfileDao.findById(tenantId, tenantProfileId.getId()); |
|||
} |
|||
|
|||
@Override |
|||
public EntityInfo findTenantProfileInfoById(TenantId tenantId, TenantProfileId tenantProfileId) { |
|||
log.trace("Executing findTenantProfileInfoById [{}]", tenantProfileId); |
|||
Validator.validateId(tenantProfileId, INCORRECT_TENANT_PROFILE_ID + tenantProfileId); |
|||
return tenantProfileDao.findTenantProfileInfoById(tenantId, tenantProfileId.getId()); |
|||
} |
|||
|
|||
@Override |
|||
public TenantProfile saveTenantProfile(TenantId tenantId, TenantProfile tenantProfile) { |
|||
log.trace("Executing saveTenantProfile [{}]", tenantProfile); |
|||
tenantProfileValidator.validate(tenantProfile, (tenantProfile1) -> TenantId.SYS_TENANT_ID); |
|||
TenantProfile savedTenantProfile; |
|||
try { |
|||
savedTenantProfile = tenantProfileDao.save(tenantId, tenantProfile); |
|||
} catch (Exception t) { |
|||
ConstraintViolationException e = extractConstraintViolationException(t).orElse(null); |
|||
if (e != null && e.getConstraintName() != null && e.getConstraintName().equalsIgnoreCase("tenant_profile_name_unq_key")) { |
|||
throw new DataValidationException("Tenant profile with such name already exists!"); |
|||
} else { |
|||
throw t; |
|||
} |
|||
} |
|||
return savedTenantProfile; |
|||
} |
|||
|
|||
@Override |
|||
public void deleteTenantProfile(TenantId tenantId, TenantProfileId tenantProfileId) { |
|||
log.trace("Executing deleteTenantProfile [{}]", tenantProfileId); |
|||
validateId(tenantId, INCORRECT_TENANT_PROFILE_ID + tenantProfileId); |
|||
deleteEntityRelations(tenantId, tenantProfileId); |
|||
tenantProfileDao.removeById(tenantId, tenantProfileId.getId()); |
|||
} |
|||
|
|||
@Override |
|||
public PageData<TenantProfile> findTenantProfiles(TenantId tenantId, PageLink pageLink) { |
|||
log.trace("Executing findTenantProfiles pageLink [{}]", pageLink); |
|||
Validator.validatePageLink(pageLink); |
|||
return tenantProfileDao.findTenantProfiles(tenantId, pageLink); |
|||
} |
|||
|
|||
@Override |
|||
public PageData<EntityInfo> findTenantProfileInfos(TenantId tenantId, PageLink pageLink) { |
|||
log.trace("Executing findTenantProfileInfos pageLink [{}]", pageLink); |
|||
Validator.validatePageLink(pageLink); |
|||
return tenantProfileDao.findTenantProfileInfos(tenantId, pageLink); |
|||
} |
|||
|
|||
@Override |
|||
public TenantProfile findOrCreateDefaultTenantProfile(TenantId tenantId) { |
|||
log.trace("Executing findOrCreateDefaultTenantProfile"); |
|||
TenantProfile defaultTenantProfile = findDefaultTenantProfile(tenantId); |
|||
if (defaultTenantProfile == null) { |
|||
defaultTenantProfile = new TenantProfile(); |
|||
defaultTenantProfile.setDefault(true); |
|||
defaultTenantProfile.setName("Default"); |
|||
defaultTenantProfile.setProfileData(JacksonUtil.OBJECT_MAPPER.createObjectNode()); |
|||
defaultTenantProfile.setDescription("Default tenant profile"); |
|||
defaultTenantProfile.setIsolatedTbCore(false); |
|||
defaultTenantProfile.setIsolatedTbRuleEngine(false); |
|||
defaultTenantProfile = saveTenantProfile(tenantId, defaultTenantProfile); |
|||
} |
|||
return defaultTenantProfile; |
|||
} |
|||
|
|||
@Override |
|||
public TenantProfile findDefaultTenantProfile(TenantId tenantId) { |
|||
log.trace("Executing findDefaultTenantProfile"); |
|||
return tenantProfileDao.findDefaultTenantProfile(tenantId); |
|||
} |
|||
|
|||
@Override |
|||
public EntityInfo findDefaultTenantProfileInfo(TenantId tenantId) { |
|||
log.trace("Executing findDefaultTenantProfileInfo"); |
|||
return tenantProfileDao.findDefaultTenantProfileInfo(tenantId); |
|||
} |
|||
|
|||
@Override |
|||
public boolean setDefaultTenantProfile(TenantId tenantId, TenantProfileId tenantProfileId) { |
|||
log.trace("Executing setDefaultTenantProfile [{}]", tenantProfileId); |
|||
validateId(tenantId, INCORRECT_TENANT_PROFILE_ID + tenantProfileId); |
|||
TenantProfile tenantProfile = tenantProfileDao.findById(tenantId, tenantProfileId.getId()); |
|||
if (!tenantProfile.isDefault()) { |
|||
tenantProfile.setDefault(true); |
|||
TenantProfile previousDefaultTenantProfile = findDefaultTenantProfile(tenantId); |
|||
if (previousDefaultTenantProfile == null) { |
|||
tenantProfileDao.save(tenantId, tenantProfile); |
|||
return true; |
|||
} else if (!previousDefaultTenantProfile.getId().equals(tenantProfile.getId())) { |
|||
previousDefaultTenantProfile.setDefault(false); |
|||
tenantProfileDao.save(tenantId, previousDefaultTenantProfile); |
|||
tenantProfileDao.save(tenantId, tenantProfile); |
|||
return true; |
|||
} |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
@Override |
|||
public void deleteTenantProfiles(TenantId tenantId) { |
|||
log.trace("Executing deleteTenantProfiles"); |
|||
tenantProfilesRemover.removeEntities(tenantId, null); |
|||
} |
|||
|
|||
private DataValidator<TenantProfile> tenantProfileValidator = |
|||
new DataValidator<TenantProfile>() { |
|||
@Override |
|||
protected void validateDataImpl(TenantId tenantId, TenantProfile tenantProfile) { |
|||
if (StringUtils.isEmpty(tenantProfile.getName())) { |
|||
throw new DataValidationException("Tenant profile name should be specified!"); |
|||
} |
|||
if (tenantProfile.isDefault()) { |
|||
TenantProfile defaultTenantProfile = findDefaultTenantProfile(tenantId); |
|||
if (defaultTenantProfile != null && !defaultTenantProfile.getId().equals(tenantProfile.getId())) { |
|||
throw new DataValidationException("Another default tenant profile is present!"); |
|||
} |
|||
} |
|||
} |
|||
}; |
|||
|
|||
private PaginatedRemover<String, TenantProfile> tenantProfilesRemover = |
|||
new PaginatedRemover<String, TenantProfile>() { |
|||
|
|||
@Override |
|||
protected PageData<TenantProfile> findEntities(TenantId tenantId, String id, PageLink pageLink) { |
|||
return tenantProfileDao.findTenantProfiles(tenantId, pageLink); |
|||
} |
|||
|
|||
@Override |
|||
protected void removeEntity(TenantId tenantId, TenantProfile entity) { |
|||
deleteTenantProfile(tenantId, new TenantProfileId(entity.getUuidId())); |
|||
} |
|||
}; |
|||
|
|||
} |
|||
@ -0,0 +1,262 @@ |
|||
/** |
|||
* Copyright © 2016-2020 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; |
|||
|
|||
import com.datastax.oss.driver.api.core.uuid.Uuids; |
|||
import org.junit.After; |
|||
import org.junit.Assert; |
|||
import org.junit.Before; |
|||
import org.junit.Test; |
|||
import org.thingsboard.server.common.data.DeviceProfile; |
|||
import org.thingsboard.server.common.data.EntityInfo; |
|||
import org.thingsboard.server.common.data.Tenant; |
|||
import org.thingsboard.server.common.data.id.RuleChainId; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.page.PageData; |
|||
import org.thingsboard.server.common.data.page.PageLink; |
|||
import org.thingsboard.server.dao.exception.DataValidationException; |
|||
import org.thingsboard.server.dao.util.mapping.JacksonUtil; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.Collections; |
|||
import java.util.List; |
|||
import java.util.stream.Collectors; |
|||
|
|||
public class BaseDeviceProfileServiceTest extends AbstractServiceTest { |
|||
|
|||
private IdComparator<DeviceProfile> idComparator = new IdComparator<>(); |
|||
private IdComparator<EntityInfo> deviceProfileInfoIdComparator = new IdComparator<>(); |
|||
|
|||
private TenantId tenantId; |
|||
|
|||
@Before |
|||
public void before() { |
|||
Tenant tenant = new Tenant(); |
|||
tenant.setTitle("My tenant"); |
|||
Tenant savedTenant = tenantService.saveTenant(tenant); |
|||
Assert.assertNotNull(savedTenant); |
|||
tenantId = savedTenant.getId(); |
|||
} |
|||
|
|||
@After |
|||
public void after() { |
|||
tenantService.deleteTenant(tenantId); |
|||
} |
|||
|
|||
@Test |
|||
public void testSaveDeviceProfile() { |
|||
DeviceProfile deviceProfile = this.createDeviceProfile("Device Profile"); |
|||
DeviceProfile savedDeviceProfile = deviceProfileService.saveDeviceProfile(deviceProfile); |
|||
Assert.assertNotNull(savedDeviceProfile); |
|||
Assert.assertNotNull(savedDeviceProfile.getId()); |
|||
Assert.assertTrue(savedDeviceProfile.getCreatedTime() > 0); |
|||
Assert.assertEquals(deviceProfile.getName(), savedDeviceProfile.getName()); |
|||
Assert.assertEquals(deviceProfile.getDescription(), savedDeviceProfile.getDescription()); |
|||
Assert.assertEquals(deviceProfile.getProfileData(), savedDeviceProfile.getProfileData()); |
|||
Assert.assertEquals(deviceProfile.isDefault(), savedDeviceProfile.isDefault()); |
|||
Assert.assertEquals(deviceProfile.getDefaultRuleChainId(), savedDeviceProfile.getDefaultRuleChainId()); |
|||
savedDeviceProfile.setName("New device profile"); |
|||
deviceProfileService.saveDeviceProfile(savedDeviceProfile); |
|||
DeviceProfile foundDeviceProfile = deviceProfileService.findDeviceProfileById(tenantId, savedDeviceProfile.getId()); |
|||
Assert.assertEquals(foundDeviceProfile.getName(), savedDeviceProfile.getName()); |
|||
|
|||
deviceProfileService.deleteDeviceProfile(tenantId, savedDeviceProfile.getId()); |
|||
} |
|||
|
|||
@Test |
|||
public void testFindDeviceProfileById() { |
|||
DeviceProfile deviceProfile = this.createDeviceProfile("Device Profile"); |
|||
DeviceProfile savedDeviceProfile = deviceProfileService.saveDeviceProfile(deviceProfile); |
|||
DeviceProfile foundDeviceProfile = deviceProfileService.findDeviceProfileById(tenantId, savedDeviceProfile.getId()); |
|||
Assert.assertNotNull(foundDeviceProfile); |
|||
Assert.assertEquals(savedDeviceProfile, foundDeviceProfile); |
|||
deviceProfileService.deleteDeviceProfile(tenantId, savedDeviceProfile.getId()); |
|||
} |
|||
|
|||
@Test |
|||
public void testFindDeviceProfileInfoById() { |
|||
DeviceProfile deviceProfile = this.createDeviceProfile("Device Profile"); |
|||
DeviceProfile savedDeviceProfile = deviceProfileService.saveDeviceProfile(deviceProfile); |
|||
EntityInfo foundDeviceProfileInfo = deviceProfileService.findDeviceProfileInfoById(tenantId, savedDeviceProfile.getId()); |
|||
Assert.assertNotNull(foundDeviceProfileInfo); |
|||
Assert.assertEquals(savedDeviceProfile.getId(), foundDeviceProfileInfo.getId()); |
|||
Assert.assertEquals(savedDeviceProfile.getName(), foundDeviceProfileInfo.getName()); |
|||
deviceProfileService.deleteDeviceProfile(tenantId, savedDeviceProfile.getId()); |
|||
} |
|||
|
|||
@Test |
|||
public void testFindDefaultDeviceProfile() { |
|||
DeviceProfile foundDefaultDeviceProfile = deviceProfileService.findDefaultDeviceProfile(tenantId); |
|||
Assert.assertNotNull(foundDefaultDeviceProfile); |
|||
Assert.assertNotNull(foundDefaultDeviceProfile.getId()); |
|||
Assert.assertNotNull(foundDefaultDeviceProfile.getName()); |
|||
} |
|||
|
|||
@Test |
|||
public void testFindDefaultDeviceProfileInfo() { |
|||
EntityInfo foundDefaultDeviceProfileInfo = deviceProfileService.findDefaultDeviceProfileInfo(tenantId); |
|||
Assert.assertNotNull(foundDefaultDeviceProfileInfo.getId()); |
|||
Assert.assertNotNull(foundDefaultDeviceProfileInfo.getName()); |
|||
Assert.assertNotNull(foundDefaultDeviceProfileInfo); |
|||
} |
|||
|
|||
@Test |
|||
public void testSetDefaultDeviceProfile() { |
|||
DeviceProfile deviceProfile1 = this.createDeviceProfile("Device Profile 1"); |
|||
DeviceProfile deviceProfile2 = this.createDeviceProfile("Device Profile 2"); |
|||
|
|||
DeviceProfile savedDeviceProfile1 = deviceProfileService.saveDeviceProfile(deviceProfile1); |
|||
DeviceProfile savedDeviceProfile2 = deviceProfileService.saveDeviceProfile(deviceProfile2); |
|||
|
|||
boolean result = deviceProfileService.setDefaultDeviceProfile(tenantId, savedDeviceProfile1.getId()); |
|||
Assert.assertTrue(result); |
|||
DeviceProfile defaultDeviceProfile = deviceProfileService.findDefaultDeviceProfile(tenantId); |
|||
Assert.assertNotNull(defaultDeviceProfile); |
|||
Assert.assertEquals(savedDeviceProfile1.getId(), defaultDeviceProfile.getId()); |
|||
result = deviceProfileService.setDefaultDeviceProfile(tenantId, savedDeviceProfile2.getId()); |
|||
Assert.assertTrue(result); |
|||
defaultDeviceProfile = deviceProfileService.findDefaultDeviceProfile(tenantId); |
|||
Assert.assertNotNull(defaultDeviceProfile); |
|||
Assert.assertEquals(savedDeviceProfile2.getId(), defaultDeviceProfile.getId()); |
|||
deviceProfileService.deleteDeviceProfile(tenantId, savedDeviceProfile1.getId()); |
|||
deviceProfileService.deleteDeviceProfile(tenantId, savedDeviceProfile2.getId()); |
|||
} |
|||
|
|||
@Test(expected = DataValidationException.class) |
|||
public void testSaveDeviceProfileWithEmptyName() { |
|||
DeviceProfile deviceProfile = new DeviceProfile(); |
|||
deviceProfile.setTenantId(tenantId); |
|||
deviceProfileService.saveDeviceProfile(deviceProfile); |
|||
} |
|||
|
|||
@Test(expected = DataValidationException.class) |
|||
public void testSaveDeviceProfileWithSameName() { |
|||
DeviceProfile deviceProfile = this.createDeviceProfile("Device Profile"); |
|||
deviceProfileService.saveDeviceProfile(deviceProfile); |
|||
DeviceProfile deviceProfile2 = this.createDeviceProfile("Device Profile"); |
|||
deviceProfileService.saveDeviceProfile(deviceProfile2); |
|||
} |
|||
|
|||
@Test |
|||
public void testDeleteDeviceProfile() { |
|||
DeviceProfile deviceProfile = this.createDeviceProfile("Device Profile"); |
|||
DeviceProfile savedDeviceProfile = deviceProfileService.saveDeviceProfile(deviceProfile); |
|||
deviceProfileService.deleteDeviceProfile(tenantId, savedDeviceProfile.getId()); |
|||
DeviceProfile foundDeviceProfile = deviceProfileService.findDeviceProfileById(tenantId, savedDeviceProfile.getId()); |
|||
Assert.assertNull(foundDeviceProfile); |
|||
} |
|||
|
|||
@Test |
|||
public void testFindDeviceProfiles() { |
|||
|
|||
List<DeviceProfile> deviceProfiles = new ArrayList<>(); |
|||
PageLink pageLink = new PageLink(17); |
|||
PageData<DeviceProfile> pageData = deviceProfileService.findDeviceProfiles(tenantId, pageLink); |
|||
Assert.assertFalse(pageData.hasNext()); |
|||
Assert.assertEquals(1, pageData.getTotalElements()); |
|||
deviceProfiles.addAll(pageData.getData()); |
|||
|
|||
for (int i=0;i<28;i++) { |
|||
DeviceProfile deviceProfile = this.createDeviceProfile("Device Profile"+i); |
|||
deviceProfiles.add(deviceProfileService.saveDeviceProfile(deviceProfile)); |
|||
} |
|||
|
|||
List<DeviceProfile> loadedDeviceProfiles = new ArrayList<>(); |
|||
pageLink = new PageLink(17); |
|||
do { |
|||
pageData = deviceProfileService.findDeviceProfiles(tenantId, pageLink); |
|||
loadedDeviceProfiles.addAll(pageData.getData()); |
|||
if (pageData.hasNext()) { |
|||
pageLink = pageLink.nextPageLink(); |
|||
} |
|||
} while (pageData.hasNext()); |
|||
|
|||
Collections.sort(deviceProfiles, idComparator); |
|||
Collections.sort(loadedDeviceProfiles, idComparator); |
|||
|
|||
Assert.assertEquals(deviceProfiles, loadedDeviceProfiles); |
|||
|
|||
for (DeviceProfile deviceProfile : loadedDeviceProfiles) { |
|||
if (!deviceProfile.isDefault()) { |
|||
deviceProfileService.deleteDeviceProfile(tenantId, deviceProfile.getId()); |
|||
} |
|||
} |
|||
|
|||
pageLink = new PageLink(17); |
|||
pageData = deviceProfileService.findDeviceProfiles(tenantId, pageLink); |
|||
Assert.assertFalse(pageData.hasNext()); |
|||
Assert.assertEquals(1, pageData.getTotalElements()); |
|||
} |
|||
|
|||
@Test |
|||
public void testFindDeviceProfileInfos() { |
|||
|
|||
List<DeviceProfile> deviceProfiles = new ArrayList<>(); |
|||
PageLink pageLink = new PageLink(17); |
|||
PageData<DeviceProfile> deviceProfilePageData = deviceProfileService.findDeviceProfiles(tenantId, pageLink); |
|||
Assert.assertFalse(deviceProfilePageData.hasNext()); |
|||
Assert.assertEquals(1, deviceProfilePageData.getTotalElements()); |
|||
deviceProfiles.addAll(deviceProfilePageData.getData()); |
|||
|
|||
for (int i=0;i<28;i++) { |
|||
DeviceProfile deviceProfile = this.createDeviceProfile("Device Profile"+i); |
|||
deviceProfiles.add(deviceProfileService.saveDeviceProfile(deviceProfile)); |
|||
} |
|||
|
|||
List<EntityInfo> loadedDeviceProfileInfos = new ArrayList<>(); |
|||
pageLink = new PageLink(17); |
|||
PageData<EntityInfo> pageData; |
|||
do { |
|||
pageData = deviceProfileService.findDeviceProfileInfos(tenantId, pageLink); |
|||
loadedDeviceProfileInfos.addAll(pageData.getData()); |
|||
if (pageData.hasNext()) { |
|||
pageLink = pageLink.nextPageLink(); |
|||
} |
|||
} while (pageData.hasNext()); |
|||
|
|||
|
|||
Collections.sort(deviceProfiles, idComparator); |
|||
Collections.sort(loadedDeviceProfileInfos, deviceProfileInfoIdComparator); |
|||
|
|||
List<EntityInfo> deviceProfileInfos = deviceProfiles.stream().map(deviceProfile -> new EntityInfo(deviceProfile.getId(), |
|||
deviceProfile.getName())).collect(Collectors.toList()); |
|||
|
|||
Assert.assertEquals(deviceProfileInfos, loadedDeviceProfileInfos); |
|||
|
|||
for (DeviceProfile deviceProfile : deviceProfiles) { |
|||
if (!deviceProfile.isDefault()) { |
|||
deviceProfileService.deleteDeviceProfile(tenantId, deviceProfile.getId()); |
|||
} |
|||
} |
|||
|
|||
pageLink = new PageLink(17); |
|||
pageData = deviceProfileService.findDeviceProfileInfos(tenantId, pageLink); |
|||
Assert.assertFalse(pageData.hasNext()); |
|||
Assert.assertEquals(1, pageData.getTotalElements()); |
|||
} |
|||
|
|||
private DeviceProfile createDeviceProfile(String name) { |
|||
DeviceProfile deviceProfile = new DeviceProfile(); |
|||
deviceProfile.setTenantId(tenantId); |
|||
deviceProfile.setName(name); |
|||
deviceProfile.setDescription(name + " Test"); |
|||
deviceProfile.setProfileData(JacksonUtil.OBJECT_MAPPER.createObjectNode()); |
|||
deviceProfile.setDefault(false); |
|||
deviceProfile.setDefaultRuleChainId(new RuleChainId(Uuids.timeBased())); |
|||
return deviceProfile; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,248 @@ |
|||
/** |
|||
* Copyright © 2016-2020 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; |
|||
|
|||
import org.junit.After; |
|||
import org.junit.Assert; |
|||
import org.junit.Test; |
|||
import org.thingsboard.server.common.data.EntityInfo; |
|||
import org.thingsboard.server.common.data.TenantProfile; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.id.TenantProfileId; |
|||
import org.thingsboard.server.common.data.page.PageData; |
|||
import org.thingsboard.server.common.data.page.PageLink; |
|||
import org.thingsboard.server.dao.exception.DataValidationException; |
|||
import org.thingsboard.server.dao.util.mapping.JacksonUtil; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.Collections; |
|||
import java.util.List; |
|||
import java.util.stream.Collectors; |
|||
|
|||
public class BaseTenantProfileServiceTest extends AbstractServiceTest { |
|||
|
|||
private IdComparator<TenantProfile> idComparator = new IdComparator<>(); |
|||
private IdComparator<EntityInfo> tenantProfileInfoIdComparator = new IdComparator<>(); |
|||
|
|||
@After |
|||
public void after() { |
|||
tenantProfileService.deleteTenantProfiles(TenantId.SYS_TENANT_ID); |
|||
} |
|||
|
|||
@Test |
|||
public void testSaveTenantProfile() { |
|||
TenantProfile tenantProfile = this.createTenantProfile("Tenant Profile"); |
|||
TenantProfile savedTenantProfile = tenantProfileService.saveTenantProfile(TenantId.SYS_TENANT_ID, tenantProfile); |
|||
Assert.assertNotNull(savedTenantProfile); |
|||
Assert.assertNotNull(savedTenantProfile.getId()); |
|||
Assert.assertTrue(savedTenantProfile.getCreatedTime() > 0); |
|||
Assert.assertEquals(tenantProfile.getName(), savedTenantProfile.getName()); |
|||
Assert.assertEquals(tenantProfile.getDescription(), savedTenantProfile.getDescription()); |
|||
Assert.assertEquals(tenantProfile.getProfileData(), savedTenantProfile.getProfileData()); |
|||
Assert.assertEquals(tenantProfile.isDefault(), savedTenantProfile.isDefault()); |
|||
Assert.assertEquals(tenantProfile.isIsolatedTbCore(), savedTenantProfile.isIsolatedTbCore()); |
|||
Assert.assertEquals(tenantProfile.isIsolatedTbRuleEngine(), savedTenantProfile.isIsolatedTbRuleEngine()); |
|||
|
|||
savedTenantProfile.setName("New tenant profile"); |
|||
tenantProfileService.saveTenantProfile(TenantId.SYS_TENANT_ID, savedTenantProfile); |
|||
TenantProfile foundTenantProfile = tenantProfileService.findTenantProfileById(TenantId.SYS_TENANT_ID, savedTenantProfile.getId()); |
|||
Assert.assertEquals(foundTenantProfile.getName(), savedTenantProfile.getName()); |
|||
|
|||
tenantProfileService.deleteTenantProfile(TenantId.SYS_TENANT_ID, savedTenantProfile.getId()); |
|||
} |
|||
|
|||
@Test |
|||
public void testFindTenantProfileById() { |
|||
TenantProfile tenantProfile = this.createTenantProfile("Tenant Profile"); |
|||
TenantProfile savedTenantProfile = tenantProfileService.saveTenantProfile(TenantId.SYS_TENANT_ID, tenantProfile); |
|||
TenantProfile foundTenantProfile = tenantProfileService.findTenantProfileById(TenantId.SYS_TENANT_ID, savedTenantProfile.getId()); |
|||
Assert.assertNotNull(foundTenantProfile); |
|||
Assert.assertEquals(savedTenantProfile, foundTenantProfile); |
|||
tenantProfileService.deleteTenantProfile(TenantId.SYS_TENANT_ID, savedTenantProfile.getId()); |
|||
} |
|||
|
|||
@Test |
|||
public void testFindTenantProfileInfoById() { |
|||
TenantProfile tenantProfile = this.createTenantProfile("Tenant Profile"); |
|||
TenantProfile savedTenantProfile = tenantProfileService.saveTenantProfile(TenantId.SYS_TENANT_ID, tenantProfile); |
|||
EntityInfo foundTenantProfileInfo = tenantProfileService.findTenantProfileInfoById(TenantId.SYS_TENANT_ID, savedTenantProfile.getId()); |
|||
Assert.assertNotNull(foundTenantProfileInfo); |
|||
Assert.assertEquals(savedTenantProfile.getId(), foundTenantProfileInfo.getId()); |
|||
Assert.assertEquals(savedTenantProfile.getName(), foundTenantProfileInfo.getName()); |
|||
tenantProfileService.deleteTenantProfile(TenantId.SYS_TENANT_ID, savedTenantProfile.getId()); |
|||
} |
|||
|
|||
@Test |
|||
public void testFindDefaultTenantProfile() { |
|||
TenantProfile tenantProfile = this.createTenantProfile("Default Tenant Profile"); |
|||
tenantProfile.setDefault(true); |
|||
TenantProfile savedTenantProfile = tenantProfileService.saveTenantProfile(TenantId.SYS_TENANT_ID, tenantProfile); |
|||
TenantProfile foundDefaultTenantProfile = tenantProfileService.findDefaultTenantProfile(TenantId.SYS_TENANT_ID); |
|||
Assert.assertNotNull(foundDefaultTenantProfile); |
|||
Assert.assertEquals(savedTenantProfile, foundDefaultTenantProfile); |
|||
tenantProfileService.deleteTenantProfile(TenantId.SYS_TENANT_ID, savedTenantProfile.getId()); |
|||
} |
|||
|
|||
@Test |
|||
public void testFindDefaultTenantProfileInfo() { |
|||
TenantProfile tenantProfile = this.createTenantProfile("Default Tenant Profile"); |
|||
tenantProfile.setDefault(true); |
|||
TenantProfile savedTenantProfile = tenantProfileService.saveTenantProfile(TenantId.SYS_TENANT_ID, tenantProfile); |
|||
EntityInfo foundDefaultTenantProfileInfo = tenantProfileService.findDefaultTenantProfileInfo(TenantId.SYS_TENANT_ID); |
|||
Assert.assertNotNull(foundDefaultTenantProfileInfo); |
|||
Assert.assertEquals(savedTenantProfile.getId(), foundDefaultTenantProfileInfo.getId()); |
|||
Assert.assertEquals(savedTenantProfile.getName(), foundDefaultTenantProfileInfo.getName()); |
|||
tenantProfileService.deleteTenantProfile(TenantId.SYS_TENANT_ID, savedTenantProfile.getId()); |
|||
} |
|||
|
|||
@Test |
|||
public void testSetDefaultTenantProfile() { |
|||
TenantProfile tenantProfile1 = this.createTenantProfile("Tenant Profile 1"); |
|||
TenantProfile tenantProfile2 = this.createTenantProfile("Tenant Profile 2"); |
|||
|
|||
TenantProfile savedTenantProfile1 = tenantProfileService.saveTenantProfile(TenantId.SYS_TENANT_ID, tenantProfile1); |
|||
TenantProfile savedTenantProfile2 = tenantProfileService.saveTenantProfile(TenantId.SYS_TENANT_ID, tenantProfile2); |
|||
|
|||
boolean result = tenantProfileService.setDefaultTenantProfile(TenantId.SYS_TENANT_ID, savedTenantProfile1.getId()); |
|||
Assert.assertTrue(result); |
|||
TenantProfile defaultTenantProfile = tenantProfileService.findDefaultTenantProfile(TenantId.SYS_TENANT_ID); |
|||
Assert.assertNotNull(defaultTenantProfile); |
|||
Assert.assertEquals(savedTenantProfile1.getId(), defaultTenantProfile.getId()); |
|||
result = tenantProfileService.setDefaultTenantProfile(TenantId.SYS_TENANT_ID, savedTenantProfile2.getId()); |
|||
Assert.assertTrue(result); |
|||
defaultTenantProfile = tenantProfileService.findDefaultTenantProfile(TenantId.SYS_TENANT_ID); |
|||
Assert.assertNotNull(defaultTenantProfile); |
|||
Assert.assertEquals(savedTenantProfile2.getId(), defaultTenantProfile.getId()); |
|||
tenantProfileService.deleteTenantProfile(TenantId.SYS_TENANT_ID, savedTenantProfile1.getId()); |
|||
tenantProfileService.deleteTenantProfile(TenantId.SYS_TENANT_ID, savedTenantProfile2.getId()); |
|||
} |
|||
|
|||
@Test(expected = DataValidationException.class) |
|||
public void testSaveTenantProfileWithEmptyName() { |
|||
TenantProfile tenantProfile = new TenantProfile(); |
|||
tenantProfileService.saveTenantProfile(TenantId.SYS_TENANT_ID, tenantProfile); |
|||
} |
|||
|
|||
@Test(expected = DataValidationException.class) |
|||
public void testSaveTenantProfileWithSameName() { |
|||
TenantProfile tenantProfile = this.createTenantProfile("Tenant Profile"); |
|||
tenantProfileService.saveTenantProfile(TenantId.SYS_TENANT_ID, tenantProfile); |
|||
TenantProfile tenantProfile2 = this.createTenantProfile("Tenant Profile"); |
|||
tenantProfileService.saveTenantProfile(TenantId.SYS_TENANT_ID, tenantProfile2); |
|||
} |
|||
|
|||
@Test |
|||
public void testDeleteTenantProfile() { |
|||
TenantProfile tenantProfile = this.createTenantProfile("Tenant Profile"); |
|||
TenantProfile savedTenantProfile = tenantProfileService.saveTenantProfile(TenantId.SYS_TENANT_ID, tenantProfile); |
|||
tenantProfileService.deleteTenantProfile(TenantId.SYS_TENANT_ID, savedTenantProfile.getId()); |
|||
TenantProfile foundTenantProfile = tenantProfileService.findTenantProfileById(TenantId.SYS_TENANT_ID, savedTenantProfile.getId()); |
|||
Assert.assertNull(foundTenantProfile); |
|||
} |
|||
|
|||
@Test |
|||
public void testFindTenantProfiles() { |
|||
|
|||
List<TenantProfile> tenantProfiles = new ArrayList<>(); |
|||
PageLink pageLink = new PageLink(17); |
|||
PageData<TenantProfile> pageData = tenantProfileService.findTenantProfiles(TenantId.SYS_TENANT_ID, pageLink); |
|||
Assert.assertFalse(pageData.hasNext()); |
|||
Assert.assertTrue(pageData.getData().isEmpty()); |
|||
tenantProfiles.addAll(pageData.getData()); |
|||
|
|||
for (int i=0;i<28;i++) { |
|||
TenantProfile tenantProfile = this.createTenantProfile("Tenant Profile"+i); |
|||
tenantProfiles.add(tenantProfileService.saveTenantProfile(TenantId.SYS_TENANT_ID, tenantProfile)); |
|||
} |
|||
|
|||
List<TenantProfile> loadedTenantProfiles = new ArrayList<>(); |
|||
pageLink = new PageLink(17); |
|||
do { |
|||
pageData = tenantProfileService.findTenantProfiles(TenantId.SYS_TENANT_ID, pageLink); |
|||
loadedTenantProfiles.addAll(pageData.getData()); |
|||
if (pageData.hasNext()) { |
|||
pageLink = pageLink.nextPageLink(); |
|||
} |
|||
} while (pageData.hasNext()); |
|||
|
|||
Collections.sort(tenantProfiles, idComparator); |
|||
Collections.sort(loadedTenantProfiles, idComparator); |
|||
|
|||
Assert.assertEquals(tenantProfiles, loadedTenantProfiles); |
|||
|
|||
for (TenantProfile tenantProfile : loadedTenantProfiles) { |
|||
tenantProfileService.deleteTenantProfile(TenantId.SYS_TENANT_ID, tenantProfile.getId()); |
|||
} |
|||
|
|||
pageLink = new PageLink(17); |
|||
pageData = tenantProfileService.findTenantProfiles(TenantId.SYS_TENANT_ID, pageLink); |
|||
Assert.assertFalse(pageData.hasNext()); |
|||
Assert.assertTrue(pageData.getData().isEmpty()); |
|||
|
|||
} |
|||
|
|||
@Test |
|||
public void testFindTenantProfileInfos() { |
|||
|
|||
List<TenantProfile> tenantProfiles = new ArrayList<>(); |
|||
|
|||
for (int i=0;i<28;i++) { |
|||
TenantProfile tenantProfile = this.createTenantProfile("Tenant Profile"+i); |
|||
tenantProfiles.add(tenantProfileService.saveTenantProfile(TenantId.SYS_TENANT_ID, tenantProfile)); |
|||
} |
|||
|
|||
List<EntityInfo> loadedTenantProfileInfos = new ArrayList<>(); |
|||
PageLink pageLink = new PageLink(17); |
|||
PageData<EntityInfo> pageData; |
|||
do { |
|||
pageData = tenantProfileService.findTenantProfileInfos(TenantId.SYS_TENANT_ID, pageLink); |
|||
loadedTenantProfileInfos.addAll(pageData.getData()); |
|||
if (pageData.hasNext()) { |
|||
pageLink = pageLink.nextPageLink(); |
|||
} |
|||
} while (pageData.hasNext()); |
|||
|
|||
Collections.sort(tenantProfiles, idComparator); |
|||
Collections.sort(loadedTenantProfileInfos, tenantProfileInfoIdComparator); |
|||
|
|||
List<EntityInfo> tenantProfileInfos = tenantProfiles.stream().map(tenantProfile -> new EntityInfo(tenantProfile.getId(), |
|||
tenantProfile.getName())).collect(Collectors.toList()); |
|||
|
|||
Assert.assertEquals(tenantProfileInfos, loadedTenantProfileInfos); |
|||
|
|||
for (EntityInfo tenantProfile : loadedTenantProfileInfos) { |
|||
tenantProfileService.deleteTenantProfile(TenantId.SYS_TENANT_ID, new TenantProfileId(tenantProfile.getId().getId())); |
|||
} |
|||
|
|||
pageLink = new PageLink(17); |
|||
pageData = tenantProfileService.findTenantProfileInfos(TenantId.SYS_TENANT_ID, pageLink); |
|||
Assert.assertFalse(pageData.hasNext()); |
|||
Assert.assertTrue(pageData.getData().isEmpty()); |
|||
|
|||
} |
|||
|
|||
private TenantProfile createTenantProfile(String name) { |
|||
TenantProfile tenantProfile = new TenantProfile(); |
|||
tenantProfile.setName(name); |
|||
tenantProfile.setDescription(name + " Test"); |
|||
tenantProfile.setProfileData(JacksonUtil.OBJECT_MAPPER.createObjectNode()); |
|||
tenantProfile.setDefault(false); |
|||
tenantProfile.setIsolatedTbCore(false); |
|||
tenantProfile.setIsolatedTbRuleEngine(false); |
|||
return tenantProfile; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,23 @@ |
|||
/** |
|||
* Copyright © 2016-2020 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.sql; |
|||
|
|||
import org.thingsboard.server.dao.service.BaseDeviceProfileServiceTest; |
|||
import org.thingsboard.server.dao.service.DaoSqlTest; |
|||
|
|||
@DaoSqlTest |
|||
public class DeviceProfileServiceSqlTest extends BaseDeviceProfileServiceTest { |
|||
} |
|||
@ -0,0 +1,23 @@ |
|||
/** |
|||
* Copyright © 2016-2020 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.sql; |
|||
|
|||
import org.thingsboard.server.dao.service.BaseTenantProfileServiceTest; |
|||
import org.thingsboard.server.dao.service.DaoSqlTest; |
|||
|
|||
@DaoSqlTest |
|||
public class TenantProfileServiceSqlTest extends BaseTenantProfileServiceTest { |
|||
} |
|||
Loading…
Reference in new issue